annotate libmpdemux/demux_aac.c @ 31501:71917902699c

100l, actually enable libvpx encoder if libvpx is detected.
author reimar
date Sun, 27 Jun 2010 16:28:45 +0000
parents 9fc9d1e788aa
children cd81fce1f010
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
1 /*
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
2 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
3 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
5 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
7 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
8 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
12 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
13 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
14 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
17 */
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 26327
diff changeset
18
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
19 #include <stdio.h>
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
20 #include <stdlib.h>
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
21 #include <string.h>
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
22
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
23 #include "config.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
24 #include "mp_msg.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
25 #include "help_mp.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
26
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 21421
diff changeset
27 #include "stream/stream.h"
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
28 #include "demuxer.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
29 #include "parse_es.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
30 #include "stheader.h"
30574
928359c13d93 Add separate header for aac_parse_frame(); avoids forward declarations.
diego
parents: 29263
diff changeset
31 #include "aac_hdr.h"
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
32 #include "ms_hdr.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
33
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
34 typedef struct {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
35 uint8_t *buf;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
36 uint64_t size; /// amount of time of data packets pushed to demuxer->audio (in bytes)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
37 float time; /// amount of time elapsed based upon samples_per_frame/sample_rate (in milliseconds)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
38 float last_pts; /// last pts seen
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
39 int bitrate; /// bitrate computed as size/time
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
40 } aac_priv_t;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
41
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
42 static int demux_aac_init(demuxer_t *demuxer)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
43 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
44 aac_priv_t *priv;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
45
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
46 priv = calloc(1, sizeof(aac_priv_t));
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
47 if(!priv)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
48 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
49
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30574
diff changeset
50 priv->buf = malloc(8);
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
51 if(!priv->buf)
17789
9f0c42967ce5 fix minor (i.e. unlikely to ever happen) leak when init fails
reimar
parents: 17636
diff changeset
52 {
9f0c42967ce5 fix minor (i.e. unlikely to ever happen) leak when init fails
reimar
parents: 17636
diff changeset
53 free(priv);
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
54 return 0;
17789
9f0c42967ce5 fix minor (i.e. unlikely to ever happen) leak when init fails
reimar
parents: 17636
diff changeset
55 }
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
56
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
57 demuxer->priv = priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
58 return 1;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
59 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
60
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
61 static void demux_close_aac(demuxer_t *demuxer)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
62 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
63 aac_priv_t *priv = (aac_priv_t *) demuxer->priv;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
64
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
65 if(!priv)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
66 return;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
67
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
68 if(priv->buf)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
69 free(priv->buf);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
70
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
71 free(demuxer->priv);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
72
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
73 return;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
74 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
75
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
76 /// returns DEMUXER_TYPE_AAC if it finds 8 ADTS frames in 32768 bytes, 0 otherwise
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
77 static int demux_aac_probe(demuxer_t *demuxer)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
78 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
79 int cnt = 0, c, len, srate, num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
80 off_t init, probed;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
81 aac_priv_t *priv;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
82
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
83 if(! demux_aac_init(demuxer))
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
84 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
85 mp_msg(MSGT_DEMUX, MSGL_ERR, "COULDN'T INIT aac_demux, exit\n");
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
86 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
87 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
88
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
89 priv = (aac_priv_t *) demuxer->priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
90
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
91 init = probed = stream_tell(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
92 while(probed-init <= 32768 && cnt < 8)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
93 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
94 c = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
95 while(c != 0xFF)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
96 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
97 c = stream_read_char(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
98 if(c < 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
99 goto fail;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
100 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
101 priv->buf[0] = 0xFF;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
102 if(stream_read(demuxer->stream, &(priv->buf[1]), 7) < 7)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
103 goto fail;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
104
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
105 len = aac_parse_frame(priv->buf, &srate, &num);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
106 if(len > 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
107 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
108 cnt++;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
109 stream_skip(demuxer->stream, len - 8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
110 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
111 probed = stream_tell(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
112 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
113
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
114 stream_seek(demuxer->stream, init);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
115 if(cnt < 8)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
116 goto fail;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
117
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16175
diff changeset
118 mp_msg(MSGT_DEMUX, MSGL_V, "demux_aac_probe, INIT: %"PRIu64", PROBED: %"PRIu64", cnt: %d\n", init, probed, cnt);
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
119 return DEMUXER_TYPE_AAC;
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
120
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
121 fail:
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
122 mp_msg(MSGT_DEMUX, MSGL_V, "demux_aac_probe, failed to detect an AAC stream\n");
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
123 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
124 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
125
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
126 static demuxer_t* demux_aac_open(demuxer_t *demuxer)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
127 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
128 sh_audio_t *sh;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
129
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
130 sh = new_sh_audio(demuxer, 0);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
131 sh->ds = demuxer->audio;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
132 sh->format = mmioFOURCC('M', 'P', '4', 'A');
26299
4d56038ec730 Fix lots and lots of other demuxers broken by r26301
reimar
parents: 25883
diff changeset
133 demuxer->audio->id = 0;
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
134 demuxer->audio->sh = sh;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
135
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
136 demuxer->filepos = stream_tell(demuxer->stream);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
137
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
138 return demuxer;
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
139 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
140
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
141 static int demux_aac_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
142 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
143 aac_priv_t *priv = (aac_priv_t *) demuxer->priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
144 demux_packet_t *dp;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
145 int c1, c2, len, srate, num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
146 float tm = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
147
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
148 if(demuxer->stream->eof || (demuxer->movi_end && stream_tell(demuxer->stream) >= demuxer->movi_end))
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
149 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
150
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
151 while(! demuxer->stream->eof)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
152 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
153 c1 = c2 = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
154 while(c1 != 0xFF)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
155 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
156 c1 = stream_read_char(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
157 if(c1 < 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
158 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
159 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
160 c2 = stream_read_char(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
161 if(c2 < 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
162 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
163 if((c2 & 0xF6) != 0xF0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
164 continue;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
165
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
166 priv->buf[0] = (unsigned char) c1;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
167 priv->buf[1] = (unsigned char) c2;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
168 if(stream_read(demuxer->stream, &(priv->buf[2]), 6) < 6)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
169 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
170
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
171 len = aac_parse_frame(priv->buf, &srate, &num);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
172 if(len > 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
173 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
174 dp = new_demux_packet(len);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
175 if(! dp)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
176 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
177 mp_msg(MSGT_DEMUX, MSGL_ERR, "fill_buffer, NEW_ADD_PACKET(%d)FAILED\n", len);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
178 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
179 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
180
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
181
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
182 memcpy(dp->buffer, priv->buf, 8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
183 stream_read(demuxer->stream, &(dp->buffer[8]), len-8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
184 if(srate)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
185 tm = (float) (num * 1024.0/srate);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
186 priv->last_pts += tm;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
187 dp->pts = priv->last_pts;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
188 //fprintf(stderr, "\nPTS: %.3f\n", dp->pts);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
189 ds_add_packet(demuxer->audio, dp);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
190 priv->size += len;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
191 priv->time += tm;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
192
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
193 priv->bitrate = (int) (priv->size / priv->time);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
194 demuxer->filepos = stream_tell(demuxer->stream);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
195
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
196 return len;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
197 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
198 else
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
199 stream_skip(demuxer->stream, -6);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
200 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
201
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
202 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
203 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
204
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
205
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
206 //This is an almost verbatim copy of high_res_mp3_seek(), from demux_audio.c
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 16877
diff changeset
207 static void demux_aac_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
208 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
209 aac_priv_t *priv = (aac_priv_t *) demuxer->priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
210 demux_stream_t *d_audio=demuxer->audio;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
211 sh_audio_t *sh_audio=d_audio->sh;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
212 float time;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
213
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
214 ds_free_packs(d_audio);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
215
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
216 time = (flags & SEEK_ABSOLUTE) ? rel_seek_secs - priv->last_pts : rel_seek_secs;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
217 if(time < 0)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
218 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
219 stream_seek(demuxer->stream, demuxer->movi_start);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
220 time = priv->last_pts + time;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
221 priv->last_pts = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
222 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
223
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
224 if(time > 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
225 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
226 int len, nf, srate, num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
227
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
228 nf = time * sh_audio->samplerate/1024;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
229
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
230 while(nf > 0)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
231 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
232 if(stream_read(demuxer->stream,priv->buf, 8) < 8)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
233 break;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
234 len = aac_parse_frame(priv->buf, &srate, &num);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
235 if(len <= 0)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
236 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
237 stream_skip(demuxer->stream, -7);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
238 continue;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
239 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
240 stream_skip(demuxer->stream, len - 8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
241 priv->last_pts += (float) (num*1024.0/srate);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
242 nf -= num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
243 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
244 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
245 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
246
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
247
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 22605
diff changeset
248 const demuxer_desc_t demuxer_desc_aac = {
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
249 "AAC demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
250 "aac",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
251 "AAC",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
252 "Nico Sabbi",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
253 "Raw AAC files ",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
254 DEMUXER_TYPE_AAC,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
255 0, // unsafe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
256 demux_aac_probe,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
257 demux_aac_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
258 demux_aac_open,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
259 demux_close_aac,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
260 demux_aac_seek,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
261 NULL
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
262 };