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