}
}
-void add_current_frame(const uint8_t *start, const uint8_t *end)
-{
- if (current_video_frame.data == nullptr ||
- current_video_frame.len > current_video_frame.size) return;
- if (start == end) return;
-
- int bytes = end - start;
- if (current_video_frame.len + bytes > current_video_frame.size) {
- printf("%d bytes overflow after last video frame\n", current_video_frame.len + bytes - current_video_frame.size);
- //dump_frame();
- } else {
- memcpy(current_video_frame.data + current_video_frame.len, start, bytes);
- current_video_frame.len += bytes;
- }
-}
-
void start_new_frame(const uint8_t *start)
{
uint16_t format = (start[3] << 8) | start[2];
//}
}
-void add_current_audio(const uint8_t *start, const uint8_t *end)
-{
- if (current_audio_frame.data == nullptr ||
- current_audio_frame.len > current_audio_frame.size) return;
- if (start == end) return;
-
- int bytes = end - start;
- if (current_audio_frame.len + bytes > current_audio_frame.size) {
- printf("%d bytes overflow after last audio block\n", current_audio_frame.len + bytes - current_audio_frame.size);
- //dump_audio_block();
- } else {
- memcpy(current_audio_frame.data + current_audio_frame.len, start, bytes);
- current_audio_frame.len += bytes;
- }
-}
-
void start_new_audio_block(const uint8_t *start)
{
uint16_t format = (start[3] << 8) | start[2];
}
}
-void decode_packs(const libusb_transfer *xfr, const char *sync_pattern, int sync_length, function<void(const uint8_t *start, const uint8_t *end)> add_callback, function<void(const uint8_t *start)> start_callback)
+void add_to_frame(FrameAllocator::Frame *current_frame, const char *frame_type_name, const uint8_t *start, const uint8_t *end)
+{
+ if (current_frame->data == nullptr ||
+ current_frame->len > current_video_frame.size ||
+ start == end) {
+ return;
+ }
+
+ int bytes = end - start;
+ if (current_frame->len + bytes > current_frame->size) {
+ printf("%d bytes overflow after last %s frame\n", current_frame->len + bytes - current_frame->size, frame_type_name);
+ //dump_frame();
+ } else {
+ memcpy(current_frame->data + current_frame->len, start, bytes);
+ current_frame->len += bytes;
+ }
+}
+
+void decode_packs(const libusb_transfer *xfr,
+ const char *sync_pattern,
+ int sync_length,
+ FrameAllocator::Frame *current_frame,
+ const char *frame_type_name,
+ function<void(const uint8_t *start)> start_callback)
{
int offset = 0;
for (unsigned i = 0; i < xfr->num_iso_packets; i++) {
const unsigned char* start_next_frame = (const unsigned char *)memmem(iso_start + iso_offset, pack->actual_length - iso_offset, sync_pattern, sync_length);
if (start_next_frame == nullptr) {
// add the rest of the buffer
- add_callback(iso_start + iso_offset, iso_start + pack->actual_length);
+ const uint8_t *start = iso_start + iso_offset;
+ const uint8_t *end = iso_start + pack->actual_length;
+ add_to_frame(current_frame, frame_type_name, start, end);
break;
} else {
- add_callback(iso_start + iso_offset, start_next_frame);
+ const uint8_t *start = iso_start + iso_offset;
+ const uint8_t *end = start_next_frame;
+ add_to_frame(current_frame, frame_type_name, start, end);
start_callback(start_next_frame + sync_length);
int suboffset = start_next_frame - iso_start;
if (xfr->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
if (xfr->endpoint == 0x84) {
- decode_packs(xfr, "DeckLinkAudioResyncT", 20, add_current_audio, start_new_audio_block);
+ decode_packs(xfr, "DeckLinkAudioResyncT", 20, ¤t_audio_frame, "audio", start_new_audio_block);
} else {
- decode_packs(xfr, "\x00\x00\xff\xff", 4, add_current_frame, start_new_frame);
+ decode_packs(xfr, "\x00\x00\xff\xff", 4, ¤t_video_frame, "video", start_new_frame);
}
}
if (xfr->type == LIBUSB_TRANSFER_TYPE_CONTROL) {