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>
19 #include <gst/pbutils/missing-plugins.h>
22 #define HTTP_TIMEOUT 10
26 eServiceFactoryMP3::eServiceFactoryMP3()
28 ePtr<eServiceCenter> sc;
30 eServiceCenter::getPrivInstance(sc);
33 std::list<std::string> extensions;
34 extensions.push_back("mp2");
35 extensions.push_back("mp3");
36 extensions.push_back("ogg");
37 extensions.push_back("mpg");
38 extensions.push_back("vob");
39 extensions.push_back("wav");
40 extensions.push_back("wave");
41 extensions.push_back("m4v");
42 extensions.push_back("mkv");
43 extensions.push_back("avi");
44 extensions.push_back("divx");
45 extensions.push_back("dat");
46 extensions.push_back("flac");
47 extensions.push_back("mp4");
48 extensions.push_back("mov");
49 extensions.push_back("m4a");
50 extensions.push_back("flv");
51 extensions.push_back("3gp");
52 extensions.push_back("3g2");
53 extensions.push_back("dts");
54 extensions.push_back("wmv");
55 extensions.push_back("asf");
56 extensions.push_back("wma");
57 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
60 m_service_info = new eStaticServiceMP3Info();
63 eServiceFactoryMP3::~eServiceFactoryMP3()
65 ePtr<eServiceCenter> sc;
67 eServiceCenter::getPrivInstance(sc);
69 sc->removeServiceFactory(eServiceFactoryMP3::id);
72 DEFINE_REF(eServiceFactoryMP3)
75 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
78 ptr = new eServiceMP3(ref);
82 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
88 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
94 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
100 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
102 DECLARE_REF(eMP3ServiceOfflineOperations);
103 eServiceReference m_ref;
105 eMP3ServiceOfflineOperations(const eServiceReference &ref);
107 RESULT deleteFromDisk(int simulate);
108 RESULT getListOfFilenames(std::list<std::string> &);
112 DEFINE_REF(eMP3ServiceOfflineOperations);
114 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
118 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
124 std::list<std::string> res;
125 if (getListOfFilenames(res))
128 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
130 eDebug("FATAL !! can't get background file eraser");
132 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
134 eDebug("Removing %s...", i->c_str());
136 eraser->erase(i->c_str());
138 ::unlink(i->c_str());
145 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
148 res.push_back(m_ref.path);
152 RESULT eMP3ServiceOfflineOperations::reindex()
158 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
160 ptr = new eMP3ServiceOfflineOperations(ref);
164 // eStaticServiceMP3Info
167 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
168 // about unopened files.
170 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
171 // should have a database backend where ID3-files etc. are cached.
172 // this would allow listing the mp3 database based on certain filters.
174 DEFINE_REF(eStaticServiceMP3Info)
176 eStaticServiceMP3Info::eStaticServiceMP3Info()
180 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
182 if ( ref.name.length() )
186 size_t last = ref.path.rfind('/');
187 if (last != std::string::npos)
188 name = ref.path.substr(last+1);
195 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
200 int eStaticServiceMP3Info::getInfo(const eServiceReference &ref, int w)
204 case iServiceInformation::sTimeCreate:
207 if(stat(ref.path.c_str(), &s) == 0)
211 return iServiceInformation::resNA;
215 return iServiceInformation::resNA;
220 int eServiceMP3::ac3_delay,
221 eServiceMP3::pcm_delay;
223 eServiceMP3::eServiceMP3(eServiceReference ref)
224 :m_ref(ref), m_pump(eApp, 1)
226 m_seekTimeout = eTimer::create(eApp);
227 m_subtitle_sync_timer = eTimer::create(eApp);
228 m_streamingsrc_timeout = 0;
230 m_currentAudioStream = -1;
231 m_currentSubtitleStream = 0;
232 m_subtitle_widget = 0;
233 m_currentTrickRatio = 0;
235 m_buffer_size = 1*1024*1024;
236 m_prev_decoder_time = -1;
237 m_decoder_time_valid_state = 0;
238 m_errorInfo.missing_codec = "";
242 CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
243 CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
244 CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
245 m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
248 eDebug("eServiceMP3::construct!");
250 const char *filename = m_ref.path.c_str();
251 const char *ext = strrchr(filename, '.');
255 m_sourceinfo.is_video = FALSE;
256 m_sourceinfo.audiotype = atUnknown;
257 if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
259 m_sourceinfo.containertype = ctMPEGPS;
260 m_sourceinfo.is_video = TRUE;
262 else if ( strcasecmp(ext, ".ts") == 0 )
264 m_sourceinfo.containertype = ctMPEGTS;
265 m_sourceinfo.is_video = TRUE;
267 else if ( strcasecmp(ext, ".mkv") == 0 )
269 m_sourceinfo.containertype = ctMKV;
270 m_sourceinfo.is_video = TRUE;
272 else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
274 m_sourceinfo.containertype = ctAVI;
275 m_sourceinfo.is_video = TRUE;
277 else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0 || strcasecmp(ext, ".m4v") == 0)
279 m_sourceinfo.containertype = ctMP4;
280 m_sourceinfo.is_video = TRUE;
282 else if ( strcasecmp(ext, ".m4a") == 0 )
284 m_sourceinfo.containertype = ctMP4;
285 m_sourceinfo.audiotype = atAAC;
287 else if ( strcasecmp(ext, ".mp3") == 0 )
288 m_sourceinfo.audiotype = atMP3;
289 else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
290 m_sourceinfo.containertype = ctCDA;
291 if ( strcasecmp(ext, ".dat") == 0 )
293 m_sourceinfo.containertype = ctVCD;
294 m_sourceinfo.is_video = TRUE;
296 if ( strstr(filename, "://") )
297 m_sourceinfo.is_streaming = TRUE;
301 if ( m_sourceinfo.is_streaming )
303 uri = g_strdup_printf ("%s", filename);
304 m_streamingsrc_timeout = eTimer::create(eApp);;
305 CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
307 std::string config_str;
308 if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
310 if ( config_str == "True" )
311 ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
313 if ( m_useragent.length() == 0 )
314 m_useragent = "Dream Multimedia Dreambox Enigma2 Mediaplayer";
316 else if ( m_sourceinfo.containertype == ctCDA )
318 int i_track = atoi(filename+18);
319 uri = g_strdup_printf ("cdda://%i", i_track);
321 else if ( m_sourceinfo.containertype == ctVCD )
323 int fd = open(filename,O_RDONLY);
325 int ret = read(fd, tmp, 128*1024);
327 if ( ret == -1 ) // this is a "REAL" VCD
328 uri = g_strdup_printf ("vcd://");
330 uri = g_filename_to_uri(filename, NULL, NULL);
334 uri = g_filename_to_uri(filename, NULL, NULL);
336 //eDebug("eServiceMP3::playbin2 uri=%s", uri);
337 eDebug("eServiceMP3::playbin2");
339 m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
341 m_errorInfo.error_message = "failed to create GStreamer pipeline!\n";
343 g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
345 int flags = 0x47; // ( GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT );
346 g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
350 GstElement *subsink = gst_element_factory_make("appsink", "subtitle_sink");
352 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
355 m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
356 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);
357 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
363 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), gstBusSyncHandler, this);
364 char srt_filename[strlen(filename)+1];
365 strncpy(srt_filename,filename,strlen(filename)-3);
366 srt_filename[strlen(filename)-3]='\0';
367 strcat(srt_filename, "srt");
369 if (stat(srt_filename, &buffer) == 0)
371 eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
372 g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
374 if ( m_sourceinfo.is_streaming )
376 g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
380 m_event((iPlayableService*)this, evUser+12);
383 gst_object_unref(GST_OBJECT(m_gst_playbin));
385 eDebug("eServiceMP3::sorry, can't play: %s",m_errorInfo.error_message.c_str());
389 setBufferSize(m_buffer_size);
392 eServiceMP3::~eServiceMP3()
394 // disconnect subtitle callback
395 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
399 g_signal_handler_disconnect (appsink, m_subs_to_pull_handler_id);
400 gst_object_unref(appsink);
403 delete m_subtitle_widget;
405 // disconnect sync handler callback
406 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), NULL, NULL);
408 if (m_state == stRunning)
412 gst_tag_list_free(m_stream_tags);
416 gst_object_unref (GST_OBJECT (m_gst_playbin));
417 eDebug("eServiceMP3::destruct!");
421 DEFINE_REF(eServiceMP3);
423 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
425 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
429 RESULT eServiceMP3::start()
431 ASSERT(m_state == stIdle);
436 eDebug("eServiceMP3::starting pipeline");
437 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
440 m_event(this, evStart);
445 void eServiceMP3::sourceTimeout()
447 eDebug("eServiceMP3::http source timeout! issuing eof...");
448 m_event((iPlayableService*)this, evEOF);
451 RESULT eServiceMP3::stop()
453 ASSERT(m_state != stIdle);
455 if (m_state == stStopped)
458 //GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_gst_playbin),GST_DEBUG_GRAPH_SHOW_ALL,"e2-playbin");
460 //eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
461 eDebug("eServiceMP3::stop service..");
462 gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
468 RESULT eServiceMP3::setTarget(int target)
473 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
479 RESULT eServiceMP3::setSlowMotion(int ratio)
483 eDebug("eServiceMP3::setSlowMotion ratio=%f",1/(float)ratio);
484 return trickSeek(1/(float)ratio);
487 RESULT eServiceMP3::setFastForward(int ratio)
489 eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
490 return trickSeek(ratio);
493 void eServiceMP3::seekTimeoutCB()
496 getPlayPosition(ppos);
498 ppos += 90000*m_currentTrickRatio;
503 m_seekTimeout->stop();
509 m_seekTimeout->stop();
516 RESULT eServiceMP3::pause()
518 if (!m_gst_playbin || m_state != stRunning)
521 gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
526 RESULT eServiceMP3::unpause()
528 if (!m_gst_playbin || m_state != stRunning)
531 gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
536 /* iSeekableService */
537 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
543 RESULT eServiceMP3::getLength(pts_t &pts)
548 if (m_state != stRunning)
551 GstFormat fmt = GST_FORMAT_TIME;
554 if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
556 /* len is in nanoseconds. we have 90 000 pts per second. */
562 RESULT eServiceMP3::seekToImpl(pts_t to)
564 /* convert pts to nanoseconds */
565 gint64 time_nanoseconds = to * 11111LL;
566 if (!gst_element_seek (m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
567 GST_SEEK_TYPE_SET, time_nanoseconds,
568 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
570 eDebug("eServiceMP3::seekTo failed");
577 RESULT eServiceMP3::seekTo(pts_t to)
582 eSingleLocker l(m_subs_to_pull_lock); // this is needed to dont handle incomming subtitles during seek!
583 if (!(ret = seekToImpl(to)))
585 m_subtitle_pages.clear();
586 m_prev_decoder_time = -1;
587 m_decoder_time_valid_state = 0;
596 RESULT eServiceMP3::trickSeek(gdouble ratio)
601 return seekRelative(0, 0);
605 flags = GST_SEEK_FLAG_NONE;
606 flags |= GST_SEEK_FLAG_FLUSH;
607 // flags |= GstSeekFlags (GST_SEEK_FLAG_ACCURATE);
608 flags |= GST_SEEK_FLAG_KEY_UNIT;
609 // flags |= GstSeekFlags (GST_SEEK_FLAG_SEGMENT);
610 // flags |= GstSeekFlags (GST_SEEK_FLAG_SKIP);
612 GstFormat fmt = GST_FORMAT_TIME;
614 gst_element_query_duration(m_gst_playbin, &fmt, &len);
615 gst_element_query_position(m_gst_playbin, &fmt, &pos);
619 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, (GstSeekFlags)flags, GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, len);
621 eDebug("eServiceMP3::trickSeek with rate %lf to %" GST_TIME_FORMAT " ", ratio, GST_TIME_ARGS (pos));
625 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_SKIP|GST_SEEK_FLAG_FLUSH), GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1);
628 if (!gst_element_send_event ( GST_ELEMENT (m_gst_playbin), s_event))
630 eDebug("eServiceMP3::trickSeek failed");
638 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
644 getPlayPosition(ppos);
645 ppos += to * direction;
653 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
655 GstFormat fmt = GST_FORMAT_TIME;
662 if (m_state != stRunning)
665 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
668 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
673 gchar *name = gst_element_get_name(sink);
674 gboolean use_get_decoder_time = strstr(name, "dvbaudiosink") || strstr(name, "dvbvideosink");
677 if (use_get_decoder_time)
678 g_signal_emit_by_name(sink, "get-decoder-time", &pos);
680 gst_object_unref(sink);
682 if (!use_get_decoder_time && !gst_element_query_position(m_gst_playbin, &fmt, &pos)) {
683 eDebug("gst_element_query_position failed in getPlayPosition");
687 /* pos is in nanoseconds. we have 90 000 pts per second. */
689 // eDebug("gst_element_query_position %lld pts (%lld ms)", pts, pos/1000000);
693 RESULT eServiceMP3::setTrickmode(int trick)
695 /* trickmode is not yet supported by our dvbmediasinks. */
699 RESULT eServiceMP3::isCurrentlySeekable()
701 int ret = 3; // seeking and fast/slow winding possible
706 if (m_state != stRunning)
709 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
711 // disable fast winding yet when a dvbvideosink or dvbaudiosink is used
712 // for this we must do some changes on different places.. (gstreamer.. our sinks.. enigma2)
714 ret &= ~2; // only seeking possible
715 gst_object_unref(sink);
718 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
720 ret &= ~2; // only seeking possible
721 gst_object_unref(sink);
728 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
734 RESULT eServiceMP3::getName(std::string &name)
736 std::string title = m_ref.getName();
740 size_t n = name.rfind('/');
741 if (n != std::string::npos)
742 name = name.substr(n + 1);
749 int eServiceMP3::getInfo(int w)
751 const gchar *tag = 0;
755 case sServiceref: return m_ref;
756 case sVideoHeight: return m_height;
757 case sVideoWidth: return m_width;
758 case sFrameRate: return m_framerate;
759 case sProgressive: return m_progressive;
760 case sAspect: return m_aspect;
764 case sTagTitleSortname:
765 case sTagArtistSortname:
766 case sTagAlbumSortname:
771 case sTagExtendedComment:
774 case sTagDescription:
777 case sTagOrganization:
779 case sTagCopyrightURI:
787 case sTagLanguageCode:
789 case sTagChannelMode:
796 case sTagReferenceLevel:
797 case sTagBeatsPerMinute:
799 case sTagPreviewImage:
801 return resIsPyObject;
802 case sTagTrackNumber:
803 tag = GST_TAG_TRACK_NUMBER;
806 tag = GST_TAG_TRACK_COUNT;
808 case sTagAlbumVolumeNumber:
809 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
811 case sTagAlbumVolumeCount:
812 tag = GST_TAG_ALBUM_VOLUME_COUNT;
815 tag = GST_TAG_BITRATE;
817 case sTagNominalBitrate:
818 tag = GST_TAG_NOMINAL_BITRATE;
820 case sTagMinimumBitrate:
821 tag = GST_TAG_MINIMUM_BITRATE;
823 case sTagMaximumBitrate:
824 tag = GST_TAG_MAXIMUM_BITRATE;
827 tag = GST_TAG_SERIAL;
829 case sTagEncoderVersion:
830 tag = GST_TAG_ENCODER_VERSION;
839 if (!m_stream_tags || !tag)
843 if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
849 std::string eServiceMP3::getInfoString(int w)
851 if ( !m_stream_tags && w < sUser && w > 26 )
853 const gchar *tag = 0;
860 tag = GST_TAG_ARTIST;
865 case sTagTitleSortname:
866 tag = GST_TAG_TITLE_SORTNAME;
868 case sTagArtistSortname:
869 tag = GST_TAG_ARTIST_SORTNAME;
871 case sTagAlbumSortname:
872 tag = GST_TAG_ALBUM_SORTNAME;
876 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
879 g_date_strftime (res, sizeof(res), "%Y-%M-%D", date);
880 return (std::string)res;
884 tag = GST_TAG_COMPOSER;
890 tag = GST_TAG_COMMENT;
892 case sTagExtendedComment:
893 tag = GST_TAG_EXTENDED_COMMENT;
896 tag = GST_TAG_LOCATION;
899 tag = GST_TAG_HOMEPAGE;
901 case sTagDescription:
902 tag = GST_TAG_DESCRIPTION;
905 tag = GST_TAG_VERSION;
910 case sTagOrganization:
911 tag = GST_TAG_ORGANIZATION;
914 tag = GST_TAG_COPYRIGHT;
916 case sTagCopyrightURI:
917 tag = GST_TAG_COPYRIGHT_URI;
920 tag = GST_TAG_CONTACT;
923 tag = GST_TAG_LICENSE;
926 tag = GST_TAG_LICENSE_URI;
932 tag = GST_TAG_AUDIO_CODEC;
935 tag = GST_TAG_VIDEO_CODEC;
938 tag = GST_TAG_ENCODER;
940 case sTagLanguageCode:
941 tag = GST_TAG_LANGUAGE_CODE;
944 tag = GST_TAG_KEYWORDS;
946 case sTagChannelMode:
947 tag = "channel-mode";
950 return m_errorInfo.error_message;
957 if (gst_tag_list_get_string(m_stream_tags, tag, &value))
959 std::string res = value;
966 PyObject *eServiceMP3::getInfoObject(int w)
968 const gchar *tag = 0;
969 bool isBuffer = false;
973 tag = GST_TAG_TRACK_GAIN;
976 tag = GST_TAG_TRACK_PEAK;
979 tag = GST_TAG_ALBUM_GAIN;
982 tag = GST_TAG_ALBUM_PEAK;
984 case sTagReferenceLevel:
985 tag = GST_TAG_REFERENCE_LEVEL;
987 case sTagBeatsPerMinute:
988 tag = GST_TAG_BEATS_PER_MINUTE;
994 case sTagPreviewImage:
995 tag = GST_TAG_PREVIEW_IMAGE;
999 tag = GST_TAG_ATTACHMENT;
1008 const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
1012 buffer = gst_value_get_buffer (gv_buffer);
1013 return PyBuffer_FromMemory(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
1018 gdouble value = 0.0;
1019 gst_tag_list_get_double(m_stream_tags, tag, &value);
1020 return PyFloat_FromDouble(value);
1026 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
1032 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
1038 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
1044 RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
1050 int eServiceMP3::getNumberOfTracks()
1052 return m_audioStreams.size();
1055 int eServiceMP3::getCurrentTrack()
1057 if (m_currentAudioStream == -1)
1058 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
1059 return m_currentAudioStream;
1062 RESULT eServiceMP3::selectTrack(unsigned int i)
1065 getPlayPosition(ppos);
1070 int ret = selectAudioStream(i);
1079 int eServiceMP3::selectAudioStream(int i)
1082 g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
1083 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", ¤t_audio, NULL);
1084 if ( current_audio == i )
1086 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
1087 m_currentAudioStream = i;
1093 int eServiceMP3::getCurrentChannel()
1098 RESULT eServiceMP3::selectChannel(int i)
1100 eDebug("eServiceMP3::selectChannel(%i)",i);
1104 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
1106 if (i >= m_audioStreams.size())
1108 info.m_description = m_audioStreams[i].codec;
1109 /* if (m_audioStreams[i].type == atMPEG)
1110 info.m_description = "MPEG";
1111 else if (m_audioStreams[i].type == atMP3)
1112 info.m_description = "MP3";
1113 else if (m_audioStreams[i].type == atAC3)
1114 info.m_description = "AC3";
1115 else if (m_audioStreams[i].type == atAAC)
1116 info.m_description = "AAC";
1117 else if (m_audioStreams[i].type == atDTS)
1118 info.m_description = "DTS";
1119 else if (m_audioStreams[i].type == atPCM)
1120 info.m_description = "PCM";
1121 else if (m_audioStreams[i].type == atOGG)
1122 info.m_description = "OGG";
1123 else if (m_audioStreams[i].type == atFLAC)
1124 info.m_description = "FLAC";
1126 info.m_description = "???";*/
1127 if (info.m_language.empty())
1128 info.m_language = m_audioStreams[i].language_code;
1132 subtype_t getSubtitleType(GstPad* pad, gchar *g_codec=NULL)
1134 subtype_t type = stUnknown;
1135 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1137 if (!caps && !g_codec)
1139 caps = gst_pad_get_allowed_caps(pad);
1144 GstStructure* str = gst_caps_get_structure(caps, 0);
1145 const gchar *g_type = gst_structure_get_name(str);
1146 eDebug("getSubtitleType::subtitle probe caps type=%s", g_type);
1148 if ( !strcmp(g_type, "video/x-dvd-subpicture") )
1150 else if ( !strcmp(g_type, "text/x-pango-markup") )
1152 else if ( !strcmp(g_type, "text/plain") )
1154 else if ( !strcmp(g_type, "subpicture/x-pgs") )
1157 eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec);
1161 eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec);
1162 if ( !strcmp(g_codec, "VOB") )
1164 else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") )
1166 else if ( !strcmp(g_codec, "ASS") )
1168 else if ( !strcmp(g_codec, "UTF-8 plain text") )
1171 eDebug("getSubtitleType::unsupported subtitle codec %s", g_codec);
1174 eDebug("getSubtitleType::unidentifiable subtitle stream!");
1179 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
1185 source = GST_MESSAGE_SRC(msg);
1186 if (!GST_IS_OBJECT(source))
1188 sourceName = gst_object_get_name(source);
1191 if (gst_message_get_structure(msg))
1192 string = gst_structure_to_string(gst_message_get_structure(msg));
1194 string = g_strdup(GST_MESSAGE_TYPE_NAME(msg));
1195 eDebug("eTsRemoteSource::gst_message from %s: %s", sourceName, string);
1198 switch (GST_MESSAGE_TYPE (msg))
1200 case GST_MESSAGE_EOS:
1201 m_event((iPlayableService*)this, evEOF);
1203 case GST_MESSAGE_STATE_CHANGED:
1205 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1208 if(!strncmp(sourceName, "hls", 3))
1210 //eDebug("HLS Protocol detected : source [%s]", sourceName);
1211 m_is_hls_stream = 1;
1216 GstState old_state, new_state;
1217 gst_message_parse_state_changed(msg, &old_state, &new_state, NULL);
1219 if(old_state == new_state)
1222 eDebug("eServiceMP3::state transition %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
1224 GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state);
1228 case GST_STATE_CHANGE_NULL_TO_READY:
1231 case GST_STATE_CHANGE_READY_TO_PAUSED:
1233 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1236 g_object_set (G_OBJECT (appsink), "max-buffers", 2, NULL);
1237 g_object_set (G_OBJECT (appsink), "sync", FALSE, NULL);
1238 g_object_set (G_OBJECT (appsink), "emit-signals", TRUE, NULL);
1239 eDebug("eServiceMP3::appsink properties set!");
1240 gst_object_unref(appsink);
1242 setAC3Delay(ac3_delay);
1243 setPCMDelay(pcm_delay);
1245 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1247 if ( m_sourceinfo.is_streaming && m_streamingsrc_timeout )
1248 m_streamingsrc_timeout->stop();
1250 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1253 case GST_STATE_CHANGE_PAUSED_TO_READY:
1256 case GST_STATE_CHANGE_READY_TO_NULL:
1262 case GST_MESSAGE_ERROR:
1266 gst_message_parse_error (msg, &err, &debug);
1268 eWarning("Gstreamer error: %s (domain:%i, code:%i) from %s", err->message, err->domain, err->code, sourceName );
1269 if ( err->domain == GST_STREAM_ERROR )
1271 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1273 if ( g_strrstr(sourceName, "videosink") )
1274 m_event((iPlayableService*)this, evUser+11);
1275 else if ( g_strrstr(sourceName, "audiosink") )
1276 m_event((iPlayableService*)this, evUser+10);
1279 else //if( err->domain == 1232 )
1281 if ( err->code == 5 )
1282 m_event((iPlayableService*)this, evUser+20);
1287 case GST_MESSAGE_INFO:
1292 gst_message_parse_info (msg, &inf, &debug);
1294 if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1296 if ( g_strrstr(sourceName, "videosink") )
1297 m_event((iPlayableService*)this, evUser+14);
1302 case GST_MESSAGE_TAG:
1304 GstTagList *tags, *result;
1305 gst_message_parse_tag(msg, &tags);
1307 result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE);
1311 gst_tag_list_free(m_stream_tags);
1312 m_stream_tags = result;
1315 const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1318 GstBuffer *buf_image;
1319 buf_image = gst_value_get_buffer (gv_image);
1320 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1321 int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image));
1323 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1324 m_event((iPlayableService*)this, evUser+13);
1326 gst_tag_list_free(tags);
1327 m_event((iPlayableService*)this, evUpdatedInfo);
1330 case GST_MESSAGE_ASYNC_DONE:
1332 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1336 gint i, active_idx, n_video = 0, n_audio = 0, n_text = 0;
1338 g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1339 g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1340 g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1342 eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1344 if ( n_video + n_audio <= 0 )
1349 m_audioStreams.clear();
1350 m_subtitleStreams.clear();
1352 for (i = 0; i < n_audio; i++)
1355 gchar *g_codec, *g_lang;
1357 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1358 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1361 GstStructure* str = gst_caps_get_structure(caps, 0);
1362 const gchar *g_type = gst_structure_get_name(str);
1363 audio.type = gstCheckAudioPad(str);
1364 g_codec = g_strdup(g_type);
1365 g_lang = g_strdup_printf ("und");
1366 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1367 if ( tags && gst_is_tag_list(tags) )
1369 gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1370 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1371 gst_tag_list_free(tags);
1373 audio.language_code = std::string(g_lang);
1374 audio.codec = std::string(g_codec);
1375 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1376 m_audioStreams.push_back(audio);
1379 gst_caps_unref(caps);
1382 for (i = 0; i < n_text; i++)
1384 gchar *g_codec = NULL, *g_lang = NULL;
1385 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1386 subtitleStream subs;
1389 g_lang = g_strdup_printf ("und");
1390 if ( tags && gst_is_tag_list(tags) )
1392 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1393 gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec);
1394 gst_tag_list_free(tags);
1397 subs.language_code = std::string(g_lang);
1398 eDebug("eServiceMP3::subtitle stream=%i language=%s codec=%s", i, g_lang, g_codec);
1401 g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1403 g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
1404 subs.type = getSubtitleType(pad, g_codec);
1406 m_subtitleStreams.push_back(subs);
1409 m_event((iPlayableService*)this, evUpdatedEventInfo);
1411 if ( m_errorInfo.missing_codec != "" )
1413 if ( m_errorInfo.missing_codec.find("video/") == 0 || ( m_errorInfo.missing_codec.find("audio/") == 0 && getNumberOfTracks() == 0 ) )
1414 m_event((iPlayableService*)this, evUser+12);
1418 case GST_MESSAGE_ELEMENT:
1420 if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1422 if ( gst_is_missing_plugin_message(msg) )
1424 GstCaps *caps= NULL;
1425 gboolean ret = gst_structure_get (msgstruct, "detail", GST_TYPE_CAPS, &caps, NULL);
1428 std::string codec = (const char*) gst_caps_to_string(caps);
1429 gchar *description = gst_missing_plugin_message_get_description(msg);
1432 eDebug("eServiceMP3::m_errorInfo.missing_codec = %s", codec.c_str());
1433 m_errorInfo.error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1434 m_errorInfo.missing_codec = codec.substr(0,(codec.find_first_of(',')));
1435 g_free(description);
1437 gst_caps_unref(caps);
1442 const gchar *eventname = gst_structure_get_name(msgstruct);
1445 if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1447 gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1448 gst_structure_get_int (msgstruct, "width", &m_width);
1449 gst_structure_get_int (msgstruct, "height", &m_height);
1450 if (strstr(eventname, "Changed"))
1451 m_event((iPlayableService*)this, evVideoSizeChanged);
1453 else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1455 gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1456 if (strstr(eventname, "Changed"))
1457 m_event((iPlayableService*)this, evVideoFramerateChanged);
1459 else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1461 gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1462 if (strstr(eventname, "Changed"))
1463 m_event((iPlayableService*)this, evVideoProgressiveChanged);
1470 case GST_MESSAGE_BUFFERING:
1472 GstBufferingMode mode;
1473 gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
1474 gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
1475 m_event((iPlayableService*)this, evBuffering);
1478 case GST_MESSAGE_STREAM_STATUS:
1480 GstStreamStatusType type;
1482 gst_message_parse_stream_status (msg, &type, &owner);
1483 if ( type == GST_STREAM_STATUS_TYPE_CREATE && m_sourceinfo.is_streaming )
1485 if ( GST_IS_PAD(source) )
1486 owner = gst_pad_get_parent_element(GST_PAD(source));
1487 else if ( GST_IS_ELEMENT(source) )
1488 owner = GST_ELEMENT(source);
1493 GstElementFactory *factory = gst_element_get_factory(GST_ELEMENT(owner));
1494 const gchar *name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
1495 if (!strcmp(name, "souphttpsrc"))
1497 m_streamingsrc_timeout->start(HTTP_TIMEOUT*1000, true);
1498 g_object_set (G_OBJECT (owner), "timeout", HTTP_TIMEOUT, NULL);
1499 eDebug("eServiceMP3::GST_STREAM_STATUS_TYPE_CREATE -> setting timeout on %s to %is", name, HTTP_TIMEOUT);
1502 else if (m_is_hls_stream && !strncmp(name, "queue", 5))
1504 m_streamingsrc_timeout->stop();
1505 m_is_hls_stream = 0;
1506 //eDebug("Stoped response timeout!! : HLS");
1509 if ( GST_IS_PAD(source) )
1510 gst_object_unref(owner);
1517 g_free (sourceName);
1520 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1522 eServiceMP3 *_this = (eServiceMP3*)user_data;
1523 _this->m_pump.send(Message(1));
1525 return GST_BUS_PASS;
1528 void eServiceMP3::gstHTTPSourceSetAgent(GObject *object, GParamSpec *unused, gpointer user_data)
1530 eServiceMP3 *_this = (eServiceMP3*)user_data;
1532 g_object_get(_this->m_gst_playbin, "source", &source, NULL);
1533 g_object_set (G_OBJECT (source), "user-agent", _this->m_useragent.c_str(), NULL);
1534 gst_object_unref(source);
1537 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1542 if ( gst_structure_has_name (structure, "audio/mpeg"))
1544 gint mpegversion, layer = -1;
1545 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1548 switch (mpegversion) {
1551 gst_structure_get_int (structure, "layer", &layer);
1567 else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1569 else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1571 else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1577 void eServiceMP3::gstPoll(const Message &msg)
1581 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
1582 GstMessage *message;
1583 while ((message = gst_bus_pop(bus)))
1585 gstBusCall(bus, message);
1586 gst_message_unref (message);
1589 else if (msg.type == 2)
1591 else if (msg.type == 3)
1592 gstTextpadHasCAPS_synced(msg.d.pad);
1594 eDebug("gstPoll unhandled Message %d\n", msg.type);
1597 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1599 void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
1601 eServiceMP3 *_this = (eServiceMP3*)user_data;
1602 eSingleLocker l(_this->m_subs_to_pull_lock);
1603 ++_this->m_subs_to_pull;
1604 _this->m_pump.send(Message(2));
1607 void eServiceMP3::gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data)
1609 eServiceMP3 *_this = (eServiceMP3*)user_data;
1611 gst_object_ref (pad);
1613 _this->m_pump.send(Message(3, pad));
1616 // after messagepump
1617 void eServiceMP3::gstTextpadHasCAPS_synced(GstPad *pad)
1621 g_object_get (G_OBJECT (pad), "caps", &caps, NULL);
1623 eDebug("gstTextpadHasCAPS:: signal::caps = %s", gst_caps_to_string(caps));
1627 subtitleStream subs;
1629 // eDebug("gstGhostpadHasCAPS_synced %p %d", pad, m_subtitleStreams.size());
1631 if (!m_subtitleStreams.empty())
1632 subs = m_subtitleStreams[m_currentSubtitleStream];
1634 subs.type = stUnknown;
1638 if ( subs.type == stUnknown )
1641 // eDebug("gstGhostpadHasCAPS::m_subtitleStreams[%i].type == stUnknown...", m_currentSubtitleStream);
1644 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", m_currentSubtitleStream, &tags);
1646 g_lang = g_strdup_printf ("und");
1647 if ( tags && gst_is_tag_list(tags) )
1648 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1650 subs.language_code = std::string(g_lang);
1651 subs.type = getSubtitleType(pad);
1653 if (!m_subtitleStreams.empty())
1654 m_subtitleStreams[m_currentSubtitleStream] = subs;
1656 m_subtitleStreams.push_back(subs);
1661 // 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));
1663 gst_caps_unref (caps);
1666 gst_object_unref (pad);
1669 void eServiceMP3::pullSubtitle()
1672 g_object_get (G_OBJECT (m_gst_playbin), "text-sink", &sink, NULL);
1676 while (m_subs_to_pull && m_subtitle_pages.size() < 2)
1680 eSingleLocker l(m_subs_to_pull_lock);
1682 g_signal_emit_by_name (sink, "pull-buffer", &buffer);
1686 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1687 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1688 size_t len = GST_BUFFER_SIZE(buffer);
1689 eDebug("pullSubtitle m_subtitleStreams[m_currentSubtitleStream].type=%i",m_subtitleStreams[m_currentSubtitleStream].type);
1691 if ( m_subtitleStreams[m_currentSubtitleStream].type )
1693 if ( m_subtitleStreams[m_currentSubtitleStream].type < stVOB )
1695 unsigned char line[len+1];
1697 memcpy(line, GST_BUFFER_DATA(buffer), len);
1699 eDebug("got new text subtitle @ buf_pos = %lld ns (in pts=%lld): '%s' ", buf_pos, buf_pos/11111, line);
1700 gRGB rgbcol(0xD0,0xD0,0xD0);
1701 page.type = SubtitlePage::Pango;
1702 page.pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
1703 page.pango_page.m_show_pts = buf_pos / 11111L;
1704 page.pango_page.m_timeout = duration_ns / 1000000;
1705 m_subtitle_pages.push_back(page);
1706 if (m_subtitle_pages.size()==1)
1711 eDebug("unsupported subpicture... ignoring");
1714 gst_buffer_unref(buffer);
1717 gst_object_unref(sink);
1720 eDebug("no subtitle sink!");
1723 void eServiceMP3::pushSubtitles()
1725 while ( !m_subtitle_pages.empty() )
1727 SubtitlePage &frontpage = m_subtitle_pages.front();
1730 gint64 show_pts = 0;
1732 getPlayPosition(running_pts);
1734 if (m_decoder_time_valid_state < 4) {
1735 ++m_decoder_time_valid_state;
1736 if (m_prev_decoder_time == running_pts)
1737 m_decoder_time_valid_state = 0;
1738 if (m_decoder_time_valid_state < 4) {
1739 // if (m_decoder_time_valid_state)
1740 // eDebug("%d: decoder time not valid! prev %lld, now %lld\n", m_decoder_time_valid_state, m_prev_decoder_time/90, running_pts/90);
1742 // eDebug("%d: decoder time not valid! now %lld\n", m_decoder_time_valid_state, running_pts/90);
1743 m_subtitle_sync_timer->start(25, true);
1744 m_prev_decoder_time = running_pts;
1749 if (frontpage.type == SubtitlePage::Pango)
1750 show_pts = frontpage.pango_page.m_show_pts;
1752 diff_ms = ( show_pts - running_pts ) / 90;
1753 eDebug("check subtitle: decoder: %lld, show_pts: %lld, diff: %lld ms", running_pts/90, show_pts/90, diff_ms);
1755 if ( diff_ms < -100 )
1757 eDebug("subtitle too late... drop");
1758 m_subtitle_pages.pop_front();
1760 else if ( diff_ms > 20 )
1762 eDebug("start timer");
1763 m_subtitle_sync_timer->start(diff_ms, true);
1766 else // immediate show
1768 if ( m_subtitle_widget )
1771 if ( frontpage.type == SubtitlePage::Pango)
1772 m_subtitle_widget->setPage(frontpage.pango_page);
1773 m_subtitle_widget->show();
1775 m_subtitle_pages.pop_front();
1778 if (m_subtitle_pages.empty())
1783 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
1785 eDebug ("eServiceMP3::enableSubtitles m_currentSubtitleStream=%i this=%p",m_currentSubtitleStream, this);
1787 int tuplesize = PyTuple_Size(tuple);
1790 eSingleLocker l(m_subs_to_pull_lock);
1793 // g_signal_emit_by_name (m_gst_playbin, "get-text-pad", m_currentSubtitleStream, &pad);
1794 // gst_element_get_static_pad(m_gst_subtitlebin, "sink");
1795 // gulong subprobe_handler_id = gst_pad_add_buffer_probe (pad, G_CALLBACK (gstCBsubtitleDrop), NULL);
1797 if (!PyTuple_Check(tuple))
1801 entry = PyTuple_GET_ITEM(tuple, 1);
1802 if (!PyInt_Check(entry))
1804 pid = PyInt_AsLong(entry);
1805 entry = PyTuple_GET_ITEM(tuple, 2);
1806 if (!PyInt_Check(entry))
1808 type = PyInt_AsLong(entry);
1810 if (m_currentSubtitleStream != pid)
1812 g_object_set (G_OBJECT (m_gst_playbin), "current-text", pid, NULL);
1813 eDebug ("eServiceMP3::enableSubtitles g_object_set current-text = %i", pid);
1814 m_currentSubtitleStream = pid;
1816 m_prev_decoder_time = -1;
1817 m_subtitle_pages.clear();
1820 m_subtitle_widget = 0;
1821 m_subtitle_widget = new eSubtitleWidget(parent);
1822 m_subtitle_widget->resize(parent->size()); /* full size */
1824 g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
1826 eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
1827 // gst_pad_remove_buffer_probe (pad, subprobe_handler_id);
1829 m_event((iPlayableService*)this, evUpdatedInfo);
1834 eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
1835 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
1839 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
1841 eDebug("eServiceMP3::disableSubtitles");
1842 m_subtitle_pages.clear();
1843 delete m_subtitle_widget;
1844 m_subtitle_widget = 0;
1848 PyObject *eServiceMP3::getCachedSubtitle()
1850 // eDebug("eServiceMP3::getCachedSubtitle");
1854 PyObject *eServiceMP3::getSubtitleList()
1856 // eDebug("eServiceMP3::getSubtitleList");
1857 ePyObject l = PyList_New(0);
1860 for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
1862 subtype_t type = IterSubtitleStream->type;
1871 ePyObject tuple = PyTuple_New(5);
1872 // eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
1873 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1874 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
1875 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
1876 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
1877 PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
1878 PyList_Append(l, tuple);
1884 eDebug("eServiceMP3::getSubtitleList finished");
1888 RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
1894 PyObject *eServiceMP3::getBufferCharge()
1896 ePyObject tuple = PyTuple_New(5);
1897 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
1898 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
1899 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
1900 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
1901 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
1905 int eServiceMP3::setBufferSize(int size)
1907 m_buffer_size = size;
1908 g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
1912 int eServiceMP3::getAC3Delay()
1917 int eServiceMP3::getPCMDelay()
1922 void eServiceMP3::setAC3Delay(int delay)
1925 if (!m_gst_playbin || m_state != stRunning)
1930 int config_delay_int = delay;
1931 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1935 std::string config_delay;
1936 if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
1937 config_delay_int += atoi(config_delay.c_str());
1938 gst_object_unref(sink);
1942 eDebug("dont apply ac3 delay when no video is running!");
1943 config_delay_int = 0;
1946 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1950 gchar *name = gst_element_get_name(sink);
1951 if (strstr(name, "dvbaudiosink"))
1952 eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
1954 gst_object_unref(sink);
1959 void eServiceMP3::setPCMDelay(int delay)
1962 if (!m_gst_playbin || m_state != stRunning)
1967 int config_delay_int = delay;
1968 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1972 std::string config_delay;
1973 if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
1974 config_delay_int += atoi(config_delay.c_str());
1975 gst_object_unref(sink);
1979 eDebug("dont apply pcm delay when no video is running!");
1980 config_delay_int = 0;
1983 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1987 gchar *name = gst_element_get_name(sink);
1988 if (strstr(name, "dvbaudiosink"))
1989 eTSMPEGDecoder::setHwPCMDelay(config_delay_int);
1992 // this is realy untested..and not used yet
1993 gint64 offset = config_delay_int;
1994 offset *= 1000000; // milli to nano
1995 g_object_set (G_OBJECT (m_gst_playbin), "ts-offset", offset, NULL);
1998 gst_object_unref(sink);