2 * Copyright 2016, Dario Casalinuovo. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 #include "RTSPMediaIO.h"
10 #define LIVE555_VERBOSITY 1
13 RTSPMediaIO::RTSPMediaIO(BUrl ourUrl
)
16 B_MEDIA_STREAMING
| B_MEDIA_MUTABLE_SIZE
| B_MEDIA_SEEK_BACKWARD
,
21 fLoopWatchVariable(0),
24 fScheduler
= BasicTaskScheduler::createNew();
25 fEnv
= BasicUsageEnvironment::createNew(*fScheduler
);
29 RTSPMediaIO::~RTSPMediaIO()
36 if (fLoopThread
!= -1)
37 wait_for_thread(fLoopThread
, &status
);
42 RTSPMediaIO::WriteAt(off_t position
, const void* buffer
, size_t size
)
44 return B_NOT_SUPPORTED
;
49 RTSPMediaIO::SetSize(off_t size
)
51 return B_NOT_SUPPORTED
;
58 fClient
= new HaikuRTSPClient(*fEnv
, fUrl
.UrlString(),
63 fClient
->sendDescribeCommand(continueAfterDESCRIBE
);
65 fLoopThread
= spawn_thread(_LoopThread
, "two minutes hate thread",
66 B_NORMAL_PRIORITY
, this);
68 if (fLoopThread
<= 0 || resume_thread(fLoopThread
) != B_OK
)
71 return fClient
->WaitForInit(5000000);
76 RTSPMediaIO::_LoopThread(void* data
)
78 static_cast<RTSPMediaIO
*>(data
)->LoopThread();
84 RTSPMediaIO::LoopThread()
86 fEnv
->taskScheduler().doEventLoop(&fLoopWatchVariable
);
92 RTSPMediaIO::ShutdownLoop()
94 fLoopWatchVariable
= 1;
98 HaikuRTSPClient::HaikuRTSPClient(UsageEnvironment
& env
, char const* rtspURL
,
99 portNumBits tunnelOverHTTPPortNum
, RTSPMediaIO
* interface
)
101 RTSPClient(env
, rtspURL
, LIVE555_VERBOSITY
, "Haiku RTSP Streamer",
102 tunnelOverHTTPPortNum
, -1),
106 streamTimerTask(NULL
),
108 fInterface(interface
),
111 fInitPort
= create_port(1, "RTSP Client wait port");
115 HaikuRTSPClient::~HaikuRTSPClient()
121 HaikuRTSPClient::Close()
124 if (session
!= NULL
) {
125 UsageEnvironment
& env
= session
->envir();
126 env
.taskScheduler().unscheduleDelayedTask(streamTimerTask
);
127 Medium::close(session
);
133 HaikuRTSPClient::WaitForInit(bigtime_t timeout
)
135 status_t status
= B_ERROR
;
136 if (read_port_etc(fInitPort
, NULL
, &status
,
137 sizeof(status
), B_RELATIVE_TIMEOUT
, timeout
) < 0) {
141 close_port(fInitPort
);
142 delete_port(fInitPort
);
149 HaikuRTSPClient::NotifyError()
151 fInterface
->ShutdownLoop();
152 status_t status
= B_ERROR
;
153 write_port(fInitPort
, NULL
, &status
, sizeof(status
));
158 HaikuRTSPClient::NotifySucces()
160 status_t status
= B_OK
;
161 write_port(fInitPort
, NULL
, &status
, sizeof(status
));
166 HaikuRTSPClient::GetInputAdapter() const
168 return fInterface
->BuildInputAdapter();