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 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
57 m_service_info = new eStaticServiceMP3Info();
60 eServiceFactoryMP3::~eServiceFactoryMP3()
62 ePtr<eServiceCenter> sc;
64 eServiceCenter::getPrivInstance(sc);
66 sc->removeServiceFactory(eServiceFactoryMP3::id);
69 DEFINE_REF(eServiceFactoryMP3)
72 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
75 ptr = new eServiceMP3(ref);
79 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
85 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
91 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
97 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
99 DECLARE_REF(eMP3ServiceOfflineOperations);
100 eServiceReference m_ref;
102 eMP3ServiceOfflineOperations(const eServiceReference &ref);
104 RESULT deleteFromDisk(int simulate);
105 RESULT getListOfFilenames(std::list<std::string> &);
109 DEFINE_REF(eMP3ServiceOfflineOperations);
111 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
115 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
121 std::list<std::string> res;
122 if (getListOfFilenames(res))
125 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
127 eDebug("FATAL !! can't get background file eraser");
129 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
131 eDebug("Removing %s...", i->c_str());
133 eraser->erase(i->c_str());
135 ::unlink(i->c_str());
142 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
145 res.push_back(m_ref.path);
149 RESULT eMP3ServiceOfflineOperations::reindex()
155 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
157 ptr = new eMP3ServiceOfflineOperations(ref);
161 // eStaticServiceMP3Info
164 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
165 // about unopened files.
167 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
168 // should have a database backend where ID3-files etc. are cached.
169 // this would allow listing the mp3 database based on certain filters.
171 DEFINE_REF(eStaticServiceMP3Info)
173 eStaticServiceMP3Info::eStaticServiceMP3Info()
177 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
179 if ( ref.name.length() )
183 size_t last = ref.path.rfind('/');
184 if (last != std::string::npos)
185 name = ref.path.substr(last+1);
192 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
197 int eStaticServiceMP3Info::getInfo(const eServiceReference &ref, int w)
201 case iServiceInformation::sTimeCreate:
204 if(stat(ref.path.c_str(), &s) == 0)
208 return iServiceInformation::resNA;
212 return iServiceInformation::resNA;
217 int eServiceMP3::ac3_delay,
218 eServiceMP3::pcm_delay;
220 eServiceMP3::eServiceMP3(eServiceReference ref)
221 :m_ref(ref), m_pump(eApp, 1)
223 m_seekTimeout = eTimer::create(eApp);
224 m_subtitle_sync_timer = eTimer::create(eApp);
225 m_streamingsrc_timeout = 0;
227 m_currentAudioStream = -1;
228 m_currentSubtitleStream = 0;
229 m_subtitle_widget = 0;
230 m_currentTrickRatio = 0;
232 m_buffer_size = 1*1024*1024;
233 m_prev_decoder_time = -1;
234 m_decoder_time_valid_state = 0;
235 m_errorInfo.missing_codec = "";
239 CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
240 CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
241 CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
242 m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
245 eDebug("eServiceMP3::construct!");
247 const char *filename = m_ref.path.c_str();
248 const char *ext = strrchr(filename, '.');
252 m_sourceinfo.is_video = FALSE;
253 m_sourceinfo.audiotype = atUnknown;
254 if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
256 m_sourceinfo.containertype = ctMPEGPS;
257 m_sourceinfo.is_video = TRUE;
259 else if ( strcasecmp(ext, ".ts") == 0 )
261 m_sourceinfo.containertype = ctMPEGTS;
262 m_sourceinfo.is_video = TRUE;
264 else if ( strcasecmp(ext, ".mkv") == 0 )
266 m_sourceinfo.containertype = ctMKV;
267 m_sourceinfo.is_video = TRUE;
269 else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
271 m_sourceinfo.containertype = ctAVI;
272 m_sourceinfo.is_video = TRUE;
274 else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0 || strcasecmp(ext, ".m4v") == 0)
276 m_sourceinfo.containertype = ctMP4;
277 m_sourceinfo.is_video = TRUE;
279 else if ( strcasecmp(ext, ".m4a") == 0 )
281 m_sourceinfo.containertype = ctMP4;
282 m_sourceinfo.audiotype = atAAC;
284 else if ( strcasecmp(ext, ".mp3") == 0 )
285 m_sourceinfo.audiotype = atMP3;
286 else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
287 m_sourceinfo.containertype = ctCDA;
288 if ( strcasecmp(ext, ".dat") == 0 )
290 m_sourceinfo.containertype = ctVCD;
291 m_sourceinfo.is_video = TRUE;
293 if ( strstr(filename, "://") )
294 m_sourceinfo.is_streaming = TRUE;
298 if ( m_sourceinfo.is_streaming )
300 uri = g_strdup_printf ("%s", filename);
301 m_streamingsrc_timeout = eTimer::create(eApp);;
302 CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
304 std::string config_str;
305 if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
307 if ( config_str == "True" )
308 ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
310 if ( m_useragent.length() == 0 )
311 m_useragent = "Dream Multimedia Dreambox Enigma2 Mediaplayer";
313 else if ( m_sourceinfo.containertype == ctCDA )
315 int i_track = atoi(filename+18);
316 uri = g_strdup_printf ("cdda://%i", i_track);
318 else if ( m_sourceinfo.containertype == ctVCD )
320 int fd = open(filename,O_RDONLY);
322 int ret = read(fd, tmp, 128*1024);
324 if ( ret == -1 ) // this is a "REAL" VCD
325 uri = g_strdup_printf ("vcd://");
327 uri = g_filename_to_uri(filename, NULL, NULL);
331 uri = g_filename_to_uri(filename, NULL, NULL);
333 eDebug("eServiceMP3::playbin2 uri=%s", uri);
335 m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
337 m_errorInfo.error_message = "failed to create GStreamer pipeline!\n";
339 g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
341 int flags = 0x47; // ( GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT );
342 g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
346 GstElement *subsink = gst_element_factory_make("appsink", "subtitle_sink");
348 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
351 m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
352 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);
353 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
359 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), gstBusSyncHandler, this);
360 char srt_filename[strlen(filename)+1];
361 strncpy(srt_filename,filename,strlen(filename)-3);
362 srt_filename[strlen(filename)-3]='\0';
363 strcat(srt_filename, "srt");
365 if (stat(srt_filename, &buffer) == 0)
367 eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
368 g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
370 if ( m_sourceinfo.is_streaming )
372 g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
376 m_event((iPlayableService*)this, evUser+12);
379 gst_object_unref(GST_OBJECT(m_gst_playbin));
381 eDebug("eServiceMP3::sorry, can't play: %s",m_errorInfo.error_message.c_str());
385 setBufferSize(m_buffer_size);
388 eServiceMP3::~eServiceMP3()
390 // disconnect subtitle callback
391 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
395 g_signal_handler_disconnect (appsink, m_subs_to_pull_handler_id);
396 gst_object_unref(appsink);
399 delete m_subtitle_widget;
401 // disconnect sync handler callback
402 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), NULL, NULL);
404 if (m_state == stRunning)
408 gst_tag_list_free(m_stream_tags);
412 gst_object_unref (GST_OBJECT (m_gst_playbin));
413 eDebug("eServiceMP3::destruct!");
417 DEFINE_REF(eServiceMP3);
419 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
421 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
425 RESULT eServiceMP3::start()
427 ASSERT(m_state == stIdle);
432 eDebug("eServiceMP3::starting pipeline");
433 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
436 m_event(this, evStart);
441 void eServiceMP3::sourceTimeout()
443 eDebug("eServiceMP3::http source timeout! issuing eof...");
444 m_event((iPlayableService*)this, evEOF);
447 RESULT eServiceMP3::stop()
449 ASSERT(m_state != stIdle);
451 if (m_state == stStopped)
454 //GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_gst_playbin),GST_DEBUG_GRAPH_SHOW_ALL,"e2-playbin");
456 eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
457 gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
463 RESULT eServiceMP3::setTarget(int target)
468 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
474 RESULT eServiceMP3::setSlowMotion(int ratio)
478 eDebug("eServiceMP3::setSlowMotion ratio=%f",1/(float)ratio);
479 return trickSeek(1/(float)ratio);
482 RESULT eServiceMP3::setFastForward(int ratio)
484 eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
485 return trickSeek(ratio);
488 void eServiceMP3::seekTimeoutCB()
491 getPlayPosition(ppos);
493 ppos += 90000*m_currentTrickRatio;
498 m_seekTimeout->stop();
504 m_seekTimeout->stop();
511 RESULT eServiceMP3::pause()
513 if (!m_gst_playbin || m_state != stRunning)
516 gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
521 RESULT eServiceMP3::unpause()
523 if (!m_gst_playbin || m_state != stRunning)
526 gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
531 /* iSeekableService */
532 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
538 RESULT eServiceMP3::getLength(pts_t &pts)
543 if (m_state != stRunning)
546 GstFormat fmt = GST_FORMAT_TIME;
549 if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
551 /* len is in nanoseconds. we have 90 000 pts per second. */
557 RESULT eServiceMP3::seekToImpl(pts_t to)
559 /* convert pts to nanoseconds */
560 gint64 time_nanoseconds = to * 11111LL;
561 if (!gst_element_seek (m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
562 GST_SEEK_TYPE_SET, time_nanoseconds,
563 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
565 eDebug("eServiceMP3::seekTo failed");
572 RESULT eServiceMP3::seekTo(pts_t to)
577 eSingleLocker l(m_subs_to_pull_lock); // this is needed to dont handle incomming subtitles during seek!
578 if (!(ret = seekToImpl(to)))
580 m_subtitle_pages.clear();
581 m_prev_decoder_time = -1;
582 m_decoder_time_valid_state = 0;
591 RESULT eServiceMP3::trickSeek(gdouble ratio)
596 return seekRelative(0, 0);
600 flags = GST_SEEK_FLAG_NONE;
601 flags |= GST_SEEK_FLAG_FLUSH;
602 // flags |= GstSeekFlags (GST_SEEK_FLAG_ACCURATE);
603 flags |= GST_SEEK_FLAG_KEY_UNIT;
604 // flags |= GstSeekFlags (GST_SEEK_FLAG_SEGMENT);
605 // flags |= GstSeekFlags (GST_SEEK_FLAG_SKIP);
607 GstFormat fmt = GST_FORMAT_TIME;
609 gst_element_query_duration(m_gst_playbin, &fmt, &len);
610 gst_element_query_position(m_gst_playbin, &fmt, &pos);
614 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, (GstSeekFlags)flags, GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, len);
616 eDebug("eServiceMP3::trickSeek with rate %lf to %" GST_TIME_FORMAT " ", ratio, GST_TIME_ARGS (pos));
620 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);
623 if (!gst_element_send_event ( GST_ELEMENT (m_gst_playbin), s_event))
625 eDebug("eServiceMP3::trickSeek failed");
633 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
639 getPlayPosition(ppos);
640 ppos += to * direction;
648 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
650 GstFormat fmt = GST_FORMAT_TIME;
657 if (m_state != stRunning)
660 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
663 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
668 gchar *name = gst_element_get_name(sink);
669 gboolean use_get_decoder_time = strstr(name, "dvbaudiosink") || strstr(name, "dvbvideosink");
672 if (use_get_decoder_time)
673 g_signal_emit_by_name(sink, "get-decoder-time", &pos);
675 gst_object_unref(sink);
677 if (!use_get_decoder_time && !gst_element_query_position(m_gst_playbin, &fmt, &pos)) {
678 eDebug("gst_element_query_position failed in getPlayPosition");
682 /* pos is in nanoseconds. we have 90 000 pts per second. */
684 // eDebug("gst_element_query_position %lld pts (%lld ms)", pts, pos/1000000);
688 RESULT eServiceMP3::setTrickmode(int trick)
690 /* trickmode is not yet supported by our dvbmediasinks. */
694 RESULT eServiceMP3::isCurrentlySeekable()
696 int ret = 3; // seeking and fast/slow winding possible
701 if (m_state != stRunning)
704 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
706 // disable fast winding yet when a dvbvideosink or dvbaudiosink is used
707 // for this we must do some changes on different places.. (gstreamer.. our sinks.. enigma2)
709 ret &= ~2; // only seeking possible
710 gst_object_unref(sink);
713 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
715 ret &= ~2; // only seeking possible
716 gst_object_unref(sink);
723 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
729 RESULT eServiceMP3::getName(std::string &name)
731 std::string title = m_ref.getName();
735 size_t n = name.rfind('/');
736 if (n != std::string::npos)
737 name = name.substr(n + 1);
744 int eServiceMP3::getInfo(int w)
746 const gchar *tag = 0;
750 case sServiceref: return m_ref;
751 case sVideoHeight: return m_height;
752 case sVideoWidth: return m_width;
753 case sFrameRate: return m_framerate;
754 case sProgressive: return m_progressive;
755 case sAspect: return m_aspect;
759 case sTagTitleSortname:
760 case sTagArtistSortname:
761 case sTagAlbumSortname:
766 case sTagExtendedComment:
769 case sTagDescription:
772 case sTagOrganization:
774 case sTagCopyrightURI:
782 case sTagLanguageCode:
784 case sTagChannelMode:
791 case sTagReferenceLevel:
792 case sTagBeatsPerMinute:
794 case sTagPreviewImage:
796 return resIsPyObject;
797 case sTagTrackNumber:
798 tag = GST_TAG_TRACK_NUMBER;
801 tag = GST_TAG_TRACK_COUNT;
803 case sTagAlbumVolumeNumber:
804 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
806 case sTagAlbumVolumeCount:
807 tag = GST_TAG_ALBUM_VOLUME_COUNT;
810 tag = GST_TAG_BITRATE;
812 case sTagNominalBitrate:
813 tag = GST_TAG_NOMINAL_BITRATE;
815 case sTagMinimumBitrate:
816 tag = GST_TAG_MINIMUM_BITRATE;
818 case sTagMaximumBitrate:
819 tag = GST_TAG_MAXIMUM_BITRATE;
822 tag = GST_TAG_SERIAL;
824 case sTagEncoderVersion:
825 tag = GST_TAG_ENCODER_VERSION;
834 if (!m_stream_tags || !tag)
838 if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
844 std::string eServiceMP3::getInfoString(int w)
846 if ( !m_stream_tags && w < sUser && w > 26 )
848 const gchar *tag = 0;
855 tag = GST_TAG_ARTIST;
860 case sTagTitleSortname:
861 tag = GST_TAG_TITLE_SORTNAME;
863 case sTagArtistSortname:
864 tag = GST_TAG_ARTIST_SORTNAME;
866 case sTagAlbumSortname:
867 tag = GST_TAG_ALBUM_SORTNAME;
871 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
874 g_date_strftime (res, sizeof(res), "%Y-%M-%D", date);
875 return (std::string)res;
879 tag = GST_TAG_COMPOSER;
885 tag = GST_TAG_COMMENT;
887 case sTagExtendedComment:
888 tag = GST_TAG_EXTENDED_COMMENT;
891 tag = GST_TAG_LOCATION;
894 tag = GST_TAG_HOMEPAGE;
896 case sTagDescription:
897 tag = GST_TAG_DESCRIPTION;
900 tag = GST_TAG_VERSION;
905 case sTagOrganization:
906 tag = GST_TAG_ORGANIZATION;
909 tag = GST_TAG_COPYRIGHT;
911 case sTagCopyrightURI:
912 tag = GST_TAG_COPYRIGHT_URI;
915 tag = GST_TAG_CONTACT;
918 tag = GST_TAG_LICENSE;
921 tag = GST_TAG_LICENSE_URI;
927 tag = GST_TAG_AUDIO_CODEC;
930 tag = GST_TAG_VIDEO_CODEC;
933 tag = GST_TAG_ENCODER;
935 case sTagLanguageCode:
936 tag = GST_TAG_LANGUAGE_CODE;
939 tag = GST_TAG_KEYWORDS;
941 case sTagChannelMode:
942 tag = "channel-mode";
945 return m_errorInfo.error_message;
952 if (gst_tag_list_get_string(m_stream_tags, tag, &value))
954 std::string res = value;
961 PyObject *eServiceMP3::getInfoObject(int w)
963 const gchar *tag = 0;
964 bool isBuffer = false;
968 tag = GST_TAG_TRACK_GAIN;
971 tag = GST_TAG_TRACK_PEAK;
974 tag = GST_TAG_ALBUM_GAIN;
977 tag = GST_TAG_ALBUM_PEAK;
979 case sTagReferenceLevel:
980 tag = GST_TAG_REFERENCE_LEVEL;
982 case sTagBeatsPerMinute:
983 tag = GST_TAG_BEATS_PER_MINUTE;
989 case sTagPreviewImage:
990 tag = GST_TAG_PREVIEW_IMAGE;
994 tag = GST_TAG_ATTACHMENT;
1003 const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
1007 buffer = gst_value_get_buffer (gv_buffer);
1008 return PyBuffer_FromMemory(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
1013 gdouble value = 0.0;
1014 gst_tag_list_get_double(m_stream_tags, tag, &value);
1015 return PyFloat_FromDouble(value);
1021 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
1027 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
1033 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
1039 RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
1045 int eServiceMP3::getNumberOfTracks()
1047 return m_audioStreams.size();
1050 int eServiceMP3::getCurrentTrack()
1052 if (m_currentAudioStream == -1)
1053 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
1054 return m_currentAudioStream;
1057 RESULT eServiceMP3::selectTrack(unsigned int i)
1060 getPlayPosition(ppos);
1065 int ret = selectAudioStream(i);
1074 int eServiceMP3::selectAudioStream(int i)
1077 g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
1078 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", ¤t_audio, NULL);
1079 if ( current_audio == i )
1081 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
1082 m_currentAudioStream = i;
1088 int eServiceMP3::getCurrentChannel()
1093 RESULT eServiceMP3::selectChannel(int i)
1095 eDebug("eServiceMP3::selectChannel(%i)",i);
1099 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
1101 if (i >= m_audioStreams.size())
1103 info.m_description = m_audioStreams[i].codec;
1104 /* if (m_audioStreams[i].type == atMPEG)
1105 info.m_description = "MPEG";
1106 else if (m_audioStreams[i].type == atMP3)
1107 info.m_description = "MP3";
1108 else if (m_audioStreams[i].type == atAC3)
1109 info.m_description = "AC3";
1110 else if (m_audioStreams[i].type == atAAC)
1111 info.m_description = "AAC";
1112 else if (m_audioStreams[i].type == atDTS)
1113 info.m_description = "DTS";
1114 else if (m_audioStreams[i].type == atPCM)
1115 info.m_description = "PCM";
1116 else if (m_audioStreams[i].type == atOGG)
1117 info.m_description = "OGG";
1118 else if (m_audioStreams[i].type == atFLAC)
1119 info.m_description = "FLAC";
1121 info.m_description = "???";*/
1122 if (info.m_language.empty())
1123 info.m_language = m_audioStreams[i].language_code;
1127 subtype_t getSubtitleType(GstPad* pad, gchar *g_codec=NULL)
1129 subtype_t type = stUnknown;
1130 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1134 GstStructure* str = gst_caps_get_structure(caps, 0);
1135 const gchar *g_type = gst_structure_get_name(str);
1136 eDebug("getSubtitleType::subtitle probe caps type=%s", g_type);
1138 if ( !strcmp(g_type, "video/x-dvd-subpicture") )
1140 else if ( !strcmp(g_type, "text/x-pango-markup") )
1142 else if ( !strcmp(g_type, "text/plain") )
1144 else if ( !strcmp(g_type, "subpicture/x-pgs") )
1147 eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec);
1151 eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec);
1152 if ( !strcmp(g_codec, "VOB") )
1154 else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") )
1156 else if ( !strcmp(g_codec, "ASS") )
1158 else if ( !strcmp(g_codec, "UTF-8 plain text") )
1161 eDebug("getSubtitleType::unsupported subtitle codec %s", g_codec);
1164 eDebug("getSubtitleType::unidentifiable subtitle stream!");
1169 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
1175 source = GST_MESSAGE_SRC(msg);
1176 if (!GST_IS_OBJECT(source))
1178 sourceName = gst_object_get_name(source);
1181 if (gst_message_get_structure(msg))
1182 string = gst_structure_to_string(gst_message_get_structure(msg));
1184 string = g_strdup(GST_MESSAGE_TYPE_NAME(msg));
1185 eDebug("eTsRemoteSource::gst_message from %s: %s", sourceName, string);
1188 switch (GST_MESSAGE_TYPE (msg))
1190 case GST_MESSAGE_EOS:
1191 m_event((iPlayableService*)this, evEOF);
1193 case GST_MESSAGE_STATE_CHANGED:
1195 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1198 if(!strncmp(sourceName, "hls", 3))
1200 //eDebug("HLS Protocol detected : source [%s]", sourceName);
1201 m_is_hls_stream = 1;
1206 GstState old_state, new_state;
1207 gst_message_parse_state_changed(msg, &old_state, &new_state, NULL);
1209 if(old_state == new_state)
1212 eDebug("eServiceMP3::state transition %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
1214 GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state);
1218 case GST_STATE_CHANGE_NULL_TO_READY:
1221 case GST_STATE_CHANGE_READY_TO_PAUSED:
1223 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1226 g_object_set (G_OBJECT (appsink), "max-buffers", 2, NULL);
1227 g_object_set (G_OBJECT (appsink), "sync", FALSE, NULL);
1228 g_object_set (G_OBJECT (appsink), "emit-signals", TRUE, NULL);
1229 eDebug("eServiceMP3::appsink properties set!");
1230 gst_object_unref(appsink);
1232 setAC3Delay(ac3_delay);
1233 setPCMDelay(pcm_delay);
1235 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1237 if ( m_sourceinfo.is_streaming && m_streamingsrc_timeout )
1238 m_streamingsrc_timeout->stop();
1240 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1243 case GST_STATE_CHANGE_PAUSED_TO_READY:
1246 case GST_STATE_CHANGE_READY_TO_NULL:
1252 case GST_MESSAGE_ERROR:
1256 gst_message_parse_error (msg, &err, &debug);
1258 eWarning("Gstreamer error: %s (domain:%i, code:%i) from %s", err->message, err->domain, err->code, sourceName );
1259 if ( err->domain == GST_STREAM_ERROR )
1261 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1263 if ( g_strrstr(sourceName, "videosink") )
1264 m_event((iPlayableService*)this, evUser+11);
1265 else if ( g_strrstr(sourceName, "audiosink") )
1266 m_event((iPlayableService*)this, evUser+10);
1269 else //if( err->domain == 1232 )
1271 if ( err->code == 5 )
1272 m_event((iPlayableService*)this, evUser+20);
1277 case GST_MESSAGE_INFO:
1282 gst_message_parse_info (msg, &inf, &debug);
1284 if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1286 if ( g_strrstr(sourceName, "videosink") )
1287 m_event((iPlayableService*)this, evUser+14);
1292 case GST_MESSAGE_TAG:
1294 GstTagList *tags, *result;
1295 gst_message_parse_tag(msg, &tags);
1297 result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE);
1301 gst_tag_list_free(m_stream_tags);
1302 m_stream_tags = result;
1305 const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1308 GstBuffer *buf_image;
1309 buf_image = gst_value_get_buffer (gv_image);
1310 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1311 int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image));
1313 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1314 m_event((iPlayableService*)this, evUser+13);
1316 gst_tag_list_free(tags);
1317 m_event((iPlayableService*)this, evUpdatedInfo);
1320 case GST_MESSAGE_ASYNC_DONE:
1322 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1326 gint i, active_idx, n_video = 0, n_audio = 0, n_text = 0;
1328 g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1329 g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1330 g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1332 eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1334 if ( n_video + n_audio <= 0 )
1339 m_audioStreams.clear();
1340 m_subtitleStreams.clear();
1342 for (i = 0; i < n_audio; i++)
1345 gchar *g_codec, *g_lang;
1347 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1348 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1351 GstStructure* str = gst_caps_get_structure(caps, 0);
1352 const gchar *g_type = gst_structure_get_name(str);
1353 audio.type = gstCheckAudioPad(str);
1354 g_codec = g_strdup(g_type);
1355 g_lang = g_strdup_printf ("und");
1356 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1357 if ( tags && gst_is_tag_list(tags) )
1359 gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1360 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1361 gst_tag_list_free(tags);
1363 audio.language_code = std::string(g_lang);
1364 audio.codec = std::string(g_codec);
1365 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1366 m_audioStreams.push_back(audio);
1369 gst_caps_unref(caps);
1372 for (i = 0; i < n_text; i++)
1374 gchar *g_codec = NULL, *g_lang = NULL;
1375 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1376 subtitleStream subs;
1379 g_lang = g_strdup_printf ("und");
1380 if ( tags && gst_is_tag_list(tags) )
1382 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1383 gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec);
1384 gst_tag_list_free(tags);
1387 subs.language_code = std::string(g_lang);
1388 eDebug("eServiceMP3::subtitle stream=%i language=%s codec=%s", i, g_lang, g_codec);
1391 g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1393 g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
1394 subs.type = getSubtitleType(pad, g_codec);
1396 m_subtitleStreams.push_back(subs);
1399 m_event((iPlayableService*)this, evUpdatedEventInfo);
1401 if ( m_errorInfo.missing_codec != "" )
1403 if ( m_errorInfo.missing_codec.find("video/") == 0 || ( m_errorInfo.missing_codec.find("audio/") == 0 && getNumberOfTracks() == 0 ) )
1404 m_event((iPlayableService*)this, evUser+12);
1408 case GST_MESSAGE_ELEMENT:
1410 if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1412 if ( gst_is_missing_plugin_message(msg) )
1415 gst_structure_get (msgstruct, "detail", GST_TYPE_CAPS, &caps, NULL);
1416 std::string codec = (const char*) gst_caps_to_string(caps);
1417 gchar *description = gst_missing_plugin_message_get_description(msg);
1420 eDebug("eServiceMP3::m_errorInfo.missing_codec = %s", codec.c_str());
1421 m_errorInfo.error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1422 m_errorInfo.missing_codec = codec.substr(0,(codec.find_first_of(',')));
1423 g_free(description);
1425 gst_caps_unref(caps);
1429 const gchar *eventname = gst_structure_get_name(msgstruct);
1432 if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1434 gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1435 gst_structure_get_int (msgstruct, "width", &m_width);
1436 gst_structure_get_int (msgstruct, "height", &m_height);
1437 if (strstr(eventname, "Changed"))
1438 m_event((iPlayableService*)this, evVideoSizeChanged);
1440 else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1442 gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1443 if (strstr(eventname, "Changed"))
1444 m_event((iPlayableService*)this, evVideoFramerateChanged);
1446 else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1448 gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1449 if (strstr(eventname, "Changed"))
1450 m_event((iPlayableService*)this, evVideoProgressiveChanged);
1457 case GST_MESSAGE_BUFFERING:
1459 GstBufferingMode mode;
1460 gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
1461 gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
1462 m_event((iPlayableService*)this, evBuffering);
1465 case GST_MESSAGE_STREAM_STATUS:
1467 GstStreamStatusType type;
1469 gst_message_parse_stream_status (msg, &type, &owner);
1470 if ( type == GST_STREAM_STATUS_TYPE_CREATE && m_sourceinfo.is_streaming )
1472 if ( GST_IS_PAD(source) )
1473 owner = gst_pad_get_parent_element(GST_PAD(source));
1474 else if ( GST_IS_ELEMENT(source) )
1475 owner = GST_ELEMENT(source);
1480 GstElementFactory *factory = gst_element_get_factory(GST_ELEMENT(owner));
1481 const gchar *name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
1482 if (!strcmp(name, "souphttpsrc"))
1484 m_streamingsrc_timeout->start(HTTP_TIMEOUT*1000, true);
1485 g_object_set (G_OBJECT (owner), "timeout", HTTP_TIMEOUT, NULL);
1486 eDebug("eServiceMP3::GST_STREAM_STATUS_TYPE_CREATE -> setting timeout on %s to %is", name, HTTP_TIMEOUT);
1489 else if (m_is_hls_stream && !strncmp(name, "queue", 5))
1491 m_streamingsrc_timeout->stop();
1492 m_is_hls_stream = 0;
1493 //eDebug("Stoped response timeout!! : HLS");
1496 if ( GST_IS_PAD(source) )
1497 gst_object_unref(owner);
1504 g_free (sourceName);
1507 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1509 eServiceMP3 *_this = (eServiceMP3*)user_data;
1510 _this->m_pump.send(Message(1));
1512 return GST_BUS_PASS;
1515 void eServiceMP3::gstHTTPSourceSetAgent(GObject *object, GParamSpec *unused, gpointer user_data)
1517 eServiceMP3 *_this = (eServiceMP3*)user_data;
1519 g_object_get(_this->m_gst_playbin, "source", &source, NULL);
1520 g_object_set (G_OBJECT (source), "user-agent", _this->m_useragent.c_str(), NULL);
1521 gst_object_unref(source);
1524 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1529 if ( gst_structure_has_name (structure, "audio/mpeg"))
1531 gint mpegversion, layer = -1;
1532 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1535 switch (mpegversion) {
1538 gst_structure_get_int (structure, "layer", &layer);
1554 else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1556 else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1558 else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1564 void eServiceMP3::gstPoll(const Message &msg)
1568 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
1569 GstMessage *message;
1570 while ((message = gst_bus_pop(bus)))
1572 gstBusCall(bus, message);
1573 gst_message_unref (message);
1576 else if (msg.type == 2)
1578 else if (msg.type == 3)
1579 gstTextpadHasCAPS_synced(msg.d.pad);
1581 eDebug("gstPoll unhandled Message %d\n", msg.type);
1584 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1586 void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
1588 eServiceMP3 *_this = (eServiceMP3*)user_data;
1589 eSingleLocker l(_this->m_subs_to_pull_lock);
1590 ++_this->m_subs_to_pull;
1591 _this->m_pump.send(Message(2));
1594 void eServiceMP3::gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data)
1596 eServiceMP3 *_this = (eServiceMP3*)user_data;
1598 gst_object_ref (pad);
1600 _this->m_pump.send(Message(3, pad));
1603 // after messagepump
1604 void eServiceMP3::gstTextpadHasCAPS_synced(GstPad *pad)
1608 g_object_get (G_OBJECT (pad), "caps", &caps, NULL);
1610 eDebug("gstTextpadHasCAPS:: signal::caps = %s", gst_caps_to_string(caps));
1614 subtitleStream subs;
1616 // eDebug("gstGhostpadHasCAPS_synced %p %d", pad, m_subtitleStreams.size());
1618 if (!m_subtitleStreams.empty())
1619 subs = m_subtitleStreams[m_currentSubtitleStream];
1621 subs.type = stUnknown;
1625 if ( subs.type == stUnknown )
1628 // eDebug("gstGhostpadHasCAPS::m_subtitleStreams[%i].type == stUnknown...", m_currentSubtitleStream);
1631 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", m_currentSubtitleStream, &tags);
1633 g_lang = g_strdup_printf ("und");
1634 if ( tags && gst_is_tag_list(tags) )
1635 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1637 subs.language_code = std::string(g_lang);
1638 subs.type = getSubtitleType(pad);
1640 if (!m_subtitleStreams.empty())
1641 m_subtitleStreams[m_currentSubtitleStream] = subs;
1643 m_subtitleStreams.push_back(subs);
1648 // 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));
1650 gst_caps_unref (caps);
1653 gst_object_unref (pad);
1656 void eServiceMP3::pullSubtitle()
1659 g_object_get (G_OBJECT (m_gst_playbin), "text-sink", &sink, NULL);
1663 while (m_subs_to_pull && m_subtitle_pages.size() < 2)
1667 eSingleLocker l(m_subs_to_pull_lock);
1669 g_signal_emit_by_name (sink, "pull-buffer", &buffer);
1673 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1674 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1675 size_t len = GST_BUFFER_SIZE(buffer);
1676 eDebug("pullSubtitle m_subtitleStreams[m_currentSubtitleStream].type=%i",m_subtitleStreams[m_currentSubtitleStream].type);
1678 if ( m_subtitleStreams[m_currentSubtitleStream].type )
1680 if ( m_subtitleStreams[m_currentSubtitleStream].type < stVOB )
1682 unsigned char line[len+1];
1684 memcpy(line, GST_BUFFER_DATA(buffer), len);
1686 eDebug("got new text subtitle @ buf_pos = %lld ns (in pts=%lld): '%s' ", buf_pos, buf_pos/11111, line);
1687 gRGB rgbcol(0xD0,0xD0,0xD0);
1688 page.type = SubtitlePage::Pango;
1689 page.pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
1690 page.pango_page.m_show_pts = buf_pos / 11111L;
1691 page.pango_page.m_timeout = duration_ns / 1000000;
1692 m_subtitle_pages.push_back(page);
1693 if (m_subtitle_pages.size()==1)
1698 eDebug("unsupported subpicture... ignoring");
1701 gst_buffer_unref(buffer);
1704 gst_object_unref(sink);
1707 eDebug("no subtitle sink!");
1710 void eServiceMP3::pushSubtitles()
1712 while ( !m_subtitle_pages.empty() )
1714 SubtitlePage &frontpage = m_subtitle_pages.front();
1717 gint64 show_pts = 0;
1719 getPlayPosition(running_pts);
1721 if (m_decoder_time_valid_state < 4) {
1722 ++m_decoder_time_valid_state;
1723 if (m_prev_decoder_time == running_pts)
1724 m_decoder_time_valid_state = 0;
1725 if (m_decoder_time_valid_state < 4) {
1726 // if (m_decoder_time_valid_state)
1727 // eDebug("%d: decoder time not valid! prev %lld, now %lld\n", m_decoder_time_valid_state, m_prev_decoder_time/90, running_pts/90);
1729 // eDebug("%d: decoder time not valid! now %lld\n", m_decoder_time_valid_state, running_pts/90);
1730 m_subtitle_sync_timer->start(25, true);
1731 m_prev_decoder_time = running_pts;
1736 if (frontpage.type == SubtitlePage::Pango)
1737 show_pts = frontpage.pango_page.m_show_pts;
1739 diff_ms = ( show_pts - running_pts ) / 90;
1740 eDebug("check subtitle: decoder: %lld, show_pts: %lld, diff: %lld ms", running_pts/90, show_pts/90, diff_ms);
1742 if ( diff_ms < -100 )
1744 eDebug("subtitle too late... drop");
1745 m_subtitle_pages.pop_front();
1747 else if ( diff_ms > 20 )
1749 eDebug("start timer");
1750 m_subtitle_sync_timer->start(diff_ms, true);
1753 else // immediate show
1755 if ( m_subtitle_widget )
1758 if ( frontpage.type == SubtitlePage::Pango)
1759 m_subtitle_widget->setPage(frontpage.pango_page);
1760 m_subtitle_widget->show();
1762 m_subtitle_pages.pop_front();
1765 if (m_subtitle_pages.empty())
1770 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
1772 eDebug ("eServiceMP3::enableSubtitles m_currentSubtitleStream=%i this=%p",m_currentSubtitleStream, this);
1774 int tuplesize = PyTuple_Size(tuple);
1777 eSingleLocker l(m_subs_to_pull_lock);
1780 // g_signal_emit_by_name (m_gst_playbin, "get-text-pad", m_currentSubtitleStream, &pad);
1781 // gst_element_get_static_pad(m_gst_subtitlebin, "sink");
1782 // gulong subprobe_handler_id = gst_pad_add_buffer_probe (pad, G_CALLBACK (gstCBsubtitleDrop), NULL);
1784 if (!PyTuple_Check(tuple))
1788 entry = PyTuple_GET_ITEM(tuple, 1);
1789 if (!PyInt_Check(entry))
1791 pid = PyInt_AsLong(entry);
1792 entry = PyTuple_GET_ITEM(tuple, 2);
1793 if (!PyInt_Check(entry))
1795 type = PyInt_AsLong(entry);
1797 if (m_currentSubtitleStream != pid)
1799 g_object_set (G_OBJECT (m_gst_playbin), "current-text", pid, NULL);
1800 eDebug ("eServiceMP3::enableSubtitles g_object_set current-text = %i", pid);
1801 m_currentSubtitleStream = pid;
1803 m_prev_decoder_time = -1;
1804 m_subtitle_pages.clear();
1807 m_subtitle_widget = 0;
1808 m_subtitle_widget = new eSubtitleWidget(parent);
1809 m_subtitle_widget->resize(parent->size()); /* full size */
1811 g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
1813 eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
1814 // gst_pad_remove_buffer_probe (pad, subprobe_handler_id);
1816 m_event((iPlayableService*)this, evUpdatedInfo);
1821 eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
1822 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
1826 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
1828 eDebug("eServiceMP3::disableSubtitles");
1829 m_subtitle_pages.clear();
1830 delete m_subtitle_widget;
1831 m_subtitle_widget = 0;
1835 PyObject *eServiceMP3::getCachedSubtitle()
1837 // eDebug("eServiceMP3::getCachedSubtitle");
1841 PyObject *eServiceMP3::getSubtitleList()
1843 // eDebug("eServiceMP3::getSubtitleList");
1844 ePyObject l = PyList_New(0);
1847 for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
1849 subtype_t type = IterSubtitleStream->type;
1858 ePyObject tuple = PyTuple_New(5);
1859 // eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
1860 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1861 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
1862 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
1863 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
1864 PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
1865 PyList_Append(l, tuple);
1871 eDebug("eServiceMP3::getSubtitleList finished");
1875 RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
1881 PyObject *eServiceMP3::getBufferCharge()
1883 ePyObject tuple = PyTuple_New(5);
1884 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
1885 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
1886 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
1887 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
1888 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
1892 int eServiceMP3::setBufferSize(int size)
1894 m_buffer_size = size;
1895 g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
1899 int eServiceMP3::getAC3Delay()
1904 int eServiceMP3::getPCMDelay()
1909 void eServiceMP3::setAC3Delay(int delay)
1912 if (!m_gst_playbin || m_state != stRunning)
1917 int config_delay_int = delay;
1918 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1922 std::string config_delay;
1923 if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
1924 config_delay_int += atoi(config_delay.c_str());
1925 gst_object_unref(sink);
1929 eDebug("dont apply ac3 delay when no video is running!");
1930 config_delay_int = 0;
1933 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1937 gchar *name = gst_element_get_name(sink);
1938 if (strstr(name, "dvbaudiosink"))
1939 eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
1941 gst_object_unref(sink);
1946 void eServiceMP3::setPCMDelay(int delay)
1949 if (!m_gst_playbin || m_state != stRunning)
1954 int config_delay_int = delay;
1955 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1959 std::string config_delay;
1960 if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
1961 config_delay_int += atoi(config_delay.c_str());
1962 gst_object_unref(sink);
1966 eDebug("dont apply pcm delay when no video is running!");
1967 config_delay_int = 0;
1970 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1974 gchar *name = gst_element_get_name(sink);
1975 if (strstr(name, "dvbaudiosink"))
1976 eTSMPEGDecoder::setHwPCMDelay(config_delay_int);
1979 // this is realy untested..and not used yet
1980 gint64 offset = config_delay_int;
1981 offset *= 1000000; // milli to nano
1982 g_object_set (G_OBJECT (m_gst_playbin), "ts-offset", offset, NULL);
1985 gst_object_unref(sink);