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 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
54 m_service_info = new eStaticServiceMP3Info();
57 eServiceFactoryMP3::~eServiceFactoryMP3()
59 ePtr<eServiceCenter> sc;
61 eServiceCenter::getPrivInstance(sc);
63 sc->removeServiceFactory(eServiceFactoryMP3::id);
66 DEFINE_REF(eServiceFactoryMP3)
69 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
72 ptr = new eServiceMP3(ref);
76 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
82 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
88 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
94 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
96 DECLARE_REF(eMP3ServiceOfflineOperations);
97 eServiceReference m_ref;
99 eMP3ServiceOfflineOperations(const eServiceReference &ref);
101 RESULT deleteFromDisk(int simulate);
102 RESULT getListOfFilenames(std::list<std::string> &);
106 DEFINE_REF(eMP3ServiceOfflineOperations);
108 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
112 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
118 std::list<std::string> res;
119 if (getListOfFilenames(res))
122 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
124 eDebug("FATAL !! can't get background file eraser");
126 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
128 eDebug("Removing %s...", i->c_str());
130 eraser->erase(i->c_str());
132 ::unlink(i->c_str());
139 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
142 res.push_back(m_ref.path);
146 RESULT eMP3ServiceOfflineOperations::reindex()
152 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
154 ptr = new eMP3ServiceOfflineOperations(ref);
158 // eStaticServiceMP3Info
161 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
162 // about unopened files.
164 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
165 // should have a database backend where ID3-files etc. are cached.
166 // this would allow listing the mp3 database based on certain filters.
168 DEFINE_REF(eStaticServiceMP3Info)
170 eStaticServiceMP3Info::eStaticServiceMP3Info()
174 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
176 if ( ref.name.length() )
180 size_t last = ref.path.rfind('/');
181 if (last != std::string::npos)
182 name = ref.path.substr(last+1);
189 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
194 int eStaticServiceMP3Info::getInfo(const eServiceReference &ref, int w)
198 case iServiceInformation::sTimeCreate:
201 if(stat(ref.path.c_str(), &s) == 0)
205 return iServiceInformation::resNA;
209 return iServiceInformation::resNA;
214 int eServiceMP3::ac3_delay,
215 eServiceMP3::pcm_delay;
217 eServiceMP3::eServiceMP3(eServiceReference ref)
218 :m_ref(ref), m_pump(eApp, 1)
220 m_seekTimeout = eTimer::create(eApp);
221 m_subtitle_sync_timer = eTimer::create(eApp);
222 m_streamingsrc_timeout = 0;
224 m_currentAudioStream = -1;
225 m_currentSubtitleStream = 0;
226 m_subtitle_widget = 0;
227 m_currentTrickRatio = 0;
229 m_buffer_size = 1*1024*1024;
230 m_prev_decoder_time = -1;
231 m_decoder_time_valid_state = 0;
232 m_errorInfo.missing_codec = "";
236 CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
237 CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
238 CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
239 m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
242 eDebug("eServiceMP3::construct!");
244 const char *filename = m_ref.path.c_str();
245 const char *ext = strrchr(filename, '.');
249 m_sourceinfo.is_video = FALSE;
250 m_sourceinfo.audiotype = atUnknown;
251 if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
253 m_sourceinfo.containertype = ctMPEGPS;
254 m_sourceinfo.is_video = TRUE;
256 else if ( strcasecmp(ext, ".ts") == 0 )
258 m_sourceinfo.containertype = ctMPEGTS;
259 m_sourceinfo.is_video = TRUE;
261 else if ( strcasecmp(ext, ".mkv") == 0 )
263 m_sourceinfo.containertype = ctMKV;
264 m_sourceinfo.is_video = TRUE;
266 else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
268 m_sourceinfo.containertype = ctAVI;
269 m_sourceinfo.is_video = TRUE;
271 else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0 || strcasecmp(ext, ".m4v") == 0)
273 m_sourceinfo.containertype = ctMP4;
274 m_sourceinfo.is_video = TRUE;
276 else if ( strcasecmp(ext, ".m4a") == 0 )
278 m_sourceinfo.containertype = ctMP4;
279 m_sourceinfo.audiotype = atAAC;
281 else if ( strcasecmp(ext, ".mp3") == 0 )
282 m_sourceinfo.audiotype = atMP3;
283 else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
284 m_sourceinfo.containertype = ctCDA;
285 if ( strcasecmp(ext, ".dat") == 0 )
287 m_sourceinfo.containertype = ctVCD;
288 m_sourceinfo.is_video = TRUE;
290 if ( strstr(filename, "://") )
291 m_sourceinfo.is_streaming = TRUE;
295 if ( m_sourceinfo.is_streaming )
297 uri = g_strdup_printf ("%s", filename);
298 m_streamingsrc_timeout = eTimer::create(eApp);;
299 CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
301 std::string config_str;
302 if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
304 if ( config_str == "True" )
305 ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
307 if ( m_useragent.length() == 0 )
308 m_useragent = "Dream Multimedia Dreambox Enigma2 Mediaplayer";
310 else if ( m_sourceinfo.containertype == ctCDA )
312 int i_track = atoi(filename+18);
313 uri = g_strdup_printf ("cdda://%i", i_track);
315 else if ( m_sourceinfo.containertype == ctVCD )
317 int fd = open(filename,O_RDONLY);
319 int ret = read(fd, tmp, 128*1024);
321 if ( ret == -1 ) // this is a "REAL" VCD
322 uri = g_strdup_printf ("vcd://");
324 uri = g_filename_to_uri(filename, NULL, NULL);
328 uri = g_filename_to_uri(filename, NULL, NULL);
330 eDebug("eServiceMP3::playbin2 uri=%s", uri);
332 m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
334 m_errorInfo.error_message = "failed to create GStreamer pipeline!\n";
336 g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
338 int flags = 0x47; // ( GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT );
339 g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
343 GstElement *subsink = gst_element_factory_make("appsink", "subtitle_sink");
345 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
348 m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
349 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);
350 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
356 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), gstBusSyncHandler, this);
357 char srt_filename[strlen(filename)+1];
358 strncpy(srt_filename,filename,strlen(filename)-3);
359 srt_filename[strlen(filename)-3]='\0';
360 strcat(srt_filename, "srt");
362 if (stat(srt_filename, &buffer) == 0)
364 eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
365 g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
367 if ( m_sourceinfo.is_streaming )
369 g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
373 m_event((iPlayableService*)this, evUser+12);
376 gst_object_unref(GST_OBJECT(m_gst_playbin));
378 eDebug("eServiceMP3::sorry, can't play: %s",m_errorInfo.error_message.c_str());
382 setBufferSize(m_buffer_size);
385 eServiceMP3::~eServiceMP3()
387 // disconnect subtitle callback
388 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
392 g_signal_handler_disconnect (appsink, m_subs_to_pull_handler_id);
393 gst_object_unref(appsink);
396 delete m_subtitle_widget;
398 // disconnect sync handler callback
399 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), NULL, NULL);
401 if (m_state == stRunning)
405 gst_tag_list_free(m_stream_tags);
409 gst_object_unref (GST_OBJECT (m_gst_playbin));
410 eDebug("eServiceMP3::destruct!");
414 DEFINE_REF(eServiceMP3);
416 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
418 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
422 RESULT eServiceMP3::start()
424 ASSERT(m_state == stIdle);
429 eDebug("eServiceMP3::starting pipeline");
430 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
433 m_event(this, evStart);
438 void eServiceMP3::sourceTimeout()
440 eDebug("eServiceMP3::http source timeout! issuing eof...");
441 m_event((iPlayableService*)this, evEOF);
444 RESULT eServiceMP3::stop()
446 ASSERT(m_state != stIdle);
448 if (m_state == stStopped)
451 //GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_gst_playbin),GST_DEBUG_GRAPH_SHOW_ALL,"e2-playbin");
453 eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
454 gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
460 RESULT eServiceMP3::setTarget(int target)
465 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
471 RESULT eServiceMP3::setSlowMotion(int ratio)
475 eDebug("eServiceMP3::setSlowMotion ratio=%f",1/(float)ratio);
476 return trickSeek(1/(float)ratio);
479 RESULT eServiceMP3::setFastForward(int ratio)
481 eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
482 return trickSeek(ratio);
485 void eServiceMP3::seekTimeoutCB()
488 getPlayPosition(ppos);
490 ppos += 90000*m_currentTrickRatio;
495 m_seekTimeout->stop();
501 m_seekTimeout->stop();
508 RESULT eServiceMP3::pause()
510 if (!m_gst_playbin || m_state != stRunning)
513 gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
518 RESULT eServiceMP3::unpause()
520 if (!m_gst_playbin || m_state != stRunning)
523 gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
528 /* iSeekableService */
529 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
535 RESULT eServiceMP3::getLength(pts_t &pts)
540 if (m_state != stRunning)
543 GstFormat fmt = GST_FORMAT_TIME;
546 if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
548 /* len is in nanoseconds. we have 90 000 pts per second. */
554 RESULT eServiceMP3::seekToImpl(pts_t to)
556 /* convert pts to nanoseconds */
557 gint64 time_nanoseconds = to * 11111LL;
558 if (!gst_element_seek (m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
559 GST_SEEK_TYPE_SET, time_nanoseconds,
560 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
562 eDebug("eServiceMP3::seekTo failed");
569 RESULT eServiceMP3::seekTo(pts_t to)
574 eSingleLocker l(m_subs_to_pull_lock); // this is needed to dont handle incomming subtitles during seek!
575 if (!(ret = seekToImpl(to)))
577 m_subtitle_pages.clear();
578 m_prev_decoder_time = -1;
579 m_decoder_time_valid_state = 0;
588 RESULT eServiceMP3::trickSeek(gdouble ratio)
593 return seekRelative(0, 0);
597 flags = GST_SEEK_FLAG_NONE;
598 flags |= GST_SEEK_FLAG_FLUSH;
599 // flags |= GstSeekFlags (GST_SEEK_FLAG_ACCURATE);
600 flags |= GST_SEEK_FLAG_KEY_UNIT;
601 // flags |= GstSeekFlags (GST_SEEK_FLAG_SEGMENT);
602 // flags |= GstSeekFlags (GST_SEEK_FLAG_SKIP);
604 GstFormat fmt = GST_FORMAT_TIME;
606 gst_element_query_duration(m_gst_playbin, &fmt, &len);
607 gst_element_query_position(m_gst_playbin, &fmt, &pos);
611 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, (GstSeekFlags)flags, GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, len);
613 eDebug("eServiceMP3::trickSeek with rate %lf to %" GST_TIME_FORMAT " ", ratio, GST_TIME_ARGS (pos));
617 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);
620 if (!gst_element_send_event ( GST_ELEMENT (m_gst_playbin), s_event))
622 eDebug("eServiceMP3::trickSeek failed");
630 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
636 getPlayPosition(ppos);
637 ppos += to * direction;
645 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
647 GstFormat fmt = GST_FORMAT_TIME;
654 if (m_state != stRunning)
657 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
660 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
665 gchar *name = gst_element_get_name(sink);
666 gboolean use_get_decoder_time = strstr(name, "dvbaudiosink") || strstr(name, "dvbvideosink");
669 if (use_get_decoder_time)
670 g_signal_emit_by_name(sink, "get-decoder-time", &pos);
672 gst_object_unref(sink);
674 if (!use_get_decoder_time && !gst_element_query_position(m_gst_playbin, &fmt, &pos)) {
675 eDebug("gst_element_query_position failed in getPlayPosition");
679 /* pos is in nanoseconds. we have 90 000 pts per second. */
681 // eDebug("gst_element_query_position %lld pts (%lld ms)", pts, pos/1000000);
685 RESULT eServiceMP3::setTrickmode(int trick)
687 /* trickmode is not yet supported by our dvbmediasinks. */
691 RESULT eServiceMP3::isCurrentlySeekable()
693 int ret = 3; // seeking and fast/slow winding possible
698 if (m_state != stRunning)
701 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
703 // disable fast winding yet when a dvbvideosink or dvbaudiosink is used
704 // for this we must do some changes on different places.. (gstreamer.. our sinks.. enigma2)
706 ret &= ~2; // only seeking possible
707 gst_object_unref(sink);
710 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
712 ret &= ~2; // only seeking possible
713 gst_object_unref(sink);
720 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
726 RESULT eServiceMP3::getName(std::string &name)
728 std::string title = m_ref.getName();
732 size_t n = name.rfind('/');
733 if (n != std::string::npos)
734 name = name.substr(n + 1);
741 int eServiceMP3::getInfo(int w)
743 const gchar *tag = 0;
747 case sServiceref: return m_ref;
748 case sVideoHeight: return m_height;
749 case sVideoWidth: return m_width;
750 case sFrameRate: return m_framerate;
751 case sProgressive: return m_progressive;
752 case sAspect: return m_aspect;
756 case sTagTitleSortname:
757 case sTagArtistSortname:
758 case sTagAlbumSortname:
763 case sTagExtendedComment:
766 case sTagDescription:
769 case sTagOrganization:
771 case sTagCopyrightURI:
779 case sTagLanguageCode:
781 case sTagChannelMode:
788 case sTagReferenceLevel:
789 case sTagBeatsPerMinute:
791 case sTagPreviewImage:
793 return resIsPyObject;
794 case sTagTrackNumber:
795 tag = GST_TAG_TRACK_NUMBER;
798 tag = GST_TAG_TRACK_COUNT;
800 case sTagAlbumVolumeNumber:
801 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
803 case sTagAlbumVolumeCount:
804 tag = GST_TAG_ALBUM_VOLUME_COUNT;
807 tag = GST_TAG_BITRATE;
809 case sTagNominalBitrate:
810 tag = GST_TAG_NOMINAL_BITRATE;
812 case sTagMinimumBitrate:
813 tag = GST_TAG_MINIMUM_BITRATE;
815 case sTagMaximumBitrate:
816 tag = GST_TAG_MAXIMUM_BITRATE;
819 tag = GST_TAG_SERIAL;
821 case sTagEncoderVersion:
822 tag = GST_TAG_ENCODER_VERSION;
831 if (!m_stream_tags || !tag)
835 if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
841 std::string eServiceMP3::getInfoString(int w)
843 if ( !m_stream_tags && w < sUser && w > 26 )
845 const gchar *tag = 0;
852 tag = GST_TAG_ARTIST;
857 case sTagTitleSortname:
858 tag = GST_TAG_TITLE_SORTNAME;
860 case sTagArtistSortname:
861 tag = GST_TAG_ARTIST_SORTNAME;
863 case sTagAlbumSortname:
864 tag = GST_TAG_ALBUM_SORTNAME;
868 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
871 g_date_strftime (res, sizeof(res), "%Y-%M-%D", date);
872 return (std::string)res;
876 tag = GST_TAG_COMPOSER;
882 tag = GST_TAG_COMMENT;
884 case sTagExtendedComment:
885 tag = GST_TAG_EXTENDED_COMMENT;
888 tag = GST_TAG_LOCATION;
891 tag = GST_TAG_HOMEPAGE;
893 case sTagDescription:
894 tag = GST_TAG_DESCRIPTION;
897 tag = GST_TAG_VERSION;
902 case sTagOrganization:
903 tag = GST_TAG_ORGANIZATION;
906 tag = GST_TAG_COPYRIGHT;
908 case sTagCopyrightURI:
909 tag = GST_TAG_COPYRIGHT_URI;
912 tag = GST_TAG_CONTACT;
915 tag = GST_TAG_LICENSE;
918 tag = GST_TAG_LICENSE_URI;
924 tag = GST_TAG_AUDIO_CODEC;
927 tag = GST_TAG_VIDEO_CODEC;
930 tag = GST_TAG_ENCODER;
932 case sTagLanguageCode:
933 tag = GST_TAG_LANGUAGE_CODE;
936 tag = GST_TAG_KEYWORDS;
938 case sTagChannelMode:
939 tag = "channel-mode";
942 return m_errorInfo.error_message;
949 if (gst_tag_list_get_string(m_stream_tags, tag, &value))
951 std::string res = value;
958 PyObject *eServiceMP3::getInfoObject(int w)
960 const gchar *tag = 0;
961 bool isBuffer = false;
965 tag = GST_TAG_TRACK_GAIN;
968 tag = GST_TAG_TRACK_PEAK;
971 tag = GST_TAG_ALBUM_GAIN;
974 tag = GST_TAG_ALBUM_PEAK;
976 case sTagReferenceLevel:
977 tag = GST_TAG_REFERENCE_LEVEL;
979 case sTagBeatsPerMinute:
980 tag = GST_TAG_BEATS_PER_MINUTE;
986 case sTagPreviewImage:
987 tag = GST_TAG_PREVIEW_IMAGE;
991 tag = GST_TAG_ATTACHMENT;
1000 const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
1004 buffer = gst_value_get_buffer (gv_buffer);
1005 return PyBuffer_FromMemory(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
1010 gdouble value = 0.0;
1011 gst_tag_list_get_double(m_stream_tags, tag, &value);
1012 return PyFloat_FromDouble(value);
1018 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
1024 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
1030 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
1036 RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
1042 int eServiceMP3::getNumberOfTracks()
1044 return m_audioStreams.size();
1047 int eServiceMP3::getCurrentTrack()
1049 if (m_currentAudioStream == -1)
1050 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
1051 return m_currentAudioStream;
1054 RESULT eServiceMP3::selectTrack(unsigned int i)
1057 getPlayPosition(ppos);
1062 int ret = selectAudioStream(i);
1071 int eServiceMP3::selectAudioStream(int i)
1074 g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
1075 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", ¤t_audio, NULL);
1076 if ( current_audio == i )
1078 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
1079 m_currentAudioStream = i;
1085 int eServiceMP3::getCurrentChannel()
1090 RESULT eServiceMP3::selectChannel(int i)
1092 eDebug("eServiceMP3::selectChannel(%i)",i);
1096 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
1098 if (i >= m_audioStreams.size())
1100 info.m_description = m_audioStreams[i].codec;
1101 /* if (m_audioStreams[i].type == atMPEG)
1102 info.m_description = "MPEG";
1103 else if (m_audioStreams[i].type == atMP3)
1104 info.m_description = "MP3";
1105 else if (m_audioStreams[i].type == atAC3)
1106 info.m_description = "AC3";
1107 else if (m_audioStreams[i].type == atAAC)
1108 info.m_description = "AAC";
1109 else if (m_audioStreams[i].type == atDTS)
1110 info.m_description = "DTS";
1111 else if (m_audioStreams[i].type == atPCM)
1112 info.m_description = "PCM";
1113 else if (m_audioStreams[i].type == atOGG)
1114 info.m_description = "OGG";
1115 else if (m_audioStreams[i].type == atFLAC)
1116 info.m_description = "FLAC";
1118 info.m_description = "???";*/
1119 if (info.m_language.empty())
1120 info.m_language = m_audioStreams[i].language_code;
1124 subtype_t getSubtitleType(GstPad* pad, gchar *g_codec=NULL)
1126 subtype_t type = stUnknown;
1127 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1131 GstStructure* str = gst_caps_get_structure(caps, 0);
1132 const gchar *g_type = gst_structure_get_name(str);
1133 eDebug("getSubtitleType::subtitle probe caps type=%s", g_type);
1135 if ( !strcmp(g_type, "video/x-dvd-subpicture") )
1137 else if ( !strcmp(g_type, "text/x-pango-markup") )
1139 else if ( !strcmp(g_type, "text/plain") )
1141 else if ( !strcmp(g_type, "subpicture/x-pgs") )
1144 eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec);
1148 eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec);
1149 if ( !strcmp(g_codec, "VOB") )
1151 else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") )
1153 else if ( !strcmp(g_codec, "ASS") )
1155 else if ( !strcmp(g_codec, "UTF-8 plain text") )
1158 eDebug("getSubtitleType::unsupported subtitle codec %s", g_codec);
1161 eDebug("getSubtitleType::unidentifiable subtitle stream!");
1166 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
1172 source = GST_MESSAGE_SRC(msg);
1173 if (!GST_IS_OBJECT(source))
1175 sourceName = gst_object_get_name(source);
1178 if (gst_message_get_structure(msg))
1179 string = gst_structure_to_string(gst_message_get_structure(msg));
1181 string = g_strdup(GST_MESSAGE_TYPE_NAME(msg));
1182 eDebug("eTsRemoteSource::gst_message from %s: %s", sourceName, string);
1185 switch (GST_MESSAGE_TYPE (msg))
1187 case GST_MESSAGE_EOS:
1188 m_event((iPlayableService*)this, evEOF);
1190 case GST_MESSAGE_STATE_CHANGED:
1192 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1195 if(!strncmp(sourceName, "hls", 3))
1197 //eDebug("HLS Protocol detected : source [%s]", sourceName);
1198 m_is_hls_stream = 1;
1203 GstState old_state, new_state;
1204 gst_message_parse_state_changed(msg, &old_state, &new_state, NULL);
1206 if(old_state == new_state)
1209 eDebug("eServiceMP3::state transition %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
1211 GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state);
1215 case GST_STATE_CHANGE_NULL_TO_READY:
1218 case GST_STATE_CHANGE_READY_TO_PAUSED:
1220 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1223 g_object_set (G_OBJECT (appsink), "max-buffers", 2, NULL);
1224 g_object_set (G_OBJECT (appsink), "sync", FALSE, NULL);
1225 g_object_set (G_OBJECT (appsink), "emit-signals", TRUE, NULL);
1226 eDebug("eServiceMP3::appsink properties set!");
1227 gst_object_unref(appsink);
1229 setAC3Delay(ac3_delay);
1230 setPCMDelay(pcm_delay);
1232 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1234 if ( m_sourceinfo.is_streaming && m_streamingsrc_timeout )
1235 m_streamingsrc_timeout->stop();
1237 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1240 case GST_STATE_CHANGE_PAUSED_TO_READY:
1243 case GST_STATE_CHANGE_READY_TO_NULL:
1249 case GST_MESSAGE_ERROR:
1253 gst_message_parse_error (msg, &err, &debug);
1255 eWarning("Gstreamer error: %s (domain:%i, code:%i) from %s", err->message, err->domain, err->code, sourceName );
1256 if ( err->domain == GST_STREAM_ERROR )
1258 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1260 if ( g_strrstr(sourceName, "videosink") )
1261 m_event((iPlayableService*)this, evUser+11);
1262 else if ( g_strrstr(sourceName, "audiosink") )
1263 m_event((iPlayableService*)this, evUser+10);
1266 else //if( err->domain == 1232 )
1268 if ( err->code == 5 )
1269 m_event((iPlayableService*)this, evUser+20);
1274 case GST_MESSAGE_INFO:
1279 gst_message_parse_info (msg, &inf, &debug);
1281 if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1283 if ( g_strrstr(sourceName, "videosink") )
1284 m_event((iPlayableService*)this, evUser+14);
1289 case GST_MESSAGE_TAG:
1291 GstTagList *tags, *result;
1292 gst_message_parse_tag(msg, &tags);
1294 result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE);
1298 gst_tag_list_free(m_stream_tags);
1299 m_stream_tags = result;
1302 const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1305 GstBuffer *buf_image;
1306 buf_image = gst_value_get_buffer (gv_image);
1307 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1308 int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image));
1310 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1311 m_event((iPlayableService*)this, evUser+13);
1313 gst_tag_list_free(tags);
1314 m_event((iPlayableService*)this, evUpdatedInfo);
1317 case GST_MESSAGE_ASYNC_DONE:
1319 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1323 gint i, active_idx, n_video = 0, n_audio = 0, n_text = 0;
1325 g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1326 g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1327 g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1329 eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1331 if ( n_video + n_audio <= 0 )
1336 m_audioStreams.clear();
1337 m_subtitleStreams.clear();
1339 for (i = 0; i < n_audio; i++)
1342 gchar *g_codec, *g_lang;
1344 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1345 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1348 GstStructure* str = gst_caps_get_structure(caps, 0);
1349 const gchar *g_type = gst_structure_get_name(str);
1350 audio.type = gstCheckAudioPad(str);
1351 g_codec = g_strdup(g_type);
1352 g_lang = g_strdup_printf ("und");
1353 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1354 if ( tags && gst_is_tag_list(tags) )
1356 gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1357 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1358 gst_tag_list_free(tags);
1360 audio.language_code = std::string(g_lang);
1361 audio.codec = std::string(g_codec);
1362 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1363 m_audioStreams.push_back(audio);
1366 gst_caps_unref(caps);
1369 for (i = 0; i < n_text; i++)
1371 gchar *g_codec = NULL, *g_lang = NULL;
1372 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1373 subtitleStream subs;
1376 g_lang = g_strdup_printf ("und");
1377 if ( tags && gst_is_tag_list(tags) )
1379 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1380 gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec);
1381 gst_tag_list_free(tags);
1384 subs.language_code = std::string(g_lang);
1385 eDebug("eServiceMP3::subtitle stream=%i language=%s codec=%s", i, g_lang, g_codec);
1388 g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1390 g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
1391 subs.type = getSubtitleType(pad, g_codec);
1393 m_subtitleStreams.push_back(subs);
1396 m_event((iPlayableService*)this, evUpdatedEventInfo);
1398 if ( m_errorInfo.missing_codec != "" )
1400 if ( m_errorInfo.missing_codec.find("video/") == 0 || ( m_errorInfo.missing_codec.find("audio/") == 0 && getNumberOfTracks() == 0 ) )
1401 m_event((iPlayableService*)this, evUser+12);
1405 case GST_MESSAGE_ELEMENT:
1407 if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1409 if ( gst_is_missing_plugin_message(msg) )
1412 gst_structure_get (msgstruct, "detail", GST_TYPE_CAPS, &caps, NULL);
1413 std::string codec = (const char*) gst_caps_to_string(caps);
1414 gchar *description = gst_missing_plugin_message_get_description(msg);
1417 eDebug("eServiceMP3::m_errorInfo.missing_codec = %s", codec.c_str());
1418 m_errorInfo.error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1419 m_errorInfo.missing_codec = codec.substr(0,(codec.find_first_of(',')));
1420 g_free(description);
1422 gst_caps_unref(caps);
1426 const gchar *eventname = gst_structure_get_name(msgstruct);
1429 if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1431 gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1432 gst_structure_get_int (msgstruct, "width", &m_width);
1433 gst_structure_get_int (msgstruct, "height", &m_height);
1434 if (strstr(eventname, "Changed"))
1435 m_event((iPlayableService*)this, evVideoSizeChanged);
1437 else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1439 gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1440 if (strstr(eventname, "Changed"))
1441 m_event((iPlayableService*)this, evVideoFramerateChanged);
1443 else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1445 gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1446 if (strstr(eventname, "Changed"))
1447 m_event((iPlayableService*)this, evVideoProgressiveChanged);
1454 case GST_MESSAGE_BUFFERING:
1456 GstBufferingMode mode;
1457 gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
1458 gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
1459 m_event((iPlayableService*)this, evBuffering);
1462 case GST_MESSAGE_STREAM_STATUS:
1464 GstStreamStatusType type;
1466 gst_message_parse_stream_status (msg, &type, &owner);
1467 if ( type == GST_STREAM_STATUS_TYPE_CREATE && m_sourceinfo.is_streaming )
1469 if ( GST_IS_PAD(source) )
1470 owner = gst_pad_get_parent_element(GST_PAD(source));
1471 else if ( GST_IS_ELEMENT(source) )
1472 owner = GST_ELEMENT(source);
1477 GstElementFactory *factory = gst_element_get_factory(GST_ELEMENT(owner));
1478 const gchar *name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
1479 if (!strcmp(name, "souphttpsrc"))
1481 m_streamingsrc_timeout->start(HTTP_TIMEOUT*1000, true);
1482 g_object_set (G_OBJECT (owner), "timeout", HTTP_TIMEOUT, NULL);
1483 eDebug("eServiceMP3::GST_STREAM_STATUS_TYPE_CREATE -> setting timeout on %s to %is", name, HTTP_TIMEOUT);
1486 else if (m_is_hls_stream && !strncmp(name, "queue", 5))
1488 m_streamingsrc_timeout->stop();
1489 m_is_hls_stream = 0;
1490 //eDebug("Stoped response timeout!! : HLS");
1493 if ( GST_IS_PAD(source) )
1494 gst_object_unref(owner);
1501 g_free (sourceName);
1504 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1506 eServiceMP3 *_this = (eServiceMP3*)user_data;
1507 _this->m_pump.send(Message(1));
1509 return GST_BUS_PASS;
1512 void eServiceMP3::gstHTTPSourceSetAgent(GObject *object, GParamSpec *unused, gpointer user_data)
1514 eServiceMP3 *_this = (eServiceMP3*)user_data;
1516 g_object_get(_this->m_gst_playbin, "source", &source, NULL);
1517 g_object_set (G_OBJECT (source), "user-agent", _this->m_useragent.c_str(), NULL);
1518 gst_object_unref(source);
1521 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1526 if ( gst_structure_has_name (structure, "audio/mpeg"))
1528 gint mpegversion, layer = -1;
1529 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1532 switch (mpegversion) {
1535 gst_structure_get_int (structure, "layer", &layer);
1551 else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1553 else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1555 else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1561 void eServiceMP3::gstPoll(const Message &msg)
1565 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
1566 GstMessage *message;
1567 while ((message = gst_bus_pop(bus)))
1569 gstBusCall(bus, message);
1570 gst_message_unref (message);
1573 else if (msg.type == 2)
1575 else if (msg.type == 3)
1576 gstTextpadHasCAPS_synced(msg.d.pad);
1578 eDebug("gstPoll unhandled Message %d\n", msg.type);
1581 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1583 void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
1585 eServiceMP3 *_this = (eServiceMP3*)user_data;
1586 eSingleLocker l(_this->m_subs_to_pull_lock);
1587 ++_this->m_subs_to_pull;
1588 _this->m_pump.send(Message(2));
1591 void eServiceMP3::gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data)
1593 eServiceMP3 *_this = (eServiceMP3*)user_data;
1595 gst_object_ref (pad);
1597 _this->m_pump.send(Message(3, pad));
1600 // after messagepump
1601 void eServiceMP3::gstTextpadHasCAPS_synced(GstPad *pad)
1605 g_object_get (G_OBJECT (pad), "caps", &caps, NULL);
1607 eDebug("gstTextpadHasCAPS:: signal::caps = %s", gst_caps_to_string(caps));
1611 subtitleStream subs;
1613 // eDebug("gstGhostpadHasCAPS_synced %p %d", pad, m_subtitleStreams.size());
1615 if (!m_subtitleStreams.empty())
1616 subs = m_subtitleStreams[m_currentSubtitleStream];
1618 subs.type = stUnknown;
1622 if ( subs.type == stUnknown )
1625 // eDebug("gstGhostpadHasCAPS::m_subtitleStreams[%i].type == stUnknown...", m_currentSubtitleStream);
1628 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", m_currentSubtitleStream, &tags);
1630 g_lang = g_strdup_printf ("und");
1631 if ( tags && gst_is_tag_list(tags) )
1632 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1634 subs.language_code = std::string(g_lang);
1635 subs.type = getSubtitleType(pad);
1637 if (!m_subtitleStreams.empty())
1638 m_subtitleStreams[m_currentSubtitleStream] = subs;
1640 m_subtitleStreams.push_back(subs);
1645 // 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));
1647 gst_caps_unref (caps);
1650 gst_object_unref (pad);
1653 void eServiceMP3::pullSubtitle()
1656 g_object_get (G_OBJECT (m_gst_playbin), "text-sink", &sink, NULL);
1660 while (m_subs_to_pull && m_subtitle_pages.size() < 2)
1664 eSingleLocker l(m_subs_to_pull_lock);
1666 g_signal_emit_by_name (sink, "pull-buffer", &buffer);
1670 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1671 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1672 size_t len = GST_BUFFER_SIZE(buffer);
1673 eDebug("pullSubtitle m_subtitleStreams[m_currentSubtitleStream].type=%i",m_subtitleStreams[m_currentSubtitleStream].type);
1675 if ( m_subtitleStreams[m_currentSubtitleStream].type )
1677 if ( m_subtitleStreams[m_currentSubtitleStream].type < stVOB )
1679 unsigned char line[len+1];
1681 memcpy(line, GST_BUFFER_DATA(buffer), len);
1683 eDebug("got new text subtitle @ buf_pos = %lld ns (in pts=%lld): '%s' ", buf_pos, buf_pos/11111, line);
1684 gRGB rgbcol(0xD0,0xD0,0xD0);
1685 page.type = SubtitlePage::Pango;
1686 page.pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
1687 page.pango_page.m_show_pts = buf_pos / 11111L;
1688 page.pango_page.m_timeout = duration_ns / 1000000;
1689 m_subtitle_pages.push_back(page);
1690 if (m_subtitle_pages.size()==1)
1695 eDebug("unsupported subpicture... ignoring");
1698 gst_buffer_unref(buffer);
1701 gst_object_unref(sink);
1704 eDebug("no subtitle sink!");
1707 void eServiceMP3::pushSubtitles()
1709 while ( !m_subtitle_pages.empty() )
1711 SubtitlePage &frontpage = m_subtitle_pages.front();
1714 gint64 show_pts = 0;
1716 getPlayPosition(running_pts);
1718 if (m_decoder_time_valid_state < 4) {
1719 ++m_decoder_time_valid_state;
1720 if (m_prev_decoder_time == running_pts)
1721 m_decoder_time_valid_state = 0;
1722 if (m_decoder_time_valid_state < 4) {
1723 // if (m_decoder_time_valid_state)
1724 // eDebug("%d: decoder time not valid! prev %lld, now %lld\n", m_decoder_time_valid_state, m_prev_decoder_time/90, running_pts/90);
1726 // eDebug("%d: decoder time not valid! now %lld\n", m_decoder_time_valid_state, running_pts/90);
1727 m_subtitle_sync_timer->start(25, true);
1728 m_prev_decoder_time = running_pts;
1733 if (frontpage.type == SubtitlePage::Pango)
1734 show_pts = frontpage.pango_page.m_show_pts;
1736 diff_ms = ( show_pts - running_pts ) / 90;
1737 eDebug("check subtitle: decoder: %lld, show_pts: %lld, diff: %lld ms", running_pts/90, show_pts/90, diff_ms);
1739 if ( diff_ms < -100 )
1741 eDebug("subtitle too late... drop");
1742 m_subtitle_pages.pop_front();
1744 else if ( diff_ms > 20 )
1746 eDebug("start timer");
1747 m_subtitle_sync_timer->start(diff_ms, true);
1750 else // immediate show
1752 if ( m_subtitle_widget )
1755 if ( frontpage.type == SubtitlePage::Pango)
1756 m_subtitle_widget->setPage(frontpage.pango_page);
1757 m_subtitle_widget->show();
1759 m_subtitle_pages.pop_front();
1762 if (m_subtitle_pages.empty())
1767 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
1769 eDebug ("eServiceMP3::enableSubtitles m_currentSubtitleStream=%i this=%p",m_currentSubtitleStream, this);
1771 int tuplesize = PyTuple_Size(tuple);
1774 eSingleLocker l(m_subs_to_pull_lock);
1777 // g_signal_emit_by_name (m_gst_playbin, "get-text-pad", m_currentSubtitleStream, &pad);
1778 // gst_element_get_static_pad(m_gst_subtitlebin, "sink");
1779 // gulong subprobe_handler_id = gst_pad_add_buffer_probe (pad, G_CALLBACK (gstCBsubtitleDrop), NULL);
1781 if (!PyTuple_Check(tuple))
1785 entry = PyTuple_GET_ITEM(tuple, 1);
1786 if (!PyInt_Check(entry))
1788 pid = PyInt_AsLong(entry);
1789 entry = PyTuple_GET_ITEM(tuple, 2);
1790 if (!PyInt_Check(entry))
1792 type = PyInt_AsLong(entry);
1794 if (m_currentSubtitleStream != pid)
1796 g_object_set (G_OBJECT (m_gst_playbin), "current-text", pid, NULL);
1797 eDebug ("eServiceMP3::enableSubtitles g_object_set current-text = %i", pid);
1798 m_currentSubtitleStream = pid;
1800 m_prev_decoder_time = -1;
1801 m_subtitle_pages.clear();
1804 m_subtitle_widget = 0;
1805 m_subtitle_widget = new eSubtitleWidget(parent);
1806 m_subtitle_widget->resize(parent->size()); /* full size */
1808 g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
1810 eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
1811 // gst_pad_remove_buffer_probe (pad, subprobe_handler_id);
1813 m_event((iPlayableService*)this, evUpdatedInfo);
1818 eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
1819 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
1823 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
1825 eDebug("eServiceMP3::disableSubtitles");
1826 m_subtitle_pages.clear();
1827 delete m_subtitle_widget;
1828 m_subtitle_widget = 0;
1832 PyObject *eServiceMP3::getCachedSubtitle()
1834 // eDebug("eServiceMP3::getCachedSubtitle");
1838 PyObject *eServiceMP3::getSubtitleList()
1840 // eDebug("eServiceMP3::getSubtitleList");
1841 ePyObject l = PyList_New(0);
1844 for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
1846 subtype_t type = IterSubtitleStream->type;
1855 ePyObject tuple = PyTuple_New(5);
1856 // eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
1857 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1858 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
1859 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
1860 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
1861 PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
1862 PyList_Append(l, tuple);
1868 eDebug("eServiceMP3::getSubtitleList finished");
1872 RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
1878 PyObject *eServiceMP3::getBufferCharge()
1880 ePyObject tuple = PyTuple_New(5);
1881 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
1882 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
1883 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
1884 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
1885 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
1889 int eServiceMP3::setBufferSize(int size)
1891 m_buffer_size = size;
1892 g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
1896 int eServiceMP3::getAC3Delay()
1901 int eServiceMP3::getPCMDelay()
1906 void eServiceMP3::setAC3Delay(int delay)
1909 if (!m_gst_playbin || m_state != stRunning)
1914 int config_delay_int = delay;
1915 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1919 std::string config_delay;
1920 if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
1921 config_delay_int += atoi(config_delay.c_str());
1922 gst_object_unref(sink);
1926 eDebug("dont apply ac3 delay when no video is running!");
1927 config_delay_int = 0;
1930 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1934 gchar *name = gst_element_get_name(sink);
1935 if (strstr(name, "dvbaudiosink"))
1936 eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
1938 gst_object_unref(sink);
1943 void eServiceMP3::setPCMDelay(int delay)
1946 if (!m_gst_playbin || m_state != stRunning)
1951 int config_delay_int = delay;
1952 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1956 std::string config_delay;
1957 if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
1958 config_delay_int += atoi(config_delay.c_str());
1959 gst_object_unref(sink);
1963 eDebug("dont apply pcm delay when no video is running!");
1964 config_delay_int = 0;
1967 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1971 gchar *name = gst_element_get_name(sink);
1972 if (strstr(name, "dvbaudiosink"))
1973 eTSMPEGDecoder::setHwPCMDelay(config_delay_int);
1976 // this is realy untested..and not used yet
1977 gint64 offset = config_delay_int;
1978 offset *= 1000000; // milli to nano
1979 g_object_set (G_OBJECT (m_gst_playbin), "ts-offset", offset, NULL);
1982 gst_object_unref(sink);