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