[FFmpeg-devel] [PATCH] intreadwrite: Indicate potential aliasing in AV_RN/AV_WN for Clang/MSVC mode

2023-08-02 Thread Martin Storsjö
While MSVC proper doesn't have a way to signal potential aliasing
corresponding to __attribute__((may_alias)) (which is what
av_alias expands to, if supported), Clang does support it.

When building with Clang in MSVC mode, __GNUC__ isn't defined but
_MSC_VER is, so Clang uses the MSVC implementation of AV_RN/AV_WN
which uses __unaligned.

Add the av_alias macro there, to indicate that the reads/writes can
alias other writes. Adding the attribute within the cast itself
doesn't seem to have any effect, it only has an effect if added in
a type definition.

Alternatively the __GNUC__ specific codepath right above could also
be used whenever __clang__ is defined; numerous __GNUC__ checks
also separately check for __clang__ to use them when building with
Clang in MSVC mode.

This fixes a couple HEVC decoder tests when built with Clang 14 or
newer in MSVC mode (with issues observed on all of x86_64, armv7
and aarch64).
---
 libavutil/intreadwrite.h | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavutil/intreadwrite.h b/libavutil/intreadwrite.h
index c4679fdba4..126ac3c7f8 100644
--- a/libavutil/intreadwrite.h
+++ b/libavutil/intreadwrite.h
@@ -224,8 +224,12 @@ union unaligned_16 { uint16_t l; } __attribute__((packed)) 
av_alias;
 
 #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_X64) || 
defined(_M_ARM64)) && AV_HAVE_FAST_UNALIGNED
 
-#   define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p)))
-#   define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v))
+typedef __unaligned uint64_t av_alias unaligned_64;
+typedef __unaligned uint32_t av_alias unaligned_32;
+typedef __unaligned uint16_t av_alias unaligned_16;
+
+#   define AV_RN(s, p) (*((const unaligned_##s*)(p)))
+#   define AV_WN(s, p, v) (*((unaligned_##s*)(p)) = (v))
 
 #elif AV_HAVE_FAST_UNALIGNED
 
-- 
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] tests: Correctly distinguish between SAMPLES and TARGET_SAMPLES for hls_fmp4_ac3.m3u8

2023-08-02 Thread Martin Storsjö
This fixes the test when running in a cross test setup where the
samples are located at a different path between build host and
temote test target.
---
 tests/fate/hlsenc.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/fate/hlsenc.mak b/tests/fate/hlsenc.mak
index 7df74f1f63..8118d5b925 100644
--- a/tests/fate/hlsenc.mak
+++ b/tests/fate/hlsenc.mak
@@ -100,7 +100,7 @@ fate-hls-fmp4: CMD = framecrc -auto_conversion_filters 
-flags +bitexact -i $(TAR
 tests/data/hls_fmp4_ac3.m3u8: TAG = GEN
 tests/data/hls_fmp4_ac3.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin \
-   -stream_loop 4 -i $(SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 -c copy 
-map 0 \
+   -stream_loop 4 -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 
-c copy -map 0 \
-hls_segment_type fmp4 -hls_fmp4_init_filename now_ac3.mp4 
-hls_list_size 0 \
-hls_time 2 -hls_segment_filename 
"$(TARGET_PATH)/tests/data/hls_fmp4_ac3_%d.m4s" \
$(TARGET_PATH)/tests/data/hls_fmp4_ac3.m3u8 2>/dev/null
-- 
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] w32pthreads: Fix function signature mismatches for CreateThread

2023-08-02 Thread Martin Storsjö
In WinRT mode, we use CreateThread instead of _beginthreadex.

CreateThread takes a LPTHREAD_START_ROUTINE function pointer,
which has got the signature DWORD WINAPI ThreadProc(LPVOID).
_beginthreadex takes a function with the signature
unsigned __stdcall func(void *).

DWORD is defined as an unsigned long, which is different type
from unsigned int, even if they have the same size on Windows.

This fixes build failures with Clang 16 and newer, where function
pointer type mismatches are a fatal error by default.
---
 compat/w32pthreads.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
index 6405e72b64..dae8d9420d 100644
--- a/compat/w32pthreads.h
+++ b/compat/w32pthreads.h
@@ -66,7 +66,14 @@ typedef CONDITION_VARIABLE pthread_cond_t;
 #define PTHREAD_CANCEL_ENABLE 1
 #define PTHREAD_CANCEL_DISABLE 0
 
-static av_unused unsigned __stdcall attribute_align_arg 
win32thread_worker(void *arg)
+#if HAVE_WINRT
+#define THREADFUNC_RETTYPE DWORD
+#else
+#define THREADFUNC_RETTYPE unsigned
+#endif
+
+static av_unused THREADFUNC_RETTYPE
+__stdcall attribute_align_arg win32thread_worker(void *arg)
 {
 pthread_t *h = (pthread_t*)arg;
 h->ret = h->func(h->arg);
-- 
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] libswresample: Prevent out of bounds.

2023-08-02 Thread kobrineli
From: Eli Kobrin 

We've been fuzzing torchvision with 
[sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)
and found out of bounds error in ffmpeg project at audioconvert.c:51.
To prevent error we need to insert corresponding check.

Signed-off-by: Eli Kobrin 
---
 libswresample/audioconvert.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
index 1d75ba1495..701f4808a0 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat 
out_fmt,
int flags)
 {
 AudioConvert *ctx;
-conv_func_type *f = 
fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + 
AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];
+
+size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB * 
av_get_packed_sample_fmt(in_fmt);
+if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
+return NULL;
+
+conv_func_type *f = fmt_pair_to_conv_functions[idx];
 
 if (!f)
 return NULL;
-- 
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".


Re: [FFmpeg-devel] [PATCH] libswresample: Prevent out of bounds.

2023-08-02 Thread Andreas Rheinhardt
kobrineli:
> From: Eli Kobrin 
> 
> We've been fuzzing torchvision with 
> [sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)
> and found out of bounds error in ffmpeg project at audioconvert.c:51.
> To prevent error we need to insert corresponding check.
> 
> Signed-off-by: Eli Kobrin 
> ---
>  libswresample/audioconvert.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
> index 1d75ba1495..701f4808a0 100644
> --- a/libswresample/audioconvert.c
> +++ b/libswresample/audioconvert.c
> @@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum 
> AVSampleFormat out_fmt,
> int flags)
>  {
>  AudioConvert *ctx;
> -conv_func_type *f = 
> fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + 
> AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];
> +
> +size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB * 
> av_get_packed_sample_fmt(in_fmt);
> +if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
> +return NULL;
> +
> +conv_func_type *f = fmt_pair_to_conv_functions[idx];
>  
>  if (!f)
>  return NULL;

Something seems to be using an invalid sample format (either out_fmt or
in_fmt). You should investigate where this comes from.
(Given that this is a public function, we should probably validate user
input; and maybe stop using AV_SAMPLE_FMT_NB altogether.)

- 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 06/15] avcodec/avcodec: Remove unnecessary forward declaration

2023-08-02 Thread Andreas Rheinhardt
This would only be necessary if this header declared a function
that takes a (pointer to) struct AVCodecContext as parameter.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/avcodec.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index a2680256d7..649411ac79 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -421,8 +421,6 @@ typedef struct RcOverride{
  */
 #define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0)
 
-struct AVCodecInternal;
-
 /**
  * main external API structure.
  * New fields can be added to the end with minor version bumps.
-- 
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 13/15] avcodec/dirac: Include used headers directly

2023-08-02 Thread Andreas Rheinhardt
Don't include them implicitly via avcodec.h. This avoids
indirect avcodec.h inclusions in lavc/dirac.c, lavf/oggparsedirac.c,
and lavf/rtp(dec|enc)_vc2hq.c.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dirac.c | 3 +++
 libavcodec/dirac.h | 6 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dirac.c b/libavcodec/dirac.c
index bc51a2fbd7..4736304977 100644
--- a/libavcodec/dirac.c
+++ b/libavcodec/dirac.c
@@ -26,9 +26,12 @@
  * @author Marco Gerards , David Conrad, Jordi Ortiz 

  */
 
+#include "config.h"
+
 #include "libavutil/pixdesc.h"
 
 #include "dirac.h"
+#include "get_bits.h"
 #include "golomb.h"
 #include "mpeg12data.h"
 
diff --git a/libavcodec/dirac.h b/libavcodec/dirac.h
index e6d9d346d9..8c348cdc02 100644
--- a/libavcodec/dirac.h
+++ b/libavcodec/dirac.h
@@ -31,7 +31,11 @@
  * @author Jordi Ortiz
  */
 
-#include "avcodec.h"
+#include 
+#include 
+
+#include "libavutil/pixfmt.h"
+#include "libavutil/rational.h"
 
 /**
  * The spec limits the number of wavelet decompositions to 4 for both
-- 
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 14/15] avformat/rawdec: Don't include avcodec.h

2023-08-02 Thread Andreas Rheinhardt
Possible since 2850584876e52beaddf7a9f30e9914dad7115618.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/rawdec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index 6b623d366e..1dd7fafcf0 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -27,8 +27,6 @@
 #include "rawdec.h"
 #include "libavutil/opt.h"
 
-#include "libavcodec/avcodec.h"
-
 #define RAW_PACKET_SIZE 1024
 
 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
-- 
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 15/15] avcodec/h264_metadata_bsf: Improve included headers

2023-08-02 Thread Andreas Rheinhardt
h264_sei.h is no longer used since the SEIs were moved to sei.h;
this also avoids inclusions of avcodec.h and bytestream.h.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_metadata_bsf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index b9cfeaba94..39b9e8eee4 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -26,10 +26,11 @@
 #include "cbs.h"
 #include "cbs_bsf.h"
 #include "cbs_h264.h"
+#include "cbs_sei.h"
 #include "h264.h"
 #include "h264_levels.h"
-#include "h264_sei.h"
 #include "h2645data.h"
+#include "sei.h"
 
 enum {
 FLIP_HORIZONTAL = 1,
-- 
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 08/15] avcodec/tak: Use void* instead of AVCodecContext* for logcontext

2023-08-02 Thread Andreas Rheinhardt
Avoids implicit inclusions of avcodec.h in lavf/takdec.c
and lavc/tak.c.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/tak.c | 4 ++--
 libavcodec/tak.h | 5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/libavcodec/tak.c b/libavcodec/tak.c
index 99678e9887..91feac5451 100644
--- a/libavcodec/tak.c
+++ b/libavcodec/tak.c
@@ -144,11 +144,11 @@ int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const 
uint8_t *buf, int size)
 return tak_parse_streaminfo(s, &gb);
 }
 
-int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
+int ff_tak_decode_frame_header(void *logctx, GetBitContext *gb,
TAKStreamInfo *ti, int log_level_offset)
 {
 if (get_bits(gb, TAK_FRAME_HEADER_SYNC_ID_BITS) != 
TAK_FRAME_HEADER_SYNC_ID) {
-av_log(avctx, AV_LOG_ERROR + log_level_offset, "missing sync id\n");
+av_log(logctx, AV_LOG_ERROR + log_level_offset, "missing sync id\n");
 return AVERROR_INVALIDDATA;
 }
 
diff --git a/libavcodec/tak.h b/libavcodec/tak.h
index 5e43598de8..1d1ee645e8 100644
--- a/libavcodec/tak.h
+++ b/libavcodec/tak.h
@@ -29,7 +29,6 @@
 
 #include 
 
-#include "avcodec.h"
 #include "get_bits.h"
 
 #define TAK_FORMAT_DATA_TYPE_BITS   3
@@ -151,13 +150,13 @@ int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const 
uint8_t *buf, int size);
 
 /**
  * Validate and decode a frame header.
- * @param  avctx AVCodecContext to use as av_log() context
+ * @param  logctxfor use as av_log() context
  * @param[in]  gbGetBitContext from which to read frame header
  * @param[out] s frame information
  * @param  log_level_offset  log level offset, can be used to silence
  *   error messages.
  * @return non-zero on error, 0 if OK
  */
-int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
+int ff_tak_decode_frame_header(void *logctx, GetBitContext *gb,
TAKStreamInfo *s, int log_level_offset);
 #endif /* AVCODEC_TAK_H */
-- 
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 10/15] avformat/av1dec: Remove avcodec.h inclusion

2023-08-02 Thread Andreas Rheinhardt
Possible since 60ecf44b037c7961ac4e69f83ff315c11c5df922.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/av1dec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavformat/av1dec.c b/libavformat/av1dec.c
index d0d53f41f7..2883b320a1 100644
--- a/libavformat/av1dec.c
+++ b/libavformat/av1dec.c
@@ -23,7 +23,6 @@
 
 #include "libavutil/common.h"
 #include "libavutil/opt.h"
-#include "libavcodec/avcodec.h"
 #include "libavcodec/av1_parse.h"
 #include "libavcodec/bsf.h"
 #include "avformat.h"
-- 
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 11/15] avformat/evcdec: Remove unused headers

2023-08-02 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/evcdec.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 6cce174f46..5ace604db6 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -20,15 +20,11 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavcodec/get_bits.h"
-#include "libavcodec/golomb.h"
-#include "libavcodec/internal.h"
 #include "libavcodec/evc.h"
 #include "libavcodec/bsf.h"
 
 #include "libavutil/opt.h"
 
-#include "rawdec.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "evc.h"
-- 
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 09/15] avcodec/h264dec: Move inline functions only used by CABAC/CAVLC code

2023-08-02 Thread Andreas Rheinhardt
Most of the inline functions in h264dec.h are only used
by h264_cavlc.c and h264_cabac.c. Therefore move them
to the common header for these two, namely h264_mvpred.h.

Signed-off-by: Andreas Rheinhardt 
---
Does someone have a better name than h264_mvpred.h for the destination?

 libavcodec/h264_mb.c |   1 +
 libavcodec/h264_mvpred.h | 132 +++
 libavcodec/h264dec.h | 132 ---
 3 files changed, 133 insertions(+), 132 deletions(-)

diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c
index 0b31774556..32d29cfb4d 100644
--- a/libavcodec/h264_mb.c
+++ b/libavcodec/h264_mb.c
@@ -34,6 +34,7 @@
 #include "h264dec.h"
 #include "h264_ps.h"
 #include "qpeldsp.h"
+#include "rectangle.h"
 #include "threadframe.h"
 
 static inline int get_lowest_part_list_y(H264SliceContext *sl,
diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h
index 46ae2738f9..bc9fef50e4 100644
--- a/libavcodec/h264_mvpred.h
+++ b/libavcodec/h264_mvpred.h
@@ -30,10 +30,142 @@
 
 #include "h264dec.h"
 #include "mpegutils.h"
+#include "rectangle.h"
+
 #include "libavutil/avassert.h"
 #include "libavutil/mem_internal.h"
 
 
+/**
+ * Get the predicted intra4x4 prediction mode.
+ */
+static av_always_inline int pred_intra_mode(const H264Context *h,
+H264SliceContext *sl, int n)
+{
+const int index8 = scan8[n];
+const int left   = sl->intra4x4_pred_mode_cache[index8 - 1];
+const int top= sl->intra4x4_pred_mode_cache[index8 - 8];
+const int min= FFMIN(left, top);
+
+ff_tlog(h->avctx, "mode:%d %d min:%d\n", left, top, min);
+
+if (min < 0)
+return DC_PRED;
+else
+return min;
+}
+
+static av_always_inline void write_back_intra_pred_mode(const H264Context *h,
+H264SliceContext *sl)
+{
+int8_t *i4x4   = sl->intra4x4_pred_mode + h->mb2br_xy[sl->mb_xy];
+int8_t *i4x4_cache = sl->intra4x4_pred_mode_cache;
+
+AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
+i4x4[4] = i4x4_cache[7 + 8 * 3];
+i4x4[5] = i4x4_cache[7 + 8 * 2];
+i4x4[6] = i4x4_cache[7 + 8 * 1];
+}
+
+static av_always_inline void write_back_non_zero_count(const H264Context *h,
+   H264SliceContext *sl)
+{
+const int mb_xy= sl->mb_xy;
+uint8_t *nnz   = h->non_zero_count[mb_xy];
+uint8_t *nnz_cache = sl->non_zero_count_cache;
+
+AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]);
+AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]);
+AV_COPY32(&nnz[ 8], &nnz_cache[4 + 8 * 3]);
+AV_COPY32(&nnz[12], &nnz_cache[4 + 8 * 4]);
+AV_COPY32(&nnz[16], &nnz_cache[4 + 8 * 6]);
+AV_COPY32(&nnz[20], &nnz_cache[4 + 8 * 7]);
+AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
+AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
+
+if (!h->chroma_y_shift) {
+AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
+AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
+AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
+AV_COPY32(&nnz[44], &nnz_cache[4 + 8 * 14]);
+}
+}
+
+static av_always_inline void write_back_motion_list(const H264Context *h,
+H264SliceContext *sl,
+int b_stride,
+int b_xy, int b8_xy,
+int mb_type, int list)
+{
+int16_t(*mv_dst)[2] = &h->cur_pic.motion_val[list][b_xy];
+int16_t(*mv_src)[2] = &sl->mv_cache[list][scan8[0]];
+AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
+AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
+AV_COPY128(mv_dst + 2 * b_stride, mv_src + 8 * 2);
+AV_COPY128(mv_dst + 3 * b_stride, mv_src + 8 * 3);
+if (CABAC(h)) {
+uint8_t (*mvd_dst)[2] = &sl->mvd_table[list][FMO ? 8 * sl->mb_xy
+: 
h->mb2br_xy[sl->mb_xy]];
+uint8_t(*mvd_src)[2]  = &sl->mvd_cache[list][scan8[0]];
+if (IS_SKIP(mb_type)) {
+AV_ZERO128(mvd_dst);
+} else {
+AV_COPY64(mvd_dst, mvd_src + 8 * 3);
+AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8 * 0);
+AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8 * 1);
+AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8 * 2);
+}
+}
+
+{
+int8_t *ref_index = &h->cur_pic.ref_index[list][b8_xy];
+int8_t *ref_cache = sl->ref_cache[list];
+ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
+ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
+ref_index[0 + 1 * 2] = ref_cache[scan8[8]];
+ref_index[1 + 1 * 2] = ref_cache[scan8[12]];
+}
+}
+
+static av_always_inline void write_back_motion(const H264Context *h,
+   H264SliceContext *sl,
+   

[FFmpeg-devel] [PATCH 12/15] avformat/internal: Use forward declaration for AVCodecDescriptor

2023-08-02 Thread Andreas Rheinhardt
This avoids including lavc/codec_desc.h everywhere and thereby
forces users to include it directly instead of lazily and potentially
unknowingly relying on indirect inclusions.

Also add the proper inclusion to libavformat/demux.c, one of the
two files that actually use the new field.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/demux.c| 1 +
 libavformat/internal.h | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 1ef297d5e7..b218f64574 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -36,6 +36,7 @@
 
 #include "libavcodec/avcodec.h"
 #include "libavcodec/bsf.h"
+#include "libavcodec/codec_desc.h"
 #include "libavcodec/internal.h"
 #include "libavcodec/packet_internal.h"
 #include "libavcodec/raw.h"
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 9fc980601f..594afd731d 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -23,7 +23,6 @@
 
 #include 
 
-#include "libavcodec/codec_desc.h"
 #include "libavcodec/packet_internal.h"
 
 #include "avformat.h"
@@ -410,7 +409,7 @@ typedef struct FFStream {
 int64_t first_dts;
 int64_t cur_dts;
 
-const AVCodecDescriptor *codec_desc;
+const struct AVCodecDescriptor *codec_desc;
 } FFStream;
 
 static av_always_inline FFStream *ffstream(AVStream *st)
-- 
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 07/15] avdevice/pulse_audio_common: Avoid inclusion of avcodec.h

2023-08-02 Thread Andreas Rheinhardt
It only needs codec_id.h.

Signed-off-by: Andreas Rheinhardt 
---
 libavdevice/pulse_audio_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavdevice/pulse_audio_common.h b/libavdevice/pulse_audio_common.h
index 902795e4f7..9def3cb796 100644
--- a/libavdevice/pulse_audio_common.h
+++ b/libavdevice/pulse_audio_common.h
@@ -23,7 +23,7 @@
 #define AVDEVICE_PULSE_AUDIO_COMMON_H
 
 #include 
-#include "libavcodec/avcodec.h"
+#include "libavcodec/codec_id.h"
 #include "avdevice.h"
 
 pa_sample_format_t ff_codec_id_to_pulse_format(enum AVCodecID codec_id);
-- 
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] [PATCH] libswresample: Prevent out of bounds.

2023-08-02 Thread kobrineli
Invalid out or int fmts are got from the user input, which was 
discovered through fuzzing. Don't know where to add check at the time of 
SwrContext creating, but I think this change is redundant to at least 
prevent dangerous out of bounds access, which set the pointer to illegal 
address.


On 2023-08-02 13:51, Andreas Rheinhardt wrote:

kobrineli:

From: Eli Kobrin 

We've been fuzzing torchvision with 
[sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)

and found out of bounds error in ffmpeg project at audioconvert.c:51.
To prevent error we need to insert corresponding check.

Signed-off-by: Eli Kobrin 
---
 libswresample/audioconvert.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libswresample/audioconvert.c 
b/libswresample/audioconvert.c

index 1d75ba1495..701f4808a0 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum 
AVSampleFormat out_fmt,

int flags)
 {
 AudioConvert *ctx;
-conv_func_type *f = 
fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + 
AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];

+
+size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB 
* av_get_packed_sample_fmt(in_fmt);

+if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
+return NULL;
+
+conv_func_type *f = fmt_pair_to_conv_functions[idx];

 if (!f)
 return NULL;


Something seems to be using an invalid sample format (either out_fmt or
in_fmt). You should investigate where this comes from.
(Given that this is a public function, we should probably validate user
input; and maybe stop using AV_SAMPLE_FMT_NB altogether.)

- 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 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] libswresample: Prevent out of bounds.

2023-08-02 Thread kobrineli
I've found out that `in_fmt` is equal to -1 at the place of error, so we 
just need to insert check at the beginning of `swr_init` function to 
check fmts positivity.


On 2023-08-02 13:51, Andreas Rheinhardt wrote:


kobrineli:


From: Eli Kobrin 

We've been fuzzing torchvision with 
[sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)

and found out of bounds error in ffmpeg project at audioconvert.c:51.
To prevent error we need to insert corresponding check.

Signed-off-by: Eli Kobrin 
---
libswresample/audioconvert.c | 7 ++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libswresample/audioconvert.c 
b/libswresample/audioconvert.c

index 1d75ba1495..701f4808a0 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum 
AVSampleFormat out_fmt,

int flags)
{
AudioConvert *ctx;
-conv_func_type *f = 
fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + 
AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];

+
+size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB 
* av_get_packed_sample_fmt(in_fmt);

+if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
+return NULL;
+
+conv_func_type *f = fmt_pair_to_conv_functions[idx];

if (!f)
return NULL;


Something seems to be using an invalid sample format (either out_fmt or
in_fmt). You should investigate where this comes from.
(Given that this is a public function, we should probably validate user
input; and maybe stop using AV_SAMPLE_FMT_NB altogether.)

- 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 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] libswresample: Prevent out of bounds.

2023-08-02 Thread kobrineli
From: Eli Kobrin 

We've been fuzzing torchvision with 
[sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)
and found out of bounds error in ffmpeg project at audioconvert.c:51.
To prevent error we need to insert corresponding check and fix checks
for in and out fmt in swr_init.

Signed-off-by: Eli Kobrin 
---
 libswresample/audioconvert.c | 7 ++-
 libswresample/swresample.c   | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
index 1d75ba1495..701f4808a0 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat 
out_fmt,
int flags)
 {
 AudioConvert *ctx;
-conv_func_type *f = 
fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + 
AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];
+
+size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB * 
av_get_packed_sample_fmt(in_fmt);
+if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
+return NULL;
+
+conv_func_type *f = fmt_pair_to_conv_functions[idx];
 
 if (!f)
 return NULL;
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 6dc329a9d0..b7cab36710 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -196,11 +196,11 @@ av_cold int swr_init(struct SwrContext *s){
 
 clear_context(s);
 
-if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
+if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB || s-> in_sample_fmt < 0){
 av_log(s, AV_LOG_ERROR, "Requested input sample format %d is 
invalid\n", s->in_sample_fmt);
 return AVERROR(EINVAL);
 }
-if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
+if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB || s->out_sample_fmt < 0){
 av_log(s, AV_LOG_ERROR, "Requested output sample format %d is 
invalid\n", s->out_sample_fmt);
 return AVERROR(EINVAL);
 }
-- 
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".


Re: [FFmpeg-devel] [PATCH] libswresample: Prevent out of bounds.

2023-08-02 Thread kobrineli
Resubmitted the patch 
(https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230802113106.1138555-1-kobrin...@ispras.ru/).

Didn't understand how to fix the existing patch.

On 2023-08-02 13:51, Andreas Rheinhardt wrote:

kobrineli:

From: Eli Kobrin 

We've been fuzzing torchvision with 
[sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)

and found out of bounds error in ffmpeg project at audioconvert.c:51.
To prevent error we need to insert corresponding check.

Signed-off-by: Eli Kobrin 
---
 libswresample/audioconvert.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libswresample/audioconvert.c 
b/libswresample/audioconvert.c

index 1d75ba1495..701f4808a0 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum 
AVSampleFormat out_fmt,

int flags)
 {
 AudioConvert *ctx;
-conv_func_type *f = 
fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + 
AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];

+
+size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB 
* av_get_packed_sample_fmt(in_fmt);

+if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
+return NULL;
+
+conv_func_type *f = fmt_pair_to_conv_functions[idx];

 if (!f)
 return NULL;


Something seems to be using an invalid sample format (either out_fmt or
in_fmt). You should investigate where this comes from.
(Given that this is a public function, we should probably validate user
input; and maybe stop using AV_SAMPLE_FMT_NB altogether.)

- 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 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] libswresample: Prevent out of bounds.

2023-08-02 Thread Ronald S. Bultje
Hi,

On Wed, Aug 2, 2023 at 7:31 AM kobrineli  wrote:

> From: Eli Kobrin 
>
> We've been fuzzing torchvision with [sydr-fuzz](
> https://github.com/ispras/oss-sydr-fuzz)
> and found out of bounds error in ffmpeg project at audioconvert.c:51.
> To prevent error we need to insert corresponding check and fix checks
> for in and out fmt in swr_init.
>
> Signed-off-by: Eli Kobrin 
> ---
>  libswresample/audioconvert.c | 7 ++-
>  libswresample/swresample.c   | 4 ++--
>  2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
> index 1d75ba1495..701f4808a0 100644
> --- a/libswresample/audioconvert.c
> +++ b/libswresample/audioconvert.c
> @@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum
> AVSampleFormat out_fmt,
> int flags)
>  {
>  AudioConvert *ctx;
> -conv_func_type *f =
> fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) +
> AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];
> +
> +size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB *
> av_get_packed_sample_fmt(in_fmt);
> +if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
> +return NULL;
> +
> +conv_func_type *f = fmt_pair_to_conv_functions[idx];
>

This is not necessary anymore, please remove this portion.


> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
> index 6dc329a9d0..b7cab36710 100644
> --- a/libswresample/swresample.c
> +++ b/libswresample/swresample.c
> @@ -196,11 +196,11 @@ av_cold int swr_init(struct SwrContext *s){
>
>  clear_context(s);
>
> -if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
> +if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB || s-> in_sample_fmt < 0){
>  av_log(s, AV_LOG_ERROR, "Requested input sample format %d is
> invalid\n", s->in_sample_fmt);
>  return AVERROR(EINVAL);
>  }
> -if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
> +if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB || s->out_sample_fmt < 0){
>  av_log(s, AV_LOG_ERROR, "Requested output sample format %d is
> invalid\n", s->out_sample_fmt);
>  return AVERROR(EINVAL);
>  }
> --
> 2.25.1
>

You can simplify this to "if ((unsigned) s->in/out_sample_fmt >=
AV_SAMPLE_FMT_NB)".

Ronald
___
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] libswresample: Prevent out of bounds.

2023-08-02 Thread kobrineli
From: Eli Kobrin 

We've been fuzzing torchvision with 
[sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)
and found out of bounds error in ffmpeg project at audioconvert.c:151.
To prevent error we need to fix checks for in and out fmt in swr_init.

Signed-off-by: Eli Kobrin 
---
 libswresample/swresample.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 6dc329a9d0..fb3d7bccbf 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -196,11 +196,11 @@ av_cold int swr_init(struct SwrContext *s){
 
 clear_context(s);
 
-if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
+if((unsigned) s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
 av_log(s, AV_LOG_ERROR, "Requested input sample format %d is 
invalid\n", s->in_sample_fmt);
 return AVERROR(EINVAL);
 }
-if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
+if((unsigned) s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
 av_log(s, AV_LOG_ERROR, "Requested output sample format %d is 
invalid\n", s->out_sample_fmt);
 return AVERROR(EINVAL);
 }
-- 
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".


Re: [FFmpeg-devel] [PATCH] libswresample: Prevent out of bounds.

2023-08-02 Thread kobrineli

Resubmitted, thanks

On 2023-08-02 15:06, Ronald S. Bultje wrote:

Hi,

On Wed, Aug 2, 2023 at 7:31 AM kobrineli  wrote:


From: Eli Kobrin 

We've been fuzzing torchvision with [sydr-fuzz](
https://github.com/ispras/oss-sydr-fuzz)
and found out of bounds error in ffmpeg project at audioconvert.c:51.
To prevent error we need to insert corresponding check and fix checks
for in and out fmt in swr_init.

Signed-off-by: Eli Kobrin 
---
 libswresample/audioconvert.c | 7 ++-
 libswresample/swresample.c   | 4 ++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libswresample/audioconvert.c 
b/libswresample/audioconvert.c

index 1d75ba1495..701f4808a0 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum
AVSampleFormat out_fmt,
int flags)
 {
 AudioConvert *ctx;
-conv_func_type *f =
fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) +
AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)];
+
+size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB 
*

av_get_packed_sample_fmt(in_fmt);
+if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB)
+return NULL;
+
+conv_func_type *f = fmt_pair_to_conv_functions[idx];



This is not necessary anymore, please remove this portion.



diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 6dc329a9d0..b7cab36710 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -196,11 +196,11 @@ av_cold int swr_init(struct SwrContext *s){

 clear_context(s);

-if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
+if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB || s-> in_sample_fmt < 
0){

 av_log(s, AV_LOG_ERROR, "Requested input sample format %d is
invalid\n", s->in_sample_fmt);
 return AVERROR(EINVAL);
 }
-if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
+if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB || s->out_sample_fmt < 
0){

 av_log(s, AV_LOG_ERROR, "Requested output sample format %d is
invalid\n", s->out_sample_fmt);
 return AVERROR(EINVAL);
 }
--
2.25.1



You can simplify this to "if ((unsigned) s->in/out_sample_fmt >=
AV_SAMPLE_FMT_NB)".

Ronald
___
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/5] avcodec/nvdec_(mjpeg|vp8): Constify AVHWAccels

2023-08-02 Thread Timo Rothenpieler

lgtm
___
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 5/6] fftools: avradio support

2023-08-02 Thread Michael Niedermayer
On Tue, Aug 01, 2023 at 10:06:19PM +0200, Paul B Mahol wrote:
> On Tue, Aug 1, 2023 at 9:51 PM Cosmin Stejerean  wrote:
> 
> > On Jul 27, 2023, at 11:36 AM, Michael Niedermayer 
> > wrote:
> >
> > Let me first explain what i want to provide to the user (most of this
> > is already implemented, some needs more work)
> > the user starts her favorite player, be that vlc, ffplay, or whatever
> > chooses sdr as input device and thats all configuration she needs.
> > She can select a specific driver, gain and so but she doesnt have to
> > Now she only needs 2 buttons, seek forward and seek backward, in
> > ffplay thats the cursor keys. To select the station.
> > And she sees on the screen what station that is, what song title and
> > artist are playing as well as what is playing on any other FM station
> > in view (that works here already in europe, for the US if it doesnt work
> >
> > i need a sample from dumpurl ...)
> > (for non interactive tools like ffmpeg she would have to select the
> > frequency she wants to listen to or all in view ...)
> >
> > Now gqrx needs me to manually enter the frequency, the modulation the
> > device, then it still doesnt work (first one has to know why from multiple
> > rtlsdr lines some dont work) and once one is through this it still
> > doesnt work, all AGC methods dont work, i have to set the gain manually
> > for the station i want to listen to to have acceptable quality. I do know
> > but at this point we lost likely 90% of users
> >
> > I know this is a contentious topic, but as a heavy user of ffmpeg for both
> > work and fun, and as an amateur radio user, what you describe sounds pretty
> > great to me. I can definitely imagine using this for a few usecases. I get
> > that other tools exist and others that know how to use those can of course
> > continue to use them. I for one would definitely love to use ffmpeg
> > directly if that was an option.
> >
> > This is not something I'd want enabled in the ffmpeg build at work due to
> > the extra surface area, but assuming I can disable the sdr radio bits at
> > build time for "serious" builds, and that this code is actively maintained
> > and designed in a way that minimizes interference with other parts of
> > ffmpeg, then it's not clear to me why there's such a strong reaction
> > against having this included in ffmpeg.
> >
> 
> Because it would always give sub-optimal results at best.

Iam not sure what you refer to by "it" exactly and what the alternative
you compare it to are but why ?

Even leaving this very generic, claiming one implementation will always
give "sub-optimal results" to another does not sound like a fact based
statment.

Thats a bit like saying a reverse engeneered codec will always give
sub optimal results to the binary original. And thats why we better
should go the optimal route


>
> Time to implement auto-pilot into FFmpeg too.

I dont know if you plan that but i dont, did not and have also not
suggested that. In fact i dont even know what exactly you refer to by
"auto-pilot"

thx

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

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad


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 16/19] avcodec/internal: Move FF_MAX_EXTRADATA_SIZE to its only user

2023-08-02 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/avcodec.c  | 7 +++
 libavcodec/internal.h | 7 ---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 340abe830e..0700a53b5c 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -44,6 +44,13 @@
 #include "internal.h"
 #include "thread.h"
 
+/**
+ * Maximum size in bytes of extradata.
+ * This value was chosen such that every bit of the buffer is
+ * addressable by a 32-bit signed integer as used by get_bits.
+ */
+#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
+
 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, 
void *arg2), void *arg, int *ret, int count, int size)
 {
 size_t i;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 4dce9f6fbb..480b18b447 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -159,13 +159,6 @@ unsigned int ff_toupper4(unsigned int x);
 
 void ff_color_frame(AVFrame *frame, const int color[4]);
 
-/**
- * Maximum size in bytes of extradata.
- * This value was chosen such that every bit of the buffer is
- * addressable by a 32-bit signed integer as used by get_bits.
- */
-#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
-
 /**
  * 2^(x) for integer x
  * @return correctly rounded float
-- 
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] [PATCH 5/6] fftools: avradio support

2023-08-02 Thread Paul B Mahol
On Wed, Aug 2, 2023 at 2:47 PM Michael Niedermayer 
wrote:

> On Tue, Aug 01, 2023 at 10:06:19PM +0200, Paul B Mahol wrote:
> > On Tue, Aug 1, 2023 at 9:51 PM Cosmin Stejerean 
> wrote:
> >
> > > On Jul 27, 2023, at 11:36 AM, Michael Niedermayer <
> mich...@niedermayer.cc>
> > > wrote:
> > >
> > > Let me first explain what i want to provide to the user (most of this
> > > is already implemented, some needs more work)
> > > the user starts her favorite player, be that vlc, ffplay, or whatever
> > > chooses sdr as input device and thats all configuration she needs.
> > > She can select a specific driver, gain and so but she doesnt have to
> > > Now she only needs 2 buttons, seek forward and seek backward, in
> > > ffplay thats the cursor keys. To select the station.
> > > And she sees on the screen what station that is, what song title and
> > > artist are playing as well as what is playing on any other FM station
> > > in view (that works here already in europe, for the US if it doesnt
> work
> > >
> > > i need a sample from dumpurl ...)
> > > (for non interactive tools like ffmpeg she would have to select the
> > > frequency she wants to listen to or all in view ...)
> > >
> > > Now gqrx needs me to manually enter the frequency, the modulation the
> > > device, then it still doesnt work (first one has to know why from
> multiple
> > > rtlsdr lines some dont work) and once one is through this it still
> > > doesnt work, all AGC methods dont work, i have to set the gain manually
> > > for the station i want to listen to to have acceptable quality. I do
> know
> > > but at this point we lost likely 90% of users
> > >
> > > I know this is a contentious topic, but as a heavy user of ffmpeg for
> both
> > > work and fun, and as an amateur radio user, what you describe sounds
> pretty
> > > great to me. I can definitely imagine using this for a few usecases. I
> get
> > > that other tools exist and others that know how to use those can of
> course
> > > continue to use them. I for one would definitely love to use ffmpeg
> > > directly if that was an option.
> > >
> > > This is not something I'd want enabled in the ffmpeg build at work due
> to
> > > the extra surface area, but assuming I can disable the sdr radio bits
> at
> > > build time for "serious" builds, and that this code is actively
> maintained
> > > and designed in a way that minimizes interference with other parts of
> > > ffmpeg, then it's not clear to me why there's such a strong reaction
> > > against having this included in ffmpeg.
> > >
> >
> > Because it would always give sub-optimal results at best.
>
> Iam not sure what you refer to by "it" exactly and what the alternative
> you compare it to are but why ?
>
> Even leaving this very generic, claiming one implementation will always
> give "sub-optimal results" to another does not sound like a fact based
> statment.
>

Current SDR in current avradio is suboptimal. That is the fact.


>
> Thats a bit like saying a reverse engeneered codec will always give
> sub optimal results to the binary original. And thats why we better
> should go the optimal route
>
>
> >
> > Time to implement auto-pilot into FFmpeg too.
>
> I dont know if you plan that but i dont, did not and have also not
> suggested that. In fact i dont even know what exactly you refer to by
> "auto-pilot"
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Into a blind darkness they enter who follow after the Ignorance,
> they as if into a greater darkness enter who devote themselves
> to the Knowledge alone. -- Isha Upanishad
> ___
> 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 17/19] avcodec/utils: Move ff_color_frame() to its only user

2023-08-02 Thread Andreas Rheinhardt
Namely h264_slice.c.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h264_slice.c | 34 +-
 libavcodec/internal.h   |  2 --
 libavcodec/utils.c  | 28 
 3 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 27fbd8d953..6cd7bb8fe7 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -28,15 +28,11 @@
 #include "config_components.h"
 
 #include "libavutil/avassert.h"
-#include "libavutil/display.h"
-#include "libavutil/film_grain_params.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/timecode.h"
-#include "internal.h"
 #include "decode.h"
 #include "cabac.h"
 #include "cabac_functions.h"
-#include "decode.h"
 #include "error_resilience.h"
 #include "avcodec.h"
 #include "h264.h"
@@ -299,6 +295,34 @@ static void copy_picture_range(H264Picture **to, 
H264Picture **from, int count,
 }
 }
 
+static void color_frame(AVFrame *frame, const int c[4])
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+
+av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
+
+for (int p = 0; p < desc->nb_components; p++) {
+uint8_t *dst = frame->data[p];
+int is_chroma = p == 1 || p == 2;
+int bytes  = is_chroma ? AV_CEIL_RSHIFT(frame->width,  
desc->log2_chroma_w) : frame->width;
+int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, 
desc->log2_chroma_h) : frame->height;
+if (desc->comp[0].depth >= 9) {
+((uint16_t*)dst)[0] = c[p];
+av_memcpy_backptr(dst + 2, 2, bytes - 2);
+dst += frame->linesize[p];
+for (int y = 1; y < height; y++) {
+memcpy(dst, frame->data[p], 2*bytes);
+dst += frame->linesize[p];
+}
+} else {
+for (int y = 0; y < height; y++) {
+memset(dst, c[p], bytes);
+dst += frame->linesize[p];
+}
+}
+}
+}
+
 static int h264_slice_header_init(H264Context *h);
 
 int ff_h264_update_thread_context(AVCodecContext *dst,
@@ -1547,7 +1571,7 @@ static int h264_field_start(H264Context *h, const 
H264SliceContext *sl,
 if (h->short_ref[0]->field_picture)
 ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 
1);
 } else if (!h->frame_recovered && !h->avctx->hwaccel)
-ff_color_frame(h->short_ref[0]->f, c);
+color_frame(h->short_ref[0]->f, c);
 h->short_ref[0]->frame_num = h->poc.prev_frame_num;
 }
 }
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 480b18b447..7de6c577fe 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -157,8 +157,6 @@ int ff_match_2uint16(const uint16_t (*tab)[2], int size, 
int a, int b);
 
 unsigned int ff_toupper4(unsigned int x);
 
-void ff_color_frame(AVFrame *frame, const int color[4]);
-
 /**
  * 2^(x) for integer x
  * @return correctly rounded float
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 672eb15d98..da652d4db1 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -406,34 +406,6 @@ int avcodec_fill_audio_frame(AVFrame *frame, int 
nb_channels,
 return ret;
 }
 
-void ff_color_frame(AVFrame *frame, const int c[4])
-{
-const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
-int p, y;
-
-av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
-
-for (p = 0; pnb_components; p++) {
-uint8_t *dst = frame->data[p];
-int is_chroma = p == 1 || p == 2;
-int bytes  = is_chroma ? AV_CEIL_RSHIFT(frame->width,  
desc->log2_chroma_w) : frame->width;
-int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, 
desc->log2_chroma_h) : frame->height;
-if (desc->comp[0].depth >= 9) {
-((uint16_t*)dst)[0] = c[p];
-av_memcpy_backptr(dst + 2, 2, bytes - 2);
-dst += frame->linesize[p];
-for (y = 1; y < height; y++) {
-memcpy(dst, frame->data[p], 2*bytes);
-dst += frame->linesize[p];
-}
-} else {
-for (y = 0; y < height; y++) {
-memset(dst, c[p], bytes);
-dst += frame->linesize[p];
-}
-}
-}
-}
 
 int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec){
 return !!(ffcodec(codec)->caps_internal & 
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM);
-- 
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 18/19] avcodec/utils: Move ff_int_from_list_or_default() to its only user

2023-08-02 Thread Andreas Rheinhardt
Namely proresenc_anatoliy.c.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/internal.h   | 12 --
 libavcodec/proresenc_anatoliy.c | 39 +
 libavcodec/utils.c  | 19 
 3 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 7de6c577fe..a67cf713ca 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -207,16 +207,4 @@ int ff_alloc_timecode_sei(const AVFrame *frame, AVRational 
rate, size_t prefix_l
  */
 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx);
 
-/**
- * Check if a value is in the list. If not, return the default value
- *
- * @param ctxContext for the log msg
- * @param val_name   Name of the checked value, for log msg
- * @param array_valid_values Array of valid int, ended with INT_MAX
- * @param default_value  Value return if checked value is not in the array
- * @return   Value or default_value.
- */
-int ff_int_from_list_or_default(void *ctx, const char * val_name, int val,
-const int * array_valid_values, int 
default_value);
-
 #endif /* AVCODEC_INTERNAL_H */
diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c
index fc48c97d5b..c701275e5d 100644
--- a/libavcodec/proresenc_anatoliy.c
+++ b/libavcodec/proresenc_anatoliy.c
@@ -32,7 +32,6 @@
 #include "avcodec.h"
 #include "codec_internal.h"
 #include "encode.h"
-#include "internal.h"
 #include "profiles.h"
 #include "proresdata.h"
 #include "put_bits.h"
@@ -198,6 +197,35 @@ typedef struct {
 char *vendor;
 } ProresContext;
 
+/**
+ * Check if a value is in the list. If not, return the default value
+ *
+ * @param ctxContext for the log msg
+ * @param val_name   Name of the checked value, for log msg
+ * @param array_valid_values Array of valid int, ended with INT_MAX
+ * @param default_value  Value return if checked value is not in the array
+ * @return   Value or default_value.
+ */
+static int int_from_list_or_default(void *ctx, const char *val_name, int val,
+const int *array_valid_values, int 
default_value)
+{
+int i = 0;
+
+while (1) {
+int ref_val = array_valid_values[i];
+if (ref_val == INT_MAX)
+break;
+if (val == ref_val)
+return val;
+i++;
+}
+/* val is not a valid value */
+av_log(ctx, AV_LOG_DEBUG,
+   "%s %d are not supported. Set to default value : %d\n",
+   val_name, val, default_value);
+return default_value;
+}
+
 static void encode_codeword(PutBitContext *pb, int val, int codebook)
 {
 unsigned int rice_order, exp_order, switch_bits, first_exp, exp, zeros;
@@ -761,9 +789,12 @@ static int prores_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 *buf++ = frame_flags;
 *buf++ = 0; /* reserved */
 /* only write color properties, if valid value. set to unspecified 
otherwise */
-*buf++ = ff_int_from_list_or_default(avctx, "frame color primaries", 
pict->color_primaries, valid_primaries, 0);
-*buf++ = ff_int_from_list_or_default(avctx, "frame color trc", 
pict->color_trc, valid_trc, 0);
-*buf++ = ff_int_from_list_or_default(avctx, "frame colorspace", 
pict->colorspace, valid_colorspace, 0);
+*buf++ = int_from_list_or_default(avctx, "frame color primaries",
+  pict->color_primaries, valid_primaries, 
0);
+*buf++ = int_from_list_or_default(avctx, "frame color trc",
+  pict->color_trc, valid_trc, 0);
+*buf++ = int_from_list_or_default(avctx, "frame colorspace",
+  pict->colorspace, valid_colorspace, 0);
 if (avctx->profile >= FF_PROFILE_PRORES_) {
 if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
 *buf++ = 0xA0;/* src b64a and no alpha */
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index da652d4db1..bd4131db62 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1142,22 +1142,3 @@ int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
 
 return bitrate;
 }
-
-int ff_int_from_list_or_default(void *ctx, const char * val_name, int val,
-const int * array_valid_values, int 
default_value)
-{
-int i = 0, ref_val;
-
-while (1) {
-ref_val = array_valid_values[i];
-if (ref_val == INT_MAX)
-break;
-if (val == ref_val)
-return val;
-i++;
-}
-/* val is not a valid value */
-av_log(ctx, AV_LOG_DEBUG,
-   "%s %d are not supported. Set to default value : %d\n", val_name, 
val, default_value);
-return default_value;
-}
-- 
2.34.1

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

To unsubscribe, visit link abov

[FFmpeg-devel] [PATCH 19/19] avcodec/svq1enc: Remove unnecessary cast

2023-08-02 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/svq1enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 4651e01ae8..5e7f410214 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -118,7 +118,7 @@ static void svq1_write_header(SVQ1EncContext *s, 
PutBitContext *pb, int frame_ty
 /* output 5 unknown bits (2 + 2 + 1) */
 put_bits(pb, 5, 2); /* 2 needed by quicktime decoder */
 
-i = ff_match_2uint16((void*)ff_svq1_frame_size_table,
+i = ff_match_2uint16(ff_svq1_frame_size_table,
  FF_ARRAY_ELEMS(ff_svq1_frame_size_table),
  s->frame_width, s->frame_height);
 put_bits(pb, 3, i);
-- 
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] What is FFmpeg and what should it be

2023-08-02 Thread Michael Niedermayer
Hi Vittorio

On Wed, Aug 02, 2023 at 03:44:13AM +0200, Vittorio Giovara wrote:
> On Sun, Jul 30, 2023 at 3:04 PM Nicolas George  wrote:
> 
> > Kieran Kunhya (12023-07-28):
> > > FFmpeg doesn't implement TCP in userspace, it doesn't implement the
> > > WiFi protocol etc etc. Different layers are delegated to different
> > > programs.
> >
> > Hi. You seem to be discussing this in more good faith than I previously
> > imagined, so I will try to tone done the irritation in my mails.
> >
> 
> sorry for jumping in mid discussion, but shouldn't that be the case always?
> 
> But if people started to routinely use FFmpeg on some kind of
> > bare-metal microcontroller where network hardware exists but the
> > official network stack is too big to share the space with FFmpeg, and if
> > somebody were to propose a limited network stack based on lavu's
> > cryptographic primitives, then it would totally make sense to accept it.
> >
> 
> no? that sounds a terrible maintenance burden in terms of both code size
> and security issues, nobody wants that!
> what could be a viable compromise is *maybe* providing the hooks where
> needed where custom io and callbacks can be implemented, but afaict there
> are plenty of those in ffmpeg already
> 
> FFmpeg has been successful because it relied on pragmatism rather than
> > dogmatic adherence to principles. Let us continue that way.
> >
> 
> ffmpeg has been successful because points of contentions were resolved with
> consensus (most of the times) and not by sheer number of emails or email
> length about the topic. I am not even familiar with this avradio thing but
> if the community seems so against it, let's maybe find another solution
> (separate library, repository, tool etc) instead of wasting time and energy
> over the same points.

the code already is in a seperate repository. And is basically isolated
in a single demuxer and single input device.
Some people still complain that it exists

About the community i do not know what the majority wants. About users
iam fairly confident that they prefer having the option to use it than
not having the option.

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] What is FFmpeg and what should it be

2023-08-02 Thread Jean-Baptiste Kempf
On Wed, 2 Aug 2023, at 14:55, Michael Niedermayer wrote:
> the code already is in a seperate repository. And is basically isolated
> in a single demuxer and single input device.

But it's not a library in that repository, like swscale, swresample or similar 
libraries.

If it was, with an API, it would be trivial to add support to this optional 
library as an FFmpeg module, and noone who complain.

jb
-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
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 5/6] fftools: avradio support

2023-08-02 Thread Michael Niedermayer
On Wed, Aug 02, 2023 at 03:00:54PM +0200, Paul B Mahol wrote:
> On Wed, Aug 2, 2023 at 2:47 PM Michael Niedermayer 
> wrote:
> 
> > On Tue, Aug 01, 2023 at 10:06:19PM +0200, Paul B Mahol wrote:
> > > On Tue, Aug 1, 2023 at 9:51 PM Cosmin Stejerean 
> > wrote:
> > >
> > > > On Jul 27, 2023, at 11:36 AM, Michael Niedermayer <
> > mich...@niedermayer.cc>
> > > > wrote:
> > > >
> > > > Let me first explain what i want to provide to the user (most of this
> > > > is already implemented, some needs more work)
> > > > the user starts her favorite player, be that vlc, ffplay, or whatever
> > > > chooses sdr as input device and thats all configuration she needs.
> > > > She can select a specific driver, gain and so but she doesnt have to
> > > > Now she only needs 2 buttons, seek forward and seek backward, in
> > > > ffplay thats the cursor keys. To select the station.
> > > > And she sees on the screen what station that is, what song title and
> > > > artist are playing as well as what is playing on any other FM station
> > > > in view (that works here already in europe, for the US if it doesnt
> > work
> > > >
> > > > i need a sample from dumpurl ...)
> > > > (for non interactive tools like ffmpeg she would have to select the
> > > > frequency she wants to listen to or all in view ...)
> > > >
> > > > Now gqrx needs me to manually enter the frequency, the modulation the
> > > > device, then it still doesnt work (first one has to know why from
> > multiple
> > > > rtlsdr lines some dont work) and once one is through this it still
> > > > doesnt work, all AGC methods dont work, i have to set the gain manually
> > > > for the station i want to listen to to have acceptable quality. I do
> > know
> > > > but at this point we lost likely 90% of users
> > > >
> > > > I know this is a contentious topic, but as a heavy user of ffmpeg for
> > both
> > > > work and fun, and as an amateur radio user, what you describe sounds
> > pretty
> > > > great to me. I can definitely imagine using this for a few usecases. I
> > get
> > > > that other tools exist and others that know how to use those can of
> > course
> > > > continue to use them. I for one would definitely love to use ffmpeg
> > > > directly if that was an option.
> > > >
> > > > This is not something I'd want enabled in the ffmpeg build at work due
> > to
> > > > the extra surface area, but assuming I can disable the sdr radio bits
> > at
> > > > build time for "serious" builds, and that this code is actively
> > maintained
> > > > and designed in a way that minimizes interference with other parts of
> > > > ffmpeg, then it's not clear to me why there's such a strong reaction
> > > > against having this included in ffmpeg.
> > > >
> > >
> > > Because it would always give sub-optimal results at best.
> >
> > Iam not sure what you refer to by "it" exactly and what the alternative
> > you compare it to are but why ?
> >
> > Even leaving this very generic, claiming one implementation will always
> > give "sub-optimal results" to another does not sound like a fact based
> > statment.
> >
> 
> Current SDR in current avradio is suboptimal. That is the fact.

Everything is suboptimal in some way

a boat is suboptimal in a dessert, and a camel in the middle of the sea

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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


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] What is FFmpeg and what should it be

2023-08-02 Thread Brad Isbell
As a frequent FFmpeg user, and an occasional RTL-SDR user, the major
tradeoff for me is in the size of FFmpeg binaries vs. features.  I
agree with Jean-Baptiste that if this were an optional library to be
added to the build, then that resolves any issues I might have as a
user.

Then I have the choice to opt for the big honkin' beast build that
includes all-the-things on my daily dev machine, but can still build
targeted builds for deployment to production servers, oddball
platforms like WASM, etc.

Brad Isbell // AudioPump, Inc.
b...@audiopump.co


On Wed, Aug 2, 2023 at 7:59 AM Jean-Baptiste Kempf  wrote:
>
> On Wed, 2 Aug 2023, at 14:55, Michael Niedermayer wrote:
> > the code already is in a seperate repository. And is basically isolated
> > in a single demuxer and single input device.
>
> But it's not a library in that repository, like swscale, swresample or 
> similar libraries.
>
> If it was, with an API, it would be trivial to add support to this optional 
> library as an FFmpeg module, and noone who complain.
>
> jb
> --
> Jean-Baptiste Kempf -  President
> +33 672 704 734
> ___
> 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] What is FFmpeg and what should it be

2023-08-02 Thread Nicolas George
Brad Isbell (12023-08-02):
> As a frequent FFmpeg user, and an occasional RTL-SDR user, the major
> tradeoff for me is in the size of FFmpeg binaries vs. features.  I
> agree with Jean-Baptiste that if this were an optional library to be
> added to the build, then that resolves any issues I might have as a
> user.
> 
> Then I have the choice to opt for the big honkin' beast build that
> includes all-the-things on my daily dev machine, but can still build
> targeted builds for deployment to production servers, oddball
> platforms like WASM, etc.

What you describe is already the case, for the avradio device just the
same as for any other component.

> On Wed, Aug 2, 2023 at 7:59 AM Jean-Baptiste Kempf  wrote:

Please do not top-post.

Regards,

-- 
  Nicolas George
___
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] What is FFmpeg and what should it be

2023-08-02 Thread Michael Niedermayer
On Wed, Aug 02, 2023 at 02:59:11PM +0200, Jean-Baptiste Kempf wrote:
> On Wed, 2 Aug 2023, at 14:55, Michael Niedermayer wrote:
> > the code already is in a seperate repository. And is basically isolated
> > in a single demuxer and single input device.
> 
> But it's not a library in that repository, like swscale, swresample or 
> similar libraries.
> 
> If it was, with an API, it would be trivial to add support to this optional 
> library as an FFmpeg module, and noone who complain.

There are multiple problems but the real problem is that
How many people discuss an SDR API ? (0)
How many people propose an SDR API ? (0)
How many people say what they want an SDR API to be able to do ? (0)
This is not a simple question ?
enumerate devices, set options, open, read frames, close ? That does not 
differ from the
existing input device / demuxer API.
If one cannot state a single difference in the API requirements from the 
existing
input device API, how can one design that API ?
If the existing input device API suposedly is not good
Is it bad just because it is the existing API ? And it would be perfectly
fine if it just had different function names ?
In other areas the community collaborates to create APIs
here all energy is spend to block patches (the latest set blocked are pure 
bugfixes)

Also swresample and swscale are simpler in what they need to provide API wise.

My very first patch i sent btw was blocked with the claim that it used
an external library and did not do the processing nativly.
Thats exactly what you suggest now

IMHO, People who want to use this API, or want to implement this API
should help with the API design and implementation

And if there are 0 people wanting to use the API then why should i design
that API ? who for ?
SDR in FFmpeg has 500+ users who want it, the API iam not sure has a user

People who have no intend to use the API or SDR or implement either
should not represent 99% of whom approv / reject the code
This is a problem, because it leads to bad code.
The people telling me what to do dont care about the results
one day its "not external lib", then its "external lib" then its
"libavfilter" then its "not libavfilter"

Again we had 0 that is ZERO discussions about an SDR API.
where does it start ? a hw enumerate, a soapy device, a void *
representing a SDR data stream from something like soapy

soapy is full of bugs, for the code to work we need to know
where the data came from and we need to interact with the hw
should we provide a layer over all of libsoapy ?
should we support only libsoapy and take a device from libsoapy
as input
should we have a generic input support that libsoapy is one of several
options ?

I cannot design this API with this. because 3 out of 4
choices will get attacked and blocked if not all 4, if someone just
implements it.
because people are unwilling to think about anything they just think
they know how it must be done and they dont discuss anything they just
demand and attack and wait how the next patchset looks. Eventually
everyone then looses interrest and a patchset goes through but thats
not good design.
So again, IMHO people should help design and implement this API
if they want an API.
If i have to design an API by trial and error until it gets no
unspecific objections by people not interrested in using it
thats not going to be an API that anyone will want to use.

thx

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

The day soldiers stop bringing you their problems is the day you have stopped 
leading them. They have either lost confidence that you can help or concluded 
you do not care. Either case is a failure of leadership. - Colin Powell


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] What is FFmpeg and what should it be

2023-08-02 Thread Michael Niedermayer
On Wed, Aug 02, 2023 at 09:12:14AM -0500, Brad Isbell wrote:
> As a frequent FFmpeg user, and an occasional RTL-SDR user, the major
> tradeoff for me is in the size of FFmpeg binaries vs. features.  I
> agree with Jean-Baptiste that if this were an optional library to be
> added to the build, then that resolves any issues I might have as a
> user.

The libraries should be split into runtime loadable plugins
Not only would that make tools alot smaller it also would allow
development of code available in ffmpeg that is maintained outside
FFmpeg.

I suggested this previosuly, it is of course not a "simple" thing
to do.

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] What is FFmpeg and what should it be

2023-08-02 Thread Nicolas George
Michael Niedermayer (12023-08-02):
> The libraries should be split into runtime loadable plugins
> Not only would that make tools alot smaller it also would allow
> development of code available in ffmpeg that is maintained outside
> FFmpeg.
> 
> I suggested this previosuly, it is of course not a "simple" thing
> to do.

No, it would be a terrible mistake.

And mostly, people who suggest or demand that do it based on
misconceptions about how linking works and/or have no actual scenario
where that would help.

But this is another discussion entirely. For this discussion, it is
enough that the libavradio device is just another device with one or a
few source files enabled by the build system, and that disabling it is
just a “--disable-” away.

Regards,

-- 
  Nicolas George
___
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/img2dec: added option -strftime_mkdir to allow directory creation if the strftime pattern include non-existing directories, similarly to how hls muxer does.

2023-08-02 Thread Nicolas George
Alexandre Heitor Schmidt (12023-08-01):
> doc/demuxers.texi: Documented how to use the new parameter.
> 
> Usage example:
> 
> ffmpeg -i /dev/video0 -strftime 1 -strftime_mkdir 1 
> "/tmp/%Y/%m/%Y_%m_%d-%H_%M_%S.jpg"
> ---
>  doc/muxers.texi   | 13 +
>  libavformat/img2enc.c | 28 +++-
>  2 files changed, 36 insertions(+), 5 deletions(-)

Hi.

Thanks for the patch. See my remark below.

> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index f6071484ff..1d03fef84b 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -1421,6 +1421,19 @@ overwritten with new images. Default value is 0.
>  If set to 1, expand the filename with date and time information from
>  @code{strftime()}. Default value is 0.
>  
> +@item strftime_mkdir
> +Used together with -strftime, if set to 1, it will create all subdirectories
> +which are expanded in @var{filename}.
> +@example
> +ffmpeg -i /dev/video0 -strftime 1 -strftime_mkdir 1 
> "/tmp/%Y/%m/%Y_%m_%d-%H_%M_%S.jpg"
> +@end example
> +This example will read all frames from /dev/video0 and save each frame into
> +@file{/tmp/%Y_%m/%Y_%m_%d-%H_%M_%S.jpg}, creating the necessary directory
> +structure if it doesn't exist. Supposing the current date at the time of the
> +image creation is 1978-04-27 15:01:02, the directory @file{/tmp/1978/04}
> +would be created - if it didn't existed - prior from saving the output file
> +@file{1978_04_27-15_01_02.jpg} into it.
> +
>  @item atomic_writing
>  Write output to a temporary file, which is renamed to target filename once
>  writing is completed. Default is disabled.
> diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
> index 9b8ec06cea..238f281467 100644
> --- a/libavformat/img2enc.c
> +++ b/libavformat/img2enc.c
> @@ -44,6 +44,7 @@ typedef struct VideoMuxData {
>  char target[4][1024];
>  int update;
>  int use_strftime;
> +int use_strftime_mkdir;
>  int frame_pts;
>  const char *muxer;
>  int use_rename;
> @@ -157,6 +158,22 @@ static int write_packet(AVFormatContext *s, AVPacket 
> *pkt)
>  av_log(s, AV_LOG_ERROR, "Could not get frame filename with 
> strftime\n");
>  return AVERROR(EINVAL);
>  }
> +
> +// whether to create non-existing directory structure
> +if (img->use_strftime_mkdir) {

> +const char *dir;
> +char *fn_copy = av_strdup(filename);
> +if (!fn_copy)
> +return AVERROR(ENOMEM);
> +dir = av_dirname(fn_copy);
> +if (ff_mkdir_p(dir) == -1 && errno != EEXIST) {
> +av_log(s, AV_LOG_ERROR, "Could not create directory %s with 
> use_strftime_mkdir\n", dir);
> +av_freep(&fn_copy);
> +return AVERROR(errno);
> +}

This is copied from hlsenc.c. Please factor it instead.

As far as I can see, ff_mkdir_p() is used exactly twice now and will be
thrice with this patch. And every time, it is invoked after
av_dirname(), so I suggest to turn it into ff_mkdir_p_parent(). That
would also fix the missing error checks in format_name().

> +av_log(s, AV_LOG_VERBOSE, "Created directory %s\n", dir);
> +av_freep(&fn_copy);
> +}
>  } else if (img->frame_pts) {
>  if (av_get_frame_filename2(filename, sizeof(filename), s->url, 
> pkt->pts, AV_FRAME_FILENAME_FLAGS_MULTIPLE) < 0) {
>  av_log(s, AV_LOG_ERROR, "Cannot write filename by pts of the 
> frames.");
> @@ -252,12 +269,13 @@ static int query_codec(enum AVCodecID id, int 
> std_compliance)
>  #define OFFSET(x) offsetof(VideoMuxData, x)
>  #define ENC AV_OPT_FLAG_ENCODING_PARAM
>  static const AVOption muxoptions[] = {
> -{ "update",   "continuously overwrite one file", OFFSET(update),  
> AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0,   1, ENC },
> -{ "start_number", "set first number in the sequence", 
> OFFSET(start_img_number), AV_OPT_TYPE_INT,  { .i64 = 1 }, 0, INT_MAX, ENC },
> -{ "strftime", "use strftime for filename", OFFSET(use_strftime),  
> AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
> -{ "frame_pts","use current frame pts for filename", 
> OFFSET(frame_pts),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
> +{ "update", "continuously overwrite one file", OFFSET(update),  
> AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0,   1, ENC },
> +{ "start_number",   "set first number in the sequence", 
> OFFSET(start_img_number), AV_OPT_TYPE_INT,  { .i64 = 1 }, 0, INT_MAX, ENC },
> +{ "strftime",   "use strftime for filename", OFFSET(use_strftime),  
> AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
> +{ "strftime_mkdir", "create directory structure for filename, if 
> needed", OFFSET(use_strftime_mkdir),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 
> ENC },
> +{ "frame_pts",  "use current frame pts for filename", 
> OFFSET(frame_pts),  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC },
>  { "atomic_writing", "write files atomically (usin

Re: [FFmpeg-devel] What is FFmpeg and what should it be

2023-08-02 Thread Jean-Baptiste Kempf
On Wed, 2 Aug 2023, at 16:20, Michael Niedermayer wrote:
> There are multiple problems but the real problem is that
> How many people discuss an SDR API ? (0)
> How many people propose an SDR API ? (0)

Did you ask people to do that?

> How many people say what they want an SDR API to be able to do ? (0)

> Again we had 0 that is ZERO discussions about an SDR API.
> where does it start ? a hw enumerate, a soapy device, a void *
> representing a SDR data stream from something like soapy

Just enough to integrate into AVInputFormat and libavformat + libavdevice.
Propose something and you will get more feedback

Then, the API will evolve into something better in v2.


jb

-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
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 v6 4/5] avformat/jpegxl: remove jpegxl_probe, instead call avcodec/jpegxl_parse

2023-08-02 Thread Leo Izen

On 8/1/23 14:59, Michael Niedermayer wrote:

On Tue, Aug 01, 2023 at 09:30:54AM -0400, Leo Izen wrote:

This prevents code duplication in the source form by calling the parse
code that was moved to avcodec last commit. The code will be duplicated
in binary form for shared builds (it's not that large), but for source
code it will only exist in one location now.

Signed-off-by: Leo Izen 
---
  libavformat/Makefile  |   6 +-
  libavformat/img2dec.c |   4 +-
  libavformat/jpegxl_anim_dec.c | 132 +++
  libavformat/jpegxl_probe.c| 412 --
  libavformat/jpegxl_probe.h|  37 ---
  libavformat/version.h |   2 +-
  6 files changed, 38 insertions(+), 555 deletions(-)
  delete mode 100644 libavformat/jpegxl_probe.c
  delete mode 100644 libavformat/jpegxl_probe.h


breaks build with shared libs



Interesting, I have jpegxl_parse.o in SHLIOBJS, but the actual file is 
in libavcodec, and it's in libavcodec/Makefile's STLIOBJS declaration. 
What else do I need to do in order to allow it to link into libavformat?


- Leo Izen

___
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] avcodec/internal: Move AVCodecInternal to a header of its own

2023-08-02 Thread Andreas Rheinhardt
Anton Khirnov:
> Quoting Andreas Rheinhardt (2023-07-11 03:10:38)
>> This allows to avoid exposing AVCodecInternal to files that
>> don't need it and only include internal.h for something else
>> (like the avpriv functions which are of course included outside
>> of libavcodec where AVCodecInternal should never be visible).
> 
> Actually looking at all those other things in internal.h it seems to me
> that (almost?) all of them belong somewhere else.
> 
> Multiple functions are only used in one place, some others are
> encoding-only and belong in encode.h, etc.
> 

I just sent some patches that moved some of those functions to their
only callers; there is one more, namely ff_alloc_timecode_sei(), but I
am unsure of how intentional it was to put it in utils.c.

ff_guess_coded_bitrate() could be moved to encode.h, but I am unsure
whether the implementation should not be moved to encode.c (or to a new
encode_utils.c?) in this case. Furthermore this function is only used by
encoders, but it is used to set a field (namely AVCodecContext.bit_rate)
which encoders are not allowed to set (for raw codecs the bitrate that
will be used is actually determined by other factors (like dimensions
fps, pixel/sample format), but normally bitrate is an input parameter
when encoding).

ff_add_cpb_side_data() is used by mostly encoders, but also used by
mpeg12dec.c, so there is currently no better place for this.

The two avpriv functions as well as ff_toupper4() (duplicated into lavf
for shared builds) can't be moved to their only callers, obviously.

ff_exp2fi() is only used by two places and could be moved to e.g.
mathops.h, but then this function would be included in so many places
where it is not used.

ff_match_2uint16() could be used to e.g. mpegutils.h, but that is just
based upon the current users and not about the function itself.

FF_SANE_NB_CHANNELS is used in several demuxers (which is the reason why
I want to separate AVCodecInternal out of internal.h).

So I conclude that one can't move everything except AVCodecInternal out
of internal.h into existing headers/callers. So either one adds a new
header misc.h or utils.h for the rest or one adds a new header for
AVCodecInternal. Or one leaves everything as it is.

- 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] libswresample: Prevent out of bounds.

2023-08-02 Thread Michael Niedermayer
On Wed, Aug 02, 2023 at 03:14:10PM +0300, kobrineli wrote:
> From: Eli Kobrin 
> 
> We've been fuzzing torchvision with 
> [sydr-fuzz](https://github.com/ispras/oss-sydr-fuzz)
> and found out of bounds error in ffmpeg project at audioconvert.c:151.
> To prevent error we need to fix checks for in and out fmt in swr_init.
> 
> Signed-off-by: Eli Kobrin 
> ---
>  libswresample/swresample.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

will apply

thx

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

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato


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] [META] Down with plaintext email policies

2023-08-02 Thread Fredrick R. Brennan
In general, unless a listserv, such as ffmpeg's, requires it, I only 
send HTML email. Please do not request plaintext personal email from me 
without a very good reason to do so. I do this as very few free software 
folks of any competence in our community insist on it. HTML email:


 *      allows for certain W3C standard certain accessibility features;
 *      certain global scripts to be interchanged; and
 *      allows Deaf people to interchange embedded video and SignWriting.

Plain email policies may have been relevant during the earlier days of 
the Internet, where simplicity was valued over accessibility or 
usability. But the technology landscape has evolved. And let us not 
assume that in allowing HTML email we must allow remote content, or even 
embedded eccentric furry signatures like my default attachment. 
Filtering is more than OK, it's essential on a listserv.


Maintaining the æsthetic of plaintext email is not worth the effort. I 
hope you will consider joining me in relaxing policies forbidding HTML 
email, perhaps starting discussions in listservs with outdated policies. 
If my emails annoy you, consider contributing to the email software you 
use to strengthen its ability to handle HTML email.


--


Best,
Fred Brennan|
|
|[[[ To any NSA and FBI agents reading my email: please consider ]]]|
|[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
|

GnuPG: |98F2 8F76 7470 129F BE3B 054C E215 4DD1 A1C7 7B8B|
Twitter: @fr_brennan
Personal website 



OpenPGP_0xE2154DD1A1C77B8B.asc
Description: OpenPGP public key
--- Begin Message ---
<<< image/webp; name="lZTn86kxZ8uLqDMV.webp": Unrecognized >>>


OpenPGP_0xE2154DD1A1C77B8B.asc
Description: OpenPGP public key


OpenPGP_signature.asc
Description: OpenPGP digital signature
--- End Message ---


OpenPGP_signature.asc
Description: OpenPGP digital 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] What is FFmpeg and what should it be

2023-08-02 Thread Cosmin Stejerean



> On Aug 2, 2023, at 7:30 AM, Nicolas George  wrote:
> 
> Michael Niedermayer (12023-08-02):
>> The libraries should be split into runtime loadable plugins
>> Not only would that make tools alot smaller it also would allow
>> development of code available in ffmpeg that is maintained outside
>> FFmpeg.
>> 
>> I suggested this previosuly, it is of course not a "simple" thing
>> to do.
> 
> No, it would be a terrible mistake.
> 
> And mostly, people who suggest or demand that do it based on
> misconceptions about how linking works and/or have no actual scenario
> where that would help.
> 
> But this is another discussion entirely.

This indeed feels like a separate discussion, but should we want to have that 
discussion I'd be happy to both provide some use cases as well as contribute 
code to facilitate the implementation. 

My understanding however is that the community is opposed to dynamically loaded 
plugins on principle, because it would make it easier to distribute proprietary 
plugins and sidestep the intent of the copyleft licensing.

- Cosmin




___
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 v6 4/5] avformat/jpegxl: remove jpegxl_probe, instead call avcodec/jpegxl_parse

2023-08-02 Thread Andreas Rheinhardt
Leo Izen:
> On 8/1/23 14:59, Michael Niedermayer wrote:
>> On Tue, Aug 01, 2023 at 09:30:54AM -0400, Leo Izen wrote:
>>> This prevents code duplication in the source form by calling the parse
>>> code that was moved to avcodec last commit. The code will be duplicated
>>> in binary form for shared builds (it's not that large), but for source
>>> code it will only exist in one location now.
>>>
>>> Signed-off-by: Leo Izen 
>>> ---
>>>   libavformat/Makefile  |   6 +-
>>>   libavformat/img2dec.c |   4 +-
>>>   libavformat/jpegxl_anim_dec.c | 132 +++
>>>   libavformat/jpegxl_probe.c    | 412 --
>>>   libavformat/jpegxl_probe.h    |  37 ---
>>>   libavformat/version.h |   2 +-
>>>   6 files changed, 38 insertions(+), 555 deletions(-)
>>>   delete mode 100644 libavformat/jpegxl_probe.c
>>>   delete mode 100644 libavformat/jpegxl_probe.h
>>
>> breaks build with shared libs
>>
> 
> Interesting, I have jpegxl_parse.o in SHLIOBJS, but the actual file is
> in libavcodec, and it's in libavcodec/Makefile's STLIOBJS declaration.
> What else do I need to do in order to allow it to link into libavformat?
> 

It seems you forgot to add the lavf/jpegxl_parse.c stub.

- 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 v7 0/5] JPEG XL Parser (and bug fixes)

2023-08-02 Thread Leo Izen
Changes from v6:
- Added dummy stub libavformat/jpegxl_parse.c to fix shared builds

Changes from v5:
- Attached an extra commit to fix existing bug with libjxldec
- Made various changes based on comments by Andreas Reinhardt
-- removed jpegxl_parse.c from avformat, and jpegxl_parse.o from 
avformat/Makefile/OBJS
-- checked for failure in init_vlc_lengths
-- used a macro to initialize VLCElem structs
-- used heap allocations for a buffer of size 250k, instead of stack
-- renamed "code" to "len"
- Fix demuxer to avoid using avio_size, breaking piped input
- Fix some parser bugs discovered during more extensive testing

Changes from v4:
- Added an entropy decoder and full parser, which finds the
boundaries between files correctly
- Removed unnecessary logging in libjxldec

Changes from v3:

- Don't remove AV_CODEC_CAP_DR1 from libjxldec
- jpegxl_parse.o added to STLIBOBJS in avcodec/Makefile
- add pipe demuxer to avformat/Makefile's SHLIBOBJS

Changes from v2:

- Fix libjxldec to work with packets that are smaller than one frame
- Change how code is shared between libavcodec and libavformat to be more 
sensible.
- Fix the parser to work with large headers that proceed the codestream in a 
container format
(for example, if several-KB Exif boxes preceed the codestream.)
- Modify the parser to set width/height instead of avctx
  Note: avctx->pix_fmt and s->format are both set, because otherwise the CLI 
tools won't print
the pixel format without libjxl enabled.
- Update the fate test based on the new parser's packetization

This test relies on FATE samples that haven't been uploaded yet. To test, unzip
the following zipfile[1] in the FATE_SAMPLES directory, placing the test images 
in jxl/.

[1]: https://buzo.us/y.zip

sha256sum: 43a2eeb0dfdf471b47a9fdfb1653974fa156ceceb776891cc137569a8ebf0e75
signature: https://buzo.us/R.asc

Leo Izen (5):
  avcodec/libjxldec: fix errors when decoding grayscale after rgb
  avcodec/libjxldec: use internal AVFrame as buffered space
  avcodec/jpegxl_parser: add JPEG XL parser
  avformat/jpegxl: remove jpegxl_probe, instead call
avcodec/jpegxl_parse
  fate/jpegxl_anim: add demuxer fate test for jpegxl_anim

 libavcodec/Makefile   |3 +
 libavcodec/jpegxl.h   |   94 ++
 libavcodec/jpegxl_parse.c |  520 ++
 libavcodec/jpegxl_parse.h |   72 +
 libavcodec/jpegxl_parser.c| 1477 +
 libavcodec/libjxldec.c|   41 +-
 libavcodec/parsers.c  |1 +
 libavcodec/version.h  |2 +-
 libavformat/Makefile  |6 +-
 libavformat/img2dec.c |4 +-
 libavformat/jpegxl_anim_dec.c |  132 +-
 .../{jpegxl_probe.h => jpegxl_parse.c}|   21 +-
 libavformat/jpegxl_probe.c|  412 -
 libavformat/version.h |2 +-
 tests/Makefile|1 +
 tests/fate/jxl.mak|   16 +
 tests/ref/fate/jxl-anim-demux-belgium |6 +
 tests/ref/fate/jxl-anim-demux-icos4d  |6 +
 tests/ref/fate/jxl-anim-demux-lenna256|6 +
 tests/ref/fate/jxl-anim-demux-newton  |6 +
 20 files changed, 2273 insertions(+), 555 deletions(-)
 create mode 100644 libavcodec/jpegxl.h
 create mode 100644 libavcodec/jpegxl_parse.c
 create mode 100644 libavcodec/jpegxl_parse.h
 create mode 100644 libavcodec/jpegxl_parser.c
 rename libavformat/{jpegxl_probe.h => jpegxl_parse.c} (55%)
 delete mode 100644 libavformat/jpegxl_probe.c
 create mode 100644 tests/fate/jxl.mak
 create mode 100644 tests/ref/fate/jxl-anim-demux-belgium
 create mode 100644 tests/ref/fate/jxl-anim-demux-icos4d
 create mode 100644 tests/ref/fate/jxl-anim-demux-lenna256
 create mode 100644 tests/ref/fate/jxl-anim-demux-newton

-- 
2.41.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 v7 1/5] avcodec/libjxldec: fix errors when decoding grayscale after rgb

2023-08-02 Thread Leo Izen
Fixes an error that's caused by decoding a grayscale JXL image after an
RGB image is decoded, with the same decoder instance.

Signed-off-by: Leo Izen 
---
 libavcodec/libjxldec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index e45ac02c07..9be1d9295a 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -298,7 +298,7 @@ static int libjxl_color_encoding_event(AVCodecContext 
*avctx, AVFrame *frame)
 }
 
 avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG;
-if (ctx->jxl_pixfmt.num_channels >= 3)
+if (ctx->basic_info.num_color_channels > 1)
 avctx->colorspace = AVCOL_SPC_RGB;
 avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
 avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
@@ -334,7 +334,7 @@ static int libjxl_color_encoding_event(AVCodecContext 
*avctx, AVFrame *frame)
 }
 /* all colors will be in-gamut so we want accurate colors */
 jxl_color.rendering_intent = JXL_RENDERING_INTENT_RELATIVE;
-jxl_color.color_space = avctx->colorspace == AVCOL_SPC_RGB ? 
JXL_COLOR_SPACE_RGB : JXL_COLOR_SPACE_GRAY;
+jxl_color.color_space = ctx->basic_info.num_color_channels > 1 ? 
JXL_COLOR_SPACE_RGB : JXL_COLOR_SPACE_GRAY;
 jret = JxlDecoderSetPreferredColorProfile(ctx->decoder, &jxl_color);
 if (jret != JXL_DEC_SUCCESS) {
 av_log(avctx, AV_LOG_WARNING, "Unable to set fallback color 
encoding\n");
-- 
2.41.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 v7 2/5] avcodec/libjxldec: use internal AVFrame as buffered space

2023-08-02 Thread Leo Izen
Before this commit, the decoder erroneously assumes that the AVFrame
passed to the receive_frame is the same one each time. Now it keeps an
internal AVFrame to write into, and copies it over when it's done.

Signed-off-by: Leo Izen 
---
 libavcodec/libjxldec.c | 37 +
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index 9be1d9295a..002740d9c1 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -58,6 +58,7 @@ typedef struct LibJxlDecodeContext {
 int64_t frame_duration;
 int prev_is_last;
 AVRational timebase;
+AVFrame *frame;
 } LibJxlDecodeContext;
 
 static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
@@ -104,6 +105,9 @@ static av_cold int libjxl_decode_init(AVCodecContext *avctx)
 
 ctx->avpkt = avctx->internal->in_pkt;
 ctx->pts = 0;
+ctx->frame = av_frame_alloc();
+if (!ctx->frame)
+return AVERROR(ENOMEM);
 
 return libjxl_init_jxl_decoder(avctx);
 }
@@ -406,10 +410,6 @@ static int libjxl_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 return AVERROR_INVALIDDATA;
 case JXL_DEC_NEED_MORE_INPUT:
 av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");
-if (!pkt->size) {
-av_packet_unref(pkt);
-return AVERROR(EAGAIN);
-}
 continue;
 case JXL_DEC_BASIC_INFO:
 av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n");
@@ -438,16 +438,19 @@ static int libjxl_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 continue;
 case JXL_DEC_COLOR_ENCODING:
 av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n");
-if ((ret = libjxl_color_encoding_event(avctx, frame)) < 0)
+ret = libjxl_color_encoding_event(avctx, ctx->frame);
+if (ret < 0)
 return ret;
 continue;
 case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
 av_log(avctx, AV_LOG_DEBUG, "NEED_IMAGE_OUT_BUFFER event 
emitted\n");
-if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+ret = ff_get_buffer(avctx, ctx->frame, 0);
+if (ret < 0)
 return ret;
-ctx->jxl_pixfmt.align = frame->linesize[0];
-if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, 
frame->data[0], frame->buf[0]->size)
-!= JXL_DEC_SUCCESS) {
+ctx->jxl_pixfmt.align = ctx->frame->linesize[0];
+if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt,
+ctx->frame->data[0], ctx->frame->buf[0]->size)
+!= JXL_DEC_SUCCESS) {
 av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out 
buffer event\n");
 return AVERROR_EXTERNAL;
 }
@@ -461,8 +464,8 @@ static int libjxl_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 case JXL_DEC_FRAME:
 av_log(avctx, AV_LOG_DEBUG, "FRAME event emitted\n");
 if (!ctx->basic_info.have_animation || ctx->prev_is_last) {
-frame->pict_type = AV_PICTURE_TYPE_I;
-frame->flags |= AV_FRAME_FLAG_KEY;
+ctx->frame->pict_type = AV_PICTURE_TYPE_I;
+ctx->frame->flags |= AV_FRAME_FLAG_KEY;
 }
 if (ctx->basic_info.have_animation) {
 JxlFrameHeader header;
@@ -481,20 +484,21 @@ static int libjxl_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 /* full image is one frame, even if animated */
 av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");
 if (ctx->iccp) {
-AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, 
AV_FRAME_DATA_ICC_PROFILE, ctx->iccp);
+AVFrameSideData *sd = 
av_frame_new_side_data_from_buf(ctx->frame, AV_FRAME_DATA_ICC_PROFILE, 
ctx->iccp);
 if (!sd)
 return AVERROR(ENOMEM);
 /* ownership is transfered, and it is not ref-ed */
 ctx->iccp = NULL;
 }
 if (avctx->pkt_timebase.num) {
-frame->pts = av_rescale_q(ctx->pts, ctx->timebase, 
avctx->pkt_timebase);
-frame->duration = av_rescale_q(ctx->frame_duration, 
ctx->timebase, avctx->pkt_timebase);
+ctx->frame->pts = av_rescale_q(ctx->pts, ctx->timebase, 
avctx->pkt_timebase);
+ctx->frame->duration = av_rescale_q(ctx->frame_duration, 
ctx->timebase, avctx->pkt_timebase);
 } else {
-frame->pts = ctx->pts;
-frame->duration = ctx->frame_duration;
+ctx->frame->pts = ctx->pts;
+ctx->frame->duration = ctx->frame_duration;
 }
 ctx->pts += ctx->frame_duration;
+av_frame_move_ref(frame, ctx->frame);
 return 0;

[FFmpeg-devel] [PATCH v7 3/5] avcodec/jpegxl_parser: add JPEG XL parser

2023-08-02 Thread Leo Izen
Add a parser to libavcodec for AV_CODEC_ID_JPEGXL. It doesn't find the
end of the stream in order to packetize the codec, but it does look at
the headers to set preliminary information like dimensions and pixel
format.

Note that much of this code is duplicated from avformat/jpegxl_probe.c,
but that code will be removed and call this instead in the next commit.

Signed-off-by: Leo Izen 
---
 libavcodec/Makefile|3 +
 libavcodec/jpegxl.h|   94 +++
 libavcodec/jpegxl_parse.c  |  520 +
 libavcodec/jpegxl_parse.h  |   72 ++
 libavcodec/jpegxl_parser.c | 1477 
 libavcodec/parsers.c   |1 +
 libavcodec/version.h   |2 +-
 7 files changed, 2168 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/jpegxl.h
 create mode 100644 libavcodec/jpegxl_parse.c
 create mode 100644 libavcodec/jpegxl_parse.h
 create mode 100644 libavcodec/jpegxl_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3c16b51462..f961d0abd6 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1056,6 +1056,8 @@ STLIBOBJS-$(CONFIG_AVFORMAT)   += to_upper4.o
 STLIBOBJS-$(CONFIG_ISO_MEDIA)  += mpegaudiotabs.o
 STLIBOBJS-$(CONFIG_FLV_MUXER)  += mpeg4audio_sample_rates.o
 STLIBOBJS-$(CONFIG_HLS_DEMUXER)+= ac3_channel_layout_tab.o
+STLIBOBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER) += jpegxl_parse.o
+STLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER)   += jpegxl_parse.o
 STLIBOBJS-$(CONFIG_MATROSKA_DEMUXER)   += mpeg4audio_sample_rates.o
 STLIBOBJS-$(CONFIG_MOV_DEMUXER)+= ac3_channel_layout_tab.o
 STLIBOBJS-$(CONFIG_MXF_MUXER)  += golomb.o
@@ -1185,6 +1187,7 @@ OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o 
hevc_data.o
 OBJS-$(CONFIG_HDR_PARSER)  += hdr_parser.o
 OBJS-$(CONFIG_IPU_PARSER)  += ipu_parser.o
 OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o
+OBJS-$(CONFIG_JPEGXL_PARSER)   += jpegxl_parser.o jpegxl_parse.o
 OBJS-$(CONFIG_MISC4_PARSER)+= misc4_parser.o
 OBJS-$(CONFIG_MJPEG_PARSER)+= mjpeg_parser.o
 OBJS-$(CONFIG_MLP_PARSER)  += mlp_parse.o mlp_parser.o mlp.o
diff --git a/libavcodec/jpegxl.h b/libavcodec/jpegxl.h
new file mode 100644
index 00..66a6be3555
--- /dev/null
+++ b/libavcodec/jpegxl.h
@@ -0,0 +1,94 @@
+/*
+ * JPEG XL Common Header Definitions
+ * Copyright (c) 2023 Leo Izen 
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_JPEGXL_H
+#define AVCODEC_JPEGXL_H
+
+#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff
+#define FF_JPEGXL_CONTAINER_SIGNATURE_LE 0x204c584a0c00
+#define FF_JPEGXL_CODESTREAM_SIGNATURE_BE 0xff0a
+#define FF_JPEGXL_CONTAINER_SIGNATURE_BE 0x000c4a584c20
+
+typedef enum FFJXLFrameEncoding {
+JPEGXL_ENC_VARDCT,
+JPEGXL_ENC_MODULAR
+} FFJXLFrameEncoding;
+
+typedef enum FFJXLFrameType {
+JPEGXL_FRAME_REGULAR,
+JPEGXL_FRAME_LF,
+JPEGXL_FRAME_REFERENCE_ONLY,
+JPEGXL_FRAME_SKIP_PROGRESSIVE
+} FFJXLFrameType;
+
+typedef enum FFJXLBlendMode {
+JPEGXL_BM_REPLACE,
+JPEGXL_BM_ADD,
+JPEGXL_BM_BLEND,
+JPEGXL_BM_MULADD,
+JPEGXL_BM_MUL
+} FFJXLBlendMode;
+
+typedef enum FFJXLExtraChannelType {
+JPEGXL_CT_ALPHA = 0,
+JPEGXL_CT_DEPTH,
+JPEGXL_CT_SPOT_COLOR,
+JPEGXL_CT_SELECTION_MASK,
+JPEGXL_CT_BLACK,
+JPEGXL_CT_CFA,
+JPEGXL_CT_THERMAL,
+JPEGXL_CT_NON_OPTIONAL = 15,
+JPEGXL_CT_OPTIONAL
+} FFJXLExtraChannelType;
+
+typedef enum FFJXLColorSpace {
+JPEGXL_CS_RGB = 0,
+JPEGXL_CS_GRAY,
+JPEGXL_CS_XYB,
+JPEGXL_CS_UNKNOWN
+} FFJXLColorSpace;
+
+typedef enum FFJXLWhitePoint {
+JPEGXL_WP_D65 = 1,
+JPEGXL_WP_CUSTOM,
+JPEGXL_WP_E = 10,
+JPEGXL_WP_DCI = 11
+} FFJXLWhitePoint;
+
+typedef enum FFJXLPrimaries {
+JPEGXL_PR_SRGB = 1,
+JPEGXL_PR_CUSTOM,
+JPEGXL_PR_2100 = 9,
+JPEGXL_PR_P3 = 11,
+} FFJXLPrimaries;
+
+typedef enum FFJXLTransferCharacteristic {
+JPEGXL_TR_BT709 = 1,
+JPEGXL_TR_UNKNOWN,
+JPEGXL_TR_LINEAR = 8,
+JPEGXL_TR_SRGB = 13,
+JPEGXL_TR_PQ = 16,
+JPEGXL_TR_DCI,
+JPEGXL_TR_HLG,
+JPEGXL_TR_GAMMA = 1 << 24,
+} FFJXLTransferCharacteristic;
+
+#endif /* AVCODEC_JPEGXL_H */
diff --git a/libavcodec

[FFmpeg-devel] [PATCH v7 4/5] avformat/jpegxl: remove jpegxl_probe, instead call avcodec/jpegxl_parse

2023-08-02 Thread Leo Izen
This prevents code duplication in the source form by calling the parse
code that was moved to avcodec last commit. The code will be duplicated
in binary form for shared builds (it's not that large), but for source
code it will only exist in one location now.

Signed-off-by: Leo Izen 
---
 libavformat/Makefile  |   6 +-
 libavformat/img2dec.c |   4 +-
 libavformat/jpegxl_anim_dec.c | 132 ++
 .../{jpegxl_probe.h => jpegxl_parse.c}|  21 +-
 libavformat/jpegxl_probe.c| 412 --
 libavformat/version.h |   2 +-
 6 files changed, 41 insertions(+), 536 deletions(-)
 rename libavformat/{jpegxl_probe.h => jpegxl_parse.c} (55%)
 delete mode 100644 libavformat/jpegxl_probe.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index bd78c206b9..f9944baab9 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -283,7 +283,7 @@ OBJS-$(CONFIG_IMAGE_HDR_PIPE_DEMUXER) += img2dec.o 
img2.o
 OBJS-$(CONFIG_IMAGE_J2K_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_JPEG_PIPE_DEMUXER)+= img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER)  += img2dec.o img2.o
-OBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER)  += img2dec.o img2.o jpegxl_probe.o
+OBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER)  += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_PAM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_PBM_PIPE_DEMUXER) += img2dec.o img2.o
 OBJS-$(CONFIG_IMAGE_PCX_PIPE_DEMUXER) += img2dec.o img2.o
@@ -320,7 +320,7 @@ OBJS-$(CONFIG_IVF_MUXER) += ivfenc.o
 OBJS-$(CONFIG_IVR_DEMUXER)   += rmdec.o rm.o rmsipr.o
 OBJS-$(CONFIG_JACOSUB_DEMUXER)   += jacosubdec.o subtitles.o
 OBJS-$(CONFIG_JACOSUB_MUXER) += jacosubenc.o rawenc.o
-OBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER)   += jpegxl_anim_dec.o jpegxl_probe.o
+OBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER)   += jpegxl_anim_dec.o
 OBJS-$(CONFIG_JV_DEMUXER)+= jvdec.o
 OBJS-$(CONFIG_KUX_DEMUXER)   += flvdec.o
 OBJS-$(CONFIG_KVAG_DEMUXER)  += kvag.o
@@ -717,6 +717,8 @@ SHLIBOBJS+= log2_tab.o 
to_upper4.o
 SHLIBOBJS-$(CONFIG_ISO_MEDIA)+= mpegaudiotabs.o
 SHLIBOBJS-$(CONFIG_FLV_MUXER)+= mpeg4audio_sample_rates.o
 SHLIBOBJS-$(CONFIG_HLS_DEMUXER)  += ac3_channel_layout_tab.o
+SHLIBOBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER)+= jpegxl_parse.o
+SHLIBOBJS-$(CONFIG_JPEGXL_ANIM_DEMUXER)  += jpegxl_parse.o
 SHLIBOBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio_sample_rates.o
 SHLIBOBJS-$(CONFIG_MOV_DEMUXER)  += ac3_channel_layout_tab.o
 SHLIBOBJS-$(CONFIG_MP3_MUXER)+= mpegaudiotabs.o
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index b986d3a502..15fd67927f 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -36,7 +36,7 @@
 #include "avio_internal.h"
 #include "internal.h"
 #include "img2.h"
-#include "jpegxl_probe.h"
+#include "libavcodec/jpegxl_parse.h"
 #include "libavcodec/mjpeg.h"
 #include "libavcodec/vbn.h"
 #include "libavcodec/xwd.h"
@@ -850,7 +850,7 @@ static int jpegxl_probe(const AVProbeData *p)
 if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
 return 0;
 #if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER
-if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size, 1) >= 0)
+if (ff_jpegxl_parse_codestream_header(p->buf, p->buf_size, NULL, 5) >= 0)
 return AVPROBE_SCORE_MAX - 2;
 #endif
 return 0;
diff --git a/libavformat/jpegxl_anim_dec.c b/libavformat/jpegxl_anim_dec.c
index 956b56c1d8..fc95a1781f 100644
--- a/libavformat/jpegxl_anim_dec.c
+++ b/libavformat/jpegxl_anim_dec.c
@@ -28,96 +28,28 @@
 #include 
 #include 
 
-#include "libavcodec/bytestream.h"
-#define BITSTREAM_READER_LE
-#include "libavcodec/get_bits.h"
-
+#include "libavcodec/jpegxl.h"
+#include "libavcodec/jpegxl_parse.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
 
 #include "avformat.h"
 #include "internal.h"
-#include "jpegxl_probe.h"
 
 typedef struct JXLAnimDemuxContext {
 AVBufferRef *initial;
 } JXLAnimDemuxContext;
 
-/*
- * copies as much of the codestream into the buffer as possible
- * pass a shorter buflen to request less
- * returns the number of bytes consumed from input, may be greater than 
input_len
- * if the input doesn't end on an ISOBMFF-box boundary
- */
-static int jpegxl_collect_codestream_header(const uint8_t *input_buffer, int 
input_len,
-uint8_t *buffer, int buflen, int 
*copied) {
-GetByteContext gb;
-*copied = 0;
-bytestream2_init(&gb, input_buffer, input_len);
-
-while (1) {
-uint64_t size;
-uint32_t tag;
-int head_size = 8;
-
-if (bytestream2_get_bytes_left(&gb) < 16)
-break;
-
-size = bytestream2_get_be32(&gb);
-if (size == 1) {
-size = bytestream2_get_be64(&gb);
- 

[FFmpeg-devel] [PATCH v7 5/5] fate/jpegxl_anim: add demuxer fate test for jpegxl_anim

2023-08-02 Thread Leo Izen
Adds a fate test for the jpegxl_anim demuxer, that should allow testing
for true positives and false positives for animated jpegxl files. Note
that two of the test cases are not animated, in order to help sort out
false positives.

Signed-off-by: Leo Izen 
---
 tests/Makefile |  1 +
 tests/fate/jxl.mak | 16 
 tests/ref/fate/jxl-anim-demux-belgium  |  6 ++
 tests/ref/fate/jxl-anim-demux-icos4d   |  6 ++
 tests/ref/fate/jxl-anim-demux-lenna256 |  6 ++
 tests/ref/fate/jxl-anim-demux-newton   |  6 ++
 6 files changed, 41 insertions(+)
 create mode 100644 tests/fate/jxl.mak
 create mode 100644 tests/ref/fate/jxl-anim-demux-belgium
 create mode 100644 tests/ref/fate/jxl-anim-demux-icos4d
 create mode 100644 tests/ref/fate/jxl-anim-demux-lenna256
 create mode 100644 tests/ref/fate/jxl-anim-demux-newton

diff --git a/tests/Makefile b/tests/Makefile
index e09f30a0fc..7b80762e81 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -201,6 +201,7 @@ include $(SRC_PATH)/tests/fate/image.mak
 include $(SRC_PATH)/tests/fate/imf.mak
 include $(SRC_PATH)/tests/fate/indeo.mak
 include $(SRC_PATH)/tests/fate/jpeg2000.mak
+include $(SRC_PATH)/tests/fate/jxl.mak
 include $(SRC_PATH)/tests/fate/libavcodec.mak
 include $(SRC_PATH)/tests/fate/libavdevice.mak
 include $(SRC_PATH)/tests/fate/libavformat.mak
diff --git a/tests/fate/jxl.mak b/tests/fate/jxl.mak
new file mode 100644
index 00..057d3be0e1
--- /dev/null
+++ b/tests/fate/jxl.mak
@@ -0,0 +1,16 @@
+# These two are animated JXL files
+FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-newton
+fate-jxl-anim-demux-newton: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/newton.jxl 
-c copy
+FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-icos4d
+fate-jxl-anim-demux-icos4d: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/icos4d.jxl 
-c copy
+
+# These two are not animated JXL. They are here to check false positives.
+FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-belgium
+fate-jxl-anim-demux-belgium: CMD = framecrc -i 
$(TARGET_SAMPLES)/jxl/belgium.jxl -c copy
+FATE_JPEGXL_ANIM_DEMUX += fate-jxl-anim-demux-lenna256
+fate-jxl-anim-demux-lenna256: CMD = framecrc -i 
$(TARGET_SAMPLES)/jxl/lenna-256.jxl -c copy
+
+FATE_JPEGXL_ANIM_DEMUX += $(FATE_JPEGXL_ANIM_DEMUX-yes)
+
+FATE_SAMPLES_FFMPEG-$(call FRAMECRC, JPEGXL_ANIM) += $(FATE_JPEGXL_ANIM_DEMUX)
+fate-jxl-anim-demux: $(FATE_JPEGXL_ANIM_DEMUX)
diff --git a/tests/ref/fate/jxl-anim-demux-belgium 
b/tests/ref/fate/jxl-anim-demux-belgium
new file mode 100644
index 00..b2fe5035ac
--- /dev/null
+++ b/tests/ref/fate/jxl-anim-demux-belgium
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 768x512
+#sar 0: 0/1
+0,  0,  0,1,   32, 0xa2930a20
diff --git a/tests/ref/fate/jxl-anim-demux-icos4d 
b/tests/ref/fate/jxl-anim-demux-icos4d
new file mode 100644
index 00..eff6ff1f1b
--- /dev/null
+++ b/tests/ref/fate/jxl-anim-demux-icos4d
@@ -0,0 +1,6 @@
+#tb 0: 1/1000
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 48x48
+#sar 0: 0/1
+0,  0,  0,0,67898, 0x53b6516b
diff --git a/tests/ref/fate/jxl-anim-demux-lenna256 
b/tests/ref/fate/jxl-anim-demux-lenna256
new file mode 100644
index 00..99233d612a
--- /dev/null
+++ b/tests/ref/fate/jxl-anim-demux-lenna256
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 256x256
+#sar 0: 0/1
+0,  0,  0,1, 8088, 0xbbfea9bd
diff --git a/tests/ref/fate/jxl-anim-demux-newton 
b/tests/ref/fate/jxl-anim-demux-newton
new file mode 100644
index 00..6fcb85c41e
--- /dev/null
+++ b/tests/ref/fate/jxl-anim-demux-newton
@@ -0,0 +1,6 @@
+#tb 0: 1/1000
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 128x96
+#sar 0: 0/1
+0,  0,  0,0,43376, 0xb2296182
-- 
2.41.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 v3 1/6] avcodec/cbs_av1: Add tx mode enum values

2023-08-02 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/av1.h | 7 +++
 libavcodec/cbs_av1_syntax_template.c | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavcodec/av1.h b/libavcodec/av1.h
index 384f7cddc7..8704bc41c1 100644
--- a/libavcodec/av1.h
+++ b/libavcodec/av1.h
@@ -175,6 +175,13 @@ enum {
 AV1_RESTORE_SWITCHABLE = 3,
 };
 
+// TX mode (section 6.8.21)
+enum {
+AV1_ONLY_4X4= 0,
+AV1_TX_MODE_LARGEST = 1,
+AV1_TX_MODE_SELECT  = 2,
+};
+
 // Sequence Headers are actually unbounded because one can use
 // an arbitrary number of leading zeroes when encoding via uvlc.
 // The following estimate is based around using the lowest number
diff --git a/libavcodec/cbs_av1_syntax_template.c 
b/libavcodec/cbs_av1_syntax_template.c
index a747e17784..3a5cafbfb7 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1028,9 +1028,9 @@ static int FUNC(read_tx_mode)(CodedBitstreamContext *ctx, 
RWContext *rw,
 int err;
 
 if (priv->coded_lossless)
-infer(tx_mode, 0);
+infer(tx_mode, AV1_ONLY_4X4);
 else
-increment(tx_mode, 1, 2);
+increment(tx_mode, AV1_TX_MODE_LARGEST, AV1_TX_MODE_SELECT);
 
 return 0;
 }
-- 
2.25.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/6] lavc/av1: Add common code and unit test for level handling

2023-08-02 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
update:
1. Rename libavcodec/av1_levels*.
2. Use array instead of handle for AV1LevelDescriptor.name.
3. Compile libavcodec/av1_levels* only when enable vaapi av1 encoder.

 libavcodec/Makefile   |   1 +
 libavcodec/av1_levels.c   |  92 +
 libavcodec/av1_levels.h   |  58 
 libavcodec/tests/.gitignore   |   1 +
 libavcodec/tests/av1_levels.c | 124 ++
 tests/fate/libavcodec.mak |   5 ++
 6 files changed, 281 insertions(+)
 create mode 100644 libavcodec/av1_levels.c
 create mode 100644 libavcodec/av1_levels.h
 create mode 100644 libavcodec/tests/av1_levels.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3c16b51462..a6b2ecbb22 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1319,6 +1319,7 @@ TESTPROGS = avcodec   
  \
 jpeg2000dwt \
 mathops\
 
+TESTPROGS-$(CONFIG_AV1_VAAPI_ENCODER) += av1_levels
 TESTPROGS-$(CONFIG_CABAC) += cabac
 TESTPROGS-$(CONFIG_DCT)   += avfft
 TESTPROGS-$(CONFIG_FFT)   += fft fft-fixed32
diff --git a/libavcodec/av1_levels.c b/libavcodec/av1_levels.c
new file mode 100644
index 00..19b6ee1736
--- /dev/null
+++ b/libavcodec/av1_levels.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2023 Intel Corporation
+ *
+ * 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 
+#include "libavutil/macros.h"
+#include "av1_levels.h"
+
+/** ignore entries which named in spec but no details. Like level 2.2 and 7.0. 
*/
+static const AV1LevelDescriptor av1_levels[] = {
+// Name  MaxVSize   MainMbps   
   MaxTiles
+// |  level_idx | MaxDisplayRate| 
HighMbps | MaxTileCols
+// |  |   MaxPicSize|   | MaxDecodeRate || 
  MainCR|   |
+// |  | |MaxHSize   |   |   | MaxHeaderRate || 
| HighCR|   |
+// |  | ||  |   |   |   |   || 
|  ||   |
+{ "2.0",  0,   147456,  2048, 1152,   4423680, 5529600, 150,   1.5,
 0, 2, 0,   8,  4 },
+{ "2.1",  1,   278784,  2816, 1584,   8363520,10454400, 150,   3.0,
 0, 2, 0,   8,  4 },
+{ "3.0",  4,   665856,  4352, 2448,  19975680,24969600, 150,   6.0,
 0, 2, 0,  16,  6 },
+{ "3.1",  5,  1065024,  5504, 3096,  31950720,39938400, 150,  10.0,
 0, 2, 0,  16,  6 },
+{ "4.0",  8,  2359296,  6144, 3456,  70778880,77856768, 300,  12.0,  
30.0, 4, 4,  32,  8 },
+{ "4.1",  9,  2359296,  6144, 3456,  141557760,  155713536, 300,  20.0,  
50.0, 4, 4,  32,  8 },
+{ "5.0", 12,  8912896,  8192, 4352,  267386880,  273715200, 300,  30.0, 
100.0, 6, 4,  64,  8 },
+{ "5.1", 13,  8912896,  8192, 4352,  534773760,  547430400, 300,  40.0, 
160.0, 8, 4,  64,  8 },
+{ "5.2", 14,  8912896,  8192, 4352, 1069547520, 1094860800, 300,  60.0, 
240.0, 8, 4,  64,  8 },
+{ "5.3", 15,  8912896,  8192, 4352, 1069547520, 1176502272, 300,  60.0, 
240.0, 8, 4,  64,  8 },
+{ "6.0", 16, 35651584, 16384, 8704, 1069547520, 1176502272, 300,  60.0, 
240.0, 8, 4, 128, 16 },
+{ "6.1", 17, 35651584, 16384, 8704, 2139095040, 2189721600, 300, 100.0, 
480.0, 8, 4, 128, 16 },
+{ "6.2", 18, 35651584, 16384, 8704, 4278190080, 4379443200, 300, 160.0, 
800.0, 8, 4, 128, 16 },
+{ "6.3", 19, 35651584, 16384, 8704, 4278190080, 4706009088, 300, 160.0, 
800.0, 8, 4, 128, 16 },
+};
+
+const AV1LevelDescriptor *ff_av1_guess_level(int64_t bitrate,
+ int tier,
+ int width,
+ int height,
+ int tiles,
+ int tile_cols,
+ float fps)
+{
+int pic_size;
+uint64_t display_rate;
+float max_br;
+
+pic_size = width * height;
+display_rate = (uint64_t

[FFmpeg-devel] [PATCH v3 3/6] lavc/vaapi_encode: Init pic at the beginning of API

2023-08-02 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index bfca315a7a..8c9f14df66 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1205,7 +1205,7 @@ fail:
 int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
-VAAPIEncodePicture *pic;
+VAAPIEncodePicture *pic = NULL;
 AVFrame *frame = ctx->frame;
 int err;
 
@@ -1228,8 +1228,6 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 }
 
 if (ctx->has_sync_buffer_func) {
-pic = NULL;
-
 if (av_fifo_can_write(ctx->encode_fifo)) {
 err = vaapi_encode_pick_next(avctx, &pic);
 if (!err) {
@@ -1255,7 +1253,6 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 av_fifo_read(ctx->encode_fifo, &pic, 1);
 ctx->encode_order = pic->encode_order + 1;
 } else {
-pic = NULL;
 err = vaapi_encode_pick_next(avctx, &pic);
 if (err < 0)
 return err;
-- 
2.25.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 4/6] lavc/vaapi_encode: Extract set output pkt timestamp function

2023-08-02 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c | 37 -
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 8c9f14df66..c8545cd8db 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -650,6 +650,27 @@ fail_at_end:
 return err;
 }
 
+static int vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
+ VAAPIEncodePicture *pic,
+ AVPacket *pkt)
+{
+VAAPIEncodeContext *ctx = avctx->priv_data;
+
+if (ctx->output_delay == 0) {
+pkt->dts = pkt->pts;
+} else if (pic->encode_order < ctx->decode_delay) {
+if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
+pkt->dts = INT64_MIN;
+else
+pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
+} else {
+pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
+(3 * ctx->output_delay + ctx->async_depth)];
+}
+
+return 0;
+}
+
 static int vaapi_encode_output(AVCodecContext *avctx,
VAAPIEncodePicture *pic, AVPacket *pkt)
 {
@@ -1273,19 +1294,9 @@ int ff_vaapi_encode_receive_packet(AVCodecContext 
*avctx, AVPacket *pkt)
 return err;
 }
 
-if (ctx->output_delay == 0) {
-pkt->dts = pkt->pts;
-} else if (pic->encode_order < ctx->decode_delay) {
-if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
-pkt->dts = INT64_MIN;
-else
-pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
-} else {
-pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
-(3 * ctx->output_delay + ctx->async_depth)];
-}
-av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64" dts 
%"PRId64".\n",
-   pkt->pts, pkt->dts);
+vaapi_encode_set_output_timestamp(avctx, pic, pkt);
+av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64", dts %"PRId64", "
+   "size %u bytes.\n", pkt->pts, pkt->dts, pkt->size);
 
 ctx->output_order = pic->encode_order;
 vaapi_encode_clear_old(avctx);
-- 
2.25.1

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 5/6] lavc/vaapi_encode: Separate reference frame into previous/future list

2023-08-02 Thread fei . w . wang-at-intel . com
From: Fei Wang 

To support more reference frames from different directions.

Signed-off-by: Fei Wang 
---
 libavcodec/vaapi_encode.c   | 112 +---
 libavcodec/vaapi_encode.h   |  15 +++--
 libavcodec/vaapi_encode_h264.c  |  94 +--
 libavcodec/vaapi_encode_h265.c  |  76 +-
 libavcodec/vaapi_encode_mpeg2.c |   6 +-
 libavcodec/vaapi_encode_vp8.c   |   6 +-
 libavcodec/vaapi_encode_vp9.c   |  26 
 7 files changed, 208 insertions(+), 127 deletions(-)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index c8545cd8db..2604f12b9e 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -276,21 +276,34 @@ static int vaapi_encode_issue(AVCodecContext *avctx,
 av_log(avctx, AV_LOG_DEBUG, "Issuing encode for pic %"PRId64"/%"PRId64" "
"as type %s.\n", pic->display_order, pic->encode_order,
picture_type_name[pic->type]);
-if (pic->nb_refs == 0) {
+if (pic->nb_refs[0] == 0 && pic->nb_refs[1] == 0) {
 av_log(avctx, AV_LOG_DEBUG, "No reference pictures.\n");
 } else {
-av_log(avctx, AV_LOG_DEBUG, "Refers to:");
-for (i = 0; i < pic->nb_refs; i++) {
+av_log(avctx, AV_LOG_DEBUG, "L0 refers to");
+for (i = 0; i < pic->nb_refs[0]; i++) {
 av_log(avctx, AV_LOG_DEBUG, " %"PRId64"/%"PRId64,
-   pic->refs[i]->display_order, pic->refs[i]->encode_order);
+   pic->refs[0][i]->display_order, 
pic->refs[0][i]->encode_order);
 }
 av_log(avctx, AV_LOG_DEBUG, ".\n");
+
+if (pic->nb_refs[1]) {
+av_log(avctx, AV_LOG_DEBUG, "L1 refers to");
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_log(avctx, AV_LOG_DEBUG, " %"PRId64"/%"PRId64,
+   pic->refs[1][i]->display_order, 
pic->refs[1][i]->encode_order);
+}
+av_log(avctx, AV_LOG_DEBUG, ".\n");
+}
 }
 
 av_assert0(!pic->encode_issued);
-for (i = 0; i < pic->nb_refs; i++) {
-av_assert0(pic->refs[i]);
-av_assert0(pic->refs[i]->encode_issued);
+for (i = 0; i < pic->nb_refs[0]; i++) {
+av_assert0(pic->refs[0][i]);
+av_assert0(pic->refs[0][i]->encode_issued);
+}
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_assert0(pic->refs[1][i]);
+av_assert0(pic->refs[1][i]->encode_issued);
 }
 
 av_log(avctx, AV_LOG_DEBUG, "Input surface is %#x.\n", pic->input_surface);
@@ -832,8 +845,12 @@ static void vaapi_encode_add_ref(AVCodecContext *avctx,
 
 if (is_ref) {
 av_assert0(pic != target);
-av_assert0(pic->nb_refs < MAX_PICTURE_REFERENCES);
-pic->refs[pic->nb_refs++] = target;
+av_assert0(pic->nb_refs[0] < MAX_PICTURE_REFERENCES &&
+   pic->nb_refs[1] < MAX_PICTURE_REFERENCES);
+if (target->display_order < pic->display_order)
+pic->refs[0][pic->nb_refs[0]++] = target;
+else
+pic->refs[1][pic->nb_refs[1]++] = target;
 ++refs;
 }
 
@@ -862,10 +879,16 @@ static void vaapi_encode_remove_refs(AVCodecContext 
*avctx,
 if (pic->ref_removed[level])
 return;
 
-for (i = 0; i < pic->nb_refs; i++) {
-av_assert0(pic->refs[i]);
---pic->refs[i]->ref_count[level];
-av_assert0(pic->refs[i]->ref_count[level] >= 0);
+for (i = 0; i < pic->nb_refs[0]; i++) {
+av_assert0(pic->refs[0][i]);
+--pic->refs[0][i]->ref_count[level];
+av_assert0(pic->refs[0][i]->ref_count[level] >= 0);
+}
+
+for (i = 0; i < pic->nb_refs[1]; i++) {
+av_assert0(pic->refs[1][i]);
+--pic->refs[1][i]->ref_count[level];
+av_assert0(pic->refs[1][i]->ref_count[level] >= 0);
 }
 
 for (i = 0; i < pic->nb_dpb_pics; i++) {
@@ -910,7 +933,7 @@ static void vaapi_encode_set_b_pictures(AVCodecContext 
*avctx,
 vaapi_encode_add_ref(avctx, pic, end,   1, 1, 0);
 vaapi_encode_add_ref(avctx, pic, prev,  0, 0, 1);
 
-for (ref = end->refs[1]; ref; ref = ref->refs[1])
+for (ref = end->refs[1][0]; ref; ref = ref->refs[1][0])
 vaapi_encode_add_ref(avctx, pic, ref, 0, 1, 0);
 }
 *last = prev;
@@ -933,7 +956,7 @@ static void vaapi_encode_set_b_pictures(AVCodecContext 
*avctx,
 vaapi_encode_add_ref(avctx, pic, end,   1, 1, 0);
 vaapi_encode_add_ref(avctx, pic, prev,  0, 0, 1);
 
-for (ref = end->refs[1]; ref; ref = ref->refs[1])
+for (ref = end->refs[1][0]; ref; ref = ref->refs[1][0])
 vaapi_encode_add_ref(avctx, pic, ref, 0, 1, 0);
 
 if (i > 1)
@@ -947,11 +970,44 @@ static void vaapi_encode_set_b_pictures(AVCodecContext 
*avctx,
 }
 }
 
+static void vaapi_encode_add_next_prev(AVCodecContext *avctx,
+   VAAPIEncodePicture *pic)
+{
+VAAPIEncodeContext *ctx = avctx->priv_d

[FFmpeg-devel] [PATCH v3 6/6] lavc/vaapi_encode: Add VAAPI AV1 encoder

2023-08-02 Thread fei . w . wang-at-intel . com
From: Fei Wang 

Signed-off-by: Fei Wang 
---
 Changelog |1 +
 configure |3 +
 doc/encoders.texi |   13 +
 libavcodec/Makefile   |1 +
 libavcodec/allcodecs.c|1 +
 libavcodec/vaapi_encode.c |  125 +++-
 libavcodec/vaapi_encode.h |   12 +
 libavcodec/vaapi_encode_av1.c | 1229 +
 libavcodec/version.h  |2 +-
 9 files changed, 1368 insertions(+), 19 deletions(-)
 create mode 100644 libavcodec/vaapi_encode_av1.c

diff --git a/Changelog b/Changelog
index bbda4f4fd4..e86f742cd3 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - Bitstream filter for converting VVC from MP4 to Annex B
 - scale_vt filter for videotoolbox
 - transpose_vt filter for videotoolbox
+- VAAPI AV1 encoder
 
 version 6.0:
 - Radiance HDR image support
diff --git a/configure b/configure
index 99388e7664..68a238a819 100755
--- a/configure
+++ b/configure
@@ -3322,6 +3322,8 @@ av1_qsv_decoder_select="qsvdec"
 av1_qsv_encoder_select="qsvenc"
 av1_qsv_encoder_deps="libvpl"
 av1_amf_encoder_deps="amf"
+av1_vaapi_encoder_deps="VAEncPictureParameterBufferAV1"
+av1_vaapi_encoder_select="cbs_av1 vaapi_encode"
 
 # parsers
 aac_parser_select="adts_header mpeg4audio"
@@ -7106,6 +7108,7 @@ if enabled vaapi; then
 check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
 check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
 check_type "va/va.h va/va_enc_vp9.h"  "VAEncPictureParameterBufferVP9"
+check_type "va/va.h va/va_enc_av1.h"  "VAEncPictureParameterBufferAV1"
 fi
 
 if enabled_all opencl libdrm ; then
diff --git a/doc/encoders.texi b/doc/encoders.texi
index 25d6b7f09e..fb331ebd8e 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -3991,6 +3991,19 @@ Average variable bitrate.
 Each encoder also has its own specific options:
 @table @option
 
+@item av1_vaapi
+@option{profile} sets the value of @emph{seq_profile}.
+@option{tier} sets the value of @emph{seq_tier}.
+@option{level} sets the value of @emph{seq_level_idx}.
+
+@table @option
+@item tiles
+Set the number of tiles to encode the input video with, as columns x rows.
+(default is 1x1).
+@item tile_groups
+Set tile groups number (default is 1).
+@end table
+
 @item h264_vaapi
 @option{profile} sets the value of @emph{profile_idc} and the 
@emph{constraint_set*_flag}s.
 @option{level} sets the value of @emph{level_idc}.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a6b2ecbb22..473afb4471 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -258,6 +258,7 @@ OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER)  += mediacodecdec.o
 OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER)  += mediacodecenc.o
 OBJS-$(CONFIG_AV1_NVENC_ENCODER)   += nvenc_av1.o nvenc.o
 OBJS-$(CONFIG_AV1_QSV_ENCODER) += qsvenc_av1.o
+OBJS-$(CONFIG_AV1_VAAPI_ENCODER)   += vaapi_encode_av1.o av1_levels.o
 OBJS-$(CONFIG_AVRN_DECODER)+= avrndec.o
 OBJS-$(CONFIG_AVRP_DECODER)+= r210dec.o
 OBJS-$(CONFIG_AVRP_ENCODER)+= r210enc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8775d15a4f..c43c1d7b48 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -844,6 +844,7 @@ extern const FFCodec ff_av1_nvenc_encoder;
 extern const FFCodec ff_av1_qsv_decoder;
 extern const FFCodec ff_av1_qsv_encoder;
 extern const FFCodec ff_av1_amf_encoder;
+extern const FFCodec ff_av1_vaapi_encoder;
 extern const FFCodec ff_libopenh264_encoder;
 extern const FFCodec ff_libopenh264_decoder;
 extern const FFCodec ff_h264_amf_encoder;
diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 2604f12b9e..2907e159fb 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -669,6 +669,15 @@ static int 
vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 
+// AV1 packs P frame and next B frame into one pkt, and uses the other
+// repeat frame header pkt at the display order position of the P frame
+// to indicate its frame index. Each frame has a corresponding pkt in its
+// display order position. So don't need to consider delay for AV1 
timestamp.
+if (avctx->codec_id == AV_CODEC_ID_AV1) {
+pkt->dts = pkt->pts - ctx->dts_pts_diff;
+return 0;
+}
+
 if (ctx->output_delay == 0) {
 pkt->dts = pkt->pts;
 } else if (pic->encode_order < ctx->decode_delay) {
@@ -689,9 +698,10 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 {
 VAAPIEncodeContext *ctx = avctx->priv_data;
 VACodedBufferSegment *buf_list, *buf;
-VAStatus vas;
+AVPacket *pkt_ptr = pkt;
 int total_size = 0;
 uint8_t *ptr;
+VAStatus vas;
 int err;
 
 err = vaapi_encode_wait(avctx, pic);
@@ -711,11 +721,52 @@ static int vaapi_encode_output(AVCodecContext *avctx,
 for (buf = buf_list; buf; buf = buf->next)
 total_size += buf-