Mercurial > mplayer.hg
annotate libmpdemux/demux_audio.c @ 18176:f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
author | reynaldo |
---|---|
date | Sat, 22 Apr 2006 05:12:10 +0000 |
parents | 0b13bab3f237 |
children | 9e2b300db17b |
rev | line source |
---|---|
4694 | 1 |
2 #include "config.h" | |
17012 | 3 #include "mp_msg.h" |
18176
f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents:
18117
diff
changeset
|
4 #include "help_mp.h" |
4694 | 5 |
6 #include <stdlib.h> | |
7 #include <stdio.h> | |
8 #include "stream.h" | |
9 #include "demuxer.h" | |
10 #include "stheader.h" | |
11 #include "genres.h" | |
6763 | 12 #include "mp3_hdr.h" |
4694 | 13 |
14 #include <string.h> | |
15 #ifdef MP_DEBUG | |
16 #include <assert.h> | |
17 #endif | |
18 | |
19 #define MP3 1 | |
20 #define WAV 2 | |
11004 | 21 #define fLaC 3 |
4694 | 22 |
23 | |
24 #define HDR_SIZE 4 | |
25 | |
26 typedef struct da_priv { | |
27 int frmt; | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
28 float last_pts; |
4694 | 29 } da_priv_t; |
30 | |
18074
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
31 //! rather arbitrary value for maximum length of wav-format headers |
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
32 #define MAX_WAVHDR_LEN (1 * 1024 * 1024) |
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
33 |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
34 // 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
|
35 #define MIN_MP3_HDRS 5 |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
36 |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
37 //! 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
|
38 typedef struct mp3_hdr { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
39 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
|
40 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
|
41 int mp3_chans; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
42 int mp3_freq; |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
43 int mpa_spf; |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
44 int mpa_layer; |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
45 int mpa_br; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
46 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
|
47 struct mp3_hdr *next; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
48 } mp3_hdr_t; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
49 |
4694 | 50 extern void free_sh_audio(sh_audio_t* sh); |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17932
diff
changeset
|
51 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); |
4694 | 52 |
7867 | 53 int hr_mp3_seek = 0; |
4694 | 54 |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
55 /** |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
56 * \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
|
57 * \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
|
58 */ |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
59 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
|
60 mp3_hdr_t *tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
61 while (*list) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
62 tmp = (*list)->next; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
63 free(*list); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
64 *list = tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
65 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
66 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
67 |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
68 /** |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
69 * \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
|
70 * 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
|
71 * a new one is created. |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
72 * 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
|
73 * are discarded. |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
74 * 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
|
75 * 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
|
76 * \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
|
77 * \param st_pos stream position where the described header starts |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
78 * \param mp3_chans number of channels as specified by the header (*) |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
79 * \param mp3_freq sampling frequency as specified by the header (*) |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
80 * \param mpa_spf frame size as specified by the header |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
81 * \param mpa_layer layer type ("version") as specified by the header (*) |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
82 * \param mpa_br bitrate as specified by the header |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
83 * \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
|
84 * \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
|
85 * 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
|
86 * freed independent of the list. |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
87 * |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
88 * parameters marked by (*) must be the same for all headers in the same chain |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
89 */ |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
90 static mp3_hdr_t *add_mp3_hdr(mp3_hdr_t **list, off_t st_pos, |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
91 int mp3_chans, int mp3_freq, int mpa_spf, |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
92 int mpa_layer, int mpa_br, int mp3_flen) { |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
93 mp3_hdr_t *tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
94 int in_list = 0; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
95 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
|
96 if (((*list)->next_frame_pos < st_pos) || ((*list)->mp3_chans != mp3_chans) |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
97 || ((*list)->mp3_freq != mp3_freq) || ((*list)->mpa_layer != mpa_layer) ) { |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
98 // wasn't valid! |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
99 tmp = (*list)->next; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
100 free(*list); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
101 *list = tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
102 } else { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
103 (*list)->cons_hdrs++; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
104 (*list)->next_frame_pos = st_pos + mp3_flen; |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
105 (*list)->mpa_spf = mpa_spf; |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
106 (*list)->mpa_br = mpa_br; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
107 if ((*list)->cons_hdrs >= MIN_MP3_HDRS) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
108 // 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
|
109 tmp = malloc(sizeof(mp3_hdr_t)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
110 memcpy(tmp, *list, sizeof(mp3_hdr_t)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
111 tmp->next = NULL; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
112 return tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
113 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
114 in_list = 1; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
115 list = &((*list)->next); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
116 } |
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 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
|
119 // 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
|
120 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
|
121 list = &((*list)->next); |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
122 tmp = malloc(sizeof(mp3_hdr_t)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
123 tmp->frame_pos = st_pos; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
124 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
|
125 tmp->mp3_chans = mp3_chans; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
126 tmp->mp3_freq = mp3_freq; |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
127 tmp->mpa_spf = mpa_spf; |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
128 tmp->mpa_layer = mpa_layer; |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
129 tmp->mpa_br = mpa_br; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
130 tmp->cons_hdrs = 1; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
131 tmp->next = *list; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
132 *list = tmp; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
133 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
134 return NULL; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
135 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
136 |
17898
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
137 #define FLAC_SIGNATURE_SIZE 4 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
138 #define FLAC_STREAMINFO_SIZE 34 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
139 #define FLAC_SEEKPOINT_SIZE 18 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
140 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
141 enum { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
142 FLAC_STREAMINFO = 0, |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
143 FLAC_PADDING, |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
144 FLAC_APPLICATION, |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
145 FLAC_SEEKTABLE, |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
146 FLAC_VORBIS_COMMENT, |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
147 FLAC_CUESHEET |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
148 } flac_preamble_t; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
149 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
150 static void |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
151 get_flac_metadata (demuxer_t* demuxer) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
152 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
153 uint8_t preamble[4]; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
154 unsigned int blk_len; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
155 stream_t *s = NULL; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
156 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
157 if (!demuxer) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
158 return; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
159 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
160 s = demuxer->stream; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
161 if (!s) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
162 return; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
163 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
164 /* file is qualified; skip over the signature bytes in the stream */ |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
165 stream_seek (s, 4); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
166 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
167 /* loop through the metadata blocks; use a do-while construct since there |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
168 * will always be 1 metadata block */ |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
169 do { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
170 int r; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
171 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
172 r = stream_read (s, (char *) preamble, FLAC_SIGNATURE_SIZE); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
173 if (r != FLAC_SIGNATURE_SIZE) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
174 return; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
175 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
176 blk_len = (preamble[1] << 16) | (preamble[2] << 8) | (preamble[3] << 0); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
177 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
178 switch (preamble[0] & 0x7F) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
179 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
180 case FLAC_STREAMINFO: |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
181 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
182 if (blk_len != FLAC_STREAMINFO_SIZE) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
183 return; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
184 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
185 stream_skip (s, FLAC_STREAMINFO_SIZE); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
186 break; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
187 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
188 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
189 case FLAC_PADDING: |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
190 stream_skip (s, blk_len); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
191 break; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
192 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
193 case FLAC_APPLICATION: |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
194 stream_skip (s, blk_len); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
195 break; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
196 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
197 case FLAC_SEEKTABLE: |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
198 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
199 int seekpoint_count, i; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
200 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
201 seekpoint_count = blk_len / FLAC_SEEKPOINT_SIZE; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
202 for (i = 0; i < seekpoint_count; i++) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
203 if (stream_skip (s, FLAC_SEEKPOINT_SIZE) != 1) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
204 return; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
205 break; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
206 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
207 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
208 case FLAC_VORBIS_COMMENT: |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
209 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
210 /* For a description of the format please have a look at */ |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
211 /* http://www.xiph.org/vorbis/doc/v-comment.html */ |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
212 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
213 uint32_t length, comment_list_len; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
214 char comments[blk_len]; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
215 void *ptr = comments; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
216 char *comment; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
217 int cn; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
218 char c; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
219 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
220 if (stream_read (s, comments, blk_len) == blk_len) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
221 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
222 uint8_t *p = ptr; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
223 length = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
224 ptr += 4 + length; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
225 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
226 p = ptr; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
227 comment_list_len = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
228 ptr += 4; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
229 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
230 cn = 0; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
231 for (; cn < comment_list_len; cn++) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
232 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
233 p = ptr; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
234 length = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
235 ptr += 4; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
236 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
237 comment = (char *) ptr; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
238 c = comment[length]; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
239 comment[length] = 0; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
240 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
241 if (!strncasecmp ("TITLE=", comment, 6) && (length - 6 > 0)) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
242 demux_info_add (demuxer, "Title", comment + 6); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
243 else if (!strncasecmp ("ARTIST=", comment, 7) && (length - 7 > 0)) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
244 demux_info_add (demuxer, "Artist", comment + 7); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
245 else if (!strncasecmp ("ALBUM=", comment, 6) && (length - 6 > 0)) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
246 demux_info_add (demuxer, "Album", comment + 6); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
247 else if (!strncasecmp ("DATE=", comment, 5) && (length - 5 > 0)) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
248 demux_info_add (demuxer, "Year", comment + 5); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
249 else if (!strncasecmp ("GENRE=", comment, 6) && (length - 6 > 0)) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
250 demux_info_add (demuxer, "Genre", comment + 6); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
251 else if (!strncasecmp ("Comment=", comment, 8) && (length - 8 > 0)) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
252 demux_info_add (demuxer, "Comment", comment + 8); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
253 else if (!strncasecmp ("TRACKNUMBER=", comment, 12) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
254 && (length - 12 > 0)) |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
255 { |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
256 char buf[31]; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
257 buf[30] = '\0'; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
258 sprintf (buf, "%d", atoi (comment + 12)); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
259 demux_info_add(demuxer, "Track", buf); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
260 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
261 comment[length] = c; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
262 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
263 ptr += length; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
264 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
265 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
266 break; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
267 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
268 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
269 case FLAC_CUESHEET: |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
270 stream_skip (s, blk_len); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
271 break; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
272 |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
273 default: |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
274 /* 6-127 are presently reserved */ |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
275 stream_skip (s, blk_len); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
276 break; |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
277 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
278 } while ((preamble[0] & 0x80) == 0); |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
279 } |
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
280 |
16175 | 281 static int demux_audio_open(demuxer_t* demuxer) { |
4694 | 282 stream_t *s; |
283 sh_audio_t* sh_audio; | |
284 uint8_t hdr[HDR_SIZE]; | |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
285 int frmt = 0, n = 0, step; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
286 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
|
287 // 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
|
288 mp3_hdr_t *mp3_hdrs = NULL, *mp3_found = NULL; |
4694 | 289 da_priv_t* priv; |
290 #ifdef MP_DEBUG | |
291 assert(demuxer != NULL); | |
292 assert(demuxer->stream != NULL); | |
293 #endif | |
294 | |
295 s = demuxer->stream; | |
296 | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
297 stream_read(s, hdr, HDR_SIZE); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
298 while(n < 30000 && !s->eof) { |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
299 int mp3_freq, mp3_chans, mp3_flen, mpa_layer, mpa_spf, mpa_br; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
300 st_pos = stream_tell(s) - HDR_SIZE; |
4694 | 301 step = 1; |
302 | |
303 if( hdr[0] == 'R' && hdr[1] == 'I' && hdr[2] == 'F' && hdr[3] == 'F' ) { | |
304 stream_skip(s,4); | |
305 if(s->eof) | |
306 break; | |
307 stream_read(s,hdr,4); | |
308 if(s->eof) | |
309 break; | |
310 if(hdr[0] != 'W' || hdr[1] != 'A' || hdr[2] != 'V' || hdr[3] != 'E' ) | |
311 stream_skip(s,-8); | |
312 else | |
313 // We found wav header. Now we can have 'fmt ' or a mp3 header | |
314 // empty the buffer | |
315 step = 4; | |
8116 | 316 } else if( hdr[0] == 'I' && hdr[1] == 'D' && hdr[2] == '3' && (hdr[3] >= 2)) { |
317 int len; | |
318 stream_skip(s,2); | |
319 stream_read(s,hdr,4); | |
320 len = (hdr[0]<<21) | (hdr[1]<<14) | (hdr[2]<<7) | hdr[3]; | |
321 stream_skip(s,len); | |
322 step = 4; | |
4694 | 323 } else if( hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) { |
324 frmt = WAV; | |
325 break; | |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
326 } else if((mp3_flen = mp_get_mp3_header(hdr, &mp3_chans, &mp3_freq, |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
327 &mpa_spf, &mpa_layer, &mpa_br)) > 0) { |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
328 mp3_found = add_mp3_hdr(&mp3_hdrs, st_pos, mp3_chans, mp3_freq, |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
329 mpa_spf, mpa_layer, mpa_br, mp3_flen); |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
330 if (mp3_found) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
331 frmt = MP3; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
332 break; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
333 } |
11004 | 334 } else if( hdr[0] == 'f' && hdr[1] == 'L' && hdr[2] == 'a' && hdr[3] == 'C' ) { |
335 frmt = fLaC; | |
336 break; | |
4694 | 337 } |
338 // Add here some other audio format detection | |
339 if(step < HDR_SIZE) | |
340 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
|
341 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
|
342 n++; |
4694 | 343 } |
344 | |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
345 free_mp3_hdrs(&mp3_hdrs); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
346 |
4694 | 347 if(!frmt) |
348 return 0; | |
349 | |
350 sh_audio = new_sh_audio(demuxer,0); | |
351 | |
352 switch(frmt) { | |
353 case MP3: | |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
354 sh_audio->format = (mp3_found->mpa_layer < 3 ? 0x50 : 0x55); |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
355 demuxer->movi_start = mp3_found->frame_pos; |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
356 next_frame_pos = mp3_found->next_frame_pos; |
6763 | 357 sh_audio->audio.dwSampleSize= 0; |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
358 sh_audio->audio.dwScale = mp3_found->mpa_spf; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
359 sh_audio->audio.dwRate = mp3_found->mp3_freq; |
6763 | 360 sh_audio->wf = malloc(sizeof(WAVEFORMATEX)); |
361 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
|
362 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
|
363 sh_audio->wf->nSamplesPerSec = mp3_found->mp3_freq; |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
364 sh_audio->wf->nAvgBytesPerSec = mp3_found->mpa_br * (1000 / 8); |
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
365 sh_audio->wf->nBlockAlign = mp3_found->mpa_spf; |
6763 | 366 sh_audio->wf->wBitsPerSample = 16; |
367 sh_audio->wf->cbSize = 0; | |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
368 sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec; |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
369 free(mp3_found); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
370 mp3_found = NULL; |
4694 | 371 if(s->end_pos) { |
372 char tag[4]; | |
373 stream_seek(s,s->end_pos-128); | |
374 stream_read(s,tag,3); | |
375 tag[3] = '\0'; | |
376 if(strcmp(tag,"TAG")) | |
377 demuxer->movi_end = s->end_pos; | |
378 else { | |
379 char buf[31]; | |
380 uint8_t g; | |
381 demuxer->movi_end = stream_tell(s)-3; | |
382 stream_read(s,buf,30); | |
383 buf[30] = '\0'; | |
384 demux_info_add(demuxer,"Title",buf); | |
385 stream_read(s,buf,30); | |
386 buf[30] = '\0'; | |
387 demux_info_add(demuxer,"Artist",buf); | |
388 stream_read(s,buf,30); | |
389 buf[30] = '\0'; | |
390 demux_info_add(demuxer,"Album",buf); | |
391 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
|
392 buf[4] = '\0'; |
4694 | 393 demux_info_add(demuxer,"Year",buf); |
394 stream_read(s,buf,30); | |
395 buf[30] = '\0'; | |
396 demux_info_add(demuxer,"Comment",buf); | |
397 if(buf[28] == 0 && buf[29] != 0) { | |
398 uint8_t trk = (uint8_t)buf[29]; | |
399 sprintf(buf,"%d",trk); | |
400 demux_info_add(demuxer,"Track",buf); | |
401 } | |
402 g = stream_read_char(s); | |
403 demux_info_add(demuxer,"Genre",genres[g]); | |
404 } | |
405 } | |
406 break; | |
407 case WAV: { | |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
408 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
|
409 unsigned int chunk_size; |
4694 | 410 WAVEFORMATEX* w; |
411 int l; | |
412 l = stream_read_dword_le(s); | |
9596 | 413 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
|
414 mp_msg(MSGT_DEMUX,MSGL_ERR,"[demux_audio] Bad wav header length: too short (%d)!!!\n",l); |
4694 | 415 free_sh_audio(sh_audio); |
416 return 0; | |
417 } | |
18074
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
418 if(l > MAX_WAVHDR_LEN) { |
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
419 mp_msg(MSGT_DEMUX,MSGL_ERR,"[demux_audio] Bad wav header length: too long (%d)!!!\n",l); |
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
420 free_sh_audio(sh_audio); |
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
421 return 0; |
a491d7628cdc
check wav header length against upper limit, should protect against
reimar
parents:
17977
diff
changeset
|
422 } |
12213 | 423 sh_audio->wf = w = (WAVEFORMATEX*)malloc(l > sizeof(WAVEFORMATEX) ? l : sizeof(WAVEFORMATEX)); |
4694 | 424 w->wFormatTag = sh_audio->format = stream_read_word_le(s); |
425 w->nChannels = sh_audio->channels = stream_read_word_le(s); | |
426 w->nSamplesPerSec = sh_audio->samplerate = stream_read_dword_le(s); | |
427 w->nAvgBytesPerSec = stream_read_dword_le(s); | |
428 w->nBlockAlign = stream_read_word_le(s); | |
429 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
|
430 w->cbSize = 0; |
16162
b5c2254d13f8
set i_bps in demux_audio for WAV and MP3 to avoid division by zero before
reimar
parents:
15215
diff
changeset
|
431 sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec; |
9596 | 432 l -= 16; |
433 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
|
434 w->cbSize = stream_read_word_le(s); |
9596 | 435 l -= 2; |
9655 | 436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 } else { |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
443 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
|
444 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
|
445 } |
9655 | 446 } |
9596 | 447 } |
9591
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
448 |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17932
diff
changeset
|
449 if( mp_msg_test(MSGT_DEMUX,MSGL_V) ) print_wave_header(w, MSGL_V); |
4694 | 450 if(l) |
451 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
|
452 do |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
453 { |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
454 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
|
455 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
|
456 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
|
457 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
|
458 } while (chunk_type != mmioFOURCC('d', 'a', 't', 'a')); |
4694 | 459 demuxer->movi_start = stream_tell(s); |
460 demuxer->movi_end = s->end_pos; | |
7847 | 461 // printf("wav: %X .. %X\n",(int)demuxer->movi_start,(int)demuxer->movi_end); |
13006 | 462 // Check if it contains dts audio |
463 if((w->wFormatTag == 0x01) && (w->nChannels == 2) && (w->nSamplesPerSec == 44100)) { | |
464 unsigned char buf[16384]; // vlc uses 16384*4 (4 dts frames) | |
465 unsigned int i; | |
466 stream_read(s, buf, sizeof(buf)); | |
17775
28c2108f1cfa
"i < sizeof(buf)" must be "i < sizeof(buf) - 5", since later buf[i + 5] is used.
reimar
parents:
17636
diff
changeset
|
467 for (i = 0; i < sizeof(buf) - 5; i += 2) { |
13006 | 468 // DTS, 14 bit, LE |
469 if((buf[i] == 0xff) && (buf[i+1] == 0x1f) && (buf[i+2] == 0x00) && | |
470 (buf[i+3] == 0xe8) && ((buf[i+4] & 0xfe) == 0xf0) && (buf[i+5] == 0x07)) { | |
471 sh_audio->format = 0x2001; | |
472 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 14 bit, LE\n"); | |
473 break; | |
474 } | |
475 // DTS, 14 bit, BE | |
476 if((buf[i] == 0x1f) && (buf[i+1] == 0xff) && (buf[i+2] == 0xe8) && | |
477 (buf[i+3] == 0x00) && (buf[i+4] == 0x07) && ((buf[i+5] & 0xfe) == 0xf0)) { | |
478 sh_audio->format = 0x2001; | |
479 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 14 bit, BE\n"); | |
480 break; | |
481 } | |
482 // DTS, 16 bit, BE | |
483 if((buf[i] == 0x7f) && (buf[i+1] == 0xfe) && (buf[i+2] == 0x80) && | |
484 (buf[i+3] == 0x01)) { | |
485 sh_audio->format = 0x2001; | |
486 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 16 bit, BE\n"); | |
487 break; | |
488 } | |
489 // DTS, 16 bit, LE | |
490 if((buf[i] == 0xfe) && (buf[i+1] == 0x7f) && (buf[i+2] == 0x01) && | |
491 (buf[i+3] == 0x80)) { | |
492 sh_audio->format = 0x2001; | |
493 mp_msg(MSGT_DEMUX,MSGL_V,"[demux_audio] DTS audio in wav, 16 bit, LE\n"); | |
494 break; | |
495 } | |
496 } | |
497 if (sh_audio->format == 0x2001) | |
498 mp_msg(MSGT_DEMUX,MSGL_DBG2,"[demux_audio] DTS sync offset = %u\n", i); | |
499 | |
500 } | |
501 stream_seek(s,demuxer->movi_start); | |
4694 | 502 } break; |
11004 | 503 case fLaC: |
504 sh_audio->format = mmioFOURCC('f', 'L', 'a', 'C'); | |
18075
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
505 demuxer->movi_start = stream_tell(s) - 4; |
11004 | 506 demuxer->movi_end = s->end_pos; |
18075
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
507 if (demuxer->movi_end > demuxer->movi_start) { |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
508 // try to find out approx. bitrate |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
509 int64_t size = demuxer->movi_end - demuxer->movi_start; |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
510 int64_t num_samples = 0; |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
511 int32_t srate = 0; |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
512 stream_skip(s, 14); |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
513 stream_read(s, (char *)&srate, 3); |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
514 srate = be2me_32(srate) >> 12; |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
515 stream_read(s, (char *)&num_samples, 5); |
18117 | 516 num_samples = (be2me_64(num_samples) >> 24) & 0xfffffffffULL; |
18075
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
517 if (num_samples && srate) |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
518 sh_audio->i_bps = size * srate / num_samples; |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
519 } |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
520 if (sh_audio->i_bps < 1) // guess value to prevent crash |
2373ed2ee546
try to detect flac bitrate early on to avoid division by zero problems.
reimar
parents:
18074
diff
changeset
|
521 sh_audio->i_bps = 64 * 1024; |
17898
a2b85171b4de
retrieve metadata from FLAC files (patch by Benjamin Zores < ben _at_ geexbox.org >)
aurel
parents:
17790
diff
changeset
|
522 get_flac_metadata (demuxer); |
11004 | 523 break; |
4694 | 524 } |
525 | |
526 priv = (da_priv_t*)malloc(sizeof(da_priv_t)); | |
527 priv->frmt = frmt; | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
528 priv->last_pts = -1; |
4694 | 529 demuxer->priv = priv; |
530 demuxer->audio->id = 0; | |
531 demuxer->audio->sh = sh_audio; | |
532 sh_audio->ds = demuxer->audio; | |
10244
a084597140af
don't set audio pts to infinity after seeking in mp3 files :)
rfelker
parents:
9655
diff
changeset
|
533 sh_audio->samplerate = sh_audio->audio.dwRate; |
4694 | 534 |
535 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
|
536 { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
537 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
|
538 (int)stream_tell(s), (int)demuxer->movi_start); |
4694 | 539 stream_seek(s,demuxer->movi_start); |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
540 if (stream_tell(s) != demuxer->movi_start) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
541 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
|
542 (int)stream_tell(s)); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
543 if (next_frame_pos) { |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
544 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
|
545 (int)next_frame_pos); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
546 stream_seek(s, next_frame_pos); |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
547 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
548 } |
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
549 } |
4694 | 550 |
13503
f8347c521898
better, tuneable (via #define) MP3 detection, limit demux_audio to scanning
reimar
parents:
13357
diff
changeset
|
551 mp_msg(MSGT_DEMUX,MSGL_V,"demux_audio: audio data 0x%X - 0x%X \n",(int)demuxer->movi_start,(int)demuxer->movi_end); |
4712 | 552 |
16175 | 553 return DEMUXER_TYPE_AUDIO; |
4694 | 554 } |
555 | |
556 | |
16175 | 557 static int demux_audio_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds) { |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
558 int l; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
559 demux_packet_t* dp; |
4694 | 560 sh_audio_t* sh_audio; |
561 demuxer_t* demux; | |
562 da_priv_t* priv; | |
563 stream_t* s; | |
564 #ifdef MP_DEBUG | |
565 assert(ds != NULL); | |
566 assert(ds->sh != NULL); | |
567 assert(ds->demuxer != NULL); | |
568 #endif | |
569 sh_audio = ds->sh; | |
570 demux = ds->demuxer; | |
571 priv = demux->priv; | |
572 s = demux->stream; | |
573 | |
16438
871e94131840
Ignore movi_end (except on error) to allow playing growing files.
reimar
parents:
16346
diff
changeset
|
574 if(s->eof) |
4694 | 575 return 0; |
576 | |
577 switch(priv->frmt) { | |
578 case MP3 : | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
579 while(1) { |
4694 | 580 uint8_t hdr[4]; |
581 stream_read(s,hdr,4); | |
16438
871e94131840
Ignore movi_end (except on error) to allow playing growing files.
reimar
parents:
16346
diff
changeset
|
582 if (s->eof) |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
583 return 0; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
584 l = mp_decode_mp3_header(hdr); |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
585 if(l < 0) { |
16438
871e94131840
Ignore movi_end (except on error) to allow playing growing files.
reimar
parents:
16346
diff
changeset
|
586 if (demux->movi_end && stream_tell(s) >= demux->movi_end) |
871e94131840
Ignore movi_end (except on error) to allow playing growing files.
reimar
parents:
16346
diff
changeset
|
587 return 0; // might be ID3 tag, i.e. EOF |
4694 | 588 stream_skip(s,-3); |
589 } else { | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
590 dp = new_demux_packet(l); |
4694 | 591 memcpy(dp->buffer,hdr,4); |
16438
871e94131840
Ignore movi_end (except on error) to allow playing growing files.
reimar
parents:
16346
diff
changeset
|
592 if (stream_read(s,dp->buffer + 4,l-4) != l-4) |
17790
99a2481164ac
fix leak on read error (forgot to free demux packet)
reimar
parents:
17775
diff
changeset
|
593 { |
99a2481164ac
fix leak on read error (forgot to free demux packet)
reimar
parents:
17775
diff
changeset
|
594 free_demux_packet(dp); |
16438
871e94131840
Ignore movi_end (except on error) to allow playing growing files.
reimar
parents:
16346
diff
changeset
|
595 return 0; |
17790
99a2481164ac
fix leak on read error (forgot to free demux packet)
reimar
parents:
17775
diff
changeset
|
596 } |
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
|
597 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
|
598 break; |
4694 | 599 } |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
600 } break; |
4694 | 601 case WAV : { |
17554 | 602 unsigned align = sh_audio->wf->nBlockAlign; |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
603 l = sh_audio->wf->nAvgBytesPerSec; |
17554 | 604 if (align) |
605 l = (l + align - 1) / align * align; | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
606 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
|
607 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
|
608 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
|
609 break; |
4694 | 610 } |
11004 | 611 case fLaC: { |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
612 l = 65535; |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
613 dp = new_demux_packet(l); |
11004 | 614 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
|
615 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
|
616 break; |
11004 | 617 } |
4694 | 618 default: |
18176
f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents:
18117
diff
changeset
|
619 mp_msg(MSGT_DEMUXER,MSGL_WARN,MSGTR_MPDEMUX_AUDIO_UnknownFormat,priv->frmt); |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
620 return 0; |
4694 | 621 } |
622 | |
14608
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
623 resize_demux_packet(dp, l); |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
624 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
|
625 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
|
626 ds_add_packet(ds, dp); |
9595f1de1393
Fix possible hang when playing broken MP3 from linear stream and remove
reimar
parents:
13503
diff
changeset
|
627 return 1; |
4694 | 628 } |
629 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
630 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
|
631 uint8_t hdr[4]; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
632 int len,nf; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
633 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
|
634 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
|
635 |
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
|
636 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
|
637 while(nf > 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
638 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
|
639 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
|
640 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
641 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
|
642 continue; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
643 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
644 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
|
645 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
|
646 nf--; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
647 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
648 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
649 |
17636 | 650 static void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ |
4694 | 651 sh_audio_t* sh_audio; |
652 stream_t* s; | |
653 int base,pos; | |
654 float len; | |
655 da_priv_t* priv; | |
656 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
657 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
|
658 return; |
4694 | 659 s = demuxer->stream; |
660 priv = demuxer->priv; | |
661 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
662 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
|
663 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
|
664 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
665 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
|
666 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
|
667 priv->last_pts = 0; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
668 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
669 if(len > 0) |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
670 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
|
671 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
|
672 return; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
673 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
674 |
5796 | 675 base = flags&1 ? demuxer->movi_start : stream_tell(s); |
676 if(flags&2) | |
677 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); | |
678 else | |
679 pos = base + (rel_seek_secs*sh_audio->i_bps); | |
4694 | 680 |
681 if(demuxer->movi_end && pos >= demuxer->movi_end) { | |
8359 | 682 pos = demuxer->movi_end; |
683 //sh_audio->delay = (stream_tell(s) - demuxer->movi_start)/(float)sh_audio->i_bps; | |
684 //return; | |
4694 | 685 } else if(pos < demuxer->movi_start) |
686 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
|
687 |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
688 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
|
689 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 690 |
691 switch(priv->frmt) { | |
692 case WAV: | |
16818
67ce689b5764
Fix seeking in wav files: align relative to start of data, not start of file
reimar
parents:
16438
diff
changeset
|
693 pos -= (pos - demuxer->movi_start) % |
67ce689b5764
Fix seeking in wav files: align relative to start of data, not start of file
reimar
parents:
16438
diff
changeset
|
694 (sh_audio->wf->nBlockAlign ? sh_audio->wf->nBlockAlign : |
67ce689b5764
Fix seeking in wav files: align relative to start of data, not start of file
reimar
parents:
16438
diff
changeset
|
695 (sh_audio->channels * sh_audio->samplesize)); |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
696 // 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
|
697 priv->last_pts -= sh_audio->wf->nAvgBytesPerSec/(float)sh_audio->i_bps; |
4694 | 698 break; |
699 } | |
700 | |
701 stream_seek(s,pos); | |
702 } | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
703 |
16175 | 704 static void demux_close_audio(demuxer_t* demuxer) { |
5812 | 705 da_priv_t* priv = demuxer->priv; |
706 | |
707 if(!priv) | |
708 return; | |
709 free(priv); | |
710 } | |
711 | |
16175 | 712 static int demux_audio_control(demuxer_t *demuxer,int cmd, void *arg){ |
10882
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
713 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
|
714 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
|
715 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
|
716 |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
717 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
|
718 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
|
719 if (audio_length<=0) return DEMUXER_CTRL_DONTKNOW; |
16346
6ff303d2876b
Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents:
16175
diff
changeset
|
720 *((double *)arg)=(double)audio_length; |
10882
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
721 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
|
722 |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
723 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
|
724 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
|
725 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
|
726 *((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
|
727 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
|
728 |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
729 default: |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
730 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
|
731 } |
e46e5a6c53b8
get_percent_pos support in demux_audio, patch by ROSEN Jeremy <jeremy.rosen at c-s.fr>
faust3
parents:
10244
diff
changeset
|
732 } |
16175 | 733 |
734 | |
735 demuxer_desc_t demuxer_desc_audio = { | |
736 "Audio demuxer", | |
737 "audio", | |
738 "Audio file", | |
739 "?", | |
740 "Audio only files", | |
741 DEMUXER_TYPE_AUDIO, | |
742 0, // unsafe autodetect | |
743 demux_audio_open, | |
744 demux_audio_fill_buffer, | |
745 NULL, | |
746 demux_close_audio, | |
747 demux_audio_seek, | |
748 demux_audio_control | |
749 }; |