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;
97 int policy2 = DDVD_PAN_SCAN;
102 m_sn = eSocketNotifier::create(eApp, ddvd_get_messagepipe_fd(m_ddvdconfig), eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup);
103 eDebug("SERVICEDVD construct!");
105 ddvd_set_dvd_path(m_ddvdconfig, ref.path.c_str());
106 ddvd_set_ac3thru(m_ddvdconfig, 0);
108 std::string ddvd_language;
109 if (!ePythonConfigQuery::getConfigValue("config.osd.language", ddvd_language))
110 ddvd_set_language(m_ddvdconfig, (ddvd_language.substr(0,2)).c_str());
112 int fd = open("/proc/stb/video/aspect", O_RDONLY);
115 rd = read(fd, tmp, 255);
116 if (rd > 2 && !strncmp(tmp, "4:3", 3))
118 else if (rd > 4 && !strncmp(tmp, "16:10", 5))
123 fd = open("/proc/stb/video/policy", O_RDONLY);
126 rd = read(fd, tmp, 255);
127 if (rd > 6 && !strncmp(tmp, "bestfit", 7))
128 policy = DDVD_JUSTSCALE;
129 else if (rd > 8 && !strncmp(tmp, "letterbox", 9))
130 policy = DDVD_LETTERBOX;
134 #ifdef DDVD_SUPPORTS_16_10_SCALING
135 fd = open("/proc/stb/video/policy2", O_RDONLY);
138 rd = read(fd, tmp, 255);
139 if (rd > 6 && !strncmp(tmp, "bestfit", 7))
140 policy2 = DDVD_JUSTSCALE;
141 else if (rd > 8 && !strncmp(tmp, "letterbox", 9))
142 policy2 = DDVD_LETTERBOX;
145 ddvd_set_video_ex(m_ddvdconfig, aspect, policy, policy2, DDVD_PAL /*unused*/);
147 ddvd_set_video(m_ddvdconfig, aspect, policy, DDVD_PAL /*unused*/);
148 #warning please update libdreamdvd for 16:10 scaling support!
151 CONNECT(m_sn->activated, eServiceDVD::gotMessage);
152 CONNECT(m_pump.recv_msg, eServiceDVD::gotThreadMessage);
153 strcpy(m_ddvd_titlestring,"");
158 void eServiceDVD::gotThreadMessage(const int &msg)
162 case 1: // thread stopped
164 m_event(this, evStopped);
169 void eServiceDVD::gotMessage(int /*what*/)
171 switch(ddvd_get_next_message(m_ddvdconfig,1))
173 case DDVD_COLORTABLE_UPDATE:
176 struct ddvd_color ctmp[4];
177 ddvd_get_last_colortable(ddvdconfig, ctmp);
181 rd1[252+i]=ctmp[i].red;
182 bl1[252+i]=ctmp[i].blue;
183 gn1[252+i]=ctmp[i].green;
184 tr1[252+i]=ctmp[i].trans;
187 if(ioctl(fb, FBIOPUTCMAP, &colormap) == -1)
189 printf("Framebuffer: <FBIOPUTCMAP failed>\n");
193 eDebug("no support for 8bpp framebuffer in dvdplayer yet!");
196 case DDVD_SCREEN_UPDATE:
197 eDebug("DVD_SCREEN_UPDATE!");
198 if (m_subtitle_widget) {
200 ddvd_get_last_blit_area(m_ddvdconfig, &x1, &x2, &y1, &y2);
202 int x_offset = 0, y_offset = 0, width = 720, height = 576;
204 #ifdef DDVD_SUPPORTS_GET_BLIT_DESTINATION
205 ddvd_get_blit_destination(m_ddvdconfig, &x_offset, &y_offset, &width, &height);
206 eDebug("values got from ddvd: %d %d %d %d", x_offset, y_offset, width, height);
207 y_offset = -y_offset;
208 width -= x_offset * 2;
209 height -= y_offset * 2;
211 eRect dest(x_offset, y_offset, width, height);
213 if (dest.width() && dest.height())
214 m_subtitle_widget->setPixmap(m_pixmap, eRect(x1, y1, (x2-x1)+1, (y2-y1)+1), dest);
217 case DDVD_SHOWOSD_STATE_PLAY:
219 eDebug("DVD_SHOWOSD_STATE_PLAY!");
221 m_event(this, evUser+1);
224 case DDVD_SHOWOSD_STATE_PAUSE:
226 eDebug("DVD_SHOWOSD_STATE_PAUSE!");
227 m_event(this, evUser+2);
230 case DDVD_SHOWOSD_STATE_FFWD:
232 eDebug("DVD_SHOWOSD_STATE_FFWD!");
233 m_event(this, evUser+3);
236 case DDVD_SHOWOSD_STATE_FBWD:
238 eDebug("DVD_SHOWOSD_STATE_FBWD!");
239 m_event(this, evUser+4);
242 case DDVD_SHOWOSD_STRING:
244 eDebug("DVD_SHOWOSD_STRING!");
245 m_event(this, evUser+5);
248 case DDVD_SHOWOSD_AUDIO:
250 eDebug("DVD_SHOWOSD_STRING!");
251 m_event(this, evUser+6);
254 case DDVD_SHOWOSD_SUBTITLE:
256 eDebug("DVD_SHOWOSD_SUBTITLE!");
257 m_event((iPlayableService*)this, evUpdatedInfo);
258 m_event(this, evUser+7);
261 case DDVD_EOF_REACHED:
262 eDebug("DVD_EOF_REACHED!");
263 m_event(this, evEOF);
265 case DDVD_SOF_REACHED:
266 eDebug("DVD_SOF_REACHED!");
267 m_event(this, evSOF);
269 case DDVD_SHOWOSD_ANGLE:
272 ddvd_get_angle_info(m_ddvdconfig, ¤t, &num);
273 eDebug("DVD_ANGLE_INFO: %d / %d", current, num);
274 m_event(this, evUser+13);
277 case DDVD_SHOWOSD_TIME:
279 static struct ddvd_time last_info;
280 struct ddvd_time info;
281 // eDebug("DVD_SHOWOSD_TIME!");
282 ddvd_get_last_time(m_ddvdconfig, &info);
283 if ( info.pos_chapter != last_info.pos_chapter )
284 m_event(this, evUser+8); // chapterUpdated
285 if ( info.pos_title != last_info.pos_title )
286 m_event(this, evUser+9); // titleUpdated
287 memcpy(&last_info, &info, sizeof(struct ddvd_time));
290 case DDVD_SHOWOSD_TITLESTRING:
292 ddvd_get_title_string(m_ddvdconfig, m_ddvd_titlestring);
293 eDebug("DDVD_SHOWOSD_TITLESTRING: %s",m_ddvd_titlestring);
297 m_event(this, evStart);
300 case DDVD_MENU_OPENED:
301 eDebug("DVD_MENU_OPENED!");
303 m_event(this, evSeekableStatusChanged);
304 m_event(this, evUser+11);
306 case DDVD_MENU_CLOSED:
307 eDebug("DVD_MENU_CLOSED!");
309 m_event(this, evSeekableStatusChanged);
310 m_event(this, evUser+12);
317 eServiceDVD::~eServiceDVD()
319 eDebug("SERVICEDVD destruct!");
322 ddvd_close(m_ddvdconfig);
326 RESULT eServiceDVD::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
328 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
332 RESULT eServiceDVD::start()
334 ASSERT(m_state == stIdle);
336 eDebug("eServiceDVD starting");
337 // m_event(this, evStart);
341 RESULT eServiceDVD::stop()
343 ASSERT(m_state != stIdle);
344 if (m_state == stStopped)
346 eDebug("DVD: stop %s", m_ref.path.c_str());
348 ddvd_send_key(m_ddvdconfig, DDVD_KEY_EXIT);
353 RESULT eServiceDVD::setTarget(int /*target*/)
358 RESULT eServiceDVD::pause(ePtr<iPauseableService> &ptr)
364 RESULT eServiceDVD::seek(ePtr<iSeekableService> &ptr)
370 RESULT eServiceDVD::subtitle(ePtr<iSubtitleOutput> &ptr)
376 RESULT eServiceDVD::keys(ePtr<iServiceKeys> &ptr)
383 RESULT eServiceDVD::setSlowMotion(int /*ratio*/)
388 RESULT eServiceDVD::setFastForward(int trick)
390 eDebug("setTrickmode(%d)", trick);
391 while (m_current_trick > trick && m_current_trick != -64)
393 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FBWD);
394 if (m_current_trick == 0)
395 m_current_trick = -2;
396 else if (m_current_trick > 0)
398 m_current_trick /= 2;
399 if (abs(m_current_trick) == 1)
403 m_current_trick *= 2;
405 while (m_current_trick < trick && m_current_trick != 64)
407 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FFWD);
408 if (m_current_trick == 0)
410 else if (m_current_trick < 0)
412 m_current_trick /= 2;
413 if (abs(m_current_trick) == 1)
417 m_current_trick *= 2;
422 RESULT eServiceDVD::pause()
424 eDebug("set pause!\n");
425 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PAUSE);
429 RESULT eServiceDVD::unpause()
431 eDebug("set unpause!\n");
432 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PLAY);
436 void eServiceDVD::thread()
438 eDebug("eServiceDVD dvd thread started");
440 ddvd_run(m_ddvdconfig);
443 void eServiceDVD::thread_finished()
445 eDebug("eServiceDVD dvd thread finished");
446 m_pump.send(1); // inform main thread
449 RESULT eServiceDVD::info(ePtr<iServiceInformation>&i)
455 RESULT eServiceDVD::getName(std::string &name)
457 if ( m_ddvd_titlestring[0] != '\0' )
458 name = m_ddvd_titlestring;
464 int eServiceDVD::getInfo(int w)
468 case sCurrentChapter:
470 struct ddvd_time info;
471 ddvd_get_last_time(m_ddvdconfig, &info);
472 return info.pos_chapter;
476 struct ddvd_time info;
477 ddvd_get_last_time(m_ddvdconfig, &info);
478 return info.end_chapter;
482 struct ddvd_time info;
483 ddvd_get_last_time(m_ddvdconfig, &info);
484 return info.pos_title;
488 struct ddvd_time info;
489 ddvd_get_last_time(m_ddvdconfig, &info);
490 return info.end_title;
492 case sTXTPID: // we abuse HAS_TELEXT icon in InfoBar to signalize subtitles status
496 ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
502 return resIsPyObject;
508 std::string eServiceDVD::getInfoString(int w)
513 return m_ref.toString();
515 eDebug("unhandled getInfoString(%d)", w);
520 PyObject *eServiceDVD::getInfoObject(int w)
526 ePyObject tuple = PyTuple_New(3);
527 int audio_id,audio_type;
529 ddvd_get_last_audio(m_ddvdconfig, &audio_id, &audio_lang, &audio_type);
530 char audio_string[3]={audio_lang >> 8, audio_lang, 0};
531 PyTuple_SetItem(tuple, 0, PyInt_FromLong(audio_id+1));
532 PyTuple_SetItem(tuple, 1, PyString_FromString(audio_string));
536 PyTuple_SetItem(tuple, 2, PyString_FromString("MPEG"));
539 PyTuple_SetItem(tuple, 2, PyString_FromString("AC3"));
542 PyTuple_SetItem(tuple, 2, PyString_FromString("DTS"));
545 PyTuple_SetItem(tuple, 2, PyString_FromString("LPCM"));
548 PyTuple_SetItem(tuple, 2, PyString_FromString(""));
554 ePyObject tuple = PyTuple_New(2);
557 ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
558 char spu_string[3]={spu_lang >> 8, spu_lang, 0};
561 PyTuple_SetItem(tuple, 0, PyInt_FromLong(0));
562 PyTuple_SetItem(tuple, 1, PyString_FromString(""));
566 PyTuple_SetItem(tuple, 0, PyInt_FromLong(spu_id+1));
567 PyTuple_SetItem(tuple, 1, PyString_FromString(spu_string));
573 ePyObject tuple = PyTuple_New(2);
575 ddvd_get_angle_info(m_ddvdconfig, ¤t, &num);
576 PyTuple_SetItem(tuple, 0, PyInt_FromLong(current));
577 PyTuple_SetItem(tuple, 1, PyInt_FromLong(num));
582 eDebug("unhandled getInfoObject(%d)", w);
587 RESULT eServiceDVD::enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) /*entry*/)
589 delete m_subtitle_widget;
591 m_subtitle_widget = new eSubtitleWidget(parent);
592 m_subtitle_widget->resize(parent->size());
594 eSize size = eSize(720, 576);
598 m_pixmap = new gPixmap(size, 32, 1); /* allocate accel surface (if possible) */
599 #ifdef DDVD_SUPPORTS_GET_BLIT_DESTINATION
600 ddvd_set_lfb_ex(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4, 1);
602 ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4);
603 #warning please update libdreamdvd for fast scaling
605 run(); // start the thread
608 m_subtitle_widget->setZPosition(-1);
609 m_subtitle_widget->show();
614 RESULT eServiceDVD::disableSubtitles(eWidget */*parent*/)
616 delete m_subtitle_widget;
617 m_subtitle_widget = 0;
621 PyObject *eServiceDVD::getSubtitleList()
623 eDebug("eServiceDVD::getSubtitleList nyi");
627 PyObject *eServiceDVD::getCachedSubtitle()
629 eDebug("eServiceDVD::getCachedSubtitle nyi");
633 RESULT eServiceDVD::getLength(pts_t &len)
635 // eDebug("eServiceDVD::getLength");
636 struct ddvd_time info;
637 ddvd_get_last_time(m_ddvdconfig, &info);
638 len = info.end_hours * 3600;
639 len += info.end_minutes * 60;
640 len += info.end_seconds;
645 RESULT eServiceDVD::seekTo(pts_t to)
647 eDebug("eServiceDVD::seekTo(%lld)",to);
650 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);
651 ddvd_set_resume_pos(m_ddvdconfig, m_resume_info);
656 RESULT eServiceDVD::seekRelative(int direction, pts_t to)
658 int seconds = to / 90000;
659 seconds *= direction;
660 eDebug("seekRelative %d %d", direction, seconds);
661 ddvd_skip_seconds(m_ddvdconfig, seconds);
665 RESULT eServiceDVD::getPlayPosition(pts_t &pos)
667 struct ddvd_time info;
668 ddvd_get_last_time(m_ddvdconfig, &info);
669 pos = info.pos_hours * 3600;
670 pos += info.pos_minutes * 60;
671 pos += info.pos_seconds;
672 // eDebug("getPlayPosition %lld", pos);
677 RESULT eServiceDVD::seekTitle(int title)
679 eDebug("setTitle %d", title);
680 ddvd_set_title(m_ddvdconfig, title);
684 RESULT eServiceDVD::seekChapter(int chapter)
686 eDebug("setChapter %d", chapter);
688 ddvd_set_chapter(m_ddvdconfig, chapter);
692 RESULT eServiceDVD::setTrickmode(int /*trick*/)
697 RESULT eServiceDVD::isCurrentlySeekable()
699 return m_state == stRunning ? 3 : 0;
702 RESULT eServiceDVD::keyPressed(int key)
706 case iServiceKeys::keyLeft:
707 ddvd_send_key(m_ddvdconfig, DDVD_KEY_LEFT);
709 case iServiceKeys::keyRight:
710 ddvd_send_key(m_ddvdconfig, DDVD_KEY_RIGHT);
712 case iServiceKeys::keyUp:
713 ddvd_send_key(m_ddvdconfig, DDVD_KEY_UP);
715 case iServiceKeys::keyDown:
716 ddvd_send_key(m_ddvdconfig, DDVD_KEY_DOWN);
718 case iServiceKeys::keyOk:
719 ddvd_send_key(m_ddvdconfig, DDVD_KEY_OK);
721 case iServiceKeys::keyUser:
722 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIO);
724 case iServiceKeys::keyUser+1:
725 ddvd_send_key(m_ddvdconfig, DDVD_KEY_SUBTITLE);
727 case iServiceKeys::keyUser+2:
728 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIOMENU);
730 case iServiceKeys::keyUser+3:
731 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_CHAPTER);
733 case iServiceKeys::keyUser+4:
734 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_CHAPTER);
736 case iServiceKeys::keyUser+5:
737 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_TITLE);
739 case iServiceKeys::keyUser+6:
740 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_TITLE);
742 case iServiceKeys::keyUser+7:
743 ddvd_send_key(m_ddvdconfig, DDVD_KEY_MENU);
745 case iServiceKeys::keyUser+8:
746 ddvd_send_key(m_ddvdconfig, DDVD_KEY_ANGLE);
754 RESULT eServiceDVD::cueSheet(ePtr<iCueSheet> &ptr)
765 PyObject *eServiceDVD::getCutList()
767 ePyObject list = PyList_New(1);
768 ePyObject tuple = PyTuple_New(2);
769 PyTuple_SetItem(tuple, 0, PyLong_FromLongLong(m_cue_pts));
770 PyTuple_SetItem(tuple, 1, PyInt_FromLong(3));
771 PyList_SetItem(list, 0, tuple);
775 void eServiceDVD::setCutList(ePyObject /*list*/)
779 void eServiceDVD::setCutListEnable(int /*enable*/)
783 void eServiceDVD::loadCuesheet()
786 if ( m_ddvd_titlestring[0] != '\0' )
787 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
789 snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
791 eDebug("eServiceDVD::loadCuesheet() filename=%s",filename);
793 FILE *f = fopen(filename, "rb");
797 unsigned long long where;
800 if (!fread(&where, sizeof(where), 1, f))
802 if (!fread(&what, sizeof(what), 1, f))
804 #if BYTE_ORDER == LITTLE_ENDIAN
805 where = bswap_64(where);
809 if (!fread(&m_resume_info, sizeof(struct ddvd_resume), 1, f))
811 if (!fread(&what, sizeof(what), 1, f))
822 eDebug("cutfile not found!");
826 m_event((iPlayableService*)this, evCuesheetChanged);
827 eDebug("eServiceDVD::loadCuesheet() pts=%lld",m_cue_pts);
831 void eServiceDVD::saveCuesheet()
833 eDebug("eServiceDVD::saveCuesheet()");
835 struct ddvd_resume resume_info;
836 ddvd_get_resume_pos(m_ddvdconfig, &resume_info);
838 if (resume_info.title)
840 struct ddvd_time info;
841 ddvd_get_last_time(m_ddvdconfig, &info);
843 pos = info.pos_hours * 3600;
844 pos += info.pos_minutes * 60;
845 pos += info.pos_seconds;
848 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);
852 eDebug("we're in a menu or somewhere else funny. so save cuesheet with pts=0");
857 if ( m_ddvd_titlestring[0] != '\0' )
858 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
860 snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
862 FILE *f = fopen(filename, "wb");
866 unsigned long long where;
869 #if BYTE_ORDER == BIG_ENDIAN
872 where = bswap_64(m_cue_pts);
875 fwrite(&where, sizeof(where), 1, f);
876 fwrite(&what, sizeof(what), 1, f);
879 fwrite(&resume_info, sizeof(struct ddvd_resume), 1, f);
880 fwrite(&what, sizeof(what), 1, f);
886 eAutoInitPtr<eServiceFactoryDVD> init_eServiceFactoryDVD(eAutoInitNumbers::service+1, "eServiceFactoryDVD");
891 Py_InitModule("servicedvd", NULL);