From patchwork Mon May 8 18:46:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3622 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp984980vsd; Mon, 8 May 2017 11:54:29 -0700 (PDT) X-Received: by 10.28.8.145 with SMTP id 139mr12283526wmi.26.1494269669842; Mon, 08 May 2017 11:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494269669; cv=none; d=google.com; s=arc-20160816; b=IAV4NkN+s7GFIMWKVUM77rt9bfpFblarX+L5+lqZGF8stN0DqsOPk1TeCzA/G99+C8 gAiC61EGALoBf9FysmENTIliDHr49Ym+jVy2F605c4cqlKUAI+OKqphzo3b8+QHN1X5y h0XIDZbKF6CFWuVvj98nv/Xr2+0ATawAz4+oZTI/0tfLZPLyFbbzsDdhzxzCg6bhDg2h wW29oToWyUDPCUtIR6Sj0cCYwqBZWkeb4GqbECSs2vDC3CygihzVDynWoLV35/DSn8Ui aQoKS73VIS4c8e/UhnILoR9y6FzjNhTLdQQf8m6fIOXaDKsBbVaX26hBsV9yWZBZQAPv H/1A== 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: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:arc-authentication-results; bh=GrFtL43miXp81UFYq1WdQ8AscRg4+Df68iQwZHqi6pw=; b=W0Xi8xHS5SffqlBafSfzPPJElseTGuwHy2VthH/QzJfPWBVZw646TgeI29Wyz8y94V Mq3vbIOAXvXePuDdSWOw4q1M1VSGMoF5Uk9nTt5PwZjwlg1c1N0S7bzIwuHosgmEuJDR B/lkLzp5b37VXKeU/xT9KCF6fe1TnTZffc4zini/w41SRDwEm+VXii+JrAiRZMu/Ijfb AppREJfrcevHUIYaEDNaQCOkhZcOPL1CSnAQ7dZVjapPcHyddzlKxBHZTXCl6ULdMnWb WKRVrB1gY+CRec0klt1ZLgPt9NjZCmAQEscOpDvGqaBC0X7QwZWBw+fSxL3NVTaQ6Yvv ZmQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; 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=NONE 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 199si3502703wms.154.2017.05.08.11.54.29; Mon, 08 May 2017 11:54:29 -0700 (PDT) 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; 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=NONE 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 EF50F688336; Mon, 8 May 2017 21:54:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21DA968023A for ; Mon, 8 May 2017 21:54:15 +0300 (EEST) Received: by mail-qk0-f195.google.com with SMTP id o85so11424981qkh.0 for ; Mon, 08 May 2017 11:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=aisEqoLqBM5ydZw0p4PlsG+1U2vDcOM589MNCBeuM+Q=; b=HsBWwNkbqGVNDuE2BfcDC2XXQAG3yDAX6TIOirRT1I8vgxnELZxlKlZmwouW6cFi/D FwZDiN08EVJBKkEQyuTTnDT+xwWV0AWKZhKnNDJ1ARh4axNqerqxLuCny68qoNakIjR4 Fup/djwmG/prQASKjtAary/ZTIcP3bF1Aka24Gg6p7j5j84jYYb+XgL+ex5kwxUraQ1G UHCCyJOYhj4tw5h5XERHD5N4871u8LDqqKnKkDRJ4DRRoJV67lNS+bZcpXxLbBUDStYt celXQulH/ANOnkgu8F5fCbBtwB7RfujmVRe78r/NohWbCvJY1uz/MJeXZlHrMb7CFZU2 9Bww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=aisEqoLqBM5ydZw0p4PlsG+1U2vDcOM589MNCBeuM+Q=; b=raHKbA9BWXxay4ZNUnQIRjIuMBL3PWInzAhtMJACyvb87mHqpYadl6sgDV29YgIU7k LvomXMr/jPyOqPVu7xAuLVewzSsRo12Si5UdqU91DPqsGNeri3Mv1BNBS4cmp95NPjyg jhWM0fcj2B6Q1zYOA437r7vHbb+1l08i9E6l4IjMuEhkRVVce2oqmVnlpYUQLrnibnO4 hN3EZuEw7iwrsuiJEisgcNsHbLtINIDmqot0r9ozlMmdayvA/n/wdWXsWPkneNLMHE7X hqGbCkaWZbIbok1eaKAKgHLIgnsrKESnVXJ9ItPdAVrIAR0EJ4h8aG9qfv9aRrgOC/qt ng+Q== X-Gm-Message-State: AODbwcCe3S0GyKE/hhZLsIGGkM+lU3iSjRf2MKr1ZuN3JjvDGZQC807H ZWmLEGGyUmDrmcN7 X-Received: by 10.55.164.149 with SMTP id n143mr28654091qke.205.1494269242933; Mon, 08 May 2017 11:47:22 -0700 (PDT) Received: from localhost.localdomain ([181.231.116.134]) by smtp.gmail.com with ESMTPSA id t136sm702878qke.40.2017.05.08.11.47.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 11:47:22 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 May 2017 15:46:24 -0300 Message-Id: <20170508184625.7056-3-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170508184625.7056-1-jamrial@gmail.com> References: <20170508184625.7056-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/4] h264dec: export cropping information instead of handling it internally 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Anton Khirnov --- This merges commit c3e84820d67cb1d8cfb4196f9b43971308a81571 from libav libavcodec/h264_picture.c | 3 --- libavcodec/h264_ps.c | 9 --------- libavcodec/h264_slice.c | 25 +++++++++++++++++++------ libavcodec/h264dec.c | 13 +------------ libavcodec/h264dec.h | 9 +++++---- 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c index 2dbe5ee40b..99d9f9075c 100644 --- a/libavcodec/h264_picture.c +++ b/libavcodec/h264_picture.c @@ -113,9 +113,6 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src) dst->mbaff = src->mbaff; dst->field_picture = src->field_picture; dst->reference = src->reference; - dst->crop = src->crop; - dst->crop_left = src->crop_left; - dst->crop_top = src->crop_top; dst->recovered = src->recovered; dst->invalid_gap = src->invalid_gap; dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt; diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index 785836123e..b7d5f65d32 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -533,15 +533,6 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, int step_x = 1 << hsub; int step_y = (2 - sps->frame_mbs_only_flag) << vsub; - if (crop_left & (0x1F >> (sps->bit_depth_luma > 8)) && - !(avctx->flags & AV_CODEC_FLAG_UNALIGNED)) { - crop_left &= ~(0x1F >> (sps->bit_depth_luma > 8)); - av_log(avctx, AV_LOG_WARNING, - "Reducing left cropping to %d " - "chroma samples to preserve alignment.\n", - crop_left); - } - if (crop_left > (unsigned)INT_MAX / 4 / step_x || crop_right > (unsigned)INT_MAX / 4 / step_x || crop_top > (unsigned)INT_MAX / 4 / step_y || diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index a7916e09ce..8ba23712a1 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -197,10 +197,6 @@ static int alloc_picture(H264Context *h, H264Picture *pic) if (ret < 0) goto fail; - pic->crop = h->ps.sps->crop; - pic->crop_top = h->ps.sps->crop_top; - pic->crop_left= h->ps.sps->crop_left; - if (h->avctx->hwaccel) { const AVHWAccel *hwaccel = h->avctx->hwaccel; av_assert0(!pic->hwaccel_picture_private); @@ -495,6 +491,11 @@ static int h264_frame_start(H264Context *h) pic->f->pict_type = h->slice_ctx[0].slice_type; + pic->f->crop_left = h->crop_left; + pic->f->crop_right = h->crop_right; + pic->f->crop_top = h->crop_top; + pic->f->crop_bottom = h->crop_bottom; + if ((ret = alloc_picture(h, pic)) < 0) return ret; if(!h->frame_recovered && !h->avctx->hwaccel @@ -870,8 +871,12 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) static int init_dimensions(H264Context *h) { const SPS *sps = (const SPS*)h->ps.sps; - int width = h->width - (sps->crop_right + sps->crop_left); - int height = h->height - (sps->crop_top + sps->crop_bottom); + int cr = sps->crop_right; + int cl = sps->crop_left; + int ct = sps->crop_top; + int cb = sps->crop_bottom; + int width = h->width - (cr + cl); + int height = h->height - (ct + cb); av_assert0(sps->crop_right + sps->crop_left < (unsigned)h->width); av_assert0(sps->crop_top + sps->crop_bottom < (unsigned)h->height); @@ -884,6 +889,10 @@ static int init_dimensions(H264Context *h) h->height_from_caller <= height) { width = h->width_from_caller; height = h->height_from_caller; + cl = 0; + ct = 0; + cr = h->width - width; + cb = h->height - height; } else { h->width_from_caller = 0; h->height_from_caller = 0; @@ -893,6 +902,10 @@ static int init_dimensions(H264Context *h) h->avctx->coded_height = h->height; h->avctx->width = width; h->avctx->height = height; + h->crop_right = cr; + h->crop_left = cl; + h->crop_top = ct; + h->crop_bottom = cb; return 0; } diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index a8d07df1e7..c7abd9d45d 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -848,8 +848,6 @@ static int get_consumed_bytes(int pos, int buf_size) static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp) { AVFrame *src = srcp->f; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src->format); - int i; int ret; if (src->format == AV_PIX_FMT_VIDEOTOOLBOX && src->buf[0]->size == 1) @@ -863,16 +861,7 @@ static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp) if (srcp->sei_recovery_frame_cnt == 0) dst->key_frame = 1; - if (!srcp->crop) - return 0; - for (i = 0; i < desc->nb_components; i++) { - int hshift = (i > 0) ? desc->log2_chroma_w : 0; - int vshift = (i > 0) ? desc->log2_chroma_h : 0; - int off = ((srcp->crop_left >> hshift) << h->pixel_shift) + - (srcp->crop_top >> vshift) * dst->linesize[i]; - dst->data[i] += off; - } return 0; } @@ -1081,7 +1070,7 @@ AVCodec ff_h264_decoder = { .capabilities = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING, .flush = flush_dpb, .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy), .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context), diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 5e03d55558..2106ba077e 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -161,10 +161,6 @@ typedef struct H264Picture { int recovered; ///< picture at IDR or recovery point + recovery count int invalid_gap; int sei_recovery_frame_cnt; - - int crop; - int crop_left; - int crop_top; } H264Picture; typedef struct H264Ref { @@ -380,6 +376,11 @@ typedef struct H264Context { */ int picture_idr; + int crop_left; + int crop_right; + int crop_top; + int crop_bottom; + int8_t(*intra4x4_pred_mode); H264PredContext hpc;