Mercurial > mplayer.hg
annotate dll_init.c @ 488:108be5ee3b1a
Thanx to Arpi, There is no more YUY2 bug.
author | se7encode |
---|---|
date | Tue, 17 Apr 2001 19:05:59 +0000 |
parents | 434889ca2340 |
children | 2bb59b7c748a |
rev | line source |
---|---|
1 | 1 // ACM audio and VfW video codecs initialization |
2 // based on the avifile library [http://divx.euro.ru] | |
3 | |
296 | 4 int init_acm_audio_codec(sh_audio_t *sh_audio){ |
1 | 5 HRESULT ret; |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
6 WAVEFORMATEX *in_fmt=sh_audio->wf; |
1 | 7 unsigned long srcsize=0; |
8 | |
9 if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n"); | |
10 | |
291 | 11 sh_audio->srcstream=NULL; |
1 | 12 |
13 // if(in_fmt->nSamplesPerSec==0){ printf("Bad WAVE header!\n");exit(1); } | |
14 // MSACM_RegisterAllDrivers(); | |
15 | |
291 | 16 sh_audio->o_wf.nChannels=in_fmt->nChannels; |
17 sh_audio->o_wf.nSamplesPerSec=in_fmt->nSamplesPerSec; | |
18 sh_audio->o_wf.nAvgBytesPerSec=2*sh_audio->o_wf.nSamplesPerSec*sh_audio->o_wf.nChannels; | |
19 sh_audio->o_wf.wFormatTag=WAVE_FORMAT_PCM; | |
20 sh_audio->o_wf.nBlockAlign=2*in_fmt->nChannels; | |
21 sh_audio->o_wf.wBitsPerSample=16; | |
22 sh_audio->o_wf.cbSize=0; | |
1 | 23 |
303 | 24 win32_codec_name = sh_audio->codec->dll; |
291 | 25 ret=acmStreamOpen(&sh_audio->srcstream,(HACMDRIVER)NULL, |
26 in_fmt,&sh_audio->o_wf, | |
1 | 27 NULL,0,0,0); |
28 if(ret){ | |
29 if(ret==ACMERR_NOTPOSSIBLE) | |
30 printf("ACM_Decoder: Unappropriate audio format\n"); | |
31 else | |
32 printf("ACM_Decoder: acmStreamOpen error %d", ret); | |
291 | 33 sh_audio->srcstream=NULL; |
1 | 34 return 0; |
35 } | |
36 if(verbose) printf("Audio codec opened OK! ;-)\n"); | |
37 | |
38 srcsize=in_fmt->nBlockAlign; | |
291 | 39 acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE); |
1 | 40 if(srcsize<OUTBURST) srcsize=OUTBURST; |
291 | 41 sh_audio->audio_out_minsize=srcsize; // audio output min. size |
1 | 42 if(verbose) printf("Audio ACM output buffer min. size: %d\n",srcsize); |
43 | |
291 | 44 acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); |
45 sh_audio->audio_in_minsize=srcsize; // audio input min. size | |
1 | 46 if(verbose) printf("Audio ACM input buffer min. size: %d\n",srcsize); |
47 | |
291 | 48 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; |
49 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
50 sh_audio->a_in_buffer_len=0; | |
92 | 51 |
1 | 52 return 1; |
53 } | |
54 | |
291 | 55 int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len){ |
92 | 56 ACMSTREAMHEADER ash; |
57 HRESULT hr; | |
58 DWORD srcsize=0; | |
291 | 59 acmStreamSize(sh_audio->srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION); |
60 if(verbose>=3)printf("acm says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,len); | |
61 // if(srcsize==0) srcsize=((WAVEFORMATEX *)&sh_audio->o_wf_ext)->nBlockAlign; | |
62 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! | |
63 if(sh_audio->a_in_buffer_len<srcsize){ | |
64 sh_audio->a_in_buffer_len+= | |
65 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
66 srcsize-sh_audio->a_in_buffer_len); | |
92 | 67 } |
68 memset(&ash, 0, sizeof(ash)); | |
69 ash.cbStruct=sizeof(ash); | |
70 ash.fdwStatus=0; | |
71 ash.dwUser=0; | |
291 | 72 ash.pbSrc=sh_audio->a_in_buffer; |
73 ash.cbSrcLength=sh_audio->a_in_buffer_len; | |
92 | 74 ash.pbDst=a_buffer; |
75 ash.cbDstLength=len; | |
291 | 76 hr=acmStreamPrepareHeader(sh_audio->srcstream,&ash,0); |
92 | 77 if(hr){ |
78 printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",hr); | |
79 return -1; | |
80 } | |
291 | 81 hr=acmStreamConvert(sh_audio->srcstream,&ash,0); |
92 | 82 if(hr){ |
83 printf("ACM_Decoder: acmStreamConvert error %d\n",hr); | |
84 return -1; | |
85 } | |
86 //printf("ACM convert %d -> %d (buf=%d)\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed,a_in_buffer_len); | |
291 | 87 if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){ |
88 sh_audio->a_in_buffer_len=0; | |
92 | 89 } else { |
291 | 90 sh_audio->a_in_buffer_len-=ash.cbSrcLengthUsed; |
91 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[ash.cbSrcLengthUsed],sh_audio->a_in_buffer_len); | |
92 | 92 } |
93 len=ash.cbDstLengthUsed; | |
291 | 94 hr=acmStreamUnprepareHeader(sh_audio->srcstream,&ash,0); |
92 | 95 if(hr){ |
96 printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",hr); | |
97 } | |
98 return len; | |
99 } | |
100 | |
101 | |
1 | 102 |
303 | 103 int init_video_codec(){ |
1 | 104 HRESULT ret; |
303 | 105 unsigned int outfmt=sh_video->codec->outfmt[sh_video->outfmtidx]; |
1 | 106 |
107 if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n"); | |
108 | |
291 | 109 memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); |
110 sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER); | |
1 | 111 |
303 | 112 win32_codec_name = sh_video->codec->dll; |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
113 sh_video->hic = ICOpen( 0x63646976, sh_video->bih->biCompression, ICMODE_FASTDECOMPRESS); |
291 | 114 // sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_DECOMPRESS); |
115 if(!sh_video->hic){ | |
1 | 116 printf("ICOpen failed! unknown codec / wrong parameters?\n"); |
117 return 0; | |
118 } | |
119 | |
291 | 120 // sh_video->bih.biBitCount=32; |
1 | 121 |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
122 ret = ICDecompressGetFormat(sh_video->hic, sh_video->bih, &sh_video->o_bih); |
1 | 123 if(ret){ |
124 printf("ICDecompressGetFormat failed: Error %d\n", ret); | |
125 return 0; | |
126 } | |
127 if(verbose) printf("ICDecompressGetFormat OK\n"); | |
128 | |
129 // printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY); | |
130 | |
291 | 131 // sh_video->o_bih.biWidth=sh_video->bih.biWidth; |
132 // sh_video->o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y'); | |
133 // ret=ICDecompressGetFormatSize(sh_video->hic,&sh_video->o_bih); | |
134 // sh_video->o_bih.biCompression = 3; //0x32315659; | |
135 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | |
136 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | |
137 // sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); | |
138 // sh_video->o_bih.biPlanes=3; | |
139 // sh_video->o_bih.biBitCount=16; | |
1 | 140 |
408 | 141 |
142 switch (outfmt) { | |
143 | |
144 /* planar format */ | |
145 case IMGFMT_YV12: | |
146 case IMGFMT_I420: | |
147 case IMGFMT_IYUV: | |
148 sh_video->o_bih.biBitCount=12; | |
467 | 149 break; |
1 | 150 |
408 | 151 /* packed format */ |
152 case IMGFMT_YUY2: | |
153 case IMGFMT_UYVY: | |
154 case IMGFMT_YVYU: | |
155 sh_video->o_bih.biBitCount=16; | |
156 break; | |
303 | 157 |
408 | 158 /* rgb/bgr format */ |
159 case IMGFMT_RGB8: | |
160 case IMGFMT_BGR8: | |
161 sh_video->o_bih.biBitCount=8; | |
162 break; | |
1 | 163 |
408 | 164 case IMGFMT_RGB15: |
165 case IMGFMT_RGB16: | |
166 case IMGFMT_BGR15: | |
167 case IMGFMT_BGR16: | |
168 sh_video->o_bih.biBitCount=16; | |
169 break; | |
170 | |
171 case IMGFMT_RGB24: | |
172 case IMGFMT_BGR24: | |
173 sh_video->o_bih.biBitCount=24; | |
174 break; | |
175 | |
176 case IMGFMT_RGB32: | |
177 case IMGFMT_BGR32: | |
178 sh_video->o_bih.biBitCount=32; | |
179 break; | |
1 | 180 |
408 | 181 default: |
182 printf("unsupported image format: 0x%x\n", outfmt); | |
183 return 0; | |
184 } | |
185 | |
186 sh_video->o_bih.biSizeImage = sh_video->o_bih.biWidth * sh_video->o_bih.biHeight * (sh_video->o_bih.biBitCount/8); | |
1 | 187 |
408 | 188 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
|
189 sh_video->o_bih.biHeight=-sh_video->bih->biHeight; // flip image! |
408 | 190 } |
1 | 191 |
467 | 192 if(!(sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK)) |
408 | 193 sh_video->o_bih.biCompression = outfmt; |
1 | 194 |
195 if(verbose) { | |
196 printf("Starting decompression, format:\n"); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
197 printf(" biSize %d\n", sh_video->bih->biSize); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
198 printf(" biWidth %d\n", sh_video->bih->biWidth); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
199 printf(" biHeight %d\n", sh_video->bih->biHeight); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
200 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
|
201 printf(" biBitCount %d\n", sh_video->bih->biBitCount); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
202 printf(" biCompression 0x%x ('%.4s')\n", sh_video->bih->biCompression, &sh_video->bih->biCompression); |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
203 printf(" biSizeImage %d\n", sh_video->bih->biSizeImage); |
1 | 204 printf("Dest fmt:\n"); |
291 | 205 printf(" biSize %d\n", sh_video->o_bih.biSize); |
206 printf(" biWidth %d\n", sh_video->o_bih.biWidth); | |
207 printf(" biHeight %d\n", sh_video->o_bih.biHeight); | |
208 printf(" biPlanes %d\n", sh_video->o_bih.biPlanes); | |
209 printf(" biBitCount %d\n", sh_video->o_bih.biBitCount); | |
408 | 210 printf(" biCompression 0x%x ('%.4s')\n", sh_video->o_bih.biCompression, &sh_video->o_bih.biCompression); |
291 | 211 printf(" biSizeImage %d\n", sh_video->o_bih.biSizeImage); |
1 | 212 } |
213 | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
214 ret = ICDecompressQuery(sh_video->hic, sh_video->bih, &sh_video->o_bih); |
1 | 215 if(ret){ |
216 printf("ICDecompressQuery failed: Error %d\n", ret); | |
217 return 0; | |
218 } | |
219 if(verbose) printf("ICDecompressQuery OK\n"); | |
220 | |
221 | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
222 ret = ICDecompressBegin(sh_video->hic, sh_video->bih, &sh_video->o_bih); |
1 | 223 if(ret){ |
224 printf("ICDecompressBegin failed: Error %d\n", ret); | |
225 return 0; | |
226 } | |
227 | |
228 #if 0 | |
229 | |
291 | 230 //sh_video->hic |
1 | 231 //ICSendMessage(HIC hic,unsigned int msg,long lParam1,long lParam2) |
232 { int i; | |
233 for(i=73;i<256;i++){ | |
234 printf("Calling ICM_USER+%d function...",i);fflush(stdout); | |
291 | 235 ret = ICSendMessage(sh_video->hic,ICM_USER+i,NULL,NULL); |
1 | 236 printf(" ret=%d\n",ret); |
237 } | |
238 } | |
239 #endif | |
240 | |
414 | 241 sh_video->our_out_buffer = shmem_alloc(sh_video->o_bih.biSizeImage); |
291 | 242 if(!sh_video->our_out_buffer){ |
243 printf("not enough memory for decoded picture buffer (%d bytes)\n", sh_video->o_bih.biSizeImage); | |
1 | 244 return 0; |
245 } | |
246 | |
467 | 247 if(sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK) |
469 | 248 sh_video->o_bih.biCompression = outfmt; |
1 | 249 |
250 // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!! | |
251 | |
252 if(verbose) printf("VIDEO CODEC Init OK!!! ;-)\n"); | |
253 return 1; | |
254 } |