Mercurial > mplayer.hg
annotate libmpdemux/demux_audio.c @ 15416:1e36bd89d66e
Document -vf pp=ac.
author | diego |
---|---|
date | Wed, 11 May 2005 23:59:42 +0000 |
parents | db6286839af7 |
children | b5c2254d13f8 |
rev | line source |
---|---|
4694 | 1 |
2 #include "config.h" | |
4712 | 3 #include "../mp_msg.h" |
4694 | 4 |
5 #include <stdlib.h> | |
6 #include <stdio.h> | |
7 #include "stream.h" | |
8 #include "demuxer.h" | |
9 #include "stheader.h" | |
10 #include "genres.h" | |
6763 | 11 #include "mp3_hdr.h" |
4694 | 12 |
13 #include <string.h> | |
14 #ifdef MP_DEBUG | |
15 #include <assert.h> | |
16 #endif | |
17 | |
18 #define MP3 1 | |
19 #define WAV 2 | |
11004 | 20 #define fLaC 3 |
4694 | 21 |
22 | |
23 #define HDR_SIZE 4 | |
24 | |
25 typedef struct da_priv { | |
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 | 28 } da_priv_t; |
29 | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
30 // how many valid frames in a row we need before accepting as valid MP3 |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
31 #define MIN_MP3_HDRS 5 |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
32 |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
33 //! Used to describe a potential (chain of) MP3 headers we found |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
34 typedef struct mp3_hdr { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
35 off_t frame_pos; // start of first frame in this "chain" of headers |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
36 off_t next_frame_pos; // here we expect the next header with same parameters |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
37 int mp3_chans; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
38 int mp3_freq; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
39 int cons_hdrs; // if this reaches MIN_MP3_HDRS we accept as MP3 file |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
40 struct mp3_hdr *next; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
41 } mp3_hdr_t; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
42 |
4694 | 43 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
|
44 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
|
45 extern void print_wave_header(WAVEFORMATEX *h); |
4694 | 46 |
7867 | 47 int hr_mp3_seek = 0; |
4694 | 48 |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
49 /** |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
50 * \brief free a list of MP3 header descriptions |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
51 * \param list pointer to the head-of-list pointer |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
52 */ |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
53 static void free_mp3_hdrs(mp3_hdr_t **list) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
54 mp3_hdr_t *tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
55 while (*list) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
56 tmp = (*list)->next; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
57 free(*list); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
58 *list = tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
59 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
60 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
61 |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
62 /** |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
63 * \brief add another potential MP3 header to our list |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
64 * If it fits into an existing chain this one is expanded otherwise |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
65 * a new one is created. |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
66 * All entries that expected a MP3 header before the current position |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
67 * are discarded. |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
68 * The list is expected to be and will be kept sorted by next_frame_pos |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
69 * and when those are equal by frame_pos. |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
70 * \param list pointer to the head-of-list pointer |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
71 * \param st_pos stream position where the described header starts |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
72 * \param mp3_chans number of channels as specified by the header |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
73 * \param mp3_freq sampling frequency as specified by the header |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
74 * \param mp3_flen length of the frame as specified by the header |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
75 * \return If non-null the current file is accepted as MP3 and the |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
76 * mp3_hdr struct describing the valid chain is returned. Must be |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
77 * freed independent of the list. |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
78 */ |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
79 static mp3_hdr_t *add_mp3_hdr(mp3_hdr_t **list, off_t st_pos, |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
80 int mp3_chans, int mp3_freq, int mp3_flen) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
81 mp3_hdr_t *tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
82 int in_list = 0; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
83 while (*list && (*list)->next_frame_pos <= st_pos) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
84 if (((*list)->next_frame_pos < st_pos) || ((*list)->mp3_chans != mp3_chans) |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
85 || ((*list)->mp3_freq != mp3_freq)) { // wasn't valid! |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
86 tmp = (*list)->next; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
87 free(*list); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
88 *list = tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
89 } else { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
90 (*list)->cons_hdrs++; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
91 (*list)->next_frame_pos = st_pos + mp3_flen; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
92 if ((*list)->cons_hdrs >= MIN_MP3_HDRS) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
93 // copy the valid entry, so that the list can be easily freed |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
94 tmp = malloc(sizeof(mp3_hdr_t)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
95 memcpy(tmp, *list, sizeof(mp3_hdr_t)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
96 tmp->next = NULL; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
97 return tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
98 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
99 in_list = 1; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
100 list = &((*list)->next); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
101 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
102 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
103 if (!in_list) { // does not belong into an existing chain, insert |
15215
db6286839af7
Fix MP3 detection (list of found MP3 headers was not kep sorted).
reimar
parents:
15205
diff
changeset
|
104 // find right position to insert to keep sorting |
db6286839af7
Fix MP3 detection (list of found MP3 headers was not kep sorted).
reimar
parents:
15205
diff
changeset
|
105 while (*list && (*list)->next_frame_pos <= st_pos + mp3_flen) |
db6286839af7
Fix MP3 detection (list of found MP3 headers was not kep sorted).
reimar
parents:
15205
diff
changeset
|
106 list = &((*list)->next); |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
107 tmp = malloc(sizeof(mp3_hdr_t)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
108 tmp->frame_pos = st_pos; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
109 tmp->next_frame_pos = st_pos + mp3_flen; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
110 tmp->mp3_chans = mp3_chans; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
111 tmp->mp3_freq = mp3_freq; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
112 tmp->cons_hdrs = 1; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
113 tmp->next = *list; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
114 *list = tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
115 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
116 return NULL; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
117 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
118 |
4694 | 119 int demux_audio_open(demuxer_t* demuxer) { |
120 stream_t *s; | |
121 sh_audio_t* sh_audio; | |
122 uint8_t hdr[HDR_SIZE]; | |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
123 int frmt = 0, n = 0, step, mp3_freq, mp3_chans, mp3_flen, mpa_layer = 3, mpa_spf = 1152; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
124 off_t st_pos = 0, next_frame_pos = 0; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
125 // mp3_hdrs list is sorted first by next_frame_pos and then by frame_pos |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
126 mp3_hdr_t *mp3_hdrs = NULL, *mp3_found = NULL; |
4694 | 127 da_priv_t* priv; |
128 #ifdef MP_DEBUG | |
129 assert(demuxer != NULL); | |
130 assert(demuxer->stream != NULL); | |
131 #endif | |
132 | |
133 s = demuxer->stream; | |
134 | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
135 stream_read(s, hdr, HDR_SIZE); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
136 while(n < 30000 && !s->eof) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
137 st_pos = stream_tell(s) - HDR_SIZE; |
4694 | 138 step = 1; |
139 | |
140 if( hdr[0] == 'R' && hdr[1] == 'I' && hdr[2] == 'F' && hdr[3] == 'F' ) { | |
141 stream_skip(s,4); | |
142 if(s->eof) | |
143 break; | |
144 stream_read(s,hdr,4); | |
145 if(s->eof) | |
146 break; | |
147 if(hdr[0] != 'W' || hdr[1] != 'A' || hdr[2] != 'V' || hdr[3] != 'E' ) | |
148 stream_skip(s,-8); | |
149 else | |
150 // We found wav header. Now we can have 'fmt ' or a mp3 header | |
151 // empty the buffer | |
152 step = 4; | |
8116 | 153 } else if( hdr[0] == 'I' && hdr[1] == 'D' && hdr[2] == '3' && (hdr[3] >= 2)) { |
154 int len; | |
155 stream_skip(s,2); | |
156 stream_read(s,hdr,4); | |
157 len = (hdr[0]<<21) | (hdr[1]<<14) | (hdr[2]<<7) | hdr[3]; | |
158 stream_skip(s,len); | |
159 step = 4; | |
4694 | 160 } else if( hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) { |
161 frmt = WAV; | |
162 break; | |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
163 } else if((mp3_flen = mp_get_mp3_header(hdr,&mp3_chans,&mp3_freq,&mpa_spf,&mpa_layer)) > 0) { |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
164 mp3_found = add_mp3_hdr(&mp3_hdrs, st_pos, mp3_chans, mp3_freq, mp3_flen); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
165 if (mp3_found) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
166 frmt = MP3; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
167 break; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
168 } |
11004 | 169 } else if( hdr[0] == 'f' && hdr[1] == 'L' && hdr[2] == 'a' && hdr[3] == 'C' ) { |
170 frmt = fLaC; | |
171 stream_skip(s,-4); | |
172 break; | |
4694 | 173 } |
174 // Add here some other audio format detection | |
175 if(step < HDR_SIZE) | |
176 memmove(hdr,&hdr[step],HDR_SIZE-step); | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
177 stream_read(s, &hdr[HDR_SIZE - step], step); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
178 n++; |
4694 | 179 } |
180 | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
181 free_mp3_hdrs(&mp3_hdrs); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
182 |
4694 | 183 if(!frmt) |
184 return 0; | |
185 | |
186 sh_audio = new_sh_audio(demuxer,0); | |
187 | |
188 switch(frmt) { | |
189 case MP3: | |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
190 sh_audio->format = (mpa_layer < 3 ? 0x50 : 0x55); |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
191 demuxer->movi_start = mp3_found->frame_pos; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
192 next_frame_pos = mp3_found->next_frame_pos; |
6763 | 193 sh_audio->audio.dwSampleSize= 0; |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
194 sh_audio->audio.dwScale = mpa_spf; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
195 sh_audio->audio.dwRate = mp3_found->mp3_freq; |
6763 | 196 sh_audio->wf = malloc(sizeof(WAVEFORMATEX)); |
197 sh_audio->wf->wFormatTag = sh_audio->format; | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
198 sh_audio->wf->nChannels = mp3_found->mp3_chans; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
199 sh_audio->wf->nSamplesPerSec = mp3_found->mp3_freq; |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
200 sh_audio->wf->nBlockAlign = mpa_spf; |
6763 | 201 sh_audio->wf->wBitsPerSample = 16; |
202 sh_audio->wf->cbSize = 0; | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
203 free(mp3_found); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
204 mp3_found = NULL; |
4694 | 205 if(s->end_pos) { |
206 char tag[4]; | |
207 stream_seek(s,s->end_pos-128); | |
208 stream_read(s,tag,3); | |
209 tag[3] = '\0'; | |
210 if(strcmp(tag,"TAG")) | |
211 demuxer->movi_end = s->end_pos; | |
212 else { | |
213 char buf[31]; | |
214 uint8_t g; | |
215 demuxer->movi_end = stream_tell(s)-3; | |
216 stream_read(s,buf,30); | |
217 buf[30] = '\0'; | |
218 demux_info_add(demuxer,"Title",buf); | |
219 stream_read(s,buf,30); | |
220 buf[30] = '\0'; | |
221 demux_info_add(demuxer,"Artist",buf); | |
222 stream_read(s,buf,30); | |
223 buf[30] = '\0'; | |
224 demux_info_add(demuxer,"Album",buf); | |
225 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
|
226 buf[4] = '\0'; |
4694 | 227 demux_info_add(demuxer,"Year",buf); |
228 stream_read(s,buf,30); | |
229 buf[30] = '\0'; | |
230 demux_info_add(demuxer,"Comment",buf); | |
231 if(buf[28] == 0 && buf[29] != 0) { | |
232 uint8_t trk = (uint8_t)buf[29]; | |
233 sprintf(buf,"%d",trk); | |
234 demux_info_add(demuxer,"Track",buf); | |
235 } | |
236 g = stream_read_char(s); | |
237 demux_info_add(demuxer,"Genre",genres[g]); | |
238 } | |
239 } | |
240 break; | |
241 case WAV: { | |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
242 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
|
243 unsigned int chunk_size; |
4694 | 244 WAVEFORMATEX* w; |
245 int l; | |
246 l = stream_read_dword_le(s); | |
9596 | 247 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
|
248 mp_msg(MSGT_DEMUX,MSGL_ERR,"[demux_audio] Bad wav header length: too short (%d)!!!\n",l); |
4694 | 249 free_sh_audio(sh_audio); |
250 return 0; | |
251 } | |
12213 | 252 sh_audio->wf = w = (WAVEFORMATEX*)malloc(l > sizeof(WAVEFORMATEX) ? l : sizeof(WAVEFORMATEX)); |
4694 | 253 w->wFormatTag = sh_audio->format = stream_read_word_le(s); |
254 w->nChannels = sh_audio->channels = stream_read_word_le(s); | |
255 w->nSamplesPerSec = sh_audio->samplerate = stream_read_dword_le(s); | |
256 w->nAvgBytesPerSec = stream_read_dword_le(s); | |
257 w->nBlockAlign = stream_read_word_le(s); | |
258 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
|
259 w->cbSize = 0; |
9596 | 260 l -= 16; |
261 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
|
262 w->cbSize = stream_read_word_le(s); |
9596 | 263 l -= 2; |
9655 | 264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 } else { |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
271 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
|
272 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
|
273 } |
9655 | 274 } |
9596 | 275 } |
9591
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
276 |
7847 | 277 if(verbose>0) print_wave_header(w); |
4694 | 278 if(l) |
279 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
|
280 do |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
281 { |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
282 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
|
283 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
|
284 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
|
285 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
|
286 } while (chunk_type != mmioFOURCC('d', 'a', 't', 'a')); |
4694 | 287 demuxer->movi_start = stream_tell(s); |
288 demuxer->movi_end = s->end_pos; | |
7847 | 289 // printf("wav: %X .. %X\n",(int)demuxer->movi_start,(int)demuxer->movi_end); |
13006 | 290 // Check if it contains dts audio |
291 if((w->wFormatTag == 0x01) && (w->nChannels == 2) && (w->nSamplesPerSec == 44100)) { | |
292 unsigned char buf[16384]; // vlc uses 16384*4 (4 dts frames) | |
293 unsigned int i; | |
294 stream_read(s, buf, sizeof(buf)); | |
295 for (i = 0; i < sizeof(buf); i += 2) { | |
296 // DTS, 14 bit, LE | |
297 if((buf[i] == 0xff) && (buf[i+1] == 0x1f) && (buf[i+2] == 0x00) && | |
298 (buf[i+3] == 0xe8) && ((buf[i+4] & 0xfe) == 0xf0) && (buf[i+5] == 0x07)) { | |
299 sh_audio->format = 0x2001; | |
300 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 14 bit, LE\n"); | |
301 break; | |
302 } | |
303 // DTS, 14 bit, BE | |
304 if((buf[i] == 0x1f) && (buf[i+1] == 0xff) && (buf[i+2] == 0xe8) && | |
305 (buf[i+3] == 0x00) && (buf[i+4] == 0x07) && ((buf[i+5] & 0xfe) == 0xf0)) { | |
306 sh_audio->format = 0x2001; | |
307 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 14 bit, BE\n"); | |
308 break; | |
309 } | |
310 // DTS, 16 bit, BE | |
311 if((buf[i] == 0x7f) && (buf[i+1] == 0xfe) && (buf[i+2] == 0x80) && | |
312 (buf[i+3] == 0x01)) { | |
313 sh_audio->format = 0x2001; | |
314 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 16 bit, BE\n"); | |
315 break; | |
316 } | |
317 // DTS, 16 bit, LE | |
318 if((buf[i] == 0xfe) && (buf[i+1] == 0x7f) && (buf[i+2] == 0x01) && | |
319 (buf[i+3] == 0x80)) { | |
320 sh_audio->format = 0x2001; | |
321 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 16 bit, LE\n"); | |
322 break; | |
323 } | |
324 } | |
325 if (sh_audio->format == 0x2001) | |
326 mp_msg(MSGT_DEMUX,MSGL_DBG2,"[demux_audio] DTS sync offset = %u\n", i); | |
327 | |
328 } | |
329 stream_seek(s,demuxer->movi_start); | |
4694 | 330 } break; |
11004 | 331 case fLaC: |
332 sh_audio->format = mmioFOURCC('f', 'L', 'a', 'C'); | |
333 demuxer->movi_start = stream_tell(s); | |
334 demuxer->movi_end = s->end_pos; | |
335 break; | |
4694 | 336 } |
337 | |
338 priv = (da_priv_t*)malloc(sizeof(da_priv_t)); | |
339 priv->frmt = frmt; | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
340 priv->last_pts = -1; |
4694 | 341 demuxer->priv = priv; |
342 demuxer->audio->id = 0; | |
343 demuxer->audio->sh = sh_audio; | |
344 sh_audio->ds = demuxer->audio; | |
10244
a084597140af
don't set audio pts to infinity after seeking in mp3 files :)
rfelker
parents:
9655
diff
changeset
|
345 sh_audio->samplerate = sh_audio->audio.dwRate; |
4694 | 346 |
347 if(stream_tell(s) != demuxer->movi_start) | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
348 { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
349 mp_msg(MSGT_DEMUX, MSGL_V, "demux_audio: seeking from 0x%X to start pos 0x%X\n", |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
350 (int)stream_tell(s), (int)demuxer->movi_start); |
4694 | 351 stream_seek(s,demuxer->movi_start); |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
352 if (stream_tell(s) != demuxer->movi_start) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
353 mp_msg(MSGT_DEMUX, MSGL_V, "demux_audio: seeking failed, now at 0x%X!\n", |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
354 (int)stream_tell(s)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
355 if (next_frame_pos) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
356 mp_msg(MSGT_DEMUX, MSGL_V, "demux_audio: seeking to 0x%X instead\n", |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
357 (int)next_frame_pos); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
358 stream_seek(s, next_frame_pos); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
359 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
360 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
361 } |
4694 | 362 |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
363 mp_msg(MSGT_DEMUX,MSGL_V,"demux_audio: audio data 0x%X - 0x%X \n",(int)demuxer->movi_start,(int)demuxer->movi_end); |
4712 | 364 |
4694 | 365 return 1; |
366 } | |
367 | |
368 | |
369 int demux_audio_fill_buffer(demux_stream_t *ds) { | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
370 int l; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
371 demux_packet_t* dp; |
4694 | 372 sh_audio_t* sh_audio; |
373 demuxer_t* demux; | |
374 da_priv_t* priv; | |
375 stream_t* s; | |
376 #ifdef MP_DEBUG | |
377 assert(ds != NULL); | |
378 assert(ds->sh != NULL); | |
379 assert(ds->demuxer != NULL); | |
380 #endif | |
381 sh_audio = ds->sh; | |
382 demux = ds->demuxer; | |
383 priv = demux->priv; | |
384 s = demux->stream; | |
385 | |
386 if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) | |
387 return 0; | |
388 | |
389 switch(priv->frmt) { | |
390 case MP3 : | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
391 while(1) { |
4694 | 392 uint8_t hdr[4]; |
393 stream_read(s,hdr,4); | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
394 if (s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end)) |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
395 return 0; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
396 l = mp_decode_mp3_header(hdr); |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
397 if(l < 0) { |
4694 | 398 stream_skip(s,-3); |
399 } else { | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
400 dp = new_demux_packet(l); |
4694 | 401 memcpy(dp->buffer,hdr,4); |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
402 stream_read(s,dp->buffer + 4,l-4); |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
403 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + sh_audio->audio.dwScale/(float)sh_audio->samplerate; |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
404 break; |
4694 | 405 } |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
406 } break; |
4694 | 407 case WAV : { |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
408 l = sh_audio->wf->nAvgBytesPerSec; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
409 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
|
410 l = stream_read(s,dp->buffer,l); |
14910
07be3bc42d47
100l to reimar.. sh_audio->samplerate and sh_audio->i_bps are not the same
rfelker
parents:
14608
diff
changeset
|
411 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + l/(float)sh_audio->i_bps; |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
412 break; |
4694 | 413 } |
11004 | 414 case fLaC: { |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
415 l = 65535; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
416 dp = new_demux_packet(l); |
11004 | 417 l = stream_read(s,dp->buffer,l); |
14910
07be3bc42d47
100l to reimar.. sh_audio->samplerate and sh_audio->i_bps are not the same
rfelker
parents:
14608
diff
changeset
|
418 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + l/(float)sh_audio->i_bps; |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
419 break; |
11004 | 420 } |
4694 | 421 default: |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
422 printf("Audio demuxer : unknown format %d\n",priv->frmt); |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
423 return 0; |
4694 | 424 } |
425 | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
426 resize_demux_packet(dp, l); |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
427 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio) - |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
428 sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
429 ds_add_packet(ds, dp); |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
430 return 1; |
4694 | 431 } |
432 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
433 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
|
434 uint8_t hdr[4]; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
435 int len,nf; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
436 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
|
437 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
|
438 |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
439 nf = time*sh->samplerate/sh->audio.dwScale; |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
440 while(nf > 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
441 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
|
442 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
|
443 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
444 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
|
445 continue; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
446 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
447 stream_skip(demuxer->stream,len-4); |
15199
980910eb6f0c
assign correct tag, dwScale and dwBlockAlign to mpeg audio; optionally assign layer and samples_per_frame when parsing mpa header
nicodvb
parents:
14910
diff
changeset
|
448 priv->last_pts += sh->audio.dwScale/(float)sh->samplerate; |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
449 nf--; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
450 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
451 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
452 |
4694 | 453 void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
454 sh_audio_t* sh_audio; | |
455 stream_t* s; | |
456 int base,pos; | |
457 float len; | |
458 da_priv_t* priv; | |
459 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
460 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
|
461 return; |
4694 | 462 s = demuxer->stream; |
463 priv = demuxer->priv; | |
464 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
465 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
|
466 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
|
467 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
468 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
|
469 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
|
470 priv->last_pts = 0; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
471 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
472 if(len > 0) |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
473 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
|
474 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
|
475 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
|
476 return; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
477 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
478 |
5796 | 479 base = flags&1 ? demuxer->movi_start : stream_tell(s); |
480 if(flags&2) | |
481 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); | |
482 else | |
483 pos = base + (rel_seek_secs*sh_audio->i_bps); | |
4694 | 484 |
485 if(demuxer->movi_end && pos >= demuxer->movi_end) { | |
8359 | 486 pos = demuxer->movi_end; |
487 //sh_audio->delay = (stream_tell(s) - demuxer->movi_start)/(float)sh_audio->i_bps; | |
488 //return; | |
4694 | 489 } else if(pos < demuxer->movi_start) |
490 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
|
491 |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
492 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
|
493 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 494 |
495 switch(priv->frmt) { | |
496 case WAV: | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
497 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
|
498 // 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
|
499 priv->last_pts -= sh_audio->wf->nAvgBytesPerSec/(float)sh_audio->i_bps; |
4694 | 500 break; |
501 } | |
502 | |
503 stream_seek(s,pos); | |
504 | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
505 resync_audio_stream(sh_audio); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
506 |
4694 | 507 } |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
508 |
5812 | 509 void demux_close_audio(demuxer_t* demuxer) { |
510 da_priv_t* priv = demuxer->priv; | |
511 | |
512 if(!priv) | |
513 return; | |
514 free(priv); | |
515 } | |
516 | |
10882
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
517 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
|
518 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
|
519 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
|
520 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
|
521 |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 *((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
|
526 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
|
527 |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
528 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
|
529 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
|
530 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
|
531 *((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
|
532 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
|
533 |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
534 default: |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
535 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
|
536 } |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
537 } |