From patchwork Fri Nov 12 10:22:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 31383 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp1633606iob; Fri, 12 Nov 2021 02:23:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3wpyAsfftt8TuwVThWrzI8ePzFIBNdw+eyrZSeYsifKQpsqRWWiAkwvEWcIV2sF/JulQm X-Received: by 2002:a05:6402:42c7:: with SMTP id i7mr20283881edc.223.1636712637106; Fri, 12 Nov 2021 02:23:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636712637; cv=none; d=google.com; s=arc-20160816; b=qhseEHwZwoPFOvqRIg9wdwtJy8L+bjI91nNwszesi7ol3eWAGB9Qs9uGm24lcrX5qc pafStn9BXtEQey9oqilQWieDBliJJiO18iOWLtMl4iCtVsKdFMCQ8lWojViobwzcRIaV WThadfHOw9ObLyzNJG4EEFpdBrmIKj11kiE3VRmNTm5BQEUs9hgrG3TySWHFCOVfupJX OLxlne2sbgyuryRoDbhrsrFiwJtpZAlupXlbXI5fkIW9n8/NPjua90bGvUUFLHPzhThS /96g6zJ3HdkLHKEuRJrvEuprAvPPg0kErGK16/+msKwP+WUEbCNcSqG4p8PCX7kqg0A3 hUsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=djST3MOmBTQ4lcznq10yclHQJih/D9ZtjdBuBf7DPRA=; b=1CPggksvxx9x/qDW1ePDVoTnnSxFvakKhljQQsfzY41oSyinp9Hw9SMgC3pPsogsNo JaZ/Ur6l5QY1TOuVt+4R5GzGVxqE+/NTV+6Uzxst5uYVbqiChhC/1kdEhNae7VJJIgky EOZaFDRcPN6xOg4DaXpbXiWllSJGNnLcUIHWYRdm5H9Fax/CZMhfYXlnUP0j6Es2GdH8 NRN+LKQ7FdpRLhA85vqJAX0JrbCxls4SsG8aNzFeQDZkgt0PpWrddRwfEcbeAySeWARw QkDI4GbwjxDrCEhliiV0aAYuleGR+keNHHmL0s0yzRkcWkrt1mtnxli4WkOvOm/gpjo8 CqEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=gettnUg7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e4si1259953edr.608.2021.11.12.02.23.56; Fri, 12 Nov 2021 02:23:57 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=gettnUg7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2E1DC68AE76; Fri, 12 Nov 2021 12:22:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A98E468AE5B for ; Fri, 12 Nov 2021 12:22:30 +0200 (EET) Received: by mail-pf1-f172.google.com with SMTP id x131so8095047pfc.12 for ; Fri, 12 Nov 2021 02:22:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GMA50OBp8AHVw+RWXRb12nQzt583rGbiYYCWL61e93o=; b=gettnUg7lnYFs8Zotl2ZwtCi80g57D8VIECgpCTEV1igfGGf80Wpwn+nbOEBtpBfYC ELJitVwSIN27TlDMOi7ktkwOvmGYzL+4T0r1subsjGuSMN383lJlswMddATBThGhI32W iqJIn3x07c7cQoEWZFEN08M74tdwm93yCwvB0mMoR1XMHtsKEFFyuLmsv+bnV9HHjceF TYZGmbaDasg+6QIWfCNJJk9zYRzbyMWv2MRKhCe9EUYglfMfbipdnNg+tQVJnhLTbhEc ePFyRfdSVq+10HWcZMWBVnEl4iNGUsYI8Fh1CLAmWJHLxActxCVH4oiEV6PEuLAyJogg km2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GMA50OBp8AHVw+RWXRb12nQzt583rGbiYYCWL61e93o=; b=iUDmc3chH/3LC7VV5MfO1z0Oeutga/dgVYZgNMx49+wWbP1jDeVEL2W+3S5swKJWoE 3JhPwFUbEKazgqJuke7RhCvkI5Sy8FHDs+xbbQ98RYJkUeP62dSR8QRqigS43XmYPPI1 P9RvwujpAxsQ0vTKuzgRosW3ZuS/zNldeojR+Iqw9QYW09JyLw1/j+SsfGaEHWmgCXhE M4pV1gPaeAczDFDFgLxoYxq/AWgszvQzgnsXAeqWnAXs+nOGVAuALhw8WoGnB/gaOjqw +cBbdjlgJY1H+Sp6hoFO2Y4NwR6oEHggTEhUG4LFv25AINPCds8Ak0Yi+IlZso9rJAgb hd2A== X-Gm-Message-State: AOAM533mMA3VIygg6y4ybkdQLqZa8gjM4eTMcpnY4wXd47LnG0wIcXzj 4ZfquG0Gx4ojU3lrFfYgh0MIyB64rGQ= X-Received: by 2002:a05:6a00:cd0:b0:49f:b198:97a5 with SMTP id b16-20020a056a000cd000b0049fb19897a5mr12770887pfv.80.1636712548885; Fri, 12 Nov 2021 02:22:28 -0800 (PST) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id f19sm6030563pfc.122.2021.11.12.02.22.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 02:22:28 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Nov 2021 18:22:13 +0800 Message-Id: <1636712536-13114-8-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1636712536-13114-1-git-send-email-lance.lmwang@gmail.com> References: <1636712536-13114-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 08/11] avcodec: suppport for s210 encode X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4zdZUoUJOpNy From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/s210enc.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 libavcodec/s210enc.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1d75cfe..69734ca 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -244,6 +244,7 @@ OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER) += binkaudio.o OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER) += binkaudio.o OBJS-$(CONFIG_BINTEXT_DECODER) += bintext.o cga_data.o OBJS-$(CONFIG_S210_DECODER) += s210dec.o +OBJS-$(CONFIG_S210_ENCODER) += s210enc.o OBJS-$(CONFIG_BMP_DECODER) += bmp.o msrledec.o OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o OBJS-$(CONFIG_BMV_AUDIO_DECODER) += bmvaudio.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index c461798..77f5ed4 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -65,6 +65,7 @@ extern const AVCodec ff_bethsoftvid_decoder; extern const AVCodec ff_bfi_decoder; extern const AVCodec ff_bink_decoder; extern const AVCodec ff_s210_decoder; +extern const AVCodec ff_s210_encoder; extern const AVCodec ff_bmp_encoder; extern const AVCodec ff_bmp_decoder; extern const AVCodec ff_bmv_video_decoder; diff --git a/libavcodec/s210enc.c b/libavcodec/s210enc.c new file mode 100644 index 0000000..c24f466 --- /dev/null +++ b/libavcodec/s210enc.c @@ -0,0 +1,90 @@ +/* + * S210 decoder + * + * Copyright (c) 2021 Limin Wang + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "encode.h" +#include "internal.h" +#include "put_bits.h" + +static av_cold int encode_init(AVCodecContext *avctx) +{ + if (avctx->width & 1) { + av_log(avctx, AV_LOG_ERROR, "s210 needs even width\n"); + return AVERROR(EINVAL); + } + + avctx->bits_per_coded_sample = 20; + avctx->bit_rate = ff_guess_coded_bitrate(avctx); + + return 0; +} + +static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *frame, int *got_packet) +{ + const int buf_size = avctx->height * avctx->width * 20 / 8; + int ret; + uint8_t *dst; + const uint16_t *y; + const uint16_t *u; + const uint16_t *v; + PutBitContext pb; + + ret = ff_get_encode_buffer(avctx, pkt, buf_size, 0); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); + return ret; + } + dst = pkt->data; + + init_put_bits(&pb, dst, buf_size); + + for (int i = 0; i < avctx->height; i++) { + y = (uint16_t*)(frame->data[0] + i * frame->linesize[0]); + u = (uint16_t*)(frame->data[1] + i * frame->linesize[1]); + v = (uint16_t*)(frame->data[2] + i * frame->linesize[2]); + + for (int j = 0; j < avctx->width; j += 2) { + /* u, y0, v, y1 */ + put_bits(&pb, 10, av_clip_uintp2(*u++, 10)); + put_bits(&pb, 10, av_clip_uintp2(*y++, 10)); + put_bits(&pb, 10, av_clip_uintp2(*v++, 10)); + put_bits(&pb, 10, av_clip_uintp2(*y++, 10)); + } + } + flush_put_bits(&pb); + + *got_packet = 1; + return 0; +} + +const AVCodec ff_s210_encoder = { + .name = "s210", + .long_name = NULL_IF_CONFIG_SMALL("10-bit 4:2:2 packed"), + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_S210, + .capabilities = AV_CODEC_CAP_DR1, + .init = encode_init, + .encode2 = encode_frame, + .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV422P10, AV_PIX_FMT_NONE }, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +};