we need policy2 in libdreamdvd for 16:10 support
[enigma2.git] / lib / python / Plugins / Extensions / DVDPlayer / src / servicedvd.cpp
index c2590af56cccc46ec8fb34ab27d49a5f1f04094c..94f2ee38ad0ed7cff675b9f2b8d8f5631ba40f41 100644 (file)
@@ -51,7 +51,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 +84,17 @@ RESULT eServiceFactoryDVD::offlineOperations(const eServiceReference &, ePtr<iSe
 
 DEFINE_REF(eServiceDVD);
 
-eServiceDVD::eServiceDVD(const char *filename):
-       m_filename(filename),
+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)
 {
-       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,9 +102,12 @@ 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);
-       ddvd_set_language(m_ddvdconfig, "de");
+
+       std::string ddvd_language;
+       if (!ePythonConfigQuery::getConfigValue("config.osd.language", ddvd_language))
+               ddvd_set_language(m_ddvdconfig, (ddvd_language.substr(0,2)).c_str());
 
        int fd = open("/proc/stb/video/aspect", O_RDONLY);
        if (fd > -1)
@@ -127,7 +131,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);
@@ -179,7 +198,20 @@ void eServiceDVD::gotMessage(int /*what*/)
                        if (m_subtitle_widget) {
                                int x1,x2,y1,y2;
                                ddvd_get_last_blit_area(m_ddvdconfig, &x1, &x2, &y1, &y2);
-                               m_subtitle_widget->setPixmap(m_pixmap, eRect(x1, y1, (x2-x1)+1, (y2-y1)+1));
+                               
+                               int x_offset = 0, y_offset = 0, width = 720, height = 576;
+
+#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
+                               eRect dest(x_offset, y_offset, width, height);
+
+                               if (dest.width() && dest.height())
+                                       m_subtitle_widget->setPixmap(m_pixmap, eRect(x1, y1, (x2-x1)+1, (y2-y1)+1), dest);
                        }
                        break;
                case DDVD_SHOWOSD_STATE_PLAY:
@@ -299,7 +331,7 @@ RESULT eServiceDVD::connectEvent(const Slot2<void,iPlayableService*,int> &event,
 
 RESULT eServiceDVD::start()
 {
-       assert(m_state == stIdle);
+       ASSERT(m_state == stIdle);
        m_state = stRunning;
        eDebug("eServiceDVD starting");
 //     m_event(this, evStart);
@@ -308,10 +340,10 @@ RESULT eServiceDVD::start()
 
 RESULT eServiceDVD::stop()
 {
-       assert(m_state != stIdle);
+       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);
 
@@ -425,7 +457,7 @@ RESULT eServiceDVD::getName(std::string &name)
        if ( m_ddvd_titlestring[0] != '\0' )
                name = m_ddvd_titlestring;
        else
-               name = m_filename;
+               name = m_ref.path;
        return 0;
 }
 
@@ -478,7 +510,7 @@ std::string eServiceDVD::getInfoString(int w)
        switch(w)
        {
                case sServiceref:
-                       break;
+                       return m_ref.toString();
                default:
                        eDebug("unhandled getInfoString(%d)", w);
        }
@@ -559,12 +591,17 @@ RESULT eServiceDVD::enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) /*
        m_subtitle_widget = new eSubtitleWidget(parent);
        m_subtitle_widget->resize(parent->size());
 
-       eSize size = parent->size();
+       eSize size = eSize(720, 576);
 
        if (!m_pixmap)
        {
-               m_pixmap = new gPixmap(size, 32);
+               m_pixmap = new gPixmap(size, 32, 1); /* allocate accel surface (if possible) */
+#ifdef DDVD_SUPPORTS_GET_BLIT_DESTINATION
+               ddvd_set_lfb_ex(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4, 1);
+#else
                ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4);
+#warning please update libdreamdvd for fast scaling
+#endif
                run(); // start the thread
        }
 
@@ -749,7 +786,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);
 
@@ -820,7 +857,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");