Merge branch 'bug_624_change_handylike_char_input'
[enigma2.git] / lib / python / Plugins / Extensions / DVDPlayer / src / servicedvd.cpp
index cf26f35d04b2c12ab2010c3142b65a1df284e207..5fbfb0aa3d45f3b69e2bac4949baf2b7212e8f2b 100644 (file)
@@ -32,6 +32,7 @@ eServiceFactoryDVD::eServiceFactoryDVD()
        {
                std::list<std::string> extensions;
                extensions.push_back("iso");
+               extensions.push_back("img");
                sc->addServiceFactory(eServiceFactoryDVD::id, this, extensions);
        }
 }
@@ -51,7 +52,7 @@ DEFINE_REF(eServiceFactoryDVD)
 RESULT eServiceFactoryDVD::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
 {
                // check resources...
-       ptr = new eServiceDVD(ref.path.c_str());
+       ptr = new eServiceDVD(ref);
        return 0;
 }
 
@@ -84,16 +85,14 @@ RESULT eServiceFactoryDVD::offlineOperations(const eServiceReference &, ePtr<iSe
 
 DEFINE_REF(eServiceDVD);
 
-eServiceDVD::eServiceDVD(const char *filename):
-       m_filename(filename),
-       m_ddvdconfig(ddvd_create()),
-       m_subtitle_widget(0),
-       m_state(stIdle),
-       m_current_trick(0),
-       m_pump(eApp, 1)
+eServiceDVD::eServiceDVD(eServiceReference ref):
+       m_ref(ref), m_ddvdconfig(ddvd_create()), m_subtitle_widget(0), m_state(stIdle),
+       m_current_trick(0), m_pump(eApp, 1), m_width(-1), m_height(-1),
+       m_aspect(-1), m_framerate(-1), m_progressive(-1)
 {
-       int aspect = DDVD_16_9; 
+       int aspect = DDVD_16_9;
        int policy = DDVD_PAN_SCAN;
+       int policy2 = DDVD_PAN_SCAN;
 
        char tmp[255];
        ssize_t rd;
@@ -101,7 +100,7 @@ eServiceDVD::eServiceDVD(const char *filename):
        m_sn = eSocketNotifier::create(eApp, ddvd_get_messagepipe_fd(m_ddvdconfig), eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup);
        eDebug("SERVICEDVD construct!");
        // create handle
-       ddvd_set_dvd_path(m_ddvdconfig, filename);
+       ddvd_set_dvd_path(m_ddvdconfig, ref.path.c_str());
        ddvd_set_ac3thru(m_ddvdconfig, 0);
 
        std::string ddvd_language;
@@ -130,7 +129,22 @@ eServiceDVD::eServiceDVD(const char *filename):
                close(fd);
        }
 
+#ifdef DDVD_SUPPORTS_16_10_SCALING
+       fd = open("/proc/stb/video/policy2", O_RDONLY);
+       if (fd > -1)
+       {
+               rd = read(fd, tmp, 255);
+               if (rd > 6 && !strncmp(tmp, "bestfit", 7))
+                       policy2 = DDVD_JUSTSCALE;
+               else if (rd > 8 && !strncmp(tmp, "letterbox", 9))
+                       policy2 = DDVD_LETTERBOX;
+               close(fd);
+       }
+       ddvd_set_video_ex(m_ddvdconfig, aspect, policy, policy2, DDVD_PAL /*unused*/);
+#else
        ddvd_set_video(m_ddvdconfig, aspect, policy, DDVD_PAL /*unused*/);
+#warning please update libdreamdvd for 16:10 scaling support!
+#endif
 
        CONNECT(m_sn->activated, eServiceDVD::gotMessage);
        CONNECT(m_pump.recv_msg, eServiceDVD::gotThreadMessage);
@@ -188,6 +202,7 @@ void eServiceDVD::gotMessage(int /*what*/)
 #ifdef DDVD_SUPPORTS_GET_BLIT_DESTINATION
                                ddvd_get_blit_destination(m_ddvdconfig, &x_offset, &y_offset, &width, &height);
                                eDebug("values got from ddvd: %d %d %d %d", x_offset, y_offset, width, height);
+                               y_offset = -y_offset;
                                width -= x_offset * 2;
                                height -= y_offset * 2;
 #endif
@@ -292,6 +307,32 @@ void eServiceDVD::gotMessage(int /*what*/)
                        m_event(this, evSeekableStatusChanged);
                        m_event(this, evUser+12);
                        break;
+#ifdef DDVD_SUPPORTS_PICTURE_INFO
+               case DDVD_SIZE_CHANGED:
+               {
+                       int changed = m_width != -1 && m_height != -1 && m_aspect != -1;
+                       ddvd_get_last_size(m_ddvdconfig, &m_width, &m_height, &m_aspect);
+                       if (changed)
+                               m_event((iPlayableService*)this, evVideoSizeChanged);
+                       break;
+               }
+               case DDVD_PROGRESSIVE_CHANGED:
+               {
+                       int changed = m_progressive != -1;
+                       ddvd_get_last_progressive(m_ddvdconfig, &m_progressive);
+                       if (changed)
+                               m_event((iPlayableService*)this, evVideoProgressiveChanged);
+                       break;
+               }
+               case DDVD_FRAMERATE_CHANGED:
+               {
+                       int changed = m_framerate != -1;
+                       ddvd_get_last_framerate(m_ddvdconfig, &m_framerate);
+                       if (changed)
+                               m_event((iPlayableService*)this, evVideoFramerateChanged);
+                       break;
+               }
+#endif
                default:
                        break;
        }
@@ -326,7 +367,7 @@ RESULT eServiceDVD::stop()
        ASSERT(m_state != stIdle);
        if (m_state == stStopped)
                return -1;
-       eDebug("DVD: stop %s", m_filename.c_str());
+       eDebug("DVD: stop %s", m_ref.path.c_str());
        m_state = stStopped;
        ddvd_send_key(m_ddvdconfig, DDVD_KEY_EXIT);
 
@@ -440,7 +481,10 @@ RESULT eServiceDVD::getName(std::string &name)
        if ( m_ddvd_titlestring[0] != '\0' )
                name = m_ddvd_titlestring;
        else
-               name = m_filename;
+               if ( !m_ref.name.empty() )
+                       name = m_ref.name;
+               else
+                       name = m_ref.path;
        return 0;
 }
 
@@ -483,6 +527,18 @@ int eServiceDVD::getInfo(int w)
                case sUser+7:
                case sUser+8:
                        return resIsPyObject;
+#ifdef DDVD_SUPPORTS_PICTURE_INFO
+               case sVideoWidth:
+                       return m_width;
+               case sVideoHeight:
+                       return m_height;
+               case sAspect:
+                       return m_aspect;
+               case sProgressive:
+                       return m_progressive;
+               case sFrameRate:
+                       return m_framerate;
+#endif
                default:
                        return resNA;
        }
@@ -493,7 +549,7 @@ std::string eServiceDVD::getInfoString(int w)
        switch(w)
        {
                case sServiceref:
-                       break;
+                       return m_ref.toString();
                default:
                        eDebug("unhandled getInfoString(%d)", w);
        }
@@ -679,7 +735,7 @@ RESULT eServiceDVD::setTrickmode(int /*trick*/)
 
 RESULT eServiceDVD::isCurrentlySeekable()
 {
-       return m_state == stRunning;
+       return m_state == stRunning ? 3 : 0;
 }
 
 RESULT eServiceDVD::keyPressed(int key)
@@ -769,7 +825,7 @@ void eServiceDVD::loadCuesheet()
        if ( m_ddvd_titlestring[0] != '\0' )
                snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
        else
-               snprintf(filename, 128, "%s/dvd.cuts", m_filename.c_str());
+               snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
 
        eDebug("eServiceDVD::loadCuesheet() filename=%s",filename);
 
@@ -840,7 +896,7 @@ void eServiceDVD::saveCuesheet()
        if ( m_ddvd_titlestring[0] != '\0' )
                snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
        else
-               snprintf(filename, 128, "%s/dvd.cuts", m_filename.c_str());
+               snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
        
        FILE *f = fopen(filename, "wb");