Statistics
| Branch: | Revision:

grapes / src / Chunkiser / payload.h @ e41a6092

History | View | Annotate | Download (2.71 KB)

1
/*
2
 *  Copyright (c) 2010 Luca Abeni
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6

    
7
/* FIXME: The functions below should use int_coding */
8

    
9
#define AUDIO_PAYLOAD_HEADER_SIZE 1 + 1 + 2 + 2 + 1 // 1 Frame type + 1 channels 2 sample rate + 2 frame size + 1 number of frames
10
#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
11
#define FRAME_HEADER_SIZE (3 + 4 + 1)        // 3 Frame size + 4 PTS + 1 DeltaTS
12
#define UDP_CHUNK_HEADER_SIZE (2 + 1)   // 2 size + 1 stream
13

    
14
static inline void frame_header_parse(const uint8_t *data, int *size, int64_t *pts, int64_t *dts)
15
{
16
  int i;
17

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

    
35
static inline void audio_payload_header_parse(const uint8_t *data, uint8_t *codec, uint8_t *ch, int *sr, int *fs)
36
{
37
  *codec = data[0];
38
  *ch = data[1];
39
  *sr = data[2] << 8 | data[3];
40
  *fs = data[4] << 8 | data[5];
41
}
42

    
43
static inline void video_payload_header_parse(const uint8_t *data, uint8_t *codec, int *width, int *height, int *frame_rate_n, int *frame_rate_d)
44
{
45
  *codec = data[0];
46
  *width = data[1] << 8 | data[2];
47
  *height = data[3] << 8 | data[4];
48
  *frame_rate_n = data[5] << 8 | data[6];
49
  *frame_rate_d = data[7] << 8 | data[8];
50
}
51

    
52
static inline void audio_payload_header_write(uint8_t *data, uint8_t codec, unsigned int channels, unsigned int sample_rate, unsigned int frame_size)
53
{
54
  data[0] = codec;
55
  data[1] = channels;
56
  data[2] = sample_rate >> 8;
57
  data[3] = sample_rate & 0xFF;
58
  data[4] = frame_size >> 8;
59
  data[5] = frame_size & 0xFF;
60
}
61

    
62
static inline void video_payload_header_write(uint8_t *data, uint8_t codec, int width, int height, int num, int den)
63
{
64
  data[0] = codec;
65
  data[1] = width >> 8;
66
  data[2] = width & 0xFF;
67
  data[3] = height >> 8;
68
  data[4] = height & 0xFF;
69
  data[5] = num >> 8;
70
  data[6] = num & 0xFF;
71
  data[7] = den >> 8;
72
  data[8] = den & 0xFF;
73
}
74

    
75
static inline void frame_header_write(uint8_t *data, int size, int32_t pts, int32_t dts)
76
{
77
  data[0] = size >> 16;
78
  data[1] = size >> 8;
79
  data[2] = size & 0xFF;
80
  data[3] = dts >> 24;
81
  data[4] = dts >> 16;
82
  data[5] = dts >> 8;
83
  data[6] = dts & 0xFF;
84
  if (pts != -1) {
85
    data[7] = (pts - dts) & 0xFF;
86
  } else {
87
    data[7] = 255;
88
  }
89
}
90

    
91
static inline void udp_chunk_header_parse(uint8_t *data, int *size, int *stream)
92
{
93
  *size = data[0] << 8 | data[1];
94
  *stream = data[2]; 
95
}
96

    
97
static inline void udp_chunk_header_write(uint8_t *data, int size, uint8_t stream)
98
{
99
  data[0] = size >> 8;
100
  data[1] = size & 0xFF;
101
  data[2] = stream;
102
}