Merge branch 'bug_747_cancel_waiting_tasks'
[enigma2.git] / lib / service / servicemp3.cpp
index 31ae9573e2757209cbe20ad44a600482fd0c2258..be55d0cd331c55008af6bcee317624ac2d46cd36 100644 (file)
@@ -1,5 +1,3 @@
-#ifdef HAVE_GSTREAMER
-
        /* note: this requires gstreamer 0.10.x and a big list of plugins. */
        /* it's currently hardcoded to use a big-endian alsasink as sink. */
 #include <lib/base/ebase.h>
        /* note: this requires gstreamer 0.10.x and a big list of plugins. */
        /* it's currently hardcoded to use a big-endian alsasink as sink. */
 #include <lib/base/ebase.h>
@@ -49,7 +47,6 @@ eServiceFactoryMP3::eServiceFactoryMP3()
                extensions.push_back("mp4");
                extensions.push_back("mov");
                extensions.push_back("m4a");
                extensions.push_back("mp4");
                extensions.push_back("mov");
                extensions.push_back("m4a");
-               extensions.push_back("m2ts");
                sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
        }
 
                sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
        }
 
@@ -231,6 +228,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
        m_buffer_size = 1*1024*1024;
        m_prev_decoder_time = -1;
        m_decoder_time_valid_state = 0;
        m_buffer_size = 1*1024*1024;
        m_prev_decoder_time = -1;
        m_decoder_time_valid_state = 0;
+       m_errorInfo.missing_codec = "";
 
        CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
        CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
 
        CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
        CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
@@ -330,7 +328,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
 
        m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
        if (!m_gst_playbin)
 
        m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
        if (!m_gst_playbin)
-               m_error_message = "failed to create GStreamer pipeline!\n";
+               m_errorInfo.error_message = "failed to create GStreamer pipeline!\n";
 
        g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
 
 
        g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
 
@@ -362,10 +360,10 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
                {
                        eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
                        g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
                {
                        eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
                        g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
-                       subtitleStream subs;
-                       subs.type = stSRT;
-                       subs.language_code = std::string("und");
-                       m_subtitleStreams.push_back(subs);
+               }
+               if ( m_sourceinfo.is_streaming )
+               {
+                       g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
                }
        } else
        {
                }
        } else
        {
@@ -374,7 +372,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
                if (m_gst_playbin)
                        gst_object_unref(GST_OBJECT(m_gst_playbin));
 
                if (m_gst_playbin)
                        gst_object_unref(GST_OBJECT(m_gst_playbin));
 
-               eDebug("eServiceMP3::sorry, can't play: %s",m_error_message.c_str());
+               eDebug("eServiceMP3::sorry, can't play: %s",m_errorInfo.error_message.c_str());
                m_gst_playbin = 0;
        }
 
                m_gst_playbin = 0;
        }
 
@@ -938,7 +936,7 @@ std::string eServiceMP3::getInfoString(int w)
                tag = "channel-mode";
                break;
        case sUser+12:
                tag = "channel-mode";
                break;
        case sUser+12:
-               return m_error_message;
+               return m_errorInfo.error_message;
        default:
                return "";
        }
        default:
                return "";
        }
@@ -1168,18 +1166,18 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                return;
        gchar *sourceName;
        GstObject *source;
                return;
        gchar *sourceName;
        GstObject *source;
-
        source = GST_MESSAGE_SRC(msg);
        source = GST_MESSAGE_SRC(msg);
+       if (!GST_IS_OBJECT(source))
+               return;
        sourceName = gst_object_get_name(source);
        sourceName = gst_object_get_name(source);
-#if 1
+#if 0
+       gchar *string;
        if (gst_message_get_structure(msg))
        if (gst_message_get_structure(msg))
-       {
-               gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
-               eDebug("eServiceMP3::gst_message from %s: %s", sourceName, string);
-               g_free(string);
-       }
+               string = gst_structure_to_string(gst_message_get_structure(msg));
        else
        else
-               eDebug("eServiceMP3::gst_message from %s: %s (without structure)", sourceName, GST_MESSAGE_TYPE_NAME(msg));
+               string = g_strdup(GST_MESSAGE_TYPE_NAME(msg));
+       eDebug("eTsRemoteSource::gst_message from %s: %s", sourceName, string);
+       g_free(string);
 #endif
        switch (GST_MESSAGE_TYPE (msg))
        {
 #endif
        switch (GST_MESSAGE_TYPE (msg))
        {
@@ -1374,51 +1372,64 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                                g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
                                if ( pad )
                                        g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
                                g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
                                if ( pad )
                                        g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
-                               if ( subs.type != stSRT )
-                                       subs.type = getSubtitleType(pad, g_codec);
+                               subs.type = getSubtitleType(pad, g_codec);
 
                                m_subtitleStreams.push_back(subs);
                                g_free (g_lang);
                        }
                        m_event((iPlayableService*)this, evUpdatedEventInfo);
 
                                m_subtitleStreams.push_back(subs);
                                g_free (g_lang);
                        }
                        m_event((iPlayableService*)this, evUpdatedEventInfo);
+
+                       if ( m_errorInfo.missing_codec != "" )
+                       {
+                               if ( m_errorInfo.missing_codec.find("video/") == 0 || ( m_errorInfo.missing_codec.find("audio/") == 0 && getNumberOfTracks() == 0 ) )
+                                       m_event((iPlayableService*)this, evUser+12);
+                       }
                        break;
                }
                case GST_MESSAGE_ELEMENT:
                {
                        break;
                }
                case GST_MESSAGE_ELEMENT:
                {
-                       if ( gst_is_missing_plugin_message(msg) )
-                       {
-                               gchar *description = gst_missing_plugin_message_get_description(msg);
-                               if ( description )
-                               {
-                                       m_error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
-                                       g_free(description);
-                                       m_event((iPlayableService*)this, evUser+12);
-                               }
-                       }
-                       else if (const GstStructure *msgstruct = gst_message_get_structure(msg))
+                       if (const GstStructure *msgstruct = gst_message_get_structure(msg))
                        {
                        {
-                               const gchar *eventname = gst_structure_get_name(msgstruct);
-                               if ( eventname )
+                               if ( gst_is_missing_plugin_message(msg) )
                                {
                                {
-                                       if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
-                                       {
-                                               gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
-                                               gst_structure_get_int (msgstruct, "width", &m_width);
-                                               gst_structure_get_int (msgstruct, "height", &m_height);
-                                               if (strstr(eventname, "Changed"))
-                                                       m_event((iPlayableService*)this, evVideoSizeChanged);
-                                       }
-                                       else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
+                                       GstCaps *caps;
+                                       gst_structure_get (msgstruct, "detail", GST_TYPE_CAPS, &caps, NULL); 
+                                       std::string codec = (const char*) gst_caps_to_string(caps);
+                                       gchar *description = gst_missing_plugin_message_get_description(msg);
+                                       if ( description )
                                        {
                                        {
-                                               gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
-                                               if (strstr(eventname, "Changed"))
-                                                       m_event((iPlayableService*)this, evVideoFramerateChanged);
+                                               eDebug("eServiceMP3::m_errorInfo.missing_codec = %s", codec.c_str());
+                                               m_errorInfo.error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
+                                               m_errorInfo.missing_codec = codec.substr(0,(codec.find_first_of(',')));
+                                               g_free(description);
                                        }
                                        }
-                                       else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
+                                       gst_caps_unref(caps);
+                               }
+                               else
+                               {
+                                       const gchar *eventname = gst_structure_get_name(msgstruct);
+                                       if ( eventname )
                                        {
                                        {
-                                               gst_structure_get_int (msgstruct, "progressive", &m_progressive);
-                                               if (strstr(eventname, "Changed"))
-                                                       m_event((iPlayableService*)this, evVideoProgressiveChanged);
+                                               if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
+                                               {
+                                                       gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
+                                                       gst_structure_get_int (msgstruct, "width", &m_width);
+                                                       gst_structure_get_int (msgstruct, "height", &m_height);
+                                                       if (strstr(eventname, "Changed"))
+                                                               m_event((iPlayableService*)this, evVideoSizeChanged);
+                                               }
+                                               else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
+                                               {
+                                                       gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
+                                                       if (strstr(eventname, "Changed"))
+                                                               m_event((iPlayableService*)this, evVideoFramerateChanged);
+                                               }
+                                               else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
+                                               {
+                                                       gst_structure_get_int (msgstruct, "progressive", &m_progressive);
+                                                       if (strstr(eventname, "Changed"))
+                                                               m_event((iPlayableService*)this, evVideoProgressiveChanged);
+                                               }
                                        }
                                }
                        }
                                        }
                                }
                        }
@@ -1811,15 +1822,25 @@ PyObject *eServiceMP3::getSubtitleList()
        for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
        {
                subtype_t type = IterSubtitleStream->type;
        for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
        {
                subtype_t type = IterSubtitleStream->type;
-               ePyObject tuple = PyTuple_New(5);
-//             eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
-               PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
-               PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
-               PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
-               PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
-               PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
-               PyList_Append(l, tuple);
-               Py_DECREF(tuple);
+               switch(type)
+               {
+               case stUnknown:
+               case stVOB:
+               case stPGS:
+                       break;
+               default:
+               {
+                       ePyObject tuple = PyTuple_New(5);
+//                     eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
+                       PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
+                       PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
+                       PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
+                       PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
+                       PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
+                       PyList_Append(l, tuple);
+                       Py_DECREF(tuple);
+               }
+               }
                stream_idx++;
        }
        eDebug("eServiceMP3::getSubtitleList finished");
                stream_idx++;
        }
        eDebug("eServiceMP3::getSubtitleList finished");
@@ -1941,6 +1962,3 @@ void eServiceMP3::setPCMDelay(int delay)
        }
 }
 
        }
 }
 
-#else
-#warning gstreamer not available, not building media player
-#endif