emit evUpdatedInfo on id3 taglist parse and implement YEAR tag
[enigma2.git] / lib / service / servicemp3.cpp
index 76495826c9389ab1536be6dc8a11afd972c9c21b..225d90f69938145f8e00a156efd428ea782c9d2b 100644 (file)
@@ -12,6 +12,7 @@
 #include <lib/base/init_num.h>
 #include <lib/base/init.h>
 #include <gst/gst.h>
+#include <gst/pbutils/missing-plugins.h>
 #include <sys/stat.h>
 /* for subtitles */
 #include <lib/gui/esubtitle.h>
@@ -34,6 +35,8 @@ eServiceFactoryMP3::eServiceFactoryMP3()
                extensions.push_back("wave");
                extensions.push_back("mkv");
                extensions.push_back("avi");
+               extensions.push_back("dat");
+               extensions.push_back("flac");
                sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
        }
 
@@ -203,8 +206,9 @@ eServiceMP3::eServiceMP3(const char *filename): m_filename(filename), m_pump(eAp
        int is_video = is_mpeg_ps || is_mpeg_ts || is_matroska || is_avi;
        int is_streaming = !strncmp(filename, "http://", 7);
        int is_AudioCD = !(strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav"));
+       int is_VCD = !strcasecmp(ext, ".dat");
        
-       eDebug("filename: %s, is_mpeg_ps: %d, is_mpeg_ts: %d, is_video: %d, is_streaming: %d, is_mp3: %d, is_matroska: %d, is_avi: %d, is_AudioCD: %d", filename, is_mpeg_ps, is_mpeg_ts, is_video, is_streaming, is_mp3, is_matroska, is_avi, is_AudioCD);
+       eDebug("filename: %s, is_mpeg_ps: %d, is_mpeg_ts: %d, is_video: %d, is_streaming: %d, is_mp3: %d, is_matroska: %d, is_avi: %d, is_AudioCD: %d, is_VCD: %d", filename, is_mpeg_ps, is_mpeg_ts, is_video, is_streaming, is_mp3, is_matroska, is_avi, is_AudioCD, is_VCD);
        
        int is_audio = !is_video;
 
@@ -392,7 +396,16 @@ eServiceMP3::eServiceMP3(const char *filename): m_filename(filename), m_pump(eAp
                                gst_bin_add(GST_BIN(m_gst_pipeline), switch_audio);
                                gst_element_link(switch_audio, queue_audio);
                        }
-                       gst_element_link(source, videodemux);
+
+                       if (is_VCD)
+                       {
+                               GstElement *cdxaparse = gst_element_factory_make("cdxaparse", "cdxaparse");
+                               gst_bin_add(GST_BIN(m_gst_pipeline), cdxaparse);
+                               gst_element_link(source, cdxaparse);
+                               gst_element_link(cdxaparse, videodemux);
+                       }
+                       else
+                               gst_element_link(source, videodemux);
                        gst_element_link(queue_audio, audio);
                        gst_element_link(queue_video, video);
                        g_signal_connect(videodemux, "pad-added", G_CALLBACK (gstCBpadAdded), this);
@@ -668,6 +681,8 @@ int eServiceMP3::getInfo(int w)
        case sTracknumber:
        case sGenre:
        case sVideoType:
+       case sTimeCreate:
+       case sUser+12:
                return resIsString;
        case sCurrentTitle:
                tag = GST_TAG_TRACK_NUMBER;
@@ -692,6 +707,8 @@ int eServiceMP3::getInfo(int w)
 
 std::string eServiceMP3::getInfoString(int w)
 {
+       if ( !m_stream_tags )
+               return "";
        gchar *tag = 0;
        switch (w)
        {
@@ -716,22 +733,29 @@ std::string eServiceMP3::getInfoString(int w)
        case sVideoType:
                tag = GST_TAG_VIDEO_CODEC;
                break;
+       case sTimeCreate:
+               GDate *date;
+               if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
+               {
+                       gchar res[5];
+                       g_date_strftime (res, sizeof(res), "%Y", date); 
+                       return (std::string)res;
+               }
+               break;
+       case sUser+12:
+               return m_error_message;
        default:
                return "";
        }
-       
-       if (!m_stream_tags || !tag)
+       if ( !tag )
                return "";
-       
        gchar *value;
-       
        if (gst_tag_list_get_string(m_stream_tags, tag, &value))
        {
                std::string res = value;
                g_free(value);
                return res;
        }
-       
        return "";
 }
 
@@ -845,7 +869,7 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
 
        source = GST_MESSAGE_SRC(msg);
        sourceName = gst_object_get_name(source);
-
+#if 0
        if (gst_message_get_structure(msg))
        {
                gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
@@ -854,7 +878,7 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
        }
        else
                eDebug("gst_message from %s: %s (without structure)", sourceName, GST_MESSAGE_TYPE_NAME(msg));
-
+#endif
        switch (GST_MESSAGE_TYPE (msg))
        {
        case GST_MESSAGE_EOS:
@@ -902,6 +926,9 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                        audio.type = gstCheckAudioPad(str);
                        m_audioStreams.push_back(audio);
                }
+
+               gst_tag_list_free(tags);
+               m_event((iPlayableService*)this, evUpdatedInfo);
                break;
        }
        case GST_MESSAGE_ASYNC_DONE:
@@ -936,6 +963,19 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                        }
                }
        }
+        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 = description;
+                               g_free(description);
+                               m_event((iPlayableService*)this, evUser+12);
+                       }
+               }
+       }
        default:
                break;
        }