From patchwork Thu Jul 9 19:20:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20938 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 1761644B0C4 for ; Thu, 9 Jul 2020 22:20:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ED52068B615; Thu, 9 Jul 2020 22:20:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 08E9468B56F for ; Thu, 9 Jul 2020 22:20:46 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id a6so3556206wrm.4 for ; Thu, 09 Jul 2020 12:20:46 -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 :mime-version:content-transfer-encoding; bh=8O6FbEHXMM6O5BXXne0/I2m5O7O831Q14P7ayGF5rKU=; b=WkxRACf5AaYbubfpyPqpDrXh03d1WI4ynac7nHr/HF9K9+n8wRkbesk/Ozpt4rv6+R C+ihwg8iUXVln36wux9miVfSbVfFIrcM4UDuiqq+PaUXUhi1xPy+8nxc/kJ8f2YYwnUi z9LOJMtMleKQoO7YFC30regJoD2eo9b0oSj8/toZkfOVc9f9aGbrGk/5SB3+OtlU6yKT cYPedIJuS+lYlaZNVp6o4vULGcSVOA50D3RoxyQL2wAr+FutSRHrdUSiN8koivcY51tL IFZwqgx0VwP4iB/GjP/XFv/M387UYxIQ0qJwb91xrdT5Kbxc59NnwuTTYpIJ9iQ5tYLk GS9g== 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:mime-version:content-transfer-encoding; bh=8O6FbEHXMM6O5BXXne0/I2m5O7O831Q14P7ayGF5rKU=; b=lMnC0xdDLlTMGXx65a6XIoFUl8yY0iX+iNY3nbbUTL2THMoegJBdRLejkMxkaVKaoc RSHtvumCbKxjjgY0/Z6Ysajr7jYa+HArOmUQOZSEc8jVIBDrvyzjV16TnZP1In1/OIah Ba+s0c4bJGAAMt991MUFNHpIgtJGunaVggOM8babqJi6CnfWjo1WdU/RTo9ZJ4JwgMNm +aRSg6JOKZyzN4gNK8d6w+fzIBiWOE59MFPqFBUnSU9GHfE0lJHyP614wyVtX+ZRHkVS c6ufx47WzTB9uQAO4hnh983J9XSROFm1K2Qpa6MdIV2rtx2Ug01J6DIbwznn3nimi41N C2XQ== X-Gm-Message-State: AOAM532k26GnT7SbS6x1URVCNIroUOejbESb7Y+tM2982GUhyUkWz81W fdvFZA1BKKTz2k7Q2XvaCQ3uiI86 X-Google-Smtp-Source: ABdhPJwqd/SBDLWp7pMWdpLK0S1Nxybqx3Vk5xF65bJuZbjnJcoY36C/GWaVF0kKZRwgds+dko1xFA== X-Received: by 2002:adf:dd8d:: with SMTP id x13mr63538482wrl.362.1594322445149; Thu, 09 Jul 2020 12:20:45 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id p25sm5485330wmg.39.2020.07.09.12.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 12:20:44 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jul 2020 21:20:22 +0200 Message-Id: <20200709192022.9412-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200709103542.19909-1-andreas.rheinhardt@gmail.com> References: <20200709103542.19909-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/17] avformat/avc: Don't discard SPS extensions for some profiles 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" For some profiles, the AVCDecoderConfigurationRecord contains an array containing all the SPS Extension NAL units; for the other profiles, these NAL units should be put into the SPS array. Yet the latter hasn't been done. This commit implements it. Signed-off-by: Andreas Rheinhardt --- Honestly, I have no sample containing an SPS extension, so this is untested. Btw: The spec is quiet on the order in the SPS array in this case. Should it be all SPS first, then the extensions or should the it be that an SPS is immediately followed by its extension (if present) followed by the next SPS? All it says is that they should be placed in the SPS array. libavformat/avc.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/libavformat/avc.c b/libavformat/avc.c index 0f43b295a4..84a55fdc98 100644 --- a/libavformat/avc.c +++ b/libavformat/avc.c @@ -185,13 +185,13 @@ static void write_array(AVIOContext *pb, const uint8_t *const *ps, int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len) { const uint8_t *nal, *nal_end, *end; - int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0; - const uint8_t *sps[H264_MAX_SPS_COUNT]; + int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0, ext_in_sps_array; + const uint8_t *sps[2 * H264_MAX_SPS_COUNT]; const uint8_t *pps[H264_MAX_PPS_COUNT]; - const uint8_t *sps_ext[H264_MAX_SPS_COUNT]; - uint16_t sps_sizes[H264_MAX_SPS_COUNT] = { 0 }; + uint16_t sps_sizes[2 * H264_MAX_SPS_COUNT] = { 0 }; uint16_t pps_sizes[H264_MAX_PPS_COUNT] = { 0 }; - uint16_t sps_ext_sizes[H264_MAX_SPS_COUNT] = { 0 }; + const uint8_t **const sps_ext = &sps[H264_MAX_SPS_COUNT]; + uint16_t *const sps_ext_sizes = &sps_sizes[H264_MAX_SPS_COUNT]; H264SPS seq; if (len <= 6) @@ -249,8 +249,14 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len) } } - if (!nb_sps || nb_sps == H264_MAX_SPS_COUNT || - !nb_pps || nb_pps == H264_MAX_PPS_COUNT) + if (!nb_sps || !nb_pps) + return AVERROR_INVALIDDATA; + ext_in_sps_array = seq.profile_idc == 66 || + seq.profile_idc == 77 || + seq.profile_idc == 88; + if (ext_in_sps_array) + nb_sps += nb_sps_ext; + if (nb_sps >= H264_MAX_SPS_COUNT || nb_pps >= H264_MAX_PPS_COUNT) return AVERROR_INVALIDDATA; avio_w8(pb, 1); /* version */ @@ -258,10 +264,11 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len) avio_w8(pb, seq.constraint_set_flags); /* profile compat */ avio_w8(pb, seq.level_idc); avio_w8(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ - write_array(pb, sps, sps_sizes, nb_sps, H264_MAX_SPS_COUNT, 0xe0); + write_array(pb, sps, sps_sizes, nb_sps, + H264_MAX_SPS_COUNT * (1 + ext_in_sps_array), 0xe0); write_array(pb, pps, pps_sizes, nb_pps, H264_MAX_PPS_COUNT, 0x00); - if (seq.profile_idc != 66 && seq.profile_idc != 77 && seq.profile_idc != 88) { + if (!ext_in_sps_array) { avio_w8(pb, 0xfc | seq.chroma_format_idc); /* 6 bits reserved (111111) + chroma_format_idc */ avio_w8(pb, 0xf8 | seq.bit_depth_luma_minus8); /* 5 bits reserved (11111) + bit_depth_luma_minus8 */ avio_w8(pb, 0xf8 | seq.bit_depth_chroma_minus8); /* 5 bits reserved (11111) + bit_depth_chroma_minus8 */