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