annotate libmpdemux/demux_audio.c @ 11353:d405317808ac

sync
author wight
date Sat, 01 Nov 2003 17:13:26 +0000
parents d48eccbbb984
children 064cb156d2b7
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"
6763
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
11 #include "mp3_hdr.h"
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
12
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
13 #include <string.h>
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
14 #ifdef MP_DEBUG
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
15 #include <assert.h>
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
16 #endif
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
17
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
18 #define MP3 1
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
19 #define WAV 2
11004
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
20 #define fLaC 3
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
21
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 #define HDR_SIZE 4
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
24
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
25 typedef struct da_priv {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
26 int frmt;
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
27 float last_pts;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
28 } da_priv_t;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
29
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
30 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
31 extern void resync_audio_stream(sh_audio_t *sh_audio);
8123
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 8116
diff changeset
32 extern void print_wave_header(WAVEFORMATEX *h);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
33
7867
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7847
diff changeset
34 int hr_mp3_seek = 0;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
35
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
36 int demux_audio_open(demuxer_t* demuxer) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
37 stream_t *s;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
38 sh_audio_t* sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
39 uint8_t hdr[HDR_SIZE];
6763
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
40 int st_pos = 0,frmt = 0, n = 0, pos = 0, step, mp3_freq,mp3_chans;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
41 da_priv_t* priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
42 #ifdef MP_DEBUG
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
43 assert(demuxer != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
44 assert(demuxer->stream != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
45 #endif
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
46
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
47 s = demuxer->stream;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
48
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
49 while(n < 5 && ! s->eof) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
50 st_pos = stream_tell(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
51 step = 1;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
52 if(pos < HDR_SIZE) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
53 stream_read(s,&hdr[pos],HDR_SIZE-pos);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
54 pos = HDR_SIZE;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
55 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
56
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
57 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
58 stream_skip(s,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
59 if(s->eof)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
60 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
61 stream_read(s,hdr,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
62 if(s->eof)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
63 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
64 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
65 stream_skip(s,-8);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
66 else
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
67 // 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
68 // empty the buffer
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
69 step = 4;
8116
3757669b825b skip id3v2 junk when looking for mp3
rfelker
parents: 8110
diff changeset
70 } else if( hdr[0] == 'I' && hdr[1] == 'D' && hdr[2] == '3' && (hdr[3] >= 2)) {
3757669b825b skip id3v2 junk when looking for mp3
rfelker
parents: 8110
diff changeset
71 int len;
3757669b825b skip id3v2 junk when looking for mp3
rfelker
parents: 8110
diff changeset
72 stream_skip(s,2);
3757669b825b skip id3v2 junk when looking for mp3
rfelker
parents: 8110
diff changeset
73 stream_read(s,hdr,4);
3757669b825b skip id3v2 junk when looking for mp3
rfelker
parents: 8110
diff changeset
74 len = (hdr[0]<<21) | (hdr[1]<<14) | (hdr[2]<<7) | hdr[3];
3757669b825b skip id3v2 junk when looking for mp3
rfelker
parents: 8110
diff changeset
75 stream_skip(s,len);
3757669b825b skip id3v2 junk when looking for mp3
rfelker
parents: 8110
diff changeset
76 step = 4;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
77 } 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
78 frmt = WAV;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
79 break;
6763
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
80 } else if((n = mp_get_mp3_header(hdr,&mp3_chans,&mp3_freq)) > 0) {
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
81 frmt = MP3;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
82 break;
11004
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
83 } else if( hdr[0] == 'f' && hdr[1] == 'L' && hdr[2] == 'a' && hdr[3] == 'C' ) {
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
84 frmt = fLaC;
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
85 stream_skip(s,-4);
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
86 break;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
87 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
88 // Add here some other audio format detection
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
89 if(step < HDR_SIZE)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
90 memmove(hdr,&hdr[step],HDR_SIZE-step);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
91 pos -= step;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
92 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
93
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
94 if(!frmt)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
95 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
96
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
97 sh_audio = new_sh_audio(demuxer,0);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
98
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
99 switch(frmt) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
100 case MP3:
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
101 sh_audio->format = 0x55;
4717
b7054dadd2c0 We should skip exactly the first frame on mp3 files.
albeu
parents: 4712
diff changeset
102 demuxer->movi_start = st_pos-HDR_SIZE+n;
6763
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
103 sh_audio->audio.dwSampleSize= 0;
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
104 sh_audio->audio.dwScale = 1152;
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
105 sh_audio->audio.dwRate = mp3_freq;
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
106 sh_audio->wf = malloc(sizeof(WAVEFORMATEX));
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
107 sh_audio->wf->wFormatTag = sh_audio->format;
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
108 sh_audio->wf->nChannels = mp3_chans;
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
109 sh_audio->wf->nSamplesPerSec = mp3_freq;
8110
arpi
parents: 8056
diff changeset
110 sh_audio->wf->nBlockAlign = 1152;
6763
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
111 sh_audio->wf->wBitsPerSample = 16;
e29f95ed5d36 Fix vbr muxing and win32 codec crash on init
albeu
parents: 5812
diff changeset
112 sh_audio->wf->cbSize = 0;
4700
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
113 for(n = 0; n < 5 ; n++) {
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
114 pos = mp_decode_mp3_header(hdr);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
115 if(pos < 0)
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
116 return 0;
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
117 stream_skip(s,pos-4);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
118 if(s->eof)
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
119 return 0;
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
120 stream_read(s,hdr,4);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
121 if(s->eof)
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
122 return 0;
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
123 }
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
124 if(s->end_pos) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
125 char tag[4];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
126 stream_seek(s,s->end_pos-128);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
127 stream_read(s,tag,3);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
128 tag[3] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
129 if(strcmp(tag,"TAG"))
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
130 demuxer->movi_end = s->end_pos;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
131 else {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
132 char buf[31];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
133 uint8_t g;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
134 demuxer->movi_end = stream_tell(s)-3;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
135 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
136 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
137 demux_info_add(demuxer,"Title",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
138 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
139 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
140 demux_info_add(demuxer,"Artist",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
141 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
142 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
143 demux_info_add(demuxer,"Album",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
144 stream_read(s,buf,4);
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
145 buf[4] = '\0';
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
146 demux_info_add(demuxer,"Year",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
147 stream_read(s,buf,30);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
148 buf[30] = '\0';
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
149 demux_info_add(demuxer,"Comment",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
150 if(buf[28] == 0 && buf[29] != 0) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
151 uint8_t trk = (uint8_t)buf[29];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
152 sprintf(buf,"%d",trk);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
153 demux_info_add(demuxer,"Track",buf);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
154 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
155 g = stream_read_char(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
156 demux_info_add(demuxer,"Genre",genres[g]);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
157 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
158 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
159 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
160 case WAV: {
4720
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
161 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
162 unsigned int chunk_size;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
163 WAVEFORMATEX* w;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
164 int l;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
165 l = stream_read_dword_le(s);
9596
7b4a17c415fb Same behaviour as old code for short headers
rtognimp
parents: 9591
diff changeset
166 if(l < 16) {
9591
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
167 mp_msg(MSGT_DEMUX,MSGL_ERR,"[demux_audio] Bad wav header length: too short (%d)!!!\n",l);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
168 free_sh_audio(sh_audio);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
169 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
170 }
9591
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
171 sh_audio->wf = w = (WAVEFORMATEX*)malloc(l);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
172 w->wFormatTag = sh_audio->format = stream_read_word_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
173 w->nChannels = sh_audio->channels = stream_read_word_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
174 w->nSamplesPerSec = sh_audio->samplerate = stream_read_dword_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
175 w->nAvgBytesPerSec = stream_read_dword_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
176 w->nBlockAlign = stream_read_word_le(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
177 w->wBitsPerSample = sh_audio->samplesize = stream_read_word_le(s);
9616
a6bbab17a87f 10l cbSize not inited for l=16.\n Could give problem in print_wave_header
rtognimp
parents: 9596
diff changeset
178 w->cbSize = 0;
9596
7b4a17c415fb Same behaviour as old code for short headers
rtognimp
parents: 9591
diff changeset
179 l -= 16;
7b4a17c415fb Same behaviour as old code for short headers
rtognimp
parents: 9591
diff changeset
180 if (l > 0) {
9591
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
181 w->cbSize = stream_read_word_le(s);
9596
7b4a17c415fb Same behaviour as old code for short headers
rtognimp
parents: 9591
diff changeset
182 l -= 2;
9655
8809e2be5cea Warning fix, patch by Dominik Mierzejewsky
rtognimp
parents: 9616
diff changeset
183 if (w->cbSize > 0) {
9591
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
184 if (l < w->cbSize) {
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
185 mp_msg(MSGT_DEMUX,MSGL_ERR,"[demux_audio] truncated extradata (%d < %d)\n",
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
186 l,w->cbSize);
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
187 stream_read(s,(char*)((char*)(w)+sizeof(WAVEFORMATEX)),l);
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
188 l = 0;
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
189 } else {
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
190 stream_read(s,(char*)((char*)(w)+sizeof(WAVEFORMATEX)),w->cbSize);
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
191 l -= w->cbSize;
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
192 }
9655
8809e2be5cea Warning fix, patch by Dominik Mierzejewsky
rtognimp
parents: 9616
diff changeset
193 }
9596
7b4a17c415fb Same behaviour as old code for short headers
rtognimp
parents: 9591
diff changeset
194 }
9591
3904b95fce8f Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents: 8359
diff changeset
195
7847
f1e6a68a42f1 dump wav header
arpi
parents: 6763
diff changeset
196 if(verbose>0) print_wave_header(w);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
197 if(l)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
198 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
199 do
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
200 {
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
201 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
202 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
203 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
204 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
205 } while (chunk_type != mmioFOURCC('d', 'a', 't', 'a'));
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
206 demuxer->movi_start = stream_tell(s);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
207 demuxer->movi_end = s->end_pos;
7847
f1e6a68a42f1 dump wav header
arpi
parents: 6763
diff changeset
208 // printf("wav: %X .. %X\n",(int)demuxer->movi_start,(int)demuxer->movi_end);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
209 } break;
11004
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
210 case fLaC:
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
211 sh_audio->format = mmioFOURCC('f', 'L', 'a', 'C');
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
212 demuxer->movi_start = stream_tell(s);
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
213 demuxer->movi_end = s->end_pos;
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
214 break;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
215 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
216
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
217 priv = (da_priv_t*)malloc(sizeof(da_priv_t));
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
218 priv->frmt = frmt;
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
219 priv->last_pts = -1;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
220 demuxer->priv = priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
221 demuxer->audio->id = 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
222 demuxer->audio->sh = sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
223 sh_audio->ds = demuxer->audio;
10244
a084597140af don't set audio pts to infinity after seeking in mp3 files :)
rfelker
parents: 9655
diff changeset
224 sh_audio->samplerate = sh_audio->audio.dwRate;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
225
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
226 if(stream_tell(s) != demuxer->movi_start)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
227 stream_seek(s,demuxer->movi_start);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
228
4712
9262f4dc332f mp3 position fixed
arpi
parents: 4700
diff changeset
229 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
230
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
231 return 1;
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 int demux_audio_fill_buffer(demux_stream_t *ds) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
236 sh_audio_t* sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
237 demuxer_t* demux;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
238 da_priv_t* priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
239 stream_t* s;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
240 #ifdef MP_DEBUG
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
241 assert(ds != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
242 assert(ds->sh != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
243 assert(ds->demuxer != NULL);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
244 #endif
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
245 sh_audio = ds->sh;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
246 demux = ds->demuxer;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
247 priv = demux->priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
248 s = demux->stream;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
249
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
250 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
251 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
252
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
253 switch(priv->frmt) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
254 case MP3 :
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
255 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
256 uint8_t hdr[4];
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
257 int len;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
258 stream_read(s,hdr,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
259 len = mp_decode_mp3_header(hdr);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
260 if(len < 0) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
261 stream_skip(s,-3);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
262 } else {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
263 demux_packet_t* dp;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
264 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
265 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
266 dp = new_demux_packet(len);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
267 memcpy(dp->buffer,hdr,4);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
268 stream_read(s,dp->buffer + 4,len-4);
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
269 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + 1152/(float)sh_audio->samplerate;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
270 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
271 ds_add_packet(ds,dp);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
272 return 1;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
273 }
4700
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
274 } break;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
275 case WAV : {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
276 int l = sh_audio->wf->nAvgBytesPerSec;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
277 demux_packet_t* dp = new_demux_packet(l);
10891
65ed62e138fa Fixed 'reading after EOF'. demuxers didn't check, how many they've read!
lumag
parents: 10882
diff changeset
278 l = stream_read(s,dp->buffer,l);
65ed62e138fa Fixed 'reading after EOF'. demuxers didn't check, how many they've read!
lumag
parents: 10882
diff changeset
279 resize_demux_packet(dp, l);
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
280 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + l/(float)sh_audio->i_bps;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
281 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
282 ds_add_packet(ds,dp);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
283 return 1;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
284 }
11004
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
285 case fLaC: {
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
286 int l = 65535;
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
287 demux_packet_t* dp = new_demux_packet(l);
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
288 l = stream_read(s,dp->buffer,l);
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
289 resize_demux_packet(dp, l);
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
290 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + l/(float)sh_audio->i_bps;
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
291 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
292 ds_add_packet(ds,dp);
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
293 return 1;
d48eccbbb984 FLAC decoding support via imported libmpflac.
lumag
parents: 10891
diff changeset
294 }
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
295 default:
4720
10ad330c1733 fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents: 4717
diff changeset
296 printf("Audio demuxer : unknown format %d\n",priv->frmt);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
297 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
298
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
299
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
300 return 0;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
301 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
302
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
303 static void high_res_mp3_seek(demuxer_t *demuxer,float time) {
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
304 uint8_t hdr[4];
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
305 int len,nf;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
306 da_priv_t* priv = demuxer->priv;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
307 sh_audio_t* sh = (sh_audio_t*)demuxer->audio->sh;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
308
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
309 nf = time*sh->samplerate/1152;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
310 while(nf > 0) {
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
311 stream_read(demuxer->stream,hdr,4);
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
312 len = mp_decode_mp3_header(hdr);
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
313 if(len < 0) {
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
314 stream_skip(demuxer->stream,-3);
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
315 continue;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
316 }
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
317 stream_skip(demuxer->stream,len-4);
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
318 priv->last_pts += 1152/(float)sh->samplerate;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
319 nf--;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
320 }
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
321 }
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
322
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
323 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
324 sh_audio_t* sh_audio;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
325 stream_t* s;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
326 int base,pos;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
327 float len;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
328 da_priv_t* priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
329
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
330 if(!(sh_audio = demuxer->audio->sh))
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
331 return;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
332 s = demuxer->stream;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
333 priv = demuxer->priv;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
334
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
335 if(priv->frmt == MP3 && hr_mp3_seek && !(flags & 2)) {
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
336 len = (flags & 1) ? rel_seek_secs - priv->last_pts : rel_seek_secs;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
337 if(len < 0) {
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
338 stream_seek(s,demuxer->movi_start);
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
339 len = priv->last_pts + len;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
340 priv->last_pts = 0;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
341 }
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
342 if(len > 0)
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
343 high_res_mp3_seek(demuxer,len);
8056
324b6e5387be A-V sync cleanup: sh_audio->timer replaced by sh_audio->delay, it contains
arpi
parents: 7867
diff changeset
344 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
345 resync_audio_stream(sh_audio);
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
346 return;
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
347 }
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
348
5796
7a4b18b787c0 Fix % seeking
albeu
parents: 4764
diff changeset
349 base = flags&1 ? demuxer->movi_start : stream_tell(s);
7a4b18b787c0 Fix % seeking
albeu
parents: 4764
diff changeset
350 if(flags&2)
7a4b18b787c0 Fix % seeking
albeu
parents: 4764
diff changeset
351 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
7a4b18b787c0 Fix % seeking
albeu
parents: 4764
diff changeset
352 else
7a4b18b787c0 Fix % seeking
albeu
parents: 4764
diff changeset
353 pos = base + (rel_seek_secs*sh_audio->i_bps);
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
354
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
355 if(demuxer->movi_end && pos >= demuxer->movi_end) {
8359
a93461f7e5ef fixed mp3 seeking near end of file
arpi
parents: 8123
diff changeset
356 pos = demuxer->movi_end;
a93461f7e5ef fixed mp3 seeking near end of file
arpi
parents: 8123
diff changeset
357 //sh_audio->delay = (stream_tell(s) - demuxer->movi_start)/(float)sh_audio->i_bps;
a93461f7e5ef fixed mp3 seeking near end of file
arpi
parents: 8123
diff changeset
358 //return;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
359 } else if(pos < demuxer->movi_start)
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
360 pos = demuxer->movi_start;
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
361
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
362 priv->last_pts = (pos-demuxer->movi_start)/(float)sh_audio->i_bps;
8056
324b6e5387be A-V sync cleanup: sh_audio->timer replaced by sh_audio->delay, it contains
arpi
parents: 7867
diff changeset
363 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
364
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
365 switch(priv->frmt) {
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
366 case WAV:
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
367 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) );
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
368 // We need to decrease the pts by one step to make it the "last one"
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
369 priv->last_pts -= sh_audio->wf->nAvgBytesPerSec/(float)sh_audio->i_bps;
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
370 break;
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
371 }
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
372
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
373 stream_seek(s,pos);
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
374
4700
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
375 resync_audio_stream(sh_audio);
30131db5dfbb Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents: 4694
diff changeset
376
4694
a21735031d6a Audio file demuxer. Extended version for demuxer info.
albeu
parents:
diff changeset
377 }
4764
9579496a91db Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents: 4720
diff changeset
378
5812
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
379 void demux_close_audio(demuxer_t* demuxer) {
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
380 da_priv_t* priv = demuxer->priv;
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
381
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
382 if(!priv)
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
383 return;
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
384 free(priv);
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
385 }
f9d23c2aa6b7 Uninit added
albeu
parents: 5796
diff changeset
386
10882
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
387 int demux_audio_control(demuxer_t *demuxer,int cmd, void *arg){
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
388 sh_audio_t *sh_audio=demuxer->audio->sh;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
389 int audio_length = demuxer->movi_end / sh_audio->i_bps;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
390 da_priv_t* priv = demuxer->priv;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
391
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
392 switch(cmd) {
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
393 case DEMUXER_CTRL_GET_TIME_LENGTH:
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
394 if (audio_length<=0) return DEMUXER_CTRL_DONTKNOW;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
395 *((unsigned long *)arg)=(unsigned long)audio_length;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
396 return DEMUXER_CTRL_GUESS;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
397
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
398 case DEMUXER_CTRL_GET_PERCENT_POS:
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
399 if (audio_length<=0)
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
400 return DEMUXER_CTRL_DONTKNOW;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
401 *((int *)arg)=(int)( (priv->last_pts*100) / audio_length);
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
402 return DEMUXER_CTRL_OK;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
403
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
404 default:
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
405 return DEMUXER_CTRL_NOTIMPL;
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
406 }
e46e5a6c53b8 get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents: 10244
diff changeset
407 }