Mercurial > mplayer.hg
annotate dll_init.c @ 1904:c651cdefdf73
Fix broken memalign detect.
author | atmos4 |
---|---|
date | Mon, 17 Sep 2001 16:18:18 +0000 |
parents | a90e0d8eba7c |
children | 5216f108cb4f |
rev | line source |
---|---|
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
1 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
2 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
3 #include <stdlib.h> |
1430 | 4 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
5 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
6 #include "config.h" |
1567 | 7 #include "mp_msg.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
8 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
9 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
10 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
11 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
12 #include "loader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
13 //#include "wine/mmreg.h" |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
14 #include "wine/vfw.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
15 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
16 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
17 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
18 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
19 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
20 #include "libvo/img_format.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
21 #include "linux/shmem.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
22 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
23 extern char* win32_codec_name; // must be set before calling DrvOpen() !!! |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
24 |
1 | 25 // ACM audio and VfW video codecs initialization |
26 // based on the avifile library [http://divx.euro.ru] | |
27 | |
296 | 28 int init_acm_audio_codec(sh_audio_t *sh_audio){ |
1 | 29 HRESULT ret; |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
30 WAVEFORMATEX *in_fmt=sh_audio->wf; |
1 | 31 unsigned long srcsize=0; |
32 | |
1567 | 33 mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (ACM) AUDIO Codec init =======\n"); |
1 | 34 |
291 | 35 sh_audio->srcstream=NULL; |
1 | 36 |
291 | 37 sh_audio->o_wf.nChannels=in_fmt->nChannels; |
38 sh_audio->o_wf.nSamplesPerSec=in_fmt->nSamplesPerSec; | |
39 sh_audio->o_wf.nAvgBytesPerSec=2*sh_audio->o_wf.nSamplesPerSec*sh_audio->o_wf.nChannels; | |
40 sh_audio->o_wf.wFormatTag=WAVE_FORMAT_PCM; | |
41 sh_audio->o_wf.nBlockAlign=2*in_fmt->nChannels; | |
42 sh_audio->o_wf.wBitsPerSample=16; | |
43 sh_audio->o_wf.cbSize=0; | |
1 | 44 |
303 | 45 win32_codec_name = sh_audio->codec->dll; |
291 | 46 ret=acmStreamOpen(&sh_audio->srcstream,(HACMDRIVER)NULL, |
47 in_fmt,&sh_audio->o_wf, | |
1 | 48 NULL,0,0,0); |
49 if(ret){ | |
50 if(ret==ACMERR_NOTPOSSIBLE) | |
1567 | 51 mp_msg(MSGT_WIN32,MSGL_ERR,"ACM_Decoder: Unappropriate audio format\n"); |
1 | 52 else |
1567 | 53 mp_msg(MSGT_WIN32,MSGL_ERR,"ACM_Decoder: acmStreamOpen error %d", (int)ret); |
291 | 54 sh_audio->srcstream=NULL; |
1 | 55 return 0; |
56 } | |
1567 | 57 mp_msg(MSGT_WIN32,MSGL_V,"Audio codec opened OK! ;-)\n"); |
1 | 58 |
631 | 59 acmStreamSize(sh_audio->srcstream, in_fmt->nBlockAlign, &srcsize, ACM_STREAMSIZEF_SOURCE); |
758 | 60 //if(verbose) printf("Audio ACM output buffer min. size: %ld (reported by codec)\n",srcsize); |
746 | 61 srcsize*=2; |
758 | 62 //if(srcsize<MAX_OUTBURST) srcsize=MAX_OUTBURST; |
63 if(!srcsize){ | |
1567 | 64 mp_msg(MSGT_WIN32,MSGL_WARN,"Warning! ACM codec reports srcsize=0\n"); |
758 | 65 srcsize=16384; |
66 } | |
67 // limit srcsize to 4-16kb | |
68 //while(srcsize && srcsize<4096) srcsize*=2; | |
69 //while(srcsize>16384) srcsize/=2; | |
291 | 70 sh_audio->audio_out_minsize=srcsize; // audio output min. size |
1567 | 71 mp_msg(MSGT_WIN32,MSGL_V,"Audio ACM output buffer min. size: %ld\n",srcsize); |
1 | 72 |
746 | 73 acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); |
291 | 74 sh_audio->audio_in_minsize=srcsize; // audio input min. size |
1567 | 75 mp_msg(MSGT_WIN32,MSGL_V,"Audio ACM input buffer min. size: %ld\n",srcsize); |
631 | 76 |
77 if(srcsize<in_fmt->nBlockAlign) srcsize=in_fmt->nBlockAlign; | |
1 | 78 |
631 | 79 sh_audio->a_in_buffer_size=2*sh_audio->audio_in_minsize; |
291 | 80 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); |
81 sh_audio->a_in_buffer_len=0; | |
92 | 82 |
1 | 83 return 1; |
84 } | |
85 | |
758 | 86 int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen){ |
92 | 87 ACMSTREAMHEADER ash; |
88 HRESULT hr; | |
89 DWORD srcsize=0; | |
758 | 90 DWORD len=minlen; |
291 | 91 acmStreamSize(sh_audio->srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION); |
1567 | 92 mp_msg(MSGT_WIN32,MSGL_DBG3,"acm says: srcsize=%ld (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,len); |
758 | 93 |
94 if(srcsize<sh_audio->wf->nBlockAlign){ | |
95 srcsize=sh_audio->wf->nBlockAlign; | |
96 acmStreamSize(sh_audio->srcstream, srcsize, &len, ACM_STREAMSIZEF_SOURCE); | |
97 if(len>maxlen) len=maxlen; | |
98 } | |
99 | |
291 | 100 // if(srcsize==0) srcsize=((WAVEFORMATEX *)&sh_audio->o_wf_ext)->nBlockAlign; |
101 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! | |
102 if(sh_audio->a_in_buffer_len<srcsize){ | |
103 sh_audio->a_in_buffer_len+= | |
104 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
105 srcsize-sh_audio->a_in_buffer_len); | |
92 | 106 } |
1567 | 107 mp_msg(MSGT_WIN32,MSGL_DBG3,"acm convert %d -> %d bytes\n",sh_audio->a_in_buffer_len,len); |
92 | 108 memset(&ash, 0, sizeof(ash)); |
109 ash.cbStruct=sizeof(ash); | |
110 ash.fdwStatus=0; | |
111 ash.dwUser=0; | |
291 | 112 ash.pbSrc=sh_audio->a_in_buffer; |
113 ash.cbSrcLength=sh_audio->a_in_buffer_len; | |
92 | 114 ash.pbDst=a_buffer; |
115 ash.cbDstLength=len; | |
291 | 116 hr=acmStreamPrepareHeader(sh_audio->srcstream,&ash,0); |
92 | 117 if(hr){ |
1567 | 118 mp_msg(MSGT_WIN32,MSGL_V,"ACM_Decoder: acmStreamPrepareHeader error %d\n",(int)hr); |
92 | 119 return -1; |
120 } | |
291 | 121 hr=acmStreamConvert(sh_audio->srcstream,&ash,0); |
92 | 122 if(hr){ |
1567 | 123 mp_msg(MSGT_WIN32,MSGL_DBG2,"ACM_Decoder: acmStreamConvert error %d\n",(int)hr); |
631 | 124 |
125 // return -1; | |
92 | 126 } |
1407 | 127 if(verbose>1) |
1567 | 128 mp_msg(MSGT_WIN32,MSGL_DBG2,"acm converted %d -> %d\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed); |
291 | 129 if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){ |
130 sh_audio->a_in_buffer_len=0; | |
92 | 131 } else { |
291 | 132 sh_audio->a_in_buffer_len-=ash.cbSrcLengthUsed; |
133 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[ash.cbSrcLengthUsed],sh_audio->a_in_buffer_len); | |
92 | 134 } |
135 len=ash.cbDstLengthUsed; | |
291 | 136 hr=acmStreamUnprepareHeader(sh_audio->srcstream,&ash,0); |
92 | 137 if(hr){ |
1567 | 138 mp_msg(MSGT_WIN32,MSGL_V,"ACM_Decoder: acmStreamUnprepareHeader error %d\n",(int)hr); |
92 | 139 } |
140 return len; | |
141 } | |
142 | |
143 | |
1 | 144 |
1297 | 145 int init_video_codec(sh_video_t *sh_video,int ex){ |
1 | 146 HRESULT ret; |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
147 int yuv=0; |
303 | 148 unsigned int outfmt=sh_video->codec->outfmt[sh_video->outfmtidx]; |
1 | 149 |
1567 | 150 mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Codec init =======\n"); |
1 | 151 |
291 | 152 memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); |
153 sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER); | |
1 | 154 |
303 | 155 win32_codec_name = sh_video->codec->dll; |
746 | 156 // sh_video->hic = ICOpen( 0x63646976, sh_video->bih->biCompression, ICMODE_FASTDECOMPRESS); |
157 sh_video->hic = ICOpen( 0x63646976, sh_video->bih->biCompression, ICMODE_DECOMPRESS); | |
291 | 158 if(!sh_video->hic){ |
1567 | 159 mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n"); |
1 | 160 return 0; |
161 } | |
162 | |
291 | 163 // sh_video->bih.biBitCount=32; |
1 | 164 |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
165 ret = ICDecompressGetFormat(sh_video->hic, sh_video->bih, &sh_video->o_bih); |
1 | 166 if(ret){ |
1567 | 167 mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressGetFormat failed: Error %d\n", (int)ret); |
1 | 168 return 0; |
169 } | |
1567 | 170 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormat OK\n"); |
1 | 171 |
172 // printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY); | |
173 | |
291 | 174 // sh_video->o_bih.biWidth=sh_video->bih.biWidth; |
175 // sh_video->o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y'); | |
176 // ret=ICDecompressGetFormatSize(sh_video->hic,&sh_video->o_bih); | |
177 // sh_video->o_bih.biCompression = 3; //0x32315659; | |
178 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | |
179 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | |
180 // sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); | |
181 // sh_video->o_bih.biPlanes=3; | |
182 // sh_video->o_bih.biBitCount=16; | |
1 | 183 |
713 | 184 #if 0 |
185 // workaround for pegasus MJPEG: | |
186 if(!sh_video->o_bih.biWidth) sh_video->o_bih.biWidth=sh_video->bih->biWidth; | |
187 if(!sh_video->o_bih.biHeight) sh_video->o_bih.biHeight=sh_video->bih->biHeight; | |
188 if(!sh_video->o_bih.biPlanes) sh_video->o_bih.biPlanes=sh_video->bih->biPlanes; | |
189 #endif | |
408 | 190 |
191 switch (outfmt) { | |
192 | |
193 /* planar format */ | |
194 case IMGFMT_YV12: | |
195 case IMGFMT_I420: | |
196 case IMGFMT_IYUV: | |
197 sh_video->o_bih.biBitCount=12; | |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
198 yuv=1; |
467 | 199 break; |
1 | 200 |
408 | 201 /* packed format */ |
202 case IMGFMT_YUY2: | |
203 case IMGFMT_UYVY: | |
204 case IMGFMT_YVYU: | |
205 sh_video->o_bih.biBitCount=16; | |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
206 yuv=1; |
408 | 207 break; |
303 | 208 |
408 | 209 /* rgb/bgr format */ |
210 case IMGFMT_RGB8: | |
211 case IMGFMT_BGR8: | |
212 sh_video->o_bih.biBitCount=8; | |
213 break; | |
1 | 214 |
408 | 215 case IMGFMT_RGB15: |
216 case IMGFMT_RGB16: | |
217 case IMGFMT_BGR15: | |
218 case IMGFMT_BGR16: | |
219 sh_video->o_bih.biBitCount=16; | |
220 break; | |
221 | |
222 case IMGFMT_RGB24: | |
223 case IMGFMT_BGR24: | |
224 sh_video->o_bih.biBitCount=24; | |
225 break; | |
226 | |
227 case IMGFMT_RGB32: | |
228 case IMGFMT_BGR32: | |
229 sh_video->o_bih.biBitCount=32; | |
230 break; | |
1 | 231 |
408 | 232 default: |
1567 | 233 mp_msg(MSGT_WIN32,MSGL_ERR,"unsupported image format: 0x%x\n", outfmt); |
408 | 234 return 0; |
235 } | |
236 | |
237 sh_video->o_bih.biSizeImage = sh_video->o_bih.biWidth * sh_video->o_bih.biHeight * (sh_video->o_bih.biBitCount/8); | |
713 | 238 |
408 | 239 if(!(sh_video->codec->outflags[sh_video->outfmtidx]&CODECS_FLAG_FLIP)) { |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
240 sh_video->o_bih.biHeight=-sh_video->bih->biHeight; // flip image! |
408 | 241 } |
1 | 242 |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
243 if(yuv && !(sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK)) |
408 | 244 sh_video->o_bih.biCompression = outfmt; |
759 | 245 else |
246 sh_video->o_bih.biCompression = 0; | |
1 | 247 |
248 if(verbose) { | |
249 printf("Starting decompression, format:\n"); | |
603 | 250 printf(" biSize %ld\n", sh_video->bih->biSize); |
251 printf(" biWidth %ld\n", sh_video->bih->biWidth); | |
252 printf(" biHeight %ld\n", sh_video->bih->biHeight); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
253 printf(" biPlanes %d\n", sh_video->bih->biPlanes); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
254 printf(" biBitCount %d\n", sh_video->bih->biBitCount); |
603 | 255 printf(" biCompression 0x%lx ('%.4s')\n", sh_video->bih->biCompression, (char *)&sh_video->bih->biCompression); |
256 printf(" biSizeImage %ld\n", sh_video->bih->biSizeImage); | |
1 | 257 printf("Dest fmt:\n"); |
603 | 258 printf(" biSize %ld\n", sh_video->o_bih.biSize); |
259 printf(" biWidth %ld\n", sh_video->o_bih.biWidth); | |
260 printf(" biHeight %ld\n", sh_video->o_bih.biHeight); | |
291 | 261 printf(" biPlanes %d\n", sh_video->o_bih.biPlanes); |
262 printf(" biBitCount %d\n", sh_video->o_bih.biBitCount); | |
603 | 263 printf(" biCompression 0x%lx ('%.4s')\n", sh_video->o_bih.biCompression, (char *)&sh_video->o_bih.biCompression); |
264 printf(" biSizeImage %ld\n", sh_video->o_bih.biSizeImage); | |
1 | 265 } |
266 | |
1297 | 267 ret = ex ? |
268 ICDecompressQueryEx(sh_video->hic, sh_video->bih, &sh_video->o_bih) : | |
269 ICDecompressQuery(sh_video->hic, sh_video->bih, &sh_video->o_bih); | |
1 | 270 if(ret){ |
1567 | 271 mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressQuery failed: Error %d\n", (int)ret); |
1 | 272 return 0; |
273 } | |
1567 | 274 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressQuery OK\n"); |
1 | 275 |
1297 | 276 ret = ex ? |
277 ICDecompressBeginEx(sh_video->hic, sh_video->bih, &sh_video->o_bih) : | |
278 ICDecompressBegin(sh_video->hic, sh_video->bih, &sh_video->o_bih); | |
1 | 279 if(ret){ |
1567 | 280 mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressBegin failed: Error %d\n", (int)ret); |
1 | 281 return 0; |
282 } | |
283 | |
1653 | 284 sh_video->our_out_buffer = memalign(64,sh_video->o_bih.biSizeImage); |
291 | 285 if(!sh_video->our_out_buffer){ |
1567 | 286 mp_msg(MSGT_WIN32,MSGL_ERR,"not enough memory for decoded picture buffer (%ld bytes)\n", sh_video->o_bih.biSizeImage); |
1 | 287 return 0; |
288 } | |
289 | |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
290 if(yuv && sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK) |
469 | 291 sh_video->o_bih.biCompression = outfmt; |
1 | 292 |
293 // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!! | |
294 | |
1567 | 295 mp_msg(MSGT_WIN32,MSGL_V,"VIDEO CODEC Init OK!!! ;-)\n"); |
1 | 296 return 1; |
297 } |