Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.4 KB)

1 1e8dedd8 Luca Abeni
/*
2
 *  Copyright (c) 2010 Luca Abeni
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6 e41a6092 Luca Abeni
7 52f45fc1 Luca Abeni
#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 1e8dedd8 Luca Abeni
#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 05c9dabb Luca Abeni
#define UDP_CHUNK_HEADER_SIZE (2 + 1)   // 2 size + 1 stream
11 1e8dedd8 Luca Abeni
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 0f79759c Luca Abeni
/* FIXME: Maybe this can use int_coding? */
18
19 1e8dedd8 Luca Abeni
  for (i = 0; i < 3; i++) {
20
    *size = *size << 8;
21
    *size |= data[i];
22
  }
23 0f79759c Luca Abeni
  *dts = int_rcpy(data + 3);
24 1e8dedd8 Luca Abeni
  if (data[7] != 255) {
25
    *pts = *dts + data[7];
26
  } else {
27
    *pts = -1;
28
  }
29
}
30
31 52f45fc1 Luca Abeni
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 0f79759c Luca Abeni
  *sr = sint_rcpy(data + 2);
36
  *fs = sint_rcpy(data + 4);
37 52f45fc1 Luca Abeni
}
38
39 09154f88 Luca Abeni
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 1e8dedd8 Luca Abeni
{
41
  *codec = data[0];
42 0f79759c Luca Abeni
  *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 1e8dedd8 Luca Abeni
}
47
48 52f45fc1 Luca Abeni
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 0f79759c Luca Abeni
  sint_cpy(data + 2, sample_rate);
53
  sint_cpy(data + 4, frame_size);
54 52f45fc1 Luca Abeni
}
55
56 09154f88 Luca Abeni
static inline void video_payload_header_write(uint8_t *data, uint8_t codec, int width, int height, int num, int den)
57 1e8dedd8 Luca Abeni
{
58
  data[0] = codec;
59 0f79759c Luca Abeni
  sint_cpy(data + 1, width);
60
  sint_cpy(data + 3, height);
61
  sint_cpy(data + 5, num);
62
  sint_cpy(data + 7, den);
63 1e8dedd8 Luca Abeni
}
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 0f79759c Luca Abeni
  int_cpy(data + 3, dts);
71 1e8dedd8 Luca Abeni
  if (pts != -1) {
72
    data[7] = (pts - dts) & 0xFF;
73
  } else {
74
    data[7] = 255;
75
  }
76
}
77 05c9dabb Luca Abeni
78 08c47845 Luca Abeni
static inline void udp_chunk_header_parse(uint8_t *data, int *size, int *stream)
79
{
80 0f79759c Luca Abeni
  *size = sint_rcpy(data);
81 08c47845 Luca Abeni
  *stream = data[2]; 
82
}
83
84 05c9dabb Luca Abeni
static inline void udp_chunk_header_write(uint8_t *data, int size, uint8_t stream)
85
{
86 0f79759c Luca Abeni
  sint_cpy(data, size);
87 5da67049 Luca Abeni
  data[2] = stream;
88 05c9dabb Luca Abeni
}