From patchwork Tue Mar 17 10:54:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 18259 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 9B37A44B45D for ; Tue, 17 Mar 2020 12:54:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7626168B5DC; Tue, 17 Mar 2020 12:54:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A776468B5CB for ; Tue, 17 Mar 2020 12:54:20 +0200 (EET) Received: by mail-pg1-f178.google.com with SMTP id 7so11537111pgr.2 for ; Tue, 17 Mar 2020 03:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LHJ3Kovsjvf630Yrs9Wft+vLKc46j6DMBzpVBGHhsno=; b=c+ZULhbaAHw6HYcYkWoeLRsaNaiR5SPcnXW7Tz1U9FMHtzmeHBDZDvgYAUAGhSqKJp APEDuKKBkDzFyOnMQFqT0WOTsU1/10xpdXJGoCZxQ/hxjPoWX25OmEx9HNdmd/L0XuPb 7ICea9sVX8k/89vcsWdXKZAsrJEWHSZTyrXDrLetvIswzTR7PCYpVA+oonq87YYwJvlX IrwKetMncZlc/qTD4MTek6Tn65EHsKq8YlPVuqqhmTJxtkMLLPxHkyNv7j90yXJPYluu gfudFpZ6Lzn8D5+AS3+M8pfWgLqgEfiPa9DbHI+Ylqq2XrAsBxtW1MNG9ncKk1Ocr2Sh AeDg== 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=LHJ3Kovsjvf630Yrs9Wft+vLKc46j6DMBzpVBGHhsno=; b=oCfUxqlMlDbzJP7gIj7neMrY1RneO+MPz2pCRsYHgvOwv6HBpcANeU6eS3wutcTDf4 i2449pXw10PHVNTPbbkrYP/olb+QpS8ZUuyvGgJNM4Krk8mdsJa5lSsA/ByxrwtNLcHS LvTr8Mq2+kKHGH385GlpA0mxmfICKBf1EHFPupKD6onuE7UREfcPkgGtr3XTxAmix78k DiFFzxTSCg7/zTlTaFVs4nnBXlAvK9uNF9+gp4L0OjYadIVkzYuW+s4f+ZkSPfAc1e7y PKlUC3F3X9KIdd/V0gdX1jXlhFqqC63gIMumqZ4K9Bn/KeQ9DrKoEZn/JvBADJqyuIDG JjFg== X-Gm-Message-State: ANhLgQ2DnoRHm4tPp4fpaUsJ2tqDt89rrG7/SS9vG/ZocMovdgDzkHrx Ds5d1Nh0+URXhCPTP4WqD5Wbfrez X-Google-Smtp-Source: ADFU+vu7rJc8jumBJZWPl4oOUH2T8pwH6JKxhwiF4vBWh+MhtTwaP3oJX8nk9rH+/cvV9MwasLXFhA== X-Received: by 2002:aa7:824e:: with SMTP id e14mr4722811pfn.18.1584442458680; Tue, 17 Mar 2020 03:54:18 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id 6sm2752224pfx.69.2020.03.17.03.54.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Mar 2020 03:54:18 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Mar 2020 18:54:07 +0800 Message-Id: <20200317105409.2795-2-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20200317105409.2795-1-lance.lmwang@gmail.com> References: <20200317105409.2795-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v9 2/4] avcodec/hevc_sei: add support for user data unregistered SEI message 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavcodec/hevc_sei.c | 31 +++++++++++++++++++++++++++++++ libavcodec/hevc_sei.h | 6 ++++++ libavcodec/hevcdec.c | 14 ++++++++++++++ tests/ref/fate/hevc-monochrome-crop | 3 +++ 4 files changed, 54 insertions(+) diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index 6057069..e3d6bc9 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -213,6 +213,30 @@ static int decode_registered_user_data_closed_caption(HEVCSEIA53Caption *s, GetB return 0; } +static int decode_nal_sei_user_data_unregistered(HEVCSEIUnregistered *s, GetBitContext *gb, + int size) +{ + AVBufferRef *buf_ref, **tmp; + + if (size < 16) + return AVERROR(EINVAL); + + tmp = av_realloc_array(s->buf_ref, s->nb_buf_ref + 1, sizeof(*s->buf_ref)); + if (!tmp) + return AVERROR(ENOMEM); + s->buf_ref = tmp; + + buf_ref = av_buffer_alloc(size); + if (!buf_ref) + return AVERROR(ENOMEM); + + for (int i = 0; i < size; i++) + buf_ref->data[i] = get_bits(gb, 8); + s->buf_ref[s->nb_buf_ref++] = buf_ref; + + return 0; +} + static int decode_nal_sei_user_data_registered_itu_t_t35(HEVCSEI *s, GetBitContext *gb, int size) { @@ -300,6 +324,8 @@ static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s, return decode_nal_sei_active_parameter_sets(s, gb, logctx); case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35: return decode_nal_sei_user_data_registered_itu_t_t35(s, gb, size); + case HEVC_SEI_TYPE_USER_DATA_UNREGISTERED: + return decode_nal_sei_user_data_unregistered(&s->unregistered, gb, size); case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: return decode_nal_sei_alternative_transfer(&s->alternative_transfer, gb); default: @@ -371,4 +397,9 @@ int ff_hevc_decode_nal_sei(GetBitContext *gb, void *logctx, HEVCSEI *s, void ff_hevc_reset_sei(HEVCSEI *s) { av_buffer_unref(&s->a53_caption.buf_ref); + + for (int i = 0; i < s->unregistered.nb_buf_ref; i++) + av_buffer_unref(&s->unregistered.buf_ref[i]); + s->unregistered.nb_buf_ref = 0; + av_freep(&s->unregistered.buf_ref); } diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h index a44ccca..3618d16 100644 --- a/libavcodec/hevc_sei.h +++ b/libavcodec/hevc_sei.h @@ -91,6 +91,11 @@ typedef struct HEVCSEIA53Caption { AVBufferRef *buf_ref; } HEVCSEIA53Caption; +typedef struct HEVCSEIUnregistered { + AVBufferRef **buf_ref; + int nb_buf_ref; +} HEVCSEIUnregistered; + typedef struct HEVCSEIMasteringDisplay { int present; uint16_t display_primaries[3][2]; @@ -116,6 +121,7 @@ typedef struct HEVCSEI { HEVCSEIDisplayOrientation display_orientation; HEVCSEIPictureTiming picture_timing; HEVCSEIA53Caption a53_caption; + HEVCSEIUnregistered unregistered; HEVCSEIMasteringDisplay mastering_display; HEVCSEIContentLight content_light; int active_seq_parameter_set_id; diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 7448be4..8909aca 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2795,6 +2795,20 @@ static int set_side_data(HEVCContext *s) s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } + for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) { + HEVCSEIUnregistered *unreg = &s->sei.unregistered; + + if (unreg->buf_ref[i]) { + AVFrameSideData *sd = av_frame_new_side_data_from_buf(out, + AV_FRAME_DATA_SEI_UNREGISTERED, + unreg->buf_ref[i]); + if (!sd) + av_buffer_unref(&unreg->buf_ref[i]); + unreg->buf_ref[i] = NULL; + } + } + s->sei.unregistered.nb_buf_ref = 0; + return 0; } diff --git a/tests/ref/fate/hevc-monochrome-crop b/tests/ref/fate/hevc-monochrome-crop index 4e45412..384404d 100644 --- a/tests/ref/fate/hevc-monochrome-crop +++ b/tests/ref/fate/hevc-monochrome-crop @@ -1,6 +1,9 @@ [FRAME] width=384 height=240 +[SIDE_DATA] +side_data_type=H.26[45] User Data Unregistered SEI message +[/SIDE_DATA] [/FRAME] [STREAM] width=384