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