fixes
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Fri, 21 Aug 2009 17:07:39 +0000 (17:07 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Fri, 21 Aug 2009 17:07:39 +0000 (17:07 +0000)
vlcplayer/src/servicets/servicets.cpp
vlcplayer/src/servicets/servicets.h

index ba05176..5749706 100644 (file)
@@ -113,7 +113,6 @@ eServiceTS::eServiceTS(const eServiceReference &url): m_pump(eApp, 1)
        m_filename = url.path.c_str();
        m_vpid = url.getData(0) == 0 ? 0x44 : url.getData(0);
        m_apid = url.getData(1) == 0 ? 0x45 : url.getData(1);
-       m_state = stIdle;
        m_audioInfo = 0;
        m_destfd = -1;
 }
@@ -276,8 +275,8 @@ RESULT eServiceTS::start()
        m_streamthread = new eStreamThread();
        CONNECT(m_streamthread->m_event, eServiceTS::recv_event);
        m_decoder->pause();
-       if (unpause() != 0) return -1;
-       m_state = stRunning;
+       if (unpause() != 0) 
+               return -1;
        m_event(this, evStart);
        return 0;
 }
@@ -289,12 +288,9 @@ RESULT eServiceTS::stop()
                ::close(m_destfd);
                m_destfd = -1;
        }
-       if (m_state != stRunning)
-               return -1;
        printf("TS: %s stop\n", m_filename.c_str());
        m_streamthread->stop();
        m_decodedemux->flush();
-       m_state = stStopped;
        m_audioInfo = 0;
        return 0;
 }
@@ -305,13 +301,11 @@ void eServiceTS::recv_event(int evt)
        switch (evt) {
        case eStreamThread::evtEOS:
                m_decodedemux->flush();
-               m_state = stStopped;
                m_event((iPlayableService*)this, evEOF);
                break;
        case eStreamThread::evtReadError:
        case eStreamThread::evtWriteError:
                m_decoder->pause();
-               m_state = stStopped;
                m_event((iPlayableService*)this, evEOF);
                break;
        case eStreamThread::evtSOS:
@@ -349,20 +343,27 @@ RESULT eServiceTS::pause()
 
 RESULT eServiceTS::unpause()
 {
-       int is_streaming = !strncmp(m_filename.c_str(), "http://", 7);
-       int srcfd = -1;
-       if (is_streaming) {
-               srcfd = openHttpConnection(m_filename);
-       } else {
-               srcfd = ::open(m_filename.c_str(), O_RDONLY);
-       }
-       if (srcfd < 0) {
-               eDebug("Cannot open source stream: %s", m_filename.c_str());
-               return 1;
+       if (!m_streamthread->running())
+       {
+               int is_streaming = !strncmp(m_filename.c_str(), "http://", 7);
+               int srcfd = -1;
+
+               if (is_streaming)
+                       srcfd = openHttpConnection(m_filename);
+               else
+                       srcfd = ::open(m_filename.c_str(), O_RDONLY);
+
+               if (srcfd < 0) {
+                       eDebug("Cannot open source stream: %s", m_filename.c_str());
+                       return 1;
+               }
+
+               m_decodedemux->flush();
+               m_streamthread->start(srcfd, m_destfd);
+               m_decoder->play();
        }
-       m_decodedemux->flush();
-       m_streamthread->start(srcfd, m_destfd);
-       m_decoder->play();
+       else
+               eDebug("unpause but thread already running!");
        return 0;
 }
 
@@ -440,8 +441,7 @@ RESULT eServiceTS::selectTrack(unsigned int i) {
                m_apid = m_audioInfo->audioStreams[i].pid;
                eDebug("[servicets] audio track %d PID 0x%02x type %d\n", i, m_apid, m_audioInfo->audioStreams[i].type);
                m_decoder->setAudioPID(m_apid, m_audioInfo->audioStreams[i].type);
-               if (m_state == stRunning)
-                       m_decoder->set();
+               m_decoder->set();
                return 0;
        } else {
                return -1;
@@ -485,7 +485,7 @@ eStreamThread::~eStreamThread() {
 void eStreamThread::start(int srcfd, int destfd) {
        m_srcfd = srcfd;
        m_destfd = destfd;
-       m_stop = false;
+       m_stop = m_running = false;
        m_audioInfo = 0;
        run(IOPRIO_CLASS_RT);
 }
@@ -630,6 +630,7 @@ void eStreamThread::thread() {
        int rc,r,w,maxfd;
        time_t next_scantime = 0;
        bool sosSend = false;
+       m_running = true;
 
        r = w = 0;
        hasStarted();
@@ -695,8 +696,6 @@ void eStreamThread::thread() {
                        }
                }
                if (eof && (r==w)) {
-                       ::close(m_srcfd);
-                       m_srcfd = -1;
                        m_messagepump.send(evtEOS);
                        break;
                }
@@ -705,8 +704,10 @@ void eStreamThread::thread() {
 }
 
 void eStreamThread::thread_finished() {
-       if (m_srcfd >= 0) ::close(m_srcfd);
+       if (m_srcfd >= 0)
+               ::close(m_srcfd);
        eDebug("eStreamThread closed");
+       m_running = false;
 }
 
 eAutoInitPtr<eServiceFactoryTS> init_eServiceFactoryTS(eAutoInitNumbers::service+1, "eServiceFactoryTS");
index 3455f0f..5b0b65a 100644 (file)
@@ -122,11 +122,6 @@ private:
        int openHttpConnection(std::string url);
 
        Signal2<void,iPlayableService*,int> m_event;
-       enum
-       {
-               stIdle, stRunning, stStopped
-       };
-       int m_state;
        eFixedMessagePump<int> m_pump;
        void recv_event(int evt);
        void setAudioPid(int pid, int type);
@@ -139,6 +134,7 @@ public:
        virtual ~eStreamThread();
        void start(int srcfd, int destfd);
        void stop();
+       bool running() { return m_running; }
 
        virtual void thread();
        virtual void thread_finished();
@@ -149,6 +145,7 @@ public:
        Signal1<void,int> m_event;
 private:
        bool m_stop;
+       bool m_running;
        int m_srcfd, m_destfd;
        ePtr<TSAudioInfo> m_audioInfo;
        eFixedMessagePump<int> m_messagepump;