Re: [FFmpeg-devel] [PATCH] libavformat\file:Fix duplicate JNI symbols

2024-03-23 Thread Zhao Zhili

On 2024/3/24 10:16, Zhao Zhili wrote:



diff --git a/libavformat/file.c b/libavformat/file.c
index dd5819c..fa13ae9 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -43,7 +43,7 @@
  #if CONFIG_ANDROID_CONTENT_PROTOCOL
  #include 
  #include "libavcodec/jni.h"
-#include "libavcodec/ffjni.c"
+#include "libavcodec/ffjni.h"
  #endif

This just break --enable-shared, so NACK.


The following patch should work for static and shared both.

https://ffmpeg.org/pipermail/ffmpeg-devel/2024-March/324138.html


___
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/file: Fix duplicate symbol ff_jni_*

2024-03-23 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavformat/Makefile | 1 +
 libavformat/ffjni.c  | 1 +
 libavformat/file.c   | 3 +--
 3 files changed, 3 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/ffjni.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 44aa485029..e10ad436a8 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -724,6 +724,7 @@ OBJS-$(CONFIG_LIBZMQ_PROTOCOL)   += libzmq.o
 
 # Objects duplicated from other libraries for shared builds
 SHLIBOBJS+= log2_tab.o to_upper4.o
+SHLIBOBJS-$(CONFIG_ANDROID_CONTENT_PROTOCOL)   += ffjni.o
 SHLIBOBJS-$(CONFIG_ISO_MEDIA)+= mpegaudiotabs.o
 SHLIBOBJS-$(CONFIG_FLV_MUXER)+= mpeg4audio_sample_rates.o
 SHLIBOBJS-$(CONFIG_HLS_DEMUXER)  += ac3_channel_layout_tab.o
diff --git a/libavformat/ffjni.c b/libavformat/ffjni.c
new file mode 100644
index 00..a5285564b2
--- /dev/null
+++ b/libavformat/ffjni.c
@@ -0,0 +1 @@
+#include "libavcodec/ffjni.c"
diff --git a/libavformat/file.c b/libavformat/file.c
index dd5819c06f..f80cb4b37a 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -41,9 +41,8 @@
 #include "os_support.h"
 #include "url.h"
 #if CONFIG_ANDROID_CONTENT_PROTOCOL
-#include 
+#include "libavcodec/ffjni.h"
 #include "libavcodec/jni.h"
-#include "libavcodec/ffjni.c"
 #endif
 
 
-- 
2.34.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/2] avformat/ccaption_dec: use NTSC resolution base

2024-03-23 Thread Marth64
Closed Captions are an NTSC concept, but the base resolution
used for x/y calculation is the default PAL base in ASS encoder.
This causes subtle positioning issues especially in 16:9
content.

Use NTSC 240 TVL (360x240) as the base instead, and compensate
the font size of the style. Update tests accordingly.

Signed-off-by: Marth64 
---
 libavcodec/ccaption_dec.c |  34 ++--
 tests/ref/fate/ffmpeg-fix_sub_duration|  14 +-
 .../fate/ffmpeg-fix_sub_duration_heartbeat|  16 +-
 tests/ref/fate/sub-cc |  10 +-
 tests/ref/fate/sub-cc-realtime|  22 +-
 tests/ref/fate/sub-cc-scte20  |  12 +-
 tests/ref/fate/sub-scc| 190 +-
 7 files changed, 153 insertions(+), 145 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 0b01765ccf..5f32fd6e1f 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -27,8 +27,11 @@
 #include "codec_internal.h"
 #include "libavutil/opt.h"
 
-#define SCREEN_ROWS 15
-#define SCREEN_COLUMNS 32
+#define CC_PLAYRESX 360
+#define CC_PLAYRESY 240
+#define CC_FONT_SIZE14
+#define SCREEN_ROWS 15
+#define SCREEN_COLUMNS  32
 
 #define SET_FLAG(var, val)   ( (var) |=   ( 1 << (val)) )
 #define UNSET_FLAG(var, val) ( (var) &=  ~( 1 << (val)) )
@@ -289,15 +292,20 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 ctx->bg_color = CCCOL_BLACK;
 ctx->rollup = 2;
 ctx->cursor_row = 10;
-return ff_ass_subtitle_header(avctx, "Monospace",
- ASS_DEFAULT_FONT_SIZE,
- ASS_DEFAULT_COLOR,
- ASS_DEFAULT_BACK_COLOR,
- ASS_DEFAULT_BOLD,
- ASS_DEFAULT_ITALIC,
- ASS_DEFAULT_UNDERLINE,
- 3,
- ASS_DEFAULT_ALIGNMENT);
+return ff_ass_subtitle_header_full(avctx,
+   CC_PLAYRESX,
+   CC_PLAYRESY,
+   "Monospace",
+   CC_FONT_SIZE,
+   ASS_DEFAULT_COLOR,
+   ASS_DEFAULT_COLOR,
+   ASS_DEFAULT_BACK_COLOR,
+   ASS_DEFAULT_BACK_COLOR,
+   ASS_DEFAULT_BOLD,
+   ASS_DEFAULT_ITALIC,
+   ASS_DEFAULT_UNDERLINE,
+   3,
+   ASS_DEFAULT_ALIGNMENT);
 }
 
 static av_cold int close_decoder(AVCodecContext *avctx)
@@ -497,8 +505,8 @@ static int capture_screen(CCaptionSubContext *ctx)
 while (row[j] == ' ' && charset[j] == CCSET_BASIC_AMERICAN && j < 
tab)
 j++;
 
-x = ASS_DEFAULT_PLAYRESX * (0.1 + 0.0250 * j);
-y = ASS_DEFAULT_PLAYRESY * (0.1 + 0.0533 * i);
+x = CC_PLAYRESX * (0.1 + 0.0250 * j);
+y = CC_PLAYRESY * (0.1 + 0.0533 * i);
 
 if (!seen_row) {
 av_bprintf(>buffer[bidx], "{\\an7}{\\pos(%d,%d)}", x, y);
diff --git a/tests/ref/fate/ffmpeg-fix_sub_duration 
b/tests/ref/fate/ffmpeg-fix_sub_duration
index 9cd36d4888..0e0ab27a8e 100644
--- a/tests/ref/fate/ffmpeg-fix_sub_duration
+++ b/tests/ref/fate/ffmpeg-fix_sub_duration
@@ -1,31 +1,31 @@
 1
 00:00:00,968 --> 00:00:01,168
-{\an7}(
+{\an7}(
 
 2
 00:00:01,168 --> 00:00:01,368
-{\an7}( inaudibl
+{\an7}( inaudibl
 
 3
 00:00:01,368 --> 00:00:01,568
-{\an7}( inaudible radio chat
+{\an7}( inaudible radio chat
 
 4
 00:00:01,568 --> 00:00:03,103
-{\an7}( inaudible radio chatter )
+{\an7}( inaudible radio chatter 
)
 
 5
 00:00:03,103 --> 00:00:03,303
-{\an7}( inaudible radio chatter )
+{\an7}( inaudible radio chatter )
 >>
 
 6
 00:00:03,303 --> 00:00:03,503
-{\an7}( inaudible radio chatter )
+{\an7}( inaudible radio chatter )
 >> Safety rema
 
 7
 00:00:03,504 --> 00:00:03,704
-{\an7}( inaudible radio chatter )
+{\an7}( inaudible radio chatter )
 >> Safety remains our numb
 
diff --git a/tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat 
b/tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat
index 3a3ec96637..5c18c1eb97 100644
--- a/tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat
+++ b/tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat
@@ -1,35 +1,35 @@
 1
 00:00:00,968 --> 00:00:01,168
-{\an7}(
+{\an7}(
 
 2
 00:00:01,168 --> 00:00:01,368
-{\an7}( inaudibl
+{\an7}( inaudibl
 
 3
 00:00:01,368 --> 00:00:01,568
-{\an7}( inaudible radio chat
+{\an7}( inaudible radio chat
 
 4
 00:00:01,568 --> 00:00:02,002
-{\an7}( inaudible radio chatter )
+{\an7}( inaudible radio chatter 
)
 
 5
 00:00:02,002 --> 00:00:03,103
-{\an7}( inaudible radio chatter )
+{\an7}( inaudible 

[FFmpeg-devel] [PATCH v4 1/2] avcodec/ccaption_dec: don't print multiple \an and \pos tags

2024-03-23 Thread Marth64
Closed Captions decoder prints multiple \pos ASS tags per cue,
and preceding the \pos tag is a fixed \an7 that fixes rendering
position from the top left corner and enforces justification.

Printing multiple \an and \pos tags in this way is invalid behavior,
because only the first \pos tag in a cue is honored by ASS anyway.
Don't write multiple \an and \pos tags. Also, update tests accordingly.

Note that when applying the patch, whitespace warnings may appear
about the test data. The subtitle stream in this test data has
intentional whitespace at the end of line for some cues, this is OK.

Signed-off-by: Marth64 
---
 libavcodec/ccaption_dec.c  |  13 ++-
 tests/ref/fate/sub-cc  |   2 +-
 tests/ref/fate/sub-cc-realtime |   8 +-
 tests/ref/fate/sub-cc-scte20   |   4 +-
 tests/ref/fate/sub-scc | 146 -
 5 files changed, 91 insertions(+), 82 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index d8b992bb94..0b01765ccf 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -20,6 +20,8 @@
  */
 
 #include 
+#include 
+
 #include "avcodec.h"
 #include "ass.h"
 #include "codec_internal.h"
@@ -457,7 +459,7 @@ static void roll_up(CCaptionSubContext *ctx)
 
 static int capture_screen(CCaptionSubContext *ctx)
 {
-int i, j, tab = 0;
+int i, j, tab = 0, seen_row = 0;
 struct Screen *screen = ctx->screen + ctx->active_screen;
 enum cc_font prev_font = CCFONT_REGULAR;
 enum cc_color_code prev_color = CCCOL_WHITE;
@@ -497,7 +499,14 @@ static int capture_screen(CCaptionSubContext *ctx)
 
 x = ASS_DEFAULT_PLAYRESX * (0.1 + 0.0250 * j);
 y = ASS_DEFAULT_PLAYRESY * (0.1 + 0.0533 * i);
-av_bprintf(>buffer[bidx], "{\\an7}{\\pos(%d,%d)}", x, y);
+
+if (!seen_row) {
+av_bprintf(>buffer[bidx], "{\\an7}{\\pos(%d,%d)}", x, y);
+seen_row = 1;
+}
+av_log(ctx, AV_LOG_TRACE, "rendering row: start_pts=%" PRId64 " 
end_pts=%" PRId64 " "
+  "x=%d y=%d\n",
+  ctx->buffer_time[0], 
ctx->buffer_time[1], x, y);
 
 for (; j < SCREEN_COLUMNS; j++) {
 const char *e_tag = "", *s_tag = "", *c_tag = "", *b_tag = "";
diff --git a/tests/ref/fate/sub-cc b/tests/ref/fate/sub-cc
index f5216b3de2..d4ab974c2f 100644
--- a/tests/ref/fate/sub-cc
+++ b/tests/ref/fate/sub-cc
@@ -13,4 +13,4 @@ Style: 
Default,Monospace,16,0,0,0,0,100,100,0,0,3,1,0,
 [Events]
 Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
 Dialogue: 0,0:00:00.83,0:00:02.97,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chatter{\i0} )
-Dialogue: 0,0:00:02.97,0:00:04.34,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number 
one
+Dialogue: 0,0:00:02.97,0:00:04.34,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N>> Safety remains our number one
diff --git a/tests/ref/fate/sub-cc-realtime b/tests/ref/fate/sub-cc-realtime
index bda890bfe5..da06307221 100644
--- a/tests/ref/fate/sub-cc-realtime
+++ b/tests/ref/fate/sub-cc-realtime
@@ -16,7 +16,7 @@ Dialogue: 
0,0:00:00.97,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}(
 Dialogue: 0,0:00:01.17,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudibl
 Dialogue: 0,0:00:01.37,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chat
 Dialogue: 0,0:00:01.57,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,44)}({\i1} 
inaudible radio chatter{\i0} )
-Dialogue: 0,0:00:03.10,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>>
-Dialogue: 0,0:00:03.30,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety rema
-Dialogue: 0,0:00:03.50,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our numb
-Dialogue: 0,0:00:03.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N{\an7}{\pos(38,44)}>> Safety remains our number 
one
+Dialogue: 0,0:00:03.10,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N>>
+Dialogue: 0,0:00:03.30,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N>> Safety rema
+Dialogue: 0,0:00:03.50,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N>> Safety remains our numb
+Dialogue: 0,0:00:03.70,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(38,28)}({\i1} 
inaudible radio chatter{\i0} )\N>> Safety remains our number one
diff --git a/tests/ref/fate/sub-cc-scte20 b/tests/ref/fate/sub-cc-scte20
index 49715301de..09fa3fb330 100644
--- a/tests/ref/fate/sub-cc-scte20
+++ b/tests/ref/fate/sub-cc-scte20
@@ -13,5 +13,5 @@ Style: 

[FFmpeg-devel] [PATCH v4 0/2] Closed Captions decoder improvements (v4)

2024-03-23 Thread Marth64
Since v3:
* Added trace logging of coordinates (requested in feedback)
* Improved calculation of coordinates by using NTSC base resolution

Signed-off-by: Marth64 
-- 
2.34.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 v9 5/5] doc/indevs: update CC extraction example to use RCWT muxer

2024-03-23 Thread Marth64
Signed-off-by: Marth64 
---
 doc/indevs.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index d1b2bacf8b..fc14737181 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -1069,9 +1069,9 @@ ffplay -f lavfi 
"movie=test.avi[out0];amovie=test.wav[out1]"
 @end example
 
 @item
-Dump decoded frames to images and closed captions to a file (experimental):
+Dump decoded frames to images and Closed Captions to an RCWT backup:
 @example
-ffmpeg -f lavfi -i "movie=test.ts[out0+subcc]" -map v frame%08d.png -map s -c 
copy -f rawvideo subcc.bin
+ffmpeg -f lavfi -i "movie=test.ts[out0+subcc]" -map v frame%08d.png -map s -c 
copy subcc.bin
 @end example
 
 @end itemize
-- 
2.34.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 v9 4/5] doc/muxers: refresh the RCWT muxer's doc to be consistent with the demuxer

2024-03-23 Thread Marth64
Signed-off-by: Marth64 
---
 doc/muxers.texi | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a10a8e216f..4161401059 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -3038,19 +3038,18 @@ ogg files can be safely chained.
 
 @end table
 
-@anchor{rcwt}
+@anchor{rcwtenc}
 @section rcwt
 
-Raw Captions With Time (RCWT) is a format native to ccextractor, a commonly
-used open source tool for processing 608/708 closed caption (CC) sources.
-It can be used to archive the original, raw CC bitstream and to produce
-a source file for later CC processing or conversion. As a result,
-it also allows for interopability with ccextractor for processing CC data
-extracted via ffmpeg. The format is simple to parse and can be used
-to retain all lines and variants of CC.
+RCWT (Raw Captions With Time) is a format native to ccextractor, a commonly
+used open source tool for processing 608/708 Closed Captions (CC) sources.
+It can be used to archive the original extracted CC bitstream and to produce
+a source file for later processing or conversion. The format allows
+for interoperability between ccextractor and FFmpeg, is simple to parse,
+and can be used to create a backup of the CC presentation.
 
-This muxer implements the specification as of 2024-01-05, which has
-been stable and unchanged for 10 years as of this writing.
+This muxer implements the specification as of March 2024, which has
+been stable and unchanged since April 2014.
 
 This muxer will have some nuances from the way that ccextractor muxes RCWT.
 No compatibility issues when processing the output with ccextractor
@@ -3060,6 +3059,16 @@ and outputs will not be a bit-exact match.
 A free specification of RCWT can be found here:
 
@url{https://github.com/CCExtractor/ccextractor/blob/master/docs/BINARY_FILE_FORMAT.TXT}
 
+@subsection Examples
+
+@itemize
+@item
+Extract Closed Captions to RCWT using lavfi:
+@example
+ffmpeg -f lavfi -i "movie=INPUT.mkv[out+subcc]" -map 0:s:0 -c:s copy 
CC.rcwt.bin
+@end example
+@end itemize
+
 @anchor{segment}
 @section segment, stream_segment, ssegment
 
-- 
2.34.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 v9 3/5] avformat/rcwtenc: remove repeated documentation

2024-03-23 Thread Marth64
The high level summary of RCWT can be delegated doc/muxers, which
makes it easier to maintain and more consistent with the documentation
of the demuxer.

Signed-off-by: Marth64 
---
 libavformat/rcwtenc.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/libavformat/rcwtenc.c b/libavformat/rcwtenc.c
index f2459ef1d3..e06bc4b734 100644
--- a/libavformat/rcwtenc.c
+++ b/libavformat/rcwtenc.c
@@ -21,11 +21,6 @@
 /*
  * RCWT (Raw Captions With Time) is a format native to ccextractor, a commonly
  * used open source tool for processing 608/708 Closed Captions (CC) sources.
- * It can be used to archive the original, raw CC bitstream and to produce
- * a source file for later CC processing or conversion. As a result,
- * it also allows for interopability with ccextractor for processing CC data
- * extracted via ffmpeg. The format is simple to parse and can be used
- * to retain all lines and variants of CC.
  *
  * This muxer implements the specification as of March 2024, which has
  * been stable and unchanged since April 2014.
-- 
2.34.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 v9 2/5] avformat/rcwtdec: add RCWT Closed Captions demuxer

2024-03-23 Thread Marth64
RCWT (Raw Captions With Time) is a format native to ccextractor,
a commonly used OSS tool for processing 608/708 Closed Captions (CC).
RCWT can be used to archive the original extracted CC bitstream.
The muxer was added in January 2024. In this commit, add the demuxer.

One can now demux RCWT files for rendering in ccaption_dec or interop
with ccextractor (which produces RCWT). Using the muxer/demuxer combo,
the CC bits can be kept for processing or rendering with either tool.
This can be an effective way to backup an original CC stream, including
format extensions like EIA-708 and overall original presentation.

Signed-off-by: Marth64 
---
 Changelog|   2 +-
 doc/demuxers.texi|  30 ++
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/rcwtdec.c| 123 +++
 5 files changed, 156 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/rcwtdec.c

diff --git a/Changelog b/Changelog
index 934241a965..4587d0d511 100644
--- a/Changelog
+++ b/Changelog
@@ -19,7 +19,7 @@ version :
 - lavu/eval: introduce randomi() function in expressions
 - VVC decoder
 - fsync filter
-- Raw Captions with Time (RCWT) closed caption muxer
+- RCWT (Raw Captions with Time) Closed Captions muxer and demuxer
 - ffmpeg CLI -bsf option may now be used for input as well as output
 - ffmpeg CLI options may now be used as -/opt , which is equivalent
   to -opt >
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index b70f3a38d7..04293c4813 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -1038,6 +1038,36 @@ the command:
 ffplay -f rawvideo -pixel_format rgb24 -video_size 320x240 -framerate 10 
input.raw
 @end example
 
+@anchor{rcwtdec}
+@section rcwt
+
+RCWT (Raw Captions With Time) is a format native to ccextractor, a commonly
+used open source tool for processing 608/708 Closed Captions (CC) sources.
+For more information on the format, see @ref{rcwtenc,,,ffmpeg-formats}.
+
+This demuxer implements the specification as of March 2024, which has
+been stable and unchanged since April 2014.
+
+@subsection Examples
+
+@itemize
+@item
+Render CC to ASS using the built-in decoder:
+@example
+ffmpeg -i CC.rcwt.bin CC.ass
+@end example
+Note that if your output appears to be empty, you may have to manually
+set the decoder's @option{data_field} option to pick the desired CC substream.
+
+@item
+Convert an RCWT backup to Scenarist (SCC) format:
+@example
+ffmpeg -i CC.rcwt.bin -c:s copy CC.scc
+@end example
+Note that the SCC format does not support all of the possible CC extensions
+that can be stored in RCWT (such as EIA-708).
+@end itemize
+
 @section sbg
 
 SBaGen script demuxer.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 44aa485029..5d77cba7f1 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -493,6 +493,7 @@ OBJS-$(CONFIG_QOA_DEMUXER)   += qoadec.o
 OBJS-$(CONFIG_R3D_DEMUXER)   += r3d.o
 OBJS-$(CONFIG_RAWVIDEO_DEMUXER)  += rawvideodec.o
 OBJS-$(CONFIG_RAWVIDEO_MUXER)+= rawenc.o
+OBJS-$(CONFIG_RCWT_DEMUXER)  += rcwtdec.o subtitles.o
 OBJS-$(CONFIG_RCWT_MUXER)+= rcwtenc.o subtitles.o
 OBJS-$(CONFIG_REALTEXT_DEMUXER)  += realtextdec.o subtitles.o
 OBJS-$(CONFIG_REDSPARK_DEMUXER)  += redspark.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index e15d0fa6d7..3140018f8d 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -391,6 +391,7 @@ extern const FFInputFormat  ff_qoa_demuxer;
 extern const FFInputFormat  ff_r3d_demuxer;
 extern const FFInputFormat  ff_rawvideo_demuxer;
 extern const FFOutputFormat ff_rawvideo_muxer;
+extern const FFInputFormat  ff_rcwt_demuxer;
 extern const FFOutputFormat ff_rcwt_muxer;
 extern const FFInputFormat  ff_realtext_demuxer;
 extern const FFInputFormat  ff_redspark_demuxer;
diff --git a/libavformat/rcwtdec.c b/libavformat/rcwtdec.c
new file mode 100644
index 00..9b0d60fe35
--- /dev/null
+++ b/libavformat/rcwtdec.c
@@ -0,0 +1,123 @@
+/*
+ * RCWT (Raw Captions With Time) demuxer
+ *
+ * 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
+ */
+
+/*
+ * RCWT (Raw Captions With Time) is a format native to ccextractor, a commonly
+ * used 

[FFmpeg-devel] [PATCH v9 1/5] avformat/subtitles: extend ff_subtitles_queue_insert() to support not yet available events

2024-03-23 Thread Marth64
If ff_subtitles_queue_insert() were given a NULL buffer
with 0 length, it would still attempt to grow the packet
or memcpy depending on if merge option is enabled.

In this commit, allow passing a NULL buffer with 0 length
without attempting to do such operations. This way, if a
subtitle demuxer happens to pass an empty cue or wants to
use av_get_packet() to read bytes, there are no unnecessary
operations on the packet after it is allocated.

Signed-off-by: Marth64 
---
 libavformat/subtitles.c | 24 
 libavformat/subtitles.h |  2 +-
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index 3413763c7b..4742ca0667 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -21,6 +21,7 @@
 #include "avformat.h"
 #include "subtitles.h"
 #include "avio_internal.h"
+#include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 
 void ff_text_init_avio(void *s, FFTextReader *r, AVIOContext *pb)
@@ -111,15 +112,20 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue 
*q,
 {
 AVPacket **subs, *sub;
 
+if (!event)
+av_assert1(len == 0);
+
 if (merge && q->nb_subs > 0) {
 /* merge with previous event */
 
 int old_len;
 sub = q->subs[q->nb_subs - 1];
 old_len = sub->size;
-if (av_grow_packet(sub, len) < 0)
-return NULL;
-memcpy(sub->data + old_len, event, len);
+if (event) {
+if (av_grow_packet(sub, len) < 0)
+return NULL;
+memcpy(sub->data + old_len, event, len);
+}
 } else {
 /* new event */
 
@@ -133,14 +139,16 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue 
*q,
 sub = av_packet_alloc();
 if (!sub)
 return NULL;
-if (av_new_packet(sub, len) < 0) {
-av_packet_free();
-return NULL;
+if (event) {
+if (av_new_packet(sub, len) < 0) {
+av_packet_free();
+return NULL;
+}
+memcpy(sub->data, event, len);
 }
-subs[q->nb_subs++] = sub;
 sub->flags |= AV_PKT_FLAG_KEY;
 sub->pts = sub->dts = 0;
-memcpy(sub->data, event, len);
+subs[q->nb_subs++] = sub;
 }
 return sub;
 }
diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
index 88665663c5..ad6b96ca6a 100644
--- a/libavformat/subtitles.h
+++ b/libavformat/subtitles.h
@@ -112,7 +112,7 @@ typedef struct {
 /**
  * Insert a new subtitle event.
  *
- * @param event the subtitle line, may not be zero terminated
+ * @param event the subtitle line (not zero terminated) or NULL on not yet 
available event
  * @param len   the length of the event (in strlen() sense, so without '\0')
  * @param merge set to 1 if the current event should be concatenated with the
  *  previous one instead of adding a new entry, 0 otherwise
-- 
2.34.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 v9 0/5] RCWT Closed Captions demuxer (v9)

2024-03-23 Thread Marth64
Since v7/8:
* Simplified demuxer error handling logic
* Fixes buggy change to ff_subtitles_queue_insert()
* Documentation improvements

Signed-off-by: Marth64 
-- 
2.34.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/dvdvideodec: add explicit inttypes.h include

2024-03-23 Thread Marth64
Since log statements printing int64 were made portable in
4464b7eeb194e98ac115f18d2b6be67361407c8a, let us include
inttypes.h explicitly (as it is unclear where PRId64 and
such are coming from now).

Reported-by: Traneptora
Signed-off-by: Marth64 
---
 libavformat/dvdvideodec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/dvdvideodec.c b/libavformat/dvdvideodec.c
index 761ac97ec6..959b267e69 100644
--- a/libavformat/dvdvideodec.c
+++ b/libavformat/dvdvideodec.c
@@ -30,6 +30,7 @@
  * 7) Close the dvdnav VM, and free dvdread's IFO structures
  */
 
+#include 
 #include 
 #include 
 #include 
-- 
2.34.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".


Re: [FFmpeg-devel] [RFC] clarifying the TC conflict of interest rule

2024-03-23 Thread Michael Niedermayer
On Fri, Mar 22, 2024 at 01:52:55PM +0100, Anton Khirnov wrote:
> Michael,

> following up on the previous discussion in this thread - if you,
> personally, would like to vote for a different option than those
> suggested so far, please propose one.

The goal of the vote is to find the option which most people prefer.
Not the option that I personally prefer.
The winning options often are compromises that noone has as their
favorite but the team as a whole prefers.

You also added 3 options yourself, which i presume you dont all
intend to vote for yourself


> I am not going to add a large number of options that nobody actually
> wants to vote for, as it imposes a burden on the voters who have to
> carefully read and compare all the options.

The intend of the vote here is to resolve a disagreement we have.

Simply omiting opposing options is not how Democracy works

You could discuss with others and try to find a smaller set of options
that still represent all cases the team may want.

I think the 2 main cases from the ones proposed by me are:
(that is just my feeling and i cant read peoples minds and there may be
 other preferrances that should be represented)


@@ -82,6 +82,14 @@ The TC has 2 modes of operation: a RFC one and an internal 
one.

 If the TC thinks it needs the input from the larger community, the TC can call 
for a RFC. Else, it can decide by itself.

+Each TC member must vote on such decision according to what is, in their view, 
best for the project.
+
+If a TC member is aware of being in a conflict of interest with regards to the 
case, they must announce it
+and recuse themselves from the TC discussion and vote.
+
+A conflict of interest is presumed to occur when a TC member has a personal 
interest
+(e.g. financial) in a specific outcome of the case that differs from what is 
best for the project.
+
+If the disagreement involves a member of the TC, that member must recuse 
themselves from the decision.
-If the disagreement involves a member of the TC, that member should recuse 
themselves from the decision.

 The decision to use a RFC process or an internal discussion is a discretionary 
decision of the TC.



@@ -82,6 +82,13 @@ The TC has 2 modes of operation: a RFC one and an internal 
one.

 If the TC thinks it needs the input from the larger community, the TC can call 
for a RFC. Else, it can decide by itself.

+Each TC member must vote on such decision according to what is, in their view, 
best for the project.
+
+If a TC member is aware of being in a conflict of interest with regards to the 
case, they must announce it
+and recuse themselves from the TC discussion and vote.
+
+A conflict of interest is presumed to occur when a TC member has a personal 
interest
+(e.g. financial) in a specific outcome of the case that differs from what is 
best for the project.
+
-If the disagreement involves a member of the TC, that member should recuse 
themselves from the decision.

 The decision to use a RFC process or an internal discussion is a discretionary 
decision of the TC.


thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle


signature.asc
Description: PGP signature
___
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".


Re: [FFmpeg-devel] [PATCH] libavformat\file:Fix duplicate JNI symbols

2024-03-23 Thread Zhao Zhili


On 2024/3/24 03:05, ad...@shaoxia.xyz wrote:

From: 联盟少侠 

Could you configure git to avoid Chinese character?


The errors indicate that there are multiple definitions of several JNI (Java 
Native Interface) symbols in the FFmpeg library. Specifically, the linker 
ld.lld has found duplicate definitions for the following symbols:

How to reproduce the error?


- ff_jni_get_env
- ff_jni_jstring_to_utf_chars
- ff_jni_utf_chars_to_jstring
- ff_jni_exception_get_summary
- ff_jni_exception_check
- ff_jni_init_jfields
- ff_jni_reset_jfields

These symbols are defined in both libavcodec.a and libavformat.a archives, 
leading to conflicts during the linking process. The duplicates are found in 
the same source file ffjni.c, but they are being compiled into two different 
static libraries.

To resolve these errors, ensure that each symbol is defined only once across 
all linked libraries, or if these symbols are required in both libraries, they 
should be marked as weak symbols to allow the linker to handle them 
appropriately. Additionally, check for any build script misconfigurations that 
may be causing the same file to be included in multiple libraries.
---
  libavformat/file.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/file.c b/libavformat/file.c
index dd5819c..fa13ae9 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -43,7 +43,7 @@
  #if CONFIG_ANDROID_CONTENT_PROTOCOL
  #include 
  #include "libavcodec/jni.h"
-#include "libavcodec/ffjni.c"
+#include "libavcodec/ffjni.h"
  #endif

This just break --enable-shared, so NACK.
  
  


___
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".


Re: [FFmpeg-devel] [PATCH 08/12] lavc/frame_thread_encoder: avoid assigning a whole AVCodecContext

2024-03-23 Thread Michael Niedermayer
On Fri, Mar 22, 2024 at 09:28:37PM +0100, Anton Khirnov wrote:
> It is highly unsafe, as AVCodecContext contains many allocated fields.
> Copying information via AVCodecParameters and with av_opt_copy() should
> handle everything needed by thread workers.
> ---
>  libavcodec/frame_thread_encoder.c | 26 --
>  1 file changed, 20 insertions(+), 6 deletions(-)

this breaks huffyuv with 2 pass

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle


signature.asc
Description: PGP signature
___
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 2/2] avutil/film_grain_params: remove do loop in CHECK macro

2024-03-23 Thread Leo Izen
The continue statement will break out of the do/while loop, not the
outer loop as intended. This is one (compound) statement anyway, so we
can remove the do/while entirely.

Signed-off-by: Leo Izen 
---
 libavutil/film_grain_params.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavutil/film_grain_params.c b/libavutil/film_grain_params.c
index b3fa37f527..8f8dcee569 100644
--- a/libavutil/film_grain_params.c
+++ b/libavutil/film_grain_params.c
@@ -70,10 +70,8 @@ const AVFilmGrainParams *av_film_grain_params_select(const 
AVFrame *frame)
 continue;
 
 #define CHECK(a, b, unspec) \
-do {\
 if ((a) != (unspec) && (b) != (unspec) && (a) != (b))   \
-continue;   \
-} while (0)
+continue
 
 CHECK(fgp->bit_depth_luma,   bit_depth_luma, 0);
 CHECK(fgp->bit_depth_chroma, bit_depth_chroma,   0);
-- 
2.44.0

___
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] avutil/film_grain_params: remove unused variables

2024-03-23 Thread Leo Izen
These variables are never read from, so they trigger -Wunused-variables

Signed-off-by: Leo Izen 
---
 libavutil/film_grain_params.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavutil/film_grain_params.c b/libavutil/film_grain_params.c
index fff7252f2f..b3fa37f527 100644
--- a/libavutil/film_grain_params.c
+++ b/libavutil/film_grain_params.c
@@ -53,8 +53,6 @@ const AVFilmGrainParams *av_film_grain_params_select(const 
AVFrame *frame)
 {
 const AVFilmGrainParams *fgp, *best = NULL;
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
-const AVFilmGrainAOMParams *aom;
-const AVFilmGrainH274Params *h274;
 int bit_depth_luma, bit_depth_chroma;
 if (!desc)
 return NULL;
@@ -88,7 +86,6 @@ const AVFilmGrainParams *av_film_grain_params_select(const 
AVFrame *frame)
 case AV_FILM_GRAIN_PARAMS_NONE:
 continue;
 case AV_FILM_GRAIN_PARAMS_AV1:
-aom = >codec.aom;
 /* AOM FGS needs an exact match for the chroma resolution */
 if (fgp->subsampling_x != desc->log2_chroma_w ||
 fgp->subsampling_y != desc->log2_chroma_h)
-- 
2.44.0

___
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 0/2] Minor avutil/film_grain_params tweaks

2024-03-23 Thread Leo Izen
A few minor tweaks to libavutil/film_grain_params.c.

Leo Izen (2):
  avutil/film_grain_params: remove unused variables
  avutil/film_grain_params: remove do loop in CHECK macro

 libavutil/film_grain_params.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

-- 
2.44.0

___
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".


Re: [FFmpeg-devel] [PATCH 1/6] avcodec/liblc3: Add encoding/decoding support of LC3 audio codec

2024-03-23 Thread Michael Niedermayer
On Fri, Mar 22, 2024 at 05:01:00PM +, Antoine Soulier via ffmpeg-devel 
wrote:
> The LC3 audio codec is the default codec of Bluetooth LE audio.
> This is a wrapper over the liblc3 library (https://github.com/google/liblc3).
> 
> Signed-off-by: Antoine Soulier 
> Signed-off-by: Antoine SOULIER 
> ---
>  libavcodec/Makefile |   3 +
>  libavcodec/allcodecs.c  |   3 +
>  libavcodec/codec_desc.c |  14 +++
>  libavcodec/codec_id.h   |   2 +
>  libavcodec/liblc3dec.c  | 146 ++
>  libavcodec/liblc3enc.c  | 191 
>  6 files changed, 359 insertions(+)
>  create mode 100644 libavcodec/liblc3dec.c
>  create mode 100644 libavcodec/liblc3enc.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 708434ac76..7d2cf3076d 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1123,6 +1123,9 @@ OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
>  OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
>  OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o
>  OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
> +OBJS-$(CONFIG_LIBLC3_ENCODER) += liblc3enc.o
> +OBJS-$(CONFIG_LIBLC3_LC3_DECODER) += liblc3dec.o
> +OBJS-$(CONFIG_LIBLC3_LC3PLUS_DECODER) += liblc3dec.o
>  OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
>  OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
>  OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER)  += libopencore-amr.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 2386b450a6..29aedaeac6 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -776,6 +776,9 @@ extern const FFCodec ff_libilbc_encoder;
>  extern const FFCodec ff_libilbc_decoder;
>  extern const FFCodec ff_libjxl_decoder;
>  extern const FFCodec ff_libjxl_encoder;
> +extern const FFCodec ff_liblc3_encoder;
> +extern const FFCodec ff_liblc3_lc3_decoder;
> +extern const FFCodec ff_liblc3_lc3plus_decoder;
>  extern const FFCodec ff_libmp3lame_encoder;
>  extern const FFCodec ff_libopencore_amrnb_encoder;
>  extern const FFCodec ff_libopencore_amrnb_decoder;
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 3bab86db62..230bba2a09 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -3425,6 +3425,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
>  .long_name = NULL_IF_CONFIG_SMALL("QOA (Quite OK Audio)"),
>  .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
>  },
> +{
> +.id= AV_CODEC_ID_LC3,
> +.type  = AVMEDIA_TYPE_AUDIO,
> +.name  = "lc3",
> +.long_name = NULL_IF_CONFIG_SMALL("LC3 (Low Complexity Communication 
> Codec)"),
> +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
> +},
> +{
> +.id= AV_CODEC_ID_LC3_PLUS,
> +.type  = AVMEDIA_TYPE_AUDIO,
> +.name  = "lc3_plus",
> +.long_name = NULL_IF_CONFIG_SMALL("LC3plus (Low Complexity 
> Communication Codec plus)"),
> +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
> +},
>  
>  /* subtitle codecs */
>  {
> diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
> index c8dc21da74..7e4cb39049 100644
> --- a/libavcodec/codec_id.h
> +++ b/libavcodec/codec_id.h
> @@ -543,6 +543,8 @@ enum AVCodecID {
>  AV_CODEC_ID_AC4,
>  AV_CODEC_ID_OSQ,
>  AV_CODEC_ID_QOA,
> +AV_CODEC_ID_LC3,
> +AV_CODEC_ID_LC3_PLUS,
>  
>  /* subtitle codecs */
>  AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing 
> at the start of subtitle codecs.
> diff --git a/libavcodec/liblc3dec.c b/libavcodec/liblc3dec.c
> new file mode 100644
> index 00..e97cecc68f
> --- /dev/null
> +++ b/libavcodec/liblc3dec.c
> @@ -0,0 +1,146 @@
> +/*
> + * LC3 decoder wrapper
> + * Copyright (C) 2024  Antoine Soulier 
> + *
> + * This file is part of FFmpeg.
> + *
> + * Permission to use, copy, modify, and/or distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include 

this breaks build

libavcodec/liblc3enc.c:20:10: fatal error: lc3.h: No such file or directory
 #include 
  ^~~

configure enables this even before the configure patch

thx

[...]
-- 
Michael 

[FFmpeg-devel] [PATCH v2 8/8] avcodec/dovi_rpu: attach ext blocks to frames

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

---
 libavcodec/dovi_rpu.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index b3defd87bda..2b4d2b470c2 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -94,7 +94,7 @@ int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
 AVFrameSideData *sd;
 AVBufferRef *buf;
 AVDOVIMetadata *dovi;
-size_t dovi_size;
+size_t dovi_size, ext_sz;
 
 if (!s->mapping || !s->color)
 return 0; /* incomplete dovi metadata */
@@ -120,6 +120,9 @@ int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
 COPY(AVDOVIRpuDataHeader, av_dovi_get_header(dovi), >header, 
disable_residual_flag);
 COPY(AVDOVIDataMapping, av_dovi_get_mapping(dovi), s->mapping, nlq_pivots);
 COPY(AVDOVIColorMetadata, av_dovi_get_color(dovi), s->color, 
source_diagonal);
+ext_sz = FFMIN(sizeof(AVDOVIDmData), dovi->ext_block_size);
+for (int i = 0; i < s->num_ext_blocks; i++)
+memcpy(av_dovi_get_ext(dovi, i), >ext_blocks[i], ext_sz);
 return 0;
 }
 
-- 
2.44.0

___
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/8] avcodec/dovi_rpu: parse extension blocks

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

We split the inner loop between v1 and v2 extension blocks to print
a warning where an extension block was encountered in an unexpected
context.

Co-authored-by: quietvoid 
---
 libavcodec/dovi_rpu.c | 178 ++
 1 file changed, 178 insertions(+)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 6097bd5422f..b3defd87bda 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -204,6 +204,170 @@ static inline unsigned get_variable_bits(GetBitContext 
*gb, int n)
 }  
 \
 } while (0)
 
+static void parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm)
+{
+switch (dm->level) {
+case 1:
+dm->l1.min_pq = get_bits(gb, 12);
+dm->l1.max_pq = get_bits(gb, 12);
+dm->l1.avg_pq = get_bits(gb, 12);
+break;
+case 2:
+dm->l2.target_max_pq = get_bits(gb, 12);
+dm->l2.trim_slope = get_bits(gb, 12);
+dm->l2.trim_offset = get_bits(gb, 12);
+dm->l2.trim_power = get_bits(gb, 12);
+dm->l2.trim_chroma_weight = get_bits(gb, 12);
+dm->l2.trim_saturation_gain = get_bits(gb, 12);
+dm->l2.ms_weight = get_bits(gb, 13) - 8192;
+break;
+case 4:
+dm->l4.anchor_pq = get_bits(gb, 12);
+dm->l4.anchor_power = get_bits(gb, 12);
+break;
+case 5:
+dm->l5.left_offset = get_bits(gb, 13);
+dm->l5.right_offset = get_bits(gb, 13);
+dm->l5.top_offset = get_bits(gb, 13);
+dm->l5.bottom_offset = get_bits(gb, 13);
+break;
+case 6:
+dm->l6.max_luminance = get_bits(gb, 16);
+dm->l6.min_luminance = get_bits(gb, 16);
+dm->l6.max_cll = get_bits(gb, 16);
+dm->l6.max_fall = get_bits(gb, 16);
+break;
+case 255:
+dm->l255.dm_run_mode = get_bits(gb, 8);
+dm->l255.dm_run_version = get_bits(gb, 8);
+for (int i = 0; i < 4; i++)
+dm->l255.dm_debug[i] = get_bits(gb, 8);
+break;
+default:
+av_log(s->logctx, AV_LOG_WARNING,
+   "Unknown Dolby Vision DM v1 level: %u\n", dm->level);
+}
+}
+
+static inline AVCIExy get_cie_xy(GetBitContext *gb)
+{
+AVCIExy xy;
+const int denom = 32767;
+xy.x = av_make_q(get_sbits(gb, 16), denom);
+xy.y = av_make_q(get_sbits(gb, 16), denom);
+return xy;
+}
+
+static void parse_ext_v2(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm,
+ int ext_block_length)
+{
+switch (dm->level) {
+case 3:
+dm->l3.min_pq_offset = get_bits(gb, 12);
+dm->l3.max_pq_offset = get_bits(gb, 12);
+dm->l3.avg_pq_offset = get_bits(gb, 12);
+break;
+case 8:
+dm->l8.target_display_index = get_bits(gb, 8);
+dm->l8.trim_slope = get_bits(gb, 12);
+dm->l8.trim_offset = get_bits(gb, 12);
+dm->l8.trim_power = get_bits(gb, 12);
+dm->l8.trim_chroma_weight = get_bits(gb, 12);
+dm->l8.trim_saturation_gain = get_bits(gb, 12);
+dm->l8.ms_weight = get_bits(gb, 12) - 8192;
+if (ext_block_length < 12)
+break;
+dm->l8.target_mid_contrast = get_bits(gb, 12);
+if (ext_block_length < 13)
+break;
+dm->l8.clip_trim = get_bits(gb, 12);
+if (ext_block_length < 19)
+break;
+for (int i = 0; i < 6; i++)
+dm->l8.saturation_vector_field[i] = get_bits(gb, 8);
+if (ext_block_length < 25)
+break;
+for (int i = 0; i < 6; i++)
+dm->l8.hue_vector_field[i] = get_bits(gb, 8);
+break;
+case 9:
+dm->l9.source_primary_index = get_bits(gb, 8);
+if (ext_block_length < 17)
+break;
+dm->l9.source_display_primaries.prim.r = get_cie_xy(gb);
+dm->l9.source_display_primaries.prim.g = get_cie_xy(gb);
+dm->l9.source_display_primaries.prim.b = get_cie_xy(gb);
+dm->l9.source_display_primaries.wp = get_cie_xy(gb);
+break;
+case 10:
+dm->l10.target_display_index = get_bits(gb, 8);
+dm->l10.target_max_pq = get_bits(gb, 12);
+dm->l10.target_min_pq = get_bits(gb, 12);
+dm->l10.target_primary_index = get_bits(gb, 8);
+if (ext_block_length < 21)
+break;
+dm->l10.target_display_primaries.prim.r = get_cie_xy(gb);
+dm->l10.target_display_primaries.prim.g = get_cie_xy(gb);
+dm->l10.target_display_primaries.prim.b = get_cie_xy(gb);
+dm->l10.target_display_primaries.wp = get_cie_xy(gb);
+break;
+case 11:
+dm->l11.content_type = get_bits(gb, 8);
+dm->l11.whitepoint = get_bits(gb, 4);
+dm->l11.reference_mode_flag = get_bits(gb, 1);
+skip_bits(gb, 3); /* reserved */
+dm->l11.sharpness = get_bits(gb, 2);
+dm->l11.noise_reduction = get_bits(gb, 2);
+

[FFmpeg-devel] [PATCH v2 5/8] avcodec/dovi_rpu: verify RPU data CRC32

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

The Dolby Vision RPU contains a CRC32 to validate the payload against.
The implementation is CRC32/MPEG-2.

The CRC is only verified with the AV_EF_CRCCHECK flag.

Co-authored-by: quietvoid 
---
 libavcodec/av1dec.c   |  3 ++-
 libavcodec/dovi_rpu.c | 18 --
 libavcodec/dovi_rpu.h |  3 ++-
 libavcodec/hevcdec.c  |  3 ++-
 libavcodec/libdav1d.c |  3 ++-
 5 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 32a795e7580..e8753d302ae 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -1001,7 +1001,8 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame 
*frame,
 provider_oriented_code != 0x800)
 break;
 
-ret = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - 
gb.buffer);
+ret = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - gb.buffer,
+avctx->err_recognition);
 if (ret < 0) {
 av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
 break; // ignore
diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index d792a429217..d584d99590a 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -22,6 +22,7 @@
  */
 
 #include "libavutil/buffer.h"
+#include "libavutil/crc.h"
 
 #include "avcodec.h"
 #include "dovi_rpu.h"
@@ -200,7 +201,8 @@ static inline unsigned get_variable_bits(GetBitContext *gb, 
int n)
 }  
 \
 } while (0)
 
-int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size)
+int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
+  int err_recognition)
 {
 AVDOVIRpuDataHeader *hdr = >header;
 GetBitContext *gb = &(GetBitContext){0};
@@ -268,6 +270,19 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 rpu_size--;
 }
 
+if (!rpu_size || rpu[rpu_size - 1] != 0x80)
+goto fail;
+
+if (err_recognition & AV_EF_CRCCHECK) {
+uint32_t crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE),
+  -1, rpu, rpu_size - 1)); /* exclude 0x80 */
+if (crc) {
+av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);
+if (err_recognition & AV_EF_EXPLODE)
+goto fail;
+}
+}
+
 if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
 return ret;
 
@@ -508,7 +523,6 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 color->source_diagonal = get_bits(gb, 10);
 }
 
-/* FIXME: verify CRC32, requires implementation of AV_CRC_32_MPEG_2 */
 return 0;
 
 fail:
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 755171c9237..8dcc65bb40a 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -79,7 +79,8 @@ void ff_dovi_update_cfg(DOVIContext *s, const 
AVDOVIDecoderConfigurationRecord *
  *
  * Returns 0 or an error code.
  */
-int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size);
+int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
+  int err_recognition);
 
 /**
  * Attach the decoded AVDOVIMetadata as side data to an AVFrame.
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 575836e340c..3c8ec531a5d 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3207,7 +3207,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t 
*buf, int length)
 return AVERROR(ENOMEM);
 memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2);
 
-ret = ff_dovi_rpu_parse(>dovi_ctx, nal->data + 2, nal->size - 2);
+ret = ff_dovi_rpu_parse(>dovi_ctx, nal->data + 2, nal->size - 2,
+s->avctx->err_recognition);
 if (ret < 0) {
 av_buffer_unref(>rpu_buf);
 av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index ddcd0708b4f..f022a4ad05c 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -567,7 +567,8 @@ static int libdav1d_receive_frame(AVCodecContext *c, 
AVFrame *frame)
 provider_oriented_code != 0x800)
 break;
 
-res = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - 
gb.buffer);
+res = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - 
gb.buffer,
+c->err_recognition);
 if (res < 0) {
 av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
 break; // ignore
-- 
2.44.0

___
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 

[FFmpeg-devel] [PATCH v2 6/8] avcodec/dovi_rpu: add ext_blocks array to DOVIContext

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

---
 libavcodec/dovi_rpu.c | 3 +++
 libavcodec/dovi_rpu.h | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index d584d99590a..6097bd5422f 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -47,6 +47,7 @@ void ff_dovi_ctx_unref(DOVIContext *s)
 {
 for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
 ff_refstruct_unref(>vdr[i]);
+ff_refstruct_unref(>ext_blocks);
 av_free(s->rpu_buf);
 
 *s = (DOVIContext) {
@@ -58,6 +59,7 @@ void ff_dovi_ctx_flush(DOVIContext *s)
 {
 for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
 ff_refstruct_unref(>vdr[i]);
+ff_refstruct_unref(>ext_blocks);
 
 *s = (DOVIContext) {
 .logctx = s->logctx,
@@ -76,6 +78,7 @@ void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext 
*s0)
 s->dv_profile = s0->dv_profile;
 for (int i = 0; i <= DOVI_MAX_DM_ID; i++)
 ff_refstruct_replace(>vdr[i], s0->vdr[i]);
+ff_refstruct_replace(>ext_blocks, s0->ext_blocks);
 }
 
 void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord 
*cfg)
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 8dcc65bb40a..9f26f332ceb 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -44,6 +44,12 @@ typedef struct DOVIContext {
 const AVDOVIDataMapping *mapping;
 const AVDOVIColorMetadata *color;
 
+/**
+ * Currently active extension blocks, updates on every ff_dovi_rpu_parse()
+ */
+AVDOVIDmData *ext_blocks;
+int num_ext_blocks;
+
 /**
  * Private fields internal to dovi_rpu.c
  */
-- 
2.44.0

___
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/8] avcodec/dovi_rpu: strip container in separate step

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

This ensures that `gb` in the following section is fully byte-aligned,
points at the start of the actual RPU, and ends on the CRC terminator.

This is important for both calculation of the CRC, as well as dovi
extension block parsing (which aligns to byte boundaries in various
places).
---
 libavcodec/dovi_rpu.c | 48 +++
 libavcodec/dovi_rpu.h |  2 ++
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 53f8c288db0..d792a429217 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/buffer.h"
 
+#include "avcodec.h"
 #include "dovi_rpu.h"
 #include "golomb.h"
 #include "get_bits.h"
@@ -45,6 +46,7 @@ void ff_dovi_ctx_unref(DOVIContext *s)
 {
 for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
 ff_refstruct_unref(>vdr[i]);
+av_free(s->rpu_buf);
 
 *s = (DOVIContext) {
 .logctx = s->logctx,
@@ -59,6 +61,9 @@ void ff_dovi_ctx_flush(DOVIContext *s)
 *s = (DOVIContext) {
 .logctx = s->logctx,
 .dv_profile = s->dv_profile,
+/* preserve temporary buffer */
+.rpu_buf = s->rpu_buf,
+.rpu_buf_sz = s->rpu_buf_sz,
 };
 }
 
@@ -202,17 +207,17 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 DOVIVdr *vdr;
 int ret;
 
-uint8_t nal_prefix;
 uint8_t rpu_type;
 uint8_t vdr_seq_info_present;
 uint8_t vdr_dm_metadata_present;
 uint8_t use_prev_vdr_rpu;
 uint8_t use_nlq;
 uint8_t profile;
-if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
-return ret;
 
-/* Container header */
+if (rpu_size < 5)
+goto fail;
+
+/* Container */
 if (s->dv_profile == 10 /* dav1.10 */) {
 /* DV inside AV1 re-uses an EMDF container skeleton, but with fixed
  * values - so we can effectively treat this as a magic byte sequence.
@@ -229,18 +234,43 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
  *   discard_unknown_payload : f(1) = 1
  */
 const unsigned header_magic = 0x01be6841u;
-unsigned header, emdf_payload_size;
-header = get_bits_long(gb, 27);
-VALIDATE(header, header_magic, header_magic);
+unsigned emdf_header, emdf_payload_size, emdf_protection;
+if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
+return ret;
+emdf_header = get_bits_long(gb, 27);
+VALIDATE(emdf_header, header_magic, header_magic);
 emdf_payload_size = get_variable_bits(gb, 8);
 VALIDATE(emdf_payload_size, 6, 512);
 if (emdf_payload_size * 8 > get_bits_left(gb))
 return AVERROR_INVALIDDATA;
+
+/* The payload is not byte-aligned (off by *one* bit, curse Dolby),
+ * so copy into a fresh buffer to preserve byte alignment of the
+ * RPU struct */
+av_fast_padded_malloc(>rpu_buf, >rpu_buf_sz, emdf_payload_size);
+if (!s->rpu_buf)
+return AVERROR(ENOMEM);
+for (int i = 0; i < emdf_payload_size; i++)
+s->rpu_buf[i] = get_bits(gb, 8);
+rpu = s->rpu_buf;
+rpu_size = emdf_payload_size;
+
+/* Validate EMDF footer */
+emdf_protection = get_bits(gb, 5 + 12);
+VALIDATE(emdf_protection, 0x400, 0x400);
 } else {
-nal_prefix = get_bits(gb, 8);
-VALIDATE(nal_prefix, 25, 25);
+/* NAL RBSP with prefix and trailing zeroes */
+VALIDATE(rpu[0], 25, 25); /* NAL prefix */
+rpu++;
+rpu_size--;
+/* Strip trailing padding bytes */
+while (rpu_size && rpu[rpu_size - 1] == 0)
+rpu_size--;
 }
 
+if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
+return ret;
+
 /* RPU header */
 rpu_type = get_bits(gb, 6);
 if (rpu_type != 2) {
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 51c5fdbb879..755171c9237 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -48,6 +48,8 @@ typedef struct DOVIContext {
  * Private fields internal to dovi_rpu.c
  */
 struct DOVIVdr *vdr[DOVI_MAX_DM_ID+1]; ///< RefStruct references
+uint8_t *rpu_buf; ///< temporary buffer
+unsigned rpu_buf_sz;
 uint8_t dv_profile;
 
 } DOVIContext;
-- 
2.44.0

___
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/8] avcodec/dovi_rpu: switch to AVERROR_INVALIDDATA

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

Instead of AVERROR(EINVAL)
---
 libavcodec/dovi_rpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index c84a942f476..53f8c288db0 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -483,5 +483,5 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 
 fail:
 ff_dovi_ctx_unref(s); /* don't leak potentially invalid state */
-return AVERROR(EINVAL);
+return AVERROR_INVALIDDATA;
 }
-- 
2.44.0

___
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/8] avutil/dovi_meta: add dolby vision extension blocks

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

As well as accessors plus a function for allocating this struct with
extension blocks,

Definitions generously taken from quietvoid/dovi_tool, which is
assembled as a collection of various patent fragments, as well as output
by the official Dolby Vision bitstream verifier tool.
---
 doc/APIchanges|   5 ++
 libavutil/dovi_meta.c |  22 ++-
 libavutil/dovi_meta.h | 146 ++
 libavutil/version.h   |   2 +-
 4 files changed, 171 insertions(+), 4 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 2f34018ea1b..fa406c445e7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-03-xx - xx - lavu 59.8.100 - dovi_meta.h
+  Add AVDOVIMetadata.ext_block_{offset,size}, AVDOVIMetadata.num_ext_blocks,
+  AVDOVIDmData and AVDOVIDmLevel{1..6,8..11,254..255}, av_dovi_get_ext()
+  and av_dovi_find_level().
+
 2024-03-xx - xx - lavu 59.7.100 - dovi_meta.h
   Add AVDOVIDataMapping.nlq_pivots.
 
diff --git a/libavutil/dovi_meta.c b/libavutil/dovi_meta.c
index 9c50da561ed..dfa4a438ed4 100644
--- a/libavutil/dovi_meta.c
+++ b/libavutil/dovi_meta.c
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "dovi_meta.h"
 #include "mem.h"
 
@@ -39,6 +41,7 @@ typedef struct AVDOVIMetadataInternal {
 AVDOVIRpuDataHeader header;
 AVDOVIDataMapping mapping;
 AVDOVIColorMetadata color;
+AVDOVIDmData ext_blocks[AV_DOVI_MAX_EXT_BLOCKS];
 } AVDOVIMetadataInternal;
 
 AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
@@ -51,10 +54,23 @@ AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
 *size = sizeof(*dovi);
 
 dovi->metadata = (struct AVDOVIMetadata) {
-.header_offset  = offsetof(AVDOVIMetadataInternal, header),
-.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
-.color_offset   = offsetof(AVDOVIMetadataInternal, color),
+.header_offset  = offsetof(AVDOVIMetadataInternal, header),
+.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
+.color_offset   = offsetof(AVDOVIMetadataInternal, color),
+.ext_block_offset   = offsetof(AVDOVIMetadataInternal, ext_blocks),
+.ext_block_size = sizeof(AVDOVIDmData),
 };
 
 return >metadata;
 }
+
+AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level)
+{
+for (int i = 0; i < data->num_ext_blocks; i++) {
+AVDOVIDmData *ext = av_dovi_get_ext(data, i);
+if (ext->level == level)
+return ext;
+}
+
+return NULL;
+}
diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
index 46b13b33995..e10332f8d7e 100644
--- a/libavutil/dovi_meta.h
+++ b/libavutil/dovi_meta.h
@@ -29,7 +29,9 @@
 
 #include 
 #include 
+
 #include "rational.h"
+#include "csp.h"
 
 /*
  * DOVI configuration
@@ -187,6 +189,130 @@ typedef struct AVDOVIColorMetadata {
 uint16_t source_diagonal;
 } AVDOVIColorMetadata;
 
+typedef struct AVDOVIDmLevel1 {
+/* Per-frame brightness metadata */
+uint16_t min_pq;
+uint16_t max_pq;
+uint16_t avg_pq;
+} AVDOVIDmLevel1;
+
+typedef struct AVDOVIDmLevel2 {
+/* Usually derived from level 8 (at different levels) */
+uint16_t target_max_pq;
+uint16_t trim_slope;
+uint16_t trim_offset;
+uint16_t trim_power;
+uint16_t trim_chroma_weight;
+uint16_t trim_saturation_gain;
+int16_t ms_weight;
+} AVDOVIDmLevel2;
+
+typedef struct AVDOVIDmLevel3 {
+uint16_t min_pq_offset;
+uint16_t max_pq_offset;
+uint16_t avg_pq_offset;
+} AVDOVIDmLevel3;
+
+typedef struct AVDOVIDmLevel4 {
+uint16_t anchor_pq;
+uint16_t anchor_power;
+} AVDOVIDmLevel4;
+
+typedef struct AVDOVIDmLevel5 {
+/* Active area definition */
+uint16_t left_offset;
+uint16_t right_offset;
+uint16_t top_offset;
+uint16_t bottom_offset;
+} AVDOVIDmLevel5;
+
+typedef struct AVDOVIDmLevel6 {
+/* Static HDR10 metadata */
+uint16_t max_luminance;
+uint16_t min_luminance;
+uint16_t max_cll;
+uint16_t max_fall;
+} AVDOVIDmLevel6;
+
+typedef struct AVDOVIDmLevel8 {
+/* Extended version of level 2 */
+uint8_t target_display_index;
+uint16_t trim_slope;
+uint16_t trim_offset;
+uint16_t trim_power;
+uint16_t trim_chroma_weight;
+uint16_t trim_saturation_gain;
+uint16_t ms_weight;
+uint16_t target_mid_contrast;
+uint16_t clip_trim;
+uint8_t saturation_vector_field[6];
+uint8_t hue_vector_field[6];
+} AVDOVIDmLevel8;
+
+typedef struct AVDOVIDmLevel9 {
+/* Source display characteristics */
+uint8_t source_primary_index;
+AVColorPrimariesDesc source_display_primaries;
+} AVDOVIDmLevel9;
+
+typedef struct AVDOVIDmLevel10 {
+/* Target display characteristics */
+uint8_t target_display_index;
+uint16_t target_max_pq;

[FFmpeg-devel] [PATCH v2 1/8] avutil/dovi_meta: add AVDOVIDataMapping.nlq_pivots

2024-03-23 Thread Niklas Haas
From: quietvoid 

The NLQ pivots are not documented but should be present in the header
for profile 7 RPU format. It has been verified using Dolby's
verification toolkit.

Signed-off-by: quietvoid 
Signed-off-by: Niklas Haas 
---
 doc/APIchanges| 3 +++
 libavcodec/dovi_rpu.c | 9 -
 libavutil/dovi_meta.h | 1 +
 libavutil/version.h   | 2 +-
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 77629072552..2f34018ea1b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-03-xx - xx - lavu 59.7.100 - dovi_meta.h
+  Add AVDOVIDataMapping.nlq_pivots.
+
 2024-03-xx - xx - lavu 59.6.100 - film_grain_params.h
   Add av_film_grain_params_select().
 
diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 31c64fb0602..c84a942f476 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -109,7 +109,7 @@ int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
 /* Copy only the parts of these structs known to us at compiler-time. */
 #define COPY(t, a, b, last) memcpy(a, b, offsetof(t, last) + sizeof((b)->last))
 COPY(AVDOVIRpuDataHeader, av_dovi_get_header(dovi), >header, 
disable_residual_flag);
-COPY(AVDOVIDataMapping, av_dovi_get_mapping(dovi), s->mapping, 
nlq[2].linear_deadzone_threshold);
+COPY(AVDOVIDataMapping, av_dovi_get_mapping(dovi), s->mapping, nlq_pivots);
 COPY(AVDOVIColorMetadata, av_dovi_get_color(dovi), s->color, 
source_diagonal);
 return 0;
 }
@@ -346,7 +346,14 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 }
 
 if (use_nlq) {
+int nlq_pivot = 0;
 vdr->mapping.nlq_method_idc = get_bits(gb, 3);
+
+for (int i = 0; i < 2; i++) {
+nlq_pivot += get_bits(gb, hdr->bl_bit_depth);
+vdr->mapping.nlq_pivots[i] = av_clip_uint16(nlq_pivot);
+}
+
 /**
  * The patent mentions another legal value, NLQ_MU_LAW, but it's
  * not documented anywhere how to parse or apply that type of NLQ.
diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
index 3d11e02bffc..46b13b33995 100644
--- a/libavutil/dovi_meta.h
+++ b/libavutil/dovi_meta.h
@@ -147,6 +147,7 @@ typedef struct AVDOVIDataMapping {
 uint32_t num_x_partitions;
 uint32_t num_y_partitions;
 AVDOVINLQParams nlq[3]; /* per component */
+uint16_t nlq_pivots[2];
 } AVDOVIDataMapping;
 
 /**
diff --git a/libavutil/version.h b/libavutil/version.h
index 445102073fc..80e6aacd0fa 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR   6
+#define LIBAVUTIL_VERSION_MINOR   7
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.44.0

___
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 0/8] Dolby Vision extension block parsing

2024-03-23 Thread Niklas Haas
Changes since v1:
- Rebased onto master
- Dropped av_dovi_metadata_alloc_ext(), instead statically allocate
  space for 32 extension blocks (AV_DOVI_MAX_EXT_BLOCKS)
- Removed misleading comment on nlq_pivots
- Fix memory leak on ff_dovi_ctx_flush()
- Switch to using ff_refstruct to properly manage ext_block lifetime
- Properly attach parsed extension blocks to the frame side data
- Avoid UB on get_cie_xy
- Validate num_ext_blocks
- Added commit fixing incorrect return code on invalid data
- Removed redundant extra init_get_bits8
- Reorderd fields to avoid unnecessary padding

___
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] libavformat\file:Fix duplicate JNI symbols

2024-03-23 Thread admin
From: 联盟少侠 

The errors indicate that there are multiple definitions of several JNI (Java 
Native Interface) symbols in the FFmpeg library. Specifically, the linker 
ld.lld has found duplicate definitions for the following symbols:

- ff_jni_get_env
- ff_jni_jstring_to_utf_chars
- ff_jni_utf_chars_to_jstring
- ff_jni_exception_get_summary
- ff_jni_exception_check
- ff_jni_init_jfields
- ff_jni_reset_jfields

These symbols are defined in both libavcodec.a and libavformat.a archives, 
leading to conflicts during the linking process. The duplicates are found in 
the same source file ffjni.c, but they are being compiled into two different 
static libraries.

To resolve these errors, ensure that each symbol is defined only once across 
all linked libraries, or if these symbols are required in both libraries, they 
should be marked as weak symbols to allow the linker to handle them 
appropriately. Additionally, check for any build script misconfigurations that 
may be causing the same file to be included in multiple libraries.
---
 libavformat/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/file.c b/libavformat/file.c
index dd5819c..fa13ae9 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -43,7 +43,7 @@
 #if CONFIG_ANDROID_CONTENT_PROTOCOL
 #include 
 #include "libavcodec/jni.h"
-#include "libavcodec/ffjni.c"
+#include "libavcodec/ffjni.h"
 #endif
 
 
-- 
2.41.0.windows.3

___
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".


Re: [FFmpeg-devel] [PATCH 2/6] avutil/dovi_meta: add dolby vision extension blocks

2024-03-23 Thread Niklas Haas
On Sat, 23 Mar 2024 19:08:04 +0100 Niklas Haas  wrote:
> On Sat, 23 Mar 2024 18:58:51 +0100 Andreas Rheinhardt 
>  wrote:
> > Niklas Haas:
> > > From: Niklas Haas 
> > > 
> > > As well as accessors plus a function for allocating this struct with
> > > extension blocks,
> > > 
> > > Definitions generously taken from quietvoid/dovi_tool, which is
> > > assembled as a collection of various patent fragments, as well as output
> > > by the official Dolby Vision bitstream verifier tool.
> > > ---
> > >  doc/APIchanges|   5 ++
> > >  libavutil/dovi_meta.c |  36 --
> > >  libavutil/dovi_meta.h | 154 ++
> > >  libavutil/version.h   |   2 +-
> > >  4 files changed, 190 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/doc/APIchanges b/doc/APIchanges
> > > index 739f33501e9..8b59150dc1f 100644
> > > --- a/doc/APIchanges
> > > +++ b/doc/APIchanges
> > > @@ -2,6 +2,11 @@ The last version increases of all libraries were on 
> > > 2024-03-07
> > >  
> > >  API changes, most recent first:
> > >  
> > > +2024-03-xx - xx - lavu 59.6.100 - dovi_meta.h
> > > +  Add AVDOVIMetadata.ext_block_{offset,size}, 
> > > AVDOVIMetadata.num_ext_blocks,
> > > +  AVDOVIDmData and AVDOVIDmLevel{1..6,8..11,254..255}, av_dovi_get_ext(),
> > > +  av_dovi_find_level() and av_dovi_metadata_alloc_ext(),
> > > +
> > >  2024-03-xx - xx - lavu 59.5.100 - dovi_meta.h
> > >Add AVDOVIDataMapping.nlq_pivots.
> > >  
> > > diff --git a/libavutil/dovi_meta.c b/libavutil/dovi_meta.c
> > > index 9c50da561ed..17e18bf95f9 100644
> > > --- a/libavutil/dovi_meta.c
> > > +++ b/libavutil/dovi_meta.c
> > > @@ -18,6 +18,8 @@
> > >   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
> > > 02110-1301 USA
> > >   */
> > >  
> > > +#include 
> > > +
> > >  #include "dovi_meta.h"
> > >  #include "mem.h"
> > >  
> > > @@ -39,22 +41,44 @@ typedef struct AVDOVIMetadataInternal {
> > >  AVDOVIRpuDataHeader header;
> > >  AVDOVIDataMapping mapping;
> > >  AVDOVIColorMetadata color;
> > > +AVDOVIDmData ext_blocks[];
> > >  } AVDOVIMetadataInternal;
> > >  
> > > -AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
> > > +AVDOVIMetadata *av_dovi_metadata_alloc_ext(int num_ext_blocks, size_t 
> > > *size)
> > >  {
> > > -AVDOVIMetadataInternal *dovi = 
> > > av_mallocz(sizeof(AVDOVIMetadataInternal));
> > > +const size_t alloc_size = sizeof(AVDOVIMetadataInternal) +
> > > +  num_ext_blocks * sizeof(AVDOVIDmData);
> > > +
> > > +AVDOVIMetadataInternal *dovi = av_mallocz(alloc_size);
> > >  if (!dovi)
> > >  return NULL;
> > >  
> > >  if (size)
> > > -*size = sizeof(*dovi);
> > > +*size = alloc_size;
> > >  
> > >  dovi->metadata = (struct AVDOVIMetadata) {
> > > -.header_offset  = offsetof(AVDOVIMetadataInternal, header),
> > > -.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
> > > -.color_offset   = offsetof(AVDOVIMetadataInternal, color),
> > > +.header_offset  = offsetof(AVDOVIMetadataInternal, header),
> > > +.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
> > > +.color_offset   = offsetof(AVDOVIMetadataInternal, color),
> > > +.ext_block_offset   = offsetof(AVDOVIMetadataInternal, 
> > > ext_blocks),
> > > +.ext_block_size = sizeof(AVDOVIDmData),
> > >  };
> > >  
> > >  return >metadata;
> > >  }
> > > +
> > > +AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
> > > +{
> > > +return av_dovi_metadata_alloc_ext(0, size);
> > > +}
> > > +
> > > +AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t 
> > > level)
> > > +{
> > > +for (int i = 0; i < data->num_ext_blocks; i++) {
> > > +AVDOVIDmData *ext = av_dovi_get_ext(data, i);
> > > +if (ext->level == level)
> > > +return ext;
> > > +}
> > > +
> > > +return NULL;
> > > +}
> > > diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
> > > index 6afc7b055a7..e77d9853f67 100644
> > > --- a/libavutil/dovi_meta.h
> > > +++ b/libavutil/dovi_meta.h
> > > @@ -29,7 +29,9 @@
> > >  
> > >  #include 
> > >  #include 
> > > +
> > >  #include "rational.h"
> > > +#include "csp.h"
> > >  
> > >  /*
> > >   * DOVI configuration
> > > @@ -187,6 +189,130 @@ typedef struct AVDOVIColorMetadata {
> > >  uint16_t source_diagonal;
> > >  } AVDOVIColorMetadata;
> > >  
> > > +typedef struct AVDOVIDmLevel1 {
> > > +/* Per-frame brightness metadata */
> > > +uint16_t min_pq;
> > > +uint16_t max_pq;
> > > +uint16_t avg_pq;
> > > +} AVDOVIDmLevel1;
> > > +
> > > +typedef struct AVDOVIDmLevel2 {
> > > +/* Usually derived from level 8 (at different levels) */
> > > +uint16_t target_max_pq;
> > > +uint16_t trim_slope;
> > > +uint16_t trim_offset;
> > > +uint16_t trim_power;
> > > +uint16_t trim_chroma_weight;
> > > +uint16_t 

Re: [FFmpeg-devel] [PATCH 6/6] avcodec/dovi_rpu: parse extension blocks

2024-03-23 Thread Niklas Haas
On Sat, 23 Mar 2024 19:00:59 +0100 Andreas Rheinhardt 
 wrote:
> Niklas Haas:
> > From: Niklas Haas 
> > 
> > We split the inner loop between v1 and v2 extension blocks to print
> > a warning where an extension block was encountered in an unexpected
> > context.
> > 
> > Co-authored-by: quietvoid 
> > ---
> >  libavcodec/dovi_rpu.c | 178 ++
> >  1 file changed, 178 insertions(+)
> > 
> > diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
> > index 21cb1850e3e..99a983f65dd 100644
> > --- a/libavcodec/dovi_rpu.c
> > +++ b/libavcodec/dovi_rpu.c
> > @@ -199,6 +199,174 @@ static inline unsigned 
> > get_variable_bits(GetBitContext *gb, int n)
> >  }  
> >  \
> >  } while (0)
> >  
> > +static void parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData 
> > *dm)
> > +{
> > +switch (dm->level) {
> > +case 1:
> > +dm->l1.min_pq = get_bits(gb, 12);
> > +dm->l1.max_pq = get_bits(gb, 12);
> > +dm->l1.avg_pq = get_bits(gb, 12);
> > +break;
> > +case 2:
> > +dm->l2.target_max_pq = get_bits(gb, 12);
> > +dm->l2.trim_slope = get_bits(gb, 12);
> > +dm->l2.trim_offset = get_bits(gb, 12);
> > +dm->l2.trim_power = get_bits(gb, 12);
> > +dm->l2.trim_chroma_weight = get_bits(gb, 12);
> > +dm->l2.trim_saturation_gain = get_bits(gb, 12);
> > +dm->l2.ms_weight = get_bits(gb, 13) - 8192;
> > +break;
> > +case 4:
> > +dm->l4.anchor_pq = get_bits(gb, 12);
> > +dm->l4.anchor_power = get_bits(gb, 12);
> > +break;
> > +case 5:
> > +dm->l5.left_offset = get_bits(gb, 13);
> > +dm->l5.right_offset = get_bits(gb, 13);
> > +dm->l5.top_offset = get_bits(gb, 13);
> > +dm->l5.bottom_offset = get_bits(gb, 13);
> > +break;
> > +case 6:
> > +dm->l6.max_luminance = get_bits(gb, 16);
> > +dm->l6.min_luminance = get_bits(gb, 16);
> > +dm->l6.max_cll = get_bits(gb, 16);
> > +dm->l6.max_fall = get_bits(gb, 16);
> > +break;
> > +case 255:
> > +dm->l255.dm_run_mode = get_bits(gb, 8);
> > +dm->l255.dm_run_version = get_bits(gb, 8);
> > +for (int i = 0; i < 4; i++)
> > +dm->l255.dm_debug[i] = get_bits(gb, 8);
> > +break;
> > +default:
> > +av_log(s->logctx, AV_LOG_WARNING,
> > +   "Unknown Dolby Vision DM v1 level: %u\n", dm->level);
> > +}
> > +}
> > +
> > +static inline AVCIExy get_cie_xy(GetBitContext *gb)
> > +{
> > +const int denom = 32767;
> > +return (AVCIExy) {
> > +.x = { get_sbits(gb, 16), denom },
> > +.y = { get_sbits(gb, 16), denom },
> > +};
> 
> The order of initializations is undefined.

Fixed.

> > +}
> > +
> > +static void parse_ext_v2(DOVIContext *s, GetBitContext *gb, AVDOVIDmData 
> > *dm,
> > + int ext_block_length)
> > +{
> > +switch (dm->level) {
> > +case 3:
> > +dm->l3.min_pq_offset = get_bits(gb, 12);
> > +dm->l3.max_pq_offset = get_bits(gb, 12);
> > +dm->l3.avg_pq_offset = get_bits(gb, 12);
> > +break;
> > +case 8:
> > +dm->l8.target_display_index = get_bits(gb, 8);
> > +dm->l8.trim_slope = get_bits(gb, 12);
> > +dm->l8.trim_offset = get_bits(gb, 12);
> > +dm->l8.trim_power = get_bits(gb, 12);
> > +dm->l8.trim_chroma_weight = get_bits(gb, 12);
> > +dm->l8.trim_saturation_gain = get_bits(gb, 12);
> > +dm->l8.ms_weight = get_bits(gb, 12) - 8192;
> > +if (ext_block_length < 12)
> > +break;
> > +dm->l8.target_mid_contrast = get_bits(gb, 12);
> > +if (ext_block_length < 13)
> > +break;
> > +dm->l8.clip_trim = get_bits(gb, 12);
> > +if (ext_block_length < 19)
> > +break;
> > +for (int i = 0; i < 6; i++)
> > +dm->l8.saturation_vector_field[i] = get_bits(gb, 8);
> > +if (ext_block_length < 25)
> > +break;
> > +for (int i = 0; i < 6; i++)
> > +dm->l8.hue_vector_field[i] = get_bits(gb, 8);
> > +break;
> > +case 9:
> > +dm->l9.source_primary_index = get_bits(gb, 8);
> > +if (ext_block_length < 17)
> > +break;
> > +dm->l9.source_display_primaries.prim.r = get_cie_xy(gb);
> > +dm->l9.source_display_primaries.prim.g = get_cie_xy(gb);
> > +dm->l9.source_display_primaries.prim.b = get_cie_xy(gb);
> > +dm->l9.source_display_primaries.wp = get_cie_xy(gb);
> > +break;
> > +case 10:
> > +dm->l10.target_display_index = get_bits(gb, 8);
> > +dm->l10.target_max_pq = get_bits(gb, 12);
> > +dm->l10.target_min_pq = get_bits(gb, 12);
> > +dm->l10.target_primary_index = get_bits(gb, 8);
> > +if (ext_block_length < 21)
> > +  

Re: [FFmpeg-devel] [PATCH 2/6] avutil/dovi_meta: add dolby vision extension blocks

2024-03-23 Thread Niklas Haas
On Sat, 23 Mar 2024 18:58:51 +0100 Andreas Rheinhardt 
 wrote:
> Niklas Haas:
> > From: Niklas Haas 
> > 
> > As well as accessors plus a function for allocating this struct with
> > extension blocks,
> > 
> > Definitions generously taken from quietvoid/dovi_tool, which is
> > assembled as a collection of various patent fragments, as well as output
> > by the official Dolby Vision bitstream verifier tool.
> > ---
> >  doc/APIchanges|   5 ++
> >  libavutil/dovi_meta.c |  36 --
> >  libavutil/dovi_meta.h | 154 ++
> >  libavutil/version.h   |   2 +-
> >  4 files changed, 190 insertions(+), 7 deletions(-)
> > 
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 739f33501e9..8b59150dc1f 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -2,6 +2,11 @@ The last version increases of all libraries were on 
> > 2024-03-07
> >  
> >  API changes, most recent first:
> >  
> > +2024-03-xx - xx - lavu 59.6.100 - dovi_meta.h
> > +  Add AVDOVIMetadata.ext_block_{offset,size}, 
> > AVDOVIMetadata.num_ext_blocks,
> > +  AVDOVIDmData and AVDOVIDmLevel{1..6,8..11,254..255}, av_dovi_get_ext(),
> > +  av_dovi_find_level() and av_dovi_metadata_alloc_ext(),
> > +
> >  2024-03-xx - xx - lavu 59.5.100 - dovi_meta.h
> >Add AVDOVIDataMapping.nlq_pivots.
> >  
> > diff --git a/libavutil/dovi_meta.c b/libavutil/dovi_meta.c
> > index 9c50da561ed..17e18bf95f9 100644
> > --- a/libavutil/dovi_meta.c
> > +++ b/libavutil/dovi_meta.c
> > @@ -18,6 +18,8 @@
> >   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
> > 02110-1301 USA
> >   */
> >  
> > +#include 
> > +
> >  #include "dovi_meta.h"
> >  #include "mem.h"
> >  
> > @@ -39,22 +41,44 @@ typedef struct AVDOVIMetadataInternal {
> >  AVDOVIRpuDataHeader header;
> >  AVDOVIDataMapping mapping;
> >  AVDOVIColorMetadata color;
> > +AVDOVIDmData ext_blocks[];
> >  } AVDOVIMetadataInternal;
> >  
> > -AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
> > +AVDOVIMetadata *av_dovi_metadata_alloc_ext(int num_ext_blocks, size_t 
> > *size)
> >  {
> > -AVDOVIMetadataInternal *dovi = 
> > av_mallocz(sizeof(AVDOVIMetadataInternal));
> > +const size_t alloc_size = sizeof(AVDOVIMetadataInternal) +
> > +  num_ext_blocks * sizeof(AVDOVIDmData);
> > +
> > +AVDOVIMetadataInternal *dovi = av_mallocz(alloc_size);
> >  if (!dovi)
> >  return NULL;
> >  
> >  if (size)
> > -*size = sizeof(*dovi);
> > +*size = alloc_size;
> >  
> >  dovi->metadata = (struct AVDOVIMetadata) {
> > -.header_offset  = offsetof(AVDOVIMetadataInternal, header),
> > -.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
> > -.color_offset   = offsetof(AVDOVIMetadataInternal, color),
> > +.header_offset  = offsetof(AVDOVIMetadataInternal, header),
> > +.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
> > +.color_offset   = offsetof(AVDOVIMetadataInternal, color),
> > +.ext_block_offset   = offsetof(AVDOVIMetadataInternal, ext_blocks),
> > +.ext_block_size = sizeof(AVDOVIDmData),
> >  };
> >  
> >  return >metadata;
> >  }
> > +
> > +AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
> > +{
> > +return av_dovi_metadata_alloc_ext(0, size);
> > +}
> > +
> > +AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level)
> > +{
> > +for (int i = 0; i < data->num_ext_blocks; i++) {
> > +AVDOVIDmData *ext = av_dovi_get_ext(data, i);
> > +if (ext->level == level)
> > +return ext;
> > +}
> > +
> > +return NULL;
> > +}
> > diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
> > index 6afc7b055a7..e77d9853f67 100644
> > --- a/libavutil/dovi_meta.h
> > +++ b/libavutil/dovi_meta.h
> > @@ -29,7 +29,9 @@
> >  
> >  #include 
> >  #include 
> > +
> >  #include "rational.h"
> > +#include "csp.h"
> >  
> >  /*
> >   * DOVI configuration
> > @@ -187,6 +189,130 @@ typedef struct AVDOVIColorMetadata {
> >  uint16_t source_diagonal;
> >  } AVDOVIColorMetadata;
> >  
> > +typedef struct AVDOVIDmLevel1 {
> > +/* Per-frame brightness metadata */
> > +uint16_t min_pq;
> > +uint16_t max_pq;
> > +uint16_t avg_pq;
> > +} AVDOVIDmLevel1;
> > +
> > +typedef struct AVDOVIDmLevel2 {
> > +/* Usually derived from level 8 (at different levels) */
> > +uint16_t target_max_pq;
> > +uint16_t trim_slope;
> > +uint16_t trim_offset;
> > +uint16_t trim_power;
> > +uint16_t trim_chroma_weight;
> > +uint16_t trim_saturation_gain;
> > +int16_t ms_weight;
> > +} AVDOVIDmLevel2;
> > +
> > +typedef struct AVDOVIDmLevel3 {
> > +uint16_t min_pq_offset;
> > +uint16_t max_pq_offset;
> > +uint16_t avg_pq_offset;
> > +} AVDOVIDmLevel3;
> > +
> > +typedef struct AVDOVIDmLevel4 {
> > +uint16_t anchor_pq;
> > +uint16_t anchor_power;
> > +} 

Re: [FFmpeg-devel] [PATCH 3/6] avcodec/dovi_rpu: strip container in separate step

2024-03-23 Thread Niklas Haas
On Sat, 23 Mar 2024 19:02:26 +0100 Andreas Rheinhardt 
 wrote:
> Niklas Haas:
> > From: Niklas Haas 
> > 
> > This ensures that `gb` in the following section is fully byte-aligned,
> > points at the start of the actual RPU, and ends on the CRC terminator.
> > 
> > This is important for both calculation of the CRC, as well as dovi
> > extension block parsing (which aligns to byte boundaries in various
> > places).
> > ---
> >  libavcodec/dovi_rpu.c | 48 +++
> >  libavcodec/dovi_rpu.h |  2 ++
> >  2 files changed, 41 insertions(+), 9 deletions(-)
> > 
> > diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
> > index c84a942f476..24a1cdf39a8 100644
> > --- a/libavcodec/dovi_rpu.c
> > +++ b/libavcodec/dovi_rpu.c
> > @@ -23,6 +23,7 @@
> >  
> >  #include "libavutil/buffer.h"
> >  
> > +#include "avcodec.h"
> 
> What is that used for?

av_fast_padded_malloc

> 
> >  #include "dovi_rpu.h"
> >  #include "golomb.h"
> >  #include "get_bits.h"
> > @@ -45,6 +46,7 @@ void ff_dovi_ctx_unref(DOVIContext *s)
> >  {
> >  for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
> >  ff_refstruct_unref(>vdr[i]);
> > +av_free(s->rpu_buf);
> >  
> >  *s = (DOVIContext) {
> >  .logctx = s->logctx,
> > @@ -202,17 +204,17 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t 
> > *rpu, size_t rpu_size)
> >  DOVIVdr *vdr;
> >  int ret;
> >  
> > -uint8_t nal_prefix;
> >  uint8_t rpu_type;
> >  uint8_t vdr_seq_info_present;
> >  uint8_t vdr_dm_metadata_present;
> >  uint8_t use_prev_vdr_rpu;
> >  uint8_t use_nlq;
> >  uint8_t profile;
> > -if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
> > -return ret;
> >  
> > -/* Container header */
> > +if (rpu_size < 5)
> > +goto fail;
> > +
> > +/* Container */
> >  if (s->dv_profile == 10 /* dav1.10 */) {
> >  /* DV inside AV1 re-uses an EMDF container skeleton, but with fixed
> >   * values - so we can effectively treat this as a magic byte 
> > sequence.
> > @@ -229,18 +231,46 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t 
> > *rpu, size_t rpu_size)
> >   *   discard_unknown_payload : f(1) = 1
> >   */
> >  const unsigned header_magic = 0x01be6841u;
> > -unsigned header, emdf_payload_size;
> > -header = get_bits_long(gb, 27);
> > -VALIDATE(header, header_magic, header_magic);
> > +unsigned emdf_header, emdf_payload_size, emdf_protection;
> > +if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
> > +return ret;
> > +emdf_header = get_bits_long(gb, 27);
> > +VALIDATE(emdf_header, header_magic, header_magic);
> >  emdf_payload_size = get_variable_bits(gb, 8);
> >  VALIDATE(emdf_payload_size, 6, 512);
> >  if (emdf_payload_size * 8 > get_bits_left(gb))
> >  return AVERROR_INVALIDDATA;
> > +
> > +/* The payload is not byte-aligned (off by *one* bit, curse Dolby),
> > + * so copy into a fresh buffer to preserve byte alignment of the
> > + * RPU struct */
> > +av_fast_padded_malloc(>rpu_buf, >rpu_buf_sz, 
> > emdf_payload_size);
> > +if (!s->rpu_buf)
> > +return AVERROR(ENOMEM);
> > +for (int i = 0; i < emdf_payload_size; i++)
> > +s->rpu_buf[i] = get_bits(gb, 8);
> > +rpu = s->rpu_buf;
> > +rpu_size = emdf_payload_size;
> > +
> > +/* Validate EMDF footer */
> > +emdf_protection = get_bits(gb, 5 + 12);
> > +VALIDATE(emdf_protection, 0x400, 0x400);
> > +
> > +if ((ret = init_get_bits8(gb, s->rpu_buf, emdf_payload_size)) < 0)
> > +return ret;
> >  } else {
> > -nal_prefix = get_bits(gb, 8);
> > -VALIDATE(nal_prefix, 25, 25);
> > +/* NAL RBSP with prefix and trailing zeroes */
> > +VALIDATE(rpu[0], 25, 25); /* NAL prefix */
> > +rpu++;
> > +rpu_size--;
> > +/* Strip trailing padding bytes */
> > +while (rpu_size && rpu[rpu_size - 1] == 0)
> > +rpu_size--;
> >  }
> >  
> > +if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
> > +return ret;
> > +
> >  /* RPU header */
> >  rpu_type = get_bits(gb, 6);
> >  if (rpu_type != 2) {
> > diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
> > index 51c5fdbb879..506974a74bf 100644
> > --- a/libavcodec/dovi_rpu.h
> > +++ b/libavcodec/dovi_rpu.h
> > @@ -49,6 +49,8 @@ typedef struct DOVIContext {
> >   */
> >  struct DOVIVdr *vdr[DOVI_MAX_DM_ID+1]; ///< RefStruct references
> >  uint8_t dv_profile;
> > +uint8_t *rpu_buf; ///< temporary buffer
> > +unsigned rpu_buf_sz;
> 
> The order here introduces unnecessary padding.

Fixed.

> 
> >  
> >  } DOVIContext;
> >  
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> 

Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add YUV color space metadata to AVCodec

2024-03-23 Thread Niklas Haas
On Fri, 09 Feb 2024 13:11:38 +0100 Niklas Haas  wrote:
> On Mon, 05 Feb 2024 19:04:30 +0100 Andreas Rheinhardt 
>  wrote:
> > This presumes the relevant states to be a cartesian product. Which need
> > not be true. A callback would be better; this would also allow to base
> > the list on other values already set in an AVCodecContext. And if this
> > were extended, it would also allow to remove init_static_data one day.
> > It is furthermore quite wasteful to store color_ranges in a list,
> > although there are only very few states for it.
> 
> There is also the consideration to be made that using a callback is
> inconsistent with the established design. Consider that framerates,
> pix_fmts, samplerates, sample fmts and channel layouts are all currently
> provided as static arrays in AVCodec. There is a natural symmetry
> between these items and the ones I intend to add (yuv matrix, range,
> chroma location, primaries and gamma) - all of them are descriptive of
> the way data is encoded, and are therefore also (or should be)
> negotiable filter link properties.
> 
> If we add a new callback API, should we then extend it to also include
> all of the existing items from the above list? Is there a reason that
> yuv range supports needs to be more dynamic than the others?
> 
> Food for thought: mjpeg is not the only codec that puts restrictions on
> the format support based on the strictness level. For example,
> yuv4mpegpipe_muxer errors out with a strictness warning if you use
> a non-standard pixel format. And arguably, in this case, this is
> **preferred** behavior over "silently" inserting a scale filter to
> convert to a supported format, as the whole point of y4m2 is to
> encapsulate raw data as-is.
> 
> Should we:
> 
> 1. Add a new dynamic callback that can query lists for all of the above
>in a way dependent on the strictness level, and use it as
>a replacement for the static lists currently in AVCodec?
> 
> 2. Continue with the status quo of having these lists be static, plus
>dynamic checks at open() time, and continue using the "convenience
>hack" of having ffmpeg_tools automatically restrict limited range mjpeg?
> 
> It is not immediately obvious to me that an automatic conversion to
> a supported format is *necessarily* preferred to erroring out unless the
> user specifies a lower strictness level.
> 
> As for an API, I think that rather than having an AVCodecContext-aware
> callback at all, I would just make callbacks that directly ingest the
> strictness level in AVCodec. That makes it far less of a black box about
> which fields of the AVCodecContext are relevant here.
> 
> i.e.
> 
> struct AVCodec {
> const enum AVColorRange (*get_color_ranges)(int strictness);
> const enum AVColorSpace (*get_color_spaces)(int strictness);
> // ditto for the other parameters?
> }

Ping for review?
___
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".


Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_scale2ref: switch to FFFrameSync

2024-03-23 Thread Niklas Haas
On Wed, 20 Mar 2024 20:55:26 +0100 Michael Niedermayer  
wrote:
> On Wed, Mar 20, 2024 at 03:23:53PM +0100, Niklas Haas wrote:
> > On Tue, 19 Mar 2024 22:55:56 +0100 Michael Niedermayer 
> >  wrote:
> > > is it neccessary to drop compatibility to the old syntax ?
> > 
> > Only if we want to use framesync. If we don't care about synchronizing
> > the streams, then we could drop FS and just use a custom activate
> > function which forwards output status only to the *corresponding* input.
> 
> if the full bugfix cant be done in the same filter then i guess we need a 2nd
> filter, maybe scale1ref

I think we can do this by extending vf_scale itself to support taking
a second input, that way we don't need a second filter at all.

My proposal for this:
- Add new variables ref_w, ref_h (and related fields), possibly aliased
  to 'rw' and 'rh'.
- When `ref_*` is referenced in any expression, vf_scale will init()
  with a second input stream.
- Semantics will be equivalent to this patch.
- Fully deprecate scale2ref, and eventually remove it and the main_*
  series of variables.

That way, scale2ref just becomes `scale=w=rw:h=rh`, and also allows us
to simplify these filters a bit.
___
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".


Re: [FFmpeg-devel] [PATCH 1/4] fftools/ffmpeg_enc: strip DOVI config record for AV1

2024-03-23 Thread Niklas Haas
On Tue, 19 Mar 2024 20:16:39 +0100 Niklas Haas  wrote:
> From: Niklas Haas 
> 
> AV1 streams don't use configuration records, so delete them when
> encoding to AV1. Ideally this would be, as the comment suggests, handled
> at the frame-level (and stripped by the av1 encoder), but given the
> status quo of copying the packet-level data here directly, we should
> definitely make an effort to strip it.

I decided to abandon this series in favor of synthesizing the RPU fully
from the parsed AVDOVIMetadata side data. I have a series for this
prepared and mostly ready, will submit it sometime in the next week.

That series also includes a new option to avoid sending RPU data when
dolby vision is not enabled.
___
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 6/6] avcodec/dovi_rpu: parse extension blocks

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

We split the inner loop between v1 and v2 extension blocks to print
a warning where an extension block was encountered in an unexpected
context.

Co-authored-by: quietvoid 
---
 libavcodec/dovi_rpu.c | 178 ++
 1 file changed, 178 insertions(+)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 21cb1850e3e..99a983f65dd 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -199,6 +199,174 @@ static inline unsigned get_variable_bits(GetBitContext 
*gb, int n)
 }  
 \
 } while (0)
 
+static void parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm)
+{
+switch (dm->level) {
+case 1:
+dm->l1.min_pq = get_bits(gb, 12);
+dm->l1.max_pq = get_bits(gb, 12);
+dm->l1.avg_pq = get_bits(gb, 12);
+break;
+case 2:
+dm->l2.target_max_pq = get_bits(gb, 12);
+dm->l2.trim_slope = get_bits(gb, 12);
+dm->l2.trim_offset = get_bits(gb, 12);
+dm->l2.trim_power = get_bits(gb, 12);
+dm->l2.trim_chroma_weight = get_bits(gb, 12);
+dm->l2.trim_saturation_gain = get_bits(gb, 12);
+dm->l2.ms_weight = get_bits(gb, 13) - 8192;
+break;
+case 4:
+dm->l4.anchor_pq = get_bits(gb, 12);
+dm->l4.anchor_power = get_bits(gb, 12);
+break;
+case 5:
+dm->l5.left_offset = get_bits(gb, 13);
+dm->l5.right_offset = get_bits(gb, 13);
+dm->l5.top_offset = get_bits(gb, 13);
+dm->l5.bottom_offset = get_bits(gb, 13);
+break;
+case 6:
+dm->l6.max_luminance = get_bits(gb, 16);
+dm->l6.min_luminance = get_bits(gb, 16);
+dm->l6.max_cll = get_bits(gb, 16);
+dm->l6.max_fall = get_bits(gb, 16);
+break;
+case 255:
+dm->l255.dm_run_mode = get_bits(gb, 8);
+dm->l255.dm_run_version = get_bits(gb, 8);
+for (int i = 0; i < 4; i++)
+dm->l255.dm_debug[i] = get_bits(gb, 8);
+break;
+default:
+av_log(s->logctx, AV_LOG_WARNING,
+   "Unknown Dolby Vision DM v1 level: %u\n", dm->level);
+}
+}
+
+static inline AVCIExy get_cie_xy(GetBitContext *gb)
+{
+const int denom = 32767;
+return (AVCIExy) {
+.x = { get_sbits(gb, 16), denom },
+.y = { get_sbits(gb, 16), denom },
+};
+}
+
+static void parse_ext_v2(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm,
+ int ext_block_length)
+{
+switch (dm->level) {
+case 3:
+dm->l3.min_pq_offset = get_bits(gb, 12);
+dm->l3.max_pq_offset = get_bits(gb, 12);
+dm->l3.avg_pq_offset = get_bits(gb, 12);
+break;
+case 8:
+dm->l8.target_display_index = get_bits(gb, 8);
+dm->l8.trim_slope = get_bits(gb, 12);
+dm->l8.trim_offset = get_bits(gb, 12);
+dm->l8.trim_power = get_bits(gb, 12);
+dm->l8.trim_chroma_weight = get_bits(gb, 12);
+dm->l8.trim_saturation_gain = get_bits(gb, 12);
+dm->l8.ms_weight = get_bits(gb, 12) - 8192;
+if (ext_block_length < 12)
+break;
+dm->l8.target_mid_contrast = get_bits(gb, 12);
+if (ext_block_length < 13)
+break;
+dm->l8.clip_trim = get_bits(gb, 12);
+if (ext_block_length < 19)
+break;
+for (int i = 0; i < 6; i++)
+dm->l8.saturation_vector_field[i] = get_bits(gb, 8);
+if (ext_block_length < 25)
+break;
+for (int i = 0; i < 6; i++)
+dm->l8.hue_vector_field[i] = get_bits(gb, 8);
+break;
+case 9:
+dm->l9.source_primary_index = get_bits(gb, 8);
+if (ext_block_length < 17)
+break;
+dm->l9.source_display_primaries.prim.r = get_cie_xy(gb);
+dm->l9.source_display_primaries.prim.g = get_cie_xy(gb);
+dm->l9.source_display_primaries.prim.b = get_cie_xy(gb);
+dm->l9.source_display_primaries.wp = get_cie_xy(gb);
+break;
+case 10:
+dm->l10.target_display_index = get_bits(gb, 8);
+dm->l10.target_max_pq = get_bits(gb, 12);
+dm->l10.target_min_pq = get_bits(gb, 12);
+dm->l10.target_primary_index = get_bits(gb, 8);
+if (ext_block_length < 21)
+break;
+dm->l10.target_display_primaries.prim.r = get_cie_xy(gb);
+dm->l10.target_display_primaries.prim.g = get_cie_xy(gb);
+dm->l10.target_display_primaries.prim.b = get_cie_xy(gb);
+dm->l10.target_display_primaries.wp = get_cie_xy(gb);
+break;
+case 11:
+dm->l11.content_type = get_bits(gb, 8);
+dm->l11.whitepoint = get_bits(gb, 4);
+dm->l11.reference_mode_flag = get_bits(gb, 1);
+skip_bits(gb, 3); /* reserved */
+dm->l11.sharpness = get_bits(gb, 2);
+dm->l11.noise_reduction = get_bits(gb, 2);
+

[FFmpeg-devel] [PATCH 5/6] avcodec/dovi_rpu: add ext_blocks array to DOVIContext

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

---
 libavcodec/dovi_rpu.c | 1 +
 libavcodec/dovi_rpu.h | 7 +++
 2 files changed, 8 insertions(+)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index cd54c8716dc..21cb1850e3e 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -48,6 +48,7 @@ void ff_dovi_ctx_unref(DOVIContext *s)
 for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
 ff_refstruct_unref(>vdr[i]);
 av_free(s->rpu_buf);
+av_free(s->ext_blocks);
 
 *s = (DOVIContext) {
 .logctx = s->logctx,
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index f88fbf9b558..c632a83f46b 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -44,6 +44,12 @@ typedef struct DOVIContext {
 const AVDOVIDataMapping *mapping;
 const AVDOVIColorMetadata *color;
 
+/**
+ * Currently active extension blocks, updates on every ff_dovi_rpu_parse()
+ */
+AVDOVIDmData *ext_blocks;
+int num_ext_blocks;
+
 /**
  * Private fields internal to dovi_rpu.c
  */
@@ -51,6 +57,7 @@ typedef struct DOVIContext {
 uint8_t dv_profile;
 uint8_t *rpu_buf; ///< temporary buffer
 unsigned rpu_buf_sz;
+unsigned ext_blocks_sz;
 
 } DOVIContext;
 
-- 
2.44.0

___
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/6] avutil/dovi_meta: add AVDOVIDataMapping.nlq_pivots

2024-03-23 Thread Niklas Haas
From: quietvoid 

The NLQ pivots are not documented but should be present in the header
for profile 7 RPU format. It has been verified using Dolby's
verification toolkit.

Signed-off-by: quietvoid 
Signed-off-by: Niklas Haas 
---
 doc/APIchanges| 3 +++
 libavcodec/dovi_rpu.c | 9 -
 libavutil/dovi_meta.h | 1 +
 libavutil/version.h   | 2 +-
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 2796b4d0c25..739f33501e9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-03-xx - xx - lavu 59.5.100 - dovi_meta.h
+  Add AVDOVIDataMapping.nlq_pivots.
+
 2024-03-xx - xx - lavc 61.3.100 - jni.h
   Add av_jni_set_android_app_ctx() and av_jni_get_android_app_ctx().
 
diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 31c64fb0602..c84a942f476 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -109,7 +109,7 @@ int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
 /* Copy only the parts of these structs known to us at compiler-time. */
 #define COPY(t, a, b, last) memcpy(a, b, offsetof(t, last) + sizeof((b)->last))
 COPY(AVDOVIRpuDataHeader, av_dovi_get_header(dovi), >header, 
disable_residual_flag);
-COPY(AVDOVIDataMapping, av_dovi_get_mapping(dovi), s->mapping, 
nlq[2].linear_deadzone_threshold);
+COPY(AVDOVIDataMapping, av_dovi_get_mapping(dovi), s->mapping, nlq_pivots);
 COPY(AVDOVIColorMetadata, av_dovi_get_color(dovi), s->color, 
source_diagonal);
 return 0;
 }
@@ -346,7 +346,14 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 }
 
 if (use_nlq) {
+int nlq_pivot = 0;
 vdr->mapping.nlq_method_idc = get_bits(gb, 3);
+
+for (int i = 0; i < 2; i++) {
+nlq_pivot += get_bits(gb, hdr->bl_bit_depth);
+vdr->mapping.nlq_pivots[i] = av_clip_uint16(nlq_pivot);
+}
+
 /**
  * The patent mentions another legal value, NLQ_MU_LAW, but it's
  * not documented anywhere how to parse or apply that type of NLQ.
diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
index 3d11e02bffc..6afc7b055a7 100644
--- a/libavutil/dovi_meta.h
+++ b/libavutil/dovi_meta.h
@@ -147,6 +147,7 @@ typedef struct AVDOVIDataMapping {
 uint32_t num_x_partitions;
 uint32_t num_y_partitions;
 AVDOVINLQParams nlq[3]; /* per component */
+uint16_t nlq_pivots[2]; /* nlq_pred_pivot_value */
 } AVDOVIDataMapping;
 
 /**
diff --git a/libavutil/version.h b/libavutil/version.h
index 882003f7199..8a1ecd44516 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR   4
+#define LIBAVUTIL_VERSION_MINOR   5
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.44.0

___
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 2/6] avutil/dovi_meta: add dolby vision extension blocks

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

As well as accessors plus a function for allocating this struct with
extension blocks,

Definitions generously taken from quietvoid/dovi_tool, which is
assembled as a collection of various patent fragments, as well as output
by the official Dolby Vision bitstream verifier tool.
---
 doc/APIchanges|   5 ++
 libavutil/dovi_meta.c |  36 --
 libavutil/dovi_meta.h | 154 ++
 libavutil/version.h   |   2 +-
 4 files changed, 190 insertions(+), 7 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 739f33501e9..8b59150dc1f 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-03-xx - xx - lavu 59.6.100 - dovi_meta.h
+  Add AVDOVIMetadata.ext_block_{offset,size}, AVDOVIMetadata.num_ext_blocks,
+  AVDOVIDmData and AVDOVIDmLevel{1..6,8..11,254..255}, av_dovi_get_ext(),
+  av_dovi_find_level() and av_dovi_metadata_alloc_ext(),
+
 2024-03-xx - xx - lavu 59.5.100 - dovi_meta.h
   Add AVDOVIDataMapping.nlq_pivots.
 
diff --git a/libavutil/dovi_meta.c b/libavutil/dovi_meta.c
index 9c50da561ed..17e18bf95f9 100644
--- a/libavutil/dovi_meta.c
+++ b/libavutil/dovi_meta.c
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
+
 #include "dovi_meta.h"
 #include "mem.h"
 
@@ -39,22 +41,44 @@ typedef struct AVDOVIMetadataInternal {
 AVDOVIRpuDataHeader header;
 AVDOVIDataMapping mapping;
 AVDOVIColorMetadata color;
+AVDOVIDmData ext_blocks[];
 } AVDOVIMetadataInternal;
 
-AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
+AVDOVIMetadata *av_dovi_metadata_alloc_ext(int num_ext_blocks, size_t *size)
 {
-AVDOVIMetadataInternal *dovi = av_mallocz(sizeof(AVDOVIMetadataInternal));
+const size_t alloc_size = sizeof(AVDOVIMetadataInternal) +
+  num_ext_blocks * sizeof(AVDOVIDmData);
+
+AVDOVIMetadataInternal *dovi = av_mallocz(alloc_size);
 if (!dovi)
 return NULL;
 
 if (size)
-*size = sizeof(*dovi);
+*size = alloc_size;
 
 dovi->metadata = (struct AVDOVIMetadata) {
-.header_offset  = offsetof(AVDOVIMetadataInternal, header),
-.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
-.color_offset   = offsetof(AVDOVIMetadataInternal, color),
+.header_offset  = offsetof(AVDOVIMetadataInternal, header),
+.mapping_offset = offsetof(AVDOVIMetadataInternal, mapping),
+.color_offset   = offsetof(AVDOVIMetadataInternal, color),
+.ext_block_offset   = offsetof(AVDOVIMetadataInternal, ext_blocks),
+.ext_block_size = sizeof(AVDOVIDmData),
 };
 
 return >metadata;
 }
+
+AVDOVIMetadata *av_dovi_metadata_alloc(size_t *size)
+{
+return av_dovi_metadata_alloc_ext(0, size);
+}
+
+AVDOVIDmData *av_dovi_find_level(const AVDOVIMetadata *data, uint8_t level)
+{
+for (int i = 0; i < data->num_ext_blocks; i++) {
+AVDOVIDmData *ext = av_dovi_get_ext(data, i);
+if (ext->level == level)
+return ext;
+}
+
+return NULL;
+}
diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
index 6afc7b055a7..e77d9853f67 100644
--- a/libavutil/dovi_meta.h
+++ b/libavutil/dovi_meta.h
@@ -29,7 +29,9 @@
 
 #include 
 #include 
+
 #include "rational.h"
+#include "csp.h"
 
 /*
  * DOVI configuration
@@ -187,6 +189,130 @@ typedef struct AVDOVIColorMetadata {
 uint16_t source_diagonal;
 } AVDOVIColorMetadata;
 
+typedef struct AVDOVIDmLevel1 {
+/* Per-frame brightness metadata */
+uint16_t min_pq;
+uint16_t max_pq;
+uint16_t avg_pq;
+} AVDOVIDmLevel1;
+
+typedef struct AVDOVIDmLevel2 {
+/* Usually derived from level 8 (at different levels) */
+uint16_t target_max_pq;
+uint16_t trim_slope;
+uint16_t trim_offset;
+uint16_t trim_power;
+uint16_t trim_chroma_weight;
+uint16_t trim_saturation_gain;
+int16_t ms_weight;
+} AVDOVIDmLevel2;
+
+typedef struct AVDOVIDmLevel3 {
+uint16_t min_pq_offset;
+uint16_t max_pq_offset;
+uint16_t avg_pq_offset;
+} AVDOVIDmLevel3;
+
+typedef struct AVDOVIDmLevel4 {
+uint16_t anchor_pq;
+uint16_t anchor_power;
+} AVDOVIDmLevel4;
+
+typedef struct AVDOVIDmLevel5 {
+/* Active area definition */
+uint16_t left_offset;
+uint16_t right_offset;
+uint16_t top_offset;
+uint16_t bottom_offset;
+} AVDOVIDmLevel5;
+
+typedef struct AVDOVIDmLevel6 {
+/* Static HDR10 metadata */
+uint16_t max_luminance;
+uint16_t min_luminance;
+uint16_t max_cll;
+uint16_t max_fall;
+} AVDOVIDmLevel6;
+
+typedef struct AVDOVIDmLevel8 {
+/* Extended version of level 2 */
+uint8_t target_display_index;
+uint16_t trim_slope;
+uint16_t trim_offset;
+uint16_t trim_power;
+uint16_t trim_chroma_weight;
+uint16_t trim_saturation_gain;
+

[FFmpeg-devel] [PATCH 3/6] avcodec/dovi_rpu: strip container in separate step

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

This ensures that `gb` in the following section is fully byte-aligned,
points at the start of the actual RPU, and ends on the CRC terminator.

This is important for both calculation of the CRC, as well as dovi
extension block parsing (which aligns to byte boundaries in various
places).
---
 libavcodec/dovi_rpu.c | 48 +++
 libavcodec/dovi_rpu.h |  2 ++
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index c84a942f476..24a1cdf39a8 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/buffer.h"
 
+#include "avcodec.h"
 #include "dovi_rpu.h"
 #include "golomb.h"
 #include "get_bits.h"
@@ -45,6 +46,7 @@ void ff_dovi_ctx_unref(DOVIContext *s)
 {
 for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
 ff_refstruct_unref(>vdr[i]);
+av_free(s->rpu_buf);
 
 *s = (DOVIContext) {
 .logctx = s->logctx,
@@ -202,17 +204,17 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 DOVIVdr *vdr;
 int ret;
 
-uint8_t nal_prefix;
 uint8_t rpu_type;
 uint8_t vdr_seq_info_present;
 uint8_t vdr_dm_metadata_present;
 uint8_t use_prev_vdr_rpu;
 uint8_t use_nlq;
 uint8_t profile;
-if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
-return ret;
 
-/* Container header */
+if (rpu_size < 5)
+goto fail;
+
+/* Container */
 if (s->dv_profile == 10 /* dav1.10 */) {
 /* DV inside AV1 re-uses an EMDF container skeleton, but with fixed
  * values - so we can effectively treat this as a magic byte sequence.
@@ -229,18 +231,46 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
  *   discard_unknown_payload : f(1) = 1
  */
 const unsigned header_magic = 0x01be6841u;
-unsigned header, emdf_payload_size;
-header = get_bits_long(gb, 27);
-VALIDATE(header, header_magic, header_magic);
+unsigned emdf_header, emdf_payload_size, emdf_protection;
+if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
+return ret;
+emdf_header = get_bits_long(gb, 27);
+VALIDATE(emdf_header, header_magic, header_magic);
 emdf_payload_size = get_variable_bits(gb, 8);
 VALIDATE(emdf_payload_size, 6, 512);
 if (emdf_payload_size * 8 > get_bits_left(gb))
 return AVERROR_INVALIDDATA;
+
+/* The payload is not byte-aligned (off by *one* bit, curse Dolby),
+ * so copy into a fresh buffer to preserve byte alignment of the
+ * RPU struct */
+av_fast_padded_malloc(>rpu_buf, >rpu_buf_sz, emdf_payload_size);
+if (!s->rpu_buf)
+return AVERROR(ENOMEM);
+for (int i = 0; i < emdf_payload_size; i++)
+s->rpu_buf[i] = get_bits(gb, 8);
+rpu = s->rpu_buf;
+rpu_size = emdf_payload_size;
+
+/* Validate EMDF footer */
+emdf_protection = get_bits(gb, 5 + 12);
+VALIDATE(emdf_protection, 0x400, 0x400);
+
+if ((ret = init_get_bits8(gb, s->rpu_buf, emdf_payload_size)) < 0)
+return ret;
 } else {
-nal_prefix = get_bits(gb, 8);
-VALIDATE(nal_prefix, 25, 25);
+/* NAL RBSP with prefix and trailing zeroes */
+VALIDATE(rpu[0], 25, 25); /* NAL prefix */
+rpu++;
+rpu_size--;
+/* Strip trailing padding bytes */
+while (rpu_size && rpu[rpu_size - 1] == 0)
+rpu_size--;
 }
 
+if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
+return ret;
+
 /* RPU header */
 rpu_type = get_bits(gb, 6);
 if (rpu_type != 2) {
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 51c5fdbb879..506974a74bf 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -49,6 +49,8 @@ typedef struct DOVIContext {
  */
 struct DOVIVdr *vdr[DOVI_MAX_DM_ID+1]; ///< RefStruct references
 uint8_t dv_profile;
+uint8_t *rpu_buf; ///< temporary buffer
+unsigned rpu_buf_sz;
 
 } DOVIContext;
 
-- 
2.44.0

___
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 4/6] avcodec/dovi_rpu: verify RPU data CRC32

2024-03-23 Thread Niklas Haas
From: Niklas Haas 

The Dolby Vision RPU contains a CRC32 to validate the payload against.
The implementation is CRC32/MPEG-2.

The CRC is only verified with the AV_EF_CRCCHECK flag.

Co-authored-by: quietvoid 
---
 libavcodec/av1dec.c   |  3 ++-
 libavcodec/dovi_rpu.c | 18 --
 libavcodec/dovi_rpu.h |  3 ++-
 libavcodec/hevcdec.c  |  3 ++-
 libavcodec/libdav1d.c |  3 ++-
 5 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 4d074c39087..bff921a12b2 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -1001,7 +1001,8 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame 
*frame,
 provider_oriented_code != 0x800)
 break;
 
-ret = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - 
gb.buffer);
+ret = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - gb.buffer,
+avctx->err_recognition);
 if (ret < 0) {
 av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
 break; // ignore
diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 24a1cdf39a8..cd54c8716dc 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -22,6 +22,7 @@
  */
 
 #include "libavutil/buffer.h"
+#include "libavutil/crc.h"
 
 #include "avcodec.h"
 #include "dovi_rpu.h"
@@ -197,7 +198,8 @@ static inline unsigned get_variable_bits(GetBitContext *gb, 
int n)
 }  
 \
 } while (0)
 
-int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size)
+int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
+  int err_recognition)
 {
 AVDOVIRpuDataHeader *hdr = >header;
 GetBitContext *gb = &(GetBitContext){0};
@@ -268,6 +270,19 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 rpu_size--;
 }
 
+if (!rpu_size || rpu[rpu_size - 1] != 0x80)
+goto fail;
+
+if (err_recognition & AV_EF_CRCCHECK) {
+uint32_t crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE),
+  -1, rpu, rpu_size - 1)); /* exclude 0x80 */
+if (crc) {
+av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);
+if (err_recognition & AV_EF_EXPLODE)
+goto fail;
+}
+}
+
 if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
 return ret;
 
@@ -508,7 +523,6 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, 
size_t rpu_size)
 color->source_diagonal = get_bits(gb, 10);
 }
 
-/* FIXME: verify CRC32, requires implementation of AV_CRC_32_MPEG_2 */
 return 0;
 
 fail:
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 506974a74bf..f88fbf9b558 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -79,7 +79,8 @@ void ff_dovi_update_cfg(DOVIContext *s, const 
AVDOVIDecoderConfigurationRecord *
  *
  * Returns 0 or an error code.
  */
-int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size);
+int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
+  int err_recognition);
 
 /**
  * Attach the decoded AVDOVIMetadata as side data to an AVFrame.
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 76aa6b45882..ebd70eda234 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3193,7 +3193,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t 
*buf, int length)
 return AVERROR(ENOMEM);
 memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2);
 
-ret = ff_dovi_rpu_parse(>dovi_ctx, nal->data + 2, nal->size - 2);
+ret = ff_dovi_rpu_parse(>dovi_ctx, nal->data + 2, nal->size - 2,
+s->avctx->err_recognition);
 if (ret < 0) {
 av_buffer_unref(>rpu_buf);
 av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 17b0743cf0c..af95e46c343 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -567,7 +567,8 @@ static int libdav1d_receive_frame(AVCodecContext *c, 
AVFrame *frame)
 provider_oriented_code != 0x800)
 break;
 
-res = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - 
gb.buffer);
+res = ff_dovi_rpu_parse(>dovi, gb.buffer, gb.buffer_end - 
gb.buffer,
+c->err_recognition);
 if (res < 0) {
 av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
 break; // ignore
-- 
2.44.0

___
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 

Re: [FFmpeg-devel] [PATCH] avfilter/af_volumedetect.c: Add 32bit float audio support

2024-03-23 Thread Yiğithan Yiğit

Fixes #9613

---
 libavfilter/af_volumedetect.c | 234 +-
 1 file changed, 172 insertions(+), 62 deletions(-)

diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c
index 8b001d1cf2..d13d043f88 100644
--- a/libavfilter/af_volumedetect.c
+++ b/libavfilter/af_volumedetect.c
@@ -24,94 +24,193 @@
 #include "avfilter.h"
 #include "internal.h"
 
+#define NOISE_FLOOR_DB_FLT -758
+#define MAX_DB_FLT 770
+#define MAX_DB 91
+#define HISTOGRAM_SIZE 0x1
+
 typedef struct VolDetectContext {
-/**
- * Number of samples at each PCM value.
- * histogram[0x8000 + i] is the number of samples at value i.
- * The extra element is there for symmetry.
- */
-uint64_t histogram[0x10001];
+uint64_t* histogram; ///< for integer number of samples at each PCM value, 
for float number of samples at each dB
+uint64_t nb_samples; ///< number of samples
+double sum2; ///< sum of the squares of the samples
+double max;  ///< maximum sample value
+int is_float;///< true if the input is in floating point
 } VolDetectContext;
 
+static inline double logdb(double v, enum AVSampleFormat sample_fmt)
+{
+/*
+* Since it is a not a power value, able to use 20.0 * log10(v)
+*/
+if (sample_fmt == AV_SAMPLE_FMT_FLT) {
+if (!v)
+return MAX_DB_FLT;
+return 20.0 * log10(v);
+} else {
+double d = v / (double)(0x8000 * 0x8000);
+if (!v)
+return MAX_DB;
+return -log10(d) * 10;
+}
+}
+
+static void update_float_stats(VolDetectContext *vd, float *audio_data)
+{
+double max_sample;
+max_sample = fabsf(*audio_data);
+if (max_sample > vd->max)
+vd->max = max_sample;
+vd->sum2 += *audio_data * *audio_data;
+vd->histogram[(int)logdb(max_sample, AV_SAMPLE_FMT_FLT) + MAX_DB_FLT]++;
+vd->nb_samples++;
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
 {
 AVFilterContext *ctx = inlink->dst;
 VolDetectContext *vd = ctx->priv;
-int nb_samples  = samples->nb_samples;
 int nb_channels = samples->ch_layout.nb_channels;
 int nb_planes   = nb_channels;
+int planar  = 0;
 int plane, i;
-int16_t *pcm;
 
-if (!av_sample_fmt_is_planar(samples->format)) {
-nb_samples *= nb_channels;
+planar = av_sample_fmt_is_planar(samples->format);
+if (!planar)
 nb_planes = 1;
+if (vd->is_float) {
+float *audio_data;
+for (plane = 0; plane < nb_planes; plane++) {
+audio_data = (float *)samples->extended_data[plane];
+for (i = 0; i < samples->nb_samples; i++) {
+/*
+ * If the input is planar, the samples are in the seperated 
planes.
+ * if the input is not planar, the samples are interleaved.
+ * if the input is not planar, split the samples into the 
planes.
+ */
+if (planar) {
+update_float_stats(vd, _data[i]);
+} else {
+for (int j = 0; j < nb_channels; j++)
+update_float_stats(vd, _data[i * nb_channels + 
j]);
+}
+}
+}
+} else {
+int16_t *pcm;
+for (plane = 0; plane < nb_planes; plane++) {
+pcm = (int16_t *)samples->extended_data[plane];
+for (i = 0; i < samples->nb_samples; i++) {
+if (planar) {
+vd->histogram[pcm[i] + 0x8000]++;
+vd->nb_samples++;
+} else {
+for (int j = 0; j < nb_channels; j++) {
+vd->histogram[pcm[i * nb_channels + j] + 0x8000]++;
+vd->nb_samples++;
+}
+}
+}
+}
 }
-for (plane = 0; plane < nb_planes; plane++) {
-pcm = (int16_t *)samples->extended_data[plane];
-for (i = 0; i < nb_samples; i++)
-vd->histogram[pcm[i] + 0x8000]++;
-}
-
 return ff_filter_frame(inlink->dst->outputs[0], samples);
 }
 
-#define MAX_DB 91
-
-static inline double logdb(uint64_t v)
+static void print_stats(AVFilterContext *ctx)
 {
-double d = v / (double)(0x8000 * 0x8000);
-if (!v)
-return MAX_DB;
-return -log10(d) * 10;
+VolDetectContext *vd = ctx->priv;
+
+if (!vd->nb_samples)
+return;
+if (vd->is_float) {
+double rms;
+int i, sum = 0;
+av_log(ctx, AV_LOG_INFO, "n_samples: %" PRId64 "\n", vd->nb_samples);
+rms = sqrt(vd->sum2 / vd->nb_samples);
+av_log(ctx, AV_LOG_INFO, "mean_volume: %.1f dB\n", logdb(rms, 
AV_SAMPLE_FMT_FLT));
+av_log(ctx, AV_LOG_INFO, "max_volume: %.1f dB\n", logdb(vd->max, 
AV_SAMPLE_FMT_FLT));
+for (i = MAX_DB_FLT - NOISE_FLOOR_DB_FLT; i >= 0 && !vd->histogram[i]; 
i--);
+for (; i >= 0 && sum < vd->nb_samples / 1000; 

[FFmpeg-devel] [PATCH] avfilter/vf_stack: round down internal item heights

2024-03-23 Thread Timo Rothenpieler
Following situation:
Someone wants to stack two yuv420p frames of the size 3x3 pixel each.
Now the various AV_CEIL_RSHIFT() calculations calculate a height of 2
pixel for each items subsampled planes.
However, for example in case of a vstack, the output frames will have a
height of 6, so the subsampled planes one of 3.
When the filter now tries to stack two items with a rounded-up height of
2 into a frame with a height of 3, it'll write an entire extra line past
the end of a buffer.

This patch instead rounds down all the item heights, to avoid this
situation. It's not ideal either, since now lines might be missed. But
that is definitely preferable over writing past the end of the
bufferThis patch instead rounds down all the item heights, to avoid this
situation. It's not ideal either, since now lines might be missed. But
that is definitely preferable over writing past the end of the buffer.
---
 libavfilter/vf_stack.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c
index 2bb3d9b1d2..46e7d6b7f5 100644
--- a/libavfilter/vf_stack.c
+++ b/libavfilter/vf_stack.c
@@ -220,11 +220,11 @@ static int config_output(AVFilterLink *outlink)
 return ret;
 }
 
-item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, 
s->desc->log2_chroma_h);
+item->height[1] = item->height[2] = inlink->h / (1 << 
s->desc->log2_chroma_h);
 item->height[0] = item->height[3] = inlink->h;
 
 if (i) {
-item->y[1] = item->y[2] = AV_CEIL_RSHIFT(height, 
s->desc->log2_chroma_h);
+item->y[1] = item->y[2] = height / (1 << 
s->desc->log2_chroma_h);
 item->y[0] = item->y[3] = height;
 
 height += ctx->inputs[i]->h;
@@ -244,7 +244,7 @@ static int config_output(AVFilterLink *outlink)
 return ret;
 }
 
-item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, 
s->desc->log2_chroma_h);
+item->height[1] = item->height[2] = inlink->h / (1 << 
s->desc->log2_chroma_h);
 item->height[0] = item->height[3] = inlink->h;
 
 if (i) {
@@ -278,14 +278,14 @@ static int config_output(AVFilterLink *outlink)
 return ret;
 }
 
-item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, 
s->desc->log2_chroma_h);
+item->height[1] = item->height[2] = inlink->h / (1 << 
s->desc->log2_chroma_h);
 item->height[0] = item->height[3] = inlink->h;
 
 if ((ret = av_image_fill_linesizes(item->x, inlink->format, 
inw)) < 0) {
 return ret;
 }
 
-item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, 
s->desc->log2_chroma_h);
+item->y[1] = item->y[2] = inh / (1 << s->desc->log2_chroma_h);
 item->y[0] = item->y[3] = inh;
 inw += ctx->inputs[k]->w;
 }
@@ -322,7 +322,7 @@ static int config_output(AVFilterLink *outlink)
 return ret;
 }
 
-item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, 
s->desc->log2_chroma_h);
+item->height[1] = item->height[2] = inlink->h / (1 << 
s->desc->log2_chroma_h);
 item->height[0] = item->height[3] = inlink->h;
 
 p2 = arg;
@@ -370,7 +370,7 @@ static int config_output(AVFilterLink *outlink)
 return ret;
 }
 
-item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, 
s->desc->log2_chroma_h);
+item->y[1] = item->y[2] = inh / (1 << s->desc->log2_chroma_h);
 item->y[0] = item->y[3] = inh;
 
 width  = FFMAX(width,  inlink->w + inw);
-- 
2.34.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] avfilter/buffersrc: fix overriding unknown channel layouts with negotiated one

2024-03-23 Thread Marton Balint
Fixes ffplay playback of unknown layouts, when SDL directly supports the audio
format, such as:

ffplay -f lavfi anullsrc=cl=2C,aformat=s16

Without the patch, "Channel layout change is not supported" errors are
generated because buffersrc (unknown 2 channel) and buffersink (stereo)
negotiated a stereo layout, but the stereo layout was never stored in the
BufferSourceContext.

This fixes a regression of 7251f909721a570726775acf61b2b9c28a950c76, but this
is more of a regression of the avfilter channel layout conversion
(1f96db959c1235bb7079d354e09914a0a2608f62).

Signed-off-by: Marton Balint 
---
 libavfilter/buffersrc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index ddcd403785..fcae4f8e69 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -507,7 +507,7 @@ static int config_props(AVFilterLink *link)
 }
 break;
 case AVMEDIA_TYPE_AUDIO:
-if (!c->ch_layout.nb_channels) {
+if (!c->ch_layout.nb_channels || c->ch_layout.order == 
AV_CHANNEL_ORDER_UNSPEC) {
 int ret = av_channel_layout_copy(>ch_layout, >ch_layout);
 if (ret < 0)
 return ret;
-- 
2.35.3

___
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".


Re: [FFmpeg-devel] [PATCH] avfilter/af_volumedetect.c: Add 32bit float audio support

2024-03-23 Thread Paul B Mahol
On Sat, Mar 23, 2024 at 3:28 PM Yiğithan Yiğit 
wrote:

> Hi,
>
> According to your advices, I made some changes of mine last patch. I feel
> like this one way more better. I removed trivial calculations but I want to
> say I am not proud of how I handled histogram in float despite 16 bit
> integer histogram. I am storing dB values instead of storing samples. I
> feel this one is more convenient. Still I am open to advices.
>
>
I see no patch at all.

volumedetect displays histogram typically with 1dB steps, so build
histogram with 1dB range between each bin.
for float, only use normal values, no +inf/subnormals/nans etc.
I bet there is less than current 2^16 entries in histogram table of filter
context to fill.
There is no need to convert each input sample to dB scale. Just to
calculate ranges for each 1dB entry calculate range in linear space and
every such sample that is in such range get added to such histogram bin
entry.
Or if you calculate in dB scale anyway than just round(ceilf/floorf/lrintf)
dB value (removing fractional parts) and add it into histogram table, do
not forget to count >+/-1.0 values too. (ones with >0dB values), you can
use normal mean/max/peak calculations (do not use histogram to calculate
them for float/double).



> Thank you.
> Yigithan
>
>
> 
>
> > On Mar 21, 2024, at 11:30 PM, Paul B Mahol  wrote:
> >
> > On Wed, Mar 20, 2024 at 11:55 PM Yiğithan Yiğit <
> yigithanyigi...@gmail.com >
> > wrote:
> >
> >>
> >>> On Mar 21, 2024, at 12:10 AM, Paul B Mahol  wrote:
> >>>
> >>> Why? This is pointless.
> >>>
> >>> volumedetect have histogram output, float patch does not have it at
> all.
> >>> Use astats filter.
> >>>
> >>> On Wed, Mar 20, 2024 at 9:47 PM Yiğithan Yiğit <
> >> yigithanyigi...@gmail.com>
> >>> wrote:
> >>>
>  ___
>  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 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”.
> >>
> >> I am a beginner/student also new at open source but I love FFmpeg and
> >> using in my daily life. From my perspective volumedetect way more user
> >> friendly. I believe adding this patch would be useful to people such as
> >> #9613. The reason lack of histogram output for float mostly for my
> >> indecision about range of the histogram. I am open the suggestions and
> >> after that I can make a new patch.
> >>
> >
> > It is trivial (to some people) to add histogram per dB for float/double
> > inputs.
> > But this patch just does some extremely trivial math calculations so that
> > float input have completely different output from integer ones.
> > That is very odd and unfriendly from my perspective.
> >
> > Besides if you only interested in discrete sample audio peak finder in
> > audio input use astats and measure_overall=Peak_level options.
> > Yes they are not default on. Because more statistics are more important
> > than single number.
> >
> > I'm not against adding proper and useful and correct float/double support
> > to volumedetect, but it needs to have same/similar structure of output as
> > integer sample format input audio, otherwise it just looks lazy and prone
> > for users wondering what is going on when they use different sample
> formats
> > in theirs graphs.
> >
> >
> >>
> >> Best Regards
> >> Yigithan
> >>
> >>
> >> ___
> >> 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 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 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 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 

Re: [FFmpeg-devel] [PATCH 3/4] avcodec/cbs_h266_syntax_template: Check tile_y

2024-03-23 Thread Nuo Mi
On Thu, Mar 21, 2024 at 9:15 AM Michael Niedermayer 
wrote:

> Fixes: out of array access
> Fixes:
> 67021/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-4883576579489792
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by
> :
> Michael Niedermayer 
>

Pushed this one.
Thank you, Michael.

> ---
>  libavcodec/cbs_h266_syntax_template.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavcodec/cbs_h266_syntax_template.c
> b/libavcodec/cbs_h266_syntax_template.c
> index 49fb12ba77..0aae9fdfd5 100644
> --- a/libavcodec/cbs_h266_syntax_template.c
> +++ b/libavcodec/cbs_h266_syntax_template.c
> @@ -2072,6 +2072,8 @@ static int FUNC(pps) (CodedBitstreamContext *ctx,
> RWContext *rw,
>
>  tile_x = tile_idx % current->num_tile_columns;
>  tile_y = tile_idx / current->num_tile_columns;
> +if (tile_y >= current->num_tile_rows)
> +return AVERROR_INVALIDDATA;
>
>  ctu_x = 0, ctu_y = 0;
>  for (j = 0; j < tile_x; j++) {
> --
> 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 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".


Re: [FFmpeg-devel] [PATCH 1/2] lavc/vvc_parser: small cleanup for style

2024-03-23 Thread Nuo Mi
On Fri, Mar 22, 2024 at 6:36 PM Jun Zhao  wrote:

> From: Jun Zhao 
>
> small cleanup for style, redundant semicolons, goto labels,
> in FFmpeg, we put goto labels at brace level.
>
Pushed this patch.
Thanks, Jun


> Signed-off-by: Jun Zhao 
> ---
>  libavcodec/vvc_parser.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/vvc_parser.c b/libavcodec/vvc_parser.c
> index c661595e1e..245cb214c9 100644
> --- a/libavcodec/vvc_parser.c
> +++ b/libavcodec/vvc_parser.c
> @@ -173,7 +173,7 @@ static void set_parser_ctx(AVCodecParserContext *s,
> AVCodecContext *avctx,
>  h266_sub_width_c[sps->sps_chroma_format_idc];
>  s->height = pps->pps_pic_height_in_luma_samples -
>  (pps->pps_conf_win_top_offset + pps->pps_conf_win_bottom_offset) *
> -h266_sub_height_c[sps->sps_chroma_format_idc];;
> +h266_sub_height_c[sps->sps_chroma_format_idc];
>
>  avctx->profile = sps->profile_tier_level.general_profile_idc;
>  avctx->level = sps->profile_tier_level.general_level_idc;
> @@ -317,7 +317,7 @@ static int get_pu_info(PuInfo *info, const
> CodedBitstreamH266Context *h266,
>  }
>  info->pic_type = get_pict_type(pu);
>  return 0;
> -  error:
> +error:
>  memset(info, 0, sizeof(*info));
>  return ret;
>  }
> @@ -329,7 +329,7 @@ static int append_au(AVPacket *pkt, const uint8_t
> *buf, int buf_size)
>  if ((ret = av_grow_packet(pkt, buf_size)) < 0)
>  goto end;
>  memcpy(pkt->data + offset, buf, buf_size);
> -  end:
> +end:
>  return ret;
>  }
>
> @@ -376,7 +376,7 @@ static int parse_nal_units(AVCodecParserContext *s,
> const uint8_t *buf,
>  } else {
>  ret = 1; //not a completed au
>  }
> -  end:
> +end:
>  ff_cbs_fragment_reset(pu);
>  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 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] all: Don't use ATOMIC_VAR_INIT

2024-03-23 Thread Andreas Rheinhardt
C11 required to use ATOMIC_VAR_INIT to statically initialize
atomic objects with static storage duration. Yet this macro
was unsuitable for initializing structures [1] and was actually
unneeded for all known implementations (this includes our
compatibility fallback implementations which simply wrap the value
in parentheses: #define ATOMIC_VAR_INIT(value) (value)).
Therefore C17 deprecated the macro and C23 actually removed it [2].

Since commit 5ff0eb34d2b1089d3dd9f27fdb51520001709138 we default
to C17 if the compiler supports it; Clang warns about ATOMIC_VAR_INIT
in this mode. Given that no implementation ever needed this macro,
this commit stops using it to avoid this warning.

[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_485
[2]: https://en.cppreference.com/w/c/atomic/ATOMIC_VAR_INIT

Signed-off-by: Andreas Rheinhardt 
---
 configure| 4 ++--
 fftools/ffmpeg.c | 2 +-
 libavformat/allformats.c | 4 ++--
 libavutil/cpu.c  | 6 +++---
 libavutil/mem.c  | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index b9fa8652c4..e577dcc677 100755
--- a/configure
+++ b/configure
@@ -6610,8 +6610,8 @@ check_headers asm/types.h
 # some configurations also require linking to libatomic, so try
 # both with -latomic and without
 for LATOMIC in "-latomic" ""; do
-check_builtin stdatomic stdatomic.h
 \
-"atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(, 0); foo 
+= bar"  \
+check_builtin stdatomic stdatomic.h\
+"atomic_int foo, bar = -1; atomic_store(, 0); foo += bar"  \
 $LATOMIC && eval stdatomic_extralibs="\$LATOMIC" && break
 done
 
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d4e5f978f1..5e00d5b645 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -157,7 +157,7 @@ void term_exit(void)
 
 static volatile int received_sigterm = 0;
 static volatile int received_nb_signals = 0;
-static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0);
+static atomic_int transcode_init_done = 0;
 static volatile int ffmpeg_exited = 0;
 static int64_t copy_ts_first_pts = AV_NOPTS_VALUE;
 
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index e15d0fa6d7..9df42bb87a 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -576,8 +576,8 @@ extern const FFInputFormat  ff_vapoursynth_demuxer;
 #include "libavformat/muxer_list.c"
 #include "libavformat/demuxer_list.c"
 
-static atomic_uintptr_t indev_list_intptr  = ATOMIC_VAR_INIT(0);
-static atomic_uintptr_t outdev_list_intptr = ATOMIC_VAR_INIT(0);
+static atomic_uintptr_t indev_list_intptr  = 0;
+static atomic_uintptr_t outdev_list_intptr = 0;
 
 const AVOutputFormat *av_muxer_iterate(void **opaque)
 {
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index 48d195168c..d4f947360a 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -49,8 +49,8 @@
 #include 
 #endif
 
-static atomic_int cpu_flags = ATOMIC_VAR_INIT(-1);
-static atomic_int cpu_count = ATOMIC_VAR_INIT(-1);
+static atomic_int cpu_flags = -1;
+static atomic_int cpu_count = -1;
 
 static int get_cpu_flags(void)
 {
@@ -208,7 +208,7 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)
 
 int av_cpu_count(void)
 {
-static atomic_int printed = ATOMIC_VAR_INIT(0);
+static atomic_int printed = 0;
 
 int nb_cpus = 1;
 int count   = 0;
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 62163b4cb3..02d4cb791f 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -69,7 +69,7 @@ void  free(void *ptr);
  * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
  * Note that this will cost performance. */
 
-static atomic_size_t max_alloc_size = ATOMIC_VAR_INIT(INT_MAX);
+static atomic_size_t max_alloc_size = INT_MAX;
 
 void av_max_alloc(size_t max){
 atomic_store_explicit(_alloc_size, max, memory_order_relaxed);
-- 
2.40.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".


Re: [FFmpeg-devel] [PATCH] avfilter/af_volumedetect.c: Add 32bit float audio support

2024-03-23 Thread Yiğithan Yiğit
Hi,

According to your advices, I made some changes of mine last patch. I feel like 
this one way more better. I removed trivial calculations but I want to say I am 
not proud of how I handled histogram in float despite 16 bit integer histogram. 
I am storing dB values instead of storing samples. I feel this one is more 
convenient. Still I am open to advices.

Thank you.
Yigithan




> On Mar 21, 2024, at 11:30 PM, Paul B Mahol  wrote:
> 
> On Wed, Mar 20, 2024 at 11:55 PM Yiğithan Yiğit  >
> wrote:
> 
>> 
>>> On Mar 21, 2024, at 12:10 AM, Paul B Mahol  wrote:
>>> 
>>> Why? This is pointless.
>>> 
>>> volumedetect have histogram output, float patch does not have it at all.
>>> Use astats filter.
>>> 
>>> On Wed, Mar 20, 2024 at 9:47 PM Yiğithan Yiğit <
>> yigithanyigi...@gmail.com>
>>> wrote:
>>> 
 ___
 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 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”.
>> 
>> I am a beginner/student also new at open source but I love FFmpeg and
>> using in my daily life. From my perspective volumedetect way more user
>> friendly. I believe adding this patch would be useful to people such as
>> #9613. The reason lack of histogram output for float mostly for my
>> indecision about range of the histogram. I am open the suggestions and
>> after that I can make a new patch.
>> 
> 
> It is trivial (to some people) to add histogram per dB for float/double
> inputs.
> But this patch just does some extremely trivial math calculations so that
> float input have completely different output from integer ones.
> That is very odd and unfriendly from my perspective.
> 
> Besides if you only interested in discrete sample audio peak finder in
> audio input use astats and measure_overall=Peak_level options.
> Yes they are not default on. Because more statistics are more important
> than single number.
> 
> I'm not against adding proper and useful and correct float/double support
> to volumedetect, but it needs to have same/similar structure of output as
> integer sample format input audio, otherwise it just looks lazy and prone
> for users wondering what is going on when they use different sample formats
> in theirs graphs.
> 
> 
>> 
>> Best Regards
>> Yigithan
>> 
>> 
>> ___
>> 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 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 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".


Re: [FFmpeg-devel] [PATCH v2 08/12] lavc/frame_thread_encoder: avoid assigning a whole AVCodecContext

2024-03-23 Thread Andreas Rheinhardt
Anton Khirnov:
> It is highly unsafe, as AVCodecContext contains many allocated fields.
> Everything needed by worked threads should be covered by
> * routing through AVCodecParameters
> * av_opt_copy()
> * copying quantisation matrices manually
> 
> avcodec_free_context() can now be used for per-thread contexts.
> ---
>  libavcodec/frame_thread_encoder.c | 44 ---
>  1 file changed, 34 insertions(+), 10 deletions(-)
> 
> diff --git a/libavcodec/frame_thread_encoder.c 
> b/libavcodec/frame_thread_encoder.c
> index cda5158117..5ea6386dfb 100644
> --- a/libavcodec/frame_thread_encoder.c
> +++ b/libavcodec/frame_thread_encoder.c
> @@ -28,6 +28,7 @@
>  #include "libavutil/thread.h"
>  #include "avcodec.h"
>  #include "avcodec_internal.h"
> +#include "codec_par.h"
>  #include "encode.h"
>  #include "internal.h"
>  #include "pthread_internal.h"
> @@ -111,8 +112,7 @@ static void * attribute_align_arg worker(void *v){
>  pthread_mutex_unlock(>finished_task_mutex);
>  }
>  end:
> -ff_codec_close(avctx);
> -av_freep();
> +avcodec_free_context();
>  return NULL;
>  }
>  
> @@ -121,6 +121,7 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
> *avctx)
>  int i=0;
>  ThreadContext *c;
>  AVCodecContext *thread_avctx = NULL;
> +AVCodecParameters *par = NULL;
>  int ret;
>  
>  if(   !(avctx->thread_type & FF_THREAD_FRAME)
> @@ -194,18 +195,27 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
> *avctx)
>  }
>  }
>  
> +par = avcodec_parameters_alloc();
> +if (!par) {
> +ret = AVERROR(ENOMEM);
> +goto fail;
> +}
> +
> +ret = avcodec_parameters_from_context(par, avctx);
> +if (ret < 0)
> +goto fail;
> +
>  for(i=0; ithread_count ; i++){
> -void *tmpv;
>  thread_avctx = avcodec_alloc_context3(avctx->codec);
>  if (!thread_avctx) {
>  ret = AVERROR(ENOMEM);
>  goto fail;
>  }
> -tmpv = thread_avctx->priv_data;
> -*thread_avctx = *avctx;
> -thread_avctx->priv_data = tmpv;
> -thread_avctx->internal = NULL;
> -thread_avctx->hw_frames_ctx = NULL;
> +
> +ret = avcodec_parameters_to_context(thread_avctx, par);
> +if (ret < 0)
> +goto fail;
> +
>  ret = av_opt_copy(thread_avctx, avctx);
>  if (ret < 0)
>  goto fail;
> @@ -217,6 +227,18 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
> *avctx)
>  thread_avctx->thread_count = 1;
>  thread_avctx->active_thread_type &= ~FF_THREAD_FRAME;
>  
> +#define DUP_MATRIX(m)   \
> +if (avctx->m) { \
> +thread_avctx->m = av_memdup(avctx->m, 64 * sizeof(avctx->m));   \
> +if (!thread_avctx->m) { \
> +ret = AVERROR(ENOMEM);  \
> +goto fail;  \
> +}   \
> +}
> +DUP_MATRIX(intra_matrix);
> +DUP_MATRIX(chroma_intra_matrix);
> +DUP_MATRIX(inter_matrix);
> +
>  if ((ret = avcodec_open2(thread_avctx, avctx->codec, NULL)) < 0)
>  goto fail;
>  av_assert0(!thread_avctx->internal->frame_thread_encoder);
> @@ -227,12 +249,14 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
> *avctx)
>  }
>  }
>  
> +avcodec_parameters_free();
> +
>  avctx->active_thread_type = FF_THREAD_FRAME;
>  
>  return 0;
>  fail:
> -ff_codec_close(thread_avctx);
> -av_freep(_avctx);
> +avcodec_parameters_free();
> +avcodec_free_context(_avctx);
>  avctx->thread_count = i;
>  av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");
>  ff_frame_thread_encoder_free(avctx);

1. The earlier code would just work in case the user used a smaller
number of elements for the matrices if these matrices were not used at
all (which happens for the majority of encoders). This is no longer true
with this patch.
2. Did you test this? Did it work? "av_memdup(avctx->m, 64 *
sizeof(avctx->m))" uses sizeof a pointer and therefore leads to a buffer
overflow.

- Andreas

___
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 08/12] lavc/frame_thread_encoder: avoid assigning a whole AVCodecContext

2024-03-23 Thread Anton Khirnov
It is highly unsafe, as AVCodecContext contains many allocated fields.
Everything needed by worked threads should be covered by
* routing through AVCodecParameters
* av_opt_copy()
* copying quantisation matrices manually

avcodec_free_context() can now be used for per-thread contexts.
---
 libavcodec/frame_thread_encoder.c | 44 ---
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/libavcodec/frame_thread_encoder.c 
b/libavcodec/frame_thread_encoder.c
index cda5158117..5ea6386dfb 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -28,6 +28,7 @@
 #include "libavutil/thread.h"
 #include "avcodec.h"
 #include "avcodec_internal.h"
+#include "codec_par.h"
 #include "encode.h"
 #include "internal.h"
 #include "pthread_internal.h"
@@ -111,8 +112,7 @@ static void * attribute_align_arg worker(void *v){
 pthread_mutex_unlock(>finished_task_mutex);
 }
 end:
-ff_codec_close(avctx);
-av_freep();
+avcodec_free_context();
 return NULL;
 }
 
@@ -121,6 +121,7 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
*avctx)
 int i=0;
 ThreadContext *c;
 AVCodecContext *thread_avctx = NULL;
+AVCodecParameters *par = NULL;
 int ret;
 
 if(   !(avctx->thread_type & FF_THREAD_FRAME)
@@ -194,18 +195,27 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
*avctx)
 }
 }
 
+par = avcodec_parameters_alloc();
+if (!par) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+ret = avcodec_parameters_from_context(par, avctx);
+if (ret < 0)
+goto fail;
+
 for(i=0; ithread_count ; i++){
-void *tmpv;
 thread_avctx = avcodec_alloc_context3(avctx->codec);
 if (!thread_avctx) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
-tmpv = thread_avctx->priv_data;
-*thread_avctx = *avctx;
-thread_avctx->priv_data = tmpv;
-thread_avctx->internal = NULL;
-thread_avctx->hw_frames_ctx = NULL;
+
+ret = avcodec_parameters_to_context(thread_avctx, par);
+if (ret < 0)
+goto fail;
+
 ret = av_opt_copy(thread_avctx, avctx);
 if (ret < 0)
 goto fail;
@@ -217,6 +227,18 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
*avctx)
 thread_avctx->thread_count = 1;
 thread_avctx->active_thread_type &= ~FF_THREAD_FRAME;
 
+#define DUP_MATRIX(m)   \
+if (avctx->m) { \
+thread_avctx->m = av_memdup(avctx->m, 64 * sizeof(avctx->m));   \
+if (!thread_avctx->m) { \
+ret = AVERROR(ENOMEM);  \
+goto fail;  \
+}   \
+}
+DUP_MATRIX(intra_matrix);
+DUP_MATRIX(chroma_intra_matrix);
+DUP_MATRIX(inter_matrix);
+
 if ((ret = avcodec_open2(thread_avctx, avctx->codec, NULL)) < 0)
 goto fail;
 av_assert0(!thread_avctx->internal->frame_thread_encoder);
@@ -227,12 +249,14 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
*avctx)
 }
 }
 
+avcodec_parameters_free();
+
 avctx->active_thread_type = FF_THREAD_FRAME;
 
 return 0;
 fail:
-ff_codec_close(thread_avctx);
-av_freep(_avctx);
+avcodec_parameters_free();
+avcodec_free_context(_avctx);
 avctx->thread_count = i;
 av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");
 ff_frame_thread_encoder_free(avctx);
-- 
2.43.0

___
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".


Re: [FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg_enc: only promote first frame side data to global when meaningful

2024-03-23 Thread Andreas Rheinhardt
Anton Khirnov:
> Quoting Andreas Rheinhardt (2024-03-23 14:15:06)
>> Anton Khirnov:
>>> Skip those side data types that do not make sense as global side data.
>>> ---
>>>  fftools/ffmpeg_enc.c | 5 +
>>>  1 file changed, 5 insertions(+)
>>>
>>> diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
>>> index f01be1c22f..6a91fd0398 100644
>>> --- a/fftools/ffmpeg_enc.c
>>> +++ b/fftools/ffmpeg_enc.c
>>> @@ -247,6 +247,11 @@ int enc_open(void *opaque, const AVFrame *frame)
>>>  enc_ctx->chroma_sample_location = frame->chroma_location;
>>>  
>>>  for (int i = 0; i < frame->nb_side_data; i++) {
>>> +const AVSideDataDescriptor *desc = 
>>> av_frame_side_data_desc(frame->side_data[i]->type);
>>> +
>>> +if (!desc || !(desc->props & AV_SIDE_DATA_PROP_GLOBAL))
>>> +continue;
>>
>> Why the first check? Is it intended that a defined side data type
>> doesn't have a descriptor? Because IIRC all side data types that can
>> occur here are defined and have not been created by letting the user
>> pass a number via options.
> 
> It shouldn't happen, but it's not inconceivable that e.g. a filter could
> attach side data with an unknown type to a frame. I can remove the check
> if you prefer it.
> 

Yes. I'd consider such a filter buggy and that bug should not be covered up.

- Andreas

___
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".


Re: [FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg_enc: only promote first frame side data to global when meaningful

2024-03-23 Thread Anton Khirnov
Quoting Andreas Rheinhardt (2024-03-23 14:15:06)
> Anton Khirnov:
> > Skip those side data types that do not make sense as global side data.
> > ---
> >  fftools/ffmpeg_enc.c | 5 +
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
> > index f01be1c22f..6a91fd0398 100644
> > --- a/fftools/ffmpeg_enc.c
> > +++ b/fftools/ffmpeg_enc.c
> > @@ -247,6 +247,11 @@ int enc_open(void *opaque, const AVFrame *frame)
> >  enc_ctx->chroma_sample_location = frame->chroma_location;
> >  
> >  for (int i = 0; i < frame->nb_side_data; i++) {
> > +const AVSideDataDescriptor *desc = 
> > av_frame_side_data_desc(frame->side_data[i]->type);
> > +
> > +if (!desc || !(desc->props & AV_SIDE_DATA_PROP_GLOBAL))
> > +continue;
> 
> Why the first check? Is it intended that a defined side data type
> doesn't have a descriptor? Because IIRC all side data types that can
> occur here are defined and have not been created by letting the user
> pass a number via options.

It shouldn't happen, but it's not inconceivable that e.g. a filter could
attach side data with an unknown type to a frame. I can remove the check
if you prefer it.

-- 
Anton Khirnov
___
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".


Re: [FFmpeg-devel] [PATCH 2/4] fftools/ffmpeg_enc: only promote first frame side data to global when meaningful

2024-03-23 Thread Andreas Rheinhardt
Anton Khirnov:
> Skip those side data types that do not make sense as global side data.
> ---
>  fftools/ffmpeg_enc.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
> index f01be1c22f..6a91fd0398 100644
> --- a/fftools/ffmpeg_enc.c
> +++ b/fftools/ffmpeg_enc.c
> @@ -247,6 +247,11 @@ int enc_open(void *opaque, const AVFrame *frame)
>  enc_ctx->chroma_sample_location = frame->chroma_location;
>  
>  for (int i = 0; i < frame->nb_side_data; i++) {
> +const AVSideDataDescriptor *desc = 
> av_frame_side_data_desc(frame->side_data[i]->type);
> +
> +if (!desc || !(desc->props & AV_SIDE_DATA_PROP_GLOBAL))
> +continue;

Why the first check? Is it intended that a defined side data type
doesn't have a descriptor? Because IIRC all side data types that can
occur here are defined and have not been created by letting the user
pass a number via options.

> +
>  ret = av_frame_side_data_clone(
>  _ctx->decoded_side_data, _ctx->nb_decoded_side_data,
>  frame->side_data[i], AV_FRAME_SIDE_DATA_FLAG_UNIQUE);

___
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 2/4] fftools/ffmpeg_enc: only promote first frame side data to global when meaningful

2024-03-23 Thread Anton Khirnov
Skip those side data types that do not make sense as global side data.
---
 fftools/ffmpeg_enc.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f01be1c22f..6a91fd0398 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -247,6 +247,11 @@ int enc_open(void *opaque, const AVFrame *frame)
 enc_ctx->chroma_sample_location = frame->chroma_location;
 
 for (int i = 0; i < frame->nb_side_data; i++) {
+const AVSideDataDescriptor *desc = 
av_frame_side_data_desc(frame->side_data[i]->type);
+
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_GLOBAL))
+continue;
+
 ret = av_frame_side_data_clone(
 _ctx->decoded_side_data, _ctx->nb_decoded_side_data,
 frame->side_data[i], AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
-- 
2.43.0

___
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/4] lavu/frame: add side data descriptors

2024-03-23 Thread Anton Khirnov
They allow exporting extended information about side data types.
---
 doc/APIchanges  |  4 +++
 libavutil/frame.c   | 70 ++---
 libavutil/frame.h   | 27 +
 libavutil/version.h |  2 +-
 4 files changed, 72 insertions(+), 31 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index a025f1df14..8794380e11 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,10 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-03-xx - xx - lavu 59.4.100 - frame.h
+  Add AVSideDataDescriptor, enum AVSideDataProps, and
+  av_frame_side_data_desc().
+
 2024-03-xx - xx - lavc 61.2.100 - avcodec.h
   Add AVCodecContext.[nb_]decoded_side_data.
 
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 89db687d9c..cb9af6326d 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -28,6 +28,36 @@
 #include "samplefmt.h"
 #include "hwcontext.h"
 
+static const AVSideDataDescriptor sd_props[] = {
+[AV_FRAME_DATA_PANSCAN] = { "AVPanScan" },
+[AV_FRAME_DATA_A53_CC]  = { "ATSC A53 Part 4 Closed 
Captions" },
+[AV_FRAME_DATA_MATRIXENCODING]  = { "AVMatrixEncoding" },
+[AV_FRAME_DATA_DOWNMIX_INFO]= { "Metadata relevant to a 
downmix procedure" },
+[AV_FRAME_DATA_AFD] = { "Active format 
description" },
+[AV_FRAME_DATA_MOTION_VECTORS]  = { "Motion vectors" },
+[AV_FRAME_DATA_SKIP_SAMPLES]= { "Skip samples" },
+[AV_FRAME_DATA_GOP_TIMECODE]= { "GOP timecode" },
+[AV_FRAME_DATA_S12M_TIMECODE]   = { "SMPTE 12-1 timecode" },
+[AV_FRAME_DATA_DYNAMIC_HDR_PLUS]= { "HDR Dynamic Metadata 
SMPTE2094-40 (HDR10+)" },
+[AV_FRAME_DATA_DYNAMIC_HDR_VIVID]   = { "HDR Dynamic Metadata CUVA 
005.1 2021 (Vivid)" },
+[AV_FRAME_DATA_REGIONS_OF_INTEREST] = { "Regions Of Interest" },
+[AV_FRAME_DATA_VIDEO_ENC_PARAMS]= { "Video encoding 
parameters" },
+[AV_FRAME_DATA_FILM_GRAIN_PARAMS]   = { "Film grain parameters" },
+[AV_FRAME_DATA_DETECTION_BBOXES]= { "Bounding boxes for object 
detection and classification" },
+[AV_FRAME_DATA_DOVI_RPU_BUFFER] = { "Dolby Vision RPU Data" },
+[AV_FRAME_DATA_DOVI_METADATA]   = { "Dolby Vision Metadata" },
+[AV_FRAME_DATA_STEREO3D]= { "Stereo 3D",   
 AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_REPLAYGAIN]  = { "AVReplayGain",
 AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_DISPLAYMATRIX]   = { "3x3 displaymatrix",   
 AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_AUDIO_SERVICE_TYPE]  = { "Audio service type",  
 AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_MASTERING_DISPLAY_METADATA]  = { "Mastering display 
metadata",   AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_CONTENT_LIGHT_LEVEL] = { "Content light level 
metadata", AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT] = { "Ambient viewing 
environment",  AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_SPHERICAL]   = { "Spherical Mapping",   
 AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_ICC_PROFILE] = { "ICC profile", 
 AV_SIDE_DATA_PROP_GLOBAL },
+[AV_FRAME_DATA_SEI_UNREGISTERED]= { "H.26[45] User Data 
Unregistered SEI message",  AV_SIDE_DATA_PROP_MULTI },
+};
+
 static void get_frame_defaults(AVFrame *frame)
 {
 memset(frame, 0, sizeof(*frame));
@@ -895,38 +925,18 @@ void av_frame_remove_side_data(AVFrame *frame, enum 
AVFrameSideDataType type)
 remove_side_data(>side_data, >nb_side_data, type);
 }
 
+const AVSideDataDescriptor *av_frame_side_data_desc(enum AVFrameSideDataType 
type)
+{
+unsigned t = type;
+if (t < FF_ARRAY_ELEMS(sd_props) && sd_props[t].name)
+return _props[t];
+return NULL;
+}
+
 const char *av_frame_side_data_name(enum AVFrameSideDataType type)
 {
-switch(type) {
-case AV_FRAME_DATA_PANSCAN: return "AVPanScan";
-case AV_FRAME_DATA_A53_CC:  return "ATSC A53 Part 4 Closed 
Captions";
-case AV_FRAME_DATA_STEREO3D:return "Stereo 3D";
-case AV_FRAME_DATA_MATRIXENCODING:  return "AVMatrixEncoding";
-case AV_FRAME_DATA_DOWNMIX_INFO:return "Metadata relevant to a downmix 
procedure";
-case AV_FRAME_DATA_REPLAYGAIN:  return "AVReplayGain";
-case AV_FRAME_DATA_DISPLAYMATRIX:   return "3x3 displaymatrix";
-case AV_FRAME_DATA_AFD: return "Active format description";
-case AV_FRAME_DATA_MOTION_VECTORS:  return "Motion vectors";
-case 

[FFmpeg-devel] [PATCH 3/4] fftools/ffmpeg_enc: move decoded_side_data setup out of video-only block

2024-03-23 Thread Anton Khirnov
Nothing about this code is video-specific.
---
 fftools/ffmpeg_enc.c | 41 +
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 6a91fd0398..61310c67f1 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -187,6 +187,27 @@ int enc_open(void *opaque, const AVFrame *frame)
 if (frame) {
 av_assert0(frame->opaque_ref);
 fd = (FrameData*)frame->opaque_ref->data;
+
+for (int i = 0; i < frame->nb_side_data; i++) {
+const AVSideDataDescriptor *desc = 
av_frame_side_data_desc(frame->side_data[i]->type);
+
+if (!desc || !(desc->props & AV_SIDE_DATA_PROP_GLOBAL))
+continue;
+
+ret = av_frame_side_data_clone(_ctx->decoded_side_data,
+   _ctx->nb_decoded_side_data,
+   frame->side_data[i],
+   AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
+if (ret < 0) {
+av_frame_side_data_free(
+_ctx->decoded_side_data,
+_ctx->nb_decoded_side_data);
+av_log(NULL, AV_LOG_ERROR,
+"failed to configure video encoder: %s!\n",
+av_err2str(ret));
+return ret;
+}
+}
 }
 
 ret = set_encoder_id(of, ost);
@@ -246,26 +267,6 @@ int enc_open(void *opaque, const AVFrame *frame)
 enc_ctx->colorspace = frame->colorspace;
 enc_ctx->chroma_sample_location = frame->chroma_location;
 
-for (int i = 0; i < frame->nb_side_data; i++) {
-const AVSideDataDescriptor *desc = 
av_frame_side_data_desc(frame->side_data[i]->type);
-
-if (!desc || !(desc->props & AV_SIDE_DATA_PROP_GLOBAL))
-continue;
-
-ret = av_frame_side_data_clone(
-_ctx->decoded_side_data, _ctx->nb_decoded_side_data,
-frame->side_data[i], AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
-if (ret < 0) {
-av_frame_side_data_free(
-_ctx->decoded_side_data,
-_ctx->nb_decoded_side_data);
-av_log(NULL, AV_LOG_ERROR,
-"failed to configure video encoder: %s!\n",
-av_err2str(ret));
-return ret;
-}
-}
-
 if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | 
AV_CODEC_FLAG_INTERLACED_ME) ||
 (frame->flags & AV_FRAME_FLAG_INTERLACED)
 #if FFMPEG_OPT_TOP
-- 
2.43.0

___
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 4/4] fftools/ffmpeg_enc: simplify error handling for decoded_side_data setup

2024-03-23 Thread Anton Khirnov
There is no need to free the already-added items, they will be freed
alongside the codec context. There is also little point in an error
message, as the only reason this can fail is malloc failure.
---
 fftools/ffmpeg_enc.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 61310c67f1..9103fb74c0 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -198,15 +198,8 @@ int enc_open(void *opaque, const AVFrame *frame)
_ctx->nb_decoded_side_data,
frame->side_data[i],
AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
-if (ret < 0) {
-av_frame_side_data_free(
-_ctx->decoded_side_data,
-_ctx->nb_decoded_side_data);
-av_log(NULL, AV_LOG_ERROR,
-"failed to configure video encoder: %s!\n",
-av_err2str(ret));
+if (ret < 0)
 return ret;
-}
 }
 }
 
-- 
2.43.0

___
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".


Re: [FFmpeg-devel] [PATCH] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.

2024-03-23 Thread Damiano Galassi
On Sat, Mar 23, 2024 at 1:11 PM Niklas Haas  wrote:

> On Fri, 22 Mar 2024 22:02:39 +0100 Damiano Galassi 
> wrote:
> > There two new fields were never sent down the filter chain, and no
> filter after the first had colorspace and color_range set, causing breakage
> in zscale and possible other filters.
> > ---
> >  libavfilter/avfilter.c  | 4 
> >  libavfilter/buffersrc.c | 2 ++
> >  2 files changed, 6 insertions(+)
> >
> > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> > index 831871de90..153fb700d3 100644
> > --- a/libavfilter/avfilter.c
> > +++ b/libavfilter/avfilter.c
> > @@ -391,6 +391,10 @@ int ff_filter_config_links(AVFilterContext *filter)
> >  link->w = inlink->w;
> >  if (!link->h)
> >  link->h = inlink->h;
> > +if (link->colorspace == AVCOL_SPC_UNSPECIFIED)
> > +link->colorspace = inlink->color_range;
> > +if (link->color_range == AVCOL_RANGE_UNSPECIFIED)
> > +link->color_range = inlink->color_range;
> >  } else if (!link->w || !link->h) {
> >  av_log(link->src, AV_LOG_ERROR,
> > "Video source filters must set their output
> link's "
> > diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
> > index ddcd403785..2760097edf 100644
> > --- a/libavfilter/buffersrc.c
> > +++ b/libavfilter/buffersrc.c
> > @@ -499,6 +499,8 @@ static int config_props(AVFilterLink *link)
> >  link->w = c->w;
> >  link->h = c->h;
> >  link->sample_aspect_ratio = c->pixel_aspect;
> > +link->colorspace = c->color_space;
> > +link->color_range = c->color_range;
> >
> >  if (c->hw_frames_ctx) {
> >  link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx);
>
> LGTM, good catch!
>

Unfortunately it breaks some tests:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240322210239.68833-1-dam...@gmail.com/
I didn't check yet what's going on there.
___
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".


Re: [FFmpeg-devel] [PATCH 2/6] avfilter/af_channelmap: fix mapping if in_channel was a string but out_channel was not specified

2024-03-23 Thread Paul B Mahol
Please add coverage for regression cases in FATE.
___
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 2/2] avformat/file: Combine all CONFIG_ANDROID_CONTENT_PROTOCOL blocks

2024-03-23 Thread Andreas Rheinhardt
Besides improving readability this also ensures that
a developer who has the android content protocol enabled
and works on the other parts of the file will not
forget to add necessary inclusions just because of
(indirect) inclusions from the files included only
when said protocol is enabled.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/file.c | 36 +++-
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/libavformat/file.c b/libavformat/file.c
index 8f3b35c795..182995717a 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -40,12 +40,6 @@
 #include 
 #include "os_support.h"
 #include "url.h"
-#if CONFIG_ANDROID_CONTENT_PROTOCOL
-#include 
-#include "libavcodec/jni.h"
-#include "libavcodec/ffjni.c"
-#endif
-
 
 /* Some systems may not have S_ISFIFO */
 #ifndef S_ISFIFO
@@ -107,21 +101,6 @@ typedef struct FileContext {
 int64_t initial_pos;
 } FileContext;
 
-
-#if CONFIG_ANDROID_CONTENT_PROTOCOL
-static const AVOption android_content_options[] = {
-{ "blocksize", "set I/O operation maximum block size", 
offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
-{ NULL }
-};
-
-static const AVClass android_content_class = {
-.class_name = "android_content",
-.item_name  = av_default_item_name,
-.option = android_content_options,
-.version= LIBAVUTIL_VERSION_INT,
-};
-#endif
-
 static const AVOption file_options[] = {
 { "truncate", "truncate existing files on write", offsetof(FileContext, 
trunc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
 { "blocksize", "set I/O operation maximum block size", 
offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
@@ -547,6 +526,9 @@ const URLProtocol ff_fd_protocol = {
 #endif /* CONFIG_FD_PROTOCOL */
 
 #if CONFIG_ANDROID_CONTENT_PROTOCOL
+#include 
+#include "libavcodec/jni.h"
+#include "libavcodec/ffjni.c"
 
 typedef struct JFields {
 jclass uri_class;
@@ -670,6 +652,18 @@ done:
 return ret;
 }
 
+static const AVOption android_content_options[] = {
+{ "blocksize", "set I/O operation maximum block size", 
offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+{ NULL }
+};
+
+static const AVClass android_content_class = {
+.class_name = "android_content",
+.item_name  = av_default_item_name,
+.option = android_content_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
 const URLProtocol ff_android_content_protocol = {
 .name= "content",
 .url_open= android_content_open,
-- 
2.40.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/file: Constify android content protocol

2024-03-23 Thread Andreas Rheinhardt
(The discrepancy between the definition and the declaration
in protocols.c is actually UB.)

Signed-off-by: Andreas Rheinhardt 
---
This and the next patch have not been tested (apart from "it compiles
when the android content protocol is disabled").

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

diff --git a/libavformat/file.c b/libavformat/file.c
index dd5819c06f..8f3b35c795 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -670,7 +670,7 @@ done:
 return ret;
 }
 
-URLProtocol ff_android_content_protocol = {
+const URLProtocol ff_android_content_protocol = {
 .name= "content",
 .url_open= android_content_open,
 .url_read= file_read,
-- 
2.40.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 2/2] avcodec/mpegutils: Simplify indenting

2024-03-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index 7f499b3d0f..d94e8f422f 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -265,7 +265,7 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame 
*pict,
 margin_left++;
 
 av_bprint_init(, 1, AV_BPRINT_SIZE_UNLIMITED);
-av_bprintf(, "%*s", margin_left, " ");
+av_bprint_chars(, ' ', margin_left);
 
 n = 0;
 if (avctx->debug & FF_DEBUG_SKIP)
-- 
2.40.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] avcodec/mpegutils: Avoid allocations when using AVBPrint

2024-03-23 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegutils.c | 21 +
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index fc3e270631..7f499b3d0f 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -252,7 +252,6 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame 
*pict,
 if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
 int x,y;
 AVBPrint buf;
-char *str = NULL;
 int n;
 int margin_left;
 int x_step;
@@ -278,16 +277,11 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame 
*pict,
 x_step = (mb_width * 16 > 999) ? 8 : 4;
 for (x = 0; x < mb_width; x += x_step)
 av_bprintf(, "%-*d", n * x_step, x << 4);
-n = av_bprint_finalize(, );
-if (n < 0) {
-av_log(avctx, AV_LOG_ERROR, "%s failed, %s\n", __func__, 
av_err2str(n));
-return;
-}
-av_log(avctx, AV_LOG_DEBUG, "%s\n", str);
-av_freep();
+
+av_log(avctx, AV_LOG_DEBUG, "%s\n", buf.str);
 
 for (y = 0; y < mb_height; y++) {
-av_bprint_init(, 1, AV_BPRINT_SIZE_UNLIMITED);
+av_bprint_clear();
 for (x = 0; x < mb_width; x++) {
 if (x == 0)
 av_bprintf(, "%*d ", margin_left - 1, y << 4);
@@ -310,13 +304,8 @@ void ff_print_debug_info2(AVCodecContext *avctx, AVFrame 
*pict,
 }
 }
 
-n = av_bprint_finalize(, );
-if (n < 0) {
-av_log(avctx, AV_LOG_ERROR, "%s failed, %s\n", __func__, 
av_err2str(n));
-return;
-}
-av_log(avctx, AV_LOG_DEBUG, "%s\n", str);
-av_freep();
+av_log(avctx, AV_LOG_DEBUG, "%s\n", buf.str);
 }
+av_bprint_finalize(, NULL);
 }
 }
-- 
2.40.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".


Re: [FFmpeg-devel] [PATCH] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.

2024-03-23 Thread Niklas Haas
On Fri, 22 Mar 2024 22:02:39 +0100 Damiano Galassi  wrote:
> There two new fields were never sent down the filter chain, and no filter 
> after the first had colorspace and color_range set, causing breakage in 
> zscale and possible other filters.
> ---
>  libavfilter/avfilter.c  | 4 
>  libavfilter/buffersrc.c | 2 ++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 831871de90..153fb700d3 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -391,6 +391,10 @@ int ff_filter_config_links(AVFilterContext *filter)
>  link->w = inlink->w;
>  if (!link->h)
>  link->h = inlink->h;
> +if (link->colorspace == AVCOL_SPC_UNSPECIFIED)
> +link->colorspace = inlink->color_range;
> +if (link->color_range == AVCOL_RANGE_UNSPECIFIED)
> +link->color_range = inlink->color_range;
>  } else if (!link->w || !link->h) {
>  av_log(link->src, AV_LOG_ERROR,
> "Video source filters must set their output 
> link's "
> diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
> index ddcd403785..2760097edf 100644
> --- a/libavfilter/buffersrc.c
> +++ b/libavfilter/buffersrc.c
> @@ -499,6 +499,8 @@ static int config_props(AVFilterLink *link)
>  link->w = c->w;
>  link->h = c->h;
>  link->sample_aspect_ratio = c->pixel_aspect;
> +link->colorspace = c->color_space;
> +link->color_range = c->color_range;
>  
>  if (c->hw_frames_ctx) {
>  link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx);

LGTM, good catch!
___
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".


Re: [FFmpeg-devel] [PATCH v3] configure: Explicitly check for static_assert, _Static_assert

2024-03-23 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> C11 provides static assertions via _Static_assert and
> provides static_assert as a convenience define for this
> in assert.h. Our codebase uses the latter, as _Static_assert
> has actually already been deprecated in C23.
> 
> Not all toolchains that declare support for C11 actually
> support it; e.g. MSVC 19.27 does not support _Static_assert,
> but somehow supports static_assert. MSVC 19.27 admits to be
> a "preview implementation of the ISO C11 standard",
> so this is not surprising (MSVC 19.28 does not come with
> this caveat).
> 
> Furthermore some FATE boxes [1] use old GCC toolchains (with
> only experimental support for C11) where _Static_assert is
> supported, but assert.h does not provide the fallback define.
> They are broken since the first usage of static_assert.
> 
> This commit therefore checks whether static_assert and
> _Static_assert work with assert.h included; if not,
> configure errors out.
> 
> This intentionally drops support for MSVC 19.27. Users like
> the old FATE boxes above can still add -Dstatic_assert=_Static_assert
> to cflags as a workaround if desired.
> 
> [1]: 
> https://fate.ffmpeg.org/report.cgi?time=20240321123620=sh4-debian-qemu-gcc-4.7
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  configure | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/configure b/configure
> index 343edb38ab..fc366549bc 100755
> --- a/configure
> +++ b/configure
> @@ -5589,6 +5589,19 @@ check_cxxflags_cc -std=$stdcxx ctype.h "__cplusplus >= 
> 201103L" ||
>  check_cflags_cc -std=$stdc ctype.h "__STDC_VERSION__ >= 201112L" ||
>  { check_cflags_cc -std=c11 ctype.h "__STDC_VERSION__ >= 201112L" && 
> stdc="c11" || die "Compiler lacks C11 support"; }
>  
> +test_cc < +#include 
> +#include 
> +struct Foo {
> +int a;
> +void *ptr;
> +} obj;
> +static_assert(offsetof(struct Foo, a) == 0,
> +  "First element of struct does not have offset 0");
> +_Static_assert(offsetof(struct Foo, ptr) >= offsetof(struct Foo, a) + 
> sizeof(obj.a),
> +   "elements not properly ordered in struct");
> +EOF
> +
>  check_cppflags -D_FILE_OFFSET_BITS=64
>  check_cppflags -D_LARGEFILE_SOURCE
>  

Will apply this patch tomorrow unless there are objections.

- Andreas

___
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".


Re: [FFmpeg-devel] [PATCH 1/6] avfilter/af_channelmap: fix error message if FL source channel was missing

2024-03-23 Thread Marton Balint



On Tue, 19 Mar 2024, Marton Balint wrote:


FL channel ID is 0, so for an unset value we must check for ID < 0.

Regression since 1f96db959c1235bb7079d354e09914a0a2608f62.


Will apply the series soon.

Regards,
Marton



Signed-off-by: Marton Balint 
---
libavfilter/af_channelmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c
index 5e1cf57680..d13dcc317d 100644
--- a/libavfilter/af_channelmap.c
+++ b/libavfilter/af_channelmap.c
@@ -165,7 +165,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx)

for (i = 0; i < map_entries; i++) {
int in_ch_idx = -1, out_ch_idx = -1;
-int in_ch = 0, out_ch = 0;
+int in_ch = -1, out_ch = -1;
static const char err[] = "Failed to parse channel map\n";
switch (mode) {
case MAP_ONE_INT:
@@ -349,7 +349,7 @@ static int channelmap_config_input(AVFilterLink *inlink)

if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) {
av_channel_layout_describe(>ch_layout, layout_name, 
sizeof(layout_name));
-if (m->in_channel) {
+if (m->in_channel >= 0) {
av_channel_name(channel_name, sizeof(channel_name), 
m->in_channel);
av_log(ctx, AV_LOG_ERROR,
   "input channel '%s' not available from input layout 
'%s'\n",
--
2.35.3

___
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 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".


Re: [FFmpeg-devel] [PATCH] avformat/mov_chan: respect channel order when parsing and creating chan atom

2024-03-23 Thread Marton Balint




On Mon, 18 Mar 2024, Marton Balint wrote:




On Mon, 18 Mar 2024, Andreas Rheinhardt wrote:


 Marton Balint:

 Previously we always assumed that the channels are in native order, even
 if
 they were not. The new channel layout API allows us to signal the proper
 channel order, so let's do so.

 Fixes ticket #98.
 ---
  libavformat/mov_chan.c | 464 +++--
  1 file changed, 211 insertions(+), 253 deletions(-)



[...]


 +#define TAG(_0)  (struct
 MovChannelLayoutMap){.tag = _0}
 +#define ID(_0)   (struct
 MovChannelLayoutMap){.id = c_##_0}


 Code like

 typedef struct Foo {
int a;
 } Foo;

 Foo bar[] = {
(Foo) {.a = 1},
 };

 is not valid C11 (or C17), because initializers for static objects are
 subject to severe restrictions; in particular, compound literals are not
 allowed. GCC and Clang ignore this except when using -pedantic, but MSVC
 does not: https://godbolt.org/z/hvnrh63za
 Just remove the "(MovChannelLayoutMap)".


Ok, will do, thanks.


Will apply.

Regards,
Marton
___
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] avutil/timestamp: change precision of av_ts_make_time_string()

2024-03-23 Thread Marton Balint
By calling the av_ts_make_time_string2() from the function we can fix the
precision issue.

Signed-off-by: Marton Balint 
---
 libavutil/timestamp.h|  4 +---
 tests/ref/fate/filter-metadata-scdet | 12 ++--
 tests/ref/fate/filter-metadata-silencedetect |  2 +-
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/libavutil/timestamp.h b/libavutil/timestamp.h
index 7e6da894df..fa53a46b98 100644
--- a/libavutil/timestamp.h
+++ b/libavutil/timestamp.h
@@ -73,9 +73,7 @@ char *av_ts_make_time_string2(char *buf, int64_t ts, 
AVRational tb);
 static inline char *av_ts_make_time_string(char *buf, int64_t ts,
const AVRational *tb)
 {
-if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
-else  snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6g", 
av_q2d(*tb) * ts);
-return buf;
+return av_ts_make_time_string2(buf, ts, *tb);
 }
 
 /**
diff --git a/tests/ref/fate/filter-metadata-scdet 
b/tests/ref/fate/filter-metadata-scdet
index ca5dbaaefc..d385920fcd 100644
--- a/tests/ref/fate/filter-metadata-scdet
+++ b/tests/ref/fate/filter-metadata-scdet
@@ -1,11 +1,11 @@
 
pts=1620|tag:lavfi.scd.score=59.252|tag:lavfi.scd.mafd=60.175|tag:lavfi.scd.time=2.7
 
pts=4140|tag:lavfi.scd.score=36.070|tag:lavfi.scd.mafd=44.209|tag:lavfi.scd.time=6.9
-pts=5800|tag:lavfi.scd.score=55.819|tag:lavfi.scd.mafd=55.819|tag:lavfi.scd.time=9.7
+pts=5800|tag:lavfi.scd.score=55.819|tag:lavfi.scd.mafd=55.819|tag:lavfi.scd.time=9.67
 
pts=6720|tag:lavfi.scd.score=18.580|tag:lavfi.scd.mafd=22.505|tag:lavfi.scd.time=11.2
 
pts=8160|tag:lavfi.scd.score=49.240|tag:lavfi.scd.mafd=49.444|tag:lavfi.scd.time=13.6
-pts=9760|tag:lavfi.scd.score=51.497|tag:lavfi.scd.mafd=51.801|tag:lavfi.scd.time=16.2667
-pts=14080|tag:lavfi.scd.score=34.165|tag:lavfi.scd.mafd=34.337|tag:lavfi.scd.time=23.4667
-pts=15700|tag:lavfi.scd.score=58.310|tag:lavfi.scd.mafd=58.315|tag:lavfi.scd.time=26.1667
-pts=18500|tag:lavfi.scd.score=16.504|tag:lavfi.scd.mafd=19.603|tag:lavfi.scd.time=30.8333
+pts=9760|tag:lavfi.scd.score=51.497|tag:lavfi.scd.mafd=51.801|tag:lavfi.scd.time=16.27
+pts=14080|tag:lavfi.scd.score=34.165|tag:lavfi.scd.mafd=34.337|tag:lavfi.scd.time=23.47
+pts=15700|tag:lavfi.scd.score=58.310|tag:lavfi.scd.mafd=58.315|tag:lavfi.scd.time=26.17
+pts=18500|tag:lavfi.scd.score=16.504|tag:lavfi.scd.mafd=19.603|tag:lavfi.scd.time=30.83
 
pts=20040|tag:lavfi.scd.score=13.764|tag:lavfi.scd.mafd=19.060|tag:lavfi.scd.time=33.4
-pts=21760|tag:lavfi.scd.score=64.451|tag:lavfi.scd.mafd=64.551|tag:lavfi.scd.time=36.2667
+pts=21760|tag:lavfi.scd.score=64.451|tag:lavfi.scd.mafd=64.551|tag:lavfi.scd.time=36.27
diff --git a/tests/ref/fate/filter-metadata-silencedetect 
b/tests/ref/fate/filter-metadata-silencedetect
index bc53fea047..e66ffe5fdd 100644
--- a/tests/ref/fate/filter-metadata-silencedetect
+++ b/tests/ref/fate/filter-metadata-silencedetect
@@ -1,5 +1,5 @@
 
pts=0|tag:lavfi.silence_duration=0.523107|tag:lavfi.silence_end=0.690023|tag:lavfi.silence_start=0.736417
-pts=46080|tag:lavfi.silence_start=1.27626|tag:lavfi.silence_end=1.80751|tag:lavfi.silence_duration=0.531247
+pts=46080|tag:lavfi.silence_start=1.276259|tag:lavfi.silence_end=1.807506|tag:lavfi.silence_duration=0.531247
 pts=92160
 pts=138240
 pts=184320
-- 
2.35.3

___
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] avutil/timestamp: introduce av_ts_make_time_string2 for better precision

2024-03-23 Thread Marton Balint
av_ts_make_time_string() used "%.6g" format, but this format was losing
precision even when the timestamp to be printed was not that large. For example
for 3 hours (10800) seconds, only 1 decimal digit was printed, which made this
format inaccurate when it was used in e.g. the silencedetect filter. Other
detection filters printing timestamps had similar issues. Also time base
parameter of the function was *AVRational instead of AVRational.

Resolve these problems by introducing a new function, av_ts_make_time_string2().

We change the used format to "%.*f", use a precision of 6, except when printing
values near 0, in which case we calculate the precision dynamically to aim for
a similar precision in normal form as with %.6g.  No longer using scientific
representation can make parsing the timestamp easier for the users, we can
safely do this because the theoretical maximum of INT64_MAX*INT32_MAX still
fits into the string buffer in normal form.

We somewhat imitate %g by trimming ending zeroes and the potential decimal
point characters. In order not to trim "inf" as well, we assume that the
decimal point string does not contain the letter "f". Note that depending on
printf %f implementation, we might trim "infinity" to "inf".

Thanks for Allan Cady for bringing up this issue.

Signed-off-by: Marton Balint 
---
 doc/APIchanges|  5 +
 libavutil/Makefile|  1 +
 libavutil/timestamp.c | 36 
 libavutil/timestamp.h |  8 
 libavutil/version.h   |  2 +-
 5 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/timestamp.c

diff --git a/doc/APIchanges b/doc/APIchanges
index 2796b4d0c2..9c6fa381e1 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-03-xx - xx - lavu 59.5.100 - timestamp.h
+  Add av_ts_make_time_string2() for better timestamp precision, the new
+  function accepts AVRational as time base instead of *AVRational, and is not
+  an inline function like its predecessor.
+
 2024-03-xx - xx - lavc 61.3.100 - jni.h
   Add av_jni_set_android_app_ctx() and av_jni_get_android_app_ctx().
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 008fcfcd9c..6e6fa8d800 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -174,6 +174,7 @@ OBJS = adler32.o
\
threadmessage.o  \
time.o   \
timecode.o   \
+   timestamp.o  \
tree.o   \
twofish.o\
utils.o  \
diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c
new file mode 100644
index 00..2a3e3012a4
--- /dev/null
+++ b/libavutil/timestamp.c
@@ -0,0 +1,36 @@
+/*
+ * 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 "timestamp.h"
+
+char *av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb)
+{
+if (ts == AV_NOPTS_VALUE) {
+snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
+} else {
+double val = av_q2d(tb) * ts;
+double log = floor(log10(fabs(val)));
+int precision = (isfinite(log) && log < 0) ? -log + 5 : 6;
+int last = snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.*f", precision, 
val);
+last = FFMIN(last, AV_TS_MAX_STRING_SIZE - 1) - 1;
+for (; last && buf[last] == '0'; last--);
+for (; last && buf[last] != 'f' && (buf[last] < '0' || buf[0] > '9'); 
last--);
+buf[last + 1] = '\0';
+}
+return buf;
+}
diff --git a/libavutil/timestamp.h b/libavutil/timestamp.h
index 2b37781eba..7e6da894df 100644
--- a/libavutil/timestamp.h
+++ b/libavutil/timestamp.h
@@ -62,6 +62,14 @@ static inline char *av_ts_make_string(char *buf, int64_t ts)
  * @param tb the timebase of the timestamp
  * @return the buffer in input
  */
+char *av_ts_make_time_string2(char *buf, 

Re: [FFmpeg-devel] [PATCH 3/4] doc/muxers: add gxf

2024-03-23 Thread Stefano Sabatini
On date Wednesday 2024-03-20 17:47:31 +0100, Andreas Rheinhardt wrote:
> Stefano Sabatini:
> > ---
> >  doc/muxers.texi | 10 ++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > index d9dd72e613..25d1a5907e 100644
> > --- a/doc/muxers.texi
> > +++ b/doc/muxers.texi
> > @@ -1776,6 +1776,16 @@ force the @ref{image2} muxer:
> >  ffmpeg -i INPUT -c:v gif -f image2 "out%d.gif"
> >  @end example
> >  
> > +@section gxf
> > +General eXchange Format (GXF) muxer.
> > +
> > +GXF was developed by Grass Valley Group, then standardized by SMPTE as 
> > SMPTE
> > +360M and was extended in SMPTE RDD 14-2007 to include high-definition video
> > +resolutions.
> > +
> > +It accepts an arbitrary number of audio and video streams, but only a 
> > limited
> 
> It only accepts a single video stream, see the check in line 734 of
> gxfenc.c.

Correct, amended and pushed together with the other pending doc patches, thanks.
___
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".


Re: [FFmpeg-devel] Add protocol for Android content providers (v4)

2024-03-23 Thread Matthieu Bouron
On Tue, Mar 19, 2024 at 06:49:43PM +0100, Matthieu Bouron wrote:
> On Sun, Mar 17, 2024 at 11:28:31PM +0100, Matthieu Bouron wrote:
> > Diff with previous iteration:
> > - rebaed on latest master
> > - applied feedback from Zhao (removed HAVE_SETMODE block, use a typedef 
> > struct,
> >   check that the fd is seekable, moved doc/APIChanges changes to the right
> >   commit)
> > 
> 
> I will push the patchset in a few days if there is no other comment (nor
> any objection).

Patchset applied (with a few rewords on the commit msgs).

-- 
Matthieu B.
___
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".


Re: [FFmpeg-devel] [PATCH v2] Changelog: Add libtorch

2024-03-23 Thread Stefano Sabatini
On date Thursday 2024-03-21 10:46:30 +0800, wenbin.chen-at-intel@ffmpeg.org 
wrote:
> From: Wenbin Chen 
> 
> Signed-off-by: Wenbin Chen 
> ---
>  Changelog | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Changelog b/Changelog
> index e3ca52430c..4af55ff537 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -35,6 +35,7 @@ version :
>  - AEA muxer
>  - ffmpeg CLI loopback decoders
>  - Support PacketTypeMetadata of PacketType in enhanced flv format
> +- dnn filter libtorch backend

will apply, thanks
___
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".


Re: [FFmpeg-devel] [PATCH 10/12] lavc/encode: map AVCodecContext.decoded_side_data to coded_side_data

2024-03-23 Thread Anton Khirnov
Quoting James Almer (2024-03-23 03:33:13)
> Why does this test change? And is it just the order or side data in the 
> output frame?

Yes, just the order. And the test is being removed, so it doesn't matter
either way.

-- 
Anton Khirnov
___
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".


Re: [FFmpeg-devel] [PATCH 06/12] fftools/ffmpeg_dec: apply cropping manually

2024-03-23 Thread Anton Khirnov
Quoting James Almer (2024-03-23 03:53:26)
> On 3/22/2024 5:28 PM, Anton Khirnov wrote:
> > lavfi does not require aligned buffers, so we can safely apply top/left
> > cropping by any amount, without passing any special flags to lavc.
> > Longer term, an even better solution would probably be auto-inserting
> > the crop filter (or its hwaccel versions) as needed.
> 
> It's what i did in my container cropping set. One problem with it is 
> that the cropping filter doesn't look at cropping values in input frames 
> but at filter options instead, and will in fact *add* cropping values to 
> the output frames if you pass it something it can't handle, like hwaccel 
> formats.

The idea is that ffmpeg_filter would set up the crop filter, then remove
the values from the frame. The crop filter then either actually performs
cropping or adds them back.

> And for that matter, cropping fields in frames should be handled by 
> encoders, or by the generic encoding code in some form. Right now they 
> are outright ignored.

Sure I guess. Patches welcome?

-- 
Anton Khirnov
___
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".