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