annotate mplayer.c @ 101:7fe6855f19cd

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