Skip to content

Commit

Permalink
Merge pull request IntelRealSense#30 from IntelRealSense/efarbs_RsDevice
Browse files Browse the repository at this point in the history
code refactoring
  • Loading branch information
esterfarbstein authored Jan 13, 2020
2 parents 8d1a6c1 + 2662c0a commit 083921c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
16 changes: 8 additions & 8 deletions tools/rs-server/RsCamera.cpp → tools/rs-server/RsDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <iostream>
#include "RsCamera.hh"
#include "RsDevice.hh"

RsCamera::RsCamera()
RsDevice::RsDevice()
{
//get RS device
//get LRS device
std::cerr << "RsCamera constructor" << std::endl;
// The context represents the current platform with respect to connected devices
rs2::context ctx;
Expand All @@ -13,21 +13,21 @@ RsCamera::RsCamera()
{
std::cerr << "No device connected, please connect a RealSense device" << std::endl;
rs2::device_hub device_hub(ctx);
m_dev = device_hub.wait_for_device();
m_device = device_hub.wait_for_device(); //todo: check wait_for_device
}
else
{
m_dev = devices[0]; // Only one device is supported
m_device = devices[0]; // Only one device is supported
}

//get RS sensors
for (auto &sensor : m_dev.query_sensors())
for (auto &sensor : m_device.query_sensors())
{
m_sensors.push_back(RsSensor(sensor));
}
}

RsCamera::~RsCamera()
RsDevice::~RsDevice()
{
std::cerr << "RsCamera destructor" << std::endl;
std::cerr << "RsDevice destructor" << std::endl;
}
8 changes: 4 additions & 4 deletions tools/rs-server/RsCamera.hh → tools/rs-server/RsDevice.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#include "RsSensor.hh"


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

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

Expand Down
1 change: 0 additions & 1 deletion tools/rs-server/RsMediaSubsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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>

Expand Down
2 changes: 1 addition & 1 deletion 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.hh"
#include "RsDevice.hh"
#include <librealsense2/rs.hpp>

class RsRTSPServer: public RTSPServer {
Expand Down
10 changes: 4 additions & 6 deletions tools/rs-server/RsSensor.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <iostream>
//#include <mutex>
//#include <thread>
#include <math.h>
#include "RsCamera.hh"
#include "RsDevice.hh"

RsSensor::RsSensor(rs2::sensor sensor)
{
Expand All @@ -19,16 +17,16 @@ RsSensor::RsSensor(rs2::sensor sensor)

int RsSensor::open(std::unordered_map<long long int, rs2::frame_queue> &stream_profiles_queues)
{
std::vector<rs2::stream_profile> stream_profiles;
std::vector<rs2::stream_profile> requested_stream_profiles;
for (auto stream_profile : stream_profiles_queues)
{
//make a vector of all requested stream profiles
long long int stream_profile_key = stream_profile.first;
stream_profiles.push_back(m_stream_profiles.at(stream_profile_key));
requested_stream_profiles.push_back(m_stream_profiles.at(stream_profile_key));
}
try
{
m_sensor.open(stream_profiles);
m_sensor.open(requested_stream_profiles);
}
catch (...)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/rs-server/RsServerMediaSession.h
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.,
#define _RS_SERVER_MEDIA_SESSION_HH

#include "ServerMediaSession.hh"
#include "RsCamera.hh"
#include "RsDevice.hh"

class RsServerMediaSession: public ServerMediaSession {
public:
Expand Down
6 changes: 3 additions & 3 deletions tools/rs-server/rs-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ along with this library; if not, write to the Free Software Foundation, Inc.,
#include <signal.h>
#include "RsSource.hh"
#include "RsMediaSubsession.h"
#include "RsCamera.hh"
#include "RsDevice.hh"
#include "RsRTSPServer.hh"
#include "RsServerMediaSession.h"

Expand All @@ -48,7 +48,7 @@ RsDeviceSource *devSource2;
RawVideoRTPSink *videoSink1;
RawVideoRTPSink *videoSink2;
RTSPServer *rtspServer;
RsCamera cam;
RsDevice device;
std::vector<RsSensor> sensors;

void play(); // forward
Expand All @@ -69,7 +69,7 @@ int main(int argc, char **argv)
exit(1);
}

sensors = cam.getSensors();
sensors = device.getSensors();
int sensorIndex =0;//TODO::to remove
for (auto sensor:sensors)
{
Expand Down

0 comments on commit 083921c

Please sign in to comment.