/src/vlc/modules/demux/rawdv.h
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * rawdv.h : raw DV helpers |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2001-2011 VLC authors and VideoLAN |
5 | | * |
6 | | * Authors: Gildas Bazin <gbazin@netcourrier.com> |
7 | | * Paul Corke <paul dot corke at datatote dot co dot uk> |
8 | | * |
9 | | * This program is free software; you can redistribute it and/or modify it |
10 | | * under the terms of the GNU Lesser General Public License as published by |
11 | | * the Free Software Foundation; either version 2.1 of the License, or |
12 | | * (at your option) any later version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | * GNU Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with this program; if not, write to the Free Software Foundation, |
21 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
22 | | *****************************************************************************/ |
23 | | |
24 | 12 | #define DV_PAL_FRAME_SIZE (12 * 150 * 80) |
25 | 232 | #define DV_NTSC_FRAME_SIZE (10 * 150 * 80) |
26 | | |
27 | | |
28 | | static const uint16_t dv_audio_shuffle525[10][9] = { |
29 | | { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */ |
30 | | { 6, 36, 66, 26, 56, 86, 16, 46, 76 }, |
31 | | { 12, 42, 72, 2, 32, 62, 22, 52, 82 }, |
32 | | { 18, 48, 78, 8, 38, 68, 28, 58, 88 }, |
33 | | { 24, 54, 84, 14, 44, 74, 4, 34, 64 }, |
34 | | |
35 | | { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */ |
36 | | { 7, 37, 67, 27, 57, 87, 17, 47, 77 }, |
37 | | { 13, 43, 73, 3, 33, 63, 23, 53, 83 }, |
38 | | { 19, 49, 79, 9, 39, 69, 29, 59, 89 }, |
39 | | { 25, 55, 85, 15, 45, 75, 5, 35, 65 }, |
40 | | }; |
41 | | |
42 | | static const uint16_t dv_audio_shuffle625[12][9] = { |
43 | | { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */ |
44 | | { 6, 42, 78, 32, 68, 104, 22, 58, 94}, |
45 | | { 12, 48, 84, 2, 38, 74, 28, 64, 100}, |
46 | | { 18, 54, 90, 8, 44, 80, 34, 70, 106}, |
47 | | { 24, 60, 96, 14, 50, 86, 4, 40, 76}, |
48 | | { 30, 66, 102, 20, 56, 92, 10, 46, 82}, |
49 | | |
50 | | { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */ |
51 | | { 7, 43, 79, 33, 69, 105, 23, 59, 95}, |
52 | | { 13, 49, 85, 3, 39, 75, 29, 65, 101}, |
53 | | { 19, 55, 91, 9, 45, 81, 35, 71, 107}, |
54 | | { 25, 61, 97, 15, 51, 87, 5, 41, 77}, |
55 | | { 31, 67, 103, 21, 57, 93, 11, 47, 83}, |
56 | | }; |
57 | | |
58 | | static inline uint16_t dv_audio_12to16( uint16_t sample ) |
59 | 204k | { |
60 | 204k | uint16_t shift, result; |
61 | | |
62 | 204k | sample = (sample < 0x800) ? sample : sample | 0xf000; |
63 | 204k | shift = (sample & 0xf00) >> 8; |
64 | | |
65 | 204k | if (shift < 0x2 || shift > 0xd) { |
66 | 108k | result = sample; |
67 | 108k | } else if (shift < 0x8) { |
68 | 55.1k | shift--; |
69 | 55.1k | result = (sample - (256 * shift)) << shift; |
70 | 55.1k | } else { |
71 | 41.3k | shift = 0xe - shift; |
72 | 41.3k | result = ((sample + ((256 * shift) + 1)) << shift) - 1; |
73 | 41.3k | } |
74 | | |
75 | 204k | return result; |
76 | 204k | } Line | Count | Source | 59 | 204k | { | 60 | 204k | uint16_t shift, result; | 61 | | | 62 | 204k | sample = (sample < 0x800) ? sample : sample | 0xf000; | 63 | 204k | shift = (sample & 0xf00) >> 8; | 64 | | | 65 | 204k | if (shift < 0x2 || shift > 0xd) { | 66 | 108k | result = sample; | 67 | 108k | } else if (shift < 0x8) { | 68 | 55.1k | shift--; | 69 | 55.1k | result = (sample - (256 * shift)) << shift; | 70 | 55.1k | } else { | 71 | 41.3k | shift = 0xe - shift; | 72 | 41.3k | result = ((sample + ((256 * shift) + 1)) << shift) - 1; | 73 | 41.3k | } | 74 | | | 75 | 204k | return result; | 76 | 204k | } |
Unexecuted instantiation: uleaddvaudio.c:dv_audio_12to16 |
77 | | |
78 | | static inline void dv_get_audio_format( es_format_t *p_fmt, |
79 | | const uint8_t *p_aaux_src ) |
80 | 244 | { |
81 | | /* 12 bits non-linear will be converted to 16 bits linear */ |
82 | 244 | es_format_Init( p_fmt, AUDIO_ES, VLC_CODEC_S16L ); |
83 | | |
84 | 244 | p_fmt->audio.i_bitspersample = 16; |
85 | 244 | p_fmt->audio.i_channels = 2; |
86 | 244 | switch( (p_aaux_src[4-1] >> 3) & 0x07 ) |
87 | 244 | { |
88 | 52 | case 0: |
89 | 52 | p_fmt->audio.i_rate = 48000; |
90 | 52 | break; |
91 | 53 | case 1: |
92 | 53 | p_fmt->audio.i_rate = 44100; |
93 | 53 | break; |
94 | 5 | case 2: |
95 | 139 | default: |
96 | 139 | p_fmt->audio.i_rate = 32000; |
97 | 139 | break; |
98 | 244 | } |
99 | 244 | } avi.c:dv_get_audio_format Line | Count | Source | 80 | 244 | { | 81 | | /* 12 bits non-linear will be converted to 16 bits linear */ | 82 | 244 | es_format_Init( p_fmt, AUDIO_ES, VLC_CODEC_S16L ); | 83 | | | 84 | 244 | p_fmt->audio.i_bitspersample = 16; | 85 | 244 | p_fmt->audio.i_channels = 2; | 86 | 244 | switch( (p_aaux_src[4-1] >> 3) & 0x07 ) | 87 | 244 | { | 88 | 52 | case 0: | 89 | 52 | p_fmt->audio.i_rate = 48000; | 90 | 52 | break; | 91 | 53 | case 1: | 92 | 53 | p_fmt->audio.i_rate = 44100; | 93 | 53 | break; | 94 | 5 | case 2: | 95 | 139 | default: | 96 | 139 | p_fmt->audio.i_rate = 32000; | 97 | 139 | break; | 98 | 244 | } | 99 | 244 | } |
Unexecuted instantiation: uleaddvaudio.c:dv_get_audio_format |
100 | | |
101 | | static inline int dv_get_audio_sample_count( const uint8_t *p_buffer, int i_dsf ) |
102 | 83.3k | { |
103 | 83.3k | int i_samples = p_buffer[0] & 0x3f; /* samples in this frame - min samples */ |
104 | 83.3k | switch( (p_buffer[3] >> 3) & 0x07 ) |
105 | 83.3k | { |
106 | 63.5k | case 0: |
107 | 63.5k | return i_samples + (i_dsf ? 1896 : 1580); |
108 | 8.75k | case 1: |
109 | 8.75k | return i_samples + (i_dsf ? 1742 : 1452); |
110 | 218 | case 2: |
111 | 11.0k | default: |
112 | 11.0k | return i_samples + (i_dsf ? 1264 : 1053); |
113 | 83.3k | } |
114 | 83.3k | } avi.c:dv_get_audio_sample_count Line | Count | Source | 102 | 146 | { | 103 | 146 | int i_samples = p_buffer[0] & 0x3f; /* samples in this frame - min samples */ | 104 | 146 | switch( (p_buffer[3] >> 3) & 0x07 ) | 105 | 146 | { | 106 | 31 | case 0: | 107 | 31 | return i_samples + (i_dsf ? 1896 : 1580); | 108 | 40 | case 1: | 109 | 40 | return i_samples + (i_dsf ? 1742 : 1452); | 110 | 2 | case 2: | 111 | 75 | default: | 112 | 75 | return i_samples + (i_dsf ? 1264 : 1053); | 113 | 146 | } | 114 | 146 | } |
uleaddvaudio.c:dv_get_audio_sample_count Line | Count | Source | 102 | 83.2k | { | 103 | 83.2k | int i_samples = p_buffer[0] & 0x3f; /* samples in this frame - min samples */ | 104 | 83.2k | switch( (p_buffer[3] >> 3) & 0x07 ) | 105 | 83.2k | { | 106 | 63.4k | case 0: | 107 | 63.4k | return i_samples + (i_dsf ? 1896 : 1580); | 108 | 8.71k | case 1: | 109 | 8.71k | return i_samples + (i_dsf ? 1742 : 1452); | 110 | 216 | case 2: | 111 | 11.0k | default: | 112 | 11.0k | return i_samples + (i_dsf ? 1264 : 1053); | 113 | 83.2k | } | 114 | 83.2k | } |
|
115 | | |
116 | | static inline block_t *dv_extract_audio( block_t *p_frame_block ) |
117 | 244 | { |
118 | 244 | block_t *p_block; |
119 | 244 | uint8_t *p_frame, *p_buf; |
120 | 244 | int i_audio_quant, i_samples, i_half_ch; |
121 | 244 | const uint16_t (*audio_shuffle)[9]; |
122 | 244 | int i, j, d, of; |
123 | | |
124 | 244 | if( p_frame_block->i_buffer < 4 ) |
125 | 0 | return NULL; |
126 | 244 | const int i_dsf = (p_frame_block->p_buffer[3] & 0x80) >> 7; |
127 | 244 | if( p_frame_block->i_buffer < (i_dsf ? DV_PAL_FRAME_SIZE |
128 | 244 | : DV_NTSC_FRAME_SIZE ) ) |
129 | 79 | return NULL; |
130 | | |
131 | | /* Beginning of AAUX pack */ |
132 | 165 | p_buf = p_frame_block->p_buffer + 80*6+80*16*3 + 3; |
133 | 165 | if( *p_buf != 0x50 ) return NULL; |
134 | | |
135 | 165 | i_audio_quant = p_buf[4] & 0x07; /* 0 - 16bit, 1 - 12bit */ |
136 | 165 | if( i_audio_quant > 1 ) |
137 | 19 | return NULL; |
138 | | |
139 | 146 | i_samples = dv_get_audio_sample_count( &p_buf[1], i_dsf ); |
140 | | |
141 | 146 | p_block = block_Alloc( 4 * i_samples ); |
142 | 146 | if( unlikely( p_block == NULL ) ) |
143 | 0 | return NULL; |
144 | | |
145 | | /* for each DIF segment */ |
146 | 146 | p_frame = p_frame_block->p_buffer; |
147 | 146 | audio_shuffle = i_dsf ? dv_audio_shuffle625 : dv_audio_shuffle525; |
148 | 146 | i_half_ch = (i_dsf ? 12 : 10)/2; |
149 | 1.13k | for( i = 0; i < (i_dsf ? 12 : 10); i++ ) |
150 | 1.08k | { |
151 | 1.08k | p_frame += 6 * 80; /* skip DIF segment header */ |
152 | | |
153 | 1.08k | if( i_audio_quant == 1 && i == i_half_ch ) break; |
154 | | |
155 | 9.88k | for( j = 0; j < 9; j++ ) |
156 | 8.89k | { |
157 | 277k | for( d = 8; d < 80; d += 2 ) |
158 | 268k | { |
159 | 268k | if( i_audio_quant == 0 ) |
160 | 165k | { |
161 | | /* 16bit quantization */ |
162 | 165k | of = audio_shuffle[i][j] + (d - 8) / 2 * |
163 | 165k | (i_dsf ? 108 : 90); |
164 | | |
165 | 165k | if( of * 2 >= 4 * i_samples ) continue; |
166 | | |
167 | | /* big endian */ |
168 | 158k | p_block->p_buffer[of*2] = p_frame[d+1]; |
169 | 158k | p_block->p_buffer[of*2+1] = p_frame[d]; |
170 | | |
171 | 158k | if( p_block->p_buffer[of*2+1] == 0x80 && |
172 | 1.86k | p_block->p_buffer[of*2] == 0x00 ) |
173 | 285 | p_block->p_buffer[of*2+1] = 0; |
174 | 158k | } |
175 | 102k | else |
176 | 102k | { |
177 | | /* 12bit quantization */ |
178 | 102k | uint16_t lc = (p_frame[d+0] << 4) | (p_frame[d+2] >> 4); |
179 | 102k | uint16_t rc = (p_frame[d+1] << 4) | (p_frame[d+2] & 0x0f); |
180 | | |
181 | 102k | lc = lc == 0x800 ? 0 : dv_audio_12to16(lc); |
182 | 102k | rc = rc == 0x800 ? 0 : dv_audio_12to16(rc); |
183 | | |
184 | 102k | of = audio_shuffle[i][j] + (d - 8) / 3 * (i_dsf ? 108 : 90); |
185 | 102k | if( of*2 >= 4 * i_samples ) |
186 | 58 | continue; |
187 | 102k | p_block->p_buffer[of*2+0] = lc & 0xff; |
188 | 102k | p_block->p_buffer[of*2+1] = lc >> 8; |
189 | | |
190 | 102k | of = audio_shuffle[i + i_half_ch][j] + (d - 8) / 3 * (i_dsf ? 108 : 90); |
191 | 102k | if( of*2 >= 4 * i_samples ) |
192 | 0 | continue; |
193 | 102k | p_block->p_buffer[of*2+0] = rc & 0xff; |
194 | 102k | p_block->p_buffer[of*2+1] = rc >> 8; |
195 | | |
196 | 102k | ++d; |
197 | 102k | } |
198 | 268k | } |
199 | | |
200 | 8.89k | p_frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ |
201 | 8.89k | } |
202 | 988 | } |
203 | | |
204 | 146 | p_block->i_pts = p_frame_block->i_pts != VLC_TICK_INVALID ? p_frame_block->i_pts |
205 | 146 | : p_frame_block->i_dts; |
206 | 146 | p_block->i_dts = p_frame_block->i_dts; |
207 | 146 | return p_block; |
208 | 146 | } Line | Count | Source | 117 | 244 | { | 118 | 244 | block_t *p_block; | 119 | 244 | uint8_t *p_frame, *p_buf; | 120 | 244 | int i_audio_quant, i_samples, i_half_ch; | 121 | 244 | const uint16_t (*audio_shuffle)[9]; | 122 | 244 | int i, j, d, of; | 123 | | | 124 | 244 | if( p_frame_block->i_buffer < 4 ) | 125 | 0 | return NULL; | 126 | 244 | const int i_dsf = (p_frame_block->p_buffer[3] & 0x80) >> 7; | 127 | 244 | if( p_frame_block->i_buffer < (i_dsf ? DV_PAL_FRAME_SIZE | 128 | 244 | : DV_NTSC_FRAME_SIZE ) ) | 129 | 79 | return NULL; | 130 | | | 131 | | /* Beginning of AAUX pack */ | 132 | 165 | p_buf = p_frame_block->p_buffer + 80*6+80*16*3 + 3; | 133 | 165 | if( *p_buf != 0x50 ) return NULL; | 134 | | | 135 | 165 | i_audio_quant = p_buf[4] & 0x07; /* 0 - 16bit, 1 - 12bit */ | 136 | 165 | if( i_audio_quant > 1 ) | 137 | 19 | return NULL; | 138 | | | 139 | 146 | i_samples = dv_get_audio_sample_count( &p_buf[1], i_dsf ); | 140 | | | 141 | 146 | p_block = block_Alloc( 4 * i_samples ); | 142 | 146 | if( unlikely( p_block == NULL ) ) | 143 | 0 | return NULL; | 144 | | | 145 | | /* for each DIF segment */ | 146 | 146 | p_frame = p_frame_block->p_buffer; | 147 | 146 | audio_shuffle = i_dsf ? dv_audio_shuffle625 : dv_audio_shuffle525; | 148 | 146 | i_half_ch = (i_dsf ? 12 : 10)/2; | 149 | 1.13k | for( i = 0; i < (i_dsf ? 12 : 10); i++ ) | 150 | 1.08k | { | 151 | 1.08k | p_frame += 6 * 80; /* skip DIF segment header */ | 152 | | | 153 | 1.08k | if( i_audio_quant == 1 && i == i_half_ch ) break; | 154 | | | 155 | 9.88k | for( j = 0; j < 9; j++ ) | 156 | 8.89k | { | 157 | 277k | for( d = 8; d < 80; d += 2 ) | 158 | 268k | { | 159 | 268k | if( i_audio_quant == 0 ) | 160 | 165k | { | 161 | | /* 16bit quantization */ | 162 | 165k | of = audio_shuffle[i][j] + (d - 8) / 2 * | 163 | 165k | (i_dsf ? 108 : 90); | 164 | | | 165 | 165k | if( of * 2 >= 4 * i_samples ) continue; | 166 | | | 167 | | /* big endian */ | 168 | 158k | p_block->p_buffer[of*2] = p_frame[d+1]; | 169 | 158k | p_block->p_buffer[of*2+1] = p_frame[d]; | 170 | | | 171 | 158k | if( p_block->p_buffer[of*2+1] == 0x80 && | 172 | 1.86k | p_block->p_buffer[of*2] == 0x00 ) | 173 | 285 | p_block->p_buffer[of*2+1] = 0; | 174 | 158k | } | 175 | 102k | else | 176 | 102k | { | 177 | | /* 12bit quantization */ | 178 | 102k | uint16_t lc = (p_frame[d+0] << 4) | (p_frame[d+2] >> 4); | 179 | 102k | uint16_t rc = (p_frame[d+1] << 4) | (p_frame[d+2] & 0x0f); | 180 | | | 181 | 102k | lc = lc == 0x800 ? 0 : dv_audio_12to16(lc); | 182 | 102k | rc = rc == 0x800 ? 0 : dv_audio_12to16(rc); | 183 | | | 184 | 102k | of = audio_shuffle[i][j] + (d - 8) / 3 * (i_dsf ? 108 : 90); | 185 | 102k | if( of*2 >= 4 * i_samples ) | 186 | 58 | continue; | 187 | 102k | p_block->p_buffer[of*2+0] = lc & 0xff; | 188 | 102k | p_block->p_buffer[of*2+1] = lc >> 8; | 189 | | | 190 | 102k | of = audio_shuffle[i + i_half_ch][j] + (d - 8) / 3 * (i_dsf ? 108 : 90); | 191 | 102k | if( of*2 >= 4 * i_samples ) | 192 | 0 | continue; | 193 | 102k | p_block->p_buffer[of*2+0] = rc & 0xff; | 194 | 102k | p_block->p_buffer[of*2+1] = rc >> 8; | 195 | | | 196 | 102k | ++d; | 197 | 102k | } | 198 | 268k | } | 199 | | | 200 | 8.89k | p_frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ | 201 | 8.89k | } | 202 | 988 | } | 203 | | | 204 | 146 | p_block->i_pts = p_frame_block->i_pts != VLC_TICK_INVALID ? p_frame_block->i_pts | 205 | 146 | : p_frame_block->i_dts; | 206 | 146 | p_block->i_dts = p_frame_block->i_dts; | 207 | 146 | return p_block; | 208 | 146 | } |
Unexecuted instantiation: uleaddvaudio.c:dv_extract_audio |
209 | | |