From patchwork Thu May 26 08:08:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35943 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp254411pzj; Thu, 26 May 2022 01:09:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy02QgJ04X5sfgYv1DeY/mf63yirjym2UafLFQeqc9pfQZWPA1PXvTRItZolznnP3pSEihD X-Received: by 2002:aa7:c44c:0:b0:42b:c58f:a100 with SMTP id n12-20020aa7c44c000000b0042bc58fa100mr8526984edr.248.1653552591979; Thu, 26 May 2022 01:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653552591; cv=none; d=google.com; s=arc-20160816; b=jC57MUhtmwtizD+NdKk/hy1tVD/USoGqcJnFfch8SvLc++nLan+tVh1YICHgNFaZ55 9G8goR4aj91/JELZpPgvMXICOHFoM16EnSGofk++CXPwFQn1gPJ4mljI+D54cjmNXnQU r5eYzIl5a32O/bvdZlLrPKbfAXFyi56xE4rFwRMBTc/3ZVtxBob70Wn7xiBR8y9aHx/W 2sa8D9GxV39Wj3GMMa6iYZchY2HTXeL/r9czQZK1E00vj9megf9qs8U3zvdsl2MMD7nn yMTHRrgaag9WJcSVpw80w3IMXXpTtoKxOp/e0J1o3Ebj3Ca3JktII6X1ZepV9OGuCz0h poaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=X9v33IOMlkj3SYealTptb6YXpC5vMBQlLLp6IKaus8M=; b=lVTCVmzh3O2hI5tcACtV6Ei6ex/JPqkfSo0g9uOxllQFhWy/jWHhc3wrKpFLydf52h INoBzROa1lOqtSnWseNnm532MMR6Iz0puPDA/ndeNfqF1ay+ipdr7rn6Yu6lEcLDMcOd HzGt93ojw8Zu1D7mjVm8v3ZD3Bu1EKDErHqgq2deGwc+d1/vFnUqD+1obfa2T+j8eKJs rRpP5z7HRnEqUepOvVRPHZRFAxPY/HvIs/RGdrAX3xQvzGXiQ/obgwhPJ0uo8BlRn6nS jiZPsYZz402h3MXM5LS4hNWIJPHWjNUBtLP6KjUANOO+4jufzqFS490aQE9EVmvEbHCt BndA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=mCet3vnH; 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 r2-20020aa7da02000000b0042b615e67dfsi851205eds.270.2022.05.26.01.09.51; Thu, 26 May 2022 01:09:51 -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 header.s=20210112 header.b=mCet3vnH; 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 D9AB968B5C8; Thu, 26 May 2022 11:09:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C1FEA68B55E for ; Thu, 26 May 2022 11:08:57 +0300 (EEST) Received: by mail-pl1-f174.google.com with SMTP id c2so860182plh.2 for ; Thu, 26 May 2022 01:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=woDLBsAm1baHrRCV48xAJlDmANE3EG0buKKKgOC6iEk=; b=mCet3vnHi85RLBFVArCrUxSXuagZKnUqDxD9K6qIETmVY42HdEoTcE2VZ6lpHpCR1H 4F+L9ThIYvxkttzib+oKbo8pWFBrYRjAZrZEsc4+XvX21fT+a2e0L1135Xgipxonaek9 vtzTNpU7CO7lbw8i1kiy6PfSRXgjooIbp5OhWaBnrkxRiLt/epezMm5kOIHsoNtkOpqb 0J09E9Ao4InaVk9u3z4s88BBrqYTX53WX6k8294J5naVfkblQhbU5xhJp45ZvfYpEuGY 5y9g5QWNsqjcsAOTOMcRAWcpq5EKYptr0KOCOpQ62kIhW3tkMc3OFW/Tg9j+CKCwDWHE U1wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=woDLBsAm1baHrRCV48xAJlDmANE3EG0buKKKgOC6iEk=; b=ZkWxhvuINBOiZu/JZd/6U7Z8IjqNZzySkrKY/MrPk2YuDTa2F3/hFAnoghRMaJhinh 8w80uNRKqEl2waNS0aklEPyBy63UEe16GuoIfc6c+uZ4ngENulJSy7O4ze5idM98yGC3 7RYvsnmhLuxtD+hgmjYj/qlNVV6TvR4qXil5vO9nKJhayR5rImS4C3Unfx1/oWlUoXgv Heu86aIxRD7vvH8bBsDzNhPsY4zq2xhmF38H2R72Bl3crN4fOt/+ihTU46jxXTZTroFp zO7/VxwMfGcSQ7JWJiAsQZcJYifTqXdgIwkRwTJqvmIyVV/pd8897fPwUask/MZiPIRQ 8QxA== X-Gm-Message-State: AOAM531vUcfbPYvJIcVLNDEvPaLsLtldb0wjWqCZ3/38VaQZ6ItjLydP MZHtlnWNOOfXAn3IMevFM+lYElNK7MfAJw== X-Received: by 2002:a17:902:7296:b0:151:62b1:e2b0 with SMTP id d22-20020a170902729600b0015162b1e2b0mr36417907pll.165.1653552536142; Thu, 26 May 2022 01:08:56 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id n16-20020a170902d2d000b0015e8d4eb21csm849366plc.102.2022.05.26.01.08.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2022 01:08:55 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Thu, 26 May 2022 08:08:48 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 5/6] avcodec/h264dec: make h264_export_frame_props() accessible 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: softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZG1cqdhdjZuh From: softworkz Signed-off-by: softworkz --- libavcodec/h264_slice.c | 98 +++++++++++++++++++++-------------------- libavcodec/h264dec.h | 2 + 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index d56722a5c2..f2a4c1c657 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1157,11 +1157,10 @@ static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_sl return 0; } -static int h264_export_frame_props(H264Context *h) +int ff_h264_export_frame_props(AVCodecContext *logctx, H264SEIContext *sei, H264Context *h, AVFrame *out) { - const SPS *sps = h->ps.sps; - H264Picture *cur = h->cur_pic_ptr; - AVFrame *out = cur->f; + const SPS *sps = h ? h->ps.sps : NULL; + H264Picture *cur = h ? h->cur_pic_ptr : NULL; out->interlaced_frame = 0; out->repeat_pict = 0; @@ -1169,19 +1168,19 @@ static int h264_export_frame_props(H264Context *h) /* Signal interlacing information externally. */ /* Prioritize picture timing SEI information over used * decoding process if it exists. */ - if (h->sei.picture_timing.present) { - int ret = ff_h264_sei_process_picture_timing(&h->sei.picture_timing, sps, - h->avctx); + if (sps && sei->picture_timing.present) { + int ret = ff_h264_sei_process_picture_timing(&sei->picture_timing, sps, + logctx); if (ret < 0) { - av_log(h->avctx, AV_LOG_ERROR, "Error processing a picture timing SEI\n"); - if (h->avctx->err_recognition & AV_EF_EXPLODE) + av_log(logctx, AV_LOG_ERROR, "Error processing a picture timing SEI\n"); + if (logctx->err_recognition & AV_EF_EXPLODE) return ret; - h->sei.picture_timing.present = 0; + sei->picture_timing.present = 0; } } - if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { - H264SEIPictureTiming *pt = &h->sei.picture_timing; + if (h && sps && sps->pic_struct_present_flag && sei->picture_timing.present) { + H264SEIPictureTiming *pt = &sei->picture_timing; switch (pt->pic_struct) { case H264_SEI_PIC_STRUCT_FRAME: break; @@ -1215,21 +1214,23 @@ static int h264_export_frame_props(H264Context *h) if ((pt->ct_type & 3) && pt->pic_struct <= H264_SEI_PIC_STRUCT_BOTTOM_TOP) out->interlaced_frame = (pt->ct_type & (1 << 1)) != 0; - } else { + } else if (h) { /* Derive interlacing flag from used decoding process. */ out->interlaced_frame = FIELD_OR_MBAFF_PICTURE(h); } - h->prev_interlaced_frame = out->interlaced_frame; - if (cur->field_poc[0] != cur->field_poc[1]) { + if (h) + h->prev_interlaced_frame = out->interlaced_frame; + + if (sps && cur->field_poc[0] != cur->field_poc[1]) { /* Derive top_field_first from field pocs. */ out->top_field_first = cur->field_poc[0] < cur->field_poc[1]; - } else { - if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { + } else if (sps) { + if (sps->pic_struct_present_flag && sei->picture_timing.present) { /* Use picture timing SEI information. Even if it is a * information of a past frame, better than nothing. */ - if (h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM || - h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP) + if (sei->picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM || + sei->picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP) out->top_field_first = 1; else out->top_field_first = 0; @@ -1243,11 +1244,11 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.frame_packing.present && - h->sei.frame_packing.arrangement_type <= 6 && - h->sei.frame_packing.content_interpretation_type > 0 && - h->sei.frame_packing.content_interpretation_type < 3) { - H264SEIFramePacking *fp = &h->sei.frame_packing; + if (sei->frame_packing.present && + sei->frame_packing.arrangement_type <= 6 && + sei->frame_packing.content_interpretation_type > 0 && + sei->frame_packing.content_interpretation_type < 3) { + H264SEIFramePacking *fp = &sei->frame_packing; AVStereo3D *stereo = av_stereo3d_create_side_data(out); if (stereo) { switch (fp->arrangement_type) { @@ -1289,11 +1290,11 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.display_orientation.present && - (h->sei.display_orientation.anticlockwise_rotation || - h->sei.display_orientation.hflip || - h->sei.display_orientation.vflip)) { - H264SEIDisplayOrientation *o = &h->sei.display_orientation; + if (sei->display_orientation.present && + (sei->display_orientation.anticlockwise_rotation || + sei->display_orientation.hflip || + sei->display_orientation.vflip)) { + H264SEIDisplayOrientation *o = &sei->display_orientation; double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16); AVFrameSideData *rotation = av_frame_new_side_data(out, AV_FRAME_DATA_DISPLAYMATRIX, @@ -1314,29 +1315,30 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.afd.present) { + if (sei->afd.present) { AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_AFD, sizeof(uint8_t)); if (sd) { - *sd->data = h->sei.afd.active_format_description; - h->sei.afd.present = 0; + *sd->data = sei->afd.active_format_description; + sei->afd.present = 0; } } - if (h->sei.a53_caption.buf_ref) { - H264SEIA53Caption *a53 = &h->sei.a53_caption; + if (sei->a53_caption.buf_ref) { + H264SEIA53Caption *a53 = &sei->a53_caption; AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_A53_CC, a53->buf_ref); if (!sd) av_buffer_unref(&a53->buf_ref); a53->buf_ref = NULL; - h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; + if (h) + h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } - for (int i = 0; i < h->sei.unregistered.nb_buf_ref; i++) { - H264SEIUnregistered *unreg = &h->sei.unregistered; + for (int i = 0; i < sei->unregistered.nb_buf_ref; i++) { + H264SEIUnregistered *unreg = &sei->unregistered; if (unreg->buf_ref[i]) { AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, @@ -1347,10 +1349,10 @@ static int h264_export_frame_props(H264Context *h) unreg->buf_ref[i] = NULL; } } - h->sei.unregistered.nb_buf_ref = 0; + sei->unregistered.nb_buf_ref = 0; - if (h->sei.film_grain_characteristics.present) { - H264SEIFilmGrainCharacteristics *fgc = &h->sei.film_grain_characteristics; + if (h && sps && sei->film_grain_characteristics.present) { + H264SEIFilmGrainCharacteristics *fgc = &sei->film_grain_characteristics; AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(out); if (!fgp) return AVERROR(ENOMEM); @@ -1404,7 +1406,7 @@ static int h264_export_frame_props(H264Context *h) h->avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; } - if (h->sei.picture_timing.timecode_cnt > 0) { + if (h && sei->picture_timing.timecode_cnt > 0) { uint32_t *tc_sd; char tcbuf[AV_TIMECODE_STR_SIZE]; @@ -1415,14 +1417,14 @@ static int h264_export_frame_props(H264Context *h) return AVERROR(ENOMEM); tc_sd = (uint32_t*)tcside->data; - tc_sd[0] = h->sei.picture_timing.timecode_cnt; + tc_sd[0] = sei->picture_timing.timecode_cnt; for (int i = 0; i < tc_sd[0]; i++) { - int drop = h->sei.picture_timing.timecode[i].dropframe; - int hh = h->sei.picture_timing.timecode[i].hours; - int mm = h->sei.picture_timing.timecode[i].minutes; - int ss = h->sei.picture_timing.timecode[i].seconds; - int ff = h->sei.picture_timing.timecode[i].frame; + int drop = sei->picture_timing.timecode[i].dropframe; + int hh = sei->picture_timing.timecode[i].hours; + int mm = sei->picture_timing.timecode[i].minutes; + int ss = sei->picture_timing.timecode[i].seconds; + int ff = sei->picture_timing.timecode[i].frame; tc_sd[i + 1] = av_timecode_get_smpte(h->avctx->framerate, drop, hh, mm, ss, ff); av_timecode_make_smpte_tc_string2(tcbuf, h->avctx->framerate, tc_sd[i + 1], 0, 0); @@ -1817,7 +1819,7 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, * field coded frames, since some SEI information is present for each field * and is merged by the SEI parsing code. */ if (!FIELD_PICTURE(h) || !h->first_field || h->missing_fields > 1) { - ret = h264_export_frame_props(h); + ret = ff_h264_export_frame_props(h->avctx, &h->sei, h, h->cur_pic_ptr->f); if (ret < 0) return ret; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 9a1ec1bace..38930da4ca 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -808,4 +808,6 @@ void ff_h264_free_tables(H264Context *h); void ff_h264_set_erpic(ERPicture *dst, H264Picture *src); +int ff_h264_export_frame_props(AVCodecContext *logctx, H264SEIContext *sei, H264Context *h, AVFrame *out); + #endif /* AVCODEC_H264DEC_H */