annotate libmpdemux/demux_audio.c @ 4720:10ad330c1733

fixed WAV demuxer so that it skips to the actual start of the audio data
author melanson
date Sat, 16 Feb 2002 05:45:16 +0000
parents b7054dadd2c0
children 9579496a91db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
1
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
2 #include "config.h"
4712
9262f4dc332f mp3 position fixed
arpi
parents: 4700
diff changeset
3 #include "../mp_msg.h"
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
4
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
5 #include <stdlib.h>
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
6 #include <stdio.h>
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
7 #include "stream.h"
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
8 #include "demuxer.h"
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
9 #include "stheader.h"
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
10 #include "genres.h"
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
11
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
12 #include <string.h>
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
13 #ifdef MP_DEBUG
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
14 #include <assert.h>
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
15 #endif
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
16
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
17 #define MP3 1
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
18 #define WAV 2
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
19
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
20
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
21 #define HDR_SIZE 4
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
22
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
23 typedef struct da_priv {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
24 int frmt;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
25 } da_priv_t;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
26
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
27 extern int mp_decode_mp3_header(unsigned char* hbuf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
28 extern void free_sh_audio(sh_audio_t* sh);
4700
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
29 extern void resync_audio_stream(sh_audio_t *sh_audio);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
30
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
31
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
32 int demux_audio_open(demuxer_t* demuxer) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
33 stream_t *s;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
34 sh_audio_t* sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
35 uint8_t hdr[HDR_SIZE];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
36 int st_pos = 0,frmt = 0, n = 0, pos = 0, step;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
37 da_priv_t* priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
38 #ifdef MP_DEBUG
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
39 assert(demuxer != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
40 assert(demuxer->stream != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
41 #endif
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
42
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
43 s = demuxer->stream;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
44
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
45 while(n < 5 && ! s->eof) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
46 st_pos = stream_tell(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
47 step = 1;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
48 if(pos < HDR_SIZE) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
49 stream_read(s,&hdr[pos],HDR_SIZE-pos);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
50 pos = HDR_SIZE;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
51 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
52
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
53 if( hdr[0] == 'R' && hdr[1] == 'I' && hdr[2] == 'F' && hdr[3] == 'F' ) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
54 stream_skip(s,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
55 if(s->eof)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
56 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
57 stream_read(s,hdr,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
58 if(s->eof)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
59 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
60 if(hdr[0] != 'W' || hdr[1] != 'A' || hdr[2] != 'V' || hdr[3] != 'E' )
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
61 stream_skip(s,-8);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
62 else
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
63 // We found wav header. Now we can have 'fmt ' or a mp3 header
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
64 // empty the buffer
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
65 step = 4;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
66 } else if( hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
67 frmt = WAV;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
68 break;
4717
b7054dadd2c0 We should skip exactly the first frame on mp3 files.
albeu
parents: 4712
diff changeset
69 } else if((n = mp_decode_mp3_header(hdr)) > 0) {
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
70 frmt = MP3;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
71 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
72 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
73 // Add here some other audio format detection
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
74 if(step < HDR_SIZE)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
75 memmove(hdr,&hdr[step],HDR_SIZE-step);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
76 pos -= step;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
77 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
78
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
79 if(!frmt)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
80 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
81
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
82 sh_audio = new_sh_audio(demuxer,0);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
83
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
84 switch(frmt) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
85 case MP3:
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
86 sh_audio->format = 0x55;
4717
b7054dadd2c0 We should skip exactly the first frame on mp3 files.
albeu
parents: 4712
diff changeset
87 demuxer->movi_start = st_pos-HDR_SIZE+n;
4700
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
88 for(n = 0; n < 5 ; n++) {
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
89 pos = mp_decode_mp3_header(hdr);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
90 if(pos < 0)
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
91 return 0;
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
92 stream_skip(s,pos-4);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
93 if(s->eof)
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
94 return 0;
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
95 stream_read(s,hdr,4);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
96 if(s->eof)
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
97 return 0;
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
98 }
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
99 if(s->end_pos) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
100 char tag[4];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
101 stream_seek(s,s->end_pos-128);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
102 stream_read(s,tag,3);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
103 tag[3] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
104 if(strcmp(tag,"TAG"))
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
105 demuxer->movi_end = s->end_pos;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
106 else {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
107 char buf[31];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
108 uint8_t g;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
109 demuxer->movi_end = stream_tell(s)-3;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
110 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
111 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
112 demux_info_add(demuxer,"Title",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
113 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
114 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
115 demux_info_add(demuxer,"Artist",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
116 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
117 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
118 demux_info_add(demuxer,"Album",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
119 stream_read(s,buf,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
120 buf[5] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
121 demux_info_add(demuxer,"Year",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
122 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
123 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
124 demux_info_add(demuxer,"Comment",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
125 if(buf[28] == 0 && buf[29] != 0) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
126 uint8_t trk = (uint8_t)buf[29];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
127 sprintf(buf,"%d",trk);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
128 demux_info_add(demuxer,"Track",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
129 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
130 g = stream_read_char(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
131 demux_info_add(demuxer,"Genre",genres[g]);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
132 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
133 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
134 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
135 case WAV: {
4720
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
136 unsigned int chunk_type;
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
137 unsigned int chunk_size;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
138 WAVEFORMATEX* w;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
139 int l;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
140 sh_audio->wf = w = (WAVEFORMATEX*)malloc(sizeof(WAVEFORMATEX));
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
141 l = stream_read_dword_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
142 if(l < 16) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
143 printf("Bad wav header length : too short !!!\n");
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
144 free_sh_audio(sh_audio);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
145 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
146 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
147 w->wFormatTag = sh_audio->format = stream_read_word_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
148 w->nChannels = sh_audio->channels = stream_read_word_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
149 w->nSamplesPerSec = sh_audio->samplerate = stream_read_dword_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
150 w->nAvgBytesPerSec = stream_read_dword_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
151 w->nBlockAlign = stream_read_word_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
152 w->wBitsPerSample = sh_audio->samplesize = stream_read_word_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
153 w->cbSize = 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
154 l -= 16;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
155 if(l)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
156 stream_skip(s,l);
4720
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
157 do
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
158 {
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
159 chunk_type = stream_read_fourcc(demuxer->stream);
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
160 chunk_size = stream_read_dword_le(demuxer->stream);
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
161 if (chunk_type != mmioFOURCC('d', 'a', 't', 'a'))
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
162 stream_skip(demuxer->stream, chunk_size);
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
163 } while (chunk_type != mmioFOURCC('d', 'a', 't', 'a'));
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
164 demuxer->movi_start = stream_tell(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
165 demuxer->movi_end = s->end_pos;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
166 } break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
167 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
168
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
169 priv = (da_priv_t*)malloc(sizeof(da_priv_t));
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
170 priv->frmt = frmt;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
171 demuxer->priv = priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
172 demuxer->audio->id = 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
173 demuxer->audio->sh = sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
174 sh_audio->ds = demuxer->audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
175
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
176 if(stream_tell(s) != demuxer->movi_start)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
177 stream_seek(s,demuxer->movi_start);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
178
4712
9262f4dc332f mp3 position fixed
arpi
parents: 4700
diff changeset
179 mp_msg(MSGT_DEMUX,MSGL_V,"demux_audio: audio data 0x%X - 0x%X \n",demuxer->movi_start,demuxer->movi_end);
9262f4dc332f mp3 position fixed
arpi
parents: 4700
diff changeset
180
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
181 return 1;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
182 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
183
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
184
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
185 int demux_audio_fill_buffer(demux_stream_t *ds) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
186 sh_audio_t* sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
187 demuxer_t* demux;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
188 da_priv_t* priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
189 stream_t* s;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
190 #ifdef MP_DEBUG
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
191 assert(ds != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
192 assert(ds->sh != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
193 assert(ds->demuxer != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
194 #endif
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
195 sh_audio = ds->sh;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
196 demux = ds->demuxer;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
197 priv = demux->priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
198 s = demux->stream;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
199
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
200 if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) )
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
201 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
202
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
203 switch(priv->frmt) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
204 case MP3 :
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
205 while(! s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
206 uint8_t hdr[4];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
207 int len;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
208 stream_read(s,hdr,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
209 len = mp_decode_mp3_header(hdr);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
210 if(len < 0) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
211 stream_skip(s,-3);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
212 } else {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
213 demux_packet_t* dp;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
214 if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) )
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
215 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
216 dp = new_demux_packet(len);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
217 memcpy(dp->buffer,hdr,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
218 stream_read(s,dp->buffer + 4,len-4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
219 ds_add_packet(ds,dp);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
220 return 1;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
221 }
4700
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
222 } break;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
223 case WAV : {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
224 int l = sh_audio->wf->nAvgBytesPerSec;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
225 demux_packet_t* dp = new_demux_packet(l);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
226 stream_read(s,dp->buffer,l);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
227 ds_add_packet(ds,dp);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
228 return 1;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
229 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
230 default:
4720
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
231 printf("Audio demuxer : unknown format %d\n",priv->frmt);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
232 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
233
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
234
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
235 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
236 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
237
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
238 void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
239 sh_audio_t* sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
240 stream_t* s;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
241 int base,pos;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
242 float len;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
243 da_priv_t* priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
244
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
245 sh_audio = demuxer->audio->sh;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
246 s = demuxer->stream;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
247 priv = demuxer->priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
248
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
249 base = flags&1 ? demuxer->movi_start : stream_tell(s) ;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
250 len = (demuxer->movi_end && flags&2) ? (demuxer->movi_end - demuxer->movi_start)*rel_seek_secs : rel_seek_secs;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
251
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
252 pos = base+(len*sh_audio->i_bps);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
253
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
254 if(demuxer->movi_end && pos >= demuxer->movi_end) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
255 sh_audio->timer = (stream_tell(s) - demuxer->movi_start)/sh_audio->i_bps;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
256 return;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
257 } else if(pos < demuxer->movi_start)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
258 pos = demuxer->movi_start;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
259
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
260
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
261 sh_audio->timer = flags&1 ? rel_seek_secs : (pos-demuxer->movi_start)/sh_audio->i_bps;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
262
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
263 switch(priv->frmt) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
264 case WAV:
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
265 pos += (pos % (sh_audio->channels * sh_audio->samplesize) );
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
266 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
267 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
268
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
269 stream_seek(s,pos);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
270
4700
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
271 resync_audio_stream(sh_audio);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
272
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
273 }