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