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