Statistics
| Branch: | Revision:

streamers / payload.h @ 69ae8acb

History | View | Annotate | Download (1.56 KB)

1
#define VIDEO_PAYLOAD_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
2
#define FRAME_HEADER_SIZE (3 + 4 + 1)        // 3 Frame size + 4 PTS + 1 DeltaTS
3

    
4
static inline void frame_header_parse(const uint8_t *data, int *size, int32_t *pts, int32_t *dts)
5
{
6
  int i;
7

    
8
  *size = 0;
9
  for (i = 0; i < 3; i++) {
10
    *size = *size << 8;
11
    *size |= data[i];
12
  }
13
  *dts = 0;
14
  for (i = 0; i < 4; i++) {
15
    *dts = *dts << 8;
16
    *dts |= data[3 + i];
17
  }
18
  if (data[7] != 255) {
19
    *pts = *dts + data[7];
20
  } else {
21
    *pts = -1;
22
  }
23
}
24

    
25
static inline void payload_header_parse(const uint8_t *data, uint8_t *codec, int *width, int *height, int *frame_rate_n, int *frame_rate_d)
26
{
27
  *codec = data[0];
28
  *width = data[1] << 8 | data[2];
29
  *height = data[3] << 8 | data[4];
30
  *frame_rate_n = data[5] << 8 | data[6];
31
  *frame_rate_d = data[7] << 8 | data[8];
32
}
33

    
34
static inline void payload_header_write(uint8_t *data, uint8_t codec, int width, int height, int num, int den)
35
{
36
  data[0] = codec;
37
  data[1] = width >> 8;
38
  data[2] = width & 0xFF;
39
  data[3] = height >> 8;
40
  data[4] = height & 0xFF;
41
  data[5] = num >> 8;
42
  data[6] = num & 0xFF;
43
  data[7] = den >> 8;
44
  data[8] = den & 0xFF;
45
}
46

    
47
static inline void frame_header_write(uint8_t *data, int size, int32_t pts, int32_t dts)
48
{
49
  data[0] = size >> 16;
50
  data[1] = size >> 8;
51
  data[2] = size & 0xFF;
52
  data[3] = dts >> 24;
53
  data[4] = dts >> 16;
54
  data[5] = dts >> 8;
55
  data[6] = dts & 0xFF;
56
  if (pts != -1) {
57
    data[7] = (pts - dts) & 0xFF;
58
  } else {
59
    data[7] = 255;
60
  }
61
}