follow libdreamdvd changes to support scaling (needs libdreamdvd >= 20081208)
[enigma2.git] / lib / python / Plugins / Extensions / DVDPlayer / src / servicedvd.cpp
index 1add04ab47661bd55c460d364baf94406c96eb7e..0a3d035912770a3b76634510932045b0a0d800b1 100644 (file)
@@ -87,30 +87,48 @@ DEFINE_REF(eServiceDVD);
 eServiceDVD::eServiceDVD(const char *filename):
        m_filename(filename),
        m_ddvdconfig(ddvd_create()),
-       m_pixmap(new gPixmap(eSize(720, 576), 32)),
        m_subtitle_widget(0),
        m_state(stIdle),
        m_current_trick(0),
        m_pump(eApp, 1)
 {
+       int aspect = DDVD_16_9; 
+       int policy = DDVD_PAN_SCAN;
+
+       char tmp[255];
+       ssize_t rd;
+
        m_sn = eSocketNotifier::create(eApp, ddvd_get_messagepipe_fd(m_ddvdconfig), eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup);
-       std::string aspect;
        eDebug("SERVICEDVD construct!");
        // create handle
        ddvd_set_dvd_path(m_ddvdconfig, filename);
        ddvd_set_ac3thru(m_ddvdconfig, 0);
        ddvd_set_language(m_ddvdconfig, "de");
 
-       if (ePythonConfigQuery::getConfigValue("config.av.aspect", aspect) != 0)
-               aspect = "16_9";
-       if (aspect == "4_3_letterbox")
-               ddvd_set_video(m_ddvdconfig, DDVD_4_3_LETTERBOX, DDVD_PAL);
-       else if (aspect == "4_3_panscan")
-               ddvd_set_video(m_ddvdconfig, DDVD_4_3_PAN_SCAN, DDVD_PAL);
-       else
-               ddvd_set_video(m_ddvdconfig, DDVD_16_9, DDVD_PAL);
+       int fd = open("/proc/stb/video/aspect", O_RDONLY);
+       if (fd > -1)
+       {
+               rd = read(fd, tmp, 255);
+               if (rd > 2 && !strncmp(tmp, "4:3", 3))
+                       aspect = DDVD_4_3;
+               else if (rd > 4 && !strncmp(tmp, "16:10", 5))
+                       aspect = DDVD_16_10;
+               close(fd);
+       }
+
+       fd = open("/proc/stb/video/policy", O_RDONLY);
+       if (fd > -1)
+       {
+               rd = read(fd, tmp, 255);
+               if (rd > 6 && !strncmp(tmp, "bestfit", 3))
+                       aspect = DDVD_JUSTSCALE;
+               else if (rd > 8 && !strncmp(tmp, "letterbox", 5))
+                       aspect = DDVD_LETTERBOX;
+               close(fd);
+       }
+
+       ddvd_set_video(m_ddvdconfig, aspect, policy, DDVD_PAL /*unused*/);
 
-       ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, 720, 576, 4, 720*4);
        CONNECT(m_sn->activated, eServiceDVD::gotMessage);
        CONNECT(m_pump.recv_msg, eServiceDVD::gotThreadMessage);
        strcpy(m_ddvd_titlestring,"");
@@ -159,7 +177,7 @@ void eServiceDVD::gotMessage(int /*what*/)
                case DDVD_SCREEN_UPDATE:
                        eDebug("DVD_SCREEN_UPDATE!");
                        if (m_subtitle_widget)
-                               m_subtitle_widget->setPixmap(m_pixmap, eRect(0, 0, 720, 576));
+                               m_subtitle_widget->setPixmap(m_pixmap, eRect(ePoint(0, 0), m_pixmap->size()));
                        break;
                case DDVD_SHOWOSD_STATE_PLAY:
                {
@@ -272,7 +290,6 @@ RESULT eServiceDVD::start()
        assert(m_state == stIdle);
        m_state = stRunning;
        eDebug("eServiceDVD starting");
-       run();
 //     m_event(this, evStart);
        return 0;
 }
@@ -516,11 +533,22 @@ RESULT eServiceDVD::enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) /*
 {
        if (m_subtitle_widget)
                delete m_subtitle_widget;
+
        m_subtitle_widget = new eSubtitleWidget(parent);
        m_subtitle_widget->resize(parent->size());
-       m_subtitle_widget->setPixmap(m_pixmap, eRect(0, 0, 720, 576));
+
+       eSize size = parent->size();
+
+       if (!m_pixmap)
+       {
+               m_pixmap = new gPixmap(size, 32);
+               ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4);
+               run(); // start the thread
+       }
+
        m_subtitle_widget->setZPosition(-1);
        m_subtitle_widget->show();
+
        return 0;
 }