[FFmpeg-devel] [PATCH] fate/jpeg2000dec: add selected conformance codestreams from ISO/IEC 15444-4

2024-08-20 Thread pal
From: Pierre-Anthony Lemieux 

---
 tests/fate/jpeg2000.mak  | 129 +--
 tests/ref/fate/jpeg2000dec-ds0_hm_15_b8  |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_02_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_02_b12 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_03_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_03_b14 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_04_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_04_b12 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_05_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_05_b12 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_07_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_07_b15 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_07_b16 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_08_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_08_b15 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_08_b16 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_09_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_10_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_11_b10 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_12_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_14_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_15_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_15_b14 |   6 ++
 tests/ref/fate/jpeg2000dec-ds0_ht_16_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_01_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_01_b12 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_02_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_02_b12 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_03_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_03_b12 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_04_b9  |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_05_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-ds1_ht_06_b11 |   6 ++
 tests/ref/fate/jpeg2000dec-hifi_ht1_02   |   6 ++
 tests/ref/fate/jpeg2000dec-hifi_p1_02|   6 ++
 tests/ref/fate/jpeg2000dec-p1_01 |   6 ++
 tests/ref/fate/jpeg2000dec-p1_02 |   6 ++
 tests/ref/fate/jpeg2000dec-p1_03 |   6 ++
 tests/ref/fate/jpeg2000dec-p1_04 |   6 ++
 tests/ref/fate/jpeg2000dec-p1_05 |   6 ++
 tests/ref/fate/jpeg2000dec-p1_06 |   6 ++
 41 files changed, 363 insertions(+), 6 deletions(-)
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_hm_15_b8
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_02_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_02_b12
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_03_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_03_b14
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_04_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_04_b12
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_05_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_05_b12
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_07_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_07_b15
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_07_b16
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_08_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_08_b15
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_08_b16
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_09_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_10_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_11_b10
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_12_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_14_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_15_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_15_b14
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_16_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_01_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_01_b12
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_02_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_02_b12
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_03_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_03_b12
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_04_b9
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_05_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-ds1_ht_06_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-hifi_ht1_02
 create mode 100644 tests/ref/fate/jpeg2000dec-hifi_p1_02
 create mode 100644 tests/ref/fate/jpeg2000dec-p1_01
 create mode 100644 tests/ref/fate/jpeg2000dec-p1_02
 create mode 100644 tests/ref/fate/jpeg2000dec-p1_03
 create mode 100644 tests/ref/fate/jpeg2000dec-p1_04
 create mode 100644 tests/ref/fate/jpeg2000dec-p1_05
 create mode 100644 tests/ref/fate/jpeg2000dec-p1_06

diff --git a/tests/fate/jpeg2000.mak b/tests/fate/jpeg2000.mak
index a99b0c4e0c..974f33bdc3 100644
--- a/tests/fate/jpeg2000.mak
+++ b/tests/fate/jpeg2000.mak
@@ -7,16 +7,13 @@
 # Notes:
 # * p0_06.j2k is not included because it uses a pixel format that is not
 #   supported (4:2:2:1)
-# * p0_10.j2k is not included because errors are emitted during decoding and
-#   there are significant deviations from the re

[FFmpeg-devel] [PATCH] fate/jpeg2000dec: add support for p0_10.j2k

2024-06-15 Thread pal
From: Pierre-Anthony Lemieux 

p0_10.j2k is one of the reference codestreams included in Rec. ITU-T T.803 | 
ISO/IEC 15444-4.
---
 tests/fate/jpeg2000.mak  | 3 +++
 tests/ref/fate/jpeg2000dec-p0_10 | 6 ++
 2 files changed, 9 insertions(+)
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_10

diff --git a/tests/fate/jpeg2000.mak b/tests/fate/jpeg2000.mak
index 2969d2cf0a..a99b0c4e0c 100644
--- a/tests/fate/jpeg2000.mak
+++ b/tests/fate/jpeg2000.mak
@@ -42,6 +42,9 @@ fate-jpeg2000dec-p0_08: CMD = framecrc -flags +bitexact 
-auto_conversion_filters
 FATE_JPEG2000DEC += fate-jpeg2000dec-p0_09
 fate-jpeg2000dec-p0_09: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_09.j2k
 
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_10
+fate-jpeg2000dec-p0_10: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_10.j2k
+
 FATE_JPEG2000DEC += fate-jpeg2000dec-p0_11
 fate-jpeg2000dec-p0_11: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_11.j2k
 
diff --git a/tests/ref/fate/jpeg2000dec-p0_10 b/tests/ref/fate/jpeg2000dec-p0_10
new file mode 100644
index 00..16c4e5e39d
--- /dev/null
+++ b/tests/ref/fate/jpeg2000dec-p0_10
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 64x64
+#sar 0: 0/1
+0,  0,  0,1,12288, 0x68638483
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] configure: remove false positives with valgrind-memcheck

2024-06-08 Thread pal
From: Pierre-Anthony Lemieux 

If  `--toolchain=valgrind-memcheck` is selected, fate-lavf-asf fails on a false 
positive.
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 6c5b8aab9a..c708f2e38c 100755
--- a/configure
+++ b/configure
@@ -4571,7 +4571,7 @@ case "$toolchain" in
 target_exec_args="--tool=massif --alloc-fn=av_malloc 
--alloc-fn=av_mallocz --alloc-fn=av_calloc --alloc-fn=av_fast_padded_malloc 
--alloc-fn=av_fast_malloc --alloc-fn=av_realloc_f --alloc-fn=av_fast_realloc 
--alloc-fn=av_realloc"
 ;;
 valgrind-memcheck)
-target_exec_args="--error-exitcode=1 --malloc-fill=0x2a 
--track-origins=yes --leak-check=full --gen-suppressions=all 
--suppressions=$source_path/tests/fate-valgrind.supp"
+target_exec_args="--error-exitcode=1 
--expensive-definedness-checks=yes --malloc-fill=0x2a --track-origins=yes 
--leak-check=full --gen-suppressions=all 
--suppressions=$source_path/tests/fate-valgrind.supp"
 ;;
 esac
 ;;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3] avcodec/jpeg2000dec: fix HT block decoder

2024-05-27 Thread pal
From: Pierre-Anthony Lemieux 

Addresses https://trac.ffmpeg.org/ticket/10905

Co-authored-by: Osamu Watanabe 
Signed-off-by: Pierre-Anthony Lemieux 
---
 libavcodec/jpeg2000htdec.c   | 122 ---
 tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 |   2 +-
 2 files changed, 63 insertions(+), 61 deletions(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index fa704b665e..eba0936089 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -196,7 +196,7 @@ static void jpeg2000_bitbuf_refill_forward(StateVars 
*buffer, const uint8_t *arr
 while (buffer->bits_left < 32) {
 buffer->tmp = 0xFF;
 buffer->bits = (buffer->last == 0xFF) ? 7 : 8;
-if (buffer->pos <= length) {
+if (buffer->pos < length) {
 buffer->tmp = array[buffer->pos];
 buffer->pos += 1;
 buffer->last = buffer->tmp;
@@ -413,7 +413,7 @@ static void recover_mag_sgn(StateVars *mag_sgn, uint8_t 
pos, uint16_t q, int32_t
 
 static int jpeg2000_import_bit(StateVars *stream, const uint8_t *array, 
uint32_t length)
 {
-int cond = stream->pos <= length;
+int cond = stream->pos < length;
 int pos = FFMIN(stream->pos, length);
 if (stream->bits == 0) {
 stream->bits = (stream->tmp == 0xFF) ? 7 : 8;
@@ -427,7 +427,7 @@ static int jpeg2000_import_bit(StateVars *stream, const 
uint8_t *array, uint32_t
 static int jpeg2000_peek_bit(StateVars *stream, const uint8_t *array, uint32_t 
length)
 {
 if (stream->bits == 0) {
-int cond = stream->pos <= length;
+int cond = stream->pos < length;
 int pos = FFMIN(stream->pos, length);
 stream->bits = (stream->tmp == 0xFF) ? 7 : 8;
 stream->pos += cond;
@@ -508,17 +508,17 @@ static int jpeg2000_decode_sig_emb(const 
Jpeg2000DecoderContext *s, MelDecoderSt
 }
 
 av_always_inline
-static int jpeg2000_get_state(int x1, int x2, int width, int shift_by,
+static int jpeg2000_get_state(int x1, int x2, int stride, int shift_by,
   const uint8_t *block_states)
 {
-return (block_states[(x1 + 1) * (width + 2) + (x2 + 1)] >> shift_by) & 1;
+return (block_states[(x1 + 1) * stride + (x2 + 1)] >> shift_by) & 1;
 }
 
 av_always_inline
-static void jpeg2000_modify_state(int x1, int x2, int width,
- int value, uint8_t *block_states)
+static void jpeg2000_modify_state(int x1, int x2, int stride,
+  int value, uint8_t *block_states)
 {
-block_states[(x1 + 1) * (width + 2) + (x2 + 1)] |= value;
+block_states[(x1 + 1) * stride + (x2 + 1)] |= value;
 }
 
 av_always_inline
@@ -528,8 +528,8 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
   StateVars *mel_stream, StateVars 
*vlc_stream,
   StateVars *mag_sgn_stream, const 
uint8_t *Dcup,
   uint32_t Lcup, uint32_t Pcup, 
uint8_t pLSB,
-  int width, int height, int32_t 
*sample_buf,
-  uint8_t *block_states)
+  int width, int height, const int 
stride,
+  int32_t *sample_buf, uint8_t 
*block_states)
 {
 uint16_t q  = 0; // Represents current quad 
position
 uint16_t q1, q2;
@@ -958,26 +958,26 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 j1 = 2 * y;
 j2 = 2 * x;
 
-sample_buf[j2 + (j1 * width)] = (int32_t)*mu;
-jpeg2000_modify_state(j1, j2, width, *sigma, block_states);
+sample_buf[j2 + (j1 * stride)] = (int32_t)*mu;
+jpeg2000_modify_state(j1, j2, stride, *sigma, block_states);
 sigma += 1;
 mu += 1;
 
 x1 = y != quad_height - 1 || is_border_y == 0;
-sample_buf[j2 + ((j1 + 1) * width)] = ((int32_t)*mu) * x1;
-jpeg2000_modify_state(j1 + 1, j2, width, (*sigma) * x1, 
block_states);
+sample_buf[j2 + ((j1 + 1) * stride)] = ((int32_t)*mu) * x1;
+jpeg2000_modify_state(j1 + 1, j2, stride, (*sigma) * x1, 
block_states);
 sigma += 1;
 mu += 1;
 
 x2 = x != quad_width - 1 || is_border_x == 0;
-sample_buf[(j2 + 1) + (j1 * width)] = ((int32_t)*mu) * x2;
-jpeg2000_modify_state(j1, j2 + 1, width, (*sigma) * x2, 
block_states);
+sample_buf[(j2 + 1) + (j1 * stride)] = ((int32_t)*mu) * x2;
+jpeg2000_modify_state(j1, j2 + 1, stride, (*sigma) * x2, 
block_states);
 sigma += 1;
 mu += 1;
 
 x3 = x1 | x2;
-sample_buf[(j2 + 1) + (j1 + 1) * width] = ((int32_t)*mu) * x3;
-jpeg2000_modify_state(j1 + 1, j2 + 1, width, (*s

[FFmpeg-devel] [PATCH] avcodec/jpeg2000dec: fix HT block decoder

2024-05-19 Thread pal
From: Pierre-Anthony Lemieux 

Addresses https://trac.ffmpeg.org/ticket/10905

Co-authored-by: Osamu Watanabe 
Signed-off-by: Pierre-Anthony Lemieux 
---
 libavcodec/jpeg2000htdec.c   | 122 ---
 tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 |   2 +-
 2 files changed, 63 insertions(+), 61 deletions(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index fa704b665e..62f70c32a8 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -196,7 +196,7 @@ static void jpeg2000_bitbuf_refill_forward(StateVars 
*buffer, const uint8_t *arr
 while (buffer->bits_left < 32) {
 buffer->tmp = 0xFF;
 buffer->bits = (buffer->last == 0xFF) ? 7 : 8;
-if (buffer->pos <= length) {
+if (buffer->pos < length) {
 buffer->tmp = array[buffer->pos];
 buffer->pos += 1;
 buffer->last = buffer->tmp;
@@ -508,17 +508,17 @@ static int jpeg2000_decode_sig_emb(const 
Jpeg2000DecoderContext *s, MelDecoderSt
 }
 
 av_always_inline
-static int jpeg2000_get_state(int x1, int x2, int width, int shift_by,
+static int jpeg2000_get_state(int x1, int x2, int stride, int shift_by,
   const uint8_t *block_states)
 {
-return (block_states[(x1 + 1) * (width + 2) + (x2 + 1)] >> shift_by) & 1;
+return (block_states[(x1 + 1) * stride + (x2 + 1)] >> shift_by) & 1;
 }
 
 av_always_inline
-static void jpeg2000_modify_state(int x1, int x2, int width,
- int value, uint8_t *block_states)
+static void jpeg2000_modify_state(int x1, int x2, int stride,
+  int value, uint8_t *block_states)
 {
-block_states[(x1 + 1) * (width + 2) + (x2 + 1)] |= value;
+block_states[(x1 + 1) * stride + (x2 + 1)] |= value;
 }
 
 av_always_inline
@@ -528,8 +528,8 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
   StateVars *mel_stream, StateVars 
*vlc_stream,
   StateVars *mag_sgn_stream, const 
uint8_t *Dcup,
   uint32_t Lcup, uint32_t Pcup, 
uint8_t pLSB,
-  int width, int height, int32_t 
*sample_buf,
-  uint8_t *block_states)
+  int width, int height, const int 
stride,
+  int32_t *sample_buf, uint8_t 
*block_states)
 {
 uint16_t q  = 0; // Represents current quad 
position
 uint16_t q1, q2;
@@ -958,32 +958,32 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 j1 = 2 * y;
 j2 = 2 * x;
 
-sample_buf[j2 + (j1 * width)] = (int32_t)*mu;
-jpeg2000_modify_state(j1, j2, width, *sigma, block_states);
+sample_buf[j2 + (j1 * stride)] = (int32_t)*mu;
+jpeg2000_modify_state(j1, j2, stride, *sigma, block_states);
 sigma += 1;
 mu += 1;
 
 x1 = y != quad_height - 1 || is_border_y == 0;
-sample_buf[j2 + ((j1 + 1) * width)] = ((int32_t)*mu) * x1;
-jpeg2000_modify_state(j1 + 1, j2, width, (*sigma) * x1, 
block_states);
+sample_buf[j2 + ((j1 + 1) * stride)] = ((int32_t)*mu) * x1;
+jpeg2000_modify_state(j1 + 1, j2, stride, (*sigma) * x1, 
block_states);
 sigma += 1;
 mu += 1;
 
 x2 = x != quad_width - 1 || is_border_x == 0;
-sample_buf[(j2 + 1) + (j1 * width)] = ((int32_t)*mu) * x2;
-jpeg2000_modify_state(j1, j2 + 1, width, (*sigma) * x2, 
block_states);
+sample_buf[(j2 + 1) + (j1 * stride)] = ((int32_t)*mu) * x2;
+jpeg2000_modify_state(j1, j2 + 1, stride, (*sigma) * x2, 
block_states);
 sigma += 1;
 mu += 1;
 
 x3 = x1 | x2;
-sample_buf[(j2 + 1) + (j1 + 1) * width] = ((int32_t)*mu) * x3;
-jpeg2000_modify_state(j1 + 1, j2 + 1, width, (*sigma) * x3, 
block_states);
+sample_buf[(j2 + 1) + (j1 + 1) * stride] = ((int32_t)*mu) * x3;
+jpeg2000_modify_state(j1 + 1, j2 + 1, stride, (*sigma) * x3, 
block_states);
 sigma += 1;
 mu += 1;
 }
 }
 ret = 1;
-free:
+free:
 av_freep(&sigma_n);
 av_freep(&E);
 av_freep(&mu_n);
@@ -992,39 +992,39 @@ free:
 
 static void jpeg2000_calc_mbr(uint8_t *mbr, const uint16_t i, const uint16_t j,
   const uint32_t mbr_info, uint8_t causal_cond,
-  uint8_t *block_states, int width)
+  uint8_t *block_states, int stride)
 {
 int local_mbr = 0;
 
-local_mbr |= jpeg2000_get_state(i - 1, j - 1, width, HT_SHIFT_SIGMA, 
block_states);
-local_mbr |= jpeg2000_get_state(i - 1, j + 

[FFmpeg-devel] [PATCH v2] avcodec/jpeg2000htdec: check if block decoding will exceed internal precision

2023-08-12 Thread pal
From: Pierre-Anthony Lemieux 

Intended to replace 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230802000135.26482-3-mich...@niedermayer.cc/
with a more accurate block decoding magnitude bound.

---
 libavcodec/jpeg2000htdec.c | 34 +-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index 2c4cea5dd9..a7329206de 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -572,6 +572,14 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 
 const uint8_t *vlc_buf = Dcup + Pcup;
 
+/*
+ * Bound on the recision needed to process the codeblock. The number of
+ * decoded bit planes is equal to at most cblk->zbp + 2 since S_blk = P if
+ * there are no placeholder passes or HT Sets and P = cblk->zbp. See Rec.
+ * ITU-T T.814, 7.6.
+ */
+int maxbp = cblk->zbp + 2;
+
 /* convert to raster-scan */
 const uint16_t is_border_x = width % 2;
 const uint16_t is_border_y = height % 2;
@@ -590,6 +598,12 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 goto free;
 }
 
+/* do we have enough precision, assuming a 32-bit decoding path */
+if (maxbp >= 32) {
+return AVERROR_INVALIDDATA;
+goto free;
+}
+
 sigma = sigma_n;
 mu = mu_n;
 
@@ -676,6 +690,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 }
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
 U[J2K_Q2] = kappa[J2K_Q2] + u[J2K_Q2];
+if (U[J2K_Q1] > maxbp || U[J2K_Q2] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++) {
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -713,6 +731,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 }
 
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
+if (U[J2K_Q1] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++)
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -842,6 +864,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
 U[J2K_Q2] = kappa[J2K_Q2] + u[J2K_Q2];
+if (U[J2K_Q1] > maxbp || U[J2K_Q2] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++) {
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -910,6 +936,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 kappa[J2K_Q1] = FFMAX(1, gamma[J2K_Q1] * (max_e[J2K_Q1] - 1));
 
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
+if (U[J2K_Q1] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++)
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -1238,8 +1268,10 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext 
*s, Jpeg2000CodingStyle *c
 }
 if ((ret = jpeg2000_decode_ht_cleanup_segment(s, cblk, t1, &mel_state, 
&mel, &vlc,
   &mag_sgn, Dcup, Lcup, Pcup, pLSB, 
width,
-  height, sample_buf, block_states)) < 
0)
+  height, sample_buf, block_states)) < 
0) {
+av_log(s->avctx, AV_LOG_ERROR, "Bad HT cleanup segment\n");
 goto free;
+}
 
 if (cblk->npasses > 1)
 jpeg2000_decode_sigprop_segment(cblk, width, height, Dref, Lref,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1] avcodec/jpeg2000htdec: check if block decoding will exceed internal precision

2023-08-10 Thread pal
From: Pierre-Anthony Lemieux 

Intended to replace 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230802000135.26482-3-mich...@niedermayer.cc/
with a more accurate block decoding magnitude bound.

---
 libavcodec/jpeg2000htdec.c | 32 +++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/libavcodec/jpeg2000htdec.c b/libavcodec/jpeg2000htdec.c
index 2c4cea5dd9..713dba17e3 100644
--- a/libavcodec/jpeg2000htdec.c
+++ b/libavcodec/jpeg2000htdec.c
@@ -572,6 +572,14 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 
 const uint8_t *vlc_buf = Dcup + Pcup;
 
+/*
+ * Bound on the recision needed to process the codeblock. The number of
+ * decoded bit planes is equal to at most cblk->zbp + 2 since S_blk = P if
+ * there are no placeholder passes or HT Sets and P = cblk->zbp. See Rec.
+ * ITU-T T.814, 7.6.
+ */
+int maxbp = cblk->zbp + 2;
+
 /* convert to raster-scan */
 const uint16_t is_border_x = width % 2;
 const uint16_t is_border_y = height % 2;
@@ -590,6 +598,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 goto free;
 }
 
+/* do we have enough precision, assuming a 32-bit decoding path */
+if (maxbp >= 32)
+return AVERROR_INVALIDDATA;
+
 sigma = sigma_n;
 mu = mu_n;
 
@@ -676,6 +688,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 }
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
 U[J2K_Q2] = kappa[J2K_Q2] + u[J2K_Q2];
+if (U[J2K_Q1] > maxbp || U[J2K_Q2] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++) {
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -713,6 +729,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 }
 
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
+if (U[J2K_Q1] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++)
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -842,6 +862,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
 U[J2K_Q2] = kappa[J2K_Q2] + u[J2K_Q2];
+if (U[J2K_Q1] > maxbp || U[J2K_Q2] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++) {
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -910,6 +934,10 @@ static int jpeg2000_decode_ht_cleanup_segment(const 
Jpeg2000DecoderContext *s,
 kappa[J2K_Q1] = FFMAX(1, gamma[J2K_Q1] * (max_e[J2K_Q1] - 1));
 
 U[J2K_Q1] = kappa[J2K_Q1] + u[J2K_Q1];
+if (U[J2K_Q1] > maxbp) {
+ret = AVERROR_INVALIDDATA;
+goto free;
+}
 
 for (int i = 0; i < 4; i++)
 m[J2K_Q1][i] = sigma_n[4 * q1 + i] * U[J2K_Q1] - 
((emb_pat_k[J2K_Q1] >> i) & 1);
@@ -1238,8 +1266,10 @@ ff_jpeg2000_decode_htj2k(const Jpeg2000DecoderContext 
*s, Jpeg2000CodingStyle *c
 }
 if ((ret = jpeg2000_decode_ht_cleanup_segment(s, cblk, t1, &mel_state, 
&mel, &vlc,
   &mag_sgn, Dcup, Lcup, Pcup, pLSB, 
width,
-  height, sample_buf, block_states)) < 
0)
+  height, sample_buf, block_states)) < 
0) {
+av_log(s->avctx, AV_LOG_ERROR, "Bad HT cleanup segment\n");
 goto free;
+}
 
 if (cblk->npasses > 1)
 jpeg2000_decode_sigprop_segment(cblk, width, height, Dref, Lref,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] avformat/imf: clean-up logging * remove log to NULL * remove extraneous logging

2023-05-29 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imf.h   |   6 +-
 libavformat/imf_cpl.c   | 179 +++-
 libavformat/imfdec.c|   2 +-
 libavformat/tests/imf.c |   4 +-
 4 files changed, 91 insertions(+), 100 deletions(-)

diff --git a/libavformat/imf.h b/libavformat/imf.h
index 70ed007312..ef124bf412 100644
--- a/libavformat/imf.h
+++ b/libavformat/imf.h
@@ -140,6 +140,7 @@ typedef struct FFIMFCPL {
 
 /**
  * Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.
+ * @param[in] log_ctx Logging context (points to an instance of AVClass). May 
be NULL.
  * @param[in] doc An XML document from which the CPL is read.
  * @param[out] cpl Pointer to a memory area (allocated by the client), where 
the
  *  function writes a pointer to the newly constructed FFIMFCPL structure (or
@@ -147,10 +148,11 @@ typedef struct FFIMFCPL {
  *  the FFIMFCPL structure using ff_imf_cpl_free().
  * @return A non-zero value in case of an error.
  */
-int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl);
+int ff_imf_parse_cpl_from_xml_dom(void *log_ctx, xmlDocPtr doc, FFIMFCPL 
**cpl);
 
 /**
  * Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
+ * @param[in] log_ctx Logging context (points to an instance of AVClass). May 
be NULL.
  * @param[in] in The context from which the CPL is read.
  * @param[out] cpl Pointer to a memory area (allocated by the client), where 
the
  * function writes a pointer to the newly constructed FFIMFCPL structure (or
@@ -158,7 +160,7 @@ int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL 
**cpl);
  * the FFIMFCPL structure using ff_imf_cpl_free().
  * @return A non-zero value in case of an error.
  */
-int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl);
+int ff_imf_parse_cpl(void *log_ctx, AVIOContext *in, FFIMFCPL **cpl);
 
 /**
  * Allocates and initializes an FFIMFCPL data structure.
diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index a7cf5fa360..fe975c2f0c 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -76,10 +76,8 @@ int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
 
 xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
 ret = av_uuid_urn_parse(element_text, uuid);
-if (ret) {
-av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
+if (ret)
 ret = AVERROR_INVALIDDATA;
-}
 xmlFree(element_text);
 
 return ret;
@@ -90,10 +88,8 @@ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational 
*rational)
 int ret = 0;
 
 xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
-if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) {
-av_log(NULL, AV_LOG_ERROR, "Invalid rational number\n");
+if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2)
 ret = AVERROR_INVALIDDATA;
-}
 xmlFree(element_text);
 
 return ret;
@@ -104,10 +100,8 @@ int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t 
*number)
 int ret = 0;
 
 xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
-if (sscanf(element_text, "%" PRIu32, number) != 1) {
-av_log(NULL, AV_LOG_ERROR, "Invalid unsigned 32-bit integer");
+if (sscanf(element_text, "%" PRIu32, number) != 1)
 ret = AVERROR_INVALIDDATA;
-}
 xmlFree(element_text);
 
 return ret;
@@ -181,10 +175,8 @@ static int fill_content_title(xmlNodePtr cpl_element, 
FFIMFCPL *cpl)
 {
 xmlNodePtr element = NULL;
 
-if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, 
"ContentTitle"))) {
-av_log(NULL, AV_LOG_ERROR, "ContentTitle element not found in the IMF 
CPL\n");
+if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, 
"ContentTitle")))
 return AVERROR_INVALIDDATA;
-}
 cpl->content_title_utf8 = xmlNodeListGetString(cpl_element->doc,
element->xmlChildrenNode,
1);
@@ -242,22 +234,15 @@ static int fill_timecode(xmlNodePtr cpl_element, FFIMFCPL 
*cpl)
return 0;
 
 element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeDropFrame");
-if (!element) {
-av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
-a TimecodeDropFrame child element\n");
+if (!element)
 return AVERROR_INVALIDDATA;
-}
 
-if (ff_imf_xml_read_boolean(element, &df)) {
-av_log(NULL, AV_LOG_ERROR, "TimecodeDropFrame element is invalid\n");
+if (ff_imf_xml_read_boolean(element, &df))
 return AVERROR_INVALIDDATA;
-}
+
 element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeStartAddress");
-if (!element) {
-av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
- 

[FFmpeg-devel] [PATCH v3 2/2] fate/imf: remove redundant code

2023-05-15 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/imf.c | 52 ++---
 1 file changed, 12 insertions(+), 40 deletions(-)

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index c02cd87ceb..068ee6c58a 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -257,7 +257,7 @@ const char *cpl_doc =
 ""
 "";
 
-const char *cpl_bad_doc = "";
+const char *cpl_bad_empty_doc = "";
 
 const char *asset_map_doc =
 ""
@@ -384,52 +384,31 @@ static int test_cpl_parsing(void)
 return 0;
 }
 
-static int test_bad_cpl_parsing(FFIMFCPL **cpl)
-{
-xmlDocPtr doc;
-int ret;
-
-doc = xmlReadMemory(cpl_bad_doc, strlen(cpl_bad_doc), NULL, NULL, 0);
-if (doc == NULL) {
-printf("XML parsing failed.\n");
-return 1;
-}
-
-ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl);
-xmlFreeDoc(doc);
-if (ret) {
-printf("CPL parsing failed.\n");
-return ret;
-}
-
-ff_imf_cpl_free(*cpl);
-*cpl = NULL;
-
-return 0;
-}
-
-static int test_bad_resource_cpl_parsing(FFIMFCPL **cpl)
-{
+static int test_cpl_from_doc(FFIMFCPL **cpl, const char* cpl_doc, int 
should_pass) {
 xmlDocPtr doc;
 int ret;
 
-doc = xmlReadMemory(cpl_bad_resource_doc, strlen(cpl_bad_resource_doc), 
NULL, NULL, 0);
+doc = xmlReadMemory(cpl_doc, strlen(cpl_doc), NULL, NULL, 0);
 if (doc == NULL) {
 printf("XML parsing failed.\n");
-return 1;
+return should_pass;
 }
 
 ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl);
 xmlFreeDoc(doc);
 if (ret) {
 printf("CPL parsing failed.\n");
-return ret;
+if (*cpl) {
+printf("Improper cleanup after failed CPL parsing\n");
+return 1;
+}
+return should_pass;
 }
 
 ff_imf_cpl_free(*cpl);
 *cpl = NULL;
 
-return 0;
+return !should_pass;
 }
 
 static int check_asset_locator_attributes(IMFAssetLocator *asset, 
IMFAssetLocator *expected_asset)
@@ -591,20 +570,13 @@ int main(int argc, char *argv[])
 ret = 1;
 
 printf(" The following should fail \n");
-if (test_bad_cpl_parsing(&cpl) == 0) {
+if (test_cpl_from_doc(&cpl, cpl_bad_empty_doc, 0) != 0)
 ret = 1;
-} else if (cpl) {
-printf("Improper cleanup after failed CPL parsing\n");
-ret = 1;
-}
 printf(" End failing test \n");
 
 printf(" The following should emit errors \n");
-if (test_bad_resource_cpl_parsing(&cpl) != 0) {
-if (cpl)
-printf("Improper cleanup after failed CPL parsing\n");
+if (test_cpl_from_doc(&cpl, cpl_bad_resource_doc, 1) != 0)
 ret = 1;
-}
 printf(" End emission of errors \n");
 
 return ret;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/2] fate/imf: fix memory leak

2023-05-15 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/imf.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index cfd84fb8c8..c02cd87ceb 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -402,6 +402,9 @@ static int test_bad_cpl_parsing(FFIMFCPL **cpl)
 return ret;
 }
 
+ff_imf_cpl_free(*cpl);
+*cpl = NULL;
+
 return 0;
 }
 
@@ -423,6 +426,9 @@ static int test_bad_resource_cpl_parsing(FFIMFCPL **cpl)
 return ret;
 }
 
+ff_imf_cpl_free(*cpl);
+*cpl = NULL;
+
 return 0;
 }
 
@@ -594,8 +600,11 @@ int main(int argc, char *argv[])
 printf(" End failing test \n");
 
 printf(" The following should emit errors \n");
-if (test_bad_resource_cpl_parsing(&cpl) != 0)
+if (test_bad_resource_cpl_parsing(&cpl) != 0) {
+if (cpl)
+printf("Improper cleanup after failed CPL parsing\n");
 ret = 1;
+}
 printf(" End emission of errors \n");
 
 return ret;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 2/2] fate/imf: remove redundant code

2023-05-15 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/imf.c | 38 +-
 1 file changed, 5 insertions(+), 33 deletions(-)

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index a5bdf16645..a23b687c3d 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -257,7 +257,7 @@ const char *cpl_doc =
 ""
 "";
 
-const char *cpl_bad_doc = "";
+const char *cpl_bad_empty_doc = "";
 
 const char *asset_map_doc =
 ""
@@ -384,36 +384,11 @@ static int test_cpl_parsing(void)
 return 0;
 }
 
-static int test_bad_cpl_parsing(FFIMFCPL **cpl)
-{
-xmlDocPtr doc;
-int ret;
-
-doc = xmlReadMemory(cpl_bad_doc, strlen(cpl_bad_doc), NULL, NULL, 0);
-if (doc == NULL) {
-printf("XML parsing failed.\n");
-return 1;
-}
-
-ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl);
-xmlFreeDoc(doc);
-if (ret) {
-printf("CPL parsing failed.\n");
-return ret;
-}
-
-ff_imf_cpl_free(*cpl);
-*cpl = NULL;
-
-return 0;
-}
-
-static int test_bad_resource_cpl_parsing(FFIMFCPL **cpl)
-{
+static int test_bad_cpl(FFIMFCPL **cpl, const char* bad_cpl_doc) {
 xmlDocPtr doc;
 int ret;
 
-doc = xmlReadMemory(cpl_bad_resource_doc, strlen(cpl_bad_resource_doc), 
NULL, NULL, 0);
+doc = xmlReadMemory(bad_cpl_doc, strlen(bad_cpl_doc), NULL, NULL, 0);
 if (doc == NULL) {
 printf("XML parsing failed.\n");
 return 1;
@@ -591,7 +566,7 @@ int main(int argc, char *argv[])
 ret = 1;
 
 printf(" The following should fail \n");
-if (test_bad_cpl_parsing(&cpl) == 0) {
+if (test_bad_cpl(&cpl, cpl_bad_empty_doc) == 0) {
 ret = 1;
 } else if (cpl) {
 printf("Improper cleanup after failed CPL parsing\n");
@@ -600,10 +575,7 @@ int main(int argc, char *argv[])
 printf(" End failing test \n");
 
 printf(" The following should emit errors \n");
-if (test_bad_resource_cpl_parsing(&cpl) != 0) {
-ret = 1;
-} else if (cpl) {
-printf("Improper cleanup after failed CPL parsing\n");
+if (test_bad_cpl(&cpl, cpl_bad_resource_doc) != 0) {
 ret = 1;
 }
 printf(" End emission of errors \n");
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 1/2] fate/imf: fix memory leak

2023-05-15 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/imf.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index cfd84fb8c8..a5bdf16645 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -402,6 +402,9 @@ static int test_bad_cpl_parsing(FFIMFCPL **cpl)
 return ret;
 }
 
+ff_imf_cpl_free(*cpl);
+*cpl = NULL;
+
 return 0;
 }
 
@@ -423,6 +426,9 @@ static int test_bad_resource_cpl_parsing(FFIMFCPL **cpl)
 return ret;
 }
 
+ff_imf_cpl_free(*cpl);
+*cpl = NULL;
+
 return 0;
 }
 
@@ -594,8 +600,12 @@ int main(int argc, char *argv[])
 printf(" End failing test \n");
 
 printf(" The following should emit errors \n");
-if (test_bad_resource_cpl_parsing(&cpl) != 0)
+if (test_bad_resource_cpl_parsing(&cpl) != 0) {
+ret = 1;
+} else if (cpl) {
+printf("Improper cleanup after failed CPL parsing\n");
 ret = 1;
+}
 printf(" End emission of errors \n");
 
 return ret;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1] avformat/imf: clean-up logging

2023-05-06 Thread pal
From: Pierre-Anthony Lemieux 

* consistently use the IMF demuxer AVFormatContext in av_log()
* remove extraneous logging

---
 libavformat/imf.h   |   5 +-
 libavformat/imf_cpl.c   | 183 +++-
 libavformat/imfdec.c|   2 +-
 libavformat/tests/imf.c |   4 +-
 4 files changed, 92 insertions(+), 102 deletions(-)

diff --git a/libavformat/imf.h b/libavformat/imf.h
index 70ed007312..81622ee55e 100644
--- a/libavformat/imf.h
+++ b/libavformat/imf.h
@@ -140,6 +140,7 @@ typedef struct FFIMFCPL {
 
 /**
  * Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.
+ * @param[in] in The context from which the CPL is read, or NULL if no context 
is available.
  * @param[in] doc An XML document from which the CPL is read.
  * @param[out] cpl Pointer to a memory area (allocated by the client), where 
the
  *  function writes a pointer to the newly constructed FFIMFCPL structure (or
@@ -147,7 +148,7 @@ typedef struct FFIMFCPL {
  *  the FFIMFCPL structure using ff_imf_cpl_free().
  * @return A non-zero value in case of an error.
  */
-int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl);
+int ff_imf_parse_cpl_from_xml_dom(AVFormatContext *in, xmlDocPtr doc, FFIMFCPL 
**cpl);
 
 /**
  * Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
@@ -158,7 +159,7 @@ int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL 
**cpl);
  * the FFIMFCPL structure using ff_imf_cpl_free().
  * @return A non-zero value in case of an error.
  */
-int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl);
+int ff_imf_parse_cpl(AVFormatContext *in, FFIMFCPL **cpl);
 
 /**
  * Allocates and initializes an FFIMFCPL data structure.
diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index ad84a68b13..29f5967542 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -76,10 +76,8 @@ int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
 
 xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
 ret = av_uuid_urn_parse(element_text, uuid);
-if (ret) {
-av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
+if (ret)
 ret = AVERROR_INVALIDDATA;
-}
 xmlFree(element_text);
 
 return ret;
@@ -90,10 +88,8 @@ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational 
*rational)
 int ret = 0;
 
 xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
-if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) {
-av_log(NULL, AV_LOG_ERROR, "Invalid rational number\n");
+if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2)
 ret = AVERROR_INVALIDDATA;
-}
 xmlFree(element_text);
 
 return ret;
@@ -104,10 +100,8 @@ int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t 
*number)
 int ret = 0;
 
 xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
-if (sscanf(element_text, "%" PRIu32, number) != 1) {
-av_log(NULL, AV_LOG_ERROR, "Invalid unsigned 32-bit integer");
+if (sscanf(element_text, "%" PRIu32, number) != 1)
 ret = AVERROR_INVALIDDATA;
-}
 xmlFree(element_text);
 
 return ret;
@@ -181,10 +175,8 @@ static int fill_content_title(xmlNodePtr cpl_element, 
FFIMFCPL *cpl)
 {
 xmlNodePtr element = NULL;
 
-if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, 
"ContentTitle"))) {
-av_log(NULL, AV_LOG_ERROR, "ContentTitle element not found in the IMF 
CPL\n");
+if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, 
"ContentTitle")))
 return AVERROR_INVALIDDATA;
-}
 cpl->content_title_utf8 = xmlNodeListGetString(cpl_element->doc,
element->xmlChildrenNode,
1);
@@ -242,22 +234,15 @@ static int fill_timecode(xmlNodePtr cpl_element, FFIMFCPL 
*cpl)
return 0;
 
 element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeDropFrame");
-if (!element) {
-av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
-a TimecodeDropFrame child element\n");
+if (!element)
 return AVERROR_INVALIDDATA;
-}
 
-if (ff_imf_xml_read_boolean(element, &df)) {
-av_log(NULL, AV_LOG_ERROR, "TimecodeDropFrame element is invalid\n");
+if (ff_imf_xml_read_boolean(element, &df))
 return AVERROR_INVALIDDATA;
-}
+
 element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeStartAddress");
-if (!element) {
-av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
-a TimecodeStartAddress child element\n");
+if (!element)
 return AVERROR_INVALIDDATA;
-}
 
 tc_str = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
 ret = parse_cpl_tc_

[FFmpeg-devel] [PATCH 2/2] avformat/tests/imf: add invalid resource test

2023-04-26 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/imf.c | 65 +
 tests/ref/fate/imf  |  2 ++
 2 files changed, 67 insertions(+)

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index 2cacb43f47..cfd84fb8c8 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -218,6 +218,45 @@ const char *cpl_doc =
 ""
 "";
 
+const char *cpl_bad_resource_doc =
+"http://www.smpte-ra.org/schemas/2067-3/2016\"";
+" xmlns:cc=\"http://www.smpte-ra.org/schemas/2067-2/2016\"";
+" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\";>"
+"urn:uuid:8713c020-2489-45f5-a9f7-87be539e20b5"
+"2021-07-13T17:06:22Z"
+"FFMPEG"
+"FFMPEG sample content"
+""
+"  "
+"urn:uuid:8e097bb0-cff7-4969-a692-bad47bfb528f"
+"  "
+""
+""
+"false"
+"24"
+"02:10:01.23"
+""
+"24000 1001"
+""
+""
+"urn:uuid:81fed4e5-9722-400a-b9d1-7f2bd21df4b6"
+""
+""
+"urn:uuid:6ae100b0-92d1-41be-9321-85e0933dfc42"
+"urn:uuid:e8ef9653-565c-479c-8039-82d4547973c5"
+""
+""
+"urn:uuid:7d418acb-07a3-4e57-984c-b8ea2f7de4ec"
+"24"
+
"urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751"
+""
+""
+""
+""
+""
+""
+"";
+
 const char *cpl_bad_doc = "";
 
 const char *asset_map_doc =
@@ -366,6 +405,27 @@ static int test_bad_cpl_parsing(FFIMFCPL **cpl)
 return 0;
 }
 
+static int test_bad_resource_cpl_parsing(FFIMFCPL **cpl)
+{
+xmlDocPtr doc;
+int ret;
+
+doc = xmlReadMemory(cpl_bad_resource_doc, strlen(cpl_bad_resource_doc), 
NULL, NULL, 0);
+if (doc == NULL) {
+printf("XML parsing failed.\n");
+return 1;
+}
+
+ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl);
+xmlFreeDoc(doc);
+if (ret) {
+printf("CPL parsing failed.\n");
+return ret;
+}
+
+return 0;
+}
+
 static int check_asset_locator_attributes(IMFAssetLocator *asset, 
IMFAssetLocator *expected_asset)
 {
 
@@ -533,5 +593,10 @@ int main(int argc, char *argv[])
 }
 printf(" End failing test \n");
 
+printf(" The following should emit errors \n");
+if (test_bad_resource_cpl_parsing(&cpl) != 0)
+ret = 1;
+printf(" End emission of errors \n");
+
 return ret;
 }
diff --git a/tests/ref/fate/imf b/tests/ref/fate/imf
index 5093167bc7..fdfed8ac17 100644
--- a/tests/ref/fate/imf
+++ b/tests/ref/fate/imf
@@ -53,3 +53,5 @@ For asset: 4:
  The following should fail 
 CPL parsing failed.
  End failing test 
+ The following should emit errors 
+ End emission of errors 
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] avformat/imf: fix invalid resource handling

2023-04-26 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imf_cpl.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index ad84a68b13..a7cf5fa360 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -608,11 +608,10 @@ static int push_main_audio_sequence(xmlNodePtr 
audio_sequence_elem, FFIMFCPL *cp
 ret = fill_trackfile_resource(resource_elem,
   &vt->resources[vt->resource_count],
   cpl);
-vt->resource_count++;
-if (ret) {
+if (ret)
 av_log(NULL, AV_LOG_ERROR, "Invalid Resource\n");
-continue;
-}
+else
+vt->resource_count++;
 
 resource_elem = xmlNextElementSibling(resource_elem);
 }
@@ -691,11 +690,10 @@ static int push_main_image_2d_sequence(xmlNodePtr 
image_sequence_elem, FFIMFCPL
 ret = fill_trackfile_resource(resource_elem,
   
&cpl->main_image_2d_track->resources[cpl->main_image_2d_track->resource_count],
   cpl);
-cpl->main_image_2d_track->resource_count++;
-if (ret) {
+if (ret)
 av_log(NULL, AV_LOG_ERROR, "Invalid Resource\n");
-continue;
-}
+else
+cpl->main_image_2d_track->resource_count++;
 
 resource_elem = xmlNextElementSibling(resource_elem);
 }
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] fate/imfdec: add audio test

2023-01-10 Thread pal
From: Pierre-Anthony Lemieux 

Improves the test material by using audio and video resources whose respective
temporal boundaries do not line up.

https://www.sandflow.com/public/countdown-audio-2023-01-10-2.zip

---
 tests/fate/imf.mak|   3 +
 tests/ref/fate/imf-cpl-with-audio | 207 ++
 2 files changed, 210 insertions(+)
 create mode 100644 tests/ref/fate/imf-cpl-with-audio

diff --git a/tests/fate/imf.mak b/tests/fate/imf.mak
index feb54d1361..49ab35e7d9 100644
--- a/tests/fate/imf.mak
+++ b/tests/fate/imf.mak
@@ -1,6 +1,9 @@
 FATE_IMF += fate-imf-cpl-with-repeat
 fate-imf-cpl-with-repeat: CMD = framecrc -f imf -i 
$(TARGET_SAMPLES)/imf/countdown/CPL_bb2ce11c-1bb6-4781-8e69-967183d02b9b.xml 
-c:v copy
 
+FATE_IMF += fate-imf-cpl-with-audio
+fate-imf-cpl-with-audio: CMD = framecrc -f imf -i 
$(TARGET_SAMPLES)/imf/countdown-audio/CPL_688f4f63-a317-4271-99bf-51444ff39c5b.xml
 -c:a copy
+
 FATE_SAMPLES_FFMPEG-$(CONFIG_IMF_DEMUXER) += $(FATE_IMF)
 
 fate-imfdec: $(FATE_IMF)
diff --git a/tests/ref/fate/imf-cpl-with-audio 
b/tests/ref/fate/imf-cpl-with-audio
new file mode 100644
index 00..b8d70ca5d8
--- /dev/null
+++ b/tests/ref/fate/imf-cpl-with-audio
@@ -0,0 +1,207 @@
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 640x360
+#sar 0: 0/1
+#tb 1: 1/48000
+#media_type 1: audio
+#codec_id 1: pcm_s24le
+#sample_rate 1: 48000
+#channel_layout_name 1: stereo
+0,  0,  0,1,  1382400, 0x6a2c410c
+1,  0,  0, 1920,11520, 0x974f4bab
+1,   1920,   1920, 1920,11520, 0xdf793f69
+0,  1,  1,1,  1382400, 0x5f0c67d2
+1,   3840,   3840, 1920,11520, 0xfd69559a
+0,  2,  2,1,  1382400, 0x408e1262
+1,   5760,   5760, 1920,11520, 0x28fa469b
+0,  3,  3,1,  1382400, 0x3567d455
+1,   7680,   7680, 1920,11520, 0xe49161cf
+0,  4,  4,1,  1382400, 0x2312e68b
+1,   9600,   9600, 1920,11520, 0xb92c49ae
+0,  5,  5,1,  1382400, 0xe3d84ec2
+1,  11520,  11520, 1920,11520, 0xd2b75d46
+0,  6,  6,1,  1382400, 0xdbb3ab8c
+1,  13440,  13440, 1920,11520, 0xa13b5a9b
+0,  7,  7,1,  1382400, 0xeb250513
+1,  15360,  15360, 1920,11520, 0xfe804299
+0,  8,  8,1,  1382400, 0x26c3c8c0
+1,  17280,  17280, 1920,11520, 0x7a8654d4
+0,  9,  9,1,  1382400, 0xbc41a23e
+1,  19200,  19200, 1920,11520, 0x1a2e48a4
+0, 10, 10,1,  1382400, 0x49d6a8de
+1,  21120,  21120, 1920,11520, 0x20504669
+0, 11, 11,1,  1382400, 0x5e05cfa4
+1,  23040,  23040,  960, 5760, 0x74bf38f6
+0, 12, 12,1,  1382400, 0x01327a34
+1,  24000,  24000, 1920,11520, 0x974f4bab
+1,  25920,  25920, 1920,11520, 0xdf793f69
+0, 13, 13,1,  1382400, 0x06ce3c36
+1,  27840,  27840, 1920,11520, 0xfd69559a
+0, 14, 14,1,  1382400, 0x6aa24e6c
+1,  29760,  29760, 1920,11520, 0x28fa469b
+0, 15, 15,1,  1382400, 0x55d8b694
+1,  31680,  31680, 1920,11520, 0xe49161cf
+0, 16, 16,1,  1382400, 0xcc6f136d
+1,  33600,  33600, 1920,11520, 0xb92c49ae
+0, 17, 17,1,  1382400, 0xe92b6ce5
+1,  35520,  35520, 1920,11520, 0xd2b75d46
+0, 18, 18,1,  1382400, 0x664d30a1
+1,  37440,  37440, 1920,11520, 0xa13b5a9b
+0, 19, 19,1,  1382400, 0x09d80a1f
+1,  39360,  39360, 1920,11520, 0xfe804299
+0, 20, 20,1,  1382400, 0x2b58536e
+1,  41280,  41280, 1920,11520, 0x7a8654d4
+0, 21, 21,1,  1382400, 0xf24b7a34
+1,  43200,  43200, 1920,11520, 0x1a2e48a4
+0, 22, 22,1,  1382400, 0xe2a524c4
+1,  45120,  45120, 1920,11520, 0x20504669
+0, 23, 23,1,  1382400, 0xe841e6b7
+1,  47040,  47040, 1920,11520, 0x7ad44ba6
+0, 24, 24,1,  1382400, 0x6a2c410c
+1,  48960,  48960, 1920,11520, 0xc8934994
+0, 25, 25,1,  1382400, 0x5f0c67d2
+1,  50880,  50880, 1920,11520, 0x07ad70bb
+0, 26, 26,1,  1382400, 0x408e1262
+1,  52800,  52800, 1920,11520, 0x1ba75d9a
+0, 27, 27,1,  1382400, 0x3567d455
+1,  54720,  54720, 1920,11520, 0x0d4a435f
+0, 28, 28,1,  1382400, 0x2312e68b
+1,  56640,  56640, 1920,11520, 0x288b6c85
+0,

[FFmpeg-devel] [PATCH v2 3/3] fate/imfdec: remove imf experimental flag

2023-01-05 Thread pal
From: Pierre-Anthony Lemieux 

---
 tests/fate/imf.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/fate/imf.mak b/tests/fate/imf.mak
index feb54d1361..d64882f89e 100644
--- a/tests/fate/imf.mak
+++ b/tests/fate/imf.mak
@@ -1,5 +1,5 @@
 FATE_IMF += fate-imf-cpl-with-repeat
-fate-imf-cpl-with-repeat: CMD = framecrc -f imf -i 
$(TARGET_SAMPLES)/imf/countdown/CPL_bb2ce11c-1bb6-4781-8e69-967183d02b9b.xml 
-c:v copy
+fate-imf-cpl-with-repeat: CMD = framecrc -i 
$(TARGET_SAMPLES)/imf/countdown/CPL_bb2ce11c-1bb6-4781-8e69-967183d02b9b.xml 
-c:v copy
 
 FATE_SAMPLES_FFMPEG-$(CONFIG_IMF_DEMUXER) += $(FATE_IMF)
 
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/3] avformat/imfdec: remove the experimental flag

2023-01-05 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 03de9ce151..a92686e93b 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -1018,7 +1018,7 @@ static const AVClass imf_class = {
 const AVInputFormat ff_imf_demuxer = {
 .name   = "imf",
 .long_name  = NULL_IF_CONFIG_SMALL("IMF (Interoperable Master 
Format)"),
-.flags  = AVFMT_EXPERIMENTAL | AVFMT_NO_BYTE_SEEK,
+.flags  = AVFMT_NO_BYTE_SEEK,
 .flags_internal = FF_FMT_INIT_CLEANUP,
 .priv_class = &imf_class,
 .priv_data_size = sizeof(IMFContext),
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/3] doc: improve IMF demuxer documentation

2023-01-05 Thread pal
From: Pierre-Anthony Lemieux 

---
 doc/demuxers.texi | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 2b6dd86c2a..75c142935e 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -289,7 +289,15 @@ This demuxer accepts the following option:
 
 Interoperable Master Format demuxer.
 
-This demuxer presents audio and video streams found in an IMF Composition.
+This demuxer presents audio and video streams found in an IMF Composition, as
+specified in @url{https://doi.org/10.5594/SMPTE.ST2067-2.2020, SMPTE ST 
2067-2}.
+
+@example
+ffmpeg [-assetmaps ,,...] -i  ...
+@end example
+
+If @code{-assetmaps} is not specified, the demuxer looks for a file called
+@file{ASSETMAP.xml} in the same directory as the CPL.
 
 @section flv, live_flv, kux
 
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1] fate/imfdec: add audio test

2022-12-29 Thread pal
From: Pierre-Anthony Lemieux 

Adds an audio test for the IMF demuxer.

FATE content at https://www.sandflow.com/public/countdown-audio.zip

---
 tests/fate/imf.mak|   3 +
 tests/ref/fate/imf-cpl-with-audio | 207 ++
 2 files changed, 210 insertions(+)
 create mode 100644 tests/ref/fate/imf-cpl-with-audio

diff --git a/tests/fate/imf.mak b/tests/fate/imf.mak
index feb54d1361..49ab35e7d9 100644
--- a/tests/fate/imf.mak
+++ b/tests/fate/imf.mak
@@ -1,6 +1,9 @@
 FATE_IMF += fate-imf-cpl-with-repeat
 fate-imf-cpl-with-repeat: CMD = framecrc -f imf -i 
$(TARGET_SAMPLES)/imf/countdown/CPL_bb2ce11c-1bb6-4781-8e69-967183d02b9b.xml 
-c:v copy
 
+FATE_IMF += fate-imf-cpl-with-audio
+fate-imf-cpl-with-audio: CMD = framecrc -f imf -i 
$(TARGET_SAMPLES)/imf/countdown-audio/CPL_688f4f63-a317-4271-99bf-51444ff39c5b.xml
 -c:a copy
+
 FATE_SAMPLES_FFMPEG-$(CONFIG_IMF_DEMUXER) += $(FATE_IMF)
 
 fate-imfdec: $(FATE_IMF)
diff --git a/tests/ref/fate/imf-cpl-with-audio 
b/tests/ref/fate/imf-cpl-with-audio
new file mode 100644
index 00..0a1d87631a
--- /dev/null
+++ b/tests/ref/fate/imf-cpl-with-audio
@@ -0,0 +1,207 @@
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 640x360
+#sar 0: 0/1
+#tb 1: 1/48000
+#media_type 1: audio
+#codec_id 1: pcm_s24le
+#sample_rate 1: 48000
+#channel_layout_name 1: stereo
+0,  0,  0,1,  1382400, 0x6a2c410c
+1,  0,  0, 1920,11520, 0x974f4bab
+1,   1920,   1920, 1920,11520, 0xdf793f69
+0,  1,  1,1,  1382400, 0x5f0c67d2
+1,   3840,   3840, 1920,11520, 0xfd69559a
+0,  2,  2,1,  1382400, 0x408e1262
+1,   5760,   5760, 1920,11520, 0x28fa469b
+0,  3,  3,1,  1382400, 0x3567d455
+1,   7680,   7680, 1920,11520, 0xe49161cf
+0,  4,  4,1,  1382400, 0x2312e68b
+1,   9600,   9600, 1920,11520, 0xb92c49ae
+0,  5,  5,1,  1382400, 0xe3d84ec2
+1,  11520,  11520, 1920,11520, 0xd2b75d46
+0,  6,  6,1,  1382400, 0xdbb3ab8c
+1,  13440,  13440, 1920,11520, 0xa13b5a9b
+0,  7,  7,1,  1382400, 0xeb250513
+1,  15360,  15360, 1920,11520, 0xfe804299
+0,  8,  8,1,  1382400, 0x26c3c8c0
+1,  17280,  17280, 1920,11520, 0x7a8654d4
+0,  9,  9,1,  1382400, 0xbc41a23e
+1,  19200,  19200, 1920,11520, 0x1a2e48a4
+0, 10, 10,1,  1382400, 0x49d6a8de
+1,  21120,  21120, 1920,11520, 0x20504669
+0, 11, 11,1,  1382400, 0x5e05cfa4
+1,  23040,  23040,  960, 5760, 0x74bf38f6
+0, 12, 12,1,  1382400, 0x01327a34
+1,  24000,  24000, 1920,11520, 0x974f4bab
+1,  25920,  25920, 1920,11520, 0xdf793f69
+0, 13, 13,1,  1382400, 0x06ce3c36
+1,  27840,  27840, 1920,11520, 0xfd69559a
+0, 14, 14,1,  1382400, 0x6aa24e6c
+1,  29760,  29760, 1920,11520, 0x28fa469b
+0, 15, 15,1,  1382400, 0x55d8b694
+1,  31680,  31680, 1920,11520, 0xe49161cf
+0, 16, 16,1,  1382400, 0xcc6f136d
+1,  33600,  33600, 1920,11520, 0xb92c49ae
+0, 17, 17,1,  1382400, 0xe92b6ce5
+1,  35520,  35520, 1920,11520, 0xd2b75d46
+0, 18, 18,1,  1382400, 0x664d30a1
+1,  37440,  37440, 1920,11520, 0xa13b5a9b
+0, 19, 19,1,  1382400, 0x09d80a1f
+1,  39360,  39360, 1920,11520, 0xfe804299
+0, 20, 20,1,  1382400, 0x2b58536e
+1,  41280,  41280, 1920,11520, 0x7a8654d4
+0, 21, 21,1,  1382400, 0xf24b7a34
+1,  43200,  43200, 1920,11520, 0x1a2e48a4
+0, 22, 22,1,  1382400, 0xe2a524c4
+1,  45120,  45120, 1920,11520, 0x20504669
+0, 23, 23,1,  1382400, 0xe841e6b7
+1,  47040,  47040, 1920,11520, 0x7ad44ba6
+0, 24, 24,1,  1382400, 0x6a2c410c
+1,  48960,  48960, 1920,11520, 0xc8934994
+0, 25, 25,1,  1382400, 0x5f0c67d2
+1,  50880,  50880, 1920,11520, 0x07ad70bb
+0, 26, 26,1,  1382400, 0x408e1262
+1,  52800,  52800, 1920,11520, 0x1ba75d9a
+0, 27, 27,1,  1382400, 0x3567d455
+1,  54720,  54720, 1920,11520, 0x0d4a435f
+0, 28, 28,1,  1382400, 0x2312e68b
+1,  56640,  56640, 1920,11520, 0x288b6c85
+0, 29, 29,1,  1382400, 0xe3d84ec2
+1,  58560,  585

[FFmpeg-devel] [PATCH v1] fate/jpeg2000: add JPEG 2000 tests using ITU/ISO conformance materials

2022-12-26 Thread pal
From: Pierre-Anthony Lemieux 

Adds JPEG 2000 decoder tests using materials from the conformance suite 
specified in
Rec. ITU-T T.803 | ISO/IEC 15444-4. The jpeg2000dec-ds0_ht_01_b11 test assumes 
that
patchset https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=8078 has been 
applied.

The test materials are available at https://gitlab.com/wg1/htj2k-codestreams

---
 tests/Makefile   |  1 +
 tests/fate/jpeg2000.mak  | 64 
 tests/ref/fate/jpeg2000dec-ds0_ht_01_b11 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_01 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_02 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_03 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_04 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_05 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_07 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_08 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_09 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_11 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_12 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_14 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_15 |  6 +++
 tests/ref/fate/jpeg2000dec-p0_16 |  6 +++
 16 files changed, 149 insertions(+)
 create mode 100644 tests/fate/jpeg2000.mak
 create mode 100644 tests/ref/fate/jpeg2000dec-ds0_ht_01_b11
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_01
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_02
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_03
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_04
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_05
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_07
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_08
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_09
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_11
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_12
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_14
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_15
 create mode 100644 tests/ref/fate/jpeg2000dec-p0_16

diff --git a/tests/Makefile b/tests/Makefile
index 1d50e1d175..d80065a9bf 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -200,6 +200,7 @@ include $(SRC_PATH)/tests/fate/id3v2.mak
 include $(SRC_PATH)/tests/fate/image.mak
 include $(SRC_PATH)/tests/fate/imf.mak
 include $(SRC_PATH)/tests/fate/indeo.mak
+include $(SRC_PATH)/tests/fate/jpeg2000.mak
 include $(SRC_PATH)/tests/fate/libavcodec.mak
 include $(SRC_PATH)/tests/fate/libavdevice.mak
 include $(SRC_PATH)/tests/fate/libavformat.mak
diff --git a/tests/fate/jpeg2000.mak b/tests/fate/jpeg2000.mak
new file mode 100644
index 00..2c22706ad3
--- /dev/null
+++ b/tests/fate/jpeg2000.mak
@@ -0,0 +1,64 @@
+# The following tests are based on the conformance suite specified in
+# Rec. ITU-T T.803 | ISO/IEC 15444-4 available at the following URLs:
+# * https://gitlab.com/wg1/htj2k-codestreams
+# * https://www.itu.int/rec/T-REC-T.803/en
+# * https://www.iso.org/standard/81574.html
+#
+# Notes:
+# * p0_06.j2k is not included because it uses a pixel format that is not
+#   supported (4:2:2:1)
+# * p0_10.j2k is not included because errors are emitted during decoding and
+#   there are significant deviations from the reference image in the 
bottom-left
+#   quadrant
+# * p0_13.j2k is not included because it uses a pixel format that is not
+#   supported (257 color channels)
+# * p0_04.j2k and p0_05.j2k exceed the error thresholds specified in the
+#   conformance suite
+# * p0_09.j2k matches the reference image exactly when bitexact is not used, 
but
+#   exceed the error thresholds specified in the conformance suite when 
bitexact
+#   is used
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_01
+fate-jpeg2000dec-p0_01: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_01.j2k
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_02
+fate-jpeg2000dec-p0_02: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_02.j2k
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_03
+fate-jpeg2000dec-p0_03: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_03.j2k
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_04
+fate-jpeg2000dec-p0_04: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_04.j2k
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_05
+fate-jpeg2000dec-p0_05: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_05.j2k
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_07
+fate-jpeg2000dec-p0_07: CMD = framecrc -flags +bitexact -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_07.j2k
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_08
+fate-jpeg2000dec-p0_08: CMD = framecrc -flags +bitexact -lowres 1 -i 
$(TARGET_SAMPLES)/jpeg2000/itu-iso/codestreams_profile0/p0_08.j2k
+
+FATE_JPEG2000DEC += fate-jpeg2000dec-p0_09
+fate-jpeg2000dec-p0_09: CMD = framecrc -flags +bitexact -i 
$(TARGET_

[FFmpeg-devel] [PATCH 2/2] doc: improve IMF demuxer documentation

2022-11-03 Thread pal
From: Pierre-Anthony Lemieux 

---
 doc/demuxers.texi | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 2b6dd86c2a..75c142935e 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -289,7 +289,15 @@ This demuxer accepts the following option:
 
 Interoperable Master Format demuxer.
 
-This demuxer presents audio and video streams found in an IMF Composition.
+This demuxer presents audio and video streams found in an IMF Composition, as
+specified in @url{https://doi.org/10.5594/SMPTE.ST2067-2.2020, SMPTE ST 
2067-2}.
+
+@example
+ffmpeg [-assetmaps ,,...] -i  ...
+@end example
+
+If @code{-assetmaps} is not specified, the demuxer looks for a file called
+@file{ASSETMAP.xml} in the same directory as the CPL.
 
 @section flv, live_flv, kux
 
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] avformat/imfdec: remove the experimental flag

2022-11-03 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 03de9ce151..a92686e93b 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -1018,7 +1018,7 @@ static const AVClass imf_class = {
 const AVInputFormat ff_imf_demuxer = {
 .name   = "imf",
 .long_name  = NULL_IF_CONFIG_SMALL("IMF (Interoperable Master 
Format)"),
-.flags  = AVFMT_EXPERIMENTAL | AVFMT_NO_BYTE_SEEK,
+.flags  = AVFMT_NO_BYTE_SEEK,
 .flags_internal = FF_FMT_INIT_CLEANUP,
 .priv_class = &imf_class,
 .priv_data_size = sizeof(IMFContext),
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 3/3] avformat/imfdec: variable initialiaztion cosmetics

2022-10-02 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imf_cpl.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index 183e6dd84e..ad84a68b13 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -72,10 +72,9 @@ xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr 
parent, const char *n
 
 int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
 {
-xmlChar *element_text = NULL;
 int ret = 0;
 
-element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
 ret = av_uuid_urn_parse(element_text, uuid);
 if (ret) {
 av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
@@ -88,10 +87,9 @@ int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
 
 int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational)
 {
-xmlChar *element_text = NULL;
 int ret = 0;
 
-element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
 if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) {
 av_log(NULL, AV_LOG_ERROR, "Invalid rational number\n");
 ret = AVERROR_INVALIDDATA;
@@ -103,10 +101,9 @@ int ff_imf_xml_read_rational(xmlNodePtr element, 
AVRational *rational)
 
 int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number)
 {
-xmlChar *element_text = NULL;
 int ret = 0;
 
-element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
 if (sscanf(element_text, "%" PRIu32, number) != 1) {
 av_log(NULL, AV_LOG_ERROR, "Invalid unsigned 32-bit integer");
 ret = AVERROR_INVALIDDATA;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/3] avformat/tests/imf: add CPL timecode test

2022-10-02 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/imf.c | 7 +++
 tests/ref/fate/imf  | 1 +
 2 files changed, 8 insertions(+)

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index a71de692f9..2cacb43f47 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -70,6 +70,11 @@ const char *cpl_doc =
 "urn:uuid:8e097bb0-cff7-4969-a692-bad47bfb528f"
 "  "
 ""
+""
+"false"
+"24"
+"02:10:01.23"
+""
 "24000 1001"
 ""
 ""
@@ -288,6 +293,7 @@ static int test_cpl_parsing(void)
 {
 xmlDocPtr doc;
 FFIMFCPL *cpl;
+char tc_buf[AV_TIMECODE_STR_SIZE];
 int ret;
 
 doc = xmlReadMemory(cpl_doc, strlen(cpl_doc), NULL, NULL, 0);
@@ -306,6 +312,7 @@ static int test_cpl_parsing(void)
 printf("%s\n", cpl->content_title_utf8);
 printf(AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->id_uuid));
 printf("%i %i\n", cpl->edit_rate.num, cpl->edit_rate.den);
+printf("%s\n", av_timecode_make_string(cpl->tc, tc_buf, 0));
 
 printf("Marker resource count: %" PRIu32 "\n", 
cpl->main_markers_track->resource_count);
 for (uint32_t i = 0; i < cpl->main_markers_track->resource_count; i++) {
diff --git a/tests/ref/fate/imf b/tests/ref/fate/imf
index 90b461dc5d..5093167bc7 100644
--- a/tests/ref/fate/imf
+++ b/tests/ref/fate/imf
@@ -1,6 +1,7 @@
 FFMPEG sample content
 urn:uuid:8713c020-2489-45f5-a9f7-87be539e20b5
 24000 1001
+02:10:01:23
 Marker resource count: 2
 Marker resource 0
   Marker 0
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/3] avformat/imfdec: use CPL start timecode if available

2022-10-02 Thread pal
From: Pierre-Anthony Lemieux 

The IMF CPL contains an optional timecode start address. This patch reads the
latter, if present, into the context's timecode metadata parameter.
This addresses https://trac.ffmpeg.org/ticket/9842.

---
 libavformat/imf.h |   2 +
 libavformat/imf_cpl.c | 106 ++
 libavformat/imfdec.c  |  11 +
 3 files changed, 119 insertions(+)

diff --git a/libavformat/imf.h b/libavformat/imf.h
index 4271cd9582..70ed007312 100644
--- a/libavformat/imf.h
+++ b/libavformat/imf.h
@@ -59,6 +59,7 @@
 #include "libavformat/avio.h"
 #include "libavutil/rational.h"
 #include "libavutil/uuid.h"
+#include "libavutil/timecode.h"
 #include 
 
 /**
@@ -130,6 +131,7 @@ typedef struct FFIMFCPL {
 AVUUID id_uuid;   /**< CompositionPlaylist/Id 
element */
 xmlChar *content_title_utf8; /**< 
CompositionPlaylist/ContentTitle element */
 AVRational edit_rate;/**< 
CompositionPlaylist/EditRate element */
+AVTimecode *tc;  /**< 
CompositionPlaylist/CompositionTimecode element */
 FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual 
Track */
 FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual 
Track */
 uint32_t main_audio_track_count; /**< Number of Main Audio 
Virtual Tracks */
diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index 474db6b7f5..183e6dd84e 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -116,6 +116,22 @@ int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t 
*number)
 return ret;
 }
 
+static int ff_imf_xml_read_boolean(xmlNodePtr element, int *value)
+{
+int ret = 0;
+
+xmlChar *element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+if (xmlStrcmp(element_text, "true") == 0 || xmlStrcmp(element_text, "1") 
== 0)
+*value = 1;
+else if (xmlStrcmp(element_text, "false") == 0 || xmlStrcmp(element_text, 
"0") == 0)
+*value = 0;
+else
+ret = 1;
+xmlFree(element_text);
+
+return ret;
+}
+
 static void imf_base_virtual_track_init(FFIMFBaseVirtualTrack *track)
 {
 memset(track->id_uuid, 0, sizeof(track->id_uuid));
@@ -179,6 +195,90 @@ static int fill_content_title(xmlNodePtr cpl_element, 
FFIMFCPL *cpl)
 return 0;
 }
 
+static int digit_to_int(char digit)
+{
+if (digit >= '0' && digit <= '9')
+return digit - '0';
+return -1;
+}
+
+/**
+ * Parses a string that conform to the TimecodeType used in IMF CPL and defined
+ * in SMPTE ST 2067-3.
+ * @param[in] s string to parse
+ * @param[out] tc_comps pointer to an array of 4 integers where the parsed HH,
+ *  MM, SS and FF fields of the timecode are returned.
+ * @return 0 on success, < 0 AVERROR code on error.
+ */
+static int parse_cpl_tc_type(const char *s, int *tc_comps)
+{
+if (av_strnlen(s, 11) != 11)
+return AVERROR(EINVAL);
+
+for (int i = 0; i < 4; i++) {
+int hi;
+int lo;
+
+hi = digit_to_int(s[i * 3]);
+lo = digit_to_int(s[i * 3 + 1]);
+
+if (hi == -1 || lo == -1)
+return AVERROR(EINVAL);
+
+tc_comps[i] = 10 * hi + lo;
+}
+
+return 0;
+}
+
+static int fill_timecode(xmlNodePtr cpl_element, FFIMFCPL *cpl)
+{
+xmlNodePtr tc_element = NULL;
+xmlNodePtr element = NULL;
+xmlChar *tc_str = NULL;
+int df = 0;
+int comps[4];
+int ret = 0;
+
+tc_element = ff_imf_xml_get_child_element_by_name(cpl_element, 
"CompositionTimecode");
+if (!tc_element)
+   return 0;
+
+element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeDropFrame");
+if (!element) {
+av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
+a TimecodeDropFrame child element\n");
+return AVERROR_INVALIDDATA;
+}
+
+if (ff_imf_xml_read_boolean(element, &df)) {
+av_log(NULL, AV_LOG_ERROR, "TimecodeDropFrame element is invalid\n");
+return AVERROR_INVALIDDATA;
+}
+element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeStartAddress");
+if (!element) {
+av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
+a TimecodeStartAddress child element\n");
+return AVERROR_INVALIDDATA;
+}
+
+tc_str = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
+ret = parse_cpl_tc_type(tc_str, comps);
+xmlFree(tc_str);
+if (ret)
+return ret;
+
+cpl->tc = av_malloc(sizeof(AVTimecode));
+if (!cpl->tc)
+return AVERROR(ENOMEM);
+ret = av_timecode_init_from_components(cpl->tc, cpl->edit_rate,
+   df ? AV_TIMECODE_FLAG_DROPFRAME : 0,
+   comps[0], comps[1], comps[2], 
comps[3],
+

[FFmpeg-devel] [PATCH v2] format/imfdec: improve error handling when selecting tracks for playback

2022-09-19 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 5bbe7a53f8..9ba8b6de8b 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -681,8 +681,11 @@ static IMFVirtualTrackPlaybackCtx 
*get_next_track_with_minimum_timestamp(AVForma
 {
 IMFContext *c = s->priv_data;
 IMFVirtualTrackPlaybackCtx *track;
-
 AVRational minimum_timestamp = av_make_q(INT32_MAX, 1);
+
+if (!c->track_count)
+return NULL;
+
 for (uint32_t i = c->track_count; i > 0; i--) {
 av_log(s, AV_LOG_TRACE, "Compare track %d timestamp " AVRATIONAL_FORMAT
" to minimum " AVRATIONAL_FORMAT
@@ -697,8 +700,6 @@ static IMFVirtualTrackPlaybackCtx 
*get_next_track_with_minimum_timestamp(AVForma
 }
 }
 
-av_log(s, AV_LOG_DEBUG, "Found next track to read: %d (timestamp: %lf / 
%lf)\n",
-   track->index, av_q2d(track->current_timestamp), 
av_q2d(minimum_timestamp));
 return track;
 }
 
@@ -761,6 +762,14 @@ static int imf_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 track = get_next_track_with_minimum_timestamp(s);
 
+if (!track) {
+av_log(s, AV_LOG_ERROR, "No track found for playback\n");
+return AVERROR_INVALIDDATA;
+}
+
+av_log(s, AV_LOG_DEBUG, "Found track %d to read at timestamp %lf\n",
+   track->index, av_q2d(track->current_timestamp));
+
 ret = get_resource_context_for_timestamp(s, track, &resource);
 if (ret)
 return ret;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] MAINTAINERS: add maintainer for the imf demuxer

2022-09-15 Thread pal
From: Pierre-Anthony Lemieux 

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index ed2ec0b90c..2d37f0b86a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -436,6 +436,7 @@ Muxers/Demuxers:
   idcin.c   Mike Melanson
   idroqdec.cMike Melanson
   iff.c Jaikrishnan Menon
+  imf*  Pierre-Anthony Lemieux
   img2*.c   Michael Niedermayer
   ipmovie.c Mike Melanson
   ircam*Paul B Mahol
@@ -633,6 +634,7 @@ Nikolay Aleksandrov   8978 1D8C FB71 588E 4B27 EAA8 
C4F0 B5FC E011 13B1
 Panagiotis Issaris6571 13A3 33D9 3726 F728 AA98 F643 B12E ECF3 E029
 Peter RossA907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B
 Philip Langdale   5DC5 8D66 5FBA 3A43 18EC 045E F8D6 B194 6A75 682E
+Pierre-Anthony Lemieux (pal)  F4B3 9492 E6F2 E4AF AEC8 46CB 698F A1F0 F8D4 EED4
 Ramiro Polla  7859 C65B 751B 1179 792E DAE8 8E95 8B2F 9B6C 5700
 Reimar Doeffinger C61D 16E5 9E2C D10C 8958 38A4 0899 A2B9 06D4 D9C7
 Reinhard Tartler  9300 5DC2 7E87 6C37 ED7B CA9A 9808 3544 9453 48A4
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] format/imfdec: improve error handling when selecting tracks for playback

2022-09-07 Thread pal
From: Pierre-Anthony Lemieux 

Addresses coverity 1512414

---
 libavformat/imfdec.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 5bbe7a53f8..58b1455c9f 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -681,8 +681,11 @@ static IMFVirtualTrackPlaybackCtx 
*get_next_track_with_minimum_timestamp(AVForma
 {
 IMFContext *c = s->priv_data;
 IMFVirtualTrackPlaybackCtx *track;
+AVRational minimum_timestamp = av_make_q(INT_MAX, 1);
+
+if (!c->track_count)
+return NULL;
 
-AVRational minimum_timestamp = av_make_q(INT32_MAX, 1);
 for (uint32_t i = c->track_count; i > 0; i--) {
 av_log(s, AV_LOG_TRACE, "Compare track %d timestamp " AVRATIONAL_FORMAT
" to minimum " AVRATIONAL_FORMAT
@@ -697,8 +700,6 @@ static IMFVirtualTrackPlaybackCtx 
*get_next_track_with_minimum_timestamp(AVForma
 }
 }
 
-av_log(s, AV_LOG_DEBUG, "Found next track to read: %d (timestamp: %lf / 
%lf)\n",
-   track->index, av_q2d(track->current_timestamp), 
av_q2d(minimum_timestamp));
 return track;
 }
 
@@ -761,6 +762,14 @@ static int imf_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 
 track = get_next_track_with_minimum_timestamp(s);
 
+if (!track) {
+av_log(s, AV_LOG_ERROR, "No track found for playback\n");
+return AVERROR_INVALIDDATA;
+}
+
+av_log(s, AV_LOG_DEBUG, "Found track %d to read at timestamp %lf\n",
+   track->index, av_q2d(track->current_timestamp));
+
 ret = get_resource_context_for_timestamp(s, track, &resource);
 if (ret)
 return ret;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/2] fate/mxf: add JPEG 2000 test

2022-09-06 Thread pal
From: Pierre-Anthony Lemieux 

---
 tests/fate/mxf.mak   |  4 ++
 tests/ref/fate/mxf-probe-j2k | 78 
 2 files changed, 82 insertions(+)
 create mode 100644 tests/ref/fate/mxf-probe-j2k

diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak
index 3ab936b5de..b2e86b49a8 100644
--- a/tests/fate/mxf.mak
+++ b/tests/fate/mxf.mak
@@ -29,6 +29,10 @@ FATE_MXF_PROBE-$(call ENCDEC, DNXHD, MXF) += 
fate-mxf-probe-dnxhd
 fate-mxf-probe-dnxhd: SRC = $(TARGET_SAMPLES)/mxf/multiple_components.mxf
 fate-mxf-probe-dnxhd: CMD = run $(PROBE_FORMAT_STREAMS_COMMAND) -i "$(SRC)"
 
+FATE_MXF_PROBE-$(call DEMDEC, MXF, JPEG2000) += fate-mxf-probe-j2k
+fate-mxf-probe-j2k: SRC = $(TARGET_SAMPLES)/imf/countdown/countdown-small.mxf
+fate-mxf-probe-j2k: CMD = run $(PROBE_FORMAT_STREAMS_COMMAND) -i "$(SRC)"
+
 FATE_MXF_PROBE-$(call ENCDEC2, DVVIDEO, PCM_S16LE, MXF) += fate-mxf-probe-dv25
 fate-mxf-probe-dv25: SRC = $(TARGET_SAMPLES)/mxf/Avid-5.mxf
 fate-mxf-probe-dv25: CMD = run $(PROBE_FORMAT_STREAMS_COMMAND) -i "$(SRC)"
diff --git a/tests/ref/fate/mxf-probe-j2k b/tests/ref/fate/mxf-probe-j2k
new file mode 100644
index 00..2dbf2ac37d
--- /dev/null
+++ b/tests/ref/fate/mxf-probe-j2k
@@ -0,0 +1,78 @@
+[STREAM]
+index=0
+codec_name=jpeg2000
+profile=1798
+codec_type=video
+codec_tag_string=[0][0][0][0]
+codec_tag=0x
+width=640
+height=360
+coded_width=640
+coded_height=360
+closed_captions=0
+film_grain=0
+has_b_frames=0
+sample_aspect_ratio=1:1
+display_aspect_ratio=16:9
+pix_fmt=rgb48le
+level=-99
+color_range=unknown
+color_space=unknown
+color_transfer=bt709
+color_primaries=bt709
+chroma_location=unspecified
+field_order=progressive
+refs=1
+id=N/A
+r_frame_rate=24/1
+avg_frame_rate=24/1
+time_base=1/24
+start_pts=0
+start_time=0.00
+duration_ts=24
+duration=1.00
+bit_rate=N/A
+max_bit_rate=N/A
+bits_per_raw_sample=16
+nb_frames=N/A
+nb_read_frames=N/A
+nb_read_packets=N/A
+DISPOSITION:default=0
+DISPOSITION:dub=0
+DISPOSITION:original=0
+DISPOSITION:comment=0
+DISPOSITION:lyrics=0
+DISPOSITION:karaoke=0
+DISPOSITION:forced=0
+DISPOSITION:hearing_impaired=0
+DISPOSITION:visual_impaired=0
+DISPOSITION:clean_effects=0
+DISPOSITION:attached_pic=0
+DISPOSITION:timed_thumbnails=0
+DISPOSITION:captions=0
+DISPOSITION:descriptions=0
+DISPOSITION:metadata=0
+DISPOSITION:dependent=0
+DISPOSITION:still_image=0
+TAG:file_package_umid=0x060A2B340101010501010F20130035E05073878E4B2FB69D2369F25ADFC9
+TAG:file_package_name=File Package: SMPTE ST 422 / ST 2067-5 frame wrapping of 
JPEG 2000 codestreams
+TAG:track_name=Image Track
+[/STREAM]
+[FORMAT]
+format_name=mxf
+duration=1.00
+bit_rate=577792
+TAG:operational_pattern_ul=060e2b34.04010101.0d010201.01010100
+TAG:uid=f1994e51-a844-49e4-9459-1ddd622eb65d
+TAG:generation_uid=1be151ac-cc95-4314-b09f-7420eda9932b
+TAG:company_name=Sandflow Consulting LLC
+TAG:product_name=dcdm2imf
+TAG:product_version_num=0.0.0.0.0
+TAG:product_version=1.0-beta1
+TAG:product_uid=927fc4d1-89a3-4f88-88bb-d363ed33084a
+TAG:modification_date=2022-01-07T22:05:01.00Z
+TAG:toolkit_version_num=2.10.38.27240.1
+TAG:application_platform=win32
+TAG:material_package_umid=0x060A2B340101010501010F20130072BAF0557DA749308C14738BCD4FA116
+TAG:material_package_name=Material Package
+[/FORMAT]
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/2] avformat/mxf: set stream frame rates for ST 422 essence containers

2022-09-06 Thread pal
From: Pierre-Anthony Lemieux 

The MXF demuxer does not currently set AVStream::avg_frame_rate and 
::r_frame_rate
when J2K essence is wrapped according to SMPTE ST 422.

---
 libavformat/mxfdec.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index feebff67aa..043e2e06ec 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2140,6 +2140,13 @@ finish_decoding_index:
 return ret;
 }
 
+static int mxf_is_st_422(const UID *essence_container_ul) {
+static const uint8_t st_422_essence_container_ul[] = { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c };
+
+return essence_container_ul && mxf_match_uid(*essence_container_ul, 
st_422_essence_container_ul,
+ 
sizeof(st_422_essence_container_ul));
+}
+
 static int mxf_is_intra_only(MXFDescriptor *descriptor)
 {
 return mxf_get_codec_ul(mxf_intra_only_essence_container_uls,
@@ -2892,6 +2899,24 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 av_log(mxf->fc, AV_LOG_INFO, "Unknown frame layout type: 
%d\n", descriptor->frame_layout);
 }
 
+if (mxf_is_st_422(essence_container_ul)) {
+switch ((*essence_container_ul)[14]) {
+case 2: /* Cn: Clip- wrapped Picture Element */
+case 3: /* I1: Interlaced Frame, 1 field/KLV */
+case 4: /* I2: Interlaced Frame, 2 fields/KLV */
+case 6: /* P1: Frame- wrapped Picture Element */
+st->avg_frame_rate = source_track->edit_rate;
+st->r_frame_rate = st->avg_frame_rate;
+break;
+case 5: /* F1: Field-wrapped Picture Element */
+st->avg_frame_rate = av_mul_q(av_make_q(2, 1), 
source_track->edit_rate);
+st->r_frame_rate = st->avg_frame_rate;
+break;
+default:
+break;
+}
+}
+
 if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) {
 switch (descriptor->essence_codec_ul[14]) {
 case 1: st->codecpar->codec_tag = MKTAG('a','p','c','o'); 
break;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/2] fate/mxf: add JPEG 2000 test

2022-09-05 Thread pal
From: Pierre-Anthony Lemieux 

---
 tests/fate/mxf.mak   |  4 ++
 tests/ref/fate/mxf-probe-j2k | 78 
 2 files changed, 82 insertions(+)
 create mode 100644 tests/ref/fate/mxf-probe-j2k

diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak
index 3ab936b5de..38d1c2ef38 100644
--- a/tests/fate/mxf.mak
+++ b/tests/fate/mxf.mak
@@ -29,6 +29,10 @@ FATE_MXF_PROBE-$(call ENCDEC, DNXHD, MXF) += 
fate-mxf-probe-dnxhd
 fate-mxf-probe-dnxhd: SRC = $(TARGET_SAMPLES)/mxf/multiple_components.mxf
 fate-mxf-probe-dnxhd: CMD = run $(PROBE_FORMAT_STREAMS_COMMAND) -i "$(SRC)"
 
+FATE_MXF_PROBE-$(call ENCDEC, JPEG2000, MXF) += fate-mxf-probe-j2k
+fate-mxf-probe-j2k: SRC = $(TARGET_SAMPLES)/imf/countdown/countdown-small.mxf
+fate-mxf-probe-j2k: CMD = run $(PROBE_FORMAT_STREAMS_COMMAND) -i "$(SRC)"
+
 FATE_MXF_PROBE-$(call ENCDEC2, DVVIDEO, PCM_S16LE, MXF) += fate-mxf-probe-dv25
 fate-mxf-probe-dv25: SRC = $(TARGET_SAMPLES)/mxf/Avid-5.mxf
 fate-mxf-probe-dv25: CMD = run $(PROBE_FORMAT_STREAMS_COMMAND) -i "$(SRC)"
diff --git a/tests/ref/fate/mxf-probe-j2k b/tests/ref/fate/mxf-probe-j2k
new file mode 100644
index 00..2dbf2ac37d
--- /dev/null
+++ b/tests/ref/fate/mxf-probe-j2k
@@ -0,0 +1,78 @@
+[STREAM]
+index=0
+codec_name=jpeg2000
+profile=1798
+codec_type=video
+codec_tag_string=[0][0][0][0]
+codec_tag=0x
+width=640
+height=360
+coded_width=640
+coded_height=360
+closed_captions=0
+film_grain=0
+has_b_frames=0
+sample_aspect_ratio=1:1
+display_aspect_ratio=16:9
+pix_fmt=rgb48le
+level=-99
+color_range=unknown
+color_space=unknown
+color_transfer=bt709
+color_primaries=bt709
+chroma_location=unspecified
+field_order=progressive
+refs=1
+id=N/A
+r_frame_rate=24/1
+avg_frame_rate=24/1
+time_base=1/24
+start_pts=0
+start_time=0.00
+duration_ts=24
+duration=1.00
+bit_rate=N/A
+max_bit_rate=N/A
+bits_per_raw_sample=16
+nb_frames=N/A
+nb_read_frames=N/A
+nb_read_packets=N/A
+DISPOSITION:default=0
+DISPOSITION:dub=0
+DISPOSITION:original=0
+DISPOSITION:comment=0
+DISPOSITION:lyrics=0
+DISPOSITION:karaoke=0
+DISPOSITION:forced=0
+DISPOSITION:hearing_impaired=0
+DISPOSITION:visual_impaired=0
+DISPOSITION:clean_effects=0
+DISPOSITION:attached_pic=0
+DISPOSITION:timed_thumbnails=0
+DISPOSITION:captions=0
+DISPOSITION:descriptions=0
+DISPOSITION:metadata=0
+DISPOSITION:dependent=0
+DISPOSITION:still_image=0
+TAG:file_package_umid=0x060A2B340101010501010F20130035E05073878E4B2FB69D2369F25ADFC9
+TAG:file_package_name=File Package: SMPTE ST 422 / ST 2067-5 frame wrapping of 
JPEG 2000 codestreams
+TAG:track_name=Image Track
+[/STREAM]
+[FORMAT]
+format_name=mxf
+duration=1.00
+bit_rate=577792
+TAG:operational_pattern_ul=060e2b34.04010101.0d010201.01010100
+TAG:uid=f1994e51-a844-49e4-9459-1ddd622eb65d
+TAG:generation_uid=1be151ac-cc95-4314-b09f-7420eda9932b
+TAG:company_name=Sandflow Consulting LLC
+TAG:product_name=dcdm2imf
+TAG:product_version_num=0.0.0.0.0
+TAG:product_version=1.0-beta1
+TAG:product_uid=927fc4d1-89a3-4f88-88bb-d363ed33084a
+TAG:modification_date=2022-01-07T22:05:01.00Z
+TAG:toolkit_version_num=2.10.38.27240.1
+TAG:application_platform=win32
+TAG:material_package_umid=0x060A2B340101010501010F20130072BAF0557DA749308C14738BCD4FA116
+TAG:material_package_name=Material Package
+[/FORMAT]
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/2] avformat/mxf: set stream frame rates for ST 422 essence containers

2022-09-05 Thread pal
From: Pierre-Anthony Lemieux 

The MXF demuxer does not currently set AVStream::avg_frame_rate and 
::r_frame_rate
when J2K essence is wrapped according to SMPTE ST 422.

---
 libavformat/mxfdec.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index feebff67aa..043e2e06ec 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2140,6 +2140,13 @@ finish_decoding_index:
 return ret;
 }
 
+static int mxf_is_st_422(const UID *essence_container_ul) {
+static const uint8_t st_422_essence_container_ul[] = { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c };
+
+return essence_container_ul && mxf_match_uid(*essence_container_ul, 
st_422_essence_container_ul,
+ 
sizeof(st_422_essence_container_ul));
+}
+
 static int mxf_is_intra_only(MXFDescriptor *descriptor)
 {
 return mxf_get_codec_ul(mxf_intra_only_essence_container_uls,
@@ -2892,6 +2899,24 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 av_log(mxf->fc, AV_LOG_INFO, "Unknown frame layout type: 
%d\n", descriptor->frame_layout);
 }
 
+if (mxf_is_st_422(essence_container_ul)) {
+switch ((*essence_container_ul)[14]) {
+case 2: /* Cn: Clip- wrapped Picture Element */
+case 3: /* I1: Interlaced Frame, 1 field/KLV */
+case 4: /* I2: Interlaced Frame, 2 fields/KLV */
+case 6: /* P1: Frame- wrapped Picture Element */
+st->avg_frame_rate = source_track->edit_rate;
+st->r_frame_rate = st->avg_frame_rate;
+break;
+case 5: /* F1: Field-wrapped Picture Element */
+st->avg_frame_rate = av_mul_q(av_make_q(2, 1), 
source_track->edit_rate);
+st->r_frame_rate = st->avg_frame_rate;
+break;
+default:
+break;
+}
+}
+
 if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) {
 switch (descriptor->essence_codec_ul[14]) {
 case 1: st->codecpar->codec_tag = MKTAG('a','p','c','o'); 
break;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1] avformat/mxf: set stream frame rates for ST 422 essence containers

2022-08-28 Thread pal
From: Pierre-Anthony Lemieux 

The MXF demuxer does not currently set AVStream::avg_frame_rate and 
::r_frame_rate
when J2K essence is wrapped according to SMPTE ST 422.

---
 libavformat/mxfdec.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index feebff67aa..043e2e06ec 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2140,6 +2140,13 @@ finish_decoding_index:
 return ret;
 }
 
+static int mxf_is_st_422(const UID *essence_container_ul) {
+static const uint8_t st_422_essence_container_ul[] = { 
0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c };
+
+return essence_container_ul && mxf_match_uid(*essence_container_ul, 
st_422_essence_container_ul,
+ 
sizeof(st_422_essence_container_ul));
+}
+
 static int mxf_is_intra_only(MXFDescriptor *descriptor)
 {
 return mxf_get_codec_ul(mxf_intra_only_essence_container_uls,
@@ -2892,6 +2899,24 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 av_log(mxf->fc, AV_LOG_INFO, "Unknown frame layout type: 
%d\n", descriptor->frame_layout);
 }
 
+if (mxf_is_st_422(essence_container_ul)) {
+switch ((*essence_container_ul)[14]) {
+case 2: /* Cn: Clip- wrapped Picture Element */
+case 3: /* I1: Interlaced Frame, 1 field/KLV */
+case 4: /* I2: Interlaced Frame, 2 fields/KLV */
+case 6: /* P1: Frame- wrapped Picture Element */
+st->avg_frame_rate = source_track->edit_rate;
+st->r_frame_rate = st->avg_frame_rate;
+break;
+case 5: /* F1: Field-wrapped Picture Element */
+st->avg_frame_rate = av_mul_q(av_make_q(2, 1), 
source_track->edit_rate);
+st->r_frame_rate = st->avg_frame_rate;
+break;
+default:
+break;
+}
+}
+
 if (st->codecpar->codec_id == AV_CODEC_ID_PRORES) {
 switch (descriptor->essence_codec_ul[14]) {
 case 1: st->codecpar->codec_tag = MKTAG('a','p','c','o'); 
break;
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1] avformat/imfdec: check if Asset/Id exists before trying to read it

2022-08-25 Thread pal
From: Pierre-Anthony Lemieux 

Fixes Coverity issue #1512406

---
 libavformat/imfdec.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 5bbe7a53f8..fde91a6419 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -233,7 +233,12 @@ static int 
parse_imf_asset_map_from_xml_dom(AVFormatContext *s,
 
 asset = &(asset_map->assets[asset_map->asset_count]);
 
-if 
(ff_imf_xml_read_uuid(ff_imf_xml_get_child_element_by_name(asset_element, 
"Id"), asset->uuid)) {
+if (!(node = ff_imf_xml_get_child_element_by_name(asset_element, 
"Id"))) {
+av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing 
Id node\n");
+return AVERROR_INVALIDDATA;
+}
+
+if (ff_imf_xml_read_uuid(node, asset->uuid)) {
 av_log(s, AV_LOG_ERROR, "Could not parse UUID from asset in asset 
map.\n");
 return AVERROR_INVALIDDATA;
 }
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 2/2] avformat/tests/imf: add CPL timecode test

2022-08-22 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/imf.c | 7 +++
 tests/ref/fate/imf  | 1 +
 2 files changed, 8 insertions(+)

diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c
index e65629ccbc..d42295dc29 100644
--- a/libavformat/tests/imf.c
+++ b/libavformat/tests/imf.c
@@ -70,6 +70,11 @@ const char *cpl_doc =
 "urn:uuid:8e097bb0-cff7-4969-a692-bad47bfb528f"
 "  "
 ""
+""
+"false"
+"24"
+"02:10:01.23"
+""
 "24000 1001"
 ""
 ""
@@ -288,6 +293,7 @@ static int test_cpl_parsing(void)
 {
 xmlDocPtr doc;
 FFIMFCPL *cpl;
+char tc_buf[AV_TIMECODE_STR_SIZE];
 int ret;
 
 doc = xmlReadMemory(cpl_doc, strlen(cpl_doc), NULL, NULL, 0);
@@ -306,6 +312,7 @@ static int test_cpl_parsing(void)
 printf("%s\n", cpl->content_title_utf8);
 printf(AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->id_uuid));
 printf("%i %i\n", cpl->edit_rate.num, cpl->edit_rate.den);
+printf("%s\n", av_timecode_make_string(cpl->tc, tc_buf, 0));
 
 printf("Marker resource count: %" PRIu32 "\n", 
cpl->main_markers_track->resource_count);
 for (uint32_t i = 0; i < cpl->main_markers_track->resource_count; i++) {
diff --git a/tests/ref/fate/imf b/tests/ref/fate/imf
index 90b461dc5d..5093167bc7 100644
--- a/tests/ref/fate/imf
+++ b/tests/ref/fate/imf
@@ -1,6 +1,7 @@
 FFMPEG sample content
 urn:uuid:8713c020-2489-45f5-a9f7-87be539e20b5
 24000 1001
+02:10:01:23
 Marker resource count: 2
 Marker resource 0
   Marker 0
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 1/2] avformat/imfdec: use CPL start timecode if available

2022-08-22 Thread pal
From: Pierre-Anthony Lemieux 

The IMF CPL contains an optional timecode start address. This patch reads the
latter, if present, into the context's timecode metadata parameter.
This addresses https://trac.ffmpeg.org/ticket/9842.

---
 libavformat/imf.h |   2 +
 libavformat/imf_cpl.c | 109 ++
 libavformat/imfdec.c  |  11 +
 3 files changed, 122 insertions(+)

diff --git a/libavformat/imf.h b/libavformat/imf.h
index 4271cd9582..70ed007312 100644
--- a/libavformat/imf.h
+++ b/libavformat/imf.h
@@ -59,6 +59,7 @@
 #include "libavformat/avio.h"
 #include "libavutil/rational.h"
 #include "libavutil/uuid.h"
+#include "libavutil/timecode.h"
 #include 
 
 /**
@@ -130,6 +131,7 @@ typedef struct FFIMFCPL {
 AVUUID id_uuid;   /**< CompositionPlaylist/Id 
element */
 xmlChar *content_title_utf8; /**< 
CompositionPlaylist/ContentTitle element */
 AVRational edit_rate;/**< 
CompositionPlaylist/EditRate element */
+AVTimecode *tc;  /**< 
CompositionPlaylist/CompositionTimecode element */
 FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual 
Track */
 FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual 
Track */
 uint32_t main_audio_track_count; /**< Number of Main Audio 
Virtual Tracks */
diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index 4acc20feee..1868d7db45 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -116,6 +116,25 @@ int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t 
*number)
 return ret;
 }
 
+static int ff_imf_xml_read_boolean(xmlNodePtr element, int *value)
+{
+xmlChar *element_text = NULL;
+int ret = 0;
+
+element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
+
+if (xmlStrcmp(element_text, "true") == 0 || xmlStrcmp(element_text, "1") 
== 0)
+*value = 1;
+else if (xmlStrcmp(element_text, "false") == 0 || xmlStrcmp(element_text, 
"0") == 0)
+*value = 0;
+else
+ret = 1;
+
+xmlFree(element_text);
+
+return ret;
+}
+
 static void imf_base_virtual_track_init(FFIMFBaseVirtualTrack *track)
 {
 memset(track->id_uuid, 0, sizeof(track->id_uuid));
@@ -179,6 +198,90 @@ static int fill_content_title(xmlNodePtr cpl_element, 
FFIMFCPL *cpl)
 return 0;
 }
 
+static int digit_to_int(char digit)
+{
+if (digit >= '0' && digit <= '9')
+return digit - '0';
+return -1;
+}
+
+/**
+ * Parses a string that conform to the TimecodeType used in IMF CPL and defined
+ * in SMPTE ST 2067-3.
+ * @param[in] s string to parse
+ * @param[out] tc_comps pointer to an array of 4 integers where the parsed HH,
+ *  MM, SS and FF fields of the timecode are returned.
+ * @return 0 on success, < 0 AVERROR code on error.
+ */
+static int parse_cpl_tc_type(const char *s, int *tc_comps)
+{
+if (av_strnlen(s, 11) != 11)
+return AVERROR(EINVAL);
+
+for (int i = 0; i < 4; i++) {
+int hi;
+int lo;
+
+hi = digit_to_int(s[i * 3]);
+lo = digit_to_int(s[i * 3 + 1]);
+
+if (hi == -1 || lo == -1)
+return AVERROR(EINVAL);
+
+tc_comps[i] = 10 * hi + lo;
+}
+
+return 0;
+}
+
+static int fill_timecode(xmlNodePtr cpl_element, FFIMFCPL *cpl)
+{
+xmlNodePtr tc_element = NULL;
+xmlNodePtr element = NULL;
+xmlChar *tc_str = NULL;
+int df = 0;
+int comps[4];
+int ret = 0;
+
+tc_element = ff_imf_xml_get_child_element_by_name(cpl_element, 
"CompositionTimecode");
+if (!tc_element)
+   return 0;
+
+element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeDropFrame");
+if (!element) {
+av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
+a TimecodeDropFrame child element\n");
+return AVERROR_INVALIDDATA;
+}
+
+if (ff_imf_xml_read_boolean(element, &df)) {
+av_log(NULL, AV_LOG_ERROR, "TimecodeDropFrame element is invalid\n");
+return AVERROR_INVALIDDATA;
+}
+element = ff_imf_xml_get_child_element_by_name(tc_element, 
"TimecodeStartAddress");
+if (!element) {
+av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
+a TimecodeStartAddress child element\n");
+return AVERROR_INVALIDDATA;
+}
+
+tc_str = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
+ret = parse_cpl_tc_type(tc_str, comps);
+xmlFree(tc_str);
+if (ret)
+return ret;
+
+cpl->tc = av_malloc(sizeof(AVTimecode));
+if (!cpl->tc)
+return AVERROR(ENOMEM);
+ret = av_timecode_init_from_components(cpl->tc, cpl->edit_rate,
+   df ? AV_TIMECODE_FLAG_DROPFRAME : 0,
+   comps[0], comps[

[FFmpeg-devel] [PATCH v8 2/2] avformat/imfdec: preserve stream information

2022-08-10 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..5bbe7a53f8 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -573,18 +573,14 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
-/* Copy stream information */
-asset_stream = avformat_new_stream(s, NULL);
+asset_stream = ff_stream_clone(s, first_resource_stream);
 if (!asset_stream) {
-av_log(s, AV_LOG_ERROR, "Could not create stream\n");
+av_log(s, AV_LOG_ERROR, "Could not clone stream\n");
 return AVERROR(ENOMEM);
 }
+
 asset_stream->id = i;
-ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
-if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
-return ret;
-}
+asset_stream->nb_frames = 0;
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v8 1/2] avformat: refactor ff_stream_encode_params_copy() to stream_params_copy()

2022-08-10 Thread pal
From: Pierre-Anthony Lemieux 

Further code style improvements.

---
 libavformat/avformat.c   | 66 
 libavformat/fifo.c   | 10 ++
 libavformat/internal.h   | 11 +++
 libavformat/mux.h|  9 --
 libavformat/mux_utils.c  | 28 -
 libavformat/segment.c|  6 ++--
 libavformat/tee.c|  8 ++---
 libavformat/webm_chunk.c |  6 ++--
 8 files changed, 85 insertions(+), 59 deletions(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 30d6ea6a49..19c7219471 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -235,6 +235,72 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream 
*src)
 return 0;
 }
 
+/**
+ * Copy all stream parameters from source to destination stream, with the
+ * exception of the index field, which is usually set by avformat_new_stream().
+ *
+ * @param dst pointer to destination AVStream
+ * @param src pointer to source AVStream
+ * @return >=0 on success, AVERROR code on error
+ */
+static int stream_params_copy(AVStream *dst, const AVStream *src)
+{
+int ret;
+
+dst->id  = src->id;
+dst->time_base   = src->time_base;
+dst->start_time  = src->start_time;
+dst->duration= src->duration;
+dst->nb_frames   = src->nb_frames;
+dst->disposition = src->disposition;
+dst->discard = src->discard;
+dst->sample_aspect_ratio = src->sample_aspect_ratio;
+dst->avg_frame_rate  = src->avg_frame_rate;
+dst->event_flags = src->event_flags;
+dst->r_frame_rate= src->r_frame_rate;
+dst->pts_wrap_bits   = src->pts_wrap_bits;
+
+av_dict_free(&dst->metadata);
+ret = av_dict_copy(&dst->metadata, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
+if (ret < 0)
+return ret;
+
+ret = ff_stream_side_data_copy(dst, src);
+if (ret < 0)
+return ret;
+
+av_packet_unref(&dst->attached_pic);
+if (src->attached_pic.data) {
+ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
+if (ret < 0)
+return ret;
+}
+
+return 0;
+}
+
+AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
+{
+AVStream *st;
+int ret;
+
+st = avformat_new_stream(dst_ctx, NULL);
+if (!st)
+return NULL;
+
+ret = stream_params_copy(st, src);
+if (ret < 0) {
+ff_remove_stream(dst_ctx, st);
+return NULL;
+}
+
+return st;
+}
+
 AVProgram *av_new_program(AVFormatContext *ac, int id)
 {
 AVProgram *program = NULL;
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index ead2bdc5cf..e28f6299d9 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -504,16 +504,10 @@ static int fifo_mux_init(AVFormatContext *avf, const 
AVOutputFormat *oformat,
 avf2->io_open = avf->io_open;
 avf2->flags = avf->flags;
 
-for (i = 0; i < avf->nb_streams; ++i) {
-AVStream *st = avformat_new_stream(avf2, NULL);
-if (!st)
+for (i = 0; i < avf->nb_streams; ++i)
+if (!ff_stream_clone(avf2, avf->streams[i]))
 return AVERROR(ENOMEM);
 
-ret = ff_stream_encode_params_copy(st, avf->streams[i]);
-if (ret < 0)
-return ret;
-}
-
 return 0;
 }
 
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b6b8fbf56f..9b07cfb271 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -625,6 +625,17 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src);
 
+/**
+ * Create a new stream and copy to it all parameters from a source stream, with
+ * the exception of the index field, which is set when the new stream is
+ * created.
+ *
+ * @param dst_ctx pointer to the context in which the new stream is created
+ * @param src pointer to source AVStream
+ * @return pointer to the new stream or NULL on error
+ */
+AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src);
+
 /**
  * Wrap ffurl_move() and log if error happens.
  *
diff --git a/libavformat/mux.h b/libavformat/mux.h
index c01da82194..1bfcaf795f 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t 
read_start, int shift_size)
  */
 int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary 
**options);
 
-/**
- * Copy encoding parameters from source to destination stream
- *
- * @param dst pointer to destination AVStream
- * @param src pointer to source AVStream
- * @return >=0 on success, AVERROR code on error
- */
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
-
 /**
  * Parse creation_time in AVFormatContext metadata if exists and warn if the
  * parsing fails.
diff --git a/libavformat/mux_utils.c b/li

[FFmpeg-devel] [PATCH v7 2/2] avformat/imfdec: preserve stream information

2022-08-06 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..5bbe7a53f8 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -573,18 +573,14 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
-/* Copy stream information */
-asset_stream = avformat_new_stream(s, NULL);
+asset_stream = ff_stream_clone(s, first_resource_stream);
 if (!asset_stream) {
-av_log(s, AV_LOG_ERROR, "Could not create stream\n");
+av_log(s, AV_LOG_ERROR, "Could not clone stream\n");
 return AVERROR(ENOMEM);
 }
+
 asset_stream->id = i;
-ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
-if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
-return ret;
-}
+asset_stream->nb_frames = 0;
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v7 1/2] avformat: refactor ff_stream_encode_params_copy() to stream_params_copy()

2022-08-06 Thread pal
From: Pierre-Anthony Lemieux 

Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299726.html

---
 libavformat/avformat.c   | 66 
 libavformat/fifo.c   |  8 ++---
 libavformat/internal.h   | 11 +++
 libavformat/mux.h|  9 --
 libavformat/mux_utils.c  | 28 -
 libavformat/segment.c|  6 ++--
 libavformat/tee.c|  7 ++---
 libavformat/webm_chunk.c |  6 ++--
 8 files changed, 86 insertions(+), 55 deletions(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 30d6ea6a49..19c7219471 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -235,6 +235,72 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream 
*src)
 return 0;
 }
 
+/**
+ * Copy all stream parameters from source to destination stream, with the
+ * exception of the index field, which is usually set by avformat_new_stream().
+ *
+ * @param dst pointer to destination AVStream
+ * @param src pointer to source AVStream
+ * @return >=0 on success, AVERROR code on error
+ */
+static int stream_params_copy(AVStream *dst, const AVStream *src)
+{
+int ret;
+
+dst->id  = src->id;
+dst->time_base   = src->time_base;
+dst->start_time  = src->start_time;
+dst->duration= src->duration;
+dst->nb_frames   = src->nb_frames;
+dst->disposition = src->disposition;
+dst->discard = src->discard;
+dst->sample_aspect_ratio = src->sample_aspect_ratio;
+dst->avg_frame_rate  = src->avg_frame_rate;
+dst->event_flags = src->event_flags;
+dst->r_frame_rate= src->r_frame_rate;
+dst->pts_wrap_bits   = src->pts_wrap_bits;
+
+av_dict_free(&dst->metadata);
+ret = av_dict_copy(&dst->metadata, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
+if (ret < 0)
+return ret;
+
+ret = ff_stream_side_data_copy(dst, src);
+if (ret < 0)
+return ret;
+
+av_packet_unref(&dst->attached_pic);
+if (src->attached_pic.data) {
+ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
+if (ret < 0)
+return ret;
+}
+
+return 0;
+}
+
+AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
+{
+AVStream *st;
+int ret;
+
+st = avformat_new_stream(dst_ctx, NULL);
+if (!st)
+return NULL;
+
+ret = stream_params_copy(st, src);
+if (ret < 0) {
+ff_remove_stream(dst_ctx, st);
+return NULL;
+}
+
+return st;
+}
+
 AVProgram *av_new_program(AVFormatContext *ac, int id)
 {
 AVProgram *program = NULL;
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index ead2bdc5cf..55d413b952 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -505,13 +505,11 @@ static int fifo_mux_init(AVFormatContext *avf, const 
AVOutputFormat *oformat,
 avf2->flags = avf->flags;
 
 for (i = 0; i < avf->nb_streams; ++i) {
-AVStream *st = avformat_new_stream(avf2, NULL);
+AVStream *st = NULL;
+
+st = ff_stream_clone(avf2, avf->streams[i]);
 if (!st)
 return AVERROR(ENOMEM);
-
-ret = ff_stream_encode_params_copy(st, avf->streams[i]);
-if (ret < 0)
-return ret;
 }
 
 return 0;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b6b8fbf56f..9b07cfb271 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -625,6 +625,17 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src);
 
+/**
+ * Create a new stream and copy to it all parameters from a source stream, with
+ * the exception of the index field, which is set when the new stream is
+ * created.
+ *
+ * @param dst_ctx pointer to the context in which the new stream is created
+ * @param src pointer to source AVStream
+ * @return pointer to the new stream or NULL on error
+ */
+AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src);
+
 /**
  * Wrap ffurl_move() and log if error happens.
  *
diff --git a/libavformat/mux.h b/libavformat/mux.h
index c01da82194..1bfcaf795f 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t 
read_start, int shift_size)
  */
 int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary 
**options);
 
-/**
- * Copy encoding parameters from source to destination stream
- *
- * @param dst pointer to destination AVStream
- * @param src pointer to source AVStream
- * @return >=0 on success, AVERROR code on error
- */
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
-
 /**
  * Parse creation_time in AVFormatContext metadata if exists and warn if the
  * parsing fails.
diff --git a/libavformat/mux_utils.c b/libavformat/

[FFmpeg-devel] [PATCH v6 2/2] avformat/imfdec: preserve stream information

2022-08-05 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..5bbe7a53f8 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -573,18 +573,14 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
-/* Copy stream information */
-asset_stream = avformat_new_stream(s, NULL);
+asset_stream = ff_stream_clone(s, first_resource_stream);
 if (!asset_stream) {
-av_log(s, AV_LOG_ERROR, "Could not create stream\n");
+av_log(s, AV_LOG_ERROR, "Could not clone stream\n");
 return AVERROR(ENOMEM);
 }
+
 asset_stream->id = i;
-ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
-if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
-return ret;
-}
+asset_stream->nb_frames = 0;
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 1/2] avformat: refactor ff_stream_encode_params_copy() to stream_params_copy()

2022-08-05 Thread pal
From: Pierre-Anthony Lemieux 

Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299685.html

---
 libavformat/avformat.c   | 68 
 libavformat/fifo.c   |  8 ++---
 libavformat/internal.h   | 12 +++
 libavformat/mux.h|  9 --
 libavformat/mux_utils.c  | 28 -
 libavformat/segment.c|  6 ++--
 libavformat/tee.c|  7 ++---
 libavformat/webm_chunk.c |  6 ++--
 8 files changed, 89 insertions(+), 55 deletions(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 30d6ea6a49..64c9d71a24 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -235,6 +235,74 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream 
*src)
 return 0;
 }
 
+/**
+ * Copy all stream parameters from source to destination stream, with the
+ * exception of:
+ *  * the index field, which is usually set by avformat_new_stream()
+ *  * the attached_pic field, if attached_pic.size is 0 or less
+ *
+ * @param dst pointer to destination AVStream
+ * @param src pointer to source AVStream
+ * @return >=0 on success, AVERROR code on error
+ */
+static int stream_params_copy(AVStream *dst, const AVStream *src)
+{
+int ret;
+
+dst->id  = src->id;
+dst->time_base   = src->time_base;
+dst->start_time  = src->start_time;
+dst->duration= src->duration;
+dst->nb_frames   = src->nb_frames;
+dst->disposition = src->disposition;
+dst->discard = src->discard;
+dst->sample_aspect_ratio = src->sample_aspect_ratio;
+dst->avg_frame_rate  = src->avg_frame_rate;
+dst->event_flags = src->event_flags;
+dst->r_frame_rate= src->r_frame_rate;
+dst->pts_wrap_bits   = src->pts_wrap_bits;
+
+av_dict_free(&dst->metadata);
+ret = av_dict_copy(&dst->metadata, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
+if (ret < 0)
+return ret;
+
+ret = ff_stream_side_data_copy(dst, src);
+if (ret < 0)
+return ret;
+
+av_packet_unref(&dst->attached_pic);
+if (src->attached_pic.size > 0) {
+ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
+if (ret < 0)
+return ret;
+}
+
+return 0;
+}
+
+AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
+{
+AVStream *st;
+int ret;
+
+st = avformat_new_stream(dst_ctx, NULL);
+if (!st)
+return NULL;
+
+ret = stream_params_copy(st, src);
+if (ret < 0) {
+ff_remove_stream(dst_ctx, st);
+return NULL;
+}
+
+return st;
+}
+
 AVProgram *av_new_program(AVFormatContext *ac, int id)
 {
 AVProgram *program = NULL;
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index ead2bdc5cf..55d413b952 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -505,13 +505,11 @@ static int fifo_mux_init(AVFormatContext *avf, const 
AVOutputFormat *oformat,
 avf2->flags = avf->flags;
 
 for (i = 0; i < avf->nb_streams; ++i) {
-AVStream *st = avformat_new_stream(avf2, NULL);
+AVStream *st = NULL;
+
+st = ff_stream_clone(avf2, avf->streams[i]);
 if (!st)
 return AVERROR(ENOMEM);
-
-ret = ff_stream_encode_params_copy(st, avf->streams[i]);
-if (ret < 0)
-return ret;
 }
 
 return 0;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b6b8fbf56f..6dd763950f 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -625,6 +625,18 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src);
 
+/**
+ * Create a new stream and copy to it all parameters from a source stream,
+ * with the exception of:
+ *  * the index field, which is set when the new stream is created
+ *  * the attached_pic field, if attached_pic.size is 0 or less
+ *
+ * @param dst_ctx pointer to the context in which the new stream is created
+ * @param src pointer to source AVStream
+ * @return pointer to the new stream or NULL on error
+ */
+AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src);
+
 /**
  * Wrap ffurl_move() and log if error happens.
  *
diff --git a/libavformat/mux.h b/libavformat/mux.h
index c01da82194..1bfcaf795f 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t 
read_start, int shift_size)
  */
 int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary 
**options);
 
-/**
- * Copy encoding parameters from source to destination stream
- *
- * @param dst pointer to destination AVStream
- * @param src pointer to source AVStream
- * @return >=0 on success, AVERROR code on error
- */
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
-
 /**
  * 

[FFmpeg-devel] [PATCH v5 2/2] avformat/imfdec: preserve stream information

2022-07-31 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://trac.ffmpeg.org/ticket/9818, the IMF demuxer does not
currently preserve stream information such as language in the case of audio
streams.

---
 libavformat/imfdec.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..4cd6a56a09 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -579,12 +579,15 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Could not create stream\n");
 return AVERROR(ENOMEM);
 }
-asset_stream->id = i;
-ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
+
+ret = ff_stream_params_copy(asset_stream, first_resource_stream);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
 return ret;
 }
+
+asset_stream->id = i;
+asset_stream->nb_frames = 0;
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 1/2] avformat: refactor ff_stream_encode_params_copy() to ff_stream_params_copy()

2022-07-31 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298491.html.
Note that ff_stream_params_copy() does not copy:
 * the index field
 * the attached_pic if its size is 0

Addresses http://ffmpeg.org/pipermail/ffmpeg-devel/2022-August/299514.html

---
 libavformat/avformat.c   | 40 
 libavformat/fifo.c   |  2 +-
 libavformat/internal.h   | 12 
 libavformat/mux.h|  9 -
 libavformat/mux_utils.c  | 28 
 libavformat/segment.c|  2 +-
 libavformat/tee.c|  2 +-
 libavformat/webm_chunk.c |  2 +-
 8 files changed, 56 insertions(+), 41 deletions(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 30d6ea6a49..242187c359 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -235,6 +235,46 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream 
*src)
 return 0;
 }
 
+int ff_stream_params_copy(AVStream *dst, const AVStream *src)
+{
+int ret;
+
+dst->id  = src->id;
+dst->time_base   = src->time_base;
+dst->start_time  = src->start_time;
+dst->duration= src->duration;
+dst->nb_frames   = src->nb_frames;
+dst->disposition = src->disposition;
+dst->discard = src->discard;
+dst->sample_aspect_ratio = src->sample_aspect_ratio;
+dst->avg_frame_rate  = src->avg_frame_rate;
+dst->event_flags = src->event_flags;
+dst->r_frame_rate= src->r_frame_rate;
+dst->pts_wrap_bits   = src->pts_wrap_bits;
+
+av_dict_free(&dst->metadata);
+ret = av_dict_copy(&dst->metadata, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
+if (ret < 0)
+return ret;
+
+ret = ff_stream_side_data_copy(dst, src);
+if (ret < 0)
+return ret;
+
+av_packet_unref(&dst->attached_pic);
+if (src->attached_pic.size > 0) {
+ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
+if (ret < 0)
+return ret;
+}
+
+return 0;
+}
+
 AVProgram *av_new_program(AVFormatContext *ac, int id)
 {
 AVProgram *program = NULL;
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index ead2bdc5cf..fef116d040 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -509,7 +509,7 @@ static int fifo_mux_init(AVFormatContext *avf, const 
AVOutputFormat *oformat,
 if (!st)
 return AVERROR(ENOMEM);
 
-ret = ff_stream_encode_params_copy(st, avf->streams[i]);
+ret = ff_stream_params_copy(st, avf->streams[i]);
 if (ret < 0)
 return ret;
 }
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b6b8fbf56f..87a00bbae3 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -625,6 +625,18 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src);
 
+/**
+ * Copy all stream parameters from source to destination stream, with the
+ * exception of:
+ *  * the index field, which is usually set by avformat_new_stream()
+ *  * the attached_pic field, if attached_pic.size is 0 or less
+ *
+ * @param dst pointer to destination AVStream
+ * @param src pointer to source AVStream
+ * @return >=0 on success, AVERROR code on error
+ */
+int ff_stream_params_copy(AVStream *dst, const AVStream *src);
+
 /**
  * Wrap ffurl_move() and log if error happens.
  *
diff --git a/libavformat/mux.h b/libavformat/mux.h
index c01da82194..1bfcaf795f 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t 
read_start, int shift_size)
  */
 int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary 
**options);
 
-/**
- * Copy encoding parameters from source to destination stream
- *
- * @param dst pointer to destination AVStream
- * @param src pointer to source AVStream
- * @return >=0 on success, AVERROR code on error
- */
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
-
 /**
  * Parse creation_time in AVFormatContext metadata if exists and warn if the
  * parsing fails.
diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c
index eb8ea3d560..2fa2ab5b0f 100644
--- a/libavformat/mux_utils.c
+++ b/libavformat/mux_utils.c
@@ -121,34 +121,6 @@ int ff_format_output_open(AVFormatContext *s, const char 
*url, AVDictionary **op
 return 0;
 }
 
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src)
-{
-int ret;
-
-dst->id  = src->id;
-dst->time_base   = src->time_base;
-dst->nb_frames   = src->nb_frames;
-dst->disposition = src->disposition;
-dst->sample_aspect_ratio = src->sample_aspect_ratio;
-dst->avg_frame_rate  = src->avg_frame_rate;
-dst->

[FFmpeg-devel] [PATCH v4 2/2] avformat/imfdec: preserve stream information

2022-07-31 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://trac.ffmpeg.org/ticket/9818, the IMF demuxer does not
currently preserve stream information such as language in the case of audio
streams.

---
 libavformat/imfdec.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..4cd6a56a09 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -579,12 +579,15 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Could not create stream\n");
 return AVERROR(ENOMEM);
 }
-asset_stream->id = i;
-ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
+
+ret = ff_stream_params_copy(asset_stream, first_resource_stream);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
 return ret;
 }
+
+asset_stream->id = i;
+asset_stream->nb_frames = 0;
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 1/2] avformat: refactor ff_stream_encode_params_copy() to ff_stream_params_copy()

2022-07-31 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298491.html.
Note that ff_stream_params_copy() does not copy:
 * the index field
 * the attached_pic if its size is 0

---
 libavformat/avformat.c   | 41 
 libavformat/fifo.c   |  2 +-
 libavformat/internal.h   | 12 
 libavformat/mux.h|  9 -
 libavformat/mux_utils.c  | 28 ---
 libavformat/segment.c|  2 +-
 libavformat/tee.c|  2 +-
 libavformat/webm_chunk.c |  2 +-
 8 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 30d6ea6a49..1d0ac5ab7e 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -235,6 +235,47 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream 
*src)
 return 0;
 }
 
+int ff_stream_params_copy(AVStream *dst, const AVStream *src)
+{
+int ret;
+
+dst->id  = src->id;
+dst->time_base   = src->time_base;
+dst->start_time  = src->start_time;
+dst->duration= src->duration;
+dst->nb_frames   = src->nb_frames;
+dst->disposition = src->disposition;
+dst->discard = src->discard;
+dst->sample_aspect_ratio = src->sample_aspect_ratio;
+dst->avg_frame_rate  = src->avg_frame_rate;
+dst->event_flags = src->event_flags;
+dst->r_frame_rate= src->r_frame_rate;
+dst->pts_wrap_bits   = src->pts_wrap_bits;
+
+av_dict_free(&dst->metadata);
+ret = av_dict_copy(&dst->metadata, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
+if (ret < 0)
+return ret;
+
+ret = ff_stream_side_data_copy(dst, src);
+if (ret < 0)
+return ret;
+
+if (src->attached_pic.size > 0) {
+ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
+if (ret < 0)
+return ret;
+} else {
+av_packet_unref(&dst->attached_pic);
+}
+
+return 0;
+}
+
 AVProgram *av_new_program(AVFormatContext *ac, int id)
 {
 AVProgram *program = NULL;
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index ead2bdc5cf..fef116d040 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -509,7 +509,7 @@ static int fifo_mux_init(AVFormatContext *avf, const 
AVOutputFormat *oformat,
 if (!st)
 return AVERROR(ENOMEM);
 
-ret = ff_stream_encode_params_copy(st, avf->streams[i]);
+ret = ff_stream_params_copy(st, avf->streams[i]);
 if (ret < 0)
 return ret;
 }
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b6b8fbf56f..87a00bbae3 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -625,6 +625,18 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src);
 
+/**
+ * Copy all stream parameters from source to destination stream, with the
+ * exception of:
+ *  * the index field, which is usually set by avformat_new_stream()
+ *  * the attached_pic field, if attached_pic.size is 0 or less
+ *
+ * @param dst pointer to destination AVStream
+ * @param src pointer to source AVStream
+ * @return >=0 on success, AVERROR code on error
+ */
+int ff_stream_params_copy(AVStream *dst, const AVStream *src);
+
 /**
  * Wrap ffurl_move() and log if error happens.
  *
diff --git a/libavformat/mux.h b/libavformat/mux.h
index c01da82194..1bfcaf795f 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t 
read_start, int shift_size)
  */
 int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary 
**options);
 
-/**
- * Copy encoding parameters from source to destination stream
- *
- * @param dst pointer to destination AVStream
- * @param src pointer to source AVStream
- * @return >=0 on success, AVERROR code on error
- */
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
-
 /**
  * Parse creation_time in AVFormatContext metadata if exists and warn if the
  * parsing fails.
diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c
index eb8ea3d560..2fa2ab5b0f 100644
--- a/libavformat/mux_utils.c
+++ b/libavformat/mux_utils.c
@@ -121,34 +121,6 @@ int ff_format_output_open(AVFormatContext *s, const char 
*url, AVDictionary **op
 return 0;
 }
 
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src)
-{
-int ret;
-
-dst->id  = src->id;
-dst->time_base   = src->time_base;
-dst->nb_frames   = src->nb_frames;
-dst->disposition = src->disposition;
-dst->sample_aspect_ratio = src->sample_aspect_ratio;
-dst->avg_frame_rate  = src->avg_frame_rate;
-dst->r_frame_rate= src->r_frame_rate;
-
-av_dict_fre

[FFmpeg-devel] [PATCH v3 2/2] avformat/imfdec: preserve stream information

2022-07-25 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://trac.ffmpeg.org/ticket/9818, the IMF demuxer does not
currently preserve stream information such as language in the case of audio
streams.

---
 libavformat/imfdec.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..4cd6a56a09 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -579,12 +579,15 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Could not create stream\n");
 return AVERROR(ENOMEM);
 }
-asset_stream->id = i;
-ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
+
+ret = ff_stream_params_copy(asset_stream, first_resource_stream);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
 return ret;
 }
+
+asset_stream->id = i;
+asset_stream->nb_frames = 0;
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/2] avformat: refactor ff_stream_encode_params_copy() to ff_stream_params_copy()

2022-07-25 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298491.html.
Note that ff_stream_params_copy() does not copy the index field, which is
usually set by avformat_new_stream().

---
 libavformat/avformat.c   | 37 +
 libavformat/fifo.c   |  2 +-
 libavformat/internal.h   | 10 ++
 libavformat/mux.h|  9 -
 libavformat/mux_utils.c  | 28 
 libavformat/segment.c|  2 +-
 libavformat/tee.c|  2 +-
 libavformat/webm_chunk.c |  2 +-
 8 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 30d6ea6a49..c426dbfa45 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -235,6 +235,43 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream 
*src)
 return 0;
 }
 
+int ff_stream_params_copy(AVStream *dst, const AVStream *src)
+{
+int ret;
+
+dst->id  = src->id;
+dst->time_base   = src->time_base;
+dst->start_time  = src->start_time;
+dst->duration= src->duration;
+dst->nb_frames   = src->nb_frames;
+dst->disposition = src->disposition;
+dst->discard = src->discard;
+dst->sample_aspect_ratio = src->sample_aspect_ratio;
+dst->avg_frame_rate  = src->avg_frame_rate;
+dst->event_flags = src->event_flags;
+dst->r_frame_rate= src->r_frame_rate;
+dst->pts_wrap_bits   = src->pts_wrap_bits;
+
+av_dict_free(&dst->metadata);
+ret = av_dict_copy(&dst->metadata, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
+if (ret < 0)
+return ret;
+
+ret = ff_stream_side_data_copy(dst, src);
+if (ret < 0)
+return ret;
+
+ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
+if (ret < 0)
+return ret;
+
+return 0;
+}
+
 AVProgram *av_new_program(AVFormatContext *ac, int id)
 {
 AVProgram *program = NULL;
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index ead2bdc5cf..fef116d040 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -509,7 +509,7 @@ static int fifo_mux_init(AVFormatContext *avf, const 
AVOutputFormat *oformat,
 if (!st)
 return AVERROR(ENOMEM);
 
-ret = ff_stream_encode_params_copy(st, avf->streams[i]);
+ret = ff_stream_params_copy(st, avf->streams[i]);
 if (ret < 0)
 return ret;
 }
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b6b8fbf56f..774ff57698 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -625,6 +625,16 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src);
 
+/**
+ * Copy all stream parameters from source to destination stream, with the
+ * exception of the index field, which is usually set by 
avformat_new_stream(). 
+ *
+ * @param dst pointer to destination AVStream
+ * @param src pointer to source AVStream
+ * @return >=0 on success, AVERROR code on error
+ */
+int ff_stream_params_copy(AVStream *dst, const AVStream *src);
+
 /**
  * Wrap ffurl_move() and log if error happens.
  *
diff --git a/libavformat/mux.h b/libavformat/mux.h
index c01da82194..1bfcaf795f 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t 
read_start, int shift_size)
  */
 int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary 
**options);
 
-/**
- * Copy encoding parameters from source to destination stream
- *
- * @param dst pointer to destination AVStream
- * @param src pointer to source AVStream
- * @return >=0 on success, AVERROR code on error
- */
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
-
 /**
  * Parse creation_time in AVFormatContext metadata if exists and warn if the
  * parsing fails.
diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c
index eb8ea3d560..2fa2ab5b0f 100644
--- a/libavformat/mux_utils.c
+++ b/libavformat/mux_utils.c
@@ -121,34 +121,6 @@ int ff_format_output_open(AVFormatContext *s, const char 
*url, AVDictionary **op
 return 0;
 }
 
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src)
-{
-int ret;
-
-dst->id  = src->id;
-dst->time_base   = src->time_base;
-dst->nb_frames   = src->nb_frames;
-dst->disposition = src->disposition;
-dst->sample_aspect_ratio = src->sample_aspect_ratio;
-dst->avg_frame_rate  = src->avg_frame_rate;
-dst->r_frame_rate= src->r_frame_rate;
-
-av_dict_free(&dst->metadata);
-ret = av_dict_copy(&dst->metadata, src->metadata, 0);
-if (ret < 0)
-return ret;
-
-ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);

[FFmpeg-devel] [PATCH v2 2/2] avformat/imfdec: preserve stream information

2022-07-12 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://trac.ffmpeg.org/ticket/9818, the IMF demuxer does not
currently preserve stream information such as language in the case of audio
streams.

---
 libavformat/imfdec.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..4cd6a56a09 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -579,12 +579,15 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 av_log(s, AV_LOG_ERROR, "Could not create stream\n");
 return AVERROR(ENOMEM);
 }
-asset_stream->id = i;
-ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
+
+ret = ff_stream_params_copy(asset_stream, first_resource_stream);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
 return ret;
 }
+
+asset_stream->id = i;
+asset_stream->nb_frames = 0;
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/2] avformat: refactor ff_stream_encode_params_copy() to ff_stream_params_copy()

2022-07-12 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://ffmpeg.org/pipermail/ffmpeg-devel/2022-July/298491.html

---
 libavformat/avformat.c   | 38 ++
 libavformat/fifo.c   |  2 +-
 libavformat/internal.h   |  9 +
 libavformat/mux.h|  9 -
 libavformat/mux_utils.c  | 28 
 libavformat/segment.c|  2 +-
 libavformat/tee.c|  2 +-
 libavformat/webm_chunk.c |  2 +-
 8 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 30d6ea6a49..a4aa92cd22 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -235,6 +235,44 @@ int ff_stream_side_data_copy(AVStream *dst, const AVStream 
*src)
 return 0;
 }
 
+int ff_stream_params_copy(AVStream *dst, const AVStream *src)
+{
+int ret;
+
+dst->id  = src->id;
+dst->index   = src->index;
+dst->time_base   = src->time_base;
+dst->start_time  = src->start_time;
+dst->duration= src->duration;
+dst->nb_frames   = src->nb_frames;
+dst->disposition = src->disposition;
+dst->discard = src->discard;
+dst->sample_aspect_ratio = src->sample_aspect_ratio;
+dst->avg_frame_rate  = src->avg_frame_rate;
+dst->event_flags = src->event_flags;
+dst->r_frame_rate= src->r_frame_rate;
+dst->pts_wrap_bits   = src->pts_wrap_bits;
+
+av_dict_free(&dst->metadata);
+ret = av_dict_copy(&dst->metadata, src->metadata, 0);
+if (ret < 0)
+return ret;
+
+ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
+if (ret < 0)
+return ret;
+
+ret = ff_stream_side_data_copy(dst, src);
+if (ret < 0)
+return ret;
+
+ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
+if (ret < 0)
+return ret;
+
+return 0;
+}
+
 AVProgram *av_new_program(AVFormatContext *ac, int id)
 {
 AVProgram *program = NULL;
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index ead2bdc5cf..fef116d040 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -509,7 +509,7 @@ static int fifo_mux_init(AVFormatContext *avf, const 
AVOutputFormat *oformat,
 if (!st)
 return AVERROR(ENOMEM);
 
-ret = ff_stream_encode_params_copy(st, avf->streams[i]);
+ret = ff_stream_params_copy(st, avf->streams[i]);
 if (ret < 0)
 return ret;
 }
diff --git a/libavformat/internal.h b/libavformat/internal.h
index b6b8fbf56f..f89da85e22 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -625,6 +625,15 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int 
be, int sflags);
  */
 int ff_stream_side_data_copy(AVStream *dst, const AVStream *src);
 
+/**
+ * Copy all stream parameters from source to destination stream
+ *
+ * @param dst pointer to destination AVStream
+ * @param src pointer to source AVStream
+ * @return >=0 on success, AVERROR code on error
+ */
+int ff_stream_params_copy(AVStream *dst, const AVStream *src);
+
 /**
  * Wrap ffurl_move() and log if error happens.
  *
diff --git a/libavformat/mux.h b/libavformat/mux.h
index c01da82194..1bfcaf795f 100644
--- a/libavformat/mux.h
+++ b/libavformat/mux.h
@@ -113,15 +113,6 @@ int ff_format_shift_data(AVFormatContext *s, int64_t 
read_start, int shift_size)
  */
 int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary 
**options);
 
-/**
- * Copy encoding parameters from source to destination stream
- *
- * @param dst pointer to destination AVStream
- * @param src pointer to source AVStream
- * @return >=0 on success, AVERROR code on error
- */
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src);
-
 /**
  * Parse creation_time in AVFormatContext metadata if exists and warn if the
  * parsing fails.
diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c
index eb8ea3d560..2fa2ab5b0f 100644
--- a/libavformat/mux_utils.c
+++ b/libavformat/mux_utils.c
@@ -121,34 +121,6 @@ int ff_format_output_open(AVFormatContext *s, const char 
*url, AVDictionary **op
 return 0;
 }
 
-int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src)
-{
-int ret;
-
-dst->id  = src->id;
-dst->time_base   = src->time_base;
-dst->nb_frames   = src->nb_frames;
-dst->disposition = src->disposition;
-dst->sample_aspect_ratio = src->sample_aspect_ratio;
-dst->avg_frame_rate  = src->avg_frame_rate;
-dst->r_frame_rate= src->r_frame_rate;
-
-av_dict_free(&dst->metadata);
-ret = av_dict_copy(&dst->metadata, src->metadata, 0);
-if (ret < 0)
-return ret;
-
-ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
-if (ret < 0)
-return ret;
-
-ret = ff_stream_side_data_copy(dst, src);
-if (ret < 0)
-return ret;
-
-return 0;
-}
-
 int ff_parse

[FFmpeg-devel] [PATCH v1] avformat/imfdec: preserve stream information

2022-07-03 Thread pal
From: Pierre-Anthony Lemieux 

As discussed at https://trac.ffmpeg.org/ticket/9818, the IMF demuxer does not
currently preserve stream information such as language in the case of audio
streams. This patch is modeled on copy_stream_props() at avformat/concatdec.c.

---
 libavformat/imfdec.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 71dfb26958..7aa66a06bf 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -580,11 +580,16 @@ static int 
set_context_streams_from_tracks(AVFormatContext *s)
 return AVERROR(ENOMEM);
 }
 asset_stream->id = i;
+asset_stream->r_frame_rate = first_resource_stream->r_frame_rate;
+asset_stream->avg_frame_rate = first_resource_stream->avg_frame_rate;
+asset_stream->sample_aspect_ratio = 
first_resource_stream->sample_aspect_ratio;
 ret = avcodec_parameters_copy(asset_stream->codecpar, 
first_resource_stream->codecpar);
 if (ret < 0) {
 av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n");
 return ret;
 }
+av_dict_copy(&asset_stream->metadata, first_resource_stream->metadata, 
0);
+ff_stream_side_data_copy(asset_stream, first_resource_stream);
 avpriv_set_pts_info(asset_stream,
 first_resource_stream->pts_wrap_bits,
 first_resource_stream->time_base.num,
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 6/6] avfilter/showinfo: refactor to use avutil/uuid

2022-06-01 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavfilter/vf_showinfo.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 12d39310ef..6efcafce28 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -42,6 +42,7 @@
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/video_enc_params.h"
 #include "libavutil/detection_bbox.h"
+#include "libavutil/uuid.h"
 
 #include "avfilter.h"
 #include "internal.h"
@@ -421,29 +422,20 @@ static void dump_video_enc_params(AVFilterContext *ctx, 
const AVFrameSideData *s
 
 static void dump_sei_unregistered_metadata(AVFilterContext *ctx, const 
AVFrameSideData *sd)
 {
-const int uuid_size = 16;
 const uint8_t *user_data = sd->data;
-int i;
 
-if (sd->size < uuid_size) {
+if (sd->size < AV_UUID_LEN) {
 av_log(ctx, AV_LOG_ERROR, "invalid data(%"SIZE_SPECIFIER" < "
-   "UUID(%d-bytes))\n", sd->size, uuid_size);
+   "UUID(%d-bytes))\n", sd->size, AV_UUID_LEN);
 return;
 }
 
 av_log(ctx, AV_LOG_INFO, "User Data Unregistered:\n");
-av_log(ctx, AV_LOG_INFO, "UUID=");
-for (i = 0; i < uuid_size; i++) {
-av_log(ctx, AV_LOG_INFO, "%02x", user_data[i]);
-if (i == 3 || i == 5 || i == 7 || i == 9)
-av_log(ctx, AV_LOG_INFO, "-");
-}
-av_log(ctx, AV_LOG_INFO, "\n");
+av_log(ctx, AV_LOG_INFO, "UUID=" AV_PRI_UUID "\n", AV_UUID_ARG(user_data));
 
 av_log(ctx, AV_LOG_INFO, "User Data=");
-for (; i < sd->size; i++) {
+for (size_t i = 16; i < sd->size; i++)
 av_log(ctx, AV_LOG_INFO, "%02x", user_data[i]);
-}
 av_log(ctx, AV_LOG_INFO, "\n");
 }
 
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 5/6] avformat/imf: refactor to use avutil/uuid

2022-06-01 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imf.h   | 18 -
 libavformat/imf_cpl.c   | 60 +++--
 libavformat/imfdec.c| 34 +++
 libavformat/tests/imf.c | 18 ++---
 4 files changed, 52 insertions(+), 78 deletions(-)

diff --git a/libavformat/imf.h b/libavformat/imf.h
index 62c4468ce9..4271cd9582 100644
--- a/libavformat/imf.h
+++ b/libavformat/imf.h
@@ -58,17 +58,9 @@
 #include "avformat.h"
 #include "libavformat/avio.h"
 #include "libavutil/rational.h"
+#include "libavutil/uuid.h"
 #include 
 
-#define FF_IMF_UUID_FORMAT\
-"urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-" \
-"%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-
-/**
- * UUID as defined in IETF RFC 422
- */
-typedef uint8_t FFIMFUUID[16];
-
 /**
  * IMF Composition Playlist Base Resource
  */
@@ -84,7 +76,7 @@ typedef struct FFIMFBaseResource {
  */
 typedef struct FFIMFTrackFileResource {
 FFIMFBaseResource base;
-FFIMFUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
+AVUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
 } FFIMFTrackFileResource;
 
 /**
@@ -109,7 +101,7 @@ typedef struct FFIMFMarkerResource {
  * IMF Composition Playlist Virtual Track
  */
 typedef struct FFIMFBaseVirtualTrack {
-FFIMFUUID id_uuid; /**< TrackId associated with the Virtual Track */
+AVUUID id_uuid; /**< TrackId associated with the Virtual Track */
 } FFIMFBaseVirtualTrack;
 
 /**
@@ -135,7 +127,7 @@ typedef struct FFIMFMarkerVirtualTrack {
  * IMF Composition Playlist
  */
 typedef struct FFIMFCPL {
-FFIMFUUID id_uuid;   /**< 
CompositionPlaylist/Id element */
+AVUUID id_uuid;   /**< CompositionPlaylist/Id 
element */
 xmlChar *content_title_utf8; /**< 
CompositionPlaylist/ContentTitle element */
 AVRational edit_rate;/**< 
CompositionPlaylist/EditRate element */
 FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual 
Track */
@@ -196,7 +188,7 @@ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational 
*rational);
  * Reads a UUID from an XML element
  * @return 0 on success, < 0 AVERROR code on error.
  */
-int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16]);
+int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid);
 
 /**
  * Returns the first child element with the specified local name
diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index 102a6b4549..4acc20feee 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -70,32 +70,14 @@ xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr 
parent, const char *n
 return NULL;
 }
 
-int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16])
+int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
 {
 xmlChar *element_text = NULL;
-int scanf_ret;
 int ret = 0;
 
 element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
-scanf_ret = sscanf(element_text,
-   FF_IMF_UUID_FORMAT,
-   &uuid[0],
-   &uuid[1],
-   &uuid[2],
-   &uuid[3],
-   &uuid[4],
-   &uuid[5],
-   &uuid[6],
-   &uuid[7],
-   &uuid[8],
-   &uuid[9],
-   &uuid[10],
-   &uuid[11],
-   &uuid[12],
-   &uuid[13],
-   &uuid[14],
-   &uuid[15]);
-if (scanf_ret != 16) {
+ret = av_uuid_urn_parse(element_text, uuid);
+if (ret) {
 av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
 ret = AVERROR_INVALIDDATA;
 }
@@ -370,7 +352,7 @@ static int fill_marker_resource(xmlNodePtr 
marker_resource_elem,
 static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
 {
 int ret = 0;
-uint8_t uuid[16];
+AVUUID uuid;
 xmlNodePtr resource_list_elem = NULL;
 xmlNodePtr resource_elem = NULL;
 xmlNodePtr track_id_elem = NULL;
@@ -388,8 +370,8 @@ static int push_marker_sequence(xmlNodePtr 
marker_sequence_elem, FFIMFCPL *cpl)
 }
 av_log(NULL,
AV_LOG_DEBUG,
-   "Processing IMF CPL Marker Sequence for Virtual Track " 
FF_IMF_UUID_FORMAT "\n",
-   UID_ARG(uuid));
+   "Processing IMF CPL Marker Sequence for Virtual Track " AV_PRI_UUID 
"\n",
+   AV_UUID_ARG(uuid));
 
 /* create main marker virtual track if it does not exist */
 if (!cpl->main_markers_track) {
@@ -397,9 +379,9 @@ static int push_marker_sequence(xmlNodePtr 
marker_sequence_elem, FFIMFCPL *cpl)
 if (!cpl->main_markers_track)
 return AVERROR(ENOMEM);
 imf_marker_virtual_track_init(cpl->main_markers_track);
-   

[FFmpeg-devel] [PATCH v4 4/6] avformat/smoothstreamingenc: refactor to use avutil/uuid

2022-06-01 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/smoothstreamingenc.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 1713dd9009..ade6d5723b 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -34,6 +34,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/uuid.h"
 
 typedef struct Fragment {
 int64_t start_time, duration;
@@ -416,13 +417,13 @@ static int parse_fragment(AVFormatContext *s, const char 
*filename, int64_t *sta
 if (len < 8 || len >= *moof_size)
 goto fail;
 if (tag == MKTAG('u','u','i','d')) {
-static const uint8_t tfxd[] = {
+static const AVUUID tfxd = {
 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
 };
-uint8_t uuid[16];
+AVUUID uuid;
 avio_read(in, uuid, 16);
-if (!memcmp(uuid, tfxd, 16) && len >= 8 + 16 + 4 + 16) {
+if (av_uuid_equal(uuid, tfxd) && len >= 8 + 16 + 4 + 16) {
 avio_seek(in, 4, SEEK_CUR);
 *start_ts = avio_rb64(in);
 *duration = avio_rb64(in);
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 3/6] avformat/mov: refactor to use avutil/uuid

2022-06-01 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/mov.c| 25 +
 libavformat/movenc.c |  9 +
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index d7be593a86..f8248ab65b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -47,6 +47,7 @@
 #include "libavutil/spherical.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
+#include "libavutil/uuid.h"
 #include "libavcodec/ac3tab.h"
 #include "libavcodec/flac.h"
 #include "libavcodec/hevc.h"
@@ -5956,21 +5957,21 @@ static int mov_read_uuid(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 AVStream *st;
 MOVStreamContext *sc;
 int64_t ret;
-uint8_t uuid[16];
-static const uint8_t uuid_isml_manifest[] = {
+AVUUID uuid;
+static const AVUUID uuid_isml_manifest = {
 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
 };
-static const uint8_t uuid_xmp[] = {
+static const AVUUID uuid_xmp = {
 0xbe, 0x7a, 0xcf, 0xcb, 0x97, 0xa9, 0x42, 0xe8,
 0x9c, 0x71, 0x99, 0x94, 0x91, 0xe3, 0xaf, 0xac
 };
-static const uint8_t uuid_spherical[] = {
+static const AVUUID uuid_spherical = {
 0xff, 0xcc, 0x82, 0x63, 0xf8, 0x55, 0x4a, 0x93,
 0x88, 0x14, 0x58, 0x7a, 0x02, 0x52, 0x1f, 0xdd,
 };
 
-if (atom.size < sizeof(uuid) || atom.size >= FFMIN(INT_MAX, SIZE_MAX))
+if (atom.size < AV_UUID_LEN || atom.size >= FFMIN(INT_MAX, SIZE_MAX))
 return AVERROR_INVALIDDATA;
 
 if (c->fc->nb_streams < 1)
@@ -5978,13 +5979,13 @@ static int mov_read_uuid(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 st = c->fc->streams[c->fc->nb_streams - 1];
 sc = st->priv_data;
 
-ret = ffio_read_size(pb, uuid, sizeof(uuid));
+ret = ffio_read_size(pb, uuid, AV_UUID_LEN);
 if (ret < 0)
 return ret;
-if (!memcmp(uuid, uuid_isml_manifest, sizeof(uuid))) {
+if (av_uuid_equal(uuid, uuid_isml_manifest)) {
 uint8_t *buffer, *ptr;
 char *endptr;
-size_t len = atom.size - sizeof(uuid);
+size_t len = atom.size - AV_UUID_LEN;
 
 if (len < 4) {
 return AVERROR_INVALIDDATA;
@@ -6022,9 +6023,9 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 }
 
 av_free(buffer);
-} else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) {
+} else if (av_uuid_equal(uuid, uuid_xmp)) {
 uint8_t *buffer;
-size_t len = atom.size - sizeof(uuid);
+size_t len = atom.size - AV_UUID_LEN;
 if (c->export_xmp) {
 buffer = av_mallocz(len + 1);
 if (!buffer) {
@@ -6044,8 +6045,8 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 if (ret < 0)
 return ret;
 }
-} else if (!memcmp(uuid, uuid_spherical, sizeof(uuid))) {
-size_t len = atom.size - sizeof(uuid);
+} else if (av_uuid_equal(uuid, uuid_spherical)) {
+size_t len = atom.size - AV_UUID_LEN;
 ret = mov_parse_uuid_spherical(sc, pb, len);
 if (ret < 0)
 return ret;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index de971f94e8..b7b2f46a17 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -57,6 +57,7 @@
 #include "libavutil/timecode.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/color_utils.h"
+#include "libavutil/uuid.h"
 #include "hevc.h"
 #include "rtpenc.h"
 #include "mov_chan.h"
@@ -4487,14 +4488,14 @@ static int mov_write_isml_manifest(AVIOContext *pb, 
MOVMuxContext *mov, AVFormat
 int64_t pos = avio_tell(pb);
 int i;
 
-static const uint8_t uuid[] = {
+static const AVUUID uuid = {
 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
 };
 
 avio_wb32(pb, 0);
 ffio_wfourcc(pb, "uuid");
-avio_write(pb, uuid, sizeof(uuid));
+avio_write(pb, uuid, AV_UUID_LEN);
 avio_wb32(pb, 0);
 
 avio_printf(pb, "\n");
@@ -4753,7 +4754,7 @@ static int mov_write_tfxd_tag(AVIOContext *pb, MOVTrack 
*track)
 
 avio_wb32(pb, 0); /* size placeholder */
 ffio_wfourcc(pb, "uuid");
-avio_write(pb, uuid, sizeof(uuid));
+avio_write(pb, uuid, AV_UUID_LEN);
 avio_w8(pb, 1);
 avio_wb24(pb, 0);
 avio_wb64(pb, track->cluster[0].dts + track->cluster[0].cts);
@@ -4779,7 +4780,7 @@ static int mov_write_tfrf_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 avio_seek(pb, track->frag_info[entry].tfrf_offset, SEEK_SET);
 avio_wb32(pb, size);
 ffio_wfourcc(pb, "uuid");
-avio_write(pb, uuid, sizeof(uuid));
+avio_write(pb, uuid, AV_UUID_LEN);
 avio_w8(pb, 1);
 avio_wb24(pb, 0);
 avio_w8(pb, n);
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or em

[FFmpeg-devel] [PATCH v4 2/6] avutil/tests/uuid: add uuid tests

2022-06-01 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavutil/Makefile |   1 +
 libavutil/tests/.gitignore |   1 +
 libavutil/tests/uuid.c | 141 +
 tests/fate/libavutil.mak   |   5 ++
 4 files changed, 148 insertions(+)
 create mode 100644 libavutil/tests/uuid.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index a0c5cacef4..5c2ff319cc 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -261,6 +261,7 @@ TESTPROGS = adler32 
\
 tree\
 twofish \
 utf8\
+uuid\
 xtea\
 tea \
 
diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
index 9d90827954..919010e4fc 100644
--- a/libavutil/tests/.gitignore
+++ b/libavutil/tests/.gitignore
@@ -48,4 +48,5 @@
 /tree
 /twofish
 /utf8
+/uuid
 /xtea
diff --git a/libavutil/tests/uuid.c b/libavutil/tests/uuid.c
new file mode 100644
index 00..ff688be030
--- /dev/null
+++ b/libavutil/tests/uuid.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2022 Pierre-Anthony Lemieux 
+ *Zane van Iperen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/uuid.h"
+#include "libavutil/log.h"
+
+static const char *UUID_1= "6021b21e-894e-43ff-8317-1ca891c1c49b";
+static const char *UUID_1_UC = "6021B21E-894E-43FF-8317-1CA891C1C49B";
+static const char *UUID_1_MIXED  = "6021b21e-894E-43fF-8317-1CA891C1c49b";
+static const char *UUID_1_URN= 
"urn:uuid:6021b21e-894e-43ff-8317-1ca891c1c49b";
+static const AVUUID UUID_1_BYTES = {0x60, 0x21, 0xb2, 0x1e, 0x89, 0x4e, 0x43, 
0xff,
+0x83, 0x17, 0x1c, 0xa8, 0x91, 0xc1, 0xc4, 
0x9b};
+
+static const AVUUID UUID_NIL = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00};
+
+static const char *UUID_BAD_1 = "16a2c9f8-afbc-4767-8621-8cb2b27599";
+static const char *UUID_BAD_2 = "75df62c2999b4bd38c9d8058fcde9123";
+static const char *UUID_BAD_3 = "a1b9a05e-f1d1-464g-a951-1ba0a374f02";
+static const char *UUID_BAD_4 = "279c66d432-7b39-41d5-966f-5e8138265c20";
+
+int main(int argc, char **argv)
+{
+AVUUID uuid;
+AVUUID uuid2 = {0x32, 0xc7, 0x00, 0xc4, 0xd5, 0xd7, 0x42, 0x0,
+0x93, 0xc0, 0x3b, 0x6d, 0xea, 0x1b, 0x20, 0x5b};
+
+/* test parsing */
+
+if (av_uuid_parse(UUID_1, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test nil */
+
+av_uuid_nil(uuid);
+
+if (!av_uuid_equal(uuid, UUID_NIL))
+return 1;
+
+/* test equality */
+
+if (av_uuid_equal(UUID_1_BYTES, uuid2))
+return 1;
+
+/* test copy */
+
+av_uuid_copy(uuid2, UUID_1_BYTES);
+
+if (!av_uuid_equal(uuid2, UUID_1_BYTES))
+return 1;
+
+/* test uppercase parsing */
+
+if (av_uuid_parse(UUID_1_UC, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test mixed-case parsing */
+
+if (av_uuid_parse(UUID_1_MIXED, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test URN uuid parse */
+
+if (av_uuid_urn_parse(UUID_1_URN, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test parse range */
+
+if (av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 45, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test bad parse range */
+
+if (!av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 44, uuid))
+return 1;
+
+/* test bad parse range 2 */
+
+if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 44, uuid))
+return 1;
+
+/* test bad parse range 2 */
+
+if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 45, uuid))
+return 1;
+

[FFmpeg-devel] [PATCH v4 1/6] avutil/uuid: add utility library for manipulating UUIDs as specified in RFC 4122

2022-06-01 Thread pal
From: Zane van Iperen 

* Addresses review comments

Co-authored-by: Pierre-Anthony Lemieux 
Signed-off-by: Zane van Iperen 
---
 libavutil/Makefile |   2 +
 libavutil/uuid.c   | 141 +++
 libavutil/uuid.h   | 147 +
 3 files changed, 290 insertions(+)
 create mode 100644 libavutil/uuid.c
 create mode 100644 libavutil/uuid.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 234de62a4b..a0c5cacef4 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -82,6 +82,7 @@ HEADERS = adler32.h   
  \
   timestamp.h   \
   tree.h\
   twofish.h \
+  uuid.h\
   version.h \
   video_enc_params.h\
   xtea.h\
@@ -174,6 +175,7 @@ OBJS = adler32.o
\
tx_float.o   \
tx_double.o  \
tx_int32.o   \
+   uuid.o   \
version.o\
video_enc_params.o   \
film_grain_params.o  \
diff --git a/libavutil/uuid.c b/libavutil/uuid.c
new file mode 100644
index 00..062e28736b
--- /dev/null
+++ b/libavutil/uuid.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2022 Pierre-Anthony Lemieux 
+ *Zane van Iperen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, and the entire permission notice in its entirety,
+ *including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *products derived from this software without specific prior
+ *written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+/**
+ * @file
+ * UUID parsing and serialization utilities.
+ * The library treat the UUID as an opaque sequence of 16 unsigned bytes,
+ * i.e. ignoring the internal layout of the UUID, which depends on the type
+ * of the UUID.
+ *
+ * @author Pierre-Anthony Lemieux 
+ * @author Zane van Iperen 
+ */
+
+#include "uuid.h"
+#include "error.h"
+#include "avstring.h"
+
+int av_uuid_parse(const char *in, AVUUID uu)
+{
+if (strlen(in) != 36)
+return AVERROR(EINVAL);
+
+return av_uuid_parse_range(in, in + 36, uu);
+}
+
+static int xdigit_to_int(char c)
+{
+c = av_tolower(c);
+
+if (c >= 'a' && c <= 'f')
+ 

[FFmpeg-devel] [PATCH v3 6/6] avfilter/showinfo: refactor to use avutil/uuid

2022-05-30 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavfilter/vf_showinfo.c | 17 +
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 12d39310ef..0d6f2805bb 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -42,6 +42,7 @@
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/video_enc_params.h"
 #include "libavutil/detection_bbox.h"
+#include "libavutil/uuid.h"
 
 #include "avfilter.h"
 #include "internal.h"
@@ -421,29 +422,21 @@ static void dump_video_enc_params(AVFilterContext *ctx, 
const AVFrameSideData *s
 
 static void dump_sei_unregistered_metadata(AVFilterContext *ctx, const 
AVFrameSideData *sd)
 {
-const int uuid_size = 16;
 const uint8_t *user_data = sd->data;
 int i;
 
-if (sd->size < uuid_size) {
+if (sd->size < AV_UUID_LEN) {
 av_log(ctx, AV_LOG_ERROR, "invalid data(%"SIZE_SPECIFIER" < "
-   "UUID(%d-bytes))\n", sd->size, uuid_size);
+   "UUID(%d-bytes))\n", sd->size, AV_UUID_LEN);
 return;
 }
 
 av_log(ctx, AV_LOG_INFO, "User Data Unregistered:\n");
-av_log(ctx, AV_LOG_INFO, "UUID=");
-for (i = 0; i < uuid_size; i++) {
-av_log(ctx, AV_LOG_INFO, "%02x", user_data[i]);
-if (i == 3 || i == 5 || i == 7 || i == 9)
-av_log(ctx, AV_LOG_INFO, "-");
-}
-av_log(ctx, AV_LOG_INFO, "\n");
+av_log(ctx, AV_LOG_INFO, "UUID=" AV_PRI_UUID "\n", AV_UUID_ARG(user_data));
 
 av_log(ctx, AV_LOG_INFO, "User Data=");
-for (; i < sd->size; i++) {
+for (i = 16; i < sd->size; i++)
 av_log(ctx, AV_LOG_INFO, "%02x", user_data[i]);
-}
 av_log(ctx, AV_LOG_INFO, "\n");
 }
 
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 5/6] avformat/imf: refactor to use avutil/uuid

2022-05-30 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imf.h   | 18 -
 libavformat/imf_cpl.c   | 60 +++--
 libavformat/imfdec.c| 34 +++
 libavformat/tests/imf.c | 18 ++---
 4 files changed, 52 insertions(+), 78 deletions(-)

diff --git a/libavformat/imf.h b/libavformat/imf.h
index 62c4468ce9..4271cd9582 100644
--- a/libavformat/imf.h
+++ b/libavformat/imf.h
@@ -58,17 +58,9 @@
 #include "avformat.h"
 #include "libavformat/avio.h"
 #include "libavutil/rational.h"
+#include "libavutil/uuid.h"
 #include 
 
-#define FF_IMF_UUID_FORMAT\
-"urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-" \
-"%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-
-/**
- * UUID as defined in IETF RFC 422
- */
-typedef uint8_t FFIMFUUID[16];
-
 /**
  * IMF Composition Playlist Base Resource
  */
@@ -84,7 +76,7 @@ typedef struct FFIMFBaseResource {
  */
 typedef struct FFIMFTrackFileResource {
 FFIMFBaseResource base;
-FFIMFUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
+AVUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
 } FFIMFTrackFileResource;
 
 /**
@@ -109,7 +101,7 @@ typedef struct FFIMFMarkerResource {
  * IMF Composition Playlist Virtual Track
  */
 typedef struct FFIMFBaseVirtualTrack {
-FFIMFUUID id_uuid; /**< TrackId associated with the Virtual Track */
+AVUUID id_uuid; /**< TrackId associated with the Virtual Track */
 } FFIMFBaseVirtualTrack;
 
 /**
@@ -135,7 +127,7 @@ typedef struct FFIMFMarkerVirtualTrack {
  * IMF Composition Playlist
  */
 typedef struct FFIMFCPL {
-FFIMFUUID id_uuid;   /**< 
CompositionPlaylist/Id element */
+AVUUID id_uuid;   /**< CompositionPlaylist/Id 
element */
 xmlChar *content_title_utf8; /**< 
CompositionPlaylist/ContentTitle element */
 AVRational edit_rate;/**< 
CompositionPlaylist/EditRate element */
 FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual 
Track */
@@ -196,7 +188,7 @@ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational 
*rational);
  * Reads a UUID from an XML element
  * @return 0 on success, < 0 AVERROR code on error.
  */
-int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16]);
+int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid);
 
 /**
  * Returns the first child element with the specified local name
diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c
index 102a6b4549..4acc20feee 100644
--- a/libavformat/imf_cpl.c
+++ b/libavformat/imf_cpl.c
@@ -70,32 +70,14 @@ xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr 
parent, const char *n
 return NULL;
 }
 
-int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16])
+int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
 {
 xmlChar *element_text = NULL;
-int scanf_ret;
 int ret = 0;
 
 element_text = xmlNodeListGetString(element->doc, 
element->xmlChildrenNode, 1);
-scanf_ret = sscanf(element_text,
-   FF_IMF_UUID_FORMAT,
-   &uuid[0],
-   &uuid[1],
-   &uuid[2],
-   &uuid[3],
-   &uuid[4],
-   &uuid[5],
-   &uuid[6],
-   &uuid[7],
-   &uuid[8],
-   &uuid[9],
-   &uuid[10],
-   &uuid[11],
-   &uuid[12],
-   &uuid[13],
-   &uuid[14],
-   &uuid[15]);
-if (scanf_ret != 16) {
+ret = av_uuid_urn_parse(element_text, uuid);
+if (ret) {
 av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
 ret = AVERROR_INVALIDDATA;
 }
@@ -370,7 +352,7 @@ static int fill_marker_resource(xmlNodePtr 
marker_resource_elem,
 static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
 {
 int ret = 0;
-uint8_t uuid[16];
+AVUUID uuid;
 xmlNodePtr resource_list_elem = NULL;
 xmlNodePtr resource_elem = NULL;
 xmlNodePtr track_id_elem = NULL;
@@ -388,8 +370,8 @@ static int push_marker_sequence(xmlNodePtr 
marker_sequence_elem, FFIMFCPL *cpl)
 }
 av_log(NULL,
AV_LOG_DEBUG,
-   "Processing IMF CPL Marker Sequence for Virtual Track " 
FF_IMF_UUID_FORMAT "\n",
-   UID_ARG(uuid));
+   "Processing IMF CPL Marker Sequence for Virtual Track " AV_PRI_UUID 
"\n",
+   AV_UUID_ARG(uuid));
 
 /* create main marker virtual track if it does not exist */
 if (!cpl->main_markers_track) {
@@ -397,9 +379,9 @@ static int push_marker_sequence(xmlNodePtr 
marker_sequence_elem, FFIMFCPL *cpl)
 if (!cpl->main_markers_track)
 return AVERROR(ENOMEM);
 imf_marker_virtual_track_init(cpl->main_markers_track);
-   

[FFmpeg-devel] [PATCH v3 4/6] avformat/smoothstreamingenc: refactor to use avutil/uuid

2022-05-30 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/smoothstreamingenc.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 1713dd9009..ade6d5723b 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -34,6 +34,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
 #include "libavutil/mathematics.h"
+#include "libavutil/uuid.h"
 
 typedef struct Fragment {
 int64_t start_time, duration;
@@ -416,13 +417,13 @@ static int parse_fragment(AVFormatContext *s, const char 
*filename, int64_t *sta
 if (len < 8 || len >= *moof_size)
 goto fail;
 if (tag == MKTAG('u','u','i','d')) {
-static const uint8_t tfxd[] = {
+static const AVUUID tfxd = {
 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
 };
-uint8_t uuid[16];
+AVUUID uuid;
 avio_read(in, uuid, 16);
-if (!memcmp(uuid, tfxd, 16) && len >= 8 + 16 + 4 + 16) {
+if (av_uuid_equal(uuid, tfxd) && len >= 8 + 16 + 4 + 16) {
 avio_seek(in, 4, SEEK_CUR);
 *start_ts = avio_rb64(in);
 *duration = avio_rb64(in);
-- 
2.25.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 3/6] avformat/mov: refactor to use avutil/uuid

2022-05-30 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/mov.c| 25 +
 libavformat/movenc.c |  9 +
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index d7be593a86..f8248ab65b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -47,6 +47,7 @@
 #include "libavutil/spherical.h"
 #include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
+#include "libavutil/uuid.h"
 #include "libavcodec/ac3tab.h"
 #include "libavcodec/flac.h"
 #include "libavcodec/hevc.h"
@@ -5956,21 +5957,21 @@ static int mov_read_uuid(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 AVStream *st;
 MOVStreamContext *sc;
 int64_t ret;
-uint8_t uuid[16];
-static const uint8_t uuid_isml_manifest[] = {
+AVUUID uuid;
+static const AVUUID uuid_isml_manifest = {
 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
 };
-static const uint8_t uuid_xmp[] = {
+static const AVUUID uuid_xmp = {
 0xbe, 0x7a, 0xcf, 0xcb, 0x97, 0xa9, 0x42, 0xe8,
 0x9c, 0x71, 0x99, 0x94, 0x91, 0xe3, 0xaf, 0xac
 };
-static const uint8_t uuid_spherical[] = {
+static const AVUUID uuid_spherical = {
 0xff, 0xcc, 0x82, 0x63, 0xf8, 0x55, 0x4a, 0x93,
 0x88, 0x14, 0x58, 0x7a, 0x02, 0x52, 0x1f, 0xdd,
 };
 
-if (atom.size < sizeof(uuid) || atom.size >= FFMIN(INT_MAX, SIZE_MAX))
+if (atom.size < AV_UUID_LEN || atom.size >= FFMIN(INT_MAX, SIZE_MAX))
 return AVERROR_INVALIDDATA;
 
 if (c->fc->nb_streams < 1)
@@ -5978,13 +5979,13 @@ static int mov_read_uuid(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 st = c->fc->streams[c->fc->nb_streams - 1];
 sc = st->priv_data;
 
-ret = ffio_read_size(pb, uuid, sizeof(uuid));
+ret = ffio_read_size(pb, uuid, AV_UUID_LEN);
 if (ret < 0)
 return ret;
-if (!memcmp(uuid, uuid_isml_manifest, sizeof(uuid))) {
+if (av_uuid_equal(uuid, uuid_isml_manifest)) {
 uint8_t *buffer, *ptr;
 char *endptr;
-size_t len = atom.size - sizeof(uuid);
+size_t len = atom.size - AV_UUID_LEN;
 
 if (len < 4) {
 return AVERROR_INVALIDDATA;
@@ -6022,9 +6023,9 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 }
 
 av_free(buffer);
-} else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) {
+} else if (av_uuid_equal(uuid, uuid_xmp)) {
 uint8_t *buffer;
-size_t len = atom.size - sizeof(uuid);
+size_t len = atom.size - AV_UUID_LEN;
 if (c->export_xmp) {
 buffer = av_mallocz(len + 1);
 if (!buffer) {
@@ -6044,8 +6045,8 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 if (ret < 0)
 return ret;
 }
-} else if (!memcmp(uuid, uuid_spherical, sizeof(uuid))) {
-size_t len = atom.size - sizeof(uuid);
+} else if (av_uuid_equal(uuid, uuid_spherical)) {
+size_t len = atom.size - AV_UUID_LEN;
 ret = mov_parse_uuid_spherical(sc, pb, len);
 if (ret < 0)
 return ret;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index de971f94e8..b7b2f46a17 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -57,6 +57,7 @@
 #include "libavutil/timecode.h"
 #include "libavutil/dovi_meta.h"
 #include "libavutil/color_utils.h"
+#include "libavutil/uuid.h"
 #include "hevc.h"
 #include "rtpenc.h"
 #include "mov_chan.h"
@@ -4487,14 +4488,14 @@ static int mov_write_isml_manifest(AVIOContext *pb, 
MOVMuxContext *mov, AVFormat
 int64_t pos = avio_tell(pb);
 int i;
 
-static const uint8_t uuid[] = {
+static const AVUUID uuid = {
 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd,
 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66
 };
 
 avio_wb32(pb, 0);
 ffio_wfourcc(pb, "uuid");
-avio_write(pb, uuid, sizeof(uuid));
+avio_write(pb, uuid, AV_UUID_LEN);
 avio_wb32(pb, 0);
 
 avio_printf(pb, "\n");
@@ -4753,7 +4754,7 @@ static int mov_write_tfxd_tag(AVIOContext *pb, MOVTrack 
*track)
 
 avio_wb32(pb, 0); /* size placeholder */
 ffio_wfourcc(pb, "uuid");
-avio_write(pb, uuid, sizeof(uuid));
+avio_write(pb, uuid, AV_UUID_LEN);
 avio_w8(pb, 1);
 avio_wb24(pb, 0);
 avio_wb64(pb, track->cluster[0].dts + track->cluster[0].cts);
@@ -4779,7 +4780,7 @@ static int mov_write_tfrf_tag(AVIOContext *pb, 
MOVMuxContext *mov,
 avio_seek(pb, track->frag_info[entry].tfrf_offset, SEEK_SET);
 avio_wb32(pb, size);
 ffio_wfourcc(pb, "uuid");
-avio_write(pb, uuid, sizeof(uuid));
+avio_write(pb, uuid, AV_UUID_LEN);
 avio_w8(pb, 1);
 avio_wb24(pb, 0);
 avio_w8(pb, n);
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or em

[FFmpeg-devel] [PATCH v3 2/6] avutil/tests/uuid: add uuid tests

2022-05-30 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavutil/Makefile |   1 +
 libavutil/tests/.gitignore |   1 +
 libavutil/tests/uuid.c | 141 +
 tests/fate/libavutil.mak   |   5 ++
 4 files changed, 148 insertions(+)
 create mode 100644 libavutil/tests/uuid.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index a0c5cacef4..5c2ff319cc 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -261,6 +261,7 @@ TESTPROGS = adler32 
\
 tree\
 twofish \
 utf8\
+uuid\
 xtea\
 tea \
 
diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
index 9d90827954..919010e4fc 100644
--- a/libavutil/tests/.gitignore
+++ b/libavutil/tests/.gitignore
@@ -48,4 +48,5 @@
 /tree
 /twofish
 /utf8
+/uuid
 /xtea
diff --git a/libavutil/tests/uuid.c b/libavutil/tests/uuid.c
new file mode 100644
index 00..ff688be030
--- /dev/null
+++ b/libavutil/tests/uuid.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2022 Pierre-Anthony Lemieux 
+ *Zane van Iperen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/uuid.h"
+#include "libavutil/log.h"
+
+static const char *UUID_1= "6021b21e-894e-43ff-8317-1ca891c1c49b";
+static const char *UUID_1_UC = "6021B21E-894E-43FF-8317-1CA891C1C49B";
+static const char *UUID_1_MIXED  = "6021b21e-894E-43fF-8317-1CA891C1c49b";
+static const char *UUID_1_URN= 
"urn:uuid:6021b21e-894e-43ff-8317-1ca891c1c49b";
+static const AVUUID UUID_1_BYTES = {0x60, 0x21, 0xb2, 0x1e, 0x89, 0x4e, 0x43, 
0xff,
+0x83, 0x17, 0x1c, 0xa8, 0x91, 0xc1, 0xc4, 
0x9b};
+
+static const AVUUID UUID_NIL = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00};
+
+static const char *UUID_BAD_1 = "16a2c9f8-afbc-4767-8621-8cb2b27599";
+static const char *UUID_BAD_2 = "75df62c2999b4bd38c9d8058fcde9123";
+static const char *UUID_BAD_3 = "a1b9a05e-f1d1-464g-a951-1ba0a374f02";
+static const char *UUID_BAD_4 = "279c66d432-7b39-41d5-966f-5e8138265c20";
+
+int main(int argc, char **argv)
+{
+AVUUID uuid;
+AVUUID uuid2 = {0x32, 0xc7, 0x00, 0xc4, 0xd5, 0xd7, 0x42, 0x0,
+0x93, 0xc0, 0x3b, 0x6d, 0xea, 0x1b, 0x20, 0x5b};
+
+/* test parsing */
+
+if (av_uuid_parse(UUID_1, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test nil */
+
+av_uuid_nil(uuid);
+
+if (!av_uuid_equal(uuid, UUID_NIL))
+return 1;
+
+/* test equality */
+
+if (av_uuid_equal(UUID_1_BYTES, uuid2))
+return 1;
+
+/* test copy */
+
+av_uuid_copy(uuid2, UUID_1_BYTES);
+
+if (!av_uuid_equal(uuid2, UUID_1_BYTES))
+return 1;
+
+/* test uppercase parsing */
+
+if (av_uuid_parse(UUID_1_UC, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test mixed-case parsing */
+
+if (av_uuid_parse(UUID_1_MIXED, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test URN uuid parse */
+
+if (av_uuid_urn_parse(UUID_1_URN, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test parse range */
+
+if (av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 45, uuid))
+return 1;
+
+if (!av_uuid_equal(uuid, UUID_1_BYTES))
+return 1;
+
+/* test bad parse range */
+
+if (!av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 44, uuid))
+return 1;
+
+/* test bad parse range 2 */
+
+if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 44, uuid))
+return 1;
+
+/* test bad parse range 2 */
+
+if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 45, uuid))
+return 1;
+

[FFmpeg-devel] [PATCH v3 1/6] avutil/uuid: add utility library for manipulating UUIDs as specified in RFC 4122

2022-05-30 Thread pal
From: Zane van Iperen 

Addresses review comments including:

* simplifying av_uuid_parse_range()
* removing avcodec/cbs_sei from this refactoring exercise

Co-authored-by: Pierre-Anthony Lemieux 
Signed-off-by: Zane van Iperen 
---
 libavutil/Makefile |   2 +
 libavutil/uuid.c   | 142 +++
 libavutil/uuid.h   | 147 +
 3 files changed, 291 insertions(+)
 create mode 100644 libavutil/uuid.c
 create mode 100644 libavutil/uuid.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 234de62a4b..a0c5cacef4 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -82,6 +82,7 @@ HEADERS = adler32.h   
  \
   timestamp.h   \
   tree.h\
   twofish.h \
+  uuid.h\
   version.h \
   video_enc_params.h\
   xtea.h\
@@ -174,6 +175,7 @@ OBJS = adler32.o
\
tx_float.o   \
tx_double.o  \
tx_int32.o   \
+   uuid.o   \
version.o\
video_enc_params.o   \
film_grain_params.o  \
diff --git a/libavutil/uuid.c b/libavutil/uuid.c
new file mode 100644
index 00..8943212f30
--- /dev/null
+++ b/libavutil/uuid.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2022 Pierre-Anthony Lemieux 
+ *Zane van Iperen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, and the entire permission notice in its entirety,
+ *including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *products derived from this software without specific prior
+ *written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+/**
+ * @file
+ * UUID parsing and serialization utilities.
+ * The library treat the UUID as an opaque sequence of 16 unsigned bytes,
+ * i.e. ignoring the internal layout of the UUID, which depends on the type
+ * of the UUID.
+ *
+ * @author Pierre-Anthony Lemieux 
+ * @author Zane van Iperen 
+ */
+
+#include "uuid.h"
+#include "error.h"
+#include "avstring.h"
+#include 
+
+int av_uuid_parse(const char *in, AVUUID uu)
+{
+if (strlen(in) != 36)
+return AVERROR(EINVAL);
+
+return av_uuid_parse_range(in, in +

[FFmpeg-devel] [PATCH v4 6/7] avformat/imf: refactor to use ff_rescale_interval()

2022-03-11 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 20 ++--
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index ac212b05e1..a19e431df3 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -904,14 +904,6 @@ static int imf_probe(const AVProbeData *p)
 return AVPROBE_SCORE_MAX;
 }
 
-static void rescale_interval(AVRational tb_in, AVRational tb_out,
- int64_t *min_ts, int64_t *ts, int64_t *max_ts)
-{
-*ts = av_rescale_q(*ts, tb_in, tb_out);
-*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, AV_ROUND_UP | 
AV_ROUND_PASS_MINMAX);
-*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, AV_ROUND_DOWN | 
AV_ROUND_PASS_MINMAX);
-}
-
 static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb)
 {
 int dst_num;
@@ -937,13 +929,13 @@ static int imf_seek(AVFormatContext *s, int stream_index, 
int64_t min_ts,
 
 /* rescale timestamps to Composition edit units */
 if (stream_index < 0)
-rescale_interval(AV_TIME_BASE_Q,
- av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(AV_TIME_BASE_Q,
+av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
+&min_ts, &ts, &max_ts);
 else
-rescale_interval(s->streams[stream_index]->time_base,
- av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(s->streams[stream_index]->time_base,
+av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
+&min_ts, &ts, &max_ts);
 
 /* requested timestamp bounds are too close */
 if (max_ts < min_ts)
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 7/7] avformat/concat: refactor to use ff_rescale_interval()

2022-03-11 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/concatdec.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..cfe1329105 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -816,16 +816,6 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
 return 0;
 }
 
-static void rescale_interval(AVRational tb_in, AVRational tb_out,
- int64_t *min_ts, int64_t *ts, int64_t *max_ts)
-{
-*ts = av_rescale_q(*ts, tb_in, tb_out);
-*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out,
-   AV_ROUND_UP   | AV_ROUND_PASS_MINMAX);
-*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out,
-   AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX);
-}
-
 static int try_seek(AVFormatContext *avf, int stream,
 int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
 {
@@ -838,8 +828,8 @@ static int try_seek(AVFormatContext *avf, int stream,
 if (stream >= 0) {
 if (stream >= cat->avf->nb_streams)
 return AVERROR(EIO);
-rescale_interval(AV_TIME_BASE_Q, cat->avf->streams[stream]->time_base,
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(AV_TIME_BASE_Q, 
cat->avf->streams[stream]->time_base,
+&min_ts, &ts, &max_ts);
 }
 return avformat_seek_file(cat->avf, stream, min_ts, ts, max_ts, flags);
 }
@@ -853,8 +843,8 @@ static int real_seek(AVFormatContext *avf, int stream,
 if (stream >= 0) {
 if (stream >= avf->nb_streams)
 return AVERROR(EINVAL);
-rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,
+&min_ts, &ts, &max_ts);
 }
 
 left  = 0;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 5/7] avformat/tests: add test for ff_rescale_interval()

2022-03-11 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/Makefile   |  1 +
 libavformat/tests/.gitignore   |  1 +
 libavformat/tests/seek_utils.c | 57 ++
 tests/fate/libavformat.mak |  5 +++
 4 files changed, 64 insertions(+)
 create mode 100644 libavformat/tests/seek_utils.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6566e40cac..3acc939551 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -707,6 +707,7 @@ SKIPHEADERS-$(CONFIG_NETWORK)+= network.h rtsp.h
 
 TESTPROGS = seek\
 url \
+seek_utils
 #   async   \
 
 FIFO-MUXER-TESTPROGS-$(CONFIG_NETWORK)   += fifo_muxer
diff --git a/libavformat/tests/.gitignore b/libavformat/tests/.gitignore
index aabf76345e..cdd0cce061 100644
--- a/libavformat/tests/.gitignore
+++ b/libavformat/tests/.gitignore
@@ -6,3 +6,4 @@
 /seek
 /srtp
 /url
+/seek_utils
diff --git a/libavformat/tests/seek_utils.c b/libavformat/tests/seek_utils.c
new file mode 100644
index 00..cc679dca05
--- /dev/null
+++ b/libavformat/tests/seek_utils.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2022 Pierre-Anthony Lemieux 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavformat/internal.h"
+
+int main(void)
+{
+  int64_t ts_min;
+  int64_t ts;
+  int64_t ts_max;
+
+  ts_min = 10;
+  ts = 20;
+  ts_max = 30;
+
+  ff_rescale_interval(av_make_q(1, 1), av_make_q(10, 1), &ts_min, &ts, 
&ts_max);
+
+  if (ts_min != 1 || ts != 2 || ts_max != 3)
+return 1;
+
+  ts_min = 10;
+  ts = 32;
+  ts_max = 32;
+
+  ff_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max);
+
+  if (ts_min != 4 || ts != 11 || ts_max != 10)
+return 1;
+
+  ts_min = 10;
+  ts = 10;
+  ts_max = 32;
+
+  ff_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max);
+
+  if (ts_min != 4 || ts != 3 || ts_max != 10)
+return 1;
+
+  return 0;
+}
diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak
index 59ff0ebc8d..d2acb4c9e0 100644
--- a/tests/fate/libavformat.mak
+++ b/tests/fate/libavformat.mak
@@ -26,6 +26,11 @@ FATE_LIBAVFORMAT-$(CONFIG_IMF_DEMUXER) += fate-imf
 fate-imf: libavformat/tests/imf$(EXESUF)
 fate-imf: CMD = run libavformat/tests/imf$(EXESUF)
 
+FATE_LIBAVFORMAT += fate-seek_utils
+fate-seek_utils: libavformat/tests/seek_utils$(EXESUF)
+fate-seek_utils: CMD = run libavformat/tests/seek_utils$(EXESUF)
+fate-seek_utils: CMP = null
+
 FATE_LIBAVFORMAT += $(FATE_LIBAVFORMAT-yes)
 FATE-$(CONFIG_AVFORMAT) += $(FATE_LIBAVFORMAT)
 fate-libavformat: $(FATE_LIBAVFORMAT)
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 4/7] avformat/seek: add ff_rescale_interval() function

2022-03-11 Thread pal
From: Pierre-Anthony Lemieux 

Refactors a function used by avformat/concat and avformat/imf.

---
 libavformat/internal.h | 20 
 libavformat/seek.c | 10 ++
 2 files changed, 30 insertions(+)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index f24c68703f..5529403a68 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -1023,4 +1023,24 @@ void avpriv_register_devices(const AVOutputFormat * 
const o[], const AVInputForm
  */
 int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int 
shift_size);
 
+/**
+ * Rescales a timestamp and the endpoints of an interval to which the temstamp
+ * belongs, from a timebase `tb_in` to a timebase `tb_out`.
+ *
+ * The upper (lower) bound of the output interval is rounded up (down) such 
that
+ * the output interval always falls within the intput interval. The timestamp 
is
+ * rounded to the nearest integer and halfway cases away from zero, and can
+ * therefore fall outside of the output interval.
+ * 
+ * Useful to simplify the rescaling of the arguments of 
AVInputFormat::read_seek2()
+ *
+ * @param[in] tb_in  Timebase of the input `min_ts`, `ts` and `max_ts`
+ * @param[in] tb_out Timebase of the ouput `min_ts`, `ts` and `max_ts`
+ * @param[in,out] min_ts Lower bound of the interval
+ * @param[in,out] ts Timestamp
+ * @param[in,out] max_ts Upper bound of the interval
+ */
+void ff_rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts);
+
 #endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/seek.c b/libavformat/seek.c
index 405ca316b3..890aea7f8a 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -751,3 +751,13 @@ int avformat_flush(AVFormatContext *s)
 ff_read_frame_flush(s);
 return 0;
 }
+
+void ff_rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts)
+{
+*ts = av_rescale_q(*ts, tb_in, tb_out);
+*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out,
+   AV_ROUND_UP   | AV_ROUND_PASS_MINMAX);
+*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out,
+   AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX);
+}
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 3/7] avformat/imf: clean-up and reduce logging

2022-03-11 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 93 ++--
 1 file changed, 29 insertions(+), 64 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index f208b262c3..ac212b05e1 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -203,11 +203,8 @@ static int 
parse_imf_asset_map_from_xml_dom(AVFormatContext *s,
 }
 
 if (asset_map_element->type != XML_ELEMENT_NODE || 
av_strcasecmp(asset_map_element->name, "AssetMap")) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Unable to parse asset map XML - wrong root node name[%s] 
type[%d]\n",
-   asset_map_element->name,
-   (int)asset_map_element->type);
+av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - wrong root 
node name[%s] type[%d]\n",
+   asset_map_element->name, (int)asset_map_element->type);
 return AVERROR_INVALIDDATA;
 }
 
@@ -333,11 +330,8 @@ static int parse_assetmap(AVFormatContext *s, const char 
*url)
 
 ret = parse_imf_asset_map_from_xml_dom(s, doc, &c->asset_locator_map, 
base_url);
 if (!ret)
-av_log(s,
-   AV_LOG_DEBUG,
-   "Found %d assets from %s\n",
-   c->asset_locator_map.asset_count,
-   url);
+av_log(s, AV_LOG_DEBUG, "Found %d assets from %s\n",
+   c->asset_locator_map.asset_count, url);
 
 xmlFreeDoc(doc);
 
@@ -370,9 +364,7 @@ static int open_track_resource_context(AVFormatContext *s,
 IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + 
resource_index;
 
 if (track_resource->ctx) {
-av_log(s,
-   AV_LOG_DEBUG,
-   "Input context already opened for %s.\n",
+av_log(s, AV_LOG_DEBUG, "Input context already opened for %s.\n",
track_resource->locator->absolute_uri);
 return 0;
 }
@@ -400,11 +392,8 @@ static int open_track_resource_context(AVFormatContext *s,
   NULL,
   &opts);
 if (ret < 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open %s input context: %s\n",
-   track_resource->locator->absolute_uri,
-   av_err2str(ret));
+av_log(s, AV_LOG_ERROR, "Could not open %s input context: %s\n",
+   track_resource->locator->absolute_uri, av_err2str(ret));
 goto cleanup;
 }
 av_dict_free(&opts);
@@ -427,8 +416,7 @@ static int open_track_resource_context(AVFormatContext *s,
st->time_base))
 av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " 
AVRATIONAL_FORMAT
"and composition timeline position: " AVRATIONAL_FORMAT "\n",
-   st->time_base.num, st->time_base.den,
-   track->current_timestamp.den, track->current_timestamp.num);
+   AVRATIONAL_ARG(st->time_base), 
AVRATIONAL_ARG(track->current_timestamp));
 
 if (seek_offset) {
 av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 
"\n",
@@ -465,9 +453,7 @@ static int open_track_file_resource(AVFormatContext *s,
 
 asset_locator = find_asset_map_locator(&c->asset_locator_map, 
track_file_resource->track_file_uuid);
 if (!asset_locator) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not find asset locator for UUID: " FF_IMF_UUID_FORMAT 
"\n",
+av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(track_file_resource->track_file_uuid));
 return AVERROR_INVALIDDATA;
 }
@@ -618,9 +604,7 @@ static int open_cpl_tracks(AVFormatContext *s)
 
 if (c->cpl->main_image_2d_track) {
 if ((ret = open_virtual_track(s, c->cpl->main_image_2d_track, 
track_index++)) != 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open image track " FF_IMF_UUID_FORMAT "\n",
+av_log(s, AV_LOG_ERROR, "Could not open image track " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(c->cpl->main_image_2d_track->base.id_uuid));
 return ret;
 }
@@ -628,9 +612,7 @@ static int open_cpl_tracks(AVFormatContext *s)
 
 for (uint32_t i = 0; i < c->cpl->main_audio_track_count; i++) {
 if ((ret = open_virtual_track(s, &c->cpl->main_audio_tracks[i], 
track_index++)) != 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open audio track " FF_IMF_UUID_FORMAT "\n",
+av_log(s, AV_LOG_ERROR, "Could not open audio track " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(c->cpl->main_audio_tracks[i].base.id_uuid));
 return ret;
 }
@@ -706,13 +688,9 @@ static IMFVirtualTrackPlaybackCtx 
*get_next_track_with_minimum_timestamp(AVForma
 
 AVRational minimum_timestamp = av_make_q(INT32_MAX, 1);
 for (uint32_t i = c->track_count; i > 0; i--) {

[FFmpeg-devel] [PATCH v4 2/7] avformat/imf: add support for input seeking

2022-03-11 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer did not implement AVInputFormat::read_seek2(), resulting in
inefficient input seeking.

Addresses https://trac.ffmpeg.org/ticket/9648

Byte- and frame-seeking are not supported.

---
 libavformat/imfdec.c | 129 ++-
 1 file changed, 102 insertions(+), 27 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index b98af020d2..f208b262c3 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -359,13 +359,15 @@ static IMFAssetLocator 
*find_asset_map_locator(IMFAssetLocatorMap *asset_map, FF
 }
 
 static int open_track_resource_context(AVFormatContext *s,
-   IMFVirtualTrackResourcePlaybackCtx 
*track_resource)
+   IMFVirtualTrackPlaybackCtx *track,
+   int32_t resource_index)
 {
 IMFContext *c = s->priv_data;
 int ret = 0;
-int64_t entry_point;
+int64_t seek_offset = 0;
 AVDictionary *opts = NULL;
 AVStream *st;
+IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + 
resource_index;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -416,32 +418,27 @@ static int open_track_resource_context(AVFormatContext *s,
 
 st = track_resource->ctx->streams[0];
 
-/* Warn if the resource time base does not match the file time base */
-if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
-av_log(s,
-   AV_LOG_WARNING,
-   "Incoherent source stream timebase " AVRATIONAL_FORMAT
-   "regarding resource edit rate: " AVRATIONAL_FORMAT,
-   st->time_base.num,
-   st->time_base.den,
-   track_resource->resource->base.edit_rate.den,
-   track_resource->resource->base.edit_rate.num);
-
-entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
-   
av_inv_q(track_resource->resource->base.edit_rate));
-
-if (entry_point) {
-av_log(s,
-   AV_LOG_DEBUG,
-   "Seek at resource %s entry point: %" PRIu32 "\n",
-   track_resource->locator->absolute_uri,
-   track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
+/* Determine the seek offset into the Track File, taking into account:
+ * - the current timestamp within the virtual track
+ * - the entry point of the resource
+ */
+if (imf_time_to_ts(&seek_offset,
+   av_sub_q(track->current_timestamp, 
track_resource->ts_offset),
+   st->time_base))
+av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " 
AVRATIONAL_FORMAT
+   "and composition timeline position: " AVRATIONAL_FORMAT "\n",
+   st->time_base.num, st->time_base.den,
+   track->current_timestamp.den, track->current_timestamp.num);
+
+if (seek_offset) {
+av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 
"\n",
+   track_resource->locator->absolute_uri, seek_offset);
+ret = avformat_seek_file(track_resource->ctx, 0, seek_offset, 
seek_offset, seek_offset, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
"Could not seek at %" PRId64 "on %s: %s\n",
-   entry_point,
+   seek_offset,
track_resource->locator->absolute_uri,
av_err2str(ret));
 avformat_close_input(&track_resource->ctx);
@@ -584,7 +581,7 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
-ret = open_track_resource_context(s, &c->tracks[i]->resources[0]);
+ret = open_track_resource_context(s, c->tracks[i], 0);
 if (ret)
 return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
@@ -774,7 +771,7 @@ static int 
get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac
"Switch resource on track %d: re-open context\n",
track->index);
 
-ret = open_track_resource_context(s, track->resources + i);
+ret = open_track_resource_context(s, track, i);
 if (ret != 0)
 return ret;
 if (track->current_resource_index > 0)
@@ -942,6 +939,83 @@ static int imf_probe(const AVProbeData *p)
 return AVPROBE_SCORE_MAX;
 }
 
+static void rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts)
+{
+*ts = av_rescale_q(*ts, tb_in, tb_out);
+*min_ts = av_rescale_q_rnd(*min_ts, tb_i

[FFmpeg-devel] [PATCH v4 1/7] avformat/imf: relocate static function imf_time_to_ts()

2022-03-11 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 3ce850b75a..b98af020d2 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -154,6 +154,25 @@ static int imf_uri_is_dos_abs_path(const char *string)
 return 0;
 }
 
+static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
+{
+int dst_num;
+int dst_den;
+AVRational r;
+
+r = av_div_q(t, time_base);
+
+if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1))
+return 1;
+
+if (dst_den != 1)
+return 1;
+
+*ts = dst_num;
+
+return 0;
+}
+
 /**
  * Parse a ASSETMAP XML file to extract the UUID-URI mapping of assets.
  * @param s the current format context, if any (can be NULL).
@@ -772,25 +791,6 @@ static int 
get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac
 return AVERROR_STREAM_NOT_FOUND;
 }
 
-static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
-{
-int dst_num;
-int dst_den;
-AVRational r;
-
-r = av_div_q(t, time_base);
-
-if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1))
-return 1;
-
-if (dst_den != 1)
-return 1;
-
-*ts = dst_num;
-
-return 0;
-}
-
 static int imf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
 IMFVirtualTrackResourcePlaybackCtx *resource = NULL;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 7/7] avformat/concat: refactor to use ff_rescale_interval()

2022-03-07 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/concatdec.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..cfe1329105 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -816,16 +816,6 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
 return 0;
 }
 
-static void rescale_interval(AVRational tb_in, AVRational tb_out,
- int64_t *min_ts, int64_t *ts, int64_t *max_ts)
-{
-*ts = av_rescale_q(*ts, tb_in, tb_out);
-*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out,
-   AV_ROUND_UP   | AV_ROUND_PASS_MINMAX);
-*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out,
-   AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX);
-}
-
 static int try_seek(AVFormatContext *avf, int stream,
 int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
 {
@@ -838,8 +828,8 @@ static int try_seek(AVFormatContext *avf, int stream,
 if (stream >= 0) {
 if (stream >= cat->avf->nb_streams)
 return AVERROR(EIO);
-rescale_interval(AV_TIME_BASE_Q, cat->avf->streams[stream]->time_base,
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(AV_TIME_BASE_Q, 
cat->avf->streams[stream]->time_base,
+&min_ts, &ts, &max_ts);
 }
 return avformat_seek_file(cat->avf, stream, min_ts, ts, max_ts, flags);
 }
@@ -853,8 +843,8 @@ static int real_seek(AVFormatContext *avf, int stream,
 if (stream >= 0) {
 if (stream >= avf->nb_streams)
 return AVERROR(EINVAL);
-rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,
+&min_ts, &ts, &max_ts);
 }
 
 left  = 0;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 6/7] avformat/imf: refactor to use ff_rescale_interval()

2022-03-07 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 20 ++--
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index ac212b05e1..a19e431df3 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -904,14 +904,6 @@ static int imf_probe(const AVProbeData *p)
 return AVPROBE_SCORE_MAX;
 }
 
-static void rescale_interval(AVRational tb_in, AVRational tb_out,
- int64_t *min_ts, int64_t *ts, int64_t *max_ts)
-{
-*ts = av_rescale_q(*ts, tb_in, tb_out);
-*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, AV_ROUND_UP | 
AV_ROUND_PASS_MINMAX);
-*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, AV_ROUND_DOWN | 
AV_ROUND_PASS_MINMAX);
-}
-
 static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb)
 {
 int dst_num;
@@ -937,13 +929,13 @@ static int imf_seek(AVFormatContext *s, int stream_index, 
int64_t min_ts,
 
 /* rescale timestamps to Composition edit units */
 if (stream_index < 0)
-rescale_interval(AV_TIME_BASE_Q,
- av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(AV_TIME_BASE_Q,
+av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
+&min_ts, &ts, &max_ts);
 else
-rescale_interval(s->streams[stream_index]->time_base,
- av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
- &min_ts, &ts, &max_ts);
+ff_rescale_interval(s->streams[stream_index]->time_base,
+av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
+&min_ts, &ts, &max_ts);
 
 /* requested timestamp bounds are too close */
 if (max_ts < min_ts)
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 5/7] avformat/tests: add test for ff_rescale_interval()

2022-03-07 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/Makefile   |  1 +
 libavformat/tests/.gitignore   |  1 +
 libavformat/tests/seek_utils.c | 57 ++
 tests/fate/libavformat.mak |  5 +++
 4 files changed, 64 insertions(+)
 create mode 100644 libavformat/tests/seek_utils.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6566e40cac..3acc939551 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -707,6 +707,7 @@ SKIPHEADERS-$(CONFIG_NETWORK)+= network.h rtsp.h
 
 TESTPROGS = seek\
 url \
+seek_utils
 #   async   \
 
 FIFO-MUXER-TESTPROGS-$(CONFIG_NETWORK)   += fifo_muxer
diff --git a/libavformat/tests/.gitignore b/libavformat/tests/.gitignore
index aabf76345e..cdd0cce061 100644
--- a/libavformat/tests/.gitignore
+++ b/libavformat/tests/.gitignore
@@ -6,3 +6,4 @@
 /seek
 /srtp
 /url
+/seek_utils
diff --git a/libavformat/tests/seek_utils.c b/libavformat/tests/seek_utils.c
new file mode 100644
index 00..f368578fc4
--- /dev/null
+++ b/libavformat/tests/seek_utils.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2022 Pierre-Anthony Lemieux 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavformat/avio_internal.h"
+
+int main(void)
+{
+  int64_t ts_min;
+  int64_t ts;
+  int64_t ts_max;
+
+  ts_min = 10;
+  ts = 20;
+  ts_max = 30;
+
+  ff_rescale_interval(av_make_q(1, 1), av_make_q(10, 1), &ts_min, &ts, 
&ts_max);
+
+  if (ts_min != 1 || ts != 2 || ts_max != 3)
+return 1;
+
+  ts_min = 10;
+  ts = 32;
+  ts_max = 32;
+
+  ff_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max);
+
+  if (ts_min != 4 || ts != 11 || ts_max != 10)
+return 1;
+
+  ts_min = 10;
+  ts = 10;
+  ts_max = 32;
+
+  ff_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max);
+
+  if (ts_min != 4 || ts != 3 || ts_max != 10)
+return 1;
+
+  return 0;
+}
diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak
index 59ff0ebc8d..d2acb4c9e0 100644
--- a/tests/fate/libavformat.mak
+++ b/tests/fate/libavformat.mak
@@ -26,6 +26,11 @@ FATE_LIBAVFORMAT-$(CONFIG_IMF_DEMUXER) += fate-imf
 fate-imf: libavformat/tests/imf$(EXESUF)
 fate-imf: CMD = run libavformat/tests/imf$(EXESUF)
 
+FATE_LIBAVFORMAT += fate-seek_utils
+fate-seek_utils: libavformat/tests/seek_utils$(EXESUF)
+fate-seek_utils: CMD = run libavformat/tests/seek_utils$(EXESUF)
+fate-seek_utils: CMP = null
+
 FATE_LIBAVFORMAT += $(FATE_LIBAVFORMAT-yes)
 FATE-$(CONFIG_AVFORMAT) += $(FATE_LIBAVFORMAT)
 fate-libavformat: $(FATE_LIBAVFORMAT)
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 4/7] avformat/seek: add ff_rescale_interval() function

2022-03-07 Thread pal
From: Pierre-Anthony Lemieux 

Refactors a function used by avformat/concat and avformat/imf.

---
 libavformat/avio_internal.h | 21 +
 libavformat/seek.c  | 10 ++
 2 files changed, 31 insertions(+)

diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h
index 1f5e3d474b..ef2ec7864f 100644
--- a/libavformat/avio_internal.h
+++ b/libavformat/avio_internal.h
@@ -23,6 +23,7 @@
 #include "url.h"
 
 #include "libavutil/log.h"
+#include "libavutil/rational.h"
 
 extern const AVClass ff_avio_class;
 
@@ -281,4 +282,24 @@ int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, 
struct AVBPrint *bp);
 int64_t ff_read_string_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp,
int64_t max_len);
 
+/**
+ * Rescales a timestamp and the endpoints of an interval to which the temstamp
+ * belongs, from a timebase `tb_in` to a timebase `tb_out`.
+ *
+ * The upper (lower) bound of the output interval is rounded up (down) such 
that
+ * the output interval always falls within the intput interval. The timestamp 
is
+ * rounded to the nearest integer and halfway cases away from zero, and can
+ * therefore fall outside of the output interval.
+ * 
+ * Useful to simplify the rescaling of the arguments of 
AVInputFormat::read_seek2()
+ *
+ * @param[in] tb_in  Timebase of the input `min_ts`, `ts` and `max_ts`
+ * @param[in] tb_out Timebase of the ouput `min_ts`, `ts` and `max_ts`
+ * @param[in,out] min_ts Lower bound of the interval
+ * @param[in,out] ts Timestamp
+ * @param[in,out] max_ts Upper bound of the interval
+ */
+void ff_rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts);
+
 #endif /* AVFORMAT_AVIO_INTERNAL_H */
diff --git a/libavformat/seek.c b/libavformat/seek.c
index 405ca316b3..890aea7f8a 100644
--- a/libavformat/seek.c
+++ b/libavformat/seek.c
@@ -751,3 +751,13 @@ int avformat_flush(AVFormatContext *s)
 ff_read_frame_flush(s);
 return 0;
 }
+
+void ff_rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts)
+{
+*ts = av_rescale_q(*ts, tb_in, tb_out);
+*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out,
+   AV_ROUND_UP   | AV_ROUND_PASS_MINMAX);
+*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out,
+   AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX);
+}
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 3/7] avformat/imf: clean-up and reduce logging

2022-03-07 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 93 ++--
 1 file changed, 29 insertions(+), 64 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index f208b262c3..ac212b05e1 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -203,11 +203,8 @@ static int 
parse_imf_asset_map_from_xml_dom(AVFormatContext *s,
 }
 
 if (asset_map_element->type != XML_ELEMENT_NODE || 
av_strcasecmp(asset_map_element->name, "AssetMap")) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Unable to parse asset map XML - wrong root node name[%s] 
type[%d]\n",
-   asset_map_element->name,
-   (int)asset_map_element->type);
+av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - wrong root 
node name[%s] type[%d]\n",
+   asset_map_element->name, (int)asset_map_element->type);
 return AVERROR_INVALIDDATA;
 }
 
@@ -333,11 +330,8 @@ static int parse_assetmap(AVFormatContext *s, const char 
*url)
 
 ret = parse_imf_asset_map_from_xml_dom(s, doc, &c->asset_locator_map, 
base_url);
 if (!ret)
-av_log(s,
-   AV_LOG_DEBUG,
-   "Found %d assets from %s\n",
-   c->asset_locator_map.asset_count,
-   url);
+av_log(s, AV_LOG_DEBUG, "Found %d assets from %s\n",
+   c->asset_locator_map.asset_count, url);
 
 xmlFreeDoc(doc);
 
@@ -370,9 +364,7 @@ static int open_track_resource_context(AVFormatContext *s,
 IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + 
resource_index;
 
 if (track_resource->ctx) {
-av_log(s,
-   AV_LOG_DEBUG,
-   "Input context already opened for %s.\n",
+av_log(s, AV_LOG_DEBUG, "Input context already opened for %s.\n",
track_resource->locator->absolute_uri);
 return 0;
 }
@@ -400,11 +392,8 @@ static int open_track_resource_context(AVFormatContext *s,
   NULL,
   &opts);
 if (ret < 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open %s input context: %s\n",
-   track_resource->locator->absolute_uri,
-   av_err2str(ret));
+av_log(s, AV_LOG_ERROR, "Could not open %s input context: %s\n",
+   track_resource->locator->absolute_uri, av_err2str(ret));
 goto cleanup;
 }
 av_dict_free(&opts);
@@ -427,8 +416,7 @@ static int open_track_resource_context(AVFormatContext *s,
st->time_base))
 av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " 
AVRATIONAL_FORMAT
"and composition timeline position: " AVRATIONAL_FORMAT "\n",
-   st->time_base.num, st->time_base.den,
-   track->current_timestamp.den, track->current_timestamp.num);
+   AVRATIONAL_ARG(st->time_base), 
AVRATIONAL_ARG(track->current_timestamp));
 
 if (seek_offset) {
 av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 
"\n",
@@ -465,9 +453,7 @@ static int open_track_file_resource(AVFormatContext *s,
 
 asset_locator = find_asset_map_locator(&c->asset_locator_map, 
track_file_resource->track_file_uuid);
 if (!asset_locator) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not find asset locator for UUID: " FF_IMF_UUID_FORMAT 
"\n",
+av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(track_file_resource->track_file_uuid));
 return AVERROR_INVALIDDATA;
 }
@@ -618,9 +604,7 @@ static int open_cpl_tracks(AVFormatContext *s)
 
 if (c->cpl->main_image_2d_track) {
 if ((ret = open_virtual_track(s, c->cpl->main_image_2d_track, 
track_index++)) != 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open image track " FF_IMF_UUID_FORMAT "\n",
+av_log(s, AV_LOG_ERROR, "Could not open image track " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(c->cpl->main_image_2d_track->base.id_uuid));
 return ret;
 }
@@ -628,9 +612,7 @@ static int open_cpl_tracks(AVFormatContext *s)
 
 for (uint32_t i = 0; i < c->cpl->main_audio_track_count; i++) {
 if ((ret = open_virtual_track(s, &c->cpl->main_audio_tracks[i], 
track_index++)) != 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open audio track " FF_IMF_UUID_FORMAT "\n",
+av_log(s, AV_LOG_ERROR, "Could not open audio track " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(c->cpl->main_audio_tracks[i].base.id_uuid));
 return ret;
 }
@@ -706,13 +688,9 @@ static IMFVirtualTrackPlaybackCtx 
*get_next_track_with_minimum_timestamp(AVForma
 
 AVRational minimum_timestamp = av_make_q(INT32_MAX, 1);
 for (uint32_t i = c->track_count; i > 0; i--) {

[FFmpeg-devel] [PATCH v3 2/7] avformat/imf: add support for input seeking

2022-03-07 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer did not implement AVInputFormat::read_seek2(), resulting in
inefficient input seeking.

Addresses https://trac.ffmpeg.org/ticket/9648

Byte- and frame-seeking are not supported.

---
 libavformat/imfdec.c | 129 ++-
 1 file changed, 102 insertions(+), 27 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index b98af020d2..f208b262c3 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -359,13 +359,15 @@ static IMFAssetLocator 
*find_asset_map_locator(IMFAssetLocatorMap *asset_map, FF
 }
 
 static int open_track_resource_context(AVFormatContext *s,
-   IMFVirtualTrackResourcePlaybackCtx 
*track_resource)
+   IMFVirtualTrackPlaybackCtx *track,
+   int32_t resource_index)
 {
 IMFContext *c = s->priv_data;
 int ret = 0;
-int64_t entry_point;
+int64_t seek_offset = 0;
 AVDictionary *opts = NULL;
 AVStream *st;
+IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + 
resource_index;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -416,32 +418,27 @@ static int open_track_resource_context(AVFormatContext *s,
 
 st = track_resource->ctx->streams[0];
 
-/* Warn if the resource time base does not match the file time base */
-if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
-av_log(s,
-   AV_LOG_WARNING,
-   "Incoherent source stream timebase " AVRATIONAL_FORMAT
-   "regarding resource edit rate: " AVRATIONAL_FORMAT,
-   st->time_base.num,
-   st->time_base.den,
-   track_resource->resource->base.edit_rate.den,
-   track_resource->resource->base.edit_rate.num);
-
-entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
-   
av_inv_q(track_resource->resource->base.edit_rate));
-
-if (entry_point) {
-av_log(s,
-   AV_LOG_DEBUG,
-   "Seek at resource %s entry point: %" PRIu32 "\n",
-   track_resource->locator->absolute_uri,
-   track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
+/* Determine the seek offset into the Track File, taking into account:
+ * - the current timestamp within the virtual track
+ * - the entry point of the resource
+ */
+if (imf_time_to_ts(&seek_offset,
+   av_sub_q(track->current_timestamp, 
track_resource->ts_offset),
+   st->time_base))
+av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " 
AVRATIONAL_FORMAT
+   "and composition timeline position: " AVRATIONAL_FORMAT "\n",
+   st->time_base.num, st->time_base.den,
+   track->current_timestamp.den, track->current_timestamp.num);
+
+if (seek_offset) {
+av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 
"\n",
+   track_resource->locator->absolute_uri, seek_offset);
+ret = avformat_seek_file(track_resource->ctx, 0, seek_offset, 
seek_offset, seek_offset, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
"Could not seek at %" PRId64 "on %s: %s\n",
-   entry_point,
+   seek_offset,
track_resource->locator->absolute_uri,
av_err2str(ret));
 avformat_close_input(&track_resource->ctx);
@@ -584,7 +581,7 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
-ret = open_track_resource_context(s, &c->tracks[i]->resources[0]);
+ret = open_track_resource_context(s, c->tracks[i], 0);
 if (ret)
 return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
@@ -774,7 +771,7 @@ static int 
get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac
"Switch resource on track %d: re-open context\n",
track->index);
 
-ret = open_track_resource_context(s, track->resources + i);
+ret = open_track_resource_context(s, track, i);
 if (ret != 0)
 return ret;
 if (track->current_resource_index > 0)
@@ -942,6 +939,83 @@ static int imf_probe(const AVProbeData *p)
 return AVPROBE_SCORE_MAX;
 }
 
+static void rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts)
+{
+*ts = av_rescale_q(*ts, tb_in, tb_out);
+*min_ts = av_rescale_q_rnd(*min_ts, tb_i

[FFmpeg-devel] [PATCH v3 1/7] avformat/imf: relocate static function imf_time_to_ts()

2022-03-07 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 3ce850b75a..b98af020d2 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -154,6 +154,25 @@ static int imf_uri_is_dos_abs_path(const char *string)
 return 0;
 }
 
+static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
+{
+int dst_num;
+int dst_den;
+AVRational r;
+
+r = av_div_q(t, time_base);
+
+if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1))
+return 1;
+
+if (dst_den != 1)
+return 1;
+
+*ts = dst_num;
+
+return 0;
+}
+
 /**
  * Parse a ASSETMAP XML file to extract the UUID-URI mapping of assets.
  * @param s the current format context, if any (can be NULL).
@@ -772,25 +791,6 @@ static int 
get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac
 return AVERROR_STREAM_NOT_FOUND;
 }
 
-static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
-{
-int dst_num;
-int dst_den;
-AVRational r;
-
-r = av_div_q(t, time_base);
-
-if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1))
-return 1;
-
-if (dst_den != 1)
-return 1;
-
-*ts = dst_num;
-
-return 0;
-}
-
 static int imf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
 IMFVirtualTrackResourcePlaybackCtx *resource = NULL;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 7/7] avformat/concat: refactor to use av_rescale_interval()

2022-02-20 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/concatdec.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0603c6e254..3ddbe833c9 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -22,6 +22,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/bprint.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/timestamp.h"
@@ -816,16 +817,6 @@ static int concat_read_packet(AVFormatContext *avf, 
AVPacket *pkt)
 return 0;
 }
 
-static void rescale_interval(AVRational tb_in, AVRational tb_out,
- int64_t *min_ts, int64_t *ts, int64_t *max_ts)
-{
-*ts = av_rescale_q(*ts, tb_in, tb_out);
-*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out,
-   AV_ROUND_UP   | AV_ROUND_PASS_MINMAX);
-*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out,
-   AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX);
-}
-
 static int try_seek(AVFormatContext *avf, int stream,
 int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
 {
@@ -838,8 +829,8 @@ static int try_seek(AVFormatContext *avf, int stream,
 if (stream >= 0) {
 if (stream >= cat->avf->nb_streams)
 return AVERROR(EIO);
-rescale_interval(AV_TIME_BASE_Q, cat->avf->streams[stream]->time_base,
- &min_ts, &ts, &max_ts);
+av_rescale_interval(AV_TIME_BASE_Q, 
cat->avf->streams[stream]->time_base,
+&min_ts, &ts, &max_ts);
 }
 return avformat_seek_file(cat->avf, stream, min_ts, ts, max_ts, flags);
 }
@@ -853,8 +844,8 @@ static int real_seek(AVFormatContext *avf, int stream,
 if (stream >= 0) {
 if (stream >= avf->nb_streams)
 return AVERROR(EINVAL);
-rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,
- &min_ts, &ts, &max_ts);
+av_rescale_interval(avf->streams[stream]->time_base, AV_TIME_BASE_Q,
+&min_ts, &ts, &max_ts);
 }
 
 left  = 0;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 6/7] avformat/imf: refactor to use av_rescale_interval()

2022-02-20 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index ac212b05e1..bc27e3cc2a 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -69,6 +69,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "mxf.h"
 #include "url.h"
@@ -904,14 +905,6 @@ static int imf_probe(const AVProbeData *p)
 return AVPROBE_SCORE_MAX;
 }
 
-static void rescale_interval(AVRational tb_in, AVRational tb_out,
- int64_t *min_ts, int64_t *ts, int64_t *max_ts)
-{
-*ts = av_rescale_q(*ts, tb_in, tb_out);
-*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out, AV_ROUND_UP | 
AV_ROUND_PASS_MINMAX);
-*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out, AV_ROUND_DOWN | 
AV_ROUND_PASS_MINMAX);
-}
-
 static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb)
 {
 int dst_num;
@@ -937,13 +930,13 @@ static int imf_seek(AVFormatContext *s, int stream_index, 
int64_t min_ts,
 
 /* rescale timestamps to Composition edit units */
 if (stream_index < 0)
-rescale_interval(AV_TIME_BASE_Q,
- av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
- &min_ts, &ts, &max_ts);
+av_rescale_interval(AV_TIME_BASE_Q,
+av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
+&min_ts, &ts, &max_ts);
 else
-rescale_interval(s->streams[stream_index]->time_base,
- av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
- &min_ts, &ts, &max_ts);
+av_rescale_interval(s->streams[stream_index]->time_base,
+av_make_q(c->cpl->edit_rate.den, 
c->cpl->edit_rate.num),
+&min_ts, &ts, &max_ts);
 
 /* requested timestamp bounds are too close */
 if (max_ts < min_ts)
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 5/7] avutil/tests: add test for avutil/mathematics

2022-02-20 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavutil/Makefile|  1 +
 libavutil/tests/.gitignore|  1 +
 libavutil/tests/mathematics.c | 57 +++
 tests/fate/libavutil.mak  |  5 +++
 4 files changed, 64 insertions(+)
 create mode 100644 libavutil/tests/mathematics.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index d17876df1a..d1c002e43f 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -239,6 +239,7 @@ TESTPROGS = adler32 
\
 lfg \
 lls \
 log \
+mathematics \
 md5 \
 murmur3 \
 opt \
diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
index 9d90827954..aba94af388 100644
--- a/libavutil/tests/.gitignore
+++ b/libavutil/tests/.gitignore
@@ -30,6 +30,7 @@
 /lls
 /log
 /lzo
+/mathematics
 /md5
 /murmur3
 /opt
diff --git a/libavutil/tests/mathematics.c b/libavutil/tests/mathematics.c
new file mode 100644
index 00..45a82617aa
--- /dev/null
+++ b/libavutil/tests/mathematics.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2022 Pierre-Anthony Lemieux 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/mathematics.h"
+
+int main(void)
+{
+  int64_t ts_min;
+  int64_t ts;
+  int64_t ts_max;
+
+  ts_min = 10;
+  ts = 20;
+  ts_max = 30;
+
+  av_rescale_interval(av_make_q(1, 1), av_make_q(10, 1), &ts_min, &ts, 
&ts_max);
+
+  if (ts_min != 1 || ts != 2 || ts_max != 3)
+return 1;
+
+  ts_min = 10;
+  ts = 32;
+  ts_max = 32;
+
+  av_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max);
+
+  if (ts_min != 4 || ts != 11 || ts_max != 10)
+return 1;
+
+  ts_min = 10;
+  ts = 10;
+  ts_max = 32;
+
+  av_rescale_interval(av_make_q(1, 1), av_make_q(3, 1), &ts_min, &ts, &ts_max);
+
+  if (ts_min != 4 || ts != 3 || ts_max != 10)
+return 1;
+
+  return 0;
+}
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 1ec9ed00ad..92b9b82aa8 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -166,6 +166,11 @@ FATE_LIBAVUTIL += fate-opt
 fate-opt: libavutil/tests/opt$(EXESUF)
 fate-opt: CMD = run libavutil/tests/opt$(EXESUF)
 
+FATE_LIBAVUTIL += fate-mathematics
+fate-mathematics: libavutil/tests/mathematics$(EXESUF)
+fate-mathematics: CMD = run libavutil/tests/mathematics$(EXESUF)
+fate-mathematics: CMP = null
+
 FATE_LIBAVUTIL += $(FATE_LIBAVUTIL-yes)
 FATE-$(CONFIG_AVUTIL) += $(FATE_LIBAVUTIL)
 fate-libavutil: $(FATE_LIBAVUTIL)
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 4/7] avutil/mathematics: add av_rescale_interval() function

2022-02-20 Thread pal
From: Pierre-Anthony Lemieux 

Refactors a function used by avformat/concat and avformat/imf.

---
 libavutil/mathematics.c | 10 ++
 libavutil/mathematics.h | 21 +
 2 files changed, 31 insertions(+)

diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index f4e541fa24..2c7f57b950 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -212,3 +212,13 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, 
AVRational inc_tb, int64_t i
 return av_sat_add64(av_rescale_q(old + 1, inc_tb, ts_tb), ts - old_ts);
 }
 }
+
+void av_rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts)
+{
+*ts = av_rescale_q(*ts, tb_in, tb_out);
+*min_ts = av_rescale_q_rnd(*min_ts, tb_in, tb_out,
+   AV_ROUND_UP   | AV_ROUND_PASS_MINMAX);
+*max_ts = av_rescale_q_rnd(*max_ts, tb_in, tb_out,
+   AV_ROUND_DOWN | AV_ROUND_PASS_MINMAX);
+}
diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h
index 64d4137a60..eb8a3f4002 100644
--- a/libavutil/mathematics.h
+++ b/libavutil/mathematics.h
@@ -161,6 +161,27 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational 
cq) av_const;
 int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,
  enum AVRounding rnd) av_const;
 
+/**
+ * Rescales a timestamp and the endpoints of an interval to which the temstamp
+ * belongs, from a timebase `tb_in` to a timebase `tb_out`.
+ *
+ * The upper (lower) bound of the output interval is rounded up (down) such 
that
+ * the output interval always falls within the intput interval. The timestamp 
is
+ * rounded to the nearest integer and halfway cases away from zero, and can
+ * therefore fall outside of the output interval.
+ * 
+ * Useful to simplify the rescaling of the arguments of 
AVInputFormat::read_seek2()
+ *
+ * @param[in] tb_in  Timebase of the input `min_ts`, `ts` and `max_ts`
+ * @param[in] tb_out Timebase of the ouput `min_ts`, `ts` and `max_ts`
+ * @param[in,out] min_ts Lower bound of the interval
+ * @param[in,out] ts Timestamp
+ * @param[in,out] max_ts Upper bound of the interval
+ */
+void av_rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts);
+
+
 /**
  * Compare two timestamps each in its own time base.
  *
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 3/7] avformat/imf: clean-up and reduce logging

2022-02-20 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 93 ++--
 1 file changed, 29 insertions(+), 64 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index f208b262c3..ac212b05e1 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -203,11 +203,8 @@ static int 
parse_imf_asset_map_from_xml_dom(AVFormatContext *s,
 }
 
 if (asset_map_element->type != XML_ELEMENT_NODE || 
av_strcasecmp(asset_map_element->name, "AssetMap")) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Unable to parse asset map XML - wrong root node name[%s] 
type[%d]\n",
-   asset_map_element->name,
-   (int)asset_map_element->type);
+av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - wrong root 
node name[%s] type[%d]\n",
+   asset_map_element->name, (int)asset_map_element->type);
 return AVERROR_INVALIDDATA;
 }
 
@@ -333,11 +330,8 @@ static int parse_assetmap(AVFormatContext *s, const char 
*url)
 
 ret = parse_imf_asset_map_from_xml_dom(s, doc, &c->asset_locator_map, 
base_url);
 if (!ret)
-av_log(s,
-   AV_LOG_DEBUG,
-   "Found %d assets from %s\n",
-   c->asset_locator_map.asset_count,
-   url);
+av_log(s, AV_LOG_DEBUG, "Found %d assets from %s\n",
+   c->asset_locator_map.asset_count, url);
 
 xmlFreeDoc(doc);
 
@@ -370,9 +364,7 @@ static int open_track_resource_context(AVFormatContext *s,
 IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + 
resource_index;
 
 if (track_resource->ctx) {
-av_log(s,
-   AV_LOG_DEBUG,
-   "Input context already opened for %s.\n",
+av_log(s, AV_LOG_DEBUG, "Input context already opened for %s.\n",
track_resource->locator->absolute_uri);
 return 0;
 }
@@ -400,11 +392,8 @@ static int open_track_resource_context(AVFormatContext *s,
   NULL,
   &opts);
 if (ret < 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open %s input context: %s\n",
-   track_resource->locator->absolute_uri,
-   av_err2str(ret));
+av_log(s, AV_LOG_ERROR, "Could not open %s input context: %s\n",
+   track_resource->locator->absolute_uri, av_err2str(ret));
 goto cleanup;
 }
 av_dict_free(&opts);
@@ -427,8 +416,7 @@ static int open_track_resource_context(AVFormatContext *s,
st->time_base))
 av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " 
AVRATIONAL_FORMAT
"and composition timeline position: " AVRATIONAL_FORMAT "\n",
-   st->time_base.num, st->time_base.den,
-   track->current_timestamp.den, track->current_timestamp.num);
+   AVRATIONAL_ARG(st->time_base), 
AVRATIONAL_ARG(track->current_timestamp));
 
 if (seek_offset) {
 av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 
"\n",
@@ -465,9 +453,7 @@ static int open_track_file_resource(AVFormatContext *s,
 
 asset_locator = find_asset_map_locator(&c->asset_locator_map, 
track_file_resource->track_file_uuid);
 if (!asset_locator) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not find asset locator for UUID: " FF_IMF_UUID_FORMAT 
"\n",
+av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(track_file_resource->track_file_uuid));
 return AVERROR_INVALIDDATA;
 }
@@ -618,9 +604,7 @@ static int open_cpl_tracks(AVFormatContext *s)
 
 if (c->cpl->main_image_2d_track) {
 if ((ret = open_virtual_track(s, c->cpl->main_image_2d_track, 
track_index++)) != 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open image track " FF_IMF_UUID_FORMAT "\n",
+av_log(s, AV_LOG_ERROR, "Could not open image track " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(c->cpl->main_image_2d_track->base.id_uuid));
 return ret;
 }
@@ -628,9 +612,7 @@ static int open_cpl_tracks(AVFormatContext *s)
 
 for (uint32_t i = 0; i < c->cpl->main_audio_track_count; i++) {
 if ((ret = open_virtual_track(s, &c->cpl->main_audio_tracks[i], 
track_index++)) != 0) {
-av_log(s,
-   AV_LOG_ERROR,
-   "Could not open audio track " FF_IMF_UUID_FORMAT "\n",
+av_log(s, AV_LOG_ERROR, "Could not open audio track " 
FF_IMF_UUID_FORMAT "\n",
UID_ARG(c->cpl->main_audio_tracks[i].base.id_uuid));
 return ret;
 }
@@ -706,13 +688,9 @@ static IMFVirtualTrackPlaybackCtx 
*get_next_track_with_minimum_timestamp(AVForma
 
 AVRational minimum_timestamp = av_make_q(INT32_MAX, 1);
 for (uint32_t i = c->track_count; i > 0; i--) {

[FFmpeg-devel] [PATCH v2 2/7] avformat/imf: add support for input seeking

2022-02-20 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer did not implement AVInputFormat::read_seek2(), resulting in
inefficient input seeking.

Addresses https://trac.ffmpeg.org/ticket/9648

Byte- and frame-seeking are not supported.

---
 libavformat/imfdec.c | 129 ++-
 1 file changed, 102 insertions(+), 27 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index b98af020d2..f208b262c3 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -359,13 +359,15 @@ static IMFAssetLocator 
*find_asset_map_locator(IMFAssetLocatorMap *asset_map, FF
 }
 
 static int open_track_resource_context(AVFormatContext *s,
-   IMFVirtualTrackResourcePlaybackCtx 
*track_resource)
+   IMFVirtualTrackPlaybackCtx *track,
+   int32_t resource_index)
 {
 IMFContext *c = s->priv_data;
 int ret = 0;
-int64_t entry_point;
+int64_t seek_offset = 0;
 AVDictionary *opts = NULL;
 AVStream *st;
+IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + 
resource_index;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -416,32 +418,27 @@ static int open_track_resource_context(AVFormatContext *s,
 
 st = track_resource->ctx->streams[0];
 
-/* Warn if the resource time base does not match the file time base */
-if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
-av_log(s,
-   AV_LOG_WARNING,
-   "Incoherent source stream timebase " AVRATIONAL_FORMAT
-   "regarding resource edit rate: " AVRATIONAL_FORMAT,
-   st->time_base.num,
-   st->time_base.den,
-   track_resource->resource->base.edit_rate.den,
-   track_resource->resource->base.edit_rate.num);
-
-entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
-   
av_inv_q(track_resource->resource->base.edit_rate));
-
-if (entry_point) {
-av_log(s,
-   AV_LOG_DEBUG,
-   "Seek at resource %s entry point: %" PRIu32 "\n",
-   track_resource->locator->absolute_uri,
-   track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
+/* Determine the seek offset into the Track File, taking into account:
+ * - the current timestamp within the virtual track
+ * - the entry point of the resource
+ */
+if (imf_time_to_ts(&seek_offset,
+   av_sub_q(track->current_timestamp, 
track_resource->ts_offset),
+   st->time_base))
+av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " 
AVRATIONAL_FORMAT
+   "and composition timeline position: " AVRATIONAL_FORMAT "\n",
+   st->time_base.num, st->time_base.den,
+   track->current_timestamp.den, track->current_timestamp.num);
+
+if (seek_offset) {
+av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 
"\n",
+   track_resource->locator->absolute_uri, seek_offset);
+ret = avformat_seek_file(track_resource->ctx, 0, seek_offset, 
seek_offset, seek_offset, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
"Could not seek at %" PRId64 "on %s: %s\n",
-   entry_point,
+   seek_offset,
track_resource->locator->absolute_uri,
av_err2str(ret));
 avformat_close_input(&track_resource->ctx);
@@ -584,7 +581,7 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
-ret = open_track_resource_context(s, &c->tracks[i]->resources[0]);
+ret = open_track_resource_context(s, c->tracks[i], 0);
 if (ret)
 return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
@@ -774,7 +771,7 @@ static int 
get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac
"Switch resource on track %d: re-open context\n",
track->index);
 
-ret = open_track_resource_context(s, track->resources + i);
+ret = open_track_resource_context(s, track, i);
 if (ret != 0)
 return ret;
 if (track->current_resource_index > 0)
@@ -942,6 +939,83 @@ static int imf_probe(const AVProbeData *p)
 return AVPROBE_SCORE_MAX;
 }
 
+static void rescale_interval(AVRational tb_in, AVRational tb_out,
+ int64_t *min_ts, int64_t *ts, int64_t *max_ts)
+{
+*ts = av_rescale_q(*ts, tb_in, tb_out);
+*min_ts = av_rescale_q_rnd(*min_ts, tb_i

[FFmpeg-devel] [PATCH v2 1/7] avformat/imf: relocate static function imf_time_to_ts()

2022-02-20 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 3ce850b75a..b98af020d2 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -154,6 +154,25 @@ static int imf_uri_is_dos_abs_path(const char *string)
 return 0;
 }
 
+static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
+{
+int dst_num;
+int dst_den;
+AVRational r;
+
+r = av_div_q(t, time_base);
+
+if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1))
+return 1;
+
+if (dst_den != 1)
+return 1;
+
+*ts = dst_num;
+
+return 0;
+}
+
 /**
  * Parse a ASSETMAP XML file to extract the UUID-URI mapping of assets.
  * @param s the current format context, if any (can be NULL).
@@ -772,25 +791,6 @@ static int 
get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrac
 return AVERROR_STREAM_NOT_FOUND;
 }
 
-static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
-{
-int dst_num;
-int dst_den;
-AVRational r;
-
-r = av_div_q(t, time_base);
-
-if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1))
-return 1;
-
-if (dst_den != 1)
-return 1;
-
-*ts = dst_num;
-
-return 0;
-}
-
 static int imf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
 IMFVirtualTrackResourcePlaybackCtx *resource = NULL;
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 3/3] avformat/imf: document IMFVirtualTrackResourcePlaybackCtx

2022-02-16 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 17a21f5ef9..143f1086b6 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -96,12 +96,12 @@ typedef struct IMFAssetLocatorMap {
 } IMFAssetLocatorMap;
 
 typedef struct IMFVirtualTrackResourcePlaybackCtx {
-IMFAssetLocator *locator;
-FFIMFTrackFileResource *resource;
-AVFormatContext *ctx;
-AVRational start_time;
-AVRational end_time;
-AVRational ts_offset;
+IMFAssetLocator *locator;  /**< Location of the resource */
+FFIMFTrackFileResource *resource;  /**< Underlying IMF CPL resource */
+AVFormatContext *ctx;  /**< Context associated with the 
resource */
+AVRational start_time; /**< inclusive start time of the 
resource on the CPL timeline (s) */
+AVRational end_time;   /**< exclusive end time of the resource 
on the CPL timeline (s) */
+AVRational ts_offset;  /**< start_time minus the entry point 
into the resource (s) */
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 2/3] avformat/imf: fix packet pts, dts and muxing

2022-02-16 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer does not set the DTS and PTS of packets accurately in all
scenarios. Moreover, audio packets are not trimmed when they exceed the
duration of the underlying resource.

imf-cpl-with-repeat FATE ref file is regenerated.

Addresses https://trac.ffmpeg.org/ticket/9611

---
 libavformat/imfdec.c   | 263 +++--
 tests/ref/fate/imf-cpl-with-repeat |  20 +--
 2 files changed, 181 insertions(+), 102 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 48bd5c78e8..17a21f5ef9 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -65,8 +65,10 @@
 #include "avio_internal.h"
 #include "imf.h"
 #include "internal.h"
+#include "libavcodec/packet.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
 #include "mxf.h"
 #include "url.h"
@@ -97,6 +99,9 @@ typedef struct IMFVirtualTrackResourcePlaybackCtx {
 IMFAssetLocator *locator;
 FFIMFTrackFileResource *resource;
 AVFormatContext *ctx;
+AVRational start_time;
+AVRational end_time;
+AVRational ts_offset;
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
@@ -108,7 +113,6 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
 int32_t current_resource_index;/**< Index of the current 
resource in resources,
 or < 0 if a current 
resource has yet to be selected */
-int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
 typedef struct IMFContext {
@@ -342,6 +346,7 @@ static int open_track_resource_context(AVFormatContext *s,
 int ret = 0;
 int64_t entry_point;
 AVDictionary *opts = NULL;
+AVStream *st;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -383,23 +388,28 @@ static int open_track_resource_context(AVFormatContext *s,
 }
 av_dict_free(&opts);
 
-/* Compare the source timebase to the resource edit rate,
- * considering the first stream of the source file
- */
-if (av_cmp_q(track_resource->ctx->streams[0]->time_base,
- av_inv_q(track_resource->resource->base.edit_rate)))
+/* make sure there is only one stream in the file */
+
+if (track_resource->ctx->nb_streams != 1) {
+ret = AVERROR_INVALIDDATA;
+goto cleanup;
+}
+
+st = track_resource->ctx->streams[0];
+
+/* Warn if the resource time base does not match the file time base */
+if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
 av_log(s,
AV_LOG_WARNING,
-   "Incoherent source stream timebase %d/%d regarding resource 
edit rate: %d/%d",
-   track_resource->ctx->streams[0]->time_base.num,
-   track_resource->ctx->streams[0]->time_base.den,
+   "Incoherent source stream timebase " AVRATIONAL_FORMAT
+   "regarding resource edit rate: " AVRATIONAL_FORMAT,
+   st->time_base.num,
+   st->time_base.den,
track_resource->resource->base.edit_rate.den,
track_resource->resource->base.edit_rate.num);
 
-entry_point = (int64_t)track_resource->resource->base.entry_point
-* track_resource->resource->base.edit_rate.den
-* AV_TIME_BASE
-/ track_resource->resource->base.edit_rate.num;
+entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
+   
av_inv_q(track_resource->resource->base.edit_rate));
 
 if (entry_point) {
 av_log(s,
@@ -407,7 +417,7 @@ static int open_track_resource_context(AVFormatContext *s,
"Seek at resource %s entry point: %" PRIu32 "\n",
track_resource->locator->absolute_uri,
track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, -1, entry_point, 
entry_point, entry_point, 0);
+ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
@@ -470,11 +480,16 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-track->resources[track->resource_count++] = vt_ctx;
-track->duration = av_add_q(track->duration,
+vt_ctx.start_time = track->duration;
+vt_ctx.ts_offset = av_sub_q(vt_ctx.start_time,
+
av_div_q(av_make_q((int)track_file_resource->base.entry_point, 1),
+ 
track_file_resource->base.edit_rate));
+vt_ctx.end_time = av_add_q(track->duration,

[FFmpeg-devel] [PATCH v4 1/3] avformat/imf: open resources only when first needed

2022-02-16 Thread pal
From: Pierre-Anthony Lemieux 

IMF CPLs can reference thousands of files, which can result in system limits
for the number of open files to be exceeded. The following patch opens and
closes files as needed.

Addresses https://trac.ffmpeg.org/ticket/9623

---
 libavformat/imfdec.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 847dead7f0..48bd5c78e8 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -103,10 +103,11 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 int32_t index; /**< Track index in 
playlist */
 AVRational current_timestamp;  /**< Current temporal 
position */
 AVRational duration;   /**< Overall duration */
-uint32_t resource_count;   /**< Number of resources */
+uint32_t resource_count;   /**< Number of resources 
(<= INT32_MAX) */
 unsigned int resources_alloc_sz;   /**< Size of the buffer 
holding the resource */
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
-uint32_t current_resource_index;   /**< Current resource */
+int32_t current_resource_index;/**< Index of the current 
resource in resources,
+or < 0 if a current 
resource has yet to be selected */
 int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
@@ -435,7 +436,6 @@ static int open_track_file_resource(AVFormatContext *s,
 IMFContext *c = s->priv_data;
 IMFAssetLocator *asset_locator;
 void *tmp;
-int ret;
 
 asset_locator = find_asset_map_locator(&c->asset_locator_map, 
track_file_resource->track_file_uuid);
 if (!asset_locator) {
@@ -452,7 +452,7 @@ static int open_track_file_resource(AVFormatContext *s,
UID_ARG(asset_locator->uuid),
asset_locator->absolute_uri);
 
-if (track->resource_count > UINT32_MAX - 
track_file_resource->base.repeat_count
+if (track->resource_count > INT32_MAX - 
track_file_resource->base.repeat_count
 || (track->resource_count + track_file_resource->base.repeat_count)
 > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx))
 return AVERROR(ENOMEM);
@@ -470,8 +470,6 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-if ((ret = open_track_resource_context(s, &vt_ctx)) != 0)
-return ret;
 track->resources[track->resource_count++] = vt_ctx;
 track->duration = av_add_q(track->duration,

av_make_q((int)track_file_resource->base.duration
@@ -501,6 +499,7 @@ static int open_virtual_track(AVFormatContext *s,
 
 if (!(track = av_mallocz(sizeof(IMFVirtualTrackPlaybackCtx
 return AVERROR(ENOMEM);
+track->current_resource_index = -1;
 track->index = track_index;
 track->duration = av_make_q(0, 1);
 
@@ -551,6 +550,9 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
+ret = open_track_resource_context(s, &c->tracks[i]->resources[0]);
+if (ret)
+return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
@@ -741,7 +743,8 @@ static IMFVirtualTrackResourcePlaybackCtx 
*get_resource_context_for_timestamp(AV
track->index);
 if (open_track_resource_context(s, &(track->resources[i])) != 
0)
 return NULL;
-
avformat_close_input(&(track->resources[track->current_resource_index].ctx));
+if (track->current_resource_index > 0)
+
avformat_close_input(&track->resources[track->current_resource_index].ctx);
 track->current_resource_index = i;
 }
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avformat/tests: add /imf to .gitignore

2022-02-04 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/tests/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/tests/.gitignore b/libavformat/tests/.gitignore
index 7ceb7a356b..aabf76345e 100644
--- a/libavformat/tests/.gitignore
+++ b/libavformat/tests/.gitignore
@@ -1,4 +1,5 @@
 /fifo_muxer
+/imf
 /movenc
 /noproxy
 /rtmpdh
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 4/4] avformat/imf: document IMFVirtualTrackResourcePlaybackCtx

2022-02-02 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 5be4411cb1..02e7bcc33f 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -96,12 +96,12 @@ typedef struct IMFAssetLocatorMap {
 } IMFAssetLocatorMap;
 
 typedef struct IMFVirtualTrackResourcePlaybackCtx {
-IMFAssetLocator *locator;
-FFIMFTrackFileResource *resource;
-AVFormatContext *ctx;
-AVRational start_time;
-AVRational end_time;
-AVRational ts_offset;
+IMFAssetLocator *locator;  /**< Location of the resource */
+FFIMFTrackFileResource *resource;  /**< Underlying IMF CPL resource */
+AVFormatContext *ctx;  /**< Context associated with the 
resource */
+AVRational start_time; /**< inclusive start time of the 
resource on the CPL timeline (s) */
+AVRational end_time;   /**< exclusive end time of the resource 
on the CPL timeline (s) */
+AVRational ts_offset;  /**< start_time minus the entry point 
into the resource (s) */
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 3/4] avformat/imf: fix packet pts, dts and muxing

2022-02-02 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer does not set the DTS and PTS of packets accurately in all
scenarios. Moreover, audio packets are not trimmed when they exceed the
duration of the underlying resource.

imf-cpl-with-repeat FATE ref file is regenerated.

Addresses https://trac.ffmpeg.org/ticket/9611

---
 libavformat/imfdec.c   | 263 +++--
 tests/ref/fate/imf-cpl-with-repeat |  20 +--
 2 files changed, 181 insertions(+), 102 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 658ddc40f2..5be4411cb1 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -65,8 +65,10 @@
 #include "avio_internal.h"
 #include "imf.h"
 #include "internal.h"
+#include "libavcodec/packet.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
 #include "mxf.h"
 #include "url.h"
@@ -97,6 +99,9 @@ typedef struct IMFVirtualTrackResourcePlaybackCtx {
 IMFAssetLocator *locator;
 FFIMFTrackFileResource *resource;
 AVFormatContext *ctx;
+AVRational start_time;
+AVRational end_time;
+AVRational ts_offset;
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
@@ -108,7 +113,6 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
 int32_t current_resource_index;/**< Index of the current 
resource in resources,
 or < 0 if a current 
resource has yet to be selected */
-int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
 typedef struct IMFContext {
@@ -342,6 +346,7 @@ static int open_track_resource_context(AVFormatContext *s,
 int ret = 0;
 int64_t entry_point;
 AVDictionary *opts = NULL;
+AVStream *st;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -383,23 +388,28 @@ static int open_track_resource_context(AVFormatContext *s,
 }
 av_dict_free(&opts);
 
-/* Compare the source timebase to the resource edit rate,
- * considering the first stream of the source file
- */
-if (av_cmp_q(track_resource->ctx->streams[0]->time_base,
- av_inv_q(track_resource->resource->base.edit_rate)))
+/* make sure there is only one stream in the file */
+
+if (track_resource->ctx->nb_streams != 1) {
+ret = AVERROR_INVALIDDATA;
+goto cleanup;
+}
+
+st = track_resource->ctx->streams[0];
+
+/* Warn if the resource time base does not match the file time base */
+if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
 av_log(s,
AV_LOG_WARNING,
-   "Incoherent source stream timebase %d/%d regarding resource 
edit rate: %d/%d",
-   track_resource->ctx->streams[0]->time_base.num,
-   track_resource->ctx->streams[0]->time_base.den,
+   "Incoherent source stream timebase " AVRATIONAL_FORMAT
+   "regarding resource edit rate: " AVRATIONAL_FORMAT,
+   st->time_base.num,
+   st->time_base.den,
track_resource->resource->base.edit_rate.den,
track_resource->resource->base.edit_rate.num);
 
-entry_point = (int64_t)track_resource->resource->base.entry_point
-* track_resource->resource->base.edit_rate.den
-* AV_TIME_BASE
-/ track_resource->resource->base.edit_rate.num;
+entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
+   
av_inv_q(track_resource->resource->base.edit_rate));
 
 if (entry_point) {
 av_log(s,
@@ -407,7 +417,7 @@ static int open_track_resource_context(AVFormatContext *s,
"Seek at resource %s entry point: %" PRIu32 "\n",
track_resource->locator->absolute_uri,
track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, -1, entry_point, 
entry_point, entry_point, 0);
+ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
@@ -470,11 +480,16 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-track->resources[track->resource_count++] = vt_ctx;
-track->duration = av_add_q(track->duration,
+vt_ctx.start_time = track->duration;
+vt_ctx.ts_offset = av_sub_q(vt_ctx.start_time,
+
av_div_q(av_make_q((int)track_file_resource->base.entry_point, 1),
+ 
track_file_resource->base.edit_rate));
+vt_ctx.end_time = av_add_q(track->duration,

[FFmpeg-devel] [PATCH v3 2/4] avformat/imf: fix missing error reporting when opening resources

2022-02-02 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index e6a1020ecc..658ddc40f2 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -550,7 +550,9 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
-open_track_resource_context(s, &c->tracks[i]->resources[0]);
+ret = open_track_resource_context(s, &c->tracks[i]->resources[0]);
+if (ret)
+return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 1/4] avformat/imf: open resources only when first needed

2022-02-02 Thread pal
From: Pierre-Anthony Lemieux 

IMF CPLs can reference thousands of files, which can result in system limits
for the number of open files to be exceeded. The following patch opens and
closes files as needed.

Addresses https://trac.ffmpeg.org/ticket/9623

---
 libavformat/imfdec.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index d67c9b8898..e6a1020ecc 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -103,10 +103,11 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 int32_t index; /**< Track index in 
playlist */
 AVRational current_timestamp;  /**< Current temporal 
position */
 AVRational duration;   /**< Overall duration */
-uint32_t resource_count;   /**< Number of resources */
+uint32_t resource_count;   /**< Number of resources 
(<= INT32_MAX) */
 unsigned int resources_alloc_sz;   /**< Size of the buffer 
holding the resource */
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
-uint32_t current_resource_index;   /**< Current resource */
+int32_t current_resource_index;/**< Index of the current 
resource in resources,
+or < 0 if a current 
resource has yet to be selected */
 int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
@@ -435,7 +436,6 @@ static int open_track_file_resource(AVFormatContext *s,
 IMFContext *c = s->priv_data;
 IMFAssetLocator *asset_locator;
 void *tmp;
-int ret;
 
 asset_locator = find_asset_map_locator(&c->asset_locator_map, 
track_file_resource->track_file_uuid);
 if (!asset_locator) {
@@ -452,7 +452,7 @@ static int open_track_file_resource(AVFormatContext *s,
UID_ARG(asset_locator->uuid),
asset_locator->absolute_uri);
 
-if (track->resource_count > UINT32_MAX - 
track_file_resource->base.repeat_count
+if (track->resource_count > INT32_MAX - 
track_file_resource->base.repeat_count
 || (track->resource_count + track_file_resource->base.repeat_count)
 > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx))
 return AVERROR(ENOMEM);
@@ -470,8 +470,6 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-if ((ret = open_track_resource_context(s, &vt_ctx)) != 0)
-return ret;
 track->resources[track->resource_count++] = vt_ctx;
 track->duration = av_add_q(track->duration,

av_make_q((int)track_file_resource->base.duration
@@ -501,6 +499,7 @@ static int open_virtual_track(AVFormatContext *s,
 
 if (!(track = av_mallocz(sizeof(IMFVirtualTrackPlaybackCtx
 return AVERROR(ENOMEM);
+track->current_resource_index = -1;
 track->index = track_index;
 track->duration = av_make_q(0, 1);
 
@@ -551,6 +550,7 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
+open_track_resource_context(s, &c->tracks[i]->resources[0]);
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
@@ -741,7 +741,8 @@ static IMFVirtualTrackResourcePlaybackCtx 
*get_resource_context_for_timestamp(AV
track->index);
 if (open_track_resource_context(s, &(track->resources[i])) != 
0)
 return NULL;
-
avformat_close_input(&(track->resources[track->current_resource_index].ctx));
+if (track->current_resource_index > 0)
+
avformat_close_input(&track->resources[track->current_resource_index].ctx);
 track->current_resource_index = i;
 }
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 4/4] avformat/imf: document IMFVirtualTrackResourcePlaybackCtx

2022-02-01 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 5be4411cb1..02e7bcc33f 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -96,12 +96,12 @@ typedef struct IMFAssetLocatorMap {
 } IMFAssetLocatorMap;
 
 typedef struct IMFVirtualTrackResourcePlaybackCtx {
-IMFAssetLocator *locator;
-FFIMFTrackFileResource *resource;
-AVFormatContext *ctx;
-AVRational start_time;
-AVRational end_time;
-AVRational ts_offset;
+IMFAssetLocator *locator;  /**< Location of the resource */
+FFIMFTrackFileResource *resource;  /**< Underlying IMF CPL resource */
+AVFormatContext *ctx;  /**< Context associated with the 
resource */
+AVRational start_time; /**< inclusive start time of the 
resource on the CPL timeline (s) */
+AVRational end_time;   /**< exclusive end time of the resource 
on the CPL timeline (s) */
+AVRational ts_offset;  /**< start_time minus the entry point 
into the resource (s) */
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 3/4] avformat/imf: fix packet pts, dts and muxing

2022-02-01 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer does not set the DTS and PTS of packets accurately in all
scenarios. Moreover, audio packets are not trimmed when they exceed the
duration of the underlying resource.

Addresses https://trac.ffmpeg.org/ticket/9611

---
 libavformat/imfdec.c | 263 ---
 1 file changed, 171 insertions(+), 92 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 658ddc40f2..5be4411cb1 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -65,8 +65,10 @@
 #include "avio_internal.h"
 #include "imf.h"
 #include "internal.h"
+#include "libavcodec/packet.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
 #include "mxf.h"
 #include "url.h"
@@ -97,6 +99,9 @@ typedef struct IMFVirtualTrackResourcePlaybackCtx {
 IMFAssetLocator *locator;
 FFIMFTrackFileResource *resource;
 AVFormatContext *ctx;
+AVRational start_time;
+AVRational end_time;
+AVRational ts_offset;
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
@@ -108,7 +113,6 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
 int32_t current_resource_index;/**< Index of the current 
resource in resources,
 or < 0 if a current 
resource has yet to be selected */
-int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
 typedef struct IMFContext {
@@ -342,6 +346,7 @@ static int open_track_resource_context(AVFormatContext *s,
 int ret = 0;
 int64_t entry_point;
 AVDictionary *opts = NULL;
+AVStream *st;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -383,23 +388,28 @@ static int open_track_resource_context(AVFormatContext *s,
 }
 av_dict_free(&opts);
 
-/* Compare the source timebase to the resource edit rate,
- * considering the first stream of the source file
- */
-if (av_cmp_q(track_resource->ctx->streams[0]->time_base,
- av_inv_q(track_resource->resource->base.edit_rate)))
+/* make sure there is only one stream in the file */
+
+if (track_resource->ctx->nb_streams != 1) {
+ret = AVERROR_INVALIDDATA;
+goto cleanup;
+}
+
+st = track_resource->ctx->streams[0];
+
+/* Warn if the resource time base does not match the file time base */
+if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
 av_log(s,
AV_LOG_WARNING,
-   "Incoherent source stream timebase %d/%d regarding resource 
edit rate: %d/%d",
-   track_resource->ctx->streams[0]->time_base.num,
-   track_resource->ctx->streams[0]->time_base.den,
+   "Incoherent source stream timebase " AVRATIONAL_FORMAT
+   "regarding resource edit rate: " AVRATIONAL_FORMAT,
+   st->time_base.num,
+   st->time_base.den,
track_resource->resource->base.edit_rate.den,
track_resource->resource->base.edit_rate.num);
 
-entry_point = (int64_t)track_resource->resource->base.entry_point
-* track_resource->resource->base.edit_rate.den
-* AV_TIME_BASE
-/ track_resource->resource->base.edit_rate.num;
+entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
+   
av_inv_q(track_resource->resource->base.edit_rate));
 
 if (entry_point) {
 av_log(s,
@@ -407,7 +417,7 @@ static int open_track_resource_context(AVFormatContext *s,
"Seek at resource %s entry point: %" PRIu32 "\n",
track_resource->locator->absolute_uri,
track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, -1, entry_point, 
entry_point, entry_point, 0);
+ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
@@ -470,11 +480,16 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-track->resources[track->resource_count++] = vt_ctx;
-track->duration = av_add_q(track->duration,
+vt_ctx.start_time = track->duration;
+vt_ctx.ts_offset = av_sub_q(vt_ctx.start_time,
+
av_div_q(av_make_q((int)track_file_resource->base.entry_point, 1),
+ 
track_file_resource->base.edit_rate));
+vt_ctx.end_time = av_add_q(track->duration,

av_make_q((int)track_file_resource->base.duration

[FFmpeg-devel] [PATCH v2 2/4] avformat/imf: fix missing error reporting when opening resources

2022-02-01 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index e6a1020ecc..658ddc40f2 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -550,7 +550,9 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
-open_track_resource_context(s, &c->tracks[i]->resources[0]);
+ret = open_track_resource_context(s, &c->tracks[i]->resources[0]);
+if (ret)
+return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/4] avformat/imf: open resources only when first needed

2022-02-01 Thread pal
From: Pierre-Anthony Lemieux 

IMF CPLs can reference thousands of files, which can result in system limits
for the number of open files to be exceeded. The following patch opens and
closes files as needed.

Addresses https://trac.ffmpeg.org/ticket/9623

---
 libavformat/imfdec.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index d67c9b8898..e6a1020ecc 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -103,10 +103,11 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 int32_t index; /**< Track index in 
playlist */
 AVRational current_timestamp;  /**< Current temporal 
position */
 AVRational duration;   /**< Overall duration */
-uint32_t resource_count;   /**< Number of resources */
+uint32_t resource_count;   /**< Number of resources 
(<= INT32_MAX) */
 unsigned int resources_alloc_sz;   /**< Size of the buffer 
holding the resource */
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
-uint32_t current_resource_index;   /**< Current resource */
+int32_t current_resource_index;/**< Index of the current 
resource in resources,
+or < 0 if a current 
resource has yet to be selected */
 int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
@@ -435,7 +436,6 @@ static int open_track_file_resource(AVFormatContext *s,
 IMFContext *c = s->priv_data;
 IMFAssetLocator *asset_locator;
 void *tmp;
-int ret;
 
 asset_locator = find_asset_map_locator(&c->asset_locator_map, 
track_file_resource->track_file_uuid);
 if (!asset_locator) {
@@ -452,7 +452,7 @@ static int open_track_file_resource(AVFormatContext *s,
UID_ARG(asset_locator->uuid),
asset_locator->absolute_uri);
 
-if (track->resource_count > UINT32_MAX - 
track_file_resource->base.repeat_count
+if (track->resource_count > INT32_MAX - 
track_file_resource->base.repeat_count
 || (track->resource_count + track_file_resource->base.repeat_count)
 > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx))
 return AVERROR(ENOMEM);
@@ -470,8 +470,6 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-if ((ret = open_track_resource_context(s, &vt_ctx)) != 0)
-return ret;
 track->resources[track->resource_count++] = vt_ctx;
 track->duration = av_add_q(track->duration,

av_make_q((int)track_file_resource->base.duration
@@ -501,6 +499,7 @@ static int open_virtual_track(AVFormatContext *s,
 
 if (!(track = av_mallocz(sizeof(IMFVirtualTrackPlaybackCtx
 return AVERROR(ENOMEM);
+track->current_resource_index = -1;
 track->index = track_index;
 track->duration = av_make_q(0, 1);
 
@@ -551,6 +550,7 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
+open_track_resource_context(s, &c->tracks[i]->resources[0]);
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
@@ -741,7 +741,8 @@ static IMFVirtualTrackResourcePlaybackCtx 
*get_resource_context_for_timestamp(AV
track->index);
 if (open_track_resource_context(s, &(track->resources[i])) != 
0)
 return NULL;
-
avformat_close_input(&(track->resources[track->current_resource_index].ctx));
+if (track->current_resource_index > 0)
+
avformat_close_input(&track->resources[track->current_resource_index].ctx);
 track->current_resource_index = i;
 }
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 4/4] avformat/imf: document IMFVirtualTrackResourcePlaybackCtx

2022-01-30 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 05dcb6ff31..9f9087f936 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -95,12 +95,12 @@ typedef struct IMFAssetLocatorMap {
 } IMFAssetLocatorMap;
 
 typedef struct IMFVirtualTrackResourcePlaybackCtx {
-IMFAssetLocator *locator;
-FFIMFTrackFileResource *resource;
-AVFormatContext *ctx;
-AVRational start_time;
-AVRational end_time;
-AVRational ts_offset;
+IMFAssetLocator *locator;  /**< Location of the resource */
+FFIMFTrackFileResource *resource;  /**< Underlying IMF CPL resource */
+AVFormatContext *ctx;  /**< Context associated with the 
resource */
+AVRational start_time; /**< inclusive start time of the 
resource on the CPL timeline (s) */
+AVRational end_time;   /**< exclusive end time of the resource 
on the CPL timeline (s) */
+AVRational ts_offset;  /**< start_time minus the entry point 
into the resource (s) */
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v1 3/4] avformat/imf: fix packet pts, dts and muxing

2022-01-30 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer does not set the DTS and PTS of packets accurately in all
scenarios. Moreover, audio packets are not trimmed when they exceed the
duration of the underlying resource.

Closes https://trac.ffmpeg.org/ticket/9611

---
 libavformat/imfdec.c | 225 +--
 1 file changed, 132 insertions(+), 93 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 6b50b582f6..05dcb6ff31 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -65,6 +65,7 @@
 #include "avio_internal.h"
 #include "imf.h"
 #include "internal.h"
+#include "libavcodec/packet.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 #include "libavutil/opt.h"
@@ -97,6 +98,9 @@ typedef struct IMFVirtualTrackResourcePlaybackCtx {
 IMFAssetLocator *locator;
 FFIMFTrackFileResource *resource;
 AVFormatContext *ctx;
+AVRational start_time;
+AVRational end_time;
+AVRational ts_offset;
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
@@ -108,7 +112,6 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
 int32_t current_resource_index;/**< Index of the current 
resource in resources,
 or < 0 if a current 
resource has yet to be selected */
-int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
 typedef struct IMFContext {
@@ -342,6 +345,7 @@ static int open_track_resource_context(AVFormatContext *s,
 int ret = 0;
 int64_t entry_point;
 AVDictionary *opts = NULL;
+AVStream *st;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -383,23 +387,28 @@ static int open_track_resource_context(AVFormatContext *s,
 }
 av_dict_free(&opts);
 
-/* Compare the source timebase to the resource edit rate,
- * considering the first stream of the source file
- */
-if (av_cmp_q(track_resource->ctx->streams[0]->time_base,
- av_inv_q(track_resource->resource->base.edit_rate)))
+/* make sure there is only one stream in the file */
+
+if (track_resource->ctx->nb_streams != 1) {
+ret = AVERROR_INVALIDDATA;
+goto cleanup;
+}
+
+st = track_resource->ctx->streams[0];
+
+/* Warn if the resource time base does not match the file time base */
+if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
 av_log(s,
AV_LOG_WARNING,
-   "Incoherent source stream timebase %d/%d regarding resource 
edit rate: %d/%d",
-   track_resource->ctx->streams[0]->time_base.num,
-   track_resource->ctx->streams[0]->time_base.den,
+   "Incoherent source stream timebase " AVRATIONAL_FORMAT
+   "regarding resource edit rate: " AVRATIONAL_FORMAT,
+   st->time_base.num,
+   st->time_base.den,
track_resource->resource->base.edit_rate.den,
track_resource->resource->base.edit_rate.num);
 
-entry_point = (int64_t)track_resource->resource->base.entry_point
-* track_resource->resource->base.edit_rate.den
-* AV_TIME_BASE
-/ track_resource->resource->base.edit_rate.num;
+entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
+   
av_inv_q(track_resource->resource->base.edit_rate));
 
 if (entry_point) {
 av_log(s,
@@ -407,7 +416,7 @@ static int open_track_resource_context(AVFormatContext *s,
"Seek at resource %s entry point: %" PRIu32 "\n",
track_resource->locator->absolute_uri,
track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, -1, entry_point, 
entry_point, entry_point, 0);
+ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
@@ -470,11 +479,16 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-track->resources[track->resource_count++] = vt_ctx;
-track->duration = av_add_q(track->duration,
+vt_ctx.start_time = track->duration;
+vt_ctx.ts_offset = av_sub_q(vt_ctx.start_time,
+
av_div_q(av_make_q((int)track_file_resource->base.entry_point, 1),
+ 
track_file_resource->base.edit_rate));
+vt_ctx.end_time = av_add_q(track->duration,

av_make_q((int)track_file_resource->base.duration
  * 
track_file_resource->base.edit_rate.den,

[FFmpeg-devel] [PATCH v1 2/4] avformat/imf: fix missing error reporting when opening resources

2022-01-30 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index d03dcd623d..6b50b582f6 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -550,7 +550,9 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
-open_track_resource_context(s, &c->tracks[i]->resources[0]);
+ret = open_track_resource_context(s, &c->tracks[i]->resources[0]);
+if (ret)
+return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
-- 
2.17.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-requ...@ffmpeg.org with subject "unsubscribe".


  1   2   >