From patchwork Tue Jun 9 18:37:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Loman X-Patchwork-Id: 20250 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 3DF0544A355 for ; Tue, 9 Jun 2020 21:37:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 18B3D68B3C7; Tue, 9 Jun 2020 21:37:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.toyon.com (mail.toyon.com [209.203.101.84]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8BA3768B21D for ; Tue, 9 Jun 2020 21:37:40 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=toyon.com; s=default; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Type; bh=DhalTU1gxj8pIn+x+ZzcGuh QIKZvpbNtiHJUxR3j6S8=; b=oQDWyCv3pgZTuYQdIycNCqwNIFmnv3CekErZoAV H4h8pUH9y48+9i1jlGIEkuSC7ZGT/QQewx3jflIfHNc5VOqOBv1HCLOBQxNNZrjP W/mCSbssnRtwGRGqTdV30EtlL7OOyJKJJbGqVU/ITlt7P5JpqDOTAC8qXdZXsEKN 65sE= From: Daniel Loman To: Date: Tue, 9 Jun 2020 11:37:31 -0700 Message-ID: <20200609183731.10599-1-dloman@toyon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] added sei side data 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: Daniel Loman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- Changelog | 1 + libavcodec/avpacket.c | 1 + libavcodec/packet.h | 6 ++++++ libavcodec/version.h | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 711c843b99..631958015a 100644 --- a/Changelog +++ b/Changelog @@ -75,6 +75,7 @@ version : - PFM decoder - dblur video filter - Real War KVAG muxer +- added sei side data field to AVPacket version 4.2: diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 033f2d8f26..a530dc6779 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -395,6 +395,7 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type) case AV_PKT_DATA_A53_CC: return "A53 Closed Captions"; case AV_PKT_DATA_ENCRYPTION_INIT_INFO: return "Encryption initialization data"; case AV_PKT_DATA_ENCRYPTION_INFO: return "Encryption info"; + case AV_PKT_DATA_SEI_USER: return "SEI unregistered data"; case AV_PKT_DATA_AFD: return "Active Format Description data"; case AV_PKT_DATA_PRFT: return "Producer Reference Time"; case AV_PKT_DATA_ICC_PROFILE: return "ICC Profile"; diff --git a/libavcodec/packet.h b/libavcodec/packet.h index 41485f4527..8c62c467dc 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -282,6 +282,12 @@ enum AVPacketSideDataType { */ AV_PKT_DATA_DOVI_CONF, + /** + * This side data contains SEI unregistered Data. + * first 17 bytes are UID and + the rest are non zero terminated fixed length bytes + */ + AV_PKT_DATA_SEI_USER, + /** * The number of side data types. * This is not part of the public API/ABI in the sense that it may diff --git a/libavcodec/version.h b/libavcodec/version.h index 524fbc3b11..4e2cc5db92 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 90 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- 2.17.1 From 136f7ef45be4b76b49038b5914f12d0ba0005cfd Mon Sep 17 00:00:00 2001 From: Daniel Loman Date: Tue, 9 Jun 2020 11:28:18 -0700 Subject: [PATCH 2/2] moved sei side data writing code into seperate function for reuse To: ffmpeg-devel@ffmpeg.org --- libavcodec/h264_metadata_bsf.c | 114 ++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index 99017653d0..24404832e8 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -276,6 +276,63 @@ static int h264_metadata_update_sps(AVBSFContext *bsf, return 0; } +static int write_sei_user_data(AVBSFContext *bsf, const uint8_t *data, int size) +{ + H264MetadataContext *ctx = bsf->priv_data; + CodedBitstreamFragment *au = &ctx->access_unit; + int err = 0, i, j; + + H264RawSEIPayload payload = { + .payload_type = H264_SEI_TYPE_USER_DATA_UNREGISTERED, + }; + H264RawSEIUserDataUnregistered *udu = + &payload.payload.user_data_unregistered; + + for (i = j = 0; j < 32 && data[i]; i++) { + int c, v; + c = data[i]; + if (c == '-') { + continue; + } else if (av_isxdigit(c)) { + c = av_tolower(c); + v = (c <= '9' ? c - '0' : c - 'a' + 10); + } else { + goto invalid_user_data; + } + if (i & 1) + udu->uuid_iso_iec_11578[j / 2] |= v; + else + udu->uuid_iso_iec_11578[j / 2] = v << 4; + ++j; + } + if (j == 32 && data[i] == '+') { + size_t len = size - i - 1; + + udu->data_ref = av_buffer_alloc(len + 1); + if (!udu->data_ref) { + return AVERROR(ENOMEM); + } + + udu->data = udu->data_ref->data; + udu->data_length = len + 1; + memcpy(udu->data, data + i + 1, len + 1); + + err = ff_cbs_h264_add_sei_message(ctx->cbc, au, &payload); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to add user data SEI " + "message to access unit.\n"); + return err; + } + + } else { + invalid_user_data: + av_log(bsf, AV_LOG_ERROR, "Invalid user data: " + "must be \"UUID+string\".\n"); + return AVERROR(EINVAL); + } + return 0; +} + static int h264_metadata_update_side_data(AVBSFContext *bsf, AVPacket *pkt) { H264MetadataContext *ctx = bsf->priv_data; @@ -412,56 +469,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) // Only insert the SEI in access units containing SPSs, and also // unconditionally in the first access unit we ever see. if (ctx->sei_user_data && (has_sps || !ctx->done_first_au)) { - H264RawSEIPayload payload = { - .payload_type = H264_SEI_TYPE_USER_DATA_UNREGISTERED, - }; - H264RawSEIUserDataUnregistered *udu = - &payload.payload.user_data_unregistered; - - for (i = j = 0; j < 32 && ctx->sei_user_data[i]; i++) { - int c, v; - c = ctx->sei_user_data[i]; - if (c == '-') { - continue; - } else if (av_isxdigit(c)) { - c = av_tolower(c); - v = (c <= '9' ? c - '0' : c - 'a' + 10); - } else { - goto invalid_user_data; - } - if (j & 1) - udu->uuid_iso_iec_11578[j / 2] |= v; - else - udu->uuid_iso_iec_11578[j / 2] = v << 4; - ++j; - } - if (j == 32 && ctx->sei_user_data[i] == '+') { - size_t len = strlen(ctx->sei_user_data + i + 1); - - udu->data_ref = av_buffer_alloc(len + 1); - if (!udu->data_ref) { - err = AVERROR(ENOMEM); - goto fail; - } - - udu->data = udu->data_ref->data; - udu->data_length = len + 1; - memcpy(udu->data, ctx->sei_user_data + i + 1, len + 1); - - err = ff_cbs_h264_add_sei_message(ctx->cbc, au, &payload); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to add user data SEI " - "message to access unit.\n"); - goto fail; - } - - } else { - invalid_user_data: - av_log(bsf, AV_LOG_ERROR, "Invalid user data: " - "must be \"UUID+string\".\n"); - err = AVERROR(EINVAL); - goto fail; - } + write_sei_user_data(bsf, ctx->sei_user_data, strlen(ctx->sei_user_data)); } if (ctx->delete_filler) { @@ -604,6 +612,12 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt) } } + uint8_t const *data; + int size; + if (data = av_packet_get_side_data(pkt, AV_PKT_DATA_SEI_USER, &size)) { + write_sei_user_data(bsf, data, size); + } + err = ff_cbs_write_packet(ctx->cbc, pkt, au); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");