Mercurial > mplayer.hg
annotate libmpdemux/demuxer.c @ 27194:fd1872d2b2d4
avoid unnecessary strdup(); patch by Aurel
author | nicodvb |
---|---|
date | Sun, 06 Jul 2008 18:04:14 +0000 |
parents | 3771c9d8daf6 |
children | 16beae919ff1 |
rev | line source |
---|---|
1 | 1 //=================== DEMUXER v2.5 ========================= |
2 | |
1430 | 3 #include <stdio.h> |
4 #include <stdlib.h> | |
3150 | 5 #include <string.h> |
1430 | 6 #include <unistd.h> |
7 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1421
diff
changeset
|
8 #include <sys/types.h> |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1421
diff
changeset
|
9 #include <sys/stat.h> |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1421
diff
changeset
|
10 |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
11 #include "config.h" |
1567 | 12 #include "mp_msg.h" |
1584 | 13 #include "help_mp.h" |
17012 | 14 #include "m_config.h" |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
15 |
17200
a1b8eeffdfcd
include fastmemcpy.h before stream.h, so it is used for the stream_read
reimar
parents:
17012
diff
changeset
|
16 #include "libvo/fastmemcpy.h" |
a1b8eeffdfcd
include fastmemcpy.h before stream.h, so it is used for the stream_read
reimar
parents:
17012
diff
changeset
|
17 |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
22488
diff
changeset
|
18 #include "stream/stream.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
19 #include "demuxer.h" |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
20 #include "stheader.h" |
4551 | 21 #include "mf.h" |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
22 |
17012 | 23 #include "libaf/af_format.h" |
5084 | 24 |
25654
0190aa38aae2
Init and destroy ass_tracks in demuxer.c based on sh_sub->type value.
eugeni
parents:
25652
diff
changeset
|
25 #ifdef USE_ASS |
0190aa38aae2
Init and destroy ass_tracks in demuxer.c based on sh_sub->type value.
eugeni
parents:
25652
diff
changeset
|
26 #include "libass/ass.h" |
0190aa38aae2
Init and destroy ass_tracks in demuxer.c based on sh_sub->type value.
eugeni
parents:
25652
diff
changeset
|
27 #include "libass/ass_mp.h" |
0190aa38aae2
Init and destroy ass_tracks in demuxer.c based on sh_sub->type value.
eugeni
parents:
25652
diff
changeset
|
28 #endif |
0190aa38aae2
Init and destroy ass_tracks in demuxer.c based on sh_sub->type value.
eugeni
parents:
25652
diff
changeset
|
29 |
22142
84f95595f31f
Fix a few gcc warnings, approved by Diego and Reimar.
rathann
parents:
21809
diff
changeset
|
30 extern void resync_video_stream(sh_video_t *sh_video); |
16877
9081ae3a702c
move resync_audio_stream after seeking to demuxer.c
reimar
parents:
16572
diff
changeset
|
31 extern void resync_audio_stream(sh_audio_t *sh_audio); |
16175 | 32 |
33 // Demuxer list | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
34 extern const demuxer_desc_t demuxer_desc_rawaudio; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
35 extern const demuxer_desc_t demuxer_desc_rawvideo; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
36 extern const demuxer_desc_t demuxer_desc_tv; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
37 extern const demuxer_desc_t demuxer_desc_mf; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
38 extern const demuxer_desc_t demuxer_desc_avi; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
39 extern const demuxer_desc_t demuxer_desc_y4m; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
40 extern const demuxer_desc_t demuxer_desc_asf; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
41 extern const demuxer_desc_t demuxer_desc_nuv; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
42 extern const demuxer_desc_t demuxer_desc_real; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
43 extern const demuxer_desc_t demuxer_desc_smjpeg; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
44 extern const demuxer_desc_t demuxer_desc_matroska; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
45 extern const demuxer_desc_t demuxer_desc_realaudio; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
46 extern const demuxer_desc_t demuxer_desc_vqf; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
47 extern const demuxer_desc_t demuxer_desc_mov; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
48 extern const demuxer_desc_t demuxer_desc_vivo; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
49 extern const demuxer_desc_t demuxer_desc_fli; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
50 extern const demuxer_desc_t demuxer_desc_film; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
51 extern const demuxer_desc_t demuxer_desc_roq; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
52 extern const demuxer_desc_t demuxer_desc_gif; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
53 extern const demuxer_desc_t demuxer_desc_ogg; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
54 extern const demuxer_desc_t demuxer_desc_avs; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
55 extern const demuxer_desc_t demuxer_desc_pva; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
56 extern const demuxer_desc_t demuxer_desc_nsv; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
57 extern const demuxer_desc_t demuxer_desc_mpeg_ts; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
58 extern const demuxer_desc_t demuxer_desc_lmlm4; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
59 extern const demuxer_desc_t demuxer_desc_mpeg_ps; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
60 extern const demuxer_desc_t demuxer_desc_mpeg_pes; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
61 extern const demuxer_desc_t demuxer_desc_mpeg_es; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
62 extern const demuxer_desc_t demuxer_desc_mpeg_gxf; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
63 extern const demuxer_desc_t demuxer_desc_mpeg4_es; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
64 extern const demuxer_desc_t demuxer_desc_h264_es; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
65 extern const demuxer_desc_t demuxer_desc_rawdv; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
66 extern const demuxer_desc_t demuxer_desc_mpc; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
67 extern const demuxer_desc_t demuxer_desc_audio; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
68 extern const demuxer_desc_t demuxer_desc_xmms; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
69 extern const demuxer_desc_t demuxer_desc_mpeg_ty; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
70 extern const demuxer_desc_t demuxer_desc_rtp; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
71 extern const demuxer_desc_t demuxer_desc_rtp_nemesi; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
72 extern const demuxer_desc_t demuxer_desc_lavf; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
73 extern const demuxer_desc_t demuxer_desc_lavf_preferred; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
74 extern const demuxer_desc_t demuxer_desc_aac; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25706
diff
changeset
|
75 extern const demuxer_desc_t demuxer_desc_nut; |
16175 | 76 |
25876
edfe8baed49f
copy note on new demuxers and codecs to the top of the array as well to be
ivo
parents:
25872
diff
changeset
|
77 /* Please do not add any new demuxers here. If you want to implement a new |
25880
4df11ac927fc
clarify comments/docs about lav* being the preferred place to implement new
ivo
parents:
25876
diff
changeset
|
78 * demuxer, add it to libavformat, except for wrappers around external |
4df11ac927fc
clarify comments/docs about lav* being the preferred place to implement new
ivo
parents:
25876
diff
changeset
|
79 * libraries and demuxers requiring binary support. */ |
25876
edfe8baed49f
copy note on new demuxers and codecs to the top of the array as well to be
ivo
parents:
25872
diff
changeset
|
80 |
27054 | 81 const demuxer_desc_t *const demuxer_list[] = { |
27055 | 82 &demuxer_desc_rawaudio, |
83 &demuxer_desc_rawvideo, | |
16175 | 84 #ifdef USE_TV |
27055 | 85 &demuxer_desc_tv, |
16175 | 86 #endif |
27055 | 87 &demuxer_desc_mf, |
23121
a257dd426da5
Simplify preprocessor directives: There is a general variable for
diego
parents:
23072
diff
changeset
|
88 #ifdef USE_LIBAVFORMAT |
27055 | 89 &demuxer_desc_lavf_preferred, |
23069
93948eb0280f
demuxer_desc_lavf_preferred depends on USE_LIBAVFORMAT or USE_LIBAVFORMAT_SO
nicodvb
parents:
22971
diff
changeset
|
90 #endif |
27055 | 91 &demuxer_desc_avi, |
92 &demuxer_desc_y4m, | |
93 &demuxer_desc_asf, | |
94 &demuxer_desc_nsv, | |
95 &demuxer_desc_nuv, | |
96 &demuxer_desc_real, | |
97 &demuxer_desc_smjpeg, | |
98 &demuxer_desc_matroska, | |
99 &demuxer_desc_realaudio, | |
100 &demuxer_desc_vqf, | |
101 &demuxer_desc_mov, | |
102 &demuxer_desc_vivo, | |
103 &demuxer_desc_fli, | |
104 &demuxer_desc_film, | |
105 &demuxer_desc_roq, | |
16175 | 106 #ifdef HAVE_GIF |
27055 | 107 &demuxer_desc_gif, |
16175 | 108 #endif |
109 #ifdef HAVE_OGGVORBIS | |
27055 | 110 &demuxer_desc_ogg, |
16175 | 111 #endif |
112 #ifdef USE_WIN32DLL | |
27055 | 113 &demuxer_desc_avs, |
16175 | 114 #endif |
27055 | 115 &demuxer_desc_pva, |
116 &demuxer_desc_mpeg_ts, | |
117 &demuxer_desc_lmlm4, | |
118 &demuxer_desc_mpeg_ps, | |
119 &demuxer_desc_mpeg_pes, | |
120 &demuxer_desc_mpeg_es, | |
121 &demuxer_desc_mpeg_gxf, | |
122 &demuxer_desc_mpeg4_es, | |
123 &demuxer_desc_h264_es, | |
124 &demuxer_desc_audio, | |
125 &demuxer_desc_mpeg_ty, | |
25266
239330301b33
Make libnemesi use specific struct and DEMUXER_TYPE
lu_zero
parents:
25197
diff
changeset
|
126 #ifdef STREAMING_LIVE555 |
27055 | 127 &demuxer_desc_rtp, |
16175 | 128 #endif |
25266
239330301b33
Make libnemesi use specific struct and DEMUXER_TYPE
lu_zero
parents:
25197
diff
changeset
|
129 #ifdef LIBNEMESI |
27055 | 130 &demuxer_desc_rtp_nemesi, |
25266
239330301b33
Make libnemesi use specific struct and DEMUXER_TYPE
lu_zero
parents:
25197
diff
changeset
|
131 #endif |
23121
a257dd426da5
Simplify preprocessor directives: There is a general variable for
diego
parents:
23072
diff
changeset
|
132 #ifdef USE_LIBAVFORMAT |
27055 | 133 &demuxer_desc_lavf, |
16175 | 134 #endif |
26873
a90971b955af
Move native musepack demuxer further down in demuxer list
reimar
parents:
26758
diff
changeset
|
135 #ifdef MUSEPACK |
27055 | 136 &demuxer_desc_mpc, |
26873
a90971b955af
Move native musepack demuxer further down in demuxer list
reimar
parents:
26758
diff
changeset
|
137 #endif |
18900
0b53e6d1b27f
move some ill-behaving demuxers further down the list
reimar
parents:
18708
diff
changeset
|
138 #ifdef HAVE_LIBDV095 |
27055 | 139 &demuxer_desc_rawdv, |
18900
0b53e6d1b27f
move some ill-behaving demuxers further down the list
reimar
parents:
18708
diff
changeset
|
140 #endif |
27055 | 141 &demuxer_desc_aac, |
19861 | 142 #ifdef HAVE_LIBNUT |
27055 | 143 &demuxer_desc_nut, |
19861 | 144 #endif |
18900
0b53e6d1b27f
move some ill-behaving demuxers further down the list
reimar
parents:
18708
diff
changeset
|
145 #ifdef HAVE_XMMS |
27055 | 146 &demuxer_desc_xmms, |
18900
0b53e6d1b27f
move some ill-behaving demuxers further down the list
reimar
parents:
18708
diff
changeset
|
147 #endif |
27055 | 148 /* Please do not add any new demuxers here. If you want to implement a new |
149 * demuxer, add it to libavformat, except for wrappers around external | |
150 * libraries and demuxers requiring binary support. */ | |
151 NULL | |
16175 | 152 }; |
153 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
154 void free_demuxer_stream(demux_stream_t *ds) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
155 { |
1643 | 156 ds_free_packs(ds); |
157 free(ds); | |
158 } | |
159 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
160 demux_stream_t *new_demuxer_stream(struct demuxer_st *demuxer, int id) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
161 { |
27055 | 162 demux_stream_t *ds = malloc(sizeof(demux_stream_t)); |
163 ds->buffer_pos = ds->buffer_size = 0; | |
164 ds->buffer = NULL; | |
165 ds->pts = 0; | |
166 ds->pts_bytes = 0; | |
167 ds->eof = 0; | |
168 ds->pos = 0; | |
169 ds->dpos = 0; | |
170 ds->pack_no = 0; | |
27045 | 171 |
27055 | 172 ds->packs = 0; |
173 ds->bytes = 0; | |
174 ds->first = ds->last = ds->current = NULL; | |
175 ds->id = id; | |
176 ds->demuxer = demuxer; | |
27045 | 177 |
27055 | 178 ds->asf_seq = -1; |
179 ds->asf_packet = NULL; | |
27045 | 180 |
27055 | 181 ds->ss_mul = ds->ss_div = 0; |
27045 | 182 |
27055 | 183 ds->sh = NULL; |
184 return ds; | |
1 | 185 } |
186 | |
16175 | 187 |
188 /** | |
189 * Get demuxer description structure for a given demuxer type | |
190 * | |
191 * @param file_format type of the demuxer | |
192 * @return structure for the demuxer, NULL if not found | |
193 */ | |
27054 | 194 static const demuxer_desc_t *get_demuxer_desc_from_type(int file_format) |
16175 | 195 { |
27055 | 196 int i; |
16175 | 197 |
27055 | 198 for (i = 0; demuxer_list[i]; i++) |
199 if (file_format == demuxer_list[i]->type) | |
200 return demuxer_list[i]; | |
16175 | 201 |
27055 | 202 return NULL; |
16175 | 203 } |
204 | |
205 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
206 demuxer_t *new_demuxer(stream_t *stream, int type, int a_id, int v_id, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
207 int s_id, char *filename) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
208 { |
27055 | 209 demuxer_t *d = malloc(sizeof(demuxer_t)); |
210 memset(d, 0, sizeof(demuxer_t)); | |
211 d->stream = stream; | |
212 d->stream_pts = MP_NOPTS_VALUE; | |
213 d->reference_clock = MP_NOPTS_VALUE; | |
214 d->movi_start = stream->start_pos; | |
215 d->movi_end = stream->end_pos; | |
216 d->seekable = 1; | |
217 d->synced = 0; | |
218 d->filepos = 0; | |
219 d->audio = new_demuxer_stream(d, a_id); | |
220 d->video = new_demuxer_stream(d, v_id); | |
221 d->sub = new_demuxer_stream(d, s_id); | |
222 d->type = type; | |
223 if (type) | |
224 if (!(d->desc = get_demuxer_desc_from_type(type))) | |
27056 | 225 mp_msg(MSGT_DEMUXER, MSGL_ERR, |
226 "BUG! Invalid demuxer type in new_demuxer(), " | |
227 "big troubles ahead."); | |
27055 | 228 if (filename) // Filename hack for avs_check_file |
229 d->filename = strdup(filename); | |
230 stream_reset(stream); | |
231 stream_seek(stream, stream->start_pos); | |
232 return d; | |
1 | 233 } |
234 | |
24022
4d576e0ed40b
When a new subtitle stream becomes available check if it is the one that
reimar
parents:
23865
diff
changeset
|
235 extern int dvdsub_id; |
4d576e0ed40b
When a new subtitle stream becomes available check if it is the one that
reimar
parents:
23865
diff
changeset
|
236 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
237 sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
238 { |
27055 | 239 if (id > MAX_S_STREAMS - 1 || id < 0) { |
27056 | 240 mp_msg(MSGT_DEMUXER, MSGL_WARN, |
241 "Requested sub stream id overflow (%d > %d)\n", id, | |
242 MAX_S_STREAMS); | |
27055 | 243 return NULL; |
244 } | |
245 if (demuxer->s_streams[id]) | |
246 mp_msg(MSGT_DEMUXER, MSGL_WARN, "Sub stream %i redefined\n", id); | |
247 else { | |
248 sh_sub_t *sh = calloc(1, sizeof(sh_sub_t)); | |
249 demuxer->s_streams[id] = sh; | |
250 sh->sid = sid; | |
251 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid); | |
252 } | |
253 return demuxer->s_streams[id]; | |
20872
a8b42366e68a
Make subtitle stream handling more similar to audio and video streams.
reimar
parents:
20851
diff
changeset
|
254 } |
a8b42366e68a
Make subtitle stream handling more similar to audio and video streams.
reimar
parents:
20851
diff
changeset
|
255 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
256 void free_sh_sub(sh_sub_t *sh) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
257 { |
23592 | 258 mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh); |
26085 | 259 free(sh->extradata); |
25702
c4275201a489
Add a forgotten #ifdef USE_ASS around ass_free_track
reimar
parents:
25657
diff
changeset
|
260 #ifdef USE_ASS |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
261 if (sh->ass_track) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
262 ass_free_track(sh->ass_track); |
25702
c4275201a489
Add a forgotten #ifdef USE_ASS around ass_free_track
reimar
parents:
25657
diff
changeset
|
263 #endif |
26082 | 264 free(sh->lang); |
23592 | 265 free(sh); |
266 } | |
267 | |
27054 | 268 sh_audio_t *new_sh_audio_aid(demuxer_t *demuxer, int id, int aid) |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
269 { |
27055 | 270 if (id > MAX_A_STREAMS - 1 || id < 0) { |
27056 | 271 mp_msg(MSGT_DEMUXER, MSGL_WARN, |
272 "Requested audio stream id overflow (%d > %d)\n", id, | |
273 MAX_A_STREAMS); | |
27052 | 274 return NULL; |
4642 | 275 } |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
276 if (demuxer->a_streams[id]) |
27055 | 277 mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_AudioStreamRedefined, id); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
278 else { |
26874 | 279 sh_audio_t *sh = calloc(1, sizeof(sh_audio_t)); |
27055 | 280 mp_msg(MSGT_DEMUXER, MSGL_V, MSGTR_FoundAudioStream, id); |
26874 | 281 demuxer->a_streams[id] = sh; |
26875
c276296cb6f8
Simplify/make new_sh behaviour more consistent when a stream gets redefined.
reimar
parents:
26874
diff
changeset
|
282 sh->aid = aid; |
26876 | 283 sh->ds = demuxer->audio; |
13357
c605df89ca9f
moved sh_audio initialization from dec_audio to demuxer.c to fix
reimar
parents:
13301
diff
changeset
|
284 // set some defaults |
27055 | 285 sh->samplesize = 2; |
286 sh->sample_format = AF_FORMAT_S16_NE; | |
287 sh->audio_out_minsize = 8192; /* default size, maybe not enough for Win32/ACM */ | |
288 sh->pts = MP_NOPTS_VALUE; | |
289 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid); | |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
290 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
291 return demuxer->a_streams[id]; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
292 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
293 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
294 void free_sh_audio(demuxer_t *demuxer, int id) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
295 { |
18708
9e2b300db17b
Change free_sh_audio() to take demuxer and stream id as parameters
uau
parents:
18404
diff
changeset
|
296 sh_audio_t *sh = demuxer->a_streams[id]; |
9e2b300db17b
Change free_sh_audio() to take demuxer and stream id as parameters
uau
parents:
18404
diff
changeset
|
297 demuxer->a_streams[id] = NULL; |
27055 | 298 mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_audio at %p\n", sh); |
26085 | 299 free(sh->wf); |
300 free(sh->codecdata); | |
26082 | 301 free(sh->lang); |
1643 | 302 free(sh); |
303 } | |
304 | |
27054 | 305 sh_video_t *new_sh_video_vid(demuxer_t *demuxer, int id, int vid) |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
306 { |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
307 if (id > MAX_V_STREAMS - 1 || id < 0) { |
27056 | 308 mp_msg(MSGT_DEMUXER, MSGL_WARN, |
309 "Requested video stream id overflow (%d > %d)\n", id, | |
310 MAX_V_STREAMS); | |
27052 | 311 return NULL; |
4642 | 312 } |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
313 if (demuxer->v_streams[id]) |
27055 | 314 mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_VideoStreamRedefined, id); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
315 else { |
26875
c276296cb6f8
Simplify/make new_sh behaviour more consistent when a stream gets redefined.
reimar
parents:
26874
diff
changeset
|
316 sh_video_t *sh = calloc(1, sizeof(sh_video_t)); |
27055 | 317 mp_msg(MSGT_DEMUXER, MSGL_V, MSGTR_FoundVideoStream, id); |
26875
c276296cb6f8
Simplify/make new_sh behaviour more consistent when a stream gets redefined.
reimar
parents:
26874
diff
changeset
|
318 demuxer->v_streams[id] = sh; |
c276296cb6f8
Simplify/make new_sh behaviour more consistent when a stream gets redefined.
reimar
parents:
26874
diff
changeset
|
319 sh->vid = vid; |
26876 | 320 sh->ds = demuxer->video; |
27055 | 321 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ID=%d\n", vid); |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
322 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
323 return demuxer->v_streams[id]; |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
324 } |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
325 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
326 void free_sh_video(sh_video_t *sh) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
327 { |
27055 | 328 mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_video at %p\n", sh); |
26085 | 329 free(sh->bih); |
1643 | 330 free(sh); |
331 } | |
332 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
333 void free_demuxer(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
334 { |
1643 | 335 int i; |
27056 | 336 mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing demuxer at %p\n", |
337 demuxer); | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
338 if (demuxer->desc->close) |
27055 | 339 demuxer->desc->close(demuxer); |
16175 | 340 // Very ugly hack to make it behave like old implementation |
341 if (demuxer->desc->type == DEMUXER_TYPE_DEMUXERS) | |
27055 | 342 goto skip_streamfree; |
1643 | 343 // free streams: |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
344 for (i = 0; i < MAX_A_STREAMS; i++) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
345 if (demuxer->a_streams[i]) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
346 free_sh_audio(demuxer, i); |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
347 for (i = 0; i < MAX_V_STREAMS; i++) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
348 if (demuxer->v_streams[i]) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
349 free_sh_video(demuxer->v_streams[i]); |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
350 for (i = 0; i < MAX_S_STREAMS; i++) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
351 if (demuxer->s_streams[i]) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
352 free_sh_sub(demuxer->s_streams[i]); |
1643 | 353 // free demuxers: |
354 free_demuxer_stream(demuxer->audio); | |
355 free_demuxer_stream(demuxer->video); | |
5412 | 356 free_demuxer_stream(demuxer->sub); |
27055 | 357 skip_streamfree: |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
358 if (demuxer->info) { |
27055 | 359 for (i = 0; demuxer->info[i] != NULL; i++) |
360 free(demuxer->info[i]); | |
361 free(demuxer->info); | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
4660
diff
changeset
|
362 } |
26085 | 363 free(demuxer->filename); |
19342 | 364 if (demuxer->chapters) { |
27055 | 365 for (i = 0; i < demuxer->num_chapters; i++) |
366 free(demuxer->chapters[i].name); | |
367 free(demuxer->chapters); | |
19342 | 368 } |
25657 | 369 if (demuxer->attachments) { |
27055 | 370 for (i = 0; i < demuxer->num_attachments; i++) { |
371 free(demuxer->attachments[i].name); | |
372 free(demuxer->attachments[i].type); | |
373 free(demuxer->attachments[i].data); | |
374 } | |
375 free(demuxer->attachments); | |
25657 | 376 } |
1643 | 377 free(demuxer); |
378 } | |
379 | |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
380 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
381 void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
382 { |
1 | 383 // append packet to DS stream: |
384 ++ds->packs; | |
27055 | 385 ds->bytes += dp->len; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
386 if (ds->last) { |
27055 | 387 // next packet in stream |
388 ds->last->next = dp; | |
389 ds->last = dp; | |
1 | 390 } else { |
27055 | 391 // first packet in stream |
392 ds->first = ds->last = dp; | |
1 | 393 } |
27056 | 394 mp_dbg(MSGT_DEMUXER, MSGL_DBG2, |
395 "DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%u [packs: A=%d V=%d]\n", | |
396 (ds == ds->demuxer->audio) ? "d_audio" : "d_video", dp->len, | |
397 dp->pts, (unsigned int) dp->pos, ds->demuxer->audio->packs, | |
398 ds->demuxer->video->packs); | |
1 | 399 } |
400 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
401 void ds_read_packet(demux_stream_t *ds, stream_t *stream, int len, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
402 double pts, off_t pos, int flags) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
403 { |
27055 | 404 demux_packet_t *dp = new_demux_packet(len); |
405 len = stream_read(stream, dp->buffer, len); | |
10891
65ed62e138fa
Fixed 'reading after EOF'. demuxers didn't check, how many they've read!
lumag
parents:
10882
diff
changeset
|
406 resize_demux_packet(dp, len); |
27045 | 407 dp->pts = pts; |
27055 | 408 dp->pos = pos; |
409 dp->flags = flags; | |
1 | 410 // append packet to DS stream: |
27055 | 411 ds_add_packet(ds, dp); |
1 | 412 } |
413 | |
414 // return value: | |
415 // 0 = EOF or no stream found or invalid type | |
416 // 1 = successfully read a packet | |
417 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
418 int demux_fill_buffer(demuxer_t *demux, demux_stream_t *ds) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
419 { |
27055 | 420 // Note: parameter 'ds' can be NULL! |
421 return demux->desc->fill_buffer(demux, ds); | |
1 | 422 } |
423 | |
424 // return value: | |
425 // 0 = EOF | |
25197
eb2c5925ec34
Fix typos in comments to stop them hurting my eyes
reimar
parents:
24826
diff
changeset
|
426 // 1 = successful |
26037 | 427 #define MAX_ACUMULATED_PACKETS 64 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
428 int ds_fill_buffer(demux_stream_t *ds) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
429 { |
27055 | 430 demuxer_t *demux = ds->demuxer; |
431 if (ds->current) | |
432 free_demux_packet(ds->current); | |
433 ds->current = NULL; | |
434 if (mp_msg_test(MSGT_DEMUXER, MSGL_DBG3)) { | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
435 if (ds == demux->audio) |
27056 | 436 mp_dbg(MSGT_DEMUXER, MSGL_DBG3, |
437 "ds_fill_buffer(d_audio) called\n"); | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
438 else if (ds == demux->video) |
27056 | 439 mp_dbg(MSGT_DEMUXER, MSGL_DBG3, |
440 "ds_fill_buffer(d_video) called\n"); | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
441 else if (ds == demux->sub) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
442 mp_dbg(MSGT_DEMUXER, MSGL_DBG3, "ds_fill_buffer(d_sub) called\n"); |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
443 else |
27056 | 444 mp_dbg(MSGT_DEMUXER, MSGL_DBG3, |
445 "ds_fill_buffer(unknown 0x%X) called\n", (unsigned int) ds); | |
27055 | 446 } |
447 while (1) { | |
448 if (ds->packs) { | |
449 demux_packet_t *p = ds->first; | |
26071
449ad51bd8c7
in ds_fill_buffer() disabled the code that demuxes until the arrival of the right reference_clock
nicodvb
parents:
26037
diff
changeset
|
450 #if 0 |
27055 | 451 if (demux->reference_clock != MP_NOPTS_VALUE) { |
27059 | 452 if ( p->pts != MP_NOPTS_VALUE |
453 && p->pts > demux->reference_clock | |
454 && ds->packs < MAX_ACUMULATED_PACKETS) { | |
27055 | 455 if (demux_fill_buffer(demux, ds)) |
456 continue; | |
457 } | |
458 } | |
26071
449ad51bd8c7
in ds_fill_buffer() disabled the code that demuxes until the arrival of the right reference_clock
nicodvb
parents:
26037
diff
changeset
|
459 #endif |
27055 | 460 // copy useful data: |
461 ds->buffer = p->buffer; | |
462 ds->buffer_pos = 0; | |
463 ds->buffer_size = p->len; | |
464 ds->pos = p->pos; | |
465 ds->dpos += p->len; // !!! | |
466 ++ds->pack_no; | |
467 if (p->pts != MP_NOPTS_VALUE) { | |
468 ds->pts = p->pts; | |
469 ds->pts_bytes = 0; | |
470 } | |
471 ds->pts_bytes += p->len; // !!! | |
472 if (p->stream_pts != MP_NOPTS_VALUE) | |
473 demux->stream_pts = p->stream_pts; | |
474 ds->flags = p->flags; | |
475 // unlink packet: | |
476 ds->bytes -= p->len; | |
477 ds->current = p; | |
478 ds->first = p->next; | |
479 if (!ds->first) | |
480 ds->last = NULL; | |
481 --ds->packs; | |
482 return 1; | |
483 } | |
27056 | 484 if (demux->audio->packs >= MAX_PACKS |
485 || demux->audio->bytes >= MAX_PACK_BYTES) { | |
486 mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyAudioInBuffer, | |
487 demux->audio->packs, demux->audio->bytes); | |
27055 | 488 mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI); |
489 break; | |
490 } | |
27056 | 491 if (demux->video->packs >= MAX_PACKS |
492 || demux->video->bytes >= MAX_PACK_BYTES) { | |
493 mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyVideoInBuffer, | |
494 demux->video->packs, demux->video->bytes); | |
27055 | 495 mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI); |
496 break; | |
497 } | |
498 if (!demux_fill_buffer(demux, ds)) { | |
27056 | 499 mp_dbg(MSGT_DEMUXER, MSGL_DBG2, |
500 "ds_fill_buffer()->demux_fill_buffer() failed\n"); | |
27055 | 501 break; // EOF |
502 } | |
1 | 503 } |
27055 | 504 ds->buffer_pos = ds->buffer_size = 0; |
505 ds->buffer = NULL; | |
27056 | 506 mp_msg(MSGT_DEMUXER, MSGL_V, |
507 "ds_fill_buffer: EOF reached (stream: %s) \n", | |
508 ds == demux->audio ? "audio" : "video"); | |
27055 | 509 ds->eof = 1; |
510 return 0; | |
1 | 511 } |
512 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
513 int demux_read_data(demux_stream_t *ds, unsigned char *mem, int len) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
514 { |
27055 | 515 int x; |
516 int bytes = 0; | |
517 while (len > 0) { | |
518 x = ds->buffer_size - ds->buffer_pos; | |
519 if (x == 0) { | |
520 if (!ds_fill_buffer(ds)) | |
521 return bytes; | |
522 } else { | |
523 if (x > len) | |
524 x = len; | |
525 if (mem) | |
526 fast_memcpy(mem + bytes, &ds->buffer[ds->buffer_pos], x); | |
527 bytes += x; | |
528 len -= x; | |
529 ds->buffer_pos += x; | |
530 } | |
531 } | |
532 return bytes; | |
1 | 533 } |
534 | |
17417
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
535 /** |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
536 * \brief read data until the given 3-byte pattern is encountered, up to maxlen |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
537 * \param mem memory to read data into, may be NULL to discard data |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
538 * \param maxlen maximum number of bytes to read |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
539 * \param read number of bytes actually read |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
540 * \param pattern pattern to search for (lowest 8 bits are ignored) |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
541 * \return whether pattern was found |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
542 */ |
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
543 int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen, |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
544 int *read, uint32_t pattern) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
545 { |
27055 | 546 register uint32_t head = 0xffffff00; |
547 register uint32_t pat = pattern & 0xffffff00; | |
548 int total_len = 0; | |
17417
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
549 do { |
27055 | 550 register unsigned char *ds_buf = &ds->buffer[ds->buffer_size]; |
551 int len = ds->buffer_size - ds->buffer_pos; | |
552 register long pos = -len; | |
553 if (unlikely(pos >= 0)) { // buffer is empty | |
554 ds_fill_buffer(ds); | |
555 continue; | |
556 } | |
557 do { | |
558 head |= ds_buf[pos]; | |
559 head <<= 8; | |
560 } while (++pos && head != pat); | |
561 len += pos; | |
562 if (total_len + len > maxlen) | |
563 len = maxlen - total_len; | |
564 len = demux_read_data(ds, mem ? &mem[total_len] : NULL, len); | |
565 total_len += len; | |
566 } while ((head != pat || total_len < 3) && total_len < maxlen && !ds->eof); | |
567 if (read) | |
568 *read = total_len; | |
569 return total_len >= 3 && head == pat; | |
17417
960b2fa1567e
function to read from a demuxer up to (and including) the specified
reimar
parents:
17366
diff
changeset
|
570 } |
746 | 571 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
572 void ds_free_packs(demux_stream_t *ds) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
573 { |
27055 | 574 demux_packet_t *dp = ds->first; |
575 while (dp) { | |
576 demux_packet_t *dn = dp->next; | |
577 free_demux_packet(dp); | |
578 dp = dn; | |
579 } | |
580 if (ds->asf_packet) { | |
581 // free unfinished .asf fragments: | |
582 free(ds->asf_packet->buffer); | |
583 free(ds->asf_packet); | |
584 ds->asf_packet = NULL; | |
585 } | |
586 ds->first = ds->last = NULL; | |
587 ds->packs = 0; // !!!!! | |
588 ds->bytes = 0; | |
589 if (ds->current) | |
590 free_demux_packet(ds->current); | |
591 ds->current = NULL; | |
592 ds->buffer = NULL; | |
593 ds->buffer_pos = ds->buffer_size; | |
594 ds->pts = 0; | |
595 ds->pts_bytes = 0; | |
1 | 596 } |
597 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
598 int ds_get_packet(demux_stream_t *ds, unsigned char **start) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
599 { |
24826 | 600 int len; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
601 if (ds->buffer_pos >= ds->buffer_size) { |
27052 | 602 if (!ds_fill_buffer(ds)) { |
1 | 603 // EOF |
604 *start = NULL; | |
605 return -1; | |
27052 | 606 } |
1 | 607 } |
27055 | 608 len = ds->buffer_size - ds->buffer_pos; |
24826 | 609 *start = &ds->buffer[ds->buffer_pos]; |
27055 | 610 ds->buffer_pos += len; |
24826 | 611 return len; |
1 | 612 } |
554 | 613 |
27055 | 614 int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts) |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
615 { |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
616 int len; |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
617 *pts = MP_NOPTS_VALUE; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
618 if (ds->buffer_pos >= ds->buffer_size) { |
27052 | 619 if (!ds_fill_buffer(ds)) { |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
620 // EOF |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
621 *start = NULL; |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
622 return -1; |
27052 | 623 } |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
624 } |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18900
diff
changeset
|
625 // Return pts unless this read starts from the middle of a packet |
25956
7e4a2ab8b61c
Change to always use MP_NOPTS_VALUE (instead of sometimes 0) for unknown pts.
reimar
parents:
25919
diff
changeset
|
626 if (!ds->buffer_pos) |
27052 | 627 *pts = ds->current->pts; |
27055 | 628 len = ds->buffer_size - ds->buffer_pos; |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
629 *start = &ds->buffer[ds->buffer_pos]; |
27055 | 630 ds->buffer_pos += len; |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
631 return len; |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
632 } |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18237
diff
changeset
|
633 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
634 int ds_get_packet_sub(demux_stream_t *ds, unsigned char **start) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
635 { |
24826 | 636 int len; |
27055 | 637 if (ds->buffer_pos >= ds->buffer_size) { |
27052 | 638 *start = NULL; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
639 if (!ds->packs) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
640 return -1; // no sub |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
641 if (!ds_fill_buffer(ds)) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
642 return -1; // EOF |
554 | 643 } |
27055 | 644 len = ds->buffer_size - ds->buffer_pos; |
24826 | 645 *start = &ds->buffer[ds->buffer_pos]; |
27055 | 646 ds->buffer_pos += len; |
24826 | 647 return len; |
554 | 648 } |
649 | |
18309
87161f96fa66
Change common pts variables from floats to doubles. Individual demuxers
uau
parents:
18242
diff
changeset
|
650 double ds_get_next_pts(demux_stream_t *ds) |
87161f96fa66
Change common pts variables from floats to doubles. Individual demuxers
uau
parents:
18242
diff
changeset
|
651 { |
27055 | 652 demuxer_t *demux = ds->demuxer; |
653 while (!ds->first) { | |
27056 | 654 if (demux->audio->packs >= MAX_PACKS |
655 || demux->audio->bytes >= MAX_PACK_BYTES) { | |
656 mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyAudioInBuffer, | |
657 demux->audio->packs, demux->audio->bytes); | |
27055 | 658 mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI); |
659 return MP_NOPTS_VALUE; | |
660 } | |
27056 | 661 if (demux->video->packs >= MAX_PACKS |
662 || demux->video->bytes >= MAX_PACK_BYTES) { | |
663 mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyVideoInBuffer, | |
664 demux->video->packs, demux->video->bytes); | |
27055 | 665 mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI); |
666 return MP_NOPTS_VALUE; | |
667 } | |
668 if (!demux_fill_buffer(demux, ds)) | |
669 return MP_NOPTS_VALUE; | |
5930
68cac7ecaf05
Fix frame_time for variable fps movies as it was the last frame duration.
albeu
parents:
5897
diff
changeset
|
670 } |
27055 | 671 return ds->first->pts; |
5930
68cac7ecaf05
Fix frame_time for variable fps movies as it was the last frame duration.
albeu
parents:
5897
diff
changeset
|
672 } |
68cac7ecaf05
Fix frame_time for variable fps movies as it was the last frame duration.
albeu
parents:
5897
diff
changeset
|
673 |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
674 // ==================================================================== |
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
675 |
16175 | 676 void demuxer_help(void) |
677 { | |
27055 | 678 int i; |
1375
dbcb5b5e1fae
file-format detection stuff moved out from mplayer.c to demuxer.c and dec_video.c
arpi
parents:
1331
diff
changeset
|
679 |
27055 | 680 mp_msg(MSGT_DEMUXER, MSGL_INFO, "Available demuxers:\n"); |
681 mp_msg(MSGT_DEMUXER, MSGL_INFO, " demuxer: type info: (comment)\n"); | |
682 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXERS\n"); | |
683 for (i = 0; demuxer_list[i]; i++) { | |
684 if (demuxer_list[i]->type > DEMUXER_TYPE_MAX) // Don't display special demuxers | |
685 continue; | |
686 if (demuxer_list[i]->comment && strlen(demuxer_list[i]->comment)) | |
687 mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %2d %s (%s)\n", | |
27056 | 688 demuxer_list[i]->name, demuxer_list[i]->type, |
689 demuxer_list[i]->info, demuxer_list[i]->comment); | |
27055 | 690 else |
691 mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %2d %s\n", | |
27056 | 692 demuxer_list[i]->name, demuxer_list[i]->type, |
693 demuxer_list[i]->info); | |
27055 | 694 } |
16175 | 695 } |
696 | |
14693
37116118ab6a
avisynth demuxer patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents:
14666
diff
changeset
|
697 |
16175 | 698 /** |
699 * Get demuxer type for a given demuxer name | |
700 * | |
701 * @param demuxer_name string with demuxer name of demuxer number | |
16321
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16310
diff
changeset
|
702 * @param force will be set if demuxer should be forced. |
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16310
diff
changeset
|
703 * May be NULL. |
16175 | 704 * @return DEMUXER_TYPE_xxx, -1 if error or not found |
705 */ | |
16321
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16310
diff
changeset
|
706 int get_demuxer_type_from_name(char *demuxer_name, int *force) |
16175 | 707 { |
27055 | 708 int i; |
709 long type_int; | |
710 char *endptr; | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
5107
diff
changeset
|
711 |
27055 | 712 if (!demuxer_name || !demuxer_name[0]) |
713 return DEMUXER_TYPE_UNKNOWN; | |
714 if (force) | |
715 *force = demuxer_name[0] == '+'; | |
716 if (demuxer_name[0] == '+') | |
717 demuxer_name = &demuxer_name[1]; | |
718 for (i = 0; demuxer_list[i]; i++) { | |
719 if (demuxer_list[i]->type > DEMUXER_TYPE_MAX) // Can't select special demuxers from commandline | |
720 continue; | |
721 if (strcmp(demuxer_name, demuxer_list[i]->name) == 0) | |
722 return demuxer_list[i]->type; | |
723 } | |
16175 | 724 |
27055 | 725 // No match found, try to parse name as an integer (demuxer number) |
726 type_int = strtol(demuxer_name, &endptr, 0); | |
727 if (*endptr) // Conversion failed | |
728 return -1; | |
729 if ((type_int > 0) && (type_int <= DEMUXER_TYPE_MAX)) | |
730 return (int) type_int; | |
731 | |
26437 | 732 return -1; |
16175 | 733 } |
3801
3cea69dda1b3
added NuppelVideo demuxer, based on Panagiotis Issaris' patch
alex
parents:
3786
diff
changeset
|
734 |
27055 | 735 int extension_parsing = 1; // 0=off 1=mixed (used only for unstable formats) |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6192
diff
changeset
|
736 |
27055 | 737 int correct_pts = 0; |
738 int user_correct_pts = -1; | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18900
diff
changeset
|
739 |
9751
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
740 /* |
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
741 NOTE : Several demuxers may be opened at the same time so |
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
742 demuxers should NEVER rely on an external var to enable them |
25197
eb2c5925ec34
Fix typos in comments to stop them hurting my eyes
reimar
parents:
24826
diff
changeset
|
743 self. If a demuxer can't do any auto-detection it should only use |
eb2c5925ec34
Fix typos in comments to stop them hurting my eyes
reimar
parents:
24826
diff
changeset
|
744 file_format. The user can explicitly set file_format with the -demuxer |
9751
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
745 option so there is really no need for another extra var. |
25197
eb2c5925ec34
Fix typos in comments to stop them hurting my eyes
reimar
parents:
24826
diff
changeset
|
746 For convenience an option can be added to set file_format directly |
9751
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
747 to the right type (ex: rawaudio,rawvideo). |
25197
eb2c5925ec34
Fix typos in comments to stop them hurting my eyes
reimar
parents:
24826
diff
changeset
|
748 Also the stream can override the file_format so a demuxer which rely |
9751
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
749 on a special stream type can set file_format at the stream level |
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
750 (ex: tv,mf). |
00c97b0891e3
Fix all demuxers wich where using a global var to enable themself.
albeu
parents:
9709
diff
changeset
|
751 */ |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
752 |
27054 | 753 static demuxer_t *demux_open_stream(stream_t *stream, int file_format, |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
754 int force, int audio_id, int video_id, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
755 int dvdsub_id, char *filename) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
756 { |
27055 | 757 demuxer_t *demuxer = NULL; |
1659 | 758 |
27055 | 759 sh_video_t *sh_video = NULL; |
26437 | 760 |
27055 | 761 const demuxer_desc_t *demuxer_desc; |
762 int fformat = 0; | |
763 int i; | |
26437 | 764 |
27055 | 765 // If somebody requested a demuxer check it |
766 if (file_format) { | |
767 if ((demuxer_desc = get_demuxer_desc_from_type(file_format))) { | |
27056 | 768 demuxer = new_demuxer(stream, demuxer_desc->type, audio_id, |
769 video_id, dvdsub_id, filename); | |
27055 | 770 if (demuxer_desc->check_file) |
771 fformat = demuxer_desc->check_file(demuxer); | |
772 if (force || !demuxer_desc->check_file) | |
773 fformat = demuxer_desc->type; | |
774 if (fformat != 0) { | |
775 if (fformat == demuxer_desc->type) { | |
776 demuxer_t *demux2 = demuxer; | |
777 // Move messages to demuxer detection code? | |
27056 | 778 mp_msg(MSGT_DEMUXER, MSGL_INFO, |
779 MSGTR_Detected_XXX_FileFormat, | |
780 demuxer_desc->shortdesc); | |
27055 | 781 file_format = fformat; |
27056 | 782 if (!demuxer->desc->open |
783 || (demux2 = demuxer->desc->open(demuxer))) { | |
27055 | 784 demuxer = demux2; |
785 goto dmx_open; | |
786 } | |
787 } else { | |
788 // Format changed after check, recurse | |
789 free_demuxer(demuxer); | |
27056 | 790 return demux_open_stream(stream, fformat, force, audio_id, |
791 video_id, dvdsub_id, filename); | |
27055 | 792 } |
793 } | |
794 // Check failed for forced demuxer, quit | |
795 free_demuxer(demuxer); | |
796 return NULL; | |
20303 | 797 } |
798 } | |
27055 | 799 // Test demuxers with safe file checks |
800 for (i = 0; (demuxer_desc = demuxer_list[i]); i++) { | |
801 if (demuxer_desc->safe_check) { | |
27056 | 802 demuxer = new_demuxer(stream, demuxer_desc->type, audio_id, |
803 video_id, dvdsub_id, filename); | |
27055 | 804 if ((fformat = demuxer_desc->check_file(demuxer)) != 0) { |
805 if (fformat == demuxer_desc->type) { | |
806 demuxer_t *demux2 = demuxer; | |
27056 | 807 mp_msg(MSGT_DEMUXER, MSGL_INFO, |
808 MSGTR_Detected_XXX_FileFormat, | |
809 demuxer_desc->shortdesc); | |
27055 | 810 file_format = fformat; |
27056 | 811 if (!demuxer->desc->open |
812 || (demux2 = demuxer->desc->open(demuxer))) { | |
27055 | 813 demuxer = demux2; |
814 goto dmx_open; | |
815 } | |
816 } else { | |
817 if (fformat == DEMUXER_TYPE_PLAYLIST) | |
818 return demuxer; // handled in mplayer.c | |
819 // Format changed after check, recurse | |
820 free_demuxer(demuxer); | |
821 demuxer = demux_open_stream(stream, fformat, force, | |
27056 | 822 audio_id, video_id, |
823 dvdsub_id, filename); | |
27055 | 824 if (demuxer) |
825 return demuxer; // done! | |
826 file_format = DEMUXER_TYPE_UNKNOWN; | |
827 } | |
828 } | |
829 free_demuxer(demuxer); | |
830 demuxer = NULL; | |
26379 | 831 } |
832 } | |
9006
d00997f12257
extension-based filetype detection for headerless files (mp3 vs mpeg, etc)
arpi
parents:
8937
diff
changeset
|
833 |
27055 | 834 // If no forced demuxer perform file extension based detection |
27056 | 835 // Ok. We're over the stable detectable fileformats, the next ones are |
836 // a bit fuzzy. So by default (extension_parsing==1) try extension-based | |
837 // detection first: | |
838 if (file_format == DEMUXER_TYPE_UNKNOWN && filename | |
839 && extension_parsing == 1) { | |
27055 | 840 file_format = demuxer_type_by_filename(filename); |
841 if (file_format != DEMUXER_TYPE_UNKNOWN) { | |
842 // we like recursion :) | |
27056 | 843 demuxer = demux_open_stream(stream, file_format, force, audio_id, |
844 video_id, dvdsub_id, filename); | |
27055 | 845 if (demuxer) |
846 return demuxer; // done! | |
847 file_format = DEMUXER_TYPE_UNKNOWN; // continue fuzzy guessing... | |
27056 | 848 mp_msg(MSGT_DEMUXER, MSGL_V, |
849 "demuxer: continue fuzzy content-based format guessing...\n"); | |
26437 | 850 } |
851 } | |
27055 | 852 // Try detection for all other demuxers |
853 for (i = 0; (demuxer_desc = demuxer_list[i]); i++) { | |
854 if (!demuxer_desc->safe_check && demuxer_desc->check_file) { | |
27056 | 855 demuxer = new_demuxer(stream, demuxer_desc->type, audio_id, |
856 video_id, dvdsub_id, filename); | |
27055 | 857 if ((fformat = demuxer_desc->check_file(demuxer)) != 0) { |
858 if (fformat == demuxer_desc->type) { | |
859 demuxer_t *demux2 = demuxer; | |
27056 | 860 mp_msg(MSGT_DEMUXER, MSGL_INFO, |
861 MSGTR_Detected_XXX_FileFormat, | |
862 demuxer_desc->shortdesc); | |
27055 | 863 file_format = fformat; |
27056 | 864 if (!demuxer->desc->open |
865 || (demux2 = demuxer->desc->open(demuxer))) { | |
27055 | 866 demuxer = demux2; |
867 goto dmx_open; | |
868 } | |
869 } else { | |
870 if (fformat == DEMUXER_TYPE_PLAYLIST) | |
871 return demuxer; // handled in mplayer.c | |
872 // Format changed after check, recurse | |
873 free_demuxer(demuxer); | |
874 demuxer = demux_open_stream(stream, fformat, force, | |
27056 | 875 audio_id, video_id, |
876 dvdsub_id, filename); | |
27055 | 877 if (demuxer) |
878 return demuxer; // done! | |
879 file_format = DEMUXER_TYPE_UNKNOWN; | |
880 } | |
881 } | |
882 free_demuxer(demuxer); | |
883 demuxer = NULL; | |
884 } | |
885 } | |
26437 | 886 |
27055 | 887 return NULL; |
888 //====== File format recognized, set up these for compatibility: ========= | |
889 dmx_open: | |
890 | |
891 demuxer->file_format = file_format; | |
892 | |
893 if ((sh_video = demuxer->video->sh) && sh_video->bih) { | |
894 int biComp = le2me_32(sh_video->bih->biCompression); | |
27056 | 895 mp_msg(MSGT_DEMUX, MSGL_INFO, |
896 "VIDEO: [%.4s] %dx%d %dbpp %5.3f fps %5.1f kbps (%4.1f kbyte/s)\n", | |
897 (char *) &biComp, sh_video->bih->biWidth, | |
898 sh_video->bih->biHeight, sh_video->bih->biBitCount, | |
899 sh_video->fps, sh_video->i_bps * 0.008f, | |
27055 | 900 sh_video->i_bps / 1024.0f); |
901 } | |
26437 | 902 #ifdef USE_ASS |
27055 | 903 if (ass_enabled && ass_library) { |
904 for (i = 0; i < MAX_S_STREAMS; ++i) { | |
905 sh_sub_t *sh = demuxer->s_streams[i]; | |
906 if (sh && sh->type == 'a') { | |
907 sh->ass_track = ass_new_track(ass_library); | |
908 if (sh->ass_track && sh->extradata) | |
27056 | 909 ass_process_codec_private(sh->ass_track, sh->extradata, |
910 sh->extradata_len); | |
27055 | 911 } else if (sh && sh->type != 'v') |
912 sh->ass_track = ass_default_track(ass_library); | |
913 } | |
914 } | |
26437 | 915 #endif |
27055 | 916 return demuxer; |
26437 | 917 } |
918 | |
27054 | 919 char *audio_stream = NULL; |
27056 | 920 char *sub_stream = NULL; |
9709 | 921 int audio_stream_cache = 0; |
7867 | 922 |
27056 | 923 char *demuxer_name = NULL; // parameter from -demuxer |
16175 | 924 char *audio_demuxer_name = NULL; // parameter from -audio-demuxer |
27056 | 925 char *sub_demuxer_name = NULL; // parameter from -sub-demuxer |
16175 | 926 |
7867 | 927 extern int hr_mp3_seek; |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
928 |
12835
4235ae5a2d60
cache min fill adjustment, based on patch by Jeremy Huddleston
iive
parents:
12434
diff
changeset
|
929 extern float stream_cache_min_percent; |
16152
10a69a812eff
remove unused cache-prefill and create cache-seek-min that controls when seek_long is prefered over waiting for cache to fill
iive
parents:
15958
diff
changeset
|
930 extern float stream_cache_seek_min_percent; |
12835
4235ae5a2d60
cache min fill adjustment, based on patch by Jeremy Huddleston
iive
parents:
12434
diff
changeset
|
931 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
932 demuxer_t *demux_open(stream_t *vs, int file_format, int audio_id, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
933 int video_id, int dvdsub_id, char *filename) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
934 { |
27055 | 935 stream_t *as = NULL, *ss = NULL; |
936 demuxer_t *vd, *ad = NULL, *sd = NULL; | |
937 demuxer_t *res; | |
938 int afmt = DEMUXER_TYPE_UNKNOWN, sfmt = DEMUXER_TYPE_UNKNOWN; | |
939 int demuxer_type; | |
940 int audio_demuxer_type = 0, sub_demuxer_type = 0; | |
941 int demuxer_force = 0, audio_demuxer_force = 0, sub_demuxer_force = 0; | |
16175 | 942 |
27056 | 943 if ((demuxer_type = |
944 get_demuxer_type_from_name(demuxer_name, &demuxer_force)) < 0) { | |
945 mp_msg(MSGT_DEMUXER, MSGL_ERR, "-demuxer %s does not exist.\n", | |
946 demuxer_name); | |
27055 | 947 } |
27056 | 948 if ((audio_demuxer_type = |
949 get_demuxer_type_from_name(audio_demuxer_name, | |
950 &audio_demuxer_force)) < 0) { | |
951 mp_msg(MSGT_DEMUXER, MSGL_ERR, "-audio-demuxer %s does not exist.\n", | |
952 audio_demuxer_name); | |
27055 | 953 } |
27056 | 954 if ((sub_demuxer_type = |
955 get_demuxer_type_from_name(sub_demuxer_name, | |
956 &sub_demuxer_force)) < 0) { | |
957 mp_msg(MSGT_DEMUXER, MSGL_ERR, "-sub-demuxer %s does not exist.\n", | |
958 sub_demuxer_name); | |
27055 | 959 } |
26437 | 960 |
27055 | 961 if (audio_stream) { |
962 as = open_stream(audio_stream, 0, &afmt); | |
963 if (!as) { | |
27056 | 964 mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_CannotOpenAudioStream, |
965 audio_stream); | |
27055 | 966 return NULL; |
967 } | |
968 if (audio_stream_cache) { | |
27056 | 969 if (!stream_enable_cache |
970 (as, audio_stream_cache * 1024, | |
971 audio_stream_cache * 1024 * (stream_cache_min_percent / | |
972 100.0), | |
973 audio_stream_cache * 1024 * (stream_cache_seek_min_percent / | |
974 100.0))) { | |
27055 | 975 free_stream(as); |
27056 | 976 mp_msg(MSGT_DEMUXER, MSGL_ERR, |
977 "Can't enable audio stream cache\n"); | |
27055 | 978 return NULL; |
979 } | |
980 } | |
26379 | 981 } |
27055 | 982 if (sub_stream) { |
983 ss = open_stream(sub_stream, 0, &sfmt); | |
984 if (!ss) { | |
27056 | 985 mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_CannotOpenSubtitlesStream, |
986 sub_stream); | |
27055 | 987 return NULL; |
988 } | |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
989 } |
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
990 |
27055 | 991 vd = demux_open_stream(vs, demuxer_type ? demuxer_type : file_format, |
27056 | 992 demuxer_force, audio_stream ? -2 : audio_id, |
993 video_id, sub_stream ? -2 : dvdsub_id, filename); | |
27055 | 994 if (!vd) { |
995 if (as) | |
996 free_stream(as); | |
997 if (ss) | |
998 free_stream(ss); | |
999 return NULL; | |
1000 } | |
1001 if (as) { | |
27056 | 1002 ad = demux_open_stream(as, |
1003 audio_demuxer_type ? audio_demuxer_type : afmt, | |
1004 audio_demuxer_force, audio_id, -2, -2, | |
1005 audio_stream); | |
27055 | 1006 if (!ad) { |
27056 | 1007 mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_OpeningAudioDemuxerFailed, |
1008 audio_stream); | |
27055 | 1009 free_stream(as); |
27056 | 1010 } else if (ad->audio->sh |
1011 && ((sh_audio_t *) ad->audio->sh)->format == 0x55) // MP3 | |
27055 | 1012 hr_mp3_seek = 1; // Enable high res seeking |
9709 | 1013 } |
27055 | 1014 if (ss) { |
1015 sd = demux_open_stream(ss, sub_demuxer_type ? sub_demuxer_type : sfmt, | |
27056 | 1016 sub_demuxer_force, -2, -2, dvdsub_id, |
1017 sub_stream); | |
27055 | 1018 if (!sd) { |
27056 | 1019 mp_msg(MSGT_DEMUXER, MSGL_WARN, |
1020 MSGTR_OpeningSubtitlesDemuxerFailed, sub_stream); | |
27055 | 1021 free_stream(ss); |
1022 } | |
1023 } | |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1024 |
27055 | 1025 if (ad && sd) |
1026 res = new_demuxers_demuxer(vd, ad, sd); | |
1027 else if (ad) | |
1028 res = new_demuxers_demuxer(vd, ad, vd); | |
1029 else if (sd) | |
1030 res = new_demuxers_demuxer(vd, vd, sd); | |
1031 else | |
1032 res = vd; | |
25919
382672c7480a
Allow demuxers to choose a default value for correct_pts
reimar
parents:
25883
diff
changeset
|
1033 |
27055 | 1034 correct_pts = user_correct_pts; |
1035 if (correct_pts < 0) | |
27056 | 1036 correct_pts = demux_control(res, DEMUXER_CTRL_CORRECT_PTS, NULL) |
1037 == DEMUXER_CTRL_OK; | |
27055 | 1038 return res; |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1039 } |
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1040 |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1041 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1042 void demux_flush(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1043 { |
26926
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1044 ds_free_packs(demuxer->video); |
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1045 ds_free_packs(demuxer->audio); |
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1046 ds_free_packs(demuxer->sub); |
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1047 } |
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1048 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1049 int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1050 int flags) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1051 { |
27055 | 1052 demux_stream_t *d_audio = demuxer->audio; |
1053 demux_stream_t *d_video = demuxer->video; | |
1054 sh_audio_t *sh_audio = d_audio->sh; | |
1055 sh_video_t *sh_video = d_video->sh; | |
20851
6602a90a06ec
consistency fix: STREAM_CTRL_GET_TIME_LENGTH and STREAM_CTRL_GET_CURRENT_TIME now return time in (double) seconds
nicodvb
parents:
20841
diff
changeset
|
1056 double tmp = 0; |
20748
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1057 double pts; |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1058 |
27055 | 1059 if (!demuxer->seekable) { |
1060 if (demuxer->file_format == DEMUXER_TYPE_AVI) | |
1061 mp_msg(MSGT_SEEK, MSGL_WARN, MSGTR_CantSeekRawAVI); | |
2790 | 1062 #ifdef USE_TV |
27055 | 1063 else if (demuxer->file_format == DEMUXER_TYPE_TV) |
1064 mp_msg(MSGT_SEEK, MSGL_WARN, MSGTR_TVInputNotSeekable); | |
2790 | 1065 #endif |
27055 | 1066 else |
1067 mp_msg(MSGT_SEEK, MSGL_WARN, MSGTR_CantSeekFile); | |
1068 return 0; | |
1069 } | |
26437 | 1070 |
26926
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1071 demux_flush(demuxer); |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1072 // clear demux buffers: |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1073 if (sh_audio) |
27055 | 1074 sh_audio->a_buffer_len = 0; |
1075 | |
27045 | 1076 demuxer->stream->eof = 0; |
27055 | 1077 demuxer->video->eof = 0; |
1078 demuxer->audio->eof = 0; | |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1079 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1080 if (sh_video) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1081 sh_video->timer = 0; // !!!!!! |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1082 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1083 if (flags & SEEK_ABSOLUTE) |
27055 | 1084 pts = 0.0f; |
20748
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1085 else { |
27055 | 1086 if (demuxer->stream_pts == MP_NOPTS_VALUE) |
1087 goto dmx_seek; | |
1088 pts = demuxer->stream_pts; | |
20748
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1089 } |
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1090 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1091 if (flags & SEEK_FACTOR) { |
27056 | 1092 if (stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, &tmp) |
1093 == STREAM_UNSUPPORTED) | |
27055 | 1094 goto dmx_seek; |
1095 pts += tmp * rel_seek_secs; | |
20748
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1096 } else |
27055 | 1097 pts += rel_seek_secs; |
20748
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1098 |
27056 | 1099 if (stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_TIME, &pts) != |
1100 STREAM_UNSUPPORTED) { | |
27055 | 1101 demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL); |
1102 return 1; | |
20748
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1103 } |
865b71a83296
now demux_seek() tries to seek aided by the stream layer, if possible
nicodvb
parents:
20319
diff
changeset
|
1104 |
27055 | 1105 dmx_seek: |
1106 if (demuxer->desc->seek) | |
1107 demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags); | |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1108 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1109 if (sh_audio) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1110 resync_audio_stream(sh_audio); |
16877
9081ae3a702c
move resync_audio_stream after seeking to demuxer.c
reimar
parents:
16572
diff
changeset
|
1111 |
27055 | 1112 return 1; |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1113 } |
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1114 |
19053
75327b24e06f
marks several string parameters as const, as they are not modified inside the function, Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
18917
diff
changeset
|
1115 int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param) |
3050 | 1116 { |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
4660
diff
changeset
|
1117 char **info = demuxer->info; |
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
4660
diff
changeset
|
1118 int n = 0; |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1496
diff
changeset
|
1119 |
3050 | 1120 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1121 for (n = 0; info && info[2 * n] != NULL; n++) { |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1122 if (!strcasecmp(opt, info[2 * n])) { |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1123 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_DemuxerInfoChanged, opt, |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1124 param); |
27055 | 1125 free(info[2 * n + 1]); |
1126 info[2 * n + 1] = strdup(param); | |
27052 | 1127 return 0; |
27055 | 1128 } |
1129 } | |
27051 | 1130 |
27056 | 1131 info = demuxer->info = (char **) realloc(info, |
1132 (2 * (n + 2)) * sizeof(char *)); | |
27055 | 1133 info[2 * n] = strdup(opt); |
1134 info[2 * n + 1] = strdup(param); | |
1135 memset(&info[2 * (n + 1)], 0, 2 * sizeof(char *)); | |
3050 | 1136 |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
4660
diff
changeset
|
1137 return 1; |
3050 | 1138 } |
1139 | |
1140 int demux_info_print(demuxer_t *demuxer) | |
1141 { | |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
4660
diff
changeset
|
1142 char **info = demuxer->info; |
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
4660
diff
changeset
|
1143 int n; |
3050 | 1144 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1145 if (!info) |
27055 | 1146 return 0; |
4694
a21735031d6a
Audio file demuxer. Extended version for demuxer info.
albeu
parents:
4660
diff
changeset
|
1147 |
27055 | 1148 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_ClipInfo); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1149 for (n = 0; info[2 * n] != NULL; n++) { |
27056 | 1150 mp_msg(MSGT_DEMUX, MSGL_INFO, " %s: %s\n", info[2 * n], |
1151 info[2 * n + 1]); | |
1152 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_NAME%d=%s\n", n, | |
1153 info[2 * n]); | |
1154 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_VALUE%d=%s\n", n, | |
1155 info[2 * n + 1]); | |
15789
32d9c8a0a02b
adds some more -identify output, patch by kiriuja < mplayer DASH patches PAM en DASH directo POUM net>
gpoirier
parents:
15780
diff
changeset
|
1156 } |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
18128
diff
changeset
|
1157 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_N=%d\n", n); |
4189 | 1158 |
1159 return 0; | |
3050 | 1160 } |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1161 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1162 char *demux_info_get(demuxer_t *demuxer, const char *opt) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1163 { |
27055 | 1164 int i; |
1165 char **info = demuxer->info; | |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1166 |
27055 | 1167 for (i = 0; info && info[2 * i] != NULL; i++) { |
1168 if (!strcasecmp(opt, info[2 * i])) | |
1169 return info[2 * i + 1]; | |
1170 } | |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1171 |
27055 | 1172 return NULL; |
4765
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1173 } |
d0c2c8af46b4
Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
4735
diff
changeset
|
1174 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1175 int demux_control(demuxer_t *demuxer, int cmd, void *arg) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1176 { |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1177 |
16175 | 1178 if (demuxer->desc->control) |
27055 | 1179 return demuxer->desc->control(demuxer, cmd, arg); |
16175 | 1180 |
1181 return DEMUXER_CTRL_NOTIMPL; | |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1182 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1183 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1184 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1185 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1186 double demuxer_get_time_length(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1187 { |
16346
6ff303d2876b
Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents:
16326
diff
changeset
|
1188 double get_time_ans; |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14276
diff
changeset
|
1189 sh_video_t *sh_video = demuxer->video->sh; |
16925 | 1190 sh_audio_t *sh_audio = demuxer->audio->sh; |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14276
diff
changeset
|
1191 // <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW |
27056 | 1192 if (demux_control |
1193 (demuxer, DEMUXER_CTRL_GET_TIME_LENGTH, (void *) &get_time_ans) <= 0) { | |
27055 | 1194 if (sh_video && sh_video->i_bps && sh_audio && sh_audio->i_bps) |
27056 | 1195 get_time_ans = (double) (demuxer->movi_end - |
1196 demuxer->movi_start) / (sh_video->i_bps + | |
1197 sh_audio->i_bps); | |
27055 | 1198 else if (sh_video && sh_video->i_bps) |
27056 | 1199 get_time_ans = (double) (demuxer->movi_end - |
1200 demuxer->movi_start) / sh_video->i_bps; | |
27055 | 1201 else if (sh_audio && sh_audio->i_bps) |
27056 | 1202 get_time_ans = (double) (demuxer->movi_end - |
1203 demuxer->movi_start) / sh_audio->i_bps; | |
27055 | 1204 else |
1205 get_time_ans = 0; | |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1206 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1207 return get_time_ans; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1208 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1209 |
20749
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1210 /** |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1211 * \brief demuxer_get_current_time() returns the time of the current play in three possible ways: |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1212 * either when the stream reader satisfies STREAM_CTRL_GET_CURRENT_TIME (e.g. dvd) |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1213 * or using sh_video->pts when the former method fails |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1214 * 0 otherwise |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1215 * \return the current play time |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1216 */ |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1217 int demuxer_get_current_time(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1218 { |
20749
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1219 double get_time_ans = 0; |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1220 sh_video_t *sh_video = demuxer->video->sh; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1221 if (demuxer->stream_pts != MP_NOPTS_VALUE) |
21782
99ab6c41eb1e
use demuxer->stream_pts rather than stream_control(STREAM_CTRL_GET_CURRENT_TIME)
nicodvb
parents:
21780
diff
changeset
|
1222 get_time_ans = demuxer->stream_pts; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1223 else if (sh_video) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1224 get_time_ans = sh_video->pts; |
20749
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1225 return (int) get_time_ans; |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1226 } |
eafd9953b505
added demuxer_get_current_time() to get the current playtime (possibly aided by the stream layer)
nicodvb
parents:
20748
diff
changeset
|
1227 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1228 int demuxer_get_percent_pos(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1229 { |
14197
2ae224195625
Use demuxer_get_percent_pos for the OSD position bar
reimar
parents:
14160
diff
changeset
|
1230 int ans = 0; |
2ae224195625
Use demuxer_get_percent_pos for the OSD position bar
reimar
parents:
14160
diff
changeset
|
1231 int res = demux_control(demuxer, DEMUXER_CTRL_GET_PERCENT_POS, &ans); |
2ae224195625
Use demuxer_get_percent_pos for the OSD position bar
reimar
parents:
14160
diff
changeset
|
1232 int len = (demuxer->movi_end - demuxer->movi_start) / 100; |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14276
diff
changeset
|
1233 if (res <= 0) { |
27055 | 1234 if (len > 0) |
1235 ans = (demuxer->filepos - demuxer->movi_start) / len; | |
1236 else | |
1237 ans = 0; | |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14276
diff
changeset
|
1238 } |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1239 if (ans < 0) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1240 ans = 0; |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1241 if (ans > 100) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1242 ans = 100; |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1243 return ans; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1244 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1245 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1246 int demuxer_switch_audio(demuxer_t *demuxer, int index) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1247 { |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1248 int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &index); |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1249 if (res == DEMUXER_CTRL_NOTIMPL) |
27055 | 1250 index = demuxer->audio->id; |
26089
e2f35d90ad39
Set audio->sh correctly when switching audio tracks. The same for video tracks.
eugeni
parents:
26088
diff
changeset
|
1251 if (demuxer->audio->id >= 0) |
27055 | 1252 demuxer->audio->sh = demuxer->a_streams[demuxer->audio->id]; |
26089
e2f35d90ad39
Set audio->sh correctly when switching audio tracks. The same for video tracks.
eugeni
parents:
26088
diff
changeset
|
1253 else |
27055 | 1254 demuxer->audio->sh = NULL; |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1255 return index; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14934
diff
changeset
|
1256 } |
19342 | 1257 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1258 int demuxer_switch_video(demuxer_t *demuxer, int index) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1259 { |
20948 | 1260 int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_VIDEO, &index); |
1261 if (res == DEMUXER_CTRL_NOTIMPL) | |
27055 | 1262 index = demuxer->video->id; |
26089
e2f35d90ad39
Set audio->sh correctly when switching audio tracks. The same for video tracks.
eugeni
parents:
26088
diff
changeset
|
1263 if (demuxer->video->id >= 0) |
27055 | 1264 demuxer->video->sh = demuxer->v_streams[demuxer->video->id]; |
26089
e2f35d90ad39
Set audio->sh correctly when switching audio tracks. The same for video tracks.
eugeni
parents:
26088
diff
changeset
|
1265 else |
27055 | 1266 demuxer->video->sh = NULL; |
20948 | 1267 return index; |
1268 } | |
1269 | |
27054 | 1270 int demuxer_add_attachment(demuxer_t *demuxer, const char *name, |
1271 const char *type, const void *data, size_t size) | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1272 { |
25657 | 1273 if (!(demuxer->num_attachments & 31)) |
27056 | 1274 demuxer->attachments = realloc(demuxer->attachments, |
1275 (demuxer->num_attachments + 32) * sizeof(demux_attachment_t)); | |
25657 | 1276 |
1277 demuxer->attachments[demuxer->num_attachments].name = strdup(name); | |
1278 demuxer->attachments[demuxer->num_attachments].type = strdup(type); | |
1279 demuxer->attachments[demuxer->num_attachments].data = malloc(size); | |
1280 memcpy(demuxer->attachments[demuxer->num_attachments].data, data, size); | |
1281 demuxer->attachments[demuxer->num_attachments].data_size = size; | |
1282 | |
27055 | 1283 return demuxer->num_attachments++; |
25657 | 1284 } |
1285 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1286 int demuxer_add_chapter(demuxer_t *demuxer, const char *name, uint64_t start, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1287 uint64_t end) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1288 { |
19342 | 1289 if (demuxer->chapters == NULL) |
27055 | 1290 demuxer->chapters = malloc(32 * sizeof(*demuxer->chapters)); |
19342 | 1291 else if (!(demuxer->num_chapters % 32)) |
27056 | 1292 demuxer->chapters = realloc(demuxer->chapters, |
1293 (demuxer->num_chapters + 32) * | |
1294 sizeof(*demuxer->chapters)); | |
19342 | 1295 |
1296 demuxer->chapters[demuxer->num_chapters].start = start; | |
1297 demuxer->chapters[demuxer->num_chapters].end = end; | |
27057
42332b47d6aa
Support NULL name parameter for demuxer_add_chapter.
reimar
parents:
27056
diff
changeset
|
1298 demuxer->chapters[demuxer->num_chapters].name = strdup(name ? name : MSGTR_Unknown); |
19342 | 1299 |
27055 | 1300 return demuxer->num_chapters++; |
19342 | 1301 } |
1302 | |
19435 | 1303 /** |
27051 | 1304 * \brief demuxer_seek_chapter() seeks to a chapter in two possible ways: |
19435 | 1305 * either using the demuxer->chapters structure set by the demuxer |
1306 * or asking help to the stream layer (e.g. dvd) | |
19439 | 1307 * \param chapter - chapter number wished - 0-based |
19435 | 1308 * \param mode 0: relative to current main pts, 1: absolute |
1309 * \param seek_pts set by the function to the pts to seek to (if demuxer->chapters is set) | |
19478
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1310 * \param num_chapters number of chapters present (set by this function is param is not null) |
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1311 * \param chapter_name name of chapter found (set by this function is param is not null) |
19435 | 1312 * \return -1 on error, current chapter if successful |
1313 */ | |
1314 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1315 int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1316 float *seek_pts, int *num_chapters, |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1317 char **chapter_name) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1318 { |
19435 | 1319 int ris; |
1320 int current, total; | |
1321 sh_video_t *sh_video = demuxer->video->sh; | |
1322 sh_audio_t *sh_audio = demuxer->audio->sh; | |
1323 | |
1324 if (!demuxer->num_chapters || !demuxer->chapters) { | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1325 if (!mode) { |
27056 | 1326 ris = stream_control(demuxer->stream, |
1327 STREAM_CTRL_GET_CURRENT_CHAPTER, ¤t); | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1328 if (ris == STREAM_UNSUPPORTED) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1329 return -1; |
19438
263e95c47aec
support relative seeking in the stream-driven case
nicodvb
parents:
19435
diff
changeset
|
1330 chapter += current; |
263e95c47aec
support relative seeking in the stream-driven case
nicodvb
parents:
19435
diff
changeset
|
1331 } |
263e95c47aec
support relative seeking in the stream-driven case
nicodvb
parents:
19435
diff
changeset
|
1332 |
26926
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1333 demux_flush(demuxer); |
19435 | 1334 |
27056 | 1335 ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER, |
1336 &chapter); | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1337 if (ris != STREAM_UNSUPPORTED) |
20839
950ea3171afc
in demux_seek() if STREAM_CTRL_SEEK_TO_CHAPTER suceeds call DEMUXER_CTRL_RESYNC to notify the demuxer of the change
nicodvb
parents:
20749
diff
changeset
|
1338 demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1339 if (sh_video) { |
19435 | 1340 ds_fill_buffer(demuxer->video); |
1341 resync_video_stream(sh_video); | |
1342 } | |
1343 | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1344 if (sh_audio) { |
19435 | 1345 ds_fill_buffer(demuxer->audio); |
1346 resync_audio_stream(sh_audio); | |
1347 } | |
27056 | 1348 // exit status may be ok, but main() doesn't have to seek itself |
1349 // (because e.g. dvds depend on sectors, not on pts) | |
19435 | 1350 *seek_pts = -1.0; |
19478
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1351 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1352 if (num_chapters) { |
27056 | 1353 if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, |
1354 num_chapters) == STREAM_UNSUPPORTED) | |
19478
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1355 *num_chapters = 0; |
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1356 } |
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1357 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1358 if (chapter_name) { |
19478
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1359 *chapter_name = NULL; |
25314
02e2e7a5599a
Fix memory leak that tmp allocated but maybe not used.
ulion
parents:
25266
diff
changeset
|
1360 if (num_chapters && *num_chapters) { |
02e2e7a5599a
Fix memory leak that tmp allocated but maybe not used.
ulion
parents:
25266
diff
changeset
|
1361 char *tmp = malloc(16); |
02e2e7a5599a
Fix memory leak that tmp allocated but maybe not used.
ulion
parents:
25266
diff
changeset
|
1362 if (tmp) { |
02e2e7a5599a
Fix memory leak that tmp allocated but maybe not used.
ulion
parents:
25266
diff
changeset
|
1363 sprintf(tmp, " of %3d", *num_chapters); |
02e2e7a5599a
Fix memory leak that tmp allocated but maybe not used.
ulion
parents:
25266
diff
changeset
|
1364 *chapter_name = tmp; |
02e2e7a5599a
Fix memory leak that tmp allocated but maybe not used.
ulion
parents:
25266
diff
changeset
|
1365 } |
19478
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1366 } |
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1367 } |
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1368 |
26758
9fb1d2c3dbd4
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
26437
diff
changeset
|
1369 return ris != STREAM_UNSUPPORTED ? chapter : -1; |
27055 | 1370 } else { // chapters structure is set in the demuxer |
19435 | 1371 total = demuxer->num_chapters; |
1372 | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1373 if (mode == 1) //absolute seeking |
19435 | 1374 current = chapter; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1375 else { //relative seeking |
19435 | 1376 uint64_t now; |
27056 | 1377 now = (sh_video ? sh_video->pts : (sh_audio ? sh_audio->pts : 0.)) |
1378 * 1000 + .5; | |
19435 | 1379 |
1380 for (current = total - 1; current >= 0; --current) { | |
27054 | 1381 demux_chapter_t *chapter = demuxer->chapters + current; |
19435 | 1382 if (chapter->start <= now) |
1383 break; | |
1384 } | |
1385 current += chapter; | |
1386 } | |
1387 | |
1388 if (current >= total) | |
27055 | 1389 return -1; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1390 if (current < 0) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1391 current = 0; |
19435 | 1392 |
1393 *seek_pts = demuxer->chapters[current].start / 1000.0; | |
1394 | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1395 if (num_chapters) |
19478
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1396 *num_chapters = demuxer->num_chapters; |
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1397 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1398 if (chapter_name) { |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1399 if (demuxer->chapters[current].name) |
19479
8dd04ec733f5
100l: *chapter_name was copied from the pointer rather than strupd()-ed (and next free()d in mplayer.c
nicodvb
parents:
19478
diff
changeset
|
1400 *chapter_name = strdup(demuxer->chapters[current].name); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1401 else |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1402 *chapter_name = NULL; |
19479
8dd04ec733f5
100l: *chapter_name was copied from the pointer rather than strupd()-ed (and next free()d in mplayer.c
nicodvb
parents:
19478
diff
changeset
|
1403 } |
19478
bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
nicodvb
parents:
19439
diff
changeset
|
1404 |
19435 | 1405 return current; |
1406 } | |
1407 } | |
25358 | 1408 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1409 int demuxer_get_current_chapter(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1410 { |
25358 | 1411 int chapter = -1; |
1412 if (!demuxer->num_chapters || !demuxer->chapters) { | |
1413 if (stream_control(demuxer->stream, STREAM_CTRL_GET_CURRENT_CHAPTER, | |
1414 &chapter) == STREAM_UNSUPPORTED) | |
1415 chapter = -1; | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1416 } else { |
25358 | 1417 sh_video_t *sh_video = demuxer->video->sh; |
1418 sh_audio_t *sh_audio = demuxer->audio->sh; | |
1419 uint64_t now; | |
27056 | 1420 now = (sh_video ? sh_video->pts : (sh_audio ? sh_audio->pts : 0)) |
1421 * 1000 + 0.5; | |
25358 | 1422 for (chapter = demuxer->num_chapters - 1; chapter >= 0; --chapter) { |
1423 if (demuxer->chapters[chapter].start <= now) | |
1424 break; | |
1425 } | |
1426 } | |
1427 return chapter; | |
1428 } | |
1429 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1430 char *demuxer_chapter_name(demuxer_t *demuxer, int chapter) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1431 { |
25358 | 1432 if (demuxer->num_chapters && demuxer->chapters) { |
27056 | 1433 if (chapter >= 0 && chapter < demuxer->num_chapters |
1434 && demuxer->chapters[chapter].name) | |
25358 | 1435 return strdup(demuxer->chapters[chapter].name); |
1436 } | |
1437 return NULL; | |
1438 } | |
1439 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1440 char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1441 { |
25358 | 1442 char *chapter_name = demuxer_chapter_name(demuxer, chapter); |
1443 if (chapter_name) { | |
1444 char *tmp = malloc(strlen(chapter_name) + 14); | |
1445 snprintf(tmp, 63, "(%d) %s", chapter + 1, chapter_name); | |
27051 | 1446 free(chapter_name); |
25358 | 1447 return tmp; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1448 } else { |
25358 | 1449 int chapter_num = demuxer_chapter_count(demuxer); |
1450 char tmp[30]; | |
1451 if (chapter_num <= 0) | |
1452 sprintf(tmp, "(%d)", chapter + 1); | |
1453 else | |
1454 sprintf(tmp, "(%d) of %d", chapter + 1, chapter_num); | |
1455 return strdup(tmp); | |
1456 } | |
1457 } | |
1458 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1459 float demuxer_chapter_time(demuxer_t *demuxer, int chapter, float *end) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1460 { |
25358 | 1461 if (demuxer->num_chapters && demuxer->chapters && chapter >= 0 |
27055 | 1462 && chapter < demuxer->num_chapters) { |
25358 | 1463 if (end) |
1464 *end = demuxer->chapters[chapter].end / 1000.0; | |
1465 return demuxer->chapters[chapter].start / 1000.0; | |
1466 } | |
1467 return -1.0; | |
1468 } | |
1469 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1470 int demuxer_chapter_count(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1471 { |
25358 | 1472 if (!demuxer->num_chapters || !demuxer->chapters) { |
1473 int num_chapters = 0; | |
1474 if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, | |
1475 &num_chapters) == STREAM_UNSUPPORTED) | |
1476 num_chapters = 0; | |
1477 return num_chapters; | |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1478 } else |
25358 | 1479 return demuxer->num_chapters; |
1480 } | |
1481 | |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1482 int demuxer_angles_count(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1483 { |
27055 | 1484 int ris, angles = -1; |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1485 |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1486 ris = stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_ANGLES, &angles); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1487 if (ris == STREAM_UNSUPPORTED) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1488 return -1; |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1489 return angles; |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1490 } |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1491 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1492 int demuxer_get_current_angle(demuxer_t *demuxer) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1493 { |
27055 | 1494 int ris, curr_angle = -1; |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1495 ris = stream_control(demuxer->stream, STREAM_CTRL_GET_ANGLE, &curr_angle); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1496 if (ris == STREAM_UNSUPPORTED) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1497 return -1; |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1498 return curr_angle; |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1499 } |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1500 |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1501 |
27047
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1502 int demuxer_set_angle(demuxer_t *demuxer, int angle) |
6ff2454fe5ec
cosmetics: Make all function declarations consistent by moving the opening
diego
parents:
27046
diff
changeset
|
1503 { |
27055 | 1504 int ris, angles = -1; |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1505 sh_video_t *sh_video = demuxer->video->sh; |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1506 sh_audio_t *sh_audio = demuxer->audio->sh; |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1507 |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1508 angles = demuxer_angles_count(demuxer); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1509 if ((angles < 1) || (angle > angles)) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1510 return -1; |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1511 |
26926
1e6241274552
added and reused demux_flush() instead of emptying the demux_stream buffers;
nicodvb
parents:
26876
diff
changeset
|
1512 demux_flush(demuxer); |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1513 |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1514 ris = stream_control(demuxer->stream, STREAM_CTRL_SET_ANGLE, &angle); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1515 if (ris == STREAM_UNSUPPORTED) |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1516 return -1; |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1517 |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1518 demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1519 if (sh_video) { |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1520 ds_fill_buffer(demuxer->video); |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1521 resync_video_stream(sh_video); |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1522 } |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1523 |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1524 if (sh_audio) { |
25575
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1525 ds_fill_buffer(demuxer->audio); |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1526 resync_audio_stream(sh_audio); |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1527 } |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1528 |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1529 return angle; |
f94eee219ee0
wrapper functions to get/set angle: the wrapping is needed to RESYNC the demuxer; patch by oattila chello hu
nicodvb
parents:
25444
diff
changeset
|
1530 } |
26086
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1531 |
27054 | 1532 int demuxer_audio_track_by_lang(demuxer_t *d, char *lang) |
26086
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1533 { |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1534 int i, len; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1535 lang += strspn(lang, ","); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1536 while ((len = strcspn(lang, ",")) > 0) { |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1537 for (i = 0; i < MAX_A_STREAMS; ++i) { |
27054 | 1538 sh_audio_t *sh = d->a_streams[i]; |
26086
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1539 if (sh && sh->lang && strncmp(sh->lang, lang, len) == 0) |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1540 return sh->aid; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1541 } |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1542 lang += len; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1543 lang += strspn(lang, ","); |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1544 } |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1545 return -1; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1546 } |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1547 |
27054 | 1548 int demuxer_sub_track_by_lang(demuxer_t *d, char *lang) |
26086
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1549 { |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1550 int i, len; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1551 lang += strspn(lang, ","); |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1552 while ((len = strcspn(lang, ",")) > 0) { |
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1553 for (i = 0; i < MAX_S_STREAMS; ++i) { |
27054 | 1554 sh_sub_t *sh = d->s_streams[i]; |
26086
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1555 if (sh && sh->lang && strncmp(sh->lang, lang, len) == 0) |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1556 return sh->sid; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1557 } |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1558 lang += len; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1559 lang += strspn(lang, ","); |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1560 } |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1561 return -1; |
c9a877daca42
Demuxer-independent functions for selecting tracks based on language.
eugeni
parents:
26085
diff
changeset
|
1562 } |
26269
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1563 |
27054 | 1564 int demuxer_default_audio_track(demuxer_t *d) |
26269
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1565 { |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1566 int i; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1567 for (i = 0; i < MAX_A_STREAMS; ++i) { |
27054 | 1568 sh_audio_t *sh = d->a_streams[i]; |
26269
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1569 if (sh && sh->default_track) |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1570 return sh->aid; |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1571 } |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1572 for (i = 0; i < MAX_A_STREAMS; ++i) { |
27054 | 1573 sh_audio_t *sh = d->a_streams[i]; |
26269
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1574 if (sh) |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1575 return sh->aid; |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1576 } |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1577 return -1; |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1578 } |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1579 |
27054 | 1580 int demuxer_default_sub_track(demuxer_t *d) |
26269
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1581 { |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1582 int i; |
27049
762a9c6bfb43
cosmetics: Consistently format all if, for, while constructs.
diego
parents:
27048
diff
changeset
|
1583 for (i = 0; i < MAX_S_STREAMS; ++i) { |
27054 | 1584 sh_sub_t *sh = d->s_streams[i]; |
26269
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1585 if (sh && sh->default_track) |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1586 return sh->sid; |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1587 } |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1588 return -1; |
65ad20416dd7
Support 'default' attribute for audio and subtitle tracks.
eugeni
parents:
26089
diff
changeset
|
1589 } |