From patchwork Mon Aug 10 15:49:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 21587 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 50CA244A46B for ; Mon, 10 Aug 2020 19:19:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F276689AD2; Mon, 10 Aug 2020 19:19:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 22C9B6881FE for ; Mon, 10 Aug 2020 19:19:26 +0300 (EEST) Received: by mail-pj1-f43.google.com with SMTP id c6so88495pje.1 for ; Mon, 10 Aug 2020 09:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=AbZ4/pK6HMGXQG9d21LSB7xVFZ/Kx8m/TKJKs7pkqZk=; b=NLMbcscVaa0cQ1ptqlCBdj+ldGCsCA0oW3siiVUXgDtMxCpjp1qZyXo3gHYP9Tf7Ci bpapz6YBB8QsJr/magsWnHwzt9n2qWKMav5o+B9e/V8XwD31UCZdCro8LUCEUbzmdvl8 1TQkfe9zdz/hrKvzfG7DgEmNyYDIRCCB8ksiXW92ehMF8b+8stYpvcI48m9OTFWXrTe7 T0o7GoVsdlwGTq8V3lQi3gUJQjiPVCusC8c2sOA5g4GbzFVvQ5Lv00NeRQuX4TcWOYzk qfvPvNTUSpTXUwwoa7mm3SGgj7iNyFp3ySd7gtgBfUAY44Ew9nMgTmfdg5zp5bNertXw lTuQ== 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:mime-version :content-transfer-encoding; bh=AbZ4/pK6HMGXQG9d21LSB7xVFZ/Kx8m/TKJKs7pkqZk=; b=JoN7Qz2FwnWvP5JL4Va0/pS/w1h1dD5jQOuXnvOQqZlVJdTCd97UwF/XHECTxlpbZ9 9jdpnNVBFvwaFTj9jwnoJb9YKsxoqoZFAw/pGvTPxHR1pjezht3NUGvn30KkfMgZDjgj IlmhF3TgCa5PbekqhuCKsLqiwtFv6Q+3GnsZVpK9TPNPpAsjgDHQe3WhkwxdaWmf3Puw NEuodKBdmMZrrh9zdnfKoEDWs4V4uSQHvoMMffIfyFQTzlL1dmBK6i52dg4FGYKYYwhL UBq/+96pN7FwufbT6i+/yd3lZjgPD3kxWD58yi/v1TvC5cGcn7n4cVC8Ze+rrnwHQRA/ Czhw== X-Gm-Message-State: AOAM531NRDL52XXxkhHpSnCrHr1iIR3OFtG0yV7Sxymrlz2k7xZxI++i 97uhr6xHlMrbU3YAZ2zTXSz7PJrF X-Google-Smtp-Source: ABdhPJxKcCea97HfVtJOizLrZLGKnoJ3bdRa8PzBMa0SDOT90Upl9USClD4kOu4wcsNvIYhle6xvZA== X-Received: by 2002:a0c:bd96:: with SMTP id n22mr28223765qvg.19.1597074608732; Mon, 10 Aug 2020 08:50:08 -0700 (PDT) Received: from localhost.localdomain ([181.23.72.45]) by smtp.gmail.com with ESMTPSA id o15sm13793249qkk.95.2020.08.10.08.50.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 08:50:07 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Aug 2020 12:49:37 -0300 Message-Id: <20200810154941.4988-1-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avcodec: split off A53 Closed Caption parsing code into its own file 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 | 1 + libavcodec/Makefile | 1 + libavcodec/atsc_a53.c | 76 +++++++++++++++++++++++++++++++++++++++++++ libavcodec/atsc_a53.h | 39 ++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 libavcodec/atsc_a53.c create mode 100644 libavcodec/atsc_a53.h diff --git a/configure b/configure index 8de1afcb99..37fe01e8be 100755 --- a/configure +++ b/configure @@ -2344,6 +2344,7 @@ CONFIG_EXTRA=" aandcttables ac3dsp adts_header + atsc_a53 audio_frame_queue audiodsp blockdsp diff --git a/libavcodec/Makefile b/libavcodec/Makefile index fc4294816e..3431ba2dca 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -64,6 +64,7 @@ OBJS-$(CONFIG_AC3DSP) += ac3dsp.o ac3.o ac3tab.o OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o mpeg4audio.o OBJS-$(CONFIG_AMF) += amfenc.o OBJS-$(CONFIG_AUDIO_FRAME_QUEUE) += audio_frame_queue.o +OBJS-$(CONFIG_ATSC_A53) += atsc_a53.o OBJS-$(CONFIG_AUDIODSP) += audiodsp.o OBJS-$(CONFIG_BLOCKDSP) += blockdsp.o OBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o diff --git a/libavcodec/atsc_a53.c b/libavcodec/atsc_a53.c new file mode 100644 index 0000000000..f040b0c10e --- /dev/null +++ b/libavcodec/atsc_a53.c @@ -0,0 +1,76 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "atsc_a53.h" +#include "get_bits.h" + +int ff_parse_a53_cc(AVBufferRef **pbuf, const uint8_t *data, int size) +{ + AVBufferRef *buf = *pbuf; + GetBitContext gb; + size_t new_size, old_size = buf ? buf->size : 0; + int ret, cc_count; + + if (size < 3) + return AVERROR(EINVAL); + + ret = init_get_bits8(&gb, data, size); + if (ret < 0) + return ret; + + if (get_bits(&gb, 8) != 0x3) // user_data_type_code + return 0; + + skip_bits(&gb, 1); // reserved + if (!get_bits(&gb, 1)) // process_cc_data_flag + return 0; + + skip_bits(&gb, 1); // zero bit + cc_count = get_bits(&gb, 5); + if (!cc_count) + return 0; + + skip_bits(&gb, 8); // reserved + + /* 3 bytes per CC plus one byte marker_bits at the end */ + if (cc_count * 3 >= (get_bits_left(&gb) >> 3)) + return AVERROR(EINVAL); + + new_size = (old_size + cc_count * 3); + + if (new_size > INT_MAX) + return AVERROR(EINVAL); + + /* Allow merging of the cc data from two fields. */ + ret = av_buffer_realloc(pbuf, new_size); + if (ret < 0) + return ret; + + buf = *pbuf; + /* Use of av_buffer_realloc assumes buffer is writeable */ + for (int i = 0; i < cc_count; i++) { + buf->data[old_size++] = get_bits(&gb, 8); + buf->data[old_size++] = get_bits(&gb, 8); + buf->data[old_size++] = get_bits(&gb, 8); + } + + return cc_count; +} diff --git a/libavcodec/atsc_a53.h b/libavcodec/atsc_a53.h new file mode 100644 index 0000000000..a419d801b9 --- /dev/null +++ b/libavcodec/atsc_a53.h @@ -0,0 +1,39 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_ATSC_A53_H +#define AVCODEC_ATSC_A53_H + +#include + +#include "libavutil/buffer.h" + +/** + * Parse a data array for ATSC A53 Part 4 Closed Captions and store them in an AVBufferRef. + * + * @param pbuf Pointer to an AVBufferRef to append the closed captions. *pbuf may be NULL, in + * which case a new buffer will be allocated and put in it. + * @param data The data array containing the raw A53 data. + * @param size Size of the data array in bytes. + * + * @return Number of closed captions parsed on success, negative error code on failure. + * If no Closed Captions are parsed, *pbuf is untouched. + */ +int ff_parse_a53_cc(AVBufferRef **pbuf, const uint8_t *data, int size); + +#endif /* AVCODEC_ATSC_A53_H */ From patchwork Mon Aug 10 15:49:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 21583 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 2C2F244A9A5 for ; Mon, 10 Aug 2020 18:50:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 055DB68974F; Mon, 10 Aug 2020 18:50:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6ED086880F0 for ; Mon, 10 Aug 2020 18:50:12 +0300 (EEST) Received: by mail-qk1-f195.google.com with SMTP id 2so8731415qkf.10 for ; Mon, 10 Aug 2020 08:50:12 -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=7z/AlBt5lPIYuXEyQrEMqnbIys/BN2DBObCYZh9PVws=; b=fcQHOLxRlyvbYe9f/iPSCyOI9BpU8+zc12YHrnnYbsRAMyE9chrx7DCWrZzfItrksG PRAm8aPUTcA3Zx0qWfh3NzWYnP+2UPc3QjhVr9O6MrpLU7H+y3/S6LjBWu1O0sFRgtAF E7bbFnelekswHmZpzP4WicLvCdEHfARR9h43bRdIA2u/Jg+UBMzSyIw00I7JjNcYLA5F nWTklWOtX4abCNhYSa6we+WnMZ8UTRVJaRZLfIEWehsiwFhKWiDs1SKTdhMHzKHEQGv/ 8d+7LHYaLZrZH3qOD/TnsBYH/LgEm+KCRqHjFnkqJI7QOLt9yek/ZhljxtPUEdRUur// zB8w== 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=7z/AlBt5lPIYuXEyQrEMqnbIys/BN2DBObCYZh9PVws=; b=fd78+/Mk5OYL86mrlGgsWJ8Qv2DE5dt1HwmE2srCsP8FP8lp2o/wNN5J44tU1cvnSa MloRq6MhnjS/pTW9b8mkVd2/eU49ect0ZRnwGIiqsVbF+vsqdOsU/KYx0swt/9uzU7Lm T+uLulsM1bzWB91PPz764f/B2Ki5uuxT5lfxOBWR96kIiekovqMxRrb/VeOUh+DumvBY WpUu3JiWLAPlFOg6dHgn/eXA+07XZ0j0kdvaMrOlU604ifDVzJnVxeEtBBcQFiDypn00 DW9tpAh/Fw9UtCADW94h+OJbRAvhFfM6rXrDd8PLctpjdCJt+xwTHS0vckLGQMCdHIRG H4gQ== X-Gm-Message-State: AOAM532lrml7DkcmYfdGSCEO/v6Xy+iV8QntMiMZrcxxDV33Vul7vOhz Kzp5AxVAQr1QSJER9KvFlhMwUavl X-Google-Smtp-Source: ABdhPJx6ESUyP7tl9KbA8OjOhW/tEUlQZ0+VeBpQCm8wi/fOqt8bef3sPw5hXr8Ik4GFFdxIW1R4tg== X-Received: by 2002:a37:a293:: with SMTP id l141mr27157805qke.222.1597074610282; Mon, 10 Aug 2020 08:50:10 -0700 (PDT) Received: from localhost.localdomain ([181.23.72.45]) by smtp.gmail.com with ESMTPSA id o15sm13793249qkk.95.2020.08.10.08.50.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 08:50:09 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Aug 2020 12:49:38 -0300 Message-Id: <20200810154941.4988-2-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 2/5] avcodec/libdav1d: add support for A53 Closed Captions 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 | 3 ++- libavcodec/libdav1d.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 37fe01e8be..83f051fdee 100755 --- a/configure +++ b/configure @@ -3211,6 +3211,7 @@ libcelt_decoder_deps="libcelt" libcodec2_decoder_deps="libcodec2" libcodec2_encoder_deps="libcodec2" libdav1d_decoder_deps="libdav1d" +libdav1d_decoder_select="atsc_a53" libdavs2_decoder_deps="libdavs2" libfdk_aac_decoder_deps="libfdk_aac" libfdk_aac_encoder_deps="libfdk_aac" @@ -6328,7 +6329,7 @@ enabled libcelt && require libcelt celt/celt.h celt_decode -lcelt0 && die "ERROR: libcelt must be installed and version must be >= 0.11.0."; } enabled libcaca && require_pkg_config libcaca caca caca.h caca_create_canvas enabled libcodec2 && require libcodec2 codec2/codec2.h codec2_create -lcodec2 -enabled libdav1d && require_pkg_config libdav1d "dav1d >= 0.4.0" "dav1d/dav1d.h" dav1d_version +enabled libdav1d && require_pkg_config libdav1d "dav1d >= 0.5.0" "dav1d/dav1d.h" dav1d_version enabled libdavs2 && require_pkg_config libdavs2 "davs2 >= 1.6.0" davs2.h davs2_decoder_open enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new enabled libdrm && require_pkg_config libdrm libdrm xf86drm.h drmGetVersion diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 132d344296..fd801c6fd5 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -26,7 +26,9 @@ #include "libavutil/imgutils.h" #include "libavutil/opt.h" +#include "atsc_a53.h" #include "avcodec.h" +#include "bytestream.h" #include "decode.h" #include "internal.h" @@ -364,6 +366,34 @@ FF_ENABLE_DEPRECATION_WARNINGS light->MaxCLL = p->content_light->max_content_light_level; light->MaxFALL = p->content_light->max_frame_average_light_level; } + if (p->itut_t35) { + GetByteContext gb; + unsigned int user_identifier; + + bytestream2_init(&gb, p->itut_t35->payload, p->itut_t35->payload_size); + bytestream2_skip(&gb, 1); // terminal provider code + bytestream2_skip(&gb, 1); // terminal provider oriented code + user_identifier = bytestream2_get_be32(&gb); + switch (user_identifier) { + case MKBETAG('G', 'A', '9', '4'): { // closed captions + AVBufferRef *buf = NULL; + + res = ff_parse_a53_cc(&buf, gb.buffer, bytestream2_get_bytes_left(&gb)); + if (res < 0) + goto fail; + if (!res) + break; + + if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, buf)) + av_buffer_unref(&buf); + + c->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; + break; + } + default: // ignore unsupported identifiers + break; + } + } res = 0; fail: From patchwork Mon Aug 10 15:49:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 21584 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 095BD44A9A5 for ; Mon, 10 Aug 2020 18:50:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC76E6882E8; Mon, 10 Aug 2020 18:50:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 200A468A0FA for ; Mon, 10 Aug 2020 18:50:14 +0300 (EEST) Received: by mail-qk1-f178.google.com with SMTP id p4so8777943qkf.0 for ; Mon, 10 Aug 2020 08:50:14 -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=LWYu4KcHTIeXVwgD+BRUlv/5pd4mJnjF2iWwFC00htc=; b=rhA6m7dcYzde4rNY9HRVg6/sT2KTKndUhrEEDqqkaI/TLPtkYMoc0KanwBI5zrSXhn ivevH06CMefKro2SYHenF9KQRJipcRLXvGxLHptdCD3QvJHX0qHkOgWXoXxZDd/w56bz /II+EnoztY8cedpzGIEAIuEP5CtSxal2TqQ+EehXIHyx7dlo92NKJx34nrC/H1ZRlKi4 4PKY+s7ZquN9nuW074laRbfBt++EbU2UY8aIOARipXRxv5ps0bIs/pNWn6sdMyDVyPO3 MZv6JmrIXiCCH7ev8g/GUi+j7W0fVjrKMjX3KLh2NOJuqCNSGlraYXOt4NhZDG78UnMA AAuw== 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=LWYu4KcHTIeXVwgD+BRUlv/5pd4mJnjF2iWwFC00htc=; b=pCcPV2wVDJFIBZ8yMmmtYD73Jr4hNvQz/BNA8MjCTzinMvky8DBMsItXp2QODBnMnT 1NWKwnUl/GysjKKqWBLulYnkuIchlL//AW5BeePtC5LmII0lhjeBQuKHOVIAwc5oNpKU VJYQMRIZlrVzi48vjXYWQD8UszY7cbGSRSALEUp3i/+HePfyZ03n8GbpOkj1zvY97EvU n1UmMMyL6QphtxILl6r+Ejyb0FZTtQ89F25CpPKTSpgJDxNiPc/QOZYaKxjuTcsgrCYv 9YERMs6tKyInM6Enk1tYX3heoM72lFUYo7K3BSbdZzGw292u0lHZsWkX+zKHZf5Bumv7 o1Mg== X-Gm-Message-State: AOAM533LlYG8nHtuGsSK+p0pMzfAZrD6eAxTZLGjymx8DEdR6yGWUPSG lzXTJxmchg/prm+5IbPbI5IRV43U X-Google-Smtp-Source: ABdhPJyB+nOwX4/njv5sjXkeve4Z402/0i9UCjNMV7JaSrhzeHgY3TgsVEd3kSX8Y8kWcF9b4QDE3w== X-Received: by 2002:a05:620a:144e:: with SMTP id i14mr26009763qkl.453.1597074612388; Mon, 10 Aug 2020 08:50:12 -0700 (PDT) Received: from localhost.localdomain ([181.23.72.45]) by smtp.gmail.com with ESMTPSA id o15sm13793249qkk.95.2020.08.10.08.50.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 08:50:11 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Aug 2020 12:49:39 -0300 Message-Id: <20200810154941.4988-3-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 3/5] avcodec/h264_sei: use ff_parse_a53_cc() to parse A53 Closed Captions 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 | 2 +- libavcodec/h264_sei.c | 48 ++----------------------------------------- 2 files changed, 3 insertions(+), 47 deletions(-) diff --git a/configure b/configure index 83f051fdee..5fd966035f 100755 --- a/configure +++ b/configure @@ -2738,7 +2738,7 @@ h263_encoder_select="h263dsp mpegvideoenc" h263i_decoder_select="h263_decoder" h263p_decoder_select="h263_decoder" h263p_encoder_select="h263_encoder" -h264_decoder_select="cabac golomb h264chroma h264dsp h264parse h264pred h264qpel videodsp" +h264_decoder_select="atsc_a53 cabac golomb h264chroma h264dsp h264parse h264pred h264qpel videodsp" h264_decoder_suggest="error_resilience" hap_decoder_select="snappy texturedsp" hap_encoder_deps="libsnappy" diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 7b8e6bd7ba..669560ae5f 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -25,6 +25,7 @@ * @author Michael Niedermayer */ +#include "atsc_a53.h" #include "avcodec.h" #include "get_bits.h" #include "golomb.h" @@ -173,55 +174,10 @@ static int decode_registered_user_data_closed_caption(H264SEIA53Caption *h, GetBitContext *gb, void *logctx, int size) { - int flag; - int user_data_type_code; - int cc_count; - if (size < 3) return AVERROR(EINVAL); - user_data_type_code = get_bits(gb, 8); - if (user_data_type_code == 0x3) { - skip_bits(gb, 1); // reserved - - flag = get_bits(gb, 1); // process_cc_data_flag - if (flag) { - skip_bits(gb, 1); // zero bit - cc_count = get_bits(gb, 5); - skip_bits(gb, 8); // reserved - size -= 2; - - if (cc_count && size >= cc_count * 3) { - int old_size = h->buf_ref ? h->buf_ref->size : 0; - const uint64_t new_size = (old_size + cc_count - * UINT64_C(3)); - int i, ret; - - if (new_size > INT_MAX) - return AVERROR(EINVAL); - - /* Allow merging of the cc data from two fields. */ - ret = av_buffer_realloc(&h->buf_ref, new_size); - if (ret < 0) - return ret; - - /* Use of av_buffer_realloc assumes buffer is writeable */ - for (i = 0; i < cc_count; i++) { - h->buf_ref->data[old_size++] = get_bits(gb, 8); - h->buf_ref->data[old_size++] = get_bits(gb, 8); - h->buf_ref->data[old_size++] = get_bits(gb, 8); - } - - skip_bits(gb, 8); // marker_bits - } - } - } else { - int i; - for (i = 0; i < size - 1; i++) - skip_bits(gb, 8); - } - - return 0; + return ff_parse_a53_cc(&h->buf_ref, gb->buffer + get_bits_count(gb) / 8, size); } static int decode_registered_user_data(H264SEIContext *h, GetBitContext *gb, From patchwork Mon Aug 10 15:49:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 21585 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 CB7C844A9A5 for ; Mon, 10 Aug 2020 18:50:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B45F468AAF6; Mon, 10 Aug 2020 18:50:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9DD0368AAF6 for ; Mon, 10 Aug 2020 18:50:15 +0300 (EEST) Received: by mail-qk1-f180.google.com with SMTP id m7so8720546qki.12 for ; Mon, 10 Aug 2020 08:50:15 -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=cUVb2zOU8C3L8CRWud5dQMBwcv17HoXtOqqln/W67DY=; b=TSt5ZNDZy6gEAtXi/M6BitvhW1dVE+mlY6p3cwPNgCxlSWXB3n/RSTdN9gY9a/qCem EQcRPTo8OmBfJaL4QBninVWRy+WSW74AyvjB7GuyI8iv+HDeRUntVoRBi8hezZvvhbNi 68LPn+leWMwdN3kM30GeOyQkEJFDtvzN6SuTmy+lpucxI4lFZgCTtjCgzkklssdL6QRe CDILqiHHgJFHgLxDSvLezHrGttp6nF7nLzGx3gZPj1mqbKce7a5zQrqOlTZIGdnSqqe1 xUomv6IXdUqyLU1+PHOTgK+59JD62zCsxMODMJIUPPDhh2rF9ysjDCqiULIHXjKO3dr2 s66w== 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=cUVb2zOU8C3L8CRWud5dQMBwcv17HoXtOqqln/W67DY=; b=n56YeTdg8wkbs4DBz6wxNA4zSb3zF/VaUUIzcfyU5OxpZyE2cyFweSneERwUZqplAd NVxB5DmRgvxrcsJDKkQXs8DXfpgZjTF+yXPOjNGyvFYIDgGvsdUrn0X4pLsLOK7EuyOr kLwFvXuZvrZFSbcpjs343/qdmIa0zMTYNRTxisdvLEatUjN/yhsBOl2Bj00ZqXV6X/sb MfyP1I5Azw4cyr5dkGfq3f3g6Ml07eU/XCMSGp6cXxXcXgFc0sG93kC8LrImSRZd082k JwG/AG+1Aol+aVv6bzwbpbkCV5ZbQzD7t90kRV7hVqZK+c619H4feKkNwHX1xBnFXpU/ 14rw== X-Gm-Message-State: AOAM5307lwtwGy3wyMGETq7vYnaolFA3NvryuRdf4OUTgNYCRYmlYIZV BQ2CKlUzlOt87fg0PQKyVDLLlrP+ X-Google-Smtp-Source: ABdhPJxgS1/hEBKNji7C28VO0M7xo6HhDRSz/GDIsFgu0q6bFAqO4YdlbTKq4VwQuxGWLgB1V4naig== X-Received: by 2002:a05:620a:13cf:: with SMTP id g15mr25247360qkl.48.1597074613836; Mon, 10 Aug 2020 08:50:13 -0700 (PDT) Received: from localhost.localdomain ([181.23.72.45]) by smtp.gmail.com with ESMTPSA id o15sm13793249qkk.95.2020.08.10.08.50.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 08:50:13 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Aug 2020 12:49:40 -0300 Message-Id: <20200810154941.4988-4-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 4/5] avcodec/hevc_sei: use ff_parse_a53_cc() to parse A53 Closed Captions 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 | 2 +- libavcodec/hevc_sei.c | 49 +++++++------------------------------------ 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/configure b/configure index 5fd966035f..762e74a8ab 100755 --- a/configure +++ b/configure @@ -2743,7 +2743,7 @@ h264_decoder_suggest="error_resilience" hap_decoder_select="snappy texturedsp" hap_encoder_deps="libsnappy" hap_encoder_select="texturedspenc" -hevc_decoder_select="bswapdsp cabac golomb hevcparse videodsp" +hevc_decoder_select="atsc_a53 bswapdsp cabac golomb hevcparse videodsp" huffyuv_decoder_select="bswapdsp huffyuvdsp llviddsp" huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp llvidencdsp" hymt_decoder_select="huffyuv_decoder" diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index a4ec65dc1a..06e7a3a10c 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -22,6 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "atsc_a53.h" #include "golomb.h" #include "hevc_ps.h" #include "hevc_sei.h" @@ -164,51 +165,17 @@ static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, const HEVCPa static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetBitContext *gb, int size) { - int flag; - int user_data_type_code; - int cc_count; + int ret; if (size < 3) return AVERROR(EINVAL); - user_data_type_code = get_bits(gb, 8); - if (user_data_type_code == 0x3) { - skip_bits(gb, 1); // reserved - - flag = get_bits(gb, 1); // process_cc_data_flag - if (flag) { - skip_bits(gb, 1); - cc_count = get_bits(gb, 5); - skip_bits(gb, 8); // reserved - size -= 2; - - if (cc_count && size >= cc_count * 3) { - int old_size = s->buf_ref ? s->buf_ref->size : 0; - const uint64_t new_size = (old_size + cc_count - * UINT64_C(3)); - int i, ret; - - if (new_size > INT_MAX) - return AVERROR(EINVAL); - - /* Allow merging of the cc data from two fields. */ - ret = av_buffer_realloc(&s->buf_ref, new_size); - if (ret < 0) - return ret; - - for (i = 0; i < cc_count; i++) { - s->buf_ref->data[old_size++] = get_bits(gb, 8); - s->buf_ref->data[old_size++] = get_bits(gb, 8); - s->buf_ref->data[old_size++] = get_bits(gb, 8); - } - skip_bits(gb, 8); // marker_bits - } - } - } else { - int i; - for (i = 0; i < size - 1; i++) - skip_bits(gb, 8); - } + ret = ff_parse_a53_cc(&s->buf_ref, gb->buffer + get_bits_count(gb) / 8, size); + + if (ret < 0) + return ret; + + skip_bits_long(gb, size * 8); return 0; } 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