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