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