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