2014-11-01 37 views
1

我有一個應用程序正在讀取一個電影文件,並且我想在到達流末尾時重置流到其初始位置。如何通過GMainLoop訪問管道?

所以我已經得到了以往的結構,我添加了一個總線觀看事件

bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); 
gst_bus_add_watch (bus, bus_call, loop); 
gst_object_unref (bus); 

這裏是bus_call功能

static gboolean bus_call (GstBus  *bus, 
         GstMessage *msg, 
         gpointer data) 
{ 
    GMainLoop *loop = (GMainLoop *) data; 

    switch (GST_MESSAGE_TYPE (msg)) 
    { 
    case GST_MESSAGE_EOS: 
     g_print ("End of stream\n"); 
      g_main_loop_quit (loop); 
     break; 
    default: 
     break; 
    } 
    return TRUE; 
} 

左右的snipet現在,當我到達流的結束我剛剛退出循環。 我可以通過循環訪問我的管道嗎? 感謝您的閱讀,請讓我知道如果我試圖做一些不可能的事

ps:我想避免將我的管道設置爲全局變量,或傳遞給bus_call包含我的管道和循環的結構,因爲它感覺不對。

回答

1

我的目標是在到達尾流時自動倒帶。用戶然後可以點擊播放按鈕,再次播放。

所以我避開了這個問題,並修改了我的播放按鈕的回調函數。 現在它檢測當前流的位置,並將其與流的長度進行比較。

gint64 streamPosition, streamLength; 
GstFormat format = GST_FORMAT_TIME; 

gst_element_query_position (pipeline, &format, &streamPosition); 
gst_element_query_duration (pipeline, &format, &streamLength); 
if (streamPosition==streamLength) 
    stopIt(widget,pipeline); 

如果當前的流位置等於流的長度,這意味着我們在流的末尾。所以我打電話一個功能倒帶流....

感覺真的生澀,但這是我現在的「最佳」解決方案。

我仍然樂於接受建議。