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