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