Skip to content

Commit

Permalink
RTSPMediaIO: Improve thread control
Browse files Browse the repository at this point in the history
* Instead to exit the thred we will wait until the live555
eventLoop quits peacefully.
* Better error handling.
* Implement SetSize as a not supported operation.
  • Loading branch information
Numerio committed Jun 22, 2016
1 parent 6903cf9 commit b13f52b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
29 changes: 17 additions & 12 deletions src/add-ons/media/plugins/rtsp_streamer/RTSPMediaIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,26 @@ RTSPMediaIO::RTSPMediaIO(BUrl* ourUrl)
B_INFINITE_TIMEOUT),
fUrl(ourUrl),
fClient(NULL),
fInputAdapter(NULL),
fScheduler(NULL),
fLoopWatchVariable(0),
fLoopThread(-1),
fInitErr(B_OK)
fInitErr(B_ERROR)
{
fInputAdapter = BuildInputAdapter();
fScheduler = BasicTaskScheduler::createNew();
fEnv = BasicUsageEnvironment::createNew(*fScheduler);

fClient = new HaikuRTSPClient(*fEnv, fUrl->UrlString(),
0, this);
if (fClient == NULL) {
fInitErr = B_ERROR;
if (fClient == NULL)
return;
}

fClient->sendDescribeCommand(continueAfterDESCRIBE);

fLoopThread = spawn_thread(_LoopThread, "two minutes hate thread",
B_NORMAL_PRIORITY, this);

if (fLoopThread <= 0 || resume_thread(fLoopThread) != B_OK) {
fInitErr = B_ERROR;
if (fLoopThread <= 0 || resume_thread(fLoopThread) != B_OK)
return;
}

fInitErr = fClient->WaitForInit(5000000);
}
Expand All @@ -54,8 +48,9 @@ RTSPMediaIO::~RTSPMediaIO()

ShutdownLoop();

status_t status;
if (fLoopThread != -1)
exit_thread(fLoopThread);
wait_for_thread(fLoopThread, &status);
}


Expand All @@ -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
RTSPMediaIO::_LoopThread(void* data)
{
Expand Down Expand Up @@ -134,11 +136,14 @@ status_t
HaikuRTSPClient::WaitForInit(bigtime_t timeout)
{
status_t status = B_ERROR;
read_port_etc(fInitPort, NULL, &status,
sizeof(status), B_RELATIVE_TIMEOUT, timeout);
if (read_port_etc(fInitPort, NULL, &status,
sizeof(status), B_RELATIVE_TIMEOUT, timeout) < 0) {
return B_ERROR;
}

close_port(fInitPort);
delete_port(fInitPort);
fInitPort = -1;
return status;
}

Expand Down
4 changes: 2 additions & 2 deletions src/add-ons/media/plugins/rtsp_streamer/RTSPMediaIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class RTSPMediaIO : public BAdapterIO
const void* buffer,
size_t size);

virtual status_t SetSize(off_t size);

void LoopThread();
void ShutdownLoop();
private:
static int32 _LoopThread(void* data);

BUrl* fUrl;
BInputAdapter* fInputAdapter;


HaikuRTSPClient* fClient;
UsageEnvironment* fEnv;
Expand Down

0 comments on commit b13f52b

Please sign in to comment.