Statistics
| Branch: | Revision:

grapes / src / Chunkiser / payload.h @ 997c2b68

History | View | Annotate | Download (2.4 KB)

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

    
7
#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
8
#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
9
#define FRAME_HEADER_SIZE (3 + 4 + 1)        // 3 Frame size + 4 PTS + 1 DeltaTS
10
#define UDP_CHUNK_HEADER_SIZE (2 + 1)   // 2 size + 1 stream
11

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

    
16
  *size = 0;
17
/* FIXME: Maybe this can use int_coding? */
18

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

    
31
static inline void audio_payload_header_parse(const uint8_t *data, uint8_t *codec, uint8_t *ch, int *sr, int *fs)
32
{
33
  *codec = data[0];
34
  *ch = data[1];
35
  *sr = sint_rcpy(data + 2);
36
  *fs = sint_rcpy(data + 4);
37
}
38

    
39
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)
40
{
41
  *codec = data[0];
42
  *width = sint_rcpy(data + 1);
43
  *height = sint_rcpy(data + 3);
44
  *frame_rate_n = sint_rcpy(data + 5);
45
  *frame_rate_d = sint_rcpy(data + 7);
46
}
47

    
48
static inline void audio_payload_header_write(uint8_t *data, uint8_t codec, unsigned int channels, unsigned int sample_rate, unsigned int frame_size)
49
{
50
  data[0] = codec;
51
  data[1] = channels;
52
  sint_cpy(data + 2, sample_rate);
53
  sint_cpy(data + 4, frame_size);
54
}
55

    
56
static inline void video_payload_header_write(uint8_t *data, uint8_t codec, int width, int height, int num, int den)
57
{
58
  data[0] = codec;
59
  sint_cpy(data + 1, width);
60
  sint_cpy(data + 3, height);
61
  sint_cpy(data + 5, num);
62
  sint_cpy(data + 7, den);
63
}
64

    
65
static inline void frame_header_write(uint8_t *data, int size, int32_t pts, int32_t dts)
66
{
67
  data[0] = size >> 16;
68
  data[1] = size >> 8;
69
  data[2] = size & 0xFF;
70
  int_cpy(data + 3, dts);
71
  if (pts != -1) {
72
    data[7] = (pts - dts) & 0xFF;
73
  } else {
74
    data[7] = 255;
75
  }
76
}
77

    
78
static inline void udp_chunk_header_parse(uint8_t *data, int *size, int *stream)
79
{
80
  *size = sint_rcpy(data);
81
  *stream = data[2]; 
82
}
83

    
84
static inline void udp_chunk_header_write(uint8_t *data, int size, uint8_t stream)
85
{
86
  sint_cpy(data, size);
87
  data[2] = stream;
88
}