RTSPMediaIO: Improve thread control

* Instead to exit the thred we will wait until the live555
eventLoop quits peacefully.
* Better error handling.
* Implement SetSize as a not supported operation.
This commit is contained in:
Dario Casalinuovo
2016-06-23 00:38:33 +02:00
parent 6903cf9bda
commit b13f52bf20
2 changed files with 19 additions and 14 deletions
@@ -17,32 +17,26 @@ RTSPMediaIO::RTSPMediaIO(BUrl* ourUrl)
B_INFINITE_TIMEOUT), B_INFINITE_TIMEOUT),
fUrl(ourUrl), fUrl(ourUrl),
fClient(NULL), fClient(NULL),
fInputAdapter(NULL),
fScheduler(NULL), fScheduler(NULL),
fLoopWatchVariable(0), fLoopWatchVariable(0),
fLoopThread(-1), fLoopThread(-1),
fInitErr(B_OK) fInitErr(B_ERROR)
{ {
fInputAdapter = BuildInputAdapter();
fScheduler = BasicTaskScheduler::createNew(); fScheduler = BasicTaskScheduler::createNew();
fEnv = BasicUsageEnvironment::createNew(*fScheduler); fEnv = BasicUsageEnvironment::createNew(*fScheduler);
fClient = new HaikuRTSPClient(*fEnv, fUrl->UrlString(), fClient = new HaikuRTSPClient(*fEnv, fUrl->UrlString(),
0, this); 0, this);
if (fClient == NULL) { if (fClient == NULL)
fInitErr = B_ERROR;
return; return;
}
fClient->sendDescribeCommand(continueAfterDESCRIBE); fClient->sendDescribeCommand(continueAfterDESCRIBE);
fLoopThread = spawn_thread(_LoopThread, "two minutes hate thread", fLoopThread = spawn_thread(_LoopThread, "two minutes hate thread",
B_NORMAL_PRIORITY, this); B_NORMAL_PRIORITY, this);
if (fLoopThread <= 0 || resume_thread(fLoopThread) != B_OK) { if (fLoopThread <= 0 || resume_thread(fLoopThread) != B_OK)
fInitErr = B_ERROR;
return; return;
}
fInitErr = fClient->WaitForInit(5000000); fInitErr = fClient->WaitForInit(5000000);
} }
@@ -54,8 +48,9 @@ RTSPMediaIO::~RTSPMediaIO()
ShutdownLoop(); ShutdownLoop();
status_t status;
if (fLoopThread != -1) if (fLoopThread != -1)
exit_thread(fLoopThread); wait_for_thread(fLoopThread, &status);
} }
@@ -80,6 +75,13 @@ RTSPMediaIO::WriteAt(off_t position, const void* buffer, size_t size)
} }
status_t
RTSPMediaIO::SetSize(off_t size)
{
return B_NOT_SUPPORTED;
}
int32 int32
RTSPMediaIO::_LoopThread(void* data) RTSPMediaIO::_LoopThread(void* data)
{ {
@@ -134,11 +136,14 @@ status_t
HaikuRTSPClient::WaitForInit(bigtime_t timeout) HaikuRTSPClient::WaitForInit(bigtime_t timeout)
{ {
status_t status = B_ERROR; status_t status = B_ERROR;
read_port_etc(fInitPort, NULL, &status, if (read_port_etc(fInitPort, NULL, &status,
sizeof(status), B_RELATIVE_TIMEOUT, timeout); sizeof(status), B_RELATIVE_TIMEOUT, timeout) < 0) {
return B_ERROR;
}
close_port(fInitPort); close_port(fInitPort);
delete_port(fInitPort); delete_port(fInitPort);
fInitPort = -1;
return status; return status;
} }
@@ -27,14 +27,14 @@ public:
const void* buffer, const void* buffer,
size_t size); size_t size);
virtual status_t SetSize(off_t size);
void LoopThread(); void LoopThread();
void ShutdownLoop(); void ShutdownLoop();
private: private:
static int32 _LoopThread(void* data); static int32 _LoopThread(void* data);
BUrl* fUrl; BUrl* fUrl;
BInputAdapter* fInputAdapter;
HaikuRTSPClient* fClient; HaikuRTSPClient* fClient;
UsageEnvironment* fEnv; UsageEnvironment* fEnv;