rs_rtp_stream.hh
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include "RsRtspClient.h"
7 #include "RsSink.h"
8 
9 #include "software-device.h"
10 #include <librealsense2/rs.hpp>
11 
12 #include <NetdevLog.h>
13 
14 const int RTP_QUEUE_MAX_SIZE = 30;
15 
16 struct Raw_Frame
17 {
18  Raw_Frame(char* buffer, int size, struct timeval timestamp)
19  : m_metadata((RsMetadataHeader*)buffer)
20  , m_buffer(buffer + sizeof(RsMetadataHeader))
21  , m_size(size)
22  , m_timestamp(timestamp){};
23  Raw_Frame(const Raw_Frame&);
24  Raw_Frame& operator=(const Raw_Frame&);
26  {
27  delete[] m_buffer;
28  };
29 
31  char* m_buffer;
32  unsigned int m_size;
33  struct timeval m_timestamp;
34 };
35 
37 {
38 public:
40  {
41  frame_data_buff.bpp = rs_stream.bpp;
42 
43  frame_data_buff.profile = rs_profile;
44  m_stream_profile = rs_profile;
45  frame_data_buff.stride = rs_stream.bpp * rs_stream.width;
46  pixels_buff.resize(frame_data_buff.stride * rs_stream.height, 0);
47  frame_data_buff.pixels = pixels_buff.data();
48  frame_data_buff.deleter = this->frame_deleter;
49 
50  m_rs_stream = rs_stream;
51  }
52 
54  {
55  return m_stream_profile;
56  }
57 
59  {
60  return m_rs_stream.type;
61  }
62 
63  void insert_frame(Raw_Frame* new_raw_frame)
64  {
65  if(queue_size() > RTP_QUEUE_MAX_SIZE)
66  {
67  ERR << "Queue is full. Dropping frame for: " << this->m_rs_stream.uid;
68  }
69  else
70  {
71  std::lock_guard<std::mutex> lock(this->stream_lock);
72  frames_queue.push(new_raw_frame);
73  }
74  }
75 
76  // extrinsics between this stream to all other streams
77  // the key is generated by RsRTSPClient::getStreamProfileUniqueKey function
78  std::map<long long int, rs2_extrinsics> extrinsics_map;
79 
81  {
82  std::lock_guard<std::mutex> lock(this->stream_lock);
83  Raw_Frame* frame = frames_queue.front();
84  frames_queue.pop();
85  return frame;
86  }
87 
88  void reset_queue()
89  {
90  while(!frames_queue.empty())
91  {
92  Raw_Frame* frame = frames_queue.front();
93  get_memory_pool().returnMem((unsigned char*)frame->m_buffer - sizeof(RsFrameHeader));
94  frames_queue.pop();
95  }
96  INF << "Frames queue cleaned for " << m_rs_stream.uid;
97  }
98 
99  int queue_size()
100  {
101  std::lock_guard<std::mutex> lock(this->stream_lock);
102  return (int)frames_queue.size();
103  }
104 
106  {
107  static MemoryPool memory_pool_instance = MemoryPool();
108  return memory_pool_instance;
109  }
110 
112 
114 
116 
117 private:
118  static void frame_deleter(void* p)
119  {
120  get_memory_pool().returnMem((unsigned char*)p - sizeof(RsFrameHeader));
121  }
122 
124 
125  std::mutex stream_lock;
126 
127  std::queue<Raw_Frame*> frames_queue;
128 
129  std::vector<uint8_t> pixels_buff;
130 };
std::mutex stream_lock
static const textual_icon lock
Definition: model-views.h:218
rs2::stream_profile m_stream_profile
void insert_frame(Raw_Frame *new_raw_frame)
#define ERR
Definition: NetdevLog.h:9
rs2_software_video_frame frame_data_buff
std::map< long long int, rs2_extrinsics > extrinsics_map
unsigned int m_size
GLfloat GLfloat p
Definition: glext.h:12687
Raw_Frame & operator=(const Raw_Frame &)
#define INF
Definition: NetdevLog.h:11
RsMetadataHeader * m_metadata
All the parameters required to define a video stream.
Definition: rs_internal.h:41
std::queue< Raw_Frame * > frames_queue
Raw_Frame(char *buffer, int size, struct timeval timestamp)
GLenum GLfloat * buffer
rs2_stream stream_type()
rs2_video_stream m_rs_stream
Raw_Frame * extract_frame()
GLsizeiptr size
rs_rtp_stream(rs2_video_stream rs_stream, rs2::stream_profile rs_profile)
static MemoryPool & get_memory_pool()
std::vector< uint8_t > pixels_buff
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
struct timeval m_timestamp
void reset_queue()
All the parameters required to define a video frame.
Definition: rs_internal.h:76
static void frame_deleter(void *p)
char * m_buffer
const rs2::stream_profile get_stream_profile()
const int RTP_QUEUE_MAX_SIZE


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