From patchwork Wed Aug 12 23:20:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21619 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 8DFD3448961 for ; Thu, 13 Aug 2020 02:25:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6339868B4B2; Thu, 13 Aug 2020 02:25:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C7CD680A1A for ; Thu, 13 Aug 2020 02:25:08 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id z18so3535285wrm.12 for ; Wed, 12 Aug 2020 16:25:08 -0700 (PDT) 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=bG1lp0YFOFp7sgNPSUHrvgy6PU0kFJWELLZG1Cs+6Bo=; b=AvmwAjraEE9roKGAVgZwlBztA1D41BNFUjPemPFCM5an/QboAuHIEM4UPnkFcCUivL 96tfPLckFPSMfpzPoNgxbpYyONzTKnHQiJyEOUywj81hqlLbDPMR9mDXHT1yMgfOMLgt v5q9aPC4XHIVjQd0ActOCADHN0zbRjKd2jOAXp8b3jC8FEcqy/XILsIIVzlUh81eo0aq P8mGQq8619fUhpDwhxBC/CwBK7b0Sx6GaRfnRBhb+/BOTNSzcp6akrAFxC/WTlOZw9ii PhuHtQFQRFucYsFr4eI95kj4qOg4GsrAeVdfSkP+QNN5qCGrSoMqyE+TIthieGATB5Xr MCFQ== 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=bG1lp0YFOFp7sgNPSUHrvgy6PU0kFJWELLZG1Cs+6Bo=; b=AE4nn+0sv6493vnD5M2BLvnwm7YXeczLnxa/Vx6W3dWJOBG32UGLEUGUQiQQ9N+Fjw 90gQbrVFE+y9d354bb3mpq8sKSspmUdyfezC8JB5kA6puVn7SlB6+YPkPlLr2oxW8oyt XIlNml5e8YsY7KQGVer+zACpwNvGST5SJnoz5mECxw9u9U4W4fLFtU5gSgf113LcvSAd PHvDw4pFrzSAPIsWe+p97Cz2jiA78ki4O7aHjYCogUB5bdiOXdVK2+OEKFNGQchQbr02 ZhsEVT4gTAVhRF+HXsAAmfA2Ehv514C2Mnye/Cv26bKhZw+LD0B5GQ1ZTaHkKCuvEuWQ F+uQ== X-Gm-Message-State: AOAM531EWL/vpAkuCOplxLRqGfxjuYJwTIlOw6ymj6U1Hvt8gKTLbIeJ OHa50vplKh2MnHUp0b3O7VDwOYuZPc8= X-Google-Smtp-Source: ABdhPJxTh8rTVNwDCMNMUKuBI5xB2EJaka8Ocgvjx20nUevQRPwLR/kR9MGQaRZTXmdfITcxAaq9Pg== X-Received: by 2002:adf:a1c6:: with SMTP id v6mr1227526wrv.197.1597274707369; Wed, 12 Aug 2020 16:25:07 -0700 (PDT) Received: from localhost.localdomain (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id p25sm6019534wma.39.2020.08.12.16.25.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 16:25:06 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Aug 2020 00:20:53 +0100 Message-Id: <20200812232054.451992-1-sw@jkqxz.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <38a52214-4fd6-b465-4029-0eba332ba8c5@jkqxz.net> References: <38a52214-4fd6-b465-4029-0eba332ba8c5@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 21.1/23] h264_metadata: 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 eb1503159b..e59b5b8369 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, - }; - 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(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) { + H264RawSEIUserDataUnregistered *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;