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