[FFmpeg-cvslog] lavc/videotoolbox: deprecate write-only output_callback

2022-09-19 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Sep 15 
15:53:12 2022 +0200| [8576c3c5d82188c1313f20666b8760fe4a29444c] | committer: 
Anton Khirnov

lavc/videotoolbox: deprecate write-only output_callback

This field has never been used for anything, so stop setting it and
deprecate it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8576c3c5d82188c1313f20666b8760fe4a29444c
---

 libavcodec/version_major.h | 1 +
 libavcodec/videotoolbox.c  | 2 --
 libavcodec/videotoolbox.h  | 5 +
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h
index 1ec815a7bc..d9386792de 100644
--- a/libavcodec/version_major.h
+++ b/libavcodec/version_major.h
@@ -51,5 +51,6 @@
 #define FF_API_IDCT_NONE   (LIBAVCODEC_VERSION_MAJOR < 60)
 #define FF_API_SVTAV1_OPTS (LIBAVCODEC_VERSION_MAJOR < 60)
 #define FF_API_AYUV_CODECID(LIBAVCODEC_VERSION_MAJOR < 60)
+#define FF_API_VT_OUTPUT_CALLBACK  (LIBAVCODEC_VERSION_MAJOR < 60)
 
 #endif /* AVCODEC_VERSION_MAJOR_H */
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index d61d310600..1b1be8ddb4 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -1377,8 +1377,6 @@ static AVVideotoolboxContext 
*av_videotoolbox_alloc_context_with_pix_fmt(enum AV
 AVVideotoolboxContext *ret = av_mallocz(sizeof(*ret));
 
 if (ret) {
-ret->output_callback = videotoolbox_decoder_callback;
-
 OSType cv_pix_fmt_type = 
av_map_videotoolbox_format_from_pixfmt2(pix_fmt, full_range);
 if (cv_pix_fmt_type == 0) {
 cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
diff --git a/libavcodec/videotoolbox.h b/libavcodec/videotoolbox.h
index af2db0d580..fd8a5b7982 100644
--- a/libavcodec/videotoolbox.h
+++ b/libavcodec/videotoolbox.h
@@ -37,6 +37,8 @@
 
 #include "libavcodec/avcodec.h"
 
+#include "libavutil/attributes.h"
+
 /**
  * This struct holds all the information that needs to be passed
  * between the caller and libavcodec for initializing Videotoolbox decoding.
@@ -50,11 +52,14 @@ typedef struct AVVideotoolboxContext {
  */
 VTDecompressionSessionRef session;
 
+#if FF_API_VT_OUTPUT_CALLBACK
 /**
  * The output callback that must be passed to the session.
  * Set by av_videottoolbox_default_init()
  */
+attribute_deprecated
 VTDecompressionOutputCallback output_callback;
+#endif
 
 /**
  * CVPixelBuffer Format Type that Videotoolbox will use for decoded frames.

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

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


[FFmpeg-cvslog] lavc/videotoolbox: do not pass AVCodecContext to decoder output callback

2022-09-19 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Sep 15 
14:53:36 2022 +0200| [d7f4ad88a0df3c1339e142957bf2c40cd056b8ce] | committer: 
Anton Khirnov

lavc/videotoolbox: do not pass AVCodecContext to decoder output callback

The opaque parameter for the callback is set in videotoolbox_start(),
called when the hwaccel is initialized. When frame threading is used,
avctx will be the context corresponding to the frame thread currently
doing the decoding. Using this same codec context in all subsequent
invocations of the decoder callback (even those triggered by a different
frame thread) is unsafe, and broken after
cc867f2c09d2b69cee8a0eccd62aff002cbbfe11, since each frame thread now
cleans up its hwaccel state after decoding each frame.

Fix this by passing hwaccel_priv_data as the opaque parameter, which
exists in a single instance forwarded between all frame threads.

The only other use of AVCodecContext in the decoder output callback is
as a logging context. For this purpose, store a logging context in
hwaccel_priv_data.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d7f4ad88a0df3c1339e142957bf2c40cd056b8ce
---

 libavcodec/videotoolbox.c | 10 ++
 libavcodec/vt_internal.h  |  2 ++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index ce83c2594a..d61d310600 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -690,8 +690,7 @@ static void videotoolbox_decoder_callback(void *opaque,
   CMTime pts,
   CMTime duration)
 {
-AVCodecContext *avctx = opaque;
-VTContext *vtctx = avctx->internal->hwaccel_priv_data;
+VTContext *vtctx = opaque;
 
 if (vtctx->frame) {
 CVPixelBufferRelease(vtctx->frame);
@@ -699,7 +698,8 @@ static void videotoolbox_decoder_callback(void *opaque,
 }
 
 if (!image_buffer) {
-av_log(avctx, status ? AV_LOG_WARNING : AV_LOG_DEBUG, "vt decoder cb: 
output image buffer is null: %i\n", status);
+av_log(vtctx->logctx, status ? AV_LOG_WARNING : AV_LOG_DEBUG,
+   "vt decoder cb: output image buffer is null: %i\n", status);
 return;
 }
 
@@ -949,7 +949,7 @@ static int videotoolbox_start(AVCodecContext *avctx)
  
videotoolbox->cv_pix_fmt_type);
 
 decoder_cb.decompressionOutputCallback = videotoolbox_decoder_callback;
-decoder_cb.decompressionOutputRefCon   = avctx;
+decoder_cb.decompressionOutputRefCon   = 
avctx->internal->hwaccel_priv_data;
 
 status = VTDecompressionSessionCreate(NULL,  // 
allocator
   videotoolbox->cm_fmt_desc, // 
videoFormatDescription
@@ -1179,6 +1179,8 @@ int ff_videotoolbox_common_init(AVCodecContext *avctx)
 AVHWFramesContext *hw_frames;
 int err;
 
+vtctx->logctx = avctx;
+
 // Old API - do nothing.
 if (avctx->hwaccel_context)
 return 0;
diff --git a/libavcodec/vt_internal.h b/libavcodec/vt_internal.h
index 54a11fd1b5..9502d7c7dc 100644
--- a/libavcodec/vt_internal.h
+++ b/libavcodec/vt_internal.h
@@ -45,6 +45,8 @@ typedef struct VTContext {
 // Current H264 parameters (used to trigger decoder restart on SPS 
changes).
 uint8_t sps[3];
 boolreconfig_needed;
+
+void *logctx;
 } VTContext;
 
 int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame);

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

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


[FFmpeg-cvslog] avcodec/avcodec: Use the new API fields to validate the layout returned by decoders

2022-09-19 Thread James Almer
ffmpeg | branch: master | James Almer  | Fri Sep 16 11:49:17 
2022 -0300| [33cdf51a065c568bfe3811846095f8d8ac73fe6d] | committer: James Almer

avcodec/avcodec: Use the new API fields to validate the layout returned by 
decoders

This block was scheduled for removal, which means that no validation would have
taken place after the old API was removed.
It was algo going to mistakenly remove an unrelated bits_per_coded_sample
check.

Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=33cdf51a065c568bfe3811846095f8d8ac73fe6d
---

 libavcodec/avcodec.c | 22 --
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 29643199be..1f8ab37abb 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -321,24 +321,12 @@ FF_DISABLE_DEPRECATION_WARNINGS
 avctx->channels = avctx->ch_layout.nb_channels;
 avctx->channel_layout = avctx->ch_layout.order == 
AV_CHANNEL_ORDER_NATIVE ?
 avctx->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 /* validate channel layout from the decoder */
-if (avctx->channel_layout) {
-int channels = 
av_get_channel_layout_nb_channels(avctx->channel_layout);
-if (!avctx->channels)
-avctx->channels = channels;
-else if (channels != avctx->channels) {
-char buf[512];
-av_get_channel_layout_string(buf, sizeof(buf), -1, 
avctx->channel_layout);
-av_log(avctx, AV_LOG_WARNING,
-   "Channel layout '%s' with %d channels does not match 
specified number of channels %d: "
-   "ignoring specified channel layout\n",
-   buf, channels, avctx->channels);
-avctx->channel_layout = 0;
-}
-}
-if (avctx->channels && avctx->channels < 0 ||
-avctx->channels > FF_SANE_NB_CHANNELS) {
+if ((avctx->ch_layout.nb_channels && 
!av_channel_layout_check(&avctx->ch_layout)) ||
+avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
 ret = AVERROR(EINVAL);
 goto free_and_end;
 }
@@ -346,8 +334,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
 ret = AVERROR(EINVAL);
 goto free_and_end;
 }
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
 
 #if FF_API_AVCTX_TIMEBASE
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)

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

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


[FFmpeg-cvslog] fate/audio: Add tests for APTX (HD)

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 29 18:06:25 2021 +0200| [9884d14711e7a36743861afedd949b5f32ac5e3c] | 
committer: Andreas Rheinhardt

fate/audio: Add tests for APTX (HD)

We have de- and encoders for APTX and APTX HD, yet not FATE tests.
This commit therefore adds a transcoding test to utilize them.

Furthermore, during creating these tests it turned out that
the duration is set incorrectly for APTX HD. This will be fixed
in a future commit.

(Thanks to Andriy Gelman for finding an issue in an earlier version
that used a 192kHz input sample which does not work reliably accross
platforms.)

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9884d14711e7a36743861afedd949b5f32ac5e3c
---

 tests/fate/audio.mak   |  7 +++
 tests/ref/fate/aptx| 18 ++
 tests/ref/fate/aptx-hd | 15 +++
 3 files changed, 40 insertions(+)

diff --git a/tests/fate/audio.mak b/tests/fate/audio.mak
index fd9905ca0a..9d39eeace3 100644
--- a/tests/fate/audio.mak
+++ b/tests/fate/audio.mak
@@ -1,3 +1,10 @@
+FATE_SAMPLES_AUDIO-$(call TRANSCODE, APTX, APTX, WAV_DEMUXER PCM_S16LE_DECODER 
ARESAMPLE_FILTER) += fate-aptx
+fate-aptx: CMD = transcode wav 
$(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav aptx "-af 
aresample -c aptx" "-af aresample -c:a pcm_s16le -t 0.25" "" "" "-f aptx 
-sample_rate 44100"
+
+FATE_SAMPLES_AUDIO-$(call TRANSCODE, APTX_HD, APTX_HD, WAV_DEMUXER 
PCM_S16LE_DECODER \
+  ARESAMPLE_FILTER PCM_S32LE_ENCODER) += fate-aptx-hd
+fate-aptx-hd: CMD = transcode wav 
$(TARGET_SAMPLES)/audio-reference/luckynight_2ch_44kHz_s16.wav aptx_hd "-af 
aresample -c aptx_hd" "-af aresample -c:a pcm_s32le -t 0.25" "" "" "-f aptx_hd 
-sample_rate 44100"
+
 FATE_BINKAUDIO-$(call DEMDEC, BINK, BINKAUDIO_DCT) += fate-binkaudio-dct
 fate-binkaudio-dct: CMD = pcm -i $(TARGET_SAMPLES)/bink/binkaudio_dct.bik
 fate-binkaudio-dct: REF = $(SAMPLES)/bink/binkaudio_dct.pcm
diff --git a/tests/ref/fate/aptx b/tests/ref/fate/aptx
new file mode 100644
index 00..4d20b7df9a
--- /dev/null
+++ b/tests/ref/fate/aptx
@@ -0,0 +1,18 @@
+b5d8a297c0e8d9854f19d9d3e8b82859 *tests/data/fate/aptx.aptx
+418950 tests/data/fate/aptx.aptx
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 44100
+#channel_layout_name 0: 2 channels
+0,  0,  0, 1024, 4096, 0xcbb4ceff
+0,   1024,   1024, 1024, 4096, 0xa66533e7
+0,   2048,   2048, 1024, 4096, 0x4f22ec39
+0,   3072,   3072, 1024, 4096, 0x45f117f9
+0,   4096,   4096, 1024, 4096, 0xad6c0b7a
+0,   5120,   5120, 1024, 4096, 0x611618fd
+0,   6144,   6144, 1024, 4096, 0x0ec02f2b
+0,   7168,   7168, 1024, 4096, 0x2cf9ae5c
+0,   8192,   8192, 1024, 4096, 0xfb008ac0
+0,   9216,   9216, 1024, 4096, 0x25068495
+0,  10240,  10240,  785, 3140, 0x5a260589
diff --git a/tests/ref/fate/aptx-hd b/tests/ref/fate/aptx-hd
new file mode 100644
index 00..0691f33c86
--- /dev/null
+++ b/tests/ref/fate/aptx-hd
@@ -0,0 +1,15 @@
+48ecaa81ee5adaaa62ed3ff6574b *tests/data/fate/aptx-hd.aptx_hd
+628425 tests/data/fate/aptx-hd.aptx_hd
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: pcm_s32le
+#sample_rate 0: 44100
+#channel_layout_name 0: 2 channels
+0,  0,  0, 1024, 8192, 0xa99888c6
+0,   1536,   1536, 1024, 8192, 0xc3e03a3c
+0,   3072,   3072, 1024, 8192, 0x3f06e090
+0,   4608,   4608, 1024, 8192, 0x92fb18f3
+0,   6144,   6144, 1024, 8192, 0x3d5603a2
+0,   7680,   7680, 1024, 8192, 0xcc3d3101
+0,   9216,   9216, 1024, 8192, 0xbcc022ef
+0,  10752,  10752,  273, 2184, 0x9873af57

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

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


[FFmpeg-cvslog] avcodec/encode: Redo checks for small last audio frame

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep 15 16:57:18 2022 +0200| [dc7b6645575aa431d1d49744a17f60ee415ebc8b] | 
committer: Andreas Rheinhardt

avcodec/encode: Redo checks for small last audio frame

In particular, check that there is only one small last frame
in case the encoder has the AV_CODEC_CAP_SMALL_LAST_FRAME set.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dc7b6645575aa431d1d49744a17f60ee415ebc8b
---

 libavcodec/encode.c   | 21 +
 libavcodec/internal.h |  4 ++--
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index ade4d458e7..9bd9f9bc08 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -157,6 +157,7 @@ static int pad_last_frame(AVCodecContext *s, AVFrame 
*frame, const AVFrame *src)
 
 fail:
 av_frame_unref(frame);
+s->internal->last_audio_frame = 0;
 return ret;
 }
 
@@ -392,28 +393,24 @@ static int encode_send_frame_internal(AVCodecContext 
*avctx, const AVFrame *src)
 avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
 
 /* check for valid frame size */
-if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
-if (src->nb_samples > avctx->frame_size) {
-av_log(avctx, AV_LOG_ERROR, "more samples than frame size\n");
-return AVERROR(EINVAL);
-}
-} else if (!(avctx->codec->capabilities & 
AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
+if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
 /* if we already got an undersized frame, that must have been the 
last */
 if (avctx->internal->last_audio_frame) {
 av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected 
for a non-last frame\n", avctx->frame_size);
 return AVERROR(EINVAL);
 }
-
+if (src->nb_samples > avctx->frame_size) {
+av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) > frame_size 
(%d)\n", src->nb_samples, avctx->frame_size);
+return AVERROR(EINVAL);
+}
 if (src->nb_samples < avctx->frame_size) {
+avctx->internal->last_audio_frame = 1;
+if (!(avctx->codec->capabilities & 
AV_CODEC_CAP_SMALL_LAST_FRAME)) {
 ret = pad_last_frame(avctx, dst, src);
 if (ret < 0)
 return ret;
-
-avctx->internal->last_audio_frame = 1;
 goto finish;
-} else if (src->nb_samples > avctx->frame_size) {
-av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size 
(%d)\n", src->nb_samples, avctx->frame_size);
-return AVERROR(EINVAL);
+}
 }
 }
 }
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 35e3dd303a..45aec38a60 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -57,8 +57,8 @@ typedef struct AVCodecInternal {
 int is_copy;
 
 /**
- * An audio frame with less than required samples has been submitted and
- * padded with silence. Reject all subsequent frames.
+ * An audio frame with less than required samples has been submitted (and
+ * potentially padded with silence). Reject all subsequent frames.
  */
 int last_audio_frame;
 

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

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


[FFmpeg-cvslog] avcodec/utils: Support APTX (HD) in av_get_audio_frame_duration()

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 29 18:29:34 2021 +0200| [6f22d1965eeab80544ecbb190bc4c379063fa481] | 
committer: Andreas Rheinhardt

avcodec/utils: Support APTX (HD) in av_get_audio_frame_duration()

APTX decodes four bytes of input to four stereo samples; APTX HD
does the same with six bytes of input. So it can be easily supported
in av_get_audio_frame_duration().

This fixes invalid durations and (derived) timestamps of demuxed
APTX HD packets and therefore fixed the timestamp in the aptx-hd
FATE test.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6f22d1965eeab80544ecbb190bc4c379063fa481
---

 libavcodec/utils.c |  4 
 tests/ref/fate/aptx-hd | 17 ++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2f57418ff7..ba64aaf32d 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -682,6 +682,10 @@ static int get_audio_frame_duration(enum AVCodecID id, int 
sr, int ch, int ba,
 return 256 * (frame_bytes / 64);
 if (id == AV_CODEC_ID_RA_144)
 return 160 * (frame_bytes / 20);
+if (id == AV_CODEC_ID_APTX)
+return 4 * (frame_bytes / 4);
+if (id == AV_CODEC_ID_APTX_HD)
+return 4 * (frame_bytes / 6);
 
 if (bps > 0) {
 /* calc from frame_bytes and bits_per_coded_sample */
diff --git a/tests/ref/fate/aptx-hd b/tests/ref/fate/aptx-hd
index 0691f33c86..498b9131a6 100644
--- a/tests/ref/fate/aptx-hd
+++ b/tests/ref/fate/aptx-hd
@@ -6,10 +6,13 @@
 #sample_rate 0: 44100
 #channel_layout_name 0: 2 channels
 0,  0,  0, 1024, 8192, 0xa99888c6
-0,   1536,   1536, 1024, 8192, 0xc3e03a3c
-0,   3072,   3072, 1024, 8192, 0x3f06e090
-0,   4608,   4608, 1024, 8192, 0x92fb18f3
-0,   6144,   6144, 1024, 8192, 0x3d5603a2
-0,   7680,   7680, 1024, 8192, 0xcc3d3101
-0,   9216,   9216, 1024, 8192, 0xbcc022ef
-0,  10752,  10752,  273, 2184, 0x9873af57
+0,   1024,   1024, 1024, 8192, 0xc3e03a3c
+0,   2048,   2048, 1024, 8192, 0x3f06e090
+0,   3072,   3072, 1024, 8192, 0x92fb18f3
+0,   4096,   4096, 1024, 8192, 0x3d5603a2
+0,   5120,   5120, 1024, 8192, 0xcc3d3101
+0,   6144,   6144, 1024, 8192, 0xbcc022ef
+0,   7168,   7168, 1024, 8192, 0x600cbb73
+0,   8192,   8192, 1024, 8192, 0xdc938cbb
+0,   9216,   9216, 1024, 8192, 0x37d968bc
+0,  10240,  10240,  785, 6280, 0x48243144

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

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


[FFmpeg-cvslog] avcodec/aptxdec: Process data in complete blocks only

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 29 22:18:52 2021 +0200| [e6bfb14223e44b4110c1d171d1ecffe9c80302a8] | 
committer: Andreas Rheinhardt

avcodec/aptxdec: Process data in complete blocks only

The APTX (HD) decoder decodes blocks of four (six) bytes to four
output samples. It makes no sense to handle incomplete blocks:
They would just lead to synchronization errors, in which case
the complete frame is discarded. So only handle complete blocks.
This also avoids reading from the packet's padding and writing
into the frame's padding.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e6bfb14223e44b4110c1d171d1ecffe9c80302a8
---

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

diff --git a/libavcodec/aptxdec.c b/libavcodec/aptxdec.c
index 878c9ffe1b..d254b3026b 100644
--- a/libavcodec/aptxdec.c
+++ b/libavcodec/aptxdec.c
@@ -151,7 +151,7 @@ static int aptx_decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 /* get output buffer */
 frame->ch_layout.nb_channels = NB_CHANNELS;
 frame->format = AV_SAMPLE_FMT_S32P;
-frame->nb_samples = 4 * avpkt->size / s->block_size;
+frame->nb_samples = 4 * (avpkt->size / s->block_size);
 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
 return ret;
 

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

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


[FFmpeg-cvslog] avcodec/aptxenc: Process data in complete blocks of four samples only

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 29 22:44:36 2021 +0200| [129cbbd7be16fc0c396cfbb291794174735dbaf7] | 
committer: Andreas Rheinhardt

avcodec/aptxenc: Process data in complete blocks of four samples only

Do this by setting AVCodecInternal.pad_samples.
This prevents reading into the frame's padding and writing
into the packet's padding.

This actually happened in our FATE tests (where the number of samples
is 2 mod 4), which therefore needed to be updated.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=129cbbd7be16fc0c396cfbb291794174735dbaf7
---

 libavcodec/aptxenc.c   | 6 --
 tests/ref/fate/aptx| 4 ++--
 tests/ref/fate/aptx-hd | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/aptxenc.c b/libavcodec/aptxenc.c
index 434a9abf0f..114e286fe2 100644
--- a/libavcodec/aptxenc.c
+++ b/libavcodec/aptxenc.c
@@ -27,6 +27,7 @@
 #include "audio_frame_queue.h"
 #include "codec_internal.h"
 #include "encode.h"
+#include "internal.h"
 
 typedef struct AptXEncContext {
 AptXContext common;
@@ -259,6 +260,7 @@ static av_cold int aptx_encode_init(AVCodecContext *avctx)
 
 if (!avctx->frame_size || avctx->frame_size % 4)
 avctx->frame_size = 1024;
+avctx->internal->pad_samples = 4;
 
 return ff_aptx_init(avctx);
 }
@@ -269,7 +271,7 @@ const FFCodec ff_aptx_encoder = {
 CODEC_LONG_NAME("aptX (Audio Processing Technology for Bluetooth)"),
 .p.type= AVMEDIA_TYPE_AUDIO,
 .p.id  = AV_CODEC_ID_APTX,
-.p.capabilities= AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME,
+.p.capabilities= AV_CODEC_CAP_DR1,
 .priv_data_size= sizeof(AptXEncContext),
 .init  = aptx_encode_init,
 FF_CODEC_ENCODE_CB(aptx_encode_frame),
@@ -290,7 +292,7 @@ const FFCodec ff_aptx_hd_encoder = {
 CODEC_LONG_NAME("aptX HD (Audio Processing Technology for Bluetooth)"),
 .p.type= AVMEDIA_TYPE_AUDIO,
 .p.id  = AV_CODEC_ID_APTX_HD,
-.p.capabilities= AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SMALL_LAST_FRAME,
+.p.capabilities= AV_CODEC_CAP_DR1,
 .priv_data_size= sizeof(AptXEncContext),
 .init  = aptx_encode_init,
 FF_CODEC_ENCODE_CB(aptx_encode_frame),
diff --git a/tests/ref/fate/aptx b/tests/ref/fate/aptx
index 4d20b7df9a..7917399297 100644
--- a/tests/ref/fate/aptx
+++ b/tests/ref/fate/aptx
@@ -1,5 +1,5 @@
-b5d8a297c0e8d9854f19d9d3e8b82859 *tests/data/fate/aptx.aptx
-418950 tests/data/fate/aptx.aptx
+97dfd7f32d34fb74337c0f6c66e26e2d *tests/data/fate/aptx.aptx
+418952 tests/data/fate/aptx.aptx
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: pcm_s16le
diff --git a/tests/ref/fate/aptx-hd b/tests/ref/fate/aptx-hd
index 498b9131a6..d74c1059c2 100644
--- a/tests/ref/fate/aptx-hd
+++ b/tests/ref/fate/aptx-hd
@@ -1,5 +1,5 @@
-48ecaa81ee5adaaa62ed3ff6574b *tests/data/fate/aptx-hd.aptx_hd
-628425 tests/data/fate/aptx-hd.aptx_hd
+6126e414af1acb193e24fdf33c7cac2e *tests/data/fate/aptx-hd.aptx_hd
+628428 tests/data/fate/aptx-hd.aptx_hd
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: pcm_s32le

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

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


[FFmpeg-cvslog] avformat/aptxdec: Don't set AVCodecParameters.frame_size

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 29 21:55:30 2021 +0200| [9d10d3a4ee7ccf3742c4d9dd26a781aaf2ab8ae9] | 
committer: Andreas Rheinhardt

avformat/aptxdec: Don't set AVCodecParameters.frame_size

This field was misunderstood: It gives the number of samples
in a packet, not the number of bytes. Its usage was wrong for APTX HD.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9d10d3a4ee7ccf3742c4d9dd26a781aaf2ab8ae9
---

 libavformat/aptxdec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c
index 693316eeb0..aa86bfe330 100644
--- a/libavformat/aptxdec.c
+++ b/libavformat/aptxdec.c
@@ -58,7 +58,6 @@ static int aptx_read_header(AVFormatContext *s)
 st->codecpar->codec_id = AV_CODEC_ID_APTX;
 st->codecpar->bits_per_coded_sample = 4;
 st->codecpar->block_align = APTX_BLOCK_SIZE;
-st->codecpar->frame_size = APTX_PACKET_SIZE;
 return 0;
 }
 
@@ -70,7 +69,6 @@ static int aptx_hd_read_header(AVFormatContext *s)
 st->codecpar->codec_id = AV_CODEC_ID_APTX_HD;
 st->codecpar->bits_per_coded_sample = 6;
 st->codecpar->block_align = APTX_HD_BLOCK_SIZE;
-st->codecpar->frame_size = APTX_HD_PACKET_SIZE;
 return 0;
 }
 

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

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


[FFmpeg-cvslog] avformat/aptxdec: Don't set AV_PKT_FLAG_CORRUPT mistakenly

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 29 22:01:16 2021 +0200| [c8707c105fc7cf3cd2ca59a5f2e645d129369d98] | 
committer: Andreas Rheinhardt

avformat/aptxdec: Don't set AV_PKT_FLAG_CORRUPT mistakenly

Just because we try to put multiple units of block_align bytes
(the atomic units for APTX and APTX HD) into one packet
does not mean that packets with fewer units than the
one we wanted are corrupt; only those packets that are not
a multiple of block_align are.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c8707c105fc7cf3cd2ca59a5f2e645d129369d98
---

 libavformat/aptxdec.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c
index aa86bfe330..0637a8afde 100644
--- a/libavformat/aptxdec.c
+++ b/libavformat/aptxdec.c
@@ -74,12 +74,18 @@ static int aptx_hd_read_header(AVFormatContext *s)
 
 static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
+int ret = av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
+if (ret >= 0 && !(ret % APTX_BLOCK_SIZE))
+pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+return ret >= 0 ? 0 : ret;
 }
 
 static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-return av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
+int ret = av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
+if (ret >= 0 && !(ret % APTX_HD_BLOCK_SIZE))
+pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+return ret >= 0 ? 0 : ret;
 }
 
 static const AVOption aptx_options[] = {

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

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


[FFmpeg-cvslog] avcodec/aptx: Use AVCodecContext.frame_size according to the API

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Aug 29 20:25:18 2021 +0200| [c0d483cecb3ca31574f850c031d66a34a4f2d140] | 
committer: Andreas Rheinhardt

avcodec/aptx: Use AVCodecContext.frame_size according to the API

Currently the APTX (HD) codecs set frame_size if unset and check
whether it is divisible by block_size (corresponding to block_align
as used by other codecs). But this is based upon a misunderstanding
of the API: frame_size is not in bytes, but in samples.

Said value is also not intended to be set by the user at all,
but set by encoders and (possibly) decoders if the number of channels
in a frame is constant. The latter condition is not fulfilled here,
so only set it for encoders. Given that the encoder can handle any
number of samples as long as it is divisible by four and given that
it worked to set a custom frame size before, the encoders accept
any multiple of four; otherwise the value is set to the value
that it already had for APTX: 1024 samples (per channel).

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c0d483cecb3ca31574f850c031d66a34a4f2d140
---

 libavcodec/aptx.c| 9 -
 libavcodec/aptxenc.c | 3 +++
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index 8e110acc97..ed814ad1c0 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -516,15 +516,6 @@ av_cold int ff_aptx_init(AVCodecContext *avctx)
 s->hd = avctx->codec->id == AV_CODEC_ID_APTX_HD;
 s->block_size = s->hd ? 6 : 4;
 
-if (avctx->frame_size == 0)
-avctx->frame_size = 256 * s->block_size;
-
-if (avctx->frame_size % s->block_size) {
-av_log(avctx, AV_LOG_ERROR,
-   "Frame size must be a multiple of %d samples\n", s->block_size);
-return AVERROR(EINVAL);
-}
-
 for (chan = 0; chan < NB_CHANNELS; chan++) {
 Channel *channel = &s->channels[chan];
 for (subband = 0; subband < NB_SUBBANDS; subband++) {
diff --git a/libavcodec/aptxenc.c b/libavcodec/aptxenc.c
index f9347853d2..434a9abf0f 100644
--- a/libavcodec/aptxenc.c
+++ b/libavcodec/aptxenc.c
@@ -257,6 +257,9 @@ static av_cold int aptx_encode_init(AVCodecContext *avctx)
 
 ff_af_queue_init(avctx, &s->afq);
 
+if (!avctx->frame_size || avctx->frame_size % 4)
+avctx->frame_size = 1024;
+
 return ff_aptx_init(avctx);
 }
 

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

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


[FFmpeg-cvslog] avcodec/encode: Enable encoders to control padding of last frame

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep 15 19:20:11 2022 +0200| [017d976629ea272965ea67201543c8b5538cbf09] | 
committer: Andreas Rheinhardt

avcodec/encode: Enable encoders to control padding of last frame

Some audio codecs work with atomic units that decode to a fixed
number of audio samples with this number being so small that it is
common to put multiple of these atoms into one packet. In these
cases it makes no sense to pad the last frame to the big frame_size,
so allow encoders to set the number of samples that they want
the last frame to be padded to instead.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=017d976629ea272965ea67201543c8b5538cbf09
---

 libavcodec/encode.c   | 17 +++--
 libavcodec/internal.h |  6 ++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 9bd9f9bc08..049b71c6f4 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -127,12 +127,12 @@ static int encode_make_refcounted(AVCodecContext *avctx, 
AVPacket *avpkt)
 /**
  * Pad last frame with silence.
  */
-static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame 
*src)
+static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame 
*src, int out_samples)
 {
 int ret;
 
 frame->format = src->format;
-frame->nb_samples = s->frame_size;
+frame->nb_samples = out_samples;
 ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout);
 if (ret < 0)
 goto fail;
@@ -406,10 +406,15 @@ static int encode_send_frame_internal(AVCodecContext 
*avctx, const AVFrame *src)
 if (src->nb_samples < avctx->frame_size) {
 avctx->internal->last_audio_frame = 1;
 if (!(avctx->codec->capabilities & 
AV_CODEC_CAP_SMALL_LAST_FRAME)) {
-ret = pad_last_frame(avctx, dst, src);
-if (ret < 0)
-return ret;
-goto finish;
+int pad_samples = avci->pad_samples ? avci->pad_samples : 
avctx->frame_size;
+int out_samples = (src->nb_samples + pad_samples - 1) / 
pad_samples * pad_samples;
+
+if (out_samples != src->nb_samples) {
+ret = pad_last_frame(avctx, dst, src, out_samples);
+if (ret < 0)
+return ret;
+goto finish;
+}
 }
 }
 }
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 45aec38a60..76a6ea6bc6 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -62,6 +62,12 @@ typedef struct AVCodecInternal {
  */
 int last_audio_frame;
 
+/**
+ * Audio encoders can set this flag during init to indicate that they
+ * want the small last frame to be padded to a multiple of pad_samples.
+ */
+int pad_samples;
+
 AVBufferRef *pool;
 
 void *thread_ctx;

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

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


[FFmpeg-cvslog] lavc/vorbisdec: use ptrdiff_t to iterate over intptr_t

2022-09-19 Thread Rémi Denis-Courmont
ffmpeg | branch: master | Rémi Denis-Courmont  | Mon Sep 19 
19:10:42 2022 +0300| [bbf045aa592f7bec895907c8878fd734a0e8713b] | committer: 
James Almer

lavc/vorbisdec: use ptrdiff_t to iterate over intptr_t

While this probably never overflows, we are better safe than sorry.

The callback prototype should probably also use ptrdiff_t or size_t,
but I diggress (this would affect the DSP callback prototype).

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bbf045aa592f7bec895907c8878fd734a0e8713b
---

 libavcodec/ppc/vorbisdsp_altivec.c | 4 ++--
 libavcodec/vorbisdec.c | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ppc/vorbisdsp_altivec.c 
b/libavcodec/ppc/vorbisdsp_altivec.c
index 4dabf2dc7d..c298d8cae3 100644
--- a/libavcodec/ppc/vorbisdsp_altivec.c
+++ b/libavcodec/ppc/vorbisdsp_altivec.c
@@ -31,12 +31,12 @@
 static void vorbis_inverse_coupling_altivec(float *mag, float *ang,
 intptr_t blocksize)
 {
-int i;
 vector float m, a;
 vector bool int t0, t1;
 const vector unsigned int v_31 = //XXX
 vec_add(vec_add(vec_splat_u32(15),vec_splat_u32(15)),vec_splat_u32(1));
-for (i = 0; i < blocksize; i += 4) {
+
+for (ptrdiff_t i = 0; i < blocksize; i += 4) {
 m = vec_ld(0, mag+i);
 a = vec_ld(0, ang+i);
 t0 = vec_cmple(m, (vector float)vec_splat_u32(0));
diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 38a5367be3..bfc4be6fc6 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1581,8 +1581,7 @@ static inline int vorbis_residue_decode(vorbis_context 
*vc, vorbis_residue *vr,
 
 void ff_vorbis_inverse_coupling(float *mag, float *ang, intptr_t blocksize)
 {
-int i;
-for (i = 0;  i < blocksize;  i++) {
+for (ptrdiff_t i = 0; i < blocksize; i++) {
 if (mag[i] > 0.0) {
 if (ang[i] > 0.0) {
 ang[i] = mag[i] - ang[i];

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

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


[FFmpeg-cvslog] lavc/vorbisdsp: use ptrdiff_t rather than intptr_t

2022-09-19 Thread Rémi Denis-Courmont
ffmpeg | branch: master | Rémi Denis-Courmont  | Mon Sep 19 
19:10:43 2022 +0300| [b52034270a82ffc4aa584945c8a18aa8e58e741b] | committer: 
James Almer

lavc/vorbisdsp: use ptrdiff_t rather than intptr_t

... for a difference between pointers.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b52034270a82ffc4aa584945c8a18aa8e58e741b
---

 libavcodec/aarch64/vorbisdsp_init.c | 2 +-
 libavcodec/arm/vorbisdsp_init_arm.c | 2 +-
 libavcodec/ppc/vorbisdsp_altivec.c  | 2 +-
 libavcodec/vorbis.h | 2 +-
 libavcodec/vorbisdec.c  | 2 +-
 libavcodec/vorbisdsp.h  | 4 ++--
 libavcodec/x86/vorbisdsp_init.c | 2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/aarch64/vorbisdsp_init.c 
b/libavcodec/aarch64/vorbisdsp_init.c
index c796f95e61..969343934b 100644
--- a/libavcodec/aarch64/vorbisdsp_init.c
+++ b/libavcodec/aarch64/vorbisdsp_init.c
@@ -22,7 +22,7 @@
 #include "libavcodec/vorbisdsp.h"
 
 void ff_vorbis_inverse_coupling_neon(float *mag, float *ang,
- intptr_t blocksize);
+ ptrdiff_t blocksize);
 
 av_cold void ff_vorbisdsp_init_aarch64(VorbisDSPContext *c)
 {
diff --git a/libavcodec/arm/vorbisdsp_init_arm.c 
b/libavcodec/arm/vorbisdsp_init_arm.c
index f4b3d80ef6..acda34f468 100644
--- a/libavcodec/arm/vorbisdsp_init_arm.c
+++ b/libavcodec/arm/vorbisdsp_init_arm.c
@@ -25,7 +25,7 @@
 #include "libavcodec/vorbisdsp.h"
 
 void ff_vorbis_inverse_coupling_neon(float *mag, float *ang,
- intptr_t blocksize);
+ ptrdiff_t blocksize);
 
 av_cold void ff_vorbisdsp_init_arm(VorbisDSPContext *c)
 {
diff --git a/libavcodec/ppc/vorbisdsp_altivec.c 
b/libavcodec/ppc/vorbisdsp_altivec.c
index c298d8cae3..8f301705e9 100644
--- a/libavcodec/ppc/vorbisdsp_altivec.c
+++ b/libavcodec/ppc/vorbisdsp_altivec.c
@@ -29,7 +29,7 @@
 
 #if HAVE_ALTIVEC
 static void vorbis_inverse_coupling_altivec(float *mag, float *ang,
-intptr_t blocksize)
+ptrdiff_t blocksize)
 {
 vector float m, a;
 vector bool int t0, t1;
diff --git a/libavcodec/vorbis.h b/libavcodec/vorbis.h
index f80187feee..270855da04 100644
--- a/libavcodec/vorbis.h
+++ b/libavcodec/vorbis.h
@@ -45,7 +45,7 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, 
unsigned num);
 void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values,
   uint16_t *y_list, int *flag,
   int multiplier, float * out, int samples);
-void ff_vorbis_inverse_coupling(float *mag, float *ang, intptr_t blocksize);
+void ff_vorbis_inverse_coupling(float *mag, float *ang, ptrdiff_t blocksize);
 
 #define ilog(i) av_log2(2*(i))
 
diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index bfc4be6fc6..10d187b82a 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1579,7 +1579,7 @@ static inline int vorbis_residue_decode(vorbis_context 
*vc, vorbis_residue *vr,
 }
 }
 
-void ff_vorbis_inverse_coupling(float *mag, float *ang, intptr_t blocksize)
+void ff_vorbis_inverse_coupling(float *mag, float *ang, ptrdiff_t blocksize)
 {
 for (ptrdiff_t i = 0; i < blocksize; i++) {
 if (mag[i] > 0.0) {
diff --git a/libavcodec/vorbisdsp.h b/libavcodec/vorbisdsp.h
index 7abec4e4b7..1775a92cf2 100644
--- a/libavcodec/vorbisdsp.h
+++ b/libavcodec/vorbisdsp.h
@@ -19,12 +19,12 @@
 #ifndef AVCODEC_VORBISDSP_H
 #define AVCODEC_VORBISDSP_H
 
-#include 
+#include 
 
 typedef struct VorbisDSPContext {
 /* assume len is a multiple of 4, and arrays are 16-byte aligned */
 void (*vorbis_inverse_coupling)(float *mag, float *ang,
-intptr_t blocksize);
+ptrdiff_t blocksize);
 } VorbisDSPContext;
 
 void ff_vorbisdsp_init(VorbisDSPContext *dsp);
diff --git a/libavcodec/x86/vorbisdsp_init.c b/libavcodec/x86/vorbisdsp_init.c
index da9f9e685e..08a3bb2965 100644
--- a/libavcodec/x86/vorbisdsp_init.c
+++ b/libavcodec/x86/vorbisdsp_init.c
@@ -25,7 +25,7 @@
 #include "libavcodec/vorbisdsp.h"
 
 void ff_vorbis_inverse_coupling_sse(float *mag, float *ang,
-intptr_t blocksize);
+ptrdiff_t blocksize);
 
 av_cold void ff_vorbisdsp_init_x86(VorbisDSPContext *dsp)
 {

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

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


[FFmpeg-cvslog] lavc/vorbisdec: use intermediate variables

2022-09-19 Thread Rémi Denis-Courmont
ffmpeg | branch: master | Rémi Denis-Courmont  | Mon Sep 19 
19:10:44 2022 +0300| [5c15cb138eb1292bc16e64d3cb39953f1c09ce97] | committer: 
James Almer

lavc/vorbisdec: use intermediate variables

The compiler cannot infer that the two float vectors do not alias,
causing unnecessary extra loads and serialisation. This patch caches
the two input values in local variables so that compiler can optimise
individual loop iterations.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5c15cb138eb1292bc16e64d3cb39953f1c09ce97
---

 libavcodec/vorbisdec.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 10d187b82a..72b8e8e15b 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1581,22 +1581,22 @@ static inline int vorbis_residue_decode(vorbis_context 
*vc, vorbis_residue *vr,
 
 void ff_vorbis_inverse_coupling(float *mag, float *ang, ptrdiff_t blocksize)
 {
-for (ptrdiff_t i = 0; i < blocksize; i++) {
-if (mag[i] > 0.0) {
-if (ang[i] > 0.0) {
-ang[i] = mag[i] - ang[i];
+for (ptrdiff_t i = 0;  i < blocksize;  i++) {
+float angi = ang[i], magi = mag[i];
+
+if (magi > 0.f) {
+if (angi > 0.f) {
+ang[i] = magi - angi;
 } else {
-float temp = ang[i];
-ang[i] = mag[i];
-mag[i]+= temp;
+ang[i] = magi;
+mag[i] = magi + angi;
 }
 } else {
-if (ang[i] > 0.0) {
-ang[i] += mag[i];
+if (angi > 0.f) {
+ang[i] = magi + angi;
 } else {
-float temp = ang[i];
-ang[i] = mag[i];
-mag[i]-= temp;
+ang[i] = magi;
+mag[i] = magi - angi;
 }
 }
 }

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

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


[FFmpeg-cvslog] avcodec/vorbisdec: Move ff_vorbis_inverse_coupling() to vorbisdsp.c

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Mon Sep 19 19:13:28 2022 +0200| [32129d64953da1502a200e850ac0a559791824b9] | 
committer: Andreas Rheinhardt

avcodec/vorbisdec: Move ff_vorbis_inverse_coupling() to vorbisdsp.c

Only used there. Also make it static.

Reviewed-by: James Almer 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=32129d64953da1502a200e850ac0a559791824b9
---

 libavcodec/vorbis.h|  1 -
 libavcodec/vorbisdec.c | 23 ---
 libavcodec/vorbisdsp.c | 26 --
 3 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/libavcodec/vorbis.h b/libavcodec/vorbis.h
index 270855da04..0dd109dd2e 100644
--- a/libavcodec/vorbis.h
+++ b/libavcodec/vorbis.h
@@ -45,7 +45,6 @@ int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, 
unsigned num);
 void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values,
   uint16_t *y_list, int *flag,
   int multiplier, float * out, int samples);
-void ff_vorbis_inverse_coupling(float *mag, float *ang, ptrdiff_t blocksize);
 
 #define ilog(i) av_log2(2*(i))
 
diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 72b8e8e15b..0d04e7c2c4 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1579,29 +1579,6 @@ static inline int vorbis_residue_decode(vorbis_context 
*vc, vorbis_residue *vr,
 }
 }
 
-void ff_vorbis_inverse_coupling(float *mag, float *ang, ptrdiff_t blocksize)
-{
-for (ptrdiff_t i = 0;  i < blocksize;  i++) {
-float angi = ang[i], magi = mag[i];
-
-if (magi > 0.f) {
-if (angi > 0.f) {
-ang[i] = magi - angi;
-} else {
-ang[i] = magi;
-mag[i] = magi + angi;
-}
-} else {
-if (angi > 0.f) {
-ang[i] = magi + angi;
-} else {
-ang[i] = magi;
-mag[i] = magi - angi;
-}
-}
-}
-}
-
 // Decode the audio packet using the functions above
 
 static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
diff --git a/libavcodec/vorbisdsp.c b/libavcodec/vorbisdsp.c
index e94b65cb7b..693c44dfcb 100644
--- a/libavcodec/vorbisdsp.c
+++ b/libavcodec/vorbisdsp.c
@@ -19,11 +19,33 @@
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "vorbisdsp.h"
-#include "vorbis.h"
+
+static void vorbis_inverse_coupling_c(float *mag, float *ang, ptrdiff_t 
blocksize)
+{
+for (ptrdiff_t i = 0;  i < blocksize;  i++) {
+float angi = ang[i], magi = mag[i];
+
+if (magi > 0.f) {
+if (angi > 0.f) {
+ang[i] = magi - angi;
+} else {
+ang[i] = magi;
+mag[i] = magi + angi;
+}
+} else {
+if (angi > 0.f) {
+ang[i] = magi + angi;
+} else {
+ang[i] = magi;
+mag[i] = magi - angi;
+}
+}
+}
+}
 
 av_cold void ff_vorbisdsp_init(VorbisDSPContext *dsp)
 {
-dsp->vorbis_inverse_coupling = ff_vorbis_inverse_coupling;
+dsp->vorbis_inverse_coupling = vorbis_inverse_coupling_c;
 
 #if ARCH_AARCH64
 ff_vorbisdsp_init_aarch64(dsp);

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

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


[FFmpeg-cvslog] avutil/dict: Error out in case of key == NULL

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 14 21:03:15 2022 +0200| [187cd278325ae2fc6d533141e7d6c557b669932a] | 
committer: Andreas Rheinhardt

avutil/dict: Error out in case of key == NULL

Up until now, using NULL as key in av_dict_get() on a non-empty
AVDictionary would crash; using NULL as key in av_dict_set()
would also crash for a non-empty AVDictionary unless AV_DICT_MULTIKEY
was set; in case the dictionary was initially empty or AV_DICT_MULTIKEY
was set, it was even possible for av_dict_set() to succeed when
adding a NULL key, namely when one uses a value != NULL and
the AV_DICT_DONT_STRDUP_VAL flag. Using av_dict_get() on such
an AVDictionary will usually lead to crashes, though.

Fix this by actually checking for key in both functions; error out
if they are NULL.

While just at it, also stop relying on av_strdup(NULL) to return NULL
in av_dict_set().

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=187cd278325ae2fc6d533141e7d6c557b669932a
---

 libavutil/dict.c   | 27 +--
 libavutil/tests/dict.c | 12 +---
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 4bba041d0a..14ad780a79 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -43,7 +43,7 @@ AVDictionaryEntry *av_dict_get(const AVDictionary *m, const 
char *key,
 {
 unsigned int i, j;
 
-if (!m)
+if (!m || !key)
 return NULL;
 
 if (prev)
@@ -74,7 +74,16 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 AVDictionary *m = *pm;
 AVDictionaryEntry *tag = NULL;
 char *copy_key = NULL, *copy_value = NULL;
+int err;
 
+if (flags & AV_DICT_DONT_STRDUP_VAL)
+copy_value = (void *)value;
+else if (value)
+copy_value = av_strdup(value);
+if (!key) {
+err = AVERROR(EINVAL);
+goto err_out;
+}
 if (!(flags & AV_DICT_MULTIKEY)) {
 tag = av_dict_get(m, key, NULL, flags);
 }
@@ -82,14 +91,10 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 copy_key = (void *)key;
 else
 copy_key = av_strdup(key);
-if (flags & AV_DICT_DONT_STRDUP_VAL)
-copy_value = (void *)value;
-else if (copy_key)
-copy_value = av_strdup(value);
 if (!m)
 m = *pm = av_mallocz(sizeof(*m));
-if (!m || (key && !copy_key) || (value && !copy_value))
-goto err_out;
+if (!m || !copy_key || (value && !copy_value))
+goto enomem;
 
 if (tag) {
 if (flags & AV_DICT_DONT_OVERWRITE) {
@@ -103,7 +108,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 size_t len = oldlen + new_part_len + 1;
 char *newval = av_realloc(tag->value, len);
 if (!newval)
-goto err_out;
+goto enomem;
 memcpy(newval + oldlen, copy_value, new_part_len + 1);
 av_freep(©_value);
 copy_value = newval;
@@ -115,7 +120,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 AVDictionaryEntry *tmp = av_realloc_array(m->elems,
   m->count + 1, 
sizeof(*m->elems));
 if (!tmp)
-goto err_out;
+goto enomem;
 m->elems = tmp;
 }
 if (copy_value) {
@@ -132,6 +137,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
 
 return 0;
 
+enomem:
+err = AVERROR(ENOMEM);
 err_out:
 if (m && !m->count) {
 av_freep(&m->elems);
@@ -139,7 +146,7 @@ err_out:
 }
 av_free(copy_key);
 av_free(copy_value);
-return AVERROR(ENOMEM);
+return err;
 }
 
 int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value,
diff --git a/libavutil/tests/dict.c b/libavutil/tests/dict.c
index 56e98557a7..d053545f4d 100644
--- a/libavutil/tests/dict.c
+++ b/libavutil/tests/dict.c
@@ -91,14 +91,20 @@ int main(void)
 av_dict_set(&dict, "f", NULL, 0);
 av_dict_set(&dict, "ff", "f", 0);
 av_dict_set(&dict, "ff", "f", AV_DICT_APPEND);
+if (av_dict_get(dict, NULL, NULL, 0))
+printf("av_dict_get() does not correctly handle NULL key.\n");
 e = NULL;
 while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
 printf("%s %s\n", e->key, e->value);
 av_dict_free(&dict);
 
-av_dict_set(&dict, NULL, "a", 0);
-av_dict_set(&dict, NULL, "b", 0);
-av_dict_get(dict, NULL, NULL, 0);
+if (av_dict_set(&dict, NULL, "a", 0) >= 0 ||
+av_dict_set(&dict, NULL, "b", 0) >= 0 ||
+av_dict_set(&dict, NULL, NULL, AV_DICT_DONT_STRDUP_KEY) >= 0 ||
+av_dict_set(&dict, NULL, av_strdup("b"), AV_DICT_DONT_STRDUP_VAL) >= 0 
||
+av_dict_count(dict))
+printf("av_dict_set does not correctly handle NULL key\n");
+
 e = NULL;
 while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX)))
  

[FFmpeg-cvslog] swscale/input: Avoid calls to av_pix_fmt_desc_get()

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep  8 03:45:12 2022 +0200| [4d7a1a4619c9ed89c5f6dbf8a0ae85b9a8aa056b] | 
committer: Andreas Rheinhardt

swscale/input: Avoid calls to av_pix_fmt_desc_get()

Up until now, libswscale/input.c used a macro to read
an input pixel which involved a call to av_pix_fmt_desc_get()
to find out whether the input pixel format is BE or LE
despite this being known at compile-time (there are templates
per pixfmt). Even worse, these calls are made in a loop,
so that e.g. there are six calls to av_pix_fmt_desc_get()
for every pair of UV pixel processed in
rgb64ToUV_half_c_template().

This commit modifies these macros to ensure that isBE()
is evaluated at compile-time. This saved 9743B of .text
for me (GCC 11.2, -O3). For a simple RGB64LE->YUV420P
transformation like
ffmpeg -f lavfi -i haldclutsrc,format=rgba64le -pix_fmt yuv420p \
-threads 1  -t 1:00  -f null -
the amount of decicycles spent in rgb64LEToUV_half_c
(which is created via the template mentioned above)
decreases from 19751 to 5341; for RGBA64BE the number
went down from 11945 to 5393. For shared builds (where
the call to av_pix_fmt_desc_get() is indirect) the old numbers
are 15230 for RGBA64BE and 27502 for RGBA64LE, whereas
the numbers with this patch are indistinguishable from
the numbers from a static build.

Also make the macros that are touched conform to the
usual convention of using uppercase names while just at it.

Reviewed-by: Anton Khirnov 
Reviewed-by: Paul B Mahol 
Reviewed-by: Michael Niedermayer 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4d7a1a4619c9ed89c5f6dbf8a0ae85b9a8aa056b
---

 libswscale/input.c | 122 +
 1 file changed, 68 insertions(+), 54 deletions(-)

diff --git a/libswscale/input.c b/libswscale/input.c
index 88e318e664..7ff7bfaa01 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -28,14 +28,21 @@
 #include "config.h"
 #include "swscale_internal.h"
 
-#define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos))
+#define input_pixel(pos) (is_be ? AV_RB16(pos) : AV_RL16(pos))
+
+#define IS_BE_LE 0
+#define IS_BE_BE 1
+#define IS_BE_   0
+/* ENDIAN_IDENTIFIER needs to be "BE", "LE" or "". The latter is intended
+ * for single-byte cases where the concept of endianness does not apply. */
+#define IS_BE(ENDIAN_IDENTIFIER) IS_BE_ ## ENDIAN_IDENTIFIER
 
 #define r ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE || 
origin == AV_PIX_FMT_BGRA64BE || origin == AV_PIX_FMT_BGRA64LE) ? b_r : r_b)
 #define b ((origin == AV_PIX_FMT_BGR48BE || origin == AV_PIX_FMT_BGR48LE || 
origin == AV_PIX_FMT_BGRA64BE || origin == AV_PIX_FMT_BGRA64LE) ? r_b : b_r)
 
 static av_always_inline void
 rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int width,
-enum AVPixelFormat origin, int32_t *rgb2yuv)
+enum AVPixelFormat origin, int32_t *rgb2yuv, int is_be)
 {
 int32_t ry = rgb2yuv[RY_IDX], gy = rgb2yuv[GY_IDX], by = rgb2yuv[BY_IDX];
 int i;
@@ -51,7 +58,7 @@ rgb64ToY_c_template(uint16_t *dst, const uint16_t *src, int 
width,
 static av_always_inline void
 rgb64ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
 const uint16_t *src1, const uint16_t *src2,
-int width, enum AVPixelFormat origin, int32_t *rgb2yuv)
+int width, enum AVPixelFormat origin, int32_t *rgb2yuv, 
int is_be)
 {
 int i;
 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
@@ -70,7 +77,7 @@ rgb64ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
 static av_always_inline void
 rgb64ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
   const uint16_t *src1, const uint16_t *src2,
-  int width, enum AVPixelFormat origin, int32_t 
*rgb2yuv)
+  int width, enum AVPixelFormat origin, int32_t 
*rgb2yuv, int is_be)
 {
 int i;
 int32_t ru = rgb2yuv[RU_IDX], gu = rgb2yuv[GU_IDX], bu = rgb2yuv[BU_IDX];
@@ -86,13 +93,13 @@ rgb64ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
 }
 }
 
-#define rgb64funcs(pattern, BE_LE, origin) \
+#define RGB64FUNCS_EXT(pattern, BE_LE, origin, is_be) \
 static void pattern ## 64 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t 
*_src, const uint8_t *unused0, const uint8_t *unused1,\
 int width, uint32_t *rgb2yuv, void *opq) \
 { \
 const uint16_t *src = (const uint16_t *) _src; \
 uint16_t *dst = (uint16_t *) _dst; \
-rgb64ToY_c_template(dst, src, width, origin, rgb2yuv); \
+rgb64ToY_c_template(dst, src, width, origin, rgb2yuv, is_be); \
 } \
  \
 static void pattern ## 64 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
@@ -102,7 +109,7 @@ static void pattern ## 64 ## BE_LE ## ToUV_c(uint8_t 
*_dstU, uint8_t *_dstV, \
 const uint16_t *src1 = (const uint16_t *) _src1, \
*src2 = (const u

[FFmpeg-cvslog] swscale/output: Don't call av_pix_fmt_desc_get() in a loop

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep  8 05:10:16 2022 +0200| [888a02a126522ad1da802eb1f4e4571afc09a14d] | 
committer: Andreas Rheinhardt

swscale/output: Don't call av_pix_fmt_desc_get() in a loop

Up until now, libswscale/output.c used a macro to write
an output pixel which involved a call to av_pix_fmt_desc_get()
to find out whether the input pixel format is BE or LE
despite this being known at compile-time (there are templates
per pixfmt). Even worse, these calls are made in a loop,
so that e.g. there are eight calls to av_pix_fmt_desc_get()
for every pixel processed in yuv2rgba64_X_c_template()
for 64bit RGB formats.

This commit modifies these macros to ensure that isBE()
is evaluated at compile-time. This saved 41184B of .text
for me (GCC 11.2, -O3). Of course, it also improved performance.
E.g. ffmpeg_g -f lavfi -i testsrc2,format=yuva420p -pix_fmt rgba64le \
-threads 1  -t 1:00  -f null - (which uses yuv2rgba64le_X_c,
which is an invocation of yuv2rgba64_X_c_template() mentioned above),
performance improved from 95589 to 41387 decicycles for one call
to yuv2packedX; for the be variant the numbers went down from
76087 to 43024 decicycles.

Reviewed-by: Anton Khirnov 
Reviewed-by: Paul B Mahol 
Reviewed-by: Michael Niedermayer 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=888a02a126522ad1da802eb1f4e4571afc09a14d
---

 libswscale/output.c | 100 ++--
 1 file changed, 58 insertions(+), 42 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 2f599698e9..0e1c1225a0 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -133,6 +133,11 @@ DECLARE_ALIGNED(8, const uint8_t, ff_dither_8x8_220)[][8] 
= {
 };
 #endif
 
+#define IS_BE_LE 0
+#define IS_BE_BE 1
+/* ENDIAN_IDENTIFIER needs to be "BE" or "LE". */
+#define IS_BE(ENDIAN_IDENTIFIER) IS_BE_ ## ENDIAN_IDENTIFIER
+
 #define output_pixel(pos, val, bias, signedness) \
 if (big_endian) { \
 AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \
@@ -935,7 +940,7 @@ YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
 #define R_B ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || 
target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? R : B)
 #define B_R ((target == AV_PIX_FMT_RGB48LE || target == AV_PIX_FMT_RGB48BE || 
target == AV_PIX_FMT_RGBA64LE || target == AV_PIX_FMT_RGBA64BE) ? B : R)
 #define output_pixel(pos, val) \
-if (isBE(target)) { \
+if (is_be) { \
 AV_WB16(pos, val); \
 } else { \
 AV_WL16(pos, val); \
@@ -947,7 +952,8 @@ yuv2ya16_X_c_template(SwsContext *c, const int16_t 
*lumFilter,
 const int16_t *chrFilter, const int32_t 
**unused_chrUSrc,
 const int32_t **unused_chrVSrc, int 
unused_chrFilterSize,
 const int32_t **alpSrc, uint16_t *dest, int dstW,
-int y, enum AVPixelFormat target, int unused_hasAlpha, 
int unused_eightbytes)
+int y, enum AVPixelFormat target,
+int unused_hasAlpha, int unused_eightbytes, int is_be)
 {
 int hasAlpha = !!alpSrc;
 int i;
@@ -984,7 +990,8 @@ yuv2ya16_2_c_template(SwsContext *c, const int32_t *buf[2],
 const int32_t *unused_ubuf[2], const int32_t 
*unused_vbuf[2],
 const int32_t *abuf[2], uint16_t *dest, int dstW,
 int yalpha, int unused_uvalpha, int y,
-enum AVPixelFormat target, int unused_hasAlpha, int 
unused_eightbytes)
+enum AVPixelFormat target, int unused_hasAlpha,
+int unused_eightbytes, int is_be)
 {
 int hasAlpha = abuf && abuf[0] && abuf[1];
 const int32_t *buf0  = buf[0],  *buf1  = buf[1],
@@ -1015,7 +1022,8 @@ static av_always_inline void
 yuv2ya16_1_c_template(SwsContext *c, const int32_t *buf0,
 const int32_t *unused_ubuf[2], const int32_t 
*unused_vbuf[2],
 const int32_t *abuf0, uint16_t *dest, int dstW,
-int unused_uvalpha, int y, enum AVPixelFormat target, 
int unused_hasAlpha, int unused_eightbytes)
+int unused_uvalpha, int y, enum AVPixelFormat target,
+int unused_hasAlpha, int unused_eightbytes, int is_be)
 {
 int hasAlpha = !!abuf0;
 int i;
@@ -1043,7 +1051,8 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t 
*lumFilter,
const int16_t *chrFilter, const int32_t **chrUSrc,
const int32_t **chrVSrc, int chrFilterSize,
const int32_t **alpSrc, uint16_t *dest, int dstW,
-   int y, enum AVPixelFormat target, int hasAlpha, int 
eightbytes)
+   int y, enum AVPixelFormat target, int hasAlpha, int 
eightbytes,
+   

[FFmpeg-cvslog] avcodec/mjpegdec: Avoid copying data when flipping image

2022-09-19 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Apr 14 16:43:53 2022 +0200| [118b36f418fb050aebecd0c868b04bdc45293012] | 
committer: Andreas Rheinhardt

avcodec/mjpegdec: Avoid copying data when flipping image

Basically reverts af15c17daa5d8d2940c0263ba4d3ecec761c11ee.
Flipping a picture by modifying the pointers is so common
that even users of direct rendering should take it into account.

Reviewed-by: Michael Niedermayer 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=118b36f418fb050aebecd0c868b04bdc45293012
---

 libavcodec/mjpegdec.c | 22 ++
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 65337360b0..ca7e752f16 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2770,28 +2770,18 @@ the_end:
 }
 }
 if (s->flipped && !s->rgb) {
-int j;
 ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, 
&vshift);
 if (ret)
 return ret;
 
-av_assert0(s->nb_components == 
av_pix_fmt_count_planes(s->picture_ptr->format));
+av_assert0(s->nb_components == av_pix_fmt_count_planes(frame->format));
 for (index=0; indexnb_components; index++) {
-uint8_t *dst = s->picture_ptr->data[index];
-int w = s->picture_ptr->width;
-int h = s->picture_ptr->height;
-if(index && index<3){
-w = AV_CEIL_RSHIFT(w, hshift);
+int h = frame->height;
+if (index && index < 3)
 h = AV_CEIL_RSHIFT(h, vshift);
-}
-if(dst){
-uint8_t *dst2 = dst + s->picture_ptr->linesize[index]*(h-1);
-for (i=0; ipicture_ptr->linesize[index];
-dst2 -= s->picture_ptr->linesize[index];
-}
+if (frame->data[index]) {
+frame->data[index] += (h - 1) * frame->linesize[index];
+frame->linesize[index] *= -1;
 }
 }
 }

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

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


[FFmpeg-cvslog] tests/checkasm: add a test for VorbisDSPContext

2022-09-19 Thread James Almer
ffmpeg | branch: master | James Almer  | Mon Sep 19 13:56:34 
2022 -0300| [8f119b501eaa1d813ea57b2dfc545d1e114f19a1] | committer: James Almer

tests/checkasm: add a test for VorbisDSPContext

Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8f119b501eaa1d813ea57b2dfc545d1e114f19a1
---

 tests/checkasm/Makefile|  1 +
 tests/checkasm/checkasm.c  |  3 ++
 tests/checkasm/checkasm.h  |  1 +
 tests/checkasm/vorbisdsp.c | 87 ++
 tests/fate/checkasm.mak|  1 +
 5 files changed, 93 insertions(+)

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 1ac170491b..ac02670e64 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -31,6 +31,7 @@ AVCODECOBJS-$(CONFIG_HEVC_DECODER)  += hevc_add_res.o 
hevc_idct.o hevc_sao.o
 AVCODECOBJS-$(CONFIG_UTVIDEO_DECODER)   += utvideodsp.o
 AVCODECOBJS-$(CONFIG_V210_DECODER)  += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)  += v210enc.o
+AVCODECOBJS-$(CONFIG_VORBIS_DECODER)+= vorbisdsp.o
 AVCODECOBJS-$(CONFIG_VP9_DECODER)   += vp9dsp.o
 
 CHECKASMOBJS-$(CONFIG_AVCODEC)  += $(AVCODECOBJS-yes)
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index e56fd3850e..6b4a0f22b2 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -165,6 +165,9 @@ static const struct {
 #if CONFIG_VIDEODSP
 { "videodsp", checkasm_check_videodsp },
 #endif
+#if CONFIG_VORBIS_DECODER
+{ "vorbisdsp", checkasm_check_vorbisdsp },
+#endif
 #endif
 #if CONFIG_AVFILTER
 #if CONFIG_AFIR_FILTER
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index d7645d3730..171dd06b47 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -88,6 +88,7 @@ void checkasm_check_vf_threshold(void);
 void checkasm_check_vp8dsp(void);
 void checkasm_check_vp9dsp(void);
 void checkasm_check_videodsp(void);
+void checkasm_check_vorbisdsp(void);
 
 struct CheckasmPerf;
 
diff --git a/tests/checkasm/vorbisdsp.c b/tests/checkasm/vorbisdsp.c
new file mode 100644
index 00..b055742519
--- /dev/null
+++ b/tests/checkasm/vorbisdsp.c
@@ -0,0 +1,87 @@
+/*
+ * 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 "config.h"
+
+#include 
+
+#include "libavutil/mem_internal.h"
+
+#include "libavcodec/vorbisdsp.h"
+
+#include "checkasm.h"
+
+#define LEN 512
+
+#define randomize_buffer(buf) \
+do {  \
+double bmg[2], stddev = 10.0, mean = 0.0; \
+  \
+for (int i = 0; i < LEN; i += 2) {\
+av_bmg_get(&checkasm_lfg, bmg);   \
+buf[i] = bmg[0] * stddev + mean;  \
+buf[i + 1] = bmg[1] * stddev + mean;  \
+} \
+} while(0);
+
+static void test_inverse_coupling(void)
+{
+LOCAL_ALIGNED_16(float, src0,  [LEN]);
+LOCAL_ALIGNED_16(float, src1,  [LEN]);
+LOCAL_ALIGNED_16(float, cdst,  [LEN]);
+LOCAL_ALIGNED_16(float, odst,  [LEN]);
+LOCAL_ALIGNED_16(float, cdst1, [LEN]);
+LOCAL_ALIGNED_16(float, odst1, [LEN]);
+
+declare_func(void, float *av_restrict mag, float *av_restrict ang,
+ ptrdiff_t blocksize);
+
+randomize_buffer(src0);
+randomize_buffer(src1);
+
+memcpy(cdst,  src0, LEN * sizeof(*src0));
+memcpy(cdst1, src1, LEN * sizeof(*src1));
+memcpy(odst,  src0, LEN * sizeof(*src0));
+memcpy(odst1, src1, LEN * sizeof(*src1));
+
+call_ref(cdst, cdst1, LEN);
+call_new(odst, odst1, LEN);
+for (int i = 0; i < LEN; i++) {
+if (!float_near_abs_eps(cdst[i],  odst[i],  FLT_EPSILON) ||
+!float_near_abs_eps(cdst1[i], odst1[i], FLT_EPSILON)) {
+fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
+i, cdst[i], odst[i], cdst[i] - odst[i]);
+fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n",
+i, cdst1[i], odst1[i], cdst1[i] - odst1[i]);
+fail();
+break;
+}
+}
+bench_new(src0, src1, LEN);
+}
+
+void checkasm_check_vorbisdsp(void)
+{
+VorbisDSPContext dsp;
+
+ff_vorbisdsp_init(&dsp);
+
+if (check_func(dsp.vorbis_inverse_coupling