servicemp3: abort pulling subtitle buffers when we get a NULL buffer
[openblackhole/openblackhole-enigma2.git] / lib / service / servicemp3.cpp
1         /* note: this requires gstreamer 0.10.x and a big list of plugins. */
2         /* it's currently hardcoded to use a big-endian alsasink as sink. */
3 #include <lib/base/ebase.h>
4 #include <lib/base/eerror.h>
5 #include <lib/base/init_num.h>
6 #include <lib/base/init.h>
7 #include <lib/base/nconfig.h>
8 #include <lib/base/object.h>
9 #include <lib/dvb/decoder.h>
10 #include <lib/components/file_eraser.h>
11 #include <lib/gui/esubtitle.h>
12 #include <lib/service/servicemp3.h>
13 #include <lib/service/service.h>
14 #include <lib/gdi/gpixmap.h>
15
16 #include <string>
17
18 #include <gst/gst.h>
19 #include <gst/pbutils/missing-plugins.h>
20 #include <sys/stat.h>
21
22 #define HTTP_TIMEOUT 10
23
24 // eServiceFactoryMP3
25
26 eServiceFactoryMP3::eServiceFactoryMP3()
27 {
28         ePtr<eServiceCenter> sc;
29         
30         eServiceCenter::getPrivInstance(sc);
31         if (sc)
32         {
33                 std::list<std::string> extensions;
34                 extensions.push_back("dts");
35                 extensions.push_back("mp2");
36                 extensions.push_back("mp3");
37                 extensions.push_back("ogg");
38                 extensions.push_back("mpg");
39                 extensions.push_back("vob");
40                 extensions.push_back("wav");
41                 extensions.push_back("wave");
42                 extensions.push_back("m4v");
43                 extensions.push_back("mkv");
44                 extensions.push_back("avi");
45                 extensions.push_back("divx");
46                 extensions.push_back("dat");
47                 extensions.push_back("flac");
48                 extensions.push_back("flv");
49                 extensions.push_back("mp4");
50                 extensions.push_back("mov");
51                 extensions.push_back("m4a");
52                 extensions.push_back("mts");
53                 extensions.push_back("m2ts");
54                 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
55         }
56
57         m_service_info = new eStaticServiceMP3Info();
58 }
59
60 eServiceFactoryMP3::~eServiceFactoryMP3()
61 {
62         ePtr<eServiceCenter> sc;
63         
64         eServiceCenter::getPrivInstance(sc);
65         if (sc)
66                 sc->removeServiceFactory(eServiceFactoryMP3::id);
67 }
68
69 DEFINE_REF(eServiceFactoryMP3)
70
71         // iServiceHandler
72 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
73 {
74                 // check resources...
75         ptr = new eServiceMP3(ref);
76         return 0;
77 }
78
79 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
80 {
81         ptr=0;
82         return -1;
83 }
84
85 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
86 {
87         ptr=0;
88         return -1;
89 }
90
91 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
92 {
93         ptr = m_service_info;
94         return 0;
95 }
96
97 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
98 {
99         DECLARE_REF(eMP3ServiceOfflineOperations);
100         eServiceReference m_ref;
101 public:
102         eMP3ServiceOfflineOperations(const eServiceReference &ref);
103         
104         RESULT deleteFromDisk(int simulate);
105         RESULT getListOfFilenames(std::list<std::string> &);
106         RESULT reindex();
107 };
108
109 DEFINE_REF(eMP3ServiceOfflineOperations);
110
111 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
112 {
113 }
114
115 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
116 {
117         if (!simulate)
118         {
119                 std::list<std::string> res;
120                 if (getListOfFilenames(res))
121                         return -1;
122                 
123                 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
124                 if (!eraser)
125                         eDebug("FATAL !! can't get background file eraser");
126
127                 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
128                 {
129                         eDebug("Removing %s...", i->c_str());
130                         if (eraser)
131                                 eraser->erase(i->c_str());
132                         else
133                                 ::unlink(i->c_str());
134                 }
135         }
136         return 0;
137 }
138
139 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
140 {
141         res.clear();
142         res.push_back(m_ref.path);
143         return 0;
144 }
145
146 RESULT eMP3ServiceOfflineOperations::reindex()
147 {
148         return -1;
149 }
150
151
152 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
153 {
154         ptr = new eMP3ServiceOfflineOperations(ref);
155         return 0;
156 }
157
158 // eStaticServiceMP3Info
159
160
161 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
162 // about unopened files.
163
164 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
165 // should have a database backend where ID3-files etc. are cached.
166 // this would allow listing the mp3 database based on certain filters.
167
168 DEFINE_REF(eStaticServiceMP3Info)
169
170 eStaticServiceMP3Info::eStaticServiceMP3Info()
171 {
172 }
173
174 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
175 {
176         if ( ref.name.length() )
177                 name = ref.name;
178         else
179         {
180                 size_t last = ref.path.rfind('/');
181                 if (last != std::string::npos)
182                         name = ref.path.substr(last+1);
183                 else
184                         name = ref.path;
185         }
186         return 0;
187 }
188
189 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
190 {
191         return -1;
192 }
193
194 int eStaticServiceMP3Info::getInfo(const eServiceReference &ref, int w)
195 {
196         switch (w)
197         {
198         case iServiceInformation::sTimeCreate:
199                 {
200                         struct stat s;
201                         if(stat(ref.path.c_str(), &s) == 0)
202                         {
203                                 return s.st_mtime;
204                         }
205                 }
206                 break;
207         }
208         return iServiceInformation::resNA;
209 }
210
211 PyObject* eStaticServiceMP3Info::getInfoObject(const eServiceReference &ref, int w)
212 {
213         switch(w)
214         {
215         case iServiceInformation::sFileSize:
216                 {
217                         struct stat s;
218                         if(stat(ref.path.c_str(), &s) == 0)
219                         {
220                                 return PyLong_FromLongLong(s.st_size);
221                         }
222                 }
223                 break;
224         }
225         Py_RETURN_NONE;
226 }
227
228 // eServiceMP3
229 int eServiceMP3::ac3_delay,
230     eServiceMP3::pcm_delay;
231
232 eServiceMP3::eServiceMP3(eServiceReference ref)
233         :m_ref(ref), m_pump(eApp, 1)
234 {
235         m_subtitle_sync_timer = eTimer::create(eApp);
236         m_streamingsrc_timeout = 0;
237         m_stream_tags = 0;
238         m_currentAudioStream = -1;
239         m_currentSubtitleStream = 0;
240         m_subtitle_widget = 0;
241         m_currentTrickRatio = 1.0;
242         m_subs_to_pull = 0;
243         m_buffer_size = 1*1024*1024;
244         m_prev_decoder_time = -1;
245         m_decoder_time_valid_state = 0;
246         m_errorInfo.missing_codec = "";
247
248         CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
249         CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
250         m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
251
252         m_state = stIdle;
253         eDebug("eServiceMP3::construct!");
254
255         const char *filename = m_ref.path.c_str();
256         const char *ext = strrchr(filename, '.');
257         if (!ext)
258                 ext = filename;
259
260         m_sourceinfo.is_video = FALSE;
261         m_sourceinfo.audiotype = atUnknown;
262         if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
263         {
264                 m_sourceinfo.containertype = ctMPEGPS;
265                 m_sourceinfo.is_video = TRUE;
266         }
267         else if ( strcasecmp(ext, ".ts") == 0 )
268         {
269                 m_sourceinfo.containertype = ctMPEGTS;
270                 m_sourceinfo.is_video = TRUE;
271         }
272         else if ( strcasecmp(ext, ".mkv") == 0 )
273         {
274                 m_sourceinfo.containertype = ctMKV;
275                 m_sourceinfo.is_video = TRUE;
276         }
277         else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
278         {
279                 m_sourceinfo.containertype = ctAVI;
280                 m_sourceinfo.is_video = TRUE;
281         }
282         else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0 || strcasecmp(ext, ".m4v") == 0)
283         {
284                 m_sourceinfo.containertype = ctMP4;
285                 m_sourceinfo.is_video = TRUE;
286         }
287         else if ( strcasecmp(ext, ".m4a") == 0 )
288         {
289                 m_sourceinfo.containertype = ctMP4;
290                 m_sourceinfo.audiotype = atAAC;
291         }
292         else if ( strcasecmp(ext, ".mp3") == 0 )
293                 m_sourceinfo.audiotype = atMP3;
294         else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
295                 m_sourceinfo.containertype = ctCDA;
296         if ( strcasecmp(ext, ".dat") == 0 )
297         {
298                 m_sourceinfo.containertype = ctVCD;
299                 m_sourceinfo.is_video = TRUE;
300         }
301         if ( (strncmp(filename, "http://", 7)) == 0 || (strncmp(filename, "udp://", 6)) == 0 || (strncmp(filename, "rtp://", 6)) == 0  || (strncmp(filename, "https://", 8)) == 0 || (strncmp(filename, "mms://", 6)) == 0 || (strncmp(filename, "rtsp://", 7)) == 0 || (strncmp(filename, "rtspt://", 7)) == 0 )
302                 m_sourceinfo.is_streaming = TRUE;
303
304         gchar *uri;
305
306         if ( m_sourceinfo.is_streaming )
307         {
308                 uri = g_strdup_printf ("%s", filename);
309                 m_streamingsrc_timeout = eTimer::create(eApp);;
310                 CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
311
312                 std::string config_str;
313                 if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
314                 {
315                         if ( config_str == "True" )
316                                 ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
317                 }
318                 if ( m_useragent.length() == 0 )
319                         m_useragent = "Dream Multimedia Dreambox Enigma2 Mediaplayer";
320         }
321         else if ( m_sourceinfo.containertype == ctCDA )
322         {
323                 int i_track = atoi(filename+18);
324                 uri = g_strdup_printf ("cdda://%i", i_track);
325         }
326         else if ( m_sourceinfo.containertype == ctVCD )
327         {
328                 int fd = open(filename,O_RDONLY);
329                 char tmp[128*1024];
330                 int ret = read(fd, tmp, 128*1024);
331                 close(fd);
332                 if ( ret == -1 ) // this is a "REAL" VCD
333                         uri = g_strdup_printf ("vcd://");
334                 else
335                         uri = g_filename_to_uri(filename, NULL, NULL);
336         }
337         else
338
339                 uri = g_filename_to_uri(filename, NULL, NULL);
340
341         eDebug("eServiceMP3::playbin2 uri=%s", uri);
342
343         m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
344         if (!m_gst_playbin)
345                 m_errorInfo.error_message = "failed to create GStreamer pipeline!\n";
346
347         g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
348
349         int flags = 0x47; // ( GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT );
350         g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
351
352         g_free(uri);
353
354         GstElement *subsink = gst_element_factory_make("appsink", "subtitle_sink");
355         if (!subsink)
356                 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
357         else
358         {
359                 m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
360                 g_object_set (G_OBJECT (subsink), "caps", gst_caps_from_string("text/plain; text/x-plain; text/x-pango-markup; video/x-dvd-subpicture; subpicture/x-pgs"), NULL);
361                 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
362                 
363         }
364
365         if ( m_gst_playbin )
366         {
367                 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), gstBusSyncHandler, this);
368                 char srt_filename[strlen(filename)+1];
369                 strncpy(srt_filename,filename,strlen(filename)-3);
370                 srt_filename[strlen(filename)-3]='\0';
371                 strcat(srt_filename, "srt");
372                 struct stat buffer;
373                 if (stat(srt_filename, &buffer) == 0)
374                 {
375                         eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
376                         g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
377                 }
378                 if ( m_sourceinfo.is_streaming )
379                 {
380                         g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
381                 }
382         } else
383         {
384                 m_event((iPlayableService*)this, evUser+12);
385
386                 if (m_gst_playbin)
387                         gst_object_unref(GST_OBJECT(m_gst_playbin));
388
389                 eDebug("eServiceMP3::sorry, can't play: %s",m_errorInfo.error_message.c_str());
390                 m_gst_playbin = 0;
391         }
392
393         setBufferSize(m_buffer_size);
394 }
395
396 eServiceMP3::~eServiceMP3()
397 {
398         // disconnect subtitle callback
399         GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
400
401         if (appsink)
402         {
403                 g_signal_handler_disconnect (appsink, m_subs_to_pull_handler_id);
404                 gst_object_unref(appsink);
405         }
406
407         delete m_subtitle_widget;
408
409         // disconnect sync handler callback
410         gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), NULL, NULL);
411
412         if (m_state == stRunning)
413                 stop();
414
415         if (m_stream_tags)
416                 gst_tag_list_free(m_stream_tags);
417         
418         if (m_gst_playbin)
419         {
420                 gst_object_unref (GST_OBJECT (m_gst_playbin));
421                 eDebug("eServiceMP3::destruct!");
422         }
423 }
424
425 DEFINE_REF(eServiceMP3);
426
427 DEFINE_REF(eServiceMP3::GstMessageContainer);
428
429 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
430 {
431         connection = new eConnection((iPlayableService*)this, m_event.connect(event));
432         return 0;
433 }
434
435 RESULT eServiceMP3::start()
436 {
437         ASSERT(m_state == stIdle);
438
439         m_state = stRunning;
440         if (m_gst_playbin)
441         {
442                 eDebug("eServiceMP3::starting pipeline");
443                 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
444         }
445
446         m_event(this, evStart);
447
448         return 0;
449 }
450
451 void eServiceMP3::sourceTimeout()
452 {
453         eDebug("eServiceMP3::http source timeout! issuing eof...");
454         m_event((iPlayableService*)this, evEOF);
455 }
456
457 RESULT eServiceMP3::stop()
458 {
459         ASSERT(m_state != stIdle);
460
461         if (m_state == stStopped)
462                 return -1;
463
464         eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
465         gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
466         m_state = stStopped;
467
468         return 0;
469 }
470
471 RESULT eServiceMP3::setTarget(int target)
472 {
473         return -1;
474 }
475
476 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
477 {
478         ptr=this;
479         return 0;
480 }
481
482 RESULT eServiceMP3::setSlowMotion(int ratio)
483 {
484         if (!ratio)
485                 return 0;
486         eDebug("eServiceMP3::setSlowMotion ratio=%f",1.0/(gdouble)ratio);
487         return trickSeek(1.0/(gdouble)ratio);
488 }
489
490 RESULT eServiceMP3::setFastForward(int ratio)
491 {
492         eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
493         return trickSeek(ratio);
494 }
495
496                 // iPausableService
497 RESULT eServiceMP3::pause()
498 {
499         if (!m_gst_playbin || m_state != stRunning)
500                 return -1;
501
502         trickSeek(0.0);
503
504         return 0;
505 }
506
507 RESULT eServiceMP3::unpause()
508 {
509         if (!m_gst_playbin || m_state != stRunning)
510                 return -1;
511
512         trickSeek(1.0);
513
514         return 0;
515 }
516
517         /* iSeekableService */
518 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
519 {
520         ptr = this;
521         return 0;
522 }
523
524 RESULT eServiceMP3::getLength(pts_t &pts)
525 {
526         if (!m_gst_playbin)
527                 return -1;
528
529         if (m_state != stRunning)
530                 return -1;
531
532         GstFormat fmt = GST_FORMAT_TIME;
533         gint64 len;
534         
535         if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
536                 return -1;
537                 /* len is in nanoseconds. we have 90 000 pts per second. */
538         
539         pts = len / 11111LL;
540         return 0;
541 }
542
543 RESULT eServiceMP3::seekToImpl(pts_t to)
544 {
545                 /* convert pts to nanoseconds */
546         gint64 time_nanoseconds = to * 11111LL;
547         if (!gst_element_seek (m_gst_playbin, m_currentTrickRatio, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
548                 GST_SEEK_TYPE_SET, time_nanoseconds,
549                 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
550         {
551                 eDebug("eServiceMP3::seekTo failed");
552                 return -1;
553         }
554
555         return 0;
556 }
557
558 RESULT eServiceMP3::seekTo(pts_t to)
559 {
560         RESULT ret = -1;
561
562         if (m_gst_playbin) {
563                 eSingleLocker l(m_subs_to_pull_lock); // this is needed to dont handle incomming subtitles during seek!
564                 if (!(ret = seekToImpl(to)))
565                 {
566                         m_subtitle_pages.clear();
567                         m_prev_decoder_time = -1;
568                         m_decoder_time_valid_state = 0;
569                         m_subs_to_pull = 0;
570                 }
571         }
572
573         return ret;
574 }
575
576
577 RESULT eServiceMP3::trickSeek(gdouble ratio)
578 {
579         m_currentTrickRatio = ratio;
580
581         if (!m_gst_playbin)
582                 return -1;
583         if (ratio > -0.01 && ratio < 0.01)
584         {
585                 gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
586                 return 0;
587         }
588
589         gint64 pos;
590         pts_t pts;
591         getPlayPosition(pts);
592         pos = pts * 11111LL;
593
594         gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
595
596         if (ratio >= 0.0)
597         {
598                 gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, -1);
599         }
600         else
601         {
602                 /* note that most elements will not support negative speed */
603                 gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos);
604         }
605
606         eSingleLocker l(m_subs_to_pull_lock);
607         m_subtitle_pages.clear();
608         m_subs_to_pull = 0;
609         return 0;
610 }
611
612
613 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
614 {
615         if (!m_gst_playbin)
616                 return -1;
617
618         pts_t ppos;
619         getPlayPosition(ppos);
620         ppos += to * direction;
621         if (ppos < 0)
622                 ppos = 0;
623         seekTo(ppos);
624         
625         return 0;
626 }
627
628 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
629 {
630         GstFormat fmt = GST_FORMAT_TIME;
631         gint64 pos;
632         GstElement *sink;
633         pts = 0;
634
635         if (!m_gst_playbin)
636                 return -1;
637         if (m_state != stRunning)
638                 return -1;
639
640         g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
641
642         if (!sink)
643                 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
644
645         if (!sink)
646                 return -1;
647
648         gchar *name = gst_element_get_name(sink);
649         gboolean use_get_decoder_time = strstr(name, "dvbaudiosink") || strstr(name, "dvbvideosink");
650         g_free(name);
651
652         if (use_get_decoder_time)
653                 g_signal_emit_by_name(sink, "get-decoder-time", &pos);
654
655         gst_object_unref(sink);
656
657         if (!use_get_decoder_time && !gst_element_query_position(m_gst_playbin, &fmt, &pos)) {
658                 eDebug("gst_element_query_position failed in getPlayPosition");
659                 return -1;
660         }
661
662         /* pos is in nanoseconds. we have 90 000 pts per second. */
663         pts = pos / 11111LL;
664         return 0;
665 }
666
667 RESULT eServiceMP3::setTrickmode(int trick)
668 {
669                 /* trickmode is not yet supported by our dvbmediasinks. */
670         return -1;
671 }
672
673 RESULT eServiceMP3::isCurrentlySeekable()
674 {
675         int ret = 3; /* just assume that seeking and fast/slow winding are possible */
676
677         if (!m_gst_playbin)
678                 return 0;
679         if (m_state != stRunning)
680                 return 0;
681
682         return ret;
683 }
684
685 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
686 {
687         i = this;
688         return 0;
689 }
690
691 RESULT eServiceMP3::getName(std::string &name)
692 {
693         std::string title = m_ref.getName();
694         if (title.empty())
695         {
696                 name = m_ref.path;
697                 size_t n = name.rfind('/');
698                 if (n != std::string::npos)
699                         name = name.substr(n + 1);
700         }
701         else
702                 name = title;
703         return 0;
704 }
705
706 int eServiceMP3::getInfo(int w)
707 {
708         const gchar *tag = 0;
709
710         switch (w)
711         {
712         case sServiceref: return m_ref;
713         case sVideoHeight: return m_height;
714         case sVideoWidth: return m_width;
715         case sFrameRate: return m_framerate;
716         case sProgressive: return m_progressive;
717         case sAspect: return m_aspect;
718         case sTagTitle:
719         case sTagArtist:
720         case sTagAlbum:
721         case sTagTitleSortname:
722         case sTagArtistSortname:
723         case sTagAlbumSortname:
724         case sTagDate:
725         case sTagComposer:
726         case sTagGenre:
727         case sTagComment:
728         case sTagExtendedComment:
729         case sTagLocation:
730         case sTagHomepage:
731         case sTagDescription:
732         case sTagVersion:
733         case sTagISRC:
734         case sTagOrganization:
735         case sTagCopyright:
736         case sTagCopyrightURI:
737         case sTagContact:
738         case sTagLicense:
739         case sTagLicenseURI:
740         case sTagCodec:
741         case sTagAudioCodec:
742         case sTagVideoCodec:
743         case sTagEncoder:
744         case sTagLanguageCode:
745         case sTagKeywords:
746         case sTagChannelMode:
747         case sUser+12:
748                 return resIsString;
749         case sTagTrackGain:
750         case sTagTrackPeak:
751         case sTagAlbumGain:
752         case sTagAlbumPeak:
753         case sTagReferenceLevel:
754         case sTagBeatsPerMinute:
755         case sTagImage:
756         case sTagPreviewImage:
757         case sTagAttachment:
758                 return resIsPyObject;
759         case sTagTrackNumber:
760                 tag = GST_TAG_TRACK_NUMBER;
761                 break;
762         case sTagTrackCount:
763                 tag = GST_TAG_TRACK_COUNT;
764                 break;
765         case sTagAlbumVolumeNumber:
766                 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
767                 break;
768         case sTagAlbumVolumeCount:
769                 tag = GST_TAG_ALBUM_VOLUME_COUNT;
770                 break;
771         case sTagBitrate:
772                 tag = GST_TAG_BITRATE;
773                 break;
774         case sTagNominalBitrate:
775                 tag = GST_TAG_NOMINAL_BITRATE;
776                 break;
777         case sTagMinimumBitrate:
778                 tag = GST_TAG_MINIMUM_BITRATE;
779                 break;
780         case sTagMaximumBitrate:
781                 tag = GST_TAG_MAXIMUM_BITRATE;
782                 break;
783         case sTagSerial:
784                 tag = GST_TAG_SERIAL;
785                 break;
786         case sTagEncoderVersion:
787                 tag = GST_TAG_ENCODER_VERSION;
788                 break;
789         case sTagCRC:
790                 tag = "has-crc";
791                 break;
792         default:
793                 return resNA;
794         }
795
796         if (!m_stream_tags || !tag)
797                 return 0;
798         
799         guint value;
800         if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
801                 return (int) value;
802
803         return 0;
804 }
805
806 std::string eServiceMP3::getInfoString(int w)
807 {
808         if ( !m_stream_tags && w < sUser && w > 26 )
809                 return "";
810         const gchar *tag = 0;
811         switch (w)
812         {
813         case sTagTitle:
814                 tag = GST_TAG_TITLE;
815                 break;
816         case sTagArtist:
817                 tag = GST_TAG_ARTIST;
818                 break;
819         case sTagAlbum:
820                 tag = GST_TAG_ALBUM;
821                 break;
822         case sTagTitleSortname:
823                 tag = GST_TAG_TITLE_SORTNAME;
824                 break;
825         case sTagArtistSortname:
826                 tag = GST_TAG_ARTIST_SORTNAME;
827                 break;
828         case sTagAlbumSortname:
829                 tag = GST_TAG_ALBUM_SORTNAME;
830                 break;
831         case sTagDate:
832                 GDate *date;
833                 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
834                 {
835                         gchar res[5];
836                         g_date_strftime (res, sizeof(res), "%Y-%M-%D", date); 
837                         return (std::string)res;
838                 }
839                 break;
840         case sTagComposer:
841                 tag = GST_TAG_COMPOSER;
842                 break;
843         case sTagGenre:
844                 tag = GST_TAG_GENRE;
845                 break;
846         case sTagComment:
847                 tag = GST_TAG_COMMENT;
848                 break;
849         case sTagExtendedComment:
850                 tag = GST_TAG_EXTENDED_COMMENT;
851                 break;
852         case sTagLocation:
853                 tag = GST_TAG_LOCATION;
854                 break;
855         case sTagHomepage:
856                 tag = GST_TAG_HOMEPAGE;
857                 break;
858         case sTagDescription:
859                 tag = GST_TAG_DESCRIPTION;
860                 break;
861         case sTagVersion:
862                 tag = GST_TAG_VERSION;
863                 break;
864         case sTagISRC:
865                 tag = GST_TAG_ISRC;
866                 break;
867         case sTagOrganization:
868                 tag = GST_TAG_ORGANIZATION;
869                 break;
870         case sTagCopyright:
871                 tag = GST_TAG_COPYRIGHT;
872                 break;
873         case sTagCopyrightURI:
874                 tag = GST_TAG_COPYRIGHT_URI;
875                 break;
876         case sTagContact:
877                 tag = GST_TAG_CONTACT;
878                 break;
879         case sTagLicense:
880                 tag = GST_TAG_LICENSE;
881                 break;
882         case sTagLicenseURI:
883                 tag = GST_TAG_LICENSE_URI;
884                 break;
885         case sTagCodec:
886                 tag = GST_TAG_CODEC;
887                 break;
888         case sTagAudioCodec:
889                 tag = GST_TAG_AUDIO_CODEC;
890                 break;
891         case sTagVideoCodec:
892                 tag = GST_TAG_VIDEO_CODEC;
893                 break;
894         case sTagEncoder:
895                 tag = GST_TAG_ENCODER;
896                 break;
897         case sTagLanguageCode:
898                 tag = GST_TAG_LANGUAGE_CODE;
899                 break;
900         case sTagKeywords:
901                 tag = GST_TAG_KEYWORDS;
902                 break;
903         case sTagChannelMode:
904                 tag = "channel-mode";
905                 break;
906         case sUser+12:
907                 return m_errorInfo.error_message;
908         default:
909                 return "";
910         }
911         if ( !tag )
912                 return "";
913         gchar *value;
914         if (m_stream_tags && gst_tag_list_get_string(m_stream_tags, tag, &value))
915         {
916                 std::string res = value;
917                 g_free(value);
918                 return res;
919         }
920         return "";
921 }
922
923 PyObject *eServiceMP3::getInfoObject(int w)
924 {
925         const gchar *tag = 0;
926         bool isBuffer = false;
927         switch (w)
928         {
929                 case sTagTrackGain:
930                         tag = GST_TAG_TRACK_GAIN;
931                         break;
932                 case sTagTrackPeak:
933                         tag = GST_TAG_TRACK_PEAK;
934                         break;
935                 case sTagAlbumGain:
936                         tag = GST_TAG_ALBUM_GAIN;
937                         break;
938                 case sTagAlbumPeak:
939                         tag = GST_TAG_ALBUM_PEAK;
940                         break;
941                 case sTagReferenceLevel:
942                         tag = GST_TAG_REFERENCE_LEVEL;
943                         break;
944                 case sTagBeatsPerMinute:
945                         tag = GST_TAG_BEATS_PER_MINUTE;
946                         break;
947                 case sTagImage:
948                         tag = GST_TAG_IMAGE;
949                         isBuffer = true;
950                         break;
951                 case sTagPreviewImage:
952                         tag = GST_TAG_PREVIEW_IMAGE;
953                         isBuffer = true;
954                         break;
955                 case sTagAttachment:
956                         tag = GST_TAG_ATTACHMENT;
957                         isBuffer = true;
958                         break;
959                 default:
960                         break;
961         }
962
963         if (m_stream_tags && tag)
964         {
965                 if (isBuffer)
966                 {
967                         const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
968                         if ( gv_buffer )
969                         {
970                                 GstBuffer *buffer;
971                                 buffer = gst_value_get_buffer (gv_buffer);
972                                 return PyBuffer_FromMemory(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
973                         }
974                 }
975                 else
976                 {
977                         gdouble value = 0.0;
978                         gst_tag_list_get_double(m_stream_tags, tag, &value);
979                         return PyFloat_FromDouble(value);
980                 }
981         }
982
983         Py_RETURN_NONE;
984 }
985
986 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
987 {
988         ptr = this;
989         return 0;
990 }
991
992 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
993 {
994         ptr = this;
995         return 0;
996 }
997
998 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
999 {
1000         ptr = this;
1001         return 0;
1002 }
1003
1004 RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
1005 {
1006         ptr = this;
1007         return 0;
1008 }
1009
1010 int eServiceMP3::getNumberOfTracks()
1011 {
1012         return m_audioStreams.size();
1013 }
1014
1015 int eServiceMP3::getCurrentTrack()
1016 {
1017         if (m_currentAudioStream == -1)
1018                 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
1019         return m_currentAudioStream;
1020 }
1021
1022 RESULT eServiceMP3::selectTrack(unsigned int i)
1023 {
1024         pts_t ppos;
1025         getPlayPosition(ppos);
1026         ppos -= 90000;
1027         if (ppos < 0)
1028                 ppos = 0;
1029
1030         int ret = selectAudioStream(i);
1031         if (!ret) {
1032                 /* flush */
1033                 seekTo(ppos);
1034         }
1035
1036         return ret;
1037 }
1038
1039 int eServiceMP3::selectAudioStream(int i)
1040 {
1041         int current_audio;
1042         g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
1043         g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &current_audio, NULL);
1044         if ( current_audio == i )
1045         {
1046                 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
1047                 m_currentAudioStream = i;
1048                 return 0;
1049         }
1050         return -1;
1051 }
1052
1053 int eServiceMP3::getCurrentChannel()
1054 {
1055         return STEREO;
1056 }
1057
1058 RESULT eServiceMP3::selectChannel(int i)
1059 {
1060         eDebug("eServiceMP3::selectChannel(%i)",i);
1061         return 0;
1062 }
1063
1064 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
1065 {
1066         if (i >= m_audioStreams.size())
1067                 return -2;
1068                 info.m_description = m_audioStreams[i].codec;
1069 /*      if (m_audioStreams[i].type == atMPEG)
1070                 info.m_description = "MPEG";
1071         else if (m_audioStreams[i].type == atMP3)
1072                 info.m_description = "MP3";
1073         else if (m_audioStreams[i].type == atAC3)
1074                 info.m_description = "AC3";
1075         else if (m_audioStreams[i].type == atAAC)
1076                 info.m_description = "AAC";
1077         else if (m_audioStreams[i].type == atDTS)
1078                 info.m_description = "DTS";
1079         else if (m_audioStreams[i].type == atPCM)
1080                 info.m_description = "PCM";
1081         else if (m_audioStreams[i].type == atOGG)
1082                 info.m_description = "OGG";
1083         else if (m_audioStreams[i].type == atFLAC)
1084                 info.m_description = "FLAC";
1085         else
1086                 info.m_description = "???";*/
1087         if (info.m_language.empty())
1088                 info.m_language = m_audioStreams[i].language_code;
1089         return 0;
1090 }
1091
1092 subtype_t getSubtitleType(GstPad* pad, gchar *g_codec=NULL)
1093 {
1094         subtype_t type = stUnknown;
1095         GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1096
1097         if ( caps )
1098         {
1099                 GstStructure* str = gst_caps_get_structure(caps, 0);
1100                 const gchar *g_type = gst_structure_get_name(str);
1101                 eDebug("getSubtitleType::subtitle probe caps type=%s", g_type);
1102
1103                 if ( !strcmp(g_type, "video/x-dvd-subpicture") )
1104                         type = stVOB;
1105                 else if ( !strcmp(g_type, "text/x-pango-markup") )
1106                         type = stSSA;
1107                 else if ( !strcmp(g_type, "text/plain") )
1108                         type = stPlainText;
1109                 else if ( !strcmp(g_type, "subpicture/x-pgs") )
1110                         type = stPGS;
1111                 else
1112                         eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec);
1113         }
1114         else if ( g_codec )
1115         {
1116                 eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec);
1117                 if ( !strcmp(g_codec, "VOB") )
1118                         type = stVOB;
1119                 else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") )
1120                         type = stSSA;
1121                 else if ( !strcmp(g_codec, "ASS") )
1122                         type = stASS;
1123                 else if ( !strcmp(g_codec, "UTF-8 plain text") )
1124                         type = stPlainText;
1125                 else
1126                         eDebug("getSubtitleType::unsupported subtitle codec %s", g_codec);
1127         }
1128         else
1129                 eDebug("getSubtitleType::unidentifiable subtitle stream!");
1130
1131         return type;
1132 }
1133
1134 void eServiceMP3::gstBusCall(GstMessage *msg)
1135 {
1136         if (!msg)
1137                 return;
1138         gchar *sourceName;
1139         GstObject *source;
1140
1141         source = GST_MESSAGE_SRC(msg);
1142         sourceName = gst_object_get_name(source);
1143 #if 0
1144         if (gst_message_get_structure(msg))
1145         {
1146                 gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
1147                 eDebug("eServiceMP3::gst_message from %s: %s", sourceName, string);
1148                 g_free(string);
1149         }
1150         else
1151                 eDebug("eServiceMP3::gst_message from %s: %s (without structure)", sourceName, GST_MESSAGE_TYPE_NAME(msg));
1152 #endif
1153         switch (GST_MESSAGE_TYPE (msg))
1154         {
1155                 case GST_MESSAGE_EOS:
1156                         m_event((iPlayableService*)this, evEOF);
1157                         break;
1158                 case GST_MESSAGE_STATE_CHANGED:
1159                 {
1160                         if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1161                                 break;
1162
1163                         GstState old_state, new_state;
1164                         gst_message_parse_state_changed(msg, &old_state, &new_state, NULL);
1165                 
1166                         if(old_state == new_state)
1167                                 break;
1168         
1169                         eDebug("eServiceMP3::state transition %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
1170         
1171                         GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state);
1172         
1173                         switch(transition)
1174                         {
1175                                 case GST_STATE_CHANGE_NULL_TO_READY:
1176                                 {
1177                                 }       break;
1178                                 case GST_STATE_CHANGE_READY_TO_PAUSED:
1179                                 {
1180                                         GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1181                                         if (appsink)
1182                                         {
1183                                                 g_object_set (G_OBJECT (appsink), "max-buffers", 2, NULL);
1184                                                 g_object_set (G_OBJECT (appsink), "sync", FALSE, NULL);
1185                                                 g_object_set (G_OBJECT (appsink), "emit-signals", TRUE, NULL);
1186                                                 eDebug("eServiceMP3::appsink properties set!");
1187                                                 gst_object_unref(appsink);
1188                                         }
1189                                         setAC3Delay(ac3_delay);
1190                                         setPCMDelay(pcm_delay);
1191                                 }       break;
1192                                 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1193                                 {
1194                                         if ( m_sourceinfo.is_streaming && m_streamingsrc_timeout )
1195                                                 m_streamingsrc_timeout->stop();
1196                                 }       break;
1197                                 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1198                                 {
1199                                 }       break;
1200                                 case GST_STATE_CHANGE_PAUSED_TO_READY:
1201                                 {
1202                                 }       break;
1203                                 case GST_STATE_CHANGE_READY_TO_NULL:
1204                                 {
1205                                 }       break;
1206                         }
1207                         break;
1208                 }
1209                 case GST_MESSAGE_ERROR:
1210                 {
1211                         gchar *debug;
1212                         GError *err;
1213                         gst_message_parse_error (msg, &err, &debug);
1214                         g_free (debug);
1215                         eWarning("Gstreamer error: %s (%i) from %s", err->message, err->code, sourceName );
1216                         if ( err->domain == GST_STREAM_ERROR )
1217                         {
1218                                 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1219                                 {
1220                                         if ( g_strrstr(sourceName, "videosink") )
1221                                                 m_event((iPlayableService*)this, evUser+11);
1222                                         else if ( g_strrstr(sourceName, "audiosink") )
1223                                                 m_event((iPlayableService*)this, evUser+10);
1224                                 }
1225                         }
1226                         g_error_free(err);
1227                         break;
1228                 }
1229                 case GST_MESSAGE_INFO:
1230                 {
1231                         gchar *debug;
1232                         GError *inf;
1233         
1234                         gst_message_parse_info (msg, &inf, &debug);
1235                         g_free (debug);
1236                         if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1237                         {
1238                                 if ( g_strrstr(sourceName, "videosink") )
1239                                         m_event((iPlayableService*)this, evUser+14);
1240                         }
1241                         g_error_free(inf);
1242                         break;
1243                 }
1244                 case GST_MESSAGE_TAG:
1245                 {
1246                         GstTagList *tags, *result;
1247                         gst_message_parse_tag(msg, &tags);
1248         
1249                         result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE);
1250                         if (result)
1251                         {
1252                                 if (m_stream_tags)
1253                                         gst_tag_list_free(m_stream_tags);
1254                                 m_stream_tags = result;
1255                         }
1256         
1257                         const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1258                         if ( gv_image )
1259                         {
1260                                 GstBuffer *buf_image;
1261                                 buf_image = gst_value_get_buffer (gv_image);
1262                                 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1263                                 int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image));
1264                                 close(fd);
1265                                 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1266                                 m_event((iPlayableService*)this, evUser+13);
1267                         }
1268                         gst_tag_list_free(tags);
1269                         m_event((iPlayableService*)this, evUpdatedInfo);
1270                         break;
1271                 }
1272                 case GST_MESSAGE_ASYNC_DONE:
1273                 {
1274                         if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1275                                 break;
1276
1277                         GstTagList *tags;
1278                         gint i, active_idx, n_video = 0, n_audio = 0, n_text = 0;
1279
1280                         g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1281                         g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1282                         g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1283
1284                         eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1285
1286                         if ( n_video + n_audio <= 0 )
1287                                 stop();
1288
1289                         active_idx = 0;
1290
1291                         m_audioStreams.clear();
1292                         m_subtitleStreams.clear();
1293
1294                         for (i = 0; i < n_audio; i++)
1295                         {
1296                                 audioStream audio;
1297                                 gchar *g_codec, *g_lang;
1298                                 GstPad* pad = 0;
1299                                 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1300                                 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1301                                 if (!caps)
1302                                         continue;
1303                                 GstStructure* str = gst_caps_get_structure(caps, 0);
1304                                 const gchar *g_type = gst_structure_get_name(str);
1305                                 eDebug("AUDIO STRUCT=%s", g_type);
1306                                 audio.type = gstCheckAudioPad(str);
1307                                 g_codec = g_strdup(g_type);
1308                                 g_lang = g_strdup_printf ("und");
1309                                 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1310                                 if ( tags && gst_is_tag_list(tags) )
1311                                 {
1312                                         gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1313                                         gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1314                                         gst_tag_list_free(tags);
1315                                 }
1316                                 audio.language_code = std::string(g_lang);
1317                                 audio.codec = std::string(g_codec);
1318                                 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1319                                 m_audioStreams.push_back(audio);
1320                                 g_free (g_lang);
1321                                 g_free (g_codec);
1322                                 gst_caps_unref(caps);
1323                         }
1324
1325                         for (i = 0; i < n_text; i++)
1326                         {       
1327                                 gchar *g_codec = NULL, *g_lang = NULL;
1328                                 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1329                                 subtitleStream subs;
1330 //                              int ret;
1331
1332                                 g_lang = g_strdup_printf ("und");
1333                                 if ( tags && gst_is_tag_list(tags) )
1334                                 {
1335                                         gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1336                                         gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec);
1337                                         gst_tag_list_free(tags);
1338                                 }
1339
1340                                 subs.language_code = std::string(g_lang);
1341                                 eDebug("eServiceMP3::subtitle stream=%i language=%s codec=%s", i, g_lang, g_codec);
1342                                 
1343                                 GstPad* pad = 0;
1344                                 g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1345                                 if ( pad )
1346                                         g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
1347                                 subs.type = getSubtitleType(pad, g_codec);
1348
1349                                 m_subtitleStreams.push_back(subs);
1350                                 g_free (g_lang);
1351                         }
1352                         m_event((iPlayableService*)this, evUpdatedEventInfo);
1353
1354                         if ( m_errorInfo.missing_codec != "" )
1355                         {
1356                                 if ( m_errorInfo.missing_codec.find("video/") == 0 || ( m_errorInfo.missing_codec.find("audio/") == 0 && getNumberOfTracks() == 0 ) )
1357                                         m_event((iPlayableService*)this, evUser+12);
1358                         }
1359                         break;
1360                 }
1361                 case GST_MESSAGE_ELEMENT:
1362                 {
1363                         if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1364                         {
1365                                 if ( gst_is_missing_plugin_message(msg) )
1366                                 {
1367                                         GstCaps *caps;
1368                                         gst_structure_get (msgstruct, "detail", GST_TYPE_CAPS, &caps, NULL); 
1369                                         std::string codec = (const char*) gst_caps_to_string(caps);
1370                                         gchar *description = gst_missing_plugin_message_get_description(msg);
1371                                         if ( description )
1372                                         {
1373                                                 eDebug("eServiceMP3::m_errorInfo.missing_codec = %s", codec.c_str());
1374                                                 m_errorInfo.error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1375                                                 m_errorInfo.missing_codec = codec.substr(0,(codec.find_first_of(',')));
1376                                                 g_free(description);
1377                                         }
1378                                         gst_caps_unref(caps);
1379                                 }
1380                                 else
1381                                 {
1382                                         const gchar *eventname = gst_structure_get_name(msgstruct);
1383                                         if ( eventname )
1384                                         {
1385                                                 if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1386                                                 {
1387                                                         gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1388                                                         gst_structure_get_int (msgstruct, "width", &m_width);
1389                                                         gst_structure_get_int (msgstruct, "height", &m_height);
1390                                                         if (strstr(eventname, "Changed"))
1391                                                                 m_event((iPlayableService*)this, evVideoSizeChanged);
1392                                                 }
1393                                                 else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1394                                                 {
1395                                                         gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1396                                                         if (strstr(eventname, "Changed"))
1397                                                                 m_event((iPlayableService*)this, evVideoFramerateChanged);
1398                                                 }
1399                                                 else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1400                                                 {
1401                                                         gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1402                                                         if (strstr(eventname, "Changed"))
1403                                                                 m_event((iPlayableService*)this, evVideoProgressiveChanged);
1404                                                 }
1405                                         }
1406                                 }
1407                         }
1408                         break;
1409                 }
1410                 case GST_MESSAGE_BUFFERING:
1411                 {
1412                         GstBufferingMode mode;
1413                         gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
1414                         gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
1415                         m_event((iPlayableService*)this, evBuffering);
1416                         break;
1417                 }
1418                 case GST_MESSAGE_STREAM_STATUS:
1419                 {
1420                         GstStreamStatusType type;
1421                         GstElement *owner;
1422                         gst_message_parse_stream_status (msg, &type, &owner);
1423                         if ( type == GST_STREAM_STATUS_TYPE_CREATE && m_sourceinfo.is_streaming )
1424                         {
1425                                 if ( GST_IS_PAD(source) )
1426                                         owner = gst_pad_get_parent_element(GST_PAD(source));
1427                                 else if ( GST_IS_ELEMENT(source) )
1428                                         owner = GST_ELEMENT(source);
1429                                 else
1430                                         owner = 0;
1431                                 if ( owner )
1432                                 {
1433                                         GstElementFactory *factory = gst_element_get_factory(GST_ELEMENT(owner));
1434                                         const gchar *name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
1435                                         if (!strcmp(name, "souphttpsrc"))
1436                                         {
1437                                                 m_streamingsrc_timeout->start(HTTP_TIMEOUT*1000, true);
1438                                                 g_object_set (G_OBJECT (owner), "timeout", HTTP_TIMEOUT, NULL);
1439                                                 eDebug("eServiceMP3::GST_STREAM_STATUS_TYPE_CREATE -> setting timeout on %s to %is", name, HTTP_TIMEOUT);
1440                                         }
1441                                         
1442                                 }
1443                                 if ( GST_IS_PAD(source) )
1444                                         gst_object_unref(owner);
1445                         }
1446                         break;
1447                 }
1448                 default:
1449                         break;
1450         }
1451         g_free (sourceName);
1452 }
1453
1454 void eServiceMP3::handleMessage(GstMessage *msg)
1455 {
1456         if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_STATE_CHANGED && GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1457         {
1458                 /*
1459                  * ignore verbose state change messages for all active elements;
1460                  * we only need to handle state-change events for the playbin
1461                  */
1462                 gst_message_unref(msg);
1463                 return;
1464         }
1465         m_pump.send(new GstMessageContainer(1, msg, NULL));
1466 }
1467
1468 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1469 {
1470         eServiceMP3 *_this = (eServiceMP3*)user_data;
1471         if (_this) _this->handleMessage(message);
1472         return GST_BUS_DROP;
1473 }
1474
1475 void eServiceMP3::gstHTTPSourceSetAgent(GObject *object, GParamSpec *unused, gpointer user_data)
1476 {
1477         eServiceMP3 *_this = (eServiceMP3*)user_data;
1478         GstElement *source;
1479         g_object_get(_this->m_gst_playbin, "source", &source, NULL);
1480         g_object_set (G_OBJECT (source), "user-agent", _this->m_useragent.c_str(), NULL);
1481         gst_object_unref(source);
1482 }
1483
1484 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1485 {
1486         if (!structure)
1487                 return atUnknown;
1488
1489         if ( gst_structure_has_name (structure, "audio/mpeg"))
1490         {
1491                 gint mpegversion, layer = -1;
1492                 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1493                         return atUnknown;
1494
1495                 switch (mpegversion) {
1496                         case 1:
1497                                 {
1498                                         gst_structure_get_int (structure, "layer", &layer);
1499                                         if ( layer == 3 )
1500                                                 return atMP3;
1501                                         else
1502                                                 return atMPEG;
1503                                         break;
1504                                 }
1505                         case 2:
1506                                 return atAAC;
1507                         case 4:
1508                                 return atAAC;
1509                         default:
1510                                 return atUnknown;
1511                 }
1512         }
1513
1514         else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1515                 return atAC3;
1516         else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1517                 return atDTS;
1518         else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1519                 return atPCM;
1520
1521         return atUnknown;
1522 }
1523
1524 void eServiceMP3::gstPoll(ePtr<GstMessageContainer> const &msg)
1525 {
1526         switch (msg->getType())
1527         {
1528                 case 1:
1529                 {
1530                         GstMessage *gstmessage = *((GstMessageContainer*)msg);
1531                         if (gstmessage)
1532                         {
1533                                 gstBusCall(gstmessage);
1534                         }
1535                         break;
1536                 }
1537                 case 2:
1538                         pullSubtitle();
1539                         break;
1540                 case 3:
1541                 {
1542                         GstPad *pad = *((GstMessageContainer*)msg);
1543                         gstTextpadHasCAPS_synced(pad);
1544                         break;
1545                 }
1546         }
1547 }
1548
1549 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1550
1551 void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
1552 {
1553         eServiceMP3 *_this = (eServiceMP3*)user_data;
1554         eSingleLocker l(_this->m_subs_to_pull_lock);
1555         ++_this->m_subs_to_pull;
1556         _this->m_pump.send(new GstMessageContainer(2, NULL, NULL));
1557 }
1558
1559 void eServiceMP3::gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data)
1560 {
1561         eServiceMP3 *_this = (eServiceMP3*)user_data;
1562
1563         gst_object_ref (pad);
1564
1565         _this->m_pump.send(new GstMessageContainer(3, NULL, pad));
1566 }
1567
1568 void eServiceMP3::gstTextpadHasCAPS_synced(GstPad *pad)
1569 {
1570         GstCaps *caps;
1571
1572         g_object_get (G_OBJECT (pad), "caps", &caps, NULL);
1573
1574         eDebug("gstTextpadHasCAPS:: signal::caps = %s", gst_caps_to_string(caps));
1575
1576         if (caps)
1577         {
1578                 subtitleStream subs;
1579
1580 //              eDebug("gstGhostpadHasCAPS_synced %p %d", pad, m_subtitleStreams.size());
1581
1582                 if (!m_subtitleStreams.empty())
1583                         subs = m_subtitleStreams[m_currentSubtitleStream];
1584                 else {
1585                         subs.type = stUnknown;
1586                         subs.pad = pad;
1587                 }
1588
1589                 if ( subs.type == stUnknown )
1590                 {
1591                         GstTagList *tags;
1592 //                      eDebug("gstGhostpadHasCAPS::m_subtitleStreams[%i].type == stUnknown...", m_currentSubtitleStream);
1593
1594                         gchar *g_lang;
1595                         g_signal_emit_by_name (m_gst_playbin, "get-text-tags", m_currentSubtitleStream, &tags);
1596
1597                         g_lang = g_strdup_printf ("und");
1598                         if ( tags && gst_is_tag_list(tags) )
1599                                 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1600
1601                         subs.language_code = std::string(g_lang);
1602                         subs.type = getSubtitleType(pad);
1603
1604                         if (!m_subtitleStreams.empty())
1605                                 m_subtitleStreams[m_currentSubtitleStream] = subs;
1606                         else
1607                                 m_subtitleStreams.push_back(subs);
1608
1609                         g_free (g_lang);
1610                 }
1611
1612 //              eDebug("gstGhostpadHasCAPS:: m_gst_prev_subtitle_caps=%s equal=%i",gst_caps_to_string(m_gst_prev_subtitle_caps),gst_caps_is_equal(m_gst_prev_subtitle_caps, caps));
1613
1614                 gst_caps_unref (caps);
1615         }
1616 }
1617
1618 void eServiceMP3::pullSubtitle()
1619 {
1620         GstElement *sink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1621         if (sink)
1622         {
1623                 while (m_subs_to_pull && m_subtitle_pages.size() < 2)
1624                 {
1625                         GstBuffer *buffer;
1626                         {
1627                                 eSingleLocker l(m_subs_to_pull_lock);
1628                                 /* m_subs_to_pull could have been cleared, while we didn't have the lock */
1629                                 if (m_subs_to_pull)
1630                                 {
1631                                         --m_subs_to_pull;
1632                                         g_signal_emit_by_name (sink, "pull-buffer", &buffer);
1633                                         if (!buffer)
1634                                         {
1635                                                 /* appsink stopped, or EOS occurred. We should not continue in our pull loop */
1636                                                 m_subs_to_pull = 0;
1637                                         }
1638                                 }
1639                         }
1640                         if (buffer)
1641                         {
1642                                 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1643                                 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1644                                 size_t len = GST_BUFFER_SIZE(buffer);
1645                                 eDebug("pullSubtitle m_subtitleStreams[m_currentSubtitleStream].type=%i",m_subtitleStreams[m_currentSubtitleStream].type);
1646                                 
1647                                 if ( m_subtitleStreams[m_currentSubtitleStream].type )
1648                                 {
1649                                         if ( m_subtitleStreams[m_currentSubtitleStream].type < stVOB )
1650                                         {
1651                                                 unsigned char line[len+1];
1652                                                 SubtitlePage page;
1653                                                 memcpy(line, GST_BUFFER_DATA(buffer), len);
1654                                                 line[len] = 0;
1655                                                 eDebug("got new text subtitle @ buf_pos = %lld ns (in pts=%lld): '%s' ", buf_pos, buf_pos/11111, line);
1656                                                 gRGB rgbcol(0xD0,0xD0,0xD0);
1657                                                 page.type = SubtitlePage::Pango;
1658                                                 page.pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
1659                                                 page.pango_page.m_show_pts = buf_pos / 11111L;
1660                                                 page.pango_page.m_timeout = duration_ns / 1000000;
1661                                                 m_subtitle_pages.push_back(page);
1662                                                 if (m_subtitle_pages.size()==1)
1663                                                         pushSubtitles();
1664                                         }
1665                                         else
1666                                         {
1667                                                 eDebug("unsupported subpicture... ignoring");
1668                                         }
1669                                 }
1670                                 gst_buffer_unref(buffer);
1671                         }
1672                 }
1673                 gst_object_unref(sink);
1674         }
1675         else
1676                 eDebug("no subtitle sink!");
1677 }
1678
1679 void eServiceMP3::pushSubtitles()
1680 {
1681         while ( !m_subtitle_pages.empty() )
1682         {
1683                 SubtitlePage &frontpage = m_subtitle_pages.front();
1684                 pts_t running_pts;
1685                 gint64 diff_ms = 0;
1686                 gint64 show_pts = 0;
1687
1688                 getPlayPosition(running_pts);
1689
1690                 if (m_decoder_time_valid_state < 4) {
1691                         ++m_decoder_time_valid_state;
1692                         if (m_prev_decoder_time == running_pts)
1693                                 m_decoder_time_valid_state = 0;
1694                         if (m_decoder_time_valid_state < 4) {
1695 //                              if (m_decoder_time_valid_state)
1696 //                                      eDebug("%d: decoder time not valid! prev %lld, now %lld\n", m_decoder_time_valid_state, m_prev_decoder_time/90, running_pts/90);
1697 //                              else
1698 //                                      eDebug("%d: decoder time not valid! now %lld\n", m_decoder_time_valid_state, running_pts/90);
1699                                 m_subtitle_sync_timer->start(25, true);
1700                                 m_prev_decoder_time = running_pts;
1701                                 break;
1702                         }
1703                 }
1704
1705                 if (frontpage.type == SubtitlePage::Pango)
1706                         show_pts = frontpage.pango_page.m_show_pts;
1707
1708                 diff_ms = ( show_pts - running_pts ) / 90;
1709                 eDebug("check subtitle: decoder: %lld, show_pts: %lld, diff: %lld ms", running_pts/90, show_pts/90, diff_ms);
1710
1711                 if ( diff_ms < -100 )
1712                 {
1713                         eDebug("subtitle too late... drop");
1714                         m_subtitle_pages.pop_front();
1715                 }
1716                 else if ( diff_ms > 20 )
1717                 {
1718                         eDebug("start timer");
1719                         m_subtitle_sync_timer->start(diff_ms, true);
1720                         break;
1721                 }
1722                 else // immediate show
1723                 {
1724                         if ( m_subtitle_widget )
1725                         {
1726                                 eDebug("show!\n");
1727                                 if ( frontpage.type == SubtitlePage::Pango)
1728                                         m_subtitle_widget->setPage(frontpage.pango_page);
1729                                 m_subtitle_widget->show();
1730                         }
1731                         m_subtitle_pages.pop_front();
1732                 }
1733         }
1734         if (m_subtitle_pages.empty())
1735                 pullSubtitle();
1736 }
1737
1738 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
1739 {
1740         ePyObject entry;
1741         int tuplesize = PyTuple_Size(tuple);
1742         int pid, type;
1743         gint text_pid = 0;
1744
1745         if (!PyTuple_Check(tuple))
1746                 goto error_out;
1747         if (tuplesize < 1)
1748                 goto error_out;
1749         entry = PyTuple_GET_ITEM(tuple, 1);
1750         if (!PyInt_Check(entry))
1751                 goto error_out;
1752         pid = PyInt_AsLong(entry);
1753         entry = PyTuple_GET_ITEM(tuple, 2);
1754         if (!PyInt_Check(entry))
1755                 goto error_out;
1756         type = PyInt_AsLong(entry);
1757
1758         if (m_currentSubtitleStream != pid)
1759         {
1760                 eSingleLocker l(m_subs_to_pull_lock);
1761                 g_object_set (G_OBJECT (m_gst_playbin), "current-text", pid, NULL);
1762                 m_currentSubtitleStream = pid;
1763                 m_subs_to_pull = 0;
1764                 m_prev_decoder_time = -1;
1765                 m_subtitle_pages.clear();
1766         }
1767
1768         m_subtitle_widget = 0;
1769         m_subtitle_widget = new eSubtitleWidget(parent);
1770         m_subtitle_widget->resize(parent->size()); /* full size */
1771
1772         g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
1773
1774         eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
1775
1776         m_event((iPlayableService*)this, evUpdatedInfo);
1777
1778         return 0;
1779
1780 error_out:
1781         eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
1782                 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
1783         return -1;
1784 }
1785
1786 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
1787 {
1788         eDebug("eServiceMP3::disableSubtitles");
1789         m_subtitle_pages.clear();
1790         delete m_subtitle_widget;
1791         m_subtitle_widget = 0;
1792         return 0;
1793 }
1794
1795 PyObject *eServiceMP3::getCachedSubtitle()
1796 {
1797 //      eDebug("eServiceMP3::getCachedSubtitle");
1798         Py_RETURN_NONE;
1799 }
1800
1801 PyObject *eServiceMP3::getSubtitleList()
1802 {
1803 //      eDebug("eServiceMP3::getSubtitleList");
1804         ePyObject l = PyList_New(0);
1805         int stream_idx = 0;
1806         
1807         for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
1808         {
1809                 subtype_t type = IterSubtitleStream->type;
1810                 switch(type)
1811                 {
1812                 case stUnknown:
1813                 case stVOB:
1814                 case stPGS:
1815                         break;
1816                 default:
1817                 {
1818                         ePyObject tuple = PyTuple_New(5);
1819 //                      eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
1820                         PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1821                         PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
1822                         PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
1823                         PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
1824                         PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
1825                         PyList_Append(l, tuple);
1826                         Py_DECREF(tuple);
1827                 }
1828                 }
1829                 stream_idx++;
1830         }
1831         eDebug("eServiceMP3::getSubtitleList finished");
1832         return l;
1833 }
1834
1835 RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
1836 {
1837         ptr = this;
1838         return 0;
1839 }
1840
1841 PyObject *eServiceMP3::getBufferCharge()
1842 {
1843         ePyObject tuple = PyTuple_New(5);
1844         PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
1845         PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
1846         PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
1847         PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
1848         PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
1849         return tuple;
1850 }
1851
1852 int eServiceMP3::setBufferSize(int size)
1853 {
1854         m_buffer_size = size;
1855         g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
1856         return 0;
1857 }
1858
1859 int eServiceMP3::getAC3Delay()
1860 {
1861         return ac3_delay;
1862 }
1863
1864 int eServiceMP3::getPCMDelay()
1865 {
1866         return pcm_delay;
1867 }
1868
1869 void eServiceMP3::setAC3Delay(int delay)
1870 {
1871         ac3_delay = delay;
1872         if (!m_gst_playbin || m_state != stRunning)
1873                 return;
1874         else
1875         {
1876                 GstElement *sink;
1877                 int config_delay_int = delay;
1878                 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1879
1880                 if (sink)
1881                 {
1882                         std::string config_delay;
1883                         if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
1884                                 config_delay_int += atoi(config_delay.c_str());
1885                         gst_object_unref(sink);
1886                 }
1887                 else
1888                 {
1889                         eDebug("dont apply ac3 delay when no video is running!");
1890                         config_delay_int = 0;
1891                 }
1892
1893                 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1894
1895                 if (sink)
1896                 {
1897                         gchar *name = gst_element_get_name(sink);
1898                         if (strstr(name, "dvbaudiosink"))
1899                                 eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
1900                         g_free(name);
1901                         gst_object_unref(sink);
1902                 }
1903         }
1904 }
1905
1906 void eServiceMP3::setPCMDelay(int delay)
1907 {
1908         pcm_delay = delay;
1909         if (!m_gst_playbin || m_state != stRunning)
1910                 return;
1911         else
1912         {
1913                 GstElement *sink;
1914                 int config_delay_int = delay;
1915                 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1916
1917                 if (sink)
1918                 {
1919                         std::string config_delay;
1920                         if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
1921                                 config_delay_int += atoi(config_delay.c_str());
1922                         gst_object_unref(sink);
1923                 }
1924                 else
1925                 {
1926                         eDebug("dont apply pcm delay when no video is running!");
1927                         config_delay_int = 0;
1928                 }
1929
1930                 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1931
1932                 if (sink)
1933                 {
1934                         gchar *name = gst_element_get_name(sink);
1935                         if (strstr(name, "dvbaudiosink"))
1936                                 eTSMPEGDecoder::setHwPCMDelay(config_delay_int);
1937                         else
1938                         {
1939                                 // this is realy untested..and not used yet
1940                                 gint64 offset = config_delay_int;
1941                                 offset *= 1000000; // milli to nano
1942                                 g_object_set (G_OBJECT (m_gst_playbin), "ts-offset", offset, NULL);
1943                         }
1944                         g_free(name);
1945                         gst_object_unref(sink);
1946                 }
1947         }
1948 }
1949