RsSimpleRTPSink.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 #include "RsSimpleRTPSink.h"
5 #include "RsDevice.hh"
6 #include <algorithm>
8 #include <iostream>
9 #include <sstream>
10 #include <string>
11 
13  Groupsock* t_RTPgs,
14  unsigned char t_rtpPayloadFormat,
15  unsigned t_rtpTimestampFrequency,
16  char const* t_sdpMediaTypeString,
17  char const* t_rtpPayloadFormatName,
18  rs2::video_stream_profile& t_videoStream,
19  std::shared_ptr<RsDevice> device,
20  unsigned t_numChannels,
21  Boolean t_allowMultipleFramesPerPacket,
22  Boolean t_doNormalMBitRule)
23 {
25  return new RsSimpleRTPSink(t_env, t_RTPgs, t_rtpPayloadFormat, t_rtpTimestampFrequency, t_sdpMediaTypeString, t_rtpPayloadFormatName, t_videoStream, device, t_numChannels, t_allowMultipleFramesPerPacket, t_doNormalMBitRule);
26 }
27 
28 std::string getSdpLineForField(const char* t_name, int t_val)
29 {
30  std::ostringstream oss;
31  oss << t_name << "=" << t_val << ";";
32  return oss.str();
33 }
34 
35 std::string getSdpLineForField(const char* t_name, const char* t_val)
36 {
37  std::ostringstream oss;
38  oss << t_name << "=" << t_val << ";";
39  return oss.str();
40 }
41 
43 {
45  str.append("rotation:");
46  for(float r : extrinsics.rotation)
47  {
48  str.append(std::to_string(r));
49  str.append(",");
50  }
51  str.pop_back();
52  str.append("translation:");
53  for(float r : extrinsics.translation)
54  {
55  str.append(std::to_string(r));
56  str.append(",");
57  }
58  str.pop_back();
59 
60  return str;
61 }
62 
64 {
65 
66  if(device == nullptr)
67  return "";
68 
70 
71  for(auto relation : device.get()->minimal_extrinsics_map)
72  {
73  //check at map for this stream relations
74  if(relation.first.first == (RsDevice::getPhysicalSensorUniqueKey(stream.stream_type(), stream.stream_index())))
75  {
76  str.append("<to_sensor_");
77  //write the 'to' stream key
78  str.append(std::to_string(relation.first.second));
79  str.append(">");
80  str.append(extrinsics_to_string(relation.second));
81  str.append("&");
82  }
83  }
84 
85  return str;
86 }
87 
88 std::string getSdpLineForVideoStream(rs2::video_stream_profile& t_videoStream, std::shared_ptr<RsDevice> device)
89 {
91  str.append(getSdpLineForField("width", t_videoStream.width()));
92  str.append(getSdpLineForField("height", t_videoStream.height()));
93  str.append(getSdpLineForField("format", t_videoStream.format()));
94  str.append(getSdpLineForField("uid", t_videoStream.unique_id()));
95  str.append(getSdpLineForField("fps", t_videoStream.fps()));
96  str.append(getSdpLineForField("stream_index", t_videoStream.stream_index()));
97  str.append(getSdpLineForField("stream_type", t_videoStream.stream_type()));
98  str.append(getSdpLineForField("bpp", getStreamProfileBpp(t_videoStream.format())));
99  str.append(getSdpLineForField("cam_serial_num", device.get()->getDevice().get_info(RS2_CAMERA_INFO_SERIAL_NUMBER)));
100  str.append(getSdpLineForField("usb_type", device.get()->getDevice().get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR)));
101  str.append(getSdpLineForField("compression", CompressionFactory::getIsEnabled()));
102 
103  str.append(getSdpLineForField("ppx", t_videoStream.get_intrinsics().ppx));
104  str.append(getSdpLineForField("ppy", t_videoStream.get_intrinsics().ppy));
105  str.append(getSdpLineForField("fx", t_videoStream.get_intrinsics().fx));
106  str.append(getSdpLineForField("fy", t_videoStream.get_intrinsics().fy));
107  str.append(getSdpLineForField("model", t_videoStream.get_intrinsics().model));
108 
109  for(size_t i = 0; i < 5; i++)
110  {
111  str.append(getSdpLineForField("coeff_" + i, t_videoStream.get_intrinsics().coeffs[i]));
112  }
113 
114  str.append(getSdpLineForField("extrinsics", get_extrinsics_string_per_stream(device, t_videoStream).c_str()));
115 
116  std::string name = device.get()->getDevice().get_info(RS2_CAMERA_INFO_NAME);
117  // We don't want to sent spaces over SDP , replace all spaces with '^'
118  std::replace(name.begin(), name.end(), ' ', '^');
119  str.append(getSdpLineForField("cam_name", name.c_str()));
120 
121  return str;
122 }
123 
124 RsSimpleRTPSink ::RsSimpleRTPSink(UsageEnvironment& t_env,
125  Groupsock* t_RTPgs,
126  unsigned char t_rtpPayloadFormat,
127  unsigned t_rtpTimestampFrequency,
128  char const* t_sdpMediaTypeString,
129  char const* t_rtpPayloadFormatName,
130  rs2::video_stream_profile& t_videoStream,
131  std::shared_ptr<RsDevice> device,
132  unsigned t_numChannels,
133  Boolean t_allowMultipleFramesPerPacket,
134  Boolean t_doNormalMBitRule)
135  : SimpleRTPSink(t_env, t_RTPgs, t_rtpPayloadFormat, t_rtpTimestampFrequency, t_sdpMediaTypeString, t_rtpPayloadFormatName, t_numChannels, t_allowMultipleFramesPerPacket, t_doNormalMBitRule)
136 {
137  // Then use this 'config' string to construct our "a=fmtp:" SDP line:
138  unsigned fmtpSDPLineMaxSize = SDP_MAX_LINE_LENGHT;
139  m_fFmtpSDPLine = new char[fmtpSDPLineMaxSize];
140  std::string sdpStr = getSdpLineForVideoStream(t_videoStream, device);
141  sprintf(m_fFmtpSDPLine, "a=fmtp:%d;%s\r\n", rtpPayloadType(), sdpStr.c_str());
142 }
143 
145 {
146  return m_fFmtpSDPLine;
147 }
::realsense_legacy_msgs::extrinsics_< std::allocator< void > > extrinsics
Definition: extrinsics.h:59
GLuint const GLchar * name
#define IS_COMPRESSION_ENABLED
float translation[3]
Definition: rs_sensor.h:99
float coeffs[5]
Definition: rs_types.h:67
GLsizei const GLchar *const * string
GLuint GLuint stream
Definition: glext.h:1790
float rotation[9]
Definition: rs_sensor.h:98
static int getPhysicalSensorUniqueKey(rs2_stream stream_type, int sensors_index)
Definition: RsDevice.cpp:9
GLdouble GLdouble r
std::string extrinsics_to_string(rs2_extrinsics extrinsics)
const unsigned int SDP_MAX_LINE_LENGHT
Definition: RsCommon.h:53
RsSimpleRTPSink(UsageEnvironment &env, Groupsock *RTPgs, unsigned char rtpPayloadFormat, unsigned rtpTimestampFrequency, char const *sdpMediaTypeString, char const *rtpPayloadFormatName, rs2::video_stream_profile &video_stream, std::shared_ptr< RsDevice > device, unsigned numChannels=1, Boolean allowMultipleFramesPerPacket=True, Boolean doNormalMBitRule=True)
int stream_index() const
Definition: rs_frame.hpp:34
rs2_intrinsics get_intrinsics() const
Definition: rs_frame.hpp:238
std::string getSdpLineForField(const char *t_name, int t_val)
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
rs2_format format() const
Definition: rs_frame.hpp:44
rs2_distortion model
Definition: rs_types.h:66
std::string getSdpLineForVideoStream(rs2::video_stream_profile &t_videoStream, std::shared_ptr< RsDevice > device)
int getStreamProfileBpp(rs2_format t_format)
Definition: RsCommon.cpp:6
static bool & getIsEnabled()
int i
static RsSimpleRTPSink * createNew(UsageEnvironment &env, Groupsock *RTPgs, unsigned char rtpPayloadFormat, unsigned rtpTimestampFrequency, char const *sdpMediaTypeString, char const *rtpPayloadFormatName, rs2::video_stream_profile &video_stream, std::shared_ptr< RsDevice > device, unsigned numChannels=1, Boolean allowMultipleFramesPerPacket=True, Boolean doNormalMBitRule=True)
int unique_id() const
Definition: rs_frame.hpp:54
std::string get_extrinsics_string_per_stream(std::shared_ptr< RsDevice > device, rs2::video_stream_profile stream)
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
auto device
Definition: pyrs_net.cpp:17
int fps() const
Definition: rs_frame.hpp:49
virtual char const * auxSDPLine()
std::string to_string(T value)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:41