Mercurial > mplayer.hg
annotate libmpdemux/demux_lavf.c @ 18762:369074e0eb7b
support for audio stream switching
author | nicodvb |
---|---|
date | Tue, 20 Jun 2006 19:57:16 +0000 |
parents | f70772d02eaa |
children | bdcbf1070680 |
rev | line source |
---|---|
12164 | 1 /* |
2 Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at> | |
3 | |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software | |
17367
401b440a6d76
Update licensing information: The FSF changed postal address.
diego
parents:
17354
diff
changeset
|
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
12164 | 17 */ |
18 | |
19 // #include <stdio.h> | |
20 #include <stdlib.h> | |
21 // #include <unistd.h> | |
22 | |
23 #include "config.h" | |
24 #include "mp_msg.h" | |
25 // #include "help_mp.h" | |
26 | |
27 #include "stream.h" | |
28 #include "demuxer.h" | |
29 #include "stheader.h" | |
30 | |
17354 | 31 #ifdef USE_LIBAVFORMAT_SO |
32 #include <ffmpeg/avformat.h> | |
33 #else | |
12164 | 34 #include "avformat.h" |
35 #include "avi.h" | |
17354 | 36 #endif |
12164 | 37 |
38 #define PROBE_BUF_SIZE 2048 | |
39 | |
40 typedef struct lavf_priv_t{ | |
41 AVInputFormat *avif; | |
42 AVFormatContext *avfc; | |
43 ByteIOContext pb; | |
44 int audio_streams; | |
45 int video_streams; | |
12168 | 46 int64_t last_pts; |
18762 | 47 int astreams[MAX_A_STREAMS]; |
12164 | 48 }lavf_priv_t; |
49 | |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17932
diff
changeset
|
50 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); |
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17932
diff
changeset
|
51 extern void print_video_header(BITMAPINFOHEADER *h, int verbose_level); |
12164 | 52 |
15011 | 53 int64_t ff_gcd(int64_t a, int64_t b); |
54 | |
12164 | 55 static int mp_open(URLContext *h, const char *filename, int flags){ |
56 return 0; | |
57 } | |
58 | |
59 static int mp_read(URLContext *h, unsigned char *buf, int size){ | |
60 stream_t *stream = (stream_t*)h->priv_data; | |
12165
6ae21c78ed8d
libavformat really doesnt like it that the streams get stuck if the end is reached
michael
parents:
12164
diff
changeset
|
61 int ret; |
6ae21c78ed8d
libavformat really doesnt like it that the streams get stuck if the end is reached
michael
parents:
12164
diff
changeset
|
62 |
12164 | 63 if(stream_eof(stream)) //needed? |
64 return -1; | |
12165
6ae21c78ed8d
libavformat really doesnt like it that the streams get stuck if the end is reached
michael
parents:
12164
diff
changeset
|
65 ret=stream_read(stream, buf, size); |
12166 | 66 |
12165
6ae21c78ed8d
libavformat really doesnt like it that the streams get stuck if the end is reached
michael
parents:
12164
diff
changeset
|
67 mp_msg(MSGT_HEADER,MSGL_DBG2,"%d=mp_read(%p, %p, %d), eof:%d\n", ret, h, buf, size, stream->eof); |
6ae21c78ed8d
libavformat really doesnt like it that the streams get stuck if the end is reached
michael
parents:
12164
diff
changeset
|
68 return ret; |
12164 | 69 } |
70 | |
71 static int mp_write(URLContext *h, unsigned char *buf, int size){ | |
72 return -1; | |
73 } | |
74 | |
75 static offset_t mp_seek(URLContext *h, offset_t pos, int whence){ | |
76 stream_t *stream = (stream_t*)h->priv_data; | |
12165
6ae21c78ed8d
libavformat really doesnt like it that the streams get stuck if the end is reached
michael
parents:
12164
diff
changeset
|
77 |
6ae21c78ed8d
libavformat really doesnt like it that the streams get stuck if the end is reached
michael
parents:
12164
diff
changeset
|
78 mp_msg(MSGT_HEADER,MSGL_DBG2,"mp_seek(%p, %d, %d)\n", h, (int)pos, whence); |
12164 | 79 if(whence == SEEK_CUR) |
80 pos +=stream_tell(stream); | |
81 else if(whence == SEEK_END) | |
82 pos += stream->end_pos; | |
83 else if(whence != SEEK_SET) | |
84 return -1; | |
85 | |
12167 | 86 if(pos<stream->end_pos && stream->eof) |
12166 | 87 stream_reset(stream); |
12164 | 88 if(stream_seek(stream, pos)==0) |
89 return -1; | |
12166 | 90 |
12164 | 91 return pos; |
92 } | |
93 | |
94 static int mp_close(URLContext *h){ | |
95 return 0; | |
96 } | |
97 | |
98 static URLProtocol mp_protocol = { | |
99 "mp", | |
100 mp_open, | |
101 mp_read, | |
102 mp_write, | |
103 mp_seek, | |
104 mp_close, | |
105 }; | |
106 | |
16175 | 107 static int lavf_check_file(demuxer_t *demuxer){ |
12164 | 108 AVProbeData avpd; |
109 uint8_t buf[PROBE_BUF_SIZE]; | |
110 lavf_priv_t *priv; | |
111 | |
112 if(!demuxer->priv) | |
113 demuxer->priv=calloc(sizeof(lavf_priv_t),1); | |
114 priv= demuxer->priv; | |
115 | |
116 av_register_all(); | |
117 | |
15819 | 118 if(stream_read(demuxer->stream, buf, PROBE_BUF_SIZE)!=PROBE_BUF_SIZE) |
119 return 0; | |
12164 | 120 avpd.filename= demuxer->stream->url; |
121 avpd.buf= buf; | |
122 avpd.buf_size= PROBE_BUF_SIZE; | |
123 | |
124 priv->avif= av_probe_input_format(&avpd, 1); | |
125 if(!priv->avif){ | |
126 mp_msg(MSGT_HEADER,MSGL_V,"LAVF_check: no clue about this gibberish!\n"); | |
127 return 0; | |
128 }else | |
129 mp_msg(MSGT_HEADER,MSGL_V,"LAVF_check: %s\n", priv->avif->long_name); | |
130 | |
16175 | 131 return DEMUXER_TYPE_LAVF; |
12164 | 132 } |
133 | |
16175 | 134 static demuxer_t* demux_open_lavf(demuxer_t *demuxer){ |
12164 | 135 AVFormatContext *avfc; |
136 AVFormatParameters ap; | |
137 lavf_priv_t *priv= demuxer->priv; | |
15011 | 138 int i,g; |
12164 | 139 char mp_filename[256]="mp:"; |
140 | |
141 memset(&ap, 0, sizeof(AVFormatParameters)); | |
142 | |
143 stream_seek(demuxer->stream, 0); | |
144 | |
145 register_protocol(&mp_protocol); | |
146 | |
12463 | 147 if(demuxer->stream->url) |
148 strncpy(mp_filename + 3, demuxer->stream->url, sizeof(mp_filename)-3); | |
149 else | |
150 strncpy(mp_filename + 3, "foobar.dummy", sizeof(mp_filename)-3); | |
12164 | 151 |
152 url_fopen(&priv->pb, mp_filename, URL_RDONLY); | |
153 | |
154 ((URLContext*)(priv->pb.opaque))->priv_data= demuxer->stream; | |
155 | |
156 if(av_open_input_stream(&avfc, &priv->pb, mp_filename, priv->avif, &ap)<0){ | |
157 mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_open_input_stream() failed\n"); | |
16175 | 158 return NULL; |
12164 | 159 } |
160 | |
161 priv->avfc= avfc; | |
162 | |
163 if(av_find_stream_info(avfc) < 0){ | |
164 mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_find_stream_info() failed\n"); | |
16175 | 165 return NULL; |
12164 | 166 } |
167 | |
12167 | 168 if(avfc->title [0]) demux_info_add(demuxer, "name" , avfc->title ); |
169 if(avfc->author [0]) demux_info_add(demuxer, "author" , avfc->author ); | |
170 if(avfc->copyright[0]) demux_info_add(demuxer, "copyright", avfc->copyright); | |
171 if(avfc->comment [0]) demux_info_add(demuxer, "comments" , avfc->comment ); | |
172 if(avfc->album [0]) demux_info_add(demuxer, "album" , avfc->album ); | |
173 // if(avfc->year ) demux_info_add(demuxer, "year" , avfc->year ); | |
174 // if(avfc->track ) demux_info_add(demuxer, "track" , avfc->track ); | |
175 if(avfc->genre [0]) demux_info_add(demuxer, "genre" , avfc->genre ); | |
12164 | 176 |
177 for(i=0; i<avfc->nb_streams; i++){ | |
178 AVStream *st= avfc->streams[i]; | |
16000 | 179 #if LIBAVFORMAT_BUILD >= 4629 |
180 AVCodecContext *codec= st->codec; | |
181 #else | |
12164 | 182 AVCodecContext *codec= &st->codec; |
16000 | 183 #endif |
12164 | 184 |
185 switch(codec->codec_type){ | |
186 case CODEC_TYPE_AUDIO:{ | |
187 WAVEFORMATEX *wf= calloc(sizeof(WAVEFORMATEX) + codec->extradata_size, 1); | |
18762 | 188 if(priv->audio_streams >= MAX_A_STREAMS) |
189 break; | |
12164 | 190 sh_audio_t* sh_audio=new_sh_audio(demuxer, i); |
18762 | 191 if(!sh_audio) |
192 break; | |
193 priv->astreams[priv->audio_streams] = i; | |
12164 | 194 priv->audio_streams++; |
195 if(!codec->codec_tag) | |
196 codec->codec_tag= codec_get_wav_tag(codec->codec_id); | |
197 wf->wFormatTag= codec->codec_tag; | |
198 wf->nChannels= codec->channels; | |
199 wf->nSamplesPerSec= codec->sample_rate; | |
200 wf->nAvgBytesPerSec= codec->bit_rate/8; | |
201 wf->nBlockAlign= codec->block_align; | |
202 wf->wBitsPerSample= codec->bits_per_sample; | |
203 wf->cbSize= codec->extradata_size; | |
204 if(codec->extradata_size){ | |
205 memcpy( | |
206 wf + 1, | |
207 codec->extradata, | |
208 codec->extradata_size); | |
209 } | |
210 sh_audio->wf= wf; | |
15011 | 211 sh_audio->audio.dwSampleSize= codec->block_align; |
212 if(codec->frame_size && codec->sample_rate){ | |
213 sh_audio->audio.dwScale=codec->frame_size; | |
214 sh_audio->audio.dwRate= codec->sample_rate; | |
215 }else{ | |
216 sh_audio->audio.dwScale= codec->block_align ? codec->block_align*8 : 8; | |
217 sh_audio->audio.dwRate = codec->bit_rate; | |
218 } | |
219 g= ff_gcd(sh_audio->audio.dwScale, sh_audio->audio.dwRate); | |
220 sh_audio->audio.dwScale /= g; | |
221 sh_audio->audio.dwRate /= g; | |
222 // printf("sca:%d rat:%d fs:%d sr:%d ba:%d\n", sh_audio->audio.dwScale, sh_audio->audio.dwRate, codec->frame_size, codec->sample_rate, codec->block_align); | |
12164 | 223 sh_audio->ds= demuxer->audio; |
224 sh_audio->format= codec->codec_tag; | |
225 sh_audio->channels= codec->channels; | |
226 sh_audio->samplerate= codec->sample_rate; | |
15007 | 227 sh_audio->i_bps= codec->bit_rate/8; |
16134
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
228 switch (codec->codec_id) { |
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
229 case CODEC_ID_PCM_S8: |
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
230 case CODEC_ID_PCM_U8: |
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
231 sh_audio->samplesize = 1; |
16135 | 232 break; |
16134
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
233 case CODEC_ID_PCM_S16LE: |
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
234 case CODEC_ID_PCM_S16BE: |
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
235 case CODEC_ID_PCM_U16LE: |
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
236 case CODEC_ID_PCM_U16BE: |
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
237 sh_audio->samplesize = 2; |
16135 | 238 break; |
239 case CODEC_ID_PCM_ALAW: | |
240 sh_audio->format = 0x6; | |
241 break; | |
242 case CODEC_ID_PCM_MULAW: | |
243 sh_audio->format = 0x7; | |
244 break; | |
16134
a1fd1a7eeb35
lavf demuxer with raw PCM fix (and a related hang)
reimar
parents:
16000
diff
changeset
|
245 } |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17932
diff
changeset
|
246 if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V); |
15004 | 247 if(demuxer->audio->id != i && demuxer->audio->id != -1) |
248 st->discard= AVDISCARD_ALL; | |
249 else{ | |
250 demuxer->audio->id = i; | |
251 demuxer->audio->sh= demuxer->a_streams[i]; | |
252 } | |
12164 | 253 break;} |
254 case CODEC_TYPE_VIDEO:{ | |
255 BITMAPINFOHEADER *bih=calloc(sizeof(BITMAPINFOHEADER) + codec->extradata_size,1); | |
256 sh_video_t* sh_video=new_sh_video(demuxer, i); | |
257 | |
258 priv->video_streams++; | |
259 if(!codec->codec_tag) | |
260 codec->codec_tag= codec_get_bmp_tag(codec->codec_id); | |
261 bih->biSize= sizeof(BITMAPINFOHEADER) + codec->extradata_size; | |
262 bih->biWidth= codec->width; | |
263 bih->biHeight= codec->height; | |
264 bih->biBitCount= codec->bits_per_sample; | |
265 bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount/8; | |
266 bih->biCompression= codec->codec_tag; | |
267 sh_video->bih= bih; | |
268 sh_video->disp_w= codec->width; | |
269 sh_video->disp_h= codec->height; | |
16718
044260623695
makes demux_lavf (-demuxer 35) use the framerate specified in the container
gpoirier
parents:
16346
diff
changeset
|
270 if (st->time_base.den) { /* if container has time_base, use that */ |
044260623695
makes demux_lavf (-demuxer 35) use the framerate specified in the container
gpoirier
parents:
16346
diff
changeset
|
271 sh_video->video.dwRate= st->time_base.den; |
044260623695
makes demux_lavf (-demuxer 35) use the framerate specified in the container
gpoirier
parents:
16346
diff
changeset
|
272 sh_video->video.dwScale= st->time_base.num; |
044260623695
makes demux_lavf (-demuxer 35) use the framerate specified in the container
gpoirier
parents:
16346
diff
changeset
|
273 } else { |
15308 | 274 #if LIBAVFORMAT_BUILD >= 4624 |
275 sh_video->video.dwRate= codec->time_base.den; | |
276 sh_video->video.dwScale= codec->time_base.num; | |
277 #else | |
12164 | 278 sh_video->video.dwRate= codec->frame_rate; |
279 sh_video->video.dwScale= codec->frame_rate_base; | |
15308 | 280 #endif |
16718
044260623695
makes demux_lavf (-demuxer 35) use the framerate specified in the container
gpoirier
parents:
16346
diff
changeset
|
281 } |
17556 | 282 sh_video->fps=av_q2d(st->r_frame_rate); |
283 sh_video->frametime=1/av_q2d(st->r_frame_rate); | |
12164 | 284 sh_video->format = bih->biCompression; |
12167 | 285 sh_video->aspect= codec->width * codec->sample_aspect_ratio.num |
286 / (float)(codec->height * codec->sample_aspect_ratio.den); | |
15007 | 287 sh_video->i_bps= codec->bit_rate/8; |
12167 | 288 mp_msg(MSGT_DEMUX,MSGL_DBG2,"aspect= %d*%d/(%d*%d)\n", |
289 codec->width, codec->sample_aspect_ratio.num, | |
290 codec->height, codec->sample_aspect_ratio.den); | |
291 | |
12164 | 292 sh_video->ds= demuxer->video; |
293 if(codec->extradata_size) | |
294 memcpy(sh_video->bih + 1, codec->extradata, codec->extradata_size); | |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
17932
diff
changeset
|
295 if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh_video->bih, MSGL_V); |
12164 | 296 /* short biPlanes; |
297 int biXPelsPerMeter; | |
298 int biYPelsPerMeter; | |
299 int biClrUsed; | |
300 int biClrImportant;*/ | |
15004 | 301 if(demuxer->video->id != i && demuxer->video->id != -1) |
302 st->discard= AVDISCARD_ALL; | |
303 else{ | |
304 demuxer->video->id = i; | |
305 demuxer->video->sh= demuxer->v_streams[i]; | |
306 } | |
12164 | 307 break;} |
15004 | 308 default: |
309 st->discard= AVDISCARD_ALL; | |
12164 | 310 } |
311 } | |
312 | |
313 mp_msg(MSGT_HEADER,MSGL_V,"LAVF: %d audio and %d video streams found\n",priv->audio_streams,priv->video_streams); | |
13749 | 314 mp_msg(MSGT_HEADER,MSGL_V,"LAVF: build %d\n", LIBAVFORMAT_BUILD); |
12164 | 315 if(!priv->audio_streams) demuxer->audio->id=-2; // nosound |
316 // else if(best_audio > 0 && demuxer->audio->id == -1) demuxer->audio->id=best_audio; | |
317 if(!priv->video_streams){ | |
318 if(!priv->audio_streams){ | |
319 mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF: no audio or video headers found - broken file?\n"); | |
16175 | 320 return NULL; |
12164 | 321 } |
322 demuxer->video->id=-2; // audio-only | |
323 } //else if (best_video > 0 && demuxer->video->id == -1) demuxer->video->id = best_video; | |
324 | |
16175 | 325 return demuxer; |
12164 | 326 } |
327 | |
16175 | 328 static int demux_lavf_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){ |
12164 | 329 lavf_priv_t *priv= demux->priv; |
330 AVPacket pkt; | |
331 demux_packet_t *dp; | |
332 demux_stream_t *ds; | |
333 int id; | |
334 mp_msg(MSGT_DEMUX,MSGL_DBG2,"demux_lavf_fill_buffer()\n"); | |
335 | |
336 demux->filepos=stream_tell(demux->stream); | |
337 | |
338 if(stream_eof(demux->stream)){ | |
339 // demuxre->stream->eof=1; | |
340 return 0; | |
341 } | |
342 | |
343 if(av_read_frame(priv->avfc, &pkt) < 0) | |
344 return 0; | |
345 | |
346 id= pkt.stream_index; | |
347 | |
348 if(id==demux->audio->id){ | |
349 // audio | |
350 ds=demux->audio; | |
351 if(!ds->sh){ | |
352 ds->sh=demux->a_streams[id]; | |
353 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected LAVF audio ID = %d\n",ds->id); | |
354 } | |
355 } else if(id==demux->video->id){ | |
356 // video | |
357 ds=demux->video; | |
358 if(!ds->sh){ | |
359 ds->sh=demux->v_streams[id]; | |
360 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected LAVF video ID = %d\n",ds->id); | |
361 } | |
14611 | 362 } else { |
363 av_free_packet(&pkt); | |
364 return 1; | |
365 } | |
12164 | 366 |
367 if(0/*pkt.destruct == av_destruct_packet*/){ | |
368 //ok kids, dont try this at home :) | |
369 dp=(demux_packet_t*)malloc(sizeof(demux_packet_t)); | |
370 dp->len=pkt.size; | |
371 dp->next=NULL; | |
372 dp->refcount=1; | |
373 dp->master=NULL; | |
374 dp->buffer=pkt.data; | |
375 pkt.destruct= NULL; | |
376 }else{ | |
377 dp=new_demux_packet(pkt.size); | |
378 memcpy(dp->buffer, pkt.data, pkt.size); | |
379 av_free_packet(&pkt); | |
380 } | |
381 | |
13747 | 382 if(pkt.pts != AV_NOPTS_VALUE){ |
15308 | 383 #if LIBAVFORMAT_BUILD >= 4624 |
384 dp->pts=pkt.pts * av_q2d(priv->avfc->streams[id]->time_base); | |
385 priv->last_pts= dp->pts * AV_TIME_BASE; | |
386 #else | |
13747 | 387 priv->last_pts= pkt.pts; |
388 dp->pts=pkt.pts / (float)AV_TIME_BASE; | |
15308 | 389 #endif |
13747 | 390 } |
12164 | 391 dp->pos=demux->filepos; |
392 dp->flags= !!(pkt.flags&PKT_FLAG_KEY); | |
393 // append packet to DS stream: | |
394 ds_add_packet(ds,dp); | |
395 return 1; | |
396 } | |
397 | |
17636 | 398 static void demux_seek_lavf(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags){ |
12168 | 399 lavf_priv_t *priv = demuxer->priv; |
17636 | 400 mp_msg(MSGT_DEMUX,MSGL_DBG2,"demux_seek_lavf(%p, %f, %f, %d)\n", demuxer, rel_seek_secs, audio_delay, flags); |
12168 | 401 |
13607 | 402 #if LIBAVFORMAT_BUILD < 4619 |
12168 | 403 av_seek_frame(priv->avfc, -1, priv->last_pts + rel_seek_secs*AV_TIME_BASE); |
13607 | 404 #else |
405 av_seek_frame(priv->avfc, -1, priv->last_pts + rel_seek_secs*AV_TIME_BASE, rel_seek_secs < 0 ? AVSEEK_FLAG_BACKWARD : 0); | |
406 #endif | |
12164 | 407 } |
408 | |
16175 | 409 static int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg) |
12164 | 410 { |
411 lavf_priv_t *priv = demuxer->priv; | |
412 | |
413 switch (cmd) { | |
12168 | 414 case DEMUXER_CTRL_GET_TIME_LENGTH: |
415 if (priv->avfc->duration == 0) | |
12164 | 416 return DEMUXER_CTRL_DONTKNOW; |
417 | |
16346
6ff303d2876b
Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents:
16175
diff
changeset
|
418 *((double *)arg) = (double)priv->avfc->duration / AV_TIME_BASE; |
12164 | 419 return DEMUXER_CTRL_OK; |
420 | |
421 case DEMUXER_CTRL_GET_PERCENT_POS: | |
12168 | 422 if (priv->avfc->duration == 0) |
12164 | 423 return DEMUXER_CTRL_DONTKNOW; |
424 | |
12168 | 425 *((int *)arg) = (int)(priv->last_pts*100 / priv->avfc->duration); |
426 return DEMUXER_CTRL_OK; | |
18762 | 427 case DEMUXER_CTRL_SWITCH_AUDIO: |
428 { | |
429 int id = *((int*)arg); | |
430 int newid = -2; | |
431 int i, curridx = -2; | |
432 | |
433 if(demuxer->audio->id == -2) | |
434 return DEMUXER_CTRL_NOTIMPL; | |
435 for(i = 0; i < priv->audio_streams; i++) | |
436 { | |
437 if(priv->astreams[i] == demuxer->audio->id) //current stream id | |
438 { | |
439 curridx = i; | |
440 break; | |
441 } | |
442 } | |
443 | |
444 if(id < 0) | |
445 { | |
446 i = (curridx + 1) % priv->audio_streams; | |
447 newid = priv->astreams[i]; | |
448 } | |
449 else | |
450 { | |
451 for(i = 0; i < priv->audio_streams; i++) | |
452 { | |
453 if(priv->astreams[i] == id) | |
454 { | |
455 newid = id; | |
456 break; | |
457 } | |
458 } | |
459 } | |
460 if(newid == -2 || i == curridx) | |
461 return DEMUXER_CTRL_NOTIMPL; | |
462 else | |
463 { | |
464 ds_free_packs(demuxer->audio); | |
465 priv->avfc->streams[demuxer->audio->id]->discard = AVDISCARD_ALL; | |
466 *((int*)arg) = demuxer->audio->id = newid; | |
467 priv->avfc->streams[newid]->discard = AVDISCARD_NONE; | |
468 return DEMUXER_CTRL_OK; | |
469 } | |
470 } | |
12164 | 471 default: |
472 return DEMUXER_CTRL_NOTIMPL; | |
473 } | |
474 } | |
475 | |
16175 | 476 static void demux_close_lavf(demuxer_t *demuxer) |
12164 | 477 { |
478 lavf_priv_t* priv = demuxer->priv; | |
479 if (priv){ | |
12304
434242b0706c
fix possible segfault on lavf demuxer patch by (adland <adland123 at yahoo dot com>)
michael
parents:
12168
diff
changeset
|
480 if(priv->avfc) |
434242b0706c
fix possible segfault on lavf demuxer patch by (adland <adland123 at yahoo dot com>)
michael
parents:
12168
diff
changeset
|
481 { |
434242b0706c
fix possible segfault on lavf demuxer patch by (adland <adland123 at yahoo dot com>)
michael
parents:
12168
diff
changeset
|
482 av_close_input_file(priv->avfc); priv->avfc= NULL; |
434242b0706c
fix possible segfault on lavf demuxer patch by (adland <adland123 at yahoo dot com>)
michael
parents:
12168
diff
changeset
|
483 } |
12164 | 484 free(priv); demuxer->priv= NULL; |
485 } | |
486 } | |
487 | |
16175 | 488 |
489 demuxer_desc_t demuxer_desc_lavf = { | |
490 "libavformat demuxer", | |
491 "lavf", | |
492 "libavformat", | |
493 "Michael Niedermayer", | |
494 "supports many formats, requires libavformat", | |
495 DEMUXER_TYPE_LAVF, | |
496 0, // Check after other demuxer | |
497 lavf_check_file, | |
498 demux_lavf_fill_buffer, | |
499 demux_open_lavf, | |
500 demux_close_lavf, | |
501 demux_seek_lavf, | |
502 demux_lavf_control | |
503 }; | |
504 |