How to seek in frames and schedule a schedule a single shot clock id correctly

Marcus Nascimento marcus.cps at gmail.com
Thu Nov 7 09:21:36 PST 2013


I'm trying to create a media player that must supports the following
features:

- Set Start and/or End position using TIME (timestamp);
- Set Start and/or End position using SAMPLE (for audio only);
- Set Start and/or End position using FRAME (for video only);
- Schedule a notification in a given TIME (timestamp);
- Schedule a notification in a given SAMPLE (for audio only);
- Schedule a notification in a given FRAME (for video only).


It is easy to do things when the Start position where set using the same
unit as the notification (both using TIME or SAMPLE or FRAME).
I managed to find a way to convert SAMPLE# to TIME and vice versa (the
opposit).
Notice the END position doesn't really matter.

But when I try to set the Start position in FRAMEs and schedule a
notification in TIME, it gets complicated, since I can't get the base time
to schedule the notification.

I couldn't also make it work when I set the Start position in TIME and
schedule a notification in FRAMEs. I can't find which is the frame
corresponding to the Start position.

Does anyone know whether it is possible to do that?

Here is how I do things:

This is how I set the END position:

gst_element_seek(pipeline, 1.0, endPosFormat,
(GstSeekFlags)(GST_SEEK_FLAG_FLUSH |
GST_SEEK_FLAG_ACCURATE), GST_SEEK_TYPE_NONE, 0, GST_SEEK_TYPE_SET,
endPosition);


This is how I set the START position:

gst_element_seek(pipeline, 1.0, startPosFormat,
(GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE),
GST_SEEK_TYPE_SET, startPosition, GST_SEEK_TYPE_NONE, 0);


startPostFormat and endPosFormat = FST_FORMAT_TIME for TIME.
startPostFormat and endPosFormat = GST_FORMAT_DEFAULT for SAMPLEs or FRAMEs.


1) When setting the Start position in TIME, I do this:

- Set the start time using the seek instruction above.
- gst_element_set_start_time(pipeline, GST_CLOCK_TIME_NONE);
- gst_element_set_base_time(pipeline, startPosition);


2) When setting the Start position in SAMPLEs, I do this:

- Set the start sample using the seek instruction above
- Convert the startPosition from SAMPLE to TIME using the RATE (got from
the caps from the sink pad of the audio-sink element).
- gst_element_set_start_time(pipeline, GST_CLOCK_TIME_NONE);
- gst_element_set_base_time(pipeline, startPosition);


3) When setting the Start position in FRAMEs, I do this:

- Set the start frame using the seek instruction above.
- I can't find a corresponding TIME for this FRAME, since I can't find a
FRAME RATE nor can guarantee it would be constant. Is it possible?


4) When scheduling a TIME notification, I do this:

- GstClock *clock = gst_pipeline_get_clock(GST_PIPELINE(pipeline));
- GstClockID *clockId = gst_clock_new_single_shot_id(clock, timeInNanoSecs);
- gst_clock_id_wait_async(clockId, MyCallback, NULL);


5) When scheduling a SAMPLE notification, I do this:

- Convert SAMPLE to TIME using the same procedure described in 2.
- Schedule the notification using the same procedure described in 4.


6) When scheduling a FRAME notification, I do this:

- Create a pad probe in the sink pad of the videosink element, using
gst_pad_add_buffer_probe.
- probeCounter = startPosition // Frame #.
- In the probe callback, I always increment the probeCounter and check if
it is greater or equal to target frame. If so, I call the notification
function.


Thanks very much,

-- 
Marcus Nascimento
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20131107/c6b2a3e2/attachment.html>


More information about the gstreamer-devel mailing list