Browse code

shorten: use bytestream functions to decode the embedded WAVE header

Justin Ruggles authored on 2011/09/17 06:40:44
Showing 1 changed files
... ...
@@ -28,6 +28,7 @@
28 28
 
29 29
 #include <limits.h>
30 30
 #include "avcodec.h"
31
+#include "bytestream.h"
31 32
 #include "get_bits.h"
32 33
 #include "golomb.h"
33 34
 
... ...
@@ -191,47 +192,37 @@ static void init_offset(ShortenContext *s)
191 191
             s->offset[chan][i] = mean;
192 192
 }
193 193
 
194
-static inline int get_le32(GetBitContext *gb)
194
+static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
195
+                              int header_size)
195 196
 {
196
-    return av_bswap32(get_bits_long(gb, 32));
197
-}
198
-
199
-static inline short get_le16(GetBitContext *gb)
200
-{
201
-    return av_bswap16(get_bits_long(gb, 16));
202
-}
203
-
204
-static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size)
205
-{
206
-    GetBitContext hb;
207 197
     int len;
208 198
     short wave_format;
209 199
 
210
-    init_get_bits(&hb, header, header_size*8);
211
-    if (get_le32(&hb) != MKTAG('R','I','F','F')) {
200
+
201
+    if (bytestream_get_le32(&header) != MKTAG('R','I','F','F')) {
212 202
         av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
213 203
         return -1;
214 204
     }
215 205
 
216
-    skip_bits_long(&hb, 32);    /* chunk_size */
206
+    header += 4; /* chunk size */;
217 207
 
218
-    if (get_le32(&hb) != MKTAG('W','A','V','E')) {
208
+    if (bytestream_get_le32(&header) != MKTAG('W','A','V','E')) {
219 209
         av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
220 210
         return -1;
221 211
     }
222 212
 
223
-    while (get_le32(&hb) != MKTAG('f','m','t',' ')) {
224
-        len = get_le32(&hb);
225
-        skip_bits(&hb, 8*len);
213
+    while (bytestream_get_le32(&header) != MKTAG('f','m','t',' ')) {
214
+        len = bytestream_get_le32(&header);
215
+        header += len;
226 216
     }
227
-    len = get_le32(&hb);
217
+    len = bytestream_get_le32(&header);
228 218
 
229 219
     if (len < 16) {
230 220
         av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
231 221
         return -1;
232 222
     }
233 223
 
234
-    wave_format = get_le16(&hb);
224
+    wave_format = bytestream_get_le16(&header);
235 225
 
236 226
     switch (wave_format) {
237 227
         case WAVE_FORMAT_PCM:
... ...
@@ -241,11 +232,11 @@ static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header
241 241
             return -1;
242 242
     }
243 243
 
244
-    skip_bits(&hb, 16); // skip channels    (already got from shorten header)
245
-    avctx->sample_rate = get_le32(&hb);
246
-    skip_bits(&hb, 32); // skip bit rate    (represents original uncompressed bit rate)
247
-    skip_bits(&hb, 16); // skip block align (not needed)
248
-    avctx->bits_per_coded_sample = get_le16(&hb);
244
+    header += 2;        // skip channels    (already got from shorten header)
245
+    avctx->sample_rate = bytestream_get_le32(&header);
246
+    header += 4;        // skip bit rate    (represents original uncompressed bit rate)
247
+    header += 2;        // skip block align (not needed)
248
+    avctx->bits_per_coded_sample = bytestream_get_le16(&header);
249 249
 
250 250
     if (avctx->bits_per_coded_sample != 16) {
251 251
         av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n");