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