midiparse: duration is max of all track durations

This commit is contained in:
Wim Taymans 2013-03-21 16:05:00 +01:00
parent 7498d104a7
commit adae7f1859

View file

@ -631,6 +631,7 @@ parse_MTrk (GstMidiParse * midiparse, guint8 * data, guint size)
{ {
GstMidiTrack *track; GstMidiTrack *track;
GstMidiCallbacks cb = { NULL, NULL, NULL }; GstMidiCallbacks cb = { NULL, NULL, NULL };
GstClockTime duration;
/* ignore excess tracks */ /* ignore excess tracks */
if (midiparse->track_count >= midiparse->ntracks) if (midiparse->track_count >= midiparse->ntracks)
@ -649,11 +650,14 @@ parse_MTrk (GstMidiParse * midiparse, guint8 * data, guint size)
handle_next_event (midiparse, track, &cb, NULL); handle_next_event (midiparse, track, &cb, NULL);
} }
midiparse->segment.duration = gst_util_uint64_scale (track->pulse, duration = gst_util_uint64_scale (track->pulse,
1000 * midiparse->tempo, midiparse->division); 1000 * midiparse->tempo, midiparse->division);
GST_DEBUG_OBJECT (midiparse, "duration %" GST_TIME_FORMAT, GST_DEBUG_OBJECT (midiparse, "duration %" GST_TIME_FORMAT,
GST_TIME_ARGS (midiparse->segment.duration)); GST_TIME_ARGS (duration));
if (duration > midiparse->segment.duration)
midiparse->segment.duration = duration;
reset_track (midiparse, track); reset_track (midiparse, track);
@ -796,6 +800,7 @@ gst_midi_parse_parse_song (GstMidiParse * midiparse)
GST_DEBUG_OBJECT (midiparse, "Parsing song"); GST_DEBUG_OBJECT (midiparse, "Parsing song");
gst_segment_init (&midiparse->segment, GST_FORMAT_TIME); gst_segment_init (&midiparse->segment, GST_FORMAT_TIME);
midiparse->segment.duration = 0;
midiparse->pulse = 0; midiparse->pulse = 0;
size = gst_adapter_available (midiparse->adapter); size = gst_adapter_available (midiparse->adapter);
@ -817,6 +822,9 @@ gst_midi_parse_parse_song (GstMidiParse * midiparse)
length -= consumed; length -= consumed;
} }
GST_DEBUG_OBJECT (midiparse, "song duration %" GST_TIME_FORMAT,
GST_TIME_ARGS (midiparse->segment.duration));
outcaps = gst_pad_get_pad_template_caps (midiparse->srcpad); outcaps = gst_pad_get_pad_template_caps (midiparse->srcpad);
gst_pad_set_caps (midiparse->srcpad, outcaps); gst_pad_set_caps (midiparse->srcpad, outcaps);
gst_caps_unref (outcaps); gst_caps_unref (outcaps);