Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.42 KB)

1
#include <unistd.h>
2
#include <stdint.h>
3
#include <stdio.h>
4

    
5
#include "out-stream.h"
6
#include "dbg.h"
7
#include "payload.h"
8

    
9
static int outfd = 1;
10

    
11
void chunk_write(int id, const uint8_t *data, int size)
12
{
13
  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
  int i;
16

    
17
  if (data[0] != 1) {
18
    fprintf(stderr, "Error! Non video chunk: %x!!!\n", data[0]);
19
    return;
20
  }
21
  width = data[1] << 8 | data[2];
22
  height = data[3] << 8 | data[4];
23
  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
  for (i = 0; i < frames; i++) {
28
    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
  }
37
#ifdef DEBUGOUT
38
#define buff_size 8 // HACK!
39
  fprintf(stderr, "\tOut Chunk[%d] - %d: %s\n", id, id % buff_size, data + header_size + frames * FRAME_HEADER_SIZE);
40
#else
41
  write(outfd, data + header_size + frames * FRAME_HEADER_SIZE, size - header_size - frames * FRAME_HEADER_SIZE);
42
#endif
43
}