aacdec: "consumed" is only used in mp4dec()
[paraslash.git] / aac_common.c
1 #include "para.h"
2 #include "aac.h"
3 #include "error.h"
4
5 NeAACDecHandle aac_open(void)
6 {
7 NeAACDecHandle h = NeAACDecOpen();
8 NeAACDecConfigurationPtr c = NeAACDecGetCurrentConfiguration(h);
9
10 c->defObjectType = LC;
11 c->outputFormat = FAAD_FMT_16BIT;
12 c->downMatrix = 0;
13 NeAACDecSetConfiguration(h, c);
14 return h;
15 };
16
17 static int aac_read_decoder_length(unsigned char *buf, int *description_len)
18 {
19 uint8_t b;
20 uint8_t numBytes = 0;
21 uint32_t length = 0;
22
23 do {
24 b = buf[numBytes];
25 numBytes++;
26 length = (length << 7) | (b & 0x7F);
27 } while
28 ((b & 0x80) && numBytes < 4);
29 *description_len = numBytes;
30 return length;
31 }
32
33 int aac_find_esds(unsigned char *buf, unsigned buflen, int *skip)
34 {
35 int i;
36
37 for (i = 0; i + 4 < buflen; i++) {
38 unsigned char *p = buf + i;
39 int decoder_length, description_len;
40
41 if (p[0] != 'e' || p[1] != 's' || p[2] != 'd' || p[3] != 's')
42 continue;
43 i += 8;
44 p = buf + i;
45 PARA_INFO_LOG("found esds@%d, next: %x\n", i, *p);
46 if (*p == 3)
47 i += 8;
48 else
49 i += 6;
50 p = buf + i;
51 PARA_INFO_LOG("next: %x\n", *p);
52 if (*p != 4)
53 continue;
54 i += 18;
55 p = buf + i;
56 PARA_INFO_LOG("next: %x\n", *p);
57 if (*p != 5)
58 continue;
59 i++;
60 p = buf + i;
61 decoder_length = aac_read_decoder_length(p, &description_len);
62 PARA_INFO_LOG("decoder length: %d\n", decoder_length);
63 i += description_len;
64 *skip = i;
65 return decoder_length;
66 }
67 return -E_ESDS;
68 }
69
70 unsigned aac_read_int32(unsigned char *buf)
71 {
72 uint8_t *d = (uint8_t*)buf;
73 return (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | d[3];
74 }
75
76
77 int aac_find_stco(unsigned char *buf, unsigned buflen, int *skip)
78 {
79 int i, ret;
80
81 for (i = 0; i + 16 < buflen; i++) {
82 unsigned char *p = buf + i;
83
84 if (p[0] != 's' || p[1] != 't' || p[2] != 'c' || p[3] != 'o')
85 continue;
86 PARA_INFO_LOG("found stco@%d\n", i);
87 i += 8;
88 ret = aac_read_int32(buf + i);
89 i += 4;
90 PARA_INFO_LOG("num entries: %d\n", ret);
91 *skip = i;
92 return ret;
93 }
94 PARA_WARNING_LOG("stco not found, buflen: %d\n", buflen);
95 return -E_STCO;
96 }
97
98 int aac_find_stsz(unsigned char *buf, unsigned buflen, unsigned *skip)
99 {
100 int i, ret;
101
102 for (i = 0; i + 16 < buflen; i++) {
103 unsigned char *p = buf + i;
104 unsigned sample_count, sample_size;
105
106 if (p[0] != 's' || p[1] != 't' || p[2] != 's' || p[3] != 'z')
107 continue;
108 PARA_INFO_LOG("found stsz@%d\n", i);
109 i += 8;
110 sample_size = aac_read_int32(buf + i);
111 PARA_INFO_LOG("sample size: %d\n", sample_size);
112 i += 4;
113 sample_count = aac_read_int32(buf + i);
114 i += 4;
115 PARA_INFO_LOG("sample count: %d\n", sample_count);
116 *skip = i;
117 return sample_count;
118 }
119 PARA_WARNING_LOG("stsz not found, buflen: %d\n", buflen);
120 return -E_STCO;
121 }
122