MCPcopy Create free account
hub / github.com/OpenKinect/libfreenect2 / onDataReceived

Method onDataReceived

src/depth_packet_stream_parser.cpp:64–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64void DepthPacketStreamParser::onDataReceived(unsigned char* buffer, size_t in_length)
65{
66 if (packet_.memory == NULL || packet_.memory->data == NULL)
67 {
68 LOG_ERROR << "Packet buffer is NULL";
69 return;
70 }
71 Buffer &wb = work_buffer_;
72
73 if(in_length == 0)
74 {
75 //synchronize to subpacket boundary
76 wb.length = 0;
77 }
78 else
79 {
80 DepthSubPacketFooter *footer = 0;
81 bool footer_found = false;
82
83 if(wb.length + in_length == wb.capacity + sizeof(DepthSubPacketFooter))
84 {
85 in_length -= sizeof(DepthSubPacketFooter);
86 footer = reinterpret_cast<DepthSubPacketFooter *>(&buffer[in_length]);
87 footer_found = true;
88 }
89
90 if(wb.length + in_length > wb.capacity)
91 {
92 LOG_DEBUG << "subpacket too large";
93 wb.length = 0;
94 return;
95 }
96
97 memcpy(wb.data + wb.length, buffer, in_length);
98 wb.length += in_length;
99
100 if(footer_found)
101 {
102 if(footer->length != wb.length)
103 {
104 LOG_DEBUG << "image data too short!";
105 }
106 else
107 {
108 if(current_sequence_ != footer->sequence)
109 {
110 if(current_subsequence_ == 0x3ff)
111 {
112 if(processor_->ready())
113 {
114 DepthPacket &packet = packet_;
115 packet.sequence = current_sequence_;
116 packet.timestamp = footer->timestamp;
117 packet.buffer = packet_.memory->data;
118 packet.buffer_length = packet_.memory->capacity;
119
120 processor_->process(packet);
121 processor_->allocateBuffer(packet_, buffer_size_);

Callers

nothing calls this directly

Calls 3

readyMethod · 0.45
processMethod · 0.45
allocateBufferMethod · 0.45

Tested by

no test coverage detected