Merge branch '2_5_to_2_6_bug_107'
[vuplus_dvbapp] / lib / service / servicemp3.cpp
index af9e1d3..e1bf23d 100644 (file)
@@ -193,7 +193,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
        m_seekTimeout = eTimer::create(eApp);
        m_subtitle_sync_timer = eTimer::create(eApp);
        m_stream_tags = 0;
-       m_currentAudioStream = 0;
+       m_currentAudioStream = -1;
        m_currentSubtitleStream = 0;
        m_subtitle_widget = 0;
        m_currentTrickRatio = 0;
@@ -301,7 +301,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
                eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
        else
        {
-               g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
+               m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
                g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
        }
 
@@ -334,16 +334,28 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
                m_gst_playbin = 0;
        }
 
-       gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
        setBufferSize(m_buffer_size);
 }
 
 eServiceMP3::~eServiceMP3()
 {
+       // disconnect subtitle callback
+       GstElement *sink;
+       g_object_get (G_OBJECT (m_gst_playbin), "text-sink", &sink, NULL);
+       if (sink)
+       {
+               g_signal_handler_disconnect (sink, m_subs_to_pull_handler_id);
+               gst_object_unref(sink);
+       }
+
        delete m_subtitle_widget;
+
+       // disconnect sync handler callback
+       gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), NULL, NULL);
+
        if (m_state == stRunning)
                stop();
-       
+
        if (m_stream_tags)
                gst_tag_list_free(m_stream_tags);
        
@@ -354,7 +366,7 @@ eServiceMP3::~eServiceMP3()
        }
 }
 
-DEFINE_REF(eServiceMP3);       
+DEFINE_REF(eServiceMP3);
 
 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
 {
@@ -365,25 +377,30 @@ RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event,
 RESULT eServiceMP3::start()
 {
        ASSERT(m_state == stIdle);
-       
+
        m_state = stRunning;
        if (m_gst_playbin)
        {
                eDebug("eServiceMP3::starting pipeline");
                gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
        }
+
        m_event(this, evStart);
+
        return 0;
 }
 
 RESULT eServiceMP3::stop()
 {
        ASSERT(m_state != stIdle);
+
        if (m_state == stStopped)
                return -1;
+
        eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
        gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
        m_state = stStopped;
+
        return 0;
 }
 
@@ -944,6 +961,8 @@ int eServiceMP3::getNumberOfTracks()
 
 int eServiceMP3::getCurrentTrack()
 {
+       if (m_currentAudioStream == -1)
+               g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
        return m_currentAudioStream;
 }