2 #include <lib/base/eerror.h>
3 #include <lib/base/object.h>
4 #include <lib/base/ebase.h>
5 #include <lib/base/nconfig.h>
7 #include <lib/service/service.h>
8 #include <lib/base/init_num.h>
9 #include <lib/base/init.h>
10 #include <lib/gui/esubtitle.h>
11 #include <lib/gdi/gpixmap.h>
14 #include <netinet/in.h>
16 #error no byte order defined!
20 #include <dreamdvd/ddvdlib.h>
22 #include "servicedvd.h"
26 eServiceFactoryDVD::eServiceFactoryDVD()
28 ePtr<eServiceCenter> sc;
30 eServiceCenter::getPrivInstance(sc);
33 std::list<std::string> extensions;
34 extensions.push_back("iso");
35 sc->addServiceFactory(eServiceFactoryDVD::id, this, extensions);
39 eServiceFactoryDVD::~eServiceFactoryDVD()
41 ePtr<eServiceCenter> sc;
43 eServiceCenter::getPrivInstance(sc);
45 sc->removeServiceFactory(eServiceFactoryDVD::id);
48 DEFINE_REF(eServiceFactoryDVD)
51 RESULT eServiceFactoryDVD::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
54 ptr = new eServiceDVD(ref);
58 RESULT eServiceFactoryDVD::record(const eServiceReference &/*ref*/, ePtr<iRecordableService> &ptr)
64 RESULT eServiceFactoryDVD::list(const eServiceReference &, ePtr<iListableService> &ptr)
71 RESULT eServiceFactoryDVD::info(const eServiceReference &/*ref*/, ePtr<iStaticServiceInformation> &ptr)
77 RESULT eServiceFactoryDVD::offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr)
85 DEFINE_REF(eServiceDVD);
87 eServiceDVD::eServiceDVD(eServiceReference ref):
89 m_ddvdconfig(ddvd_create()),
95 int aspect = DDVD_16_9;
96 int policy = DDVD_PAN_SCAN;
101 m_sn = eSocketNotifier::create(eApp, ddvd_get_messagepipe_fd(m_ddvdconfig), eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup);
102 eDebug("SERVICEDVD construct!");
104 ddvd_set_dvd_path(m_ddvdconfig, ref.path.c_str());
105 ddvd_set_ac3thru(m_ddvdconfig, 0);
107 std::string ddvd_language;
108 if (!ePythonConfigQuery::getConfigValue("config.osd.language", ddvd_language))
109 ddvd_set_language(m_ddvdconfig, (ddvd_language.substr(0,2)).c_str());
111 int fd = open("/proc/stb/video/aspect", O_RDONLY);
114 rd = read(fd, tmp, 255);
115 if (rd > 2 && !strncmp(tmp, "4:3", 3))
117 else if (rd > 4 && !strncmp(tmp, "16:10", 5))
122 fd = open("/proc/stb/video/policy", O_RDONLY);
125 rd = read(fd, tmp, 255);
126 if (rd > 6 && !strncmp(tmp, "bestfit", 7))
127 policy = DDVD_JUSTSCALE;
128 else if (rd > 8 && !strncmp(tmp, "letterbox", 9))
129 policy = DDVD_LETTERBOX;
133 ddvd_set_video(m_ddvdconfig, aspect, policy, DDVD_PAL /*unused*/);
135 CONNECT(m_sn->activated, eServiceDVD::gotMessage);
136 CONNECT(m_pump.recv_msg, eServiceDVD::gotThreadMessage);
137 strcpy(m_ddvd_titlestring,"");
142 void eServiceDVD::gotThreadMessage(const int &msg)
146 case 1: // thread stopped
148 m_event(this, evStopped);
153 void eServiceDVD::gotMessage(int /*what*/)
155 switch(ddvd_get_next_message(m_ddvdconfig,1))
157 case DDVD_COLORTABLE_UPDATE:
160 struct ddvd_color ctmp[4];
161 ddvd_get_last_colortable(ddvdconfig, ctmp);
165 rd1[252+i]=ctmp[i].red;
166 bl1[252+i]=ctmp[i].blue;
167 gn1[252+i]=ctmp[i].green;
168 tr1[252+i]=ctmp[i].trans;
171 if(ioctl(fb, FBIOPUTCMAP, &colormap) == -1)
173 printf("Framebuffer: <FBIOPUTCMAP failed>\n");
177 eDebug("no support for 8bpp framebuffer in dvdplayer yet!");
180 case DDVD_SCREEN_UPDATE:
181 eDebug("DVD_SCREEN_UPDATE!");
182 if (m_subtitle_widget) {
184 ddvd_get_last_blit_area(m_ddvdconfig, &x1, &x2, &y1, &y2);
186 int x_offset = 0, y_offset = 0, width = 720, height = 576;
188 #ifdef DDVD_SUPPORTS_GET_BLIT_DESTINATION
189 ddvd_get_blit_destination(m_ddvdconfig, &x_offset, &y_offset, &width, &height);
190 eDebug("values got from ddvd: %d %d %d %d", x_offset, y_offset, width, height);
191 y_offset = -y_offset;
192 width -= x_offset * 2;
193 height -= y_offset * 2;
195 eRect dest(x_offset, y_offset, width, height);
197 if (dest.width() && dest.height())
198 m_subtitle_widget->setPixmap(m_pixmap, eRect(x1, y1, (x2-x1)+1, (y2-y1)+1), dest);
201 case DDVD_SHOWOSD_STATE_PLAY:
203 eDebug("DVD_SHOWOSD_STATE_PLAY!");
205 m_event(this, evUser+1);
208 case DDVD_SHOWOSD_STATE_PAUSE:
210 eDebug("DVD_SHOWOSD_STATE_PAUSE!");
211 m_event(this, evUser+2);
214 case DDVD_SHOWOSD_STATE_FFWD:
216 eDebug("DVD_SHOWOSD_STATE_FFWD!");
217 m_event(this, evUser+3);
220 case DDVD_SHOWOSD_STATE_FBWD:
222 eDebug("DVD_SHOWOSD_STATE_FBWD!");
223 m_event(this, evUser+4);
226 case DDVD_SHOWOSD_STRING:
228 eDebug("DVD_SHOWOSD_STRING!");
229 m_event(this, evUser+5);
232 case DDVD_SHOWOSD_AUDIO:
234 eDebug("DVD_SHOWOSD_STRING!");
235 m_event(this, evUser+6);
238 case DDVD_SHOWOSD_SUBTITLE:
240 eDebug("DVD_SHOWOSD_SUBTITLE!");
241 m_event((iPlayableService*)this, evUpdatedInfo);
242 m_event(this, evUser+7);
245 case DDVD_EOF_REACHED:
246 eDebug("DVD_EOF_REACHED!");
247 m_event(this, evEOF);
249 case DDVD_SOF_REACHED:
250 eDebug("DVD_SOF_REACHED!");
251 m_event(this, evSOF);
253 case DDVD_SHOWOSD_ANGLE:
256 ddvd_get_angle_info(m_ddvdconfig, ¤t, &num);
257 eDebug("DVD_ANGLE_INFO: %d / %d", current, num);
258 m_event(this, evUser+13);
261 case DDVD_SHOWOSD_TIME:
263 static struct ddvd_time last_info;
264 struct ddvd_time info;
265 // eDebug("DVD_SHOWOSD_TIME!");
266 ddvd_get_last_time(m_ddvdconfig, &info);
267 if ( info.pos_chapter != last_info.pos_chapter )
268 m_event(this, evUser+8); // chapterUpdated
269 if ( info.pos_title != last_info.pos_title )
270 m_event(this, evUser+9); // titleUpdated
271 memcpy(&last_info, &info, sizeof(struct ddvd_time));
274 case DDVD_SHOWOSD_TITLESTRING:
276 ddvd_get_title_string(m_ddvdconfig, m_ddvd_titlestring);
277 eDebug("DDVD_SHOWOSD_TITLESTRING: %s",m_ddvd_titlestring);
281 m_event(this, evStart);
284 case DDVD_MENU_OPENED:
285 eDebug("DVD_MENU_OPENED!");
287 m_event(this, evSeekableStatusChanged);
288 m_event(this, evUser+11);
290 case DDVD_MENU_CLOSED:
291 eDebug("DVD_MENU_CLOSED!");
293 m_event(this, evSeekableStatusChanged);
294 m_event(this, evUser+12);
301 eServiceDVD::~eServiceDVD()
303 eDebug("SERVICEDVD destruct!");
306 ddvd_close(m_ddvdconfig);
310 RESULT eServiceDVD::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
312 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
316 RESULT eServiceDVD::start()
318 ASSERT(m_state == stIdle);
320 eDebug("eServiceDVD starting");
321 // m_event(this, evStart);
325 RESULT eServiceDVD::stop()
327 ASSERT(m_state != stIdle);
328 if (m_state == stStopped)
330 eDebug("DVD: stop %s", m_ref.path.c_str());
332 ddvd_send_key(m_ddvdconfig, DDVD_KEY_EXIT);
337 RESULT eServiceDVD::setTarget(int /*target*/)
342 RESULT eServiceDVD::pause(ePtr<iPauseableService> &ptr)
348 RESULT eServiceDVD::seek(ePtr<iSeekableService> &ptr)
354 RESULT eServiceDVD::subtitle(ePtr<iSubtitleOutput> &ptr)
360 RESULT eServiceDVD::keys(ePtr<iServiceKeys> &ptr)
367 RESULT eServiceDVD::setSlowMotion(int /*ratio*/)
372 RESULT eServiceDVD::setFastForward(int trick)
374 eDebug("setTrickmode(%d)", trick);
375 while (m_current_trick > trick && m_current_trick != -64)
377 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FBWD);
378 if (m_current_trick == 0)
379 m_current_trick = -2;
380 else if (m_current_trick > 0)
382 m_current_trick /= 2;
383 if (abs(m_current_trick) == 1)
387 m_current_trick *= 2;
389 while (m_current_trick < trick && m_current_trick != 64)
391 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FFWD);
392 if (m_current_trick == 0)
394 else if (m_current_trick < 0)
396 m_current_trick /= 2;
397 if (abs(m_current_trick) == 1)
401 m_current_trick *= 2;
406 RESULT eServiceDVD::pause()
408 eDebug("set pause!\n");
409 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PAUSE);
413 RESULT eServiceDVD::unpause()
415 eDebug("set unpause!\n");
416 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PLAY);
420 void eServiceDVD::thread()
422 eDebug("eServiceDVD dvd thread started");
424 ddvd_run(m_ddvdconfig);
427 void eServiceDVD::thread_finished()
429 eDebug("eServiceDVD dvd thread finished");
430 m_pump.send(1); // inform main thread
433 RESULT eServiceDVD::info(ePtr<iServiceInformation>&i)
439 RESULT eServiceDVD::getName(std::string &name)
441 if ( m_ddvd_titlestring[0] != '\0' )
442 name = m_ddvd_titlestring;
448 int eServiceDVD::getInfo(int w)
452 case sCurrentChapter:
454 struct ddvd_time info;
455 ddvd_get_last_time(m_ddvdconfig, &info);
456 return info.pos_chapter;
460 struct ddvd_time info;
461 ddvd_get_last_time(m_ddvdconfig, &info);
462 return info.end_chapter;
466 struct ddvd_time info;
467 ddvd_get_last_time(m_ddvdconfig, &info);
468 return info.pos_title;
472 struct ddvd_time info;
473 ddvd_get_last_time(m_ddvdconfig, &info);
474 return info.end_title;
476 case sTXTPID: // we abuse HAS_TELEXT icon in InfoBar to signalize subtitles status
480 ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
486 return resIsPyObject;
492 std::string eServiceDVD::getInfoString(int w)
497 return m_ref.toString();
499 eDebug("unhandled getInfoString(%d)", w);
504 PyObject *eServiceDVD::getInfoObject(int w)
510 ePyObject tuple = PyTuple_New(3);
511 int audio_id,audio_type;
513 ddvd_get_last_audio(m_ddvdconfig, &audio_id, &audio_lang, &audio_type);
514 char audio_string[3]={audio_lang >> 8, audio_lang, 0};
515 PyTuple_SetItem(tuple, 0, PyInt_FromLong(audio_id+1));
516 PyTuple_SetItem(tuple, 1, PyString_FromString(audio_string));
520 PyTuple_SetItem(tuple, 2, PyString_FromString("MPEG"));
523 PyTuple_SetItem(tuple, 2, PyString_FromString("AC3"));
526 PyTuple_SetItem(tuple, 2, PyString_FromString("DTS"));
529 PyTuple_SetItem(tuple, 2, PyString_FromString("LPCM"));
532 PyTuple_SetItem(tuple, 2, PyString_FromString(""));
538 ePyObject tuple = PyTuple_New(2);
541 ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
542 char spu_string[3]={spu_lang >> 8, spu_lang, 0};
545 PyTuple_SetItem(tuple, 0, PyInt_FromLong(0));
546 PyTuple_SetItem(tuple, 1, PyString_FromString(""));
550 PyTuple_SetItem(tuple, 0, PyInt_FromLong(spu_id+1));
551 PyTuple_SetItem(tuple, 1, PyString_FromString(spu_string));
557 ePyObject tuple = PyTuple_New(2);
559 ddvd_get_angle_info(m_ddvdconfig, ¤t, &num);
560 PyTuple_SetItem(tuple, 0, PyInt_FromLong(current));
561 PyTuple_SetItem(tuple, 1, PyInt_FromLong(num));
566 eDebug("unhandled getInfoObject(%d)", w);
571 RESULT eServiceDVD::enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) /*entry*/)
573 delete m_subtitle_widget;
575 m_subtitle_widget = new eSubtitleWidget(parent);
576 m_subtitle_widget->resize(parent->size());
578 eSize size = eSize(720, 576);
582 m_pixmap = new gPixmap(size, 32, 1); /* allocate accel surface (if possible) */
583 #ifdef DDVD_SUPPORTS_GET_BLIT_DESTINATION
584 ddvd_set_lfb_ex(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4, 1);
586 ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4);
587 #warning please update libdreamdvd for fast scaling
589 run(); // start the thread
592 m_subtitle_widget->setZPosition(-1);
593 m_subtitle_widget->show();
598 RESULT eServiceDVD::disableSubtitles(eWidget */*parent*/)
600 delete m_subtitle_widget;
601 m_subtitle_widget = 0;
605 PyObject *eServiceDVD::getSubtitleList()
607 eDebug("eServiceDVD::getSubtitleList nyi");
611 PyObject *eServiceDVD::getCachedSubtitle()
613 eDebug("eServiceDVD::getCachedSubtitle nyi");
617 RESULT eServiceDVD::getLength(pts_t &len)
619 // eDebug("eServiceDVD::getLength");
620 struct ddvd_time info;
621 ddvd_get_last_time(m_ddvdconfig, &info);
622 len = info.end_hours * 3600;
623 len += info.end_minutes * 60;
624 len += info.end_seconds;
629 RESULT eServiceDVD::seekTo(pts_t to)
631 eDebug("eServiceDVD::seekTo(%lld)",to);
634 eDebug("set_resume_pos: resume_info.title=%d, chapter=%d, block=%lu, audio_id=%d, audio_lock=%d, spu_id=%d, spu_lock=%d",m_resume_info.title,m_resume_info.chapter,m_resume_info.block,m_resume_info.audio_id, m_resume_info.audio_lock, m_resume_info.spu_id, m_resume_info.spu_lock);
635 ddvd_set_resume_pos(m_ddvdconfig, m_resume_info);
640 RESULT eServiceDVD::seekRelative(int direction, pts_t to)
642 int seconds = to / 90000;
643 seconds *= direction;
644 eDebug("seekRelative %d %d", direction, seconds);
645 ddvd_skip_seconds(m_ddvdconfig, seconds);
649 RESULT eServiceDVD::getPlayPosition(pts_t &pos)
651 struct ddvd_time info;
652 ddvd_get_last_time(m_ddvdconfig, &info);
653 pos = info.pos_hours * 3600;
654 pos += info.pos_minutes * 60;
655 pos += info.pos_seconds;
656 // eDebug("getPlayPosition %lld", pos);
661 RESULT eServiceDVD::seekTitle(int title)
663 eDebug("setTitle %d", title);
664 ddvd_set_title(m_ddvdconfig, title);
668 RESULT eServiceDVD::seekChapter(int chapter)
670 eDebug("setChapter %d", chapter);
672 ddvd_set_chapter(m_ddvdconfig, chapter);
676 RESULT eServiceDVD::setTrickmode(int /*trick*/)
681 RESULT eServiceDVD::isCurrentlySeekable()
683 return m_state == stRunning;
686 RESULT eServiceDVD::keyPressed(int key)
690 case iServiceKeys::keyLeft:
691 ddvd_send_key(m_ddvdconfig, DDVD_KEY_LEFT);
693 case iServiceKeys::keyRight:
694 ddvd_send_key(m_ddvdconfig, DDVD_KEY_RIGHT);
696 case iServiceKeys::keyUp:
697 ddvd_send_key(m_ddvdconfig, DDVD_KEY_UP);
699 case iServiceKeys::keyDown:
700 ddvd_send_key(m_ddvdconfig, DDVD_KEY_DOWN);
702 case iServiceKeys::keyOk:
703 ddvd_send_key(m_ddvdconfig, DDVD_KEY_OK);
705 case iServiceKeys::keyUser:
706 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIO);
708 case iServiceKeys::keyUser+1:
709 ddvd_send_key(m_ddvdconfig, DDVD_KEY_SUBTITLE);
711 case iServiceKeys::keyUser+2:
712 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIOMENU);
714 case iServiceKeys::keyUser+3:
715 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_CHAPTER);
717 case iServiceKeys::keyUser+4:
718 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_CHAPTER);
720 case iServiceKeys::keyUser+5:
721 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_TITLE);
723 case iServiceKeys::keyUser+6:
724 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_TITLE);
726 case iServiceKeys::keyUser+7:
727 ddvd_send_key(m_ddvdconfig, DDVD_KEY_MENU);
729 case iServiceKeys::keyUser+8:
730 ddvd_send_key(m_ddvdconfig, DDVD_KEY_ANGLE);
738 RESULT eServiceDVD::cueSheet(ePtr<iCueSheet> &ptr)
749 PyObject *eServiceDVD::getCutList()
751 ePyObject list = PyList_New(1);
752 ePyObject tuple = PyTuple_New(2);
753 PyTuple_SetItem(tuple, 0, PyLong_FromLongLong(m_cue_pts));
754 PyTuple_SetItem(tuple, 1, PyInt_FromLong(3));
755 PyList_SetItem(list, 0, tuple);
759 void eServiceDVD::setCutList(ePyObject /*list*/)
763 void eServiceDVD::setCutListEnable(int /*enable*/)
767 void eServiceDVD::loadCuesheet()
770 if ( m_ddvd_titlestring[0] != '\0' )
771 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
773 snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
775 eDebug("eServiceDVD::loadCuesheet() filename=%s",filename);
777 FILE *f = fopen(filename, "rb");
781 unsigned long long where;
784 if (!fread(&where, sizeof(where), 1, f))
786 if (!fread(&what, sizeof(what), 1, f))
788 #if BYTE_ORDER == LITTLE_ENDIAN
789 where = bswap_64(where);
793 if (!fread(&m_resume_info, sizeof(struct ddvd_resume), 1, f))
795 if (!fread(&what, sizeof(what), 1, f))
806 eDebug("cutfile not found!");
810 m_event((iPlayableService*)this, evCuesheetChanged);
811 eDebug("eServiceDVD::loadCuesheet() pts=%lld",m_cue_pts);
815 void eServiceDVD::saveCuesheet()
817 eDebug("eServiceDVD::saveCuesheet()");
819 struct ddvd_resume resume_info;
820 ddvd_get_resume_pos(m_ddvdconfig, &resume_info);
822 if (resume_info.title)
824 struct ddvd_time info;
825 ddvd_get_last_time(m_ddvdconfig, &info);
827 pos = info.pos_hours * 3600;
828 pos += info.pos_minutes * 60;
829 pos += info.pos_seconds;
832 eDebug("ddvd_get_resume_pos resume_info.title=%d, chapter=%d, block=%lu, audio_id=%d, audio_lock=%d, spu_id=%d, spu_lock=%d (pts=%llu)",resume_info.title,resume_info.chapter,resume_info.block,resume_info.audio_id, resume_info.audio_lock, resume_info.spu_id, resume_info.spu_lock,m_cue_pts);
836 eDebug("we're in a menu or somewhere else funny. so save cuesheet with pts=0");
841 if ( m_ddvd_titlestring[0] != '\0' )
842 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
844 snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
846 FILE *f = fopen(filename, "wb");
850 unsigned long long where;
853 #if BYTE_ORDER == BIG_ENDIAN
856 where = bswap_64(m_cue_pts);
859 fwrite(&where, sizeof(where), 1, f);
860 fwrite(&what, sizeof(what), 1, f);
863 fwrite(&resume_info, sizeof(struct ddvd_resume), 1, f);
864 fwrite(&what, sizeof(what), 1, f);
870 eAutoInitPtr<eServiceFactoryDVD> init_eServiceFactoryDVD(eAutoInitNumbers::service+1, "eServiceFactoryDVD");
875 Py_InitModule("servicedvd", NULL);