From patchwork Mon Aug 10 15:49:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 21586 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 B9E9F44A9A5 for ; Mon, 10 Aug 2020 18:50:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8ED4868ABFA; Mon, 10 Aug 2020 18:50:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F6166881DC for ; Mon, 10 Aug 2020 18:50:17 +0300 (EEST) Received: by mail-qk1-f194.google.com with SMTP id m7so8720661qki.12 for ; Mon, 10 Aug 2020 08:50:17 -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:mime-version :content-transfer-encoding; bh=iKc6zD5feyZzgzFC/sBLgScOsfFnZDPn+SjtXdHl/Rg=; b=TFYFw7+xMEbFFUE1GArHKwY6T9WfTtyY0xt1NeW9DXieGOV0JouUi237p1+RBF1si3 IaGKB7cNmfvumPvgTSXQr3JPpmCxbkonrXxgpgFIWY/PYBzGYa0J1VirIa0m73twirpi KJjLJ49AIwE5AOstITifx/EHSYtOwcDcGjlJ28YorCDjgfbH9DLV/qmn7UbbzVpbrI6k +akDDi8RKhsidXpXlEbthqx/jDv8vkqA3U1wmitog/5HF1TJGBeLgmrkeEvugYhroEYj 3otBH7+crGt5jfaj5iQnECfvaCJuxWAy8VArbyLSaOZ+s1RXtMrjb3zcpKoWeBd4T8xo vYBw== 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:mime-version:content-transfer-encoding; bh=iKc6zD5feyZzgzFC/sBLgScOsfFnZDPn+SjtXdHl/Rg=; b=a3jam9sc45UghTOBLNzJrAwzvobqblq9DoQfPL1FVZX53wWZkTwG+i3j09abQeK/J1 3W5+PHCVhI44JUwC1ZejMQIQ//WQB3XMNd8RWEqtgqHvALfNt6wALviWg0kQomeZFuhf GTM6Vrhd9RVZWa6OZItZebkOKLOiRi+uP7ORdOLQ9dbNDAlmtZsL/BUEPGvWZ544woVs +ZRd5VCbARVkwDyo/ebFTzQv1s75pMZQRTe4KZLyFSWxOAPnosLNR5OjHeGKmXIn4dHm fhus+a7ZrSu04+OH+r8NMlkXeaY7A1hPUrUPdqBgVJiLAFbznwfJIckJFIxul8mBKOKI ep5Q== X-Gm-Message-State: AOAM533Qbtr53183hI3EEUGXnSnIGMCB+lMQPabPbBOJviVg9XdsCuxu HcAdSy0Q4Sag6IVqM6HMx83xTRAl X-Google-Smtp-Source: ABdhPJwJ1DOIaiys2QbShCq4WtCYL5t1iGCqdGwN59i+GncARliHAlFuFs15abIgwldXIHP1BVfAAg== X-Received: by 2002:a05:620a:1034:: with SMTP id a20mr27049715qkk.88.1597074615328; Mon, 10 Aug 2020 08:50:15 -0700 (PDT) Received: from localhost.localdomain ([181.23.72.45]) by smtp.gmail.com with ESMTPSA id o15sm13793249qkk.95.2020.08.10.08.50.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 08:50:14 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Aug 2020 12:49:41 -0300 Message-Id: <20200810154941.4988-5-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200810154941.4988-1-jamrial@gmail.com> References: <20200810154941.4988-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avcodec: move ff_alloc_a53_sei() to atsc_53 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- configure | 9 +++++--- libavcodec/atsc_a53.c | 43 ++++++++++++++++++++++++++++++++++++ libavcodec/atsc_a53.h | 17 ++++++++++++++ libavcodec/internal.h | 15 ------------- libavcodec/libx264.c | 1 + libavcodec/nvenc.c | 1 + libavcodec/utils.c | 43 ------------------------------------ libavcodec/videotoolboxenc.c | 1 + 8 files changed, 69 insertions(+), 61 deletions(-) diff --git a/configure b/configure index 762e74a8ab..0815b0d6a0 100755 --- a/configure +++ b/configure @@ -3060,9 +3060,10 @@ h264_mediacodec_decoder_select="h264_mp4toannexb_bsf h264_parser" h264_mf_encoder_deps="mediafoundation" h264_mmal_decoder_deps="mmal" h264_nvenc_encoder_deps="nvenc" +h264_nvenc_encoder_select="atsc_a53" h264_omx_encoder_deps="omx" h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec" -h264_qsv_encoder_select="qsvenc" +h264_qsv_encoder_select="atsc_a53 qsvenc" h264_rkmpp_decoder_deps="rkmpp" h264_rkmpp_decoder_select="h264_mp4toannexb_bsf" h264_vaapi_encoder_select="cbs_h264 vaapi_encode" @@ -3076,6 +3077,7 @@ hevc_mediacodec_decoder_deps="mediacodec" hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser" hevc_mf_encoder_deps="mediafoundation" hevc_nvenc_encoder_deps="nvenc" +hevc_nvenc_encoder_select="atsc_a53" hevc_qsv_decoder_select="hevc_mp4toannexb_bsf qsvdec" hevc_qsv_encoder_select="hevcparse qsvenc" hevc_rkmpp_decoder_deps="rkmpp" @@ -3200,9 +3202,9 @@ pcm_mulaw_at_encoder_deps="audiotoolbox" pcm_mulaw_at_encoder_select="audio_frame_queue" chromaprint_muxer_deps="chromaprint" h264_videotoolbox_encoder_deps="pthreads" -h264_videotoolbox_encoder_select="videotoolbox_encoder" +h264_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder" hevc_videotoolbox_encoder_deps="pthreads" -hevc_videotoolbox_encoder_select="videotoolbox_encoder" +hevc_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder" libaom_av1_decoder_deps="libaom" libaom_av1_encoder_deps="libaom" libaom_av1_encoder_select="extract_extradata_bsf" @@ -3265,6 +3267,7 @@ libwebp_encoder_deps="libwebp" libwebp_anim_encoder_deps="libwebp" libx262_encoder_deps="libx262" libx264_encoder_deps="libx264" +libx264_encoder_select="atsc_a53" libx264rgb_encoder_deps="libx264 x264_csp_bgr" libx264rgb_encoder_select="libx264_encoder" libx265_encoder_deps="libx265" diff --git a/libavcodec/atsc_a53.c b/libavcodec/atsc_a53.c index f040b0c10e..b0e4bbd4a3 100644 --- a/libavcodec/atsc_a53.c +++ b/libavcodec/atsc_a53.c @@ -22,6 +22,49 @@ #include "atsc_a53.h" #include "get_bits.h" +int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, + void **data, size_t *sei_size) +{ + AVFrameSideData *side_data = NULL; + uint8_t *sei_data; + + if (frame) + side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC); + + if (!side_data) { + *data = NULL; + return 0; + } + + *sei_size = side_data->size + 11; + *data = av_mallocz(*sei_size + prefix_len); + if (!*data) + return AVERROR(ENOMEM); + sei_data = (uint8_t*)*data + prefix_len; + + // country code + sei_data[0] = 181; + sei_data[1] = 0; + sei_data[2] = 49; + + /** + * 'GA94' is standard in North America for ATSC, but hard coding + * this style may not be the right thing to do -- other formats + * do exist. This information is not available in the side_data + * so we are going with this right now. + */ + AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4')); + sei_data[7] = 3; + sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40; + sei_data[9] = 0; + + memcpy(sei_data + 10, side_data->data, side_data->size); + + sei_data[side_data->size+10] = 255; + + return 0; +} + int ff_parse_a53_cc(AVBufferRef **pbuf, const uint8_t *data, int size) { AVBufferRef *buf = *pbuf; diff --git a/libavcodec/atsc_a53.h b/libavcodec/atsc_a53.h index a419d801b9..0622a55549 100644 --- a/libavcodec/atsc_a53.h +++ b/libavcodec/atsc_a53.h @@ -19,9 +19,26 @@ #ifndef AVCODEC_ATSC_A53_H #define AVCODEC_ATSC_A53_H +#include #include #include "libavutil/buffer.h" +#include "libavutil/frame.h" + +/** + * Check AVFrame for A53 side data and allocate and fill SEI message with A53 info + * + * @param frame Raw frame to get A53 side data from + * @param prefix_len Number of bytes to allocate before SEI message + * @param data Pointer to a variable to store allocated memory + * Upon return the variable will hold NULL on error or if frame has no A53 info. + * Otherwise it will point to prefix_len uninitialized bytes followed by + * *sei_size SEI message + * @param sei_size Pointer to a variable to store generated SEI message length + * @return Zero on success, negative error code on failure + */ +int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, + void **data, size_t *sei_size); /** * Parse a data array for ATSC A53 Part 4 Closed Captions and store them in an AVBufferRef. diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 0a1c0a17ec..21486ae987 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -363,21 +363,6 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame); */ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx); -/** - * Check AVFrame for A53 side data and allocate and fill SEI message with A53 info - * - * @param frame Raw frame to get A53 side data from - * @param prefix_len Number of bytes to allocate before SEI message - * @param data Pointer to a variable to store allocated memory - * Upon return the variable will hold NULL on error or if frame has no A53 info. - * Otherwise it will point to prefix_len uninitialized bytes followed by - * *sei_size SEI message - * @param sei_size Pointer to a variable to store generated SEI message length - * @return Zero on success, negative error code on failure - */ -int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, - void **data, size_t *sei_size); - /** * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info * diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 347d29df27..ca7cc3a540 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -30,6 +30,7 @@ #include "avcodec.h" #include "internal.h" #include "packet_internal.h" +#include "atsc_a53.h" #if defined(_MSC_VER) #define X264_API_IMPORTS 1 diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 8f5036b699..ee8ba3cb39 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -31,6 +31,7 @@ #include "libavutil/avassert.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" +#include "atsc_a53.h" #include "encode.h" #include "internal.h" #include "packet_internal.h" diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 5a2a90b030..1814b417fc 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -2204,49 +2204,6 @@ int avcodec_parameters_to_context(AVCodecContext *codec, return 0; } -int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, - void **data, size_t *sei_size) -{ - AVFrameSideData *side_data = NULL; - uint8_t *sei_data; - - if (frame) - side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC); - - if (!side_data) { - *data = NULL; - return 0; - } - - *sei_size = side_data->size + 11; - *data = av_mallocz(*sei_size + prefix_len); - if (!*data) - return AVERROR(ENOMEM); - sei_data = (uint8_t*)*data + prefix_len; - - // country code - sei_data[0] = 181; - sei_data[1] = 0; - sei_data[2] = 49; - - /** - * 'GA94' is standard in North America for ATSC, but hard coding - * this style may not be the right thing to do -- other formats - * do exist. This information is not available in the side_data - * so we are going with this right now. - */ - AV_WL32(sei_data + 3, MKTAG('G', 'A', '9', '4')); - sei_data[7] = 3; - sei_data[8] = ((side_data->size/3) & 0x1f) | 0x40; - sei_data[9] = 0; - - memcpy(sei_data + 10, side_data->data, side_data->size); - - sei_data[side_data->size+10] = 255; - - return 0; -} - static unsigned bcd2uint(uint8_t bcd) { unsigned low = bcd & 0xf; diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index cc08cf6a50..e89cfaeed8 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -31,6 +31,7 @@ #include "libavutil/pixdesc.h" #include "internal.h" #include +#include "atsc_a53.h" #include "h264.h" #include "h264_sei.h" #include