annotate mplayerHQ.c @ 498:86c689b3e40e

disable ddebug printfs
author arpi_esp
date Wed, 18 Apr 2001 01:25:09 +0000
parents effc62af528c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1 // AVI & MPEG Player v0.11 (C) 2000-2001. by A'rpi/ESP-team
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
3 // Enable ALSA emulation (using 32kB audio buffer) - timer testing only
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
4 //#define SIMULATE_ALSA
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
5
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
6 // Define, if you want to run libmpeg2 in a new process (using codec-ctrl)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
7 //#define HAVE_CODECCTRL
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
8
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
9 #ifdef USE_XMMP_AUDIO
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
10 #define OUTBURST 4096
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
11 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
12 //#define OUTBURST 1024
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
13 #define OUTBURST 1024
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
14 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
15
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
16 #define AUDIO_BUFF 32768
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
17
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
18 #include <stdio.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
19 #include <stdlib.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
20 #include <string.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
21
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
22 #include <signal.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
23
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
24 #include <sys/ioctl.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
25 #include <unistd.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
26 #include <sys/mman.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
27
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
28 #include <sys/types.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
29 #include <sys/wait.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
30 #include <sys/time.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
31 #include <sys/stat.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
32 #include <fcntl.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
33 #include <sys/soundcard.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
34 #include <linux/cdrom.h>
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
35
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
36 #include "version.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
37 #include "config.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
38
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
39 #include "cfgparser.h"
159
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
40 #include "cfg-mplayer-def.h"
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
41
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
42 #include "libvo/video_out.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
43
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
44 // CODECS:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
45 #include "mp3lib/mp3.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
46 #include "libac3/ac3.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
47 #include "libmpeg2/mpeg2.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
48 #include "libmpeg2/mpeg2_internal.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
49
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
50 #include "loader.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
51 #include "wine/avifmt.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
52
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
53 #include "opendivx/decore.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
54
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
55
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
56 #ifdef USE_XMMP_AUDIO
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
57 #include "libxmm/xmmp.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
58 #include "libxmm/libxmm.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
59 XMM xmm;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
60 XMM_PluginSound *pSound=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
61 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
62
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
63 extern int vo_screenwidth;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
64
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
65 extern char* win32_codec_name; // must be set before calling DrvOpen() !!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
66
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
67 extern int errno;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
68
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
69 #include "linux/getch2.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
70 #include "linux/keycodes.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
71 #include "linux/timer.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
72 #include "linux/shmem.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
73
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
74 #ifdef HAVE_LIRC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
75 #include "lirc_mp.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
76 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
77
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
78 #include "help_mp.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
79
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
80 #define DEBUG if(0)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
81 static int verbose=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
82
153
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 148
diff changeset
83 static int cfg_inc_verbose(struct config *conf){
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 148
diff changeset
84 ++verbose;
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 148
diff changeset
85 return 0;
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 148
diff changeset
86 }
8e55121885b2 new configfile/cmdline parser
arpi_esp
parents: 148
diff changeset
87
162
effc62af528c new option: -include
szabii
parents: 159
diff changeset
88 static int cfg_include(struct config *conf, char *filename){
effc62af528c new option: -include
szabii
parents: 159
diff changeset
89 return parse_config_file(conf, filename);
effc62af528c new option: -include
szabii
parents: 159
diff changeset
90 }
effc62af528c new option: -include
szabii
parents: 159
diff changeset
91
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
92 static int max_framesize=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
93
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
94 static int dbg_es_sent=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
95 static int dbg_es_rcvd=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
96
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
97 //static int show_packets=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
98
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
99 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
100
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
101 typedef struct {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
102 // file:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
103 MainAVIHeader avih;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
104 unsigned int movi_start;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
105 unsigned int movi_end;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
106 // index:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
107 AVIINDEXENTRY* idx;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
108 int idx_size;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
109 int idx_pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
110 int idx_pos_a;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
111 int idx_pos_v;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
112 int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
113 // int a_idx;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
114 // int v_idx;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
115 // video:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
116 AVIStreamHeader video;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
117 char *video_codec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
118 BITMAPINFOHEADER bih; // in format
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
119 BITMAPINFOHEADER o_bih; // out format
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
120 HIC hic;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
121 void *our_out_buffer;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
122 unsigned int bitrate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
123 // video format flags: (filled by codecs.c)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
124 char yuv_supported; // 1 if codec support YUY2 output format
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
125 char yuv_hack_needed; // requires for divx & mpeg4
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
126 char no_32bpp_support; // requires for INDEO 3.x, 4.x
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
127 char flipped; // image is upside-down
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
128 // audio:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
129 AVIStreamHeader audio;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
130 char *audio_codec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
131 int audio_seekable;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
132 char wf_ext[64]; // in format
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
133 WAVEFORMATEX wf; // out format
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
134 HACMSTREAM srcstream;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
135 int audio_in_minsize;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
136 int audio_out_minsize;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
137 } avi_header_t;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
138
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
139 avi_header_t avi_header;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
140
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
141 #include "aviprint.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
142 #include "codecs.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
143
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
144 extern picture_t *picture;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
145
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
146 char* encode_name=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
147 char* encode_index_name=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
148 int encode_bitrate=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
149
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
150 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
151 // Input media streaming & demultiplexer:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
152 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
153
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
154 #include "stream.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
155 #include "demuxer.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
156 #include "demux_avi.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
157 #include "demux_mpg.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
158
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
159 demuxer_t *demuxer=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
160 demux_stream_t *d_audio=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
161 demux_stream_t *d_video=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
162
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
163 // MPEG video stream parser:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
164 #include "parse_es.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
165
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
166 static const int frameratecode2framerate[16] = {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
167 0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
168 60*10000, 0,0,0,0,0,0,0
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
169 };
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
170
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
171 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
172 // Audio codecs:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
173 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
174
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
175 //int mp3_read(char *buf,int size){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
176 int mplayer_audio_read(char *buf,int size){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
177 int len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
178 len=demux_read_data(d_audio,buf,size);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
179 return len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
180 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
181
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
182 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
183 int len=ds_get_packet(d_audio,(char**)start);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
184 //printf("<ac3:%d>\n",len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
185 if(len<0)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
186 *start = *end = NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
187 else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
188 *end = *start + len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
189 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
190
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
191 #include "alaw.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
192
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
193 #include "xa/xa_gsm.h"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
194
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
195 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
196 // The OpenDivX stuff:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
197 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
198
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
199 unsigned char *opendivx_src[3];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
200 int opendivx_stride[3];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
201
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
202 // callback, the opendivx decoder calls this for each frame:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
203 void convert_linux(unsigned char *puc_y, int stride_y,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
204 unsigned char *puc_u, unsigned char *puc_v, int stride_uv,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
205 unsigned char *bmp, int width_y, int height_y){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
206
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
207 // printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
208
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
209 opendivx_src[0]=puc_y;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
210 opendivx_src[1]=puc_u;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
211 opendivx_src[2]=puc_v;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
212
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
213 opendivx_stride[0]=stride_y;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
214 opendivx_stride[1]=stride_uv;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
215 opendivx_stride[2]=stride_uv;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
216 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
217
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
218 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
219
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
220 #ifdef SIMULATE_ALSA
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
221 // Simulate ALSA buffering on OSS device :) (for testing...)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
222
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
223 #define fake_ALSA_size 32768
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
224 char fake_ALSA_buffer[fake_ALSA_size];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
225 int fake_ALSA_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
226
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
227 void fake_ALSA_write(int audio_fd,char* a_buffer,int len){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
228 while(len>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
229 int x=fake_ALSA_size-fake_ALSA_len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
230 if(x>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
231 if(x>len) x=len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
232 memcpy(&fake_ALSA_buffer[fake_ALSA_len],a_buffer,x);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
233 fake_ALSA_len+=x;len-=x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
234 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
235 if(fake_ALSA_len>=fake_ALSA_size){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
236 write(audio_fd,fake_ALSA_buffer,fake_ALSA_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
237 fake_ALSA_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
238 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
239 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
240 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
241 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
242 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
243
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
244 // AVI file header reader/parser/writer:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
245 #include "aviheader.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
246 #include "aviwrite.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
247
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
248 // ASF headers:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
249 #include "asfheader.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
250 #include "demux_asf.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
251
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
252 // DLL codecs init routines
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
253 #include "dll_init.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
254
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
255 // Common FIFO functions, and keyboard/event FIFO code
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
256 #include "fifo.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
257
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
258 // MPEG video codec process controller:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
259 #ifdef HAVE_CODECCTRL
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
260 #include "codecctrl.c"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
261 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
262
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
263 //**************************************************************************//
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
264
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
265 static vo_functions_t *video_out=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
266
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
267 static int play_in_bg=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
268
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
269 void exit_player(char* how){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
270 if(how) printf("\nExiting... (%s)\n",how);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
271 printf("max framesize was %d bytes\n",max_framesize);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
272 // restore terminal:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
273 getch2_disable();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
274 #ifdef HAVE_CODECCTRL
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
275 if(child_pid){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
276 // MPEG
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
277 // printf("\n\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
278 //send_cmd(data_fifo,0);usleep(50000); // EOF request
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
279 DEBUG_SIG { printf("Sending TERM signal to CTRL...\n");DEBUG_SIGNALS_SLEEP}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
280 kill(child_pid,SIGTERM);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
281 usleep(10000); // kill & wait 10ms
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
282 DEBUG_SIG { printf("Closing PIPEs...\n");DEBUG_SIGNALS_SLEEP}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
283 close(control_fifo);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
284 close(data_fifo);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
285 DEBUG_SIG { printf("Freeing shmem...\n");DEBUG_SIGNALS_SLEEP}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
286 if(videobuffer) shmem_free(videobuffer);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
287 DEBUG_SIG { printf("Exiting...\n");DEBUG_SIGNALS_SLEEP}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
288 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
289 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
290 {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
291 // AVI
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
292 video_out->uninit();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
293 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
294 #ifdef USE_XMMP_AUDIO
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
295 if(verbose) printf("XMM: closing audio driver...\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
296 if(pSound){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
297 pSound->Exit( pSound );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
298 xmm_Exit( &xmm );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
299 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
300 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
301 if(encode_name) avi_fixate();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
302 #ifdef HAVE_LIRC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
303 lirc_mp_cleanup();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
304 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
305 //if(play_in_bg) system("xsetroot -solid \\#000000");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
306 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
307 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
308
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
309 static char* current_module=NULL; // for debugging
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
310
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
311 void exit_sighandler(int x){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
312 static int sig_count=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
313 ++sig_count;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
314 if(sig_count==2) exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
315 if(sig_count>2){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
316 // can't stop :(
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
317 kill(getpid(),SIGKILL);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
318 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
319 printf("\nMPlayer interrupted by signal %d in module: %s \n",x,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
320 current_module?current_module:"unknown"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
321 );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
322 exit_player(NULL);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
323 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
324
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
325 int divx_quality=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
326
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
327 int main(int argc,char* argv[], char *envp[]){
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
328 char* filename=NULL; //"MI2-Trailer.avi";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
329 int i;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
330 int seek_to_sec=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
331 int seek_to_byte=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
332 int f; // filedes
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
333 int stream_type;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
334 stream_t* stream=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
335 int file_format=DEMUXER_TYPE_UNKNOWN;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
336 int has_audio=1; // audio format 0=none 1=mpeg 2=pcm 3=ac3 4=win32 5=alaw 6=msgsm
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
337 int has_video=0; // video format 0=none 1=mpeg 2=win32 3=OpenDivX
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
338 //
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
339 int audio_format=0; // override
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
340 #ifdef ALSA_TIMER
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
341 int alsa=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
342 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
343 int alsa=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
344 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
345 int audio_buffer_size=-1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
346 int audio_id=-1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
347 int video_id=-1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
348 float default_max_pts_correction=0.01f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
349 int delay_corrected=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
350 float force_fps=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
351 float default_fps=25;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
352 float audio_delay=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
353 int vcd_track=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
354 #ifdef VCD_CACHE
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
355 int vcd_cache_size=128;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
356 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
357 int no_index=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
358 #ifdef AVI_SYNC_BPS
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
359 int pts_from_bps=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
360 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
361 int pts_from_bps=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
362 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
363 char* title="MPlayer";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
364 // screen info:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
365 char* video_driver=NULL; //"mga"; // default
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
366 int fullscreen=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
367 int screen_size_x=SCREEN_SIZE_X;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
368 int screen_size_y=SCREEN_SIZE_Y;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
369 int screen_size_xy=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
370 // movie info:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
371 int movie_size_x=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
372 int movie_size_y=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
373 int out_fmt=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
374 char *dsp="/dev/dsp";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
375 int force_ni=0;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
376 char *homedir;
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
377 char conffile[100];
159
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
378 char confdir[100];
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
379 int conffile_fd;
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
380 #include "cfg-mplayer.h"
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
381
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
382 printf("%s",banner_text);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
383
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
384 if (parse_config_file(conf, "/etc/mplayer.conf") < 0)
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
385 exit(1);
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
386 if ((homedir = getenv("HOME")) == NULL) {
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
387 printf("Can't find HOME dir\n");
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
388 } else {
159
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
389 snprintf(confdir, 100, "%s/.mplayer", homedir);
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
390 mkdir(confdir, 0777);
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
391 snprintf(conffile, 100, "%s/config", confdir);
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
392 if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0644)) != -1) {
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
393 write(conffile_fd, default_config, strlen(default_config));
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
394 close(conffile_fd);
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
395 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
396 if (parse_config_file(conf, conffile) < 0)
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
397 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
398 }
147
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
399 if (parse_command_line(conf, argc, argv, envp, &filename) < 0)
0a0d7dd8fb51 new command line/config file parser
szabii
parents: 118
diff changeset
400 exit(1);
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
401
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
402 // Many users forget to include command line in bugreports...
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
403 if(verbose){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
404 printf("CommandLine:");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
405 for(i=1;i<argc;i++)printf(" '%s'",argv[i]);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
406 printf("\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
407 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
408
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
409 if(video_driver && strcmp(video_driver,"help")==0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
410 printf("Available video output drivers:\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
411 i=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
412 while (video_out_drivers[i]) {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
413 const vo_info_t *info = video_out_drivers[i++]->get_info ();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
414 printf("\t%s\t%s\n", info->short_name, info->name);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
415 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
416 printf("\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
417 exit(0);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
418 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
419
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
420 // check video_out driver name:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
421 if(!video_driver)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
422 video_out=video_out_drivers[0];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
423 else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
424 for (i=0; video_out_drivers[i] != NULL; i++){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
425 const vo_info_t *info = video_out_drivers[i]->get_info ();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
426 if(strcmp(info->short_name,video_driver) == 0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
427 video_out = video_out_drivers[i];break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
428 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
429 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
430 if(!video_out){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
431 printf("Invalid video output driver name: %s\n",video_driver);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
432 return 0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
433 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
434
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
435
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
436 if(!filename){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
437 if(vcd_track) filename="/dev/cdrom";
159
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
438 else {
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
439 printf("%s",help_text); exit(0);
8e9b6c00756f added cfgparser fixes to mplayerHQ.c
szabii
parents: 153
diff changeset
440 }
118
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
441 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
442
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
443
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
444 if(vcd_track){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
445 //============ Open VideoCD track ==============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
446 f=open(filename,O_RDONLY);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
447 if(f<0){ printf("CD-ROM Device '%s' not found!\n",filename);return 1; }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
448 vcd_read_toc(f);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
449 if(!vcd_seek_to_track(f,vcd_track)){ printf("Error selecting VCD track!\n");return 1;}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
450 seek_to_byte+=VCD_SECTOR_DATA*vcd_get_msf();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
451 if(verbose) printf("VCD start byte position: 0x%X\n",seek_to_byte);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
452 stream_type=STREAMTYPE_VCD;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
453 #ifdef VCD_CACHE
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
454 vcd_cache_init(vcd_cache_size);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
455 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
456 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
457 //============ Open plain FILE ============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
458 f=open(filename,O_RDONLY);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
459 if(f<0){ printf("File not found: '%s'\n",filename);return 1; }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
460 stream_type=STREAMTYPE_FILE;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
461 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
462
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
463 stream=new_stream(f,stream_type);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
464
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
465 //============ Open & Sync stream and detect file format ===============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
466
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
467 if(has_audio==0) audio_id=-2; // do NOT read audio packets...
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
468
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
469 //=============== Try to open as AVI file: =================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
470 stream_reset(stream);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
471 demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
472 stream_seek(demuxer->stream,seek_to_byte);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
473 { //---- RIFF header:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
474 int id=stream_read_dword_le(demuxer->stream); // "RIFF"
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
475 if(id==mmioFOURCC('R','I','F','F')){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
476 stream_read_dword_le(demuxer->stream); //filesize
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
477 id=stream_read_dword_le(demuxer->stream); // "AVI "
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
478 if(id==formtypeAVI){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
479 printf("Detected AVI file format!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
480 file_format=DEMUXER_TYPE_AVI;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
481 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
482 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
483 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
484 //=============== Try to open as ASF file: =================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
485 if(file_format==DEMUXER_TYPE_UNKNOWN){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
486 stream_reset(stream);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
487 demuxer=new_demuxer(stream,DEMUXER_TYPE_ASF,audio_id,video_id);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
488 stream_seek(demuxer->stream,seek_to_byte);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
489 if(asf_check_header()){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
490 printf("Detected ASF file format!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
491 file_format=DEMUXER_TYPE_ASF;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
492 // printf("!!! ASF files not (yet) supported !!!\n");exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
493 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
494 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
495 //=============== Try to open as MPEG-PS file: =================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
496 if(file_format==DEMUXER_TYPE_UNKNOWN){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
497 stream_reset(stream);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
498 demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_PS,audio_id,video_id);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
499 stream_seek(demuxer->stream,seek_to_byte);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
500 if(audio_format) demuxer->audio->type=audio_format; // override audio format
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
501 if(ds_fill_buffer(demuxer->video)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
502 printf("Detected MPEG-PS file format!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
503 file_format=DEMUXER_TYPE_MPEG_PS;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
504 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
505 // some hack to get meaningfull error messages to our unhappy users:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
506 // if(num_elementary_packets100>16 &&
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
507 // abs(num_elementary_packets101-num_elementary_packets100)<8){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
508 if(num_elementary_packets100>=2 && num_elementary_packets101>=2 &&
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
509 abs(num_elementary_packets101-num_elementary_packets100)<8){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
510 file_format=DEMUXER_TYPE_MPEG_ES; // <-- hack is here :)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
511 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
512 if(demuxer->synced==2)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
513 printf("Missing MPEG video stream!? contact the author, it may be a bug :(\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
514 else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
515 printf("Not MPEG System Stream format... (maybe Transport Stream?)\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
516 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
517 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
518 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
519 //=============== Try to open as MPEG-ES file: =================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
520 if(file_format==DEMUXER_TYPE_MPEG_ES){ // little hack, see above!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
521 stream_reset(stream);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
522 demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_ES,audio_id,video_id);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
523 stream_seek(demuxer->stream,seek_to_byte);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
524 if(!ds_fill_buffer(demuxer->video)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
525 printf("Invalid MPEG-ES stream??? contact the author, it may be a bug :(\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
526 file_format=DEMUXER_TYPE_UNKNOWN;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
527 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
528 printf("Detected MPEG-ES file format!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
529 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
530 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
531 //=============== Unknown, exiting... ===========================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
532 if(file_format==DEMUXER_TYPE_UNKNOWN){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
533 printf("============= Sorry, this file format not recognized/supported ===============\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
534 printf("=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
535 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
536 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
537 //====== File format recognized, set up these for compatibility: =========
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
538 d_audio=demuxer->audio;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
539 d_video=demuxer->video;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
540
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
541 switch(file_format){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
542 case DEMUXER_TYPE_AVI: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
543 //---- AVI header:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
544 read_avi_header(no_index);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
545 stream_reset(demuxer->stream);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
546 stream_seek(demuxer->stream,avi_header.movi_start);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
547 avi_header.idx_pos=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
548 avi_header.idx_pos_a=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
549 avi_header.idx_pos_v=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
550 if(avi_header.idx_size>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
551 // decide index format:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
552 if(avi_header.idx[0].dwChunkOffset<avi_header.movi_start)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
553 avi_header.idx_offset=avi_header.movi_start-4;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
554 else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
555 avi_header.idx_offset=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
556 if(verbose) printf("AVI index offset: %d\n",avi_header.idx_offset);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
557 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
558 demuxer->endpos=avi_header.movi_end;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
559
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
560 if(avi_header.idx_size>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
561 // check that file is non-interleaved:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
562 int i;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
563 int a_pos=-1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
564 int v_pos=-1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
565 for(i=0;i<avi_header.idx_size;i++){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
566 AVIINDEXENTRY* idx=&avi_header.idx[i];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
567 demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
568 int pos=idx->dwChunkOffset+avi_header.idx_offset;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
569 if(a_pos==-1 && ds==demuxer->audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
570 a_pos=pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
571 if(v_pos!=-1) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
572 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
573 if(v_pos==-1 && ds==demuxer->video){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
574 v_pos=pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
575 if(a_pos!=-1) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
576 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
577 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
578 if(v_pos==-1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
579 printf("AVI_NI: missing video stream!? contact the author, it may be a bug :(\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
580 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
581 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
582 if(a_pos==-1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
583 printf("AVI_NI: No audio stream found -> nosound\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
584 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
585 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
586 if(force_ni || abs(a_pos-v_pos)>0x100000){ // distance > 1MB
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
587 printf("Detected NON-INTERLEAVED AVI file-format!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
588 // file_format=DEMUXER_TYPE_AVI_NI; // HACK!!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
589 demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
590 pts_from_bps=1; // force BPS sync!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
591 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
592 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
593 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
594 // no index
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
595 if(force_ni){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
596 printf("Using NON-INTERLEAVED Broken AVI file-format!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
597 // file_format=DEMUXER_TYPE_AVI_NI; // HACK!!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
598 demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
599 avi_header.idx_pos_a=
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
600 avi_header.idx_pos_v=avi_header.movi_start;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
601 pts_from_bps=1; // force BPS sync!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
602 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
603 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
604
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
605 if(!ds_fill_buffer(d_video)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
606 printf("AVI: missing video stream!? contact the author, it may be a bug :(\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
607 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
608 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
609 has_video=2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
610 // Decide audio format:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
611 if(audio_format)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
612 has_audio=audio_format; // override type
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
613 else if(has_audio)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
614 switch(((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
615 case 0:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
616 has_audio=0;break; // disable/no audio
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
617 case 6:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
618 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
619 has_audio=5;break; // aLaw
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
620 case 0x31:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
621 case 0x32:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
622 has_audio=6;break; // MS-GSM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
623 case 0x50:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
624 #ifdef DEFAULT_MPG123
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
625 case 0x55:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
626 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
627 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
628 has_audio=1;break; // MPEG
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
629 case 0x01:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
630 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
631 has_audio=2;break; // PCM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
632 case 0x2000:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
633 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
634 has_audio=3;break; // AC3
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
635 default:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
636 avi_header.audio_seekable=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
637 has_audio=4; // Win32/ACM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
638 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
639 if(verbose) printf("detected AVI audio format: %d\n",has_audio);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
640 if(has_audio==4){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
641 if(!avi_header.audio_codec) avi_header.audio_codec=get_auds_codec_name();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
642 if(!avi_header.audio_codec) has_audio=0; // unknown win32 codec
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
643 if(verbose) printf("win32 audio codec: '%s'\n",avi_header.audio_codec);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
644 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
645 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
646 if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
647 if(!ds_fill_buffer(d_audio)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
648 printf("AVI: No Audio stream found... ->nosound\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
649 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
650 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
651 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
652 default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
653 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
654 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
655 case DEMUXER_TYPE_ASF: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
656 //---- ASF header:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
657 read_asf_header();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
658 stream_reset(demuxer->stream);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
659 stream_seek(demuxer->stream,avi_header.movi_start);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
660 avi_header.idx_pos=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
661 #if 0
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
662 if(avi_header.idx_size>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
663 // decide index format:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
664 if(avi_header.idx[0].dwChunkOffset<avi_header.movi_start)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
665 avi_header.idx_offset=avi_header.movi_start-4;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
666 else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
667 avi_header.idx_offset=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
668 if(verbose) printf("ASF index offset: %d\n",avi_header.idx_offset);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
669 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
670 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
671 demuxer->endpos=avi_header.movi_end;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
672 if(!ds_fill_buffer(d_video)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
673 printf("ASF: missing video stream!? contact the author, it may be a bug :(\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
674 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
675 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
676 has_video=2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
677 // Decide audio format:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
678 if(audio_format)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
679 has_audio=audio_format; // override type
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
680 else if(has_audio)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
681 switch(((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
682 case 0:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
683 has_audio=0;break; // disable/no audio
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
684 case 6:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
685 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
686 has_audio=5;break; // aLaw
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
687 case 0x31:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
688 case 0x32:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
689 has_audio=6;break; // MS-GSM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
690 case 0x50:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
691 #ifdef DEFAULT_MPG123
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
692 case 0x55:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
693 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
694 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
695 has_audio=1;break; // MPEG
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
696 case 0x01:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
697 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
698 has_audio=2;break; // PCM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
699 case 0x2000:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
700 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
701 has_audio=3;break; // AC3
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
702 default:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
703 avi_header.audio_seekable=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
704 has_audio=4; // Win32/ACM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
705 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
706 if(verbose) printf("detected ASF audio format: %d\n",has_audio);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
707 if(has_audio==4){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
708 if(!avi_header.audio_codec) avi_header.audio_codec=get_auds_codec_name();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
709 if(!avi_header.audio_codec) has_audio=0; // unknown win32 codec
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
710 if(verbose) printf("win32 audio codec: '%s'\n",avi_header.audio_codec);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
711 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
712 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
713 if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
714 if(!ds_fill_buffer(d_audio)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
715 printf("ASF: No Audio stream found... ->nosound\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
716 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
717 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
718 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
719 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
720 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
721 case DEMUXER_TYPE_MPEG_ES: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
722 demuxer->audio->type=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
723 has_audio=0; // ES streams has no audio channel
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
724 has_video=1; // mpeg video
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
725 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
726 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
727 case DEMUXER_TYPE_MPEG_PS: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
728 if(has_audio)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
729 if(!ds_fill_buffer(d_audio)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
730 printf("MPEG: No Audio stream found... ->nosound\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
731 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
732 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
733 has_audio=d_audio->type;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
734 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
735 if(verbose) printf("detected MPG-PS audio format: %d\n",has_audio);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
736 has_video=1; // mpeg video
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
737 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
738 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
739 } // switch(file_format)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
740
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
741 if(verbose) printf("file successfully opened (has_audio=%d)\n",has_audio);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
742
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
743 fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
744
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
745 //================== Init VIDEO (codec & libvo) ==========================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
746
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
747 if(has_video==2){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
748 if(avi_header.video.fccHandler==mmioFOURCC('d', 'v', 'x', '1')) has_video=3;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
749 if(avi_header.video.fccHandler==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
750 if(avi_header.bih.biCompression==mmioFOURCC('d', 'v', 'x', '1')) has_video=3;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
751 if(avi_header.bih.biCompression==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
752 // if(avi_header.bih.biCompression==mmioFOURCC('D', 'I', 'V', 'X')) has_video=3; // Gabucino
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
753 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
754
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
755 switch(has_video){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
756 case 2: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
757 if(!avi_header.video_codec) avi_header.video_codec=get_vids_codec_name();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
758 if(verbose)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
759 printf("win32 video codec: '%s' %s%s%s\n",avi_header.video_codec,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
760 avi_header.yuv_supported?"[YUV]":"",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
761 avi_header.yuv_hack_needed?"[hack]":"",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
762 avi_header.flipped?"[FLIP]":""
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
763 );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
764 if(!avi_header.video_codec) exit(1); // unknown video codec
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
765 if(avi_header.yuv_supported && video_out->query_format(IMGFMT_YUY2)) out_fmt=IMGFMT_YUY2; else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
766 if(avi_header.no_32bpp_support && video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|24; else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
767 if(video_out->query_format(IMGFMT_BGR|15)) out_fmt=IMGFMT_BGR|16; else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
768 if(video_out->query_format(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|16; else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
769 if(video_out->query_format(IMGFMT_BGR|24)) out_fmt=IMGFMT_BGR|24; else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
770 if(video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|32; else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
771 printf("Sorry, selected video_out device is incompatible with this codec.\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
772 printf("(It can't show 24bpp or 32bpp RGB images. Try to run X at 24/32bpp!)\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
773 // printf("(cannot convert between YUY2, YV12 and RGB colorspace formats)\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
774 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
775 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
776 //if(verbose) printf("AVI out_fmt=%X\n",out_fmt);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
777 if(verbose) if(out_fmt==IMGFMT_YUY2) printf("Using YUV/YUY2 video output format!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
778 if(!init_video_codec(out_fmt)) exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
779 if(verbose) printf("INFO: Win32 video codec init OK!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
780 if(out_fmt==(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|15; // fix bpp
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
781
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
782 // calculating video bitrate:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
783 avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
784 if(avi_header.audio.fccType) avi_header.bitrate-=avi_header.audio.dwLength;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
785 if(verbose) printf("AVI video length=%d\n",avi_header.bitrate);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
786 avi_header.bitrate=((float)avi_header.bitrate/(float)avi_header.video.dwLength)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
787 *((float)avi_header.video.dwRate/(float)avi_header.video.dwScale);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
788 // default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
789 printf("VIDEO: [%.4s] %dx%d %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
790 &avi_header.bih.biCompression,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
791 avi_header.bih.biWidth,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
792 avi_header.bih.biHeight,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
793 avi_header.bih.biBitCount,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
794 default_fps,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
795 avi_header.bitrate*0.008f,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
796 avi_header.bitrate/1024.0f );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
797
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
798 // display info:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
799 movie_size_x=avi_header.o_bih.biWidth;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
800 movie_size_y=abs(avi_header.o_bih.biHeight);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
801 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
802 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
803 case 3: { // OpenDivX
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
804 out_fmt=IMGFMT_YV12;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
805 if(!video_out->query_format(out_fmt)) {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
806 printf("Sorry, selected video_out device is incompatible with this codec!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
807 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
808 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
809
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
810 if(verbose) printf("OpenDivX video codec\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
811 { DEC_PARAM dec_param;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
812 DEC_SET dec_set;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
813 dec_param.x_dim = avi_header.bih.biWidth;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
814 dec_param.y_dim = avi_header.bih.biHeight;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
815 dec_param.color_depth = 32;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
816 decore(0x123, DEC_OPT_INIT, &dec_param, NULL);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
817 dec_set.postproc_level = divx_quality;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
818 decore(0x123, DEC_OPT_SETPP, &dec_set, NULL);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
819 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
820 if(verbose) printf("INFO: OpenDivX video codec init OK!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
821
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
822 // calculating video bitrate:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
823 avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
824 if(avi_header.audio.fccType) avi_header.bitrate-=avi_header.audio.dwLength;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
825 if(verbose) printf("AVI video length=%d\n",avi_header.bitrate);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
826 avi_header.bitrate=((float)avi_header.bitrate/(float)avi_header.video.dwLength)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
827 *((float)avi_header.video.dwRate/(float)avi_header.video.dwScale);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
828 // default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
829 printf("VIDEO: [%.4s] %dx%d %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
830 &avi_header.bih.biCompression,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
831 avi_header.bih.biWidth,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
832 avi_header.bih.biHeight,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
833 avi_header.bih.biBitCount,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
834 default_fps,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
835 avi_header.bitrate*0.008f,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
836 avi_header.bitrate/1024.0f );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
837
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
838 // display info:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
839 // movie_size_x=avi_header.bih.biWidth+(divx_quality?0:64);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
840 movie_size_x=avi_header.bih.biWidth;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
841 movie_size_y=abs(avi_header.bih.biHeight);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
842 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
843 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
844 case 1: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
845 out_fmt=IMGFMT_YV12;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
846 if(!video_out->query_format(out_fmt)) {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
847 printf("Sorry, selected video_out device is incompatible with this codec!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
848 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
849 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
850 // Find sequence_header first:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
851 if(verbose) printf("Searching for sequence header... ");fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
852 while(1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
853 int i=sync_video_packet(d_video);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
854 if(i==0x1B3) break; // found it!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
855 if(!i || !skip_video_packet(d_video)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
856 if(verbose) printf("NONE :(\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
857 printf("MPEG: FATAL: EOF while searching for sequence header\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
858 exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
859 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
860 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
861 if(verbose) printf("FOUND!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
862 // allocate some shared memory for the video packet buffer:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
863 videobuffer=shmem_alloc(VIDEOBUFFER_SIZE);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
864 if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
865 // init libmpeg2:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
866 mpeg2_init();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
867 #ifdef MPEG12_POSTPROC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
868 picture->pp_options=divx_quality;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
869 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
870 if(divx_quality){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
871 printf("WARNING! You requested image postprocessing for an MPEG 1/2 video,\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
872 printf(" but compiled MPlayer without MPEG 1/2 postprocessing support!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
873 printf(" #define MPEG12_POSTPROC in config.h, and recompile libmpeg2!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
874 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
875 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
876 if(verbose) printf("mpeg2_init() ok\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
877 // ========= Read & process sequence header & extension ============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
878 videobuf_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
879 if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header!\n");return 1;}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
880 if(header_process_sequence_header (picture, &videobuffer[4])) {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
881 printf ("bad sequence header!\n"); return 1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
882 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
883 if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext.
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
884 videobuf_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
885 if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header extension!\n");return 1;}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
886 if(header_process_extension (picture, &videobuffer[4])) {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
887 printf ("bad sequence header extension!\n"); return 1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
888 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
889 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
890 default_fps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
891 if(verbose) printf("mpeg bitrate: %d (%X)\n",picture->bitrate,picture->bitrate);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
892 printf("VIDEO: %s %dx%d (aspect %d) %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
893 picture->mpeg1?"MPEG1":"MPEG2",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
894 picture->display_picture_width,picture->display_picture_height,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
895 picture->aspect_ratio_information,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
896 default_fps,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
897 picture->bitrate*0.5f,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
898 picture->bitrate/16.0f );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
899 // display info:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
900 // movie_size_x=picture->coded_picture_width;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
901 movie_size_x=picture->display_picture_width;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
902 movie_size_y=picture->display_picture_height;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
903 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
904 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
905 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
906
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
907 // ================== Init output files for encoding ===============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
908 if(encode_name){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
909 // encode file!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
910 FILE *encode_file=fopen(encode_name,"rb");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
911 if(encode_file){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
912 fclose(encode_file);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
913 printf("File already exists: %s (don't overwrite your favourite AVI!)\n",encode_name);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
914 return 0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
915 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
916 encode_file=fopen(encode_name,"wb");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
917 if(!encode_file){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
918 printf("Cannot create file for encoding\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
919 return 0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
920 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
921 write_avi_header_1(encode_file,mmioFOURCC('d', 'i', 'v', 'x'),default_fps,movie_size_x,movie_size_y);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
922 fclose(encode_file);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
923 encode_index_name=malloc(strlen(encode_name)+8);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
924 strcpy(encode_index_name,encode_name);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
925 strcat(encode_index_name,".index");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
926 if((encode_file=fopen(encode_index_name,"wb")))
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
927 fclose(encode_file);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
928 else encode_index_name=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
929 has_audio=0; // disable audio !!!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
930 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
931
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
932 // ========== Init keyboard FIFO (connection to libvo) ============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
933
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
934 make_pipe(&keyb_fifo_get,&keyb_fifo_put);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
935
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
936 // ========== Init display (movie_size_x*movie_size_y/out_fmt) ============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
937
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
938 #ifdef X11_FULLSCREEN
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
939 if(fullscreen){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
940 if(vo_init()){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
941 //if(verbose) printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
942 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
943 if(!screen_size_xy) screen_size_xy=vo_screenwidth; // scale with asp.ratio
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
944 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
945 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
946
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
947 if(screen_size_xy>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
948 if(screen_size_xy<=8){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
949 screen_size_x=screen_size_xy*movie_size_x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
950 screen_size_y=screen_size_xy*movie_size_y;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
951 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
952 screen_size_x=screen_size_xy;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
953 screen_size_y=screen_size_xy*movie_size_y/movie_size_x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
954 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
955 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
956 if(screen_size_x<=8) screen_size_x*=movie_size_x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
957 if(screen_size_y<=8) screen_size_y*=movie_size_y;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
958 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
959 if(verbose) printf("Destination size: %d x %d out_fmt=%0X\n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
960 screen_size_x,screen_size_y,out_fmt);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
961
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
962 if(verbose) printf("video_out->init(%dx%d->%dx%d,fs=%d,'%s',0x%X)\n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
963 movie_size_x,movie_size_y,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
964 screen_size_x,screen_size_y,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
965 fullscreen,title,out_fmt);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
966
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
967 if(video_out->init(movie_size_x,movie_size_y,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
968 screen_size_x,screen_size_y,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
969 fullscreen,title,out_fmt)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
970 printf("FATAL: Cannot initialize video driver!\n");exit(1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
971 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
972 if(verbose) printf("INFO: Video OUT driver init OK!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
973
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
974 fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
975
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
976
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
977 if(has_video==1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
978 //================== init mpeg codec ===================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
979 mpeg2_allocate_image_buffers (picture);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
980 if(verbose) printf("INFO: mpeg2_init_video() OK!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
981 #ifdef HAVE_CODECCTRL
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
982 // ====== Init MPEG codec process ============
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
983 make_pipe(&control_fifo,&control_fifo2);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
984 make_pipe(&data_fifo2,&data_fifo);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
985 // ====== Let's FORK() !!! ===================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
986 if((child_pid=fork())==0)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
987 mpeg_codec_controller(video_out); // this one is running in a new process!!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
988 signal(SIGPIPE,SIG_IGN); // Ignore "Broken pipe" signal (codec restarts)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
989 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
990 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
991
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
992 //================== MAIN: ==========================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
993 {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
994 char* a_buffer=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
995 int a_buffer_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
996 int a_buffer_size=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
997 int audio_fd=-1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
998 int pcm_bswap=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
999 float buffer_delay=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1000 float frame_correction=0; // A-V timestamp kulonbseg atlagolas
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1001 int frame_corr_num=0; //
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1002 float a_frame=0; // Audio
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1003 float v_frame=0; // Video
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1004 float time_frame=10; // Timer
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1005 float a_pts=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1006 float v_pts=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1007 float c_total=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1008 float max_pts_correction=default_max_pts_correction;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1009 int eof=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1010 int force_redraw=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1011 ac3_frame_t *ac3_frame=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1012 float num_frames=0; // number of frames played
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1013 //int real_num_frames=0; // number of frames readed
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1014 double video_time_usage=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1015 double vout_time_usage=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1016 double audio_time_usage=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1017 int grab_frames=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1018
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1019 #ifdef HAVE_LIRC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1020 lirc_mp_setup();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1021 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1022
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1023 #ifdef USE_TERMCAP
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1024 load_termcap(NULL); // load key-codes
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1025 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1026 getch2_enable();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1027
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1028 //========= Catch terminate signals: ================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1029 // terminate requests:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1030 signal(SIGTERM,exit_sighandler); // kill
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1031 signal(SIGHUP,exit_sighandler); // kill -HUP / xterm closed
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1032 signal(SIGINT,exit_sighandler); // Interrupt from keyboard
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1033 signal(SIGQUIT,exit_sighandler); // Quit from keyboard
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1034 // fatal errors:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1035 signal(SIGBUS,exit_sighandler); // bus error
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1036 signal(SIGSEGV,exit_sighandler); // segfault
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1037 signal(SIGILL,exit_sighandler); // illegal instruction
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1038 signal(SIGFPE,exit_sighandler); // floating point exc.
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1039 signal(SIGABRT,exit_sighandler); // abort()
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1040
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1041 //================ SETUP AUDIO ==========================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1042 current_module="setup_audio";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1043
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1044 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1045
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1046 if(verbose) printf("Initializing audio codec...\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1047
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1048 MP3_bps=2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1049 pcm_bswap=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1050 a_buffer_size=AUDIO_BUFF+8192; // default size, maybe not enough for Win32/ACM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1051
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1052 if(has_audio==4){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1053 // Win32 ACM audio codec:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1054 if(init_audio_codec()){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1055 MP3_channels=avi_header.wf.nChannels;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1056 MP3_samplerate=avi_header.wf.nSamplesPerSec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1057 if(a_buffer_size<avi_header.audio_out_minsize+AUDIO_BUFF)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1058 a_buffer_size=avi_header.audio_out_minsize+AUDIO_BUFF;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1059 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1060 printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1061 if((((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag)==0x55){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1062 printf("Audio format is MP3 -> fallback to internal mp3lib/mpg123\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1063 has_audio=1; // fallback to mp3lib
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1064 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1065 has_audio=0; // nosound
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1066 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1067 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1068
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1069 // allocate audio out buffer:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1070 a_buffer=malloc(a_buffer_size);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1071 memset(a_buffer,0,a_buffer_size);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1072 a_buffer_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1073
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1074 if(has_audio==4){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1075 int ret=acm_decode_audio(a_buffer,a_buffer_size);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1076 if(ret<0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1077 printf("ACM error %d -> switching to nosound...\n",ret);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1078 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1079 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1080 a_buffer_len=ret;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1081 printf("ACM decoding test: %d bytes\n",ret);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1082 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1083 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1084
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1085 if(has_audio==2){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1086 if(file_format==DEMUXER_TYPE_AVI){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1087 // AVI PCM Audio:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1088 WAVEFORMATEX *h=(WAVEFORMATEX*)&avi_header.wf_ext;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1089 MP3_channels=h->nChannels;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1090 MP3_samplerate=h->nSamplesPerSec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1091 MP3_bps=(h->wBitsPerSample+7)/8;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1092 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1093 // DVD PCM audio:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1094 MP3_channels=2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1095 MP3_samplerate=48000;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1096 pcm_bswap=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1097 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1098 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1099 if(has_audio==3){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1100 // Dolby AC3 audio:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1101 ac3_config.fill_buffer_callback = ac3_fill_buffer;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1102 ac3_config.num_output_ch = 2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1103 ac3_config.flags = 0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1104 #ifdef HAVE_MMX
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1105 ac3_config.flags |= AC3_MMX_ENABLE;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1106 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1107 #ifdef HAVE_3DNOW
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1108 ac3_config.flags |= AC3_3DNOW_ENABLE;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1109 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1110 ac3_init();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1111 ac3_frame = ac3_decode_frame();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1112 if(ac3_frame){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1113 MP3_samplerate=ac3_frame->sampling_rate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1114 MP3_channels=2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1115 } else has_audio=0; // bad frame -> disable audio
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1116 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1117 if(has_audio==5){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1118 // aLaw audio codec:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1119 Gen_aLaw_2_Signed(); // init table
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1120 MP3_channels=((WAVEFORMATEX*)&avi_header.wf_ext)->nChannels;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1121 MP3_samplerate=((WAVEFORMATEX*)&avi_header.wf_ext)->nSamplesPerSec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1122 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1123 if(has_audio==6){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1124 // MS-GSM audio codec:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1125 GSM_Init();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1126 MP3_channels=((WAVEFORMATEX*)&avi_header.wf_ext)->nChannels;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1127 MP3_samplerate=((WAVEFORMATEX*)&avi_header.wf_ext)->nSamplesPerSec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1128 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1129 // must be here for Win32->mp3lib fallbacks
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1130 if(has_audio==1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1131 // MPEG Audio:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1132 MP3_Init();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1133 MP3_samplerate=MP3_channels=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1134 // printf("[\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1135 a_buffer_len=MP3_DecodeFrame(a_buffer,-1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1136 // printf("]\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1137 MP3_channels=2; // hack
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1138 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1139
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1140 if(verbose) printf("Audio: type: %d samplerate=%d channels=%d bps=%d\n",has_audio,MP3_samplerate,MP3_channels,MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1141
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1142 if(!MP3_channels || !MP3_samplerate){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1143 printf("Unknown/missing audio format, using nosound\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1144 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1145 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1146
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1147 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1148 #ifdef USE_XMMP_AUDIO
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1149 xmm_Init( &xmm );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1150 xmm.cSound = (XMM_PluginSound *)xmm_PluginRegister( XMMP_AUDIO_DRIVER );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1151 if( xmm.cSound ){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1152 pSound = xmm.cSound->Init( &xmm );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1153 if( pSound && pSound->Start( pSound, MP3_samplerate, MP3_channels,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1154 ( MP3_bps == 2 ) ? XMM_SOUND_FMT_S16LE : XMM_SOUND_FMT_U8 )){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1155 printf("XMM: audio setup ok\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1156 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1157 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1158 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1159 } else has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1160 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1161 audio_fd=open(dsp, O_WRONLY);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1162 if(audio_fd<0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1163 printf("Can't open audio device %s -> nosound\n",dsp);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1164 has_audio=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1165 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1166 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1167 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1168
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1169 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1170 #ifdef USE_XMMP_AUDIO
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1171 if(audio_buffer_size==-1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1172 // Measuring buffer size:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1173 buffer_delay=pSound->QueryDelay(pSound, 0);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1174 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1175 // -abs commandline option
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1176 buffer_delay=audio_buffer_size/(float)(MP3_samplerate*MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1177 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1178 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1179 int r;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1180 r=(MP3_bps==2)?AFMT_S16_LE:AFMT_U8;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1181 r=MP3_channels-1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1182 r=MP3_samplerate; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1183 printf("audio_setup: your card doesn't support %d Hz samplerate\n",r);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1184
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1185 #if 0
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1186 // r = (64 << 16) + 1024;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1187 r = (65536 << 16) + 512;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1188 if(ioctl (audio_fd, SNDCTL_DSP_SETFRAGMENT, &r)==-1)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1189 printf("audio_setup: your card doesn't support setting fragments\n",r);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1190 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1191
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1192 if(audio_buffer_size==-1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1193 // Measuring buffer size:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1194 audio_buffer_size=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1195 #ifdef HAVE_AUDIO_SELECT
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1196 while(audio_buffer_size<0x40000){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1197 fd_set rfds;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1198 struct timeval tv;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1199 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1200 tv.tv_sec=0; tv.tv_usec = 0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1201 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1202 write(audio_fd,&a_buffer[a_buffer_len],OUTBURST);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1203 audio_buffer_size+=OUTBURST;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1204 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1205 if(audio_buffer_size==0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1206 printf("\n *** Your audio driver DOES NOT support select() ***\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1207 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1208 exit_player("audio_init");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1209 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1210 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1211 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1212 buffer_delay=audio_buffer_size/(float)(MP3_samplerate*MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1213 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1214 a_frame=-(buffer_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1215 printf("Audio buffer size: %d bytes, delay: %5.3fs\n",audio_buffer_size,buffer_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1216 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1217
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1218 } // has_audio
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1219
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1220 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1221 printf("Audio: type: %d samplerate: %d channels: %d bps: %d\n",has_audio,MP3_samplerate,MP3_channels,MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1222 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1223 printf("Audio: no sound\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1224 if(verbose) printf("Freeing %d unused audio chunks\n",d_audio->packs);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1225 ds_free_packs(d_audio); // free buffered chunks
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1226 d_audio->id=-2; // do not read audio chunks
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1227 if(a_buffer) free(a_buffer);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1228 alsa=1; MP3_samplerate=76800;MP3_bps=MP3_channels=2; // fake, required for timer
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1229 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1230
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1231 current_module=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1232
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1233 //==================== START PLAYING =======================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1234
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1235 if(file_format==DEMUXER_TYPE_AVI){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1236 a_pts=d_audio->pts-(buffer_delay+audio_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1237 audio_delay-=(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1238 // audio_delay-=(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1239 printf("AVI Initial frame delay: %5.3f\n",(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1240 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a_pts=%5.3f a_frame=%5.3f\n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1241 audio_delay,buffer_delay,a_pts,a_frame);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1242 printf("START: a_pts=%5.3f v_pts=%5.3f \n",d_audio->pts,d_video->pts);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1243 delay_corrected=0; // has to correct PTS diffs
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1244 d_video->pts=0;d_audio->pts=0; // PTS is outdated now!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1245 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1246 if(force_fps) default_fps=force_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1247
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1248 printf("Start playing...\n");fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1249
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1250 #if 0
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1251 // ACM debug code
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1252 { DWORD srcsize=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1253 DWORD dstsize=16384*8;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1254 int ret=acmStreamSize(avi_header.srcstream,dstsize, &srcsize, ACM_STREAMSIZEF_DESTINATION);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1255 printf("acmStreamSize %d -> %d (err=%d)\n",dstsize,srcsize,ret);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1256 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1257 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1258
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1259 InitTimer();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1260
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1261 while(!eof){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1262 float old_vframe=v_frame;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1263 /*========================== DECODE AUDIO ============================*/
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1264
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1265 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1266 unsigned int t=GetTimer();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1267 int a_play_bytes=(v_frame-a_frame)*(float)(MP3_samplerate*MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1268
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1269 a_play_bytes&=~15;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1270 // a_play_bytes=((a_play_bytes/OUTBURST)+2)*OUTBURST;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1271 // printf("a_play_bytes=%d\n",a_play_bytes);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1272 if(a_play_bytes>AUDIO_BUFF) a_play_bytes=AUDIO_BUFF;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1273
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1274 current_module="decode_audio"; // Enter AUDIO decoder module
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1275
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1276 // Update buffer if needed
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1277 while(a_buffer_len<a_play_bytes && !d_audio->eof){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1278 switch(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1279 case 1: // MPEG layer 2 or 3
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1280 a_buffer_len+=MP3_DecodeFrame(&a_buffer[a_buffer_len],-1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1281 MP3_channels=2; // hack
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1282 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1283 case 2: // PCM
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1284 { int i=demux_read_data(d_audio,&a_buffer[a_buffer_len],OUTBURST);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1285 if(pcm_bswap){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1286 int j;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1287 if(i&3){ printf("Warning! pcm_audio_size&3 !=0 (%d)\n",i);i&=~3; }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1288 for(j=0;j<i;j+=2){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1289 char x=a_buffer[a_buffer_len+j];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1290 a_buffer[a_buffer_len+j]=a_buffer[a_buffer_len+j+1];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1291 a_buffer[a_buffer_len+j+1]=x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1292 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1293 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1294 a_buffer_len+=i;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1295 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1296 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1297 case 5: // aLaw decoder
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1298 { int l=demux_read_data(d_audio,&a_buffer[a_buffer_len],OUTBURST/2);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1299 unsigned short *d=(unsigned short *) &a_buffer[a_buffer_len];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1300 unsigned char *s=&a_buffer[a_buffer_len];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1301 a_buffer_len+=2*l;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1302 while(l>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1303 --l;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1304 d[l]=xa_alaw_2_sign[s[l]];
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1305 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1306 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1307 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1308 case 6: // MS-GSM decoder
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1309 { unsigned char buf[65]; // 65 bytes / frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1310 while(a_buffer_len<OUTBURST){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1311 if(demux_read_data(d_audio,buf,65)!=65) break; // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1312 XA_MSGSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 65 byte -> 320 short
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1313 // XA_GSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 33 byte -> 160 short
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1314 a_buffer_len+=2*320;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1315 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1316 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1317 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1318 case 3: // AC3 decoder
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1319 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1320 if(!ac3_frame) ac3_frame=ac3_decode_frame();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1321 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1322 if(ac3_frame){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1323 memcpy(&a_buffer[a_buffer_len],ac3_frame->audio_data,256 * 6 *MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1324 a_buffer_len+=256 * 6 *MP3_channels*MP3_bps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1325 ac3_frame=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1326 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1327 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1328 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1329 case 4:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1330 { int ret=acm_decode_audio(&a_buffer[a_buffer_len],a_buffer_size-a_buffer_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1331 if(ret>0) a_buffer_len+=ret;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1332 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1333 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1334 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1335 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1336 current_module=NULL; // Leave AUDIO decoder module
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1337 t=GetTimer()-t;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1338 audio_time_usage+=t*0.000001;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1339
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1340 } // if(has_audio)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1341
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1342 /*========================== DECODE VIDEO ============================*/
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1343
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1344 current_module="decode_video";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1345
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1346 //-------------------- Decode a frame: -----------------------
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1347 switch(has_video){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1348 case 3: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1349 // OpenDivX
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1350 unsigned int t=GetTimer();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1351 unsigned int t2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1352 DEC_FRAME dec_frame;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1353 char* start=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1354 int in_size=ds_get_packet(d_video,&start);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1355 if(in_size<0){ eof=1;break;}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1356 if(in_size>max_framesize) max_framesize=in_size;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1357 // let's decode
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1358 dec_frame.length = in_size;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1359 dec_frame.bitstream = start;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1360 //dec_frame.bmp = video_out;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1361 dec_frame.render_flag = 1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1362 decore(0x123, 0, &dec_frame, NULL);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1363 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1364
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1365 if(opendivx_src[0]){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1366 video_out->draw_slice(opendivx_src,opendivx_stride,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1367 movie_size_x,movie_size_y,0,0);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1368 opendivx_src[0]=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1369 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1370
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1371 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1372
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1373 ++num_frames;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1374 v_frame+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1375
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1376 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1377 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1378 case 2: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1379 HRESULT ret;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1380 char* start=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1381 unsigned int t=GetTimer();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1382 unsigned int t2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1383 float pts1=d_video->pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1384 int in_size=ds_get_packet(d_video,&start);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1385 float pts2=d_video->pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1386 if(in_size<0){ eof=1;break;}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1387 if(in_size>max_framesize) max_framesize=in_size;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1388
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1389 // printf("frame len = %5.4f\n",pts2-pts1);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1390
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1391 //if(in_size>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1392 avi_header.bih.biSizeImage = in_size;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1393 ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1394 // ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL),
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1395 &avi_header.bih, start,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1396 &avi_header.o_bih, avi_header.our_out_buffer);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1397 if(ret){ printf("Error decompressing frame, err=%d\n",ret);break; }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1398 //}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1399
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1400 t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1401 video_out->draw_frame((uint8_t **)&avi_header.our_out_buffer);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1402 t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1403
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1404 ++num_frames;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1405
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1406 if(file_format==DEMUXER_TYPE_ASF){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1407 float d=pts2-pts1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1408 if(d>0 && d<0.2) v_frame+=d;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1409 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1410 v_frame+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1411 //v_pts+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1412
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1413 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1414 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1415 case 1: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1416 #ifndef HAVE_CODECCTRL
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1417
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1418 int in_frame=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1419 videobuf_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1420 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1421 int i=sync_video_packet(d_video);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1422 if(in_frame){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1423 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1424 // send END OF FRAME code:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1425 #if 1
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1426 videobuffer[videobuf_len+0]=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1427 videobuffer[videobuf_len+1]=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1428 videobuffer[videobuf_len+2]=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1429 videobuffer[videobuf_len+3]=0xFF;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1430 videobuf_len+=4;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1431 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1432 if(!i) eof=1; // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1433 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1434 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1435 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1436 //if(i==0x100) in_frame=1; // picture startcode
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1437 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1438 else if(!i){ eof=1; break;} // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1439 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1440 if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1441 if(!read_video_packet(d_video)){ eof=1; break;} // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1442 //printf("read packet 0x%X, len=%d\n",i,videobuf_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1443 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1444
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1445 if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1446 //printf("--- SEND %d bytes\n",videobuf_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1447 if(grab_frames==1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1448 FILE *f=fopen("grab.mpg","ab");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1449 fwrite(videobuffer,videobuf_len-4,1,f);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1450 fclose(f);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1451 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1452 ++dbg_es_sent;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1453 //if(videobuf_len>4)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1454 //my_write(data_fifo,(char*) &videobuf_len,4);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1455
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1456 { int t=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1457 int x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1458 float l;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1459 t-=GetTimer();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1460 mpeg2_decode_data(video_out, videobuffer, videobuffer+videobuf_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1461 t+=GetTimer();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1462 //*** CMD=0 : Frame completed ***
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1463 //send_cmd(control_fifo2,0); // FRAME_COMPLETED command
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1464 x=frameratecode2framerate[picture->frame_rate_code]; //fps
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1465 ++dbg_es_rcvd;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1466 l=(100+picture->repeat_count)*0.01f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1467 num_frames+=l;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1468 picture->repeat_count=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1469 video_time_usage+=t*0.000001;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1470 if(x && !force_fps) default_fps=x*0.0001f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1471 if(!force_redraw){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1472 // increase video timers:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1473 v_frame+=l/default_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1474 v_pts+=l/default_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1475 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1476 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1477 //if(eof) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1478
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1479 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1480 while(1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1481 int x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1482 while(1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1483 x=-1; // paranoia
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1484 if(4==read(control_fifo,&x,4)) break; // status/command
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1485 usleep(5000); // do not eat 100% CPU (waiting for codec restart)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1486 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1487 if(x==0x3030303){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1488 //*** CMD=3030303 : Video packet requested ***
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1489 // read a single compressed frame:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1490 int in_frame=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1491 videobuf_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1492 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1493 int i=sync_video_packet(d_video);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1494 if(in_frame){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1495 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1496 // send END OF FRAME code:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1497 #if 1
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1498 videobuffer[videobuf_len+0]=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1499 videobuffer[videobuf_len+1]=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1500 videobuffer[videobuf_len+2]=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1501 videobuffer[videobuf_len+3]=0xFF;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1502 videobuf_len+=4;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1503 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1504 if(!i) eof=1; // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1505 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1506 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1507 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1508 //if(i==0x100) in_frame=1; // picture startcode
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1509 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1510 else if(!i){ eof=1; break;} // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1511 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1512 if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1513 if(!read_video_packet(d_video)){ eof=1; break;} // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1514 //printf("read packet 0x%X, len=%d\n",i,videobuf_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1515 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1516 if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1517 //printf("--- SEND %d bytes\n",videobuf_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1518 if(grab_frames==1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1519 FILE *f=fopen("grab.mpg","ab");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1520 fwrite(videobuffer,videobuf_len-4,1,f);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1521 fclose(f);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1522 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1523 ++dbg_es_sent;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1524 //if(videobuf_len>4)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1525 my_write(data_fifo,(char*) &videobuf_len,4);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1526 if(eof) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1527 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1528 if(x==0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1529 //*** CMD=0 : Frame completed ***
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1530 int l=100;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1531 int t=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1532 read(control_fifo,&x,4); // FPS
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1533 read(control_fifo,&l,4); // Length*100
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1534 read(control_fifo,&t,4); // Time*1000000
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1535 //printf("+++ FRAME COMPLETED fps=%d len=%d time=%d\n",x,l,t);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1536 ++dbg_es_rcvd;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1537 num_frames+=l/100.0f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1538 video_time_usage+=t*0.000001;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1539 if(x && !force_fps) default_fps=x*0.0001f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1540 if(!force_redraw){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1541 // increase video timers:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1542 v_frame+=l*0.01f/default_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1543 v_pts+=l*0.01f/default_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1544 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1545 break; // frame OK.
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1546 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1547 if(x==0x22222222){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1548 //*** CMD=22222222 : codec reset/restart ***
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1549 read(control_fifo,&codec_pid,4); // PID
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1550 printf("\nVideo codec started... (pid %d)\n",codec_pid);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1551 send_cmd(data_fifo,0x22222222); // send response (syncword)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1552 dbg_es_sent=dbg_es_rcvd=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1553 //printf(" [ReSync-VIDEO] \n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1554 while(1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1555 int id=sync_video_packet(d_video);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1556 if(id==0x100 || id>=0x1B0) break; // header chunk
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1557 if(!id || !skip_video_packet(d_video)){ eof=1; break;} // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1558 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1559 if(eof) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1560 max_pts_correction=0.2;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1561 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1562 printf("invalid cmd: 0x%X\n",x);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1563 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1564 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1565 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1566 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1567 } // switch
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1568 //------------------------ frame decoded. --------------------
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1569
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1570
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1571 /*========================== PLAY AUDIO ============================*/
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1572
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1573 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1574 int len=(old_vframe-a_frame)*(float)(MP3_samplerate*MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1575 len&=~15;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1576 if(len>a_buffer_len) len=a_buffer_len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1577
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1578 current_module="play_audio";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1579
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1580 // Play sound from the buffer:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1581
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1582 #ifdef USE_XMMP_AUDIO
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1583 pSound->Write( pSound, a_buffer, len );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1584 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1585 #ifdef SIMULATE_ALSA
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1586 fake_ALSA_write(audio_fd,a_buffer,len); // for testing purposes
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1587 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1588 write(audio_fd,a_buffer,len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1589 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1590 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1591
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1592 a_buffer_len-=len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1593 memcpy(a_buffer,&a_buffer[len],a_buffer_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1594
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1595 a_frame+=len/(float)(MP3_samplerate*MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1596 a_pts+=len/(float)(MP3_samplerate*MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1597 time_frame+=len/(float)(MP3_samplerate*MP3_channels*MP3_bps);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1598
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1599 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1600
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1601 /*========================== UPDATE TIMERS ============================*/
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1602
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1603 current_module="alsa_timer";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1604
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1605 if(alsa){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1606 // Use system timer for sync, not audio card/driver
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1607 time_frame-=GetRelativeTime();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1608 // printf("time_frame=%5.3f\n",time_frame);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1609 if(time_frame<0 || time_frame>0.1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1610 time_frame=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1611 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1612 // if(time_frame>0.01) usleep(1000000*(time_frame-0.01)); // sleeping
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1613 // if(time_frame>0.019) usleep(1000000*(time_frame-0.019)); // sleeping
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1614 // if(time_frame>0.001) usleep(1000000*(time_frame)); // sleeping
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1615 // if(time_frame>0.02) usleep(1000000*(time_frame)); // sleeping if >20ms
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1616 while(time_frame>0.0001){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1617 if(time_frame>0.021) usleep(1000000*(time_frame-0.020)); else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1618 if(time_frame>0.011) usleep(0);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1619 // usleep(1000);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1620 time_frame-=GetRelativeTime();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1621 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1622 // printf("%8.3f \n",time_frame*1000);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1623 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1624
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1625 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1626
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1627 current_module="flip_page";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1628 video_out->flip_page();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1629
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1630 if(eof) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1631 if(force_redraw) --force_redraw;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1632
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1633 // 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);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1634 // fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1635
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1636 current_module="PTS_correction";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1637
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1638 #if 1
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1639 /*================ A-V TIMESTAMP CORRECTION: =========================*/
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1640 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1641 if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1642 // a_pts=(float)ds_tell(d_audio)/((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec-(buffer_delay+audio_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1643 a_pts=(float)ds_tell(d_audio)/((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec-(buffer_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1644 delay_corrected=1; // hack
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1645 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1646 if(d_audio->pts){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1647 // printf("\n=== APTS a_pts=%5.3f v_pts=%5.3f === \n",d_audio->pts,d_video->pts);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1648 #if 1
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1649 if(!delay_corrected){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1650 float x=d_audio->pts-d_video->pts-(buffer_delay+audio_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1651 float y=-(buffer_delay+audio_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1652 printf("Initial PTS delay: %5.3f sec (calculated: %5.3f)\n",x,y);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1653 audio_delay+=x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1654 //a_pts-=x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1655 delay_corrected=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1656 printf("v: audio_delay=%5.3f buffer_delay=%5.3f a.pts=%5.3f v.pts=%5.3f\n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1657 audio_delay,buffer_delay,d_audio->pts,d_video->pts);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1658 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1659 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1660 a_pts=d_audio->pts-(buffer_delay+audio_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1661 d_audio->pts=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1662 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1663 if(d_video->pts) v_pts=d_video->pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1664 if(frame_corr_num==5){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1665 float x=(frame_correction/5.0f);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1666 if(!delay_corrected){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1667 #if 0
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1668 printf("Initial PTS delay: %5.3f sec\n",x);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1669 delay_corrected=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1670 audio_delay+=x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1671 a_pts-=x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1672 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1673 } else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1674 {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1675 printf("A:%6.1f V:%6.1f A-V:%7.3f",a_pts,v_pts,x);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1676 x*=0.03f;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1677 if(x<-max_pts_correction) x=-max_pts_correction; else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1678 if(x> max_pts_correction) x= max_pts_correction;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1679 max_pts_correction=default_max_pts_correction;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1680 a_frame+=x; c_total+=x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1681 #if 0
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1682 printf(" ct:%7.3f a=%d v=%d \r",c_total,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1683 d_audio->pos,d_video->pos);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1684 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1685 printf(" ct:%7.3f %3d %2d%% %2d%% %3.1f%% %d \r",c_total,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1686 (int)num_frames,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1687 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1688 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1689 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1690 dbg_es_sent-dbg_es_rcvd
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1691 );
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1692 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1693 fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1694 // printf("\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1695 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1696 //force_fps+=1*force_fps*x;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1697 // printf(" ct:%7.3f fps:%5.2f nf:%2.1f/%d t:%d.%03d\r",c_total,default_fps,num_frames,real_num_frames,codec_time_usage_sec,codec_time_usage/1000);fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1698 frame_corr_num=0; frame_correction=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1699 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1700 if(frame_corr_num>=0) frame_correction+=a_pts-v_pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1701 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1702 // No audio:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1703 if(d_video->pts) v_pts=d_video->pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1704 if(frame_corr_num==5){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1705 // printf("A: --- V:%6.1f \r",v_pts);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1706 printf("V:%6.1f %3d %2d%% %2d%% %3.1f%% %d \r",v_pts,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1707 (int)num_frames,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1708 (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1709 (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1710 (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1711 dbg_es_sent-dbg_es_rcvd);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1712
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1713 fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1714 frame_corr_num=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1715 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1716 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1717 ++frame_corr_num;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1718 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1719
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1720 current_module=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1721
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1722 // } // while(v_frame<a_frame || force_redraw)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1723
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1724
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1725 //================= Keyboard events, SEEKing ====================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1726
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1727 { int rel_seek_secs=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1728 int c;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1729 while(
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1730 #ifdef HAVE_LIRC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1731 (c=lirc_mp_getinput())>0 ||
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1732 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1733 (c=getch2(0))>0 || (c=mplayer_get_key())>0) switch(c){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1734 // seek 10 sec
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1735 case KEY_RIGHT:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1736 rel_seek_secs+=10;break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1737 case KEY_LEFT:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1738 rel_seek_secs-=10;break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1739 // seek 1 min
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1740 case KEY_UP:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1741 rel_seek_secs+=60;break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1742 case KEY_DOWN:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1743 rel_seek_secs-=60;break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1744 // delay correction:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1745 case '+':
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1746 buffer_delay+=0.1; // increase audio buffer size
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1747 a_frame-=0.1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1748 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1749 case '-':
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1750 buffer_delay-=0.1; // decrease audio buffer size
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1751 a_frame+=0.1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1752 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1753 // quit
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1754 case KEY_ESC: // ESC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1755 case KEY_ENTER: // ESC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1756 case 'q': exit_player("Quit");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1757 case 'g': grab_frames=2;break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1758 // restart codec
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1759 #ifdef HAVE_CODECCTRL
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1760 case 'k': kill(codec_pid,SIGKILL);break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1761 // case 'k': kill(child_pid,SIGKILL);break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1762 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1763 // pause
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1764 case 'p':
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1765 case ' ':
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1766 printf("\n------ PAUSED -------\r");fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1767 while(
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1768 #ifdef HAVE_LIRC
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1769 lirc_mp_getinput()<=0 &&
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1770 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1771 getch2(20)<=0 && mplayer_get_key()<=0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1772 video_out->check_events();
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1773 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1774 a_pts+=-buffer_delay;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1775 a_frame+=-buffer_delay;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1776 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1777 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1778 if(rel_seek_secs)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1779 if(file_format==DEMUXER_TYPE_AVI && avi_header.idx_size<=0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1780 printf("Can't seek in raw .AVI streams! (index required) \n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1781 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1782 int skip_audio_bytes=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1783 float skip_audio_secs=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1784
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1785 // clear demux buffers:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1786 if(has_audio) ds_free_packs(d_audio);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1787 ds_free_packs(d_video);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1788
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1789 // printf("a_buffer_len=%d \n",a_buffer_len);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1790 a_buffer_len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1791
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1792 switch(file_format){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1793
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1794 case DEMUXER_TYPE_AVI: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1795 //================= seek in AVI ==========================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1796 int rel_seek_frames=rel_seek_secs*default_fps;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1797 int curr_audio_pos=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1798 int audio_chunk_pos=-1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1799 int video_chunk_pos=d_video->pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1800
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1801 skip_video_frames=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1802
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1803 // SEEK streams
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1804 // if(d_video->pts) avi_video_pts=d_video->pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1805 avi_audio_pts=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1806 d_video->pts=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1807 d_audio->pts=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1808
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1809 // find video chunk pos:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1810 if(rel_seek_frames>0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1811 // seek forward
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1812 while(video_chunk_pos<avi_header.idx_size){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1813 int id=avi_header.idx[video_chunk_pos].ckid;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1814 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1815 if(avi_stream_id(id)==d_video->id){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1816 if((--rel_seek_frames)<0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1817 v_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1818 ++skip_audio_bytes;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1819 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1820 ++video_chunk_pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1821 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1822 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1823 // seek backward
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1824 while(video_chunk_pos>=0){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1825 int id=avi_header.idx[video_chunk_pos].ckid;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1826 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1827 if(avi_stream_id(id)==d_video->id){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1828 if((++rel_seek_frames)>0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1829 v_pts-=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1830 --skip_audio_bytes;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1831 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1832 --video_chunk_pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1833 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1834 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1835 avi_header.idx_pos_a=avi_header.idx_pos_v=
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1836 avi_header.idx_pos=video_chunk_pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1837 // printf("%d frames skipped\n",skip_audio_bytes);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1838
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1839 #if 1
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1840 // re-calc video pts:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1841 avi_video_pts=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1842 for(i=0;i<video_chunk_pos;i++){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1843 int id=avi_header.idx[i].ckid;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1844 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1845 if(avi_stream_id(id)==d_video->id){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1846 avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1847 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1848 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1849 //printf("v-pts recalc! %5.3f -> %5.3f \n",v_pts,avi_video_pts);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1850 v_pts=avi_video_pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1851 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1852 avi_video_pts=v_pts;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1853 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1854 a_pts=avi_video_pts-(buffer_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1855 //a_pts=v_pts; //-(buffer_delay+audio_delay);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1856
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1857 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1858 int i;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1859 int apos=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1860 int last=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1861 int len=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1862
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1863 // calc new audio position in audio stream: (using avg.bps value)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1864 curr_audio_pos=(avi_video_pts) * ((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1865 if(curr_audio_pos<0)curr_audio_pos=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1866 #if 1
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1867 curr_audio_pos&=~15; // requires for PCM formats!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1868 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1869 curr_audio_pos/=((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1870 curr_audio_pos*=((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1871 avi_header.audio_seekable=1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1872 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1873
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1874 // find audio chunk pos:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1875 for(i=0;i<video_chunk_pos;i++){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1876 int id=avi_header.idx[i].ckid;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1877 //if(TWOCCFromFOURCC(id)==cktypeWAVEbytes){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1878 if(avi_stream_id(id)==d_audio->id){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1879 int aid=StreamFromFOURCC(id);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1880 if(d_audio->id==aid || d_audio->id==-1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1881 len=avi_header.idx[i].dwChunkLength;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1882 last=i;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1883 if(apos<=curr_audio_pos && curr_audio_pos<(apos+len)){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1884 if(verbose)printf("break;\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1885 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1886 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1887 apos+=len;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1888 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1889 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1890 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1891 if(verbose)printf("XXX i=%d last=%d apos=%d curr_audio_pos=%d \n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1892 i,last,apos,curr_audio_pos);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1893 // audio_chunk_pos=last; // maybe wrong (if not break; )
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1894 audio_chunk_pos=i; // maybe wrong (if not break; )
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1895 skip_audio_bytes=curr_audio_pos-apos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1896
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1897 // update stream position:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1898 d_audio->pos=audio_chunk_pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1899 d_audio->dpos=apos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1900 avi_header.idx_pos_a=avi_header.idx_pos_v=
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1901 avi_header.idx_pos=audio_chunk_pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1902
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1903 if(!avi_header.audio_seekable){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1904 #if 0
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1905 // curr_audio_pos=apos; // selected audio codec can't seek in chunk
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1906 skip_audio_secs=(float)skip_audio_bytes/(float)((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1907 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",skip_audio_bytes,skip_audio_secs);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1908 skip_audio_bytes=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1909 #else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1910 int d=skip_audio_bytes % ((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1911 skip_audio_bytes-=d;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1912 // curr_audio_pos-=d;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1913 skip_audio_secs=(float)d/(float)((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1914 //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",d,skip_audio_secs);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1915 #endif
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1916 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1917 // now: audio_chunk_pos=pos in index
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1918 // skip_audio_bytes=bytes to skip from that chunk
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1919 // skip_audio_secs=time to play audio before video (if can't skip)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1920
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1921 // calc skip_video_frames & adjust video pts counter:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1922 // i=last;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1923 i=avi_header.idx_pos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1924 while(i<video_chunk_pos){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1925 int id=avi_header.idx[i].ckid;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1926 // if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1927 if(avi_stream_id(id)==d_video->id){ // video frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1928 ++skip_video_frames;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1929 // requires for correct audio pts calculation (demuxer):
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1930 avi_video_pts-=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1931 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1932 ++i;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1933 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1934
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1935 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1936
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1937 if(verbose) printf("SEEK: idx=%d (a:%d v:%d) v.skip=%d a.skip=%d/%4.3f \n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1938 avi_header.idx_pos,audio_chunk_pos,video_chunk_pos,
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1939 skip_video_frames,skip_audio_bytes,skip_audio_secs);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1940
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1941 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1942 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1943
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1944 case DEMUXER_TYPE_ASF: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1945 //================= seek in ASF ==========================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1946 float p_rate=10; // packets / sec
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1947 int rel_seek_packs=rel_seek_secs*p_rate;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1948 int rel_seek_bytes=rel_seek_packs*fileh.packetsize;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1949 int newpos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1950 //printf("ASF: packs: %d duration: %d \n",(int)fileh.packets,*((int*)&fileh.duration));
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1951 // printf("ASF_seek: %d secs -> %d packs -> %d bytes \n",
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1952 // rel_seek_secs,rel_seek_packs,rel_seek_bytes);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1953 newpos=demuxer->filepos+rel_seek_bytes;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1954 if(newpos<0) newpos=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1955 stream_seek(demuxer->stream,newpos);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1956 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1957 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1958
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1959 case DEMUXER_TYPE_MPEG_ES:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1960 case DEMUXER_TYPE_MPEG_PS: {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1961 //================= seek in MPEG ==========================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1962 int newpos;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1963 if(picture->bitrate==0x3FFFF) // unspecified?
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1964 newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1965 else
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1966 newpos=demuxer->filepos+(picture->bitrate*1000/16)*rel_seek_secs;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1967 // picture->bitrate=2324*75*8; // standard VCD bitrate (75 sectors / sec)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1968
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1969 if(newpos<seek_to_byte) newpos=seek_to_byte;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1970 stream_seek(demuxer->stream,newpos);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1971 // re-sync video:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1972 videobuf_code_len=0; // reset ES stream buffer
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1973 while(1){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1974 int i=sync_video_packet(d_video);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1975 if(i==0x1B3 || i==0x1B8) break; // found it!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1976 if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1977 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1978 // re-sync audio: (must read to get actual audio PTS)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1979 // if(has_audio) ds_fill_buffer(d_audio);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1980 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1981 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1982
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1983 } // switch(file_format)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1984
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1985 //====================== re-sync audio: =====================
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1986 if(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1987
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1988 if(skip_audio_bytes){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1989 demux_read_data(d_audio,NULL,skip_audio_bytes);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1990 d_audio->pts=0; // PTS is outdated because of the raw data skipping
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1991 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1992
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1993 current_module="resync_audio";
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1994
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1995 switch(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1996 case 1:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1997 MP3_DecodeFrame(NULL,-2); // resync
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1998 MP3_DecodeFrame(NULL,-2); // resync
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
1999 MP3_DecodeFrame(NULL,-2); // resync
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2000 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2001 case 3:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2002 ac3_bitstream_reset(); // reset AC3 bitstream buffer
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2003 // if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);}
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2004 ac3_frame=ac3_decode_frame(); // resync
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2005 // if(verbose) printf(" OK!\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2006 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2007 case 4:
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2008 a_in_buffer_len=0; // reset ACM audio buffer
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2009 break;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2010 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2011
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2012 // re-sync PTS (MPEG-PS only!!!)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2013 if(file_format==DEMUXER_TYPE_MPEG_PS)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2014 if(d_video->pts && d_audio->pts){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2015 if (d_video->pts < d_audio->pts){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2016
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2017 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2018 while(d_video->pts > d_audio->pts){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2019 switch(has_audio){
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2020 case 1: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2021 case 3: ac3_frame=ac3_decode_frame();break; // skip AC3 frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2022 default: ds_fill_buffer(d_audio); // skip PCM frame
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2023 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2024 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2025 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2026 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2027
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2028 current_module=NULL;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2029
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2030 c_total=0; // kell ez?
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2031 printf("A:%6.1f V:%6.1f A-V:%7.3f",d_audio->pts,d_video->pts,0.0f);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2032 printf(" ct:%7.3f \r",c_total);fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2033 } else {
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2034 printf("A: --- V:%6.1f \r",d_video->pts);fflush(stdout);
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2035 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2036
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2037 max_pts_correction=0.1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2038 frame_corr_num=-5; frame_correction=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2039 force_redraw=5;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2040 a_frame=-buffer_delay-skip_audio_secs;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2041 // a_frame=-audio_delay-buffer_delay-skip_audio_secs;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2042 v_frame=0; // !!!!!!
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2043 audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2044 // num_frames=real_num_frames=0;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2045 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2046 } // keyboard event handler
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2047
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2048
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2049
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2050 } // while(!eof)
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2051
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2052 //printf("\nEnd of file.\n");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2053 exit_player("End of file");
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2054 }
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2055 return 1;
7c67c52142ed added mplayerHQ
arpi_esp
parents:
diff changeset
2056 }