annotate libmpdemux/demux_aac.c @ 17611:831762e82a47

do not forget to initialize dp->buffer
author henry
date Sun, 12 Feb 2006 17:01:30 +0000
parents 9081ae3a702c
children b849a99cdc3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
1 #include <stdio.h>
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
2 #include <stdlib.h>
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
3 #include <string.h>
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
4
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
5 #include "config.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
6 #include "mp_msg.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
7 #include "help_mp.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
8
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
9 #include "stream.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
10 #include "demuxer.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
11 #include "parse_es.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
12 #include "stheader.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
13
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
14 #include "bswap.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
15 #include "ms_hdr.h"
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
16
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
17 typedef struct {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
18 uint8_t *buf;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
19 uint64_t size; /// amount of time of data packets pushed to demuxer->audio (in bytes)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
20 float time; /// amount of time elapsed based upon samples_per_frame/sample_rate (in milliseconds)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
21 float last_pts; /// last pts seen
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
22 int bitrate; /// bitrate computed as size/time
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
23 } aac_priv_t;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
24
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
25 /// \param srate (out) sample rate
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
26 /// \param num (out) number of audio frames in this ADTS frame
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
27 /// \return size of the ADTS frame in bytes
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
28 /// aac_parse_frames needs a buffer at least 8 bytes long
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
29 int aac_parse_frame(uint8_t *buf, int *srate, int *num)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
30 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
31 int i = 0, sr, fl = 0, id;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
32 static int srates[] = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 0, 0, 0};
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
33
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
34 if((buf[i] != 0xFF) || ((buf[i+1] & 0xF6) != 0xF0))
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
35 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
36
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
37 id = (buf[i+1] >> 3) & 0x01; //id=1 mpeg2, 0: mpeg4
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
38 sr = (buf[i+2] >> 2) & 0x0F;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
39 if(sr > 11)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
40 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
41 *srate = srates[sr];
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
42
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
43 fl = ((buf[i+3] & 0x03) << 11) | (buf[i+4] << 3) | ((buf[i+5] >> 5) & 0x07);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
44 *num = (buf[i+6] & 0x02) + 1;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
45
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
46 return fl;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
47 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
48
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
49 static int demux_aac_init(demuxer_t *demuxer)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
50 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
51 aac_priv_t *priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
52
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
53 priv = calloc(1, sizeof(aac_priv_t));
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
54 if(!priv)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
55 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
56
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
57 priv->buf = (uint8_t*) malloc(8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
58 if(!priv->buf)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
59 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
60
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
61 demuxer->priv = priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
62 return 1;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
63 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
64
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
65 static void demux_close_aac(demuxer_t *demuxer)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
66 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
67 aac_priv_t *priv = (aac_priv_t *) demuxer->priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
68
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
69 if(!priv)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
70 return;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
71
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
72 if(priv->buf)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
73 free(priv->buf);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
74
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
75 free(demuxer->priv);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
76
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
77 return;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
78 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
79
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
80 /// returns DEMUXER_TYPE_AAC if it finds 8 ADTS frames in 32768 bytes, 0 otherwise
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
81 static int demux_aac_probe(demuxer_t *demuxer)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
82 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
83 int cnt = 0, c, len, srate, num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
84 off_t init, probed;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
85 aac_priv_t *priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
86
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
87 if(! demux_aac_init(demuxer))
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
88 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
89 mp_msg(MSGT_DEMUX, MSGL_ERR, "COULDN'T INIT aac_demux, exit\n");
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
90 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
91 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
92
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
93 priv = (aac_priv_t *) demuxer->priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
94
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
95 init = probed = stream_tell(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
96 while(probed-init <= 32768 && cnt < 8)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
97 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
98 c = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
99 while(c != 0xFF)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
100 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
101 c = stream_read_char(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
102 if(c < 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
103 goto fail;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
104 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
105 priv->buf[0] = 0xFF;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
106 if(stream_read(demuxer->stream, &(priv->buf[1]), 7) < 7)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
107 goto fail;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
108
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
109 len = aac_parse_frame(priv->buf, &srate, &num);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
110 if(len > 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
111 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
112 cnt++;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
113 stream_skip(demuxer->stream, len - 8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
114 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
115 probed = stream_tell(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
116 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
117
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
118 stream_seek(demuxer->stream, init);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
119 if(cnt < 8)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
120 goto fail;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
121
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16175
diff changeset
122 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
123 return DEMUXER_TYPE_AAC;
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
124
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
125 fail:
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
126 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
127 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
128 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
129
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
130 static demuxer_t* demux_aac_open(demuxer_t *demuxer)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
131 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
132 sh_audio_t *sh;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
133
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
134 sh = new_sh_audio(demuxer, 0);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
135 sh->ds = demuxer->audio;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
136 sh->format = mmioFOURCC('M', 'P', '4', 'A');
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
137 demuxer->audio->sh = sh;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
138
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
139 demuxer->filepos = stream_tell(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
140
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
141 return demuxer;
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
142 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
143
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
144 static int demux_aac_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
145 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
146 aac_priv_t *priv = (aac_priv_t *) demuxer->priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
147 demux_packet_t *dp;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
148 int c1, c2, len, srate, num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
149 float tm = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
150
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
151 if(demuxer->stream->eof || (demuxer->movi_end && stream_tell(demuxer->stream) >= demuxer->movi_end))
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
152 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
153
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
154 while(! demuxer->stream->eof)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
155 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
156 c1 = c2 = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
157 while(c1 != 0xFF)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
158 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
159 c1 = stream_read_char(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
160 if(c1 < 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
161 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
162 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
163 c2 = stream_read_char(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
164 if(c2 < 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
165 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
166 if((c2 & 0xF6) != 0xF0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
167 continue;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
168
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
169 priv->buf[0] = (unsigned char) c1;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
170 priv->buf[1] = (unsigned char) c2;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
171 if(stream_read(demuxer->stream, &(priv->buf[2]), 6) < 6)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
172 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
173
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
174 len = aac_parse_frame(priv->buf, &srate, &num);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
175 if(len > 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
176 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
177 dp = new_demux_packet(len);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
178 if(! dp)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
179 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
180 mp_msg(MSGT_DEMUX, MSGL_ERR, "fill_buffer, NEW_ADD_PACKET(%d)FAILED\n", len);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
181 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
182 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
183
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
184
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
185 memcpy(dp->buffer, priv->buf, 8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
186 stream_read(demuxer->stream, &(dp->buffer[8]), len-8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
187 if(srate)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
188 tm = (float) (num * 1024.0/srate);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
189 priv->last_pts += tm;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
190 dp->pts = priv->last_pts;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
191 //fprintf(stderr, "\nPTS: %.3f\n", dp->pts);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
192 ds_add_packet(demuxer->audio, dp);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
193 priv->size += len;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
194 priv->time += tm;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
195
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
196 priv->bitrate = (int) (priv->size / priv->time);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
197 demuxer->filepos = stream_tell(demuxer->stream);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
198
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
199 return len;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
200 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
201 else
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
202 stream_skip(demuxer->stream, -6);
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 return 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
206 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
207
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
208
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
209 //This is an almost verbatim copy of high_res_mp3_seek(), from demux_audio.c
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
210 static void demux_aac_seek(demuxer_t *demuxer, float rel_seek_secs, int flags)
15720
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
211 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
212 aac_priv_t *priv = (aac_priv_t *) demuxer->priv;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
213 demux_stream_t *d_audio=demuxer->audio;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
214 sh_audio_t *sh_audio=d_audio->sh;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
215 float time;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
216
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
217 ds_free_packs(d_audio);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
218
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
219 time = (flags & 1) ? rel_seek_secs - priv->last_pts : rel_seek_secs;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
220 if(time < 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
221 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
222 stream_seek(demuxer->stream, demuxer->movi_start);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
223 time = priv->last_pts + time;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
224 priv->last_pts = 0;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
225 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
226
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
227 if(time > 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
228 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
229 int len, nf, srate, num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
230
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
231 nf = time * sh_audio->samplerate/1024;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
232
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
233 while(nf > 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
234 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
235 if(stream_read(demuxer->stream,priv->buf, 8) < 8)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
236 break;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
237 len = aac_parse_frame(priv->buf, &srate, &num);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
238 if(len <= 0)
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
239 {
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
240 stream_skip(demuxer->stream, -7);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
241 continue;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
242 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
243 stream_skip(demuxer->stream, len - 8);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
244 priv->last_pts += (float) (num*1024.0/srate);
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
245 nf -= num;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
246 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
247 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
248 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)priv->bitrate;
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
249 }
e999d58f94fd added AAC ADTS demuxer
nicodvb
parents:
diff changeset
250
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
251
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
252 demuxer_desc_t demuxer_desc_aac = {
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
253 "AAC demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
254 "aac",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
255 "AAC",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
256 "Nico Sabbi",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
257 "Raw AAC files ",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
258 DEMUXER_TYPE_AAC,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
259 0, // unsafe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
260 demux_aac_probe,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
261 demux_aac_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
262 demux_aac_open,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
263 demux_close_aac,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
264 demux_aac_seek,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
265 NULL
6b86089c2edd Demuxer modularization
rtognimp
parents: 15820
diff changeset
266 };