From patchwork Thu Aug 29 07:18:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 14776 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AF90044940E for ; Thu, 29 Aug 2019 10:18:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 85206680782; Thu, 29 Aug 2019 10:18:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F7E1680722 for ; Thu, 29 Aug 2019 10:18:45 +0300 (EEST) Received: by mail-pl1-f193.google.com with SMTP id t14so1142082plr.11 for ; Thu, 29 Aug 2019 00:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oX4uCPAmFpp3Aei1CDAAWu1Qk5BI2nl/YVclBfD4kXA=; b=gm05STPOT3oHcDJwWAYraw42LZk2n0ws5qyWP5wKxVx0gu/F+IKjIIiJnHOYRP5wcZ Icho389q5zwHAAK63rzmEG/OVIgeFXLA5UOWzZEwWFV7R7yZO+tqBcRJ4G5kJUlTUPSe oS+HzYV6EUYdWdxx0mSJevyg2DljUPHTG9uLfr1OtQQGcr+/SSI3ihaCtp01TJlWKhxY ExTI6jV8PX4JEsIANjGrGORkFO71cs2cLwA5j2H+Scoq7I3ypOcA3KDLBpQuNvMmF3Qp 4byL6bMpppsWNRrZDE5C9rz7UT54gqBITvoUXFZyISnwbczod22x/085iXoSLZ+e0zr+ D+bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oX4uCPAmFpp3Aei1CDAAWu1Qk5BI2nl/YVclBfD4kXA=; b=dWfKn5fDwhNEUUzFEjQbNNrDHoGVapG2yegQmw8+Gd66l5Z7Vlbypi/7iSRMghH+4g mRY51ZHNW610lL6/ZiYHB7twhShmnpkZqm9LMK3TzmybSey1aitwpcwp2dgVV5liY/UA Ozu9yVATXcXroPQEarWn6FZAW+ZFVqD7jMtg6Va8B49nzMkY+BCjlarXouMvo243ofr/ cbnXrtsK8SaGM/W8ZyDKmz4j8iMOl3fsthAQ86Jyf7k+QEF4G8OL+sHk1R1oos+7Zfmr QSf1et8RppQunbr8J73XxyJlVpJv+usBAdEHgBoSzZIGBSK05tcB+5bktduNXKB2hf86 oF3g== X-Gm-Message-State: APjAAAVXdbbo+57sewnjQW4mqm5QZhpAd9BlMNhVh+i1DMWjGw10b7Nr ZGkPPlFcu2pb3YbRI9lWYnusuUnN X-Google-Smtp-Source: APXvYqzDMt5XKQoRjPtuKjtLWhMDSN/Gnfze0rr0i3502lccSFlamYLIMy5zkLsuOiNqxBJaJBo/2g== X-Received: by 2002:a17:902:e30b:: with SMTP id cg11mr8502440plb.335.1567063123475; Thu, 29 Aug 2019 00:18:43 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id a128sm1851682pfb.185.2019.08.29.00.18.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 00:18:42 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Aug 2019 15:18:39 +0800 Message-Id: <20190829071839.24586-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <1567007116-9088-1-git-send-email-lance.lmwang@gmail.com> References: <1567007116-9088-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 5/6] avcodec/v210enc: define DEFINE_V210_ENCODE_FUNC to remove duplicate code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/v210enc.c | 171 +++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 102 deletions(-) diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c index 2400538f73..1b17d885cc 100644 --- a/libavcodec/v210enc.c +++ b/libavcodec/v210enc.c @@ -89,15 +89,77 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } +#define DEFINE_V210_ENCODE_FUNC(nbits, depth) \ +static void v210_enc_##depth(AVCodecContext *avctx, \ + uint8_t *dst, const AVFrame *pic) \ +{ \ + V210EncContext *s = avctx->priv_data; \ + int aligned_width = ((avctx->width + 47) / 48) * 48; \ + int stride = aligned_width * 8 / 3; \ + int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4; \ + int h, w; \ + int bytes = nbits / 8; \ + const uint##nbits##_t *y = (const uint##nbits##_t *)pic->data[0]; \ + const uint##nbits##_t *u = (const uint##nbits##_t *)pic->data[1]; \ + const uint##nbits##_t *v = (const uint##nbits##_t *)pic->data[2]; \ + const int sample_size = 6 * s->sample_factor_##depth; \ + const int sample_w = avctx->width / sample_size; \ + \ + for (h = 0; h < avctx->height; h++) { \ + uint32_t val; \ + w = sample_w * sample_size; \ + s->pack_line_##depth (y, u, v, dst, w); \ + \ + y += w; \ + u += w >> 1; \ + v += w >> 1; \ + dst += sample_w * 16 * s->sample_factor_##depth; \ + \ + for (; w < avctx->width - 5; w += 6) { \ + WRITE_PIXELS(u, y, v, depth); \ + WRITE_PIXELS(y, u, y, depth); \ + WRITE_PIXELS(v, y, u, depth); \ + WRITE_PIXELS(y, v, y, depth); \ + } \ + if (w < avctx->width - 1) { \ + WRITE_PIXELS(u, y, v, depth); \ + \ + val = CLIP(*y++, depth) << (10-depth); \ + if (w == avctx->width - 2) { \ + AV_WL32(dst, val); \ + dst += 4; \ + } \ + } \ + if (w < avctx->width - 3) { \ + val |= (CLIP(*u++, depth) << (20-depth)) | \ + (CLIP(*y++, depth) << (30-depth)); \ + AV_WL32(dst, val); \ + dst += 4; \ + \ + val = CLIP(*v++, depth) << (10-depth) | \ + (CLIP(*y++, depth) << (20-depth)); \ + AV_WL32(dst, val); \ + dst += 4; \ + } \ + \ + memset(dst, 0, line_padding); \ + dst += line_padding; \ + y += pic->linesize[0] / bytes - avctx->width; \ + u += pic->linesize[1] / bytes - avctx->width / 2; \ + v += pic->linesize[2] / bytes - avctx->width / 2; \ + } \ +} + +DEFINE_V210_ENCODE_FUNC(8, 8) +DEFINE_V210_ENCODE_FUNC(16, 10); + static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet) { - V210EncContext *s = avctx->priv_data; int aligned_width = ((avctx->width + 47) / 48) * 48; int stride = aligned_width * 8 / 3; - int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4; AVFrameSideData *side_data; - int h, w, ret; + int ret; uint8_t *dst; ret = ff_alloc_packet2(avctx, pkt, avctx->height * stride, avctx->height * stride); @@ -107,105 +169,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, } dst = pkt->data; - if (pic->format == AV_PIX_FMT_YUV422P10) { - const uint16_t *y = (const uint16_t *)pic->data[0]; - const uint16_t *u = (const uint16_t *)pic->data[1]; - const uint16_t *v = (const uint16_t *)pic->data[2]; - - const int sample_size = 6 * s->sample_factor_10; - const int sample_w = avctx->width / sample_size; - - for (h = 0; h < avctx->height; h++) { - uint32_t val; - w = sample_w * sample_size; - s->pack_line_10(y, u, v, dst, w); - - y += w; - u += w >> 1; - v += w >> 1; - dst += sample_w * 16 * s->sample_factor_10; - - for (; w < avctx->width - 5; w += 6) { - WRITE_PIXELS(u, y, v, 10); - WRITE_PIXELS(y, u, y, 10); - WRITE_PIXELS(v, y, u, 10); - WRITE_PIXELS(y, v, y, 10); - } - if (w < avctx->width - 1) { - WRITE_PIXELS(u, y, v, 10); - - val = CLIP(*y++, 10); - if (w == avctx->width - 2) { - AV_WL32(dst, val); - dst += 4; - } - } - if (w < avctx->width - 3) { - val |= (CLIP(*u++, 10) << (20-10)) | (CLIP(*y++, 10) << (30-10)); - AV_WL32(dst, val); - dst += 4; - - val = CLIP(*v++, 10) << (10-10) | (CLIP(*y++, 10) << (20-10)); - AV_WL32(dst, val); - dst += 4; - } - - memset(dst, 0, line_padding); - dst += line_padding; - y += pic->linesize[0] / 2 - avctx->width; - u += pic->linesize[1] / 2 - avctx->width / 2; - v += pic->linesize[2] / 2 - avctx->width / 2; - } - } else if(pic->format == AV_PIX_FMT_YUV422P) { - const uint8_t *y = pic->data[0]; - const uint8_t *u = pic->data[1]; - const uint8_t *v = pic->data[2]; - - const int sample_size = 6 * s->sample_factor_8; - const int sample_w = avctx->width / sample_size; - - for (h = 0; h < avctx->height; h++) { - uint32_t val; - w = sample_w * sample_size; - s->pack_line_8(y, u, v, dst, w); - - y += w; - u += w >> 1; - v += w >> 1; - dst += sample_w * 16 * s->sample_factor_8; - - for (; w < avctx->width - 5; w += 6) { - WRITE_PIXELS(u, y, v, 8); - WRITE_PIXELS(y, u, y, 8); - WRITE_PIXELS(v, y, u, 8); - WRITE_PIXELS(y, v, y, 8); - } - if (w < avctx->width - 1) { - WRITE_PIXELS(u, y, v, 8); - - val = CLIP(*y++, 8) << (10-8); - if (w == avctx->width - 2) { - AV_WL32(dst, val); - dst += 4; - } - } - if (w < avctx->width - 3) { - val |= (CLIP(*u++, 8) << (20-8)) | (CLIP(*y++, 8) << (30-8)); - AV_WL32(dst, val); - dst += 4; - - val = (CLIP(*v++, 8) << (10-8)) | (CLIP(*y++, 8) << (20-8)); - AV_WL32(dst, val); - dst += 4; - } - memset(dst, 0, line_padding); - dst += line_padding; - - y += pic->linesize[0] - avctx->width; - u += pic->linesize[1] - avctx->width / 2; - v += pic->linesize[2] - avctx->width / 2; - } - } + if (pic->format == AV_PIX_FMT_YUV422P10) + v210_enc_10(avctx, dst, pic); + else if(pic->format == AV_PIX_FMT_YUV422P) + v210_enc_8(avctx, dst, pic); side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_A53_CC); if (side_data && side_data->size) {