mpg123audiodec: Correctly handle the case of clipping all decoded samples

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3365

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6360>
This commit is contained in:
Sebastian Dröge 2024-03-11 10:39:27 +02:00 committed by Tim-Philipp Müller
parent f04f86f3ee
commit eaffd61da6

View file

@ -321,6 +321,7 @@ gst_mpg123_audio_dec_push_decoded_bytes (GstMpg123AudioDec * mpg123_decoder,
{ {
GstBuffer *output_buffer; GstBuffer *output_buffer;
GstAudioDecoder *dec; GstAudioDecoder *dec;
GstMapInfo info;
output_buffer = NULL; output_buffer = NULL;
dec = GST_AUDIO_DECODER (mpg123_decoder); dec = GST_AUDIO_DECODER (mpg123_decoder);
@ -336,7 +337,7 @@ gst_mpg123_audio_dec_push_decoded_bytes (GstMpg123AudioDec * mpg123_decoder,
return GST_FLOW_OK; return GST_FLOW_OK;
} }
if (G_UNLIKELY (clip_end >= num_decoded_bytes)) { if (G_UNLIKELY (clip_start + clip_end >= num_decoded_bytes)) {
/* Fully-clipped frames still need to be finished, since they got /* Fully-clipped frames still need to be finished, since they got
* decoded properly, they are just made of padding samples. */ * decoded properly, they are just made of padding samples. */
GST_LOG_OBJECT (mpg123_decoder, "frame is fully clipped; " GST_LOG_OBJECT (mpg123_decoder, "frame is fully clipped; "
@ -351,24 +352,16 @@ gst_mpg123_audio_dec_push_decoded_bytes (GstMpg123AudioDec * mpg123_decoder,
output_buffer = gst_audio_decoder_allocate_output_buffer (dec, output_buffer = gst_audio_decoder_allocate_output_buffer (dec,
num_decoded_bytes); num_decoded_bytes);
if (output_buffer == NULL) { if (gst_buffer_map (output_buffer, &info, GST_MAP_WRITE)) {
/* This is necessary to advance playback in time, memcpy (info.data, decoded_bytes, num_decoded_bytes);
* even when nothing was decoded. */ gst_buffer_unmap (output_buffer, &info);
return gst_audio_decoder_finish_frame (dec, NULL, 1);
} else { } else {
GstMapInfo info; GST_ERROR_OBJECT (mpg123_decoder, "gst_buffer_map() returned NULL");
gst_buffer_unref (output_buffer);
if (gst_buffer_map (output_buffer, &info, GST_MAP_WRITE)) { output_buffer = NULL;
memcpy (info.data, decoded_bytes, num_decoded_bytes);
gst_buffer_unmap (output_buffer, &info);
} else {
GST_ERROR_OBJECT (mpg123_decoder, "gst_buffer_map() returned NULL");
gst_buffer_unref (output_buffer);
output_buffer = NULL;
}
return gst_audio_decoder_finish_frame (dec, output_buffer, 1);
} }
return gst_audio_decoder_finish_frame (dec, output_buffer, 1);
} }