only display missing codec warning when necessary (bixes bug #374)
[enigma2.git] / lib / service / servicemp3.cpp
index 31ae9573e2757209cbe20ad44a600482fd0c2258..4a97631360f8f221b195ddc0eab00e83b63348e1 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>
@@ -49,7 +47,6 @@ eServiceFactoryMP3::eServiceFactoryMP3()
                extensions.push_back("mp4");
                extensions.push_back("mov");
                extensions.push_back("m4a");
-               extensions.push_back("m2ts");
                sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
        }
 
@@ -225,6 +222,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref)
        m_stream_tags = 0;
        m_currentAudioStream = -1;
        m_currentSubtitleStream = 0;
+       m_audioStream_manually_changed = FALSE;
        m_subtitle_widget = 0;
        m_currentTrickRatio = 0;
        m_subs_to_pull = 0;
@@ -362,10 +360,6 @@ 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);
-                       subtitleStream subs;
-                       subs.type = stSRT;
-                       subs.language_code = std::string("und");
-                       m_subtitleStreams.push_back(subs);
                }
        } else
        {
@@ -1058,6 +1052,7 @@ RESULT eServiceMP3::selectTrack(unsigned int i)
        if (ppos < 0)
                ppos = 0;
 
+       m_audioStream_manually_changed = TRUE;
        int ret = selectAudioStream(i);
        if (!ret) {
                /* flush */
@@ -1171,7 +1166,7 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
 
        source = GST_MESSAGE_SRC(msg);
        sourceName = gst_object_get_name(source);
-#if 1
+#if 0
        if (gst_message_get_structure(msg))
        {
                gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
@@ -1251,7 +1246,19 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                                        if ( g_strrstr(sourceName, "videosink") )
                                                m_event((iPlayableService*)this, evUser+11);
                                        else if ( g_strrstr(sourceName, "audiosink") )
-                                               m_event((iPlayableService*)this, evUser+10);
+                                       {
+                                               if ( getNumberOfTracks() == 1 || m_audioStream_manually_changed == TRUE )
+                                               {
+                                                       m_event((iPlayableService*)this, evUser+10);
+                                               }
+                                               else
+                                               {
+                                                       int next_track = getCurrentTrack() + 1;
+                                                       if ( next_track >= getNumberOfTracks() )
+                                                               next_track = 0;
+                                                       selectAudioStream(next_track);
+                                               }
+                                       }
                                }
                        }
                        g_error_free(err);
@@ -1321,6 +1328,7 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
 
                        m_audioStreams.clear();
                        m_subtitleStreams.clear();
+                       m_audioStream_manually_changed = FALSE;
 
                        for (i = 0; i < n_audio; i++)
                        {
@@ -1374,8 +1382,7 @@ 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);
-                               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);
@@ -1388,6 +1395,7 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                        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";
@@ -1811,15 +1819,25 @@ PyObject *eServiceMP3::getSubtitleList()
        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");
@@ -1941,6 +1959,3 @@ void eServiceMP3::setPCMDelay(int delay)
        }
 }
 
-#else
-#warning gstreamer not available, not building media player
-#endif