3 /* note: this requires gstreamer 0.10.x and a big list of plugins. */
4 /* it's currently hardcoded to use a big-endian alsasink as sink. */
5 #include <lib/base/ebase.h>
6 #include <lib/base/eerror.h>
7 #include <lib/base/init_num.h>
8 #include <lib/base/init.h>
9 #include <lib/base/nconfig.h>
10 #include <lib/base/object.h>
11 #include <lib/dvb/decoder.h>
12 #include <lib/components/file_eraser.h>
13 #include <lib/gui/esubtitle.h>
14 #include <lib/service/servicemp3.h>
15 #include <lib/service/service.h>
16 #include <lib/gdi/gpixmap.h>
21 #include <gst/pbutils/missing-plugins.h>
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("m2ts");
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_subtitle_hide_timer = eTimer::create(eApp);
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 CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
231 CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
232 CONNECT(m_subtitle_hide_timer->timeout, eServiceMP3::hideSubtitles);
233 CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
234 m_aspect = m_width = m_height = m_framerate = m_progressive = -1;
237 eDebug("eServiceMP3::construct!");
239 const char *filename = m_ref.path.c_str();
240 const char *ext = strrchr(filename, '.');
244 sourceStream sourceinfo;
245 sourceinfo.is_video = FALSE;
246 sourceinfo.audiotype = atUnknown;
247 if ( (strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin") && strcasecmp(ext, ".dat") ) == 0 )
249 sourceinfo.containertype = ctMPEGPS;
250 sourceinfo.is_video = TRUE;
252 else if ( strcasecmp(ext, ".ts") == 0 )
254 sourceinfo.containertype = ctMPEGTS;
255 sourceinfo.is_video = TRUE;
257 else if ( strcasecmp(ext, ".mkv") == 0 )
259 sourceinfo.containertype = ctMKV;
260 sourceinfo.is_video = TRUE;
262 else if ( strcasecmp(ext, ".avi") == 0 || strcasecmp(ext, ".divx") == 0)
264 sourceinfo.containertype = ctAVI;
265 sourceinfo.is_video = TRUE;
267 else if ( strcasecmp(ext, ".mp4") == 0 || strcasecmp(ext, ".mov") == 0 || strcasecmp(ext, ".m4v") == 0)
269 sourceinfo.containertype = ctMP4;
270 sourceinfo.is_video = TRUE;
272 else if ( strcasecmp(ext, ".m4a") == 0 )
274 sourceinfo.containertype = ctMP4;
275 sourceinfo.audiotype = atAAC;
277 else if ( strcasecmp(ext, ".mp3") == 0 )
278 sourceinfo.audiotype = atMP3;
279 else if ( (strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
280 sourceinfo.containertype = ctCDA;
281 if ( strcasecmp(ext, ".dat") == 0 )
283 sourceinfo.containertype = ctVCD;
284 sourceinfo.is_video = TRUE;
286 if ( (strncmp(filename, "http://", 7)) == 0 || (strncmp(filename, "udp://", 6)) == 0 || (strncmp(filename, "rtp://", 6)) == 0 || (strncmp(filename, "https://", 8)) == 0 || (strncmp(filename, "mms://", 6)) == 0 || (strncmp(filename, "rtsp://", 7)) == 0 )
287 sourceinfo.is_streaming = TRUE;
291 if ( sourceinfo.is_streaming )
293 uri = g_strdup_printf ("%s", filename);
295 else if ( sourceinfo.containertype == ctCDA )
297 int i_track = atoi(filename+18);
298 uri = g_strdup_printf ("cdda://%i", i_track);
300 else if ( sourceinfo.containertype == ctVCD )
302 int fd = open(filename,O_RDONLY);
304 int ret = read(fd, tmp, 128*1024);
306 if ( ret == -1 ) // this is a "REAL" VCD
307 uri = g_strdup_printf ("vcd://");
309 uri = g_filename_to_uri(filename, NULL, NULL);
313 uri = g_filename_to_uri(filename, NULL, NULL);
315 eDebug("eServiceMP3::playbin2 uri=%s", uri);
317 m_gst_playbin = gst_element_factory_make("playbin2", "playbin");
319 m_error_message = "failed to create GStreamer pipeline!\n";
321 g_object_set (G_OBJECT (m_gst_playbin), "uri", uri, NULL);
323 int flags = 0x47; // ( == GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT )
324 g_object_set (G_OBJECT (m_gst_playbin), "flags", flags, NULL);
328 m_gst_subtitlebin = gst_bin_new("subtitle_bin");
330 GstElement *appsink = gst_element_factory_make("appsink", "subtitle_sink");
331 GstElement *fakesink = gst_element_factory_make("fakesink", "subtitle_fakesink");
334 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-appsink");
338 // m_subs_to_pull_handler_id = g_signal_connect (appsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
339 // g_object_set (G_OBJECT (appsink), "caps", gst_caps_from_string("text/plain; text/x-pango-markup"), NULL);
340 // g_object_set (G_OBJECT (m_gst_playbin), "text-sink", appsink, NULL);
344 GstElement *dvdsubdec = gst_element_factory_make("dvdsubdec", "vobsubtitle_decoder");
346 eDebug("eServiceMP3::sorry, can't play: missing gst-plugin-dvdsub");
348 gst_bin_add_many(GST_BIN(m_gst_subtitlebin), dvdsubdec, appsink, fakesink, NULL);
349 GstPad *ghostpad = gst_ghost_pad_new("sink", gst_element_get_static_pad (fakesink, "sink"));
350 // // GstPad *ghostpad = gst_ghost_pad_new("sink", gst_element_get_static_pad (dvdsubdec, "sink"));
351 gst_element_add_pad (m_gst_subtitlebin, ghostpad);
352 eDebug("eServiceMP3::construct dvdsubdec=%p, appsink=%p, fakesink=%p, ghostpad=%p,", dvdsubdec, appsink, fakesink, ghostpad);
354 g_signal_connect (ghostpad, "notify::caps", G_CALLBACK (gstCBsubtitleCAPS), this);
356 GstCaps* caps = gst_caps_from_string("text/plain; text/x-pango-markup; video/x-raw-rgb");
357 g_object_set (G_OBJECT (appsink), "caps", caps, NULL);
358 g_object_set (G_OBJECT (dvdsubdec), "singlebuffer", TRUE, NULL);
359 gst_caps_unref(caps);
361 g_object_set (G_OBJECT (m_gst_playbin), "text-sink", m_gst_subtitlebin, NULL);
362 m_subs_to_pull_handler_id = g_signal_connect (appsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this);
366 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), gstBusSyncHandler, this);
367 char srt_filename[strlen(filename)+1];
368 strncpy(srt_filename,filename,strlen(filename)-3);
369 srt_filename[strlen(filename)-3]='\0';
370 strcat(srt_filename, "srt");
372 if (stat(srt_filename, &buffer) == 0)
374 eDebug("eServiceMP3::subtitle uri: %s", g_filename_to_uri(srt_filename, NULL, NULL));
375 g_object_set (G_OBJECT (m_gst_playbin), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL);
378 subs.language_code = std::string("und");
379 m_subtitleStreams.push_back(subs);
383 m_event((iPlayableService*)this, evUser+12);
386 gst_object_unref(GST_OBJECT(m_gst_playbin));
388 eDebug("eServiceMP3::sorry, can't play: %s",m_error_message.c_str());
392 setBufferSize(m_buffer_size);
395 eServiceMP3::~eServiceMP3()
397 // disconnect subtitle callback
398 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_subtitlebin), "subtitle_sink");
399 // GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
403 g_signal_handler_disconnect (appsink, m_subs_to_pull_handler_id);
404 gst_object_unref(appsink);
407 delete m_subtitle_widget;
409 // disconnect sync handler callback
410 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin)), NULL, NULL);
412 if (m_state == stRunning)
416 gst_tag_list_free(m_stream_tags);
420 gst_object_unref (GST_OBJECT (m_gst_playbin));
421 eDebug("eServiceMP3::destruct!");
425 DEFINE_REF(eServiceMP3);
427 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
429 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
433 RESULT eServiceMP3::start()
435 ASSERT(m_state == stIdle);
440 eDebug("eServiceMP3::starting pipeline");
441 gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
444 m_event(this, evStart);
449 RESULT eServiceMP3::stop()
451 ASSERT(m_state != stIdle);
453 if (m_state == stStopped)
456 eDebug("eServiceMP3::stop %s", m_ref.path.c_str());
457 gst_element_set_state(m_gst_playbin, GST_STATE_NULL);
463 RESULT eServiceMP3::setTarget(int target)
468 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
474 RESULT eServiceMP3::setSlowMotion(int ratio)
478 eDebug("eServiceMP3::setSlowMotion ratio=%f",1/(float)ratio);
479 return trickSeek(1/(float)ratio);
482 RESULT eServiceMP3::setFastForward(int ratio)
484 eDebug("eServiceMP3::setFastForward ratio=%i",ratio);
485 return trickSeek(ratio);
488 void eServiceMP3::seekTimeoutCB()
491 getPlayPosition(ppos);
493 ppos += 90000*m_currentTrickRatio;
498 m_seekTimeout->stop();
504 m_seekTimeout->stop();
511 RESULT eServiceMP3::pause()
513 if (!m_gst_playbin || m_state != stRunning)
516 gst_element_set_state(m_gst_playbin, GST_STATE_PAUSED);
521 RESULT eServiceMP3::unpause()
523 if (!m_gst_playbin || m_state != stRunning)
526 gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING);
531 /* iSeekableService */
532 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
538 RESULT eServiceMP3::getLength(pts_t &pts)
543 if (m_state != stRunning)
546 GstFormat fmt = GST_FORMAT_TIME;
549 if (!gst_element_query_duration(m_gst_playbin, &fmt, &len))
551 /* len is in nanoseconds. we have 90 000 pts per second. */
557 RESULT eServiceMP3::seekToImpl(pts_t to)
559 /* convert pts to nanoseconds */
560 gint64 time_nanoseconds = to * 11111LL;
561 if (!gst_element_seek (m_gst_playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
562 GST_SEEK_TYPE_SET, time_nanoseconds,
563 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
565 eDebug("eServiceMP3::seekTo failed");
572 RESULT eServiceMP3::seekTo(pts_t to)
577 eSingleLocker l(m_subs_to_pull_lock); // this is needed to dont handle incomming subtitles during seek!
578 if (!(ret = seekToImpl(to)))
580 m_subtitle_pages.clear();
589 RESULT eServiceMP3::trickSeek(gdouble ratio)
594 return seekRelative(0, 0);
598 flags = GST_SEEK_FLAG_NONE;
599 flags |= GST_SEEK_FLAG_FLUSH;
600 // flags |= GstSeekFlags (GST_SEEK_FLAG_ACCURATE);
601 flags |= GST_SEEK_FLAG_KEY_UNIT;
602 // flags |= GstSeekFlags (GST_SEEK_FLAG_SEGMENT);
603 // flags |= GstSeekFlags (GST_SEEK_FLAG_SKIP);
605 GstFormat fmt = GST_FORMAT_TIME;
607 gst_element_query_duration(m_gst_playbin, &fmt, &len);
608 gst_element_query_position(m_gst_playbin, &fmt, &pos);
612 s_event = gst_event_new_seek (ratio, GST_FORMAT_TIME, (GstSeekFlags)flags, GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, len);
614 eDebug("eServiceMP3::trickSeek with rate %lf to %" GST_TIME_FORMAT " ", ratio, GST_TIME_ARGS (pos));
618 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);
621 if (!gst_element_send_event ( GST_ELEMENT (m_gst_playbin), s_event))
623 eDebug("eServiceMP3::trickSeek failed");
631 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
637 getPlayPosition(ppos);
638 ppos += to * direction;
646 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
648 GstFormat fmt = GST_FORMAT_TIME;
655 if (m_state != stRunning)
658 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
661 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
666 gchar *name = gst_element_get_name(sink);
667 gboolean use_get_decoder_time = strstr(name, "dvbaudiosink") || strstr(name, "dvbvideosink");
670 if (use_get_decoder_time)
671 g_signal_emit_by_name(sink, "get-decoder-time", &pos);
673 gst_object_unref(sink);
675 if (!use_get_decoder_time && !gst_element_query_position(m_gst_playbin, &fmt, &pos)) {
676 eDebug("gst_element_query_position failed in getPlayPosition");
680 /* pos is in nanoseconds. we have 90 000 pts per second. */
682 eDebug("gst_element_query_position %lld pts (%lld ms)", pts, pos/1000000);
686 RESULT eServiceMP3::setTrickmode(int trick)
688 /* trickmode is not yet supported by our dvbmediasinks. */
692 RESULT eServiceMP3::isCurrentlySeekable()
694 int ret = 3; // seeking and fast/slow winding possible
699 if (m_state != stRunning)
702 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
704 // disable fast winding yet when a dvbvideosink or dvbaudiosink is used
705 // for this we must do some changes on different places.. (gstreamer.. our sinks.. enigma2)
707 ret &= ~2; // only seeking possible
708 gst_object_unref(sink);
711 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
713 ret &= ~2; // only seeking possible
714 gst_object_unref(sink);
721 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
727 RESULT eServiceMP3::getName(std::string &name)
729 std::string title = m_ref.getName();
733 size_t n = name.rfind('/');
734 if (n != std::string::npos)
735 name = name.substr(n + 1);
742 int eServiceMP3::getInfo(int w)
744 const gchar *tag = 0;
748 case sServiceref: return m_ref;
749 case sVideoHeight: return m_height;
750 case sVideoWidth: return m_width;
751 case sFrameRate: return m_framerate;
752 case sProgressive: return m_progressive;
753 case sAspect: return m_aspect;
757 case sTagTitleSortname:
758 case sTagArtistSortname:
759 case sTagAlbumSortname:
764 case sTagExtendedComment:
767 case sTagDescription:
770 case sTagOrganization:
772 case sTagCopyrightURI:
780 case sTagLanguageCode:
782 case sTagChannelMode:
789 case sTagReferenceLevel:
790 case sTagBeatsPerMinute:
792 case sTagPreviewImage:
794 return resIsPyObject;
795 case sTagTrackNumber:
796 tag = GST_TAG_TRACK_NUMBER;
799 tag = GST_TAG_TRACK_COUNT;
801 case sTagAlbumVolumeNumber:
802 tag = GST_TAG_ALBUM_VOLUME_NUMBER;
804 case sTagAlbumVolumeCount:
805 tag = GST_TAG_ALBUM_VOLUME_COUNT;
808 tag = GST_TAG_BITRATE;
810 case sTagNominalBitrate:
811 tag = GST_TAG_NOMINAL_BITRATE;
813 case sTagMinimumBitrate:
814 tag = GST_TAG_MINIMUM_BITRATE;
816 case sTagMaximumBitrate:
817 tag = GST_TAG_MAXIMUM_BITRATE;
820 tag = GST_TAG_SERIAL;
822 case sTagEncoderVersion:
823 tag = GST_TAG_ENCODER_VERSION;
832 if (!m_stream_tags || !tag)
836 if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
842 std::string eServiceMP3::getInfoString(int w)
844 if ( !m_stream_tags && w < sUser && w > 26 )
846 const gchar *tag = 0;
853 tag = GST_TAG_ARTIST;
858 case sTagTitleSortname:
859 tag = GST_TAG_TITLE_SORTNAME;
861 case sTagArtistSortname:
862 tag = GST_TAG_ARTIST_SORTNAME;
864 case sTagAlbumSortname:
865 tag = GST_TAG_ALBUM_SORTNAME;
869 if (gst_tag_list_get_date(m_stream_tags, GST_TAG_DATE, &date))
872 g_date_strftime (res, sizeof(res), "%Y-%M-%D", date);
873 return (std::string)res;
877 tag = GST_TAG_COMPOSER;
883 tag = GST_TAG_COMMENT;
885 case sTagExtendedComment:
886 tag = GST_TAG_EXTENDED_COMMENT;
889 tag = GST_TAG_LOCATION;
892 tag = GST_TAG_HOMEPAGE;
894 case sTagDescription:
895 tag = GST_TAG_DESCRIPTION;
898 tag = GST_TAG_VERSION;
903 case sTagOrganization:
904 tag = GST_TAG_ORGANIZATION;
907 tag = GST_TAG_COPYRIGHT;
909 case sTagCopyrightURI:
910 tag = GST_TAG_COPYRIGHT_URI;
913 tag = GST_TAG_CONTACT;
916 tag = GST_TAG_LICENSE;
919 tag = GST_TAG_LICENSE_URI;
925 tag = GST_TAG_AUDIO_CODEC;
928 tag = GST_TAG_VIDEO_CODEC;
931 tag = GST_TAG_ENCODER;
933 case sTagLanguageCode:
934 tag = GST_TAG_LANGUAGE_CODE;
937 tag = GST_TAG_KEYWORDS;
939 case sTagChannelMode:
940 tag = "channel-mode";
943 return m_error_message;
950 if (gst_tag_list_get_string(m_stream_tags, tag, &value))
952 std::string res = value;
959 PyObject *eServiceMP3::getInfoObject(int w)
961 const gchar *tag = 0;
962 bool isBuffer = false;
966 tag = GST_TAG_TRACK_GAIN;
969 tag = GST_TAG_TRACK_PEAK;
972 tag = GST_TAG_ALBUM_GAIN;
975 tag = GST_TAG_ALBUM_PEAK;
977 case sTagReferenceLevel:
978 tag = GST_TAG_REFERENCE_LEVEL;
980 case sTagBeatsPerMinute:
981 tag = GST_TAG_BEATS_PER_MINUTE;
987 case sTagPreviewImage:
988 tag = GST_TAG_PREVIEW_IMAGE;
992 tag = GST_TAG_ATTACHMENT;
1001 const GValue *gv_buffer = gst_tag_list_get_value_index(m_stream_tags, tag, 0);
1005 buffer = gst_value_get_buffer (gv_buffer);
1006 return PyBuffer_FromMemory(GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
1011 gdouble value = 0.0;
1012 gst_tag_list_get_double(m_stream_tags, tag, &value);
1013 return PyFloat_FromDouble(value);
1019 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
1025 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
1031 RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
1037 RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
1043 int eServiceMP3::getNumberOfTracks()
1045 return m_audioStreams.size();
1048 int eServiceMP3::getCurrentTrack()
1050 if (m_currentAudioStream == -1)
1051 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", &m_currentAudioStream, NULL);
1052 return m_currentAudioStream;
1055 RESULT eServiceMP3::selectTrack(unsigned int i)
1058 getPlayPosition(ppos);
1063 int ret = selectAudioStream(i);
1072 int eServiceMP3::selectAudioStream(int i)
1075 g_object_set (G_OBJECT (m_gst_playbin), "current-audio", i, NULL);
1076 g_object_get (G_OBJECT (m_gst_playbin), "current-audio", ¤t_audio, NULL);
1077 if ( current_audio == i )
1079 eDebug ("eServiceMP3::switched to audio stream %i", current_audio);
1080 m_currentAudioStream = i;
1086 int eServiceMP3::getCurrentChannel()
1091 RESULT eServiceMP3::selectChannel(int i)
1093 eDebug("eServiceMP3::selectChannel(%i)",i);
1097 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
1099 if (i >= m_audioStreams.size())
1101 info.m_description = m_audioStreams[i].codec;
1102 /* if (m_audioStreams[i].type == atMPEG)
1103 info.m_description = "MPEG";
1104 else if (m_audioStreams[i].type == atMP3)
1105 info.m_description = "MP3";
1106 else if (m_audioStreams[i].type == atAC3)
1107 info.m_description = "AC3";
1108 else if (m_audioStreams[i].type == atAAC)
1109 info.m_description = "AAC";
1110 else if (m_audioStreams[i].type == atDTS)
1111 info.m_description = "DTS";
1112 else if (m_audioStreams[i].type == atPCM)
1113 info.m_description = "PCM";
1114 else if (m_audioStreams[i].type == atOGG)
1115 info.m_description = "OGG";
1116 else if (m_audioStreams[i].type == atFLAC)
1117 info.m_description = "FLAC";
1119 info.m_description = "???";*/
1120 if (info.m_language.empty())
1121 info.m_language = m_audioStreams[i].language_code;
1125 subtype_t getSubtitleType(GstPad* pad, gchar *g_codec=NULL)
1127 subtype_t type = stUnknown;
1128 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1132 GstStructure* str = gst_caps_get_structure(caps, 0);
1133 const gchar *g_type = gst_structure_get_name(str);
1134 eDebug("getSubtitleType::subtitle probe caps type=%s", g_type);
1136 if ( !strcmp(g_type, "video/x-dvd-subpicture") )
1138 else if ( !strcmp(g_type, "text/x-pango-markup") )
1140 else if ( !strcmp(g_type, "text/plain") )
1143 eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec);
1147 eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec);
1148 if ( !strcmp(g_codec, "VOB") )
1150 else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") )
1152 else if ( !strcmp(g_codec, "ASS") )
1154 else if ( !strcmp(g_codec, "UTF-8 plain text") )
1157 eDebug("getSubtitleType::unsupported subtitle codec %s", g_codec);
1160 eDebug("getSubtitleType::unidentifiable subtitle stream!");
1165 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
1172 source = GST_MESSAGE_SRC(msg);
1173 sourceName = gst_object_get_name(source);
1175 if (gst_message_get_structure(msg))
1177 gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
1178 eDebug("eServiceMP3::gst_message from %s: %s", sourceName, string);
1182 eDebug("eServiceMP3::gst_message from %s: %s (without structure)", sourceName, GST_MESSAGE_TYPE_NAME(msg));
1184 switch (GST_MESSAGE_TYPE (msg))
1186 case GST_MESSAGE_EOS:
1187 m_event((iPlayableService*)this, evEOF);
1189 case GST_MESSAGE_STATE_CHANGED:
1191 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1194 GstState old_state, new_state;
1195 gst_message_parse_state_changed(msg, &old_state, &new_state, NULL);
1197 if(old_state == new_state)
1200 eDebug("eServiceMP3::state transition %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state));
1202 GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state);
1206 case GST_STATE_CHANGE_NULL_TO_READY:
1209 case GST_STATE_CHANGE_READY_TO_PAUSED:
1211 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_subtitlebin), "subtitle_sink");
1212 // GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1215 g_object_set (G_OBJECT (appsink), "max-buffers", 2, NULL);
1216 g_object_set (G_OBJECT (appsink), "sync", FALSE, NULL);
1217 g_object_set (G_OBJECT (appsink), "async", FALSE, NULL);
1218 g_object_set (G_OBJECT (appsink), "emit-signals", TRUE, NULL);
1219 eDebug("eServiceMP3::appsink properties set!");
1220 gst_object_unref(appsink);
1222 setAC3Delay(ac3_delay);
1223 setPCMDelay(pcm_delay);
1225 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1228 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1231 case GST_STATE_CHANGE_PAUSED_TO_READY:
1234 case GST_STATE_CHANGE_READY_TO_NULL:
1240 case GST_MESSAGE_ERROR:
1244 gst_message_parse_error (msg, &err, &debug);
1246 eWarning("Gstreamer error: %s (%i) from %s", err->message, err->code, sourceName );
1247 if ( err->domain == GST_STREAM_ERROR )
1249 if ( err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND )
1251 if ( g_strrstr(sourceName, "videosink") )
1252 m_event((iPlayableService*)this, evUser+11);
1253 else if ( g_strrstr(sourceName, "audiosink") )
1254 m_event((iPlayableService*)this, evUser+10);
1260 case GST_MESSAGE_INFO:
1265 gst_message_parse_info (msg, &inf, &debug);
1267 if ( inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE )
1269 if ( g_strrstr(sourceName, "videosink") )
1270 m_event((iPlayableService*)this, evUser+14);
1275 case GST_MESSAGE_TAG:
1277 GstTagList *tags, *result;
1278 gst_message_parse_tag(msg, &tags);
1280 result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_REPLACE);
1284 gst_tag_list_free(m_stream_tags);
1285 m_stream_tags = result;
1288 const GValue *gv_image = gst_tag_list_get_value_index(tags, GST_TAG_IMAGE, 0);
1291 GstBuffer *buf_image;
1292 buf_image = gst_value_get_buffer (gv_image);
1293 int fd = open("/tmp/.id3coverart", O_CREAT|O_WRONLY|O_TRUNC, 0644);
1294 int ret = write(fd, GST_BUFFER_DATA(buf_image), GST_BUFFER_SIZE(buf_image));
1296 eDebug("eServiceMP3::/tmp/.id3coverart %d bytes written ", ret);
1297 m_event((iPlayableService*)this, evUser+13);
1299 gst_tag_list_free(tags);
1300 m_event((iPlayableService*)this, evUpdatedInfo);
1303 case GST_MESSAGE_ASYNC_DONE:
1305 if(GST_MESSAGE_SRC(msg) != GST_OBJECT(m_gst_playbin))
1309 gint i, active_idx, n_video = 0, n_audio = 0, n_text = 0;
1311 g_object_get (m_gst_playbin, "n-video", &n_video, NULL);
1312 g_object_get (m_gst_playbin, "n-audio", &n_audio, NULL);
1313 g_object_get (m_gst_playbin, "n-text", &n_text, NULL);
1315 eDebug("eServiceMP3::async-done - %d video, %d audio, %d subtitle", n_video, n_audio, n_text);
1317 if ( n_video + n_audio <= 0 )
1322 m_audioStreams.clear();
1323 m_subtitleStreams.clear();
1325 for (i = 0; i < n_audio; i++)
1328 gchar *g_codec, *g_lang;
1330 g_signal_emit_by_name (m_gst_playbin, "get-audio-pad", i, &pad);
1331 GstCaps* caps = gst_pad_get_negotiated_caps(pad);
1334 GstStructure* str = gst_caps_get_structure(caps, 0);
1335 const gchar *g_type = gst_structure_get_name(str);
1336 audio.type = gstCheckAudioPad(str);
1337 g_codec = g_strdup(g_type);
1338 g_lang = g_strdup_printf ("und");
1339 g_signal_emit_by_name (m_gst_playbin, "get-audio-tags", i, &tags);
1340 if ( tags && gst_is_tag_list(tags) )
1342 gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec);
1343 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1344 gst_tag_list_free(tags);
1346 audio.language_code = std::string(g_lang);
1347 audio.codec = std::string(g_codec);
1348 eDebug("eServiceMP3::audio stream=%i codec=%s language=%s", i, g_codec, g_lang);
1349 m_audioStreams.push_back(audio);
1352 gst_caps_unref(caps);
1355 for (i = 0; i < n_text; i++)
1357 gchar *g_codec = NULL, *g_lang = NULL;
1358 g_signal_emit_by_name (m_gst_playbin, "get-text-tags", i, &tags);
1359 subtitleStream subs;
1362 g_lang = g_strdup_printf ("und");
1363 if ( tags && gst_is_tag_list(tags) )
1365 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1366 gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec);
1367 gst_tag_list_free(tags);
1370 subs.language_code = std::string(g_lang);
1371 eDebug("eServiceMP3::subtitle stream=%i language=%s codec=%s", i, g_lang, g_codec);
1374 g_signal_emit_by_name (m_gst_playbin, "get-text-pad", i, &pad);
1375 if ( subs.type != stSRT )
1376 subs.type = getSubtitleType(pad, g_codec);
1378 m_subtitleStreams.push_back(subs);
1381 m_event((iPlayableService*)this, evUpdatedEventInfo);
1383 case GST_MESSAGE_ELEMENT:
1385 if ( gst_is_missing_plugin_message(msg) )
1387 gchar *description = gst_missing_plugin_message_get_description(msg);
1390 m_error_message = "GStreamer plugin " + (std::string)description + " not available!\n";
1391 g_free(description);
1392 m_event((iPlayableService*)this, evUser+12);
1395 else if (const GstStructure *msgstruct = gst_message_get_structure(msg))
1397 const gchar *eventname = gst_structure_get_name(msgstruct);
1400 if (!strcmp(eventname, "eventSizeChanged") || !strcmp(eventname, "eventSizeAvail"))
1402 gst_structure_get_int (msgstruct, "aspect_ratio", &m_aspect);
1403 gst_structure_get_int (msgstruct, "width", &m_width);
1404 gst_structure_get_int (msgstruct, "height", &m_height);
1405 if (strstr(eventname, "Changed"))
1406 m_event((iPlayableService*)this, evVideoSizeChanged);
1408 else if (!strcmp(eventname, "eventFrameRateChanged") || !strcmp(eventname, "eventFrameRateAvail"))
1410 gst_structure_get_int (msgstruct, "frame_rate", &m_framerate);
1411 if (strstr(eventname, "Changed"))
1412 m_event((iPlayableService*)this, evVideoFramerateChanged);
1414 else if (!strcmp(eventname, "eventProgressiveChanged") || !strcmp(eventname, "eventProgressiveAvail"))
1416 gst_structure_get_int (msgstruct, "progressive", &m_progressive);
1417 if (strstr(eventname, "Changed"))
1418 m_event((iPlayableService*)this, evVideoProgressiveChanged);
1424 case GST_MESSAGE_BUFFERING:
1426 GstBufferingMode mode;
1427 gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
1428 gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
1429 m_event((iPlayableService*)this, evBuffering);
1434 g_free (sourceName);
1437 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
1439 eServiceMP3 *_this = (eServiceMP3*)user_data;
1440 _this->m_pump.send(1);
1442 return GST_BUS_PASS;
1445 audiotype_t eServiceMP3::gstCheckAudioPad(GstStructure* structure)
1450 if ( gst_structure_has_name (structure, "audio/mpeg"))
1452 gint mpegversion, layer = -1;
1453 if (!gst_structure_get_int (structure, "mpegversion", &mpegversion))
1456 switch (mpegversion) {
1459 gst_structure_get_int (structure, "layer", &layer);
1475 else if ( gst_structure_has_name (structure, "audio/x-ac3") || gst_structure_has_name (structure, "audio/ac3") )
1477 else if ( gst_structure_has_name (structure, "audio/x-dts") || gst_structure_has_name (structure, "audio/dts") )
1479 else if ( gst_structure_has_name (structure, "audio/x-raw-int") )
1485 void eServiceMP3::gstPoll(const int &msg)
1487 /* ok, we have a serious problem here. gstBusSyncHandler sends
1488 us the wakup signal, but likely before it was posted.
1489 the usleep, an EVIL HACK (DON'T DO THAT!!!) works around this.
1491 I need to understand the API a bit more to make this work
1495 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_playbin));
1496 GstMessage *message;
1498 while ((message = gst_bus_pop (bus)))
1500 gstBusCall(bus, message);
1501 gst_message_unref (message);
1508 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1510 void eServiceMP3::gstCBsubtitleAvail(GstElement *appsink, gpointer user_data)
1512 eServiceMP3 *_this = (eServiceMP3*)user_data;
1513 eSingleLocker l(_this->m_subs_to_pull_lock);
1514 ++_this->m_subs_to_pull;
1515 _this->m_pump.send(2);
1518 void eServiceMP3::gstCBsubtitleCAPS(GObject *obj, GParamSpec *pspec, gpointer user_data)
1520 eDebug("gstCBsubtitleCAPS:: signal::caps callback obj=%p", obj);
1522 eServiceMP3 *_this = (eServiceMP3*)user_data;
1523 eDebug("gstCBsubtitleCAPS:: m_currentSubtitleStream=%i, m_subtitleStreams.size()=%i", _this->m_currentSubtitleStream, _this->m_subtitleStreams.size());
1525 if ( _this->m_currentSubtitleStream >= _this->m_subtitleStreams.size() )
1531 subtitleStream subs = _this->m_subtitleStreams[_this->m_currentSubtitleStream];
1533 if ( subs.type == stUnknown )
1536 eDebug("gstCBsubtitleCAPS::m_subtitleStreams[%i].type == stUnknown...", _this->m_currentSubtitleStream);
1539 g_signal_emit_by_name (_this->m_gst_playbin, "get-text-tags", _this->m_currentSubtitleStream, &tags);
1541 g_lang = g_strdup_printf ("und");
1542 if ( tags && gst_is_tag_list(tags) )
1543 gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang);
1544 subs.language_code = std::string(g_lang);
1546 subs.type = getSubtitleType(GST_PAD(obj));
1548 _this->m_subtitleStreams[_this->m_currentSubtitleStream] = subs;
1554 void eServiceMP3::gstCBsubtitleLink(subtype_t type, gpointer user_data)
1556 eServiceMP3 *_this = (eServiceMP3*)user_data;
1558 if ( type == stVOB )
1560 GstPad *ghostpad = gst_element_get_static_pad(_this->m_gst_subtitlebin, "sink");
1561 GstElement *dvdsubdec = gst_bin_get_by_name(GST_BIN(_this->m_gst_subtitlebin), "vobsubtitle_decoder");
1562 GstPad *subdecsinkpad = gst_element_get_static_pad (dvdsubdec, "sink");
1563 int ret = gst_ghost_pad_set_target((GstGhostPad*)ghostpad, subdecsinkpad);
1564 GstElement *appsink = gst_bin_get_by_name(GST_BIN(_this->m_gst_subtitlebin), "subtitle_sink");
1565 ret += gst_element_link(dvdsubdec, appsink);
1566 eDebug("gstCBsubtitleLink:: dvdsubdec=%p, subdecsinkpad=%p, ghostpad=%p, link=%i", dvdsubdec, subdecsinkpad, ghostpad, ret);
1568 else if ( type < stVOB && type > stUnknown )
1570 GstPad *ghostpad = gst_element_get_static_pad(_this->m_gst_subtitlebin, "sink");
1571 GstElement *appsink = gst_bin_get_by_name(GST_BIN(_this->m_gst_subtitlebin), "subtitle_sink");
1572 GstPad *appsinkpad = gst_element_get_static_pad (appsink, "sink");
1573 GstElement *dvdsubdec = gst_bin_get_by_name(GST_BIN(_this->m_gst_subtitlebin), "vobsubtitle_decoder");
1574 gst_element_unlink(dvdsubdec, appsink);
1575 int ret = gst_ghost_pad_set_target((GstGhostPad*)ghostpad, appsinkpad);
1576 eDebug("gstCBsubtitleLink:: appsink=%p, appsinkpad=%p, ghostpad=%p, link=%i", appsink, appsinkpad, ghostpad, ret);
1580 GstPad *ghostpad = gst_element_get_static_pad(_this->m_gst_subtitlebin, "sink");
1581 GstElement *fakesink = gst_bin_get_by_name(GST_BIN(_this->m_gst_subtitlebin), "subtitle_fakesink");
1582 GstPad *fakesinkpad = gst_element_get_static_pad (fakesink, "sink");
1583 int ret = gst_ghost_pad_set_target((GstGhostPad*)ghostpad, fakesinkpad);
1584 eDebug("gstCBsubtitleLink:: unsupported subtitles ... throwing them into fakesink");
1588 void eServiceMP3::pullSubtitle()
1590 GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_subtitlebin), "subtitle_sink");
1591 // GstElement *appsink = gst_bin_get_by_name(GST_BIN(m_gst_playbin), "subtitle_sink");
1595 while (m_subs_to_pull && m_subtitle_pages.size() < 2)
1599 eSingleLocker l(m_subs_to_pull_lock);
1601 g_signal_emit_by_name (appsink, "pull-buffer", &buffer);
1605 gint64 buf_pos = GST_BUFFER_TIMESTAMP(buffer);
1606 gint64 duration_ns = GST_BUFFER_DURATION(buffer);
1607 size_t len = GST_BUFFER_SIZE(buffer);
1608 eDebug("pullSubtitle m_subtitleStreams[m_currentSubtitleStream].type=%i",m_subtitleStreams[m_currentSubtitleStream].type);
1610 if ( m_subtitleStreams[m_currentSubtitleStream].type )
1612 if ( m_subtitleStreams[m_currentSubtitleStream].type < stVOB )
1614 unsigned char line[len+1];
1615 memcpy(line, GST_BUFFER_DATA(buffer), len);
1617 eDebug("got new text subtitle @ buf_pos = %lld ns (in pts=%lld): '%s' ", buf_pos, buf_pos/11111, line);
1618 ePangoSubtitlePage* page = new ePangoSubtitlePage;
1619 gRGB rgbcol(0xD0,0xD0,0xD0);
1620 page->m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)line));
1621 page->show_pts = buf_pos / 11111L;
1622 page->m_timeout = duration_ns / 1000000;
1623 SubtitlePage subtitlepage;
1624 subtitlepage.pango_page = page;
1625 subtitlepage.vob_page = NULL;
1626 m_subtitle_pages.push_back(subtitlepage);
1631 eDebug("got new subpicture @ buf_pos = %lld ns (in pts=%lld), duration=%lld ns, len=%i bytes. ", buf_pos, buf_pos/11111, duration_ns, len);
1632 eVobSubtitlePage* page = new eVobSubtitlePage;
1633 eSize size = eSize(720, 576);
1634 page->m_pixmap = new gPixmap(size, 32, 0);
1635 // ePtr<gPixmap> pixmap;
1636 // pixmap = new gPixmap(size, 32, 1); /* allocate accel surface (if possible) */
1637 memcpy(page->m_pixmap->surface->data, GST_BUFFER_DATA(buffer), len);
1638 page->show_pts = buf_pos / 11111L;
1639 page->m_timeout = duration_ns / 1000;
1640 SubtitlePage subtitlepage;
1641 subtitlepage.vob_page = page;
1642 subtitlepage.pango_page = NULL;
1643 m_subtitle_pages.push_back(subtitlepage);
1647 gst_buffer_unref(buffer);
1650 gst_object_unref(appsink);
1653 eDebug("no subtitle sink!");
1656 void eServiceMP3::pushSubtitles()
1659 while ( !m_subtitle_pages.empty() )
1661 SubtitlePage frontpage = m_subtitle_pages.front();
1664 getPlayPosition(running_pts);
1666 if ( frontpage.pango_page != 0 )
1668 diff_ms = ( frontpage.pango_page->show_pts - running_pts ) / 90;
1669 eDebug("eServiceMP3::pushSubtitles TEXT show_pts = %lld running_pts = %lld diff = %lld", frontpage.pango_page->show_pts, running_pts, diff_ms);
1672 if ( frontpage.vob_page != 0 )
1674 diff_ms = ( frontpage.vob_page->show_pts - running_pts ) / 90;
1675 eDebug("eServiceMP3::pushSubtitles VOB show_pts = %lld running_pts = %lld diff = %lld", frontpage.vob_page->show_pts, running_pts, diff_ms);
1678 if ( diff_ms < -100 )
1680 GstFormat fmt = GST_FORMAT_TIME;
1682 if ( gst_element_query_position(m_gst_playbin, &fmt, &now) != -1 )
1685 diff_ms = abs((now - running_pts) / 90);
1686 eDebug("diff < -100ms check decoder/pipeline diff: decoder: %lld, pipeline: %lld, diff: %lld", running_pts, now, diff_ms);
1687 if (diff_ms > 100000)
1689 eDebug("high decoder/pipeline difference.. assume decoder has now started yet.. check again in 1sec");
1690 m_subtitle_sync_timer->start(1000, true);
1695 eDebug("query position for decoder/pipeline check failed!");
1696 eDebug("subtitle to late... drop");
1697 m_subtitle_pages.pop_front();
1699 else if ( diff_ms > 20 )
1701 eDebug("start recheck timer");
1702 m_subtitle_sync_timer->start(diff_ms > 1000 ? 1000 : diff_ms, true);
1705 else // immediate show
1707 if ( m_subtitle_widget )
1709 if ( frontpage.pango_page != 0)
1711 eDebug("immediate show pango subtitle line");
1712 m_subtitle_widget->setPage(*(frontpage.pango_page));
1714 else if ( frontpage.vob_page != 0)
1716 m_subtitle_widget->setPixmap(frontpage.vob_page->m_pixmap, eRect(0, 0, 720, 576));
1717 eDebug("blit vobsub pixmap... hide in %i ms", frontpage.vob_page->m_timeout);
1718 m_subtitle_hide_timer->start(frontpage.vob_page->m_timeout, true);
1720 m_subtitle_widget->show();
1722 m_subtitle_pages.pop_front();
1725 if (m_subtitle_pages.empty())
1729 void eServiceMP3::hideSubtitles()
1731 eDebug("eServiceMP3::hideSubtitles()");
1732 if ( m_subtitle_widget )
1733 m_subtitle_widget->hide();
1736 RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
1738 eDebug ("eServiceMP3::enableSubtitles m_currentSubtitleStream=%i",m_currentSubtitleStream);
1740 int tuplesize = PyTuple_Size(tuple);
1743 eSingleLocker l(m_subs_to_pull_lock);
1745 if (!PyTuple_Check(tuple))
1749 entry = PyTuple_GET_ITEM(tuple, 1);
1750 if (!PyInt_Check(entry))
1752 pid = PyInt_AsLong(entry);
1753 entry = PyTuple_GET_ITEM(tuple, 2);
1754 if (!PyInt_Check(entry))
1756 type = PyInt_AsLong(entry);
1758 eDebug ("eServiceMP3::enableSubtitles new pid=%i",pid);
1759 // if (m_currentSubtitleStream != pid)
1762 g_object_set (G_OBJECT (m_gst_playbin), "current-text", pid, NULL);
1763 eDebug ("eServiceMP3::enableSubtitles g_object_set");
1764 m_currentSubtitleStream = pid;
1766 m_subtitle_pages.clear();
1767 eDebug ("eServiceMP3::enableSubtitles cleared");
1770 gstCBsubtitleLink(m_subtitleStreams[m_currentSubtitleStream].type, this);
1772 m_subtitle_widget = 0;
1773 m_subtitle_widget = new eSubtitleWidget(parent);
1774 m_subtitle_widget->resize(parent->size()); /* full size */
1776 g_object_get (G_OBJECT (m_gst_playbin), "current-text", &text_pid, NULL);
1778 eDebug ("eServiceMP3::switched to subtitle stream %i", text_pid);
1779 m_event((iPlayableService*)this, evUpdatedInfo);
1784 eDebug("eServiceMP3::enableSubtitles needs a tuple as 2nd argument!\n"
1785 "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
1789 RESULT eServiceMP3::disableSubtitles(eWidget *parent)
1791 eDebug("eServiceMP3::disableSubtitles");
1792 m_subtitle_pages.clear();
1793 eDebug("eServiceMP3::disableSubtitles cleared");
1794 delete m_subtitle_widget;
1795 eDebug("eServiceMP3::disableSubtitles deleted");
1796 m_subtitle_widget = 0;
1797 eDebug("eServiceMP3::disableSubtitles nulled");
1801 PyObject *eServiceMP3::getCachedSubtitle()
1803 // eDebug("eServiceMP3::getCachedSubtitle");
1807 PyObject *eServiceMP3::getSubtitleList()
1809 eDebug("eServiceMP3::getSubtitleList");
1810 ePyObject l = PyList_New(0);
1813 for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
1815 subtype_t type = IterSubtitleStream->type;
1816 ePyObject tuple = PyTuple_New(5);
1817 eDebug("eServiceMP3::getSubtitleList idx=%i type=%i, code=%s", stream_idx, int(type), (IterSubtitleStream->language_code).c_str());
1818 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
1819 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_idx));
1820 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
1821 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
1822 PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
1823 PyList_Append(l, tuple);
1827 eDebug("eServiceMP3::getSubtitleList finished");
1831 RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
1837 PyObject *eServiceMP3::getBufferCharge()
1839 ePyObject tuple = PyTuple_New(5);
1840 PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
1841 PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
1842 PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
1843 PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
1844 PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
1848 int eServiceMP3::setBufferSize(int size)
1850 m_buffer_size = size;
1851 g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
1855 int eServiceMP3::getAC3Delay()
1860 int eServiceMP3::getPCMDelay()
1865 void eServiceMP3::setAC3Delay(int delay)
1868 if (!m_gst_playbin || m_state != stRunning)
1873 int config_delay_int = delay;
1874 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1878 std::string config_delay;
1879 if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
1880 config_delay_int += atoi(config_delay.c_str());
1881 gst_object_unref(sink);
1885 eDebug("dont apply ac3 delay when no video is running!");
1886 config_delay_int = 0;
1889 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1893 gchar *name = gst_element_get_name(sink);
1894 if (strstr(name, "dvbaudiosink"))
1895 eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
1897 gst_object_unref(sink);
1902 void eServiceMP3::setPCMDelay(int delay)
1905 if (!m_gst_playbin || m_state != stRunning)
1910 int config_delay_int = delay;
1911 g_object_get (G_OBJECT (m_gst_playbin), "video-sink", &sink, NULL);
1915 std::string config_delay;
1916 if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
1917 config_delay_int += atoi(config_delay.c_str());
1918 gst_object_unref(sink);
1922 eDebug("dont apply pcm delay when no video is running!");
1923 config_delay_int = 0;
1926 g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
1930 gchar *name = gst_element_get_name(sink);
1931 if (strstr(name, "dvbaudiosink"))
1932 eTSMPEGDecoder::setHwPCMDelay(config_delay_int);
1935 // this is realy untested..and not used yet
1936 gint64 offset = config_delay_int;
1937 offset *= 1000000; // milli to nano
1938 g_object_set (G_OBJECT (m_gst_playbin), "ts-offset", offset, NULL);
1941 gst_object_unref(sink);
1947 #warning gstreamer not available, not building media player