servicedvd.cpp: fix typo
[enigma2.git] / lib / python / Plugins / Extensions / DVDPlayer / src / servicedvd.cpp
1 /* yes, it's dvd  */
2 #include <lib/base/eerror.h>
3 #include <lib/base/object.h>
4 #include <lib/base/ebase.h>
5 #include <lib/base/nconfig.h>
6 #include <string>
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>
12
13 #include <byteswap.h>
14 #include <netinet/in.h>
15 #ifndef BYTE_ORDER
16 #error no byte order defined!
17 #endif
18
19 extern "C" {
20 #include <dreamdvd/ddvdlib.h>
21 }
22 #include "servicedvd.h"
23
24 // eServiceFactoryDVD
25
26 eServiceFactoryDVD::eServiceFactoryDVD()
27 {
28         ePtr<eServiceCenter> sc;
29         
30         eServiceCenter::getPrivInstance(sc);
31         if (sc)
32         {
33                 std::list<std::string> extensions;
34                 extensions.push_back("iso");
35                 sc->addServiceFactory(eServiceFactoryDVD::id, this, extensions);
36         }
37 }
38
39 eServiceFactoryDVD::~eServiceFactoryDVD()
40 {
41         ePtr<eServiceCenter> sc;
42         
43         eServiceCenter::getPrivInstance(sc);
44         if (sc)
45                 sc->removeServiceFactory(eServiceFactoryDVD::id);
46 }
47
48 DEFINE_REF(eServiceFactoryDVD)
49
50         // iServiceHandler
51 RESULT eServiceFactoryDVD::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
52 {
53                 // check resources...
54         ptr = new eServiceDVD(ref.path.c_str());
55         return 0;
56 }
57
58 RESULT eServiceFactoryDVD::record(const eServiceReference &/*ref*/, ePtr<iRecordableService> &ptr)
59 {
60         ptr=0;
61         return -1;
62 }
63
64 RESULT eServiceFactoryDVD::list(const eServiceReference &, ePtr<iListableService> &ptr)
65 {
66         ptr=0;
67         return -1;
68 }
69
70
71 RESULT eServiceFactoryDVD::info(const eServiceReference &/*ref*/, ePtr<iStaticServiceInformation> &ptr)
72 {
73         ptr=0;
74         return -1;
75 }
76
77 RESULT eServiceFactoryDVD::offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr)
78 {
79         ptr = 0;
80         return -1;
81 }
82
83 // eServiceDVD
84
85 DEFINE_REF(eServiceDVD);
86
87 eServiceDVD::eServiceDVD(const char *filename):
88         m_filename(filename),
89         m_ddvdconfig(ddvd_create()),
90         m_subtitle_widget(0),
91         m_state(stIdle),
92         m_current_trick(0),
93         m_pump(eApp, 1)
94 {
95         int aspect = DDVD_16_9; 
96         int policy = DDVD_PAN_SCAN;
97
98         char tmp[255];
99         ssize_t rd;
100
101         m_sn = eSocketNotifier::create(eApp, ddvd_get_messagepipe_fd(m_ddvdconfig), eSocketNotifier::Read|eSocketNotifier::Priority|eSocketNotifier::Error|eSocketNotifier::Hungup);
102         eDebug("SERVICEDVD construct!");
103         // create handle
104         ddvd_set_dvd_path(m_ddvdconfig, filename);
105         ddvd_set_ac3thru(m_ddvdconfig, 0);
106         ddvd_set_language(m_ddvdconfig, "de");
107
108         int fd = open("/proc/stb/video/aspect", O_RDONLY);
109         if (fd > -1)
110         {
111                 rd = read(fd, tmp, 255);
112                 if (rd > 2 && !strncmp(tmp, "4:3", 3))
113                         aspect = DDVD_4_3;
114                 else if (rd > 4 && !strncmp(tmp, "16:10", 5))
115                         aspect = DDVD_16_10;
116                 close(fd);
117         }
118
119         fd = open("/proc/stb/video/policy", O_RDONLY);
120         if (fd > -1)
121         {
122                 rd = read(fd, tmp, 255);
123                 if (rd > 6 && !strncmp(tmp, "bestfit", 7))
124                         policy = DDVD_JUSTSCALE;
125                 else if (rd > 8 && !strncmp(tmp, "letterbox", 9))
126                         policy = DDVD_LETTERBOX;
127                 close(fd);
128         }
129
130         ddvd_set_video(m_ddvdconfig, aspect, policy, DDVD_PAL /*unused*/);
131
132         CONNECT(m_sn->activated, eServiceDVD::gotMessage);
133         CONNECT(m_pump.recv_msg, eServiceDVD::gotThreadMessage);
134         strcpy(m_ddvd_titlestring,"");
135         m_cue_pts = 0;
136         pause();
137 }
138
139 void eServiceDVD::gotThreadMessage(const int &msg)
140 {
141         switch(msg)
142         {
143         case 1: // thread stopped
144                 m_state = stStopped;
145                 m_event(this, evStopped);
146                 break;
147         }
148 }
149
150 void eServiceDVD::gotMessage(int /*what*/)
151 {
152         switch(ddvd_get_next_message(m_ddvdconfig,1))
153         {
154                 case DDVD_COLORTABLE_UPDATE:
155                 {
156 /*
157                         struct ddvd_color ctmp[4];
158                         ddvd_get_last_colortable(ddvdconfig, ctmp);
159                         int i=0;
160                         while (i < 4)
161                         {
162                                 rd1[252+i]=ctmp[i].red;
163                                 bl1[252+i]=ctmp[i].blue;
164                                 gn1[252+i]=ctmp[i].green;
165                                 tr1[252+i]=ctmp[i].trans;
166                                 i++;
167                         }
168                         if(ioctl(fb, FBIOPUTCMAP, &colormap) == -1)
169                         {
170                                 printf("Framebuffer: <FBIOPUTCMAP failed>\n");
171                                 return 1;
172                         }
173 */
174                         eDebug("no support for 8bpp framebuffer in dvdplayer yet!");
175                         break;
176                 }
177                 case DDVD_SCREEN_UPDATE:
178                         eDebug("DVD_SCREEN_UPDATE!");
179                         if (m_subtitle_widget) {
180                                 int x1,x2,y1,y2;
181                                 ddvd_get_last_blit_area(m_ddvdconfig, &x1, &x2, &y1, &y2);
182                                 m_subtitle_widget->setPixmap(m_pixmap, eRect(x1, y1, x2-x1, y2-y1));
183                         }
184                         break;
185                 case DDVD_SHOWOSD_STATE_PLAY:
186                 {
187                         eDebug("DVD_SHOWOSD_STATE_PLAY!");
188                         m_current_trick = 0;
189                         m_event(this, evUser+1);
190                         break;
191                 }
192                 case DDVD_SHOWOSD_STATE_PAUSE:
193                 {
194                         eDebug("DVD_SHOWOSD_STATE_PAUSE!");
195                         m_event(this, evUser+2);
196                         break;
197                 }
198                 case DDVD_SHOWOSD_STATE_FFWD:
199                 {
200                         eDebug("DVD_SHOWOSD_STATE_FFWD!");
201                         m_event(this, evUser+3);
202                         break;
203                 }
204                 case DDVD_SHOWOSD_STATE_FBWD:
205                 {
206                         eDebug("DVD_SHOWOSD_STATE_FBWD!");
207                         m_event(this, evUser+4);
208                         break;
209                 }
210                 case DDVD_SHOWOSD_STRING:
211                 {
212                         eDebug("DVD_SHOWOSD_STRING!");
213                         m_event(this, evUser+5);
214                         break;
215                 }
216                 case DDVD_SHOWOSD_AUDIO:
217                 {
218                         eDebug("DVD_SHOWOSD_STRING!");
219                         m_event(this, evUser+6);
220                         break;
221                 }
222                 case DDVD_SHOWOSD_SUBTITLE:
223                 {
224                         eDebug("DVD_SHOWOSD_SUBTITLE!");
225                         m_event((iPlayableService*)this, evUpdatedInfo);
226                         m_event(this, evUser+7);
227                         break;
228                 }
229                 case DDVD_EOF_REACHED:
230                         eDebug("DVD_EOF_REACHED!");
231                         m_event(this, evEOF);
232                         break;
233                 case DDVD_SOF_REACHED:
234                         eDebug("DVD_SOF_REACHED!");
235                         m_event(this, evSOF);
236                         break;
237                 case DDVD_SHOWOSD_TIME:
238                 {
239                         static struct ddvd_time last_info;
240                         struct ddvd_time info;
241 //                      eDebug("DVD_SHOWOSD_TIME!");
242                         ddvd_get_last_time(m_ddvdconfig, &info);
243                         if ( info.pos_chapter != last_info.pos_chapter )
244                                 m_event(this, evUser+8); // chapterUpdated
245                         if ( info.pos_title != last_info.pos_title )
246                                 m_event(this, evUser+9); // titleUpdated
247                         memcpy(&last_info, &info, sizeof(struct ddvd_time));
248                         break;
249                 }
250                 case DDVD_SHOWOSD_TITLESTRING:
251                 {
252                         ddvd_get_title_string(m_ddvdconfig, m_ddvd_titlestring);
253                         eDebug("DDVD_SHOWOSD_TITLESTRING: %s",m_ddvd_titlestring);
254                         loadCuesheet();
255                         if (!m_cue_pts)
256                                 unpause();
257                         m_event(this, evStart);
258                         break;
259                 }
260                 case DDVD_MENU_OPENED:
261                         eDebug("DVD_MENU_OPENED!");
262                         m_state = stMenu;
263                         m_event(this, evSeekableStatusChanged);
264                         m_event(this, evUser+11);
265                         break;
266                 case DDVD_MENU_CLOSED:
267                         eDebug("DVD_MENU_CLOSED!");
268                         m_state = stRunning;
269                         m_event(this, evSeekableStatusChanged);
270                         m_event(this, evUser+12);
271                         break;
272                 default:
273                         break;
274         }
275 }
276
277 eServiceDVD::~eServiceDVD()
278 {
279         eDebug("SERVICEDVD destruct!");
280         kill();
281         saveCuesheet();
282         ddvd_close(m_ddvdconfig);
283         disableSubtitles(0);
284 }
285
286 RESULT eServiceDVD::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
287 {
288         connection = new eConnection((iPlayableService*)this, m_event.connect(event));
289         return 0;
290 }
291
292 RESULT eServiceDVD::start()
293 {
294         assert(m_state == stIdle);
295         m_state = stRunning;
296         eDebug("eServiceDVD starting");
297 //      m_event(this, evStart);
298         return 0;
299 }
300
301 RESULT eServiceDVD::stop()
302 {
303         assert(m_state != stIdle);
304         if (m_state == stStopped)
305                 return -1;
306         eDebug("DVD: stop %s", m_filename.c_str());
307         m_state = stStopped;
308         ddvd_send_key(m_ddvdconfig, DDVD_KEY_EXIT);
309
310         return 0;
311 }
312
313 RESULT eServiceDVD::setTarget(int /*target*/)
314 {
315         return -1;
316 }
317
318 RESULT eServiceDVD::pause(ePtr<iPauseableService> &ptr)
319 {
320         ptr=this;
321         return 0;
322 }
323
324 RESULT eServiceDVD::seek(ePtr<iSeekableService> &ptr)
325 {
326         ptr=this;
327         return 0;
328 }
329
330 RESULT eServiceDVD::subtitle(ePtr<iSubtitleOutput> &ptr)
331 {
332         ptr=this;
333         return 0;
334 }
335
336 RESULT eServiceDVD::keys(ePtr<iServiceKeys> &ptr)
337 {
338         ptr=this;
339         return 0;
340 }
341
342         // iPausableService
343 RESULT eServiceDVD::setSlowMotion(int /*ratio*/)
344 {
345         return -1;
346 }
347
348 RESULT eServiceDVD::setFastForward(int trick)
349 {
350         eDebug("setTrickmode(%d)", trick);
351         while (m_current_trick > trick && m_current_trick != -64)
352         {
353                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FBWD);
354                 if (m_current_trick == 0)
355                         m_current_trick = -2;
356                 else if (m_current_trick > 0)
357                 {
358                         m_current_trick /= 2;
359                         if (abs(m_current_trick) == 1)
360                                 m_current_trick=0;
361                 }
362                 else
363                         m_current_trick *= 2;
364         }
365         while (m_current_trick < trick && m_current_trick != 64)
366         {
367                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_FFWD);
368                 if (m_current_trick == 0)
369                         m_current_trick = 2;
370                 else if (m_current_trick < 0)
371                 {
372                         m_current_trick /= 2;
373                         if (abs(m_current_trick) == 1)
374                                 m_current_trick=0;
375                 }
376                 else
377                         m_current_trick *= 2;
378         }
379         return 0;
380 }
381
382 RESULT eServiceDVD::pause()
383 {
384         eDebug("set pause!\n");
385         ddvd_send_key(m_ddvdconfig, DDVD_KEY_PAUSE);
386         return 0;
387 }
388
389 RESULT eServiceDVD::unpause()
390 {
391         eDebug("set unpause!\n");
392         ddvd_send_key(m_ddvdconfig, DDVD_KEY_PLAY);
393         return 0;
394 }
395
396 void eServiceDVD::thread()
397 {
398         eDebug("eServiceDVD dvd thread started");
399         hasStarted();
400         ddvd_run(m_ddvdconfig);
401 }
402
403 void eServiceDVD::thread_finished()
404 {
405         eDebug("eServiceDVD dvd thread finished");
406         m_pump.send(1); // inform main thread
407 }
408
409 RESULT eServiceDVD::info(ePtr<iServiceInformation>&i)
410 {
411         i = this;
412         return 0;
413 }
414
415 RESULT eServiceDVD::getName(std::string &name)
416 {
417         if ( m_ddvd_titlestring[0] != '\0' )
418                 name = m_ddvd_titlestring;
419         else
420                 name = m_filename;
421         return 0;
422 }
423
424 int eServiceDVD::getInfo(int w)
425 {
426         switch (w)
427         {
428                 case sCurrentChapter:
429                 {
430                         struct ddvd_time info;
431                         ddvd_get_last_time(m_ddvdconfig, &info);
432                         return info.pos_chapter;
433                 }
434                 case sTotalChapters:
435                 {
436                         struct ddvd_time info;
437                         ddvd_get_last_time(m_ddvdconfig, &info);
438                         return info.end_chapter;
439                 }
440                 case sCurrentTitle:
441                 {
442                         struct ddvd_time info;
443                         ddvd_get_last_time(m_ddvdconfig, &info);
444                         return info.pos_title;
445                 }
446                 case sTotalTitles:
447                 {
448                         struct ddvd_time info;
449                         ddvd_get_last_time(m_ddvdconfig, &info);
450                         return info.end_title;
451                 }
452                 case sTXTPID:   // we abuse HAS_TELEXT icon in InfoBar to signalize subtitles status
453                 {
454                         int spu_id;
455                         uint16_t spu_lang;
456                         ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
457                         return spu_id;
458                 }
459                 case sUser+6:
460                 case sUser+7:
461                         return resIsPyObject;
462                 default:
463                         return resNA;
464         }
465 }
466
467 std::string eServiceDVD::getInfoString(int w)
468 {
469         switch(w)
470         {
471                 case sServiceref:
472                         break;
473                 default:
474                         eDebug("unhandled getInfoString(%d)", w);
475         }
476         return "";
477 }
478
479 PyObject *eServiceDVD::getInfoObject(int w)
480 {
481         switch(w)
482         {
483                 case sUser+6:
484                 {
485                         ePyObject tuple = PyTuple_New(3);
486                         int audio_id,audio_type;
487                         uint16_t audio_lang;
488                         ddvd_get_last_audio(m_ddvdconfig, &audio_id, &audio_lang, &audio_type);
489                         char audio_string[3]={audio_lang >> 8, audio_lang, 0};
490                         PyTuple_SetItem(tuple, 0, PyInt_FromLong(audio_id+1));
491                         PyTuple_SetItem(tuple, 1, PyString_FromString(audio_string));
492                         switch(audio_type)
493                         {
494                                 case DDVD_MPEG:
495                                         PyTuple_SetItem(tuple, 2, PyString_FromString("MPEG"));
496                                         break;
497                                 case DDVD_AC3:
498                                         PyTuple_SetItem(tuple, 2, PyString_FromString("AC3"));
499                                         break;
500                                 case DDVD_DTS:
501                                         PyTuple_SetItem(tuple, 2, PyString_FromString("DTS"));
502                                         break;
503                                 case DDVD_LPCM:
504                                         PyTuple_SetItem(tuple, 2, PyString_FromString("LPCM"));
505                                         break;
506                                 default:
507                                         PyTuple_SetItem(tuple, 2, PyString_FromString(""));
508                         }
509                         return tuple;
510                 }
511                 case sUser+7:
512                 {
513                         ePyObject tuple = PyTuple_New(2);
514                         int spu_id;
515                         uint16_t spu_lang;
516                         ddvd_get_last_spu(m_ddvdconfig, &spu_id, &spu_lang);
517                         char spu_string[3]={spu_lang >> 8, spu_lang, 0};
518                         if (spu_id == -1)
519                         {
520                                 PyTuple_SetItem(tuple, 0, PyInt_FromLong(0));
521                                 PyTuple_SetItem(tuple, 1, PyString_FromString(""));
522                         }
523                         else
524                         {
525                                 PyTuple_SetItem(tuple, 0, PyInt_FromLong(spu_id+1));
526                                 PyTuple_SetItem(tuple, 1, PyString_FromString(spu_string));
527                         }                               
528                         return tuple;
529                 }
530                 default:
531                         eDebug("unhandled getInfoObject(%d)", w);
532         }
533         Py_RETURN_NONE;
534 }
535
536 RESULT eServiceDVD::enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) /*entry*/)
537 {
538         delete m_subtitle_widget;
539
540         m_subtitle_widget = new eSubtitleWidget(parent);
541         m_subtitle_widget->resize(parent->size());
542
543         eSize size = parent->size();
544
545         if (!m_pixmap)
546         {
547                 m_pixmap = new gPixmap(size, 32);
548                 ddvd_set_lfb(m_ddvdconfig, (unsigned char *)m_pixmap->surface->data, size.width(), size.height(), 4, size.width()*4);
549                 run(); // start the thread
550         }
551
552         m_subtitle_widget->setZPosition(-1);
553         m_subtitle_widget->show();
554
555         return 0;
556 }
557
558 RESULT eServiceDVD::disableSubtitles(eWidget */*parent*/)
559 {
560         delete m_subtitle_widget;
561         m_subtitle_widget = 0;
562         return 0;
563 }
564
565 PyObject *eServiceDVD::getSubtitleList()
566 {
567         eDebug("eServiceDVD::getSubtitleList nyi");
568         Py_RETURN_NONE;
569 }
570
571 PyObject *eServiceDVD::getCachedSubtitle()
572 {
573         eDebug("eServiceDVD::getCachedSubtitle nyi");
574         Py_RETURN_NONE;
575 }
576
577 RESULT eServiceDVD::getLength(pts_t &len)
578 {
579 //      eDebug("eServiceDVD::getLength");
580         struct ddvd_time info;
581         ddvd_get_last_time(m_ddvdconfig, &info);
582         len = info.end_hours * 3600;
583         len += info.end_minutes * 60;
584         len += info.end_seconds;
585         len *= 90000;
586         return 0;
587 }
588
589 RESULT eServiceDVD::seekTo(pts_t to)
590 {
591         eDebug("eServiceDVD::seekTo(%lld)",to);
592         if ( to > 0 )
593         {
594                 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);
595                 ddvd_set_resume_pos(m_ddvdconfig, m_resume_info);
596         }
597         return 0;
598 }
599
600 RESULT eServiceDVD::seekRelative(int direction, pts_t to)
601 {
602         int seconds = to / 90000;
603         seconds *= direction;
604         eDebug("seekRelative %d %d", direction, seconds);
605         ddvd_skip_seconds(m_ddvdconfig, seconds);
606         return 0;
607 }
608
609 RESULT eServiceDVD::getPlayPosition(pts_t &pos)
610 {
611         struct ddvd_time info;
612         ddvd_get_last_time(m_ddvdconfig, &info);
613         pos = info.pos_hours * 3600;
614         pos += info.pos_minutes * 60;
615         pos += info.pos_seconds;
616 //      eDebug("getPlayPosition %lld", pos);
617         pos *= 90000;
618         return 0;
619 }
620
621 RESULT eServiceDVD::seekTitle(int title)
622 {
623         eDebug("setTitle %d", title);
624         ddvd_set_title(m_ddvdconfig, title);
625         return 0;
626 }
627
628 RESULT eServiceDVD::seekChapter(int chapter)
629 {
630         eDebug("setChapter %d", chapter);
631         if ( chapter > 0 )
632                 ddvd_set_chapter(m_ddvdconfig, chapter);
633         return 0;
634 }
635
636 RESULT eServiceDVD::setTrickmode(int /*trick*/)
637 {
638         return -1;
639 }
640
641 RESULT eServiceDVD::isCurrentlySeekable()
642 {
643         return m_state == stRunning;
644 }
645
646 RESULT eServiceDVD::keyPressed(int key)
647 {
648         switch(key)
649         {
650         case iServiceKeys::keyLeft:
651                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_LEFT);
652                 break;
653         case iServiceKeys::keyRight:
654                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_RIGHT);
655                 break;
656         case iServiceKeys::keyUp:
657                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_UP);
658                 break;
659         case iServiceKeys::keyDown:
660                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_DOWN);
661                 break;
662         case iServiceKeys::keyOk:
663                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_OK);
664                 break;
665         case iServiceKeys::keyUser:
666                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIO);
667                 break;
668         case iServiceKeys::keyUser+1:
669                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_SUBTITLE);
670                 break;
671         case iServiceKeys::keyUser+2:
672                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_AUDIOMENU);
673                 break;
674         case iServiceKeys::keyUser+3:
675                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_CHAPTER);
676                 break;
677         case iServiceKeys::keyUser+4:
678                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_CHAPTER);
679                 break;
680         case iServiceKeys::keyUser+5:
681                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_NEXT_TITLE);
682                 break;
683         case iServiceKeys::keyUser+6:
684                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_PREV_TITLE);
685                 break;
686         case iServiceKeys::keyUser+7:
687                 ddvd_send_key(m_ddvdconfig, DDVD_KEY_MENU);
688                 break;
689         default:
690                 return -1;
691         }
692         return 0;
693 }
694
695 RESULT eServiceDVD::cueSheet(ePtr<iCueSheet> &ptr)
696 {
697         if (m_cue_pts)
698         {
699                 ptr = this;
700                 return 0;
701         }
702         ptr = 0;
703         return -1;
704 }
705
706 PyObject *eServiceDVD::getCutList()
707 {
708         ePyObject list = PyList_New(1);
709         ePyObject tuple = PyTuple_New(2);
710         PyTuple_SetItem(tuple, 0, PyLong_FromLongLong(m_cue_pts));
711         PyTuple_SetItem(tuple, 1, PyInt_FromLong(3));
712         PyList_SetItem(list, 0, tuple);
713         return list;
714 }
715
716 void eServiceDVD::setCutList(ePyObject /*list*/)
717 {
718 }
719
720 void eServiceDVD::setCutListEnable(int /*enable*/)
721 {
722 }
723
724 void eServiceDVD::loadCuesheet()
725 {
726         char filename[128];
727         if ( m_ddvd_titlestring[0] != '\0' )
728                 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
729         else
730                 snprintf(filename, 128, "%s/dvd.cuts", m_filename.c_str());
731
732         eDebug("eServiceDVD::loadCuesheet() filename=%s",filename);
733
734         FILE *f = fopen(filename, "rb");
735
736         if (f)
737         {
738                 unsigned long long where;
739                 unsigned int what;
740
741                 if (!fread(&where, sizeof(where), 1, f))
742                         return;
743                 if (!fread(&what, sizeof(what), 1, f))
744                         return;
745 #if BYTE_ORDER == LITTLE_ENDIAN
746                 where = bswap_64(where);
747 #endif
748                 what = ntohl(what);
749
750                 if (!fread(&m_resume_info, sizeof(struct ddvd_resume), 1, f))
751                         return;
752                 if (!fread(&what, sizeof(what), 1, f))
753                         return;
754
755                 what = ntohl(what);
756                 if (what != 4 )
757                         return;
758
759                 m_cue_pts = where;
760
761                 fclose(f);
762         } else
763                 eDebug("cutfile not found!");
764
765         if (m_cue_pts)
766         {
767                 m_event((iPlayableService*)this, evCuesheetChanged);
768                 eDebug("eServiceDVD::loadCuesheet() pts=%lld",m_cue_pts);
769         }
770 }
771
772 void eServiceDVD::saveCuesheet()
773 {
774         eDebug("eServiceDVD::saveCuesheet()");
775
776         struct ddvd_resume resume_info;
777         ddvd_get_resume_pos(m_ddvdconfig, &resume_info);
778
779         if (resume_info.title)
780         {
781                 struct ddvd_time info;
782                 ddvd_get_last_time(m_ddvdconfig, &info);
783                 pts_t pos;
784                 pos = info.pos_hours * 3600;
785                 pos += info.pos_minutes * 60;
786                 pos += info.pos_seconds;
787                 pos *= 90000;
788                 m_cue_pts = pos;
789                 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);
790         }
791         else
792         {
793                 eDebug("we're in a menu or somewhere else funny. so save cuesheet with pts=0");
794                 m_cue_pts = 0;
795         }
796
797         char filename[128];
798         if ( m_ddvd_titlestring[0] != '\0' )
799                 snprintf(filename, 128, "/home/root/dvd-%s.cuts", m_ddvd_titlestring);
800         else
801                 snprintf(filename, 128, "%s/dvd.cuts", m_filename.c_str());
802         
803         FILE *f = fopen(filename, "wb");
804
805         if (f)
806         {
807                 unsigned long long where;
808                 int what;
809
810 #if BYTE_ORDER == BIG_ENDIAN
811                 where = m_cue_pts;
812 #else
813                 where = bswap_64(m_cue_pts);
814 #endif
815                 what = htonl(3);
816                 fwrite(&where, sizeof(where), 1, f);
817                 fwrite(&what, sizeof(what), 1, f);
818                 
819                 what = htonl(4);
820                 fwrite(&resume_info, sizeof(struct ddvd_resume), 1, f);
821                 fwrite(&what, sizeof(what), 1, f);
822
823                 fclose(f);
824         }
825 }
826
827 eAutoInitPtr<eServiceFactoryDVD> init_eServiceFactoryDVD(eAutoInitNumbers::service+1, "eServiceFactoryDVD");
828
829 PyMODINIT_FUNC
830 initservicedvd(void)
831 {
832         Py_InitModule("servicedvd", NULL);
833 }