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