Skip to content

Commit

Permalink
Merge pull request IntelRealSense#29 from IntelRealSense/scpungin_LRS…
Browse files Browse the repository at this point in the history
…_integration

add profile hash
  • Loading branch information
cspungin authored Jan 13, 2020
2 parents 84b45c2 + 6b08e21 commit 8d1a6c1
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 170 deletions.
3 changes: 3 additions & 0 deletions third-party/live/liveMedia/MultiFramedRTPSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ MultiFramedRTPSink::MultiFramedRTPSink(UsageEnvironment& env,
rtpPayloadFormatName, numChannels),
fOutBuf(NULL), fCurFragmentationOffset(0), fPreviousFrameEndedFragmentation(False),
fOnSendErrorFunc(NULL), fOnSendErrorData(NULL) {
env << "MultiFramedRTPSink constructor\n";
setPacketSizes((RTP_PAYLOAD_PREFERRED_SIZE), (RTP_PAYLOAD_MAX_SIZE));
}

Expand Down Expand Up @@ -156,6 +157,7 @@ void MultiFramedRTPSink::setFramePadding(unsigned numPaddingBytes) {
Boolean MultiFramedRTPSink::continuePlaying() {
// Send the first packet.
// (This will also schedule any future sends.)
envir() << "continuePlaying\n";
buildAndSendPacket(True);
return True;
}
Expand All @@ -166,6 +168,7 @@ void MultiFramedRTPSink::stopPlaying() {
fOutBuf->resetOverflowData();

// Then call the default "stopPlaying()" function:
envir() << "MultiFramedRTPSink ::stopPlaying\n";
MediaSink::stopPlaying();
}

Expand Down
2 changes: 1 addition & 1 deletion third-party/live/liveMedia/RawVideoRTPSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ::RawVideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs, u_int8_t rtpPayloadFo
: VideoRTPSink(env, RTPgs, rtpPayloadFormat, 90000, "RAW"),
fFmtpSDPLine(NULL), fSampling(NULL), fWidth(width), fHeight(height),
fDepth(depth), fColorimetry(NULL), fLineindex(0) {

env << "RawVideoRTPSink constructor\n";
// Then use this 'config' string to construct our "a=fmtp:" SDP line:
unsigned fmtpSDPLineMaxSize = 200;// 200 => more than enough space
fFmtpSDPLine = new char[fmtpSDPLineMaxSize];
Expand Down
1 change: 1 addition & 0 deletions third-party/live/liveMedia/VideoRTPSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ VideoRTPSink::VideoRTPSink(UsageEnvironment& env,
char const* rtpPayloadFormatName)
: MultiFramedRTPSink(env, rtpgs, rtpPayloadType, rtpTimestampFrequency,
rtpPayloadFormatName) {
env << "VideoRTPSink constructor\n";
}

VideoRTPSink::~VideoRTPSink() {
Expand Down
103 changes: 1 addition & 102 deletions tools/rs-server/RsCamera.cpp
Original file line number Diff line number Diff line change
@@ -1,106 +1,5 @@
#include <iostream>
#include <mutex>
#include <thread>

#include "RsCamera.h"

RsSensor::RsSensor(rs2::sensor sensor)
{
//std::cerr << "RsSensor constructor" << std::endl;
m_sensor = sensor;
for (rs2::stream_profile stream_profile : m_sensor.get_stream_profiles())
{
if (stream_profile.is<rs2::video_stream_profile>())
{
m_stream_profiles.push_back(stream_profile.as<rs2::video_stream_profile>());
}
}
}

RsSensor::~RsSensor()
{
//std::cerr << "RsSensor destructor" << std::endl;
}

int RsSensor::open(std::map<int, rs2::frame_queue> &stream_profiles_queues)
{
std::vector<rs2::stream_profile> stream_profiles;
for (auto stream_profile : stream_profiles_queues)
{
//make a vector of all requested stream profiles
stream_profiles.push_back(m_stream_profiles[stream_profile.first]);
}
try
{
m_sensor.open(stream_profiles);
}
catch (...)
{
std::cerr << "unsupported combination of streams" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

int RsSensor::start(std::map<int, rs2::frame_queue> &stream_profiles_queues)
{
auto callback = [&](const rs2::frame &frame) {
int profile_indx = getStreamProfileIndex(frame.get_profile());
//check if profile exists in map:
if (profile_indx != -1 && stream_profiles_queues.find(profile_indx) != stream_profiles_queues.end())
{
//push frame to its queue
stream_profiles_queues[profile_indx].enqueue(frame);
}
};

m_sensor.start(callback);

return EXIT_SUCCESS;
}

int RsSensor::getStreamProfileIndex(rs2::stream_profile profile)
{
if (profile.is<rs2::video_stream_profile>())
{
rs2::video_stream_profile video_stream_profile = profile.as<rs2::video_stream_profile>();
return getStreamProfileIndex(video_stream_profile.stream_type(), video_stream_profile.format(), video_stream_profile.fps(), video_stream_profile.width(), video_stream_profile.height());
}
else
{
return -1; //only video_stream_profile is supported
}

}
int RsSensor::getStreamProfileIndex(rs2_stream type, rs2_format format, int fps, int width, int height)
{
int index = 0;
for (rs2::video_stream_profile video_stream_profile : m_stream_profiles)
{
if (video_stream_profile.stream_type() == type &&
video_stream_profile.format() == format &&
video_stream_profile.width() == width &&
video_stream_profile.height() == height &&
video_stream_profile.fps() == fps)
{
return index;
}
index++;
}
return -1;
}

std::string RsSensor::get_sensor_name()
{
if (m_sensor.supports(RS2_CAMERA_INFO_NAME))
{
return m_sensor.get_info(RS2_CAMERA_INFO_NAME);
}
else
{
return "Unknown Sensor";
}
}
#include "RsCamera.hh"

RsCamera::RsCamera()
{
Expand Down
38 changes: 0 additions & 38 deletions tools/rs-server/RsCamera.h

This file was deleted.

20 changes: 20 additions & 0 deletions tools/rs-server/RsCamera.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _RS_CAMERA_HH
#define _RS_CAMERA_HH

#include <librealsense2/rs.hpp>
#include "RsSensor.hh"


class RsCamera
{
public:
RsCamera();
~RsCamera();
std::vector<RsSensor> &getSensors() { return m_sensors; }

private:
rs2::device m_dev;
std::vector<RsSensor> m_sensors;
};

#endif
12 changes: 7 additions & 5 deletions tools/rs-server/RsMediaSubsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ along with this library; if not, write to the Free Software Foundation, Inc.,
// on demand, from a file.
// Implementation
#include "RsMediaSubsession.h"
#include "RsMediaSubsession.h"
#include "RsRawVideoRTPSink.h"
//#include <librealsense2/h/rs_sensor.h>

#define CAPACITY 100
Expand Down Expand Up @@ -70,30 +72,30 @@ ::createNewRTPSink(Groupsock* rtpGroupsock,
case RS2_FORMAT_RGB8:
{
pixelSize = 3;
return RawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "RGB");
return RsRawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "RGB");
}
case RS2_FORMAT_BGR8:
{
pixelSize = 3;
return RawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "BGR");
return RsRawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "BGR");
}
case RS2_FORMAT_RGBA8:
{
pixelSize = 3;
return RawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "RGBA");
return RsRawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "RGBA");
}
case RS2_FORMAT_BGRA8:
{
pixelSize = 3;
return RawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "BGRA");
return RsRawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "BGRA");
}
case RS2_FORMAT_Z16:
case RS2_FORMAT_Y16:
case RS2_FORMAT_RAW16:
case RS2_FORMAT_YUYV:
{
pixelSize = 2;
return RawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "YCbCr-4:2:2");
return RsRawVideoRTPSink::createNew(envir(), rtpGroupsock, rtpPayloadTypeIfDynamic, videoStreamProfile.height(), videoStreamProfile.width(), 8, "YCbCr-4:2:2");
}
default:
pixelSize = 0;
Expand Down
15 changes: 7 additions & 8 deletions tools/rs-server/RsRTSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ RsRTSPServer::RsRTSPClientConnection
::RsRTSPClientConnection(RTSPServer& ourServer, int clientSocket, struct sockaddr_in clientAddr)
:RTSPClientConnection(ourServer, clientSocket, clientAddr)
{
//envir() << "RsRTSPClientConnection constructor" << this <<"\n";
envir() << "RsRTSPClientConnection constructor" << this <<"\n";
}

RsRTSPServer::RsRTSPClientConnection::~RsRTSPClientConnection()
{
//envir() << "RsRTSPClientConnection destructor" << this <<"\n";
envir() << "RsRTSPClientConnection destructor" << this <<"\n";
}


Expand Down Expand Up @@ -147,11 +147,10 @@ int RsRTSPServer::RsRTSPClientSession::openRsCamera()
{
if (fStreamStates[i].subsession != NULL)
{
int profile_indx = ((RsServerMediaSession*)fOurServerMediaSession)->getRsSensor().getStreamProfileIndex(((RsMediaSubsession*)(fStreamStates[i].subsession))->get_stream_profile());

streamProfiles[profile_indx] = ((RsMediaSubsession*)(fStreamStates[i].subsession))->get_frame_queue();
long long int profile_key = ((RsServerMediaSession*)fOurServerMediaSession)->getRsSensor().getStreamProfileKey(((RsMediaSubsession*)(fStreamStates[i].subsession))->get_stream_profile());
streamProfiles[profile_key] = ((RsMediaSubsession*)(fStreamStates[i].subsession))->get_frame_queue();
rs2::frame f;
while (streamProfiles[profile_indx].poll_for_frame(&f));
while (streamProfiles[profile_key].poll_for_frame(&f));
}
}
((RsServerMediaSession*)fOurServerMediaSession)->openRsCamera(streamProfiles);//TODO:: to check if this is indeed RsServerMediaSession
Expand All @@ -164,9 +163,9 @@ int RsRTSPServer::RsRTSPClientSession::closeRsCamera()
{
if (fStreamStates[i].subsession != NULL)
{
int profile_indx = ((RsServerMediaSession*)fOurServerMediaSession)->getRsSensor().getStreamProfileIndex(((RsMediaSubsession*)(fStreamStates[i].subsession))->get_stream_profile());
long long int profile_key = ((RsServerMediaSession*)fOurServerMediaSession)->getRsSensor().getStreamProfileKey(((RsMediaSubsession*)(fStreamStates[i].subsession))->get_stream_profile());
rs2::frame f;
while (streamProfiles[profile_indx].poll_for_frame(&f));
while (streamProfiles[profile_key].poll_for_frame(&f));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tools/rs-server/RsRTSPServer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ along with this library; if not, write to the Free Software Foundation, Inc.,
#include "RsRTSPServer.hh"
#endif

#include "RsCamera.h"
#include "RsCamera.hh"
#include <librealsense2/rs.hpp>

class RsRTSPServer: public RTSPServer {
Expand Down Expand Up @@ -72,7 +72,7 @@ public:
protected:
//RsRTSPServer& fOurRsRTSPServer; // same as ::fOurServer
private:
std::map<int, rs2::frame_queue> streamProfiles;
std::unordered_map<long long int, rs2::frame_queue> streamProfiles;
};

protected: // redefined virtual functions
Expand All @@ -86,7 +86,7 @@ protected:
virtual ClientSession* createNewClientSession(u_int32_t sessionId);

private:
int openRsCamera(RsSensor sensor,std::map<int, rs2::frame_queue>& streamProfiles);
int openRsCamera(RsSensor sensor,std::unordered_map<long long int, rs2::frame_queue>& streamProfiles);

private:
friend class RsRTSPClientConnection;
Expand Down
44 changes: 44 additions & 0 deletions tools/rs-server/RsRawVideoRTPSink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


#include "RsRawVideoRTPSink.h"

RsRawVideoRTPSink*
RsRawVideoRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs, u_int8_t rtpPayloadFormat,
// The following headers provide the 'configuration' information, for the SDP description:
unsigned height, unsigned width, unsigned depth,
char const* sampling, char const* colorimetry)
{
return new RsRawVideoRTPSink(env, RTPgs, rtpPayloadFormat,
height, width, depth, sampling);

}



/*RawVideoRTPSink* RawVideoRTPSink
::createNew(UsageEnvironment& env, Groupsock* RTPgs, u_int8_t rtpPayloadFormat,
unsigned height, unsigned width, unsigned depth,
char const* sampling, char const* colorimetry) {
return new RawVideoRTPSink(env, RTPgs,
rtpPayloadFormat,
height, width, depth,
sampling, colorimetry);
}*/

RsRawVideoRTPSink
::RsRawVideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs, u_int8_t rtpPayloadFormat,
unsigned height, unsigned width, unsigned depth,
char const* sampling, char const* colorimetry)
: RawVideoRTPSink(env, RTPgs, rtpPayloadFormat,
height, width, depth, sampling, colorimetry) {
env << "RawVideoRTPSink constructor\n";

}

void RsRawVideoRTPSink::stopPlaying()
{
//fCurFragmentationOffset = 0;
RawVideoRTPSink::stopPlaying();


}
29 changes: 29 additions & 0 deletions tools/rs-server/RsRawVideoRTPSink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _RS_RAW_VIDEO_RTP_SINK_HH
#define _RS_RAW_VIDEO_RTP_SINK_HH

#include "RawVideoRTPSink.hh"


class RsRawVideoRTPSink: public RawVideoRTPSink {
public:
static RsRawVideoRTPSink*
createNew(UsageEnvironment& env, Groupsock* RTPgs, u_int8_t rtpPayloadFormat,
// The following headers provide the 'configuration' information, for the SDP description:
unsigned height, unsigned width, unsigned depth,
char const* sampling, char const* colorimetry = "BT709-2" );

protected:
RsRawVideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs,
u_int8_t rtpPayloadFormat,
unsigned height, unsigned width, unsigned depth,
char const* sampling, char const* colorimetry= "BT709-2" );



protected: // redefined virtual functions:
virtual void stopPlaying();

};


#endif //_RS_RAW_VIDEO_RTP_SINK_HH
Loading

0 comments on commit 8d1a6c1

Please sign in to comment.