2 * Copyright 2011, Gabriel Hartmann, gabriel.hartmann@gmail.com.
3 * Distributed under the terms of the MIT License.
7 #include "UVCDeframer.h"
10 #include "CamDevice.h"
15 #define MAX_TAG_LEN CAMDEFRAMER_MAX_TAG_LEN
16 #define MAXFRAMEBUF CAMDEFRAMER_MAX_QUEUED_FRAMES
19 UVCDeframer::UVCDeframer(CamDevice
* device
)
20 : CamDeframer(device
),
27 UVCDeframer::~UVCDeframer()
33 UVCDeframer::Write(const void* buffer
, size_t size
)
35 const uint8
* buf
= (const uint8
*)buffer
;
36 int payloadSize
= size
- buf
[0]; // total length - header length
38 // This packet is just a header
45 if (fFrames
.CountItems() < MAXFRAMEBUF
)
46 fCurrentFrame
= AllocFrame();
48 printf("Dropped %ld bytes. Too many queued frames.)\n", size
);
53 // Write payload to buffer
54 fInputBuffer
.Write(&buf
[buf
[0]], payloadSize
);
56 // If end of frame add frame to list of frames
57 if ((buf
[1] & 2) || (buf
[1] & 1) != fID
) {
60 buf
= (uint8
*)fInputBuffer
.Buffer();
61 fCurrentFrame
->Write(buf
, fInputBuffer
.BufferLength());
62 fFrames
.AddItem(fCurrentFrame
);
63 release_sem(fFrameSem
);
72 UVCDeframer::_PrintBuffer(const void* buffer
, size_t size
)
74 uint8
* b
= (uint8
*)buffer
;
75 for (size_t i
= 0; i
< size
; i
++)
76 printf("0x%x\t", b
[i
]);