From patchwork Fri Jul 1 20:48:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36583 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp1261171pzh; Fri, 1 Jul 2022 13:49:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sWC+Y5nH9OXI8NJu+ZQQ6OwOn0W7KXUSt+1PvvNR3BAZPjnDVuXvpYMqZRsFRtdAXRpU+X X-Received: by 2002:a17:907:9812:b0:726:3e5b:d299 with SMTP id ji18-20020a170907981200b007263e5bd299mr16682573ejc.26.1656708574268; Fri, 01 Jul 2022 13:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656708574; cv=none; d=google.com; s=arc-20160816; b=iR2T42IST5k5z5Goe+UTkOIymQ6+dlE2OWKIWu7Z/G1zNqe5Jzl+8ilTpXlZl6OXTB kG8LLEVhpXn/WOUVaaEIlixm1igkzAOb82+AaQrci8r4ReTXYAHJ/Vwv5XqEVrA6aQd1 KrywOXM1JrsGTLp5zKn2/+ueKkJYGzoQTzeHZqvDqub5vIEhKj2+MlDsMHTCwngxmspW M1meIgr0hMHhgcVqsCxfb/rNFqMh/oGJ6nZYS3jGSwf57Su16FLFOnFsOR+URklloyba E5D372f6E9lFQLF/JcaZ+LP0j7YMblk70jfErZlXe+CkwJeOYjGIUGaArjxX4Gn033+x F1CA== 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=UkGH/QDJ/N8o219sZxA42j1bi1vCKLadN9t/EIp/D86iSAsVHW4aN2f8PJZHRe8XMj rkJzcE0eZAdIoy5GOeeJe/93eu3WbfM5N7+eiZ5kXRyG+OZMgIE/fsAQbwA0VACt3Rm5 64Jx8Er9qecWTt+/ePPbTYKIF8xhFiJKiFLGv1z6PwvKgjhkY+XDtIGWzKZreW/Euo14 gNcBy4dBVBsCJIxkzUQ6ntuSb7wcvEHInY+OdiOf9m2et93rLSYarfLke6FcRM6m2jAx TkYmYQ1cA5RbnZANJhbv7mZaxhpNaXUhz6m9TQXJh8IOQ59c4GF9uiEUcD/zMPQhW/Kf 15lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="g/r8IFGw"; 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 y5-20020a17090668c500b007136091f459si3686315ejr.302.2022.07.01.13.49.33; Fri, 01 Jul 2022 13:49:34 -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="g/r8IFGw"; 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 AE31768B803; Fri, 1 Jul 2022 23:49:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 160F968B7B5 for ; Fri, 1 Jul 2022 23:49:06 +0300 (EEST) Received: by mail-pj1-f46.google.com with SMTP id d14so3701418pjs.3; Fri, 01 Jul 2022 13:49:05 -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=g/r8IFGw5/4UWthgh3NZQINfX3RmwQUbQEDhLB5FWoZogaLFl5bFoVoDO23qDXdAmK aftuAah+U0Vreu9trfePc4SpGYGoXawwmqa0VQFbv+j2EbUGg1Syr7wDf3dJoFCxTNy0 Z45pAAqHf7rQwi9m+ya1TlYp5RWv3P7YKyDiBP9AdWgKD9D3NiENMbZKBGnmku4Tr1pQ kloJPD+JceGzFkRffYBlzaaX7wWxYri9Pf0n62Z8TsQtEtwIYRPRxdWXtrCEonWKsCi9 r1SFf0IoupDR/31a0D1bt4S1DKcLZnojNVd73j/t2onQI46eRjACTbcFf3xnB2lWuwMx TkIw== 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=RjIL1VpdBuiCMvptIlSG7F03LXNYi03fMBrWCp//ZIxh+39HLhK5/ipzim0fE0ft18 URxhQyv6ed8vvuXP8ZESnVbLimf/UA7xply9FT6y2gExsTR8Y69gk2qphfBDyjqYfjXP fDFxBXRMbqjEGaCr8hvyuG+O2Sul8XdUTfrkhOqpUGDIIoJb/KN2vk1GPvcJdjpB7Lpw fVhYIW7hoLDqBb7Y21TjF8aIn4zgOAF/WbGplu1FnRQ0KKKLBbEqVZRAqk5qa1D2o420 GsF/gAx+Ubr/U3GRzDAfr46hwbfNHFLKcglTaQUvlhInAxQ68h09QC8ahGj+5vA09UXv q1+g== X-Gm-Message-State: AJIora86RARtm/0mOURQQ8Oo0y8K1yzV/sxbjA2m/L6YgXkir/Rcb17j Jwi1KQQK81nR01igsnDK84cwxgNINUDJOg== X-Received: by 2002:a17:902:f151:b0:16a:466a:4ae4 with SMTP id d17-20020a170902f15100b0016a466a4ae4mr2527205plb.61.1656708544415; Fri, 01 Jul 2022 13:49:04 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id v4-20020a170902b7c400b0016223b5d228sm15899458plz.288.2022.07.01.13.49.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2022 13:49:03 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <4c0b6eb4cb9b480a9cab1695719cc52f9bb078dc.1656708534.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Fri, 01 Jul 2022 20:48:53 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v5 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: Kieran Kunhya , softworkz , "Xiang, Haihao" , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UprlDMeJz9xv 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 */