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