annotate mplayer.c @ 54:8ff005e84a97

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