From patchwork Mon Nov 29 18:51:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31796 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp6577592iob; Mon, 29 Nov 2021 10:52:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJw31u4ndIGuTiUN2lAR3hqdWx3acrkt1HHdqrunWIRB1mc4bZXMgN7PwWxoEE132w/5kAUw X-Received: by 2002:a05:6402:514d:: with SMTP id n13mr79501830edd.380.1638211951915; Mon, 29 Nov 2021 10:52:31 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t1si21807405ejg.360.2021.11.29.10.52.31; Mon, 29 Nov 2021 10:52:31 -0800 (PST) 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=@hotmail.com header.s=selector1 header.b=TvXmUmM5; arc=fail (body hash mismatch); 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=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5663868AC7B; Mon, 29 Nov 2021 20:52:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11olkn2036.outbound.protection.outlook.com [40.92.19.36]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CE8DE68A8EE for ; Mon, 29 Nov 2021 20:52:00 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BvZwjTlcv1VDUJrEVROhbKUN5BaCZFDFv6HN5P5K6VEs1hQDYGBWsxRzps3lNdRxCJZ52JMzn50YQRM8D3avFJ7UrbGjLW/7d6b7vq20CJm/KTHdGDV6FmZpPr3rk0YIgi35pTFvq4Hn0tyiVWlOvCW2zsmso8n13wfmHFCDhA+8S5u4Dj9vO/mqon3gkEJPJOJqmUDUjyoFdLd9lstWJusE6DjKw4BuwuV4EcoDpI4uP68cF3KavtUX7p7IPyP+9vCQlo5QIyuBoz0s3t1lU2mqOlXfa2rPqYIDifJR31z6LVqciwfu9O/BkwVeNHlcfXB2wsua7kjCAiNQhIgZDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yd3xoClzLNV00HS8+OYjN00X/WrpVGZGWD28HRsto0c=; b=G4RGk7BiV3aACM1Gug3+O00SH/7UsdtHeXKms/48cpa0MITRgM9N75qNsbKo/ZRY09+B9FLL6wJNNiD7nc09FrfCFrtrUG7FiS3acRk9NQUjNwYECqDSDoIqMT86CVB/sv1VuC/WutlCsPRU+bOKt2Gzh2R3VO+pXV9c67ltiHn87Id5AjzMbF+/4V9xscEWFf7G7itwKqtchP4dWnaCCpEonun21qtl4Gdw+taompYWGyNIB7qzcrNkrIhuaj+MMSK+L8//H0txDM5phjiY6yixMopxoGPNxe2yDizoAklUIg6sb7Et0jqcLHOiYqLnaVP2aNE0XGLy3zSaj9nTLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yd3xoClzLNV00HS8+OYjN00X/WrpVGZGWD28HRsto0c=; b=TvXmUmM5/rlEnXzeX7YRRD0LJubEw7AVvipM2+JvLVrWSQfdLvxfS0SxKicMHctRAUZ1361lwAYKTITVdV8/rKlSMxUAmvJO4dMTk1fHFM0YComzmcnBpbJkCj/BdeK2VNWBQjtPSJ42qbMPKEKDEy6cPPyNKHb4PyVY3J3AkkmKG116nv7CbnY3fv9W2BngHUvmX5SScDaHhC94GHKsi7fIdA/yGUYt+Euifz8fX+DU8oPfRrQ7mQVPdg7hDsHZH77iQx8oZBWjzV6JQtWSqsWRBQEmGXaz7udHvALkTDEVBg5OMb5O8uOB80kmJ+Dh2aQwdz1yt6exPxBpJsA05A== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0125.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22; Mon, 29 Nov 2021 18:51:50 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%5]) with mapi id 15.20.4734.024; Mon, 29 Nov 2021 18:51:50 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH 3/5] avcodec/h264dec: make h264_export_frame_props() accessible Thread-Index: AQHX5VIrU6vcRGytmkuM5JyUtdA9YA== Date: Mon, 29 Nov 2021 18:51:50 +0000 Message-ID: References: <62b3a721e463650b46e527abcc9169ec1cc3e9f8.1638210102.git.softworkz@hotmail.com> <2362f84d0e53c691dbf248743c6640c91d83a491.1638210102.git.softworkz@hotmail.com> In-Reply-To: <2362f84d0e53c691dbf248743c6640c91d83a491.1638210102.git.softworkz@hotmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [DqFi/6fPSOggrVO+FhR7Warl+/VgIf2Q] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0e6dd0ae-97a2-4a7f-f900-08d9b3694dd0 x-ms-traffictypediagnostic: DM8P223MB0125: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ieqN6qgDJR5p8Ss5NMeVYEbIPvlldcipTDlKRUnNRATQnHp+ashv4N/RPUvRO+3nOaylaDlngIEm4N6tpYGLcX+v9O5rSpcjCls6Tkf+FmopSbLMfn2JCh5pKBxU7IBYjsAo8hPoMnWynEH+vHk0NAVccQwVlJb3kFRG3GwWaqEDGmqkKKyQPKZCURIWwYOrR0Lpl+OACN06ywbw0Mcdi2gUKyWZa+skCWP+J3zOsqY5AjX3e9ayJ064VxGVYUwNUUbG7znnXETMI0hJOF6SWOUhvvyeMr2tlPv75KpddPnP/yqk1Pu+g74ph6WgnDM9xs8gM7kRM+yUUYKzOdPtiLy0vWTfa4SOHuFtaA8psDxHfVYnWK1mAofKdcSKKOk7kAZEMtLWXqnEFHJ2cz1hqzuKIEKt5AieTaqCmX2K8gxtS88lQOlR1TpkK1Hq51w4I2OWkjcfd92zpY0PoLDocwWi8xVY4dgziT5S82OmkeAzwVV3L3ieuhx+PhxkvaiUSoPTJ/cmeNM4O4zw5yrrlkZKwNY25kNTXnClCo7mHpRWoZ9aIev/v1uCUuC8KtxRuIgGxAz3l/O2Ow4Nre3VNQ== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: vKkHeVK7tgRoMjKb1m2gyESimVIKfiFtjwjsxx2E6a/0fL/q1FqkFjGLSH4rq6WQsAQFRYrMILdqR76OWVUnuczYnyFq1fMxcLzX1mGT6iWtj9+gknTLp1bNAvZ0xMdJFUGJ/9MTdbC8qiHT4tkEA5SXmI6ovNlSGsKkrmtl9i1Y4mtSt8vHzpD3UvkMUsbUa3jSgtOh53CLuiUr4eAjcNdlSIM7hVdgk9sYpvNrvydU6SHJpfhcFrzP5fDLnjzB2YNQX//+SGcgf+CddAE3ornkcNgd5sEMfGMvk9PtqwdcdarBJK0HlkY9wN4OSOkcg1mN5Wl9O7K74084ZLbTHfbnaFLbh0A2m8Ay7lICZOTz0PyEYgzF3VZSLmJwKKyaxaWgMVSr6iVCviEh6YEUohe7uBCo9lXpG5Cr4LkXZUlxZ8Z50n/UUcRM9A2AFEPScokQV75caN9s5buCN8I1r4blR4nixgiLjfkUGsZuiilci7Z270zk6cRt2i5LOOY5mkhbvXaadlChNFZvprJTK8FbAqzMtzQ+FTcerawDRXxk4py6iX3wAW5i12bcssDOhlCifYCS+Vi9oIgMJE3cvrCxHmhlfJ6UI2YUlVaXYB22ZgQlr/EBCsU2esgUpjZMiJuhfejGjUmllKlHVJdhe+V0gu8UrTOa400OweB+ESB76kkfTXHlZQmoChmREnXd0JdmTczfGugpFJULi3DW3w== MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3912-16-msonline-outlook-1fc6d.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 0e6dd0ae-97a2-4a7f-f900-08d9b3694dd0 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Nov 2021 18:51:50.7338 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8P223MB0125 Subject: [FFmpeg-devel] [PATCH 3/5] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AS7Y6xkdviDT 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 4467882775..5c1f38de03 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1163,11 +1163,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; @@ -1175,19 +1174,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; @@ -1221,21 +1220,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; @@ -1249,11 +1250,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) { @@ -1295,11 +1296,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, @@ -1311,29 +1312,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, @@ -1344,10 +1346,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); @@ -1401,7 +1403,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]; @@ -1412,14 +1414,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); @@ -1814,7 +1816,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 87c4e4e539..c887f5f2a4 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -872,4 +872,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 */