Statistics
| Branch: | Revision:

streamers / payload.h @ 7f591208

History | View | Annotate | Download (1.64 KB)

1
/*
2
 *  Copyright (c) 2010 Luca Abeni
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6
#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
7
#define FRAME_HEADER_SIZE (3 + 4 + 1)        // 3 Frame size + 4 PTS + 1 DeltaTS
8

    
9
static inline void frame_header_parse(const uint8_t *data, int *size, int64_t *pts, int64_t *dts)
10
{
11
  int i;
12

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

    
30
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)
31
{
32
  *codec = data[0];
33
  *width = data[1] << 8 | data[2];
34
  *height = data[3] << 8 | data[4];
35
  *frame_rate_n = data[5] << 8 | data[6];
36
  *frame_rate_d = data[7] << 8 | data[8];
37
}
38

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

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