use stride, allocate accel surface
[enigma2.git] / lib / dvb / decoder.cpp
index f73dbdd99b8878e24a83f090b1a6873628dfb830..90bf19e1d68aa72d93f17ec8077a03482b2f3b30 100644 (file)
 #define dmxPesFilterParams dmx_pes_filter_params
 #define DMX_PES_VIDEO0 DMX_PES_VIDEO
 #define DMX_PES_AUDIO0 DMX_PES_AUDIO
+#define DMX_PES_PCR0 DMX_PES_PCR
+#define DMX_PES_TELETEXT0 DMX_PES_TELETEXT
 #define DMX_PES_VIDEO1 DMX_PES_VIDEO
 #define DMX_PES_AUDIO1 DMX_PES_AUDIO
+#define DMX_PES_PCR1 DMX_PES_PCR
+#define DMX_PES_TELETEXT1 DMX_PES_TELETEXT
 #include <ost/dmx.h>
 #include <ost/video.h>
 #include <ost/audio.h>
@@ -196,6 +200,9 @@ int eDVBAudio::startPid(int pid, int type)
        case aAACHE:
                bypass = 9;
                break;
+       case aLPCM:
+               bypass = 6;
+               break;
        }
 
        eDebugNoNewLine("AUDIO_SET_BYPASS(%d) - ", bypass);
@@ -203,8 +210,7 @@ int eDVBAudio::startPid(int pid, int type)
                eDebug("failed (%m)");
        else
                eDebug("ok");
-       freeze();
-
+       freeze();  // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
        eDebugNoNewLine("AUDIO_PLAY - ");
        if (::ioctl(m_fd, AUDIO_PLAY) < 0)
                eDebug("failed (%m)");
@@ -285,7 +291,7 @@ int eDVBAudio::getPTS(pts_t &now)
 
 eDVBAudio::~eDVBAudio()
 {
-       unfreeze();
+       unfreeze();  // why unfreeze here... but not unfreeze video in ~eDVBVideo ?!?
        if (m_fd >= 0)
                ::close(m_fd);
        if (m_fd_demux >= 0)
@@ -295,7 +301,6 @@ eDVBAudio::~eDVBAudio()
 DEFINE_REF(eDVBVideo);
 
 eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
-<<<<<<< HEAD:lib/dvb/decoder.cpp
        : m_demux(demux), m_dev(dev),
        m_width(-1), m_height(-1), m_framerate(-1), m_aspect(-1), m_progressive(-1)
 {
@@ -449,7 +454,7 @@ int eDVBVideo::startPid(int pid, int type)
                return -errno;
        }
        eDebug("ok");
-       freeze();
+       freeze();  // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
        eDebugNoNewLine("VIDEO_PLAY - ");
        if (::ioctl(m_fd, VIDEO_PLAY) < 0)
                eDebug("failed (%m)");
@@ -688,7 +693,7 @@ int eDVBVideo::getFrameRate()
 
 DEFINE_REF(eDVBPCR);
 
-eDVBPCR::eDVBPCR(eDVBDemux *demux): m_demux(demux)
+eDVBPCR::eDVBPCR(eDVBDemux *demux, int dev): m_demux(demux), m_dev(dev)
 {
        char filename[128];
 #if HAVE_DVB_API_VERSION < 3
@@ -747,7 +752,7 @@ int eDVBPCR::startPid(int pid)
        pes.pid      = pid;
        pes.input    = DMX_IN_FRONTEND;
        pes.output   = DMX_OUT_DECODER;
-       pes.pes_type = DMX_PES_PCR;
+       pes.pes_type = m_dev ? DMX_PES_PCR1 : DMX_PES_PCR0; /* FIXME */
        pes.flags    = 0;
        eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
        if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
@@ -784,7 +789,8 @@ eDVBPCR::~eDVBPCR()
 
 DEFINE_REF(eDVBTText);
 
-eDVBTText::eDVBTText(eDVBDemux *demux): m_demux(demux)
+eDVBTText::eDVBTText(eDVBDemux *demux, int dev)
+    :m_demux(demux), m_dev(dev)
 {
        char filename[128];
 #if HAVE_DVB_API_VERSION < 3
@@ -806,7 +812,7 @@ int eDVBTText::startPid(int pid)
        pes.pid      = pid;
        pes.input    = DMX_IN_FRONTEND;
        pes.output   = DMX_OUT_DECODER;
-       pes.pes_type = DMX_PES_TELETEXT;
+       pes.pes_type = m_dev ? DMX_PES_TELETEXT1 : DMX_PES_TELETEXT0; // FIXME
        pes.flags    = 0;
 
        eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - ttx - ", pid);
@@ -816,7 +822,7 @@ int eDVBTText::startPid(int pid)
                return -errno;
        }
        eDebug("ok");
-       eDebugNoNewLine("DEMUX_START - pcr - ");
+       eDebugNoNewLine("DEMUX_START - ttx - ");
        if (::ioctl(m_fd_demux, DMX_START) < 0)
        {
                eDebug("failed(%m)");
@@ -856,7 +862,10 @@ int eTSMPEGDecoder::setState()
        if ((nott && m_text) || (!m_text && !nott))
                m_changed |= changeText | changeState;
 
-       bool changed = !!m_changed;
+       const char *decoder_states[] = {"stop", "pause", "play", "decoderfastforward", "trickmode", "slowmotion"};
+       eDebug("decoder state: %s, vpid=%d, apid=%d", decoder_states[m_state], m_vpid, m_apid);
+
+       int changed = m_changed;
 #if HAVE_DVB_API_VERSION < 3
        bool checkAVSync = m_changed & (changeAudio|changeVideo|changePCR);
        if (m_changed & changeAudio && m_audio)
@@ -894,7 +903,7 @@ int eTSMPEGDecoder::setState()
        }
        if (m_changed & changePCR)
        {
-               m_pcr = new eDVBPCR(m_demux);
+               m_pcr = new eDVBPCR(m_demux, m_decoder);
                if (m_pcr->setPid(m_pcrpid))
                        res = -1;
        }
@@ -959,7 +968,7 @@ int eTSMPEGDecoder::setState()
        {
                if ((m_pcrpid >= 0) && (m_pcrpid < 0x1FFF))
                {
-                       m_pcr = new eDVBPCR(m_demux);
+                       m_pcr = new eDVBPCR(m_demux, m_decoder);
                        if (m_pcr->startPid(m_pcrpid))
                                res = -1;
                }
@@ -990,7 +999,7 @@ int eTSMPEGDecoder::setState()
        {
                if ((m_textpid >= 0) && (m_textpid < 0x1FFF) && !nott)
                {
-                       m_text = new eDVBTText(m_demux);
+                       m_text = new eDVBTText(m_demux, m_decoder);
                        if (m_text->startPid(m_textpid))
                                res = -1;
                }
@@ -998,7 +1007,7 @@ int eTSMPEGDecoder::setState()
        }
 #endif
 
-       if (m_changed & changeState)
+       if (changed & (changeState|changeVideo|changeAudio))
        {
                                        /* play, slowmotion, fast-forward */
                int state_table[6][4] = 
@@ -1011,7 +1020,7 @@ int eTSMPEGDecoder::setState()
                                /* [stateSlowMotion] =           */ {1, m_ff_sm_ratio, 0}
                        };
                int *s = state_table[m_state];
-               if (m_video)
+               if (changed & (changeState|changeVideo) && m_video)
                {
                        m_video->setSlowMotion(s[1]);
                        m_video->setFastForward(s[2]);
@@ -1020,7 +1029,7 @@ int eTSMPEGDecoder::setState()
                        else
                                m_video->freeze();
                }
-               if (m_audio)
+               if (changed & (changeState|changeAudio) && m_audio)
                {
                        if (s[0])
                                m_audio->unfreeze();
@@ -1072,7 +1081,9 @@ RESULT eTSMPEGDecoder::setAC3Delay(int delay)
 }
 
 eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
-       :m_demux(demux), m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp))
+       : m_demux(demux), 
+               m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
+               m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp))
 {
        demux->connectEvent(slot(*this, &eTSMPEGDecoder::demux_event), m_demux_event_conn);
        CONNECT(m_showSinglePicTimer->timeout, eTSMPEGDecoder::finishShowSinglePic);
@@ -1089,7 +1100,7 @@ eTSMPEGDecoder::~eTSMPEGDecoder()
 
 RESULT eTSMPEGDecoder::setVideoPID(int vpid, int type)
 {
-       if (m_vpid != vpid)
+       if ((m_vpid != vpid) || (m_vtype != type))
        {
                m_changed |= changeVideo;
                m_vpid = vpid;
@@ -1166,9 +1177,14 @@ RESULT eTSMPEGDecoder::set()
 RESULT eTSMPEGDecoder::play()
 {
        if (m_state == statePlay)
-               return 0;
-       m_state = statePlay;
-       m_changed |= changeState;
+       {
+               if (!m_changed)
+                       return 0;
+       } else  
+       {
+               m_state = statePlay;
+               m_changed |= changeState;
+       }
        return setState();
 }
 
@@ -1286,15 +1302,18 @@ RESULT eTSMPEGDecoder::showSinglePic(const char *filename)
                                unsigned char seq_end[] = { 0x00, 0x00, 0x01, 0xB7 };
                                unsigned char iframe[s.st_size];
                                unsigned char stuffing[8192];
+                               int streamtype = VIDEO_STREAMTYPE_MPEG2;
                                memset(stuffing, 0, 8192);
                                read(f, iframe, s.st_size);
                                if (ioctl(m_video_clip_fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)
                                        eDebug("VIDEO_SELECT_SOURCE MEMORY failed (%m)");
+                               if (ioctl(m_video_clip_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
+                                       eDebug("VIDEO_SET_STREAMTYPE failed(%m)");
                                if (ioctl(m_video_clip_fd, VIDEO_PLAY) < 0)
                                        eDebug("VIDEO_PLAY failed (%m)");
-                               if (::ioctl(m_video_clip_fd, VIDEO_CONTINUE) < 0)
+                               if (ioctl(m_video_clip_fd, VIDEO_CONTINUE) < 0)
                                        eDebug("video: VIDEO_CONTINUE: %m");
-                               if (::ioctl(m_video_clip_fd, VIDEO_CLEAR_BUFFER) < 0)
+                               if (ioctl(m_video_clip_fd, VIDEO_CLEAR_BUFFER) < 0)
                                        eDebug("video: VIDEO_CLEAR_BUFFER: %m");
                                while(pos <= (s.st_size-4) && !(seq_end_avail = (!iframe[pos] && !iframe[pos+1] && iframe[pos+2] == 1 && iframe[pos+3] == 0xB7)))
                                        ++pos;