原文:Basic tutorial 4: Time management (gstreamer.freedesktop.org)
目标
本教程展示了如何使用与GStreamer时间相关的工具。特别是:
- 如何查询pipeline信息,如流位置或持续时间。
- 如何查找(跳转)到流中的不同位置(时间)。
介绍
GstQuery是一种允许向element或pad查询信息的机制。在这个例子中,我们查询pipeline是否允许seek(一些源,比如实时流,不允许查找)。如果允许,那么,一旦电影播放了十秒钟,我们就使用seek跳到另一个位置。
在前面的教程中,一旦我们设置并运行了pipeline,我们的main函数就会等待通过总线接收ERROR或EOS。这里,我们修改了这个函数,让它定期唤醒并查询pipeline中的流位置,这样我们就可以在屏幕上打印它。这类似于媒体播放器所做的,定期更新用户界面。
最后,查询流持续时间并在其更改时进行更新。
Seek示例
#include <gst/gst.h>
/* Structure to contain all our information, so we can pass it around */
typedef struct _CustomData
{
GstElement *playbin; /* Our one and only element */
gboolean playing; /* Are we in the PLAYING state? */
gboolean terminate; /* Should we terminate execution? */
gboolean seek_enabled; /* Is seeking enabled for this media? */
gboolean seek_done; /* Have we performed the seek already? */
gint64 duration; /* How long does this media last, in nanoseconds */
} CustomData;
/* Forward definition of the message processing function */
static void handle_message (CustomData * data, GstMessage * msg);
int
main (int argc, char *argv[])
{
CustomData data;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
data.playing = FALSE;
data.terminate = FALSE;
data.seek_enabled = FALSE;
data.seek_done = FALSE;
data.duration = GST_CLOCK_TIME_NONE;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
data.playbin = gst_element_factory_make ("playbin", "playbin");
if (!data.playbin) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
/* Set the URI to play */
g_object_set (data.playbin, "uri",
"https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm",
NULL);
/* Start playing */
ret = gst_element_set_state (data.playbin, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (data.playbin);
return -1;
}
/* Listen to the bus */
bus = gst_element_get_bus (data.playbin);
do {
msg = gst_bus_timed_pop_filtered (bus, 100 * GST_MSECOND,
GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS |
GST_MESSAGE_DURATION);
/* Parse message */
if (msg != NULL) {
handle_message (&data, msg);
} else {

——基础教程4:时间管理&spm=1001.2101.3001.5002&articleId=135572399&d=1&t=3&u=1eaa38345fac40ba803483826f3984af)
1342

被折叠的 条评论
为什么被折叠?



