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 width -= x_offset * 2;
192 height -= y_offset * 2;
194 eRect dest(x_offset, y_offset, width, height);
196 if (dest.width() && dest.height())
197 m_subtitle_widget->setPixmap(m_pixmap, eRect(x1, y1, (x2-x1)+1, (y2-y1)+1), dest);
200 case DDVD_SHOWOSD_STATE_PLAY:
202 eDebug("DVD_SHOWOSD_STATE_PLAY!");
204 m_event(this, evUser+1);
207 case DDVD_SHOWOSD_STATE_PAUSE:
209 eDebug("DVD_SHOWOSD_STATE_PAUSE!");
210 m_event(this, evUser+2);
213 case DDVD_SHOWOSD_STATE_FFWD:
215 eDebug("DVD_SHOWOSD_STATE_FFWD!");
216 m_event(this, evUser+3);
219 case DDVD_SHOWOSD_STATE_FBWD:
221 eDebug("DVD_SHOWOSD_STATE_FBWD!");
222 m_event(this, evUser+4);
225 case DDVD_SHOWOSD_STRING:
227 eDebug("DVD_SHOWOSD_STRING!");
228 m_event(this, evUser+5);
231 case DDVD_SHOWOSD_AUDIO:
233 eDebug("DVD_SHOWOSD_STRING!");
234 m_event(this, evUser+6);
237 case DDVD_SHOWOSD_SUBTITLE:
239 eDebug("DVD_SHOWOSD_SUBTITLE!");
240 m_event((iPlayableService*)this, evUpdatedInfo);
241 m_event(this, evUser+7);
244 case DDVD_EOF_REACHED:
245 eDebug("DVD_EOF_REACHED!");
246 m_event(this, evEOF);
248 case DDVD_SOF_REACHED:
249 eDebug("DVD_SOF_REACHED!");
250 m_event(this, evSOF);
252 case DDVD_SHOWOSD_ANGLE:
255 ddvd_get_angle_info(m_ddvdconfig, ¤t, &num);
256 eDebug("DVD_ANGLE_INFO: %d / %d", current, num);
257 m_event(this, evUser+13);
260 case DDVD_SHOWOSD_TIME:
262 static struct ddvd_time last_info;
263 struct ddvd_time info;
264 // eDebug("DVD_SHOWOSD_TIME!");
265 ddvd_get_last_time(m_ddvdconfig, &info);
266 if ( info.pos_chapter != last_info.pos_chapter )
267 m_event(this, evUser+8); // chapterUpdated
268 if ( info.pos_title != last_info.pos_title )
269 m_event(this, evUser+9); // titleUpdated
270 memcpy(&last_info, &info, sizeof(struct ddvd_time));
273 case DDVD_SHOWOSD_TITLESTRING:
275 ddvd_get_title_string(m_ddvdconfig, m_ddvd_titlestring);
276 eDebug("DDVD_SHOWOSD_TITLESTRING: %s",m_ddvd_titlestring);
280 m_event(this, evStart);
283 case DDVD_MENU_OPENED:
284 eDebug("DVD_MENU_OPENED!");
286 m_event(this, evSeekableStatusChanged);
287 m_event(this, evUser+11);
289 case DDVD_MENU_CLOSED:
290 eDebug("DVD_MENU_CLOSED!");
292 m_event(this, evSeekableStatusChanged);
293 m_event(this, evUser+12);
300 eServiceDVD::~eServiceDVD()
302 eDebug("SERVICEDVD destruct!");
305 ddvd_close(m_ddvdconfig);
309 RESULT eServiceDVD::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
311 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
315 RESULT eServiceDVD::start()
317 ASSERT(m_state == stIdle);
319 eDebug("eServiceDVD starting");
320 // m_event(this, evStart);
324 RESULT eServiceDVD::stop()
326 ASSERT(m_state != stIdle);
327 if (m_state == stStopped)
329 eDebug("DVD: stop %s", m_ref.path.c_str());
331 ddvd_send_key(m_ddvdconfig, DDVD_KEY_EXIT);
336 RESULT eServiceDVD::setTarget(int /*target*/)
341 RESULT eServiceDVD::pause(ePtr<iPauseableService> &ptr)
347 RESULT eServiceDVD::seek(ePtr<iSeekableService> &ptr)
353 RESULT eServiceDVD::subtitle(ePtr<iSubtitleOutput> &ptr)
359 RESULT eServiceDVD::keys(ePtr<iServiceKeys> &ptr)
366 RESULT eServiceDVD::setSlowMotion(int /*ratio*/)
371 RESULT eServiceDVD::setFastForward(int trick)
373 eDebug("setTrickmode(%d)", trick);
374 while (m_current_trick > trick && m_current_trick != -64)
376 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FBWD);
377 if (m_current_trick == 0)
378 m_current_trick = -2;
379 else if (m_current_trick > 0)
381 m_current_trick /= 2;
382 if (abs(m_current_trick) == 1)
386 m_current_trick *= 2;
388 while (m_current_trick < trick && m_current_trick != 64)
390 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FFWD);
391 if (m_current_trick == 0)
393 else if (m_current_trick < 0)
395 m_current_trick /= 2;
396 if (abs(m_current_trick) == 1)
400 m_current_trick *= 2;
405 RESULT eServiceDVD::pause()
407 eDebug("set pause!\n");
408 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PAUSE);
412 RESULT eServiceDVD::unpause()
414 eDebug("set unpause!\n");
415 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PLAY);
419 void eServiceDVD::thread()
421 eDebug("eServiceDVD dvd thread started");
423 ddvd_run(m_ddvdconfig);
426 void eServiceDVD::thread_finished()
428 eDebug("eServiceDVD dvd thread finished");
429 m_pump.send(1); // inform main thread
432 RESULT eServiceDVD::info(ePtr<iServiceInformation>&i)
438 RESULT eServiceDVD::getName(std::string &name)
440 if ( m_ddvd_titlestring[0] != '\0' )
441 name = m_ddvd_titlestring;
447 int eServiceDVD::getInfo(int w)
451 case sCurrentChapter:
453 struct ddvd_time info;
454 ddvd_get_last_time(m_ddvdconfig, &info);
455 return info.pos_chapter;
459 struct ddvd_time info;
460 ddvd_get_last_time(m_ddvdconfig, &info);
461 return info.end_chapter;
465 struct ddvd_time info;
466 ddvd_get_last_time(m_ddvdconfig, &info);
467 return info.pos_title;
471 struct ddvd_time info;
472 ddvd_get_last_time(m_ddvdconfig, &info);
473 return info.end_title;
475 case sTXTPID: // we abuse HAS_TELEXT icon in InfoBar to signalize subtitles status
479 ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
485 return resIsPyObject;
491 std::string eServiceDVD::getInfoString(int w)
496 return m_ref.toString();
498 eDebug("unhandled getInfoString(%d)", w);
503 PyObject *eServiceDVD::getInfoObject(int w)
509 ePyObject tuple = PyTuple_New(3);
510 int audio_id,audio_type;
512 ddvd_get_last_audio(m_ddvdconfig, &audio_id, &audio_lang, &audio_type);
513 char audio_string[3]={audio_lang >> 8, audio_lang, 0};
514 PyTuple_SetItem(tuple, 0, PyInt_FromLong(audio_id+1));
515 PyTuple_SetItem(tuple, 1, PyString_FromString(audio_string));
519 PyTuple_SetItem(tuple, 2, PyString_FromString("MPEG"));
522 PyTuple_SetItem(tuple, 2, PyString_FromString("AC3"));
525 PyTuple_SetItem(tuple, 2, PyString_FromString("DTS"));
528 PyTuple_SetItem(tuple, 2, PyString_FromString("LPCM"));
531 PyTuple_SetItem(tuple, 2, PyString_FromString(""));
537 ePyObject tuple = PyTuple_New(2);
540 ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
541 char spu_string[3]={spu_lang >> 8, spu_lang, 0};
544 PyTuple_SetItem(tuple, 0, PyInt_FromLong(0));
545 PyTuple_SetItem(tuple, 1, PyString_FromString(""));
549 PyTuple_SetItem(tuple, 0, PyInt_FromLong(spu_id+1));
550 PyTuple_SetItem(tuple, 1, PyString_FromString(spu_string));
556 ePyObject tuple = PyTuple_New(2);
558 ddvd_get_angle_info(m_ddvdconfig, ¤t, &num);
559 PyTuple_SetItem(tuple, 0, PyInt_FromLong(current));
560 PyTuple_SetItem(tuple, 1, PyInt_FromLong(num));
565 eDebug("unhandled getInfoObject(%d)", w);
570 RESULT eServiceDVD::enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) /*entry*/)
572 delete m_subtitle_widget;
574 m_subtitle_widget = new eSubtitleWidget(parent);
575 m_subtitle_widget->resize(parent->size());
577 eSize size = eSize(720, 576);
581 m_pixmap = new gPixmap(size, 32, 1); /* allocate accel surface (if possible) */
582 #ifdef DDVD_SUPPORTS_GET_BLIT_DESTINATION
583 ddvd_set_lfb_ex(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4, 1);
585 ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4);
586 #warning please update libdreamdvd for fast scaling
588 run(); // start the thread
591 m_subtitle_widget->setZPosition(-1);
592 m_subtitle_widget->show();
597 RESULT eServiceDVD::disableSubtitles(eWidget */*parent*/)
599 delete m_subtitle_widget;
600 m_subtitle_widget = 0;
604 PyObject *eServiceDVD::getSubtitleList()
606 eDebug("eServiceDVD::getSubtitleList nyi");
610 PyObject *eServiceDVD::getCachedSubtitle()
612 eDebug("eServiceDVD::getCachedSubtitle nyi");
616 RESULT eServiceDVD::getLength(pts_t &len)
618 // eDebug("eServiceDVD::getLength");
619 struct ddvd_time info;
620 ddvd_get_last_time(m_ddvdconfig, &info);
621 len = info.end_hours * 3600;
622 len += info.end_minutes * 60;
623 len += info.end_seconds;
628 RESULT eServiceDVD::seekTo(pts_t to)
630 eDebug("eServiceDVD::seekTo(%lld)",to);
633 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);
634 ddvd_set_resume_pos(m_ddvdconfig, m_resume_info);
639 RESULT eServiceDVD::seekRelative(int direction, pts_t to)
641 int seconds = to / 90000;
642 seconds *= direction;
643 eDebug("seekRelative %d %d", direction, seconds);
644 ddvd_skip_seconds(m_ddvdconfig, seconds);
648 RESULT eServiceDVD::getPlayPosition(pts_t &pos)
650 struct ddvd_time info;
651 ddvd_get_last_time(m_ddvdconfig, &info);
652 pos = info.pos_hours * 3600;
653 pos += info.pos_minutes * 60;
654 pos += info.pos_seconds;
655 // eDebug("getPlayPosition %lld", pos);
660 RESULT eServiceDVD::seekTitle(int title)
662 eDebug("setTitle %d", title);
663 ddvd_set_title(m_ddvdconfig, title);
667 RESULT eServiceDVD::seekChapter(int chapter)
669 eDebug("setChapter %d", chapter);
671 ddvd_set_chapter(m_ddvdconfig, chapter);
675 RESULT eServiceDVD::setTrickmode(int /*trick*/)
680 RESULT eServiceDVD::isCurrentlySeekable()
682 return m_state == stRunning;
685 RESULT eServiceDVD::keyPressed(int key)
689 case iServiceKeys::keyLeft:
690 ddvd_send_key(m_ddvdconfig, DDVD_KEY_LEFT);
692 case iServiceKeys::keyRight:
693 ddvd_send_key(m_ddvdconfig, DDVD_KEY_RIGHT);
695 case iServiceKeys::keyUp:
696 ddvd_send_key(m_ddvdconfig, DDVD_KEY_UP);
698 case iServiceKeys::keyDown:
699 ddvd_send_key(m_ddvdconfig, DDVD_KEY_DOWN);
701 case iServiceKeys::keyOk:
702 ddvd_send_key(m_ddvdconfig, DDVD_KEY_OK);
704 case iServiceKeys::keyUser:
705 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIO);
707 case iServiceKeys::keyUser+1:
708 ddvd_send_key(m_ddvdconfig, DDVD_KEY_SUBTITLE);
710 case iServiceKeys::keyUser+2:
711 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIOMENU);
713 case iServiceKeys::keyUser+3:
714 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_CHAPTER);
716 case iServiceKeys::keyUser+4:
717 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_CHAPTER);
719 case iServiceKeys::keyUser+5:
720 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_TITLE);
722 case iServiceKeys::keyUser+6:
723 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_TITLE);
725 case iServiceKeys::keyUser+7:
726 ddvd_send_key(m_ddvdconfig, DDVD_KEY_MENU);
728 case iServiceKeys::keyUser+8:
729 ddvd_send_key(m_ddvdconfig, DDVD_KEY_ANGLE);
737 RESULT eServiceDVD::cueSheet(ePtr<iCueSheet> &ptr)
748 PyObject *eServiceDVD::getCutList()
750 ePyObject list = PyList_New(1);
751 ePyObject tuple = PyTuple_New(2);
752 PyTuple_SetItem(tuple, 0, PyLong_FromLongLong(m_cue_pts));
753 PyTuple_SetItem(tuple, 1, PyInt_FromLong(3));
754 PyList_SetItem(list, 0, tuple);
758 void eServiceDVD::setCutList(ePyObject /*list*/)
762 void eServiceDVD::setCutListEnable(int /*enable*/)
766 void eServiceDVD::loadCuesheet()
769 if ( m_ddvd_titlestring[0] != '\0' )
770 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
772 snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
774 eDebug("eServiceDVD::loadCuesheet() filename=%s",filename);
776 FILE *f = fopen(filename, "rb");
780 unsigned long long where;
783 if (!fread(&where, sizeof(where), 1, f))
785 if (!fread(&what, sizeof(what), 1, f))
787 #if BYTE_ORDER == LITTLE_ENDIAN
788 where = bswap_64(where);
792 if (!fread(&m_resume_info, sizeof(struct ddvd_resume), 1, f))
794 if (!fread(&what, sizeof(what), 1, f))
805 eDebug("cutfile not found!");
809 m_event((iPlayableService*)this, evCuesheetChanged);
810 eDebug("eServiceDVD::loadCuesheet() pts=%lld",m_cue_pts);
814 void eServiceDVD::saveCuesheet()
816 eDebug("eServiceDVD::saveCuesheet()");
818 struct ddvd_resume resume_info;
819 ddvd_get_resume_pos(m_ddvdconfig, &resume_info);
821 if (resume_info.title)
823 struct ddvd_time info;
824 ddvd_get_last_time(m_ddvdconfig, &info);
826 pos = info.pos_hours * 3600;
827 pos += info.pos_minutes * 60;
828 pos += info.pos_seconds;
831 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);
835 eDebug("we're in a menu or somewhere else funny. so save cuesheet with pts=0");
840 if ( m_ddvd_titlestring[0] != '\0' )
841 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
843 snprintf(filename, 128, "%s/dvd.cuts", m_ref.path.c_str());
845 FILE *f = fopen(filename, "wb");
849 unsigned long long where;
852 #if BYTE_ORDER == BIG_ENDIAN
855 where = bswap_64(m_cue_pts);
858 fwrite(&where, sizeof(where), 1, f);
859 fwrite(&what, sizeof(what), 1, f);
862 fwrite(&resume_info, sizeof(struct ddvd_resume), 1, f);
863 fwrite(&what, sizeof(what), 1, f);
869 eAutoInitPtr<eServiceFactoryDVD> init_eServiceFactoryDVD(eAutoInitNumbers::service+1, "eServiceFactoryDVD");
874 Py_InitModule("servicedvd", NULL);