+
+void eServiceMP3::gstCBsubtitleAvail(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer user_data)
+{
+ gint64 duration_ns = GST_BUFFER_DURATION(buffer);
+ const unsigned char *text = (unsigned char *)GST_BUFFER_DATA(buffer);
+ eDebug("gstCBsubtitleAvail: %s",text);
+ eServiceMP3 *_this = (eServiceMP3*)user_data;
+ if ( _this->m_subtitle_widget )
+ {
+ ePangoSubtitlePage page;
+ gRGB rgbcol(0xD0,0xD0,0xD0);
+ page.m_elements.push_back(ePangoSubtitlePageElement(rgbcol, (const char*)text));
+ page.m_timeout = duration_ns / 1000000;
+ (_this->m_subtitle_widget)->setPage(page);
+ }
+}
+
+RESULT eServiceMP3::enableSubtitles(eWidget *parent, ePyObject tuple)
+{
+ ePyObject entry;
+ int tuplesize = PyTuple_Size(tuple);
+ int pid;
+ int type;
+ gint nb_sources;
+ GstPad *active_pad;
+ GstElement *switch_substream = NULL;
+ GstElement *switch_subparse = gst_bin_get_by_name (GST_BIN(m_gst_pipeline), "switch_subparse");
+
+ if (!PyTuple_Check(tuple))
+ goto error_out;
+ if (tuplesize < 1)
+ goto error_out;
+ entry = PyTuple_GET_ITEM(tuple, 1);
+ if (!PyInt_Check(entry))
+ goto error_out;
+ pid = PyInt_AsLong(entry);
+ entry = PyTuple_GET_ITEM(tuple, 2);
+ if (!PyInt_Check(entry))
+ goto error_out;
+ type = PyInt_AsLong(entry);
+
+ switch ((subtype_t)type)
+ {
+ case stPlainText:
+ switch_substream = gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"switch_substream_plain");
+ break;
+ case stSSA:
+ switch_substream = gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"switch_substream_ssa");
+ break;
+ case stSRT:
+ switch_substream = gst_bin_get_by_name(GST_BIN(m_gst_pipeline),"switch_substream_srt");
+ break;
+ default:
+ goto error_out;
+ }
+
+ m_subtitle_widget = new eSubtitleWidget(parent);
+ m_subtitle_widget->resize(parent->size()); /* full size */
+
+ if ( !switch_substream )
+ {
+ eDebug("can't switch subtitle tracks! gst-plugin-selector needed");
+ return -2;
+ }
+ g_object_get (G_OBJECT (switch_substream), "n-pads", &nb_sources, NULL);
+ if ( (unsigned int)pid >= m_subtitleStreams.size() || pid >= nb_sources || (unsigned int)m_currentSubtitleStream >= m_subtitleStreams.size() )
+ return -2;
+ g_object_get (G_OBJECT (switch_subparse), "n-pads", &nb_sources, NULL);
+ if ( type < 0 || type >= nb_sources )
+ return -2;
+
+ char sinkpad[6];
+ sprintf(sinkpad, "sink%d", type);
+ g_object_set (G_OBJECT (switch_subparse), "active-pad", gst_element_get_pad (switch_subparse, sinkpad), NULL);
+ sprintf(sinkpad, "sink%d", pid);
+ g_object_set (G_OBJECT (switch_substream), "active-pad", gst_element_get_pad (switch_substream, sinkpad), NULL);
+ m_currentSubtitleStream = pid;
+
+ return 0;
+error_out:
+ eDebug("enableSubtitles needs a tuple as 2nd argument!\n"
+ "for gst subtitles (2, subtitle_stream_count, subtitle_type)");
+ return -1;
+}
+
+RESULT eServiceMP3::disableSubtitles(eWidget *parent)
+{
+ eDebug("eServiceMP3::disableSubtitles");
+ delete m_subtitle_widget;
+ m_subtitle_widget = 0;
+ return 0;
+}
+
+PyObject *eServiceMP3::getCachedSubtitle()
+{
+ eDebug("eServiceMP3::getCachedSubtitle");
+ Py_RETURN_NONE;
+}
+
+PyObject *eServiceMP3::getSubtitleList()
+{
+ eDebug("eServiceMP3::getSubtitleList");
+
+ ePyObject l = PyList_New(0);
+ int stream_count[sizeof(subtype_t)];
+ for ( unsigned int i = 0; i < sizeof(subtype_t); i++ )
+ stream_count[i] = 0;
+
+ for (std::vector<subtitleStream>::iterator IterSubtitleStream(m_subtitleStreams.begin()); IterSubtitleStream != m_subtitleStreams.end(); ++IterSubtitleStream)
+ {
+ subtype_t type = IterSubtitleStream->type;
+ ePyObject tuple = PyTuple_New(5);
+ PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(2));
+ PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(stream_count[type]));
+ PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(int(type)));
+ PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(0));
+ PyTuple_SET_ITEM(tuple, 4, PyString_FromString((IterSubtitleStream->language_code).c_str()));
+ PyList_Append(l, tuple);
+ Py_DECREF(tuple);
+ stream_count[type]++;
+ }
+ return l;
+}
+