From patchwork Fri Aug 17 10:41:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: joshdk@ob-encoder.com X-Patchwork-Id: 10020 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp600837jad; Fri, 17 Aug 2018 03:49:59 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzvvrmuGhxcacmtFAjD5q0EUrOV2NPWOjrXw0JA42AY9VpximPoYZ96NAWHg1vZrvS3XxZq X-Received: by 2002:adf:f74d:: with SMTP id z13-v6mr22064534wrp.85.1534502999501; Fri, 17 Aug 2018 03:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534502999; cv=none; d=google.com; s=arc-20160816; b=ThhRq4ZBFVmMuGfBFKBP1FQdzCX1D+FdRHvrHdiqFKGvq2RZfdGBOdlmNAgdfefnTc 11D8gNK60byi+ZSG4JaMHjhMGEwL5kkr3uZ8teE4msg22h33t4fyYGZcDUkZ3mCrapXF xVABP0pobJ5tE413bN9Cd07GS8EDUANMKqagOFhABvbjOTVWFeg2LiagG9qwseDh4rYH RwNZv3iM09UzUHMNyW/fT/fXKLS8gPP9hZX5ipEy/Qu+Bic4A6hfRMcQYpr5UDKbeUO0 l3bM6NAwM17wsr2MAf6A/ngS++bvIjKgX0Qwrab84oLLWcz3RlSAIj6l95G+0o0CjUqP DS0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=qv8MFDs7cFTdY+5FEoBSImQbaS9EI3McqK2gc3aY8xk=; b=yFbk0pVyj1H34/3/bNSSNudaTvmlJ8ToyR61qg2AxzWjrH80exJSUa6OONh97wV0AJ Z2NCiC+cp8O3Xountf3JS4R19gLXu0F7Ryvzpk6udSL73IdvWEnK9YY/VPPnVno3jd5e anv8oAAJQ1OxQmiPwPfB/l3FSjNfb7iaLTmGTljADNI5qfIDMgKQKWMzH19m78DaItWY pQQbS8rSJdqsB1WkFJhWgghAGSBMsBaxTBqf7x9zrCXYbjLzBpbmKibXCer5raqJcWhX INa9VMPRg6tcqE9lOyVrn3iZ7YBevx3k24c2egbWydmY6lK7ZN+85NOxDaRX7EsXSOvZ r3Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ob-encoder-com.20150623.gappssmtp.com header.s=20150623 header.b=HEWNA+cD; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f2-v6si1205092wri.121.2018.08.17.03.49.58; Fri, 17 Aug 2018 03:49:59 -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=@ob-encoder-com.20150623.gappssmtp.com header.s=20150623 header.b=HEWNA+cD; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A2E91689F46; Fri, 17 Aug 2018 13:49:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4A05F68999A for ; Fri, 17 Aug 2018 13:49:25 +0300 (EEST) Received: by mail-wm0-f47.google.com with SMTP id o11-v6so7135117wmh.2 for ; Fri, 17 Aug 2018 03:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ob-encoder-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iF2FCUFhOQm8Rj0YVOz3i084OZu5TrIL9v0HG8zjVlA=; b=HEWNA+cDODiMlXvZ+ccmKngb2/E+1k8n4sZZEGgvLI4Uuhs6plz+n1Io5iUPwnjl7l +3NBZiI4ecHUo4Y2xfQaoaSnR45i5YLGPyUnA6oe7exiKrPGJXnayZiYO5f3riIidp0u plo9lykCkTDH+RV0prOh4Fu9xoTEXTzdWV7vQbVyQ1Qc/oeyNMwE6vi0PPdI/nc2gZJL rEgv47UrlZVDI27y+nZ3NpZJlafYEdB5ME6NC3A6xuHF4jA0B1Cr2KR6dvbWt4ZCwjxC Pmax9UfYP59j0KmBlDPCe9xfxFrq+cVcep+1hlTsRcaMqt+GUQ47xf7mrLQSEVvmBb7f NDvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iF2FCUFhOQm8Rj0YVOz3i084OZu5TrIL9v0HG8zjVlA=; b=Ma4GNuhH85uXw0qza9AIgNJGbDHB3wYX9W/5sgmgQvCn9oX/wyZriXiQ9RUPIY2jGj iMdYmOqCmS5+aeL4H1kDff3pPIBF+uZTOyQmP1vHdg1pn6V8eCkekq81hvIfqTrtlZUC 9+yBfx58fZk9OsUFdp87pQCaAT6tazIXKrgSOF0rXSvTF2k9v/+sVmEMDOISitPAsNSV qfBsCCxLqeqGod8CbGx53PwSLpbi6Oj5P8GiiT7/K+WEYR3GpC8DH8/i+fC98JInlKkK 1dVh7SFPZkVXzCtS+w+NIDtVgdeCEQxz1RaucIYJ0ZDktt626669wo/Zg2F0F/JCHqiw O7Gg== X-Gm-Message-State: AOUpUlEdMxXEsjtyAQlHMN1oet+IopSoXkgLKaD94qaY4XVjS4tFTZNz /4sRU7mRFBbU/yjDMmQFtf0+OzDzzGqRjA== X-Received: by 2002:a1c:e409:: with SMTP id b9-v6mr17571124wmh.34.1534502491172; Fri, 17 Aug 2018 03:41:31 -0700 (PDT) Received: from localhost.localdomain (cpc75394-sotn16-2-0-cust168.15-1.cable.virginm.net. [82.22.8.169]) by smtp.gmail.com with ESMTPSA id q188-v6sm6255887wmd.36.2018.08.17.03.41.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Aug 2018 03:41:30 -0700 (PDT) From: joshdk@ob-encoder.com X-Google-Original-From: joshdk@obe.tv To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 Aug 2018 11:41:29 +0100 Message-Id: <20180817104129.8597-1-joshdk@obe.tv> X-Mailer: git-send-email 2.17.1 In-Reply-To: <190855bf-59b5-6dba-1c23-ed0673b75f2a@gmail.com> References: <190855bf-59b5-6dba-1c23-ed0673b75f2a@gmail.com> Subject: [FFmpeg-devel] [PATCH v2] h264: Support multi-field closed captions by using AVBufferRef and not resetting per field 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 Cc: Josh de Kock , Kieran Kunhya MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Kieran Kunhya Signed-off-by: Josh de Kock --- libavcodec/h264_sei.c | 15 ++++++++------- libavcodec/h264_sei.h | 3 +-- libavcodec/h264_slice.c | 26 ++++++++++++++++++-------- libavcodec/h264dec.c | 5 +++-- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 6499086210..43593d34d2 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -51,8 +51,7 @@ void ff_h264_sei_uninit(H264SEIContext *h) h->display_orientation.present = 0; h->afd.present = 0; - h->a53_caption.a53_caption_size = 0; - av_freep(&h->a53_caption.a53_caption); + av_buffer_unref(&h->a53_caption.buf_ref); } static int decode_picture_timing(H264SEIPictureTiming *h, GetBitContext *gb, @@ -169,7 +168,8 @@ static int decode_registered_user_data_closed_caption(H264SEIA53Caption *h, size -= 2; if (cc_count && size >= cc_count * 3) { - const uint64_t new_size = (h->a53_caption_size + cc_count + 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; @@ -177,14 +177,15 @@ static int decode_registered_user_data_closed_caption(H264SEIA53Caption *h, return AVERROR(EINVAL); /* Allow merging of the cc data from two fields. */ - ret = av_reallocp(&h->a53_caption, new_size); + 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->a53_caption[h->a53_caption_size++] = get_bits(gb, 8); - h->a53_caption[h->a53_caption_size++] = get_bits(gb, 8); - h->a53_caption[h->a53_caption_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); + h->buf_ref->data[old_size++] = get_bits(gb, 8); } skip_bits(gb, 8); // marker_bits diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h index a169a10e49..5b7c8ef9d8 100644 --- a/libavcodec/h264_sei.h +++ b/libavcodec/h264_sei.h @@ -95,8 +95,7 @@ typedef struct H264SEIAFD { } H264SEIAFD; typedef struct H264SEIA53Caption { - int a53_caption_size; - uint8_t *a53_caption; + AVBufferRef *buf_ref; } H264SEIA53Caption; typedef struct H264SEIUnregistered { diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index ede9a1a6ea..f31c9a2579 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -430,6 +430,15 @@ int ff_h264_update_thread_context(AVCodecContext *dst, h->frame_recovered = h1->frame_recovered; + av_buffer_unref(&h->sei.a53_caption.buf_ref); + h->sei.a53_caption.buf_ref = NULL; + + if (h1->sei.a53_caption.buf_ref) { + h->sei.a53_caption.buf_ref = av_buffer_ref(h1->sei.a53_caption.buf_ref); + if (!h->sei.a53_caption.buf_ref) + return AVERROR(ENOMEM); + } + if (!h->cur_pic_ptr) return 0; @@ -1269,15 +1278,16 @@ static int h264_export_frame_props(H264Context *h) } } - if (h->sei.a53_caption.a53_caption) { + if (h->sei.a53_caption.buf_ref) { H264SEIA53Caption *a53 = &h->sei.a53_caption; - AVFrameSideData *sd = av_frame_new_side_data(cur->f, - AV_FRAME_DATA_A53_CC, - a53->a53_caption_size); - if (sd) - memcpy(sd->data, a53->a53_caption, a53->a53_caption_size); - av_freep(&a53->a53_caption); - a53->a53_caption_size = 0; + + AVFrameSideData *sd = av_frame_new_side_data_from_buf(cur->f, AV_FRAME_DATA_A53_CC, av_buffer_ref(a53->buf_ref)); + if (sd) { + av_buffer_unref(&a53->buf_ref); + } else { + return AVERROR(ENOMEM); + } + h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 7494c7a8f2..8d115fa040 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -609,9 +609,10 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) { h->current_slice = 0; - if (!h->first_field) + if (!h->first_field) { h->cur_pic_ptr = NULL; - ff_h264_sei_uninit(&h->sei); + ff_h264_sei_uninit(&h->sei); + } } if (h->nal_length_size == 4) {