From patchwork Mon Aug 19 23:36:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Juan=20De=20Le=C3=B3n?= X-Patchwork-Id: 14601 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 A84BC447D66 for ; Tue, 20 Aug 2019 02:37:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92DB168AB5B; Tue, 20 Aug 2019 02:37:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BBFCD68AAE8 for ; Tue, 20 Aug 2019 02:37:27 +0300 (EEST) Received: by mail-pl1-f202.google.com with SMTP id d6so2878412pls.17 for ; Mon, 19 Aug 2019 16:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=H6FDvEEf0S3eozt/k8ExnOxlGR4AMjMr1zuCTFsgVc0=; b=v2m0effgYbszc0SV6NZ9FZDWGoQ9A+z3E7rg+niiOxnuGiIfOkk9M6ZGvOW5uE7Akv 9WTsZqyk2VwEaAYZl4pUOqOu7J0Xl4eokmKrE7N7dnalvFsybAJqGnOK96A32noVoOQJ zi8XX9VxYqpl1Ej+I4CfmK4PLheDDwhwnBSJ7gr6sXcBB0wtBY+Fu5IJqTgZ/iomsIj5 xaCV4//jtv3yjJ6+eBEUVk3wezbG8pbcKmp6M8Xm/wDBTAqBKKUPvVIjNyJu8uYTWZD6 gAlAIcerdNEy0RY+MC9+3prGXoEU9kEpT8iGlwdWMduhcEoIE306vjxawg5xlUC2VKc6 PGjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=H6FDvEEf0S3eozt/k8ExnOxlGR4AMjMr1zuCTFsgVc0=; b=mPcfU9j7/XlLJciYp3iGIKU4S4o6U4gOiI1Ur2fypAgVPdX2dqgGj6SWo+bmff3nDN gqsxdBUq4jm2Zm3VdUfP75hyLrhbdHJD3htP9EDoAH4AvRR1F2w84IzFY+E3kzHsSD7d /WTSNxVhNsyg713dxwG/G52+YVyzNHPBb1fceXFxEWtNunqxvF7eTxpqdXN8XbEGqc/r shfEkIclWjggoqBFvkNBuNZ9Ljvz55nz15ip+7vxDNqjledFJA9RIYCDT8vLH/zpyhHl q6xKgfrpdJBgZnesbisjBvftsWLnSHrWkEMz+H5Ugazn47oXxoUCk56GsaNkmROBkeP7 UGDQ== X-Gm-Message-State: APjAAAVVJ7XgioApfpweBstak1SmdSVDazHU720//rNpJXAN8TXRbXr4 zCSXgTdwcv2RIY9sgmVV+DQYsntkA4iuUZqHYmNyS9/ITTfWWTtQVXy9fGoM36RXo4NFmbD3vWb i685DpSbvfzQzYCRSZ4y65qWOP+0tIqBrxbcKZsFoy1N3C+nmDF7hEA96nF5H4+c= X-Google-Smtp-Source: APXvYqzsmYbxF1ZLodfkBLBznL2qdMShb0TisdsRgT0GvmucmK3lEztuuZkWXbPkJ+lKVHTDZiI0cGXHDnM= X-Received: by 2002:a63:48c:: with SMTP id 134mr22418324pge.386.1566257845482; Mon, 19 Aug 2019 16:37:25 -0700 (PDT) Date: Mon, 19 Aug 2019 16:36:54 -0700 In-Reply-To: <20190819233655.171637-1-juandl@google.com> Message-Id: <20190819233655.171637-3-juandl@google.com> Mime-Version: 1.0 References: <20190819233655.171637-1-juandl@google.com> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog From: "=?UTF-8?q?Juan=20De=20Le=C3=B3n?=" To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/3] libavcodec: extractqp changes for h264 decoder 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: =?UTF-8?q?Juan=20De=20Le=C3=B3n?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Added extractqp flag as an argument to the -debug flag to enable qp extraction for the h264 decoder using AVEncodeInfo as AVFrameSideData. Signed-off-by: Juan De León --- libavcodec/avcodec.h | 1 + libavcodec/h264dec.c | 40 ++++++++++++++++++++++++++++++++++++++ libavcodec/options_table.h | 1 + 3 files changed, 42 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index d234271c5b..9e3185720a 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2671,6 +2671,7 @@ typedef struct AVCodecContext { #endif #define FF_DEBUG_BUFFERS 0x00008000 #define FF_DEBUG_THREADS 0x00010000 +#define FF_DEBUG_EXTRACTQP 0x00020000 #define FF_DEBUG_GREEN_MD 0x00800000 #define FF_DEBUG_NOMC 0x01000000 diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 8d1bd16a8e..1edbfde65e 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -28,6 +28,7 @@ #define UNCHECKED_BITSTREAM_READER 1 #include "libavutil/avassert.h" +#include "libavutil/encode_info.h" #include "libavutil/display.h" #include "libavutil/imgutils.h" #include "libavutil/opt.h" @@ -906,6 +907,45 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g f->format, f->width, f->height>>1); } + if (h->avctx->debug & FF_DEBUG_EXTRACTQP) { + int mb_height = h->height / 16; + int mb_width = h->width / 16; + int mb_xy = mb_width * mb_height; + const PPS *pps = (const PPS*)h->ps.pps; + + AVEncodeInfoFrame *encode_info = av_encode_info_create_side_data(out->f, mb_xy); + if (!encode_info) { + av_log(h->avctx, AV_LOG_ERROR, "Failed to allocate encode info in side data\n"); + return AVERROR(ENOMEM); + } + + encode_info->plane_q[0] = pps->init_qp; //base Y qp + if (pps->chroma_qp_index_offset[0] != 0) { + encode_info->plane_q[1] = pps->init_qp + pps->chroma_qp_index_offset[0]; + } + if (pps->chroma_qp_diff != 0) { + encode_info->plane_q[2] = pps->init_qp + pps->chroma_qp_index_offset[1]; + } + + // loop allocate qp + int qs_index, mb_y, mb_x; + int idx = 0; + AVEncodeInfoBlock *block; + for (mb_y = 0; mb_y < mb_height; mb_y++) { + for (mb_x = 0; mb_x < mb_width; mb_x++) { + qs_index = mb_x + mb_y * h->mb_stride; //qscale table index + + block = av_encode_info_get_block(encode_info, idx); + block->src_x = mb_x * 16 - h->crop_left; + block->src_y = mb_y * 16 - h->crop_top; + block->w = block->h = 16; + + block->delta_q = out->qscale_table[qs_index] - pps->init_qp; + idx++; + } + } + } + ret = output_frame(h, dst, out); if (ret < 0) return ret; diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 4a266eca16..e0e78a69c5 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -219,6 +219,7 @@ static const AVOption avcodec_options[] = { {"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"}, {"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|A|D, "debug"}, {"nomc", "skip motion compensation", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_NOMC }, INT_MIN, INT_MAX, V|A|D, "debug"}, +{"extractqp", "enable QP extraction per frame", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_EXTRACTQP }, INT_MIN, INT_MAX, V|D, "debug"}, {"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, #if FF_API_PRIVATE_OPT