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