* [FFmpeg-devel] [PATCH] avformat/vvc: fix writing general_constraint_info bytes
@ 2024-05-16 14:58 James Almer
2024-05-16 17:27 ` [FFmpeg-devel] [PATCH v2] " James Almer
0 siblings, 1 reply; 2+ messages in thread
From: James Almer @ 2024-05-16 14:58 UTC (permalink / raw)
To: ffmpeg-devel
The existing implementation was completely broken.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/Makefile | 2 +-
libavformat/bitstream.c | 1 +
libavformat/vvc.c | 33 ++++++++++++++++-----------------
tests/ref/fate/source | 1 +
4 files changed, 19 insertions(+), 18 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..f4b8195948 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"
@@ -45,7 +46,7 @@ typedef struct VVCPTLRecord {
uint8_t general_level_idc;
uint8_t ptl_frame_only_constraint_flag;
uint8_t ptl_multilayer_enabled_flag;
- uint8_t general_constraint_info[9];
+ uint8_t general_constraint_info[64];
uint8_t ptl_sublayer_level_present_flag[VVC_MAX_SUBLAYERS - 1];
uint8_t sublayer_level_idc[VVC_MAX_SUBLAYERS - 1];
uint8_t ptl_num_sub_profiles;
@@ -138,10 +139,6 @@ 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;
- memset(&vvcc->ptl.general_constraint_info[0], 0, sizeof(uint8_t) * 9);
}
/*
@@ -580,8 +577,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;
}
@@ -603,7 +598,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 +729,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 +764,16 @@ 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);
+ put_bits(&pbc, 6, vvcc->ptl.general_constraint_info[vvcc->ptl.num_bytes_constraint_info - 1]);
+ } else
+ put_bits(&pbc, 6, 0);
+ flush_put_bits(&pbc);
+ avio_write(pb, buf, FFMAX(vvcc->ptl.num_bytes_constraint_info, 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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH v2] avformat/vvc: fix writing general_constraint_info bytes
2024-05-16 14:58 [FFmpeg-devel] [PATCH] avformat/vvc: fix writing general_constraint_info bytes James Almer
@ 2024-05-16 17:27 ` James Almer
0 siblings, 0 replies; 2+ messages in thread
From: James Almer @ 2024-05-16 17:27 UTC (permalink / raw)
To: ffmpeg-devel
The existing implementation was completely broken.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/Makefile | 2 +-
libavformat/bitstream.c | 1 +
libavformat/vvc.c | 28 ++++++++++++++--------------
tests/ref/fate/source | 1 +
4 files changed, 17 insertions(+), 15 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..36d387f295 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,7 @@ 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;
memset(&vvcc->ptl.general_constraint_info[0], 0, sizeof(uint8_t) * 9);
}
@@ -580,8 +579,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;
}
@@ -603,7 +600,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 +731,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 +766,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, FFMAX(vvcc->ptl.num_bytes_constraint_info, 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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-16 17:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-16 14:58 [FFmpeg-devel] [PATCH] avformat/vvc: fix writing general_constraint_info bytes James Almer
2024-05-16 17:27 ` [FFmpeg-devel] [PATCH v2] " James Almer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git