dvdemux: don't screw up first audio buffer

Query the audio format, esp. dvdemux->num_channels, before we use that
variable to allocate the initial buffer. That way we don't accidentally
push a zero-sized buffer as first audio buffer.
This commit is contained in:
Tim-Philipp Müller 2009-06-18 23:43:49 +01:00
parent 6c6e96becd
commit 42936a73e6

View file

@ -1235,30 +1235,10 @@ gst_dvdemux_demux_audio (GstDVDemux * dvdemux, GstBuffer * buffer,
GstBuffer *outbuf;
gint frequency, channels;
outbuf = gst_buffer_new_and_alloc (num_samples *
sizeof (gint16) * dvdemux->channels);
a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf);
for (i = 0; i < num_samples; i++) {
for (j = 0; j < dvdemux->channels; j++) {
*(a_ptr++) = dvdemux->audio_buffers[j][i];
}
}
GST_DEBUG ("pushing audio %" GST_TIME_FORMAT,
GST_TIME_ARGS (dvdemux->time_segment.last_stop));
GST_BUFFER_TIMESTAMP (outbuf) = dvdemux->time_segment.last_stop;
GST_BUFFER_DURATION (outbuf) = duration;
GST_BUFFER_OFFSET (outbuf) = dvdemux->audio_offset;
dvdemux->audio_offset += num_samples;
GST_BUFFER_OFFSET_END (outbuf) = dvdemux->audio_offset;
if (!dvdemux->audiosrcpad)
gst_dvdemux_add_audio_pad (dvdemux);
/* check if format changed */
/* get initial format or check if format changed */
frequency = dv_get_frequency (dvdemux->decoder);
channels = dv_get_num_channels (dvdemux->decoder);
@ -1280,6 +1260,26 @@ gst_dvdemux_demux_audio (GstDVDemux * dvdemux, GstBuffer * buffer,
gst_caps_unref (caps);
}
outbuf = gst_buffer_new_and_alloc (num_samples *
sizeof (gint16) * dvdemux->channels);
a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf);
for (i = 0; i < num_samples; i++) {
for (j = 0; j < dvdemux->channels; j++) {
*(a_ptr++) = dvdemux->audio_buffers[j][i];
}
}
GST_DEBUG ("pushing audio %" GST_TIME_FORMAT,
GST_TIME_ARGS (dvdemux->time_segment.last_stop));
GST_BUFFER_TIMESTAMP (outbuf) = dvdemux->time_segment.last_stop;
GST_BUFFER_DURATION (outbuf) = duration;
GST_BUFFER_OFFSET (outbuf) = dvdemux->audio_offset;
dvdemux->audio_offset += num_samples;
GST_BUFFER_OFFSET_END (outbuf) = dvdemux->audio_offset;
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (dvdemux->audiosrcpad));
ret = gst_pad_push (dvdemux->audiosrcpad, outbuf);