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/eerror.h>
6 #include <lib/base/object.h>
7 #include <lib/base/ebase.h>
9 #include <lib/service/servicemp3.h>
10 #include <lib/service/service.h>
11 #include <lib/components/file_eraser.h>
12 #include <lib/base/init_num.h>
13 #include <lib/base/init.h>
18 eServiceFactoryMP3::eServiceFactoryMP3()
20 ePtr<eServiceCenter> sc;
22 eServiceCenter::getPrivInstance(sc);
25 std::list<std::string> extensions;
26 extensions.push_back("mp3");
27 extensions.push_back("ogg");
28 extensions.push_back("mpg");
29 extensions.push_back("vob");
30 extensions.push_back("wav");
31 extensions.push_back("wave");
32 extensions.push_back("mkv");
33 extensions.push_back("avi");
34 sc->addServiceFactory(eServiceFactoryMP3::id, this, extensions);
37 m_service_info = new eStaticServiceMP3Info();
40 eServiceFactoryMP3::~eServiceFactoryMP3()
42 ePtr<eServiceCenter> sc;
44 eServiceCenter::getPrivInstance(sc);
46 sc->removeServiceFactory(eServiceFactoryMP3::id);
49 DEFINE_REF(eServiceFactoryMP3)
52 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
55 ptr = new eServiceMP3(ref.path.c_str());
59 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
65 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
71 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
77 class eMP3ServiceOfflineOperations: public iServiceOfflineOperations
79 DECLARE_REF(eMP3ServiceOfflineOperations);
80 eServiceReference m_ref;
82 eMP3ServiceOfflineOperations(const eServiceReference &ref);
84 RESULT deleteFromDisk(int simulate);
85 RESULT getListOfFilenames(std::list<std::string> &);
88 DEFINE_REF(eMP3ServiceOfflineOperations);
90 eMP3ServiceOfflineOperations::eMP3ServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReference&)ref)
94 RESULT eMP3ServiceOfflineOperations::deleteFromDisk(int simulate)
100 std::list<std::string> res;
101 if (getListOfFilenames(res))
104 eBackgroundFileEraser *eraser = eBackgroundFileEraser::getInstance();
106 eDebug("FATAL !! can't get background file eraser");
108 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
110 eDebug("Removing %s...", i->c_str());
112 eraser->erase(i->c_str());
114 ::unlink(i->c_str());
121 RESULT eMP3ServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
124 res.push_back(m_ref.path);
129 RESULT eServiceFactoryMP3::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
131 ptr = new eMP3ServiceOfflineOperations(ref);
135 // eStaticServiceMP3Info
138 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
139 // about unopened files.
141 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
142 // should have a database backend where ID3-files etc. are cached.
143 // this would allow listing the mp3 database based on certain filters.
145 DEFINE_REF(eStaticServiceMP3Info)
147 eStaticServiceMP3Info::eStaticServiceMP3Info()
151 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
153 size_t last = ref.path.rfind('/');
154 if (last != std::string::npos)
155 name = ref.path.substr(last+1);
161 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
168 eServiceMP3::eServiceMP3(const char *filename): m_filename(filename), m_pump(eApp, 1)
171 m_audioStreams.clear();
172 m_currentAudioStream = 0;
173 m_currentTrickRatio = 0;
174 CONNECT(m_seekTimeout.timeout, eServiceMP3::seekTimeoutCB);
175 CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
176 GstElement *source = 0;
178 GstElement *filter = 0, *decoder = 0, *conv = 0, *flt = 0, *sink = 0; /* for audio */
180 GstElement *audio = 0, *switch_audio = 0, *queue_audio = 0, *video = 0, *queue_video = 0, *videodemux = 0;
183 eDebug("SERVICEMP3 construct!");
185 /* FIXME: currently, decodebin isn't possible for
186 video streams. in that case, make a manual pipeline. */
188 const char *ext = strrchr(filename, '.');
192 int is_mpeg_ps = !(strcasecmp(ext, ".mpeg") && strcasecmp(ext, ".mpg") && strcasecmp(ext, ".vob") && strcasecmp(ext, ".bin"));
193 int is_mpeg_ts = !strcasecmp(ext, ".ts");
194 int is_matroska = !strcasecmp(ext, ".mkv");
195 int is_avi = !strcasecmp(ext, ".avi");
196 int is_mp3 = !strcasecmp(ext, ".mp3"); /* force mp3 instead of decodebin */
197 int is_video = is_mpeg_ps || is_mpeg_ts || is_matroska || is_avi;
198 int is_streaming = !strncmp(filename, "http://", 7);
199 int is_AudioCD = !(strncmp(filename, "/autofs/", 8) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav"));
201 eDebug("filename: %s, is_mpeg_ps: %d, is_mpeg_ts: %d, is_video: %d, is_streaming: %d, is_mp3: %d, is_matroska: %d, is_avi: %d, is_AudioCD: %d", filename, is_mpeg_ps, is_mpeg_ts, is_video, is_streaming, is_mp3, is_matroska, is_avi, is_AudioCD);
203 int is_audio = !is_video;
207 m_gst_pipeline = gst_pipeline_new ("mediaplayer");
209 eWarning("failed to create pipeline");
213 source = gst_element_factory_make ("cdiocddasrc", "cda-source");
215 g_object_set (G_OBJECT (source), "device", "/dev/cdroms/cdrom0", NULL);
219 if ( !is_streaming && !is_AudioCD )
220 source = gst_element_factory_make ("filesrc", "file-source");
221 else if ( is_streaming )
223 source = gst_element_factory_make ("neonhttpsrc", "http-source");
225 g_object_set (G_OBJECT (source), "automatic-redirect", TRUE, NULL);
229 eWarning("failed to create %s", is_streaming ? "neonhttpsrc" : "filesrc");
230 /* configure source */
231 else if (!is_AudioCD)
232 g_object_set (G_OBJECT (source), "location", filename, NULL);
235 int track = atoi(filename+18);
236 eDebug("play audio CD track #%i",track);
238 g_object_set (G_OBJECT (source), "track", track, NULL);
243 /* filesrc -> decodebin -> audioconvert -> capsfilter -> alsasink */
244 const char *decodertype = is_mp3 ? "mad" : "decodebin";
246 decoder = gst_element_factory_make (decodertype, "decoder");
248 eWarning("failed to create %s decoder", decodertype);
250 /* mp3 decoding needs id3demux to extract ID3 data. 'decodebin' would do that internally. */
253 filter = gst_element_factory_make ("id3demux", "filter");
255 eWarning("failed to create id3demux");
258 conv = gst_element_factory_make ("audioconvert", "converter");
260 eWarning("failed to create audioconvert");
262 flt = gst_element_factory_make ("capsfilter", "flt");
264 eWarning("failed to create capsfilter");
266 /* for some reasons, we need to set the sample format to depth/width=16, because auto negotiation doesn't work. */
267 /* endianness, however, is not required to be set anymore. */
270 GstCaps *caps = gst_caps_new_simple("audio/x-raw-int", /* "endianness", G_TYPE_INT, 4321, */ "depth", G_TYPE_INT, 16, "width", G_TYPE_INT, 16, /*"channels", G_TYPE_INT, 2, */(char*)0);
271 g_object_set (G_OBJECT (flt), "caps", caps, (char*)0);
272 gst_caps_unref(caps);
275 sink = gst_element_factory_make ("alsasink", "alsa-output");
277 eWarning("failed to create osssink");
279 if (source && decoder && conv && sink)
281 } else /* is_video */
283 /* filesrc -> mpegdemux -> | queue_audio -> dvbaudiosink
284 | queue_video -> dvbvideosink */
286 audio = gst_element_factory_make("dvbaudiosink", "audiosink");
287 queue_audio = gst_element_factory_make("queue", "queue_audio");
289 video = gst_element_factory_make("dvbvideosink", "videosink");
290 queue_video = gst_element_factory_make("queue", "queue_video");
293 videodemux = gst_element_factory_make("flupsdemux", "videodemux");
295 videodemux = gst_element_factory_make("flutsdemux", "videodemux");
296 else if (is_matroska)
297 videodemux = gst_element_factory_make("matroskademux", "videodemux");
299 videodemux = gst_element_factory_make("avidemux", "videodemux");
303 eDebug("fluendo mpegdemux not available, falling back to mpegdemux\n");
304 videodemux = gst_element_factory_make("mpegdemux", "videodemux");
307 eDebug("audio: %p, queue_audio %p, video %p, queue_video %p, videodemux %p", audio, queue_audio, video, queue_video, videodemux);
308 if (audio && queue_audio && video && queue_video && videodemux)
310 g_object_set (G_OBJECT (queue_audio), "max-size-bytes", 256*1024, NULL);
311 g_object_set (G_OBJECT (queue_audio), "max-size-buffers", 0, NULL);
312 g_object_set (G_OBJECT (queue_audio), "max-size-time", (guint64)0, NULL);
313 g_object_set (G_OBJECT (queue_video), "max-size-buffers", 0, NULL);
314 g_object_set (G_OBJECT (queue_video), "max-size-bytes", 2*1024*1024, NULL);
315 g_object_set (G_OBJECT (queue_video), "max-size-time", (guint64)0, NULL);
320 if (m_gst_pipeline && all_ok)
322 gst_bus_set_sync_handler(gst_pipeline_get_bus (GST_PIPELINE (m_gst_pipeline)), gstBusSyncHandler, this);
326 queue_audio = gst_element_factory_make("queue", "queue_audio");
327 g_object_set (G_OBJECT (sink), "preroll-queue-len", 80, NULL);
328 gst_bin_add_many (GST_BIN (m_gst_pipeline), source, queue_audio, conv, sink, NULL);
329 gst_element_link_many(source, queue_audio, conv, sink, NULL);
333 queue_audio = gst_element_factory_make("queue", "queue_audio");
337 /* decodebin has dynamic pads. When they get created, we connect them to the audio bin */
338 g_signal_connect (decoder, "new-decoded-pad", G_CALLBACK(gstCBnewPad), this);
339 g_signal_connect (decoder, "unknown-type", G_CALLBACK(gstCBunknownType), this);
340 g_object_set (G_OBJECT (sink), "preroll-queue-len", 80, NULL);
343 /* gst_bin will take the 'floating references' */
344 gst_bin_add_many (GST_BIN (m_gst_pipeline),
345 source, queue_audio, decoder, NULL);
349 /* id3demux also has dynamic pads, which need to be connected to the decoder (this is done in the 'gstCBfilterPadAdded' CB) */
350 gst_bin_add(GST_BIN(m_gst_pipeline), filter);
351 gst_element_link(source, filter);
352 g_signal_connect (filter, "pad-added", G_CALLBACK(gstCBfilterPadAdded), this);
354 /* in decodebin's case we can just connect the source with the decodebin, and decodebin will take care about id3demux (or whatever is required) */
355 gst_element_link_many(source, queue_audio, decoder, NULL);
357 /* create audio bin with the audioconverter, the capsfilter and the audiosink */
358 audio = gst_bin_new ("audiobin");
360 GstPad *audiopad = gst_element_get_static_pad (conv, "sink");
361 gst_bin_add_many(GST_BIN(audio), conv, flt, sink, (char*)0);
362 gst_element_link_many(conv, flt, sink, (char*)0);
363 gst_element_add_pad(audio, gst_ghost_pad_new ("sink", audiopad));
364 gst_object_unref(audiopad);
365 gst_bin_add (GST_BIN(m_gst_pipeline), audio);
366 /* in mad's case, we can directly connect the decoder to the audiobin. otherwise, we do this in gstCBnewPad */
368 gst_element_link(decoder, audio);
369 audioStream audioStreamElem;
370 m_audioStreams.push_back(audioStreamElem);
371 } else /* is_video */
373 gst_bin_add_many(GST_BIN(m_gst_pipeline), source, videodemux, audio, queue_audio, video, queue_video, NULL);
374 switch_audio = gst_element_factory_make ("input-selector", "switch_audio");
377 g_object_set (G_OBJECT (switch_audio), "select-all", TRUE, NULL);
378 gst_bin_add(GST_BIN(m_gst_pipeline), switch_audio);
379 gst_element_link(switch_audio, queue_audio);
381 gst_element_link(source, videodemux);
382 gst_element_link(queue_audio, audio);
383 gst_element_link(queue_video, video);
384 g_signal_connect(videodemux, "pad-added", G_CALLBACK (gstCBpadAdded), this);
389 gst_object_unref(GST_OBJECT(m_gst_pipeline));
391 gst_object_unref(GST_OBJECT(source));
393 gst_object_unref(GST_OBJECT(decoder));
395 gst_object_unref(GST_OBJECT(conv));
397 gst_object_unref(GST_OBJECT(sink));
400 gst_object_unref(GST_OBJECT(audio));
402 gst_object_unref(GST_OBJECT(queue_audio));
404 gst_object_unref(GST_OBJECT(video));
406 gst_object_unref(GST_OBJECT(queue_video));
408 gst_object_unref(GST_OBJECT(videodemux));
410 gst_object_unref(GST_OBJECT(switch_audio));
412 eDebug("sorry, can't play.");
416 gst_element_set_state (m_gst_pipeline, GST_STATE_PLAYING);
419 eServiceMP3::~eServiceMP3()
421 if (m_state == stRunning)
425 gst_tag_list_free(m_stream_tags);
429 gst_object_unref (GST_OBJECT (m_gst_pipeline));
430 eDebug("SERVICEMP3 destruct!");
434 DEFINE_REF(eServiceMP3);
436 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
438 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
442 RESULT eServiceMP3::start()
444 assert(m_state == stIdle);
449 eDebug("starting pipeline");
450 gst_element_set_state (m_gst_pipeline, GST_STATE_PLAYING);
452 m_event(this, evStart);
456 RESULT eServiceMP3::stop()
458 assert(m_state != stIdle);
459 if (m_state == stStopped)
461 eDebug("MP3: %s stop\n", m_filename.c_str());
462 gst_element_set_state(m_gst_pipeline, GST_STATE_NULL);
467 RESULT eServiceMP3::setTarget(int target)
472 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr)
478 RESULT eServiceMP3::setSlowMotion(int ratio)
480 /* we can't do slomo yet */
484 RESULT eServiceMP3::setFastForward(int ratio)
486 m_currentTrickRatio = ratio;
488 m_seekTimeout.start(1000, 0);
490 m_seekTimeout.stop();
494 void eServiceMP3::seekTimeoutCB()
497 getPlayPosition(ppos);
499 ppos += 90000*m_currentTrickRatio;
504 m_seekTimeout.stop();
510 m_seekTimeout.stop();
517 RESULT eServiceMP3::pause()
521 GstStateChangeReturn res = gst_element_set_state(m_gst_pipeline, GST_STATE_PAUSED);
522 if (res == GST_STATE_CHANGE_ASYNC)
525 getPlayPosition(ppos);
531 RESULT eServiceMP3::unpause()
536 GstStateChangeReturn res;
537 res = gst_element_set_state(m_gst_pipeline, GST_STATE_PLAYING);
541 /* iSeekableService */
542 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr)
548 RESULT eServiceMP3::getLength(pts_t &pts)
552 if (m_state != stRunning)
555 GstFormat fmt = GST_FORMAT_TIME;
558 if (!gst_element_query_duration(m_gst_pipeline, &fmt, &len))
561 /* len is in nanoseconds. we have 90 000 pts per second. */
567 RESULT eServiceMP3::seekTo(pts_t to)
572 /* convert pts to nanoseconds */
573 gint64 time_nanoseconds = to * 11111LL;
574 if (!gst_element_seek (m_gst_pipeline, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
575 GST_SEEK_TYPE_SET, time_nanoseconds,
576 GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
578 eDebug("SEEK failed");
584 RESULT eServiceMP3::seekRelative(int direction, pts_t to)
590 getPlayPosition(ppos);
591 ppos += to * direction;
599 RESULT eServiceMP3::getPlayPosition(pts_t &pts)
603 if (m_state != stRunning)
606 GstFormat fmt = GST_FORMAT_TIME;
609 if (!gst_element_query_position(m_gst_pipeline, &fmt, &len))
612 /* len is in nanoseconds. we have 90 000 pts per second. */
617 RESULT eServiceMP3::setTrickmode(int trick)
619 /* trickmode is not yet supported by our dvbmediasinks. */
623 RESULT eServiceMP3::isCurrentlySeekable()
628 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
634 RESULT eServiceMP3::getName(std::string &name)
637 size_t n = name.rfind('/');
638 if (n != std::string::npos)
639 name = name.substr(n + 1);
643 int eServiceMP3::getInfo(int w)
658 tag = GST_TAG_TRACK_NUMBER;
661 tag = GST_TAG_TRACK_COUNT;
667 if (!m_stream_tags || !tag)
671 if (gst_tag_list_get_uint(m_stream_tags, tag, &value))
678 std::string eServiceMP3::getInfoString(int w)
687 tag = GST_TAG_ARTIST;
693 tag = GST_TAG_COMMENT;
696 tag = GST_TAG_TRACK_NUMBER;
702 tag = GST_TAG_VIDEO_CODEC;
708 if (!m_stream_tags || !tag)
713 if (gst_tag_list_get_string(m_stream_tags, tag, &value))
715 std::string res = value;
723 RESULT eServiceMP3::audioChannel(ePtr<iAudioChannelSelection> &ptr)
729 RESULT eServiceMP3::audioTracks(ePtr<iAudioTrackSelection> &ptr)
735 int eServiceMP3::getNumberOfTracks()
737 return m_audioStreams.size();
740 int eServiceMP3::getCurrentTrack()
742 return m_currentAudioStream;
745 RESULT eServiceMP3::selectTrack(unsigned int i)
747 int ret = selectAudioStream(i);
750 getPlayPosition(ppos);
756 int eServiceMP3::selectAudioStream(int i)
760 GstElement *selector = gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"switch_audio");
763 eDebug("can't switch audio tracks! gst-plugin-selector needed");
766 g_object_get (G_OBJECT (selector), "n-pads", &nb_sources, NULL);
767 if ( i >= m_audioStreams.size() || i >= nb_sources || m_currentAudioStream >= m_audioStreams.size() )
770 sprintf(sinkpad, "sink%d", i);
771 g_object_set (G_OBJECT (selector), "active-pad", gst_element_get_pad (selector, sinkpad), NULL);
772 g_object_get (G_OBJECT (selector), "active-pad", &active_pad, NULL);
774 name = gst_pad_get_name (active_pad);
775 eDebug ("switched audio to (%s)", name);
777 m_currentAudioStream = i;
781 int eServiceMP3::getCurrentChannel()
786 RESULT eServiceMP3::selectChannel(int i)
788 eDebug("eServiceMP3::selectChannel(%i)",i);
792 RESULT eServiceMP3::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
794 // eDebug("eServiceMP3::getTrackInfo(&info, %i)",i);
795 if (i >= m_audioStreams.size())
797 if (m_audioStreams[i].type == audioStream::atMP2)
798 info.m_description = "MP2";
799 else if (m_audioStreams[i].type == audioStream::atMP3)
800 info.m_description = "MP3";
801 else if (m_audioStreams[i].type == audioStream::atAC3)
802 info.m_description = "AC3";
803 else if (m_audioStreams[i].type == audioStream::atAAC)
804 info.m_description = "AAC";
805 else if (m_audioStreams[i].type == audioStream::atDTS)
806 info.m_description = "DTS";
807 else if (m_audioStreams[i].type == audioStream::atPCM)
808 info.m_description = "PCM";
809 else if (m_audioStreams[i].type == audioStream::atOGG)
810 info.m_description = "OGG";
812 info.m_description = "???";
813 if (info.m_language.empty())
814 info.m_language = m_audioStreams[i].language_code;
818 void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
825 source = GST_MESSAGE_SRC(msg);
826 sourceName = gst_object_get_name(source);
828 if (gst_message_get_structure(msg))
830 gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
831 eDebug("gst_message from %s: %s", sourceName, string);
835 eDebug("gst_message from %s: %s (without structure)", sourceName, GST_MESSAGE_TYPE_NAME(msg));
837 switch (GST_MESSAGE_TYPE (msg))
839 case GST_MESSAGE_EOS:
840 m_event((iPlayableService*)this, evEOF);
842 case GST_MESSAGE_ERROR:
847 gst_message_parse_error (msg, &err, &debug);
849 eWarning("Gstreamer error: %s (%i)", err->message, err->code );
850 if ( err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_DECODE )
852 if ( g_strrstr(sourceName, "videosink") )
853 m_event((iPlayableService*)this, evUser+11);
856 /* TODO: signal error condition to user */
859 case GST_MESSAGE_TAG:
861 GstTagList *tags, *result;
862 gst_message_parse_tag(msg, &tags);
864 result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_PREPEND);
868 gst_tag_list_free(m_stream_tags);
869 m_stream_tags = result;
872 if (gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_audiocodec) && m_audioStreams.size())
874 std::vector<audioStream>::iterator IterAudioStream = m_audioStreams.begin();
875 while ( IterAudioStream->language_code.length() && IterAudioStream != m_audioStreams.end())
877 if ( g_strrstr(g_audiocodec, "MPEG-1 layer 2") )
878 IterAudioStream->type = audioStream::atMP2;
879 else if ( g_strrstr(g_audiocodec, "MPEG-1 layer 3") )
880 IterAudioStream->type = audioStream::atMP3;
881 else if ( g_strrstr(g_audiocodec, "AC-3 audio") )
882 IterAudioStream->type = audioStream::atAC3;
883 else if ( g_strrstr(g_audiocodec, "Uncompressed 16-bit PCM audio") )
884 IterAudioStream->type = audioStream::atPCM;
886 if ( gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_language) )
887 IterAudioStream->language_code = std::string(g_language);
889 g_free (g_audiocodec);
899 GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
901 eServiceMP3 *_this = (eServiceMP3*)user_data;
902 _this->m_pump.send(1);
907 void eServiceMP3::gstCBpadAdded(GstElement *decodebin, GstPad *pad, gpointer user_data)
909 eServiceMP3 *_this = (eServiceMP3*)user_data;
910 GstBin *pipeline = GST_BIN(_this->m_gst_pipeline);
912 name = gst_pad_get_name (pad);
913 eDebug ("A new pad %s was created", name);
914 if (g_strrstr(name,"audio")) // mpegdemux, matroskademux, avidemux use video_nn with n=0,1,.., flupsdemux uses stream id
916 GstElement *selector = gst_bin_get_by_name(pipeline , "switch_audio" );
919 _this->m_audioStreams.push_back(audio);
922 GstPadLinkReturn ret = gst_pad_link(pad, gst_element_get_request_pad (selector, "sink%d"));
923 if ( _this->m_audioStreams.size() == 1 )
925 _this->selectAudioStream(0);
926 gst_element_set_state (_this->m_gst_pipeline, GST_STATE_PLAYING);
929 g_object_set (G_OBJECT (selector), "select-all", FALSE, NULL);
932 gst_pad_link(pad, gst_element_get_static_pad(gst_bin_get_by_name(pipeline,"queue_audio"), "sink"));
934 if (g_strrstr(name,"video"))
936 gst_pad_link(pad, gst_element_get_static_pad(gst_bin_get_by_name(pipeline,"queue_video"), "sink"));
941 void eServiceMP3::gstCBfilterPadAdded(GstElement *filter, GstPad *pad, gpointer user_data)
943 eServiceMP3 *_this = (eServiceMP3*)user_data;
944 GstElement *decoder = gst_bin_get_by_name(GST_BIN(_this->m_gst_pipeline),"decoder");
945 gst_pad_link(pad, gst_element_get_static_pad (decoder, "sink"));
948 void eServiceMP3::gstCBnewPad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer user_data)
950 eServiceMP3 *_this = (eServiceMP3*)user_data;
956 GstElement *audio = gst_bin_get_by_name(GST_BIN(_this->m_gst_pipeline),"audiobin");
957 audiopad = gst_element_get_static_pad (audio, "sink");
958 if ( !audiopad || GST_PAD_IS_LINKED (audiopad)) {
959 eDebug("audio already linked!");
960 g_object_unref (audiopad);
964 /* check media type */
965 caps = gst_pad_get_caps (pad);
966 str = gst_caps_get_structure (caps, 0);
967 eDebug("gst new pad! %s", gst_structure_get_name (str));
969 if (!g_strrstr (gst_structure_get_name (str), "audio")) {
970 gst_caps_unref (caps);
971 gst_object_unref (audiopad);
975 gst_caps_unref (caps);
976 gst_pad_link (pad, audiopad);
979 void eServiceMP3::gstCBunknownType(GstElement *decodebin, GstPad *pad, GstCaps *caps, gpointer user_data)
983 /* check media type */
984 caps = gst_pad_get_caps (pad);
985 str = gst_caps_get_structure (caps, 0);
986 eDebug("unknown type: %s - this can't be decoded.", gst_structure_get_name (str));
987 gst_caps_unref (caps);
990 void eServiceMP3::gstPoll(const int&)
992 /* ok, we have a serious problem here. gstBusSyncHandler sends
993 us the wakup signal, but likely before it was posted.
994 the usleep, an EVIL HACK (DON'T DO THAT!!!) works around this.
996 I need to understand the API a bit more to make this work
1000 GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_pipeline));
1001 GstMessage *message;
1002 while ((message = gst_bus_pop (bus)))
1004 gstBusCall(bus, message);
1005 gst_message_unref (message);
1009 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");
1011 #warning gstreamer not available, not building media player