gst/mpegaudioparse/gstmpegaudioparse.*: Make timestamp handling in mp3parse saner; now works for at least simple cases.

Original commit message from CVS:
* gst/mpegaudioparse/gstmpegaudioparse.c:
(mp3_type_frame_length_from_header), (gst_mp3parse_reset),
(gst_mp3parse_init), (gst_mp3parse_dispose),
(gst_mp3parse_sink_event), (gst_mp3parse_chain), (head_check),
(gst_mp3parse_change_state):
* gst/mpegaudioparse/gstmpegaudioparse.h:
Make timestamp handling in mp3parse saner; now works for at least
simple cases.
This commit is contained in:
Michael Smith 2006-11-13 17:01:15 +00:00
parent 13ecca8090
commit 3b792adbec
3 changed files with 41 additions and 19 deletions

View file

@ -1,3 +1,14 @@
2006-11-13 Michael Smith <msmith@fluendo.com>
* gst/mpegaudioparse/gstmpegaudioparse.c:
(mp3_type_frame_length_from_header), (gst_mp3parse_reset),
(gst_mp3parse_init), (gst_mp3parse_dispose),
(gst_mp3parse_sink_event), (gst_mp3parse_chain), (head_check),
(gst_mp3parse_change_state):
* gst/mpegaudioparse/gstmpegaudioparse.h:
Make timestamp handling in mp3parse saner; now works for at least
simple cases.
2006-11-13 Michael Smith <msmith@fluendo.com> 2006-11-13 Michael Smith <msmith@fluendo.com>
* gst/mpegaudioparse/Makefile.am: * gst/mpegaudioparse/Makefile.am:

View file

@ -109,13 +109,17 @@ gst_mp3parse_get_type (void)
return mp3parse_type; return mp3parse_type;
} }
static guint mp3types_bitrates[2][3][16] = static guint mp3types_bitrates[2][3][16] = {
{ {{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,}, {
{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,}, {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}}, {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}
{{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,}, },
{
{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}, {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}}, {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}
},
}; };
static guint mp3types_freqs[3][3] = { {44100, 48000, 32000}, static guint mp3types_freqs[3][3] = { {44100, 48000, 32000},
@ -240,6 +244,8 @@ gst_mp3parse_reset (GstMPEGAudioParse * mp3parse)
{ {
mp3parse->skip = 0; mp3parse->skip = 0;
mp3parse->resyncing = TRUE; mp3parse->resyncing = TRUE;
mp3parse->next_ts = -1;
mp3parse->last_ts = -1;
gst_adapter_clear (mp3parse->adapter); gst_adapter_clear (mp3parse->adapter);
@ -296,11 +302,8 @@ gst_mp3parse_sink_event (GstPad * pad, GstEvent * event)
gst_event_parse_new_segment (event, NULL, NULL, &format, NULL, NULL, gst_event_parse_new_segment (event, NULL, NULL, &format, NULL, NULL,
NULL); NULL);
if (format != GST_FORMAT_TIME)
mp3parse->next_ts = 0;
else
/* we will be receiving timestamps */
mp3parse->next_ts = -1; mp3parse->next_ts = -1;
mp3parse->last_ts = -1;
break; break;
} }
default: default:
@ -331,11 +334,10 @@ gst_mp3parse_chain (GstPad * pad, GstBuffer * buf)
timestamp = GST_BUFFER_TIMESTAMP (buf); timestamp = GST_BUFFER_TIMESTAMP (buf);
if (GST_CLOCK_TIME_IS_VALID (timestamp)) { /* If we don't yet have a next timestamp, and this is valid, use it */
GST_DEBUG_OBJECT (mp3parse, "Using incoming timestamp of %" GST_TIME_FORMAT, if (!GST_CLOCK_TIME_IS_VALID (mp3parse->next_ts) &&
GST_TIME_ARGS (timestamp)); GST_CLOCK_TIME_IS_VALID (timestamp))
mp3parse->next_ts = timestamp; mp3parse->next_ts = timestamp;
}
gst_adapter_push (mp3parse->adapter, buf); gst_adapter_push (mp3parse->adapter, buf);
@ -441,8 +443,6 @@ gst_mp3parse_chain (GstPad * pad, GstBuffer * buf)
GST_DEBUG_OBJECT (mp3parse, "pushing buffer of %d bytes", GST_DEBUG_OBJECT (mp3parse, "pushing buffer of %d bytes",
GST_BUFFER_SIZE (outbuf)); GST_BUFFER_SIZE (outbuf));
GST_BUFFER_TIMESTAMP (outbuf) = mp3parse->next_ts;
/* see http://www.codeproject.com/audio/MPEGAudioInfo.asp */ /* see http://www.codeproject.com/audio/MPEGAudioInfo.asp */
if (mp3parse->layer == 1) if (mp3parse->layer == 1)
spf = 384; spf = 384;
@ -456,7 +456,17 @@ gst_mp3parse_chain (GstPad * pad, GstBuffer * buf)
} }
GST_BUFFER_DURATION (outbuf) = spf * GST_SECOND / mp3parse->rate; GST_BUFFER_DURATION (outbuf) = spf * GST_SECOND / mp3parse->rate;
mp3parse->next_ts += GST_BUFFER_DURATION (outbuf); if (GST_CLOCK_TIME_IS_VALID (mp3parse->next_ts)) {
GST_BUFFER_TIMESTAMP (outbuf) = mp3parse->next_ts;
mp3parse->next_ts = GST_CLOCK_TIME_NONE;
} else if (GST_CLOCK_TIME_IS_VALID (mp3parse->last_ts)) {
GST_BUFFER_TIMESTAMP (outbuf) = mp3parse->last_ts +
GST_BUFFER_DURATION (outbuf);
} else {
GST_BUFFER_TIMESTAMP (outbuf) = 0;
}
mp3parse->last_ts = GST_BUFFER_TIMESTAMP (outbuf);
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mp3parse->srcpad)); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (mp3parse->srcpad));

View file

@ -46,6 +46,7 @@ struct _GstMPEGAudioParse {
GstPad *sinkpad,*srcpad; GstPad *sinkpad,*srcpad;
GstClockTime last_ts;
GstClockTime next_ts; GstClockTime next_ts;
GstAdapter *adapter; GstAdapter *adapter;