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 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
53 m_service_info = new eStaticServiceMP3Info();
56 eServiceFactoryMP3::~eServiceFactoryMP3()
58 ePtr<eServiceCenter> sc;
60 eServiceCenter::getPrivInstance(sc);
62 sc->removeServiceFactory(eServiceFactoryMP3::id);
65 DEFINE_REF(eServiceFactoryMP3)
68 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
71 ptr = new eServiceMP3(ref);
75 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
81 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
87 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
93 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
95 DECLARE_REF(eMP3ServiceOfflineOperations);
96 eServiceReference m_ref;
98 eMP3ServiceOfflineOperations(const eServiceReference &ref);
100 RESULT deleteFromDisk(int simulate);
101 RESULT getListOfFilenames(std::list<std::string> &);
105 DEFINE_REF(eMP3ServiceOfflineOperations);
107 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
111 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
117 std::list<std::string> res;
118 if (getListOfFilenames(res))
121 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
123 eDebug("FATAL !! can't get background file eraser");
125 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
127 eDebug("Removing %s...", i->c_str());
129 eraser->erase(i->c_str());
131 ::unlink(i->c_str());
138 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
141 res.push_back(m_ref.path);
145 RESULT eMP3ServiceOfflineOperations::reindex()
151 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
153 ptr = new eMP3ServiceOfflineOperations(ref);
157 // eStaticServiceMP3Info
160 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
161 // about unopened files.
163 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
164 // should have a database backend where ID3-files etc. are cached.
165 // this would allow listing the mp3 database based on certain filters.
167 DEFINE_REF(eStaticServiceMP3Info)
169 eStaticServiceMP3Info::eStaticServiceMP3Info()
173 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
175 if ( ref.name.length() )
179 size_t last = ref.path.rfind('/');
180 if (last != std::string::npos)
181 name = ref.path.substr(last+1);
188 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
193 int eStaticServiceMP3Info::getInfo(const eServiceReference &ref, int w)
197 case iServiceInformation::sTimeCreate:
200 if(stat(ref.path.c_str(), &s) == 0)
204 return iServiceInformation::resNA;
208 return iServiceInformation::resNA;
213 int eServiceMP3::ac3_delay,
214 eServiceMP3::pcm_delay;
216 eServiceMP3::eServiceMP3(eServiceReference ref)
217 :m_ref(ref), m_pump(eApp, 1)
219 m_seekTimeout = eTimer::create(eApp);
220 m_subtitle_sync_timer = eTimer::create(eApp);
221 m_streamingsrc_timeout = 0;
223 m_currentAudioStream = -1;
224 m_currentSubtitleStream = 0;
225 m_subtitle_widget = 0;
226 m_currentTrickRatio = 0;
228 m_buffer_size = 1*1024*1024;
229 m_prev_decoder_time = -1;
230 m_decoder_time_valid_state = 0;
231 m_errorInfo.missing_codec = "";
235 CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
236 CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
237 CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
238 m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
241 eDebug("eServiceMP3::construct!");
243 const char *filename = m_ref.path.c_str();
244 const char *ext = strrchr(filename, '.');
248 m_sourceinfo.is_video = FALSE;
249 m_sourceinfo.audiotype = atUnknown;
250 if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
252 m_sourceinfo.containertype = ctMPEGPS;
253 m_sourceinfo.is_video = TRUE;
255 else if ( strcasecmp(ext, ".ts") == 0 )
257 m_sourceinfo.containertype = ctMPEGTS;
258 m_sourceinfo.is_video = TRUE;
260 else if ( strcasecmp(ext, ".mkv") == 0 )
262 m_sourceinfo.containertype = ctMKV;
263 m_sourceinfo.is_video = TRUE;
265 else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
267 m_sourceinfo.containertype = ctAVI;
268 m_sourceinfo.is_video = TRUE;
270 else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0 || strcasecmp(ext, ".m4v") == 0)
272 m_sourceinfo.containertype = ctMP4;
273 m_sourceinfo.is_video = TRUE;
275 else if ( strcasecmp(ext, ".m4a") == 0 )
277 m_sourceinfo.containertype = ctMP4;
278 m_sourceinfo.audiotype = atAAC;
280 else if ( strcasecmp(ext, ".mp3") == 0 )
281 m_sourceinfo.audiotype = atMP3;
282 else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
283 m_sourceinfo.containertype = ctCDA;
284 if ( strcasecmp(ext, ".dat") == 0 )
286 m_sourceinfo.containertype = ctVCD;
287 m_sourceinfo.is_video = TRUE;
289 if ( strstr(filename, "://") )
290 m_sourceinfo.is_streaming = TRUE;
294 if ( m_sourceinfo.is_streaming )
296 uri = g_strdup_printf ("%s", filename);
297 m_streamingsrc_timeout = eTimer::create(eApp);;
298 CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
300 std::string config_str;
301 if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
303 if ( config_str == "True" )
304 ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
306 if ( m_useragent.length() == 0 )
307 m_useragent = "Dream Multimedia Dreambox Enigma2 Mediaplayer";
309 else if ( m_sourceinfo.containertype == ctCDA )
311 int i_track = atoi(filename+18);
312 uri = g_strdup_printf ("cdda://%i", i_track);
314 else if ( m_sourceinfo.containertype == ctVCD )
316 int fd = open(filename,O_RDONLY);
318 int ret = read(fd, tmp, 128*1024);
320 if ( ret == -1 ) // this is a "REAL" VCD
321 uri = g_strdup_printf ("vcd://");
323 uri = g_filename_to_uri(filename, NULL, NULL);
327 uri = g_filename_to_uri(filename, NULL, NULL);
329 eDebug("eServiceMP3::playbin2 uri=%s", uri);
331 m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
333 m_errorInfo.error_message = "failed to create GStreamer pipeline!\n";
335 g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
337 int flags = 0x47; // ( GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT );
338 g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
342 GstElement *subsink = gst_element_factory_make("appsink", "subtitle_sink");
344 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
347 m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
348 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);
349 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
355 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), gstBusSyncHandler, this);
356 char srt_filename[strlen(filename)+1];
357 strncpy(srt_filename,filename,strlen(filename)-3);
358 srt_filename[strlen(filename)-3]='\0';
359 strcat(srt_filename, "srt");
361 if (stat(srt_filename, &buffer) == 0)
363 eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
364 g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
366 if ( m_sourceinfo.is_streaming )
368 g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
372 m_event((iPlayableService*)this, evUser+12);
375 gst_object_unref(GST_OBJECT(m_gst_playbin));
377 eDebug("eServiceMP3::sorry, can't play: %s",m_errorInfo.error_message.c_str());
381 setBufferSize(m_buffer_size);
384 eServiceMP3::~eServiceMP3()
386 // disconnect subtitle callback
387 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
391 g_signal_handler_disconnect (appsink, m_subs_to_pull_handler_id);
392 gst_object_unref(appsink);
395 delete m_subtitle_widget;
397 // disconnect sync handler callback
398 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), NULL, NULL);
400 if (m_state == stRunning)
404 gst_tag_list_free(m_stream_tags);
408 gst_object_unref (GST_OBJECT (m_gst_playbin));
409 eDebug("eServiceMP3::destruct!");
413 DEFINE_REF(eServiceMP3);
415 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
417 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
421 RESULT eServiceMP3::start()
423 ASSERT(m_state == stIdle);
428 eDebug("eServiceMP3::starting pipeline");
429 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
432 m_event(this, evStart);
437 void eServiceMP3::sourceTimeout()
439 eDebug("eServiceMP3::http source timeout! issuing eof...");
440 m_event((iPlayableService*)this, evEOF);
443 RESULT eServiceMP3::stop()
445 ASSERT(m_state != stIdle);
447 if (m_state == stStopped)
450 //GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_gst_playbin),GST_DEBUG_GRAPH_SHOW_ALL,"e2-playbin");
452 eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
453 gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
459 RESULT eServiceMP3::setTarget(int target)
464 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
470 RESULT eServiceMP3::setSlowMotion(int ratio)
474 eDebug("eServiceMP3::setSlowMotion ratio=%f",1/(float)ratio);
475 return trickSeek(1/(float)ratio);
478 RESULT eServiceMP3::setFastForward(int ratio)
480 eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
481 return trickSeek(ratio);
484 void eServiceMP3::seekTimeoutCB()
487 getPlayPosition(ppos);
489 ppos += 90000*m_currentTrickRatio;
494 m_seekTimeout->stop();
500 m_seekTimeout->stop();
507 RESULT eServiceMP3::pause()
509 if (!m_gst_playbin || m_state != stRunning)
512 gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
517 RESULT eServiceMP3::unpause()
519 if (!m_gst_playbin || m_state != stRunning)
522 gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
527 /* iSeekableService */
528 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
534 RESULT eServiceMP3::getLength(pts_t &pts)
539 if (m_state != stRunning)
542 GstFormat fmt = GST_FORMAT_TIME;
545 if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
547 /* len is in nanoseconds. we have 90 000 pts per second. */
553 RESULT eServiceMP3::seekToImpl(pts_t to)
555 /* convert pts to nanoseconds */
556 gint64 time_nanoseconds = to * 11111LL;
557 if (!gst_element_seek (m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
558 GST_SEEK_TYPE_SET, time_nanoseconds,
559 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
561 eDebug("eServiceMP3::seekTo failed");
568 RESULT eServiceMP3::seekTo(pts_t to)
573 eSingleLocker l(m_subs_to_pull_lock); // this is needed to dont handle incomming subtitles during seek!
574 if (!(ret = seekToImpl(to)))
576 m_subtitle_pages.clear();
577 m_prev_decoder_time = -1;
578 m_decoder_time_valid_state = 0;
587 RESULT eServiceMP3::trickSeek(gdouble ratio)
592 return seekRelative(0, 0);
596 flags = GST_SEEK_FLAG_NONE;
597 flags |= GST_SEEK_FLAG_FLUSH;
598 // flags |= GstSeekFlags (GST_SEEK_FLAG_ACCURATE);
599 flags |= GST_SEEK_FLAG_KEY_UNIT;
600 // flags |= GstSeekFlags (GST_SEEK_FLAG_SEGMENT);
601 // flags |= GstSeekFlags (GST_SEEK_FLAG_SKIP);
603 GstFormat fmt = GST_FORMAT_TIME;
605 gst_element_query_duration(m_gst_playbin, &fmt, &len);
606 gst_element_query_position(m_gst_playbin, &fmt, &pos);
610 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, (GstSeekFlags)flags, GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, len);
612 eDebug("eServiceMP3::trickSeek with rate %lf to %" GST_TIME_FORMAT " ", ratio, GST_TIME_ARGS (pos));
616 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);
619 if (!gst_element_send_event ( GST_ELEMENT (m_gst_playbin), s_event))
621 eDebug("eServiceMP3::trickSeek failed");
629 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
635 getPlayPosition(ppos);
636 ppos += to * direction;
644 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
646 GstFormat fmt = GST_FORMAT_TIME;
653 if (m_state != stRunning)
656 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
659 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
664 gchar *name = gst_element_get_name(sink);
665 gboolean use_get_decoder_time = strstr(name, "dvbaudiosink") || strstr(name, "dvbvideosink");
668 if (use_get_decoder_time)
669 g_signal_emit_by_name(sink, "get-decoder-time", &pos);
671 gst_object_unref(sink);
673 if (!use_get_decoder_time && !gst_element_query_position(m_gst_playbin, &fmt, &pos)) {
674 eDebug("gst_element_query_position failed in getPlayPosition");
678 /* pos is in nanoseconds. we have 90 000 pts per second. */
680 // eDebug("gst_element_query_position %lld pts (%lld ms)", pts, pos/1000000);
684 RESULT eServiceMP3::setTrickmode(int trick)
686 /* trickmode is not yet supported by our dvbmediasinks. */
690 RESULT eServiceMP3::isCurrentlySeekable()
692 int ret = 3; // seeking and fast/slow winding possible
697 if (m_state != stRunning)
700 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
702 // disable fast winding yet when a dvbvideosink or dvbaudiosink is used
703 // for this we must do some changes on different places.. (gstreamer.. our sinks.. enigma2)
705 ret &= ~2; // only seeking possible
706 gst_object_unref(sink);
709 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
711 ret &= ~2; // only seeking possible
712 gst_object_unref(sink);
719 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
725 RESULT eServiceMP3::getName(std::string &name)
727 std::string title = m_ref.getName();
731 size_t n = name.rfind('/');
732 if (n != std::string::npos)
733 name = name.substr(n + 1);
740 int eServiceMP3::getInfo(int w)
742 const gchar *tag = 0;
746 case sServiceref: return m_ref;
747 case sVideoHeight: return m_height;
748 case sVideoWidth: return m_width;
749 case sFrameRate: return m_framerate;
750 case sProgressive: return m_progressive;
751 case sAspect: return m_aspect;
755 case sTagTitleSortname:
756 case sTagArtistSortname:
757 case sTagAlbumSortname:
762 case sTagExtendedComment:
765 case sTagDescription:
768 case sTagOrganization:
770 case sTagCopyrightURI:
778 case sTagLanguageCode:
780 case sTagChannelMode:
787 case sTagReferenceLevel:
788 case sTagBeatsPerMinute:
790 case sTagPreviewImage:
792 return resIsPyObject;
793 case sTagTrackNumber:
794 tag = GST_TAG_TRACK_NUMBER;
797 tag = GST_TAG_TRACK_COUNT;
799 case sTagAlbumVolumeNumber:
800 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
802 case sTagAlbumVolumeCount:
803 tag = GST_TAG_ALBUM_VOLUME_COUNT;
806 tag = GST_TAG_BITRATE;
808 case sTagNominalBitrate:
809 tag = GST_TAG_NOMINAL_BITRATE;
811 case sTagMinimumBitrate:
812 tag = GST_TAG_MINIMUM_BITRATE;
814 case sTagMaximumBitrate:
815 tag = GST_TAG_MAXIMUM_BITRATE;
818 tag = GST_TAG_SERIAL;
820 case sTagEncoderVersion:
821 tag = GST_TAG_ENCODER_VERSION;
830 if (!m_stream_tags || !tag)
834 if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
840 std::string eServiceMP3::getInfoString(int w)
842 if ( !m_stream_tags && w < sUser && w > 26 )
844 const gchar *tag = 0;
851 tag = GST_TAG_ARTIST;
856 case sTagTitleSortname:
857 tag = GST_TAG_TITLE_SORTNAME;
859 case sTagArtistSortname:
860 tag = GST_TAG_ARTIST_SORTNAME;
862 case sTagAlbumSortname:
863 tag = GST_TAG_ALBUM_SORTNAME;
867 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
870 g_date_strftime (res, sizeof(res), "%Y-%M-%D", date);
871 return (std::string)res;
875 tag = GST_TAG_COMPOSER;
881 tag = GST_TAG_COMMENT;
883 case sTagExtendedComment:
884 tag = GST_TAG_EXTENDED_COMMENT;
887 tag = GST_TAG_LOCATION;
890 tag = GST_TAG_HOMEPAGE;
892 case sTagDescription:
893 tag = GST_TAG_DESCRIPTION;
896 tag = GST_TAG_VERSION;
901 case sTagOrganization:
902 tag = GST_TAG_ORGANIZATION;
905 tag = GST_TAG_COPYRIGHT;
907 case sTagCopyrightURI:
908 tag = GST_TAG_COPYRIGHT_URI;
911 tag = GST_TAG_CONTACT;
914 tag = GST_TAG_LICENSE;
917 tag = GST_TAG_LICENSE_URI;
923 tag = GST_TAG_AUDIO_CODEC;
926 tag = GST_TAG_VIDEO_CODEC;
929 tag = GST_TAG_ENCODER;
931 case sTagLanguageCode:
932 tag = GST_TAG_LANGUAGE_CODE;
935 tag = GST_TAG_KEYWORDS;
937 case sTagChannelMode:
938 tag = "channel-mode";
941 return m_errorInfo.error_message;
948 if (gst_tag_list_get_string(m_stream_tags, tag, &value))
950 std::string res = value;
957 PyObject *eServiceMP3::getInfoObject(int w)
959 const gchar *tag = 0;
960 bool isBuffer = false;
964 tag = GST_TAG_TRACK_GAIN;
967 tag = GST_TAG_TRACK_PEAK;
970 tag = GST_TAG_ALBUM_GAIN;
973 tag = GST_TAG_ALBUM_PEAK;
975 case sTagReferenceLevel:
976 tag = GST_TAG_REFERENCE_LEVEL;
978 case sTagBeatsPerMinute:
979 tag = GST_TAG_BEATS_PER_MINUTE;
985 case sTagPreviewImage:
986 tag = GST_TAG_PREVIEW_IMAGE;
990 tag = GST_TAG_ATTACHMENT;
999 const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
1003 buffer = gst_value_get_buffer (gv_buffer);
1004 return PyBuffer_FromMemory(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
1009 gdouble value = 0.0;
1010 gst_tag_list_get_double(m_stream_tags, tag, &value);
1011 return PyFloat_FromDouble(value);
1017 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
1023 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
1029 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
1035 RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
1041 int eServiceMP3::getNumberOfTracks()
1043 return m_audioStreams.size();
1046 int eServiceMP3::getCurrentTrack()
1048 if (m_currentAudioStream == -1)
1049 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
1050 return m_currentAudioStream;
1053 RESULT eServiceMP3::selectTrack(unsigned int i)
1056 getPlayPosition(ppos);
1061 int ret = selectAudioStream(i);
1070 int eServiceMP3::selectAudioStream(int i)
1073 g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
1074 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", ¤t_audio, NULL);
1075 if ( current_audio == i )
1077 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
1078 m_currentAudioStream = i;
1084 int eServiceMP3::getCurrentChannel()
1089 RESULT eServiceMP3::selectChannel(int i)
1091 eDebug("eServiceMP3::selectChannel(%i)",i);
1095 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
1097 if (i >= m_audioStreams.size())
1099 info.m_description = m_audioStreams[i].codec;
1100 /* if (m_audioStreams[i].type == atMPEG)
1101 info.m_description = "MPEG";
1102 else if (m_audioStreams[i].type == atMP3)
1103 info.m_description = "MP3";
1104 else if (m_audioStreams[i].type == atAC3)
1105 info.m_description = "AC3";
1106 else if (m_audioStreams[i].type == atAAC)
1107 info.m_description = "AAC";
1108 else if (m_audioStreams[i].type == atDTS)
1109 info.m_description = "DTS";
1110 else if (m_audioStreams[i].type == atPCM)
1111 info.m_description = "PCM";
1112 else if (m_audioStreams[i].type == atOGG)
1113 info.m_description = "OGG";
1114 else if (m_audioStreams[i].type == atFLAC)
1115 info.m_description = "FLAC";
1117 info.m_description = "???";*/
1118 if (info.m_language.empty())
1119 info.m_language = m_audioStreams[i].language_code;
1123 subtype_t getSubtitleType(GstPad* pad, gchar *g_codec=NULL)
1125 subtype_t type = stUnknown;
1126 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1130 GstStructure* str = gst_caps_get_structure(caps, 0);
1131 const gchar *g_type = gst_structure_get_name(str);
1132 eDebug("getSubtitleType::subtitle probe caps type=%s", g_type);
1134 if ( !strcmp(g_type, "video/x-dvd-subpicture") )
1136 else if ( !strcmp(g_type, "text/x-pango-markup") )
1138 else if ( !strcmp(g_type, "text/plain") )
1140 else if ( !strcmp(g_type, "subpicture/x-pgs") )
1143 eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec);
1147 eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec);
1148 if ( !strcmp(g_codec, "VOB") )
1150 else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") )
1152 else if ( !strcmp(g_codec, "ASS") )
1154 else if ( !strcmp(g_codec, "UTF-8 plain text") )
1157 eDebug("getSubtitleType::unsupported subtitle codec %s", g_codec);
1160 eDebug("getSubtitleType::unidentifiable subtitle stream!");
1165 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
1171 source = GST_MESSAGE_SRC(msg);
1172 if (!GST_IS_OBJECT(source))
1174 sourceName = gst_object_get_name(source);
1177 if (gst_message_get_structure(msg))
1178 string = gst_structure_to_string(gst_message_get_structure(msg));
1180 string = g_strdup(GST_MESSAGE_TYPE_NAME(msg));
1181 eDebug("eTsRemoteSource::gst_message from %s: %s", sourceName, string);
1184 switch (GST_MESSAGE_TYPE (msg))
1186 case GST_MESSAGE_EOS:
1187 m_event((iPlayableService*)this, evEOF);
1189 case GST_MESSAGE_STATE_CHANGED:
1191 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1194 if(!strncmp(sourceName, "hls", 3))
1196 //eDebug("HLS Protocol detected : source [%s]", sourceName);
1197 m_is_hls_stream = 1;
1202 GstState old_state, new_state;
1203 gst_message_parse_state_changed(msg, &old_state, &new_state, NULL);
1205 if(old_state == new_state)
1208 eDebug("eServiceMP3::state transition %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
1210 GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state);
1214 case GST_STATE_CHANGE_NULL_TO_READY:
1217 case GST_STATE_CHANGE_READY_TO_PAUSED:
1219 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1222 g_object_set (G_OBJECT (appsink), "max-buffers", 2, NULL);
1223 g_object_set (G_OBJECT (appsink), "sync", FALSE, NULL);
1224 g_object_set (G_OBJECT (appsink), "emit-signals", TRUE, NULL);
1225 eDebug("eServiceMP3::appsink properties set!");
1226 gst_object_unref(appsink);
1228 setAC3Delay(ac3_delay);
1229 setPCMDelay(pcm_delay);
1231 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1233 if ( m_sourceinfo.is_streaming && m_streamingsrc_timeout )
1234 m_streamingsrc_timeout->stop();
1236 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1239 case GST_STATE_CHANGE_PAUSED_TO_READY:
1242 case GST_STATE_CHANGE_READY_TO_NULL:
1248 case GST_MESSAGE_ERROR:
1252 gst_message_parse_error (msg, &err, &debug);
1254 eWarning("Gstreamer error: %s (domain:%i, code:%i) from %s", err->message, err->domain, err->code, sourceName );
1255 if ( err->domain == GST_STREAM_ERROR )
1257 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1259 if ( g_strrstr(sourceName, "videosink") )
1260 m_event((iPlayableService*)this, evUser+11);
1261 else if ( g_strrstr(sourceName, "audiosink") )
1262 m_event((iPlayableService*)this, evUser+10);
1265 else //if( err->domain == 1232 )
1267 if ( err->code == 5 )
1268 m_event((iPlayableService*)this, evUser+20);
1273 case GST_MESSAGE_INFO:
1278 gst_message_parse_info (msg, &inf, &debug);
1280 if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1282 if ( g_strrstr(sourceName, "videosink") )
1283 m_event((iPlayableService*)this, evUser+14);
1288 case GST_MESSAGE_TAG:
1290 GstTagList *tags, *result;
1291 gst_message_parse_tag(msg, &tags);
1293 result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE);
1297 gst_tag_list_free(m_stream_tags);
1298 m_stream_tags = result;
1301 const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1304 GstBuffer *buf_image;
1305 buf_image = gst_value_get_buffer (gv_image);
1306 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1307 int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image));
1309 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1310 m_event((iPlayableService*)this, evUser+13);
1312 gst_tag_list_free(tags);
1313 m_event((iPlayableService*)this, evUpdatedInfo);
1316 case GST_MESSAGE_ASYNC_DONE:
1318 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1322 gint i, active_idx, n_video = 0, n_audio = 0, n_text = 0;
1324 g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1325 g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1326 g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1328 eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1330 if ( n_video + n_audio <= 0 )
1335 m_audioStreams.clear();
1336 m_subtitleStreams.clear();
1338 for (i = 0; i < n_audio; i++)
1341 gchar *g_codec, *g_lang;
1343 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1344 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1347 GstStructure* str = gst_caps_get_structure(caps, 0);
1348 const gchar *g_type = gst_structure_get_name(str);
1349 audio.type = gstCheckAudioPad(str);
1350 g_codec = g_strdup(g_type);
1351 g_lang = g_strdup_printf ("und");
1352 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1353 if ( tags && gst_is_tag_list(tags) )
1355 gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1356 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1357 gst_tag_list_free(tags);
1359 audio.language_code = std::string(g_lang);
1360 audio.codec = std::string(g_codec);
1361 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1362 m_audioStreams.push_back(audio);
1365 gst_caps_unref(caps);
1368 for (i = 0; i < n_text; i++)
1370 gchar *g_codec = NULL, *g_lang = NULL;
1371 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1372 subtitleStream subs;
1375 g_lang = g_strdup_printf ("und");
1376 if ( tags && gst_is_tag_list(tags) )
1378 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1379 gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec);
1380 gst_tag_list_free(tags);
1383 subs.language_code = std::string(g_lang);
1384 eDebug("eServiceMP3::subtitle stream=%i language=%s codec=%s", i, g_lang, g_codec);
1387 g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1389 g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
1390 subs.type = getSubtitleType(pad, g_codec);
1392 m_subtitleStreams.push_back(subs);
1395 m_event((iPlayableService*)this, evUpdatedEventInfo);
1397 if ( m_errorInfo.missing_codec != "" )
1399 if ( m_errorInfo.missing_codec.find("video/") == 0 || ( m_errorInfo.missing_codec.find("audio/") == 0 && getNumberOfTracks() == 0 ) )
1400 m_event((iPlayableService*)this, evUser+12);
1404 case GST_MESSAGE_ELEMENT:
1406 if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1408 if ( gst_is_missing_plugin_message(msg) )
1411 gst_structure_get (msgstruct, "detail", GST_TYPE_CAPS, &caps, NULL);
1412 std::string codec = (const char*) gst_caps_to_string(caps);
1413 gchar *description = gst_missing_plugin_message_get_description(msg);
1416 eDebug("eServiceMP3::m_errorInfo.missing_codec = %s", codec.c_str());
1417 m_errorInfo.error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1418 m_errorInfo.missing_codec = codec.substr(0,(codec.find_first_of(',')));
1419 g_free(description);
1421 gst_caps_unref(caps);
1425 const gchar *eventname = gst_structure_get_name(msgstruct);
1428 if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1430 gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1431 gst_structure_get_int (msgstruct, "width", &m_width);
1432 gst_structure_get_int (msgstruct, "height", &m_height);
1433 if (strstr(eventname, "Changed"))
1434 m_event((iPlayableService*)this, evVideoSizeChanged);
1436 else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1438 gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1439 if (strstr(eventname, "Changed"))
1440 m_event((iPlayableService*)this, evVideoFramerateChanged);
1442 else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1444 gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1445 if (strstr(eventname, "Changed"))
1446 m_event((iPlayableService*)this, evVideoProgressiveChanged);
1453 case GST_MESSAGE_BUFFERING:
1455 GstBufferingMode mode;
1456 gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
1457 gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
1458 m_event((iPlayableService*)this, evBuffering);
1461 case GST_MESSAGE_STREAM_STATUS:
1463 GstStreamStatusType type;
1465 gst_message_parse_stream_status (msg, &type, &owner);
1466 if ( type == GST_STREAM_STATUS_TYPE_CREATE && m_sourceinfo.is_streaming )
1468 if ( GST_IS_PAD(source) )
1469 owner = gst_pad_get_parent_element(GST_PAD(source));
1470 else if ( GST_IS_ELEMENT(source) )
1471 owner = GST_ELEMENT(source);
1476 GstElementFactory *factory = gst_element_get_factory(GST_ELEMENT(owner));
1477 const gchar *name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
1478 if (!strcmp(name, "souphttpsrc"))
1480 m_streamingsrc_timeout->start(HTTP_TIMEOUT*1000, true);
1481 g_object_set (G_OBJECT (owner), "timeout", HTTP_TIMEOUT, NULL);
1482 eDebug("eServiceMP3::GST_STREAM_STATUS_TYPE_CREATE -> setting timeout on %s to %is", name, HTTP_TIMEOUT);
1485 else if (m_is_hls_stream && !strncmp(name, "queue", 5))
1487 m_streamingsrc_timeout->stop();
1488 m_is_hls_stream = 0;
1489 //eDebug("Stoped response timeout!! : HLS");
1492 if ( GST_IS_PAD(source) )
1493 gst_object_unref(owner);
1500 g_free (sourceName);
1503 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1505 eServiceMP3 *_this = (eServiceMP3*)user_data;
1506 _this->m_pump.send(Message(1));
1508 return GST_BUS_PASS;
1511 void eServiceMP3::gstHTTPSourceSetAgent(GObject *object, GParamSpec *unused, gpointer user_data)
1513 eServiceMP3 *_this = (eServiceMP3*)user_data;
1515 g_object_get(_this->m_gst_playbin, "source", &source, NULL);
1516 g_object_set (G_OBJECT (source), "user-agent", _this->m_useragent.c_str(), NULL);
1517 gst_object_unref(source);
1520 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1525 if ( gst_structure_has_name (structure, "audio/mpeg"))
1527 gint mpegversion, layer = -1;
1528 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1531 switch (mpegversion) {
1534 gst_structure_get_int (structure, "layer", &layer);
1550 else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1552 else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1554 else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1560 void eServiceMP3::gstPoll(const Message &msg)
1564 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
1565 GstMessage *message;
1566 while ((message = gst_bus_pop(bus)))
1568 gstBusCall(bus, message);
1569 gst_message_unref (message);
1572 else if (msg.type == 2)
1574 else if (msg.type == 3)
1575 gstTextpadHasCAPS_synced(msg.d.pad);
1577 eDebug("gstPoll unhandled Message %d\n", msg.type);
1580 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1582 void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
1584 eServiceMP3 *_this = (eServiceMP3*)user_data;
1585 eSingleLocker l(_this->m_subs_to_pull_lock);
1586 ++_this->m_subs_to_pull;
1587 _this->m_pump.send(Message(2));
1590 void eServiceMP3::gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data)
1592 eServiceMP3 *_this = (eServiceMP3*)user_data;
1594 gst_object_ref (pad);
1596 _this->m_pump.send(Message(3, pad));
1599 // after messagepump
1600 void eServiceMP3::gstTextpadHasCAPS_synced(GstPad *pad)
1604 g_object_get (G_OBJECT (pad), "caps", &caps, NULL);
1606 eDebug("gstTextpadHasCAPS:: signal::caps = %s", gst_caps_to_string(caps));
1610 subtitleStream subs;
1612 // eDebug("gstGhostpadHasCAPS_synced %p %d", pad, m_subtitleStreams.size());
1614 if (!m_subtitleStreams.empty())
1615 subs = m_subtitleStreams[m_currentSubtitleStream];
1617 subs.type = stUnknown;
1621 if ( subs.type == stUnknown )
1624 // eDebug("gstGhostpadHasCAPS::m_subtitleStreams[%i].type == stUnknown...", m_currentSubtitleStream);
1627 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", m_currentSubtitleStream, &tags);
1629 g_lang = g_strdup_printf ("und");
1630 if ( tags && gst_is_tag_list(tags) )
1631 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1633 subs.language_code = std::string(g_lang);
1634 subs.type = getSubtitleType(pad);
1636 if (!m_subtitleStreams.empty())
1637 m_subtitleStreams[m_currentSubtitleStream] = subs;
1639 m_subtitleStreams.push_back(subs);
1644 // 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));
1646 gst_caps_unref (caps);
1649 gst_object_unref (pad);
1652 void eServiceMP3::pullSubtitle()
1655 g_object_get (G_OBJECT (m_gst_playbin), "text-sink", &sink, NULL);
1659 while (m_subs_to_pull && m_subtitle_pages.size() < 2)
1663 eSingleLocker l(m_subs_to_pull_lock);
1665 g_signal_emit_by_name (sink, "pull-buffer", &buffer);
1669 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1670 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1671 size_t len = GST_BUFFER_SIZE(buffer);
1672 eDebug("pullSubtitle m_subtitleStreams[m_currentSubtitleStream].type=%i",m_subtitleStreams[m_currentSubtitleStream].type);
1674 if ( m_subtitleStreams[m_currentSubtitleStream].type )
1676 if ( m_subtitleStreams[m_currentSubtitleStream].type < stVOB )
1678 unsigned char line[len+1];
1680 memcpy(line, GST_BUFFER_DATA(buffer), len);
1682 eDebug("got new text subtitle @ buf_pos = %lld ns (in pts=%lld): '%s' ", buf_pos, buf_pos/11111, line);
1683 gRGB rgbcol(0xD0,0xD0,0xD0);
1684 page.type = SubtitlePage::Pango;
1685 page.pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
1686 page.pango_page.m_show_pts = buf_pos / 11111L;
1687 page.pango_page.m_timeout = duration_ns / 1000000;
1688 m_subtitle_pages.push_back(page);
1689 if (m_subtitle_pages.size()==1)
1694 eDebug("unsupported subpicture... ignoring");
1697 gst_buffer_unref(buffer);
1700 gst_object_unref(sink);
1703 eDebug("no subtitle sink!");
1706 void eServiceMP3::pushSubtitles()
1708 while ( !m_subtitle_pages.empty() )
1710 SubtitlePage &frontpage = m_subtitle_pages.front();
1713 gint64 show_pts = 0;
1715 getPlayPosition(running_pts);
1717 if (m_decoder_time_valid_state < 4) {
1718 ++m_decoder_time_valid_state;
1719 if (m_prev_decoder_time == running_pts)
1720 m_decoder_time_valid_state = 0;
1721 if (m_decoder_time_valid_state < 4) {
1722 // if (m_decoder_time_valid_state)
1723 // eDebug("%d: decoder time not valid! prev %lld, now %lld\n", m_decoder_time_valid_state, m_prev_decoder_time/90, running_pts/90);
1725 // eDebug("%d: decoder time not valid! now %lld\n", m_decoder_time_valid_state, running_pts/90);
1726 m_subtitle_sync_timer->start(25, true);
1727 m_prev_decoder_time = running_pts;
1732 if (frontpage.type == SubtitlePage::Pango)
1733 show_pts = frontpage.pango_page.m_show_pts;
1735 diff_ms = ( show_pts - running_pts ) / 90;
1736 eDebug("check subtitle: decoder: %lld, show_pts: %lld, diff: %lld ms", running_pts/90, show_pts/90, diff_ms);
1738 if ( diff_ms < -100 )
1740 eDebug("subtitle too late... drop");
1741 m_subtitle_pages.pop_front();
1743 else if ( diff_ms > 20 )
1745 eDebug("start timer");
1746 m_subtitle_sync_timer->start(diff_ms, true);
1749 else // immediate show
1751 if ( m_subtitle_widget )
1754 if ( frontpage.type == SubtitlePage::Pango)
1755 m_subtitle_widget->setPage(frontpage.pango_page);
1756 m_subtitle_widget->show();
1758 m_subtitle_pages.pop_front();
1761 if (m_subtitle_pages.empty())
1766 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
1768 eDebug ("eServiceMP3::enableSubtitles m_currentSubtitleStream=%i this=%p",m_currentSubtitleStream, this);
1770 int tuplesize = PyTuple_Size(tuple);
1773 eSingleLocker l(m_subs_to_pull_lock);
1776 // g_signal_emit_by_name (m_gst_playbin, "get-text-pad", m_currentSubtitleStream, &pad);
1777 // gst_element_get_static_pad(m_gst_subtitlebin, "sink");
1778 // gulong subprobe_handler_id = gst_pad_add_buffer_probe (pad, G_CALLBACK (gstCBsubtitleDrop), NULL);
1780 if (!PyTuple_Check(tuple))
1784 entry = PyTuple_GET_ITEM(tuple, 1);
1785 if (!PyInt_Check(entry))
1787 pid = PyInt_AsLong(entry);
1788 entry = PyTuple_GET_ITEM(tuple, 2);
1789 if (!PyInt_Check(entry))
1791 type = PyInt_AsLong(entry);
1793 if (m_currentSubtitleStream != pid)
1795 g_object_set (G_OBJECT (m_gst_playbin), "current-text", pid, NULL);
1796 eDebug ("eServiceMP3::enableSubtitles g_object_set current-text = %i", pid);
1797 m_currentSubtitleStream = pid;
1799 m_prev_decoder_time = -1;
1800 m_subtitle_pages.clear();
1803 m_subtitle_widget = 0;
1804 m_subtitle_widget = new eSubtitleWidget(parent);
1805 m_subtitle_widget->resize(parent->size()); /* full size */
1807 g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
1809 eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
1810 // gst_pad_remove_buffer_probe (pad, subprobe_handler_id);
1812 m_event((iPlayableService*)this, evUpdatedInfo);
1817 eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
1818 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
1822 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
1824 eDebug("eServiceMP3::disableSubtitles");
1825 m_subtitle_pages.clear();
1826 delete m_subtitle_widget;
1827 m_subtitle_widget = 0;
1831 PyObject *eServiceMP3::getCachedSubtitle()
1833 // eDebug("eServiceMP3::getCachedSubtitle");
1837 PyObject *eServiceMP3::getSubtitleList()
1839 // eDebug("eServiceMP3::getSubtitleList");
1840 ePyObject l = PyList_New(0);
1843 for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
1845 subtype_t type = IterSubtitleStream->type;
1854 ePyObject tuple = PyTuple_New(5);
1855 // eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
1856 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1857 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
1858 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
1859 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
1860 PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
1861 PyList_Append(l, tuple);
1867 eDebug("eServiceMP3::getSubtitleList finished");
1871 RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
1877 PyObject *eServiceMP3::getBufferCharge()
1879 ePyObject tuple = PyTuple_New(5);
1880 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
1881 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
1882 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
1883 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
1884 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
1888 int eServiceMP3::setBufferSize(int size)
1890 m_buffer_size = size;
1891 g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
1895 int eServiceMP3::getAC3Delay()
1900 int eServiceMP3::getPCMDelay()
1905 void eServiceMP3::setAC3Delay(int delay)
1908 if (!m_gst_playbin || m_state != stRunning)
1913 int config_delay_int = delay;
1914 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1918 std::string config_delay;
1919 if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
1920 config_delay_int += atoi(config_delay.c_str());
1921 gst_object_unref(sink);
1925 eDebug("dont apply ac3 delay when no video is running!");
1926 config_delay_int = 0;
1929 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1933 gchar *name = gst_element_get_name(sink);
1934 if (strstr(name, "dvbaudiosink"))
1935 eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
1937 gst_object_unref(sink);
1942 void eServiceMP3::setPCMDelay(int delay)
1945 if (!m_gst_playbin || m_state != stRunning)
1950 int config_delay_int = delay;
1951 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1955 std::string config_delay;
1956 if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
1957 config_delay_int += atoi(config_delay.c_str());
1958 gst_object_unref(sink);
1962 eDebug("dont apply pcm delay when no video is running!");
1963 config_delay_int = 0;
1966 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1970 gchar *name = gst_element_get_name(sink);
1971 if (strstr(name, "dvbaudiosink"))
1972 eTSMPEGDecoder::setHwPCMDelay(config_delay_int);
1975 // this is realy untested..and not used yet
1976 gint64 offset = config_delay_int;
1977 offset *= 1000000; // milli to nano
1978 g_object_set (G_OBJECT (m_gst_playbin), "ts-offset", offset, NULL);
1981 gst_object_unref(sink);