2005-09-24 14:14:03 +00:00
|
|
|
Segments
|
|
|
|
--------
|
|
|
|
|
|
|
|
A segment in GStreamer denotes a set of media samples that must be
|
|
|
|
processed. A segment has a start time, a stop time and a processing
|
|
|
|
rate.
|
|
|
|
|
|
|
|
A media stream has a start and a stop time. The start time is
|
2005-10-21 15:13:08 +00:00
|
|
|
always 0 and the stop time is the total duration (or -1 if unknown,
|
|
|
|
for example a live stream). We call this the complete media stream.
|
2005-09-24 14:14:03 +00:00
|
|
|
|
|
|
|
The segment of the complete media stream can be played by issuing a seek
|
|
|
|
on the stream. The seek has a start time, a stop time and a processing rate.
|
|
|
|
|
|
|
|
|
|
|
|
complete stream
|
|
|
|
+------------------------------------------------+
|
|
|
|
0 duration
|
|
|
|
segment
|
|
|
|
|--------------------------|
|
|
|
|
start stop
|
|
|
|
|
|
|
|
|
|
|
|
The playback of a segment starts with a source or demuxer element pushing a
|
2011-06-06 14:11:31 +00:00
|
|
|
segment event containing the start time, stop time and rate of the segment.
|
|
|
|
The purpose of this segment is to inform downstream elements of the
|
2005-09-24 14:14:03 +00:00
|
|
|
requested segment positions. Some elements might produce buffers that fall
|
|
|
|
outside of the segment and that might therefore be discarded or clipped.
|
|
|
|
|
2005-10-21 15:13:08 +00:00
|
|
|
|
|
|
|
Use case: FLUSHING seek
|
2010-11-01 13:32:43 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
2005-10-21 15:13:08 +00:00
|
|
|
|
2005-09-24 14:14:03 +00:00
|
|
|
ex.
|
|
|
|
|
|
|
|
filesrc ! avidemux ! videodecoder ! videosink
|
|
|
|
|
2005-10-21 15:13:08 +00:00
|
|
|
When doing a seek in this pipeline for a segment 1 to 5 seconds, avidemux
|
|
|
|
will perform the seek.
|
|
|
|
|
2008-10-13 17:19:25 +00:00
|
|
|
Avidemux starts by sending a FLUSH_START event downstream and upstream. This
|
|
|
|
will cause its streaming task to PAUSED because _pad_pull_range() and
|
2012-05-11 07:07:16 +00:00
|
|
|
_pad_push() will return FLUSHING. It then waits for the STREAM_LOCK,
|
2008-10-13 17:19:25 +00:00
|
|
|
which will be unlocked when the streaming task pauses. At this point no
|
|
|
|
streaming is happening anymore in the pipeline and a FLUSH_STOP is sent
|
|
|
|
upstream and downstream.
|
|
|
|
|
2005-09-24 14:14:03 +00:00
|
|
|
When avidemux starts playback of the segment from second 1 to 5, it pushes
|
2011-06-06 14:11:31 +00:00
|
|
|
out a segment with 1 and 5 as start and stop times. The stream_time in
|
|
|
|
the segment is also 1 as this is the position we seek to.
|
2005-09-24 14:14:03 +00:00
|
|
|
|
|
|
|
The video decoder stores these values internally and forwards them to the
|
|
|
|
next downstream element (videosink, which also stores the values)
|
|
|
|
|
|
|
|
Since second 1 does not contain a keyframe, the avi demuxer starts sending
|
|
|
|
data from the previous keyframe which is at timestamp 0.
|
|
|
|
|
|
|
|
The video decoder decodes the keyframe but knows it should not push the
|
|
|
|
video frame yet as it falls outside of the configured segment.
|
|
|
|
|
|
|
|
When the video decoder receives the frame with timestamp 1, it is able to
|
|
|
|
decode this frame as it received and decoded the data up to the previous
|
|
|
|
keyframe. It then continues to decode and push frames with timestamps >= 1.
|
|
|
|
When it reaches timestamp 5, it does not decode and push frames anymore.
|
|
|
|
|
2005-10-21 15:13:08 +00:00
|
|
|
The video sink receives a frame of timestamp 1. It takes the start value of
|
2012-07-04 15:16:04 +00:00
|
|
|
the previous segment and aplies the following (simplified) formula:
|
2005-10-21 15:13:08 +00:00
|
|
|
|
|
|
|
render_time = BUFFER_TIMESTAMP - segment_start + element->base_time
|
|
|
|
|
2008-10-13 17:19:25 +00:00
|
|
|
It then syncs against the clock with this render_time. Note that
|
2005-10-21 15:13:08 +00:00
|
|
|
BUFFER_TIMESTAMP is always >= segment_start or else it would fall outside of
|
|
|
|
the configure segment.
|
|
|
|
|
2008-10-13 17:19:25 +00:00
|
|
|
Videosink reports its current position as (simplified):
|
2005-10-21 15:13:08 +00:00
|
|
|
|
|
|
|
current_position = clock_time - element->base_time + segment_time
|
|
|
|
|
2008-10-13 17:19:25 +00:00
|
|
|
See part-synchronisation.txt for a more detailed and accurate explanation of
|
|
|
|
synchronisation and position reporting.
|
|
|
|
|
2005-10-21 15:13:08 +00:00
|
|
|
Since after a flushing seek the stream_time is reset to 0, the new buffer
|
2011-01-19 15:48:26 +00:00
|
|
|
will be rendered immediately after the seek and the current_position will be
|
2005-10-21 15:13:08 +00:00
|
|
|
the stream_time of the seek that was performed.
|
|
|
|
|
2005-09-24 14:14:03 +00:00
|
|
|
The stop time is important when the video format contains B frames. The
|
2012-05-24 10:48:19 +00:00
|
|
|
video decoder receives a P frame first, which it can decode but not push yet.
|
2005-09-24 14:14:03 +00:00
|
|
|
When it receives a B frame, it can decode the B frame and push the B frame
|
|
|
|
followed by the previously decoded P frame. If the P frame is outside of the
|
|
|
|
segment, the decoder knows it should not send the P frame.
|
|
|
|
|
2007-09-24 11:22:26 +00:00
|
|
|
Avidemux stops sending data after pushing a frame with timestamp 5 and
|
2012-01-14 18:16:01 +00:00
|
|
|
returns GST_FLOW_EOS from the chain function to make the upstream
|
2007-09-24 11:22:26 +00:00
|
|
|
elements perform the EOS logic.
|
2005-09-24 14:14:03 +00:00
|
|
|
|
|
|
|
|
2005-10-21 15:13:08 +00:00
|
|
|
Use case: live stream
|
2010-11-01 13:32:43 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
2005-10-21 15:13:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Use case: segment looping
|
2010-11-01 13:32:43 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
2005-10-21 15:13:08 +00:00
|
|
|
|
|
|
|
Consider the case of a wav file with raw audio.
|
|
|
|
|
|
|
|
filesrc ! wavparse ! alsasink
|
2005-09-24 14:14:03 +00:00
|
|
|
|