Mercurial > mplayer.hg
annotate mplayer.c @ 549:c97496b240c1
new options: -dumpaudio and -dumpvideo
author | arpi_esp |
---|---|
date | Fri, 20 Apr 2001 18:28:13 +0000 |
parents | 22ed5f5821e2 |
children | c2a449f90087 |
rev | line source |
---|---|
1 | 1 // AVI & MPEG Player v0.11 (C) 2000-2001. by A'rpi/ESP-team |
2 | |
112 | 3 // Enable ALSA emulation (using 32kB audio buffer) - timer testing only |
1 | 4 //#define SIMULATE_ALSA |
5 | |
6 #ifdef USE_XMMP_AUDIO | |
7 #define OUTBURST 4096 | |
8 #else | |
9 //#define OUTBURST 1024 | |
10 #define OUTBURST 512 | |
11 #endif | |
12 | |
13 #include <stdio.h> | |
14 #include <stdlib.h> | |
109 | 15 #include <string.h> |
1 | 16 |
17 #include <signal.h> | |
18 | |
19 #include <sys/ioctl.h> | |
20 #include <unistd.h> | |
21 #include <sys/mman.h> | |
22 | |
23 #include <sys/types.h> | |
24 #include <sys/wait.h> | |
25 #include <sys/time.h> | |
26 #include <sys/stat.h> | |
27 #include <fcntl.h> | |
28 #include <sys/soundcard.h> | |
29 #include <linux/cdrom.h> | |
30 | |
31 #include "version.h" | |
32 #include "config.h" | |
33 | |
147 | 34 #include "cfgparser.h" |
151 | 35 #include "cfg-mplayer-def.h" |
147 | 36 |
258 | 37 #include "subreader.h" |
38 | |
36 | 39 #include "libvo/video_out.h" |
220 | 40 #include "libvo/sub.h" |
36 | 41 |
1 | 42 // CODECS: |
43 #include "mp3lib/mp3.h" | |
44 #include "libac3/ac3.h" | |
45 #include "libmpeg2/mpeg2.h" | |
46 #include "libmpeg2/mpeg2_internal.h" | |
47 | |
48 #include "loader.h" | |
49 #include "wine/avifmt.h" | |
50 | |
303 | 51 #include "codec-cfg.h" |
175 | 52 |
492 | 53 #include "dvdauth.h" |
54 | |
175 | 55 #ifdef USE_DIRECTSHOW |
56 #include "DirectShow/DS_VideoDec.h" | |
190 | 57 #include "DirectShow/DS_AudioDec.h" |
175 | 58 #endif |
59 | |
1 | 60 #include "opendivx/decore.h" |
61 | |
62 | |
63 #ifdef USE_XMMP_AUDIO | |
64 #include "libxmm/xmmp.h" | |
65 #include "libxmm/libxmm.h" | |
66 XMM xmm; | |
67 XMM_PluginSound *pSound=NULL; | |
68 #endif | |
69 | |
33 | 70 extern int vo_screenwidth; |
1 | 71 |
72 extern char* win32_codec_name; // must be set before calling DrvOpen() !!! | |
73 | |
74 extern int errno; | |
75 | |
76 #include "linux/getch2.h" | |
77 #include "linux/keycodes.h" | |
78 #include "linux/timer.h" | |
79 #include "linux/shmem.h" | |
80 | |
81 #ifdef HAVE_LIRC | |
82 #include "lirc_mp.h" | |
83 #endif | |
84 | |
85 #include "help_mp.h" | |
86 | |
87 #define DEBUG if(0) | |
362 | 88 int verbose=0; |
1 | 89 |
398 | 90 #define ABS(x) (((x)>=0)?(x):(-(x))) |
91 | |
258 | 92 //**************************************************************************// |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
93 // .SUB |
258 | 94 //**************************************************************************// |
95 | |
96 static current_sub=0; | |
97 | |
98 static subtitle* subtitles=NULL; | |
482 | 99 static int nosub_range_start=-1; |
100 static int nosub_range_end=-1; | |
258 | 101 |
482 | 102 void find_sub(int key){ |
258 | 103 int i,j; |
482 | 104 if(vo_sub){ |
105 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
106 } else { | |
107 if(key>nosub_range_start && key<nosub_range_end) return; // OK! | |
108 } | |
109 // sub changed! | |
110 | |
111 // printf("\r---- sub changed ----\n"); | |
112 | |
113 // check next sub. | |
114 if(current_sub>=0 && current_sub+1<sub_num){ | |
115 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
116 // no sub | |
117 nosub_range_start=subtitles[current_sub].end; | |
118 nosub_range_end=subtitles[current_sub+1].start; | |
119 vo_sub=NULL; | |
120 return; | |
121 } | |
122 // next sub? | |
123 ++current_sub; | |
124 vo_sub=&subtitles[current_sub]; | |
125 if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! | |
126 } | |
127 | |
128 // printf("\r---- sub log search... ----\n"); | |
129 | |
258 | 130 // use logarithmic search: |
131 i=0;j=sub_num-1; | |
132 // printf("Searching %d in %d..%d\n",key,subtitles[i].start,subtitles[j].end); | |
133 while(j>=i){ | |
134 current_sub=(i+j+1)/2; | |
482 | 135 vo_sub=&subtitles[current_sub]; |
136 if(key<vo_sub->start) j=current_sub-1; | |
137 else if(key>vo_sub->end) i=current_sub+1; | |
138 else return; // found! | |
258 | 139 } |
482 | 140 // if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! |
141 | |
142 // check where are we... | |
143 if(key<vo_sub->start){ | |
144 if(current_sub<=0){ | |
145 // before the first sub | |
146 nosub_range_start=key-1; // tricky | |
147 nosub_range_end=vo_sub->start; | |
148 // printf("FIRST... key=%d end=%d \n",key,vo_sub->start); | |
149 vo_sub=NULL; | |
150 return; | |
151 } | |
152 --current_sub; | |
153 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
154 // no sub | |
155 nosub_range_start=subtitles[current_sub].end; | |
156 nosub_range_end=subtitles[current_sub+1].start; | |
157 // printf("No sub... 1 \n"); | |
158 vo_sub=NULL; | |
159 return; | |
160 } | |
161 printf("HEH???? "); | |
162 } else { | |
163 if(key<=vo_sub->end) printf("JAJJ! "); else | |
164 if(current_sub+1>=sub_num){ | |
165 // at the end? | |
166 nosub_range_start=vo_sub->end; | |
167 nosub_range_end=0x7FFFFFFF; // MAXINT | |
168 // printf("END!?\n"); | |
169 vo_sub=NULL; | |
170 return; | |
171 } else | |
172 if(key>subtitles[current_sub].end && key<subtitles[current_sub+1].start){ | |
173 // no sub | |
174 nosub_range_start=subtitles[current_sub].end; | |
175 nosub_range_end=subtitles[current_sub+1].start; | |
176 // printf("No sub... 2 \n"); | |
177 vo_sub=NULL; | |
178 return; | |
179 } | |
180 } | |
181 | |
182 printf("SUB ERROR: %d ? %d --- %d [%d] \n",key,vo_sub->start,vo_sub->end,current_sub); | |
183 | |
258 | 184 vo_sub=NULL; // no sub here |
185 } | |
186 | |
187 //**************************************************************************// | |
188 // Config file | |
189 //**************************************************************************// | |
190 | |
153 | 191 static int cfg_inc_verbose(struct config *conf){ |
192 ++verbose; | |
193 return 0; | |
194 } | |
195 | |
162 | 196 static int cfg_include(struct config *conf, char *filename){ |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
197 return parse_config_file(conf, filename); |
162 | 198 } |
199 | |
178 | 200 char *get_path(char *filename){ |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
201 char *homedir; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
202 char *buff; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
203 static char *config_dir = "/.mplayer"; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
204 int len; |
178 | 205 |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
206 if ((homedir = getenv("HOME")) == NULL) |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
207 return NULL; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
208 len = strlen(homedir) + strlen(config_dir) + 1; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
209 if (filename == NULL) { |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
210 if ((buff = (char *) malloc(len)) == NULL) |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
211 return NULL; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
212 sprintf(buff, "%s%s", homedir, config_dir); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
213 } else { |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
214 len += strlen(filename) + 1; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
215 if ((buff = (char *) malloc(len)) == NULL) |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
216 return NULL; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
217 sprintf(buff, "%s%s/%s", homedir, config_dir, filename); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
218 } |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
219 return buff; |
178 | 220 } |
221 | |
1 | 222 static int max_framesize=0; |
223 | |
442 | 224 //static int dbg_es_sent=0; |
225 //static int dbg_es_rcvd=0; | |
1 | 226 |
227 //static int show_packets=0; | |
228 | |
229 //**************************************************************************// | |
442 | 230 //**************************************************************************// |
231 // Input media streaming & demultiplexer: | |
232 //**************************************************************************// | |
233 | |
234 #include "stream.c" | |
235 #include "demuxer.c" | |
236 | |
237 #include "stheader.h" | |
1 | 238 |
239 typedef struct { | |
240 // file: | |
241 MainAVIHeader avih; | |
242 unsigned int movi_start; | |
243 unsigned int movi_end; | |
244 // index: | |
245 AVIINDEXENTRY* idx; | |
246 int idx_size; | |
247 int idx_pos; | |
248 int idx_pos_a; | |
249 int idx_pos_v; | |
250 int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez | |
442 | 251 // streams: |
252 sh_audio_t* a_streams[256]; | |
253 sh_video_t* v_streams[256]; | |
1 | 254 // video: |
291 | 255 unsigned int bitrate; |
1 | 256 } avi_header_t; |
257 | |
258 avi_header_t avi_header; | |
259 | |
260 #include "aviprint.c" | |
261 | |
442 | 262 sh_audio_t* new_sh_audio(int id){ |
263 if(avi_header.a_streams[id]){ | |
264 printf("Warning! Audio stream header %d redefined!\n",id); | |
265 } else { | |
500
c2b3a1f340c8
MPEG-ES segfault fixed, stream list printfs moved v 1->0
arpi_esp
parents:
495
diff
changeset
|
266 printf("==> Found audio stream: %d\n",id); |
442 | 267 avi_header.a_streams[id]=malloc(sizeof(sh_audio_t)); |
268 memset(avi_header.a_streams[id],0,sizeof(sh_audio_t)); | |
269 } | |
270 return avi_header.a_streams[id]; | |
271 } | |
1 | 272 |
442 | 273 sh_video_t* new_sh_video(int id){ |
274 if(avi_header.v_streams[id]){ | |
275 printf("Warning! video stream header %d redefined!\n",id); | |
276 } else { | |
500
c2b3a1f340c8
MPEG-ES segfault fixed, stream list printfs moved v 1->0
arpi_esp
parents:
495
diff
changeset
|
277 printf("==> Found video stream: %d\n",id); |
442 | 278 avi_header.v_streams[id]=malloc(sizeof(sh_video_t)); |
279 memset(avi_header.v_streams[id],0,sizeof(sh_video_t)); | |
280 } | |
281 return avi_header.v_streams[id]; | |
282 } | |
1 | 283 |
291 | 284 |
1 | 285 #include "demux_avi.c" |
286 #include "demux_mpg.c" | |
287 | |
288 demuxer_t *demuxer=NULL; | |
289 demux_stream_t *d_audio=NULL; | |
290 demux_stream_t *d_video=NULL; | |
291 | |
442 | 292 sh_audio_t *sh_audio=NULL;//&sh_audio_i; |
293 sh_video_t *sh_video=NULL;//&sh_video_i; | |
294 | |
295 char* encode_name=NULL; | |
296 char* encode_index_name=NULL; | |
297 int encode_bitrate=0; | |
291 | 298 |
1 | 299 // MPEG video stream parser: |
300 #include "parse_es.c" | |
301 | |
442 | 302 extern picture_t *picture; |
303 | |
112 | 304 static const int frameratecode2framerate[16] = { |
305 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, | |
306 60*10000, 0,0,0,0,0,0,0 | |
307 }; | |
308 | |
111 | 309 //**************************************************************************// |
310 // Audio codecs: | |
311 //**************************************************************************// | |
312 | |
296 | 313 // MP3 decoder buffer callback: |
1 | 314 int mplayer_audio_read(char *buf,int size){ |
315 int len; | |
291 | 316 len=demux_read_data(sh_audio->ds,buf,size); |
1 | 317 return len; |
318 } | |
319 | |
296 | 320 // AC3 decoder buffer callback: |
1 | 321 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
291 | 322 int len=ds_get_packet(sh_audio->ds,(char**)start); |
1 | 323 //printf("<ac3:%d>\n",len); |
324 if(len<0) | |
325 *start = *end = NULL; | |
326 else | |
327 *end = *start + len; | |
328 } | |
329 | |
330 #include "alaw.c" | |
331 #include "xa/xa_gsm.h" | |
332 | |
291 | 333 #include "dec_audio.c" |
334 | |
111 | 335 //**************************************************************************// |
336 // The OpenDivX stuff: | |
337 //**************************************************************************// | |
338 | |
1 | 339 unsigned char *opendivx_src[3]; |
340 int opendivx_stride[3]; | |
341 | |
111 | 342 // callback, the opendivx decoder calls this for each frame: |
80 | 343 void convert_linux(unsigned char *puc_y, int stride_y, |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
344 unsigned char *puc_u, unsigned char *puc_v, int stride_uv, |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
345 unsigned char *bmp, int width_y, int height_y){ |
1 | 346 |
347 // printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv); | |
348 | |
349 opendivx_src[0]=puc_y; | |
350 opendivx_src[1]=puc_u; | |
351 opendivx_src[2]=puc_v; | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
352 |
1 | 353 opendivx_stride[0]=stride_y; |
354 opendivx_stride[1]=stride_uv; | |
355 opendivx_stride[2]=stride_uv; | |
356 } | |
357 | |
358 //**************************************************************************// | |
359 | |
360 #ifdef SIMULATE_ALSA | |
361 // Simulate ALSA buffering on OSS device :) (for testing...) | |
362 | |
363 #define fake_ALSA_size 32768 | |
364 char fake_ALSA_buffer[fake_ALSA_size]; | |
365 int fake_ALSA_len=0; | |
366 | |
367 void fake_ALSA_write(int audio_fd,char* a_buffer,int len){ | |
368 while(len>0){ | |
369 int x=fake_ALSA_size-fake_ALSA_len; | |
370 if(x>0){ | |
371 if(x>len) x=len; | |
372 memcpy(&fake_ALSA_buffer[fake_ALSA_len],a_buffer,x); | |
373 fake_ALSA_len+=x;len-=x; | |
374 } | |
375 if(fake_ALSA_len>=fake_ALSA_size){ | |
376 write(audio_fd,fake_ALSA_buffer,fake_ALSA_len); | |
377 fake_ALSA_len=0; | |
378 } | |
379 } | |
380 } | |
381 #endif | |
382 //**************************************************************************// | |
383 | |
384 // AVI file header reader/parser/writer: | |
385 #include "aviheader.c" | |
386 #include "aviwrite.c" | |
387 | |
388 // ASF headers: | |
389 #include "asfheader.c" | |
390 #include "demux_asf.c" | |
391 | |
392 // DLL codecs init routines | |
393 #include "dll_init.c" | |
394 | |
112 | 395 // Common FIFO functions, and keyboard/event FIFO code |
396 #include "fifo.c" | |
397 | |
1 | 398 //**************************************************************************// |
399 | |
400 static vo_functions_t *video_out=NULL; | |
401 | |
402 static int play_in_bg=0; | |
403 | |
404 void exit_player(char* how){ | |
405 if(how) printf("\nExiting... (%s)\n",how); | |
340 | 406 if(verbose) printf("max framesize was %d bytes\n",max_framesize); |
1 | 407 // restore terminal: |
408 getch2_disable(); | |
398 | 409 video_out->uninit(); |
1 | 410 #ifdef USE_XMMP_AUDIO |
411 if(verbose) printf("XMM: closing audio driver...\n"); | |
412 if(pSound){ | |
413 pSound->Exit( pSound ); | |
414 xmm_Exit( &xmm ); | |
415 } | |
416 #endif | |
417 if(encode_name) avi_fixate(); | |
418 #ifdef HAVE_LIRC | |
419 lirc_mp_cleanup(); | |
420 #endif | |
421 //if(play_in_bg) system("xsetroot -solid \\#000000"); | |
422 exit(1); | |
423 } | |
424 | |
425 static char* current_module=NULL; // for debugging | |
426 | |
427 void exit_sighandler(int x){ | |
428 static int sig_count=0; | |
429 ++sig_count; | |
430 if(sig_count==2) exit(1); | |
431 if(sig_count>2){ | |
432 // can't stop :( | |
433 kill(getpid(),SIGKILL); | |
434 } | |
435 printf("\nMPlayer interrupted by signal %d in module: %s \n",x, | |
436 current_module?current_module:"unknown" | |
437 ); | |
438 exit_player(NULL); | |
439 } | |
440 | |
441 int divx_quality=0; | |
442 | 442 extern int vo_dbpp; |
1 | 443 |
147 | 444 int main(int argc,char* argv[], char *envp[]){ |
1 | 445 char* filename=NULL; //"MI2-Trailer.avi"; |
446 int i; | |
447 int seek_to_sec=0; | |
448 int seek_to_byte=0; | |
449 int f; // filedes | |
450 int stream_type; | |
451 stream_t* stream=NULL; | |
452 int file_format=DEMUXER_TYPE_UNKNOWN; | |
442 | 453 int has_audio=1; |
454 //int has_video=1; | |
1 | 455 // |
456 int audio_format=0; // override | |
457 #ifdef ALSA_TIMER | |
458 int alsa=1; | |
459 #else | |
460 int alsa=0; | |
461 #endif | |
462 int audio_buffer_size=-1; | |
463 int audio_id=-1; | |
464 int video_id=-1; | |
465 float default_max_pts_correction=0.01f; | |
466 int delay_corrected=1; | |
467 float force_fps=0; | |
468 float audio_delay=0; | |
469 int vcd_track=0; | |
470 #ifdef VCD_CACHE | |
471 int vcd_cache_size=128; | |
472 #endif | |
473 int no_index=0; | |
474 #ifdef AVI_SYNC_BPS | |
475 int pts_from_bps=1; | |
476 #else | |
477 int pts_from_bps=0; | |
478 #endif | |
479 char* title="MPlayer"; | |
480 // screen info: | |
481 char* video_driver=NULL; //"mga"; // default | |
482 int fullscreen=0; | |
208
ae0f909ccc7c
Adds code to deal with vidmode selection. -- mgraffam
mgraffam
parents:
190
diff
changeset
|
483 int vidmode=0; |
337 | 484 int softzoom=0; |
485 int screen_size_x=0;//SCREEN_SIZE_X; | |
486 int screen_size_y=0;//SCREEN_SIZE_Y; | |
1 | 487 int screen_size_xy=0; |
488 // movie info: | |
489 int out_fmt=0; | |
490 char *dsp="/dev/dsp"; | |
491 int force_ni=0; | |
178 | 492 char *conffile; |
151 | 493 int conffile_fd; |
212 | 494 char *font_name=NULL; |
215 | 495 float font_factor=0.75; |
258 | 496 char *sub_name=NULL; |
497 float sub_delay=0; | |
498 float sub_fps=0; | |
510 | 499 int sub_auto = 1; |
549 | 500 char stream_dump_name=NULL; |
501 int stream_dump_type=0; | |
388 | 502 //int user_bpp=0; |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
503 |
459 | 504 #include "mixer.h" |
147 | 505 #include "cfg-mplayer.h" |
1 | 506 |
507 printf("%s",banner_text); | |
508 | |
147 | 509 if (parse_config_file(conf, "/etc/mplayer.conf") < 0) |
510 exit(1); | |
178 | 511 if ((conffile = get_path("")) == NULL) { |
147 | 512 printf("Can't find HOME dir\n"); |
513 } else { | |
178 | 514 mkdir(conffile, 0777); |
515 free(conffile); | |
516 if ((conffile = get_path("config")) == NULL) { | |
517 printf("get_path(\"config\") sziiiivas\n"); | |
518 } else { | |
519 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) { | |
520 printf("Creating config file: %s\n", conffile); | |
521 write(conffile_fd, default_config, strlen(default_config)); | |
522 close(conffile_fd); | |
523 } | |
524 if (parse_config_file(conf, conffile) < 0) | |
525 exit(1); | |
526 free(conffile); | |
151 | 527 } |
1 | 528 } |
147 | 529 if (parse_command_line(conf, argc, argv, envp, &filename) < 0) |
530 exit(1); | |
1 | 531 |
532 // Many users forget to include command line in bugreports... | |
533 if(verbose){ | |
534 printf("CommandLine:"); | |
535 for(i=1;i<argc;i++)printf(" '%s'",argv[i]); | |
536 printf("\n"); | |
537 } | |
538 | |
539 if(video_driver && strcmp(video_driver,"help")==0){ | |
540 printf("Available video output drivers:\n"); | |
541 i=0; | |
542 while (video_out_drivers[i]) { | |
543 const vo_info_t *info = video_out_drivers[i++]->get_info (); | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
544 printf("\t%s\t%s\n", info->short_name, info->name); |
1 | 545 } |
546 printf("\n"); | |
547 exit(0); | |
548 } | |
549 | |
442 | 550 if(!filename){ |
551 if(vcd_track) filename="/dev/cdrom"; | |
552 else { | |
553 printf("%s",help_text); exit(0); | |
554 } | |
555 } | |
556 | |
557 // check video_out driver name: | |
558 if(!video_driver) | |
559 video_out=video_out_drivers[0]; | |
560 else | |
561 for (i=0; video_out_drivers[i] != NULL; i++){ | |
562 const vo_info_t *info = video_out_drivers[i]->get_info (); | |
563 if(strcmp(info->short_name,video_driver) == 0){ | |
564 video_out = video_out_drivers[i];break; | |
565 } | |
566 } | |
567 if(!video_out){ | |
568 printf("Invalid video output driver name: %s\n",video_driver); | |
569 return 0; | |
570 } | |
571 | |
572 // check codec.conf | |
573 if(!parse_codec_cfg(get_path("codecs.conf"))){ | |
574 printf("(copy/link DOCS/codecs.conf to ~/.mplayer/codecs.conf)\n"); | |
575 exit(1); | |
576 } | |
577 | |
212 | 578 // check font |
579 if(font_name){ | |
337 | 580 vo_font=read_font_desc(font_name,font_factor,verbose>1); |
212 | 581 if(!vo_font) printf("Can't load font: %s\n",font_name); |
220 | 582 } else { |
583 // try default: | |
337 | 584 vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1); |
212 | 585 } |
586 | |
258 | 587 // check .sub |
588 if(sub_name){ | |
589 subtitles=sub_read_file(sub_name); | |
590 if(!subtitles) printf("Can't load subtitles: %s\n",font_name); | |
591 } else { | |
510 | 592 if ( sub_auto ) |
593 { | |
594 // auto load sub file ... | |
595 subtitles=sub_read_file( sub_filename( filename ) ); | |
596 if ( subtitles == NULL ) subtitles=sub_read_file(get_path("default.sub")); // try default: | |
597 } else subtitles=sub_read_file(get_path("default.sub")); // try default: | |
258 | 598 } |
599 | |
600 | |
1 | 601 if(vcd_track){ |
602 //============ Open VideoCD track ============== | |
603 f=open(filename,O_RDONLY); | |
604 if(f<0){ printf("CD-ROM Device '%s' not found!\n",filename);return 1; } | |
605 vcd_read_toc(f); | |
606 if(!vcd_seek_to_track(f,vcd_track)){ printf("Error selecting VCD track!\n");return 1;} | |
607 seek_to_byte+=VCD_SECTOR_DATA*vcd_get_msf(); | |
608 if(verbose) printf("VCD start byte position: 0x%X\n",seek_to_byte); | |
609 stream_type=STREAMTYPE_VCD; | |
610 #ifdef VCD_CACHE | |
611 vcd_cache_init(vcd_cache_size); | |
612 #endif | |
613 } else { | |
614 //============ Open plain FILE ============ | |
615 f=open(filename,O_RDONLY); | |
616 if(f<0){ printf("File not found: '%s'\n",filename);return 1; } | |
492 | 617 #ifdef HAVE_LIBCSS |
546 | 618 if (dvdimportkey) { |
619 if (dvd_import_key(dvdimportkey)) { | |
620 fprintf(stderr,"Error processing DVD KEY.\n"); | |
621 exit(1); | |
622 } | |
623 printf("DVD command line requested key is stored for descrambling.\n"); | |
624 } | |
492 | 625 if (dvd_device) { |
626 if (dvd_auth(dvd_device,f)) exit(0); | |
627 printf("DVD auth sequence seems to be OK.\n"); | |
628 } | |
629 #endif | |
1 | 630 stream_type=STREAMTYPE_FILE; |
631 } | |
632 | |
633 stream=new_stream(f,stream_type); | |
634 | |
635 //============ Open & Sync stream and detect file format =============== | |
636 | |
442 | 637 if(!has_audio) audio_id=-2; // do NOT read audio packets... |
1 | 638 |
639 //=============== Try to open as AVI file: ================= | |
640 stream_reset(stream); | |
641 demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id); | |
642 stream_seek(demuxer->stream,seek_to_byte); | |
643 { //---- RIFF header: | |
644 int id=stream_read_dword_le(demuxer->stream); // "RIFF" | |
645 if(id==mmioFOURCC('R','I','F','F')){ | |
646 stream_read_dword_le(demuxer->stream); //filesize | |
647 id=stream_read_dword_le(demuxer->stream); // "AVI " | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
648 if(id==formtypeAVI){ |
1 | 649 printf("Detected AVI file format!\n"); |
650 file_format=DEMUXER_TYPE_AVI; | |
651 } | |
652 } | |
653 } | |
654 //=============== Try to open as ASF file: ================= | |
655 if(file_format==DEMUXER_TYPE_UNKNOWN){ | |
656 stream_reset(stream); | |
657 demuxer=new_demuxer(stream,DEMUXER_TYPE_ASF,audio_id,video_id); | |
658 stream_seek(demuxer->stream,seek_to_byte); | |
659 if(asf_check_header()){ | |
660 printf("Detected ASF file format!\n"); | |
661 file_format=DEMUXER_TYPE_ASF; | |
662 } | |
663 } | |
664 //=============== Try to open as MPEG-PS file: ================= | |
665 if(file_format==DEMUXER_TYPE_UNKNOWN){ | |
666 stream_reset(stream); | |
667 demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_PS,audio_id,video_id); | |
668 stream_seek(demuxer->stream,seek_to_byte); | |
669 if(audio_format) demuxer->audio->type=audio_format; // override audio format | |
670 if(ds_fill_buffer(demuxer->video)){ | |
671 printf("Detected MPEG-PS file format!\n"); | |
672 file_format=DEMUXER_TYPE_MPEG_PS; | |
673 } else { | |
674 // some hack to get meaningfull error messages to our unhappy users: | |
675 // if(num_elementary_packets100>16 && | |
676 // abs(num_elementary_packets101-num_elementary_packets100)<8){ | |
677 if(num_elementary_packets100>=2 && num_elementary_packets101>=2 && | |
678 abs(num_elementary_packets101-num_elementary_packets100)<8){ | |
679 file_format=DEMUXER_TYPE_MPEG_ES; // <-- hack is here :) | |
680 } else { | |
681 if(demuxer->synced==2) | |
682 printf("Missing MPEG video stream!? contact the author, it may be a bug :(\n"); | |
683 else | |
684 printf("Not MPEG System Stream format... (maybe Transport Stream?)\n"); | |
685 } | |
686 } | |
687 } | |
688 //=============== Try to open as MPEG-ES file: ================= | |
689 if(file_format==DEMUXER_TYPE_MPEG_ES){ // little hack, see above! | |
690 stream_reset(stream); | |
691 demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_ES,audio_id,video_id); | |
692 stream_seek(demuxer->stream,seek_to_byte); | |
693 if(!ds_fill_buffer(demuxer->video)){ | |
694 printf("Invalid MPEG-ES stream??? contact the author, it may be a bug :(\n"); | |
695 file_format=DEMUXER_TYPE_UNKNOWN; | |
696 } else { | |
697 printf("Detected MPEG-ES file format!\n"); | |
698 } | |
699 } | |
700 //=============== Unknown, exiting... =========================== | |
701 if(file_format==DEMUXER_TYPE_UNKNOWN){ | |
702 printf("============= Sorry, this file format not recognized/supported ===============\n"); | |
703 printf("=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n"); | |
704 exit(1); | |
705 } | |
706 //====== File format recognized, set up these for compatibility: ========= | |
707 d_audio=demuxer->audio; | |
708 d_video=demuxer->video; | |
442 | 709 //d_audio->sh=sh_audio; |
710 //d_video->sh=sh_video; | |
711 //sh_audio=d_audio->sh;sh_audio->ds=d_audio; | |
712 //sh_video=d_video->sh;sh_video->ds=d_video; | |
1 | 713 |
714 switch(file_format){ | |
715 case DEMUXER_TYPE_AVI: { | |
716 //---- AVI header: | |
717 read_avi_header(no_index); | |
718 stream_reset(demuxer->stream); | |
719 stream_seek(demuxer->stream,avi_header.movi_start); | |
720 avi_header.idx_pos=0; | |
721 avi_header.idx_pos_a=0; | |
722 avi_header.idx_pos_v=0; | |
723 if(avi_header.idx_size>0){ | |
724 // decide index format: | |
725 if(avi_header.idx[0].dwChunkOffset<avi_header.movi_start) | |
726 avi_header.idx_offset=avi_header.movi_start-4; | |
727 else | |
728 avi_header.idx_offset=0; | |
729 if(verbose) printf("AVI index offset: %d\n",avi_header.idx_offset); | |
730 } | |
731 demuxer->endpos=avi_header.movi_end; | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
732 |
1 | 733 if(avi_header.idx_size>0){ |
734 // check that file is non-interleaved: | |
735 int i; | |
736 int a_pos=-1; | |
737 int v_pos=-1; | |
738 for(i=0;i<avi_header.idx_size;i++){ | |
739 AVIINDEXENTRY* idx=&avi_header.idx[i]; | |
740 demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid); | |
741 int pos=idx->dwChunkOffset+avi_header.idx_offset; | |
742 if(a_pos==-1 && ds==demuxer->audio){ | |
743 a_pos=pos; | |
744 if(v_pos!=-1) break; | |
745 } | |
746 if(v_pos==-1 && ds==demuxer->video){ | |
747 v_pos=pos; | |
748 if(a_pos!=-1) break; | |
749 } | |
750 } | |
751 if(v_pos==-1){ | |
752 printf("AVI_NI: missing video stream!? contact the author, it may be a bug :(\n"); | |
753 exit(1); | |
754 } | |
755 if(a_pos==-1){ | |
756 printf("AVI_NI: No audio stream found -> nosound\n"); | |
757 has_audio=0; | |
758 } else { | |
759 if(force_ni || abs(a_pos-v_pos)>0x100000){ // distance > 1MB | |
760 printf("Detected NON-INTERLEAVED AVI file-format!\n"); | |
761 demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!! | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
762 pts_from_bps=1; // force BPS sync! |
1 | 763 } |
764 } | |
765 } else { | |
766 // no index | |
767 if(force_ni){ | |
768 printf("Using NON-INTERLEAVED Broken AVI file-format!\n"); | |
769 demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!! | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
770 avi_header.idx_pos_a= |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
771 avi_header.idx_pos_v=avi_header.movi_start; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
772 pts_from_bps=1; // force BPS sync! |
1 | 773 } |
774 } | |
775 if(!ds_fill_buffer(d_video)){ | |
776 printf("AVI: missing video stream!? contact the author, it may be a bug :(\n"); | |
777 exit(1); | |
778 } | |
442 | 779 sh_video=d_video->sh;sh_video->ds=d_video; |
1 | 780 if(has_audio){ |
442 | 781 if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id); |
1 | 782 if(!ds_fill_buffer(d_audio)){ |
442 | 783 printf("AVI: No Audio stream found... ->nosound\n"); |
1 | 784 has_audio=0; |
442 | 785 sh_audio=NULL; |
786 } else { | |
787 sh_audio=d_audio->sh;sh_audio->ds=d_audio; | |
788 sh_audio->format=sh_audio->wf->wFormatTag; | |
789 } | |
1 | 790 } |
398 | 791 // calc. FPS: |
792 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; | |
793 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; | |
375 | 794 // calculating video bitrate: |
795 avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8; | |
796 if(sh_audio) avi_header.bitrate-=sh_audio->audio.dwLength; | |
797 if(verbose) printf("AVI video length=%d\n",avi_header.bitrate); | |
398 | 798 avi_header.bitrate=((float)avi_header.bitrate/(float)sh_video->video.dwLength)*sh_video->fps; |
375 | 799 printf("VIDEO: [%.4s] %dx%d %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", |
442 | 800 &sh_video->bih->biCompression, |
801 sh_video->bih->biWidth, | |
802 sh_video->bih->biHeight, | |
803 sh_video->bih->biBitCount, | |
398 | 804 sh_video->fps, |
375 | 805 avi_header.bitrate*0.008f, |
806 avi_header.bitrate/1024.0f ); | |
1 | 807 break; |
808 } | |
809 case DEMUXER_TYPE_ASF: { | |
810 //---- ASF header: | |
811 read_asf_header(); | |
812 stream_reset(demuxer->stream); | |
813 stream_seek(demuxer->stream,avi_header.movi_start); | |
814 avi_header.idx_pos=0; | |
815 demuxer->endpos=avi_header.movi_end; | |
816 if(!ds_fill_buffer(d_video)){ | |
817 printf("ASF: missing video stream!? contact the author, it may be a bug :(\n"); | |
818 exit(1); | |
819 } | |
442 | 820 sh_video=d_video->sh;sh_video->ds=d_video; |
1 | 821 if(has_audio){ |
822 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id); | |
823 if(!ds_fill_buffer(d_audio)){ | |
824 printf("ASF: No Audio stream found... ->nosound\n"); | |
825 has_audio=0; | |
442 | 826 sh_audio=NULL; |
827 } else { | |
828 sh_audio=d_audio->sh;sh_audio->ds=d_audio; | |
829 sh_audio->format=sh_audio->wf->wFormatTag; | |
830 } | |
1 | 831 } |
398 | 832 sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms |
375 | 833 printf("VIDEO: [%.4s] %dx%d %dbpp\n", |
442 | 834 &sh_video->bih->biCompression, |
835 sh_video->bih->biWidth, | |
836 sh_video->bih->biHeight, | |
837 sh_video->bih->biBitCount); | |
1 | 838 break; |
839 } | |
840 case DEMUXER_TYPE_MPEG_ES: { | |
442 | 841 d_audio->type=0; |
500
c2b3a1f340c8
MPEG-ES segfault fixed, stream list printfs moved v 1->0
arpi_esp
parents:
495
diff
changeset
|
842 has_audio=0;sh_audio=NULL; // ES streams has no audio channel |
c2b3a1f340c8
MPEG-ES segfault fixed, stream list printfs moved v 1->0
arpi_esp
parents:
495
diff
changeset
|
843 d_video->sh=new_sh_video(0); // create dummy video stream header, id=0 |
375 | 844 break; |
845 } | |
846 case DEMUXER_TYPE_MPEG_PS: { | |
847 if(has_audio) | |
848 if(!ds_fill_buffer(d_audio)){ | |
849 printf("MPEG: No Audio stream found... ->nosound\n"); | |
442 | 850 has_audio=0;sh_audio=NULL; |
375 | 851 } else { |
442 | 852 sh_audio=d_audio->sh;sh_audio->ds=d_audio; |
382 | 853 if(verbose) printf("detected MPG-PS audio format: %d\n",d_audio->type); |
375 | 854 switch(d_audio->type){ |
855 case 1: sh_audio->format=0x50;break; // mpeg | |
442 | 856 case 2: sh_audio->format=0x10001;break; // dvd pcm |
375 | 857 case 3: sh_audio->format=0x2000;break; // ac3 |
858 default: has_audio=0; // unknown type | |
859 } | |
860 } | |
861 break; | |
862 } | |
863 } // switch(file_format) | |
864 | |
865 // Determine image properties: | |
866 switch(file_format){ | |
867 case DEMUXER_TYPE_AVI: | |
868 case DEMUXER_TYPE_ASF: { | |
869 // display info: | |
442 | 870 sh_video->format=sh_video->bih->biCompression; |
871 sh_video->disp_w=sh_video->bih->biWidth; | |
872 sh_video->disp_h=abs(sh_video->bih->biHeight); | |
375 | 873 break; |
874 } | |
875 case DEMUXER_TYPE_MPEG_ES: | |
876 case DEMUXER_TYPE_MPEG_PS: { | |
303 | 877 // Find sequence_header first: |
878 if(verbose) printf("Searching for sequence header... ");fflush(stdout); | |
879 while(1){ | |
880 int i=sync_video_packet(d_video); | |
881 if(i==0x1B3) break; // found it! | |
882 if(!i || !skip_video_packet(d_video)){ | |
883 if(verbose) printf("NONE :(\n"); | |
884 printf("MPEG: FATAL: EOF while searching for sequence header\n"); | |
885 exit(1); | |
886 } | |
887 } | |
888 if(verbose) printf("OK!\n"); | |
442 | 889 sh_video=d_video->sh;sh_video->ds=d_video; |
303 | 890 sh_video->format=1; // mpeg video |
375 | 891 mpeg2_init(); |
892 // ========= Read & process sequence header & extension ============ | |
893 videobuffer=shmem_alloc(VIDEOBUFFER_SIZE); | |
894 if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);} | |
895 videobuf_len=0; | |
896 if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header!\n");exit(1);} | |
897 if(header_process_sequence_header (picture, &videobuffer[4])) { | |
898 printf ("bad sequence header!\n"); exit(1); | |
899 } | |
900 if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext. | |
901 videobuf_len=0; | |
902 if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header extension!\n");exit(1);} | |
903 if(header_process_extension (picture, &videobuffer[4])) { | |
904 printf ("bad sequence header extension!\n"); exit(1); | |
303 | 905 } |
906 } | |
375 | 907 // display info: |
398 | 908 sh_video->fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; |
909 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code]; | |
910 sh_video->disp_w=picture->display_picture_width; | |
911 sh_video->disp_h=picture->display_picture_height; | |
375 | 912 // info: |
913 if(verbose) printf("mpeg bitrate: %d (%X)\n",picture->bitrate,picture->bitrate); | |
914 printf("VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", | |
915 picture->mpeg1?"MPEG1":"MPEG2", | |
398 | 916 sh_video->disp_w,sh_video->disp_h, |
375 | 917 picture->aspect_ratio_information, |
398 | 918 sh_video->fps, |
375 | 919 picture->bitrate*0.5f, |
920 picture->bitrate/16.0f ); | |
1 | 921 break; |
922 } | |
923 } // switch(file_format) | |
924 | |
442 | 925 //if(verbose) printf("file successfully opened (has_audio=%d)\n",has_audio); |
1 | 926 |
398 | 927 printf("[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", |
928 file_format,sh_video->format,sh_video->disp_w,sh_video->disp_h, | |
929 sh_video->fps,sh_video->frametime | |
930 ); | |
931 | |
1 | 932 fflush(stdout); |
933 | |
549 | 934 if(stream_dump_type){ |
935 FILE *f; | |
936 int len; | |
937 demux_stream_t *ds=(stream_dump_type==1)?d_audio:d_video; | |
938 demux_stream_t *ds2=(stream_dump_type!=1)?d_audio:d_video; | |
939 ds_free_packs(ds2); ds2->id=-2; // ignore this stream! | |
940 f=fopen(stream_dump_name?stream_dump_name:"stream.dump","wb"); | |
941 if(!f){ printf("Can't open dump file!!!\n");exit(1); } | |
942 while(!ds->eof){ | |
943 char* start; | |
944 int in_size=ds_get_packet(ds,&start); | |
945 if(in_size>0) fwrite(start,in_size,1,f); | |
946 } | |
947 fclose(f); | |
948 printf("core dumped :)\n"); | |
949 exit(1); | |
950 } | |
951 | |
303 | 952 //================== Init AUDIO (codec) ========================== |
953 if(has_audio){ | |
954 // Go through the codec.conf and find the best codec... | |
332 | 955 sh_audio->codec=find_codec(sh_audio->format,NULL,NULL,1); |
303 | 956 if(!sh_audio->codec){ |
957 printf("Can't find codec for audio format 0x%X !\n",sh_audio->format); | |
958 has_audio=0; | |
959 } else { | |
340 | 960 printf("Found audio codec: [%s] drv:%d (%s)\n",sh_audio->codec->name,sh_audio->codec->driver,sh_audio->codec->info); |
442 | 961 //has_audio=sh_audio->codec->driver; |
303 | 962 } |
1 | 963 } |
964 | |
303 | 965 if(has_audio){ |
966 if(verbose) printf("Initializing audio codec...\n"); | |
442 | 967 if(!init_audio(sh_audio)){ |
303 | 968 printf("Couldn't initialize audio codec! -> nosound\n"); |
442 | 969 has_audio=0; |
303 | 970 } else { |
340 | 971 printf("AUDIO: samplerate=%d channels=%d bps=%d\n",sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize); |
303 | 972 } |
175 | 973 } |
974 | |
303 | 975 //================== Init VIDEO (codec & libvo) ========================== |
976 | |
977 // Go through the codec.conf and find the best codec... | |
442 | 978 sh_video->codec=find_codec(sh_video->format, |
979 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,NULL,0); | |
303 | 980 if(!sh_video->codec){ |
981 printf("Can't find codec for video format 0x%X !\n",sh_video->format); | |
982 exit(1); | |
983 } | |
442 | 984 //has_video=sh_video->codec->driver; |
303 | 985 |
340 | 986 printf("Found video codec: [%s] drv:%d (%s)\n",sh_video->codec->name,sh_video->codec->driver,sh_video->codec->info); |
303 | 987 |
988 for(i=0;i<CODECS_MAX_OUTFMT;i++){ | |
487 | 989 int ret; |
303 | 990 out_fmt=sh_video->codec->outfmt[i]; |
534
2a45d5adcc88
do not query vo drivers for format 0xFFFFFFFF (thanx to szabi)
arpi_esp
parents:
510
diff
changeset
|
991 if(out_fmt==0xFFFFFFFF) continue; |
487 | 992 ret=video_out->query_format(out_fmt); |
993 if(verbose) printf("vo_debug: query(0x%X) returned 0x%X\n",out_fmt,ret); | |
994 if(ret) break; | |
303 | 995 } |
996 if(i>=CODECS_MAX_OUTFMT){ | |
997 printf("Sorry, selected video_out device is incompatible with this codec.\n"); | |
998 exit(1); | |
999 } | |
1000 sh_video->outfmtidx=i; | |
1001 | |
487 | 1002 if(verbose) printf("vo_debug1: out_fmt=0x%08X\n",out_fmt); |
1003 | |
442 | 1004 switch(sh_video->codec->driver){ |
175 | 1005 case 2: { |
1 | 1006 if(!init_video_codec(out_fmt)) exit(1); |
1007 if(verbose) printf("INFO: Win32 video codec init OK!\n"); | |
1008 break; | |
1009 } | |
175 | 1010 case 4: { // Win32/DirectShow |
303 | 1011 #ifndef USE_DIRECTSHOW |
1012 printf("MPlayer was compiled WITHOUT directshow support!\n"); | |
1013 exit(1); | |
1014 #else | |
291 | 1015 sh_video->our_out_buffer=NULL; |
442 | 1016 if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, &sh_video->our_out_buffer)){ |
303 | 1017 printf("ERROR: Couldn't open required DirectShow codec: %s\n",sh_video->codec->dll); |
273 | 1018 printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n"); |
1019 printf("package from: ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip !\n"); | |
1020 printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n"); | |
1021 exit(1); | |
1022 } | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1023 |
470 | 1024 switch(out_fmt){ |
1025 case IMGFMT_YUY2: | |
1026 case IMGFMT_UYVY: | |
1027 DS_VideoDecoder_SetDestFmt(16,out_fmt);break; // packed YUV | |
1028 case IMGFMT_YV12: | |
1029 case IMGFMT_I420: | |
1030 case IMGFMT_IYUV: | |
1031 DS_VideoDecoder_SetDestFmt(12,out_fmt);break; // planar YUV | |
1032 default: | |
1033 DS_VideoDecoder_SetDestFmt(out_fmt&255,0); // RGB/BGR | |
1034 } | |
175 | 1035 |
1036 DS_VideoDecoder_Start(); | |
1037 | |
1038 printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) ); | |
1039 // printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) ); | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1040 |
175 | 1041 if(verbose) printf("INFO: Win32/DShow video codec init OK!\n"); |
1042 break; | |
374 | 1043 #endif |
175 | 1044 } |
1 | 1045 case 3: { // OpenDivX |
1046 if(verbose) printf("OpenDivX video codec\n"); | |
1047 { DEC_PARAM dec_param; | |
1048 DEC_SET dec_set; | |
442 | 1049 dec_param.x_dim = sh_video->bih->biWidth; |
1050 dec_param.y_dim = sh_video->bih->biHeight; | |
1051 dec_param.color_depth = 32; | |
1052 decore(0x123, DEC_OPT_INIT, &dec_param, NULL); | |
1053 dec_set.postproc_level = divx_quality; | |
1054 decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); | |
1 | 1055 } |
1056 if(verbose) printf("INFO: OpenDivX video codec init OK!\n"); | |
1057 break; | |
1058 } | |
1059 case 1: { | |
1060 // init libmpeg2: | |
41 | 1061 #ifdef MPEG12_POSTPROC |
1 | 1062 picture->pp_options=divx_quality; |
41 | 1063 #else |
1064 if(divx_quality){ | |
1065 printf("WARNING! You requested image postprocessing for an MPEG 1/2 video,\n"); | |
1066 printf(" but compiled MPlayer without MPEG 1/2 postprocessing support!\n"); | |
1067 printf(" #define MPEG12_POSTPROC in config.h, and recompile libmpeg2!\n"); | |
1068 } | |
1069 #endif | |
375 | 1070 mpeg2_allocate_image_buffers (picture); |
1 | 1071 break; |
1072 } | |
1073 } | |
1074 | |
487 | 1075 if(verbose) printf("vo_debug2: out_fmt=0x%08X\n",out_fmt); |
1076 | |
1 | 1077 // ================== Init output files for encoding =============== |
1078 if(encode_name){ | |
1079 // encode file!!! | |
1080 FILE *encode_file=fopen(encode_name,"rb"); | |
1081 if(encode_file){ | |
1082 fclose(encode_file); | |
1083 printf("File already exists: %s (don't overwrite your favourite AVI!)\n",encode_name); | |
1084 return 0; | |
1085 } | |
1086 encode_file=fopen(encode_name,"wb"); | |
1087 if(!encode_file){ | |
1088 printf("Cannot create file for encoding\n"); | |
1089 return 0; | |
1090 } | |
398 | 1091 write_avi_header_1(encode_file,mmioFOURCC('d', 'i', 'v', 'x'),sh_video->fps,sh_video->disp_w,sh_video->disp_h); |
1 | 1092 fclose(encode_file); |
1093 encode_index_name=malloc(strlen(encode_name)+8); | |
1094 strcpy(encode_index_name,encode_name); | |
1095 strcat(encode_index_name,".index"); | |
1096 if((encode_file=fopen(encode_index_name,"wb"))) | |
1097 fclose(encode_file); | |
1098 else encode_index_name=NULL; | |
1099 has_audio=0; // disable audio !!!!! | |
1100 } | |
1101 | |
1102 // ========== Init keyboard FIFO (connection to libvo) ============ | |
1103 | |
1104 make_pipe(&keyb_fifo_get,&keyb_fifo_put); | |
1105 | |
398 | 1106 // ========== Init display (sh_video->disp_w*sh_video->disp_h/out_fmt) ============ |
1 | 1107 |
1108 #ifdef X11_FULLSCREEN | |
1109 if(fullscreen){ | |
1110 if(vo_init()){ | |
1111 //if(verbose) printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen); | |
1112 } | |
1113 if(!screen_size_xy) screen_size_xy=vo_screenwidth; // scale with asp.ratio | |
1114 } | |
1115 #endif | |
1116 | |
1117 if(screen_size_xy>0){ | |
1118 if(screen_size_xy<=8){ | |
398 | 1119 screen_size_x=screen_size_xy*sh_video->disp_w; |
1120 screen_size_y=screen_size_xy*sh_video->disp_h; | |
1 | 1121 } else { |
1122 screen_size_x=screen_size_xy; | |
398 | 1123 screen_size_y=screen_size_xy*sh_video->disp_h/sh_video->disp_w; |
1 | 1124 } |
337 | 1125 } else if(!vidmode){ |
1126 if(!screen_size_x) screen_size_x=SCREEN_SIZE_X; | |
1127 if(!screen_size_y) screen_size_y=SCREEN_SIZE_Y; | |
398 | 1128 if(screen_size_x<=8) screen_size_x*=sh_video->disp_w; |
1129 if(screen_size_y<=8) screen_size_y*=sh_video->disp_h; | |
1 | 1130 } |
208
ae0f909ccc7c
Adds code to deal with vidmode selection. -- mgraffam
mgraffam
parents:
190
diff
changeset
|
1131 |
340 | 1132 { const vo_info_t *info = video_out->get_info(); |
1133 printf("VO: [%s] %dx%d => %dx%d %s%s%s ",info->short_name, | |
398 | 1134 sh_video->disp_w,sh_video->disp_h, |
340 | 1135 screen_size_x,screen_size_y, |
1136 fullscreen?"fs ":"", | |
1137 vidmode?"vm ":"", | |
1138 softzoom?"zoom ":"" | |
1139 // fullscreen|(vidmode<<1)|(softzoom<<2) | |
1140 ); | |
1141 if((out_fmt&IMGFMT_BGR_MASK)==IMGFMT_BGR) | |
1142 printf("BGR%d\n",out_fmt&255); else | |
1143 if((out_fmt&IMGFMT_BGR_MASK)==IMGFMT_RGB) | |
1144 printf("RGB%d\n",out_fmt&255); else | |
1145 if(out_fmt==IMGFMT_YUY2) printf("YUY2\n"); else | |
470 | 1146 if(out_fmt==IMGFMT_UYVY) printf("UYVY\n"); else |
1147 if(out_fmt==IMGFMT_I420) printf("I420\n"); else | |
1148 if(out_fmt==IMGFMT_IYUV) printf("IYUV\n"); else | |
340 | 1149 if(out_fmt==IMGFMT_YV12) printf("YV12\n"); |
1150 } | |
1151 | |
1152 // if(verbose) printf("Destination size: %d x %d out_fmt=%0X\n", | |
1153 // screen_size_x,screen_size_y,out_fmt); | |
1 | 1154 |
337 | 1155 if(verbose) printf("video_out->init(%dx%d->%dx%d,flags=%d,'%s',0x%X)\n", |
398 | 1156 sh_video->disp_w,sh_video->disp_h, |
1 | 1157 screen_size_x,screen_size_y, |
337 | 1158 fullscreen|(vidmode<<1)|(softzoom<<2), |
1159 title,out_fmt); | |
1 | 1160 |
487 | 1161 if(verbose) printf("vo_debug3: out_fmt=0x%08X\n",out_fmt); |
1162 | |
398 | 1163 if(video_out->init(sh_video->disp_w,sh_video->disp_h, |
1 | 1164 screen_size_x,screen_size_y, |
337 | 1165 fullscreen|(vidmode<<1)|(softzoom<<2), |
1166 title,out_fmt)){ | |
1 | 1167 printf("FATAL: Cannot initialize video driver!\n");exit(1); |
1168 } | |
1169 if(verbose) printf("INFO: Video OUT driver init OK!\n"); | |
1170 | |
1171 fflush(stdout); | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1172 |
1 | 1173 //================== MAIN: ========================== |
1174 { | |
1175 int audio_fd=-1; | |
1176 float buffer_delay=0; | |
1177 float frame_correction=0; // A-V timestamp kulonbseg atlagolas | |
1178 int frame_corr_num=0; // | |
1179 float a_frame=0; // Audio | |
1180 float v_frame=0; // Video | |
1181 float time_frame=0; // Timer | |
1182 float a_pts=0; | |
1183 float v_pts=0; | |
1184 float c_total=0; | |
1185 float max_pts_correction=default_max_pts_correction; | |
1186 int eof=0; | |
1187 int force_redraw=0; | |
1188 float num_frames=0; // number of frames played | |
1189 double video_time_usage=0; | |
1190 double vout_time_usage=0; | |
1191 double audio_time_usage=0; | |
36 | 1192 int grab_frames=0; |
212 | 1193 char osd_text_buffer[64]; |
371 | 1194 int osd_level=2; |
220 | 1195 int osd_visible=100; |
1196 int osd_function=OSD_PLAY; | |
1 | 1197 |
1198 #ifdef HAVE_LIRC | |
1199 lirc_mp_setup(); | |
1200 #endif | |
1201 | |
1202 #ifdef USE_TERMCAP | |
1203 load_termcap(NULL); // load key-codes | |
1204 #endif | |
1205 getch2_enable(); | |
1206 | |
1207 //========= Catch terminate signals: ================ | |
1208 // terminate requests: | |
1209 signal(SIGTERM,exit_sighandler); // kill | |
1210 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed | |
1211 signal(SIGINT,exit_sighandler); // Interrupt from keyboard | |
1212 signal(SIGQUIT,exit_sighandler); // Quit from keyboard | |
1213 // fatal errors: | |
1214 signal(SIGBUS,exit_sighandler); // bus error | |
1215 signal(SIGSEGV,exit_sighandler); // segfault | |
1216 signal(SIGILL,exit_sighandler); // illegal instruction | |
1217 signal(SIGFPE,exit_sighandler); // floating point exc. | |
1218 signal(SIGABRT,exit_sighandler); // abort() | |
1219 | |
1220 //================ SETUP AUDIO ========================== | |
1221 current_module="setup_audio"; | |
1222 | |
1223 if(has_audio){ | |
1224 #ifdef USE_XMMP_AUDIO | |
1225 xmm_Init( &xmm ); | |
1226 xmm.cSound = (XMM_PluginSound *)xmm_PluginRegister( XMMP_AUDIO_DRIVER ); | |
1227 if( xmm.cSound ){ | |
1228 pSound = xmm.cSound->Init( &xmm ); | |
296 | 1229 if( pSound && pSound->Start( pSound, sh_audio->samplerate, sh_audio->channels, |
1230 ( sh_audio->samplesize == 2 ) ? XMM_SOUND_FMT_S16LE : XMM_SOUND_FMT_U8 )){ | |
1 | 1231 printf("XMM: audio setup ok\n"); |
1232 } else { | |
1233 has_audio=0; | |
1234 } | |
1235 } else has_audio=0; | |
1236 #else | |
1237 audio_fd=open(dsp, O_WRONLY); | |
1238 if(audio_fd<0){ | |
1239 printf("Can't open audio device %s -> nosound\n",dsp); | |
1240 has_audio=0; | |
1241 } | |
1242 #endif | |
1243 } | |
1244 | |
1245 if(has_audio){ | |
1246 #ifdef USE_XMMP_AUDIO | |
1247 if(audio_buffer_size==-1){ | |
1248 // Measuring buffer size: | |
1249 buffer_delay=pSound->QueryDelay(pSound, 0); | |
1250 } else { | |
1251 // -abs commandline option | |
296 | 1252 buffer_delay=audio_buffer_size/(float)(sh_audio->o_bps); |
1 | 1253 } |
1254 #else | |
1255 int r; | |
296 | 1256 r=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r); |
1257 r=sh_audio->channels-1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r); | |
1258 r=sh_audio->samplerate; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1) | |
1 | 1259 printf("audio_setup: your card doesn't support %d Hz samplerate\n",r); |
1260 | |
103 | 1261 #if 0 |
1262 // r = (64 << 16) + 1024; | |
1263 r = (65536 << 16) + 512; | |
1264 if(ioctl (audio_fd, SNDCTL_DSP_SETFRAGMENT, &r)==-1) | |
1265 printf("audio_setup: your card doesn't support setting fragments\n",r); | |
1266 #endif | |
1267 | |
1 | 1268 if(audio_buffer_size==-1){ |
1269 // Measuring buffer size: | |
1270 audio_buffer_size=0; | |
1271 #ifdef HAVE_AUDIO_SELECT | |
1272 while(audio_buffer_size<0x40000){ | |
1273 fd_set rfds; | |
1274 struct timeval tv; | |
1275 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); | |
1276 tv.tv_sec=0; tv.tv_usec = 0; | |
1277 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break; | |
296 | 1278 write(audio_fd,&sh_audio->a_buffer[sh_audio->a_buffer_len],OUTBURST); |
1 | 1279 audio_buffer_size+=OUTBURST; |
1280 } | |
1281 if(audio_buffer_size==0){ | |
1282 printf("\n *** Your audio driver DOES NOT support select() ***\n"); | |
1283 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n"); | |
1284 exit_player("audio_init"); | |
1285 } | |
1286 #endif | |
1287 } | |
296 | 1288 buffer_delay=audio_buffer_size/(float)(sh_audio->o_bps); |
1 | 1289 #endif |
1290 a_frame=-(buffer_delay); | |
1291 printf("Audio buffer size: %d bytes, delay: %5.3fs\n",audio_buffer_size,buffer_delay); | |
1292 } | |
1293 | |
1294 | |
340 | 1295 if(!has_audio){ |
1 | 1296 printf("Audio: no sound\n"); |
1297 if(verbose) printf("Freeing %d unused audio chunks\n",d_audio->packs); | |
1298 ds_free_packs(d_audio); // free buffered chunks | |
1299 d_audio->id=-2; // do not read audio chunks | |
442 | 1300 if(sh_audio) if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
296 | 1301 alsa=1; |
1302 // fake, required for timer: | |
442 | 1303 sh_audio=new_sh_audio(255); // FIXME!!!!!!!!!! |
296 | 1304 sh_audio->samplerate=76800; |
1305 sh_audio->samplesize=sh_audio->channels=2; | |
1306 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | |
1 | 1307 } |
1308 | |
1309 current_module=NULL; | |
1310 | |
1311 //==================== START PLAYING ======================= | |
1312 | |
109 | 1313 if(file_format==DEMUXER_TYPE_AVI){ |
1 | 1314 a_pts=d_audio->pts-(buffer_delay+audio_delay); |
398 | 1315 audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime; |
291 | 1316 // audio_delay-=(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)/default_fps; |
340 | 1317 if(verbose){ |
398 | 1318 printf("AVI Initial frame delay: %5.3f\n",(float)(sh_audio->audio.dwInitialFrames-sh_video->video.dwInitialFrames)*sh_video->frametime); |
340 | 1319 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a_pts=%5.3f a_frame=%5.3f\n", |
1320 audio_delay,buffer_delay,a_pts,a_frame); | |
1321 printf("START: a_pts=%5.3f v_pts=%5.3f \n",d_audio->pts,d_video->pts); | |
1322 } | |
1 | 1323 delay_corrected=0; // has to correct PTS diffs |
1324 d_video->pts=0;d_audio->pts=0; // PTS is outdated now! | |
1325 } | |
398 | 1326 if(force_fps){ |
1327 sh_video->fps=force_fps; | |
1328 sh_video->frametime=1.0f/sh_video->fps; | |
1329 } | |
1 | 1330 |
1331 printf("Start playing...\n");fflush(stdout); | |
1332 | |
1333 InitTimer(); | |
1334 | |
1335 while(!eof){ | |
1336 | |
1337 /*========================== PLAY AUDIO ============================*/ | |
1338 | |
1339 while(has_audio){ | |
291 | 1340 |
1341 // Update buffer if needed | |
1 | 1342 unsigned int t=GetTimer(); |
1343 current_module="decode_audio"; // Enter AUDIO decoder module | |
442 | 1344 //sh_audio->codec->driver=has_audio; // FIXME! |
296 | 1345 while(sh_audio->a_buffer_len<OUTBURST && !d_audio->eof){ |
1346 int ret=decode_audio(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len],sh_audio->a_buffer_size-sh_audio->a_buffer_len); | |
1347 if(ret>0) sh_audio->a_buffer_len+=ret; else break; | |
1 | 1348 } |
1349 current_module=NULL; // Leave AUDIO decoder module | |
291 | 1350 t=GetTimer()-t;audio_time_usage+=t*0.000001; |
1351 | |
1 | 1352 |
1353 // Play sound from the buffer: | |
296 | 1354 if(sh_audio->a_buffer_len>=OUTBURST){ // if not EOF |
1 | 1355 #ifdef USE_XMMP_AUDIO |
296 | 1356 pSound->Write( pSound, sh_audio->a_buffer, OUTBURST ); |
1 | 1357 #else |
1358 #ifdef SIMULATE_ALSA | |
296 | 1359 fake_ALSA_write(audio_fd,sh_audio->a_buffer,OUTBURST); // for testing purposes |
1 | 1360 #else |
296 | 1361 write(audio_fd,sh_audio->a_buffer,OUTBURST); |
1 | 1362 #endif |
1363 #endif | |
296 | 1364 sh_audio->a_buffer_len-=OUTBURST; |
1365 memcpy(sh_audio->a_buffer,&sh_audio->a_buffer[OUTBURST],sh_audio->a_buffer_len); | |
1 | 1366 #ifndef USE_XMMP_AUDIO |
1367 #ifndef SIMULATE_ALSA | |
1368 // check buffer | |
1369 #ifdef HAVE_AUDIO_SELECT | |
1370 { fd_set rfds; | |
1371 struct timeval tv; | |
1372 FD_ZERO(&rfds); | |
1373 FD_SET(audio_fd, &rfds); | |
1374 tv.tv_sec = 0; | |
1375 tv.tv_usec = 0; | |
1376 if(select(audio_fd+1, NULL, &rfds, NULL, &tv)){ | |
296 | 1377 a_frame+=OUTBURST/(float)(sh_audio->o_bps); |
1378 a_pts+=OUTBURST/(float)(sh_audio->o_bps); | |
1 | 1379 // printf("Filling audio buffer...\n"); |
1380 continue; | |
1381 // } else { | |
1382 // printf("audio buffer full...\n"); | |
1383 } | |
1384 } | |
1385 #endif | |
1386 #endif | |
1387 #endif | |
1388 } | |
1389 | |
1390 break; | |
1391 } // if(has_audio) | |
1392 | |
1393 /*========================== UPDATE TIMERS ============================*/ | |
1394 | |
296 | 1395 a_frame+=OUTBURST/(float)(sh_audio->o_bps); |
1396 a_pts+=OUTBURST/(float)(sh_audio->o_bps); | |
1 | 1397 |
1398 if(alsa){ | |
1399 // Use system timer for sync, not audio card/driver | |
296 | 1400 time_frame+=OUTBURST/(float)(sh_audio->o_bps); |
1 | 1401 time_frame-=GetRelativeTime(); |
1402 if(time_frame<-0.1 || time_frame>0.1){ | |
1403 time_frame=0; | |
1404 } else { | |
398 | 1405 while(time_frame>0.022){ |
535 | 1406 usleep(time_frame-0.022); |
398 | 1407 time_frame-=GetRelativeTime(); |
1408 } | |
103 | 1409 while(time_frame>0.007){ |
398 | 1410 usleep(0); |
103 | 1411 time_frame-=GetRelativeTime(); |
1412 } | |
398 | 1413 } |
1 | 1414 } |
1415 | |
1416 | |
1417 /*========================== PLAY VIDEO ============================*/ | |
1418 | |
1419 if(1) | |
1420 while(v_frame<a_frame || force_redraw){ | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1421 |
398 | 1422 float frame_time=1; |
1423 float pts1=d_video->pts; | |
1 | 1424 |
1425 current_module="decode_video"; | |
1426 | |
1427 //-------------------- Decode a frame: ----------------------- | |
442 | 1428 switch(sh_video->codec->driver){ |
1 | 1429 case 3: { |
1430 // OpenDivX | |
1431 unsigned int t=GetTimer(); | |
1432 unsigned int t2; | |
1433 DEC_FRAME dec_frame; | |
1434 char* start=NULL; | |
1435 int in_size=ds_get_packet(d_video,&start); | |
1436 if(in_size<0){ eof=1;break;} | |
1437 if(in_size>max_framesize) max_framesize=in_size; | |
1438 // let's decode | |
1439 dec_frame.length = in_size; | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1440 dec_frame.bitstream = start; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1441 dec_frame.render_flag = 1; |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1442 decore(0x123, 0, &dec_frame, NULL); |
1 | 1443 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; |
1444 | |
1445 if(opendivx_src[0]){ | |
1446 video_out->draw_slice(opendivx_src,opendivx_stride, | |
398 | 1447 sh_video->disp_w,sh_video->disp_h,0,0); |
1 | 1448 opendivx_src[0]=NULL; |
1449 } | |
1450 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; | |
1451 | |
1452 break; | |
1453 } | |
175 | 1454 #ifdef USE_DIRECTSHOW |
1455 case 4: { // W32/DirectShow | |
1456 char* start=NULL; | |
1457 unsigned int t=GetTimer(); | |
1458 unsigned int t2; | |
1459 int in_size=ds_get_packet(d_video,&start); | |
1460 if(in_size<0){ eof=1;break;} | |
1461 if(in_size>max_framesize) max_framesize=in_size; | |
1462 | |
1463 DS_VideoDecoder_DecodeFrame(start, in_size, 0, 1); | |
470 | 1464 current_module="draw_frame"; |
1465 | |
175 | 1466 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; |
470 | 1467 if(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420){ |
1468 uint8_t* dst[3]; | |
1469 int stride[3]; | |
1470 stride[0]=sh_video->disp_w; | |
1471 stride[1]=stride[2]=sh_video->disp_w/2; | |
1472 dst[0]=sh_video->our_out_buffer; | |
1473 dst[2]=dst[0]+sh_video->disp_w*sh_video->disp_h; | |
1474 dst[1]=dst[2]+sh_video->disp_w*sh_video->disp_h/4; | |
1475 video_out->draw_slice(dst,stride,sh_video->disp_w,sh_video->disp_h,0,0); | |
1476 } else | |
291 | 1477 video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer); |
175 | 1478 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; |
1479 break; | |
1480 } | |
1481 #endif | |
1 | 1482 case 2: { |
1483 HRESULT ret; | |
1484 char* start=NULL; | |
1485 unsigned int t=GetTimer(); | |
1486 unsigned int t2; | |
1487 int in_size=ds_get_packet(d_video,&start); | |
1488 if(in_size<0){ eof=1;break;} | |
1489 if(in_size>max_framesize) max_framesize=in_size; | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1490 |
442 | 1491 if(in_size){ |
1492 sh_video->bih->biSizeImage = in_size; | |
1493 // ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), | |
1494 ret = ICDecompress(sh_video->hic, ICDECOMPRESS_NOTKEYFRAME, | |
1495 sh_video->bih, start, | |
291 | 1496 &sh_video->o_bih, sh_video->our_out_buffer); |
1 | 1497 if(ret){ printf("Error decompressing frame, err=%d\n",ret);break; } |
442 | 1498 } |
470 | 1499 current_module="draw_frame"; |
1 | 1500 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f; |
470 | 1501 // if(out_fmt==IMGFMT_YV12){ |
1502 if(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420){ | |
1503 uint8_t* dst[3]; | |
1504 int stride[3]; | |
1505 stride[0]=sh_video->disp_w; | |
1506 stride[1]=stride[2]=sh_video->disp_w/2; | |
1507 dst[0]=sh_video->our_out_buffer; | |
1508 dst[2]=dst[0]+sh_video->disp_w*sh_video->disp_h; | |
1509 dst[1]=dst[2]+sh_video->disp_w*sh_video->disp_h/4; | |
1510 video_out->draw_slice(dst,stride,sh_video->disp_w,sh_video->disp_h,0,0); | |
1511 } else | |
291 | 1512 video_out->draw_frame((uint8_t **)&sh_video->our_out_buffer); |
1 | 1513 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f; |
1514 | |
1515 break; | |
1516 } | |
1517 case 1: { | |
111 | 1518 int in_frame=0; |
398 | 1519 int t=0; |
1520 float newfps; | |
111 | 1521 videobuf_len=0; |
1522 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){ | |
1523 int i=sync_video_packet(d_video); | |
1524 if(in_frame){ | |
1525 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame | |
398 | 1526 #if 1 |
111 | 1527 // send END OF FRAME code: |
1528 videobuffer[videobuf_len+0]=0; | |
1529 videobuffer[videobuf_len+1]=0; | |
1530 videobuffer[videobuf_len+2]=1; | |
1531 videobuffer[videobuf_len+3]=0xFF; | |
1532 videobuf_len+=4; | |
1533 #endif | |
1534 if(!i) eof=1; // EOF | |
1535 break; | |
1536 } | |
1537 } else { | |
1538 //if(i==0x100) in_frame=1; // picture startcode | |
1539 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode | |
1540 else if(!i){ eof=1; break;} // EOF | |
1541 } | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1542 if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1; |
111 | 1543 if(!read_video_packet(d_video)){ eof=1; break;} // EOF |
1544 //printf("read packet 0x%X, len=%d\n",i,videobuf_len); | |
1545 } | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1546 |
111 | 1547 if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug |
1548 //printf("--- SEND %d bytes\n",videobuf_len); | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1549 if(grab_frames==1){ |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1550 FILE *f=fopen("grab.mpg","ab"); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1551 fwrite(videobuffer,videobuf_len-4,1,f); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1552 fclose(f); |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1553 } |
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1554 |
398 | 1555 t-=GetTimer(); |
111 | 1556 mpeg2_decode_data(video_out, videobuffer, videobuffer+videobuf_len); |
398 | 1557 t+=GetTimer(); video_time_usage+=t*0.000001; |
111 | 1558 |
398 | 1559 newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f; |
442 | 1560 if(ABS(sh_video->fps-newfps)>0.01f) if(!force_fps){ |
398 | 1561 printf("Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,newfps,sh_video->fps-newfps,picture->frame_rate_code); |
1562 sh_video->fps=newfps; | |
1563 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code]; | |
1 | 1564 } |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1565 |
398 | 1566 frame_time=(100+picture->repeat_count)*0.01f; |
1567 picture->repeat_count=0; | |
1568 | |
1 | 1569 break; |
1570 } | |
1571 } // switch | |
1572 //------------------------ frame decoded. -------------------- | |
1573 | |
398 | 1574 // Increase video timers: |
1575 num_frames+=frame_time; | |
1576 frame_time*=sh_video->frametime; | |
442 | 1577 if(file_format==DEMUXER_TYPE_ASF && !force_fps){ |
398 | 1578 // .ASF files has no fixed FPS - just frame durations! |
1579 float d=d_video->pts-pts1; | |
1580 if(d>=0 && d<5) frame_time=d; | |
1581 } | |
1582 v_frame+=frame_time; | |
1583 v_pts+=frame_time; | |
117 | 1584 |
398 | 1585 current_module="flip_page"; |
117 | 1586 video_out->flip_page(); |
1 | 1587 current_module=NULL; |
1588 | |
1589 if(eof) break; | |
220 | 1590 if(force_redraw){ |
1591 --force_redraw; | |
1592 if(!force_redraw) osd_function=OSD_PLAY; | |
1593 } | |
1 | 1594 |
1595 // printf("A:%6.1f V:%6.1f A-V:%7.3f frame=%5.2f \r",d_audio->pts,d_video->pts,d_audio->pts-d_video->pts,a_frame); | |
1596 // fflush(stdout); | |
1597 | |
1598 #if 1 | |
1599 /*================ A-V TIMESTAMP CORRECTION: =========================*/ | |
1600 if(has_audio){ | |
109 | 1601 if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI)){ |
291 | 1602 // a_pts=(float)ds_tell(d_audio)/sh_audio->wf.nAvgBytesPerSec-(buffer_delay+audio_delay); |
442 | 1603 a_pts=(float)ds_tell(d_audio)/sh_audio->wf->nAvgBytesPerSec-(buffer_delay); |
1 | 1604 delay_corrected=1; // hack |
1605 } else | |
1606 if(d_audio->pts){ | |
1607 // printf("\n=== APTS a_pts=%5.3f v_pts=%5.3f === \n",d_audio->pts,d_video->pts); | |
1608 #if 1 | |
1609 if(!delay_corrected){ | |
1610 float x=d_audio->pts-d_video->pts-(buffer_delay+audio_delay); | |
1611 float y=-(buffer_delay+audio_delay); | |
1612 printf("Initial PTS delay: %5.3f sec (calculated: %5.3f)\n",x,y); | |
1613 audio_delay+=x; | |
1614 //a_pts-=x; | |
1615 delay_corrected=1; | |
340 | 1616 if(verbose) |
1 | 1617 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a.pts=%5.3f v.pts=%5.3f\n", |
1618 audio_delay,buffer_delay,d_audio->pts,d_video->pts); | |
1619 } | |
1620 #endif | |
1621 a_pts=d_audio->pts-(buffer_delay+audio_delay); | |
1622 d_audio->pts=0; | |
1623 } | |
1624 if(d_video->pts) v_pts=d_video->pts; | |
1625 if(frame_corr_num==5){ | |
1626 float x=(frame_correction/5.0f); | |
398 | 1627 if(delay_corrected){ |
1 | 1628 printf("A:%6.1f V:%6.1f A-V:%7.3f",a_pts,v_pts,x); |
1629 x*=0.5f; | |
1630 if(x<-max_pts_correction) x=-max_pts_correction; else | |
1631 if(x> max_pts_correction) x= max_pts_correction; | |
1632 max_pts_correction=default_max_pts_correction; | |
1633 a_frame+=x; c_total+=x; | |
442 | 1634 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% \r",c_total, |
1 | 1635 (int)num_frames, |
1636 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, | |
1637 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, | |
442 | 1638 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0 |
1639 // dbg_es_sent-dbg_es_rcvd | |
1 | 1640 ); |
1641 fflush(stdout); | |
1642 } | |
1643 frame_corr_num=0; frame_correction=0; | |
1644 } | |
1645 if(frame_corr_num>=0) frame_correction+=a_pts-v_pts; | |
1646 } else { | |
1647 // No audio: | |
1648 if(d_video->pts) v_pts=d_video->pts; | |
1649 if(frame_corr_num==5){ | |
1650 // printf("A: --- V:%6.1f \r",v_pts); | |
442 | 1651 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% \r",v_pts, |
1 | 1652 (int)num_frames, |
1653 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0, | |
1654 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0, | |
442 | 1655 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0 |
1656 // dbg_es_sent-dbg_es_rcvd | |
1657 ); | |
1 | 1658 |
1659 fflush(stdout); | |
1660 frame_corr_num=0; | |
1661 } | |
1662 } | |
1663 ++frame_corr_num; | |
1664 #endif | |
1665 | |
220 | 1666 if(osd_visible){ |
1667 --osd_visible; | |
1668 if(!osd_visible) vo_osd_progbar_type=-1; // disable | |
1669 } | |
371 | 1670 |
1671 if(osd_function==OSD_PAUSE){ | |
1672 printf("\n------ PAUSED -------\r");fflush(stdout); | |
1673 while( | |
1674 #ifdef HAVE_LIRC | |
1675 lirc_mp_getinput()<=0 && | |
1676 #endif | |
1677 getch2(20)<=0 && mplayer_get_key()<=0){ | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1678 video_out->check_events(); |
371 | 1679 } |
1680 osd_function=OSD_PLAY; | |
1681 } | |
1682 | |
1 | 1683 } // while(v_frame<a_frame || force_redraw) |
1684 | |
1685 | |
1686 //================= Keyboard events, SEEKing ==================== | |
1687 | |
1688 { int rel_seek_secs=0; | |
1689 int c; | |
1690 while( | |
1691 #ifdef HAVE_LIRC | |
1692 (c=lirc_mp_getinput())>0 || | |
1693 #endif | |
1694 (c=getch2(0))>0 || (c=mplayer_get_key())>0) switch(c){ | |
1695 // seek 10 sec | |
1696 case KEY_RIGHT: | |
220 | 1697 osd_function=OSD_FFW; |
1 | 1698 rel_seek_secs+=10;break; |
1699 case KEY_LEFT: | |
220 | 1700 osd_function=OSD_REW; |
1 | 1701 rel_seek_secs-=10;break; |
1702 // seek 1 min | |
1703 case KEY_UP: | |
220 | 1704 osd_function=OSD_FFW; |
1 | 1705 rel_seek_secs+=60;break; |
1706 case KEY_DOWN: | |
220 | 1707 osd_function=OSD_REW; |
1 | 1708 rel_seek_secs-=60;break; |
1709 // delay correction: | |
1710 case '+': | |
220 | 1711 buffer_delay+=0.1; // increase audio buffer delay |
1 | 1712 a_frame-=0.1; |
1713 break; | |
1714 case '-': | |
220 | 1715 buffer_delay-=0.1; // decrease audio buffer delay |
1 | 1716 a_frame+=0.1; |
1717 break; | |
1718 // quit | |
1719 case KEY_ESC: // ESC | |
1720 case KEY_ENTER: // ESC | |
1721 case 'q': exit_player("Quit"); | |
36 | 1722 case 'g': grab_frames=2;break; |
1 | 1723 // pause |
1724 case 'p': | |
1725 case ' ': | |
220 | 1726 osd_function=OSD_PAUSE; |
371 | 1727 break; |
1728 case 'o': // toggle OSD | |
1729 osd_level=(osd_level+1)%3; | |
1 | 1730 break; |
459 | 1731 case '*': |
1732 mixer_incvolume(); | |
1733 break; | |
1734 case '/': | |
1735 mixer_decvolume(); | |
1736 break; | |
1737 case 'm': | |
510 | 1738 mixer_usemaster=!mixer_usemaster; |
459 | 1739 break; |
1 | 1740 } |
1741 if(rel_seek_secs) | |
1742 if(file_format==DEMUXER_TYPE_AVI && avi_header.idx_size<=0){ | |
1743 printf("Can't seek in raw .AVI streams! (index required) \n"); | |
1744 } else { | |
1745 int skip_audio_bytes=0; | |
1746 float skip_audio_secs=0; | |
1747 | |
1748 // clear demux buffers: | |
1749 if(has_audio) ds_free_packs(d_audio); | |
1750 ds_free_packs(d_video); | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1751 |
296 | 1752 // printf("sh_audio->a_buffer_len=%d \n",sh_audio->a_buffer_len); |
1753 sh_audio->a_buffer_len=0; | |
1 | 1754 |
1755 switch(file_format){ | |
1756 | |
1757 case DEMUXER_TYPE_AVI: { | |
1758 //================= seek in AVI ========================== | |
398 | 1759 int rel_seek_frames=rel_seek_secs*sh_video->fps; |
1 | 1760 int curr_audio_pos=0; |
1761 int audio_chunk_pos=-1; | |
1762 int video_chunk_pos=d_video->pos; | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1763 |
1 | 1764 skip_video_frames=0; |
1765 | |
1766 // SEEK streams | |
1767 // if(d_video->pts) avi_video_pts=d_video->pts; | |
1768 avi_audio_pts=0; | |
1769 d_video->pts=0; | |
1770 d_audio->pts=0; | |
1771 | |
1772 // find video chunk pos: | |
1773 if(rel_seek_frames>0){ | |
1774 // seek forward | |
1775 while(video_chunk_pos<avi_header.idx_size){ | |
1776 int id=avi_header.idx[video_chunk_pos].ckid; | |
1777 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame | |
1778 if(avi_stream_id(id)==d_video->id){ // video frame | |
1779 if((--rel_seek_frames)<0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; | |
291 | 1780 v_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
1 | 1781 ++skip_audio_bytes; |
1782 } | |
1783 ++video_chunk_pos; | |
1784 } | |
1785 } else { | |
1786 // seek backward | |
1787 while(video_chunk_pos>=0){ | |
1788 int id=avi_header.idx[video_chunk_pos].ckid; | |
1789 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame | |
1790 if(avi_stream_id(id)==d_video->id){ // video frame | |
1791 if((++rel_seek_frames)>0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; | |
291 | 1792 v_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
1 | 1793 --skip_audio_bytes; |
1794 } | |
1795 --video_chunk_pos; | |
1796 } | |
1797 } | |
1798 avi_header.idx_pos_a=avi_header.idx_pos_v= | |
1799 avi_header.idx_pos=video_chunk_pos; | |
1800 // printf("%d frames skipped\n",skip_audio_bytes); | |
1801 | |
1802 #if 1 | |
1803 // re-calc video pts: | |
1804 avi_video_pts=0; | |
1805 for(i=0;i<video_chunk_pos;i++){ | |
1806 int id=avi_header.idx[i].ckid; | |
1807 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame | |
1808 if(avi_stream_id(id)==d_video->id){ // video frame | |
291 | 1809 avi_video_pts+=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
1 | 1810 } |
1811 } | |
1812 //printf("v-pts recalc! %5.3f -> %5.3f \n",v_pts,avi_video_pts); | |
1813 v_pts=avi_video_pts; | |
1814 #else | |
1815 avi_video_pts=v_pts; | |
1816 #endif | |
1817 a_pts=avi_video_pts-(buffer_delay); | |
1818 //a_pts=v_pts; //-(buffer_delay+audio_delay); | |
1819 | |
1820 if(has_audio){ | |
1821 int i; | |
1822 int apos=0; | |
1823 int last=0; | |
1824 int len=0; | |
1825 | |
1826 // calc new audio position in audio stream: (using avg.bps value) | |
442 | 1827 curr_audio_pos=(avi_video_pts) * sh_audio->wf->nAvgBytesPerSec; |
1 | 1828 if(curr_audio_pos<0)curr_audio_pos=0; |
1829 #if 1 | |
1830 curr_audio_pos&=~15; // requires for PCM formats!!! | |
1831 #else | |
442 | 1832 curr_audio_pos/=sh_audio->wf->nBlockAlign; |
1833 curr_audio_pos*=sh_audio->wf->nBlockAlign; | |
1 | 1834 avi_header.audio_seekable=1; |
1835 #endif | |
1836 | |
1837 // find audio chunk pos: | |
1838 for(i=0;i<video_chunk_pos;i++){ | |
1839 int id=avi_header.idx[i].ckid; | |
1840 //if(TWOCCFromFOURCC(id)==cktypeWAVEbytes){ | |
1841 if(avi_stream_id(id)==d_audio->id){ | |
1842 int aid=StreamFromFOURCC(id); | |
1843 if(d_audio->id==aid || d_audio->id==-1){ | |
1844 len=avi_header.idx[i].dwChunkLength; | |
1845 last=i; | |
1846 if(apos<=curr_audio_pos && curr_audio_pos<(apos+len)){ | |
1847 if(verbose)printf("break;\n"); | |
1848 break; | |
1849 } | |
1850 apos+=len; | |
1851 } | |
1852 } | |
1853 } | |
1854 if(verbose)printf("XXX i=%d last=%d apos=%d curr_audio_pos=%d \n", | |
1855 i,last,apos,curr_audio_pos); | |
1856 // audio_chunk_pos=last; // maybe wrong (if not break; ) | |
1857 audio_chunk_pos=i; // maybe wrong (if not break; ) | |
1858 skip_audio_bytes=curr_audio_pos-apos; | |
1859 | |
1860 // update stream position: | |
1861 d_audio->pos=audio_chunk_pos; | |
1862 d_audio->dpos=apos; | |
1863 avi_header.idx_pos_a=avi_header.idx_pos_v= | |
1864 avi_header.idx_pos=audio_chunk_pos; | |
1865 | |
303 | 1866 if(!(sh_audio->codec->flags&CODECS_FLAG_SEEKABLE)){ |
1 | 1867 #if 0 |
1868 // curr_audio_pos=apos; // selected audio codec can't seek in chunk | |
442 | 1869 skip_audio_secs=(float)skip_audio_bytes/(float)sh_audio->wf->nAvgBytesPerSec; |
1 | 1870 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",skip_audio_bytes,skip_audio_secs); |
1871 skip_audio_bytes=0; | |
1872 #else | |
442 | 1873 int d=skip_audio_bytes % sh_audio->wf->nBlockAlign; |
1 | 1874 skip_audio_bytes-=d; |
1875 // curr_audio_pos-=d; | |
442 | 1876 skip_audio_secs=(float)d/(float)sh_audio->wf->nAvgBytesPerSec; |
1 | 1877 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",d,skip_audio_secs); |
1878 #endif | |
1879 } | |
1880 // now: audio_chunk_pos=pos in index | |
1881 // skip_audio_bytes=bytes to skip from that chunk | |
1882 // skip_audio_secs=time to play audio before video (if can't skip) | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1883 |
1 | 1884 // calc skip_video_frames & adjust video pts counter: |
1885 // i=last; | |
1886 i=avi_header.idx_pos; | |
1887 while(i<video_chunk_pos){ | |
1888 int id=avi_header.idx[i].ckid; | |
1889 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame | |
1890 if(avi_stream_id(id)==d_video->id){ // video frame | |
1891 ++skip_video_frames; | |
1892 // requires for correct audio pts calculation (demuxer): | |
291 | 1893 avi_video_pts-=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
1 | 1894 } |
1895 ++i; | |
1896 } | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1897 |
1 | 1898 } |
1899 | |
1900 if(verbose) printf("SEEK: idx=%d (a:%d v:%d) v.skip=%d a.skip=%d/%4.3f \n", | |
1901 avi_header.idx_pos,audio_chunk_pos,video_chunk_pos, | |
1902 skip_video_frames,skip_audio_bytes,skip_audio_secs); | |
1903 | |
220 | 1904 // Set OSD: |
371 | 1905 if(osd_level){ |
398 | 1906 osd_visible=sh_video->fps; // 1 sec |
371 | 1907 vo_osd_progbar_type=0; |
1908 vo_osd_progbar_value=(demuxer->filepos)/((avi_header.movi_end-avi_header.movi_start)>>8); | |
1909 //printf("avi filepos = %d \n",vo_osd_progbar_value); | |
1910 // printf("avi filepos = %d (len=%d) \n",demuxer->filepos,(avi_header.movi_end-avi_header.movi_start)); | |
1911 } | |
220 | 1912 |
1 | 1913 } |
1914 break; | |
1915 | |
1916 case DEMUXER_TYPE_ASF: { | |
1917 //================= seek in ASF ========================== | |
1918 float p_rate=10; // packets / sec | |
1919 int rel_seek_packs=rel_seek_secs*p_rate; | |
1920 int rel_seek_bytes=rel_seek_packs*fileh.packetsize; | |
1921 int newpos; | |
1922 //printf("ASF: packs: %d duration: %d \n",(int)fileh.packets,*((int*)&fileh.duration)); | |
1923 // printf("ASF_seek: %d secs -> %d packs -> %d bytes \n", | |
1924 // rel_seek_secs,rel_seek_packs,rel_seek_bytes); | |
1925 newpos=demuxer->filepos+rel_seek_bytes; | |
1926 if(newpos<0) newpos=0; | |
1927 stream_seek(demuxer->stream,newpos); | |
1928 } | |
1929 break; | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1930 |
1 | 1931 case DEMUXER_TYPE_MPEG_ES: |
1932 case DEMUXER_TYPE_MPEG_PS: { | |
1933 //================= seek in MPEG ========================== | |
1934 int newpos; | |
1935 if(picture->bitrate==0x3FFFF) // unspecified? | |
1936 newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec | |
1937 else | |
1938 newpos=demuxer->filepos+(picture->bitrate*1000/16)*rel_seek_secs; | |
1939 // picture->bitrate=2324*75*8; // standard VCD bitrate (75 sectors / sec) | |
1940 | |
1941 if(newpos<seek_to_byte) newpos=seek_to_byte; | |
495
d4eb6bd44bbc
Seeking to sector boundary (STREAM_BUFFER_SIZE) for MPEGs
lgb
parents:
492
diff
changeset
|
1942 newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */ |
1 | 1943 stream_seek(demuxer->stream,newpos); |
1944 // re-sync video: | |
1945 videobuf_code_len=0; // reset ES stream buffer | |
1946 while(1){ | |
1947 int i=sync_video_packet(d_video); | |
1948 if(i==0x1B3 || i==0x1B8) break; // found it! | |
1949 if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF | |
1950 } | |
1951 // re-sync audio: (must read to get actual audio PTS) | |
1952 // if(has_audio) ds_fill_buffer(d_audio); | |
1953 } | |
1954 break; | |
1955 | |
1956 } // switch(file_format) | |
1957 | |
1958 //====================== re-sync audio: ===================== | |
1959 if(has_audio){ | |
1960 | |
1961 if(skip_audio_bytes){ | |
1962 demux_read_data(d_audio,NULL,skip_audio_bytes); | |
1963 d_audio->pts=0; // PTS is outdated because of the raw data skipping | |
1964 } | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1965 |
1 | 1966 current_module="resync_audio"; |
1967 | |
442 | 1968 switch(sh_audio->codec->driver){ |
1 | 1969 case 1: |
1970 MP3_DecodeFrame(NULL,-2); // resync | |
1971 MP3_DecodeFrame(NULL,-2); // resync | |
1972 MP3_DecodeFrame(NULL,-2); // resync | |
1973 break; | |
1974 case 3: | |
1975 ac3_bitstream_reset(); // reset AC3 bitstream buffer | |
1976 // if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);} | |
291 | 1977 sh_audio->ac3_frame=ac3_decode_frame(); // resync |
1 | 1978 // if(verbose) printf(" OK!\n"); |
1979 break; | |
1980 case 4: | |
291 | 1981 case 7: |
1982 sh_audio->a_in_buffer_len=0; // reset ACM/DShow audio buffer | |
1 | 1983 break; |
1984 } | |
1985 | |
1986 // re-sync PTS (MPEG-PS only!!!) | |
1987 if(file_format==DEMUXER_TYPE_MPEG_PS) | |
1988 if(d_video->pts && d_audio->pts){ | |
1989 if (d_video->pts < d_audio->pts){ | |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
1990 |
1 | 1991 } else { |
1992 while(d_video->pts > d_audio->pts){ | |
442 | 1993 switch(sh_audio->codec->driver){ |
1 | 1994 case 1: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame |
291 | 1995 case 3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame |
1 | 1996 default: ds_fill_buffer(d_audio); // skip PCM frame |
1997 } | |
1998 } | |
1999 } | |
2000 } | |
2001 | |
2002 current_module=NULL; | |
2003 | |
2004 c_total=0; // kell ez? | |
2005 printf("A:%6.1f V:%6.1f A-V:%7.3f",d_audio->pts,d_video->pts,0.0f); | |
2006 printf(" ct:%7.3f \r",c_total);fflush(stdout); | |
2007 } else { | |
2008 printf("A: --- V:%6.1f \r",d_video->pts);fflush(stdout); | |
2009 } | |
2010 | |
2011 max_pts_correction=0.1; | |
2012 frame_corr_num=-5; frame_correction=0; | |
2013 force_redraw=5; | |
2014 a_frame=-buffer_delay-skip_audio_secs; | |
2015 // a_frame=-audio_delay-buffer_delay-skip_audio_secs; | |
2016 v_frame=0; // !!!!!! | |
2017 audio_time_usage=0; video_time_usage=0; vout_time_usage=0; | |
2018 // num_frames=real_num_frames=0; | |
2019 } | |
2020 } // keyboard event handler | |
2021 | |
220 | 2022 //================= Update OSD ==================== |
2023 { int i; | |
371 | 2024 if(osd_level>=2){ |
2025 vo_osd_text=osd_text_buffer; | |
2026 sprintf(vo_osd_text,"%c %02d:%02d:%02d",osd_function,(int)v_pts/3600,((int)v_pts/60)%60,((int)v_pts)%60); | |
2027 } else { | |
2028 vo_osd_text=NULL; | |
2029 } | |
220 | 2030 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0; |
371 | 2031 // vo_osd_text=osd_text_buffer; |
458
49b0474b2e26
I really hope that you will learn how to use cvs, sooner or later...
arpi_esp
parents:
452
diff
changeset
|
2032 |
258 | 2033 // find sub |
2034 if(subtitles){ | |
398 | 2035 if(sub_fps==0) sub_fps=sh_video->fps; |
482 | 2036 current_module="find_sub"; |
258 | 2037 find_sub(sub_uses_time?(100*(v_pts+sub_delay)):((v_pts+sub_delay)*sub_fps)); // FIXME! frame counter... |
482 | 2038 current_module=NULL; |
258 | 2039 } |
220 | 2040 } |
1 | 2041 |
2042 } // while(!eof) | |
2043 | |
2044 //printf("\nEnd of file.\n"); | |
2045 exit_player("End of file"); | |
109 | 2046 } |
2047 return 1; | |
2048 } |