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