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