fix hardware playback of mp3 files with APE tags.
[enigma2.git] / lib / service / servicemp3.cpp
index 86b7696f979099b9ebdf3a187b75c11e5d2b470f..bbcb3b5cf061ea165673a79609a38d6ddb769abd 100644 (file)
@@ -188,7 +188,8 @@ eServiceMP3::eServiceMP3(const char *filename): m_filename(filename), m_pump(eAp
        GstElement *source = 0;
        GstElement *decoder = 0, *conv = 0, *flt = 0, *parser = 0, *sink = 0; /* for audio */
        GstElement *audio = 0, *switch_audio = 0, *queue_audio = 0, *video = 0, *queue_video = 0, *videodemux = 0, *audiodemux = 0, *id3demux;
-       
+       m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
+
        m_state = stIdle;
        eDebug("SERVICEMP3 construct!");
        
@@ -283,9 +284,14 @@ eServiceMP3::eServiceMP3(const char *filename): m_filename(filename), m_pump(eAp
                int ret = read(fd, tmp, 128*1024);
                close(fd);
                if ( ret == -1 ) // this is a "REAL" VCD
+               {
                        source = gst_element_factory_make ("vcdsrc", "vcd-source");
                        if (source)
+                       {
                                g_object_set (G_OBJECT (source), "device", "/dev/cdroms/cdrom0", NULL);
+                               eDebug("servicemp3: this is a 'REAL' video cd... we use vcdsrc !");
+                       }
+               }
        }
        if ( !source && !sourceinfo.is_streaming )
        {
@@ -490,7 +496,7 @@ eServiceMP3::eServiceMP3(const char *filename): m_filename(filename), m_pump(eAp
 
                        if ( sourceinfo.containertype == ctVCD && gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"file-source") )
                        {
-                               eDebug("this is a fake video cd... we use filesrc ! cdxaparse !");
+                               eDebug("servicemp3: this is a fake video cd... we use filesrc ! cdxaparse !");
                                GstElement *cdxaparse = gst_element_factory_make("cdxaparse", "cdxaparse");
                                gst_bin_add(GST_BIN(m_gst_pipeline), cdxaparse);
                                gst_element_link(source, cdxaparse);
@@ -775,13 +781,13 @@ RESULT eServiceMP3::getPlayPosition(pts_t &pts)
                return -1;
        if (m_state != stRunning)
                return -1;
-       
+
        GstFormat fmt = GST_FORMAT_TIME;
        gint64 len;
        
        if (!gst_element_query_position(m_gst_pipeline, &fmt, &len))
                return -1;
-       
+
                /* len is in nanoseconds. we have 90 000 pts per second. */
        pts = len / 11111;
        return 0;
@@ -819,6 +825,11 @@ int eServiceMP3::getInfo(int w)
 
        switch (w)
        {
+       case sVideoHeight: return m_height;
+       case sVideoWidth: return m_width;
+       case sFrameRate: return m_framerate;
+       case sProgressive: return m_progressive;
+       case sAspect: return m_aspect;
        case sTitle:
        case sArtist:
        case sAlbum:
@@ -1036,11 +1047,21 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
        
                        gst_message_parse_error (msg, &err, &debug);
                        g_free (debug);
-                       eWarning("Gstreamer error: %s (%i)", err->message, err->code );
-                       if ( err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
+                       eWarning("Gstreamer error: %s (%i) from %s", err->message, err->code, sourceName );
+                       if ( err->domain == GST_STREAM_ERROR )
                        {
-                               if ( g_strrstr(sourceName, "videosink") )
+                               if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND && g_strrstr(sourceName, "videosink") )
                                        m_event((iPlayableService*)this, evUser+11);
+                               else if ( err->code == GST_STREAM_ERROR_FAILED && g_strrstr(sourceName, "file-source") )
+                               {
+                                       eWarning("error in tag parsing, linking mp3parse directly to file-sink, bypassing id3demux...");
+                                       GstElement *source = gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"file-source");
+                                       GstElement *parser = gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"audiosink");
+                                       gst_element_set_state(m_gst_pipeline, GST_STATE_NULL);
+                                       gst_element_unlink(source, gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"id3demux"));
+                                       gst_element_link(source, parser);
+                                       gst_element_set_state (m_gst_pipeline, GST_STATE_PLAYING);
+                               }
                        }
                        g_error_free(err);
                        break;
@@ -1147,28 +1168,28 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                        }
                        else if (const GstStructure *msgstruct = gst_message_get_structure(msg))
                        {
-                               const gchar *eventname;
-                               if ( eventname = gst_structure_get_name(msgstruct) )
+                               const gchar *eventname = gst_structure_get_name(msgstruct);
+                               if ( eventname )
                                {
-                                       if (!strcmp(eventname, "eventSizeChanged"))
+                                       if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
                                        {
-                                               gint aspect_ratio, width, height = 0;
-                                               gst_structure_get_int (msgstruct, "aspect_ratio", &aspect_ratio);
-                                               gst_structure_get_int (msgstruct, "width", &width);
-                                               gst_structure_get_int (msgstruct, "height", &height);
-                                               eDebug("****** decoder threw eventSizeChanged! aspect_ratio=%i, width=%i, height=%i", aspect_ratio, width, height);
+                                               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);
                                        }
-                                       if (!strcmp(eventname, "eventFrameRateChanged"))
+                                       else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
                                        {
-                                               gint frame_rate = 0;
-                                               gst_structure_get_int (msgstruct, "frame_rate", &frame_rate);
-                                               eDebug("****** decoder threw eventFrameRateChanged! frame_rate=%i", frame_rate);
+                                               gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
+                                               if (strstr(eventname, "Changed"))
+                                                       m_event((iPlayableService*)this, evVideoFramerateChanged);
                                        }
-                                       if (!strcmp(eventname, "eventProgressiveChanged"))
+                                       else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
                                        {
-                                               gint progressive = 0;
-                                               gst_structure_get_int (msgstruct, "progressive", &progressive);
-                                               eDebug("****** decoder threw eventProgressiveChanged! progressive=%i", progressive);
+                                               gst_structure_get_int (msgstruct, "progressive", &m_progressive);
+                                               if (strstr(eventname, "Changed"))
+                                                       m_event((iPlayableService*)this, evVideoProgressiveChanged);
                                        }
                                }
                        }
@@ -1418,14 +1439,17 @@ eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::servi
 void eServiceMP3::gstCBsubtitleAvail(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer user_data)
 {
        gint64 duration_ns = GST_BUFFER_DURATION(buffer);
-       const unsigned char *text = (unsigned char *)GST_BUFFER_DATA(buffer);
-       eDebug("gstCBsubtitleAvail: %s",text);
+       size_t len = GST_BUFFER_SIZE(buffer);
+       unsigned char tmp[len+1];
+       memcpy(tmp, GST_BUFFER_DATA(buffer), len);
+       tmp[len] = 0;
+       eDebug("gstCBsubtitleAvail: %s", tmp);
        eServiceMP3 *_this = (eServiceMP3*)user_data;
        if ( _this->m_subtitle_widget )
        {
                ePangoSubtitlePage page;
                gRGB rgbcol(0xD0,0xD0,0xD0);
-               page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)text));
+               page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)tmp));
                page.m_timeout = duration_ns / 1000000;
                (_this->m_subtitle_widget)->setPage(page);
        }