introduce new iStreamedService interface (e.g. controlling buffer for streaming media)
authorFraxinas <andreas.frisch@multimedia-labs.de>
Wed, 3 Jun 2009 11:28:31 +0000 (13:28 +0200)
committerFraxinas <andreas.frisch@multimedia-labs.de>
Wed, 3 Jun 2009 11:28:31 +0000 (13:28 +0200)
lib/python/Plugins/Extensions/DVDPlayer/src/servicedvd.h
lib/service/iservice.h
lib/service/servicedvb.h
lib/service/servicedvbrecord.h
lib/service/servicemp3.cpp
lib/service/servicemp3.h

index 12e21d2..94843a4 100644 (file)
@@ -42,6 +42,7 @@ public:
        RESULT audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; }
        RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
        RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
+       RESULT streamed(ePtr<iStreamedService> &ptr) { ptr = 0; return -1; }
        RESULT cueSheet(ePtr<iCueSheet> &ptr);
 
                // iPlayableService
index 22ffde6..373f24c 100644 (file)
@@ -742,6 +742,19 @@ public:
 };
 SWIG_TEMPLATE_TYPEDEF(ePtr<iStreamableService>, iStreamableServicePtr);
 
+SWIG_IGNORE(iStreamedService);
+class iStreamedService: public iObject
+{
+#ifdef SWIG
+       iStreamedService();
+       ~iStreamedService();
+#endif
+public:
+       virtual PyObject *getBufferCharge()=0;
+       virtual int setBufferSize(int size)=0;
+};
+SWIG_TEMPLATE_TYPEDEF(ePtr<iStreamedService>, iStreamedServicePtr);
+
 class iServiceKeys_ENUMS
 {
 #ifdef SWIG
@@ -812,6 +825,8 @@ public:
                evVideoFramerateChanged,
                evVideoProgressiveChanged,
 
+               evBuffering,
+
                evStopped,
 
                evUser = 0x100
@@ -847,6 +862,7 @@ public:
        virtual SWIG_VOID(RESULT) audioDelay(ePtr<iAudioDelay> &SWIG_OUTPUT)=0;
        virtual SWIG_VOID(RESULT) rdsDecoder(ePtr<iRdsDecoder> &SWIG_OUTPUT)=0;
        virtual SWIG_VOID(RESULT) stream(ePtr<iStreamableService> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) streamed(ePtr<iStreamedService> &SWIG_OUTPUT)=0;
        virtual SWIG_VOID(RESULT) keys(ePtr<iServiceKeys> &SWIG_OUTPUT)=0;
 };
 SWIG_TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
index 43e4690..6eba506 100644 (file)
@@ -114,13 +114,14 @@ public:
        RESULT audioDelay(ePtr<iAudioDelay> &ptr);
        RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr);
        RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
+       RESULT streamed(ePtr<iStreamedService> &ptr) { ptr = 0; return -1; }
 
                // iPauseableService
        RESULT pause();
        RESULT unpause();
        RESULT setSlowMotion(int ratio);
        RESULT setFastForward(int ratio);
-       
+
                // iSeekableService
        RESULT getLength(pts_t &len);
        RESULT seekTo(pts_t to);
@@ -182,6 +183,7 @@ public:
                // iStreamableService
        RESULT stream(ePtr<iStreamableService> &ptr);
        PyObject *getStreamingData();
+
 private:
        friend class eServiceFactoryDVB;
        eServiceReference m_reference;
index 319fbb7..0535f02 100644 (file)
@@ -28,7 +28,7 @@ public:
        RESULT frontendInfo(ePtr<iFrontendInformation> &ptr);
        RESULT subServices(ePtr<iSubserviceList> &ptr);
 
-               /* streamable service */
+               // iStreamableService
        PyObject *getStreamingData();
 
                // iSubserviceList
index fd3587a..2ddfe92 100644 (file)
@@ -196,6 +196,7 @@ eServiceMP3::eServiceMP3(const char *filename, const char *title): m_filename(fi
        m_currentSubtitleStream = 0;
        m_subtitle_widget = 0;
        m_currentTrickRatio = 0;
+       m_buffer_size = 1*1024*1024;
        CONNECT(m_seekTimeout->timeout, eServiceMP3::seekTimeoutCB);
        CONNECT(m_subtitle_sync_timer->timeout, eServiceMP3::pushSubtitles);
        CONNECT(m_pump.recv_msg, eServiceMP3::gstPoll);
@@ -332,6 +333,7 @@ eServiceMP3::eServiceMP3(const char *filename, const char *title): m_filename(fi
        }
 
        gst_element_set_state (m_gst_playbin, GST_STATE_PLAYING);
+       setBufferSize(m_buffer_size);
 }
 
 eServiceMP3::~eServiceMP3()
@@ -1214,6 +1216,14 @@ eDebug("AUDIO STRUCT=%s", g_type);
                                        g_free(eventname);
                                }
                        }
+                       break;
+               }
+               case GST_MESSAGE_BUFFERING:
+               {
+                       GstBufferingMode mode;
+                       gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent));
+                       gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft));
+                       m_event((iPlayableService*)this, evBuffering);
                }
                default:
                        break;
@@ -1401,6 +1411,7 @@ RESULT eServiceMP3::disableSubtitles(eWidget *parent)
 
 PyObject *eServiceMP3::getCachedSubtitle()
 {
+//     eDebug("eServiceMP3::getCachedSubtitle");
        Py_RETURN_NONE;
 }
 
@@ -1429,6 +1440,31 @@ PyObject *eServiceMP3::getSubtitleList()
        return l;
 }
 
+RESULT eServiceMP3::streamed(ePtr<iStreamedService> &ptr)
+{
+       ptr = this;
+       return 0;
+}
+
+PyObject *eServiceMP3::getBufferCharge()
+{
+       ePyObject tuple = PyTuple_New(5);
+       PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(m_bufferInfo.bufferPercent));
+       PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(m_bufferInfo.avgInRate));
+       PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(m_bufferInfo.avgOutRate));
+       PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(m_bufferInfo.bufferingLeft));
+       PyTuple_SET_ITEM(tuple, 4, PyInt_FromLong(m_buffer_size));
+       return tuple;
+}
+
+int eServiceMP3::setBufferSize(int size)
+{
+       m_buffer_size = size;
+       g_object_set (G_OBJECT (m_gst_playbin), "buffer-size", m_buffer_size, NULL);
+       return 0;
+}
+
+
 #else
 #warning gstreamer not available, not building media player
 #endif
index f4d657c..1d77483 100644 (file)
@@ -50,7 +50,7 @@ typedef enum { stPlainText, stSSA, stSRT } subtype_t;
 typedef enum { ctNone, ctMPEGTS, ctMPEGPS, ctMKV, ctAVI, ctMP4, ctVCD, ctCDA } containertype_t;
 
 class eServiceMP3: public iPlayableService, public iPauseableService, 
-       public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection, public iSubtitleOutput, public Object
+       public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection, public iSubtitleOutput, public iStreamedService, public Object
 {
        DECLARE_REF(eServiceMP3);
 public:
@@ -78,8 +78,8 @@ public:
        RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; }
        RESULT audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; }
        RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
-       RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
        RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
+       RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
 
                // iPausableService
        RESULT pause();
@@ -117,6 +117,11 @@ public:
        PyObject *getSubtitleList();
        PyObject *getCachedSubtitle();
 
+               // iStreamedService
+       RESULT streamed(ePtr<iStreamedService> &ptr);
+       PyObject *getBufferCharge();
+       int setBufferSize(int size);
+
        struct audioStream
        {
                GstPad* pad;
@@ -149,6 +154,17 @@ public:
                {
                }
        };
+       struct bufferInfo
+       {
+               int bufferPercent;
+               int avgInRate;
+               int avgOutRate;
+               long long bufferingLeft;
+               bufferInfo()
+                       :bufferPercent(0), avgInRate(0), avgOutRate(0), bufferingLeft(-1)
+               {
+               }
+       };
 private:
        int m_currentAudioStream;
        int m_currentSubtitleStream;
@@ -162,6 +178,8 @@ private:
        friend class eServiceFactoryMP3;
        std::string m_filename;
        std::string m_title;
+       int m_buffer_size;
+       bufferInfo m_bufferInfo;
        eServiceMP3(const char *filename, const char *title);
        Signal2<void,iPlayableService*,int> m_event;
        enum