From patchwork Fri Jan 1 21:35:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 24756 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 A9C0144B645 for ; Fri, 1 Jan 2021 23:45:59 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 86F0568A9AA; Fri, 1 Jan 2021 23:45:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA7C068A817 for ; Fri, 1 Jan 2021 23:45:58 +0200 (EET) Received: by mail-wm1-f53.google.com with SMTP id 190so9905081wmz.0 for ; Fri, 01 Jan 2021 13:45:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wxZfjziJjWCoPwBEZPWE89U269aeQ/92IHywIpzet6k=; b=GEriUbKtMDQCyeQ5hVH3Uyc/nZ7Mop69K9MAVga79Qo0l8iqQswdaZnBrYAqIjVd4T GA3JbnbipGfGzllbsbUreAHjsZBWpvGHQcz7KSMwCTdGy9ONQlu4OzMG9KcNW+GjTnyC ZU6N0fG2AJ2R5JWnLei5WfAMyVjLlcfxr202qISkDEFEiXNdUE1dkkkcvSyFv1wKeNL+ OiarlejR8SIuKchLFI/VT4Vc26PVW1pDs3zntyMOQ79T4daMaaY5pGuvnZSLC86GL5uH z/WvCYh3BBkD+VfvJ+0K+CnB1wbcdjiinfk2/b0wshImOp/d026+uK6orYQvmpS4cZy1 PuYw== 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=wxZfjziJjWCoPwBEZPWE89U269aeQ/92IHywIpzet6k=; b=cBf5+rXmi+vxa4RRgprd41m3j0MPr7vGhlvpIbe1lQDxu2TCb9+LPnjQfzH39DIAYu RIOLw00yh1dOTHxI1R5+bwk6nxTJr+8GzPjpPR7I6QXCbsYA4XOMC6dmzK/CuuWFN1ht fMhxB6Iu1ie+GaXltFspFZ5kFHLKjb5k1/0JE75c9yAT9k9z30KNvUJZjXRclII8Ib2P xw8baBuoWiTBbYElf4xdkPaY9V9nES7t7k4h658mJ2SjEXvL1/R4eObXfZ9T3AN1f/uL 2JZbXGi39ueBcH9vabJS+B6fP1HX4e4WyZC8O49tJvIkOrtUmwI64kTVC2RIKwrYbnTu IG2g== X-Gm-Message-State: AOAM531ILOWKrAQzOmRcl3DBJk0mxmfg5ZN4ihufY9T2xRLBuJUQJDs4 mr42O608G5gtvavjw0a/IhRKQobDMALwtw== X-Google-Smtp-Source: ABdhPJxfyo2LRoczUbKyN7GmlNzD/qt0db4Lmq5bGs4vRzKaBk4Ylv/hCYHNotmsfonC8gQdIvCMPA== X-Received: by 2002:a7b:c7d3:: with SMTP id z19mr17297697wmk.31.1609537071025; Fri, 01 Jan 2021 13:37:51 -0800 (PST) Received: from localhost.localdomain (cpc91226-cmbg18-2-0-cust7.5-4.cable.virginm.net. [82.0.29.8]) by smtp.gmail.com with ESMTPSA id v20sm18784595wml.34.2021.01.01.13.37.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jan 2021 13:37:50 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Jan 2021 21:35:12 +0000 Message-Id: <20210101213537.169546-3-sw@jkqxz.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210101213537.169546-1-sw@jkqxz.net> References: <20210101213537.169546-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/27] h264_metadata_bsf: Move SEI user data parsing to init time 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" --- libavcodec/h264_metadata_bsf.c | 91 ++++++++++++++++------------------ 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c index d7cf58095b..f39e649ac6 100644 --- a/libavcodec/h264_metadata_bsf.c +++ b/libavcodec/h264_metadata_bsf.c @@ -78,6 +78,7 @@ typedef struct H264MetadataContext { int crop_bottom; const char *sei_user_data; + H264RawSEIPayload sei_user_data_payload; int delete_filler; @@ -413,54 +414,10 @@ 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, - }; - SEIRawUserDataUnregistered *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(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); + err = ff_cbs_h264_add_sei_message(au, &ctx->sei_user_data_payload); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to add user data SEI " + "message to access unit.\n"); goto fail; } } @@ -627,6 +584,44 @@ static int h264_metadata_init(AVBSFContext *bsf) CodedBitstreamFragment *au = &ctx->access_unit; int err, i; + if (ctx->sei_user_data) { + SEIRawUserDataUnregistered *udu = + &ctx->sei_user_data_payload.payload.user_data_unregistered; + int j; + + ctx->sei_user_data_payload.payload_type = + H264_SEI_TYPE_USER_DATA_UNREGISTERED; + + // Parse UUID. It must be a hex string of length 32, possibly + // containing '-'s between hex digits (which we ignore). + for (i = j = 0; j < 32 && i < 64 && 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 { + break; + } + 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] == '+') { + udu->data = (uint8_t*)ctx->sei_user_data + i + 1; + udu->data_length = strlen(udu->data) + 1; + } else { + av_log(bsf, AV_LOG_ERROR, "Invalid user data: " + "must be \"UUID+string\".\n"); + err = AVERROR(EINVAL); + goto fail; + } + } + err = ff_cbs_init(&ctx->input, AV_CODEC_ID_H264, bsf); if (err < 0) return err;