Re: [FFmpeg-devel] [PATCH 1/2] avcodec/s302m: enable non-PCM decoding

2024-01-22 Thread Kieran Kunhya
On Tue, 23 Jan 2024 at 06:50, Gyan Doshi  wrote:

> Set up framework for non-PCM decoding in-place and
> add support for Dolby-E decoding.
>
> Useful for direct transcoding of non-PCM audio in live inputs.
>

Does this handle a Dolby E packet spanning multiple S302M packets? I'm not
saying you should support this as it's rare and very annoying to implement
but it does happen.

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

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


[FFmpeg-devel] [PATCH 2/2] fate: add tests for dolby_e decoding in s302m

2024-01-22 Thread Gyan Doshi
Three tests, one each for

1) 16-bit Dolby-E words in 20-bits AES3 words
2) 20-bit Dolby-E words in 20-bits AES3 words
3) 20-bit Dolby-E words in 24-bits AES3 words
---
 tests/fate/acodec.mak   |  15 ++
 tests/ref/acodec/s302m-20-dolbye-16 | 221 
 tests/ref/acodec/s302m-20-dolbye-20 | 127 
 tests/ref/acodec/s302m-24-dolbye-20 | 170 +
 4 files changed, 533 insertions(+)
 create mode 100644 tests/ref/acodec/s302m-20-dolbye-16
 create mode 100644 tests/ref/acodec/s302m-20-dolbye-20
 create mode 100644 tests/ref/acodec/s302m-24-dolbye-20

Samples available during review at

https://gyan.dev/ffmpeg/s302m/s302_20bits_DolbyE_16bits.ts 
https://gyan.dev/ffmpeg/s302m/s302_20bits_DolbyE_20bits.ts 
https://gyan.dev/ffmpeg/s302m/s302_24bits_DolbyE_20bits.ts

Thanks to Nicolas Gaullier for the samples.

diff --git a/tests/fate/acodec.mak b/tests/fate/acodec.mak
index 7b09e3bd63..60d3b8515b 100644
--- a/tests/fate/acodec.mak
+++ b/tests/fate/acodec.mak
@@ -165,6 +165,21 @@ fate-acodec-s302m: CODEC = s302m
 fate-acodec-s302m: ENCOPTS = -af aresample=48000:tsf=s16p -strict -2
 fate-acodec-s302m: DECOPTS = -af aresample=44100:tsf=s16p
 
+FATE_ACODEC-$(call FRAMECRC, MPEGTS, S302M DOLBY_E) += 
fate-acodec-s302m-20-dolbye-16
+fate-acodec-s302m-20-dolbye-16: CMD = framecrc -auto_conversion_filters \
+  -non_pcm_mode decode_copy -i 
$(TARGET_SAMPLES)/s302m/s302_20bits_DolbyE_16bits.ts \
+  -vn -c:a pcm_s16le
+
+FATE_ACODEC-$(call FRAMECRC, MPEGTS, S302M DOLBY_E) += 
fate-acodec-s302m-20-dolbye-20
+fate-acodec-s302m-20-dolbye-20: CMD = framecrc -auto_conversion_filters \
+  -non_pcm_mode decode_copy -i 
$(TARGET_SAMPLES)/s302m/s302_20bits_DolbyE_20bits.ts \
+  -vn -c:a pcm_s16le
+
+FATE_ACODEC-$(call FRAMECRC, MPEGTS, S302M DOLBY_E) += 
fate-acodec-s302m-24-dolbye-20
+fate-acodec-s302m-24-dolbye-20: CMD = framecrc -auto_conversion_filters \
+  -non_pcm_mode decode_copy -i 
$(TARGET_SAMPLES)/s302m/s302_24bits_DolbyE_20bits.ts \
+  -vn -c:a pcm_s16le
+
 FATE_ACODEC-$(call ENCDEC, WAVPACK, WV, ARESAMPLE_FILTER) += 
fate-acodec-wavpack
 fate-acodec-wavpack: FMT = wv
 fate-acodec-wavpack: CODEC = wavpack -compression_level 1
diff --git a/tests/ref/acodec/s302m-20-dolbye-16 
b/tests/ref/acodec/s302m-20-dolbye-16
new file mode 100644
index 00..e0c7b9e13b
--- /dev/null
+++ b/tests/ref/acodec/s302m-20-dolbye-16
@@ -0,0 +1,221 @@
+#tb 0: 1/44800
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 44800
+#channel_layout_name 0: 5.1(side)
+0,  0,  0, 1792,21504, 0x9136aa8a
+0,   1792,   1792, 1792,21504, 0x6b8b42f0
+0,   3584,   3584, 1792,21504, 0xc73c0342
+0,   5376,   5376, 1792,21504, 0x9d777e2a
+0,   7168,   7168, 1792,21504, 0x2ee86c97
+0,   8960,   8960, 1792,21504, 0xfdd41829
+0,  10752,  10752, 1792,21504, 0x58ea1b12
+0,  12544,  12544, 1792,21504, 0xa81a35f4
+0,  14336,  14336, 1792,21504, 0x2bd9bb62
+0,  16128,  16128, 1792,21504, 0x0648940e
+0,  17920,  17920, 1792,21504, 0x377452f9
+0,  19712,  19712, 1792,21504, 0xf50f26b9
+0,  21504,  21504, 1792,21504, 0x935e7c69
+0,  23296,  23296, 1792,21504, 0x99363659
+0,  25088,  25088, 1792,21504, 0x78212dd2
+0,  26880,  26880, 1792,21504, 0x687f5776
+0,  28672,  28672, 1792,21504, 0xd6d3320c
+0,  30464,  30464, 1792,21504, 0x96e1b731
+0,  32256,  32256, 1792,21504, 0xbb0b9cd9
+0,  34048,  34048, 1792,21504, 0x819db403
+0,  35840,  35840, 1792,21504, 0xa95c859a
+0,  37632,  37632, 1792,21504, 0xd9cd11cc
+0,  39424,  39424, 1792,21504, 0xe7a3abbf
+0,  41216,  41216, 1792,21504, 0x975e4ddc
+0,  43008,  43008, 1792,21504, 0x329af143
+0,  44800,  44800, 1792,21504, 0x9bb6281b
+0,  46592,  46592, 1792,21504, 0x96cc0fa8
+0,  48384,  48384, 1792,21504, 0xaae03a7d
+0,  50176,  50176, 1792,21504, 0x2a5d6225
+0,  51968,  51968, 1792,21504, 0xf7cc19f5
+0,  53760,  53760, 1792,21504, 0x89e85e67
+0,  2,  2, 1792,21504, 0x607ab65e
+0,  57344,  57344, 1792,21504, 0x95c0ad8f
+0,  59136,  59136, 1792,21504, 0x6b9e8b96
+0,  60928,  60928, 1792,21504, 0x7b83696c
+0,  62720,  62720, 1792,21504, 0xac0b6fbf
+0,  64512,  64512, 1792,21504, 0xfa249f22
+0,  66304,  66304, 1792,21504, 0x51acbb93
+0,  68096,  68096, 1792,21504, 0xd77b34be
+0,  69888,  69888, 1792,21504, 0xd5494a86
+0,  71680,  71680, 1792,21504, 0xd83c3d91
+0,  73472,  73472, 1792

[FFmpeg-devel] [PATCH 1/2] avcodec/s302m: enable non-PCM decoding

2024-01-22 Thread Gyan Doshi
Set up framework for non-PCM decoding in-place and
add support for Dolby-E decoding.

Useful for direct transcoding of non-PCM audio in live inputs.
---
 configure  |   1 +
 doc/decoders.texi  |  40 +++
 libavcodec/s302m.c | 609 +
 3 files changed, 543 insertions(+), 107 deletions(-)

diff --git a/configure b/configure
index c8ae0a061d..8db3fa3f4b 100755
--- a/configure
+++ b/configure
@@ -2979,6 +2979,7 @@ rv20_decoder_select="h263_decoder"
 rv20_encoder_select="h263_encoder"
 rv30_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
 rv40_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
+s302m_decoder_select="dolby_e_decoder"
 screenpresso_decoder_deps="zlib"
 shorten_decoder_select="bswapdsp"
 sipr_decoder_select="lsp"
diff --git a/doc/decoders.texi b/doc/decoders.texi
index 293c82c2ba..9f85c876bf 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -347,6 +347,46 @@ configuration. You need to explicitly configure the build 
with
 An FFmpeg native decoder for Opus exists, so users can decode Opus
 without this library.
 
+@section s302m
+
+SMPTE ST 302 decoder.
+
+SMPTE ST 302 is a method for storing AES3 data format within an MPEG Transport
+Stream. AES3 streams can contain LPCM streams of 2, 4, 6 or 8 channels with a
+bit depth of 16, 20 or 24-bits at a sample rate of 48 kHz.
+They can also contain non-PCM codec streams such as AC-3 or Dolby-E.
+
+Decoding non-PCM streams directly requires that the necessary stream decoder be
+present in the build. At present, only Dolby-E decoding is supported.
+
+@subsection Options
+
+The following options are supported by the s302m decoder.
+
+@table @option
+@item non_pcm_mode @var{mode}
+Specify how to process non-PCM streams
+
+@table @samp
+@item copy
+Treat data as if it were LPCM.
+@item drop
+Discard the stream.
+@item decode_copy
+Decode if possible eise treat the same as @code{copy}.
+@item decode_drop
+Decode if possible eise treat the same as @code{drop}.
+@end table
+
+The default value is @code{decode_drop}. This option does not affect the 
processing of
+LPCM streams.
+
+@item non_pcm_options @var{options}
+Set options for non-PCM decoder using a list of key=value pairs separated by 
":".
+Consult the docs for the non-PCM decoder for its options.
+
+@end table
+
 @c man end AUDIO DECODERS
 
 @chapter Subtitles Decoders
diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index f1b41608f3..d6a75cfa73 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -24,21 +24,264 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
+#include "libavutil/dict.h"
 #include "libavutil/reverse.h"
 #include "avcodec.h"
 #include "codec_internal.h"
+#include "get_bits.h"
 #include "decode.h"
 
 #define AES3_HEADER_LEN 4
 
+#define NONPCMSYNC_16MARKER  0x4E1F0F8720
+#define NONPCMSYNC_20MARKER  0x4E1F60F872A0
+#define NONPCMSYNC_24MARKER  0x7E1F690F872A50
+
+#define NONPCMSYNC_16_IN_20MARKER  0x04E1F00F8720
+#define NONPCMSYNC_20_IN_24MARKER  0x04E1F600F872A0
+
+#define IS_NONPCMSYNC_16(state)   ((state & 0x00) == 
NONPCMSYNC_16MARKER)
+#define IS_NONPCMSYNC_20(state)   ((state & 0xF0F0)   == 
NONPCMSYNC_20MARKER)
+#define IS_NONPCMSYNC_24(state)   ((state & 0xFF0FF0) == 
NONPCMSYNC_24MARKER)
+
+#define IS_NONPCMSYNC_16_IN_20(state)   ((state & 0x0000)   == 
NONPCMSYNC_16_IN_20MARKER)
+#define IS_NONPCMSYNC_20_IN_24(state)   ((state & 0x0F00F0) == 
NONPCMSYNC_20_IN_24MARKER)
+
+#define IS_NONPCMSYNC(bit,state)  ( ((bit == 16) &&  IS_NONPCMSYNC_16(state)) 
|| \
+((bit == 20) && (IS_NONPCMSYNC_20(state) 
|| IS_NONPCMSYNC_16_IN_20(state))) || \
+((bit == 24) && (IS_NONPCMSYNC_24(state) 
|| IS_NONPCMSYNC_20_IN_24(state))) \
+  )
+
+enum non_pcm_modes {
+NON_PCM_COPY,
+NON_PCM_DROP,
+NON_PCM_DEC_ELSE_COPY,
+NON_PCM_DEC_ELSE_DROP,
+};
+
 typedef struct S302Context {
 AVClass *class;
+
+int avctx_props_set;
+
+int channels;
+int bits;
+
 int non_pcm_mode;
+int non_pcm_data_type;
+int non_pcm_bits;
+int non_pcm_dec;
+
+AVCodecContext *non_pcm_ctx;
+AVDictionary   *non_pcm_opts;
+AVPacket *packet;
+AVFrame  *frame;
 } S302Context;
 
+static av_cold int s302m_init(AVCodecContext *avctx)
+{
+S302Context *s = avctx->priv_data;
+
+s->non_pcm_data_type = -1;
+
+return 0;
+}
+
+static int s302m_non_pcm_inspect(AVCodecContext *avctx, const uint8_t *buf, 
int buf_size,
+  int *offset, int *length)
+{
+S302Context *s = avctx->priv_data;
+GetBitContext gb;
+int ret, aes_frm_size, data_type, length_code = 0;
+uint64_t state = 0;
+uint32_t size;
+
+if (s->channels != 2) {
+goto end;
+}
+
+ret = init_get_bits8(&gb, buf, buf_size);
+if (ret < 0)
+ 

Re: [FFmpeg-devel] [PATCH 8/9] avcodec: add D3D12VA hardware HEVC encoder

2024-01-22 Thread Wu, Tong1
>>
>> From: Tong Wu 
>>
>> This implementation is based on D3D12 Video Encoding Spec:
>> https://microsoft.github.io/DirectX-Specs/d3d/D3D12VideoEncoding.html
>>
>> Sample command line for transcoding:
>> ffmpeg.exe -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4
>> -c:v hevc_d3d12va output.mp4
>>
>> Signed-off-by: Tong Wu 
>> ---
> > configure|6 +
> > libavcodec/Makefile  |4 +-
> > libavcodec/allcodecs.c   |1 +
> > libavcodec/d3d12va_encode.c  | 1441
>++
> > libavcodec/d3d12va_encode.h  |  200 +
> > libavcodec/d3d12va_encode_hevc.c | 1016 +
> > libavcodec/hw_base_encode.h  |2 +-
> > 7 files changed, 2668 insertions(+), 2 deletions(-)
> > create mode 100644 libavcodec/d3d12va_encode.c
> > create mode 100644 libavcodec/d3d12va_encode.h
> > create mode 100644 libavcodec/d3d12va_encode_hevc.c
>
>> +D3D12_OBJECT_RELEASE(ctx->sync_ctx.fence);
>> +if (ctx->sync_ctx.event)
>> +CloseHandle(ctx->sync_ctx.event);
>> +
>> +D3D12_OBJECT_RELEASE(ctx->video_device3);
>> +D3D12_OBJECT_RELEASE(ctx->device);
>> +D3D12_OBJECT_RELEASE(ctx->encoder_heap);
>> +D3D12_OBJECT_RELEASE(ctx->encoder);
>
>We need to release all of the objects, including the encoder and
>encoder_heap, created by the device before releasing the device.
>
>> +
>> +typedef struct D3D12VAEncodeProfile {
>> +//lavc profile value (AV_PROFILE_*).
>> +int   av_profile;
>> +//Supported bit depth.
>> +int   depth;
>> +//Number of components.
>> +int   nb_components;
>> +//Chroma subsampling in width dimension.
>> +int   log2_chroma_w;
>> +//Chroma subsampling in height dimension.
>> +int   log2_chroma_h;
>> +//D3D12 profile value.
>> +D3D12_VIDEO_ENCODER_PROFILE_DESC d3d12_profile;
>> +} D3D12VAEncodeProfile;
>> +
>> +typedef struct D3D12VAEncodeRCMode {
>> +// Base.
>> +HWBaseEncodeRCMode base;
>> +// Supported by D3D12 HW.
>> +int supported;
>> +// D3D12 mode value.
>> +D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE d3d12_mode;
>> +} D3D12VAEncodeRCMode;
>> +
>> +typedef struct D3D12VAEncodeContext {
>> +HWBaseEncodeContext base;
>> +
>> +//Codec-specific hooks.
>> +const struct D3D12VAEncodeType *codec;
>> +
>> +//Chosen encoding profile details.
>> +const D3D12VAEncodeProfile *profile;
>> +
>> +//Chosen rate control mode details.
>> +const D3D12VAEncodeRCMode *rc_mode;
>> +
>> +AVD3D12VADeviceContext *hwctx;
>> +
>> +//Device3 interface.
>> +ID3D12Device3 *device3;
>> +
>> +ID3D12VideoDevice3 *video_device3;
>> +
>> +//Pool of (reusable) bitstream output buffers.
>> +AVBufferPool   *output_buffer_pool;
>> +
>> +//D3D12 video encoder.
>> +AVBufferRef *encoder_ref;
>> +
>> +ID3D12VideoEncoder *encoder;
>> +
>> +//D3D12 video encoder heap.
>> +ID3D12VideoEncoderHeap *encoder_heap;
>> +
>> +//A cached queue for reusing the D3D12 command allocators.
>> +//@see https://learn.microsoft.com/en-
>us/windows/win32/direct3d12/recording-command-lists-and-
>bundles#id3d12commandallocator
>> +AVFifo *allocator_queue;
>> +
>> +//D3D12 command queue.
>> +ID3D12CommandQueue *command_queue;
>> +
>> +//D3D12 video encode command list.
>> +ID3D12VideoEncodeCommandList2 *command_list;
>> +
>> +//The sync context used to sync command queue.
>> +AVD3D12VASyncContext sync_ctx;
>> +
>> +//bi_not_empty feature.
>> +int bi_not_empty;
>> +
>> +//D3D12 hardware structures.
>> +D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC resolution;
>> +
>> +D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION codec_conf;
>> +
>> +D3D12_VIDEO_ENCODER_RATE_CONTROL rc;
>> +
>> +D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS
>req;
>> +
>> +D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE GOP;
>> +
>> +
>D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOLUTION_SUPPORT_LIMITS
>res_limits;
>> +
>> +D3D12_VIDEO_ENCODER_LEVEL_SETTING level;
>> +} D3D12VAEncodeContext;
>> +
>Can we use the comment style the same as D3D12VADecodeContext?
>

Will update in V2 thanks for the review.

Thanks,
Tong

___
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 7/9] avutil/hwcontext_d3d12va: add Flags for resource creation

2024-01-22 Thread Wu, Tong1
>From: ffmpeg-devel  On Behalf Of Mark
>Thompson
>Sent: Tuesday, January 23, 2024 5:52 AM
>To: ffmpeg-devel@ffmpeg.org
>Subject: Re: [FFmpeg-devel] [PATCH 7/9] avutil/hwcontext_d3d12va: add Flags
>for resource creation
>
>On 22/01/2024 05:57, tong1.wu-at-intel@ffmpeg.org wrote:
>> From: Tong Wu 
>>
>> Flags field is added to support diffferent resource creation.
>>
>> Signed-off-by: Tong Wu 
>> ---
>>   doc/APIchanges| 3 +++
>>   libavutil/hwcontext_d3d12va.c | 2 +-
>>   libavutil/hwcontext_d3d12va.h | 5 +
>>   libavutil/version.h   | 2 +-
>>   4 files changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index e477ed78e0..a33e54dd3b 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-
>09
>>
>>   API changes, most recent first:
>>
>> +2024-01-xx - xx - lavu 58.37.100 - hwcontext_d3d12va.h
>> + Add AVD3D12VAFramesContext.Flags
>> +
>>   2023-11-xx - xx - lavfi 9.16.100 - buffersink.h buffersrc.h
>> Add av_buffersink_get_colorspace and av_buffersink_get_color_range.
>> Add AVBufferSrcParameters.color_space and
>AVBufferSrcParameters.color_range.
>> diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
>> index 414dd44290..0d94f48543 100644
>> --- a/libavutil/hwcontext_d3d12va.c
>> +++ b/libavutil/hwcontext_d3d12va.c
>> @@ -237,7 +237,7 @@ static AVBufferRef *d3d12va_pool_alloc(void
>*opaque, size_t size)
>>   .Format   = hwctx->format,
>>   .SampleDesc   = {.Count = 1, .Quality = 0 },
>>   .Layout   = D3D12_TEXTURE_LAYOUT_UNKNOWN,
>> -.Flags= D3D12_RESOURCE_FLAG_NONE,
>> +.Flags= hwctx->Flags,
>
>This seems like a hole in the existing decoder implementation?  How does it
>work without making
>D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY textures when
>required by the device?

For current decoder implementation it applies to most devices and it's indeed 
not supported when driver requests this REFERENCE_ONLY flag. It seems that I 
haven't met this request in my working environment. We may add it later if 
needed.

>
>>   };
>>
>>   frame = av_mallocz(sizeof(AVD3D12VAFrame));
>> diff --git a/libavutil/hwcontext_d3d12va.h b/libavutil/hwcontext_d3d12va.h
>> index ff06e6f2ef..dc1c17d3f9 100644
>> --- a/libavutil/hwcontext_d3d12va.h
>> +++ b/libavutil/hwcontext_d3d12va.h
>> @@ -129,6 +129,11 @@ typedef struct AVD3D12VAFramesContext {
>>* If unset, will be automatically set.
>>*/
>>   DXGI_FORMAT format;
>> +
>> +/**
>> + * This field is used for resource creation.
>
>This documentation could be better.  Used to do what?  Can it not be set, and
>what is the behaviour if it isn't?

Will update in V2.

>
>> + */
>> +D3D12_RESOURCE_FLAGS Flags;
>
>Use lowercase for structure elements.
>
>>   } AVD3D12VAFramesContext;
>>
>>   #endif /* AVUTIL_HWCONTEXT_D3D12VA_H */
>> diff --git a/libavutil/version.h b/libavutil/version.h
>> index 772c4e209c..3ad1a9446c 100644
>> --- a/libavutil/version.h
>> +++ b/libavutil/version.h
>> @@ -79,7 +79,7 @@
>>*/
>>
>>   #define LIBAVUTIL_VERSION_MAJOR  58
>> -#define LIBAVUTIL_VERSION_MINOR  36
>> +#define LIBAVUTIL_VERSION_MINOR  37
>>   #define LIBAVUTIL_VERSION_MICRO 101
>>
>>   #define LIBAVUTIL_VERSION_INT
>AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
>
>It's not good to be changing the user-facing API like this.  Are there any more
>properties here which really should be user-visible?  Adding them one at a
>time later would be very unfortunate and make compatibility harder.
>
>Thanks,
>
>- Mark

AFAIK, I don't think there're more properties that need to be added one by one 
in a short time. It's going to be just this one that is really needed since we 
have to give specific flags for recon frames creation during encoding.

Thanks for the opinions and I'll update those in next version.

Best Regards,
Tong


>___
>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 v5] avcodec/cbs_vp8: Use little endian in fixed() and improve the pos check

2024-01-22 Thread Dai, Jianhui J
This commit adds value range checks to cbs_vp8_read_unsigned_le,
migrates fixed() to use it, and enforces little-endian consistency for
all read methods.

The VP8 compressed header may not be byte-aligned due to boolean coding.
Use bitwise comparison to prevent the potential overread.

TETS: ffmpeg -i fate-suite/vp8-test-vectors-r1/* -vcodec copy -bsf:v
trace_headers -f null -

Signed-off-by: Jianhui Dai 
---
 libavcodec/cbs_vp8.c | 53 +++-
 1 file changed, 37 insertions(+), 16 deletions(-)

diff --git a/libavcodec/cbs_vp8.c b/libavcodec/cbs_vp8.c
index 065156c248..338d56ed7f 100644
--- a/libavcodec/cbs_vp8.c
+++ b/libavcodec/cbs_vp8.c
@@ -33,22 +33,22 @@ extern const uint8_t ff_vp8_token_update_probs[4][8][3][11];
 typedef struct CBSVP8BoolDecoder {
 GetBitContext *gbc;
 
-uint8_t value;
 uint8_t range;
 
-uint8_t count; // Store the number of bits in the `value` buffer.
-
+uint8_t value;
+// Store the number of bits in the `value` buffer.
+uint8_t count;
 } CBSVP8BoolDecoder;
 
-static int cbs_vp8_bool_decoder_init(CBSVP8BoolDecoder *decoder, GetBitContext 
*gbc)
+static int cbs_vp8_bool_decoder_init(CBSVP8BoolDecoder *decoder,
+ GetBitContext *gbc)
 {
 av_assert0(decoder);
 av_assert0(gbc);
 
 decoder->gbc = gbc;
-decoder->value = 0;
 decoder->range = 255;
-
+decoder->value = 0;
 decoder->count = 0;
 
 return 0;
@@ -60,7 +60,7 @@ static bool cbs_vp8_bool_decoder_fill_value(CBSVP8BoolDecoder 
*decoder)
 
 av_assert0(decoder->count <= 8);
 if (decoder->count == 8) {
-  return true;
+return true;
 }
 
 if (get_bits_left(decoder->gbc) >= bits) {
@@ -141,7 +141,7 @@ static int cbs_vp8_bool_decoder_read_unsigned(
 }
 
 if (trace_enable) {
-  CBS_TRACE_READ_END();
+CBS_TRACE_READ_END();
 }
 
 *write_to = value;
@@ -181,9 +181,11 @@ static int cbs_vp8_bool_decoder_read_signed(
 return 0;
 }
 
-static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx, GetBitContext 
*gbc,
- int width, const char *name,
- const int *subscripts, uint32_t *write_to)
+static int cbs_vp8_read_unsigned_le(CodedBitstreamContext *ctx,
+GetBitContext *gbc, int width,
+const char *name, const int *subscripts,
+uint32_t *write_to, uint32_t range_min,
+uint32_t range_max)
 {
 int32_t value;
 
@@ -200,6 +202,14 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext 
*ctx, GetBitContext *g
 
 CBS_TRACE_READ_END();
 
+if (value < range_min || value > range_max) {
+av_log(ctx->log_ctx, AV_LOG_ERROR,
+   "%s out of range: "
+   "%" PRIu32 ", but must be in [%" PRIu32 ",%" PRIu32 "].\n",
+   name, value, range_min, range_max);
+return AVERROR_INVALIDDATA;
+}
+
 *write_to = value;
 return 0;
 }
@@ -246,15 +256,16 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext 
*ctx, GetBitContext *g
 do { \
 uint32_t value; \
 CHECK(cbs_vp8_read_unsigned_le(ctx, rw, width, #name, \
-SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
+   SUBSCRIPTS(subs, __VA_ARGS__), &value, \
+   0, MAX_UINT_BITS(width))); \
 current->name = value; \
 } while (0)
 
 #define fixed(width, name, value) \
 do { \
 uint32_t fixed_value; \
-CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, 0, &fixed_value, \
-   value, value)); \
+CHECK(cbs_vp8_read_unsigned_le(ctx, rw, width, #name, 0, &fixed_value, 
\
+   value, value)); \
 } while (0)
 
 #define bc_unsigned_subs(width, prob, enable_trace, name, subs, ...) \
@@ -277,6 +288,15 @@ static int cbs_vp8_read_unsigned_le(CodedBitstreamContext 
*ctx, GetBitContext *g
 
 #include "cbs_vp8_syntax_template.c"
 
+#undef READ
+#undef READWRITE
+#undef RWContext
+#undef CBSVP8BoolCodingRW
+#undef xf
+#undef fixed
+#undef bc_unsigned_subs
+#undef bc_signed_subs
+
 static int cbs_vp8_split_fragment(CodedBitstreamContext *ctx,
   CodedBitstreamFragment *frag, int header)
 {
@@ -327,9 +347,10 @@ static int cbs_vp8_read_unit(CodedBitstreamContext *ctx,
 if (err < 0)
 return err;
 
+// Position may not be byte-aligned after compressed header; use bit-level
+// comparison.
 pos = get_bits_count(&gbc);
-pos /= 8;
-av_assert0(pos <= unit->data_size);
+av_assert0(pos <= unit->data_size * 8);
 
 frame->data_ref = av_buffer_ref(unit->data_ref);
 if (!frame->data_ref)
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-de

Re: [FFmpeg-devel] [PATCH] hwcontext_opencl: choose the first device if multiple devices are available

2024-01-22 Thread Xiang, Haihao
On Ma, 2024-01-22 at 20:32 +, Mark Thompson wrote:
> On 17/01/2024 07:36, Xiang, Haihao wrote:
> > From: Haihao Xiang 
> > 
> > This makes '-init_hw_device opencl' work in a multiple-device system.
> 
> Under what circumstances is this more useful than the existing behaviour which
> prompts the user to select the device they intend?

@item -init_hw_device
@var{type}[=@var{name}][:@var{device}[,@var{key=value}...]]

My understanding is that only @var{type} is mandatory, @var{device} (and others)
is optional, indeed '-init_hw_device opencl' works well in a single-device
system, however the same command doesn't work in a multiple-device system. It is
not a good experience for me. 

> 
> There is no particular ordering to devices, the first one is just random. 
> Having your process fail with an opaque message (because the device picked
> lacks some operation) or run many times slower than expected (because the
> smallest device happened to be first in the list) or do something different on
> a machine which looks the same (because it has an extra driver for something
> else) rather than just saying up front that there are multiple devices and the
> user needs to pick seems worse to me, since it is much harder to see where the
> problem is.

I understand your concern, how about making the default works while prompting a
warning about the device selection ? 

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH v2 0/1] avfilter/vf_vpp_qsv: apply 3D LUT from file

2024-01-22 Thread Xiang, Haihao
On Sa, 2024-01-20 at 23:14 +0800, Chen Yufei wrote:
> This patch adds support for applying 3D LUT from file using oneVPL VPP.
> 
> PATCH v1 uses VA-API to create LUT surface. Because oneVPL can't work with VA-
> API on Windows,
> this version now creates LUT in system memory (MFX_RESOURCE_SYSTEM_SURFACE)
> and let oneVPL
> copy LUT to video memory.
> 
> Note: requires oneVPL-intel-gpu version >= 24.1.1 because this version
> contains
> a fix for creating LUT in video memory.
> (For details, refer to
> https://github.com/oneapi-src/oneVPL-intel-gpu/issues/307)

Please bump a new runtime version, then you may check the runtime version for
this feature. 

Thanks
Haihao


> 
> Chen Yufei (1):
>   avfilter/vf_vpp_qsv: apply 3D LUT from file.
> 
>  libavfilter/Makefile |   8 +-
>  libavfilter/lut3d.c  | 669 +++
>  libavfilter/lut3d.h  |  13 +
>  libavfilter/vf_lut3d.c   | 590 +-
>  libavfilter/vf_vpp_qsv.c | 113 ++-
>  5 files changed, 799 insertions(+), 594 deletions(-)
>  create mode 100644 libavfilter/lut3d.c
> 

___
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] avutil/opt: use AVBPrint to print a channel layout in av_opt_get()

2024-01-22 Thread James Almer
A 128 byte buffer may not be enough for some layouts with lots of channels.

Signed-off-by: James Almer 
---
 libavutil/opt.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 0908751752..814b485a15 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -936,9 +936,15 @@ FF_DISABLE_DEPRECATION_WARNINGS
 break;
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
-case AV_OPT_TYPE_CHLAYOUT:
-ret = av_channel_layout_describe(dst, buf, sizeof(buf));
-break;
+case AV_OPT_TYPE_CHLAYOUT: {
+AVBPrint bp;
+av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
+av_channel_layout_describe_bprint(dst, &bp);
+if (!av_bprint_is_complete(&bp))
+return AVERROR(ENOMEM);
+av_bprint_finalize(&bp, (char **)out_val);
+return *out_val ? 0 : AVERROR(ENOMEM);
+}
 case AV_OPT_TYPE_DICT:
 if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
 *out_val = NULL;
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH] avformat/mxfenc: Remove AVERROR²

2024-01-22 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/mxfenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 685c11b3a50..c67e8ff9609 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2656,13 +2656,13 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, 
AVStream *st, AVPacket *
 
 if (bytestream2_get_be16u(&g) != JPEG2000_SOC) {
 av_log(s, AV_LOG_ERROR, "Mandatory SOC marker is not present\n");
-return AVERROR(AVERROR_INVALIDDATA);
+return AVERROR_INVALIDDATA;
 }
 
 /* Extract usefull size information from the SIZ marker */
 if (bytestream2_get_be16u(&g) != JPEG2000_SIZ) {
 av_log(s, AV_LOG_ERROR, "Mandatory SIZ marker is not present\n");
-return AVERROR(AVERROR_INVALIDDATA);
+return AVERROR_INVALIDDATA;
 }
 bytestream2_skip(&g, 2); // Skip Lsiz
 sc->j2k_info.j2k_cap = bytestream2_get_be16u(&g);
@@ -2677,7 +2677,7 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, 
AVStream *st, AVPacket *
 j2k_ncomponents = bytestream2_get_be16u(&g);
 if (j2k_ncomponents != component_count) {
 av_log(s, AV_LOG_ERROR, "Incoherence about components image 
number.\n");
-return AVERROR(AVERROR_INVALIDDATA);
+return AVERROR_INVALIDDATA;
 }
 bytestream2_get_bufferu(&g, sc->j2k_info.j2k_comp_desc, 3 * 
j2k_ncomponents);
 
-- 
2.17.1

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

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


Re: [FFmpeg-devel] [PATCH] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Tomas Härdin
tis 2024-01-23 klockan 00:40 +0300 skrev Victor Luchitz:
> On Tue, Jan 23, 2024 at 12:12 AM Tomas Härdin  wrote:
> 
> > mån 2024-01-22 klockan 22:14 +0300 skrev Victor Luchits:
> > > The bitrate option (-b:v) can now be used to specify the bit rate
> > > of the video stream of the RoQ encoder.
> > > 
> > > Original patch by Joseph Fenton aka Chilly Willy
> > > 
> > > Signed-off-by: Victor Luchits 
> > 
> > Still doesn't apply.
> > 
> 
> I have no clue as to what's going on there.. The patch applies
> perfectly
> fine
> without all the eml stuff.
> 
> root@banana:~/ffmpeg# git reset --hard origin/master
> HEAD is now at d2eb6f4d44 fftools/ffmpeg_mux_init: don't free the
> AVDictionaryEntry until after it's been used
> root@ banana:~/ffmpeg# git apply
> 0001-liavcodec-add-bit-rate-support-to-RoQ-video-encoder.patch
> root@ banana:~/ffmpeg# echo $?
> 0
> 
> Any help would be highly appreciated.
> 
> 
> > > +    /* Keyframe when no MOT or FCC codes in frame */
> > > +    if (s->key_frame) {
> > > +    av_log(avctx, AV_LOG_VERBOSE, "\nFound keyframe!\n");
> > > +    rframe->pict_type = AV_PICTURE_TYPE_I;
> > > +    avpkt->flags |= AV_PKT_FLAG_KEY;
> > > +    } else {
> > > +    rframe->pict_type = AV_PICTURE_TYPE_P;
> > > +    avpkt->flags &= ~AV_PKT_FLAG_KEY;
> > > +    }
> > 
> > Looks like framesSinceKeyframe still doesn't get reset
> > 
> 
> framesSinceKeyframe wasn't introduced in this patch and I'm a bit
> scared
> to mess with it as part of this changeset as that would introduce
> some new
> changes to the core of the original implementation.

It doesn't have to hold this patch up I guess. Doesn't look terribly
complicated either way

> > > +    if (avctx->bit_rate) {
> > > +    /* no specific bit rate desired, use frame quality */
> > > +    if (frame->quality)
> > > +    enc->lambda = frame->quality - 1;
> > > +    else
> > > +    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > +    }
> > 
> > Looks like you got this backwards
> > 
> 
> You're totally right, thanks!
> 
> I'll resubmit the patch once we figure out what's the deal with git
> failing
> to apply the patch for you.

Try attaching the patch rather than pasting it

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

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


Re: [FFmpeg-devel] [PATCH v3 7/8] avcodec/x86/vvc: add avg and avg_w AVX2 optimizations

2024-01-22 Thread Michael Niedermayer
On Tue, Jan 23, 2024 at 01:46:27AM +0800, toq...@outlook.com wrote:
> From: Wu Jianhua 
> 
> The avg/avg_w is based on dav1d.
> See https://code.videolan.org/videolan/dav1d/-/blob/master/src/x86/mc_avx2.asm
> 
> vvc_avg_8_2x2_c: 71.6
> vvc_avg_8_2x2_avx2: 26.8
> vvc_avg_8_2x4_c: 140.8
> vvc_avg_8_2x4_avx2: 34.6
> vvc_avg_8_2x8_c: 410.3
> vvc_avg_8_2x8_avx2: 41.3
> vvc_avg_8_2x16_c: 769.3
> vvc_avg_8_2x16_avx2: 60.3
> vvc_avg_8_2x32_c: 1669.6
> vvc_avg_8_2x32_avx2: 105.1
> vvc_avg_8_2x64_c: 1978.3
> vvc_avg_8_2x64_avx2: 425.8
> vvc_avg_8_2x128_c: 6536.8
> vvc_avg_8_2x128_avx2: 1315.1
> vvc_avg_8_4x2_c: 155.6
> vvc_avg_8_4x2_avx2: 26.1
> vvc_avg_8_4x4_c: 250.3
> vvc_avg_8_4x4_avx2: 31.3
> vvc_avg_8_4x8_c: 831.8
> vvc_avg_8_4x8_avx2: 41.3
> vvc_avg_8_4x16_c: 1461.1
> vvc_avg_8_4x16_avx2: 57.1
> vvc_avg_8_4x32_c: 2821.6
> vvc_avg_8_4x32_avx2: 105.1
> vvc_avg_8_4x64_c: 3615.8
> vvc_avg_8_4x64_avx2: 412.6
> vvc_avg_8_4x128_c: 11962.6
> vvc_avg_8_4x128_avx2: 1274.3
> vvc_avg_8_8x2_c: 215.8
> vvc_avg_8_8x2_avx2: 29.1
> vvc_avg_8_8x4_c: 430.6
> vvc_avg_8_8x4_avx2: 37.6
> vvc_avg_8_8x8_c: 1463.3
> vvc_avg_8_8x8_avx2: 51.8
> vvc_avg_8_8x16_c: 2630.1
> vvc_avg_8_8x16_avx2: 97.6
> vvc_avg_8_8x32_c: 5813.8
> vvc_avg_8_8x32_avx2: 196.6
> vvc_avg_8_8x64_c: 6687.3
> vvc_avg_8_8x64_avx2: 487.8
> vvc_avg_8_8x128_c: 13178.6
> vvc_avg_8_8x128_avx2: 1290.6
> vvc_avg_8_16x2_c: 443.8
> vvc_avg_8_16x2_avx2: 28.3
> vvc_avg_8_16x4_c: 1253.3
> vvc_avg_8_16x4_avx2: 32.1
> vvc_avg_8_16x8_c: 2236.3
> vvc_avg_8_16x8_avx2: 44.3
> vvc_avg_8_16x16_c: 5127.8
> vvc_avg_8_16x16_avx2: 63.3
> vvc_avg_8_16x32_c: 6573.3
> vvc_avg_8_16x32_avx2: 223.6
> vvc_avg_8_16x64_c: 30311.8
> vvc_avg_8_16x64_avx2: 437.8
> vvc_avg_8_16x128_c: 25693.3
> vvc_avg_8_16x128_avx2: 1266.8
> vvc_avg_8_32x2_c: 954.6
> vvc_avg_8_32x2_avx2: 32.1
> vvc_avg_8_32x4_c: 2359.6
> vvc_avg_8_32x4_avx2: 39.6
> vvc_avg_8_32x8_c: 5703.6
> vvc_avg_8_32x8_avx2: 57.1
> vvc_avg_8_32x16_c: 9967.6
> vvc_avg_8_32x16_avx2: 107.1
> vvc_avg_8_32x32_c: 21327.6
> vvc_avg_8_32x32_avx2: 272.6
> vvc_avg_8_32x64_c: 39240.8
> vvc_avg_8_32x64_avx2: 529.6
> vvc_avg_8_32x128_c: 52580.8
> vvc_avg_8_32x128_avx2: 1338.8
> vvc_avg_8_64x2_c: 1647.3
> vvc_avg_8_64x2_avx2: 38.8
> vvc_avg_8_64x4_c: 5130.1
> vvc_avg_8_64x4_avx2: 58.8
> vvc_avg_8_64x8_c: 6529.3
> vvc_avg_8_64x8_avx2: 88.3
> vvc_avg_8_64x16_c: 19913.6
> vvc_avg_8_64x16_avx2: 162.3
> vvc_avg_8_64x32_c: 39360.8
> vvc_avg_8_64x32_avx2: 295.8
> vvc_avg_8_64x64_c: 49658.3
> vvc_avg_8_64x64_avx2: 784.1
> vvc_avg_8_64x128_c: 108513.1
> vvc_avg_8_64x128_avx2: 1977.1
> vvc_avg_8_128x2_c: 3226.1
> vvc_avg_8_128x2_avx2: 61.1
> vvc_avg_8_128x4_c: 10280.3
> vvc_avg_8_128x4_avx2: 94.6
> vvc_avg_8_128x8_c: 18079.3
> vvc_avg_8_128x8_avx2: 155.3
> vvc_avg_8_128x16_c: 45121.8
> vvc_avg_8_128x16_avx2: 285.3
> vvc_avg_8_128x32_c: 48651.8
> vvc_avg_8_128x32_avx2: 581.6
> vvc_avg_8_128x64_c: 165078.6
> vvc_avg_8_128x64_avx2: 1942.8
> vvc_avg_8_128x128_c: 339103.1
> vvc_avg_8_128x128_avx2: 4332.6
> vvc_avg_10_2x2_c: 144.3
> vvc_avg_10_2x2_avx2: 26.8
> vvc_avg_10_2x4_c: 142.6
> vvc_avg_10_2x4_avx2: 45.3
> vvc_avg_10_2x8_c: 478.1
> vvc_avg_10_2x8_avx2: 38.1
> vvc_avg_10_2x16_c: 518.3
> vvc_avg_10_2x16_avx2: 58.1
> vvc_avg_10_2x32_c: 2059.8
> vvc_avg_10_2x32_avx2: 93.1
> vvc_avg_10_2x64_c: 2383.8
> vvc_avg_10_2x64_avx2: 714.8
> vvc_avg_10_2x128_c: 4498.3
> vvc_avg_10_2x128_avx2: 1466.3
> vvc_avg_10_4x2_c: 228.6
> vvc_avg_10_4x2_avx2: 26.8
> vvc_avg_10_4x4_c: 378.3
> vvc_avg_10_4x4_avx2: 30.6
> vvc_avg_10_4x8_c: 866.8
> vvc_avg_10_4x8_avx2: 44.6
> vvc_avg_10_4x16_c: 1018.1
> vvc_avg_10_4x16_avx2: 58.1
> vvc_avg_10_4x32_c: 3590.8
> vvc_avg_10_4x32_avx2: 128.8
> vvc_avg_10_4x64_c: 4200.8
> vvc_avg_10_4x64_avx2: 663.6
> vvc_avg_10_4x128_c: 8450.8
> vvc_avg_10_4x128_avx2: 1531.8
> vvc_avg_10_8x2_c: 369.3
> vvc_avg_10_8x2_avx2: 28.3
> vvc_avg_10_8x4_c: 513.8
> vvc_avg_10_8x4_avx2: 32.1
> vvc_avg_10_8x8_c: 1720.3
> vvc_avg_10_8x8_avx2: 49.1
> vvc_avg_10_8x16_c: 1894.8
> vvc_avg_10_8x16_avx2: 71.6
> vvc_avg_10_8x32_c: 3931.3
> vvc_avg_10_8x32_avx2: 148.1
> vvc_avg_10_8x64_c: 7964.3
> vvc_avg_10_8x64_avx2: 613.1
> vvc_avg_10_8x128_c: 15540.1
> vvc_avg_10_8x128_avx2: 1585.1
> vvc_avg_10_16x2_c: 877.3
> vvc_avg_10_16x2_avx2: 27.6
> vvc_avg_10_16x4_c: 955.8
> vvc_avg_10_16x4_avx2: 29.8
> vvc_avg_10_16x8_c: 3419.6
> vvc_avg_10_16x8_avx2: 62.6
> vvc_avg_10_16x16_c: 3826.8
> vvc_avg_10_16x16_avx2: 54.3
> vvc_avg_10_16x32_c: 7655.3
> vvc_avg_10_16x32_avx2: 86.3
> vvc_avg_10_16x64_c: 30011.1
> vvc_avg_10_16x64_avx2: 692.6
> vvc_avg_10_16x128_c: 47894.8
> vvc_avg_10_16x128_avx2: 1580.3
> vvc_avg_10_32x2_c: 944.3
> vvc_avg_10_32x2_avx2: 29.8
> vvc_avg_10_32x4_c: 2022.6
> vvc_avg_10_32x4_avx2: 35.1
> vvc_avg_10_32x8_c: 6148.8
> vvc_avg_10_32x8_avx2: 51.3
> vvc_avg_10_32x16_c: 12601.6
> vvc_avg_10_32x16_avx2: 70.8
> vvc_avg_10_32x32_c: 15958.6
> vvc_avg_10_32x32_avx2: 124.3
> vvc_avg_10_32x64_c: 31784.6
> vvc_avg_10_32x64_avx2: 757.3
> vvc_avg_10_32x128_c: 63892.8
> vvc_avg_10_32x128_avx2: 17

Re: [FFmpeg-devel] [PATCH] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread epirat07
Typo in commit message: liavcodec should be libavcodec

On 22 Jan 2024, at 20:14, Victor Luchits wrote:

> The bitrate option (-b:v) can now be used to specify the bit rate
> of the video stream of the RoQ encoder.
>
> Original patch by Joseph Fenton aka Chilly Willy
>
> Signed-off-by: Victor Luchits 
> ---
>  Changelog|   1 +
>  libavcodec/roqvideo.h|   1 +
>  libavcodec/roqvideodec.c |  16 ++
>  libavcodec/roqvideoenc.c | 107 +++
>  libavcodec/version.h |   2 +-
>  5 files changed, 117 insertions(+), 10 deletions(-)
>
> diff --git a/Changelog b/Changelog
> index c40b6d08fd..6974312f9d 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -22,6 +22,7 @@ version :
>  - ffmpeg CLI -bsf option may now be used for input as well as output
>  - ffmpeg CLI options may now be used as -/opt , which is equivalent
>to -opt >
> +- RoQ video bit rate option support
>   version 6.1:
>  - libaribcaption decoder
> diff --git a/libavcodec/roqvideo.h b/libavcodec/roqvideo.h
> index 2c2e42884d..6d30bcaada 100644
> --- a/libavcodec/roqvideo.h
> +++ b/libavcodec/roqvideo.h
> @@ -43,6 +43,7 @@ typedef struct RoqContext {
>  AVFrame *last_frame;
>  AVFrame *current_frame;
>  int width, height;
> +int key_frame;
>   roq_cell cb2x2[256];
>  roq_qcell cb4x4[256];
> diff --git a/libavcodec/roqvideodec.c b/libavcodec/roqvideodec.c
> index bfc69a65c9..b4ade3a43b 100644
> --- a/libavcodec/roqvideodec.c
> +++ b/libavcodec/roqvideodec.c
> @@ -70,6 +70,7 @@ static void roqvideo_decode_frame(RoqContext *ri, 
> GetByteContext *gb)
>   chunk_start = bytestream2_tell(gb);
>  xpos = ypos = 0;
> +ri->key_frame = 1;
>   if (chunk_size > bytestream2_get_bytes_left(gb)) {
>  av_log(ri->logctx, AV_LOG_ERROR, "Chunk does not fit in input 
> buffer\n");
> @@ -92,12 +93,14 @@ static void roqvideo_decode_frame(RoqContext *ri, 
> GetByteContext *gb)
>   switch(vqid) {
>  case RoQ_ID_MOT:
> +ri->key_frame = 0;
>  break;
>  case RoQ_ID_FCC: {
>  int byte = bytestream2_get_byte(gb);
>  mx = 8 - (byte >> 4) - ((signed char) (chunk_arg >> 8));
>  my = 8 - (byte & 0xf) - ((signed char) chunk_arg);
>  ff_apply_motion_8x8(ri, xp, yp, mx, my);
> +ri->key_frame = 0;
>  break;
>  }
>  case RoQ_ID_SLD:
> @@ -125,12 +128,14 @@ static void roqvideo_decode_frame(RoqContext *ri, 
> GetByteContext *gb)
>  vqflg_pos--;
>  switch(vqid) {
>  case RoQ_ID_MOT:
> +ri->key_frame = 0;
>  break;
>  case RoQ_ID_FCC: {
>  int byte = bytestream2_get_byte(gb);
>  mx = 8 - (byte >> 4) - ((signed char) (chunk_arg 
> >> 8));
>  my = 8 - (byte & 0xf) - ((signed char) 
> chunk_arg);
>  ff_apply_motion_4x4(ri, x, y, mx, my);
> +ri->key_frame = 0;
>  break;
>  }
>  case RoQ_ID_SLD:
> @@ -214,6 +219,17 @@ static int roq_decode_frame(AVCodecContext *avctx, 
> AVFrame *rframe,
>   if ((ret = av_frame_ref(rframe, s->current_frame)) < 0)
>  return ret;
> +
> +/* Keyframe when no MOT or FCC codes in frame */
> +if (s->key_frame) {
> +av_log(avctx, AV_LOG_VERBOSE, "\nFound keyframe!\n");
> +rframe->pict_type = AV_PICTURE_TYPE_I;
> +avpkt->flags |= AV_PKT_FLAG_KEY;
> +} else {
> +rframe->pict_type = AV_PICTURE_TYPE_P;
> +avpkt->flags &= ~AV_PKT_FLAG_KEY;
> +}
> +
>  *got_frame  = 1;
>   /* shuffle frames */
> diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
> index 0933abf4f9..68ec9ec238 100644
> --- a/libavcodec/roqvideoenc.c
> +++ b/libavcodec/roqvideoenc.c
> @@ -136,6 +136,8 @@ typedef struct RoqEncContext {
>  struct ELBGContext *elbg;
>  AVLFG randctx;
>  uint64_t lambda;
> +uint64_t last_lambda;
> +int lambda_delta;
>   motion_vect *this_motion4;
>  motion_vect *last_motion4;
> @@ -887,8 +889,9 @@ static int generate_new_codebooks(RoqEncContext *enc)
>  return 0;
>  }
>  -static int roq_encode_video(RoqEncContext *enc)
> +static int roq_encode_video(AVCodecContext *avctx)
>  {
> +RoqEncContext *const enc = avctx->priv_data;
>  RoqTempData *const tempData = &enc->tmp_data;
>  RoqContext *const roq = &enc->common;
>  int ret;
> @@ -910,14 +913,14 @@ static int roq_encode_video(RoqEncContext *enc)
>   /* Quake 3 can't handle chunks bigger than 65535 bytes */
>  if (tempData->mainChunkSize/8 > 65535 && enc->quake3_compat) {
> -if (en

[FFmpeg-devel] [PATCH 2/3 v2] avformat/mov: add support for tile HEIF still images

2024-01-22 Thread James Almer
Export each tile as its own stream, and the tiling information as a Stream
Group of type TILE_GRID.
This also enables exporting other stream items like thumbnails, which may be
present in non tiled HEIF images too. For those, the primary stream will be
tagged with the default disposition.

Based on a patch by Swaraj Hota

Signed-off-by: James Almer 
---
Fixed a bug setting tile dimensions in the stream group.
Also, the grid info can now be read from mdat and not just idat.
 
 libavcodec/packet.h|   9 ++
 libavformat/avformat.h |   6 +
 libavformat/isom.h |   8 +-
 libavformat/mov.c  | 318 -
 4 files changed, 304 insertions(+), 37 deletions(-)

diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 2c57d262c6..48ca799334 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -323,6 +323,15 @@ enum AVPacketSideDataType {
  */
 AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM,
 
+/**
+ * Tile info for image reconstruction, e.g HEIF.
+ * @code
+ * u32le tile number in row major order [0..nb_tiles-1]
+ * u32le nb_tiles
+ * @endcode
+ */
+AV_PKT_DATA_TILE_INFO,
+
 /**
  * The number of side data types.
  * This is not part of the public API/ABI in the sense that it may
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index ab9a3fc6be..cf4e72e11d 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -811,6 +811,12 @@ typedef struct AVIndexEntry {
  * The video stream contains still images.
  */
 #define AV_DISPOSITION_STILL_IMAGE  (1 << 20)
+/**
+ * The video stream is intended to be merged with another stream before
+ * presentation.
+ * Used for example to signal the stream contains a tile from a HEIF grid.
+ */
+#define AV_DISPOSITION_TILE (1 << 21)
 
 /**
  * @return The AV_DISPOSITION_* flag corresponding to disp or a negative error
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 2cf456fee1..cd5478b61c 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -267,10 +267,10 @@ typedef struct HEIFItem {
 int item_id;
 int64_t extent_length;
 int64_t extent_offset;
-int64_t size;
 int width;
 int height;
 int type;
+int is_idat_relative;
 } HEIFItem;
 
 typedef struct MOVContext {
@@ -335,6 +335,12 @@ typedef struct MOVContext {
 int cur_item_id;
 HEIFItem *heif_info;
 int heif_info_size;
+int grid_item_id;
+int thmb_item_id;
+int16_t *tile_id_list;
+int nb_tiles;
+uint8_t *idat_buf;
+int64_t idat_size;
 int interleaved_read;
 } MOVContext;
 
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 5cb907e120..3b7d3e4285 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -184,6 +184,30 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext 
*pb, int len,
 return p - dst;
 }
 
+static AVStream *get_curr_st(MOVContext *c)
+{
+AVStream *st = NULL;
+
+if (c->fc->nb_streams < 1)
+return NULL;
+
+for (int i = 0; i < c->heif_info_size; i++) {
+HEIFItem *item = &c->heif_info[i];
+
+if (!item->st)
+continue;
+if (item->st->id != c->cur_item_id)
+continue;
+
+st = item->st;
+break;
+}
+if (!st)
+st = c->fc->streams[c->fc->nb_streams-1];
+
+return st;
+}
+
 static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len)
 {
 AVStream *st;
@@ -1766,9 +1790,9 @@ static int mov_read_colr(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 uint16_t color_primaries, color_trc, color_matrix;
 int ret;
 
-if (c->fc->nb_streams < 1)
+st = get_curr_st(c);
+if (!st)
 return 0;
-st = c->fc->streams[c->fc->nb_streams - 1];
 
 ret = ffio_read_size(pb, color_parameter_type, 4);
 if (ret < 0)
@@ -2116,9 +2140,9 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 AVStream *st;
 int ret;
 
-if (c->fc->nb_streams < 1)
+st = get_curr_st(c);
+if (!st)
 return 0;
-st = c->fc->streams[c->fc->nb_streams-1];
 
 if ((uint64_t)atom.size > (1<<30))
 return AVERROR_INVALIDDATA;
@@ -4928,12 +4952,10 @@ static int heif_add_stream(MOVContext *c, HEIFItem 
*item)
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 st->codecpar->codec_id = mov_codec_id(st, item->type);
 sc->ffindex = st->index;
-c->trak_index = st->index;
 st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
 st->time_base.num = st->time_base.den = 1;
 st->nb_frames = 1;
 sc->time_scale = 1;
-sc = st->priv_data;
 sc->pb = c->fc->pb;
 sc->pb_is_copied = 1;
 
@@ -7761,15 +7783,75 @@ static int mov_read_pitm(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return atom.size;
 }
 
+static int mov_read_idat(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+av_log(c->fc, AV_LOG_TRACE, "idat: size %"PRId64"\n", atom.size);
+
+c->idat_buf = av_malloc(atom.size);
+if 

Re: [FFmpeg-devel] [PATCH 7/9] avutil/hwcontext_d3d12va: add Flags for resource creation

2024-01-22 Thread Mark Thompson

On 22/01/2024 05:57, tong1.wu-at-intel@ffmpeg.org wrote:

From: Tong Wu 

Flags field is added to support diffferent resource creation.

Signed-off-by: Tong Wu 
---
  doc/APIchanges| 3 +++
  libavutil/hwcontext_d3d12va.c | 2 +-
  libavutil/hwcontext_d3d12va.h | 5 +
  libavutil/version.h   | 2 +-
  4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index e477ed78e0..a33e54dd3b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
  
  API changes, most recent first:
  
+2024-01-xx - xx - lavu 58.37.100 - hwcontext_d3d12va.h

+ Add AVD3D12VAFramesContext.Flags
+
  2023-11-xx - xx - lavfi 9.16.100 - buffersink.h buffersrc.h
Add av_buffersink_get_colorspace and av_buffersink_get_color_range.
Add AVBufferSrcParameters.color_space and AVBufferSrcParameters.color_range.
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 414dd44290..0d94f48543 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -237,7 +237,7 @@ static AVBufferRef *d3d12va_pool_alloc(void *opaque, size_t 
size)
  .Format   = hwctx->format,
  .SampleDesc   = {.Count = 1, .Quality = 0 },
  .Layout   = D3D12_TEXTURE_LAYOUT_UNKNOWN,
-.Flags= D3D12_RESOURCE_FLAG_NONE,
+.Flags= hwctx->Flags,


This seems like a hole in the existing decoder implementation?  How does it 
work without making D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY textures 
when required by the device?


  };
  
  frame = av_mallocz(sizeof(AVD3D12VAFrame));

diff --git a/libavutil/hwcontext_d3d12va.h b/libavutil/hwcontext_d3d12va.h
index ff06e6f2ef..dc1c17d3f9 100644
--- a/libavutil/hwcontext_d3d12va.h
+++ b/libavutil/hwcontext_d3d12va.h
@@ -129,6 +129,11 @@ typedef struct AVD3D12VAFramesContext {
   * If unset, will be automatically set.
   */
  DXGI_FORMAT format;
+
+/**
+ * This field is used for resource creation.


This documentation could be better.  Used to do what?  Can it not be set, and 
what is the behaviour if it isn't?


+ */
+D3D12_RESOURCE_FLAGS Flags;


Use lowercase for structure elements.


  } AVD3D12VAFramesContext;
  
  #endif /* AVUTIL_HWCONTEXT_D3D12VA_H */

diff --git a/libavutil/version.h b/libavutil/version.h
index 772c4e209c..3ad1a9446c 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
   */
  
  #define LIBAVUTIL_VERSION_MAJOR  58

-#define LIBAVUTIL_VERSION_MINOR  36
+#define LIBAVUTIL_VERSION_MINOR  37
  #define LIBAVUTIL_VERSION_MICRO 101
  
  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \


It's not good to be changing the user-facing API like this.  Are there any more 
properties here which really should be user-visible?  Adding them one at a time 
later would be very unfortunate and make compatibility harder.

Thanks,

- Mark
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Victor Luchitz
On Tue, Jan 23, 2024 at 12:12 AM Tomas Härdin  wrote:

> mån 2024-01-22 klockan 22:14 +0300 skrev Victor Luchits:
> > The bitrate option (-b:v) can now be used to specify the bit rate
> > of the video stream of the RoQ encoder.
> >
> > Original patch by Joseph Fenton aka Chilly Willy
> >
> > Signed-off-by: Victor Luchits 
>
> Still doesn't apply.
>

I have no clue as to what's going on there.. The patch applies perfectly
fine
without all the eml stuff.

root@banana:~/ffmpeg# git reset --hard origin/master
HEAD is now at d2eb6f4d44 fftools/ffmpeg_mux_init: don't free the
AVDictionaryEntry until after it's been used
root@ banana:~/ffmpeg# git apply
0001-liavcodec-add-bit-rate-support-to-RoQ-video-encoder.patch
root@ banana:~/ffmpeg# echo $?
0

Any help would be highly appreciated.


> > +/* Keyframe when no MOT or FCC codes in frame */
> > +if (s->key_frame) {
> > +av_log(avctx, AV_LOG_VERBOSE, "\nFound keyframe!\n");
> > +rframe->pict_type = AV_PICTURE_TYPE_I;
> > +avpkt->flags |= AV_PKT_FLAG_KEY;
> > +} else {
> > +rframe->pict_type = AV_PICTURE_TYPE_P;
> > +avpkt->flags &= ~AV_PKT_FLAG_KEY;
> > +}
>
> Looks like framesSinceKeyframe still doesn't get reset
>

framesSinceKeyframe wasn't introduced in this patch and I'm a bit scared
to mess with it as part of this changeset as that would introduce some new
changes to the core of the original implementation.


> > +if (avctx->bit_rate) {
> > +/* no specific bit rate desired, use frame quality */
> > +if (frame->quality)
> > +enc->lambda = frame->quality - 1;
> > +else
> > +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > +}
>
> Looks like you got this backwards
>

You're totally right, thanks!

I'll resubmit the patch once we figure out what's the deal with git failing
to apply the patch for you.


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


-- 
Best regards,
 Victor Luchitz
___
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] [vaapi-cavs 7/7] cavs: support vaapi hwaccel decoding

2024-01-22 Thread Mark Thompson

On 21/01/2024 14:18, jianfeng.zheng wrote:

see https://github.com/intel/libva/pull/738

Signed-off-by: jianfeng.zheng 
---
  configure |  14 
  libavcodec/Makefile   |   1 +
  libavcodec/cavs.h |   4 +
  libavcodec/cavsdec.c  | 101 +--
  libavcodec/hwaccels.h |   1 +
  libavcodec/vaapi_cavs.c   | 164 ++
  libavcodec/vaapi_decode.c |   4 +
  7 files changed, 284 insertions(+), 5 deletions(-)
  create mode 100644 libavcodec/vaapi_cavs.c


I suggest splitting this patch into two: add hwaccel hooks to AVS decoder, then 
add VAAPI implementation for it.


diff --git a/configure b/configure
index c8ae0a061d..89759eda5d 100755
--- a/configure
+++ b/configure
...
@@ -7175,6 +7177,18 @@ if enabled vaapi; then
  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"
+
+#
+# Using 'VA_CHECK_VERSION' in source codes make things easy. But we have 
to wait
+# until newly added VAProfile being distributed by VAAPI released version.
+#
+# Before or after that, we can use auto-detection to keep version 
compatibility.
+# It always works.
+#
+disable va_profile_avs &&
+test_code cc va/va.h "VAProfile p1 = VAProfileAVSJizhun, p2 = 
VAProfileAVSGuangdian;" &&
+enable va_profile_avs
+enabled va_profile_avs && check_type "va/va.h va/va_dec_avs.h" 
"VAPictureParameterBufferAVS"
  fi


Why can't this be done with check_type for the decode structure like the other 
VAAPI codecs?

(I don't think this should be applied to ffmpeg mainline until finalised in 
libva to avoid any incompatibility, but that doesn't require a released version 
of libva.)


...
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index 5036ef50f7..5ca021c098 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -25,11 +25,14 @@
   * @author Stefan Gehrer 
   */
  
+#include "config_components.h"

  #include "libavutil/avassert.h"
  #include "libavutil/emms.h"
  #include "avcodec.h"
  #include "get_bits.h"
  #include "golomb.h"
+#include "hwaccel_internal.h"
+#include "hwconfig.h"
  #include "profiles.h"
  #include "cavs.h"
  #include "codec_internal.h"
@@ -1002,9 +1005,9 @@ static inline int decode_slice_header(AVSContext *h, 
GetBitContext *gb)
  }
  h->mb_weight_pred_flag = get_bits1(gb);
  if (!h->avctx->hwaccel) {
-av_log(h->avctx, AV_LOG_ERROR,
-   "weighted prediction not yet supported\n");
-}
+av_log(h->avctx, AV_LOG_ERROR,
+"weighted prediction not yet supported\n");
+}


Unrelated whitespace change?


  }
  }
  if (h->aec_flag) {
@@ -1115,6 +1118,46 @@ static inline int check_for_slice(AVSContext *h)
   * frame level
   *
   /
+static int hwaccel_pic(AVSContext *h)
+{
+int ret = 0;
+int stc = -1;
+const uint8_t *frm_start = align_get_bits(&h->gb);
+const uint8_t *frm_end = h->gb.buffer_end;
+const uint8_t *slc_start = frm_start;
+const uint8_t *slc_end = frm_end;
+GetBitContext gb = h->gb;
+const FFHWAccel *hwaccel = ffhwaccel(h->avctx->hwaccel);
+
+ret = hwaccel->start_frame(h->avctx, NULL, 0);
+if (ret < 0)
+return ret;
+
+for (slc_start = frm_start; slc_start + 4 < frm_end; slc_start = slc_end) {
+slc_end = avpriv_find_start_code(slc_start + 4, frm_end, &stc);
+if (slc_end < frm_end) {
+slc_end -= 4;
+}
+
+init_get_bits(&h->gb, slc_start, (slc_end - slc_start) * 8);


init_get_bits8 avoids the unlikely-but-possible overflow case here.


+if (!check_for_slice(h)) {
+break;
+}
+
+ret = hwaccel->decode_slice(h->avctx, slc_start, slc_end - slc_start);
+if (ret < 0) {
+break;
+}
+}
+
+h->gb = gb;
+skip_bits(&h->gb, (slc_start - frm_start) * 8);


This is skipping to the start of the error in error cases?  Is that intended?


+
+if (ret < 0)
+return ret;
+
+return hwaccel->end_frame(h->avctx);


Are there any bad consequences if you call this with zero slices in the frame, 
since the loop above appears to allow that?  (If yes, maybe only call 
start_frame once you know you have some slices.)


+}
  
  /**

   * @brief remove frame out of dpb
@@ -1125,6 +1168,9 @@ static void cavs_frame_unref(AVSFrame *frame)
  if (!frame->f || !frame->f->buf[0])
  return;
  
+av_buffer_unref(&frame->hwaccel_priv_buf);

+frame->hwaccel_picture_private = NULL;
+
  av_frame_unref(frame->f);
  }
  
@@ -1219,6 +1265,17 @@ static int decode_pic(AVSContext *h)

  if (ret < 0)
  return ret;
  
+if (h->avctx->hwac

Re: [FFmpeg-devel] [PATCH] configure: autodetect libglslang ldflags

2024-01-22 Thread Martin Storsjö

On Mon, 22 Jan 2024, Lynne wrote:


Jan 22, 2024, 07:52 by ffmpeg-devel@ffmpeg.org:


Since glslang 14.0.0, OGLCompiler and HLSL stub libraries have been
fully removed from the build.

This fixes the configuration by detecting if the stub libraries are
still present (glslang releases before version 14.0.0).

ffbuild/config.log:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lOSDependent: No such file or directory
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lHLSL: No such file or directory
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lOGLCompiler: No such file or directory

Addresses https://trac.ffmpeg.org/ticket/10713
See https://bugs.gentoo.org/show_bug.cgi?id=918989
Should fix https://ffmpeg.org/pipermail/ffmpeg-devel/2023-August/313666.html

Signed-off-by: Matthew White 
---
configure | 23 +--
1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index c8ae0a061d..abff488dc0 100755
--- a/configure
+++ b/configure
@@ -2626,6 +2626,7 @@ CMDLINE_SET="
ignore_tests
install
ld
+libglslang_ldflags
ln_s
logfile
malloc_prefix
@@ -6652,6 +6653,24 @@ if enabled_all libglslang libshaderc; then
die "ERROR: libshaderc and libglslang are mutually exclusive, if in doubt, disable 
libglslang"
fi

+if enabled libglslang; then
+if [ -x "$(command -v glslang)" ]; then
+# https://github.com/KhronosGroup/glslang
+# commit 6be56e45e574b375d759b89dad35f780bbd4792f: Remove 
`OGLCompiler` and `HLSL` stub libraries from build
+# StandAlone/StandAlone.cpp: 
"SpirvGeneratorVersion:GLSLANG_VERSION_MAJOR.GLSLANG_VERSION_MINOR.GLSLANG_VERSION_PATCH
 GLSLANG_VERSION_FLAVOR"
+glslang_version="$(glslang -dumpversion)"
+glslang_major="${glslang_version%%.*}"
+glslang_major="${glslang_major#*:}"
+if test ${glslang_major} -le 13; then
+libglslang_ldflags=" -lOSDependent -lHLSL -lOGLCompiler"
+elif ! [[ ${glslang_major} =~ ^[0-9]+$ ]]; then
+die "ERROR: glslang's computed major version isn't a number: 
'${glslang_major}'"
+fi
+else
+die "ERROR: glslang binary not found, impossible to determine installed 
glslang's version"
+fi
+fi
+
check_cpp_condition winrt windows.h 
"!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"

if ! disabled w32threads && ! enabled pthreads; then
@@ -6771,10 +6790,10 @@ enabled libfreetype   && require_pkg_config libfreetype 
freetype2 "ft2build.
enabled libfribidi&& require_pkg_config libfribidi fribidi fribidi.h 
fribidi_version_info
enabled libharfbuzz   && require_pkg_config libharfbuzz harfbuzz hb.h 
hb_buffer_create
enabled libglslang && { check_lib spirv_compiler 
glslang/Include/glslang_c_interface.h glslang_initialize_process \
--lglslang -lMachineIndependent -lOSDependent 
-lHLSL -lOGLCompiler -lGenericCodeGen \
+-lglslang -lMachineIndependent 
"${libglslang_ldflags}" -lGenericCodeGen \
-lSPVRemapper -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools -lpthread -lstdc++ -lm ||
require spirv_compiler glslang/Include/glslang_c_interface.h 
glslang_initialize_process \
--lglslang -lOSDependent -lHLSL -lOGLCompiler \
+-lglslang "${libglslang_ldflags}" \
-lSPVRemapper -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools -lpthread -lstdc++ -lm; }
enabled libgme&& { check_pkg_config libgme libgme gme/gme.h 
gme_new_emu ||
require libgme gme/gme.h gme_new_emu -lgme -lstdc++; }
--
2.43.0



This is very very cursed. Fitting for the public API of the world's 
fifth worst library. Debian is stuck on version 13, so the majority of 
users are still stuck on version 13. Debian ships a pkg-config file, but 
of course it's incorrect, if you try to compile against it. Oh, and 
libshaderc in Debian ships with a bug such that it segfaults on init, so 
it's not like you can avoid that. And that package's pkg-config file got 
broken in the past.


I think this is fine for now. I'll let it be discussed for a few more 
days before merging it.


I think breaking cross compilation with glslang is pretty bad. Apparently 
VLC doesn't enable glslang in their ffmpeg builds though, but I would 
expect that some does.


Wouldn't it just be possible to test whether linkins succeeds with one set 
of libraries, and if not, try with the other set, and pick whichever set 
works with the library at hand? That would be way much simpler than this 
patch, and also work for cross compilation.


// Martin

___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Tomas Härdin
mån 2024-01-22 klockan 22:14 +0300 skrev Victor Luchits:
> The bitrate option (-b:v) can now be used to specify the bit rate
> of the video stream of the RoQ encoder.
> 
> Original patch by Joseph Fenton aka Chilly Willy
> 
> Signed-off-by: Victor Luchits 

Still doesn't apply.

> +/* Keyframe when no MOT or FCC codes in frame */
> +if (s->key_frame) {
> +av_log(avctx, AV_LOG_VERBOSE, "\nFound keyframe!\n");
> +rframe->pict_type = AV_PICTURE_TYPE_I;
> +avpkt->flags |= AV_PKT_FLAG_KEY;
> +} else {
> +rframe->pict_type = AV_PICTURE_TYPE_P;
> +avpkt->flags &= ~AV_PKT_FLAG_KEY;
> +}

Looks like framesSinceKeyframe still doesn't get reset

> +if (avctx->bit_rate) {
> +/* no specific bit rate desired, use frame quality */
> +if (frame->quality)
> +enc->lambda = frame->quality - 1;
> +else
> +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> +}

Looks like you got this backwards

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

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


[FFmpeg-devel] [PATCH] avformat/mov: ignore item boxes for animated heif

2024-01-22 Thread James Almer
Fixes a regression since d9fed9df2a, where the single animated stream would
be exported twice as two independent streams.

Signed-off-by: James Almer 
---
 libavformat/isom.h |   1 +
 libavformat/mov.c  | 141 +
 2 files changed, 93 insertions(+), 49 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 2cf456fee1..21caaac256 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -280,6 +280,7 @@ typedef struct MOVContext {
 int64_t duration; ///< duration of the longest track
 int found_moov;   ///< 'moov' atom has been found
 int found_iloc;   ///< 'iloc' atom has been found
+int found_iinf;   ///< 'iinf' atom has been found
 int found_mdat;   ///< 'mdat' atom has been found
 int found_hdlr_mdta;  ///< 'hdlr' atom with type 'mdta' has been found
 int trak_index;   ///< Index of the current 'trak'
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 5cb907e120..72c3fff4a4 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -81,6 +81,7 @@ typedef struct MOVParseTableEntry {
 
 static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
 static int mov_read_mfra(MOVContext *c, AVIOContext *f);
+static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
 static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, 
unsigned int* allocated_size,
   int count, int duration);
 
@@ -4639,6 +4640,17 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 MOVStreamContext *sc;
 int ret;
 
+if (c->found_iinf) {
+// * For animated heif, if the iinf box showed up before the moov
+//   box, we need to clear all the streams read in the former.
+for (int i = c->fc->nb_streams - 1; i >= 0; i--) {
+mov_free_stream_context(c->fc, c->fc->streams[i]);
+ff_remove_stream(c->fc, c->fc->streams[i]);
+}
+av_freep(&c->heif_info);
+c->heif_info_size = c->found_iinf = c->found_iloc = 0;
+}
+
 st = avformat_new_stream(c->fc, NULL);
 if (!st) return AVERROR(ENOMEM);
 st->id = -1;
@@ -7768,8 +7780,9 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 uint64_t base_offset, extent_offset, extent_length;
 uint8_t value;
 
-if (c->found_iloc) {
-av_log(c->fc, AV_LOG_INFO, "Duplicate iloc box found\n");
+if (c->found_moov) {
+// * For animated heif, we don't care about the iloc box as all the
+//   necessary information can be found in the moov box.
 return 0;
 }
 
@@ -7891,6 +7904,16 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 int entry_count;
 int version, ret;
 
+if (c->found_iinf) {
+av_log(c->fc, AV_LOG_WARNING, "Duplicate iinf box found\n");
+return 0;
+}
+if (c->found_moov) {
+// * For animated heif, we don't care about the iinf box as all the
+//   necessary information can be found in the moov box.
+return 0;
+}
+
 version = avio_r8(pb);
 avio_rb24(pb);  // flags.
 entry_count = version ? avio_rb32(pb) : avio_rb16(pb);
@@ -7914,6 +7937,7 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return ret;
 }
 
+c->found_iinf = 1;
 return 0;
 }
 
@@ -7927,6 +7951,13 @@ static int mov_read_iref(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 uint32_t width, height;
+
+if (c->found_moov) {
+// * For animated heif, we don't care about the ispe box as all the
+//   necessary information can be found in the moov box.
+return 0;
+}
+
 avio_r8(pb);  /* version */
 avio_rb24(pb);  /* flags */
 width  = avio_rb32(pb);
@@ -7961,6 +7992,12 @@ static int mov_read_iprp(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 int version, flags;
 int ret;
 
+if (c->found_moov) {
+// * For animated heif, we don't care about the iprp box as all the
+//   necessary information can be found in the moov box.
+return 0;
+}
+
 a.size = avio_rb32(pb);
 a.type = avio_rl32(pb);
 
@@ -8581,6 +8618,58 @@ static void mov_free_encryption_index(MOVEncryptionIndex 
**index) {
 av_freep(index);
 }
 
+static void mov_free_stream_context(AVFormatContext *s, AVStream *st)
+{
+MOVStreamContext *sc = st->priv_data;
+
+if (!sc)
+return;
+
+av_freep(&sc->ctts_data);
+for (int i = 0; i < sc->drefs_count; i++) {
+av_freep(&sc->drefs[i].path);
+av_freep(&sc->drefs[i].dir);
+}
+av_freep(&sc->drefs);
+
+sc->drefs_count = 0;
+
+if (!sc->pb_is_copied)
+ff_format_io_close(s, &sc->pb);
+
+sc->pb = NULL;
+av_freep(&sc->chunk_offsets);
+av_freep(&sc->stsc_data);
+av_freep(&sc->sample_sizes);
+av_fre

Re: [FFmpeg-devel] [PATCH] hwcontext_opencl: choose the first device if multiple devices are available

2024-01-22 Thread Mark Thompson

On 17/01/2024 07:36, Xiang, Haihao wrote:

From: Haihao Xiang 

This makes '-init_hw_device opencl' work in a multiple-device system.


Under what circumstances is this more useful than the existing behaviour which 
prompts the user to select the device they intend?

There is no particular ordering to devices, the first one is just random.  
Having your process fail with an opaque message (because the device picked 
lacks some operation) or run many times slower than expected (because the 
smallest device happened to be first in the list) or do something different on 
a machine which looks the same (because it has an extra driver for something 
else) rather than just saying up front that there are multiple devices and the 
user needs to pick seems worse to me, since it is much harder to see where the 
problem is.

Thanks,

- Mark
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Victor Luchitz
I've just posted a new version of the patch that addresses most (if not
all) of the comments from previous reviews.

On Mon, Jan 22, 2024 at 10:10 PM Tomas Härdin  wrote:

> mån 2024-01-22 klockan 21:32 +0300 skrev Victor Luchitz:
> > On Mon, Jan 22, 2024 at 4:57 PM Tomas Härdin  wrote:
> >
> > > > >
> > > > > >  -if (frame->quality)
> > > > > > -enc->lambda = frame->quality - 1;
> > > > > > -else
> > > > > > -enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > > +if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > > > > > +/* no specific bit rate desired, use frame quality
> > > > > > */
> > > > > > +if (frame->quality)
> > > > > > +enc->lambda = frame->quality - 1;
> > > > > > +else
> > > > > > +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > > +}
> > > > >
> > > > > This looks like a bit of a janky way to switch between qscale
> > > > > and
> > > > > bitrate. Isn't there a way to detect whether an option has been
> > > > > set
> > > > > explicitly? At the very least this behavior should be
> > > > > documented in
> > > > > doc/encoders.texi
> > > > >
> > > >
> > > > Originally, the code just checked for bit_rate !=
> > > > AV_CODEC_DEFAULT_BITRATE,
> > > > which required including options_table.h, which in turn produced
> > > > a
> > > > bunch
> > > > of compilation warnings about certain fields being deprecated.
> > > > None
> > > > of the
> > > > other codecs include that file + many simply check the bit_rate
> > > > field
> > > > against
> > > > magic constants.
> > >
> > > grepping for 20 didn't reveal anything like that. Do you have a
> > > specific example of an encoder that does this?
> > >
> >
> > ~/ffmpeg/libavcodec# grep -RI bit_rate . | grep 000 | grep -v 1000 |
> > wc -l
> > 38
>
> Most of these seem to revolve around sane defaults, picking various
> submodes or rejecting too high or too low bitrates
>
>
> > Most of the cases here are comparisons against magic constants
> > without
> > any comments about how they were chosen or what they do, none
> > whatsoever.
>
> I would suggest adding a different default as Martin suggests. If users
> really want shitty encodes I see no reason to deny them. I could see it
> being useful for modders.
>
> You might want an option for the tolerance stuff too
>
> /Tomas
> ___
> 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".
>


-- 
Best regards,
 Victor Luchitz
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Victor Luchits

The bitrate option (-b:v) can now be used to specify the bit rate
of the video stream of the RoQ encoder.

Original patch by Joseph Fenton aka Chilly Willy

Signed-off-by: Victor Luchits 
---
 Changelog|   1 +
 libavcodec/roqvideo.h|   1 +
 libavcodec/roqvideodec.c |  16 ++
 libavcodec/roqvideoenc.c | 107 +++
 libavcodec/version.h |   2 +-
 5 files changed, 117 insertions(+), 10 deletions(-)

diff --git a/Changelog b/Changelog
index c40b6d08fd..6974312f9d 100644
--- a/Changelog
+++ b/Changelog
@@ -22,6 +22,7 @@ version :
 - ffmpeg CLI -bsf option may now be used for input as well as output
 - ffmpeg CLI options may now be used as -/opt , which is equivalent
   to -opt >
+- RoQ video bit rate option support
 
 version 6.1:

 - libaribcaption decoder
diff --git a/libavcodec/roqvideo.h b/libavcodec/roqvideo.h
index 2c2e42884d..6d30bcaada 100644
--- a/libavcodec/roqvideo.h
+++ b/libavcodec/roqvideo.h
@@ -43,6 +43,7 @@ typedef struct RoqContext {
 AVFrame *last_frame;
 AVFrame *current_frame;
 int width, height;
+int key_frame;
 
 roq_cell cb2x2[256];

 roq_qcell cb4x4[256];
diff --git a/libavcodec/roqvideodec.c b/libavcodec/roqvideodec.c
index bfc69a65c9..b4ade3a43b 100644
--- a/libavcodec/roqvideodec.c
+++ b/libavcodec/roqvideodec.c
@@ -70,6 +70,7 @@ static void roqvideo_decode_frame(RoqContext *ri, 
GetByteContext *gb)
 
 chunk_start = bytestream2_tell(gb);

 xpos = ypos = 0;
+ri->key_frame = 1;
 
 if (chunk_size > bytestream2_get_bytes_left(gb)) {

 av_log(ri->logctx, AV_LOG_ERROR, "Chunk does not fit in input 
buffer\n");
@@ -92,12 +93,14 @@ static void roqvideo_decode_frame(RoqContext *ri, 
GetByteContext *gb)
 
 switch(vqid) {

 case RoQ_ID_MOT:
+ri->key_frame = 0;
 break;
 case RoQ_ID_FCC: {
 int byte = bytestream2_get_byte(gb);
 mx = 8 - (byte >> 4) - ((signed char) (chunk_arg >> 8));
 my = 8 - (byte & 0xf) - ((signed char) chunk_arg);
 ff_apply_motion_8x8(ri, xp, yp, mx, my);
+ri->key_frame = 0;
 break;
 }
 case RoQ_ID_SLD:
@@ -125,12 +128,14 @@ static void roqvideo_decode_frame(RoqContext *ri, 
GetByteContext *gb)
 vqflg_pos--;
 switch(vqid) {
 case RoQ_ID_MOT:
+ri->key_frame = 0;
 break;
 case RoQ_ID_FCC: {
 int byte = bytestream2_get_byte(gb);
 mx = 8 - (byte >> 4) - ((signed char) (chunk_arg 
>> 8));
 my = 8 - (byte & 0xf) - ((signed char) chunk_arg);
 ff_apply_motion_4x4(ri, x, y, mx, my);
+ri->key_frame = 0;
 break;
 }
 case RoQ_ID_SLD:
@@ -214,6 +219,17 @@ static int roq_decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 
 if ((ret = av_frame_ref(rframe, s->current_frame)) < 0)

 return ret;
+
+/* Keyframe when no MOT or FCC codes in frame */
+if (s->key_frame) {
+av_log(avctx, AV_LOG_VERBOSE, "\nFound keyframe!\n");
+rframe->pict_type = AV_PICTURE_TYPE_I;
+avpkt->flags |= AV_PKT_FLAG_KEY;
+} else {
+rframe->pict_type = AV_PICTURE_TYPE_P;
+avpkt->flags &= ~AV_PKT_FLAG_KEY;
+}
+
 *got_frame  = 1;
 
 /* shuffle frames */

diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
index 0933abf4f9..68ec9ec238 100644
--- a/libavcodec/roqvideoenc.c
+++ b/libavcodec/roqvideoenc.c
@@ -136,6 +136,8 @@ typedef struct RoqEncContext {
 struct ELBGContext *elbg;
 AVLFG randctx;
 uint64_t lambda;
+uint64_t last_lambda;
+int lambda_delta;
 
 motion_vect *this_motion4;

 motion_vect *last_motion4;
@@ -887,8 +889,9 @@ static int generate_new_codebooks(RoqEncContext *enc)
 return 0;
 }
 
-static int roq_encode_video(RoqEncContext *enc)

+static int roq_encode_video(AVCodecContext *avctx)
 {
+RoqEncContext *const enc = avctx->priv_data;
 RoqTempData *const tempData = &enc->tmp_data;
 RoqContext *const roq = &enc->common;
 int ret;
@@ -910,14 +913,14 @@ static int roq_encode_video(RoqEncContext *enc)
 
 /* Quake 3 can't handle chunks bigger than 65535 bytes */

 if (tempData->mainChunkSize/8 > 65535 && enc->quake3_compat) {
-if (enc->lambda > 10) {
+if (enc->lambda > 1) {
 av_log(roq->logctx, AV_LOG_ERROR, "Cannot encode video in Quake 
compatible form\n");
 return AVERROR(EINVAL);
 }
 av_log(roq->logctx, AV_LOG_ERROR,
"Warning, generated a frame too big for Quake (%d > 65535), "

Re: [FFmpeg-devel] [PATCH] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Tomas Härdin
mån 2024-01-22 klockan 21:32 +0300 skrev Victor Luchitz:
> On Mon, Jan 22, 2024 at 4:57 PM Tomas Härdin  wrote:
> 
> > > > 
> > > > >  -    if (frame->quality)
> > > > > -    enc->lambda = frame->quality - 1;
> > > > > -    else
> > > > > -    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > +    if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > > > > +    /* no specific bit rate desired, use frame quality
> > > > > */
> > > > > +    if (frame->quality)
> > > > > +    enc->lambda = frame->quality - 1;
> > > > > +    else
> > > > > +    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > +    }
> > > > 
> > > > This looks like a bit of a janky way to switch between qscale
> > > > and
> > > > bitrate. Isn't there a way to detect whether an option has been
> > > > set
> > > > explicitly? At the very least this behavior should be
> > > > documented in
> > > > doc/encoders.texi
> > > > 
> > > 
> > > Originally, the code just checked for bit_rate !=
> > > AV_CODEC_DEFAULT_BITRATE,
> > > which required including options_table.h, which in turn produced
> > > a
> > > bunch
> > > of compilation warnings about certain fields being deprecated.
> > > None
> > > of the
> > > other codecs include that file + many simply check the bit_rate
> > > field
> > > against
> > > magic constants.
> > 
> > grepping for 20 didn't reveal anything like that. Do you have a
> > specific example of an encoder that does this?
> > 
> 
> ~/ffmpeg/libavcodec# grep -RI bit_rate . | grep 000 | grep -v 1000 |
> wc -l
> 38

Most of these seem to revolve around sane defaults, picking various
submodes or rejecting too high or too low bitrates


> Most of the cases here are comparisons against magic constants
> without
> any comments about how they were chosen or what they do, none
> whatsoever.

I would suggest adding a different default as Martin suggests. If users
really want shitty encodes I see no reason to deny them. I could see it
being useful for modders.

You might want an option for the tolerance stuff too

/Tomas
___
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] configure: autodetect libglslang ldflags

2024-01-22 Thread Matthew White via ffmpeg-devel
> This is very very cursed. Fitting for the public API of the world's fifth 
> worst library.
> Debian is stuck on version 13, so the majority of users are still stuck on 
> version 13.
> Debian ships a pkg-config file, but of course it's incorrect, if you try to 
> compile against it.
> Oh, and libshaderc in Debian ships with a bug such that it segfaults on init, 
> so it's
> not like you can avoid that. And that package's pkg-config file got broken in 
> the past.
> 
> I think this is fine for now. I'll let it be discussed for a few more days 
> before merging it.

Thanks for explaining.

By the way, the patch of mine is just a quick fix to not break the FFmpeg's 
configuration
process when enabling glslang, `./configure --enable-libglslang`, while either 
libglslang
up to release 13.1.1 or since 14.0.0 is installed in the system.

Accepting only glslang version 14.0.0 and above (--enable-libglslang) will 
obsolete this
patch: stub flags/libraries "-lOSDependent -lHLSL -lOGLCompiler" may just be 
dropped.

If useful, this patch is trivial even to backport, I am currently applying it 
to v6.1.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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Victor Luchitz
On Mon, Jan 22, 2024 at 4:57 PM Tomas Härdin  wrote:

> > >
> > > >  -if (frame->quality)
> > > > -enc->lambda = frame->quality - 1;
> > > > -else
> > > > -enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > +if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > > > +/* no specific bit rate desired, use frame quality */
> > > > +if (frame->quality)
> > > > +enc->lambda = frame->quality - 1;
> > > > +else
> > > > +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > +}
> > >
> > > This looks like a bit of a janky way to switch between qscale and
> > > bitrate. Isn't there a way to detect whether an option has been set
> > > explicitly? At the very least this behavior should be documented in
> > > doc/encoders.texi
> > >
> >
> > Originally, the code just checked for bit_rate !=
> > AV_CODEC_DEFAULT_BITRATE,
> > which required including options_table.h, which in turn produced a
> > bunch
> > of compilation warnings about certain fields being deprecated. None
> > of the
> > other codecs include that file + many simply check the bit_rate field
> > against
> > magic constants.
>
> grepping for 20 didn't reveal anything like that. Do you have a
> specific example of an encoder that does this?
>

~/ffmpeg/libavcodec# grep -RI bit_rate . | grep 000 | grep -v 1000 | wc -l
38

Most of the cases here are comparisons against magic constants without
any comments about how they were chosen or what they do, none whatsoever.


> Perhaps we could move AV_CODEC_DEFAULT_BITRATE somewhere else, to avoid
> pulling in a bunch of unrelated stuff. Maybe that doesn't need to hold
> up this patch though. Tbh the way bitrate is defaulted to a value,
> which makes it impossible to differentiate between a user-supplied -b
> 200k an no -b at all, is even more janky. The default is also
> ridiculously low..
>
> I know some encoders like libvpx allow specifying both quality (-crf)
> and bitrate at the same time
>
> /Tomas
> ___
> 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".
>


-- 
Best regards,
 Victor Luchitz
___
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 3/3] fate/mov: test remuxing all stream heif items

2024-01-22 Thread James Almer
Signed-off-by: James Almer 
---
 tests/fate/mov.mak   | 2 +-
 tests/ref/fate/mov-heic-demux-still-image-multiple-items | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index f202f36d96..f549ae33d7 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -156,7 +156,7 @@ fate-mov-heic-demux-still-image-1-item: CMD = framemd5 -i 
$(TARGET_SAMPLES)/heif
 
 FATE_MOV_FFMPEG-$(call FRAMEMD5, MOV, HEVC, HEVC_PARSER) \
+= fate-mov-heic-demux-still-image-multiple-items
-fate-mov-heic-demux-still-image-multiple-items: CMD = framemd5 -i 
$(TARGET_SAMPLES)/heif-conformance/C003.heic -c:v copy
+fate-mov-heic-demux-still-image-multiple-items: CMD = framemd5 -i 
$(TARGET_SAMPLES)/heif-conformance/C003.heic -c:v copy -map 0
 
 # Resulting remux should have:
 # 1. first audio stream with AV_DISPOSITION_HEARING_IMPAIRED
diff --git a/tests/ref/fate/mov-heic-demux-still-image-multiple-items 
b/tests/ref/fate/mov-heic-demux-still-image-multiple-items
index c850c1ff9c..753cef267a 100644
--- a/tests/ref/fate/mov-heic-demux-still-image-multiple-items
+++ b/tests/ref/fate/mov-heic-demux-still-image-multiple-items
@@ -2,10 +2,17 @@
 #version: 2
 #hash: MD5
 #extradata 0, 100, 5444bf01e03182c73ae957179d560f4d
+#extradata 1, 100, 5444bf01e03182c73ae957179d560f4d
 #tb 0: 1/1
 #media_type 0: video
 #codec_id 0: hevc
 #dimensions 0: 1280x720
 #sar 0: 0/1
+#tb 1: 1/1
+#media_type 1: video
+#codec_id 1: hevc
+#dimensions 1: 1280x720
+#sar 1: 0/1
 #stream#, dts,pts, duration, size, hash
 0,  0,  0,1,   111554, 03ceabfab39afd2e2e796b9362111f32
+1,  0,  0,1,   112393, daa001d351c088a5bc328459e2501c95
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 2/3] avformat/mov: add support for tile HEIF still images

2024-01-22 Thread James Almer
Export each tile as its own stream, and the tiling information as a Stream
Group of type TILE_GRID.
This also enables exporting other stream items like thumbnails, which may be
present in non tiled HEIF images too. For those, the primary stream will be
tagged with the default disposition.

Based on a patch by Swaraj Hota

Signed-off-by: James Almer 
---
Any suggestion on how to have the thumbnail stream reference the Stream Group?
Anton suggested a new Stream Group for this, as there could be more than one
stream item referencing the image grid. I did not check if the spec allows more
than one thumbnail stream for the same grid, though.

 libavcodec/packet.h|   9 ++
 libavformat/avformat.h |   6 +
 libavformat/isom.h |   8 +-
 libavformat/mov.c  | 310 -
 4 files changed, 296 insertions(+), 37 deletions(-)

diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 2c57d262c6..48ca799334 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -323,6 +323,15 @@ enum AVPacketSideDataType {
  */
 AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM,
 
+/**
+ * Tile info for image reconstruction, e.g HEIF.
+ * @code
+ * u32le tile number in row major order [0..nb_tiles-1]
+ * u32le nb_tiles
+ * @endcode
+ */
+AV_PKT_DATA_TILE_INFO,
+
 /**
  * The number of side data types.
  * This is not part of the public API/ABI in the sense that it may
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index ab9a3fc6be..cf4e72e11d 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -811,6 +811,12 @@ typedef struct AVIndexEntry {
  * The video stream contains still images.
  */
 #define AV_DISPOSITION_STILL_IMAGE  (1 << 20)
+/**
+ * The video stream is intended to be merged with another stream before
+ * presentation.
+ * Used for example to signal the stream contains a tile from a HEIF grid.
+ */
+#define AV_DISPOSITION_TILE (1 << 21)
 
 /**
  * @return The AV_DISPOSITION_* flag corresponding to disp or a negative error
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 2cf456fee1..cd5478b61c 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -267,10 +267,10 @@ typedef struct HEIFItem {
 int item_id;
 int64_t extent_length;
 int64_t extent_offset;
-int64_t size;
 int width;
 int height;
 int type;
+int is_idat_relative;
 } HEIFItem;
 
 typedef struct MOVContext {
@@ -335,6 +335,12 @@ typedef struct MOVContext {
 int cur_item_id;
 HEIFItem *heif_info;
 int heif_info_size;
+int grid_item_id;
+int thmb_item_id;
+int16_t *tile_id_list;
+int nb_tiles;
+uint8_t *idat_buf;
+int64_t idat_size;
 int interleaved_read;
 } MOVContext;
 
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 5cb907e120..5e253877b8 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -184,6 +184,30 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext 
*pb, int len,
 return p - dst;
 }
 
+static AVStream *get_curr_st(MOVContext *c)
+{
+AVStream *st = NULL;
+
+if (c->fc->nb_streams < 1)
+return NULL;
+
+for (int i = 0; i < c->heif_info_size; i++) {
+HEIFItem *item = &c->heif_info[i];
+
+if (!item->st)
+continue;
+if (item->st->id != c->cur_item_id)
+continue;
+
+st = item->st;
+break;
+}
+if (!st)
+st = c->fc->streams[c->fc->nb_streams-1];
+
+return st;
+}
+
 static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len)
 {
 AVStream *st;
@@ -1766,9 +1790,9 @@ static int mov_read_colr(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 uint16_t color_primaries, color_trc, color_matrix;
 int ret;
 
-if (c->fc->nb_streams < 1)
+st = get_curr_st(c);
+if (!st)
 return 0;
-st = c->fc->streams[c->fc->nb_streams - 1];
 
 ret = ffio_read_size(pb, color_parameter_type, 4);
 if (ret < 0)
@@ -2116,9 +2140,9 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 AVStream *st;
 int ret;
 
-if (c->fc->nb_streams < 1)
+st = get_curr_st(c);
+if (!st)
 return 0;
-st = c->fc->streams[c->fc->nb_streams-1];
 
 if ((uint64_t)atom.size > (1<<30))
 return AVERROR_INVALIDDATA;
@@ -4928,12 +4952,10 @@ static int heif_add_stream(MOVContext *c, HEIFItem 
*item)
 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 st->codecpar->codec_id = mov_codec_id(st, item->type);
 sc->ffindex = st->index;
-c->trak_index = st->index;
 st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
 st->time_base.num = st->time_base.den = 1;
 st->nb_frames = 1;
 sc->time_scale = 1;
-sc = st->priv_data;
 sc->pb = c->fc->pb;
 sc->pb_is_copied = 1;
 
@@ -7761,15 +7783,60 @@ static int mov_read_pitm(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return atom.size;
 }
 
+static int mov_read_idat(MOVCo

[FFmpeg-devel] [PATCH 1/3 v3] avformat: add a Tile Grid stream group type

2024-01-22 Thread James Almer
This will be used to support tiled image formats like HEIF.

Signed-off-by: James Almer 
---
Moved the struct to libavformat. It can be moved to libavutil if we decide to
reuse it.

 libavformat/avformat.c |  8 
 libavformat/avformat.h | 86 ++
 libavformat/dump.c | 42 +
 libavformat/options.c  | 32 
 4 files changed, 168 insertions(+)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 882927f7b1..58dfa0746a 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -100,6 +100,14 @@ void ff_free_stream_group(AVStreamGroup **pstg)
 av_iamf_mix_presentation_free(&stg->params.iamf_mix_presentation);
 break;
 }
+case AV_STREAM_GROUP_PARAMS_TILE_GRID: {
+if (stg->params.tile_grid) {
+av_freep(&stg->params.tile_grid->tile_width);
+av_freep(&stg->params.tile_grid->tile_height);
+}
+av_freep(&stg->params.tile_grid);
+break;
+}
 default:
 break;
 }
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 5d0fe82250..ab9a3fc6be 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1022,11 +1022,96 @@ enum AVStreamGroupParamsType {
 AV_STREAM_GROUP_PARAMS_NONE,
 AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT,
 AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION,
+AV_STREAM_GROUP_PARAMS_TILE_GRID,
 };
 
 struct AVIAMFAudioElement;
 struct AVIAMFMixPresentation;
 
+/**
+ * AVTileGrid holds information on how to combine several independent images in
+ * a single grid for presentation.
+ *
+ * Its size is not a part of the ABI. No new fields may be added to this struct
+ * without a major version bump.
+ */
+typedef struct AVTileGrid {
+const AVClass *av_class;
+
+/**
+ * Amount of rows in the grid.
+ *
+ * Must be > 0.
+ */
+int tile_rows;
+/**
+ * Amount of columns in the grid.
+ *
+ * Must be > 0.
+ */
+int tile_cols;
+
+/**
+ * A @ref tile_rows * @ref tile_cols sized array of width values for each
+ * tile in the grid, in row major order.
+ * The sum of tile width values must be consistent across all rows.
+ *
+ * Must be allocated with the av_malloc() family of functions, and will be
+ * freed by av_tile_grid_free().
+ */
+int *tile_width;
+
+/**
+ * A @ref tile_rows * @ref tile_cols sized array of height values for each
+ * tile in the grid, in row major order.
+ * The sum of tile height values must be consistent across all columns.
+ *
+ * Must be allocated with the av_malloc() family of functions, and will be
+ * freed by av_tile_grid_free().
+ */
+int *tile_height;
+
+/**
+ * Offset in pixels from the left edge of the grid where the actual image
+ * meant for presentation starts.
+ *
+ * This field must be >= 0 and <= the sum of values for a row in the
+ * tile_width array minus @ref output_width.
+ */
+int horizontal_offset;
+/**
+ * Offset in pixels from the top edge of the grid where the actual image 
meant
+ * for presentation starts.
+ *
+ * This field must be >= 0 and <= the sum of values for a column in the
+ * tile_height array minus @ref output_height.
+ */
+int vertical_offset;
+
+/**
+ * Width of the final image for presentation.
+ *
+ * Must be > 0 and <= the sum of values for a row in the tile_width array
+ * minus @ref horizontal_offset.
+ * When it's not equal to the sum of values for a row in the tile_width 
array,
+ * the result of said sum minus output_width minus @ref horizontal_offset 
is
+ * the amount of pixels to be cropped from the right edge of the final 
image
+ * before presentation.
+ */
+int output_width;
+/**
+ * Height of the final image for presentation.
+ *
+ * Must be > 0 and <= the sum of values for a column in the tile_height 
array
+ * minus @ref vertical_offset.
+ * When it's not equal to the sum of values for a column in the 
tile_height,
+ * the result of said sum minus output_height minus @ref vertical_offset is
+ * the amount of pixels to be cropped from the bottom edge of the final 
image
+ * before presentation.
+ */
+int output_height;
+} AVTileGrid;
+
 typedef struct AVStreamGroup {
 /**
  * A class for @ref avoptions. Set by avformat_stream_group_create().
@@ -1062,6 +1147,7 @@ typedef struct AVStreamGroup {
 union {
 struct AVIAMFAudioElement *iamf_audio_element;
 struct AVIAMFMixPresentation *iamf_mix_presentation;
+struct AVTileGrid *tile_grid;
 } params;
 
 /**
diff --git a/libavformat/dump.c b/libavformat/dump.c
index aff51b43f6..5a8b5d7160 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 
+#include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #in

Re: [FFmpeg-devel] [PATCH] configure: autodetect libglslang ldflags

2024-01-22 Thread Lynne
Jan 22, 2024, 07:52 by ffmpeg-devel@ffmpeg.org:

> Since glslang 14.0.0, OGLCompiler and HLSL stub libraries have been
> fully removed from the build.
>
> This fixes the configuration by detecting if the stub libraries are
> still present (glslang releases before version 14.0.0).
>
> ffbuild/config.log:
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
> cannot find -lOSDependent: No such file or directory
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
> cannot find -lHLSL: No such file or directory
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
> cannot find -lOGLCompiler: No such file or directory
>
> Addresses https://trac.ffmpeg.org/ticket/10713
> See https://bugs.gentoo.org/show_bug.cgi?id=918989
> Should fix https://ffmpeg.org/pipermail/ffmpeg-devel/2023-August/313666.html
>
> Signed-off-by: Matthew White 
> ---
> configure | 23 +--
> 1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index c8ae0a061d..abff488dc0 100755
> --- a/configure
> +++ b/configure
> @@ -2626,6 +2626,7 @@ CMDLINE_SET="
> ignore_tests
> install
> ld
> +libglslang_ldflags
> ln_s
> logfile
> malloc_prefix
> @@ -6652,6 +6653,24 @@ if enabled_all libglslang libshaderc; then
> die "ERROR: libshaderc and libglslang are mutually exclusive, if in doubt, 
> disable libglslang"
> fi
>
> +if enabled libglslang; then
> +if [ -x "$(command -v glslang)" ]; then
> +# https://github.com/KhronosGroup/glslang
> +# commit 6be56e45e574b375d759b89dad35f780bbd4792f: Remove 
> `OGLCompiler` and `HLSL` stub libraries from build
> +# StandAlone/StandAlone.cpp: 
> "SpirvGeneratorVersion:GLSLANG_VERSION_MAJOR.GLSLANG_VERSION_MINOR.GLSLANG_VERSION_PATCH
>  GLSLANG_VERSION_FLAVOR"
> +glslang_version="$(glslang -dumpversion)"
> +glslang_major="${glslang_version%%.*}"
> +glslang_major="${glslang_major#*:}"
> +if test ${glslang_major} -le 13; then
> +libglslang_ldflags=" -lOSDependent -lHLSL -lOGLCompiler"
> +elif ! [[ ${glslang_major} =~ ^[0-9]+$ ]]; then
> +die "ERROR: glslang's computed major version isn't a number: 
> '${glslang_major}'"
> +fi
> +else
> +die "ERROR: glslang binary not found, impossible to determine 
> installed glslang's version"
> +fi
> +fi
> +
> check_cpp_condition winrt windows.h 
> "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
>
> if ! disabled w32threads && ! enabled pthreads; then
> @@ -6771,10 +6790,10 @@ enabled libfreetype   && require_pkg_config 
> libfreetype freetype2 "ft2build.
> enabled libfribidi&& require_pkg_config libfribidi fribidi fribidi.h 
> fribidi_version_info
> enabled libharfbuzz   && require_pkg_config libharfbuzz harfbuzz hb.h 
> hb_buffer_create
> enabled libglslang && { check_lib spirv_compiler 
> glslang/Include/glslang_c_interface.h glslang_initialize_process \
> --lglslang -lMachineIndependent -lOSDependent 
> -lHLSL -lOGLCompiler -lGenericCodeGen \
> +-lglslang -lMachineIndependent 
> "${libglslang_ldflags}" -lGenericCodeGen \
> -lSPVRemapper -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools -lpthread -lstdc++ -lm 
> ||
> require spirv_compiler glslang/Include/glslang_c_interface.h 
> glslang_initialize_process \
> --lglslang -lOSDependent -lHLSL -lOGLCompiler \
> +-lglslang "${libglslang_ldflags}" \
> -lSPVRemapper -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools -lpthread -lstdc++ -lm; 
> }
> enabled libgme&& { check_pkg_config libgme libgme gme/gme.h 
> gme_new_emu ||
> require libgme gme/gme.h gme_new_emu -lgme -lstdc++; }
> --
> 2.43.0
>

This is very very cursed. Fitting for the public API of the world's fifth worst 
library.
Debian is stuck on version 13, so the majority of users are still stuck on 
version 13.
Debian ships a pkg-config file, but of course it's incorrect, if you try to 
compile against it.
Oh, and libshaderc in Debian ships with a bug such that it segfaults on init, 
so it's
not like you can avoid that. And that package's pkg-config file got broken in 
the past.

I think this is fine for now. I'll let it be discussed for a few more days 
before merging it.
___
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 8/8] tests/checkasm/vvc_mc: add check_avg

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 tests/checkasm/vvc_mc.c | 64 +
 1 file changed, 64 insertions(+)

diff --git a/tests/checkasm/vvc_mc.c b/tests/checkasm/vvc_mc.c
index 711280deec..8adb00573f 100644
--- a/tests/checkasm/vvc_mc.c
+++ b/tests/checkasm/vvc_mc.c
@@ -35,6 +35,7 @@
 static const uint32_t pixel_mask[] = { 0x, 0x03ff03ff, 0x0fff0fff, 
0x3fff3fff, 0x };
 static const int sizes[] = { 2, 4, 8, 16, 32, 64, 128 };
 
+#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
 #define PIXEL_STRIDE (MAX_CTU_SIZE * 2)
 #define EXTRA_BEFORE 3
 #define EXTRA_AFTER  4
@@ -261,10 +262,73 @@ static void check_put_vvc_chroma_uni(void)
 report("put_uni_chroma");
 }
 
+#define AVG_SRC_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE)
+#define AVG_DST_BUF_SIZE (MAX_PB_SIZE * MAX_PB_SIZE * 2)
+
+static void check_avg(void)
+{
+LOCAL_ALIGNED_32(int16_t, src00, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int16_t, src01, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int16_t, src10, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int16_t, src11, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, dst0, [AVG_DST_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, dst1, [AVG_DST_BUF_SIZE]);
+VVCDSPContext c;
+
+for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
+randomize_avg_src((uint8_t*)src00, (uint8_t*)src10, AVG_SRC_BUF_SIZE * 
sizeof(int16_t));
+randomize_avg_src((uint8_t*)src01, (uint8_t*)src11, AVG_SRC_BUF_SIZE * 
sizeof(int16_t));
+ff_vvc_dsp_init(&c, bit_depth);
+for (int h = 2; h <= MAX_CTU_SIZE; h *= 2) {
+for (int w = 2; w <= MAX_CTU_SIZE; w *= 2) {
+{
+   declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, 
void, uint8_t *dst, ptrdiff_t dst_stride,
+const int16_t *src0, const int16_t *src1, int width, 
int height);
+if (check_func(c.inter.avg, "avg_%d_%dx%d", bit_depth, w, 
h)) {
+memset(dst0, 0, AVG_DST_BUF_SIZE);
+memset(dst1, 0, AVG_DST_BUF_SIZE);
+call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, 
src01, w, h);
+call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, 
src11, w, h);
+if (memcmp(dst0, dst1, DST_BUF_SIZE))
+fail();
+if (w == h)
+bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, 
src00, src01, w, h);
+}
+}
+{
+declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, 
void, uint8_t *dst, ptrdiff_t dst_stride,
+const int16_t *src0, const int16_t *src1, int width, 
int height,
+int denom, int w0, int w1, int o0, int o1);
+{
+const int denom = rnd() % 8;
+const int w0= rnd() % 256 - 128;
+const int w1= rnd() % 256 - 128;
+const int o0= rnd() % 256 - 128;
+const int o1= rnd() % 256 - 128;
+if (check_func(c.inter.w_avg, "w_avg_%d_%dx%d", 
bit_depth, w, h)) {
+memset(dst0, 0, AVG_DST_BUF_SIZE);
+memset(dst1, 0, AVG_DST_BUF_SIZE);
+
+call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, 
src01, w, h, denom, w0, w1, o0, o1);
+call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, 
src11, w, h, denom, w0, w1, o0, o1);
+if (memcmp(dst0, dst1, DST_BUF_SIZE))
+fail();
+if (w == h)
+bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, 
src00, src01, w, h, denom, w0, w1, o0, o1);
+}
+}
+}
+}
+}
+}
+report("avg");
+}
+
 void checkasm_check_vvc_mc(void)
 {
 check_put_vvc_luma();
 check_put_vvc_luma_uni();
 check_put_vvc_chroma();
 check_put_vvc_chroma_uni();
+check_avg();
 }
-- 
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 v3 5/8] avcodec/vvcdec: reuse h26x/2656_inter.asm to enable x86 optimizations

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/Makefile  |   1 +
 libavcodec/vvc/vvcdsp.c  |   4 +
 libavcodec/vvc/vvcdsp.h  |   2 +
 libavcodec/x86/vvc/Makefile  |   6 +
 libavcodec/x86/vvc/vvcdsp_init.c | 202 +++
 5 files changed, 215 insertions(+)
 create mode 100644 libavcodec/x86/vvc/Makefile
 create mode 100644 libavcodec/x86/vvc/vvcdsp_init.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..ce33631b60 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -65,6 +65,7 @@ OBJS = ac3_parser.o   
  \
 
 # subsystems
 include $(SRC_PATH)/libavcodec/vvc/Makefile
+include $(SRC_PATH)/libavcodec/x86/vvc/Makefile
 OBJS-$(CONFIG_AANDCTTABLES)+= aandcttab.o
 OBJS-$(CONFIG_AC3DSP)  += ac3dsp.o ac3.o ac3tab.o
 OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o 
mpeg4audio_sample_rates.o
diff --git a/libavcodec/vvc/vvcdsp.c b/libavcodec/vvc/vvcdsp.c
index c82ea7be30..c542be5258 100644
--- a/libavcodec/vvc/vvcdsp.c
+++ b/libavcodec/vvc/vvcdsp.c
@@ -138,4 +138,8 @@ void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
 VVC_DSP(8);
 break;
 }
+
+#if ARCH_X86
+ff_vvc_dsp_init_x86(vvcdsp, bit_depth);
+#endif
 }
diff --git a/libavcodec/vvc/vvcdsp.h b/libavcodec/vvc/vvcdsp.h
index b5a63c5833..6f59e73654 100644
--- a/libavcodec/vvc/vvcdsp.h
+++ b/libavcodec/vvc/vvcdsp.h
@@ -167,4 +167,6 @@ typedef struct VVCDSPContext {
 
 void ff_vvc_dsp_init(VVCDSPContext *hpc, int bit_depth);
 
+void ff_vvc_dsp_init_x86(VVCDSPContext *hpc, const int bit_depth);
+
 #endif /* AVCODEC_VVC_VVCDSP_H */
diff --git a/libavcodec/x86/vvc/Makefile b/libavcodec/x86/vvc/Makefile
new file mode 100644
index 00..b4acc22501
--- /dev/null
+++ b/libavcodec/x86/vvc/Makefile
@@ -0,0 +1,6 @@
+clean::
+   $(RM) $(CLEANSUFFIXES:%=libavcodec/x86/vvc/%)
+
+OBJS-$(CONFIG_VVC_DECODER) += x86/vvc/vvcdsp_init.o
+X86ASM-OBJS-$(CONFIG_VVC_DECODER)  += x86/h26x/h2656dsp.o   \
+   
  x86/h26x/h2656_inter.o
diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
new file mode 100644
index 00..c197cdb4cc
--- /dev/null
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -0,0 +1,202 @@
+/*
+ * VVC DSP init for x86
+ *
+ * Copyright (C) 2022-2024 Nuo Mi
+ * Copyright (c) 2023-2024 Wu Jianhua
+ *
+ * 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 "config.h"
+
+#include "libavutil/cpu.h"
+#include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
+#include "libavcodec/vvc/vvcdec.h"
+#include "libavcodec/vvc/vvc_ctu.h"
+#include "libavcodec/vvc/vvcdsp.h"
+#include "libavcodec/x86/h26x/h2656dsp.h"
+
+#define FW_PUT(name, depth, opt) \
+static void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const 
uint8_t *src, ptrdiff_t srcstride, \
+ int height, const int8_t *hf, 
const int8_t *vf, int width)\
+{  
\
+ff_h2656_put_## name ## _ ## depth ## _##opt(dst, 2 * MAX_PB_SIZE, src, 
srcstride, height, hf, vf, width); \
+}
+
+#define FW_PUT_TAP(fname, bitd, opt ) \
+FW_PUT(fname##4,   bitd, opt );   \
+FW_PUT(fname##8,   bitd, opt );   \
+FW_PUT(fname##16,  bitd, opt );   \
+FW_PUT(fname##32,  bitd, opt );   \
+FW_PUT(fname##64,  bitd, opt );   \
+FW_PUT(fname##128, bitd, opt );   \
+
+#define FW_PUT_4TAP(fname, bitd, opt) \
+FW_PUT(fname ## 2, bitd, opt) \
+FW_PUT_TAP(fname,  bitd, opt)
+
+#define FW_PUT_4TAP_SSE4(bitd)   \
+FW_PUT_4TAP(pixels,  bitd, sse4) \
+FW_PUT_4TAP(4tap_h,  bitd, sse4) \
+FW_PUT_4TAP(4tap_v,  bitd, sse4) \
+FW_PUT_4TAP(4tap_hv, bitd, sse4)
+
+#define FW_PUT_8TAP_SSE4(bitd)  \
+FW_PUT_TAP(8tap_h,  bitd, sse4) \
+FW_PUT_TAP(8tap_v,  bitd, sse4) \
+FW_PUT_TAP(8tap_hv, bitd, sse4)
+
+#define FW_PUT_SSE4(bitd)  \
+FW_PUT_4TAP_SSE4(bitd) \
+FW_PUT_8TAP_SSE4(bitd)
+
+FW_PUT_SSE4( 8);
+FW_PUT_SSE4(10);
+FW_PUT_SSE4(12);
+
+#define FW_PUT_T

[FFmpeg-devel] [PATCH v3 7/8] avcodec/x86/vvc: add avg and avg_w AVX2 optimizations

2024-01-22 Thread toqsxw
From: Wu Jianhua 

The avg/avg_w is based on dav1d.
See https://code.videolan.org/videolan/dav1d/-/blob/master/src/x86/mc_avx2.asm

vvc_avg_8_2x2_c: 71.6
vvc_avg_8_2x2_avx2: 26.8
vvc_avg_8_2x4_c: 140.8
vvc_avg_8_2x4_avx2: 34.6
vvc_avg_8_2x8_c: 410.3
vvc_avg_8_2x8_avx2: 41.3
vvc_avg_8_2x16_c: 769.3
vvc_avg_8_2x16_avx2: 60.3
vvc_avg_8_2x32_c: 1669.6
vvc_avg_8_2x32_avx2: 105.1
vvc_avg_8_2x64_c: 1978.3
vvc_avg_8_2x64_avx2: 425.8
vvc_avg_8_2x128_c: 6536.8
vvc_avg_8_2x128_avx2: 1315.1
vvc_avg_8_4x2_c: 155.6
vvc_avg_8_4x2_avx2: 26.1
vvc_avg_8_4x4_c: 250.3
vvc_avg_8_4x4_avx2: 31.3
vvc_avg_8_4x8_c: 831.8
vvc_avg_8_4x8_avx2: 41.3
vvc_avg_8_4x16_c: 1461.1
vvc_avg_8_4x16_avx2: 57.1
vvc_avg_8_4x32_c: 2821.6
vvc_avg_8_4x32_avx2: 105.1
vvc_avg_8_4x64_c: 3615.8
vvc_avg_8_4x64_avx2: 412.6
vvc_avg_8_4x128_c: 11962.6
vvc_avg_8_4x128_avx2: 1274.3
vvc_avg_8_8x2_c: 215.8
vvc_avg_8_8x2_avx2: 29.1
vvc_avg_8_8x4_c: 430.6
vvc_avg_8_8x4_avx2: 37.6
vvc_avg_8_8x8_c: 1463.3
vvc_avg_8_8x8_avx2: 51.8
vvc_avg_8_8x16_c: 2630.1
vvc_avg_8_8x16_avx2: 97.6
vvc_avg_8_8x32_c: 5813.8
vvc_avg_8_8x32_avx2: 196.6
vvc_avg_8_8x64_c: 6687.3
vvc_avg_8_8x64_avx2: 487.8
vvc_avg_8_8x128_c: 13178.6
vvc_avg_8_8x128_avx2: 1290.6
vvc_avg_8_16x2_c: 443.8
vvc_avg_8_16x2_avx2: 28.3
vvc_avg_8_16x4_c: 1253.3
vvc_avg_8_16x4_avx2: 32.1
vvc_avg_8_16x8_c: 2236.3
vvc_avg_8_16x8_avx2: 44.3
vvc_avg_8_16x16_c: 5127.8
vvc_avg_8_16x16_avx2: 63.3
vvc_avg_8_16x32_c: 6573.3
vvc_avg_8_16x32_avx2: 223.6
vvc_avg_8_16x64_c: 30311.8
vvc_avg_8_16x64_avx2: 437.8
vvc_avg_8_16x128_c: 25693.3
vvc_avg_8_16x128_avx2: 1266.8
vvc_avg_8_32x2_c: 954.6
vvc_avg_8_32x2_avx2: 32.1
vvc_avg_8_32x4_c: 2359.6
vvc_avg_8_32x4_avx2: 39.6
vvc_avg_8_32x8_c: 5703.6
vvc_avg_8_32x8_avx2: 57.1
vvc_avg_8_32x16_c: 9967.6
vvc_avg_8_32x16_avx2: 107.1
vvc_avg_8_32x32_c: 21327.6
vvc_avg_8_32x32_avx2: 272.6
vvc_avg_8_32x64_c: 39240.8
vvc_avg_8_32x64_avx2: 529.6
vvc_avg_8_32x128_c: 52580.8
vvc_avg_8_32x128_avx2: 1338.8
vvc_avg_8_64x2_c: 1647.3
vvc_avg_8_64x2_avx2: 38.8
vvc_avg_8_64x4_c: 5130.1
vvc_avg_8_64x4_avx2: 58.8
vvc_avg_8_64x8_c: 6529.3
vvc_avg_8_64x8_avx2: 88.3
vvc_avg_8_64x16_c: 19913.6
vvc_avg_8_64x16_avx2: 162.3
vvc_avg_8_64x32_c: 39360.8
vvc_avg_8_64x32_avx2: 295.8
vvc_avg_8_64x64_c: 49658.3
vvc_avg_8_64x64_avx2: 784.1
vvc_avg_8_64x128_c: 108513.1
vvc_avg_8_64x128_avx2: 1977.1
vvc_avg_8_128x2_c: 3226.1
vvc_avg_8_128x2_avx2: 61.1
vvc_avg_8_128x4_c: 10280.3
vvc_avg_8_128x4_avx2: 94.6
vvc_avg_8_128x8_c: 18079.3
vvc_avg_8_128x8_avx2: 155.3
vvc_avg_8_128x16_c: 45121.8
vvc_avg_8_128x16_avx2: 285.3
vvc_avg_8_128x32_c: 48651.8
vvc_avg_8_128x32_avx2: 581.6
vvc_avg_8_128x64_c: 165078.6
vvc_avg_8_128x64_avx2: 1942.8
vvc_avg_8_128x128_c: 339103.1
vvc_avg_8_128x128_avx2: 4332.6
vvc_avg_10_2x2_c: 144.3
vvc_avg_10_2x2_avx2: 26.8
vvc_avg_10_2x4_c: 142.6
vvc_avg_10_2x4_avx2: 45.3
vvc_avg_10_2x8_c: 478.1
vvc_avg_10_2x8_avx2: 38.1
vvc_avg_10_2x16_c: 518.3
vvc_avg_10_2x16_avx2: 58.1
vvc_avg_10_2x32_c: 2059.8
vvc_avg_10_2x32_avx2: 93.1
vvc_avg_10_2x64_c: 2383.8
vvc_avg_10_2x64_avx2: 714.8
vvc_avg_10_2x128_c: 4498.3
vvc_avg_10_2x128_avx2: 1466.3
vvc_avg_10_4x2_c: 228.6
vvc_avg_10_4x2_avx2: 26.8
vvc_avg_10_4x4_c: 378.3
vvc_avg_10_4x4_avx2: 30.6
vvc_avg_10_4x8_c: 866.8
vvc_avg_10_4x8_avx2: 44.6
vvc_avg_10_4x16_c: 1018.1
vvc_avg_10_4x16_avx2: 58.1
vvc_avg_10_4x32_c: 3590.8
vvc_avg_10_4x32_avx2: 128.8
vvc_avg_10_4x64_c: 4200.8
vvc_avg_10_4x64_avx2: 663.6
vvc_avg_10_4x128_c: 8450.8
vvc_avg_10_4x128_avx2: 1531.8
vvc_avg_10_8x2_c: 369.3
vvc_avg_10_8x2_avx2: 28.3
vvc_avg_10_8x4_c: 513.8
vvc_avg_10_8x4_avx2: 32.1
vvc_avg_10_8x8_c: 1720.3
vvc_avg_10_8x8_avx2: 49.1
vvc_avg_10_8x16_c: 1894.8
vvc_avg_10_8x16_avx2: 71.6
vvc_avg_10_8x32_c: 3931.3
vvc_avg_10_8x32_avx2: 148.1
vvc_avg_10_8x64_c: 7964.3
vvc_avg_10_8x64_avx2: 613.1
vvc_avg_10_8x128_c: 15540.1
vvc_avg_10_8x128_avx2: 1585.1
vvc_avg_10_16x2_c: 877.3
vvc_avg_10_16x2_avx2: 27.6
vvc_avg_10_16x4_c: 955.8
vvc_avg_10_16x4_avx2: 29.8
vvc_avg_10_16x8_c: 3419.6
vvc_avg_10_16x8_avx2: 62.6
vvc_avg_10_16x16_c: 3826.8
vvc_avg_10_16x16_avx2: 54.3
vvc_avg_10_16x32_c: 7655.3
vvc_avg_10_16x32_avx2: 86.3
vvc_avg_10_16x64_c: 30011.1
vvc_avg_10_16x64_avx2: 692.6
vvc_avg_10_16x128_c: 47894.8
vvc_avg_10_16x128_avx2: 1580.3
vvc_avg_10_32x2_c: 944.3
vvc_avg_10_32x2_avx2: 29.8
vvc_avg_10_32x4_c: 2022.6
vvc_avg_10_32x4_avx2: 35.1
vvc_avg_10_32x8_c: 6148.8
vvc_avg_10_32x8_avx2: 51.3
vvc_avg_10_32x16_c: 12601.6
vvc_avg_10_32x16_avx2: 70.8
vvc_avg_10_32x32_c: 15958.6
vvc_avg_10_32x32_avx2: 124.3
vvc_avg_10_32x64_c: 31784.6
vvc_avg_10_32x64_avx2: 757.3
vvc_avg_10_32x128_c: 63892.8
vvc_avg_10_32x128_avx2: 1711.3
vvc_avg_10_64x2_c: 1890.8
vvc_avg_10_64x2_avx2: 34.3
vvc_avg_10_64x4_c: 6267.3
vvc_avg_10_64x4_avx2: 42.6
vvc_avg_10_64x8_c: 12778.1
vvc_avg_10_64x8_avx2: 67.8
vvc_avg_10_64x16_c: 22304.3
vvc_avg_10_64x16_avx2: 116.8
vvc_avg_10_64x32_c: 30777.1
vvc_avg_10_64x32_avx2: 201.1
vvc_avg_10_64x64_c: 60169.1
vvc_avg_10_64x64_avx2: 1454.3
vvc_avg_10_64x128_c: 124392.8
vvc_avg_10_64x128_avx2: 3648.6
vvc_avg_10_128x2

[FFmpeg-devel] [PATCH v3 4/8] avcodec/x86/h26x/h2656_inter: add dststride to put

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/x86/h26x/h2656_inter.asm | 32 ++---
 libavcodec/x86/h26x/h2656dsp.c  |  4 ++--
 libavcodec/x86/h26x/h2656dsp.h  |  2 +-
 libavcodec/x86/hevcdsp_init.c   |  2 +-
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/libavcodec/x86/h26x/h2656_inter.asm 
b/libavcodec/x86/h26x/h2656_inter.asm
index aa296d549c..cbba0c1ea5 100644
--- a/libavcodec/x86/h26x/h2656_inter.asm
+++ b/libavcodec/x86/h26x/h2656_inter.asm
@@ -22,8 +22,6 @@
 ; */
 %include "libavutil/x86/x86util.asm"
 
-%define MAX_PB_SIZE 64
-
 SECTION_RODATA 32
 cextern pw_255
 cextern pw_512
@@ -342,7 +340,7 @@ SECTION .text
 %endmacro
 
 %macro LOOP_END 3
-add  %1q, 2*MAX_PB_SIZE  ; dst += dststride
+add  %1q, dststrideq ; dst += dststride
 add  %2q, %3q; src += srcstride
 dec  heightd ; cmp height
 jnz   .loop  ; height loop
@@ -539,7 +537,7 @@ SECTION .text
 
 
 ; **
-; void %1_put_pixels(int16_t *dst, const uint8_t *_src, ptrdiff_t srcstride,
+; void %1_put_pixels(int16_t *dst, ptrdiff_t dststride, const uint8_t *_src, 
ptrdiff_t srcstride,
 ; int height, const int8_t *hf, const int8_t *vf, int 
width)
 ; **
 
@@ -549,7 +547,7 @@ SECTION .text
 %endmacro
 
 %macro MC_PIXELS 3
-cglobal %1_put_pixels%2_%3, 4, 4, 3, dst, src, srcstride, height
+cglobal %1_put_pixels%2_%3, 5, 5, 3, dst, dststride, src, srcstride, height
 pxor  m2, m2
 .loop:
 SIMPLE_LOAD   %2, %3, srcq, m0
@@ -579,10 +577,10 @@ cglobal %1_put_uni_pixels%2_%3, 5, 5, 2, dst, dststride, 
src, srcstride, height
 %endif
 
 ; **
-; void %1_put_4tap_hX(int16_t *dst,
+; void %1_put_4tap_hX(int16_t *dst, ptrdiff_t dststride,
 ;  const uint8_t *_src, ptrdiff_t _srcstride, int height, int8_t *hf, 
int8_t *vf, int width);
 ; **
-cglobal %1_put_4tap_h%2_%3, 5, 5, XMM_REGS, dst, src, srcstride, height, hf
+cglobal %1_put_4tap_h%2_%3, 6, 6, XMM_REGS, dst, dststride, src, srcstride, 
height, hf
 %assign %%stride ((%3 + 7)/8)
 MC_4TAP_FILTER   %3, hf, m4, m5
 .loop:
@@ -612,10 +610,10 @@ cglobal %1_put_uni_4tap_h%2_%3, 6, 7, XMM_REGS, dst, 
dststride, src, srcstride,
 RET
 
 ; **
-; void %1_put_4tap_v(int16_t *dst,
+; void %1_put_4tap_v(int16_t *dst, ptrdiff_t dststride,
 ;  const uint8_t *_src, ptrdiff_t _srcstride, int height, int8_t *hf, 
int8_t *vf, int width)
 ; **
-cglobal %1_put_4tap_v%2_%3, 6, 6, XMM_REGS, dst, src, srcstride, height, 
r3src, vf
+cglobal %1_put_4tap_v%2_%3, 7, 7, XMM_REGS, dst, dststride, src, srcstride, 
height, r3src, vf
 sub srcq, srcstrideq
 MC_4TAP_FILTER%3, vf, m4, m5
 lea   r3srcq, [srcstrideq*3]
@@ -649,10 +647,10 @@ cglobal %1_put_uni_4tap_v%2_%3, 7, 7, XMM_REGS, dst, 
dststride, src, srcstride,
 
 %macro PUT_4TAP_HV 3
 ; **
-; void put_4tap_hv(int16_t *dst,
+; void put_4tap_hv(int16_t *dst, ptrdiff_t dststride,
 ;  const uint8_t *_src, ptrdiff_t _srcstride, int height, int8_t *hf, 
int8_t *vf, int width)
 ; **
-cglobal %1_put_4tap_hv%2_%3, 6, 7, 16 , dst, src, srcstride, height, hf, vf, 
r3src
+cglobal %1_put_4tap_hv%2_%3, 7, 8, 16 , dst, dststride, src, srcstride, 
height, hf, vf, r3src
 %assign %%stride ((%3 + 7)/8)
 sub srcq, srcstrideq
 MC_4TAP_HV_FILTER%3
@@ -784,12 +782,12 @@ cglobal %1_put_uni_4tap_hv%2_%3, 7, 8, 16 , dst, 
dststride, src, srcstride, heig
 %endmacro
 
 ; **
-; void put_8tap_hX_X_X(int16_t *dst, const uint8_t *_src, ptrdiff_t srcstride,
+; void put_8tap_hX_X_X(int16_t *dst, ptrdiff_t dststride, const uint8_t *_src, 
ptrdiff_t srcstride,
 ;   int height, const int8_t *hf, const int8_t *vf, int 
width)
 ; **
 
 %macro PUT_8TAP 3
-cglobal %1_put_8tap_h%2_%3, 5, 5, 16, dst, src, srcstride, height, hf
+cglobal %1_put_8tap_h%2_%3, 6, 6, 16, dst, dststride, src, srcstride, height, 
hf
 MC_8TAP_FILTER  %3, hf
 .loop:
 MC_8TAP_H_LOAD  %3, srcq, %2, 10
@@ -824,10 +822,10 @@ cglobal %1_put_uni_8tap_h%2_%3, 6, 7, 16 , dst, 
dststride, src, srcstride, heigh
 
 
 ; **
-; void put_8tap_vX_X_X(int16_t *dst, const uint8_t *_src, ptrdiff_t srcstride,
+; void put_8tap_vX_X_X(int16_t *dst, ptrdiff_t dststride, const uint8_t *_src, 
ptrdiff_t srcstride,
 ;  int height, const int8_t *hf, const int8_t *vf, int 
width)
 ; **
-cglobal %1_put_8tap_v%2_%3, 6, 8, 16, dst, src, srcstride, height, r3src, vf
+cglobal %1_put_8tap_v%2_%3, 7, 8, 16, dst, dststride, src, srcstride, height, 

[FFmpeg-devel] [PATCH v3 6/8] tests/checkasm: add checkasm_check_vvc_mc

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 tests/checkasm/Makefile   |   1 +
 tests/checkasm/checkasm.c |   3 +
 tests/checkasm/checkasm.h |   1 +
 tests/checkasm/vvc_mc.c   | 270 ++
 4 files changed, 275 insertions(+)
 create mode 100644 tests/checkasm/vvc_mc.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 3b5b54352b..3562acb2b2 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -40,6 +40,7 @@ AVCODECOBJS-$(CONFIG_V210_DECODER)  += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)  += v210enc.o
 AVCODECOBJS-$(CONFIG_VORBIS_DECODER)+= vorbisdsp.o
 AVCODECOBJS-$(CONFIG_VP9_DECODER)   += vp9dsp.o
+AVCODECOBJS-$(CONFIG_VVC_DECODER)   += vvc_mc.o
 
 CHECKASMOBJS-$(CONFIG_AVCODEC)  += $(AVCODECOBJS-yes)
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 87f24c77ca..36a97957e5 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -194,6 +194,9 @@ static const struct {
 #if CONFIG_VORBIS_DECODER
 { "vorbisdsp", checkasm_check_vorbisdsp },
 #endif
+#if CONFIG_VVC_DECODER
+{ "vvc_mc", checkasm_check_vvc_mc },
+#endif
 #endif
 #if CONFIG_AVFILTER
 #if CONFIG_AFIR_FILTER
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 4db8c495ea..53cb3ccfbf 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -131,6 +131,7 @@ void checkasm_check_vp8dsp(void);
 void checkasm_check_vp9dsp(void);
 void checkasm_check_videodsp(void);
 void checkasm_check_vorbisdsp(void);
+void checkasm_check_vvc_mc(void);
 
 struct CheckasmPerf;
 
diff --git a/tests/checkasm/vvc_mc.c b/tests/checkasm/vvc_mc.c
new file mode 100644
index 00..711280deec
--- /dev/null
+++ b/tests/checkasm/vvc_mc.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2023-2024 Nuo Mi
+ * Copyright (c) 2023-2024 Wu Jianhua
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "checkasm.h"
+#include "libavcodec/avcodec.h"
+#include "libavcodec/vvc/vvc_ctu.h"
+#include "libavcodec/vvc/vvc_data.h"
+
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
+
+static const uint32_t pixel_mask[] = { 0x, 0x03ff03ff, 0x0fff0fff, 
0x3fff3fff, 0x };
+static const int sizes[] = { 2, 4, 8, 16, 32, 64, 128 };
+
+#define PIXEL_STRIDE (MAX_CTU_SIZE * 2)
+#define EXTRA_BEFORE 3
+#define EXTRA_AFTER  4
+#define SRC_EXTRA(EXTRA_BEFORE + EXTRA_AFTER) * 2
+#define SRC_BUF_SIZE (PIXEL_STRIDE + SRC_EXTRA) * (PIXEL_STRIDE + SRC_EXTRA)
+#define DST_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE * 2)
+#define SRC_OFFSET   ((PIXEL_STRIDE + EXTRA_BEFORE * 2) * EXTRA_BEFORE)
+
+#define randomize_buffers(buf0, buf1, size, mask)   \
+do {\
+int k;  \
+for (k = 0; k < size; k += 4) { \
+uint32_t r = rnd() & mask;  \
+AV_WN32A(buf0 + k, r);  \
+AV_WN32A(buf1 + k, r);  \
+}   \
+} while (0)
+
+#define randomize_pixels(buf0, buf1, size)  \
+do {\
+uint32_t mask = pixel_mask[(bit_depth - 8) >> 1];   \
+randomize_buffers(buf0, buf1, size, mask);  \
+} while (0)
+
+#define randomize_avg_src(buf0, buf1, size) \
+do {\
+uint32_t mask = 0x3fff3fff; \
+randomize_buffers(buf0, buf1, size, mask);  \
+} while (0)
+
+static void check_put_vvc_luma(void)
+{
+LOCAL_ALIGNED_32(int16_t, dst0, [DST_BUF_SIZE / 2]);
+LOCAL_ALIGNED_32(int16_t, dst1, [DST_BUF_SIZE / 2]);
+LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
+VVCDSPContext c;
+
+declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, int16_t 
*dst, const uint8_t *src, const ptrdiff_t src_stride,
+  

[FFmpeg-devel] [PATCH v3 2/8] avcodec/hevcdsp_template: reuse put/put_luma/put_chroma from h2656_inter_template

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/hevcdsp_template.c | 594 +++---
 1 file changed, 46 insertions(+), 548 deletions(-)

diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c
index 0de14e9dcf..9b48bdf08e 100644
--- a/libavcodec/hevcdsp_template.c
+++ b/libavcodec/hevcdsp_template.c
@@ -26,6 +26,7 @@
 #include "bit_depth_template.c"
 #include "hevcdsp.h"
 #include "h26x/h2656_sao_template.c"
+#include "h26x/h2656_inter_template.c"
 
 static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int 
height,
   GetBitContext *gb, int pcm_bit_depth)
@@ -299,37 +300,51 @@ IDCT_DC(32)
 

 //
 

-static void FUNC(put_hevc_pel_pixels)(int16_t *dst,
-  const uint8_t *_src, ptrdiff_t 
_srcstride,
-  int height, intptr_t mx, intptr_t my, 
int width)
-{
-int x, y;
-const pixel *src= (const pixel *)_src;
-ptrdiff_t srcstride = _srcstride / sizeof(pixel);
-
-for (y = 0; y < height; y++) {
-for (x = 0; x < width; x++)
-dst[x] = src[x] << (14 - BIT_DEPTH);
-src += srcstride;
-dst += MAX_PB_SIZE;
-}
-}
-
-static void FUNC(put_hevc_pel_uni_pixels)(uint8_t *_dst, ptrdiff_t _dststride, 
const uint8_t *_src, ptrdiff_t _srcstride,
-  int height, intptr_t mx, intptr_t 
my, int width)
-{
-int y;
-const pixel *src= (const pixel *)_src;
-ptrdiff_t srcstride = _srcstride / sizeof(pixel);
-pixel *dst  = (pixel *)_dst;
-ptrdiff_t dststride = _dststride / sizeof(pixel);
-
-for (y = 0; y < height; y++) {
-memcpy(dst, src, width * sizeof(pixel));
-src += srcstride;
-dst += dststride;
-}
-}
+#define ff_hevc_pel_filters ff_hevc_qpel_filters
+#define DECL_HV_FILTER(f)  \
+const uint8_t *hf = ff_hevc_ ## f ## _filters[mx - 1]; \
+const uint8_t *vf = ff_hevc_ ## f ## _filters[my - 1];
+
+#define FW_PUT(p, f, t)
   \
+static void FUNC(put_hevc_## f)(int16_t *dst, const uint8_t *src, ptrdiff_t 
srcstride, int height,\
+  intptr_t mx, intptr_t my, int width) 
   \
+{  
   \
+DECL_HV_FILTER(p)  
   \
+FUNC(put_ ## t)(dst, src, srcstride, height, hf, vf, width);   
   \
+}
+
+#define FW_PUT_UNI(p, f, t)
   \
+static void FUNC(put_hevc_ ## f)(uint8_t *dst, ptrdiff_t dststride, const 
uint8_t *src,   \
+  ptrdiff_t srcstride, int height, intptr_t 
mx, intptr_t my, int width)   \
+{  
   \
+DECL_HV_FILTER(p)  
   \
+FUNC(put_ ## t)(dst, dststride, src, srcstride, height, hf, vf, width);
   \
+}
+
+#define FW_PUT_UNI_W(p, f, t)  
   \
+static void FUNC(put_hevc_ ## f)(uint8_t *dst, ptrdiff_t dststride, const 
uint8_t *src,   \
+  ptrdiff_t srcstride,int height, int denom, 
int wx, int ox,  \
+  intptr_t mx, intptr_t my, int width) 
   \
+{  
   \
+DECL_HV_FILTER(p)  
   \
+FUNC(put_ ## t)(dst, dststride, src, srcstride, height, denom, wx, ox, hf, 
vf, width);\
+}
+
+#define FW_PUT_FUNCS(f, t, dir)   \
+FW_PUT(f, f ## _ ## dir, t ## _ ## dir) \
+FW_PUT_UNI(f, f ## _uni_ ## dir, uni_ ## t ## _ ## dir)\
+FW_PUT_UNI_W(f, f ## _uni_w_ ## dir, uni_## t ## _w_ ## dir)
+
+FW_PUT(pel, pel_pixels, pixels)
+FW_PUT_UNI(pel, pel_uni_pixels, uni_pixels)
+FW_PUT_UNI_W(pel, pel_uni_w_pixels, uni_w_pixels)
+
+FW_PUT_FUNCS(qpel, luma,   h )
+FW_PUT_FUNCS(qpel, luma,   v )
+FW_PUT_FUNCS(qpel, luma,   hv)
+FW_PUT_FUNCS(epel, chroma, h )
+FW_PUT_FUNCS(epel, chroma, v )
+FW_PUT_FUNCS(epel, chroma, hv)
 
 static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_

[FFmpeg-devel] [PATCH v3 3/8] avcodec/x86/hevc_mc: move put/put_uni to h26x/h2656_inter.asm

2024-01-22 Thread toqsxw
From: Wu Jianhua 

This enable that the asm optimization can be reused by VVC

Signed-off-by: Wu Jianhua 
---
 libavcodec/x86/Makefile |1 +
 libavcodec/x86/h26x/h2656_inter.asm | 1145 +++
 libavcodec/x86/h26x/h2656dsp.c  |   98 +++
 libavcodec/x86/h26x/h2656dsp.h  |  103 +++
 libavcodec/x86/hevc_mc.asm  |  462 +--
 libavcodec/x86/hevcdsp_init.c   |  108 ++-
 6 files changed, 1471 insertions(+), 446 deletions(-)
 create mode 100644 libavcodec/x86/h26x/h2656_inter.asm
 create mode 100644 libavcodec/x86/h26x/h2656dsp.c
 create mode 100644 libavcodec/x86/h26x/h2656dsp.h

diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index d5fb30645a..8098cd840c 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -167,6 +167,7 @@ X86ASM-OBJS-$(CONFIG_HEVC_DECODER) += 
x86/hevc_add_res.o\
   x86/hevc_deblock.o\
   x86/hevc_idct.o   \
   x86/hevc_mc.o \
+  x86/h26x/h2656_inter.o\
   x86/hevc_sao.o\
   x86/hevc_sao_10bit.o
 X86ASM-OBJS-$(CONFIG_JPEG2000_DECODER) += x86/jpeg2000dsp.o
diff --git a/libavcodec/x86/h26x/h2656_inter.asm 
b/libavcodec/x86/h26x/h2656_inter.asm
new file mode 100644
index 00..aa296d549c
--- /dev/null
+++ b/libavcodec/x86/h26x/h2656_inter.asm
@@ -0,0 +1,1145 @@
+; /*
+; * Provide SSE luma and chroma mc functions for HEVC/VVC decoding
+; * Copyright (c) 2013 Pierre-Edouard LEPERE
+; * Copyright (c) 2023-2024 Nuo Mi
+; * Copyright (c) 2023-2024 Wu Jianhua
+; *
+; * This file is part of FFmpeg.
+; *
+; * FFmpeg is free software; you can redistribute it and/or
+; * modify it under the terms of the GNU Lesser General Public
+; * License as published by the Free Software Foundation; either
+; * version 2.1 of the License, or (at your option) any later version.
+; *
+; * FFmpeg is distributed in the hope that it will be useful,
+; * but WITHOUT ANY WARRANTY; without even the implied warranty of
+; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+; * Lesser General Public License for more details.
+; *
+; * You should have received a copy of the GNU Lesser General Public
+; * License along with FFmpeg; if not, write to the Free Software
+; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+; */
+%include "libavutil/x86/x86util.asm"
+
+%define MAX_PB_SIZE 64
+
+SECTION_RODATA 32
+cextern pw_255
+cextern pw_512
+cextern pw_2048
+cextern pw_1023
+cextern pw_1024
+cextern pw_4096
+cextern pw_8192
+%define scale_8 pw_512
+%define scale_10 pw_2048
+%define scale_12 pw_8192
+%define max_pixels_8 pw_255
+%define max_pixels_10 pw_1023
+max_pixels_12:  times 16 dw ((1 << 12)-1)
+cextern pb_0
+
+SECTION .text
+%macro SIMPLE_LOAD 4;width, bitd, tab, r1
+%if %1 == 2 || (%2 == 8 && %1 <= 4)
+movd  %4, [%3]   ; 
load data from source
+%elif %1 == 4 || (%2 == 8 && %1 <= 8)
+movq  %4, [%3]   ; 
load data from source
+%elif notcpuflag(avx)
+movu  %4, [%3]   ; 
load data from source
+%elif %1 <= 8 || (%2 == 8 && %1 <= 16)
+movdqu   %4, [%3]
+%else
+movu  %4, [%3]
+%endif
+%endmacro
+
+%macro VPBROADCASTW 2
+%if notcpuflag(avx2)
+movd   %1, %2
+pshuflw%1, %1, 0
+punpcklwd  %1, %1
+%else
+vpbroadcastw   %1, %2
+%endif
+%endmacro
+
+%macro MC_4TAP_FILTER 4 ; bitdepth, filter, a, b,
+VPBROADCASTW   %3, [%2q + 0 * 2]  ; coeff 0, 1
+VPBROADCASTW   %4, [%2q + 1 * 2]  ; coeff 2, 3
+%if %1 != 8
+pmovsxbw   %3, xmm%3
+pmovsxbw   %4, xmm%4
+%endif
+%endmacro
+
+%macro MC_4TAP_HV_FILTER 1
+VPBROADCASTW  m12, [vfq + 0 * 2]  ; vf 0, 1
+VPBROADCASTW  m13, [vfq + 1 * 2]  ; vf 2, 3
+VPBROADCASTW  m14, [hfq + 0 * 2]  ; hf 0, 1
+VPBROADCASTW  m15, [hfq + 1 * 2]  ; hf 2, 3
+
+pmovsxbw  m12, xm12
+pmovsxbw  m13, xm13
+%if %1 != 8
+pmovsxbw  m14, xm14
+pmovsxbw  m15, xm15
+%endif
+lea   r3srcq, [srcstrideq*3]
+%endmacro
+
+%macro MC_8TAP_SAVE_FILTER 5;offset, mm registers
+mova [rsp + %1 + 0*mmsize], %2
+mova [rsp + %1 + 1*mmsize], %3
+mova [rsp + %1 + 2*mmsize], %4
+mova [rsp + %1 + 3*mmsize], %5
+%endmacro
+
+%macro MC_8TAP_FILTER 2-3 ;bitdepth, filter, offset
+VPBROADCASTW  m12, [%2q + 0 * 2]  ; coeff 0, 1
+VPBROADCASTW  m13, [%2q + 1 * 2]  ; coeff 2, 3
+VPBROADCASTW  m14, [%2q + 2 * 2]  ; coeff 4, 5
+VPBROADCASTW  m15, [%2q + 3 * 2] 

[FFmpeg-devel] [PATCH v3 1/8] avcodec/vvc/vvc_inter_template: move put/put_luma/put_chroma template to h2656_inter_template.c

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/h26x/h2656_inter_template.c | 577 +
 libavcodec/vvc/vvc_inter_template.c| 559 +---
 2 files changed, 578 insertions(+), 558 deletions(-)
 create mode 100644 libavcodec/h26x/h2656_inter_template.c

diff --git a/libavcodec/h26x/h2656_inter_template.c 
b/libavcodec/h26x/h2656_inter_template.c
new file mode 100644
index 00..864f6c7e7d
--- /dev/null
+++ b/libavcodec/h26x/h2656_inter_template.c
@@ -0,0 +1,577 @@
+/*
+ * inter prediction template for HEVC/VVC
+ *
+ * Copyright (C) 2022 Nuo Mi
+ * Copyright (C) 2024 Wu Jianhua
+ *
+ * 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
+ */
+
+#define CHROMA_EXTRA_BEFORE 1
+#define CHROMA_EXTRA3
+#define LUMA_EXTRA_BEFORE   3
+#define LUMA_EXTRA  7
+
+static void FUNC(put_pixels)(int16_t *dst,
+const uint8_t *_src, const ptrdiff_t _src_stride,
+const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+const pixel *src= (const pixel *)_src;
+const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
+
+for (int y = 0; y < height; y++) {
+for (int x = 0; x < width; x++)
+dst[x] = src[x] << (14 - BIT_DEPTH);
+src += src_stride;
+dst += MAX_PB_SIZE;
+}
+}
+
+static void FUNC(put_uni_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+ const int8_t *hf, const int8_t *vf, const int width)
+{
+const pixel *src= (const pixel *)_src;
+pixel *dst  = (pixel *)_dst;
+const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
+const ptrdiff_t dst_stride  = _dst_stride / sizeof(pixel);
+
+for (int y = 0; y < height; y++) {
+memcpy(dst, src, width * sizeof(pixel));
+src += src_stride;
+dst += dst_stride;
+}
+}
+
+static void FUNC(put_uni_w_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+const int denom, const int wx, const int _ox,  const int8_t *hf, const 
int8_t *vf,
+const int width)
+{
+const pixel *src= (const pixel *)_src;
+pixel *dst  = (pixel *)_dst;
+const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
+const ptrdiff_t dst_stride  = _dst_stride / sizeof(pixel);
+const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+const int offset= 1 << (shift - 1);
+#else
+const int offset= 0;
+#endif
+const int ox= _ox * (1 << (BIT_DEPTH - 8));
+
+for (int y = 0; y < height; y++) {
+for (int x = 0; x < width; x++) {
+const int v = (src[x] << (14 - BIT_DEPTH));
+dst[x] = av_clip_pixel(((v * wx + offset) >> shift) + ox);
+}
+src += src_stride;
+dst += dst_stride;
+}
+}
+
+#define LUMA_FILTER(src, stride)   
\
+(filter[0] * src[x - 3 * stride] + 
\
+ filter[1] * src[x - 2 * stride] + 
\
+ filter[2] * src[x - stride] + 
\
+ filter[3] * src[x ] + 
\
+ filter[4] * src[x + stride] + 
\
+ filter[5] * src[x + 2 * stride] + 
\
+ filter[6] * src[x + 3 * stride] + 
\
+ filter[7] * src[x + 4 * stride])
+
+static void FUNC(put_luma_h)(int16_t *dst, const uint8_t *_src, const 
ptrdiff_t _src_stride,
+const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+const pixel *src   = (const pixel*)_src;
+const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+const int8_t *filter   = hf;
+
+for (int y = 0; y < height; y++) {
+for (int x = 0; x < width; x++)
+dst[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+src += src_stride;
+dst += MAX_PB_SIZE;
+}
+}
+
+static void FUNC(put_luma_v)(int

[FFmpeg-devel] 回复: 回复: 回复: [PATCH 2/2] fate: add raw IAMF tests

2024-01-22 Thread Wu Jianhua
>发件人: ffmpeg-devel  代表 James Almer 
>
>发送时间: 2024年1月22日 8:49
>收件人: ffmpeg-devel@ffmpeg.org
>主题: Re: [FFmpeg-devel] 回复: 回复: [PATCH 2/2] fate: add raw IAMF tests
>
> On 1/22/2024 1:23 PM, Wu Jianhua wrote:
>>> 发件人: ffmpeg-devel  代表 James Almer 
>>> 
>>> 发送时间: 2024年1月22日 8:10
>>> 收件人: ffmpeg-devel@ffmpeg.org
>>> 主题: Re: [FFmpeg-devel] 回复: [PATCH 2/2] fate: add raw IAMF tests
>>>
>>> On 1/22/2024 1:02 PM, Wu Jianhua wrote:
> 发件人: ffmpeg-devel  代表 James Almer 
> 
> 发送时间: 2024年1月20日 4:22
> 收件人: ffmpeg-devel@ffmpeg.org
> 主题: [FFmpeg-devel] [PATCH 2/2] fate: add raw IAMF tests
>
> Covers muxing from raw pcm audio input into FLAC, using several scalable 
> layouts,
> and demuxing the result.
>

 Hi there.

 Test iamf-7_1_4 failed. Look at tests/data/fate/iamf-7_1_4.err for details.
 make: *** [tests/Makefile:317: fate-iamf-7_1_4] Error 234
 Test iamf-5_1_4 failed. Look at tests/data/fate/iamf-5_1_4.err for details.
 make: *** [tests/Makefile:317: fate-iamf-5_1_4] Error 234

 These tests failed on my machine and looks like some machines on 
 http://fate.ffmpeg.org/ failed as well.

 Can you help check what the problem is?
>>>
>>> What is your system (The shell, mainly)? And what is the error you get?
>>>
>>
>> My OS is Ubuntu 22.04.3 LTS and the compiler is gcc version 11.4.0 (Ubuntu 
>> 11.4.0-1ubuntu1~22.04) .
> 
> Can you check again with current git head?

The issue is fixed. Thanks for the quick fix.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] 回复: 回复: [PATCH 2/2] fate: add raw IAMF tests

2024-01-22 Thread James Almer

On 1/22/2024 1:23 PM, Wu Jianhua wrote:

发件人: ffmpeg-devel  代表 James Almer 

发送时间: 2024年1月22日 8:10
收件人: ffmpeg-devel@ffmpeg.org
主题: Re: [FFmpeg-devel] 回复: [PATCH 2/2] fate: add raw IAMF tests

On 1/22/2024 1:02 PM, Wu Jianhua wrote:

发件人: ffmpeg-devel  代表 James Almer 

发送时间: 2024年1月20日 4:22
收件人: ffmpeg-devel@ffmpeg.org
主题: [FFmpeg-devel] [PATCH 2/2] fate: add raw IAMF tests

Covers muxing from raw pcm audio input into FLAC, using several scalable 
layouts,
and demuxing the result.



Hi there.

Test iamf-7_1_4 failed. Look at tests/data/fate/iamf-7_1_4.err for details.
make: *** [tests/Makefile:317: fate-iamf-7_1_4] Error 234
Test iamf-5_1_4 failed. Look at tests/data/fate/iamf-5_1_4.err for details.
make: *** [tests/Makefile:317: fate-iamf-5_1_4] Error 234

These tests failed on my machine and looks like some machines on 
http://fate.ffmpeg.org/ failed as well.

Can you help check what the problem is?


What is your system (The shell, mainly)? And what is the error you get?



My OS is Ubuntu 22.04.3 LTS and the compiler is gcc version 11.4.0 (Ubuntu 
11.4.0-1ubuntu1~22.04) .


Can you check again with current git head?
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Victor Luchitz
The rationale behind the bit_rate check is that RoQ was originally
designed with early CD-ROM games in mind (The 7th Guest, The
11th Hour), thus the lowest bit_rate that would make any sense in
that context should be based around that. You really want to get
the best picture quality without exceeding the 150KB/s limit of the
drive.

I also did try various lower bitrates, including the default one, on a
variety of files, and they resulted in either extremely poor visuals,
or the encoder spending a lot of extra time trying to downgrade the
picture quality before giving up. Or both. I didn't try extremely low
resolutions such as 128x128, as I don't see why anyone would
want to specify a bitrate that is less than that of a 1x CD-ROM
drive, while also using a viewport the size of a post stamp.

Either way, I'd really appreciate your input on how to deal with this
situation.

On Mon, Jan 22, 2024 at 5:19 PM Tomas Härdin  wrote:

> mån 2024-01-22 klockan 15:59 +0200 skrev Martin Storsjö:
> > On Mon, 22 Jan 2024, Tomas Härdin wrote:
> >
> > > > > > > >  -if (frame->quality)
> > > > > > -enc->lambda = frame->quality - 1;
> > > > > > -else
> > > > > > -enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > > +if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > > > > > +/* no specific bit rate desired, use frame quality
> > > > > > */
> > > > > > +if (frame->quality)
> > > > > > +enc->lambda = frame->quality - 1;
> > > > > > +else
> > > > > > +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > > +}
> > > > >
> > > > > This looks like a bit of a janky way to switch between qscale
> > > > > and
> > > > > bitrate. Isn't there a way to detect whether an option has been
> > > > > set
> > > > > explicitly? At the very least this behavior should be
> > > > > documented in
> > > > > doc/encoders.texi
> > > > >
> > > >
> > > > Originally, the code just checked for bit_rate !=
> > > > AV_CODEC_DEFAULT_BITRATE,
> > > > which required including options_table.h, which in turn produced
> > > > a
> > > > bunch
> > > > of compilation warnings about certain fields being deprecated.
> > > > None
> > > > of the
> > > > other codecs include that file + many simply check the bit_rate
> > > > field
> > > > against
> > > > magic constants.
> > >
> > > grepping for 20 didn't reveal anything like that. Do you have a
> > > specific example of an encoder that does this?
> > >
> > > Perhaps we could move AV_CODEC_DEFAULT_BITRATE somewhere else, to
> > > avoid
> > > pulling in a bunch of unrelated stuff. Maybe that doesn't need to
> > > hold
> > > up this patch though. Tbh the way bitrate is defaulted to a value,
> > > which makes it impossible to differentiate between a user-supplied
> > > -b
> > > 200k an no -b at all, is even more janky. The default is also
> > > ridiculously low..
> > >
> > > I know some encoders like libvpx allow specifying both quality (-
> > > crf)
> > > and bitrate at the same time
> >
> > FWIW, it's possible for an encoder to individually override the
> > defaults
> > for fields like these. See e.g. x264_defaults in libx264.c, where it
> > overrides the default bitrate to zero.
>
> Ooh, didn't know that. That sounds like a decent solution here. Can RoQ
> really not do < 800 kbps at all or is it just that it looks bad with
> say 256x256 but perhaps more decent with 128x128 or so?
>
> /Tomas
> ___
> 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".
>


-- 
Best regards,
 Victor Luchitz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] 回复: 回复: [PATCH 2/2] fate: add raw IAMF tests

2024-01-22 Thread Wu Jianhua
> 发件人: ffmpeg-devel  代表 James Almer 
> 
> 发送时间: 2024年1月22日 8:10
> 收件人: ffmpeg-devel@ffmpeg.org
> 主题: Re: [FFmpeg-devel] 回复: [PATCH 2/2] fate: add raw IAMF tests
>
> On 1/22/2024 1:02 PM, Wu Jianhua wrote:
>>> 发件人: ffmpeg-devel  代表 James Almer 
>>> 
>>> 发送时间: 2024年1月20日 4:22
>>> 收件人: ffmpeg-devel@ffmpeg.org
>>> 主题: [FFmpeg-devel] [PATCH 2/2] fate: add raw IAMF tests
>>>
>>> Covers muxing from raw pcm audio input into FLAC, using several scalable 
>>> layouts,
>>> and demuxing the result.
>>>
>>
>> Hi there.
>>
>> Test iamf-7_1_4 failed. Look at tests/data/fate/iamf-7_1_4.err for details.
>> make: *** [tests/Makefile:317: fate-iamf-7_1_4] Error 234
>> Test iamf-5_1_4 failed. Look at tests/data/fate/iamf-5_1_4.err for details.
>> make: *** [tests/Makefile:317: fate-iamf-5_1_4] Error 234
>>
>> These tests failed on my machine and looks like some machines on 
>> http://fate.ffmpeg.org/ failed as well.
>>
>> Can you help check what the problem is?
>
> What is your system (The shell, mainly)? And what is the error you get?
>

My OS is Ubuntu 22.04.3 LTS and the compiler is gcc version 11.4.0 (Ubuntu 
11.4.0-1ubuntu1~22.04) .

Here is the full error message:
TESTseek-acodec-adpcm-ima_wav-trellis
--- ./tests/ref/fate/iamf-stereo2024-01-23 00:17:30.109846236 +0800
+++ tests/data/fate/iamf-stereo 2024-01-23 00:18:16.857845219 +0800
@@ -1,18 +0,0 @@
-ace731a4fbc302e24498d6b64daa16e7 *tests/data/fate/iamf-stereo.iamf
-14426 tests/data/fate/iamf-stereo.iamf
-#extradata 0:   34, 0x40a802c6
-#tb 0: 1/44100
-#media_type 0: audio
-#codec_id 0: flac
-#sample_rate 0: 44100
-#channel_layout_name 0: stereo
-0,  0,  0, 4608, 1399, 0x6e89566e
-0,   4608,   4608, 4608, 1442, 0x6c3c5b13
-0,   9216,   9216, 4608, 1380, 0xc497571b
-0,  13824,  13824, 4608, 1383, 0x48e9510f
-0,  18432,  18432, 4608, 1572, 0x9a514719
-0,  23040,  23040, 4608, 1391, 0x74ac5014
-0,  27648,  27648, 4608, 1422, 0x2f9d47c5
-0,  32256,  32256, 4608, 1768, 0x2a044b99
-0,  36864,  36864, 4608, 1534, 0xb0b35a3f
-0,  41472,  41472, 4608,  926, 0xc26a5eae
Test iamf-stereo failed. Look at tests/data/fate/iamf-stereo.err for details.
make: *** [tests/Makefile:317: fate-iamf-stereo] Error 234
make: *** Waiting for unfinished jobs
TESTseek-acodec-adpcm-ms
--- ./tests/ref/fate/iamf-5_1_4 2024-01-23 00:17:30.109846236 +0800
+++ tests/data/fate/iamf-5_1_4  2024-01-23 00:18:16.845845219 +0800
@@ -1,98 +0,0 @@
-c447cbbc8943cfb751fdf1145a094250 *tests/data/fate/iamf-5_1_4.iamf
-85603 tests/data/fate/iamf-5_1_4.iamf
-#extradata 0:   34, 0x40a802c6
-#extradata 1:   34, 0x40a802c6
-#extradata 2:   34, 0x407c02c4
-#extradata 3:   34, 0x407c02c4
-#extradata 4:   34, 0x40a802c6
-#extradata 5:   34, 0x40a802c6
-#tb 0: 1/44100
-#media_type 0: audio
-#codec_id 0: flac
-#sample_rate 0: 44100
-#channel_layout_name 0: stereo
-#tb 1: 1/44100
-#media_type 1: audio
-#codec_id 1: flac
-#sample_rate 1: 44100
-#channel_layout_name 1: stereo
-#tb 2: 1/44100
-#media_type 2: audio
-#codec_id 2: flac
-#sample_rate 2: 44100
-#channel_layout_name 2: mono
-#tb 3: 1/44100
-#media_type 3: audio
-#codec_id 3: flac
-#sample_rate 3: 44100
-#channel_layout_name 3: mono
-#tb 4: 1/44100
-#media_type 4: audio
-#codec_id 4: flac
-#sample_rate 4: 44100
-#channel_layout_name 4: stereo
-#tb 5: 1/44100
-#media_type 5: audio
-#codec_id 5: flac
-#sample_rate 5: 44100
-#channel_layout_name 5: stereo
-0,  0,  0, 4608, 1399, 0x6e89566e
-1,  0,  0, 4608, 1399, 0x6e89566e
-2,  0,  0, 4608, 1396, 0x0dcb5677
-3,  0,  0, 4608, 1396, 0x0dcb5677
-4,  0,  0, 4608, 1399, 0x6e89566e
-5,  0,  0, 4608, 1399, 0x6e89566e
-0,   4608,   4608, 4608, 1442, 0x6c3c5b13
-1,   4608,   4608, 4608, 1442, 0x6c3c5b13
-2,   4608,   4608, 4608, 1439, 0xc46b5ac5
-3,   4608,   4608, 4608, 1439, 0xc46b5ac5
-4,   4608,   4608, 4608, 1442, 0x6c3c5b13
-5,   4608,   4608, 4608, 1442, 0x6c3c5b13
-0,   9216,   9216, 4608, 1380, 0xc497571b
-1,   9216,   9216, 4608, 1380, 0xc497571b
-2,   9216,   9216, 4608, 1377, 0x5b2a55fe
-3,   9216,   9216, 4608, 1377, 0x5b2a55fe
-4,   9216,   9216, 4608, 1380, 0xc497571b
-5,   9216,   9216, 4608, 1380, 0xc497571b
-0,  13824,  13824, 4608, 1383, 0x48e9510f
-1,  13824,  13824, 4608, 1383, 0x48e9510f
-2,  13824,  13824, 4608, 1380, 0x045550d3
-3,  13824,  13824, 4608, 1380, 0x045550d3
-4,  13824,  13824, 4608, 1383, 0x48e9510f
-5,  13824,  13824, 4608, 1383, 0x48e9510f
-0,  18432

Re: [FFmpeg-devel] [PATCH] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Victor Luchitz
Thanks, I will look into it

On Mon, Jan 22, 2024 at 4:59 PM Martin Storsjö  wrote:

> On Mon, 22 Jan 2024, Tomas Härdin wrote:
>
> >>> >>>  -if (frame->quality)
> >> > > -enc->lambda = frame->quality - 1;
> >> > > -else
> >> > > -enc->lambda = 2*ROQ_LAMBDA_SCALE;
> >> > > +if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> >> > > +/* no specific bit rate desired, use frame quality */
> >> > > +if (frame->quality)
> >> > > +enc->lambda = frame->quality - 1;
> >> > > +else
> >> > > +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> >> > > +}
> >> >
> >> > This looks like a bit of a janky way to switch between qscale and
> >> > bitrate. Isn't there a way to detect whether an option has been set
> >> > explicitly? At the very least this behavior should be documented in
> >> > doc/encoders.texi
> >> >
> >>
> >> Originally, the code just checked for bit_rate !=
> >> AV_CODEC_DEFAULT_BITRATE,
> >> which required including options_table.h, which in turn produced a
> >> bunch
> >> of compilation warnings about certain fields being deprecated. None
> >> of the
> >> other codecs include that file + many simply check the bit_rate field
> >> against
> >> magic constants.
> >
> > grepping for 20 didn't reveal anything like that. Do you have a
> > specific example of an encoder that does this?
> >
> > Perhaps we could move AV_CODEC_DEFAULT_BITRATE somewhere else, to avoid
> > pulling in a bunch of unrelated stuff. Maybe that doesn't need to hold
> > up this patch though. Tbh the way bitrate is defaulted to a value,
> > which makes it impossible to differentiate between a user-supplied -b
> > 200k an no -b at all, is even more janky. The default is also
> > ridiculously low..
> >
> > I know some encoders like libvpx allow specifying both quality (-crf)
> > and bitrate at the same time
>
> FWIW, it's possible for an encoder to individually override the defaults
> for fields like these. See e.g. x264_defaults in libx264.c, where it
> overrides the default bitrate to zero.
>
> // Martin
> ___
> 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".
>


-- 
Best regards,
 Victor Luchitz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] 回复: [PATCH 2/2] fate: add raw IAMF tests

2024-01-22 Thread James Almer

On 1/22/2024 1:02 PM, Wu Jianhua wrote:

发件人: ffmpeg-devel  代表 James Almer 

发送时间: 2024年1月20日 4:22
收件人: ffmpeg-devel@ffmpeg.org
主题: [FFmpeg-devel] [PATCH 2/2] fate: add raw IAMF tests

Covers muxing from raw pcm audio input into FLAC, using several scalable 
layouts,
and demuxing the result.



Hi there.

Test iamf-7_1_4 failed. Look at tests/data/fate/iamf-7_1_4.err for details.
make: *** [tests/Makefile:317: fate-iamf-7_1_4] Error 234
Test iamf-5_1_4 failed. Look at tests/data/fate/iamf-5_1_4.err for details.
make: *** [tests/Makefile:317: fate-iamf-5_1_4] Error 234

These tests failed on my machine and looks like some machines on 
http://fate.ffmpeg.org/ failed as well.

Can you help check what the problem is?


What is your system (The shell, mainly)? And what is the error you get?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] 回复: [PATCH 2/2] fate: add raw IAMF tests

2024-01-22 Thread Wu Jianhua
> 发件人: ffmpeg-devel  代表 James Almer 
> 
> 发送时间: 2024年1月20日 4:22
> 收件人: ffmpeg-devel@ffmpeg.org
> 主题: [FFmpeg-devel] [PATCH 2/2] fate: add raw IAMF tests
>
> Covers muxing from raw pcm audio input into FLAC, using several scalable 
> layouts,
> and demuxing the result.
>

Hi there.

Test iamf-7_1_4 failed. Look at tests/data/fate/iamf-7_1_4.err for details.
make: *** [tests/Makefile:317: fate-iamf-7_1_4] Error 234
Test iamf-5_1_4 failed. Look at tests/data/fate/iamf-5_1_4.err for details.
make: *** [tests/Makefile:317: fate-iamf-5_1_4] Error 234

These tests failed on my machine and looks like some machines on 
http://fate.ffmpeg.org/ failed as well.

Can you help check what the problem is?

Thanks,
Jianhua
___
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 8/9] avcodec: add D3D12VA hardware HEVC encoder

2024-01-22 Thread Wu Jianhua
> 发件人: ffmpeg-devel  代表 
> tong1.wu-at-intel@ffmpeg.org 
> 发送时间: 2024年1月21日 21:57
> 收件人: ffmpeg-devel@ffmpeg.org
> 抄送: Tong Wu
> 主题: [FFmpeg-devel] [PATCH 8/9] avcodec: add D3D12VA hardware HEVC encoder
> 
> From: Tong Wu 
> 
> This implementation is based on D3D12 Video Encoding Spec:
> https://microsoft.github.io/DirectX-Specs/d3d/D3D12VideoEncoding.html
> 
> Sample command line for transcoding:
> ffmpeg.exe -hwaccel d3d12va -hwaccel_output_format d3d12 -i input.mp4
> -c:v hevc_d3d12va output.mp4
> 
> Signed-off-by: Tong Wu 
> ---
 > configure|6 +
 > libavcodec/Makefile  |4 +-
 > libavcodec/allcodecs.c   |1 +
 > libavcodec/d3d12va_encode.c  | 1441 ++
 > libavcodec/d3d12va_encode.h  |  200 +
 > libavcodec/d3d12va_encode_hevc.c | 1016 +
 > libavcodec/hw_base_encode.h  |2 +-
 > 7 files changed, 2668 insertions(+), 2 deletions(-)
 > create mode 100644 libavcodec/d3d12va_encode.c
 > create mode 100644 libavcodec/d3d12va_encode.h
 > create mode 100644 libavcodec/d3d12va_encode_hevc.c

> +D3D12_OBJECT_RELEASE(ctx->sync_ctx.fence);
> +if (ctx->sync_ctx.event)
> +CloseHandle(ctx->sync_ctx.event);
> +
> +D3D12_OBJECT_RELEASE(ctx->video_device3);
> +D3D12_OBJECT_RELEASE(ctx->device);
> +D3D12_OBJECT_RELEASE(ctx->encoder_heap);
> +D3D12_OBJECT_RELEASE(ctx->encoder);

We need to release all of the objects, including the encoder and encoder_heap, 
created by the device before releasing the device.

> +
> +typedef struct D3D12VAEncodeProfile {
> +//lavc profile value (AV_PROFILE_*).
> +int   av_profile;
> +//Supported bit depth.
> +int   depth;
> +//Number of components.
> +int   nb_components;
> +//Chroma subsampling in width dimension.
> +int   log2_chroma_w;
> +//Chroma subsampling in height dimension.
> +int   log2_chroma_h;
> +//D3D12 profile value.
> +D3D12_VIDEO_ENCODER_PROFILE_DESC d3d12_profile;
> +} D3D12VAEncodeProfile;
> +
> +typedef struct D3D12VAEncodeRCMode {
> +// Base.
> +HWBaseEncodeRCMode base;
> +// Supported by D3D12 HW.
> +int supported;
> +// D3D12 mode value.
> +D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE d3d12_mode;
> +} D3D12VAEncodeRCMode;
> +
> +typedef struct D3D12VAEncodeContext {
> +HWBaseEncodeContext base;
> +
> +//Codec-specific hooks.
> +const struct D3D12VAEncodeType *codec;
> +
> +//Chosen encoding profile details.
> +const D3D12VAEncodeProfile *profile;
> +
> +//Chosen rate control mode details.
> +const D3D12VAEncodeRCMode *rc_mode;
> +
> +AVD3D12VADeviceContext *hwctx;
> +
> +//Device3 interface.
> +ID3D12Device3 *device3;
> +
> +ID3D12VideoDevice3 *video_device3;
> +
> +//Pool of (reusable) bitstream output buffers.
> +AVBufferPool   *output_buffer_pool;
> +
> +//D3D12 video encoder.
> +AVBufferRef *encoder_ref;
> +
> +ID3D12VideoEncoder *encoder;
> +
> +//D3D12 video encoder heap.
> +ID3D12VideoEncoderHeap *encoder_heap;
> +
> +//A cached queue for reusing the D3D12 command allocators.
> +//@see 
> https://learn.microsoft.com/en-us/windows/win32/direct3d12/recording-command-lists-and-bundles#id3d12commandallocator
> +AVFifo *allocator_queue;
> +
> +//D3D12 command queue.
> +ID3D12CommandQueue *command_queue;
> +
> +//D3D12 video encode command list.
> +ID3D12VideoEncodeCommandList2 *command_list;
> +
> +//The sync context used to sync command queue.
> +AVD3D12VASyncContext sync_ctx;
> +
> +//bi_not_empty feature.
> +int bi_not_empty;
> +
> +//D3D12 hardware structures.
> +D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC resolution;
> +
> +D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION codec_conf;
> +
> +D3D12_VIDEO_ENCODER_RATE_CONTROL rc;
> +
> +D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS req;
> +
> +D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE GOP;
> +
> +D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOLUTION_SUPPORT_LIMITS res_limits;
> +
> +D3D12_VIDEO_ENCODER_LEVEL_SETTING level;
> +} D3D12VAEncodeContext;
> +
Can we use the comment style the same as D3D12VADecodeContext?


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

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


[FFmpeg-devel] [PATCH v3 6/8] tests/checkasm: add checkasm_check_vvc_mc

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 tests/checkasm/Makefile   |   1 +
 tests/checkasm/checkasm.c |   3 +
 tests/checkasm/checkasm.h |   1 +
 tests/checkasm/vvc_mc.c   | 270 ++
 4 files changed, 275 insertions(+)
 create mode 100644 tests/checkasm/vvc_mc.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 3b5b54352b..3562acb2b2 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -40,6 +40,7 @@ AVCODECOBJS-$(CONFIG_V210_DECODER)  += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)  += v210enc.o
 AVCODECOBJS-$(CONFIG_VORBIS_DECODER)+= vorbisdsp.o
 AVCODECOBJS-$(CONFIG_VP9_DECODER)   += vp9dsp.o
+AVCODECOBJS-$(CONFIG_VVC_DECODER)   += vvc_mc.o
 
 CHECKASMOBJS-$(CONFIG_AVCODEC)  += $(AVCODECOBJS-yes)
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 87f24c77ca..36a97957e5 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -194,6 +194,9 @@ static const struct {
 #if CONFIG_VORBIS_DECODER
 { "vorbisdsp", checkasm_check_vorbisdsp },
 #endif
+#if CONFIG_VVC_DECODER
+{ "vvc_mc", checkasm_check_vvc_mc },
+#endif
 #endif
 #if CONFIG_AVFILTER
 #if CONFIG_AFIR_FILTER
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 4db8c495ea..53cb3ccfbf 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -131,6 +131,7 @@ void checkasm_check_vp8dsp(void);
 void checkasm_check_vp9dsp(void);
 void checkasm_check_videodsp(void);
 void checkasm_check_vorbisdsp(void);
+void checkasm_check_vvc_mc(void);
 
 struct CheckasmPerf;
 
diff --git a/tests/checkasm/vvc_mc.c b/tests/checkasm/vvc_mc.c
new file mode 100644
index 00..711280deec
--- /dev/null
+++ b/tests/checkasm/vvc_mc.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2023-2024 Nuo Mi
+ * Copyright (c) 2023-2024 Wu Jianhua
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "checkasm.h"
+#include "libavcodec/avcodec.h"
+#include "libavcodec/vvc/vvc_ctu.h"
+#include "libavcodec/vvc/vvc_data.h"
+
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
+
+static const uint32_t pixel_mask[] = { 0x, 0x03ff03ff, 0x0fff0fff, 
0x3fff3fff, 0x };
+static const int sizes[] = { 2, 4, 8, 16, 32, 64, 128 };
+
+#define PIXEL_STRIDE (MAX_CTU_SIZE * 2)
+#define EXTRA_BEFORE 3
+#define EXTRA_AFTER  4
+#define SRC_EXTRA(EXTRA_BEFORE + EXTRA_AFTER) * 2
+#define SRC_BUF_SIZE (PIXEL_STRIDE + SRC_EXTRA) * (PIXEL_STRIDE + SRC_EXTRA)
+#define DST_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE * 2)
+#define SRC_OFFSET   ((PIXEL_STRIDE + EXTRA_BEFORE * 2) * EXTRA_BEFORE)
+
+#define randomize_buffers(buf0, buf1, size, mask)   \
+do {\
+int k;  \
+for (k = 0; k < size; k += 4) { \
+uint32_t r = rnd() & mask;  \
+AV_WN32A(buf0 + k, r);  \
+AV_WN32A(buf1 + k, r);  \
+}   \
+} while (0)
+
+#define randomize_pixels(buf0, buf1, size)  \
+do {\
+uint32_t mask = pixel_mask[(bit_depth - 8) >> 1];   \
+randomize_buffers(buf0, buf1, size, mask);  \
+} while (0)
+
+#define randomize_avg_src(buf0, buf1, size) \
+do {\
+uint32_t mask = 0x3fff3fff; \
+randomize_buffers(buf0, buf1, size, mask);  \
+} while (0)
+
+static void check_put_vvc_luma(void)
+{
+LOCAL_ALIGNED_32(int16_t, dst0, [DST_BUF_SIZE / 2]);
+LOCAL_ALIGNED_32(int16_t, dst1, [DST_BUF_SIZE / 2]);
+LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
+VVCDSPContext c;
+
+declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, int16_t 
*dst, const uint8_t *src, const ptrdiff_t src_stride,
+  

[FFmpeg-devel] [PATCH v3 8/8] tests/checkasm/vvc_mc: add check_avg

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 tests/checkasm/vvc_mc.c | 64 +
 1 file changed, 64 insertions(+)

diff --git a/tests/checkasm/vvc_mc.c b/tests/checkasm/vvc_mc.c
index 711280deec..8adb00573f 100644
--- a/tests/checkasm/vvc_mc.c
+++ b/tests/checkasm/vvc_mc.c
@@ -35,6 +35,7 @@
 static const uint32_t pixel_mask[] = { 0x, 0x03ff03ff, 0x0fff0fff, 
0x3fff3fff, 0x };
 static const int sizes[] = { 2, 4, 8, 16, 32, 64, 128 };
 
+#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
 #define PIXEL_STRIDE (MAX_CTU_SIZE * 2)
 #define EXTRA_BEFORE 3
 #define EXTRA_AFTER  4
@@ -261,10 +262,73 @@ static void check_put_vvc_chroma_uni(void)
 report("put_uni_chroma");
 }
 
+#define AVG_SRC_BUF_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE)
+#define AVG_DST_BUF_SIZE (MAX_PB_SIZE * MAX_PB_SIZE * 2)
+
+static void check_avg(void)
+{
+LOCAL_ALIGNED_32(int16_t, src00, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int16_t, src01, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int16_t, src10, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(int16_t, src11, [AVG_SRC_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, dst0, [AVG_DST_BUF_SIZE]);
+LOCAL_ALIGNED_32(uint8_t, dst1, [AVG_DST_BUF_SIZE]);
+VVCDSPContext c;
+
+for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
+randomize_avg_src((uint8_t*)src00, (uint8_t*)src10, AVG_SRC_BUF_SIZE * 
sizeof(int16_t));
+randomize_avg_src((uint8_t*)src01, (uint8_t*)src11, AVG_SRC_BUF_SIZE * 
sizeof(int16_t));
+ff_vvc_dsp_init(&c, bit_depth);
+for (int h = 2; h <= MAX_CTU_SIZE; h *= 2) {
+for (int w = 2; w <= MAX_CTU_SIZE; w *= 2) {
+{
+   declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, 
void, uint8_t *dst, ptrdiff_t dst_stride,
+const int16_t *src0, const int16_t *src1, int width, 
int height);
+if (check_func(c.inter.avg, "avg_%d_%dx%d", bit_depth, w, 
h)) {
+memset(dst0, 0, AVG_DST_BUF_SIZE);
+memset(dst1, 0, AVG_DST_BUF_SIZE);
+call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, 
src01, w, h);
+call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, 
src11, w, h);
+if (memcmp(dst0, dst1, DST_BUF_SIZE))
+fail();
+if (w == h)
+bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, 
src00, src01, w, h);
+}
+}
+{
+declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, 
void, uint8_t *dst, ptrdiff_t dst_stride,
+const int16_t *src0, const int16_t *src1, int width, 
int height,
+int denom, int w0, int w1, int o0, int o1);
+{
+const int denom = rnd() % 8;
+const int w0= rnd() % 256 - 128;
+const int w1= rnd() % 256 - 128;
+const int o0= rnd() % 256 - 128;
+const int o1= rnd() % 256 - 128;
+if (check_func(c.inter.w_avg, "w_avg_%d_%dx%d", 
bit_depth, w, h)) {
+memset(dst0, 0, AVG_DST_BUF_SIZE);
+memset(dst1, 0, AVG_DST_BUF_SIZE);
+
+call_ref(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, src00, 
src01, w, h, denom, w0, w1, o0, o1);
+call_new(dst1, MAX_CTU_SIZE * SIZEOF_PIXEL, src10, 
src11, w, h, denom, w0, w1, o0, o1);
+if (memcmp(dst0, dst1, DST_BUF_SIZE))
+fail();
+if (w == h)
+bench_new(dst0, MAX_CTU_SIZE * SIZEOF_PIXEL, 
src00, src01, w, h, denom, w0, w1, o0, o1);
+}
+}
+}
+}
+}
+}
+report("avg");
+}
+
 void checkasm_check_vvc_mc(void)
 {
 check_put_vvc_luma();
 check_put_vvc_luma_uni();
 check_put_vvc_chroma();
 check_put_vvc_chroma_uni();
+check_avg();
 }
-- 
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 v3 7/8] avcodec/x86/vvc: add avg and avg_w AVX2 optimizations

2024-01-22 Thread toqsxw
From: Wu Jianhua 

The avg/avg_w is based on dav1d.
See https://code.videolan.org/videolan/dav1d/-/blob/master/src/x86/mc_avx2.asm

vvc_avg_8_2x2_c: 71.6
vvc_avg_8_2x2_avx2: 26.8
vvc_avg_8_2x4_c: 140.8
vvc_avg_8_2x4_avx2: 34.6
vvc_avg_8_2x8_c: 410.3
vvc_avg_8_2x8_avx2: 41.3
vvc_avg_8_2x16_c: 769.3
vvc_avg_8_2x16_avx2: 60.3
vvc_avg_8_2x32_c: 1669.6
vvc_avg_8_2x32_avx2: 105.1
vvc_avg_8_2x64_c: 1978.3
vvc_avg_8_2x64_avx2: 425.8
vvc_avg_8_2x128_c: 6536.8
vvc_avg_8_2x128_avx2: 1315.1
vvc_avg_8_4x2_c: 155.6
vvc_avg_8_4x2_avx2: 26.1
vvc_avg_8_4x4_c: 250.3
vvc_avg_8_4x4_avx2: 31.3
vvc_avg_8_4x8_c: 831.8
vvc_avg_8_4x8_avx2: 41.3
vvc_avg_8_4x16_c: 1461.1
vvc_avg_8_4x16_avx2: 57.1
vvc_avg_8_4x32_c: 2821.6
vvc_avg_8_4x32_avx2: 105.1
vvc_avg_8_4x64_c: 3615.8
vvc_avg_8_4x64_avx2: 412.6
vvc_avg_8_4x128_c: 11962.6
vvc_avg_8_4x128_avx2: 1274.3
vvc_avg_8_8x2_c: 215.8
vvc_avg_8_8x2_avx2: 29.1
vvc_avg_8_8x4_c: 430.6
vvc_avg_8_8x4_avx2: 37.6
vvc_avg_8_8x8_c: 1463.3
vvc_avg_8_8x8_avx2: 51.8
vvc_avg_8_8x16_c: 2630.1
vvc_avg_8_8x16_avx2: 97.6
vvc_avg_8_8x32_c: 5813.8
vvc_avg_8_8x32_avx2: 196.6
vvc_avg_8_8x64_c: 6687.3
vvc_avg_8_8x64_avx2: 487.8
vvc_avg_8_8x128_c: 13178.6
vvc_avg_8_8x128_avx2: 1290.6
vvc_avg_8_16x2_c: 443.8
vvc_avg_8_16x2_avx2: 28.3
vvc_avg_8_16x4_c: 1253.3
vvc_avg_8_16x4_avx2: 32.1
vvc_avg_8_16x8_c: 2236.3
vvc_avg_8_16x8_avx2: 44.3
vvc_avg_8_16x16_c: 5127.8
vvc_avg_8_16x16_avx2: 63.3
vvc_avg_8_16x32_c: 6573.3
vvc_avg_8_16x32_avx2: 223.6
vvc_avg_8_16x64_c: 30311.8
vvc_avg_8_16x64_avx2: 437.8
vvc_avg_8_16x128_c: 25693.3
vvc_avg_8_16x128_avx2: 1266.8
vvc_avg_8_32x2_c: 954.6
vvc_avg_8_32x2_avx2: 32.1
vvc_avg_8_32x4_c: 2359.6
vvc_avg_8_32x4_avx2: 39.6
vvc_avg_8_32x8_c: 5703.6
vvc_avg_8_32x8_avx2: 57.1
vvc_avg_8_32x16_c: 9967.6
vvc_avg_8_32x16_avx2: 107.1
vvc_avg_8_32x32_c: 21327.6
vvc_avg_8_32x32_avx2: 272.6
vvc_avg_8_32x64_c: 39240.8
vvc_avg_8_32x64_avx2: 529.6
vvc_avg_8_32x128_c: 52580.8
vvc_avg_8_32x128_avx2: 1338.8
vvc_avg_8_64x2_c: 1647.3
vvc_avg_8_64x2_avx2: 38.8
vvc_avg_8_64x4_c: 5130.1
vvc_avg_8_64x4_avx2: 58.8
vvc_avg_8_64x8_c: 6529.3
vvc_avg_8_64x8_avx2: 88.3
vvc_avg_8_64x16_c: 19913.6
vvc_avg_8_64x16_avx2: 162.3
vvc_avg_8_64x32_c: 39360.8
vvc_avg_8_64x32_avx2: 295.8
vvc_avg_8_64x64_c: 49658.3
vvc_avg_8_64x64_avx2: 784.1
vvc_avg_8_64x128_c: 108513.1
vvc_avg_8_64x128_avx2: 1977.1
vvc_avg_8_128x2_c: 3226.1
vvc_avg_8_128x2_avx2: 61.1
vvc_avg_8_128x4_c: 10280.3
vvc_avg_8_128x4_avx2: 94.6
vvc_avg_8_128x8_c: 18079.3
vvc_avg_8_128x8_avx2: 155.3
vvc_avg_8_128x16_c: 45121.8
vvc_avg_8_128x16_avx2: 285.3
vvc_avg_8_128x32_c: 48651.8
vvc_avg_8_128x32_avx2: 581.6
vvc_avg_8_128x64_c: 165078.6
vvc_avg_8_128x64_avx2: 1942.8
vvc_avg_8_128x128_c: 339103.1
vvc_avg_8_128x128_avx2: 4332.6
vvc_avg_10_2x2_c: 144.3
vvc_avg_10_2x2_avx2: 26.8
vvc_avg_10_2x4_c: 142.6
vvc_avg_10_2x4_avx2: 45.3
vvc_avg_10_2x8_c: 478.1
vvc_avg_10_2x8_avx2: 38.1
vvc_avg_10_2x16_c: 518.3
vvc_avg_10_2x16_avx2: 58.1
vvc_avg_10_2x32_c: 2059.8
vvc_avg_10_2x32_avx2: 93.1
vvc_avg_10_2x64_c: 2383.8
vvc_avg_10_2x64_avx2: 714.8
vvc_avg_10_2x128_c: 4498.3
vvc_avg_10_2x128_avx2: 1466.3
vvc_avg_10_4x2_c: 228.6
vvc_avg_10_4x2_avx2: 26.8
vvc_avg_10_4x4_c: 378.3
vvc_avg_10_4x4_avx2: 30.6
vvc_avg_10_4x8_c: 866.8
vvc_avg_10_4x8_avx2: 44.6
vvc_avg_10_4x16_c: 1018.1
vvc_avg_10_4x16_avx2: 58.1
vvc_avg_10_4x32_c: 3590.8
vvc_avg_10_4x32_avx2: 128.8
vvc_avg_10_4x64_c: 4200.8
vvc_avg_10_4x64_avx2: 663.6
vvc_avg_10_4x128_c: 8450.8
vvc_avg_10_4x128_avx2: 1531.8
vvc_avg_10_8x2_c: 369.3
vvc_avg_10_8x2_avx2: 28.3
vvc_avg_10_8x4_c: 513.8
vvc_avg_10_8x4_avx2: 32.1
vvc_avg_10_8x8_c: 1720.3
vvc_avg_10_8x8_avx2: 49.1
vvc_avg_10_8x16_c: 1894.8
vvc_avg_10_8x16_avx2: 71.6
vvc_avg_10_8x32_c: 3931.3
vvc_avg_10_8x32_avx2: 148.1
vvc_avg_10_8x64_c: 7964.3
vvc_avg_10_8x64_avx2: 613.1
vvc_avg_10_8x128_c: 15540.1
vvc_avg_10_8x128_avx2: 1585.1
vvc_avg_10_16x2_c: 877.3
vvc_avg_10_16x2_avx2: 27.6
vvc_avg_10_16x4_c: 955.8
vvc_avg_10_16x4_avx2: 29.8
vvc_avg_10_16x8_c: 3419.6
vvc_avg_10_16x8_avx2: 62.6
vvc_avg_10_16x16_c: 3826.8
vvc_avg_10_16x16_avx2: 54.3
vvc_avg_10_16x32_c: 7655.3
vvc_avg_10_16x32_avx2: 86.3
vvc_avg_10_16x64_c: 30011.1
vvc_avg_10_16x64_avx2: 692.6
vvc_avg_10_16x128_c: 47894.8
vvc_avg_10_16x128_avx2: 1580.3
vvc_avg_10_32x2_c: 944.3
vvc_avg_10_32x2_avx2: 29.8
vvc_avg_10_32x4_c: 2022.6
vvc_avg_10_32x4_avx2: 35.1
vvc_avg_10_32x8_c: 6148.8
vvc_avg_10_32x8_avx2: 51.3
vvc_avg_10_32x16_c: 12601.6
vvc_avg_10_32x16_avx2: 70.8
vvc_avg_10_32x32_c: 15958.6
vvc_avg_10_32x32_avx2: 124.3
vvc_avg_10_32x64_c: 31784.6
vvc_avg_10_32x64_avx2: 757.3
vvc_avg_10_32x128_c: 63892.8
vvc_avg_10_32x128_avx2: 1711.3
vvc_avg_10_64x2_c: 1890.8
vvc_avg_10_64x2_avx2: 34.3
vvc_avg_10_64x4_c: 6267.3
vvc_avg_10_64x4_avx2: 42.6
vvc_avg_10_64x8_c: 12778.1
vvc_avg_10_64x8_avx2: 67.8
vvc_avg_10_64x16_c: 22304.3
vvc_avg_10_64x16_avx2: 116.8
vvc_avg_10_64x32_c: 30777.1
vvc_avg_10_64x32_avx2: 201.1
vvc_avg_10_64x64_c: 60169.1
vvc_avg_10_64x64_avx2: 1454.3
vvc_avg_10_64x128_c: 124392.8
vvc_avg_10_64x128_avx2: 3648.6
vvc_avg_10_128x2

[FFmpeg-devel] [PATCH v3 5/8] avcodec/vvcdec: reuse h26x/2656_inter.asm to enable x86 optimizations

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/Makefile  |   1 +
 libavcodec/vvc/vvcdsp.c  |   4 +
 libavcodec/vvc/vvcdsp.h  |   2 +
 libavcodec/x86/vvc/Makefile  |   6 +
 libavcodec/x86/vvc/vvcdsp_init.c | 202 +++
 5 files changed, 215 insertions(+)
 create mode 100644 libavcodec/x86/vvc/Makefile
 create mode 100644 libavcodec/x86/vvc/vvcdsp_init.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..ce33631b60 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -65,6 +65,7 @@ OBJS = ac3_parser.o   
  \
 
 # subsystems
 include $(SRC_PATH)/libavcodec/vvc/Makefile
+include $(SRC_PATH)/libavcodec/x86/vvc/Makefile
 OBJS-$(CONFIG_AANDCTTABLES)+= aandcttab.o
 OBJS-$(CONFIG_AC3DSP)  += ac3dsp.o ac3.o ac3tab.o
 OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o 
mpeg4audio_sample_rates.o
diff --git a/libavcodec/vvc/vvcdsp.c b/libavcodec/vvc/vvcdsp.c
index c82ea7be30..c542be5258 100644
--- a/libavcodec/vvc/vvcdsp.c
+++ b/libavcodec/vvc/vvcdsp.c
@@ -138,4 +138,8 @@ void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
 VVC_DSP(8);
 break;
 }
+
+#if ARCH_X86
+ff_vvc_dsp_init_x86(vvcdsp, bit_depth);
+#endif
 }
diff --git a/libavcodec/vvc/vvcdsp.h b/libavcodec/vvc/vvcdsp.h
index b5a63c5833..6f59e73654 100644
--- a/libavcodec/vvc/vvcdsp.h
+++ b/libavcodec/vvc/vvcdsp.h
@@ -167,4 +167,6 @@ typedef struct VVCDSPContext {
 
 void ff_vvc_dsp_init(VVCDSPContext *hpc, int bit_depth);
 
+void ff_vvc_dsp_init_x86(VVCDSPContext *hpc, const int bit_depth);
+
 #endif /* AVCODEC_VVC_VVCDSP_H */
diff --git a/libavcodec/x86/vvc/Makefile b/libavcodec/x86/vvc/Makefile
new file mode 100644
index 00..b4acc22501
--- /dev/null
+++ b/libavcodec/x86/vvc/Makefile
@@ -0,0 +1,6 @@
+clean::
+   $(RM) $(CLEANSUFFIXES:%=libavcodec/x86/vvc/%)
+
+OBJS-$(CONFIG_VVC_DECODER) += x86/vvc/vvcdsp_init.o
+X86ASM-OBJS-$(CONFIG_VVC_DECODER)  += x86/h26x/h2656dsp.o   \
+   
  x86/h26x/h2656_inter.o
diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
new file mode 100644
index 00..c197cdb4cc
--- /dev/null
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -0,0 +1,202 @@
+/*
+ * VVC DSP init for x86
+ *
+ * Copyright (C) 2022-2024 Nuo Mi
+ * Copyright (c) 2023-2024 Wu Jianhua
+ *
+ * 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 "config.h"
+
+#include "libavutil/cpu.h"
+#include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
+#include "libavcodec/vvc/vvcdec.h"
+#include "libavcodec/vvc/vvc_ctu.h"
+#include "libavcodec/vvc/vvcdsp.h"
+#include "libavcodec/x86/h26x/h2656dsp.h"
+
+#define FW_PUT(name, depth, opt) \
+static void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const 
uint8_t *src, ptrdiff_t srcstride, \
+ int height, const int8_t *hf, 
const int8_t *vf, int width)\
+{  
\
+ff_h2656_put_## name ## _ ## depth ## _##opt(dst, 2 * MAX_PB_SIZE, src, 
srcstride, height, hf, vf, width); \
+}
+
+#define FW_PUT_TAP(fname, bitd, opt ) \
+FW_PUT(fname##4,   bitd, opt );   \
+FW_PUT(fname##8,   bitd, opt );   \
+FW_PUT(fname##16,  bitd, opt );   \
+FW_PUT(fname##32,  bitd, opt );   \
+FW_PUT(fname##64,  bitd, opt );   \
+FW_PUT(fname##128, bitd, opt );   \
+
+#define FW_PUT_4TAP(fname, bitd, opt) \
+FW_PUT(fname ## 2, bitd, opt) \
+FW_PUT_TAP(fname,  bitd, opt)
+
+#define FW_PUT_4TAP_SSE4(bitd)   \
+FW_PUT_4TAP(pixels,  bitd, sse4) \
+FW_PUT_4TAP(4tap_h,  bitd, sse4) \
+FW_PUT_4TAP(4tap_v,  bitd, sse4) \
+FW_PUT_4TAP(4tap_hv, bitd, sse4)
+
+#define FW_PUT_8TAP_SSE4(bitd)  \
+FW_PUT_TAP(8tap_h,  bitd, sse4) \
+FW_PUT_TAP(8tap_v,  bitd, sse4) \
+FW_PUT_TAP(8tap_hv, bitd, sse4)
+
+#define FW_PUT_SSE4(bitd)  \
+FW_PUT_4TAP_SSE4(bitd) \
+FW_PUT_8TAP_SSE4(bitd)
+
+FW_PUT_SSE4( 8);
+FW_PUT_SSE4(10);
+FW_PUT_SSE4(12);
+
+#define FW_PUT_T

[FFmpeg-devel] [PATCH v3 4/8] avcodec/x86/h26x/h2656_inter: add dststride to put

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/x86/h26x/h2656_inter.asm | 32 ++---
 libavcodec/x86/h26x/h2656dsp.c  |  4 ++--
 libavcodec/x86/h26x/h2656dsp.h  |  2 +-
 libavcodec/x86/hevcdsp_init.c   |  2 +-
 4 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/libavcodec/x86/h26x/h2656_inter.asm 
b/libavcodec/x86/h26x/h2656_inter.asm
index aa296d549c..cbba0c1ea5 100644
--- a/libavcodec/x86/h26x/h2656_inter.asm
+++ b/libavcodec/x86/h26x/h2656_inter.asm
@@ -22,8 +22,6 @@
 ; */
 %include "libavutil/x86/x86util.asm"
 
-%define MAX_PB_SIZE 64
-
 SECTION_RODATA 32
 cextern pw_255
 cextern pw_512
@@ -342,7 +340,7 @@ SECTION .text
 %endmacro
 
 %macro LOOP_END 3
-add  %1q, 2*MAX_PB_SIZE  ; dst += dststride
+add  %1q, dststrideq ; dst += dststride
 add  %2q, %3q; src += srcstride
 dec  heightd ; cmp height
 jnz   .loop  ; height loop
@@ -539,7 +537,7 @@ SECTION .text
 
 
 ; **
-; void %1_put_pixels(int16_t *dst, const uint8_t *_src, ptrdiff_t srcstride,
+; void %1_put_pixels(int16_t *dst, ptrdiff_t dststride, const uint8_t *_src, 
ptrdiff_t srcstride,
 ; int height, const int8_t *hf, const int8_t *vf, int 
width)
 ; **
 
@@ -549,7 +547,7 @@ SECTION .text
 %endmacro
 
 %macro MC_PIXELS 3
-cglobal %1_put_pixels%2_%3, 4, 4, 3, dst, src, srcstride, height
+cglobal %1_put_pixels%2_%3, 5, 5, 3, dst, dststride, src, srcstride, height
 pxor  m2, m2
 .loop:
 SIMPLE_LOAD   %2, %3, srcq, m0
@@ -579,10 +577,10 @@ cglobal %1_put_uni_pixels%2_%3, 5, 5, 2, dst, dststride, 
src, srcstride, height
 %endif
 
 ; **
-; void %1_put_4tap_hX(int16_t *dst,
+; void %1_put_4tap_hX(int16_t *dst, ptrdiff_t dststride,
 ;  const uint8_t *_src, ptrdiff_t _srcstride, int height, int8_t *hf, 
int8_t *vf, int width);
 ; **
-cglobal %1_put_4tap_h%2_%3, 5, 5, XMM_REGS, dst, src, srcstride, height, hf
+cglobal %1_put_4tap_h%2_%3, 6, 6, XMM_REGS, dst, dststride, src, srcstride, 
height, hf
 %assign %%stride ((%3 + 7)/8)
 MC_4TAP_FILTER   %3, hf, m4, m5
 .loop:
@@ -612,10 +610,10 @@ cglobal %1_put_uni_4tap_h%2_%3, 6, 7, XMM_REGS, dst, 
dststride, src, srcstride,
 RET
 
 ; **
-; void %1_put_4tap_v(int16_t *dst,
+; void %1_put_4tap_v(int16_t *dst, ptrdiff_t dststride,
 ;  const uint8_t *_src, ptrdiff_t _srcstride, int height, int8_t *hf, 
int8_t *vf, int width)
 ; **
-cglobal %1_put_4tap_v%2_%3, 6, 6, XMM_REGS, dst, src, srcstride, height, 
r3src, vf
+cglobal %1_put_4tap_v%2_%3, 7, 7, XMM_REGS, dst, dststride, src, srcstride, 
height, r3src, vf
 sub srcq, srcstrideq
 MC_4TAP_FILTER%3, vf, m4, m5
 lea   r3srcq, [srcstrideq*3]
@@ -649,10 +647,10 @@ cglobal %1_put_uni_4tap_v%2_%3, 7, 7, XMM_REGS, dst, 
dststride, src, srcstride,
 
 %macro PUT_4TAP_HV 3
 ; **
-; void put_4tap_hv(int16_t *dst,
+; void put_4tap_hv(int16_t *dst, ptrdiff_t dststride,
 ;  const uint8_t *_src, ptrdiff_t _srcstride, int height, int8_t *hf, 
int8_t *vf, int width)
 ; **
-cglobal %1_put_4tap_hv%2_%3, 6, 7, 16 , dst, src, srcstride, height, hf, vf, 
r3src
+cglobal %1_put_4tap_hv%2_%3, 7, 8, 16 , dst, dststride, src, srcstride, 
height, hf, vf, r3src
 %assign %%stride ((%3 + 7)/8)
 sub srcq, srcstrideq
 MC_4TAP_HV_FILTER%3
@@ -784,12 +782,12 @@ cglobal %1_put_uni_4tap_hv%2_%3, 7, 8, 16 , dst, 
dststride, src, srcstride, heig
 %endmacro
 
 ; **
-; void put_8tap_hX_X_X(int16_t *dst, const uint8_t *_src, ptrdiff_t srcstride,
+; void put_8tap_hX_X_X(int16_t *dst, ptrdiff_t dststride, const uint8_t *_src, 
ptrdiff_t srcstride,
 ;   int height, const int8_t *hf, const int8_t *vf, int 
width)
 ; **
 
 %macro PUT_8TAP 3
-cglobal %1_put_8tap_h%2_%3, 5, 5, 16, dst, src, srcstride, height, hf
+cglobal %1_put_8tap_h%2_%3, 6, 6, 16, dst, dststride, src, srcstride, height, 
hf
 MC_8TAP_FILTER  %3, hf
 .loop:
 MC_8TAP_H_LOAD  %3, srcq, %2, 10
@@ -824,10 +822,10 @@ cglobal %1_put_uni_8tap_h%2_%3, 6, 7, 16 , dst, 
dststride, src, srcstride, heigh
 
 
 ; **
-; void put_8tap_vX_X_X(int16_t *dst, const uint8_t *_src, ptrdiff_t srcstride,
+; void put_8tap_vX_X_X(int16_t *dst, ptrdiff_t dststride, const uint8_t *_src, 
ptrdiff_t srcstride,
 ;  int height, const int8_t *hf, const int8_t *vf, int 
width)
 ; **
-cglobal %1_put_8tap_v%2_%3, 6, 8, 16, dst, src, srcstride, height, r3src, vf
+cglobal %1_put_8tap_v%2_%3, 7, 8, 16, dst, dststride, src, srcstride, height, 

[FFmpeg-devel] [PATCH v3 3/8] avcodec/x86/hevc_mc: move put/put_uni to h26x/h2656_inter.asm

2024-01-22 Thread toqsxw
From: Wu Jianhua 

This enable that the asm optimization can be reused by VVC

Signed-off-by: Wu Jianhua 
---
 libavcodec/x86/Makefile |1 +
 libavcodec/x86/h26x/h2656_inter.asm | 1145 +++
 libavcodec/x86/h26x/h2656dsp.c  |   98 +++
 libavcodec/x86/h26x/h2656dsp.h  |  103 +++
 libavcodec/x86/hevc_mc.asm  |  462 +--
 libavcodec/x86/hevcdsp_init.c   |  108 ++-
 6 files changed, 1471 insertions(+), 446 deletions(-)
 create mode 100644 libavcodec/x86/h26x/h2656_inter.asm
 create mode 100644 libavcodec/x86/h26x/h2656dsp.c
 create mode 100644 libavcodec/x86/h26x/h2656dsp.h

diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index d5fb30645a..8098cd840c 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -167,6 +167,7 @@ X86ASM-OBJS-$(CONFIG_HEVC_DECODER) += 
x86/hevc_add_res.o\
   x86/hevc_deblock.o\
   x86/hevc_idct.o   \
   x86/hevc_mc.o \
+  x86/h26x/h2656_inter.o\
   x86/hevc_sao.o\
   x86/hevc_sao_10bit.o
 X86ASM-OBJS-$(CONFIG_JPEG2000_DECODER) += x86/jpeg2000dsp.o
diff --git a/libavcodec/x86/h26x/h2656_inter.asm 
b/libavcodec/x86/h26x/h2656_inter.asm
new file mode 100644
index 00..aa296d549c
--- /dev/null
+++ b/libavcodec/x86/h26x/h2656_inter.asm
@@ -0,0 +1,1145 @@
+; /*
+; * Provide SSE luma and chroma mc functions for HEVC/VVC decoding
+; * Copyright (c) 2013 Pierre-Edouard LEPERE
+; * Copyright (c) 2023-2024 Nuo Mi
+; * Copyright (c) 2023-2024 Wu Jianhua
+; *
+; * This file is part of FFmpeg.
+; *
+; * FFmpeg is free software; you can redistribute it and/or
+; * modify it under the terms of the GNU Lesser General Public
+; * License as published by the Free Software Foundation; either
+; * version 2.1 of the License, or (at your option) any later version.
+; *
+; * FFmpeg is distributed in the hope that it will be useful,
+; * but WITHOUT ANY WARRANTY; without even the implied warranty of
+; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+; * Lesser General Public License for more details.
+; *
+; * You should have received a copy of the GNU Lesser General Public
+; * License along with FFmpeg; if not, write to the Free Software
+; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+; */
+%include "libavutil/x86/x86util.asm"
+
+%define MAX_PB_SIZE 64
+
+SECTION_RODATA 32
+cextern pw_255
+cextern pw_512
+cextern pw_2048
+cextern pw_1023
+cextern pw_1024
+cextern pw_4096
+cextern pw_8192
+%define scale_8 pw_512
+%define scale_10 pw_2048
+%define scale_12 pw_8192
+%define max_pixels_8 pw_255
+%define max_pixels_10 pw_1023
+max_pixels_12:  times 16 dw ((1 << 12)-1)
+cextern pb_0
+
+SECTION .text
+%macro SIMPLE_LOAD 4;width, bitd, tab, r1
+%if %1 == 2 || (%2 == 8 && %1 <= 4)
+movd  %4, [%3]   ; 
load data from source
+%elif %1 == 4 || (%2 == 8 && %1 <= 8)
+movq  %4, [%3]   ; 
load data from source
+%elif notcpuflag(avx)
+movu  %4, [%3]   ; 
load data from source
+%elif %1 <= 8 || (%2 == 8 && %1 <= 16)
+movdqu   %4, [%3]
+%else
+movu  %4, [%3]
+%endif
+%endmacro
+
+%macro VPBROADCASTW 2
+%if notcpuflag(avx2)
+movd   %1, %2
+pshuflw%1, %1, 0
+punpcklwd  %1, %1
+%else
+vpbroadcastw   %1, %2
+%endif
+%endmacro
+
+%macro MC_4TAP_FILTER 4 ; bitdepth, filter, a, b,
+VPBROADCASTW   %3, [%2q + 0 * 2]  ; coeff 0, 1
+VPBROADCASTW   %4, [%2q + 1 * 2]  ; coeff 2, 3
+%if %1 != 8
+pmovsxbw   %3, xmm%3
+pmovsxbw   %4, xmm%4
+%endif
+%endmacro
+
+%macro MC_4TAP_HV_FILTER 1
+VPBROADCASTW  m12, [vfq + 0 * 2]  ; vf 0, 1
+VPBROADCASTW  m13, [vfq + 1 * 2]  ; vf 2, 3
+VPBROADCASTW  m14, [hfq + 0 * 2]  ; hf 0, 1
+VPBROADCASTW  m15, [hfq + 1 * 2]  ; hf 2, 3
+
+pmovsxbw  m12, xm12
+pmovsxbw  m13, xm13
+%if %1 != 8
+pmovsxbw  m14, xm14
+pmovsxbw  m15, xm15
+%endif
+lea   r3srcq, [srcstrideq*3]
+%endmacro
+
+%macro MC_8TAP_SAVE_FILTER 5;offset, mm registers
+mova [rsp + %1 + 0*mmsize], %2
+mova [rsp + %1 + 1*mmsize], %3
+mova [rsp + %1 + 2*mmsize], %4
+mova [rsp + %1 + 3*mmsize], %5
+%endmacro
+
+%macro MC_8TAP_FILTER 2-3 ;bitdepth, filter, offset
+VPBROADCASTW  m12, [%2q + 0 * 2]  ; coeff 0, 1
+VPBROADCASTW  m13, [%2q + 1 * 2]  ; coeff 2, 3
+VPBROADCASTW  m14, [%2q + 2 * 2]  ; coeff 4, 5
+VPBROADCASTW  m15, [%2q + 3 * 2] 

[FFmpeg-devel] [PATCH v3 2/8] avcodec/hevcdsp_template: reuse put/put_luma/put_chroma from h2656_inter_template

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/hevcdsp_template.c | 594 +++---
 1 file changed, 46 insertions(+), 548 deletions(-)

diff --git a/libavcodec/hevcdsp_template.c b/libavcodec/hevcdsp_template.c
index 0de14e9dcf..9b48bdf08e 100644
--- a/libavcodec/hevcdsp_template.c
+++ b/libavcodec/hevcdsp_template.c
@@ -26,6 +26,7 @@
 #include "bit_depth_template.c"
 #include "hevcdsp.h"
 #include "h26x/h2656_sao_template.c"
+#include "h26x/h2656_inter_template.c"
 
 static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int 
height,
   GetBitContext *gb, int pcm_bit_depth)
@@ -299,37 +300,51 @@ IDCT_DC(32)
 

 //
 

-static void FUNC(put_hevc_pel_pixels)(int16_t *dst,
-  const uint8_t *_src, ptrdiff_t 
_srcstride,
-  int height, intptr_t mx, intptr_t my, 
int width)
-{
-int x, y;
-const pixel *src= (const pixel *)_src;
-ptrdiff_t srcstride = _srcstride / sizeof(pixel);
-
-for (y = 0; y < height; y++) {
-for (x = 0; x < width; x++)
-dst[x] = src[x] << (14 - BIT_DEPTH);
-src += srcstride;
-dst += MAX_PB_SIZE;
-}
-}
-
-static void FUNC(put_hevc_pel_uni_pixels)(uint8_t *_dst, ptrdiff_t _dststride, 
const uint8_t *_src, ptrdiff_t _srcstride,
-  int height, intptr_t mx, intptr_t 
my, int width)
-{
-int y;
-const pixel *src= (const pixel *)_src;
-ptrdiff_t srcstride = _srcstride / sizeof(pixel);
-pixel *dst  = (pixel *)_dst;
-ptrdiff_t dststride = _dststride / sizeof(pixel);
-
-for (y = 0; y < height; y++) {
-memcpy(dst, src, width * sizeof(pixel));
-src += srcstride;
-dst += dststride;
-}
-}
+#define ff_hevc_pel_filters ff_hevc_qpel_filters
+#define DECL_HV_FILTER(f)  \
+const uint8_t *hf = ff_hevc_ ## f ## _filters[mx - 1]; \
+const uint8_t *vf = ff_hevc_ ## f ## _filters[my - 1];
+
+#define FW_PUT(p, f, t)
   \
+static void FUNC(put_hevc_## f)(int16_t *dst, const uint8_t *src, ptrdiff_t 
srcstride, int height,\
+  intptr_t mx, intptr_t my, int width) 
   \
+{  
   \
+DECL_HV_FILTER(p)  
   \
+FUNC(put_ ## t)(dst, src, srcstride, height, hf, vf, width);   
   \
+}
+
+#define FW_PUT_UNI(p, f, t)
   \
+static void FUNC(put_hevc_ ## f)(uint8_t *dst, ptrdiff_t dststride, const 
uint8_t *src,   \
+  ptrdiff_t srcstride, int height, intptr_t 
mx, intptr_t my, int width)   \
+{  
   \
+DECL_HV_FILTER(p)  
   \
+FUNC(put_ ## t)(dst, dststride, src, srcstride, height, hf, vf, width);
   \
+}
+
+#define FW_PUT_UNI_W(p, f, t)  
   \
+static void FUNC(put_hevc_ ## f)(uint8_t *dst, ptrdiff_t dststride, const 
uint8_t *src,   \
+  ptrdiff_t srcstride,int height, int denom, 
int wx, int ox,  \
+  intptr_t mx, intptr_t my, int width) 
   \
+{  
   \
+DECL_HV_FILTER(p)  
   \
+FUNC(put_ ## t)(dst, dststride, src, srcstride, height, denom, wx, ox, hf, 
vf, width);\
+}
+
+#define FW_PUT_FUNCS(f, t, dir)   \
+FW_PUT(f, f ## _ ## dir, t ## _ ## dir) \
+FW_PUT_UNI(f, f ## _uni_ ## dir, uni_ ## t ## _ ## dir)\
+FW_PUT_UNI_W(f, f ## _uni_w_ ## dir, uni_## t ## _w_ ## dir)
+
+FW_PUT(pel, pel_pixels, pixels)
+FW_PUT_UNI(pel, pel_uni_pixels, uni_pixels)
+FW_PUT_UNI_W(pel, pel_uni_w_pixels, uni_w_pixels)
+
+FW_PUT_FUNCS(qpel, luma,   h )
+FW_PUT_FUNCS(qpel, luma,   v )
+FW_PUT_FUNCS(qpel, luma,   hv)
+FW_PUT_FUNCS(epel, chroma, h )
+FW_PUT_FUNCS(epel, chroma, v )
+FW_PUT_FUNCS(epel, chroma, hv)
 
 static void FUNC(put_hevc_pel_bi_pixels)(uint8_t *_

[FFmpeg-devel] [PATCH v3 1/8] avcodec/vvc/vvc_inter_template: move put/put_luma/put_chroma template to h2656_inter_template.c

2024-01-22 Thread toqsxw
From: Wu Jianhua 

Signed-off-by: Wu Jianhua 
---
 libavcodec/h26x/h2656_inter_template.c | 577 +
 libavcodec/vvc/vvc_inter_template.c| 559 +---
 2 files changed, 578 insertions(+), 558 deletions(-)
 create mode 100644 libavcodec/h26x/h2656_inter_template.c

diff --git a/libavcodec/h26x/h2656_inter_template.c 
b/libavcodec/h26x/h2656_inter_template.c
new file mode 100644
index 00..864f6c7e7d
--- /dev/null
+++ b/libavcodec/h26x/h2656_inter_template.c
@@ -0,0 +1,577 @@
+/*
+ * inter prediction template for HEVC/VVC
+ *
+ * Copyright (C) 2022 Nuo Mi
+ * Copyright (C) 2024 Wu Jianhua
+ *
+ * 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
+ */
+
+#define CHROMA_EXTRA_BEFORE 1
+#define CHROMA_EXTRA3
+#define LUMA_EXTRA_BEFORE   3
+#define LUMA_EXTRA  7
+
+static void FUNC(put_pixels)(int16_t *dst,
+const uint8_t *_src, const ptrdiff_t _src_stride,
+const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+const pixel *src= (const pixel *)_src;
+const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
+
+for (int y = 0; y < height; y++) {
+for (int x = 0; x < width; x++)
+dst[x] = src[x] << (14 - BIT_DEPTH);
+src += src_stride;
+dst += MAX_PB_SIZE;
+}
+}
+
+static void FUNC(put_uni_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+ const int8_t *hf, const int8_t *vf, const int width)
+{
+const pixel *src= (const pixel *)_src;
+pixel *dst  = (pixel *)_dst;
+const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
+const ptrdiff_t dst_stride  = _dst_stride / sizeof(pixel);
+
+for (int y = 0; y < height; y++) {
+memcpy(dst, src, width * sizeof(pixel));
+src += src_stride;
+dst += dst_stride;
+}
+}
+
+static void FUNC(put_uni_w_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+const int denom, const int wx, const int _ox,  const int8_t *hf, const 
int8_t *vf,
+const int width)
+{
+const pixel *src= (const pixel *)_src;
+pixel *dst  = (pixel *)_dst;
+const ptrdiff_t src_stride  = _src_stride / sizeof(pixel);
+const ptrdiff_t dst_stride  = _dst_stride / sizeof(pixel);
+const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+const int offset= 1 << (shift - 1);
+#else
+const int offset= 0;
+#endif
+const int ox= _ox * (1 << (BIT_DEPTH - 8));
+
+for (int y = 0; y < height; y++) {
+for (int x = 0; x < width; x++) {
+const int v = (src[x] << (14 - BIT_DEPTH));
+dst[x] = av_clip_pixel(((v * wx + offset) >> shift) + ox);
+}
+src += src_stride;
+dst += dst_stride;
+}
+}
+
+#define LUMA_FILTER(src, stride)   
\
+(filter[0] * src[x - 3 * stride] + 
\
+ filter[1] * src[x - 2 * stride] + 
\
+ filter[2] * src[x - stride] + 
\
+ filter[3] * src[x ] + 
\
+ filter[4] * src[x + stride] + 
\
+ filter[5] * src[x + 2 * stride] + 
\
+ filter[6] * src[x + 3 * stride] + 
\
+ filter[7] * src[x + 4 * stride])
+
+static void FUNC(put_luma_h)(int16_t *dst, const uint8_t *_src, const 
ptrdiff_t _src_stride,
+const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+const pixel *src   = (const pixel*)_src;
+const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+const int8_t *filter   = hf;
+
+for (int y = 0; y < height; y++) {
+for (int x = 0; x < width; x++)
+dst[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+src += src_stride;
+dst += MAX_PB_SIZE;
+}
+}
+
+static void FUNC(put_luma_v)(int

Re: [FFmpeg-devel] [PATCH] configure: autodetect libglslang ldflags

2024-01-22 Thread Matthew White via ffmpeg-devel
> Also, how does this work when cross compiling - won't the "glslang" binary 
> be for the foreign cross target? Or is it something like the sdl-config 
> script which is a local shell script that can give relevant build flags (a 
> design preceding pkg-config)?

I don't have an answer to that, in FFmpeg's configure I saw using something like
`[ -x "$(command -v gzip)" ] && enable gzip`, so I replicated it to check on the
glslang's binary.  I guess that who is ready to cross compile may try this patch
with glslang installed to tell what's happening.

I worked on this fix in GNU/Linux Gentoo.  Trying both glslang 14.0.0 and 13.1.1
only the latter requires "-lOSDependent -lHLSL -lOGLCompiler".  I configured the
compilation with `./configure --enable-libglslang`, the stub flags/libraries are
not required for glslang 14.0.0.  I can compile FFmpeg 6.1.1 by backporting this
patch.

This patch may be dropped altogether by locking FFmpeg on glslang 14.0.0 and up,
and removing the stub "-lOSDependent -lHLSL -lOGLCompiler" flags/libraries.
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Tomas Härdin
mån 2024-01-22 klockan 15:59 +0200 skrev Martin Storsjö:
> On Mon, 22 Jan 2024, Tomas Härdin wrote:
> 
> > > > > > >  -    if (frame->quality)
> > > > > -    enc->lambda = frame->quality - 1;
> > > > > -    else
> > > > > -    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > +    if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > > > > +    /* no specific bit rate desired, use frame quality
> > > > > */
> > > > > +    if (frame->quality)
> > > > > +    enc->lambda = frame->quality - 1;
> > > > > +    else
> > > > > +    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > > > +    }
> > > > 
> > > > This looks like a bit of a janky way to switch between qscale
> > > > and
> > > > bitrate. Isn't there a way to detect whether an option has been
> > > > set
> > > > explicitly? At the very least this behavior should be
> > > > documented in
> > > > doc/encoders.texi
> > > > 
> > > 
> > > Originally, the code just checked for bit_rate !=
> > > AV_CODEC_DEFAULT_BITRATE,
> > > which required including options_table.h, which in turn produced
> > > a
> > > bunch
> > > of compilation warnings about certain fields being deprecated.
> > > None
> > > of the
> > > other codecs include that file + many simply check the bit_rate
> > > field
> > > against
> > > magic constants.
> > 
> > grepping for 20 didn't reveal anything like that. Do you have a
> > specific example of an encoder that does this?
> > 
> > Perhaps we could move AV_CODEC_DEFAULT_BITRATE somewhere else, to
> > avoid
> > pulling in a bunch of unrelated stuff. Maybe that doesn't need to
> > hold
> > up this patch though. Tbh the way bitrate is defaulted to a value,
> > which makes it impossible to differentiate between a user-supplied
> > -b
> > 200k an no -b at all, is even more janky. The default is also
> > ridiculously low..
> > 
> > I know some encoders like libvpx allow specifying both quality (-
> > crf)
> > and bitrate at the same time
> 
> FWIW, it's possible for an encoder to individually override the
> defaults 
> for fields like these. See e.g. x264_defaults in libx264.c, where it 
> overrides the default bitrate to zero.

Ooh, didn't know that. That sounds like a decent solution here. Can RoQ
really not do < 800 kbps at all or is it just that it looks bad with
say 256x256 but perhaps more decent with 128x128 or so?

/Tomas
___
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] configure: autodetect libglslang ldflags

2024-01-22 Thread Matthew White via ffmpeg-devel
As far as I can tell, there're no pkg-config features in
https://github.com/KhronosGroup/glslang installation, at
least by installing it on my system, GNU/Linux Gentoo.
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Martin Storsjö

On Mon, 22 Jan 2024, Tomas Härdin wrote:


>>>  -    if (frame->quality)

> > -    enc->lambda = frame->quality - 1;
> > -    else
> > -    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > +    if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > +    /* no specific bit rate desired, use frame quality */
> > +    if (frame->quality)
> > +    enc->lambda = frame->quality - 1;
> > +    else
> > +    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > +    }
> 
> This looks like a bit of a janky way to switch between qscale and

> bitrate. Isn't there a way to detect whether an option has been set
> explicitly? At the very least this behavior should be documented in
> doc/encoders.texi
> 


Originally, the code just checked for bit_rate !=
AV_CODEC_DEFAULT_BITRATE,
which required including options_table.h, which in turn produced a
bunch
of compilation warnings about certain fields being deprecated. None
of the
other codecs include that file + many simply check the bit_rate field
against
magic constants.


grepping for 20 didn't reveal anything like that. Do you have a
specific example of an encoder that does this?

Perhaps we could move AV_CODEC_DEFAULT_BITRATE somewhere else, to avoid
pulling in a bunch of unrelated stuff. Maybe that doesn't need to hold
up this patch though. Tbh the way bitrate is defaulted to a value,
which makes it impossible to differentiate between a user-supplied -b
200k an no -b at all, is even more janky. The default is also
ridiculously low..

I know some encoders like libvpx allow specifying both quality (-crf)
and bitrate at the same time


FWIW, it's possible for an encoder to individually override the defaults 
for fields like these. See e.g. x264_defaults in libx264.c, where it 
overrides the default bitrate to zero.


// Martin
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Tomas Härdin
> > 
> > >  -    if (frame->quality)
> > > -    enc->lambda = frame->quality - 1;
> > > -    else
> > > -    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > +    if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > > +    /* no specific bit rate desired, use frame quality */
> > > +    if (frame->quality)
> > > +    enc->lambda = frame->quality - 1;
> > > +    else
> > > +    enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > > +    }
> > 
> > This looks like a bit of a janky way to switch between qscale and
> > bitrate. Isn't there a way to detect whether an option has been set
> > explicitly? At the very least this behavior should be documented in
> > doc/encoders.texi
> > 
> 
> Originally, the code just checked for bit_rate !=
> AV_CODEC_DEFAULT_BITRATE,
> which required including options_table.h, which in turn produced a
> bunch
> of compilation warnings about certain fields being deprecated. None
> of the
> other codecs include that file + many simply check the bit_rate field
> against
> magic constants.

grepping for 20 didn't reveal anything like that. Do you have a
specific example of an encoder that does this?

Perhaps we could move AV_CODEC_DEFAULT_BITRATE somewhere else, to avoid
pulling in a bunch of unrelated stuff. Maybe that doesn't need to hold
up this patch though. Tbh the way bitrate is defaulted to a value,
which makes it impossible to differentiate between a user-supplied -b
200k an no -b at all, is even more janky. The default is also
ridiculously low..

I know some encoders like libvpx allow specifying both quality (-crf)
and bitrate at the same time

/Tomas
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Victor Luchitz
On Mon, Jan 22, 2024 at 4:06 PM Tomas Härdin  wrote:

> mån 2024-01-22 klockan 00:08 +0300 skrev Victor Luchits:
> > One can now use the bitrate option (-b) to specify bit rate of the
> > video
> > stream in the RoQ encoder. The option only becomes effective for
> > values
> > above 800kbit/s, which is roughly equivalent to bandwidth of a 1x-
> > speed
> > CD-ROM drive, minus the bandwidth taken up by stereo DPCM stream.
> > Values
> > below this threshold produce visually inadequate results.
> >
> > Original patch by Joseph Fenton aka Chilly Willy
> >
> > Signed-off-by: Victor Luchits 
> > ---
> >   Changelog|   1 +
> >   libavcodec/roqvideo.h|   1 +
> >   libavcodec/roqvideodec.c |  15 +
> >   libavcodec/roqvideoenc.c | 118 ++--
> > ---
> >   libavcodec/version.h |   2 +-
> >   5 files changed, 123 insertions(+), 14 deletions(-)
>
> Fails to apply with git am on current master
>
> > warning: Patch sent with format=flowed; space at the end of lines
> > might be lost.
> > Applying: liavcodec: add bit-rate support to RoQ video encoder
> > error: corrupt patch at line 20
> > Patch failed at 0001 liavcodec: add bit-rate support to RoQ video
> > encoder
>
> Typo: liavcodec
>
> > +/* Keyframe when no MOT or FCC codes in frame */
> > +if (s->key_frame) {
> > +av_log(avctx, AV_LOG_VERBOSE, "\nFound keyframe!\n");
> > +rframe->pict_type = AV_PICTURE_TYPE_I;
> > +avpkt->flags |= AV_PKT_FLAG_KEY;
>
> Consider resetting framesSinceKeyframe here
>

Thanks, good catch, gonna look into that.


>
> >  -if (avctx->width > 65535 || avctx->height > 65535) {
>
> The leading space is probably what makes the patch not apply
>

Found it, thanks.


>
> > -av_log(avctx, AV_LOG_ERROR, "Dimensions are max %d\n", enc-
> > >quake3_compat ? 32768 : 65535);
> > +if (enc->quake3_compat && ((avctx->width > 32767 || avctx-
> > >height > 32767))) {
> > +av_log(avctx, AV_LOG_ERROR, "Dimensions are max %d\n",
> > 32767);
> > +return AVERROR(EINVAL);
> > +}
> > +else if (avctx->width > 65535 || avctx->height > 65535) {
> > +av_log(avctx, AV_LOG_ERROR, "Dimensions are max %d\n",
> > 65535);
> >  return AVERROR(EINVAL);
> >  }
> >  -if (((avctx->width)&(avctx->width-1))||((avctx->height)&(avctx-
> > >height-1)))
> > +if (enc->quake3_compat && ((avctx->width)&(avctx->width-
> > 1))||((avctx->height)&(avctx->height-1)))
> >  av_log(avctx, AV_LOG_ERROR, "Warning: dimensions not power
> > of two, this is not supported by quake\n");
>
> These changes appear to be unrelated to bitrate. Consider separating
> them into a separate patch.
>

Noted.


>
> >  -if (frame->quality)
> > -enc->lambda = frame->quality - 1;
> > -else
> > -enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > +if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> > +/* no specific bit rate desired, use frame quality */
> > +if (frame->quality)
> > +enc->lambda = frame->quality - 1;
> > +else
> > +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> > +}
>
> This looks like a bit of a janky way to switch between qscale and
> bitrate. Isn't there a way to detect whether an option has been set
> explicitly? At the very least this behavior should be documented in
> doc/encoders.texi
>

Originally, the code just checked for bit_rate != AV_CODEC_DEFAULT_BITRATE,
which required including options_table.h, which in turn produced a bunch
of compilation warnings about certain fields being deprecated. None of the
other codecs include that file + many simply check the bit_rate field
against
magic constants. That made me assume that including options_table.h
goes against the common practice.


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


-- 
Best regards,
 Victor Luchitz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 2/3] doc/muxers: add codec2

2024-01-22 Thread Tomas Härdin
tis 2024-01-16 klockan 00:57 +0100 skrev Stefano Sabatini:
> ---
>  doc/muxers.texi | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 1bdd7d34d5..eadcba690c 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -882,6 +882,11 @@ Apple CAF (Core Audio Format) muxer.
>  
>  It accepts a single audio stream.
>  
> +@section codec2
> +Codec2 audio audio muxer.
> +
> +It accepts a single codec2 audio stream.

Looks fine. It's a very simple format after all. Also I should get my
codec2 patchset through..

/Tomas
___
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] liavcodec: add bit-rate support to RoQ video encoder

2024-01-22 Thread Tomas Härdin
mån 2024-01-22 klockan 00:08 +0300 skrev Victor Luchits:
> One can now use the bitrate option (-b) to specify bit rate of the
> video
> stream in the RoQ encoder. The option only becomes effective for
> values
> above 800kbit/s, which is roughly equivalent to bandwidth of a 1x-
> speed
> CD-ROM drive, minus the bandwidth taken up by stereo DPCM stream.
> Values
> below this threshold produce visually inadequate results.
> 
> Original patch by Joseph Fenton aka Chilly Willy
> 
> Signed-off-by: Victor Luchits 
> ---
>   Changelog    |   1 +
>   libavcodec/roqvideo.h    |   1 +
>   libavcodec/roqvideodec.c |  15 +
>   libavcodec/roqvideoenc.c | 118 ++--
> ---
>   libavcodec/version.h |   2 +-
>   5 files changed, 123 insertions(+), 14 deletions(-)

Fails to apply with git am on current master

> warning: Patch sent with format=flowed; space at the end of lines
> might be lost.
> Applying: liavcodec: add bit-rate support to RoQ video encoder
> error: corrupt patch at line 20
> Patch failed at 0001 liavcodec: add bit-rate support to RoQ video
> encoder

Typo: liavcodec

> +/* Keyframe when no MOT or FCC codes in frame */
> +if (s->key_frame) {
> +av_log(avctx, AV_LOG_VERBOSE, "\nFound keyframe!\n");
> +rframe->pict_type = AV_PICTURE_TYPE_I;
> +avpkt->flags |= AV_PKT_FLAG_KEY;

Consider resetting framesSinceKeyframe here

>  -if (avctx->width > 65535 || avctx->height > 65535) {

The leading space is probably what makes the patch not apply

> -av_log(avctx, AV_LOG_ERROR, "Dimensions are max %d\n", enc-
> >quake3_compat ? 32768 : 65535);
> +if (enc->quake3_compat && ((avctx->width > 32767 || avctx-
> >height > 32767))) {
> +av_log(avctx, AV_LOG_ERROR, "Dimensions are max %d\n",
> 32767);
> +return AVERROR(EINVAL);
> +}
> +else if (avctx->width > 65535 || avctx->height > 65535) {
> +av_log(avctx, AV_LOG_ERROR, "Dimensions are max %d\n",
> 65535);
>  return AVERROR(EINVAL);
>  }
>  -if (((avctx->width)&(avctx->width-1))||((avctx->height)&(avctx-
> >height-1)))
> +if (enc->quake3_compat && ((avctx->width)&(avctx->width-
> 1))||((avctx->height)&(avctx->height-1)))
>  av_log(avctx, AV_LOG_ERROR, "Warning: dimensions not power
> of two, this is not supported by quake\n");

These changes appear to be unrelated to bitrate. Consider separating
them into a separate patch.

>  -if (frame->quality)
> -enc->lambda = frame->quality - 1;
> -else
> -enc->lambda = 2*ROQ_LAMBDA_SCALE;
> +if (avctx->bit_rate <= ROQ_DEFAULT_MIN_BIT_RATE) {
> +/* no specific bit rate desired, use frame quality */
> +if (frame->quality)
> +enc->lambda = frame->quality - 1;
> +else
> +enc->lambda = 2*ROQ_LAMBDA_SCALE;
> +}

This looks like a bit of a janky way to switch between qscale and
bitrate. Isn't there a way to detect whether an option has been set
explicitly? At the very least this behavior should be documented in
doc/encoders.texi

/Tomas
___
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 v1 2/2] vaapi: add vaapi_avs2 support

2024-01-22 Thread Jianfeng Zheng
Zhao Zhili  于2024年1月22日周一 20:02写道:
>
>
>
> > On Jan 22, 2024, at 08:06, Liu Steven  wrote:
> >
> >
> >
> >> On Jan 21, 2024, at 22:47, Jianfeng Zheng  wrote:
> >>
> >> Zhao Zhili  于2024年1月20日周六 12:22写道:
> >>>
> >>>
>  -Original Message-
>  From: ffmpeg-devel  On Behalf Of 
>  jianfeng.zheng
>  Sent: 2024年1月19日 23:53
>  To: ffmpeg-devel@ffmpeg.org
>  Cc: jianfeng.zheng 
>  Subject: [FFmpeg-devel] [PATCH v1 2/2] vaapi: add vaapi_avs2 support
> 
>  see https://github.com/intel/libva/pull/738
> 
>  [Moore Threads](https://www.mthreads.com) (short for Mthreads) is a
>  Chinese GPU manufacturer. All our products, like MTTS70/MTTS80/.. ,
>  support AVS2 8bit/10bit HW decoding at max 8k resolution.
> 
>  Signed-off-by: jianfeng.zheng 
>  ---
>  configure|   7 +
>  libavcodec/Makefile  |   2 +
>  libavcodec/allcodecs.c   |   1 +
>  libavcodec/avs2.c| 345 ++-
>  libavcodec/avs2.h| 460 +++-
>  libavcodec/avs2_parser.c |   5 +-
>  libavcodec/avs2dec.c | 569 +
>  libavcodec/avs2dec.h |  48 +++
>  libavcodec/avs2dec_headers.c | 787 +++
>  libavcodec/codec_desc.c  |   5 +-
>  libavcodec/defs.h|   4 +
>  libavcodec/hwaccels.h|   1 +
>  libavcodec/libdavs2.c|   2 +-
>  libavcodec/profiles.c|   6 +
>  libavcodec/profiles.h|   1 +
>  libavcodec/vaapi_avs2.c  | 227 ++
>  libavcodec/vaapi_decode.c|   5 +
>  libavformat/matroska.c   |   1 +
>  libavformat/mpeg.h   |   1 +
>  19 files changed, 2450 insertions(+), 27 deletions(-)
>  create mode 100644 libavcodec/avs2dec.c
>  create mode 100644 libavcodec/avs2dec.h
>  create mode 100644 libavcodec/avs2dec_headers.c
>  create mode 100644 libavcodec/vaapi_avs2.c
> 
> >>>
> >>> Please split the patch properly. It's hard to review in a single chunk, 
> >>> and it can't be tested
> >>> without the hardware.
> >>
> >> As a new player in the GPU market, we have always attached great importance
> >> to the participation of the open source community. And willing to feed 
> >> back our
> >> new features to the field of video hardware acceleration.
> >>
> >> As a pioneer, these new features may only be supported by our hardware
> >> at current
> >> time. We are willing to provide some market selling devices for free
> >> to community
> >> accredited contributors for testing related functions.
> > I accredited Zhili Zhao, but i cannot sure Zhili Zhao have interest in the 
> > GPU card and not sure he has a computer can insert a PCI GPU card:D
>
> I have done a little work on AVS/AVS2/AVS3 and some hardware acceleration 
> work.
> I have a Lenovo 7000K and Dell Precision 3640, and I’m more concerned about 
> driver.

If you using Ubuntu driver is easy by install our all-in-one deb driver package.

Some how the problem is VAAPI-AVS/AVS2 interfaces should be accected by
Intel first. I'm wondering if Intel guys would be interest in taking
try our newest
devices like S80?

>
> >
> >>
> >>>
> >>> ___
> >>> ffmpeg-devel mailing list
> >>> ffmpeg-devel@ffmpeg.org
> >>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>>
> >>> To unsubscribe, visit link above, or email
> >>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> >
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "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] configure: autodetect libglslang ldflags

2024-01-22 Thread Martin Storsjö

On Mon, 22 Jan 2024, Timo Rothenpieler wrote:


On 22/01/2024 07:51, Matthew White via ffmpeg-devel wrote:

Since glslang 14.0.0, OGLCompiler and HLSL stub libraries have been
fully removed from the build.

This fixes the configuration by detecting if the stub libraries are
still present (glslang releases before version 14.0.0).

ffbuild/config.log:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lOSDependent: No such file or directory
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lHLSL: No such file or directory
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lOGLCompiler: No such file or directory


Addresses https://trac.ffmpeg.org/ticket/10713
See https://bugs.gentoo.org/show_bug.cgi?id=918989
Should fix 
https://ffmpeg.org/pipermail/ffmpeg-devel/2023-August/313666.html


Signed-off-by: Matthew White 
---
  configure | 23 +--
  1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index c8ae0a061d..abff488dc0 100755
--- a/configure
+++ b/configure
@@ -2626,6 +2626,7 @@ CMDLINE_SET="
  ignore_tests
  install
  ld
+libglslang_ldflags
  ln_s
  logfile
  malloc_prefix
@@ -6652,6 +6653,24 @@ if enabled_all libglslang libshaderc; then
  die "ERROR: libshaderc and libglslang are mutually exclusive, if in 
doubt, disable libglslang"

  fi
  +if enabled libglslang; then
+if [ -x "$(command -v glslang)" ]; then
+# https://github.com/KhronosGroup/glslang
+# commit 6be56e45e574b375d759b89dad35f780bbd4792f: Remove 
`OGLCompiler` and `HLSL` stub libraries from build
+# StandAlone/StandAlone.cpp: 
"SpirvGeneratorVersion:GLSLANG_VERSION_MAJOR.GLSLANG_VERSION_MINOR.GLSLANG_VERSION_PATCH 
GLSLANG_VERSION_FLAVOR"

+glslang_version="$(glslang -dumpversion)"
+glslang_major="${glslang_version%%.*}"
+glslang_major="${glslang_major#*:}"
+if test ${glslang_major} -le 13; then
+libglslang_ldflags=" -lOSDependent -lHLSL -lOGLCompiler"
+elif ! [[ ${glslang_major} =~ ^[0-9]+$ ]]; then
+die "ERROR: glslang's computed major version isn't a number: 
'${glslang_major}'"

+fi
+else
+die "ERROR: glslang binary not found, impossible to determine 
installed glslang's version"

+fi
+fi
+


Does that library really not have a sane pkg-config file?
This kind of guesswork in configure is extremely ugly.


Also, how does this work when cross compiling - won't the "glslang" binary 
be for the foreign cross target? Or is it something like the sdl-config 
script which is a local shell script that can give relevant build flags (a 
design preceding pkg-config)?


// Martin

___
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] configure: autodetect libglslang ldflags

2024-01-22 Thread Timo Rothenpieler

On 22/01/2024 07:51, Matthew White via ffmpeg-devel wrote:

Since glslang 14.0.0, OGLCompiler and HLSL stub libraries have been
fully removed from the build.

This fixes the configuration by detecting if the stub libraries are
still present (glslang releases before version 14.0.0).

ffbuild/config.log:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lOSDependent: No such file or directory
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lHLSL: No such file or directory
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: 
cannot find -lOGLCompiler: No such file or directory

Addresses https://trac.ffmpeg.org/ticket/10713
See https://bugs.gentoo.org/show_bug.cgi?id=918989
Should fix https://ffmpeg.org/pipermail/ffmpeg-devel/2023-August/313666.html

Signed-off-by: Matthew White 
---
  configure | 23 +--
  1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index c8ae0a061d..abff488dc0 100755
--- a/configure
+++ b/configure
@@ -2626,6 +2626,7 @@ CMDLINE_SET="
  ignore_tests
  install
  ld
+libglslang_ldflags
  ln_s
  logfile
  malloc_prefix
@@ -6652,6 +6653,24 @@ if enabled_all libglslang libshaderc; then
  die "ERROR: libshaderc and libglslang are mutually exclusive, if in doubt, 
disable libglslang"
  fi
  
+if enabled libglslang; then

+if [ -x "$(command -v glslang)" ]; then
+# https://github.com/KhronosGroup/glslang
+# commit 6be56e45e574b375d759b89dad35f780bbd4792f: Remove 
`OGLCompiler` and `HLSL` stub libraries from build
+# StandAlone/StandAlone.cpp: 
"SpirvGeneratorVersion:GLSLANG_VERSION_MAJOR.GLSLANG_VERSION_MINOR.GLSLANG_VERSION_PATCH
 GLSLANG_VERSION_FLAVOR"
+glslang_version="$(glslang -dumpversion)"
+glslang_major="${glslang_version%%.*}"
+glslang_major="${glslang_major#*:}"
+if test ${glslang_major} -le 13; then
+libglslang_ldflags=" -lOSDependent -lHLSL -lOGLCompiler"
+elif ! [[ ${glslang_major} =~ ^[0-9]+$ ]]; then
+die "ERROR: glslang's computed major version isn't a number: 
'${glslang_major}'"
+fi
+else
+die "ERROR: glslang binary not found, impossible to determine installed 
glslang's version"
+fi
+fi
+


Does that library really not have a sane pkg-config file?
This kind of guesswork in configure is extremely ugly.


  check_cpp_condition winrt windows.h 
"!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
  
  if ! disabled w32threads && ! enabled pthreads; then

@@ -6771,10 +6790,10 @@ enabled libfreetype   && require_pkg_config libfreetype 
freetype2 "ft2build.
  enabled libfribidi&& require_pkg_config libfribidi fribidi fribidi.h 
fribidi_version_info
  enabled libharfbuzz   && require_pkg_config libharfbuzz harfbuzz hb.h 
hb_buffer_create
  enabled libglslang && { check_lib spirv_compiler 
glslang/Include/glslang_c_interface.h glslang_initialize_process \
--lglslang -lMachineIndependent -lOSDependent 
-lHLSL -lOGLCompiler -lGenericCodeGen \
+-lglslang -lMachineIndependent 
"${libglslang_ldflags}" -lGenericCodeGen \
  -lSPVRemapper -lSPIRV -lSPIRV-Tools-opt 
-lSPIRV-Tools -lpthread -lstdc++ -lm ||
  require spirv_compiler 
glslang/Include/glslang_c_interface.h glslang_initialize_process \
--lglslang -lOSDependent -lHLSL -lOGLCompiler \
+-lglslang "${libglslang_ldflags}" \
  -lSPVRemapper -lSPIRV -lSPIRV-Tools-opt 
-lSPIRV-Tools -lpthread -lstdc++ -lm; }
  enabled libgme&& { check_pkg_config libgme libgme gme/gme.h 
gme_new_emu ||
 require libgme gme/gme.h gme_new_emu -lgme 
-lstdc++; }


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

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

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

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


Re: [FFmpeg-devel] [PATCH 1/2 v2] avutil: add a Tile Grid API

2024-01-22 Thread James Almer

On 1/22/2024 7:38 AM, Anton Khirnov wrote:

Quoting James Almer (2024-01-21 22:03:10)

I could remove the types and the union altogether and leave only the
array even for uniform tiles if you think that simplifies the API, but
seems like a waste of memory to allocate a rows x cols array of ints
just to have the same value written for every entry.


My point is that the API can abstract away the details of how the data
is stored. You could have it always behave like a list of N rectangles,
while only storing as much information as is needed.


The struct needs tile rows, tile columns, tile dimensions, output 
dimensions, and cropping information. I don't see how it could get smaller.

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

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


Re: [FFmpeg-devel] [PATCH 1/2 v2] avutil: add a Tile Grid API

2024-01-22 Thread James Almer

On 1/22/2024 7:32 AM, Anton Khirnov wrote:

Quoting James Almer (2024-01-21 20:29:58)

On 1/21/2024 4:02 PM, Anton Khirnov wrote:

I still don't see why should it be a good idea to use this struct for
generic container cropping. It feels very much like a hammer in search
of a nail.


Because once we support container cropping, we will be defining a
stream/packet side data type that will contain a subset of the fields
from this struct.


AVCodecParameters is a subset of AVCodecContext. By this logic we should
use AVCodecContext everywhere instead of AVCodecParameters.

There are also issues with storing it in packet side data since it
can contain pointers to malloced data.


Ah, that's true. At least if i remove the union.




If we reuse this struct, we can export a clap box as an AVTileGrid (Or i
can rename it to AVImageGrid, and tile to subrectangle) either as the
stream group tile grid specific parameters if HEIF, or as stream side
data otherwise.


How does that make the API better? It seems highly counterintuitive to
me to export container cropping information in a struct designed for
tiling.


Or you could consider it a struct designed to represent a group of 
images combined in a grid, for the purpose of extracting a subrectangle 
for presentation. How many images there are is defined by the rows and 
cols fields, and it can be 1.









And what do you mean with not supporting describing arbitrary
partitioning? Isn't that what variable tile dimensions achieve?


IIUC your tiling scheme still assumes that the partitioning is by rows
and columns. A completely generic partitioning could be irregular.


A new tile type that doesn't define rows and columns can be added if
needed. But the current variable tile type can support things like grids
of two rows and two columns where the second row is effectively a single
tile, simply by setting the second tile in said row as having a width of 0.


The problem I see here is that every consumer of this struct then has to
explicitly support every type, and adding a new type requires updating
all callers. This seems unnecessary when "list of N rectangles" covers
all possible partitionings.


Well, the variable type supports a list of N rectangles where each
rectangle has arbitrary dimensions, and you can do things like having
three tiles/rectangles that together still form a rectangle, while
defining row and column count. So i don't personally see the need for a
new type to begin with.


I don't see how is that supposed to work. E.g. consider the following
partitioning:
┌─┬┬─┐
│ │├─┤
├─┤│ │
│ ├┤ │
└─┴┴─┘

How would you represent it in this API?


___
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 v1 2/2] vaapi: add vaapi_avs2 support

2024-01-22 Thread Zhao Zhili


> On Jan 22, 2024, at 08:06, Liu Steven  wrote:
> 
> 
> 
>> On Jan 21, 2024, at 22:47, Jianfeng Zheng  wrote:
>> 
>> Zhao Zhili  于2024年1月20日周六 12:22写道:
>>> 
>>> 
 -Original Message-
 From: ffmpeg-devel  On Behalf Of 
 jianfeng.zheng
 Sent: 2024年1月19日 23:53
 To: ffmpeg-devel@ffmpeg.org
 Cc: jianfeng.zheng 
 Subject: [FFmpeg-devel] [PATCH v1 2/2] vaapi: add vaapi_avs2 support
 
 see https://github.com/intel/libva/pull/738
 
 [Moore Threads](https://www.mthreads.com) (short for Mthreads) is a
 Chinese GPU manufacturer. All our products, like MTTS70/MTTS80/.. ,
 support AVS2 8bit/10bit HW decoding at max 8k resolution.
 
 Signed-off-by: jianfeng.zheng 
 ---
 configure|   7 +
 libavcodec/Makefile  |   2 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/avs2.c| 345 ++-
 libavcodec/avs2.h| 460 +++-
 libavcodec/avs2_parser.c |   5 +-
 libavcodec/avs2dec.c | 569 +
 libavcodec/avs2dec.h |  48 +++
 libavcodec/avs2dec_headers.c | 787 +++
 libavcodec/codec_desc.c  |   5 +-
 libavcodec/defs.h|   4 +
 libavcodec/hwaccels.h|   1 +
 libavcodec/libdavs2.c|   2 +-
 libavcodec/profiles.c|   6 +
 libavcodec/profiles.h|   1 +
 libavcodec/vaapi_avs2.c  | 227 ++
 libavcodec/vaapi_decode.c|   5 +
 libavformat/matroska.c   |   1 +
 libavformat/mpeg.h   |   1 +
 19 files changed, 2450 insertions(+), 27 deletions(-)
 create mode 100644 libavcodec/avs2dec.c
 create mode 100644 libavcodec/avs2dec.h
 create mode 100644 libavcodec/avs2dec_headers.c
 create mode 100644 libavcodec/vaapi_avs2.c
 
>>> 
>>> Please split the patch properly. It's hard to review in a single chunk, and 
>>> it can't be tested
>>> without the hardware.
>> 
>> As a new player in the GPU market, we have always attached great importance
>> to the participation of the open source community. And willing to feed back 
>> our
>> new features to the field of video hardware acceleration.
>> 
>> As a pioneer, these new features may only be supported by our hardware
>> at current
>> time. We are willing to provide some market selling devices for free
>> to community
>> accredited contributors for testing related functions.
> I accredited Zhili Zhao, but i cannot sure Zhili Zhao have interest in the 
> GPU card and not sure he has a computer can insert a PCI GPU card:D

I have done a little work on AVS/AVS2/AVS3 and some hardware acceleration work.
I have a Lenovo 7000K and Dell Precision 3640, and I’m more concerned about 
driver.

> 
>> 
>>> 
>>> ___
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>> 
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

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


Re: [FFmpeg-devel] [PATCH 1/2 v2] avutil: add a Tile Grid API

2024-01-22 Thread James Almer

On 1/22/2024 7:32 AM, Anton Khirnov wrote:

Quoting James Almer (2024-01-21 20:29:58)

On 1/21/2024 4:02 PM, Anton Khirnov wrote:

I still don't see why should it be a good idea to use this struct for
generic container cropping. It feels very much like a hammer in search
of a nail.


Because once we support container cropping, we will be defining a
stream/packet side data type that will contain a subset of the fields
from this struct.


AVCodecParameters is a subset of AVCodecContext. By this logic we should
use AVCodecContext everywhere instead of AVCodecParameters.

There are also issues with storing it in packet side data since it
can contain pointers to malloced data.


If we reuse this struct, we can export a clap box as an AVTileGrid (Or i
can rename it to AVImageGrid, and tile to subrectangle) either as the
stream group tile grid specific parameters if HEIF, or as stream side
data otherwise.


How does that make the API better? It seems highly counterintuitive to
me to export container cropping information in a struct designed for
tiling.






And what do you mean with not supporting describing arbitrary
partitioning? Isn't that what variable tile dimensions achieve?


IIUC your tiling scheme still assumes that the partitioning is by rows
and columns. A completely generic partitioning could be irregular.


A new tile type that doesn't define rows and columns can be added if
needed. But the current variable tile type can support things like grids
of two rows and two columns where the second row is effectively a single
tile, simply by setting the second tile in said row as having a width of 0.


The problem I see here is that every consumer of this struct then has to
explicitly support every type, and adding a new type requires updating
all callers. This seems unnecessary when "list of N rectangles" covers
all possible partitionings.


Well, the variable type supports a list of N rectangles where each
rectangle has arbitrary dimensions, and you can do things like having
three tiles/rectangles that together still form a rectangle, while
defining row and column count. So i don't personally see the need for a
new type to begin with.


I don't see how is that supposed to work. E.g. consider the following
partitioning:
┌─┬┬─┐
│ │├─┤
├─┤│ │
│ ├┤ │
└─┴┴─┘

How would you represent it in this API?


That's two rows and three columns. Lets assume the smallest rectangle 
there is 1x1:


1x2 2x3 1x1
1x2 2x1 1x3

Meaning

tile_width[] = { 1, 2, 1, 1, 2, 1 };
tile_height[] = { 2, 3, 1, 2, 1, 3 };

As long as the sum of widths on every row and the sum of heights on 
every column is the same (To ensure you get a rectangle), it can be 
represented.


If what you're trying to say is "What about offsets?", they can be 
inferred based on dimensions and position of previous tiles within the grid.
I don't think adding yet another array to store offsets is worth it. But 
maybe a helper function that will build it?

___
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] FFmpeg's HLS muxer's deprecation of the hls_wrap option

2024-01-22 Thread Zhao Zhili


> On Jan 22, 2024, at 18:20, Dennis Mungai  wrote:
> 
> On Mon, 22 Jan 2024 at 13:10, Steven Liu  wrote:
> 
>> Dennis Mungai  于2024年1月21日周日 00:42写道:
>> 
 
>>> Perfect, and thanks for considering a revert of this deprecated feature.
>> 
>> Hi Dennis,
>> 
>> Need more talk, Why don't try to use hls_flags
>> +delete_segments+append_list. ?
>> 
>> 
>> Thanks
>> Steven
>> 
> 
> As stated earlier, even with these flags, we cannot replicate the advantage
> of the deprecated -hls_wrap whereby the segment names remain constant.
> append_list only omits the #EXT-EXT-ENDLIST tag.

The hls_wrap conflicts with current HLS specification, which add the restriction
at 2014. The specification explicitly says "EXT-X-MEDIA-SEQUENCE tag MUST
NOT decrease or wrap". So hls_wrap can’t be reverted.

Try what Steven suggests, or figure out a better idea than revert hls_wrap.

> ___
> 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] FFmpeg's HLS muxer's deprecation of the hls_wrap option

2024-01-22 Thread Steven Liu
Dennis Mungai 于2024年1月22日 周一18:20写道:

> On Mon, 22 Jan 2024 at 13:10, Steven Liu  wrote:
>
> > Dennis Mungai  于2024年1月21日周日 00:42写道:
> >
> > > >
> > > Perfect, and thanks for considering a revert of this deprecated
> feature.
> >
> > Hi Dennis,
> >
> > Need more talk, Why don't try to use hls_flags
> > +delete_segments+append_list. ?
> >
> >
> > Thanks
> > Steven
> >
>
> As stated earlier, even with these flags, we cannot replicate the advantage

No I don‘t think that is advantage, because hls_wrap can cover the old
segments with same segment file name.
And the deprecated warning has been there more than five years I think.

>
> of the deprecated -hls_wrap whereby the segment names remain constant.
> append_list only omits the #EXT-EXT-ENDLIST tag.




> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 1/2 v2] avutil: add a Tile Grid API

2024-01-22 Thread Anton Khirnov
Quoting James Almer (2024-01-21 22:03:10)
> I could remove the types and the union altogether and leave only the
> array even for uniform tiles if you think that simplifies the API, but
> seems like a waste of memory to allocate a rows x cols array of ints
> just to have the same value written for every entry.

My point is that the API can abstract away the details of how the data
is stored. You could have it always behave like a list of N rectangles,
while only storing as much information as is needed.

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

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


Re: [FFmpeg-devel] [PATCH 1/2 v2] avutil: add a Tile Grid API

2024-01-22 Thread Anton Khirnov
Quoting James Almer (2024-01-21 20:29:58)
> On 1/21/2024 4:02 PM, Anton Khirnov wrote:
> > I still don't see why should it be a good idea to use this struct for
> > generic container cropping. It feels very much like a hammer in search
> > of a nail.
> 
> Because once we support container cropping, we will be defining a 
> stream/packet side data type that will contain a subset of the fields 
> from this struct.

AVCodecParameters is a subset of AVCodecContext. By this logic we should
use AVCodecContext everywhere instead of AVCodecParameters.

There are also issues with storing it in packet side data since it
can contain pointers to malloced data.

> If we reuse this struct, we can export a clap box as an AVTileGrid (Or i 
> can rename it to AVImageGrid, and tile to subrectangle) either as the 
> stream group tile grid specific parameters if HEIF, or as stream side 
> data otherwise.

How does that make the API better? It seems highly counterintuitive to
me to export container cropping information in a struct designed for
tiling.

> > 
> >>>
>  And what do you mean with not supporting describing arbitrary
>  partitioning? Isn't that what variable tile dimensions achieve?
> >>>
> >>> IIUC your tiling scheme still assumes that the partitioning is by rows
> >>> and columns. A completely generic partitioning could be irregular.
> >>
> >> A new tile type that doesn't define rows and columns can be added if
> >> needed. But the current variable tile type can support things like grids
> >> of two rows and two columns where the second row is effectively a single
> >> tile, simply by setting the second tile in said row as having a width of 0.
> > 
> > The problem I see here is that every consumer of this struct then has to
> > explicitly support every type, and adding a new type requires updating
> > all callers. This seems unnecessary when "list of N rectangles" covers
> > all possible partitionings.
> 
> Well, the variable type supports a list of N rectangles where each 
> rectangle has arbitrary dimensions, and you can do things like having 
> three tiles/rectangles that together still form a rectangle, while 
> defining row and column count. So i don't personally see the need for a 
> new type to begin with.

I don't see how is that supposed to work. E.g. consider the following
partitioning:
┌─┬┬─┐
│ │├─┤
├─┤│ │
│ ├┤ │
└─┴┴─┘

How would you represent it in this API?

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

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


Re: [FFmpeg-devel] FFmpeg's HLS muxer's deprecation of the hls_wrap option

2024-01-22 Thread Dennis Mungai
On Mon, 22 Jan 2024 at 13:10, Steven Liu  wrote:

> Dennis Mungai  于2024年1月21日周日 00:42写道:
>
> > >
> > Perfect, and thanks for considering a revert of this deprecated feature.
>
> Hi Dennis,
>
> Need more talk, Why don't try to use hls_flags
> +delete_segments+append_list. ?
>
>
> Thanks
> Steven
>

As stated earlier, even with these flags, we cannot replicate the advantage
of the deprecated -hls_wrap whereby the segment names remain constant.
append_list only omits the #EXT-EXT-ENDLIST tag.
___
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] FFmpeg's HLS muxer's deprecation of the hls_wrap option

2024-01-22 Thread Steven Liu
Dennis Mungai  于2024年1月21日周日 00:42写道:

> >
> Perfect, and thanks for considering a revert of this deprecated feature.

Hi Dennis,

Need more talk, Why don't try to use hls_flags +delete_segments+append_list. ?


Thanks
Steven
___
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] Fwd: patch for 44.1/32 khz pcm input in pcm dvd encoder

2024-01-22 Thread Andrew Randrianasulu
-- Forwarded message -
От: Andrew Randrianasulu 
Date: вс, 21 янв. 2024 г., 06:49
Subject: patch for 44.1/32 khz pcm input in pcm dvd encoder
To: FFmpeg user questions , Cinelerra.GG <
c...@lists.cinelerra-gg.org>


relative to ffmpeg.git commit 6c4388b468bf92c0c1e7733c6cfe4ff3f9ca9723

lightly tested with mpv and mediainfo like this:

./ffmpeg -i ~/f9518976.mp4 -target pal-dvd -ar 44100 -c:a pcm_dvd -f dvd
t.mpg

mpv plays sound correctly, mediainfo does not know those frequencies and
display 0khz. ;)




forwarded to ffmpeg-devel as requested.
From 0438f90d10ef7f5162d6b7221a02ad240c1e99dd Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu 
Date: Sun, 21 Jan 2024 06:10:32 +0300
Subject: [PATCH] Add 32/44.1 khz sampling frequencies to pcm-dvd encoder

Signed-off-by: Andrew Randrianasulu 
---
 libavcodec/pcm-dvdenc.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c
index a2e5cbdc2e..67121e31b4 100644
--- a/libavcodec/pcm-dvdenc.c
+++ b/libavcodec/pcm-dvdenc.c
@@ -38,6 +38,12 @@ static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
 int quant, freq, frame_size;
 
 switch (avctx->sample_rate) {
+case 32000:
+	freq = 3;
+	break;
+case 44100:
+	freq = 2;
+	break;
 case 48000:
 freq = 0;
 break;
@@ -181,7 +187,7 @@ const FFCodec ff_pcm_dvd_encoder = {
 .priv_data_size = sizeof(PCMDVDContext),
 .init   = pcm_dvd_encode_init,
 FF_CODEC_ENCODE_CB(pcm_dvd_encode_frame),
-.p.supported_samplerates = (const int[]) { 48000, 96000, 0},
+.p.supported_samplerates = (const int[]) { 32000, 44100, 48000, 96000, 0},
 CODEC_OLD_CHANNEL_LAYOUTS(AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO,
   AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_7POINT1)
 .p.ch_layouts   = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH 7/8] fftools/ffmpeg_demux: implement -bsf for input

2024-01-22 Thread Anton Khirnov
Quoting Stefano Sabatini (2024-01-21 20:15:46)
> On date Sunday 2024-01-21 19:35:01 +0100, Anton Khirnov wrote:
> > Quoting Stefano Sabatini (2024-01-21 19:22:35)
> > > On date Sunday 2024-01-21 18:43:36 +0100, Anton Khirnov wrote:
> > > > Quoting Stefano Sabatini (2024-01-20 12:32:42)
> > > [...]
> > > > > When you present an example you usually start with an explanation
> > > > > (what it does) and then present the command, not the other way around.
> > > > 
> > > > I don't, neither does most literature I can recall. Typically you first
> > > > present a thing, then explain its structure. Explaning the structure of
> > > > something the reader has not seen yet is backwards, unnatural, and hard
> > > > to understand.
> > > 
> > > I still don't understand what "literature" you are referring to.
> > 
> > Various manuals and textbooks I've read.
> > 
> > > If you see most examples in the FFmpeg docs they are in the form:
> > 
> 
> > Our documentation is widely considered to be somewhere between atrocious
> > and unusable
> 
> nah, it's not so bad, also this applies to most documentation
> 
> Besides FFmpeg is possibly the most sophisticated existing toolkit in
> terms of features/configuration, so this is somehow expected (at least
> if you expect a tutorial rather than a reference).

I wouldn't be so sure. E.g. Qt has a bigger and more complex API than
ours, yet its documentation is more complete and coherent.

> > (and sometimes actively misleading), so the fact that it
> > does something in a specific way does not at all mean that it's a good
> > idea.
> 
> So what do you propose instead? The fact that it is not perfect does
> not mean that everything is bad.

I'm not saying everything is bad. I'm saying this specific way of
writing examples is bad and should be changed. Which is what I'm doing
in this patch.

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

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