implement iAudioDelay interface also for servicemp3.cpp (media files)
authorghost <andreas.monzner@multimedia-labs.de>
Wed, 4 Nov 2009 12:09:50 +0000 (13:09 +0100)
committerghost <andreas.monzner@multimedia-labs.de>
Wed, 4 Nov 2009 12:09:50 +0000 (13:09 +0100)
no possibility to store this delays persistent.. they are valid until the next reboot or delay change

lib/dvb/decoder.cpp
lib/dvb/decoder.h
lib/service/servicemp3.cpp
lib/service/servicemp3.h

index 90bf19e..0935069 100644 (file)
@@ -1048,9 +1048,9 @@ int eTSMPEGDecoder::setState()
 int eTSMPEGDecoder::m_pcm_delay=-1,
        eTSMPEGDecoder::m_ac3_delay=-1;
 
 int eTSMPEGDecoder::m_pcm_delay=-1,
        eTSMPEGDecoder::m_ac3_delay=-1;
 
-RESULT eTSMPEGDecoder::setPCMDelay(int delay)
+RESULT eTSMPEGDecoder::setHwPCMDelay(int delay)
 {
 {
-       if (m_decoder == 0 && delay != m_pcm_delay )
+       if (delay != m_pcm_delay )
        {
                FILE *fp = fopen("/proc/stb/audio/audio_delay_pcm", "w");
                if (fp)
        {
                FILE *fp = fopen("/proc/stb/audio/audio_delay_pcm", "w");
                if (fp)
@@ -1064,9 +1064,9 @@ RESULT eTSMPEGDecoder::setPCMDelay(int delay)
        return -1;
 }
 
        return -1;
 }
 
-RESULT eTSMPEGDecoder::setAC3Delay(int delay)
+RESULT eTSMPEGDecoder::setHwAC3Delay(int delay)
 {
 {
-       if ( m_decoder == 0 && delay != m_ac3_delay )
+       if ( delay != m_ac3_delay )
        {
                FILE *fp = fopen("/proc/stb/audio/audio_delay_bitstream", "w");
                if (fp)
        {
                FILE *fp = fopen("/proc/stb/audio/audio_delay_bitstream", "w");
                if (fp)
@@ -1080,6 +1080,17 @@ RESULT eTSMPEGDecoder::setAC3Delay(int delay)
        return -1;
 }
 
        return -1;
 }
 
+
+RESULT eTSMPEGDecoder::setPCMDelay(int delay)
+{
+       return m_decoder == 0 ? setHwPCMDelay(delay) : -1;
+}
+
+RESULT eTSMPEGDecoder::setAC3Delay(int delay)
+{
+       return m_decoder == 0 ? setHwAC3Delay(delay) : -1;
+}
+
 eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
        : m_demux(demux), 
                m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
 eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
        : m_demux(demux), 
                m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
index b53638b..3a0fbac 100644 (file)
@@ -193,6 +193,8 @@ public:
        int getVideoProgressive();
        int getVideoFrameRate();
        int getVideoAspect();
        int getVideoProgressive();
        int getVideoFrameRate();
        int getVideoAspect();
+       static RESULT setHwPCMDelay(int delay);
+       static RESULT setHwAC3Delay(int delay);
 };
 
 #endif
 };
 
 #endif
index e1bf23d..93d2ec7 100644 (file)
@@ -2,20 +2,23 @@
 
        /* note: this requires gstreamer 0.10.x and a big list of plugins. */
        /* it's currently hardcoded to use a big-endian alsasink as sink. */
 
        /* note: this requires gstreamer 0.10.x and a big list of plugins. */
        /* it's currently hardcoded to use a big-endian alsasink as sink. */
+#include <lib/base/ebase.h>
 #include <lib/base/eerror.h>
 #include <lib/base/eerror.h>
+#include <lib/base/init_num.h>
+#include <lib/base/init.h>
+#include <lib/base/nconfig.h>
 #include <lib/base/object.h>
 #include <lib/base/object.h>
-#include <lib/base/ebase.h>
-#include <string>
+#include <lib/dvb/decoder.h>
+#include <lib/components/file_eraser.h>
+#include <lib/gui/esubtitle.h>
 #include <lib/service/servicemp3.h>
 #include <lib/service/service.h>
 #include <lib/service/servicemp3.h>
 #include <lib/service/service.h>
-#include <lib/components/file_eraser.h>
-#include <lib/base/init_num.h>
-#include <lib/base/init.h>
+
+#include <string>
+
 #include <gst/gst.h>
 #include <gst/pbutils/missing-plugins.h>
 #include <sys/stat.h>
 #include <gst/gst.h>
 #include <gst/pbutils/missing-plugins.h>
 #include <sys/stat.h>
-/* for subtitles */
-#include <lib/gui/esubtitle.h>
 
 // eServiceFactoryMP3
 
 
 // eServiceFactoryMP3
 
@@ -186,6 +189,8 @@ int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
 }
 
 // eServiceMP3
 }
 
 // eServiceMP3
+int eServiceMP3::ac3_delay,
+    eServiceMP3::pcm_delay;
 
 eServiceMP3::eServiceMP3(eServiceReference ref)
        :m_ref(ref), m_pump(eApp, 1)
 
 eServiceMP3::eServiceMP3(eServiceReference ref)
        :m_ref(ref), m_pump(eApp, 1)
@@ -658,7 +663,6 @@ RESULT eServiceMP3::getName(std::string &name)
        return 0;
 }
 
        return 0;
 }
 
-
 int eServiceMP3::getInfo(int w)
 {
        const gchar *tag = 0;
 int eServiceMP3::getInfo(int w)
 {
        const gchar *tag = 0;
@@ -954,6 +958,12 @@ RESULT eServiceMP3::subtitle(ePtr<iSubtitleOutput> &ptr)
        return 0;
 }
 
        return 0;
 }
 
+RESULT eServiceMP3::audioDelay(ePtr<iAudioDelay> &ptr)
+{
+       ptr = this;
+       return 0;
+}
+
 int eServiceMP3::getNumberOfTracks()
 {
        return m_audioStreams.size();
 int eServiceMP3::getNumberOfTracks()
 {
        return m_audioStreams.size();
@@ -1092,6 +1102,8 @@ void eServiceMP3::gstBusCall(GstBus *bus, GstMessage *msg)
                                                g_object_set (G_OBJECT (sink), "emit-signals", TRUE, NULL);
                                                gst_object_unref(sink);
                                        }
                                                g_object_set (G_OBJECT (sink), "emit-signals", TRUE, NULL);
                                                gst_object_unref(sink);
                                        }
+                                       setAC3Delay(ac3_delay);
+                                       setPCMDelay(pcm_delay);
                                }       break;
                                case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
                                {
                                }       break;
                                case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
                                {
@@ -1578,6 +1590,75 @@ int eServiceMP3::setBufferSize(int size)
        return 0;
 }
 
        return 0;
 }
 
+int eServiceMP3::getAC3Delay()
+{
+       return ac3_delay;
+}
+
+int eServiceMP3::getPCMDelay()
+{
+       return pcm_delay;
+}
+
+void eServiceMP3::setAC3Delay(int delay)
+{
+       if (!m_gst_playbin || m_state != stRunning)
+               return;
+       else
+       {
+               GstElement *sink;
+               std::string config_delay;
+               int config_delay_int = delay;
+               if(ePythonConfigQuery::getConfigValue("config.av.generalAC3delay", config_delay) == 0)
+                       config_delay_int += atoi(config_delay.c_str());
+
+               g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
+
+               if (!sink)
+                       return;
+               else {
+                       gchar *name = gst_element_get_name(sink);
+
+                       if (strstr(name, "dvbaudiosink"))
+                               eTSMPEGDecoder::setHwAC3Delay(config_delay_int);
+                       g_free(name);
+                       gst_object_unref(sink);
+               }
+       }
+}
+
+void eServiceMP3::setPCMDelay(int delay)
+{
+       if (!m_gst_playbin || m_state != stRunning)
+               return;
+       else
+       {
+               GstElement *sink;
+               std::string config_delay;
+               int config_delay_int = delay;
+               if(ePythonConfigQuery::getConfigValue("config.av.generalPCMdelay", config_delay) == 0)
+                       config_delay_int += atoi(config_delay.c_str());
+
+               g_object_get (G_OBJECT (m_gst_playbin), "audio-sink", &sink, NULL);
+
+               if (!sink)
+                       return;
+               else {
+                       gchar *name = gst_element_get_name(sink);
+
+                       if (strstr(name, "dvbaudiosink"))
+                               eTSMPEGDecoder::setHwPCMDelay(config_delay_int);
+                       else {
+                               // this is realy untested..and not used yet
+                               gint64 offset = config_delay_int;
+                               offset *= 1000000; // milli to nano
+                               g_object_set (G_OBJECT (m_gst_playbin), "ts-offset", offset, NULL);
+                       }
+                       g_free(name);
+                       gst_object_unref(sink);
+               }
+       }
+}
 
 #else
 #warning gstreamer not available, not building media player
 
 #else
 #warning gstreamer not available, not building media player
index 15ed0b0..985179f 100644 (file)
@@ -49,8 +49,9 @@ typedef enum { atUnknown, atMPEG, atMP3, atAC3, atDTS, atAAC, atPCM, atOGG, atFL
 typedef enum { stPlainText, stSSA, stSRT } subtype_t;
 typedef enum { ctNone, ctMPEGTS, ctMPEGPS, ctMKV, ctAVI, ctMP4, ctVCD, ctCDA } containertype_t;
 
 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 iStreamedService, public Object
+class eServiceMP3: public iPlayableService, public iPauseableService,
+       public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection, 
+       public iSubtitleOutput, public iStreamedService, public iAudioDelay, public Object
 {
        DECLARE_REF(eServiceMP3);
 public:
 {
        DECLARE_REF(eServiceMP3);
 public:
@@ -70,13 +71,14 @@ public:
        RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
        RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
        RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
        RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
        RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
        RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
+       RESULT audioDelay(ePtr<iAudioDelay> &ptr);
 
                // not implemented (yet)
        RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; }
        RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; }
        RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; }
        RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; }
 
                // not implemented (yet)
        RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; }
        RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; }
        RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; }
        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 keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
        RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
        RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
        RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
        RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
@@ -122,6 +124,12 @@ public:
        PyObject *getBufferCharge();
        int setBufferSize(int size);
 
        PyObject *getBufferCharge();
        int setBufferSize(int size);
 
+               // iAudioDelay
+       int getAC3Delay();
+       int getPCMDelay();
+       void setAC3Delay(int);
+       void setPCMDelay(int);
+
        struct audioStream
        {
                GstPad* pad;
        struct audioStream
        {
                GstPad* pad;
@@ -166,6 +174,8 @@ public:
                }
        };
 private:
                }
        };
 private:
+       static int pcm_delay;
+       static int ac3_delay;
        int m_currentAudioStream;
        int m_currentSubtitleStream;
        int selectAudioStream(int i);
        int m_currentAudioStream;
        int m_currentSubtitleStream;
        int selectAudioStream(int i);