1
0
mirror of https://git.ffmpeg.org/ffmpeg.git synced 2026-10-24 02:09:03 +03:00

avcodec/libspeexenc: preserve the encoded packet size

ff_af_queue_remove() now returns a status code. Its return value
replaced the byte count from speex_bits_write(), so every successful
encode emitted an empty packet.

Store the encoded byte count in the packet before updating its timing.
Add generated-input FATE coverage for mono and stereo encoding, including
multiple frames per packet. Check decoded frame counts instead of exact
encoded bytes so the tests do not depend on libspeex's implementation.
Select the PCM decoder dependency for the target endianness because
lavfi exposes native-endian audio.

Fixes: c31a781412
Fixes: #23926
Assisted-by: Fairy
This commit is contained in:
Michael Niedermayer
2026-09-25 16:37:36 +00:00
committed by michaelni
parent c7454d8df7
commit c0c7684d08
4 changed files with 28 additions and 2 deletions

View File

@@ -292,7 +292,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
s->pkt_frame_count = 0;
if ((ret = ff_alloc_packet(avctx, avpkt, speex_bits_nbytes(&s->bits))) < 0)
return ret;
ret = speex_bits_write(&s->bits, avpkt->data, avpkt->size);
avpkt->size = speex_bits_write(&s->bits, avpkt->data, avpkt->size);
speex_bits_reset(&s->bits);
/* Get the next frame pts/duration */
@@ -301,7 +301,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (ret < 0)
return ret;
avpkt->size = ret;
*got_packet_ptr = 1;
return 0;
}

View File

@@ -14,3 +14,18 @@ fate-libx264-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sa
FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes)
fate-enc-external: $(FATE_ENC_EXTERNAL-yes)
# Check decoded frame counts without depending on libspeex's encoded bytes.
FATE_LIBSPEEX-$(call ALLYES, LIBSPEEX_ENCODER SPEEX_DECODER OGG_MUXER OGG_DEMUXER LAVFI_INDEV SINE_FILTER ARESAMPLE_FILTER \
PCM_S16$(if $(filter yes,$(HAVE_BIGENDIAN)),BE,LE)_DECODER FILE_PROTOCOL) += fate-libspeex-encode fate-libspeex-encode-stereo
fate-libspeex-encode: SPEEX_OPTS = -ac 1
fate-libspeex-encode-stereo: SPEEX_OPTS = -ac 2 -frames_per_packet 2
$(FATE_LIBSPEEX-yes): CMD = run_with_temp \
"$(FFMPEG) -nostdin -hide_banner -loglevel error \
-f lavfi -i sine=frequency=1000:sample_rate=32000:duration=1 \
-c:a libspeex -b:a 30k $(SPEEX_OPTS) -f ogg -y" \
"ffprobe$(PROGSSUF)$(EXESUF) -v error -bitexact -count_frames \
-show_entries stream=codec_name,sample_rate,channels,nb_read_frames" ogg
FATE_FFMPEG_FFPROBE += $(FATE_LIBSPEEX-yes)
fate-enc-external: $(FATE_LIBSPEEX-yes)

View File

@@ -0,0 +1,6 @@
[STREAM]
codec_name=speex
sample_rate=32000
channels=1
nb_read_frames=50
[/STREAM]

View File

@@ -0,0 +1,6 @@
[STREAM]
codec_name=speex
sample_rate=32000
channels=2
nb_read_frames=25
[/STREAM]