From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id B7CFE49FBD for ; Fri, 17 May 2024 13:43:21 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C068F68D2BA; Fri, 17 May 2024 16:43:17 +0300 (EEST) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C64EA68D1C4 for ; Fri, 17 May 2024 16:43:10 +0300 (EEST) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1ed835f3c3cso10012035ad.3 for ; Fri, 17 May 2024 06:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715953388; x=1716558188; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Ie+870ZSmebYNJH3T8S6AtPu/rRdgfskcV86wSj1a38=; b=imP23LtMhBv49CfTK8eOCxfKQJ7U/KwrDg3ujIbSF701pMOwvt8SZ8jUeqEQZmyQoj raWR5CuWxOPMff0t/NsyNw4RQhKzJeJsHoY6m9SrtdJJGUAs2Oyh2ydl1DUg07/VN+ng ZqF6LhHzeWHDITjZaH+QXCChy6oHRT5JPxQbaVWNEcs6tbiHwLAfcxrOP2HQivj5zR3U JIBoDXDOS8wbWiw7rOxj1OVYhs+jhB1EH9Pr1FQZnwUel2mgyClz2y380W8OYitC+bOG x4qgjbFsfId3au+ndEJspJjrFhFOAiszlBuKJeonZzMy//CFnKnBZUZBoMqwIkV91lqT oChw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715953388; x=1716558188; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ie+870ZSmebYNJH3T8S6AtPu/rRdgfskcV86wSj1a38=; b=pRn1wrbmurP5M4uNgKcecG+5dMl85kTxu2hcm1yhWkU958PC7tJez4D/vP0k5aecvp HgjJo7SbrEn3Jb9NLGMtiH1x80MXZxUYtLh7CaR27v5v4SrFrR7K6CPW1qnH3Ab6wqBT 6fG4ZAABQnCt+Vd3wdf2LWfTiAisGOeItWkhPFXXv3pJLHaTUOyGxN4sE0q8/0uUu8iF ihdFYDCR9/yuRSyKnPrOd30IKc7gHT2RCxywrYYthplgR+c5vRh879Vp5BZ590od68AE eWfVRtOLpGsnVxPc9l7+/2a0ESU715iX1CeiiJKhVFQ4SU+FGgbTjNcut8tAsAmBY1lf ETWw== X-Gm-Message-State: AOJu0YxMbOCBiApHillSsky11dsjAmvNBCG64novQ1O9IFZcoB7WCPM/ Ib4g3l/SBNjDQ+9mIgsgt1KnJpXDAKCiAzLuk2FsLLMcGBIiaRaRWsfo5w== X-Google-Smtp-Source: AGHT+IHfX7khzeGYCPmy2YQ6f22dQDJDVEfT9zq+pDldmr1zKS5xhts1Ayu4grd3y5aUOesT7QAB5Q== X-Received: by 2002:a17:903:230b:b0:1e6:7731:80 with SMTP id d9443c01a7336-1ef43d16e69mr283749905ad.11.1715953387677; Fri, 17 May 2024 06:43:07 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0b9d15dfsm157145935ad.62.2024.05.17.06.43.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 06:43:07 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2024 10:42:26 -0300 Message-ID: <20240517134228.288-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3 v3] avformat/vvc: fix writing general_constraint_info bytes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: The existing implementation was completely broken. Signed-off-by: James Almer --- libavformat/Makefile | 2 +- libavformat/bitstream.c | 1 + libavformat/vvc.c | 38 ++++++++++++++++++++------------------ tests/ref/fate/source | 1 + 4 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 libavformat/bitstream.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 2d4e0e0c95..211ccf45e5 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -727,7 +727,7 @@ OBJS-$(CONFIG_LIBSSH_PROTOCOL) += libssh.o OBJS-$(CONFIG_LIBZMQ_PROTOCOL) += libzmq.o # Objects duplicated from other libraries for shared builds -SHLIBOBJS += log2_tab.o to_upper4.o +SHLIBOBJS += log2_tab.o to_upper4.o bitstream.o SHLIBOBJS-$(CONFIG_ISO_MEDIA) += mpegaudiotabs.o SHLIBOBJS-$(CONFIG_FLV_MUXER) += mpeg4audio_sample_rates.o SHLIBOBJS-$(CONFIG_HLS_DEMUXER) += ac3_channel_layout_tab.o diff --git a/libavformat/bitstream.c b/libavformat/bitstream.c new file mode 100644 index 0000000000..2afda37c30 --- /dev/null +++ b/libavformat/bitstream.c @@ -0,0 +1 @@ +#include "libavcodec/bitstream.c" diff --git a/libavformat/vvc.c b/libavformat/vvc.c index 3123cd8d83..98177a7ad8 100644 --- a/libavformat/vvc.c +++ b/libavformat/vvc.c @@ -21,6 +21,7 @@ */ #include "libavcodec/get_bits.h" +#include "libavcodec/put_bits.h" #include "libavcodec/golomb.h" #include "libavcodec/vvc.h" #include "libavutil/intreadwrite.h" @@ -138,9 +139,8 @@ static void vvcc_update_ptl(VVCDecoderConfigurationRecord *vvcc, vvcc->ptl.num_bytes_constraint_info = 9; memcpy(&vvcc->ptl.general_constraint_info[0], &ptl->gci_general_constraints[0], sizeof(uint8_t) * 9); - } else { - vvcc->ptl.num_bytes_constraint_info = 1; + vvcc->ptl.num_bytes_constraint_info = 0; memset(&vvcc->ptl.general_constraint_info[0], 0, sizeof(uint8_t) * 9); } @@ -185,7 +185,7 @@ static void vvcc_parse_ptl(GetBitContext *gb, unsigned int profileTierPresentFlag, unsigned int max_sub_layers_minus1) { - VVCCProfileTierLevel general_ptl; + VVCCProfileTierLevel general_ptl = { 0 }; int j; if (profileTierPresentFlag) { @@ -326,6 +326,7 @@ static int vvcc_parse_vps(GetBitContext *gb, for (int i = 0; i <= vps_num_ptls_minus1; i++) vvcc_parse_ptl(gb, vvcc, vps_pt_present_flag[i], vps_ptl_max_tid[i]); + vvcc->ptl_present_flag = 1; /* nothing useful for vvcc past this point */ return 0; @@ -356,8 +357,10 @@ static int vvcc_parse_sps(GetBitContext *gb, vvcc->chroma_format_idc = get_bits(gb, 2); sps_log2_ctu_size_minus5 = get_bits(gb, 2); - if (get_bits1(gb)) // sps_ptl_dpb_hrd_params_present_flag + if (get_bits1(gb)) { // sps_ptl_dpb_hrd_params_present_flag + vvcc->ptl_present_flag = 1; vvcc_parse_ptl(gb, vvcc, 1, sps_max_sublayers_minus1); + } skip_bits1(gb); // sps_gdr_enabled_flag if (get_bits(gb, 1)) // sps_ref_pic_resampling_enabled_flag @@ -579,10 +582,6 @@ static void vvcc_init(VVCDecoderConfigurationRecord *vvcc) { memset(vvcc, 0, sizeof(VVCDecoderConfigurationRecord)); vvcc->lengthSizeMinusOne = 3; // 4 bytes - - vvcc->ptl.num_bytes_constraint_info = 1; - - vvcc->ptl_present_flag = 1; } static void vvcc_close(VVCDecoderConfigurationRecord *vvcc) @@ -603,7 +602,6 @@ static int vvcc_write(AVIOContext *pb, VVCDecoderConfigurationRecord *vvcc) { uint8_t i; uint16_t j, vps_count = 0, sps_count = 0, pps_count = 0; - unsigned char *buf = NULL; /* * It's unclear how to properly compute these fields, so * let's always set them to values meaning 'unspecified'. @@ -735,6 +733,10 @@ static int vvcc_write(AVIOContext *pb, VVCDecoderConfigurationRecord *vvcc) avio_w8(pb, vvcc->lengthSizeMinusOne << 1 | vvcc->ptl_present_flag | 0xf8); if (vvcc->ptl_present_flag) { + uint8_t buf[64]; + PutBitContext pbc; + + init_put_bits(&pbc, buf, sizeof(buf)); /* * unsigned int(9) ols_idx; * unsigned int(3) num_sublayers; @@ -766,15 +768,15 @@ static int vvcc_write(AVIOContext *pb, VVCDecoderConfigurationRecord *vvcc) * unsigned int (1) ptl_frame_only_constraint_flag * unsigned int (1) ptl_multilayer_enabled_flag * unsigned int (8*num_bytes_constraint_info -2) general_constraint_info */ - buf = - (unsigned char *) malloc(sizeof(unsigned char) * - vvcc->ptl.num_bytes_constraint_info); - *buf = vvcc->ptl.ptl_frame_only_constraint_flag << vvcc->ptl. - num_bytes_constraint_info * 8 - 1 | vvcc->ptl. - ptl_multilayer_enabled_flag << vvcc->ptl.num_bytes_constraint_info * - 8 - 2 | *vvcc->ptl.general_constraint_info >> 2; - avio_write(pb, buf, vvcc->ptl.num_bytes_constraint_info); - free(buf); + put_bits(&pbc, 1, vvcc->ptl.ptl_frame_only_constraint_flag); + put_bits(&pbc, 1, vvcc->ptl.ptl_multilayer_enabled_flag); + if (vvcc->ptl.num_bytes_constraint_info) { + ff_copy_bits(&pbc, vvcc->ptl.general_constraint_info, (vvcc->ptl.num_bytes_constraint_info - 1) * 8); + put_bits(&pbc, 6, vvcc->ptl.general_constraint_info[vvcc->ptl.num_bytes_constraint_info - 1] & 0x3f); + } else + put_bits(&pbc, 6, 0); + flush_put_bits(&pbc); + avio_write(pb, buf, put_bytes_count(&pbc, 1)); if (vvcc->num_sublayers > 1) { uint8_t ptl_sublayer_level_present_flags = 0; diff --git a/tests/ref/fate/source b/tests/ref/fate/source index 7b5f14b4f0..d8d4224145 100644 --- a/tests/ref/fate/source +++ b/tests/ref/fate/source @@ -10,6 +10,7 @@ libavdevice/reverse.c libavfilter/af_arnndn.c libavfilter/file_open.c libavfilter/log2_tab.c +libavformat/bitstream.c libavformat/file_open.c libavformat/golomb_tab.c libavformat/log2_tab.c -- 2.45.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".