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