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/epgcache.h>
10 #include <lib/dvb/decoder.h>
11 #include <lib/components/file_eraser.h>
12 #include <lib/gui/esubtitle.h>
13 #include <lib/service/servicemp3.h>
14 #include <lib/service/service.h>
15 #include <lib/gdi/gpixmap.h>
20 #include <gst/pbutils/missing-plugins.h>
23 #define GSTREAMER_SUBTITLE_SYNC_MODE_BUG
25 #define SUBTITLE_DEBUG
27 #define HTTP_TIMEOUT 10
31 GST_PLAY_FLAG_VIDEO = 0x00000001,
32 GST_PLAY_FLAG_AUDIO = 0x00000002,
33 GST_PLAY_FLAG_TEXT = 0x00000004,
34 GST_PLAY_FLAG_VIS = 0x00000008,
35 GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010,
36 GST_PLAY_FLAG_NATIVE_AUDIO = 0x00000020,
37 GST_PLAY_FLAG_NATIVE_VIDEO = 0x00000040,
38 GST_PLAY_FLAG_DOWNLOAD = 0x00000080,
39 GST_PLAY_FLAG_BUFFERING = 0x00000100
44 eServiceFactoryMP3::eServiceFactoryMP3()
46 ePtr<eServiceCenter> sc;
48 eServiceCenter::getPrivInstance(sc);
51 std::list<std::string> extensions;
52 extensions.push_back("mp2");
53 extensions.push_back("mp3");
54 extensions.push_back("ogg");
55 extensions.push_back("mpg");
56 extensions.push_back("vob");
57 extensions.push_back("wav");
58 extensions.push_back("wave");
59 extensions.push_back("m4v");
60 extensions.push_back("mkv");
61 extensions.push_back("avi");
62 extensions.push_back("divx");
63 extensions.push_back("dat");
64 extensions.push_back("flac");
65 extensions.push_back("mp4");
66 extensions.push_back("mov");
67 extensions.push_back("m4a");
68 extensions.push_back("flv");
69 extensions.push_back("3gp");
70 extensions.push_back("3g2");
71 extensions.push_back("dts");
72 extensions.push_back("wmv");
73 extensions.push_back("asf");
74 extensions.push_back("wma");
75 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
78 m_service_info = new eStaticServiceMP3Info();
81 eServiceFactoryMP3::~eServiceFactoryMP3()
83 ePtr<eServiceCenter> sc;
85 eServiceCenter::getPrivInstance(sc);
87 sc->removeServiceFactory(eServiceFactoryMP3::id);
90 DEFINE_REF(eServiceFactoryMP3)
93 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
96 ptr = new eServiceMP3(ref);
100 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
106 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
112 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
114 ptr = m_service_info;
118 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
120 DECLARE_REF(eMP3ServiceOfflineOperations);
121 eServiceReference m_ref;
123 eMP3ServiceOfflineOperations(const eServiceReference &ref);
125 RESULT deleteFromDisk(int simulate);
126 RESULT getListOfFilenames(std::list<std::string> &);
130 DEFINE_REF(eMP3ServiceOfflineOperations);
132 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
136 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
140 std::list<std::string> res;
141 if (getListOfFilenames(res))
144 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
146 eDebug("FATAL !! can't get background file eraser");
148 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
150 eDebug("Removing %s...", i->c_str());
152 eraser->erase(i->c_str());
154 ::unlink(i->c_str());
160 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
163 res.push_back(m_ref.path);
167 RESULT eMP3ServiceOfflineOperations::reindex()
173 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
175 ptr = new eMP3ServiceOfflineOperations(ref);
179 // eStaticServiceMP3Info
182 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
183 // about unopened files.
185 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
186 // should have a database backend where ID3-files etc. are cached.
187 // this would allow listing the mp3 database based on certain filters.
189 DEFINE_REF(eStaticServiceMP3Info)
191 eStaticServiceMP3Info::eStaticServiceMP3Info()
195 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
197 if ( ref.name.length() )
201 size_t last = ref.path.rfind('/');
202 if (last != std::string::npos)
203 name = ref.path.substr(last+1);
210 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
215 int eStaticServiceMP3Info::getInfo(const eServiceReference &ref, int w)
219 case iServiceInformation::sTimeCreate:
222 if(stat(ref.path.c_str(), &s) == 0)
226 return iServiceInformation::resNA;
230 return iServiceInformation::resNA;
233 RESULT eStaticServiceMP3Info::getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &evt, time_t start_time)
235 if (ref.path.find("://") != std::string::npos)
237 eServiceReference equivalentref(ref);
238 equivalentref.type = eServiceFactoryMP3::id;
239 equivalentref.path.clear();
240 return eEPGCache::getInstance()->lookupEventTime(equivalentref, start_time, evt);
247 int eServiceMP3::ac3_delay,
248 eServiceMP3::pcm_delay;
250 eServiceMP3::eServiceMP3(eServiceReference ref)
253 m_nownext_timer(eTimer::create(eApp))
255 m_subtitle_sync_timer = eTimer::create(eApp);
256 m_streamingsrc_timeout = 0;
258 m_currentAudioStream = -1;
259 m_currentSubtitleStream = -1;
260 m_subtitle_widget = 0;
261 m_currentTrickRatio = 1.0;
262 m_buffer_size = 1*1024*1024;
263 m_prev_decoder_time = -1;
264 m_decoder_time_valid_state = 0;
265 m_errorInfo.missing_codec = "";
267 audioSink = videoSink = NULL;
268 CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
269 CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
270 CONNECT(m_nownext_timer->timeout, eServiceMP3::updateEpgCacheNowNext);
271 m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
274 eDebug("eServiceMP3::construct!");
276 const char *filename = m_ref.path.c_str();
277 const char *ext = strrchr(filename, '.');
279 ext = filename + strlen(filename);
281 m_sourceinfo.is_video = FALSE;
282 m_sourceinfo.audiotype = atUnknown;
283 if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
285 m_sourceinfo.containertype = ctMPEGPS;
286 m_sourceinfo.is_video = TRUE;
288 else if ( strcasecmp(ext, ".ts") == 0 )
290 m_sourceinfo.containertype = ctMPEGTS;
291 m_sourceinfo.is_video = TRUE;
293 else if ( strcasecmp(ext, ".mkv") == 0 )
295 m_sourceinfo.containertype = ctMKV;
296 m_sourceinfo.is_video = TRUE;
298 else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
300 m_sourceinfo.containertype = ctAVI;
301 m_sourceinfo.is_video = TRUE;
303 else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0 || strcasecmp(ext, ".m4v") == 0)
305 m_sourceinfo.containertype = ctMP4;
306 m_sourceinfo.is_video = TRUE;
308 else if ( strcasecmp(ext, ".m4a") == 0 )
310 m_sourceinfo.containertype = ctMP4;
311 m_sourceinfo.audiotype = atAAC;
313 else if ( strcasecmp(ext, ".mp3") == 0 )
314 m_sourceinfo.audiotype = atMP3;
315 else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
316 m_sourceinfo.containertype = ctCDA;
317 if ( strcasecmp(ext, ".dat") == 0 )
319 m_sourceinfo.containertype = ctVCD;
320 m_sourceinfo.is_video = TRUE;
322 if ( strstr(filename, "://") )
323 m_sourceinfo.is_streaming = TRUE;
327 if ( m_sourceinfo.is_streaming )
329 uri = g_strdup_printf ("%s", filename);
330 if (strstr(filename, "rtmp://") || strstr(filename, "rtsp://")) {
331 m_streamingsrc_timeout = eTimer::create(eApp);
333 if (m_streamingsrc_timeout) {
334 CONNECT(m_streamingsrc_timeout->timeout, eServiceMP3::sourceTimeout);
336 std::string config_str;
337 if( ePythonConfigQuery::getConfigValue("config.mediaplayer.useAlternateUserAgent", config_str) == 0 )
339 if ( config_str == "True" )
340 ePythonConfigQuery::getConfigValue("config.mediaplayer.alternateUserAgent", m_useragent);
342 if ( m_useragent.length() == 0 )
343 m_useragent = "Enigma2 Mediaplayer";
345 else if ( m_sourceinfo.containertype == ctCDA )
347 int i_track = atoi(filename+18);
348 uri = g_strdup_printf ("cdda://%i", i_track);
350 else if ( m_sourceinfo.containertype == ctVCD )
352 int fd = open(filename,O_RDONLY);
354 int ret = read(fd, tmp, 128*1024);
356 if ( ret == -1 ) // this is a "REAL" VCD
357 uri = g_strdup_printf ("vcd://");
359 uri = g_filename_to_uri(filename, NULL, NULL);
363 uri = g_filename_to_uri(filename, NULL, NULL);
365 eDebug("eServiceMP3::playbin uri=%s", uri);
367 #if GST_VERSION_MAJOR < 1
368 m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
370 m_gst_playbin = gst_element_factory_make("playbin", "playbin");
376 g_object_get(G_OBJECT (m_gst_playbin), "flags", &flags, NULL);
377 flags |= GST_PLAY_FLAG_NATIVE_VIDEO;
378 flags &= ~GST_PLAY_FLAG_SOFT_VOLUME;
379 g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
380 g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
383 GstElement *subsink = gst_element_factory_make("subsink", "subtitle_sink");
385 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-subsink");
388 m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
389 g_object_set (G_OBJECT (subsink), "caps", gst_caps_from_string("text/plain; text/x-plain; text/x-raw; text/x-pango-markup; video/x-dvd-subpicture; subpicture/x-pgs"), NULL);
390 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", subsink, NULL);
391 g_object_set (G_OBJECT (m_gst_playbin), "current-text", m_currentSubtitleStream, NULL);
393 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
394 #if GST_VERSION_MAJOR < 1
395 gst_bus_set_sync_handler(bus, gstBusSyncHandler, this);
397 gst_bus_set_sync_handler(bus, gstBusSyncHandler, this, NULL);
399 gst_object_unref(bus);
400 char srt_filename[ext - filename + 5];
401 strncpy(srt_filename, filename, ext - filename);
402 srt_filename[ext - filename]='\0';
403 strcat(srt_filename, ".srt");
405 if (stat(srt_filename, &buffer) == 0)
407 eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
408 g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
410 if ( m_sourceinfo.is_streaming )
412 g_signal_connect (G_OBJECT (m_gst_playbin), "notify::source", G_CALLBACK (gstHTTPSourceSetAgent), this);
414 flags |= GST_PLAY_FLAG_BUFFERING;
415 g_object_set(G_OBJECT(m_gst_playbin), "buffer-duration", 5LL * GST_SECOND, NULL);
416 g_object_set(G_OBJECT(m_gst_playbin), "buffer-size", m_buffer_size, NULL);
420 m_event((iPlayableService*)this, evUser+12);
423 gst_object_unref(GST_OBJECT(m_gst_playbin));
425 m_errorInfo.error_message = "failed to create GStreamer pipeline!\n";
426 eDebug("eServiceMP3::sorry, can't play: %s",m_errorInfo.error_message.c_str());
431 eServiceMP3::~eServiceMP3()
433 // disconnect subtitle callback
434 GstElement *subsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
438 g_signal_handler_disconnect (subsink, m_subs_to_pull_handler_id);
439 gst_object_unref(subsink);
442 if (m_subtitle_widget)
443 delete m_subtitle_widget;
447 // disconnect sync handler callback
448 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
449 #if GST_VERSION_MAJOR < 1
450 gst_bus_set_sync_handler(bus, NULL, NULL);
452 gst_bus_set_sync_handler(bus, NULL, NULL, NULL);
454 gst_object_unref(bus);
457 if (m_state == stRunning)
461 gst_tag_list_free(m_stream_tags);
465 gst_object_unref(GST_OBJECT(audioSink));
470 gst_object_unref(GST_OBJECT(videoSink));
476 gst_object_unref (GST_OBJECT (m_gst_playbin));
477 eDebug("eServiceMP3::destruct!");
481 void eServiceMP3::updateEpgCacheNowNext()
484 ePtr<eServiceEvent> next = 0;
485 ePtr<eServiceEvent> ptr = 0;
486 eServiceReference ref(m_ref);
487 ref.type = eServiceFactoryMP3::id;
490 if (eEPGCache::getInstance() && eEPGCache::getInstance()->lookupEventTime(ref, -1, ptr) >= 0)
492 ePtr<eServiceEvent> current = m_event_now;
493 if (!current || !ptr || current->getEventId() != ptr->getEventId())
497 time_t next_time = ptr->getBeginTime() + ptr->getDuration();
498 if (eEPGCache::getInstance()->lookupEventTime(ref, next_time, ptr) >= 0)
506 int refreshtime = 60;
513 time_t now = ::time(0);
514 refreshtime = (int)(next->getBeginTime() - now) + 3;
515 if (refreshtime <= 0 || refreshtime > 60)
521 m_nownext_timer->startLongTimer(refreshtime);
524 m_event((iPlayableService*)this, evUpdatedEventInfo);
528 DEFINE_REF(eServiceMP3);
530 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
532 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
536 RESULT eServiceMP3::start()
538 ASSERT(m_state == stIdle);
543 eDebug("eServiceMP3::starting pipeline");
544 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
547 m_event(this, evStart);
552 void eServiceMP3::sourceTimeout()
554 eDebug("eServiceMP3::http source timeout! issuing eof...");
555 m_event((iPlayableService*)this, evEOF);
558 RESULT eServiceMP3::stop()
560 ASSERT(m_state != stIdle);
562 if (!m_gst_playbin || m_state == stStopped)
565 //GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(m_gst_playbin),GST_DEBUG_GRAPH_SHOW_ALL,"e2-playbin");
567 //eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
568 gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
570 m_nownext_timer->stop();
575 RESULT eServiceMP3::setTarget(int target)
580 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
586 RESULT eServiceMP3::setSlowMotion(int ratio)
590 eDebug("eServiceMP3::setSlowMotion ratio=%f",1/(float)ratio);
591 return trickSeek(1.0/(gdouble)ratio);
594 RESULT eServiceMP3::setFastForward(int ratio)
596 eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
597 return trickSeek(ratio);
601 RESULT eServiceMP3::pause()
603 if (!m_gst_playbin || m_state != stRunning)
606 gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
611 RESULT eServiceMP3::unpause()
613 if (!m_gst_playbin || m_state != stRunning)
616 if (m_currentTrickRatio != 1.0)
619 gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
624 /* iSeekableService */
625 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
631 RESULT eServiceMP3::getLength(pts_t &pts)
633 if (!m_gst_playbin || m_state != stRunning)
636 GstFormat fmt = GST_FORMAT_TIME;
638 #if GST_VERSION_MAJOR < 1
639 if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
641 if (!gst_element_query_duration(m_gst_playbin, fmt, &len))
644 /* len is in nanoseconds. we have 90 000 pts per second. */
650 RESULT eServiceMP3::seekToImpl(pts_t to)
652 /* convert pts to nanoseconds */
653 gint64 time_nanoseconds = to * 11111LL;
654 #if GST_VERSION_MAJOR < 1
655 if (!gst_element_seek (m_gst_playbin, m_currentTrickRatio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH),
656 GST_SEEK_TYPE_SET, time_nanoseconds,
657 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
659 if (!gst_element_seek (m_gst_playbin, m_currentTrickRatio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT),
660 GST_SEEK_TYPE_SET, time_nanoseconds,
661 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
664 eDebug("eServiceMP3::seekTo failed");
671 RESULT eServiceMP3::seekTo(pts_t to)
676 m_subtitle_sync_timer->stop();
677 m_subtitle_pages.clear();
678 m_prev_decoder_time = -1;
679 m_decoder_time_valid_state = 0;
680 ret = seekToImpl(to);
687 RESULT eServiceMP3::trickSeek(gdouble ratio)
692 return seekRelative(0, 0);
696 flags = GST_SEEK_FLAG_NONE;
697 flags |= GST_SEEK_FLAG_FLUSH;
698 #if GST_VERSION_MAJOR >= 1
699 flags |= GST_SEEK_FLAG_KEY_UNIT;
702 GstFormat fmt = GST_FORMAT_TIME;
703 bool validposition = false;
707 #if GST_VERSION_MAJOR < 1
708 gst_element_query_duration(m_gst_playbin, &fmt, &len);
710 gst_element_query_duration(m_gst_playbin, fmt, &len);
713 if (getPlayPosition(pos) >= 0)
715 validposition = true;
723 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, (GstSeekFlags)flags, GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, len);
725 eDebug("eServiceMP3::trickSeek with rate %lf to %" GST_TIME_FORMAT " ", ratio, GST_TIME_ARGS (pos));
729 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);
732 if (!gst_element_send_event ( GST_ELEMENT (m_gst_playbin), s_event))
734 eDebug("eServiceMP3::trickSeek failed");
738 m_subtitle_pages.clear();
739 m_prev_decoder_time = -1;
740 m_decoder_time_valid_state = 0;
741 m_currentTrickRatio = ratio;
746 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
753 if (getPlayPosition(ppos) < 0 )
756 ppos += to * direction;
763 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
765 GstFormat fmt = GST_FORMAT_TIME;
769 if (!m_gst_playbin || m_state != stRunning)
772 if (audioSink || videoSink)
774 g_signal_emit_by_name(audioSink ? audioSink : videoSink, "get-decoder-time", &pos);
775 if (!GST_CLOCK_TIME_IS_VALID(pos))
780 #if GST_VERSION_MAJOR < 1
781 if(!gst_element_query_position(m_gst_playbin, &fmt, &pos))
783 if(!gst_element_query_position(m_gst_playbin, fmt, &pos))
786 eDebug("gst_element_query_position failed in getPlayPosition");
791 /* pos is in nanoseconds. we have 90 000 pts per second. */
793 // eDebug("gst_element_query_position %lld pts (%lld ms)", pts, pos/1000000LL);
797 RESULT eServiceMP3::setTrickmode(int trick)
799 /* trickmode is not yet supported by our dvbmediasinks. */
803 RESULT eServiceMP3::isCurrentlySeekable()
805 int ret = 3; // seeking and fast/slow winding possible
810 if (m_state != stRunning)
813 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
815 // disable fast winding yet when a dvbvideosink or dvbaudiosink is used
816 // for this we must do some changes on different places.. (gstreamer.. our sinks.. enigma2)
818 ret &= ~2; // only seeking possible
819 gst_object_unref(sink);
822 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
824 ret &= ~2; // only seeking possible
825 gst_object_unref(sink);
832 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
838 RESULT eServiceMP3::getName(std::string &name)
840 std::string title = m_ref.getName();
844 size_t n = name.rfind('/');
845 if (n != std::string::npos)
846 name = name.substr(n + 1);
853 RESULT eServiceMP3::getEvent(ePtr<eServiceEvent> &evt, int nownext)
855 evt = nownext ? m_event_next : m_event_now;
861 int eServiceMP3::getInfo(int w)
863 const gchar *tag = 0;
867 case sServiceref: return m_ref;
868 case sVideoHeight: return m_height;
869 case sVideoWidth: return m_width;
870 case sFrameRate: return m_framerate;
871 case sProgressive: return m_progressive;
872 case sAspect: return m_aspect;
876 case sTagTitleSortname:
877 case sTagArtistSortname:
878 case sTagAlbumSortname:
883 case sTagExtendedComment:
886 case sTagDescription:
889 case sTagOrganization:
891 case sTagCopyrightURI:
899 case sTagLanguageCode:
901 case sTagChannelMode:
908 case sTagReferenceLevel:
909 case sTagBeatsPerMinute:
911 case sTagPreviewImage:
913 return resIsPyObject;
914 case sTagTrackNumber:
915 tag = GST_TAG_TRACK_NUMBER;
918 tag = GST_TAG_TRACK_COUNT;
920 case sTagAlbumVolumeNumber:
921 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
923 case sTagAlbumVolumeCount:
924 tag = GST_TAG_ALBUM_VOLUME_COUNT;
927 tag = GST_TAG_BITRATE;
929 case sTagNominalBitrate:
930 tag = GST_TAG_NOMINAL_BITRATE;
932 case sTagMinimumBitrate:
933 tag = GST_TAG_MINIMUM_BITRATE;
935 case sTagMaximumBitrate:
936 tag = GST_TAG_MAXIMUM_BITRATE;
939 tag = GST_TAG_SERIAL;
941 case sTagEncoderVersion:
942 tag = GST_TAG_ENCODER_VERSION;
951 if (!m_stream_tags || !tag)
955 if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
961 std::string eServiceMP3::getInfoString(int w)
963 if ( m_sourceinfo.is_streaming )
971 eServiceReference ref(m_ref);
972 ref.type = eServiceFactoryMP3::id;
974 return ref.toString();
981 if ( !m_stream_tags && w < sUser && w > 26 )
983 const gchar *tag = 0;
990 tag = GST_TAG_ARTIST;
995 case sTagTitleSortname:
996 tag = GST_TAG_TITLE_SORTNAME;
998 case sTagArtistSortname:
999 tag = GST_TAG_ARTIST_SORTNAME;
1001 case sTagAlbumSortname:
1002 tag = GST_TAG_ALBUM_SORTNAME;
1006 #if GST_VERSION_MAJOR >= 1
1007 GstDateTime *date_time;
1009 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
1012 g_date_strftime (res, sizeof(res), "%Y-%M-%D", date);
1013 return (std::string)res;
1015 #if GST_VERSION_MAJOR >= 1
1016 else if (gst_tag_list_get_date_time(m_stream_tags, GST_TAG_DATE_TIME, &date_time))
1018 if (gst_date_time_has_year(date_time))
1021 snprintf(res, sizeof(res), "%04d", gst_date_time_get_year(date_time));
1022 gst_date_time_unref(date_time);
1023 return (std::string)res;
1025 gst_date_time_unref(date_time);
1030 tag = GST_TAG_COMPOSER;
1033 tag = GST_TAG_GENRE;
1036 tag = GST_TAG_COMMENT;
1038 case sTagExtendedComment:
1039 tag = GST_TAG_EXTENDED_COMMENT;
1042 tag = GST_TAG_LOCATION;
1045 tag = GST_TAG_HOMEPAGE;
1047 case sTagDescription:
1048 tag = GST_TAG_DESCRIPTION;
1051 tag = GST_TAG_VERSION;
1056 case sTagOrganization:
1057 tag = GST_TAG_ORGANIZATION;
1060 tag = GST_TAG_COPYRIGHT;
1062 case sTagCopyrightURI:
1063 tag = GST_TAG_COPYRIGHT_URI;
1066 tag = GST_TAG_CONTACT;
1069 tag = GST_TAG_LICENSE;
1071 case sTagLicenseURI:
1072 tag = GST_TAG_LICENSE_URI;
1075 tag = GST_TAG_CODEC;
1077 case sTagAudioCodec:
1078 tag = GST_TAG_AUDIO_CODEC;
1080 case sTagVideoCodec:
1081 tag = GST_TAG_VIDEO_CODEC;
1084 tag = GST_TAG_ENCODER;
1086 case sTagLanguageCode:
1087 tag = GST_TAG_LANGUAGE_CODE;
1090 tag = GST_TAG_KEYWORDS;
1092 case sTagChannelMode:
1093 tag = "channel-mode";
1096 return m_errorInfo.error_message;
1103 if (gst_tag_list_get_string(m_stream_tags, tag, &value))
1105 std::string res = value;
1112 PyObject *eServiceMP3::getInfoObject(int w)
1114 const gchar *tag = 0;
1115 bool isBuffer = false;
1119 tag = GST_TAG_TRACK_GAIN;
1122 tag = GST_TAG_TRACK_PEAK;
1125 tag = GST_TAG_ALBUM_GAIN;
1128 tag = GST_TAG_ALBUM_PEAK;
1130 case sTagReferenceLevel:
1131 tag = GST_TAG_REFERENCE_LEVEL;
1133 case sTagBeatsPerMinute:
1134 tag = GST_TAG_BEATS_PER_MINUTE;
1137 tag = GST_TAG_IMAGE;
1140 case sTagPreviewImage:
1141 tag = GST_TAG_PREVIEW_IMAGE;
1144 case sTagAttachment:
1145 tag = GST_TAG_ATTACHMENT;
1152 if (m_stream_tags && tag)
1156 const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
1160 unsigned char *bufferData;
1161 unsigned int bufferSize;
1162 buffer = gst_value_get_buffer (gv_buffer);
1163 #if GST_VERSION_MAJOR < 1
1164 bufferData = GST_BUFFER_DATA(buffer);
1165 bufferSize = GST_BUFFER_SIZE(buffer);
1168 gst_buffer_map(buffer, &map, GST_MAP_READ);
1169 bufferData = map.data;
1170 bufferSize = map.size;
1172 PyObject *ret = PyBuffer_FromMemory(bufferData, bufferSize);
1173 #if GST_VERSION_MAJOR >= 1
1174 gst_buffer_unmap(buffer, &map);
1181 gdouble value = 0.0;
1182 gst_tag_list_get_double(m_stream_tags, tag, &value);
1183 return PyFloat_FromDouble(value);
1190 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
1196 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
1202 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
1208 RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
1214 int eServiceMP3::getNumberOfTracks()
1216 return m_audioStreams.size();
1219 int eServiceMP3::getCurrentTrack()
1221 if (m_currentAudioStream == -1)
1222 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
1223 return m_currentAudioStream;
1226 RESULT eServiceMP3::selectTrack(unsigned int i)
1228 bool validposition = false;
1230 if (getPlayPosition(ppos) >= 0)
1232 validposition = true;
1238 int ret = selectAudioStream(i);
1250 int eServiceMP3::selectAudioStream(int i)
1253 g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
1254 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", ¤t_audio, NULL);
1255 if ( current_audio == i )
1257 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
1258 m_currentAudioStream = i;
1264 int eServiceMP3::getCurrentChannel()
1269 RESULT eServiceMP3::selectChannel(int i)
1271 eDebug("eServiceMP3::selectChannel(%i)",i);
1275 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
1277 if (i >= m_audioStreams.size())
1279 info.m_description = m_audioStreams[i].codec;
1280 /* if (m_audioStreams[i].type == atMPEG)
1281 info.m_description = "MPEG";
1282 else if (m_audioStreams[i].type == atMP3)
1283 info.m_description = "MP3";
1284 else if (m_audioStreams[i].type == atAC3)
1285 info.m_description = "AC3";
1286 else if (m_audioStreams[i].type == atAAC)
1287 info.m_description = "AAC";
1288 else if (m_audioStreams[i].type == atDTS)
1289 info.m_description = "DTS";
1290 else if (m_audioStreams[i].type == atPCM)
1291 info.m_description = "PCM";
1292 else if (m_audioStreams[i].type == atOGG)
1293 info.m_description = "OGG";
1294 else if (m_audioStreams[i].type == atFLAC)
1295 info.m_description = "FLAC";
1297 info.m_description = "???";*/
1298 if (info.m_language.empty())
1299 info.m_language = m_audioStreams[i].language_code;
1303 subtype_t getSubtitleType(GstPad* pad, gchar *g_codec=NULL)
1305 subtype_t type = stUnknown;
1306 #if GST_VERSION_MAJOR < 1
1307 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1309 GstCaps* caps = gst_pad_get_current_caps(pad);
1311 if (!caps && !g_codec)
1313 caps = gst_pad_get_allowed_caps(pad);
1316 if ( caps && !gst_caps_is_empty(caps))
1318 GstStructure* str = gst_caps_get_structure(caps, 0);
1319 const gchar *g_type = gst_structure_get_name(str);
1320 eDebug("getSubtitleType::subtitle probe caps type=%s", g_type);
1322 if ( !strcmp(g_type, "video/x-dvd-subpicture") )
1324 else if ( !strcmp(g_type, "text/x-pango-markup") )
1326 else if ( !strcmp(g_type, "text/plain") || !strcmp(g_type, "text/x-plain") || !strcmp(g_type, "text/x-raw"))
1328 else if ( !strcmp(g_type, "subpicture/x-pgs") )
1331 eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec);
1335 eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec);
1336 if ( !strcmp(g_codec, "VOB") )
1338 else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") )
1340 else if ( !strcmp(g_codec, "ASS") )
1342 else if ( !strcmp(g_codec, "UTF-8 plain text") )
1345 eDebug("getSubtitleType::unsupported subtitle codec %s", g_codec);
1348 eDebug("getSubtitleType::unidentifiable subtitle stream!");
1353 #if GST_VERSION_MAJOR < 1
1354 gint eServiceMP3::match_sinktype(GstElement *element, gpointer type)
1356 return strcmp(g_type_name(G_OBJECT_TYPE(element)), (const char*)type);
1359 gint eServiceMP3::match_sinktype(const GValue *velement, const gchar *type)
1361 GstElement *element = GST_ELEMENT_CAST(g_value_get_object(velement));
1362 return strcmp(g_type_name(G_OBJECT_TYPE(element)), type);
1366 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
1370 gchar *sourceName = NULL;
1371 GstObject *source = NULL;
1372 GstElement *subsink = NULL;
1373 source = GST_MESSAGE_SRC(msg);
1374 if (!GST_IS_OBJECT(source))
1376 sourceName = gst_object_get_name(source);
1379 if (gst_message_get_structure(msg))
1380 string = gst_structure_to_string(gst_message_get_structure(msg));
1382 string = g_strdup(GST_MESSAGE_TYPE_NAME(msg));
1383 eDebug("eTsRemoteSource::gst_message from %s: %s", sourceName, string);
1386 switch (GST_MESSAGE_TYPE (msg))
1388 case GST_MESSAGE_EOS:
1389 m_event((iPlayableService*)this, evEOF);
1391 case GST_MESSAGE_STATE_CHANGED:
1393 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1398 GstState old_state, new_state;
1399 gst_message_parse_state_changed(msg, &old_state, &new_state, NULL);
1401 if(old_state == new_state)
1404 eDebug("eServiceMP3::state transition %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
1406 GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state);
1410 case GST_STATE_CHANGE_NULL_TO_READY:
1413 case GST_STATE_CHANGE_READY_TO_PAUSED:
1415 #if GST_VERSION_MAJOR >= 1
1416 GValue result = { 0, };
1418 GstIterator *children;
1419 subsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1422 #ifdef GSTREAMER_SUBTITLE_SYNC_MODE_BUG
1423 g_object_set (G_OBJECT (subsink), "sync", FALSE, NULL);
1425 gst_object_unref(subsink);
1430 gst_object_unref(GST_OBJECT(audioSink));
1435 gst_object_unref(GST_OBJECT(videoSink));
1439 children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin));
1440 #if GST_VERSION_MAJOR < 1
1441 audioSink = GST_ELEMENT_CAST(gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, (gpointer)"GstDVBAudioSink"));
1443 if (gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &result, (gpointer)"GstDVBAudioSink"))
1445 audioSink = GST_ELEMENT_CAST(g_value_dup_object(&result));
1446 g_value_unset(&result);
1449 gst_iterator_free(children);
1451 children = gst_bin_iterate_recurse(GST_BIN(m_gst_playbin));
1452 #if GST_VERSION_MAJOR < 1
1453 videoSink = GST_ELEMENT_CAST(gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, (gpointer)"GstDVBVideoSink"));
1455 if (gst_iterator_find_custom(children, (GCompareFunc)match_sinktype, &result, (gpointer)"GstDVBVideoSink"))
1457 videoSink = GST_ELEMENT_CAST(g_value_dup_object(&result));
1458 g_value_unset(&result);
1461 gst_iterator_free(children);
1463 setAC3Delay(ac3_delay);
1464 setPCMDelay(pcm_delay);
1466 updateEpgCacheNowNext();
1469 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1471 if ( m_sourceinfo.is_streaming && m_streamingsrc_timeout )
1472 m_streamingsrc_timeout->stop();
1474 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1477 case GST_STATE_CHANGE_PAUSED_TO_READY:
1481 gst_object_unref(GST_OBJECT(audioSink));
1486 gst_object_unref(GST_OBJECT(videoSink));
1490 case GST_STATE_CHANGE_READY_TO_NULL:
1496 case GST_MESSAGE_ERROR:
1500 gst_message_parse_error (msg, &err, &debug);
1502 eWarning("Gstreamer error: %s (domain:%i, code:%i) from %s", err->message, err->domain, err->code, sourceName );
1503 if ( err->domain == GST_STREAM_ERROR )
1505 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1507 if ( g_strrstr(sourceName, "videosink") )
1508 m_event((iPlayableService*)this, evUser+11);
1509 else if ( g_strrstr(sourceName, "audiosink") )
1510 m_event((iPlayableService*)this, evUser+10);
1513 else if ( err->domain == GST_RESOURCE_ERROR )
1515 if ( err->code == GST_RESOURCE_ERROR_OPEN_READ || err->code == GST_RESOURCE_ERROR_READ )
1523 case GST_MESSAGE_INFO:
1528 gst_message_parse_info (msg, &inf, &debug);
1530 if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1532 if ( g_strrstr(sourceName, "videosink") )
1533 m_event((iPlayableService*)this, evUser+14);
1538 case GST_MESSAGE_TAG:
1540 GstTagList *tags, *result;
1541 gst_message_parse_tag(msg, &tags);
1543 result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE);
1547 gst_tag_list_free(m_stream_tags);
1548 m_stream_tags = result;
1551 const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1554 GstBuffer *buf_image;
1555 #if GST_VERSION_MAJOR < 1
1556 buf_image = gst_value_get_buffer (gv_image);
1559 sample = (GstSample *)g_value_get_boxed(gv_image);
1560 buf_image = gst_sample_get_buffer(sample);
1562 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1568 #if GST_VERSION_MAJOR < 1
1569 data = GST_BUFFER_DATA(buf_image);
1570 size = GST_BUFFER_SIZE(buf_image);
1573 gst_buffer_map(buf_image, &map, GST_MAP_READ);
1577 ret = write(fd, data, size);
1578 #if GST_VERSION_MAJOR >= 1
1579 gst_buffer_unmap(buf_image, &map);
1582 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1584 m_event((iPlayableService*)this, evUser+13);
1586 gst_tag_list_free(tags);
1587 m_event((iPlayableService*)this, evUpdatedInfo);
1590 case GST_MESSAGE_ASYNC_DONE:
1592 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1595 gint i, n_video = 0, n_audio = 0, n_text = 0;
1597 g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1598 g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1599 g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1601 eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1603 if ( n_video + n_audio <= 0 )
1606 m_audioStreams.clear();
1607 m_subtitleStreams.clear();
1609 for (i = 0; i < n_audio; i++)
1612 gchar *g_codec, *g_lang;
1613 GstTagList *tags = NULL;
1615 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1616 #if GST_VERSION_MAJOR < 1
1617 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1619 GstCaps* caps = gst_pad_get_current_caps(pad);
1623 GstStructure* str = gst_caps_get_structure(caps, 0);
1624 const gchar *g_type = gst_structure_get_name(str);
1625 audio.type = gstCheckAudioPad(str);
1626 g_codec = g_strdup(g_type);
1627 g_lang = g_strdup_printf ("und");
1628 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1629 #if GST_VERSION_MAJOR < 1
1630 if ( tags && gst_is_tag_list(tags) )
1632 if ( tags && GST_IS_TAG_LIST(tags) )
1635 gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1636 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1637 gst_tag_list_free(tags);
1639 audio.language_code = std::string(g_lang);
1640 audio.codec = std::string(g_codec);
1641 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1642 m_audioStreams.push_back(audio);
1645 gst_caps_unref(caps);
1648 for (i = 0; i < n_text; i++)
1650 gchar *g_codec = NULL, *g_lang = NULL;
1651 GstTagList *tags = NULL;
1652 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1653 subtitleStream subs;
1656 g_lang = g_strdup_printf ("und");
1657 #if GST_VERSION_MAJOR < 1
1658 if ( tags && gst_is_tag_list(tags) )
1660 if ( tags && GST_IS_TAG_LIST(tags) )
1663 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1664 gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec);
1665 gst_tag_list_free(tags);
1668 subs.language_code = std::string(g_lang);
1669 eDebug("eServiceMP3::subtitle stream=%i language=%s codec=%s", i, g_lang, g_codec);
1672 g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1674 g_signal_connect (G_OBJECT (pad), "notify::caps", G_CALLBACK (gstTextpadHasCAPS), this);
1675 subs.type = getSubtitleType(pad, g_codec);
1677 m_subtitleStreams.push_back(subs);
1680 m_event((iPlayableService*)this, evUpdatedInfo);
1682 if ( m_errorInfo.missing_codec != "" )
1684 if ( m_errorInfo.missing_codec.find("video/") == 0 || ( m_errorInfo.missing_codec.find("audio/") == 0 && getNumberOfTracks() == 0 ) )
1685 m_event((iPlayableService*)this, evUser+12);
1689 case GST_MESSAGE_ELEMENT:
1691 if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1693 if ( gst_is_missing_plugin_message(msg) )
1695 GstCaps *caps= NULL;
1696 gboolean ret = gst_structure_get (msgstruct, "detail", GST_TYPE_CAPS, &caps, NULL);
1699 std::string codec = (const char*) gst_caps_to_string(caps);
1700 gchar *description = gst_missing_plugin_message_get_description(msg);
1703 eDebug("eServiceMP3::m_errorInfo.missing_codec = %s", codec.c_str());
1704 m_errorInfo.error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1705 m_errorInfo.missing_codec = codec.substr(0,(codec.find_first_of(',')));
1706 g_free(description);
1708 gst_caps_unref(caps);
1713 const gchar *eventname = gst_structure_get_name(msgstruct);
1716 if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1718 gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1719 gst_structure_get_int (msgstruct, "width", &m_width);
1720 gst_structure_get_int (msgstruct, "height", &m_height);
1721 if (strstr(eventname, "Changed"))
1722 m_event((iPlayableService*)this, evVideoSizeChanged);
1724 else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1726 gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1727 if (strstr(eventname, "Changed"))
1728 m_event((iPlayableService*)this, evVideoFramerateChanged);
1730 else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1732 gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1733 if (strstr(eventname, "Changed"))
1734 m_event((iPlayableService*)this, evVideoProgressiveChanged);
1741 case GST_MESSAGE_BUFFERING:
1743 GstBufferingMode mode;
1744 gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
1745 gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
1746 m_event((iPlayableService*)this, evBuffering);
1749 case GST_MESSAGE_STREAM_STATUS:
1751 GstStreamStatusType type;
1753 gst_message_parse_stream_status (msg, &type, &owner);
1754 if ( type == GST_STREAM_STATUS_TYPE_CREATE && m_sourceinfo.is_streaming )
1756 if ( GST_IS_PAD(source) )
1757 owner = gst_pad_get_parent_element(GST_PAD(source));
1758 else if ( GST_IS_ELEMENT(source) )
1759 owner = GST_ELEMENT(source);
1764 GstElementFactory *factory = gst_element_get_factory(GST_ELEMENT(owner));
1765 const gchar *name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
1766 if (!strcmp(name, "souphttpsrc"))
1768 if (m_streamingsrc_timeout) {
1769 m_streamingsrc_timeout->start(HTTP_TIMEOUT*1000, true);
1771 g_object_set (G_OBJECT (owner), "timeout", HTTP_TIMEOUT, NULL);
1772 eDebug("eServiceMP3::GST_STREAM_STATUS_TYPE_CREATE -> setting timeout on %s to %is", name, HTTP_TIMEOUT);
1775 if ( GST_IS_PAD(source) )
1776 gst_object_unref(owner);
1783 g_free (sourceName);
1786 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1788 eServiceMP3 *_this = (eServiceMP3*)user_data;
1789 _this->m_pump.send(Message(1));
1791 return GST_BUS_PASS;
1794 void eServiceMP3::gstHTTPSourceSetAgent(GObject *object, GParamSpec *unused, gpointer user_data)
1796 eServiceMP3 *_this = (eServiceMP3*)user_data;
1797 GstElement *source = NULL;
1798 g_object_get(_this->m_gst_playbin, "source", &source, NULL);
1801 #if GST_VERSION_MAJOR >= 1
1802 if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "timeout") != 0)
1804 GstElementFactory *factory = gst_element_get_factory(source);
1807 const gchar *sourcename = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory));
1808 if (!strcmp(sourcename, "souphttpsrc"))
1810 g_object_set(G_OBJECT(source), "timeout", HTTP_TIMEOUT, NULL);
1814 if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "ssl-strict") != 0)
1816 g_object_set(G_OBJECT(source), "ssl-strict", FALSE, NULL);
1819 g_object_set (G_OBJECT (source), "user-agent", _this->m_useragent.c_str(), NULL);
1820 gst_object_unref(source);
1824 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1829 if ( gst_structure_has_name (structure, "audio/mpeg"))
1831 gint mpegversion, layer = -1;
1832 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1835 switch (mpegversion) {
1838 gst_structure_get_int (structure, "layer", &layer);
1854 else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1856 else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1858 #if GST_VERSION_MAJOR < 1
1859 else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1861 else if ( gst_structure_has_name (structure, "audio/x-raw") )
1868 void eServiceMP3::gstPoll(const Message &msg)
1874 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
1875 GstMessage *message;
1876 while ((message = gst_bus_pop(bus)))
1878 gstBusCall(bus, message);
1879 gst_message_unref (message);
1881 gst_object_unref(bus);
1886 pullSubtitle(msg.d.buffer);
1887 gst_buffer_unref(msg.d.buffer);
1892 gstTextpadHasCAPS_synced(msg.d.pad);
1893 gst_object_unref(msg.d.pad);
1898 eDebug("gstPoll unhandled Message %d\n", msg.type);
1904 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1906 void eServiceMP3::gstCBsubtitleAvail(GstElement *subsink, GstBuffer *buffer, gpointer user_data)
1908 eServiceMP3 *_this = (eServiceMP3*)user_data;
1909 if (_this->m_currentSubtitleStream < 0)
1911 if (buffer) gst_buffer_unref(buffer);
1914 _this->m_pump.send(Message(2, buffer));
1917 void eServiceMP3::gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data)
1919 eServiceMP3 *_this = (eServiceMP3*)user_data;
1921 gst_object_ref (pad);
1923 _this->m_pump.send(Message(3, pad));
1926 // after messagepump
1927 void eServiceMP3::gstTextpadHasCAPS_synced(GstPad *pad)
1931 g_object_get (G_OBJECT (pad), "caps", &caps, NULL);
1933 eDebug("gstTextpadHasCAPS:: signal::caps = %s", gst_caps_to_string(caps));
1937 subtitleStream subs;
1939 // eDebug("gstGhostpadHasCAPS_synced %p %d", pad, m_subtitleStreams.size());
1941 if (m_currentSubtitleStream >= 0 && m_currentSubtitleStream < (int)m_subtitleStreams.size())
1942 subs = m_subtitleStreams[m_currentSubtitleStream];
1944 subs.type = stUnknown;
1948 if ( subs.type == stUnknown )
1950 GstTagList *tags = NULL;
1952 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", m_currentSubtitleStream, &tags);
1954 g_lang = g_strdup_printf ("und");
1955 #if GST_VERSION_MAJOR < 1
1956 if ( tags && gst_is_tag_list(tags) )
1958 if ( tags && GST_IS_TAG_LIST(tags) )
1960 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1962 subs.language_code = std::string(g_lang);
1963 subs.type = getSubtitleType(pad);
1965 if (m_currentSubtitleStream >= 0 && m_currentSubtitleStream < (int)m_subtitleStreams.size())
1966 m_subtitleStreams[m_currentSubtitleStream] = subs;
1968 m_subtitleStreams.push_back(subs);
1973 // 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));
1975 gst_caps_unref (caps);
1979 void eServiceMP3::pullSubtitle(GstBuffer *buffer)
1981 if (buffer && m_currentSubtitleStream >= 0 && m_currentSubtitleStream < (int)m_subtitleStreams.size())
1983 #if GST_VERSION_MAJOR < 1
1984 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1985 size_t len = GST_BUFFER_SIZE(buffer);
1988 if(!gst_buffer_map(buffer, &map, GST_MAP_READ))
1990 eDebug("eServiceMP3::pullSubtitle gst_buffer_map failed");
1991 gst_buffer_unref(buffer);
1994 gint64 buf_pos = GST_BUFFER_PTS(buffer);
1995 size_t len = map.size;
1996 // eDebug("gst_buffer_get_size %zu map.size %zu", gst_buffer_get_size(buffer), len);
1998 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1999 int subType = m_subtitleStreams[m_currentSubtitleStream].type;
2000 #ifdef SUBTITLE_DEBUG
2001 eDebug("pullSubtitle type = %i" ,subType);
2005 if ( subType < stVOB )
2007 int delay = ePythonConfigQuery::getConfigIntValue("config.subtitles.pango_subtitles_delay");
2008 int subtitle_fps = ePythonConfigQuery::getConfigIntValue("config.subtitles.pango_subtitles_fps");
2010 double convert_fps = 1.0;
2011 if (subtitle_fps > 1 && m_framerate > 0)
2012 convert_fps = subtitle_fps / (double)m_framerate;
2014 unsigned char line[len+1];
2016 #if GST_VERSION_MAJOR < 1
2017 memcpy(line, GST_BUFFER_DATA(buffer), len);
2019 memcpy(line, map.data, len);
2022 #ifdef SUBTITLE_DEBUG
2023 eDebug("got new text subtitle @ buf_pos = %lld ns (in pts=%lld), dur=%lld: '%s' ", buf_pos, buf_pos/11111LL, duration_ns, line);
2025 gRGB rgbcol(0xD0,0xD0,0xD0);
2026 page.type = SubtitlePage::Pango;
2027 page.pango_page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
2028 page.pango_page.m_show_pts = buf_pos / 11111LL + convert_fps + delay;
2029 page.pango_page.m_timeout = duration_ns / 1000000;
2030 m_subtitle_pages.push_back(page);
2031 m_subtitle_sync_timer->start(1, true);
2035 eDebug("unsupported subpicture... ignoring");
2038 #if GST_VERSION_MAJOR >= 1
2039 gst_buffer_unmap(buffer, &map);
2044 void eServiceMP3::pushSubtitles()
2046 long next_timer = 0;
2047 while ( !m_subtitle_pages.empty() )
2051 gint64 show_pts = 0;
2053 if (getPlayPosition(running_pts) < 0)
2054 m_decoder_time_valid_state = 0;
2056 if (m_decoder_time_valid_state < 4) {
2057 ++m_decoder_time_valid_state;
2058 if (m_prev_decoder_time == running_pts)
2059 m_decoder_time_valid_state = 0;
2060 if (m_decoder_time_valid_state < 4) {
2061 // if (m_decoder_time_valid_state)
2062 // eDebug("%d: decoder time not valid! prev %lld, now %lld\n", m_decoder_time_valid_state, m_prev_decoder_time/90, running_pts/90);
2064 // eDebug("%d: decoder time not valid! now %lld\n", m_decoder_time_valid_state, running_pts/90);
2066 m_prev_decoder_time = running_pts;
2071 SubtitlePage &frontpage = m_subtitle_pages.front();
2072 if (frontpage.type == SubtitlePage::Pango)
2073 show_pts = frontpage.pango_page.m_show_pts;
2075 diff_ms = ( show_pts - running_pts ) / 90;
2077 #ifdef SUBTITLE_DEBUG
2078 int32_t decoder_ms, start_ms, end_ms, diff_start_ms, diff_end_ms;
2079 ePangoSubtitlePageElement &element = frontpage.pango_page.m_elements[0];
2080 std::string text = element.m_pango_line;
2081 decoder_ms = running_pts / 90;
2082 start_ms = show_pts/ 90;
2083 end_ms = start_ms + frontpage.pango_page.m_timeout;
2084 diff_start_ms = start_ms - decoder_ms;
2085 diff_end_ms = end_ms - decoder_ms;
2087 eDebug("*** next subtitle: decoder: %d, start: %d, end: %d, duration_ms: %d, diff_start: %d, diff_end: %d : %s",
2088 decoder_ms, start_ms, end_ms, end_ms - start_ms, diff_start_ms, diff_end_ms, text.c_str());
2091 if ( diff_ms < -100 )
2093 #ifdef SUBTITLE_DEBUG
2094 eDebug("subtitle too late... drop");
2096 m_subtitle_pages.pop_front();
2098 else if ( diff_ms > 20 )
2100 #ifdef SUBTITLE_DEBUG
2101 eDebug("*** current sub in the future, start timer, %d\n", diff_start_ms);
2103 next_timer = diff_ms;
2106 else // immediate show
2108 if ( m_subtitle_widget )
2110 #ifdef SUBTITLE_DEBUG
2111 eDebug("*** current sub actual, show!");
2113 if ( frontpage.type == SubtitlePage::Pango)
2114 m_subtitle_widget->setPage(frontpage.pango_page);
2115 m_subtitle_widget->show();
2117 m_subtitle_pages.pop_front();
2124 m_subtitle_sync_timer->start(next_timer, true);
2128 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
2130 eDebug ("eServiceMP3::enableSubtitles m_currentSubtitleStream=%i this=%p",m_currentSubtitleStream, this);
2132 int tuplesize = PyTuple_Size(tuple);
2137 // g_signal_emit_by_name (m_gst_playbin, "get-text-pad", m_currentSubtitleStream, &pad);
2138 // gst_element_get_static_pad(m_gst_subtitlebin, "sink");
2139 // gulong subprobe_handler_id = gst_pad_add_buffer_probe (pad, G_CALLBACK (gstCBsubtitleDrop), NULL);
2141 if (!PyTuple_Check(tuple))
2145 entry = PyTuple_GET_ITEM(tuple, 1);
2146 if (!PyInt_Check(entry))
2148 pid = PyInt_AsLong(entry);
2149 entry = PyTuple_GET_ITEM(tuple, 2);
2150 if (!PyInt_Check(entry))
2152 type = PyInt_AsLong(entry);
2154 if (m_currentSubtitleStream != pid)
2156 g_object_set (G_OBJECT (m_gst_playbin), "current-text", -1, NULL);
2157 m_subtitle_sync_timer->stop();
2158 m_subtitle_pages.clear();
2159 m_prev_decoder_time = -1;
2160 m_decoder_time_valid_state = 0;
2161 m_currentSubtitleStream = pid;
2162 g_object_set (G_OBJECT (m_gst_playbin), "current-text", m_currentSubtitleStream, NULL);
2163 eDebug ("eServiceMP3::enableSubtitles g_object_set current-text = %i", pid);
2166 m_subtitle_widget = 0;
2167 m_subtitle_widget = new eSubtitleWidget(parent);
2168 m_subtitle_widget->resize(parent->size()); /* full size */
2170 g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
2172 eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
2173 // gst_pad_remove_buffer_probe (pad, subprobe_handler_id);
2175 #ifdef GSTREAMER_SUBTITLE_SYNC_MODE_BUG
2177 * when we're running the subsink in sync=false mode,
2178 * we have to force a seek, before the new subtitle stream will start
2180 seekRelative(-1, 90000);
2183 m_event((iPlayableService*)this, evUpdatedInfo);
2188 eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
2189 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
2193 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
2195 m_currentSubtitleStream = -1;
2196 g_object_set (G_OBJECT (m_gst_playbin), "current-text", m_currentSubtitleStream, NULL);
2197 eDebug("eServiceMP3::disableSubtitles");
2198 m_subtitle_sync_timer->stop();
2199 m_subtitle_pages.clear();
2200 m_prev_decoder_time = -1;
2201 m_decoder_time_valid_state = 0;
2202 if (m_subtitle_widget)
2203 delete m_subtitle_widget;
2204 m_subtitle_widget = 0;
2208 PyObject *eServiceMP3::getCachedSubtitle()
2210 // eDebug("eServiceMP3::getCachedSubtitle");
2211 bool autoturnon = ePythonConfigQuery::getConfigBoolValue("config.subtitles.pango_autoturnon", true);
2215 if (!m_subtitleStreams.empty())
2218 if (m_currentSubtitleStream >= 0 && m_currentSubtitleStream < (int)m_subtitleStreams.size())
2220 index = m_currentSubtitleStream;
2222 ePyObject tuple = PyTuple_New(5);
2223 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
2224 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(index));
2225 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(m_subtitleStreams[index].type)));
2226 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
2227 PyTuple_SET_ITEM(tuple, 4, PyString_FromString(m_subtitleStreams[index].language_code.c_str()));
2234 PyObject *eServiceMP3::getSubtitleList()
2236 // eDebug("eServiceMP3::getSubtitleList");
2237 ePyObject l = PyList_New(0);
2240 for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
2242 subtype_t type = IterSubtitleStream->type;
2251 ePyObject tuple = PyTuple_New(5);
2252 // eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
2253 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
2254 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
2255 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
2256 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
2257 PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
2258 PyList_Append(l, tuple);
2264 eDebug("eServiceMP3::getSubtitleList finished");
2268 RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
2274 PyObject *eServiceMP3::getBufferCharge()
2276 ePyObject tuple = PyTuple_New(5);
2277 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
2278 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
2279 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
2280 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
2281 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
2285 int eServiceMP3::setBufferSize(int size)
2287 m_buffer_size = size;
2288 g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
2292 int eServiceMP3::getAC3Delay()
2297 int eServiceMP3::getPCMDelay()
2302 void eServiceMP3::setAC3Delay(int delay)
2305 if (!m_gst_playbin || m_state != stRunning)
2309 int config_delay_int = delay;
2312 std::string config_delay;
2313 if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
2314 config_delay_int += atoi(config_delay.c_str());
2318 eDebug("dont apply ac3 delay when no video is running!");
2319 config_delay_int = 0;
2324 eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
2329 void eServiceMP3::setPCMDelay(int delay)
2332 if (!m_gst_playbin || m_state != stRunning)
2336 int config_delay_int = delay;
2339 std::string config_delay;
2340 if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
2341 config_delay_int += atoi(config_delay.c_str());
2345 eDebug("dont apply pcm delay when no video is running!");
2346 config_delay_int = 0;
2351 eTSMPEGDecoder::setHwPCMDelay(config_delay_int);