-
Notifications
You must be signed in to change notification settings - Fork 769
Rgb packet handling #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0323c13
to
95f197e
Compare
95f197e
to
c089f28
Compare
c089f28
to
4499dac
Compare
4499dac
to
a52ded2
Compare
@@ -36,11 +37,26 @@ namespace libfreenect2 | |||
LIBFREENECT2_PACK(struct RawRgbPacket | |||
{ | |||
uint32_t sequence; | |||
uint32_t unknown0; | |||
uint32_t magicHeader; // is 'BBBB' equal 0x42424242 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to magic_header
a52ded2
to
d4c1c84
Compare
First, can you please squash these into a single commit? The second one is cosmetic. As a matter of fact, a custom hardware accelerated JPEG decoder I'm testing cannot handle garbage after JPEG. So this extra check is actually required for compatibility. My experiments show your // starting from JPEG EOI: 0xff 0xd9
// char _pad_0xa5[]; //0-3 bytes alignment of 0xa5
// char _filler[_filler_length] = "ZZZZ...";
LIBFREENECT2_PACK(struct RgbPacketFooter {
uint32_t magic_header; // is '9999' equal 0x39393939
uint32_t sequence;
int32_t unknown1; // _filler_length
[...] Also, I wrote and tested some code to find out the exact size of the JPEG image by searching for its EOI. For your reference. Following the new specifications the code will finish in finite steps and if EOI is not found, returning failure is justified. In my testing it always worked. |
// if magic markers match | ||
if (length - i >= sizeof(RgbPacketFooter) && footer->magic_header == 0x39393939 && footer->magic_footer == 0x42424242) | ||
{ | ||
memcpy(&fb.data[fb.length], buffer, length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This copies all remaining data to the fb. I guess it would be more correct to just copy i+sizeof(footer) and copy any remaining data to the new fb after the swap?
@christiankerl Yes. Here is my take (edit: updated commit) to compute the exact value of jpeg_buffer_length using filler_length. Several changes:
|
|
d4c1c84
to
340b219
Compare
Nice suggestions for improvements @xlz. I have tried to incorporate most of them - Still lacking to calculate the exact jpeg buffer size with the 0-3 padding bytes, but I'll try look at it tomorrow. I have removed the for loop, but this requires the assumption that there will be no concatenated images in the USB transfers - which I'm not qualified to determine if it can or will happen? If it does, we will just hit bufferoverflow and reset buffers. Over 1000 runs in the onDataReceived method, I tried with and without a for loop and I measured difference from 160 ms to 1.6 ms in processing time - so indeed it is more costly, but difference compared to the overall processing is minimal. |
In fact you can totally detect the magic bytes in the middle of an image. There is no guarantee these 8 bytes won't appear. If our assumption does not hold, report of buffer overflows will immediately show up. (It is similar for depth processing which is also doing scanning currently. I'll put on my patch shortly.) On the side of performance, on ARM platform the CPU is significantly weaker for these kind of memory scanning. |
10a38c1
to
c61c0e8
Compare
inspecting to find magic markers. copy data in chunks. Verify by packetlength and sequence of footer and header.
…ed without the next image in same USB buffer. Better calculation of jpeg buffer size (still missing the 0-3 padding bytes(0xa5)
c61c0e8
to
a9c139c
Compare
Closing in favor of #221 . |
A try at getting a better rgb packet handling with inspiration from hovren's pull request: #72
Its still a work in progress, but I wouldn't mind any feedback on the way 👍