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