/src/vlc/modules/demux/mp4/avci.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * avci.h : AVC Intra SPS/PPS tables |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2015 VLC authors and VideoLAN |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify it |
7 | | * under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation; either version 2.1 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
19 | | *****************************************************************************/ |
20 | | #ifndef MP4_AVCI_H |
21 | | # define MP4_AVCI_H |
22 | | |
23 | | /* AVCi Tables derived from ffmpeg ff_generate_AVCi_extradata */ |
24 | | static const uint8_t AVCi_HIGH_422_1080p_sps[] = { |
25 | | 0x7a, 0x10, 0x29, 0xb6, 0xd4, 0x20, 0x22, 0x33, |
26 | | 0x19, 0xc6, 0x63, 0x23, 0x21, 0x01, 0x11, 0x98, |
27 | | 0xce, 0x33, 0x19, 0x18, 0x21, 0x02, 0x56, 0xb9, |
28 | | 0x3d, 0x7d, 0x7e, 0x4f, 0xe3, 0x3f, 0x11, 0xf1, |
29 | | 0x9e, 0x08, 0xb8, 0x8c, 0x54, 0x43, 0xc0, 0x78, |
30 | | 0x02, 0x27, 0xe2, 0x70, 0x1e, 0x30, 0x10, 0x10, |
31 | | 0x14, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, |
32 | | 0x03, 0x00, 0xca, 0x10 |
33 | | }; |
34 | | |
35 | | static const uint8_t AVCi_HIGH_422_1080i_sps[] = { |
36 | | 0x7a, 0x10, 0x29, 0xb6, 0xd4, 0x20, 0x22, 0x33, |
37 | | 0x19, 0xc6, 0x63, 0x23, 0x21, 0x01, 0x11, 0x98, |
38 | | 0xce, 0x33, 0x19, 0x18, 0x21, 0x03, 0x3a, 0x46, |
39 | | 0x65, 0x6a, 0x65, 0x24, 0xad, 0xe9, 0x12, 0x32, |
40 | | 0x14, 0x1a, 0x26, 0x34, 0xad, 0xa4, 0x41, 0x82, |
41 | | 0x23, 0x01, 0x50, 0x2b, 0x1a, 0x24, 0x69, 0x48, |
42 | | 0x30, 0x40, 0x2e, 0x11, 0x12, 0x08, 0xc6, 0x8c, |
43 | | 0x04, 0x41, 0x28, 0x4c, 0x34, 0xf0, 0x1e, 0x01, |
44 | | 0x13, 0xf2, 0xe0, 0x3c, 0x60, 0x20, 0x20, 0x28, |
45 | | 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x03, |
46 | | 0x01, 0x94, 0x20 |
47 | | }; |
48 | | |
49 | | static const uint8_t AVCi_HIGH_422_720p_sps[] = { |
50 | | 0x7a, 0x10, 0x29, 0xb6, 0xd4, 0x20, 0x2a, 0x33, |
51 | | 0x1d, 0xc7, 0x62, 0xa1, 0x08, 0x40, 0x54, 0x66, |
52 | | 0x3b, 0x8e, 0xc5, 0x42, 0x02, 0x10, 0x25, 0x64, |
53 | | 0x2c, 0x89, 0xe8, 0x85, 0xe4, 0x21, 0x4b, 0x90, |
54 | | 0x83, 0x06, 0x95, 0xd1, 0x06, 0x46, 0x97, 0x20, |
55 | | 0xc8, 0xd7, 0x43, 0x08, 0x11, 0xc2, 0x1e, 0x4c, |
56 | | 0x91, 0x0f, 0x01, 0x40, 0x16, 0xec, 0x07, 0x8c, |
57 | | 0x04, 0x04, 0x05, 0x00, 0x00, 0x03, 0x00, 0x01, |
58 | | 0x00, 0x00, 0x03, 0x00, 0x64, 0x84 |
59 | | }; |
60 | | |
61 | | static const uint8_t AVCi_HIGH_10_1080p_sps[] = { |
62 | | 0x6e, 0x10, 0x28, 0xa6, 0xd4, 0x20, 0x32, 0x33, |
63 | | 0x0c, 0x71, 0x18, 0x88, 0x62, 0x10, 0x19, 0x19, |
64 | | 0x86, 0x38, 0x8c, 0x44, 0x30, 0x21, 0x02, 0x56, |
65 | | 0x4e, 0x6f, 0x37, 0xcd, 0xf9, 0xbf, 0x81, 0x6b, |
66 | | 0xf3, 0x7c, 0xde, 0x6e, 0x6c, 0xd3, 0x3c, 0x05, |
67 | | 0xa0, 0x22, 0x7e, 0x5f, 0xfc, 0x00, 0x0c, 0x00, |
68 | | 0x13, 0x8c, 0x04, 0x04, 0x05, 0x00, 0x00, 0x03, |
69 | | 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x32, 0x84, |
70 | | }; |
71 | | |
72 | | static const uint8_t AVCi_HIGH_10_1080i_sps[] = { |
73 | | 0x6e, 0x10, 0x28, 0xa6, 0xd4, 0x20, 0x32, 0x33, |
74 | | 0x0c, 0x71, 0x18, 0x88, 0x62, 0x10, 0x19, 0x19, |
75 | | 0x86, 0x38, 0x8c, 0x44, 0x30, 0x21, 0x02, 0x56, |
76 | | 0x4e, 0x6e, 0x61, 0x87, 0x3e, 0x73, 0x4d, 0x98, |
77 | | 0x0c, 0x03, 0x06, 0x9c, 0x0b, 0x73, 0xe6, 0xc0, |
78 | | 0xb5, 0x18, 0x63, 0x0d, 0x39, 0xe0, 0x5b, 0x02, |
79 | | 0xd4, 0xc6, 0x19, 0x1a, 0x79, 0x8c, 0x32, 0x34, |
80 | | 0x24, 0xf0, 0x16, 0x81, 0x13, 0xf7, 0xff, 0x80, |
81 | | 0x02, 0x00, 0x01, 0xf1, 0x80, 0x80, 0x80, 0xa0, |
82 | | 0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x06, |
83 | | 0x50, 0x80 |
84 | | }; |
85 | | |
86 | | static const uint8_t AVCi_HIGH_10_720p_sps[] = { |
87 | | 0x6e, 0x10, 0x20, 0xa6, 0xd4, 0x20, 0x32, 0x33, |
88 | | 0x0c, 0x71, 0x18, 0x88, 0x62, 0x10, 0x19, 0x19, |
89 | | 0x86, 0x38, 0x8c, 0x44, 0x30, 0x21, 0x02, 0x56, |
90 | | 0x4e, 0x6f, 0x37, 0xcd, 0xf9, 0xbf, 0x81, 0x6b, |
91 | | 0xf3, 0x7c, 0xde, 0x6e, 0x6c, 0xd3, 0x3c, 0x0f, |
92 | | 0x01, 0x6e, 0xff, 0xc0, 0x00, 0xc0, 0x01, 0x38, |
93 | | 0xc0, 0x40, 0x40, 0x50, 0x00, 0x00, 0x03, 0x00, |
94 | | 0x10, 0x00, 0x00, 0x06, 0x48, 0x40 |
95 | | }; |
96 | | |
97 | | static const uint8_t AVCi_HIGH_422_1080x_pps[] = { |
98 | | 0xce, 0x33, 0x48, 0xd0 |
99 | | }; |
100 | | |
101 | | static const uint8_t AVCi_HIGH_422_720p_pps[] = { |
102 | | 0xce, 0x31, 0x12, 0x11 |
103 | | }; |
104 | | |
105 | | static const uint8_t AVCi_HIGH_10_pps[] = { |
106 | | 0xee, 0x31, 0x12, 0x11 |
107 | | }; |
108 | | |
109 | | |
110 | | #define AVCI_ENTRY(a,b, A, B) {b, A, B, sizeof(A), sizeof(B), a} |
111 | 0 | #define AVCI_ENTRIES 6 |
112 | | |
113 | | static const struct |
114 | | { |
115 | | bool b_interlace; |
116 | | const uint8_t *p_sps; |
117 | | const uint8_t *p_pps; |
118 | | uint8_t i_sps; |
119 | | uint8_t i_pps; |
120 | | uint16_t i_res; |
121 | | } AVCi_lookup_table[AVCI_ENTRIES] = { |
122 | | AVCI_ENTRY(1920, true, AVCi_HIGH_422_1080i_sps, AVCi_HIGH_422_1080x_pps), |
123 | | AVCI_ENTRY(1920, false, AVCi_HIGH_422_1080p_sps, AVCi_HIGH_422_1080x_pps), |
124 | | AVCI_ENTRY(1280, false, AVCi_HIGH_422_720p_sps, AVCi_HIGH_422_720p_pps), |
125 | | AVCI_ENTRY(1440, true, AVCi_HIGH_10_1080i_sps, AVCi_HIGH_10_pps), |
126 | | AVCI_ENTRY(1440, false, AVCi_HIGH_10_1080p_sps, AVCi_HIGH_10_pps), |
127 | | AVCI_ENTRY(960, false, AVCi_HIGH_10_720p_sps, AVCi_HIGH_10_pps), |
128 | | }; |
129 | | |
130 | | static inline bool AVCi_lookup(uint16_t i_res, bool b_i, |
131 | | const uint8_t **pp_sps, uint8_t *pi_sps, |
132 | | const uint8_t **pp_pps, uint8_t *pi_pps) |
133 | 0 | { |
134 | 0 | for(int i=0; i<AVCI_ENTRIES; i++) |
135 | 0 | { |
136 | 0 | if(AVCi_lookup_table[i].b_interlace == b_i && AVCi_lookup_table[i].i_res == i_res) |
137 | 0 | { |
138 | 0 | *pp_sps = AVCi_lookup_table[i].p_sps; |
139 | 0 | *pi_sps = AVCi_lookup_table[i].i_sps; |
140 | 0 | *pp_pps = AVCi_lookup_table[i].p_pps; |
141 | 0 | *pi_pps = AVCi_lookup_table[i].i_pps; |
142 | 0 | return true; |
143 | 0 | } |
144 | 0 | } |
145 | 0 | return false; |
146 | 0 | } |
147 | | |
148 | | #undef AVCI_ENTRY |
149 | | #undef AVCI_ENTRIES |
150 | | |
151 | | #if 0 |
152 | | static uint8_t * AVCi_create_avcC( uint16_t i_res, bool b_interlaced, int *pi_avcC ) |
153 | | { |
154 | | const uint8_t *p_pps, *p_sps; |
155 | | uint8_t i_sps, i_pps; |
156 | | uint8_t *p_data = NULL; |
157 | | if( AVCi_lookup( i_res, b_interlaced, |
158 | | &p_sps, &i_sps, &p_pps, &i_pps ) ) |
159 | | { |
160 | | int i_size = 5 + i_pps + i_sps + 2 + 2 * 3; |
161 | | if( (p_data = (uint8_t *) malloc(i_size)) ) |
162 | | { |
163 | | *pi_avcC = i_size; |
164 | | /* Merge everything into avc decoder config record s4,1s,1p */ |
165 | | p_data[0] = 0x01; |
166 | | memcpy(&p_data[1], p_sps, 3); |
167 | | p_data[4] = 0xff; |
168 | | p_data[5] = 0xe1; /* 1 sps */ |
169 | | p_data[6] = 0x00; p_data[7] = i_sps + 1; /* sps NAL size */ |
170 | | p_data[8] = 0x67; /* SPS_NAL Header */ |
171 | | memcpy(&p_data[9], p_sps, i_sps); |
172 | | p_data[9 + i_sps] = 0x01; /* 1 sps */ |
173 | | p_data[10 + i_sps] = 0x00; p_data[11 + i_sps] = i_pps + 1; /* pps NAL size */ |
174 | | p_data[12 + i_sps] = 0x68; /* PPS_NAL Header */ |
175 | | memcpy(&p_data[13 + i_sps], p_pps, i_pps); |
176 | | } |
177 | | } |
178 | | return p_data; |
179 | | } |
180 | | #endif |
181 | | |
182 | | static uint8_t * AVCi_create_AnnexB( uint16_t i_res, bool b_interlaced, int *pi_avcC ) |
183 | 0 | { |
184 | 0 | const uint8_t *p_pps, *p_sps; |
185 | 0 | uint8_t i_sps, i_pps; |
186 | 0 | uint8_t *p_data = NULL; |
187 | 0 | const uint8_t rgi_startcode[] = {0,0,0,1}; |
188 | 0 | if( AVCi_lookup( i_res, b_interlaced, |
189 | 0 | &p_sps, &i_sps, &p_pps, &i_pps ) ) |
190 | 0 | { |
191 | 0 | int i_size = i_pps + i_sps + 2 * 5; |
192 | 0 | if( (p_data = (uint8_t *) malloc(i_size)) ) |
193 | 0 | { |
194 | 0 | *pi_avcC = i_size; |
195 | 0 | memcpy(p_data, rgi_startcode, 4); |
196 | 0 | p_data[4] = 0x67; /* SPS_NAL Header */ |
197 | 0 | memcpy(&p_data[5], p_sps, i_sps); |
198 | 0 | memcpy(&p_data[5 + i_sps], rgi_startcode, 4); |
199 | 0 | p_data[9 + i_sps] = 0x68; /* PPS_NAL Header */ |
200 | 0 | memcpy(&p_data[10 + i_sps], p_pps, i_pps); |
201 | 0 | } |
202 | 0 | } |
203 | 0 | return p_data; |
204 | 0 | } |
205 | | |
206 | | #endif |