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;
}
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;
}
::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;
}
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:
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;
}
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;
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);
}
int rc,r,w,maxfd;
time_t next_scantime = 0;
bool sosSend = false;
+ m_running = true;
r = w = 0;
hasStarted();
}
}
if (eof && (r==w)) {
- ::close(m_srcfd);
- m_srcfd = -1;
m_messagepump.send(evtEOS);
break;
}
}
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");
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);
virtual ~eStreamThread();
void start(int srcfd, int destfd);
void stop();
+ bool running() { return m_running; }
virtual void thread();
virtual void thread_finished();
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;