这是我的搜索功能:
gboolean seek(CustomData* data)
{
gint64 position;
GstFormat format = GST_FORMAT_TIME;
GstEvent *seek_event;
/* Obtain the current position, needed for the seek event */
if (!gst_element_query_position(data->pipeline, &format, &position))
{
g_printerr("Unable to retrieve current position.\n");
return FALSE;
}
/* Create the seek event */
if (data->rate > 0)
{
seek_event = gst_event_new_seek(data->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, GST_SEEK_TYPE_SET,
position, GST_SEEK_TYPE_NONE, 0);
}
else if (data->rate < 0)
{
seek_event = gst_event_new_seek(data->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, GST_SEEK_TYPE_SET, 0,
GST_SEEK_TYPE_SET, position);
}
else
{
g_printerr("Rate is set to 0.\n");
return FALSE;
}
/* Check that seek_event was created */
if (seek_event == NULL) {
g_printerr("Could not create seek event.\n");
return FALSE;
}
/* Send the event */
if (!gst_element_send_event(data->autovideosink, seek_event))
{
g_printerr("Could not perform seek event.\n");
return FALSE;
}
g_print("Current rate: %gx\n", data->rate);
return TRUE;
}
但它无法发送 seek 事件。这段代码只是从 GStreamer 教程中稍微修改了一下,但我正在播放一个 .vob 文件,并且我有一个自定义管道而不是 playbin2。我也在使用appsrc,所以我从文件中提供缓冲区,但我不认为这会导致快速转发出现任何问题。但是,我不能向前或向后寻找(将速率设置为 2x 或 .5x 在同一位置失败)。