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