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