Statistics
| Branch: | Revision:

streamers / out-stream-dummy.c @ 421c2dc2

History | View | Annotate | Download (1.42 KB)

1 54b631d9 Luca Abeni
#include <unistd.h>
2
#include <stdint.h>
3
#include <stdio.h>
4
5
#include "out-stream.h"
6
#include "dbg.h"
7 421c2dc2 Luca Abeni
#include "payload.h"
8 54b631d9 Luca Abeni
9
static int outfd = 1;
10
11
void chunk_write(int id, const uint8_t *data, int size)
12
{
13 74ff12bb Luca Abeni
  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
14
  int width, height, frame_rate_n, frame_rate_d, frames;
15 e0f42ea7 Luca Abeni
  int i;
16
17
  if (data[0] != 1) {
18 74ff12bb Luca Abeni
    fprintf(stderr, "Error! Non video chunk: %x!!!\n", data[0]);
19 e0f42ea7 Luca Abeni
    return;
20
  }
21
  width = data[1] << 8 | data[2];
22
  height = data[3] << 8 | data[4];
23 74ff12bb Luca Abeni
  frame_rate_n = data[5] << 8 | data[6];
24
  frame_rate_d = data[7] << 8 | data[8];
25
  dprintf("Frame size: %dx%d -- Frame rate: %d / %d\n", width, height, frame_rate_n, frame_rate_d);
26
  frames = data[9];
27 e0f42ea7 Luca Abeni
  for (i = 0; i < frames; i++) {
28 b5e34f09 Luca Abeni
    int frame_size;
29
30
    frame_size = data[header_size + FRAME_HEADER_SIZE * i];
31
    frame_size = frame_size << 8;
32
    frame_size |= data[header_size + FRAME_HEADER_SIZE * i + 1];
33
    frame_size = frame_size << 8;
34
    frame_size |= data[header_size + FRAME_HEADER_SIZE * i + 2];
35
    dprintf("Frame %d has size %d\n", i, frame_size);
36 e0f42ea7 Luca Abeni
  }
37 60c05f2e Csaba Kiraly
#ifdef DEBUGOUT
38 54b631d9 Luca Abeni
#define buff_size 8 // HACK!
39 b5e34f09 Luca Abeni
  fprintf(stderr, "\tOut Chunk[%d] - %d: %s\n", id, id % buff_size, data + header_size + frames * FRAME_HEADER_SIZE);
40 54b631d9 Luca Abeni
#else
41 b5e34f09 Luca Abeni
  write(outfd, data + header_size + frames * FRAME_HEADER_SIZE, size - header_size - frames * FRAME_HEADER_SIZE);
42 54b631d9 Luca Abeni
#endif
43
}