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