Skip to content

Commit

Permalink
Merge branch 'master' into mchnan_delete_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mchanan authored Mar 25, 2020
2 parents 8a4c48f + 3078527 commit c1396e5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/ethernet/RsSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void RsSink::afterGettingFrameUid3(void* t_clientData, unsigned t_frameSize, uns
void RsSink::afterGettingFrame(unsigned t_frameSize, unsigned t_numTruncatedBytes, struct timeval t_presentationTime, unsigned /*t_durationInMicroseconds*/)
{
RsNetworkHeader* header = (RsNetworkHeader*)m_receiveBuffer;
if(header->frameSize == t_frameSize - sizeof(RsNetworkHeader))
if(header->data.frameSize == t_frameSize - sizeof(RsNetworkHeader))
{
if(this->m_rtpCallback != NULL)
{
Expand All @@ -112,7 +112,7 @@ void RsSink::afterGettingFrame(unsigned t_frameSize, unsigned t_numTruncatedByte
{
return;
}
int decompressedSize = m_iCompress->decompressBuffer(m_receiveBuffer + sizeof(RsFrameHeader), header->frameSize - sizeof(RsMetadataHeader), m_to + sizeof(RsFrameHeader));
int decompressedSize = m_iCompress->decompressBuffer(m_receiveBuffer + sizeof(RsFrameHeader), header->data.frameSize - sizeof(RsMetadataHeader), m_to + sizeof(RsFrameHeader));
if(decompressedSize != -1)
{
// copy metadata
Expand All @@ -123,7 +123,7 @@ void RsSink::afterGettingFrame(unsigned t_frameSize, unsigned t_numTruncatedByte
}
else
{
this->m_rtpCallback->on_frame(m_receiveBuffer + sizeof(RsNetworkHeader), header->frameSize, t_presentationTime);
this->m_rtpCallback->on_frame(m_receiveBuffer + sizeof(RsNetworkHeader), header->data.frameSize, t_presentationTime);
}
}
else
Expand All @@ -136,7 +136,7 @@ void RsSink::afterGettingFrame(unsigned t_frameSize, unsigned t_numTruncatedByte
else
{
m_memPool->returnMem(m_receiveBuffer);
envir() << m_streamId << ":corrupted frame!!!: data size is " << header->frameSize << " frame size is " << t_frameSize << "\n";
envir() << m_streamId << ":corrupted frame!!!: data size is " << header->data.frameSize << " frame size is " << t_frameSize << "\n";
}
m_receiveBuffer = nullptr;

Expand Down
7 changes: 4 additions & 3 deletions src/ethernet/ip_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,14 @@ void ip_device::inject_frames_loop(std::shared_ptr<rs_rtp_stream> rtp_stream)
{
Raw_Frame* frame = rtp_stream.get()->extract_frame();
rtp_stream.get()->frame_data_buff.pixels = frame->m_buffer;
rtp_stream.get()->frame_data_buff.timestamp = frame->m_metadata->timestamp;

rtp_stream.get()->frame_data_buff.timestamp = frame->m_metadata->data.timestamp;

rtp_stream.get()->frame_data_buff.frame_number++;
rtp_stream.get()->frame_data_buff.domain = frame->m_metadata->timestampDomain;
rtp_stream.get()->frame_data_buff.domain = frame->m_metadata->data.timestampDomain;

remote_sensors[sensor_id]->sw_sensor->set_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP, rtp_stream.get()->frame_data_buff.timestamp);
remote_sensors[sensor_id]->sw_sensor->set_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, frame->m_metadata->actualFps);
remote_sensors[sensor_id]->sw_sensor->set_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, frame->m_metadata->data.actualFps);
remote_sensors[sensor_id]->sw_sensor->set_metadata(RS2_FRAME_METADATA_FRAME_COUNTER, rtp_stream.get()->frame_data_buff.frame_number);
remote_sensors[sensor_id]->sw_sensor->set_metadata(RS2_FRAME_METADATA_FRAME_EMITTER_MODE, 1);

Expand Down
4 changes: 2 additions & 2 deletions src/ipDeviceCommon/MemoryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MemoryPool
std::unique_lock<std::mutex> lk(m_mutex);
for(int i = 0; i < POOL_SIZE; i++)
{
unsigned char* mem = new unsigned char[sizeof(RsFrameHeader) + MAX_FRAME_SIZE]; //TODO:to use OutPacketBuffer::maxSize;
unsigned char* mem = static_cast<unsigned char*>(aligned_alloc(16,MAX_MESSAGE_SIZE));
m_pool.push(mem);
}
lk.unlock();
Expand Down Expand Up @@ -80,7 +80,7 @@ class MemoryPool
m_pool.pop();
if(mem != nullptr)
{
delete mem;
free(mem);
}
else
{
Expand Down
29 changes: 19 additions & 10 deletions src/ipDeviceCommon/RsCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@

#pragma pack(push, 1)

struct RsNetworkHeader
{
uint32_t frameSize;
};
struct RsMetadataHeader
{
double timestamp;
long long frameCounter;
int actualFps;
rs2_timestamp_domain timestampDomain;
union RsNetworkHeader { //IMPORTANT:: RsNetworkHeader should be alligned to 16 bytes, this enables frame data to start on 16 bit alligned address
char maxHeaderSize[128];
struct
{
uint32_t frameSize;
} data;
};

union RsMetadataHeader { //IMPORTANT:: RsNetworkHeader should be alligned to 16 bytes, this enables frame data to start on 16 bit alligned address
char maxHeaderSize[128];
struct
{
double timestamp;
long long frameCounter;
int actualFps;
rs2_timestamp_domain timestampDomain;
} data;
};

struct RsFrameHeader
{
RsNetworkHeader networkHeader;
Expand All @@ -40,6 +48,7 @@ const int MAX_WIDTH = 1280;
const int MAX_HEIGHT = 720;
const int MAX_BPP = 3;
const int MAX_FRAME_SIZE = MAX_WIDTH * MAX_HEIGHT * MAX_BPP;
const int MAX_MESSAGE_SIZE = MAX_FRAME_SIZE + sizeof(RsFrameHeader);
const unsigned int SDP_MAX_LINE_LENGHT = 4000;
const unsigned int RTP_TIMESTAMP_FREQ = 90000;

Expand Down
5 changes: 4 additions & 1 deletion tools/rs-server/RsServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ struct server

void main(int argc, char** argv)
{
std::cout << "Rs-server is running\n";

START_EASYLOGGINGPP(argc, argv);

OutPacketBuffer::increaseMaxSizeTo(MAX_FRAME_SIZE);
OutPacketBuffer::increaseMaxSizeTo(MAX_MESSAGE_SIZE);

// Begin by setting up our usage environment:
scheduler = BasicTaskScheduler::createNew();
Expand Down Expand Up @@ -129,6 +131,7 @@ struct server
env = NULL;
delete scheduler;
scheduler = NULL;
std::cout << "Rs-server downloading\n";
}

// Make server a proper singleton
Expand Down
14 changes: 7 additions & 7 deletions tools/rs-server/RsSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,32 +101,32 @@ void RsDeviceSource::deliverRSFrame(rs2::frame* t_frame)
}
memmove(fTo + sizeof(RsFrameHeader), data, fFrameSize);
fFrameSize += sizeof(RsMetadataHeader);
header.networkHeader.frameSize = fFrameSize;
header.networkHeader.data.frameSize = fFrameSize;
fFrameSize += sizeof(RsNetworkHeader);
if(t_frame->supports_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP))
{
header.metadataHeader.timestamp = t_frame->get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP) / 1000;
header.metadataHeader.data.timestamp = t_frame->get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP) / 1000;
}
else
{
header.metadataHeader.timestamp = t_frame->get_timestamp();
header.metadataHeader.data.timestamp = t_frame->get_timestamp();
}

if(t_frame->supports_frame_metadata(RS2_FRAME_METADATA_FRAME_COUNTER))
{
header.metadataHeader.frameCounter = t_frame->get_frame_metadata(RS2_FRAME_METADATA_FRAME_COUNTER);
header.metadataHeader.data.frameCounter = t_frame->get_frame_metadata(RS2_FRAME_METADATA_FRAME_COUNTER);
}
else
{
header.metadataHeader.frameCounter = t_frame->get_frame_number();
header.metadataHeader.data.frameCounter = t_frame->get_frame_number();
}

if(t_frame->supports_frame_metadata(RS2_FRAME_METADATA_ACTUAL_FPS))
{
header.metadataHeader.actualFps = t_frame->get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_FPS);
header.metadataHeader.data.actualFps = t_frame->get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_FPS);
}

header.metadataHeader.timestampDomain = t_frame->get_frame_timestamp_domain();
header.metadataHeader.data.timestampDomain = t_frame->get_frame_timestamp_domain();

memmove(fTo, &header, sizeof(header));

Expand Down

0 comments on commit c1396e5

Please sign in to comment.