+RESULT eServiceMP3::getPlayPosition(pts_t &pts)
+{
+ if (!m_gst_pipeline)
+ return -1;
+ if (m_state != stRunning)
+ return -1;
+
+ GstFormat fmt = GST_FORMAT_TIME;
+ gint64 len;
+
+ if (!gst_element_query_position(m_gst_pipeline, &fmt, &len))
+ return -1;
+
+ /* len is in nanoseconds. we have 90 000 pts per second. */
+ pts = len / 11111;
+ return 0;
+}
+
+RESULT eServiceMP3::setTrickmode(int trick)
+{
+ /* trickmode currently doesn't make any sense for us. */
+ return -1;
+}
+
+RESULT eServiceMP3::isCurrentlySeekable()
+{
+ return 1;
+}
+
+RESULT eServiceMP3::info(ePtr<iServiceInformation>&i)
+{
+ i = this;
+ return 0;
+}
+
+RESULT eServiceMP3::getName(std::string &name)
+{
+ name = "MP3 File: " + m_filename;
+ return 0;
+}
+
+int eServiceMP3::getInfo(int w)
+{
+ switch (w)
+ {
+ case sTitle:
+ case sArtist:
+ case sAlbum:
+ case sComment:
+ case sTracknumber:
+ case sGenre:
+ return resIsString;
+
+ default:
+ return resNA;
+ }
+}
+
+std::string eServiceMP3::getInfoString(int w)
+{
+ gchar *tag = 0;
+ switch (w)
+ {
+ case sTitle:
+ tag = GST_TAG_TITLE;
+ break;
+ case sArtist:
+ tag = GST_TAG_ARTIST;
+ break;
+ case sAlbum:
+ tag = GST_TAG_ALBUM;
+ break;
+ case sComment:
+ tag = GST_TAG_COMMENT;
+ break;
+ case sTracknumber:
+ tag = GST_TAG_TRACK_NUMBER;
+ break;
+ case sGenre:
+ tag = GST_TAG_GENRE;
+ break;
+ default:
+ return "";
+ }
+
+ if (!m_stream_tags || !tag)
+ return "";
+
+ gchar *value;
+
+ if (gst_tag_list_get_string(m_stream_tags, tag, &value))
+ {
+ std::string res = value;
+ g_free(value);
+ return res;
+ }
+
+ return "";
+}
+
+
+ void foreach(const GstTagList *list, const gchar *tag, gpointer user_data)
+ {
+ if (tag)
+ eDebug("Tag: %c%c%c%c", tag[0], tag[1], tag[2], tag[3]);
+
+ }
+
+void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
+{
+ gchar *string = gst_structure_to_string(gst_message_get_structure(msg));
+ eDebug("gst_message: %s", string);
+ g_free(string);
+
+
+ switch (GST_MESSAGE_TYPE (msg))
+ {
+ case GST_MESSAGE_EOS:
+ m_event((iPlayableService*)this, evEOF);
+ break;
+ case GST_MESSAGE_ERROR:
+ {
+ gchar *debug;
+ GError *err;
+ gst_message_parse_error (msg, &err, &debug);
+ g_free (debug);
+ eWarning("Gstreamer error: %s", err->message);
+ g_error_free(err);
+ exit(0);
+ break;
+ }
+ case GST_MESSAGE_TAG:
+ {
+ GstTagList *tags, *result;
+ gst_message_parse_tag(msg, &tags);
+
+ result = gst_tag_list_merge(m_stream_tags, tags, GST_TAG_MERGE_PREPEND);
+ if (result)
+ {
+ if (m_stream_tags)
+ gst_tag_list_free(m_stream_tags);
+ m_stream_tags = result;
+ }
+ gst_tag_list_free(tags);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+GstBusSyncReply eServiceMP3::gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data)
+{
+ eServiceMP3 *_this = (eServiceMP3*)user_data;
+ _this->m_pump.send(1);
+ /* wake */
+ return GST_BUS_PASS;
+}
+
+void eServiceMP3::gstCBnewPad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer user_data)
+{
+ eServiceMP3 *_this = (eServiceMP3*)user_data;
+ GstCaps *caps;
+ GstStructure *str;
+ GstPad *audiopad;
+
+ /* only link once */
+ audiopad = gst_element_get_pad (_this->m_gst_audio, "sink");
+ if (GST_PAD_IS_LINKED (audiopad)) {
+ g_object_unref (audiopad);
+ return;
+ }
+
+
+ /* check media type */
+ caps = gst_pad_get_caps (pad);
+ str = gst_caps_get_structure (caps, 0);
+ if (!g_strrstr (gst_structure_get_name (str), "audio")) {
+ gst_caps_unref (caps);
+ gst_object_unref (audiopad);
+ return;
+ }
+
+ gst_caps_unref (caps);
+ gst_pad_link (pad, audiopad);
+}
+
+
+void eServiceMP3::gstPoll(const int&)
+{
+ /* ok, we have a serious problem here. gstBusSyncHandler sends
+ us the wakup signal, but likely before it was posted.
+ the usleep, an EVIL HACK (DON'T DO THAT!!!) works around this.
+
+ I need to understand the API a bit more to make this work
+ proplerly. */
+ usleep(1);
+
+ GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_gst_pipeline));
+ GstMessage *message;
+ while (message = gst_bus_pop (bus))
+ {
+ gstBusCall(bus, message);
+ gst_message_unref (message);
+ }
+}
+