lib/base/console.cpp: fix eConsoleAppContainer write (when called with one string...
[enigma2.git] / lib / dvb / dvb.cpp
index e6d9a25de6a0fe5841494a34196db8ba1dcf8104..17712dde154bb39d5beed4096db20dc79474fa8e 100644 (file)
@@ -438,7 +438,9 @@ alloc_fe_by_id_not_possible:
        return err;
 }
 
        return err;
 }
 
-RESULT eDVBResourceManager::allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap)
+#define capHoldDecodeReference 64
+
+RESULT eDVBResourceManager::allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int &cap)
 {
                /* find first unused demux which is on same adapter as frontend (or any, if PVR)
                   never use the first one unless we need a decoding demux. */
 {
                /* find first unused demux which is on same adapter as frontend (or any, if PVR)
                   never use the first one unless we need a decoding demux. */
@@ -455,6 +457,7 @@ RESULT eDVBResourceManager::allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBA
 
        if (m_boxtype == DM800 || m_boxtype == DM500HD) // dm800 / 500hd
        {
 
        if (m_boxtype == DM800 || m_boxtype == DM500HD) // dm800 / 500hd
        {
+               cap |= capHoldDecodeReference; // this is checked in eDVBChannel::getDemux
                for (; i != m_demux.end(); ++i, ++n)
                {
                        if (!i->m_inuse)
                for (; i != m_demux.end(); ++i, ++n)
                {
                        if (!i->m_inuse)
@@ -510,6 +513,7 @@ RESULT eDVBResourceManager::allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBA
        }
        else if (m_boxtype == DM8000)
        {
        }
        else if (m_boxtype == DM8000)
        {
+               cap |= capHoldDecodeReference; // this is checked in eDVBChannel::getDemux
                for (; i != m_demux.end(); ++i, ++n)
                {
                        if (fe)
                for (; i != m_demux.end(); ++i, ++n)
                {
                        if (fe)
@@ -1120,6 +1124,7 @@ eDVBChannel::eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *fronte
        m_frontend = frontend;
 
        m_pvr_thread = 0;
        m_frontend = frontend;
 
        m_pvr_thread = 0;
+       m_pvr_fd_dst = -1;
 
        m_skipmode_n = m_skipmode_m = m_skipmode_frames = 0;
 
 
        m_skipmode_n = m_skipmode_m = m_skipmode_frames = 0;
 
@@ -1319,16 +1324,6 @@ void eDVBChannel::getNextSourceSpan(off_t current_offset, size_t bytes_read, off
                return;
        }
 
                return;
        }
 
-       m_cue->m_lock.RdLock();
-       if (!m_cue->m_decoding_demux)
-       {
-               start = current_offset;
-               size = max;
-               eDebug("getNextSourceSpan, no decoding demux. forcing normal play");
-               m_cue->m_lock.Unlock();
-               return;
-       }
-
        if (m_skipmode_n)
        {
                eDebug("skipmode %d:%d (x%d)", m_skipmode_m, m_skipmode_n, m_skipmode_frames);
        if (m_skipmode_n)
        {
                eDebug("skipmode %d:%d (x%d)", m_skipmode_m, m_skipmode_n, m_skipmode_frames);
@@ -1336,7 +1331,6 @@ void eDVBChannel::getNextSourceSpan(off_t current_offset, size_t bytes_read, off
        }
 
        eDebug("getNextSourceSpan, current offset is %08llx, m_skipmode_m = %d!", current_offset, m_skipmode_m);
        }
 
        eDebug("getNextSourceSpan, current offset is %08llx, m_skipmode_m = %d!", current_offset, m_skipmode_m);
-       
        int frame_skip_success = 0;
 
        if (m_skipmode_m)
        int frame_skip_success = 0;
 
        if (m_skipmode_m)
@@ -1381,6 +1375,8 @@ void eDVBChannel::getNextSourceSpan(off_t current_offset, size_t bytes_read, off
                }
        }
 
                }
        }
 
+       m_cue->m_lock.RdLock();
+
        while (!m_cue->m_seek_requests.empty())
        {
                std::pair<int, pts_t> seek = m_cue->m_seek_requests.front();
        while (!m_cue->m_seek_requests.empty())
        {
                std::pair<int, pts_t> seek = m_cue->m_seek_requests.front();
@@ -1405,6 +1401,13 @@ void eDVBChannel::getNextSourceSpan(off_t current_offset, size_t bytes_read, off
                                eDebug("decoder getPTS failed, can't seek relative");
                                continue;
                        }
                                eDebug("decoder getPTS failed, can't seek relative");
                                continue;
                        }
+                       if (!m_cue->m_decoding_demux)
+                       {
+                               eDebug("getNextSourceSpan, no decoding demux. couldn't seek to %llx... ignore request!", pts);
+                               start = current_offset;
+                               size = max;
+                               continue;
+                       }
                        if (getCurrentPosition(m_cue->m_decoding_demux, now, 1))
                        {
                                eDebug("seekTo: getCurrentPosition failed!");
                        if (getCurrentPosition(m_cue->m_decoding_demux, now, 1))
                        {
                                eDebug("seekTo: getCurrentPosition failed!");
@@ -1457,12 +1460,7 @@ void eDVBChannel::getNextSourceSpan(off_t current_offset, size_t bytes_read, off
                        continue;
                }
                
                        continue;
                }
                
-               size_t iframe_len;
-                       /* try to align to iframe */
-               int direction = pts < 0 ? -1 : 1;
-               m_tstools.findFrame(offset, iframe_len, direction);
-
-               eDebug("ok, resolved skip (rel: %d, diff %lld), now at %08llx (skipped additional %d frames due to iframe re-align)", relative, pts, offset, direction);
+               eDebug("ok, resolved skip (rel: %d, diff %lld), now at %08llx", relative, pts, offset);
                current_offset = align(offset, blocksize); /* in case tstools return non-aligned offset */
        }
 
                current_offset = align(offset, blocksize); /* in case tstools return non-aligned offset */
        }
 
@@ -1693,17 +1691,24 @@ RESULT eDVBChannel::getDemux(ePtr<iDVBDemux> &demux, int cap)
 
                if (m_mgr->allocateDemux(m_frontend ? (eDVBRegisteredFrontend*)*m_frontend : (eDVBRegisteredFrontend*)0, our_demux, cap))
                        return -1;
 
                if (m_mgr->allocateDemux(m_frontend ? (eDVBRegisteredFrontend*)*m_frontend : (eDVBRegisteredFrontend*)0, our_demux, cap))
                        return -1;
-       }
 
 
-       demux = *our_demux;
+               demux = *our_demux;
+
                /* don't hold a reference to the decoding demux, we don't need it. */
 
                /* FIXME: by dropping the 'allocated demux' in favour of the 'iDVBDemux',
                   the refcount is lost. thus, decoding demuxes are never allocated.
 
                   this poses a big problem for PiP. */
                /* don't hold a reference to the decoding demux, we don't need it. */
 
                /* FIXME: by dropping the 'allocated demux' in favour of the 'iDVBDemux',
                   the refcount is lost. thus, decoding demuxes are never allocated.
 
                   this poses a big problem for PiP. */
-       if (cap & capDecode)
-               our_demux = 0;
+
+               if (cap & capHoldDecodeReference) // this is set in eDVBResourceManager::allocateDemux for Dm500HD/DM800 and DM8000
+                       ;
+               else if (cap & capDecode)
+                       our_demux = 0;
+       }
+       else
+               demux = *our_demux;
+
        return 0;
 }
 
        return 0;
 }
 
@@ -1739,16 +1744,19 @@ RESULT eDVBChannel::playFile(const char *file)
                /* DON'T EVEN THINK ABOUT FIXING THIS. FIX THE ATI SOURCES FIRST,
                   THEN DO A REAL FIX HERE! */
 
                /* DON'T EVEN THINK ABOUT FIXING THIS. FIX THE ATI SOURCES FIRST,
                   THEN DO A REAL FIX HERE! */
 
+       if (m_pvr_fd_dst < 0)
+       {
                /* (this codepath needs to be improved anyway.) */
 #if HAVE_DVB_API_VERSION < 3
                /* (this codepath needs to be improved anyway.) */
 #if HAVE_DVB_API_VERSION < 3
-       m_pvr_fd_dst = open("/dev/pvr", O_WRONLY);
+               m_pvr_fd_dst = open("/dev/pvr", O_WRONLY);
 #else
 #else
-       m_pvr_fd_dst = open("/dev/misc/pvr", O_WRONLY);
+               m_pvr_fd_dst = open("/dev/misc/pvr", O_WRONLY);
 #endif
 #endif
-       if (m_pvr_fd_dst < 0)
-       {
-               eDebug("can't open /dev/misc/pvr - you need to buy the new(!) $$$ box! (%m)"); // or wait for the driver to be improved.
-               return -ENODEV;
+               if (m_pvr_fd_dst < 0)
+               {
+                       eDebug("can't open /dev/misc/pvr - you need to buy the new(!) $$$ box! (%m)"); // or wait for the driver to be improved.
+                       return -ENODEV;
+               }
        }
 
        m_pvr_thread = new eDVBChannelFilePush();
        }
 
        m_pvr_thread = new eDVBChannelFilePush();
@@ -1756,10 +1764,14 @@ RESULT eDVBChannel::playFile(const char *file)
        m_pvr_thread->setStreamMode(1);
        m_pvr_thread->setScatterGather(this);
 
        m_pvr_thread->setStreamMode(1);
        m_pvr_thread->setScatterGather(this);
 
+       m_event(this, evtPreStart);
+
        if (m_pvr_thread->start(file, m_pvr_fd_dst))
        {
                delete m_pvr_thread;
                m_pvr_thread = 0;
        if (m_pvr_thread->start(file, m_pvr_fd_dst))
        {
                delete m_pvr_thread;
                m_pvr_thread = 0;
+               ::close(m_pvr_fd_dst);
+               m_pvr_fd_dst = -1;
                eDebug("can't open PVR file %s (%m)", file);
                return -ENOENT;
        }
                eDebug("can't open PVR file %s (%m)", file);
                return -ENOENT;
        }
@@ -1776,10 +1788,11 @@ void eDVBChannel::stopFile()
        if (m_pvr_thread)
        {
                m_pvr_thread->stop();
        if (m_pvr_thread)
        {
                m_pvr_thread->stop();
-               ::close(m_pvr_fd_dst);
                delete m_pvr_thread;
                m_pvr_thread = 0;
        }
                delete m_pvr_thread;
                m_pvr_thread = 0;
        }
+       if (m_pvr_fd_dst >= 0)
+               ::close(m_pvr_fd_dst);
 }
 
 void eDVBChannel::setCueSheet(eCueSheet *cuesheet)
 }
 
 void eDVBChannel::setCueSheet(eCueSheet *cuesheet)