Skip to content

Commit

Permalink
Merge pull request IntelRealSense#19 from IntelRealSense/rtsp_branch_…
Browse files Browse the repository at this point in the history
…michalpr2

Rtsp client setup and play
  • Loading branch information
michalprager authored Jan 1, 2020
2 parents 62141eb + b4518e6 commit 0e47623
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 22 deletions.
8 changes: 7 additions & 1 deletion examples/rtsp-client-app/myClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

int main()
{
IcamOERtsp* camOErtspInstance = camOERTSPClient::getRtspClient("rtsp://10.12.145.82:8554/unicast", "myClient");
//IcamOERtsp* camOErtspInstance = camOERTSPClient::getRtspClient("rtsp://10.12.145.82:8554/unicast", "myClient");
IcamOERtsp* camOErtspInstance = camOERTSPClient::getRtspClient("rtsp://10.12.144.35:8554/unicast", "myClient");
std::vector<rs2_video_stream> myProfiles;
((camOERTSPClient*)camOErtspInstance)->initFunc();
myProfiles = camOErtspInstance->queryStreams();
Expand All @@ -15,5 +16,10 @@ int main()
std::cout << "Profile " << i << ": " << "width = " << myProfiles[i].width << " height = " << myProfiles[i].height << "\n";
}

int res = camOErtspInstance->addStream(myProfiles[0]);
std::cout << "After setup. res = " << res << "\n";
camOErtspInstance->start();
std::cout << "After play.\n";

return 0;
}
67 changes: 47 additions & 20 deletions src/ethernet/camOERtspClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ camOERTSPClient::camOERTSPClient(UsageEnvironment& env, char const* rtspURL,
camOERTSPClient::~camOERTSPClient() {
}

// TODO: should we have seperate mutex for each command?
std::condition_variable cv;
std::mutex describe_mtx;
std::mutex command_mtx;
bool describe_done = false;

// Forward function definitions:
Expand All @@ -38,29 +39,45 @@ void continueAfterSETUP(RTSPClient* rtspClient, int resultCode, char* resultStri
void continueAfterPLAY(RTSPClient* rtspClient, int resultCode, char* resultString);
void setupSubsession(MediaSubsession* subsession, RTSPClient* rtspClient);

void camOERTSPClient::describe()
std::vector<rs2_video_stream> camOERTSPClient::queryStreams()
{
this->sendDescribeCommand(continueAfterDESCRIBE);
this->envir() << "in sendDescribe after sending command\n";
// wait for continueAfterDESCRIBE to finish
std::unique_lock<std::mutex> lck(describe_mtx);
std::unique_lock<std::mutex> lck(command_mtx);
cv.wait(lck);

this->envir() << "in sendDescribe After wait\n";
}

std::vector<rs2_video_stream> camOERTSPClient::queryStreams()
{
this->describe();
this->envir() << "in sendDescribe After wait\n";
return this->supportedProfiles;
}
int camOERTSPClient::addStream(rs2_video_stream)
int camOERTSPClient::addStream(rs2_video_stream stream)
{

MediaSubsession* subsession = this->subsessionMap.find(stream.uid)->second;


if (subsession != NULL) {
if (!subsession->initiate()) {
this->envir() << "Failed to initiate the subsession \n";

} else {
this->envir() << "Initiated the subsession \n";;

// Continue setting up this subsession, by sending a RTSP "SETUP" command:
this->sendSetupCommand(*subsession, continueAfterSETUP, False, REQUEST_STREAMING_OVER_TCP);
// wait for continueAfterSETUP to finish
std::unique_lock<std::mutex> lck(command_mtx);
cv.wait(lck);
}
}
// TODO: return error code
return 0;
}
void camOERTSPClient::start()
{

this->sendPlayCommand(*this->scs.session, continueAfterPLAY);
// wait for continueAfterPLAY to finish
std::unique_lock<std::mutex> lck(command_mtx);
cv.wait(lck);
}
void camOERTSPClient::stop()
{
Expand Down Expand Up @@ -110,6 +127,7 @@ void continueAfterDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultS
break;
}

int stream_counter = 0;
scs.iter = new MediaSubsessionIterator(*scs.session);
scs.subsession = scs.iter->next();
while (scs.subsession != NULL) {
Expand All @@ -121,12 +139,16 @@ void continueAfterDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultS
rs2_video_stream videoStream;
videoStream.width = width;
videoStream.height = height;
videoStream.uid = stream_counter;
// TODO: update width and height in subsession?
((camOERTSPClient*)rtspClient)->subsessionMap.insert(std::pair<int, MediaSubsession*>(videoStream.uid, scs.subsession));
stream_counter++;
((camOERTSPClient*)rtspClient)->supportedProfiles.push_back(videoStream);
scs.subsession = scs.iter->next();
// TODO: when to delete p?
}

std::unique_lock<std::mutex> lck(describe_mtx);
std::unique_lock<std::mutex> lck(command_mtx);
cv.notify_one();

return;
Expand All @@ -137,14 +159,19 @@ void continueAfterDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultS
//shutdownStream(rtspClient);
}

void setupSubsession(MediaSubsession* subsession, RTSPClient* rtspClient)
{
void continueAfterSETUP(RTSPClient* rtspClient, int resultCode, char* resultString) {
UsageEnvironment& env = rtspClient->envir(); // alias
env << "Setting up subsession: " << subsession->codecName() << "\n";
rtspClient->sendSetupCommand(*subsession, continueAfterSETUP, False, REQUEST_STREAMING_OVER_TCP);
env << "continueAfterSETUP " << resultCode << " " << resultString <<"\n";

std::unique_lock<std::mutex> lck(command_mtx);
cv.notify_one();
}

void continueAfterSETUP(RTSPClient* rtspClient, int resultCode, char* resultString) {
void continueAfterPLAY(RTSPClient* rtspClient, int resultCode, char* resultString)
{
UsageEnvironment& env = rtspClient->envir(); // alias
env << "continueAfterSETUP" << "\n";
}
env << "continueAfterPLAY " << resultCode << " " << resultString <<"\n";
std::unique_lock<std::mutex> lck(command_mtx);
cv.notify_one();

}
6 changes: 5 additions & 1 deletion src/ethernet/camOERtspClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <librealsense2/hpp/rs_internal.hpp>

#include <vector>
#include <map>

class camOERTSPClient: public RTSPClient, IcamOERtsp
{
Expand All @@ -17,12 +18,14 @@ class camOERTSPClient: public RTSPClient, IcamOERtsp
char const* applicationName = NULL,
portNumBits tunnelOverHTTPPortNum = 0);
void describe();
void setup(rs2_video_stream stream);
void initFunc();



// IcamOERtsp functions
virtual std::vector<rs2_video_stream> queryStreams();
virtual int addStream(rs2_video_stream);
virtual int addStream(rs2_video_stream stream);
virtual void start();
virtual void stop();
virtual void close();
Expand All @@ -33,6 +36,7 @@ class camOERTSPClient: public RTSPClient, IcamOERtsp
public:
StreamClientState scs;
std::vector<rs2_video_stream> supportedProfiles;
std::map<int, MediaSubsession*> subsessionMap;

private:
camOERTSPClient(UsageEnvironment& env, char const* rtspURL,
Expand Down

0 comments on commit 0e47623

Please sign in to comment.