streamers / out-stream.c @ 74ff12bb
History | View | Annotate | Download (1.1 KB)
1 |
#include <unistd.h> |
---|---|
2 |
#include <stdint.h> |
3 |
#include <stdio.h> |
4 |
|
5 |
#include "out-stream.h" |
6 |
#include "dbg.h" |
7 |
|
8 |
static int outfd = 1; |
9 |
|
10 |
void chunk_write(int id, const uint8_t *data, int size) |
11 |
{ |
12 |
const int header_size = 1 + 2 + 2 + 2 + 2 + 1; // 1 Frame type + 2 width + 2 height + 2 frame rate num + 2 frame rate den + 1 number of frames |
13 |
int width, height, frame_rate_n, frame_rate_d, frames;
|
14 |
int i;
|
15 |
|
16 |
if (data[0] != 1) { |
17 |
fprintf(stderr, "Error! Non video chunk: %x!!!\n", data[0]); |
18 |
return;
|
19 |
} |
20 |
width = data[1] << 8 | data[2]; |
21 |
height = data[3] << 8 | data[4]; |
22 |
frame_rate_n = data[5] << 8 | data[6]; |
23 |
frame_rate_d = data[7] << 8 | data[8]; |
24 |
dprintf("Frame size: %dx%d -- Frame rate: %d / %d\n", width, height, frame_rate_n, frame_rate_d);
|
25 |
frames = data[9];
|
26 |
for (i = 0; i < frames; i++) { |
27 |
dprintf("Frame %d has size %d\n", i, data[10 + 2 * i] << 8 | data[11 + 2 * i]); |
28 |
} |
29 |
#ifdef DEBUG
|
30 |
#define buff_size 8 // HACK! |
31 |
fprintf(stderr, "\tOut Chunk[%d] - %d: %s\n", id, id % buff_size, data + header_size + frames * 2); |
32 |
#else
|
33 |
write(outfd, data + header_size + frames * 2, size - header_size - frames * 2); |
34 |
#endif
|
35 |
} |