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