Merge branch 'master' of git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / service / servicemp3.cpp
1 #ifdef HAVE_GSTREAMER
2
3         /* note: this requires gstreamer 0.10.x and a big list of plugins. */
4         /* it's currently hardcoded to use a big-endian alsasink as sink. */
5 #include <lib/base/eerror.h>
6 #include <lib/base/object.h>
7 #include <lib/base/ebase.h>
8 #include <string>
9 #include <lib/service/servicemp3.h>
10 #include <lib/service/service.h>
11 #include <lib/components/file_eraser.h>
12 #include <lib/base/init_num.h>
13 #include <lib/base/init.h>
14 #include <gst/gst.h>
15 #include <gst/pbutils/missing-plugins.h>
16 #include <sys/stat.h>
17 /* for subtitles */
18 #include <lib/gui/esubtitle.h>
19
20 // eServiceFactoryMP3
21
22 eServiceFactoryMP3::eServiceFactoryMP3()
23 {
24         ePtr<eServiceCenter> sc;
25         
26         eServiceCenter::getPrivInstance(sc);
27         if (sc)
28         {
29                 std::list<std::string> extensions;
30                 extensions.push_back("mp2");
31                 extensions.push_back("mp3");
32                 extensions.push_back("ogg");
33                 extensions.push_back("mpg");
34                 extensions.push_back("vob");
35                 extensions.push_back("wav");
36                 extensions.push_back("wave");
37                 extensions.push_back("mkv");
38                 extensions.push_back("avi");
39                 extensions.push_back("divx");
40                 extensions.push_back("dat");
41                 extensions.push_back("flac");
42                 extensions.push_back("mp4");
43                 extensions.push_back("mov");
44                 extensions.push_back("m4a");
45                 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
46         }
47
48         m_service_info = new eStaticServiceMP3Info();
49 }
50
51 eServiceFactoryMP3::~eServiceFactoryMP3()
52 {
53         ePtr<eServiceCenter> sc;
54         
55         eServiceCenter::getPrivInstance(sc);
56         if (sc)
57                 sc->removeServiceFactory(eServiceFactoryMP3::id);
58 }
59
60 DEFINE_REF(eServiceFactoryMP3)
61
62         // iServiceHandler
63 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
64 {
65                 // check resources...
66         ptr = new eServiceMP3(ref.path.c_str(),ref.getName().c_str());
67         return 0;
68 }
69
70 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
71 {
72         ptr=0;
73         return -1;
74 }
75
76 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
77 {
78         ptr=0;
79         return -1;
80 }
81
82 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
83 {
84         ptr = m_service_info;
85         return 0;
86 }
87
88 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
89 {
90         DECLARE_REF(eMP3ServiceOfflineOperations);
91         eServiceReference m_ref;
92 public:
93         eMP3ServiceOfflineOperations(const eServiceReference &ref);
94         
95         RESULT deleteFromDisk(int simulate);
96         RESULT getListOfFilenames(std::list<std::string> &);
97 };
98
99 DEFINE_REF(eMP3ServiceOfflineOperations);
100
101 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
102 {
103 }
104
105 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
106 {
107         if (simulate)
108                 return 0;
109         else
110         {
111                 std::list<std::string> res;
112                 if (getListOfFilenames(res))
113                         return -1;
114                 
115                 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
116                 if (!eraser)
117                         eDebug("FATAL !! can't get background file eraser");
118                 
119                 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
120                 {
121                         eDebug("Removing %s...", i->c_str());
122                         if (eraser)
123                                 eraser->erase(i->c_str());
124                         else
125                                 ::unlink(i->c_str());
126                 }
127                 
128                 return 0;
129         }
130 }
131
132 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
133 {
134         res.clear();
135         res.push_back(m_ref.path);
136         return 0;
137 }
138
139
140 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
141 {
142         ptr = new eMP3ServiceOfflineOperations(ref);
143         return 0;
144 }
145
146 // eStaticServiceMP3Info
147
148
149 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
150 // about unopened files.
151
152 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
153 // should have a database backend where ID3-files etc. are cached.
154 // this would allow listing the mp3 database based on certain filters.
155
156 DEFINE_REF(eStaticServiceMP3Info)
157
158 eStaticServiceMP3Info::eStaticServiceMP3Info()
159 {
160 }
161
162 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
163 {
164         if ( ref.name.length() )
165                 name = ref.name;
166         else
167         {
168                 size_t last = ref.path.rfind('/');
169                 if (last != std::string::npos)
170                         name = ref.path.substr(last+1);
171                 else
172                         name = ref.path;
173         }
174         return 0;
175 }
176
177 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
178 {
179         return -1;
180 }
181
182 // eServiceMP3
183
184 eServiceMP3::eServiceMP3(const char *filename, const char *title): m_filename(filename), m_title(title), m_pump(eApp, 1)
185 {
186         m_seekTimeout = eTimer::create(eApp);
187         m_subtitle_sync_timer = eTimer::create(eApp);
188         m_stream_tags = 0;
189         m_currentAudioStream = 0;
190         m_currentSubtitleStream = 0;
191         m_subtitle_widget = 0;
192         m_currentTrickRatio = 0;
193         CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
194         CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
195         CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
196         m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
197
198         m_state = stIdle;
199         eDebug("eServiceMP3::construct!");
200         
201         const char *ext = strrchr(filename, '.');
202         if (!ext)
203                 ext = filename;
204
205         sourceStream sourceinfo;
206         sourceinfo.is_video = FALSE;
207         sourceinfo.audiotype = atUnknown;
208         if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
209         {
210                 sourceinfo.containertype = ctMPEGPS;
211                 sourceinfo.is_video = TRUE;
212         }
213         else if ( strcasecmp(ext, ".ts") == 0 )
214         {
215                 sourceinfo.containertype = ctMPEGTS;
216                 sourceinfo.is_video = TRUE;
217         }
218         else if ( strcasecmp(ext, ".mkv") == 0 )
219         {
220                 sourceinfo.containertype = ctMKV;
221                 sourceinfo.is_video = TRUE;
222         }
223         else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
224         {
225                 sourceinfo.containertype = ctAVI;
226                 sourceinfo.is_video = TRUE;
227         }
228         else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0)
229         {
230                 sourceinfo.containertype = ctMP4;
231                 sourceinfo.is_video = TRUE;
232         }
233         else if ( strcasecmp(ext, ".m4a") == 0 )
234         {
235                 sourceinfo.containertype = ctMP4;
236                 sourceinfo.audiotype = atAAC;
237         }
238         else if ( strcasecmp(ext, ".mp3") == 0 )
239                 sourceinfo.audiotype = atMP3;
240         else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
241                 sourceinfo.containertype = ctCDA;
242         if ( strcasecmp(ext, ".dat") == 0 )
243         {
244                 sourceinfo.containertype = ctVCD;
245                 sourceinfo.is_video = TRUE;
246         }
247         if ( (strncmp(filename, "http://", 7)) == 0 || (strncmp(filename, "udp://", 6)) == 0 || (strncmp(filename, "rtsp://", 7)) == 0 )
248                 sourceinfo.is_streaming = TRUE;
249
250         gchar *uri;
251
252         if ( sourceinfo.is_streaming )
253         {
254                 uri = g_strdup_printf ("%s", filename);
255         }
256         else if ( sourceinfo.containertype == ctCDA )
257         {
258                 int i_track = atoi(filename+18);
259                 uri = g_strdup_printf ("cdda://%i", i_track);
260         }
261         else if ( sourceinfo.containertype == ctVCD )
262         {
263                 int fd = open(filename,O_RDONLY);
264                 char tmp[128*1024];
265                 int ret = read(fd, tmp, 128*1024);
266                 close(fd);
267                 if ( ret == -1 ) // this is a "REAL" VCD
268                         uri = g_strdup_printf ("vcd://");
269                 else
270                         uri = g_strdup_printf ("file://%s", filename);
271         }
272         else
273
274                 uri = g_strdup_printf ("file://%s", filename);
275
276         eDebug("eServiceMP3::playbin2 uri=%s", uri);
277
278         m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
279         if (!m_gst_playbin)
280                 m_error_message = "failed to create GStreamer pipeline!\n";
281
282         g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
283
284         int flags = 0x47; // ( == GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT )
285         g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
286
287         g_free(uri);
288
289         GstElement *subsink = gst_element_factory_make("appsink", "subtitle_sink");
290         if (!subsink)
291                 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
292         else
293         {
294                 g_object_set (G_OBJECT (subsink), "emit-signals", TRUE, NULL);
295                 g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
296                 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
297         }
298
299         if ( m_gst_playbin )
300         {
301                 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), gstBusSyncHandler, this);
302                 char srt_filename[strlen(filename)+1];
303                 strncpy(srt_filename,filename,strlen(filename)-3);
304                 srt_filename[strlen(filename)-3]='\0';
305                 strcat(srt_filename, "srt");
306                 struct stat buffer;
307                 if (stat(srt_filename, &buffer) == 0)
308                 {
309                         std::string suburi = "file://" + (std::string)srt_filename;
310                         eDebug("eServiceMP3::subtitle uri: %s",suburi.c_str());
311                         g_object_set (G_OBJECT (m_gst_playbin), "suburi", suburi.c_str(), NULL);
312                         subtitleStream subs;
313                         subs.type = stSRT;
314                         subs.language_code = std::string("und");
315                         m_subtitleStreams.push_back(subs);
316                 }
317         } else
318         {
319                 m_event((iPlayableService*)this, evUser+12);
320
321                 if (m_gst_playbin)
322                         gst_object_unref(GST_OBJECT(m_gst_playbin));
323
324                 eDebug("eServiceMP3::sorry, can't play: %s",m_error_message.c_str());
325                 m_gst_playbin = 0;
326         }
327
328         gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
329 }
330
331 eServiceMP3::~eServiceMP3()
332 {
333         delete m_subtitle_widget;
334         if (m_state == stRunning)
335                 stop();
336         
337         if (m_stream_tags)
338                 gst_tag_list_free(m_stream_tags);
339         
340         if (m_gst_playbin)
341         {
342                 gst_object_unref (GST_OBJECT (m_gst_playbin));
343                 eDebug("eServiceMP3::destruct!");
344         }
345 }
346
347 DEFINE_REF(eServiceMP3);        
348
349 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
350 {
351         connection = new eConnection((iPlayableService*)this, m_event.connect(event));
352         return 0;
353 }
354
355 RESULT eServiceMP3::start()
356 {
357         ASSERT(m_state == stIdle);
358         
359         m_state = stRunning;
360         if (m_gst_playbin)
361         {
362                 eDebug("eServiceMP3::starting pipeline");
363                 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
364         }
365         m_event(this, evStart);
366         return 0;
367 }
368
369 RESULT eServiceMP3::stop()
370 {
371         ASSERT(m_state != stIdle);
372         if (m_state == stStopped)
373                 return -1;
374         eDebug("eServiceMP3::stop %s", m_filename.c_str());
375         gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
376         m_state = stStopped;
377         return 0;
378 }
379
380 RESULT eServiceMP3::setTarget(int target)
381 {
382         return -1;
383 }
384
385 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
386 {
387         ptr=this;
388         return 0;
389 }
390
391 RESULT eServiceMP3::setSlowMotion(int ratio)
392 {
393         if (!ratio)
394                 return 0;
395         eDebug("eServiceMP3::setSlowMotion ratio=%f",1/(float)ratio);
396         return trickSeek(1/(float)ratio);
397 }
398
399 RESULT eServiceMP3::setFastForward(int ratio)
400 {
401         eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
402         return trickSeek(ratio);
403 }
404
405 void eServiceMP3::seekTimeoutCB()
406 {
407         pts_t ppos, len;
408         getPlayPosition(ppos);
409         getLength(len);
410         ppos += 90000*m_currentTrickRatio;
411         
412         if (ppos < 0)
413         {
414                 ppos = 0;
415                 m_seekTimeout->stop();
416         }
417         if (ppos > len)
418         {
419                 ppos = 0;
420                 stop();
421                 m_seekTimeout->stop();
422                 return;
423         }
424         seekTo(ppos);
425 }
426
427                 // iPausableService
428 RESULT eServiceMP3::pause()
429 {
430         if (!m_gst_playbin || m_state != stRunning)
431                 return -1;
432         GstStateChangeReturn res = gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
433         if (res == GST_STATE_CHANGE_ASYNC)
434         {
435                 pts_t ppos;
436                 getPlayPosition(ppos);
437                 seekTo(ppos);
438         }
439         return 0;
440 }
441
442 RESULT eServiceMP3::unpause()
443 {
444         m_subtitle_pages.clear();
445         if (!m_gst_playbin || m_state != stRunning)
446                 return -1;
447
448         GstStateChangeReturn res;
449         res = gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
450         return 0;
451 }
452
453         /* iSeekableService */
454 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
455 {
456         ptr = this;
457         return 0;
458 }
459
460 RESULT eServiceMP3::getLength(pts_t &pts)
461 {
462         if (!m_gst_playbin)
463                 return -1;
464         if (m_state != stRunning)
465                 return -1;
466         
467         GstFormat fmt = GST_FORMAT_TIME;
468         gint64 len;
469         
470         if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
471                 return -1;
472                 /* len is in nanoseconds. we have 90 000 pts per second. */
473         
474         pts = len / 11111;
475         return 0;
476 }
477
478 RESULT eServiceMP3::seekTo(pts_t to)
479 {
480         if (!m_gst_playbin)
481                 return -1;
482
483                 /* convert pts to nanoseconds */
484         gint64 time_nanoseconds = to * 11111LL;
485         if (!gst_element_seek (m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
486                 GST_SEEK_TYPE_SET, time_nanoseconds,
487                 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
488         {
489                 eDebug("eServiceMP3::seekTo failed");
490                 return -1;
491         }
492         return 0;
493 }
494
495 RESULT eServiceMP3::trickSeek(gdouble ratio)
496 {
497         if (!m_gst_playbin)
498                 return -1;
499         if (!ratio)
500                 return seekRelative(0, 0);
501
502         GstEvent *s_event;
503         GstSeekFlags flags;
504         flags = GST_SEEK_FLAG_NONE;
505         flags |= GstSeekFlags (GST_SEEK_FLAG_FLUSH);
506 //      flags |= GstSeekFlags (GST_SEEK_FLAG_ACCURATE);
507         flags |= GstSeekFlags (GST_SEEK_FLAG_KEY_UNIT);
508 //      flags |= GstSeekFlags (GST_SEEK_FLAG_SEGMENT);
509 //      flags |= GstSeekFlags (GST_SEEK_FLAG_SKIP);
510
511         GstFormat fmt = GST_FORMAT_TIME;
512         gint64 pos, len;
513         gst_element_query_duration(m_gst_playbin, &fmt, &len);
514         gst_element_query_position(m_gst_playbin, &fmt, &pos);
515
516         if ( ratio >= 0 )
517         {
518                 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, len);
519
520                 eDebug("eServiceMP3::trickSeek with rate %lf to %" GST_TIME_FORMAT " ", ratio, GST_TIME_ARGS (pos));
521         }
522         else
523         {
524                 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, GST_SEEK_FLAG_SKIP|GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1);
525         }
526
527         if (!gst_element_send_event ( GST_ELEMENT (m_gst_playbin), s_event))
528         {
529                 eDebug("eServiceMP3::trickSeek failed");
530                 return -1;
531         }
532
533         return 0;
534 }
535
536
537 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
538 {
539         if (!m_gst_playbin)
540                 return -1;
541
542         pts_t ppos;
543         getPlayPosition(ppos);
544         ppos += to * direction;
545         if (ppos < 0)
546                 ppos = 0;
547         seekTo(ppos);
548         
549         return 0;
550 }
551
552 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
553 {
554         if (!m_gst_playbin)
555                 return -1;
556         if (m_state != stRunning)
557                 return -1;
558
559         GstFormat fmt = GST_FORMAT_TIME;
560         gint64 len;
561         
562         if (!gst_element_query_position(m_gst_playbin, &fmt, &len))
563                 return -1;
564
565                 /* len is in nanoseconds. we have 90 000 pts per second. */
566         pts = len / 11111;
567         return 0;
568 }
569
570 RESULT eServiceMP3::setTrickmode(int trick)
571 {
572                 /* trickmode is not yet supported by our dvbmediasinks. */
573         return -1;
574 }
575
576 RESULT eServiceMP3::isCurrentlySeekable()
577 {
578         return 1;
579 }
580
581 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
582 {
583         i = this;
584         return 0;
585 }
586
587 RESULT eServiceMP3::getName(std::string &name)
588 {
589         if (m_title.empty())
590         {
591                 name = m_filename;
592                 size_t n = name.rfind('/');
593                 if (n != std::string::npos)
594                         name = name.substr(n + 1);
595         }
596         else
597                 name = m_title;
598         return 0;
599 }
600
601
602 int eServiceMP3::getInfo(int w)
603 {
604         gchar *tag = 0;
605
606         switch (w)
607         {
608         case sVideoHeight: return m_height;
609         case sVideoWidth: return m_width;
610         case sFrameRate: return m_framerate;
611         case sProgressive: return m_progressive;
612         case sAspect: return m_aspect;
613         case sTagTitle:
614         case sTagArtist:
615         case sTagAlbum:
616         case sTagTitleSortname:
617         case sTagArtistSortname:
618         case sTagAlbumSortname:
619         case sTagDate:
620         case sTagComposer:
621         case sTagGenre:
622         case sTagComment:
623         case sTagExtendedComment:
624         case sTagLocation:
625         case sTagHomepage:
626         case sTagDescription:
627         case sTagVersion:
628         case sTagISRC:
629         case sTagOrganization:
630         case sTagCopyright:
631         case sTagCopyrightURI:
632         case sTagContact:
633         case sTagLicense:
634         case sTagLicenseURI:
635         case sTagCodec:
636         case sTagAudioCodec:
637         case sTagVideoCodec:
638         case sTagEncoder:
639         case sTagLanguageCode:
640         case sTagKeywords:
641         case sTagChannelMode:
642         case sUser+12:
643                 return resIsString;
644         case sTagTrackGain:
645         case sTagTrackPeak:
646         case sTagAlbumGain:
647         case sTagAlbumPeak:
648         case sTagReferenceLevel:
649         case sTagBeatsPerMinute:
650         case sTagImage:
651         case sTagPreviewImage:
652         case sTagAttachment:
653                 return resIsPyObject;
654         case sTagTrackNumber:
655                 tag = GST_TAG_TRACK_NUMBER;
656                 break;
657         case sTagTrackCount:
658                 tag = GST_TAG_TRACK_COUNT;
659                 break;
660         case sTagAlbumVolumeNumber:
661                 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
662                 break;
663         case sTagAlbumVolumeCount:
664                 tag = GST_TAG_ALBUM_VOLUME_COUNT;
665                 break;
666         case sTagBitrate:
667                 tag = GST_TAG_BITRATE;
668                 break;
669         case sTagNominalBitrate:
670                 tag = GST_TAG_NOMINAL_BITRATE;
671                 break;
672         case sTagMinimumBitrate:
673                 tag = GST_TAG_MINIMUM_BITRATE;
674                 break;
675         case sTagMaximumBitrate:
676                 tag = GST_TAG_MAXIMUM_BITRATE;
677                 break;
678         case sTagSerial:
679                 tag = GST_TAG_SERIAL;
680                 break;
681         case sTagEncoderVersion:
682                 tag = GST_TAG_ENCODER_VERSION;
683                 break;
684         case sTagCRC:
685                 tag = "has-crc";
686                 break;
687         default:
688                 return resNA;
689         }
690
691         if (!m_stream_tags || !tag)
692                 return 0;
693         
694         guint value;
695         if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
696                 return (int) value;
697
698         return 0;
699 }
700
701 std::string eServiceMP3::getInfoString(int w)
702 {
703         if ( !m_stream_tags )
704                 return "";
705         gchar *tag = 0;
706         switch (w)
707         {
708         case sTagTitle:
709                 tag = GST_TAG_TITLE;
710                 break;
711         case sTagArtist:
712                 tag = GST_TAG_ARTIST;
713                 break;
714         case sTagAlbum:
715                 tag = GST_TAG_ALBUM;
716                 break;
717         case sTagTitleSortname:
718                 tag = GST_TAG_TITLE_SORTNAME;
719                 break;
720         case sTagArtistSortname:
721                 tag = GST_TAG_ARTIST_SORTNAME;
722                 break;
723         case sTagAlbumSortname:
724                 tag = GST_TAG_ALBUM_SORTNAME;
725                 break;
726         case sTagDate:
727                 GDate *date;
728                 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
729                 {
730                         gchar res[5];
731                         g_date_strftime (res, sizeof(res), "%Y-%M-%D", date); 
732                         return (std::string)res;
733                 }
734                 break;
735         case sTagComposer:
736                 tag = GST_TAG_COMPOSER;
737                 break;
738         case sTagGenre:
739                 tag = GST_TAG_GENRE;
740                 break;
741         case sTagComment:
742                 tag = GST_TAG_COMMENT;
743                 break;
744         case sTagExtendedComment:
745                 tag = GST_TAG_EXTENDED_COMMENT;
746                 break;
747         case sTagLocation:
748                 tag = GST_TAG_LOCATION;
749                 break;
750         case sTagHomepage:
751                 tag = GST_TAG_HOMEPAGE;
752                 break;
753         case sTagDescription:
754                 tag = GST_TAG_DESCRIPTION;
755                 break;
756         case sTagVersion:
757                 tag = GST_TAG_VERSION;
758                 break;
759         case sTagISRC:
760                 tag = GST_TAG_ISRC;
761                 break;
762         case sTagOrganization:
763                 tag = GST_TAG_ORGANIZATION;
764                 break;
765         case sTagCopyright:
766                 tag = GST_TAG_COPYRIGHT;
767                 break;
768         case sTagCopyrightURI:
769                 tag = GST_TAG_COPYRIGHT_URI;
770                 break;
771         case sTagContact:
772                 tag = GST_TAG_CONTACT;
773                 break;
774         case sTagLicense:
775                 tag = GST_TAG_LICENSE;
776                 break;
777         case sTagLicenseURI:
778                 tag = GST_TAG_LICENSE_URI;
779                 break;
780         case sTagCodec:
781                 tag = GST_TAG_CODEC;
782                 break;
783         case sTagAudioCodec:
784                 tag = GST_TAG_AUDIO_CODEC;
785                 break;
786         case sTagVideoCodec:
787                 tag = GST_TAG_VIDEO_CODEC;
788                 break;
789         case sTagEncoder:
790                 tag = GST_TAG_ENCODER;
791                 break;
792         case sTagLanguageCode:
793                 tag = GST_TAG_LANGUAGE_CODE;
794                 break;
795         case sTagKeywords:
796                 tag = GST_TAG_KEYWORDS;
797                 break;
798         case sTagChannelMode:
799                 tag = "channel-mode";
800                 break;
801
802         case sUser+12:
803                 return m_error_message;
804         default:
805                 return "";
806         }
807         if ( !tag )
808                 return "";
809         gchar *value;
810         if (gst_tag_list_get_string(m_stream_tags, tag, &value))
811         {
812                 std::string res = value;
813                 g_free(value);
814                 return res;
815         }
816         return "";
817 }
818
819 PyObject *eServiceMP3::getInfoObject(int w)
820 {
821         gchar *tag = 0;
822         bool isBuffer = false;
823         switch (w)
824         {
825                 case sTagTrackGain:
826                         tag = GST_TAG_TRACK_GAIN;
827                         break;
828                 case sTagTrackPeak:
829                         tag = GST_TAG_TRACK_PEAK;
830                         break;
831                 case sTagAlbumGain:
832                         tag = GST_TAG_ALBUM_GAIN;
833                         break;
834                 case sTagAlbumPeak:
835                         tag = GST_TAG_ALBUM_PEAK;
836                         break;
837                 case sTagReferenceLevel:
838                         tag = GST_TAG_REFERENCE_LEVEL;
839                         break;
840                 case sTagBeatsPerMinute:
841                         tag = GST_TAG_BEATS_PER_MINUTE;
842                         break;
843                 case sTagImage:
844                         tag = GST_TAG_IMAGE;
845                         isBuffer = true;
846                         break;
847                 case sTagPreviewImage:
848                         tag = GST_TAG_PREVIEW_IMAGE;
849                         isBuffer = true;
850                         break;
851                 case sTagAttachment:
852                         tag = GST_TAG_ATTACHMENT;
853                         isBuffer = true;
854                         break;
855                 default:
856                         break;
857         }
858         gdouble value;
859         if ( !tag || !m_stream_tags )
860                 value = 0.0;
861         PyObject *pyValue;
862         if ( isBuffer )
863         {
864                 const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
865                 if ( gv_buffer )
866                 {
867                         GstBuffer *buffer;
868                         buffer = gst_value_get_buffer (gv_buffer);
869                         pyValue = PyBuffer_FromMemory(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
870                 }
871         }
872         else
873         {
874                 gst_tag_list_get_double(m_stream_tags, tag, &value);
875                 pyValue = PyFloat_FromDouble(value);
876         }
877
878         return pyValue;
879 }
880
881 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
882 {
883         ptr = this;
884         return 0;
885 }
886
887 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
888 {
889         ptr = this;
890         return 0;
891 }
892
893 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
894 {
895         ptr = this;
896         return 0;
897 }
898
899 int eServiceMP3::getNumberOfTracks()
900 {
901         return m_audioStreams.size();
902 }
903
904 int eServiceMP3::getCurrentTrack()
905 {
906         return m_currentAudioStream;
907 }
908
909 RESULT eServiceMP3::selectTrack(unsigned int i)
910 {
911         int ret = selectAudioStream(i);
912         /* flush */
913         pts_t ppos;
914         getPlayPosition(ppos);
915         seekTo(ppos);
916
917         return ret;
918 }
919
920 int eServiceMP3::selectAudioStream(int i)
921 {
922         int current_audio;
923         g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
924         g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &current_audio, NULL);
925         if ( current_audio == i )
926         {
927                 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
928                 m_currentAudioStream = i;
929                 return 0;
930         }
931         return -1;
932 }
933
934 int eServiceMP3::getCurrentChannel()
935 {
936         return STEREO;
937 }
938
939 RESULT eServiceMP3::selectChannel(int i)
940 {
941         eDebug("eServiceMP3::selectChannel(%i)",i);
942         return 0;
943 }
944
945 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
946 {
947         if (i >= m_audioStreams.size())
948                 return -2;
949                 info.m_description = m_audioStreams[i].codec;
950 /*      if (m_audioStreams[i].type == atMPEG)
951                 info.m_description = "MPEG";
952         else if (m_audioStreams[i].type == atMP3)
953                 info.m_description = "MP3";
954         else if (m_audioStreams[i].type == atAC3)
955                 info.m_description = "AC3";
956         else if (m_audioStreams[i].type == atAAC)
957                 info.m_description = "AAC";
958         else if (m_audioStreams[i].type == atDTS)
959                 info.m_description = "DTS";
960         else if (m_audioStreams[i].type == atPCM)
961                 info.m_description = "PCM";
962         else if (m_audioStreams[i].type == atOGG)
963                 info.m_description = "OGG";
964         else if (m_audioStreams[i].type == atFLAC)
965                 info.m_description = "FLAC";
966         else
967                 info.m_description = "???";*/
968         if (info.m_language.empty())
969                 info.m_language = m_audioStreams[i].language_code;
970         return 0;
971 }
972
973 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
974 {
975         if (!msg)
976                 return;
977         gchar *sourceName;
978         GstObject *source;
979
980         source = GST_MESSAGE_SRC(msg);
981         sourceName = gst_object_get_name(source);
982 #if 0
983         if (gst_message_get_structure(msg))
984         {
985                 gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
986                 eDebug("eServiceMP3::gst_message from %s: %s", sourceName, string);
987                 g_free(string);
988         }
989         else
990                 eDebug("eServiceMP3::gst_message from %s: %s (without structure)", sourceName, GST_MESSAGE_TYPE_NAME(msg));
991 #endif
992         if ( GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STATE_CHANGED )
993                 return;
994         switch (GST_MESSAGE_TYPE (msg))
995         {
996                 case GST_MESSAGE_EOS:
997                         m_event((iPlayableService*)this, evEOF);
998                         break;
999                 case GST_MESSAGE_ERROR:
1000                 {
1001                         gchar *debug;
1002                         GError *err;
1003         
1004                         gst_message_parse_error (msg, &err, &debug);
1005                         g_free (debug);
1006                         eWarning("Gstreamer error: %s (%i) from %s", err->message, err->code, sourceName );
1007                         if ( err->domain == GST_STREAM_ERROR )
1008                         {
1009                                 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1010                                 {
1011                                         if ( g_strrstr(sourceName, "videosink") )
1012                                                 m_event((iPlayableService*)this, evUser+11);
1013                                         else if ( g_strrstr(sourceName, "audiosink") )
1014                                                 m_event((iPlayableService*)this, evUser+10);
1015                                 }
1016                         }
1017                         g_error_free(err);
1018                         break;
1019                 }
1020                 case GST_MESSAGE_INFO:
1021                 {
1022                         gchar *debug;
1023                         GError *inf;
1024         
1025                         gst_message_parse_info (msg, &inf, &debug);
1026                         g_free (debug);
1027                         if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1028                         {
1029                                 if ( g_strrstr(sourceName, "videosink") )
1030                                         m_event((iPlayableService*)this, evUser+14);
1031                         }
1032                         g_error_free(inf);
1033                         break;
1034                 }
1035                 case GST_MESSAGE_TAG:
1036                 {
1037                         GstTagList *tags, *result;
1038                         gst_message_parse_tag(msg, &tags);
1039         
1040                         result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_PREPEND);
1041                         if (result)
1042                         {
1043                                 if (m_stream_tags)
1044                                         gst_tag_list_free(m_stream_tags);
1045                                 m_stream_tags = result;
1046                         }
1047         
1048                         const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1049                         if ( gv_image )
1050                         {
1051                                 GstBuffer *buf_image;
1052                                 buf_image = gst_value_get_buffer (gv_image);
1053                                 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1054                                 int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image));
1055                                 close(fd);
1056                                 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1057                                 m_event((iPlayableService*)this, evUser+13);
1058                         }
1059         
1060                         gst_tag_list_free(tags);
1061                         m_event((iPlayableService*)this, evUpdatedInfo);
1062                         break;
1063                 }
1064                 case GST_MESSAGE_ASYNC_DONE:
1065                 {
1066                         GstTagList *tags;
1067                         gint i, active_idx, n_video = 0, n_audio = 0, n_text = 0;
1068
1069                         g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1070                         g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1071                         g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1072
1073                         eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1074
1075                         active_idx = 0;
1076
1077                         m_audioStreams.clear();
1078                         m_subtitleStreams.clear();
1079
1080                         for (i = 0; i < n_audio; i++)
1081                         {
1082                                 audioStream audio;
1083                                 gchar *g_codec, *g_lang;
1084                                 GstPad* pad = 0;
1085                                 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1086                                 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1087                                 GstStructure* str = gst_caps_get_structure(caps, 0);
1088 gchar *g_type;
1089 g_type = gst_structure_get_name(str);
1090 eDebug("AUDIO STRUCT=%s", g_type);
1091                                 audio.type = gstCheckAudioPad(str);
1092                                 g_codec = g_strdup(g_type);
1093                                 g_lang = g_strdup_printf ("und");
1094                                 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1095                                 if ( tags && gst_is_tag_list(tags) )
1096                                 {
1097                                         gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1098                                         gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1099                                 }
1100                                 audio.language_code = std::string(g_lang);
1101                                 audio.codec = std::string(g_codec);
1102                                 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1103                                 m_audioStreams.push_back(audio);
1104                                 g_free (g_lang);
1105                                 g_free (g_codec);
1106                         }
1107
1108                         for (i = 0; i < n_text; i++)
1109                         {       
1110                                 gchar *g_lang;
1111 //                              gchar *g_type;
1112 //                              GstPad* pad = 0;
1113 //                              g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1114 //                              GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1115 //                              GstStructure* str = gst_caps_get_structure(caps, 0);
1116 //                              g_type = gst_structure_get_name(str);
1117 //                              g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1118                                 subtitleStream subs;
1119                                 subs.type = stPlainText;
1120                                 g_lang = g_strdup_printf ("und");
1121                                 if ( tags && gst_is_tag_list(tags) )
1122                                         gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1123                                 subs.language_code = std::string(g_lang);
1124                                 eDebug("eServiceMP3::subtitle stream=%i language=%s"/* type=%s*/, i, g_lang/*, g_type*/);
1125                                 m_subtitleStreams.push_back(subs);
1126                                 g_free (g_lang);
1127 //                              g_free (g_type);
1128                         }
1129                 }
1130                 case GST_MESSAGE_ELEMENT:
1131                 {
1132                         if ( gst_is_missing_plugin_message(msg) )
1133                         {
1134                                 gchar *description = gst_missing_plugin_message_get_description(msg);
1135                                 if ( description )
1136                                 {
1137                                         m_error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1138                                         g_free(description);
1139                                         m_event((iPlayableService*)this, evUser+12);
1140                                 }
1141                         }
1142                         else if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1143                         {
1144                                 const gchar *eventname = gst_structure_get_name(msgstruct);
1145                                 if ( eventname )
1146                                 {
1147                                         if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1148                                         {
1149                                                 gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1150                                                 gst_structure_get_int (msgstruct, "width", &m_width);
1151                                                 gst_structure_get_int (msgstruct, "height", &m_height);
1152                                                 if (strstr(eventname, "Changed"))
1153                                                         m_event((iPlayableService*)this, evVideoSizeChanged);
1154                                         }
1155                                         else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1156                                         {
1157                                                 gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1158                                                 if (strstr(eventname, "Changed"))
1159                                                         m_event((iPlayableService*)this, evVideoFramerateChanged);
1160                                         }
1161                                         else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1162                                         {
1163                                                 gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1164                                                 if (strstr(eventname, "Changed"))
1165                                                         m_event((iPlayableService*)this, evVideoProgressiveChanged);
1166                                         }
1167                                 }
1168                         }
1169                 }
1170                 default:
1171                         break;
1172         }
1173         g_free (sourceName);
1174 }
1175
1176 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1177 {
1178         eServiceMP3 *_this = (eServiceMP3*)user_data;
1179         _this->m_pump.send(1);
1180                 /* wake */
1181         return GST_BUS_PASS;
1182 }
1183
1184 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1185 {
1186         if (!structure)
1187                 return atUnknown;
1188
1189         if ( gst_structure_has_name (structure, "audio/mpeg"))
1190         {
1191                 gint mpegversion, layer = -1;
1192                 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1193                         return atUnknown;
1194
1195                 switch (mpegversion) {
1196                         case 1:
1197                                 {
1198                                         gst_structure_get_int (structure, "layer", &layer);
1199                                         if ( layer == 3 )
1200                                                 return atMP3;
1201                                         else
1202                                                 return atMPEG;
1203                                         break;
1204                                 }
1205                         case 2:
1206                                 return atAAC;
1207                         case 4:
1208                                 return atAAC;
1209                         default:
1210                                 return atUnknown;
1211                 }
1212         }
1213
1214         else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1215                 return atAC3;
1216         else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1217                 return atDTS;
1218         else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1219                 return atPCM;
1220
1221         return atUnknown;
1222 }
1223
1224 void eServiceMP3::gstPoll(const int&)
1225 {
1226                 /* ok, we have a serious problem here. gstBusSyncHandler sends 
1227                    us the wakup signal, but likely before it was posted.
1228                    the usleep, an EVIL HACK (DON'T DO THAT!!!) works around this.
1229                    
1230                    I need to understand the API a bit more to make this work 
1231                    proplerly. */
1232         usleep(1);
1233         
1234         GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
1235         GstMessage *message;
1236         while ((message = gst_bus_pop (bus)))
1237         {
1238                 gstBusCall(bus, message);
1239                 gst_message_unref (message);
1240         }
1241 }
1242
1243 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1244
1245 void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
1246 {
1247         eServiceMP3 *_this = (eServiceMP3*)user_data;
1248         GstBuffer *buffer;
1249         g_signal_emit_by_name (appsink, "pull-buffer", &buffer);
1250         if (buffer)
1251         {
1252                 GstFormat fmt = GST_FORMAT_TIME;
1253                 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1254                 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1255                 size_t len = GST_BUFFER_SIZE(buffer);
1256                 unsigned char line[len+1];
1257                 memcpy(line, GST_BUFFER_DATA(buffer), len);
1258                 line[len] = 0;
1259 //              eDebug("got new subtitle @ buf_pos = %lld ns (in pts=%lld): '%s' ", buf_pos, buf_pos/11111, line);
1260                 if ( _this->m_subtitle_widget )
1261                 {
1262                         ePangoSubtitlePage page;
1263                         gRGB rgbcol(0xD0,0xD0,0xD0);
1264                         page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
1265                         page.show_pts = buf_pos / 11111L;
1266                         page.m_timeout = duration_ns / 1000000;
1267                         _this->m_subtitle_pages.push_back(page);
1268                         _this->pushSubtitles();
1269                 }
1270         }
1271 }
1272
1273 void eServiceMP3::pushSubtitles()
1274 {
1275         ePangoSubtitlePage page;
1276         GstClockTime base_time;
1277         pts_t running_pts;
1278         GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin),"subtitle_sink");
1279         GstClock *clock;
1280         clock = gst_element_get_clock (appsink);
1281         do
1282         {
1283                 page = m_subtitle_pages.front();
1284
1285                 base_time = gst_element_get_base_time (appsink);
1286                 running_pts = ( gst_clock_get_time (clock) - base_time ) / 11111L;
1287                 gint64 diff_ms = ( page.show_pts - running_pts ) / 90;
1288 //              eDebug("eServiceMP3::pushSubtitles show_pts = %lld  running_pts = %lld  diff = %lld", page.show_pts, running_pts, diff_ms);
1289                 if ( diff_ms > 20 )
1290                 {
1291 //                      eDebug("m_subtitle_sync_timer->start(%lld,1)", diff_ms);
1292                         m_subtitle_sync_timer->start(diff_ms, 1);
1293                         break;
1294                 }
1295                 else
1296                 {
1297                         m_subtitle_widget->setPage(page);
1298                         m_subtitle_pages.pop_front();
1299                 }
1300         } while ( !m_subtitle_pages.empty() );
1301
1302         gst_object_unref (clock);
1303 }
1304
1305 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
1306 {
1307         ePyObject entry;
1308         int tuplesize = PyTuple_Size(tuple);
1309         int pid, type;
1310         gint text_pid = 0;
1311
1312         if (!PyTuple_Check(tuple))
1313                 goto error_out;
1314         if (tuplesize < 1)
1315                 goto error_out;
1316         entry = PyTuple_GET_ITEM(tuple, 1);
1317         if (!PyInt_Check(entry))
1318                 goto error_out;
1319         pid = PyInt_AsLong(entry);
1320         entry = PyTuple_GET_ITEM(tuple, 2);
1321         if (!PyInt_Check(entry))
1322                 goto error_out;
1323         type = PyInt_AsLong(entry);
1324
1325         g_object_set (G_OBJECT (m_gst_playbin), "current-text", pid, NULL);
1326         m_currentSubtitleStream = pid;
1327
1328         m_subtitle_widget = new eSubtitleWidget(parent);
1329         m_subtitle_widget->resize(parent->size()); /* full size */
1330
1331         g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
1332
1333         eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
1334
1335         return 0;
1336
1337 error_out:
1338         eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
1339                 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
1340         return -1;
1341 }
1342
1343 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
1344 {
1345         eDebug("eServiceMP3::disableSubtitles");
1346         delete m_subtitle_widget;
1347         m_subtitle_widget = 0;
1348         return 0;
1349 }
1350
1351 PyObject *eServiceMP3::getCachedSubtitle()
1352 {
1353         eDebug("eServiceMP3::getCachedSubtitle");
1354         Py_RETURN_NONE;
1355 }
1356
1357 PyObject *eServiceMP3::getSubtitleList()
1358 {
1359         eDebug("eServiceMP3::getSubtitleList");
1360
1361         ePyObject l = PyList_New(0);
1362         int stream_count[sizeof(subtype_t)];
1363         for ( unsigned int i = 0; i < sizeof(subtype_t); i++ )
1364                 stream_count[i] = 0;
1365
1366         for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
1367         {
1368                 subtype_t type = IterSubtitleStream->type;
1369                 ePyObject tuple = PyTuple_New(5);
1370                 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1371                 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_count[type]));
1372                 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
1373                 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
1374                 PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
1375                 PyList_Append(l, tuple);
1376                 Py_DECREF(tuple);
1377                 stream_count[type]++;
1378         }
1379         return l;
1380 }
1381
1382 #else
1383 #warning gstreamer not available, not building media player
1384 #endif