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