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