Mercurial > mplayer.hg
annotate dll_init.c @ 7131:1943b619990c
Sipro audio now supported.
author | diego |
---|---|
date | Thu, 29 Aug 2002 01:56:09 +0000 |
parents | 1e47c2e7aa8e |
children |
rev | line source |
---|---|
2775 | 1 |
2 #include "config.h" | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
3 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
4 #include <stdio.h> |
2775 | 5 #ifdef HAVE_MALLOC_H |
6 #include <malloc.h> | |
7 #endif | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
8 #include <stdlib.h> |
1430 | 9 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
10 |
1567 | 11 #include "mp_msg.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1653
diff
changeset
|
12 #include "help_mp.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
13 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
14 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
15 #include "demuxer.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 "loader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
18 //#include "wine/mmreg.h" |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1297
diff
changeset
|
19 #include "wine/vfw.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
20 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
21 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
22 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
23 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
24 |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
25 #include "dll_init.h" |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
26 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
27 #include "libvo/img_format.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
28 #include "linux/shmem.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
489
diff
changeset
|
29 |
2087 | 30 extern int divx_quality; |
31 | |
1 | 32 // ACM audio and VfW video codecs initialization |
33 // based on the avifile library [http://divx.euro.ru] | |
34 | |
296 | 35 int init_acm_audio_codec(sh_audio_t *sh_audio){ |
1 | 36 HRESULT ret; |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
414
diff
changeset
|
37 WAVEFORMATEX *in_fmt=sh_audio->wf; |
3725 | 38 unsigned int srcsize=0; |
1 | 39 |
1567 | 40 mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (ACM) AUDIO Codec init =======\n"); |
1 | 41 |
291 | 42 sh_audio->srcstream=NULL; |
1 | 43 |
291 | 44 sh_audio->o_wf.nChannels=in_fmt->nChannels; |
45 sh_audio->o_wf.nSamplesPerSec=in_fmt->nSamplesPerSec; | |
46 sh_audio->o_wf.nAvgBytesPerSec=2*sh_audio->o_wf.nSamplesPerSec*sh_audio->o_wf.nChannels; | |
47 sh_audio->o_wf.wFormatTag=WAVE_FORMAT_PCM; | |
48 sh_audio->o_wf.nBlockAlign=2*in_fmt->nChannels; | |
49 sh_audio->o_wf.wBitsPerSample=16; | |
3437
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
50 // sh_audio->o_wf.wBitsPerSample=in_fmt->wBitsPerSample; |
291 | 51 sh_audio->o_wf.cbSize=0; |
1 | 52 |
3437
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
53 if(verbose) { |
6526 | 54 #if 1 |
3437
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
55 printf("Input format:\n"); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
56 printf(" wFormatTag %d\n", in_fmt->wFormatTag); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
57 printf(" nChannels %d\n", in_fmt->nChannels); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
58 printf(" nSamplesPerSec %ld\n", in_fmt->nSamplesPerSec); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
59 printf(" nAvgBytesPerSec %d\n", in_fmt->nAvgBytesPerSec); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
60 printf(" nBlockAlign %d\n", in_fmt->nBlockAlign); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
61 printf(" wBitsPerSample %d\n", in_fmt->wBitsPerSample); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
62 printf(" cbSize %d\n", in_fmt->cbSize); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
63 printf("Output fmt:\n"); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
64 printf(" wFormatTag %d\n", sh_audio->o_wf.wFormatTag); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
65 printf(" nChannels %d\n", sh_audio->o_wf.nChannels); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
66 printf(" nSamplesPerSec %ld\n", sh_audio->o_wf.nSamplesPerSec); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
67 printf(" nAvgBytesPerSec %d\n", sh_audio->o_wf.nAvgBytesPerSec); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
68 printf(" nBlockAlign %d\n", sh_audio->o_wf.nBlockAlign); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
69 printf(" wBitsPerSample %d\n", sh_audio->o_wf.wBitsPerSample); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
70 printf(" cbSize %d\n", sh_audio->o_wf.cbSize); |
5760 | 71 #else |
72 printf("Input format:\n"); | |
73 print_wave_header(in_fmt); | |
6526 | 74 print_wave_header(sh_audio->wf); |
5760 | 75 printf("Output fmt:\n"); |
76 print_wave_header(&sh_audio->o_wf); | |
77 printf("\n"); | |
78 #endif | |
3437
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
79 } |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
80 |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
81 |
303 | 82 win32_codec_name = sh_audio->codec->dll; |
291 | 83 ret=acmStreamOpen(&sh_audio->srcstream,(HACMDRIVER)NULL, |
84 in_fmt,&sh_audio->o_wf, | |
1 | 85 NULL,0,0,0); |
86 if(ret){ | |
87 if(ret==ACMERR_NOTPOSSIBLE) | |
1567 | 88 mp_msg(MSGT_WIN32,MSGL_ERR,"ACM_Decoder: Unappropriate audio format\n"); |
1 | 89 else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1653
diff
changeset
|
90 mp_msg(MSGT_WIN32,MSGL_ERR,"ACM_Decoder: acmStreamOpen error: %d", (int)ret); |
291 | 91 sh_audio->srcstream=NULL; |
1 | 92 return 0; |
93 } | |
1567 | 94 mp_msg(MSGT_WIN32,MSGL_V,"Audio codec opened OK! ;-)\n"); |
1 | 95 |
631 | 96 acmStreamSize(sh_audio->srcstream, in_fmt->nBlockAlign, &srcsize, ACM_STREAMSIZEF_SOURCE); |
758 | 97 //if(verbose) printf("Audio ACM output buffer min. size: %ld (reported by codec)\n",srcsize); |
746 | 98 srcsize*=2; |
758 | 99 //if(srcsize<MAX_OUTBURST) srcsize=MAX_OUTBURST; |
100 if(!srcsize){ | |
1567 | 101 mp_msg(MSGT_WIN32,MSGL_WARN,"Warning! ACM codec reports srcsize=0\n"); |
758 | 102 srcsize=16384; |
103 } | |
104 // limit srcsize to 4-16kb | |
105 //while(srcsize && srcsize<4096) srcsize*=2; | |
106 //while(srcsize>16384) srcsize/=2; | |
291 | 107 sh_audio->audio_out_minsize=srcsize; // audio output min. size |
1567 | 108 mp_msg(MSGT_WIN32,MSGL_V,"Audio ACM output buffer min. size: %ld\n",srcsize); |
1 | 109 |
746 | 110 acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); |
5458 | 111 // if(srcsize<in_fmt->nBlockAlign) srcsize=in_fmt->nBlockAlign; |
1 | 112 |
5458 | 113 mp_msg(MSGT_WIN32,MSGL_V,"Audio ACM input buffer min. size: %ld\n",srcsize); |
92 | 114 |
5458 | 115 sh_audio->audio_in_minsize=2*srcsize; // audio input min. size |
116 | |
1 | 117 return 1; |
118 } | |
119 | |
758 | 120 int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen){ |
92 | 121 ACMSTREAMHEADER ash; |
122 HRESULT hr; | |
123 DWORD srcsize=0; | |
758 | 124 DWORD len=minlen; |
291 | 125 acmStreamSize(sh_audio->srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION); |
1567 | 126 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 | 127 |
128 if(srcsize<sh_audio->wf->nBlockAlign){ | |
129 srcsize=sh_audio->wf->nBlockAlign; | |
130 acmStreamSize(sh_audio->srcstream, srcsize, &len, ACM_STREAMSIZEF_SOURCE); | |
131 if(len>maxlen) len=maxlen; | |
132 } | |
133 | |
291 | 134 // if(srcsize==0) srcsize=((WAVEFORMATEX *)&sh_audio->o_wf_ext)->nBlockAlign; |
135 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! | |
136 if(sh_audio->a_in_buffer_len<srcsize){ | |
137 sh_audio->a_in_buffer_len+= | |
138 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
139 srcsize-sh_audio->a_in_buffer_len); | |
92 | 140 } |
1567 | 141 mp_msg(MSGT_WIN32,MSGL_DBG3,"acm convert %d -> %d bytes\n",sh_audio->a_in_buffer_len,len); |
92 | 142 memset(&ash, 0, sizeof(ash)); |
143 ash.cbStruct=sizeof(ash); | |
144 ash.fdwStatus=0; | |
145 ash.dwUser=0; | |
291 | 146 ash.pbSrc=sh_audio->a_in_buffer; |
147 ash.cbSrcLength=sh_audio->a_in_buffer_len; | |
92 | 148 ash.pbDst=a_buffer; |
149 ash.cbDstLength=len; | |
291 | 150 hr=acmStreamPrepareHeader(sh_audio->srcstream,&ash,0); |
92 | 151 if(hr){ |
1567 | 152 mp_msg(MSGT_WIN32,MSGL_V,"ACM_Decoder: acmStreamPrepareHeader error %d\n",(int)hr); |
92 | 153 return -1; |
154 } | |
291 | 155 hr=acmStreamConvert(sh_audio->srcstream,&ash,0); |
92 | 156 if(hr){ |
1567 | 157 mp_msg(MSGT_WIN32,MSGL_DBG2,"ACM_Decoder: acmStreamConvert error %d\n",(int)hr); |
3437
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
158 switch(hr) |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
159 { |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
160 case ACMERR_NOTPOSSIBLE: |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
161 case ACMERR_UNPREPARED: |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
162 mp_msg(MSGT_WIN32, MSGL_DBG2, "ACM_Decoder: acmStreamConvert error: probarly not initialized!\n"); |
ae0e2736a5d4
added in/out format debug to acm init like in vfw init (for testing vivo decoder dll :)
alex
parents:
2897
diff
changeset
|
163 } |
631 | 164 // return -1; |
92 | 165 } |
1407 | 166 if(verbose>1) |
1567 | 167 mp_msg(MSGT_WIN32,MSGL_DBG2,"acm converted %d -> %d\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed); |
291 | 168 if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){ |
169 sh_audio->a_in_buffer_len=0; | |
92 | 170 } else { |
291 | 171 sh_audio->a_in_buffer_len-=ash.cbSrcLengthUsed; |
172 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[ash.cbSrcLengthUsed],sh_audio->a_in_buffer_len); | |
92 | 173 } |
174 len=ash.cbDstLengthUsed; | |
291 | 175 hr=acmStreamUnprepareHeader(sh_audio->srcstream,&ash,0); |
92 | 176 if(hr){ |
1567 | 177 mp_msg(MSGT_WIN32,MSGL_V,"ACM_Decoder: acmStreamUnprepareHeader error %d\n",(int)hr); |
92 | 178 } |
179 return len; | |
180 } | |
181 | |
5449 | 182 int close_acm_audio_codec(sh_audio_t *sh_audio) |
183 { | |
184 HRESULT ret; | |
185 | |
186 ret = acmStreamClose(sh_audio->srcstream, 0); | |
187 | |
188 if (ret) | |
189 switch(ret) | |
190 { | |
191 case ACMERR_BUSY: | |
192 case ACMERR_CANCELED: | |
193 mp_msg(MSGT_WIN32, MSGL_DBG2, "ACM_Decoder: stream busy, waiting..\n"); | |
194 sleep(100); | |
195 return(close_acm_audio_codec(sh_audio)); | |
196 case ACMERR_UNPREPARED: | |
197 case ACMERR_NOTPOSSIBLE: | |
198 return(0); | |
199 default: | |
200 mp_msg(MSGT_WIN32, MSGL_WARN, "ACM_Decoder: unknown error occured: %d\n", ret); | |
201 return(0); | |
202 } | |
203 | |
204 // MSACM_UnregisterAllDrivers(); | |
205 return(1); | |
206 } | |
207 | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
208 int init_vfw_video_codec(sh_video_t *sh_video,int ex){ |
1 | 209 HRESULT ret; |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
210 int yuv=0; |
303 | 211 unsigned int outfmt=sh_video->codec->outfmt[sh_video->outfmtidx]; |
2679 | 212 char *temp; |
213 int temp_len; | |
2087 | 214 int i; |
1 | 215 |
1567 | 216 mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Codec init =======\n"); |
1 | 217 |
291 | 218 memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); |
219 sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER); | |
1 | 220 |
303 | 221 win32_codec_name = sh_video->codec->dll; |
746 | 222 // sh_video->hic = ICOpen( 0x63646976, sh_video->bih->biCompression, ICMODE_FASTDECOMPRESS); |
223 sh_video->hic = ICOpen( 0x63646976, sh_video->bih->biCompression, ICMODE_DECOMPRESS); | |
291 | 224 if(!sh_video->hic){ |
1567 | 225 mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n"); |
1 | 226 return 0; |
227 } | |
228 | |
2679 | 229 // sh_video->bih->biBitCount=32; |
230 | |
231 temp_len = ICDecompressGetFormatSize(sh_video->hic, sh_video->bih); | |
232 | |
233 if (temp_len < sh_video->o_bih.biSize) | |
234 temp_len = sh_video->o_bih.biSize; | |
235 | |
236 temp = malloc(temp_len); | |
237 printf("ICDecompressGetFormatSize ret: %d\n", temp_len); | |
238 | |
239 #if 0 | |
240 { | |
241 ICINFO icinfo; | |
242 ret = ICGetInfo(sh_video->hic, &icinfo, sizeof(ICINFO)); | |
243 printf("%d - %d - %d\n", ret, icinfo.dwSize, sizeof(ICINFO)); | |
244 printf("Compressor type: %.4x\n", icinfo.fccType); | |
245 printf("Compressor subtype: %.4x\n", icinfo.fccHandler); | |
246 printf("Compressor flags: %lu, version %lu, ICM version: %lu\n", | |
247 icinfo.dwFlags, icinfo.dwVersion, icinfo.dwVersionICM); | |
248 printf("Compressor name: %s\n", icinfo.szName); | |
249 printf("Compressor description: %s\n", icinfo.szDescription); | |
250 | |
251 printf("Flags:"); | |
252 if (icinfo.dwFlags & VIDCF_QUALITY) | |
253 printf(" quality"); | |
254 if (icinfo.dwFlags & VIDCF_FASTTEMPORALD) | |
255 printf(" fast-decompr"); | |
256 if (icinfo.dwFlags & VIDCF_QUALITYTIME) | |
257 printf(" temp-quality"); | |
258 printf("\n"); | |
259 } | |
260 #endif | |
1 | 261 |
2087 | 262 // Note: DivX.DLL overwrites 4 bytes _AFTER_ the o_bih header, so it corrupts |
263 // the sh_video struct content. We call it with an 1024-byte temp space and | |
264 // then copy out the data we need: | |
2679 | 265 memset(temp,0x77,temp_len); |
2885 | 266 // memcpy(temp,sh_video->bih,sizeof(BITMAPINFOHEADER)); |
267 // sh_video->o_bih.biSize = temp_len; | |
2087 | 268 |
269 ret = ICDecompressGetFormat(sh_video->hic, sh_video->bih, temp); | |
2679 | 270 if(ret < 0){ |
1567 | 271 mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressGetFormat failed: Error %d\n", (int)ret); |
2679 | 272 for (i=0; i < temp_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", temp[i]); |
1 | 273 return 0; |
274 } | |
1567 | 275 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormat OK\n"); |
1 | 276 |
2087 | 277 memcpy(&sh_video->o_bih,temp,sizeof(sh_video->o_bih)); |
2679 | 278 |
279 if (temp_len > sizeof(sh_video->o_bih)) | |
280 { | |
281 mp_msg(MSGT_WIN32, MSGL_V, "Extra info in o_bih (%d bytes)!\n", | |
282 temp_len-sizeof(sh_video->o_bih)); | |
283 for(i=sizeof(sh_video->o_bih);i<temp_len;i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02X ",temp[i]); | |
284 } | |
285 free(temp); | |
1 | 286 // printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY); |
287 | |
291 | 288 // sh_video->o_bih.biWidth=sh_video->bih.biWidth; |
289 // sh_video->o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y'); | |
290 // ret=ICDecompressGetFormatSize(sh_video->hic,&sh_video->o_bih); | |
291 // sh_video->o_bih.biCompression = 3; //0x32315659; | |
292 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | |
293 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | |
294 // sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); | |
295 // sh_video->o_bih.biPlanes=3; | |
296 // sh_video->o_bih.biBitCount=16; | |
1 | 297 |
713 | 298 #if 0 |
299 // workaround for pegasus MJPEG: | |
300 if(!sh_video->o_bih.biWidth) sh_video->o_bih.biWidth=sh_video->bih->biWidth; | |
301 if(!sh_video->o_bih.biHeight) sh_video->o_bih.biHeight=sh_video->bih->biHeight; | |
302 if(!sh_video->o_bih.biPlanes) sh_video->o_bih.biPlanes=sh_video->bih->biPlanes; | |
303 #endif | |
408 | 304 |
305 switch (outfmt) { | |
306 | |
307 /* planar format */ | |
308 case IMGFMT_YV12: | |
309 case IMGFMT_I420: | |
310 case IMGFMT_IYUV: | |
311 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
|
312 yuv=1; |
467 | 313 break; |
6526 | 314 case IMGFMT_YVU9: |
315 case IMGFMT_IF09: | |
316 sh_video->o_bih.biBitCount=9; | |
317 yuv=1; | |
318 break; | |
1 | 319 |
408 | 320 /* packed format */ |
321 case IMGFMT_YUY2: | |
322 case IMGFMT_UYVY: | |
323 case IMGFMT_YVYU: | |
324 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
|
325 yuv=1; |
408 | 326 break; |
303 | 327 |
408 | 328 /* rgb/bgr format */ |
329 case IMGFMT_RGB8: | |
330 case IMGFMT_BGR8: | |
331 sh_video->o_bih.biBitCount=8; | |
332 break; | |
1 | 333 |
408 | 334 case IMGFMT_RGB15: |
335 case IMGFMT_RGB16: | |
336 case IMGFMT_BGR15: | |
337 case IMGFMT_BGR16: | |
338 sh_video->o_bih.biBitCount=16; | |
339 break; | |
340 | |
341 case IMGFMT_RGB24: | |
342 case IMGFMT_BGR24: | |
343 sh_video->o_bih.biBitCount=24; | |
344 break; | |
345 | |
346 case IMGFMT_RGB32: | |
347 case IMGFMT_BGR32: | |
348 sh_video->o_bih.biBitCount=32; | |
349 break; | |
1 | 350 |
408 | 351 default: |
1567 | 352 mp_msg(MSGT_WIN32,MSGL_ERR,"unsupported image format: 0x%x\n", outfmt); |
408 | 353 return 0; |
354 } | |
355 | |
356 sh_video->o_bih.biSizeImage = sh_video->o_bih.biWidth * sh_video->o_bih.biHeight * (sh_video->o_bih.biBitCount/8); | |
713 | 357 |
408 | 358 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
|
359 sh_video->o_bih.biHeight=-sh_video->bih->biHeight; // flip image! |
408 | 360 } |
1 | 361 |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
362 if(yuv && !(sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK)) |
408 | 363 sh_video->o_bih.biCompression = outfmt; |
759 | 364 else |
365 sh_video->o_bih.biCompression = 0; | |
1 | 366 |
367 if(verbose) { | |
368 printf("Starting decompression, format:\n"); | |
603 | 369 printf(" biSize %ld\n", sh_video->bih->biSize); |
370 printf(" biWidth %ld\n", sh_video->bih->biWidth); | |
371 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
|
372 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
|
373 printf(" biBitCount %d\n", sh_video->bih->biBitCount); |
603 | 374 printf(" biCompression 0x%lx ('%.4s')\n", sh_video->bih->biCompression, (char *)&sh_video->bih->biCompression); |
375 printf(" biSizeImage %ld\n", sh_video->bih->biSizeImage); | |
1 | 376 printf("Dest fmt:\n"); |
603 | 377 printf(" biSize %ld\n", sh_video->o_bih.biSize); |
378 printf(" biWidth %ld\n", sh_video->o_bih.biWidth); | |
379 printf(" biHeight %ld\n", sh_video->o_bih.biHeight); | |
291 | 380 printf(" biPlanes %d\n", sh_video->o_bih.biPlanes); |
381 printf(" biBitCount %d\n", sh_video->o_bih.biBitCount); | |
603 | 382 printf(" biCompression 0x%lx ('%.4s')\n", sh_video->o_bih.biCompression, (char *)&sh_video->o_bih.biCompression); |
383 printf(" biSizeImage %ld\n", sh_video->o_bih.biSizeImage); | |
1 | 384 } |
385 | |
1297 | 386 ret = ex ? |
387 ICDecompressQueryEx(sh_video->hic, sh_video->bih, &sh_video->o_bih) : | |
388 ICDecompressQuery(sh_video->hic, sh_video->bih, &sh_video->o_bih); | |
1 | 389 if(ret){ |
1567 | 390 mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressQuery failed: Error %d\n", (int)ret); |
2714 | 391 // return 0; |
392 } else | |
1567 | 393 mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressQuery OK\n"); |
1 | 394 |
1297 | 395 ret = ex ? |
396 ICDecompressBeginEx(sh_video->hic, sh_video->bih, &sh_video->o_bih) : | |
397 ICDecompressBegin(sh_video->hic, sh_video->bih, &sh_video->o_bih); | |
1 | 398 if(ret){ |
1567 | 399 mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressBegin failed: Error %d\n", (int)ret); |
2876 | 400 // return 0; |
1 | 401 } |
402 | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
403 sh_video->our_out_buffer = (char*)memalign(64,sh_video->o_bih.biSizeImage); |
291 | 404 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
|
405 mp_msg(MSGT_WIN32,MSGL_ERR,MSGTR_NoMemForDecodedImage, sh_video->o_bih.biSizeImage); |
1 | 406 return 0; |
407 } | |
408 | |
489
2bb59b7c748a
BGR modes with VfW codecs fixed - biCompression must be 0 for BGR...
arpi_esp
parents:
469
diff
changeset
|
409 if(yuv && sh_video->codec->outflags[sh_video->outfmtidx] & CODECS_FLAG_YUVHACK) |
469 | 410 sh_video->o_bih.biCompression = outfmt; |
1 | 411 |
412 // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!! | |
2087 | 413 |
414 ICSendMessage(sh_video->hic, ICM_USER+80, (long)(&divx_quality) ,NULL); | |
415 | |
1567 | 416 mp_msg(MSGT_WIN32,MSGL_V,"VIDEO CODEC Init OK!!! ;-)\n"); |
1 | 417 return 1; |
418 } | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
419 |
2087 | 420 int vfw_set_postproc(sh_video_t* sh_video,int quality){ |
421 // Works only with opendivx/divx4 based DLL | |
422 return ICSendMessage(sh_video->hic, ICM_USER+80, (long)(&quality) ,NULL); | |
423 } | |
424 | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
425 int vfw_decode_video(sh_video_t* sh_video,void* start,int in_size,int drop_frame,int ex){ |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
426 HRESULT ret; |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
427 |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
428 sh_video->bih->biSizeImage = in_size; |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
429 |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
430 if(ex) |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
431 ret = ICDecompressEx(sh_video->hic, |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
432 ( (sh_video->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) | |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
433 ( (drop_frame==2 && !(sh_video->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ) , |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
434 sh_video->bih, start, |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
435 &sh_video->o_bih, |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
436 drop_frame ? 0 : sh_video->our_out_buffer); |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
437 else |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
438 ret = ICDecompress(sh_video->hic, |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
439 ( (sh_video->ds->flags&1) ? 0 : ICDECOMPRESS_NOTKEYFRAME ) | |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
440 ( (drop_frame==2 && !(sh_video->ds->flags&1))?(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL):0 ) , |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
441 sh_video->bih, start, |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
442 &sh_video->o_bih, |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
443 drop_frame ? 0 : sh_video->our_out_buffer); |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
444 |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
445 return (int)ret; |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
446 } |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
447 |
5449 | 448 int vfw_close_video_codec(sh_video_t *sh_video, int ex) |
449 { | |
450 HRESULT ret; | |
451 | |
452 ret = ICDecompressEnd(sh_video->hic); | |
453 if (ret) | |
454 { | |
455 mp_msg(MSGT_WIN32, MSGL_WARN, "ICDecompressEnd failed: %d\n", ret); | |
456 return(0); | |
457 } | |
458 | |
459 ret = ICClose(sh_video->hic); | |
460 if (ret) | |
461 { | |
462 mp_msg(MSGT_WIN32, MSGL_WARN, "ICClose failed: %d\n", ret); | |
463 return(0); | |
464 } | |
465 | |
466 return(1); | |
467 } | |
468 | |
4574 | 469 /************************ VFW COMPRESSION *****************************/ |
470 | |
471 static int encoder_hic=0; | |
472 static void* encoder_buf=NULL; | |
473 static int encoder_buf_size=0; | |
474 static int encoder_frameno=0; | |
475 | |
476 //int init_vfw_encoder(char *dll_name, BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih) | |
4638 | 477 BITMAPINFOHEADER* vfw_open_encoder(char *dll_name, BITMAPINFOHEADER *input_bih,unsigned int out_fourcc) |
4574 | 478 { |
479 HRESULT ret; | |
480 BITMAPINFOHEADER* output_bih=NULL; | |
481 int temp_len; | |
482 | |
483 //sh_video = malloc(sizeof(sh_video_t)); | |
484 | |
485 mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Encoder init =======\n"); | |
486 | |
487 // memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); | |
488 // output_bih->biSize = sizeof(BITMAPINFOHEADER); | |
489 | |
490 win32_codec_name = dll_name; | |
4638 | 491 encoder_hic = ICOpen( 0x63646976, out_fourcc, ICMODE_COMPRESS); |
4574 | 492 if(!encoder_hic){ |
493 mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n"); | |
494 return NULL; | |
495 } | |
496 printf("HIC: %x\n", encoder_hic); | |
497 | |
498 #if 1 | |
499 { | |
500 ICINFO icinfo; | |
501 | |
502 ret = ICGetInfo(encoder_hic, &icinfo, sizeof(ICINFO)); | |
503 printf("%d - %d - %d\n", ret, icinfo.dwSize, sizeof(ICINFO)); | |
504 printf("Compressor type: %.4x\n", icinfo.fccType); | |
505 printf("Compressor subtype: %.4x\n", icinfo.fccHandler); | |
506 printf("Compressor flags: %lu, version %lu, ICM version: %lu\n", | |
507 icinfo.dwFlags, icinfo.dwVersion, icinfo.dwVersionICM); | |
508 //printf("Compressor name: %s\n", icinfo.szName); | |
509 //printf("Compressor description: %s\n", icinfo.szDescription); | |
510 | |
511 printf("Flags:"); | |
512 if (icinfo.dwFlags & VIDCF_QUALITY) | |
513 printf(" quality"); | |
514 if (icinfo.dwFlags & VIDCF_FASTTEMPORALD) | |
515 printf(" fast-decompr"); | |
516 if (icinfo.dwFlags & VIDCF_QUALITYTIME) | |
517 printf(" temp-quality"); | |
518 printf("\n"); | |
519 } | |
520 #endif | |
521 | |
522 temp_len = ICCompressGetFormatSize(encoder_hic, input_bih); | |
523 printf("ICCompressGetFormatSize ret: %d\n", temp_len); | |
524 | |
525 if (temp_len < sizeof(BITMAPINFOHEADER)) temp_len=sizeof(BITMAPINFOHEADER); | |
526 | |
527 output_bih = malloc(temp_len+4); | |
528 memset(output_bih,0,temp_len); | |
529 output_bih->biSize = temp_len; //sizeof(BITMAPINFOHEADER); | |
530 | |
5554 | 531 return output_bih; |
532 } | |
533 | |
534 int vfw_start_encoder(BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih){ | |
535 HRESULT ret; | |
536 int temp_len=output_bih->biSize; | |
537 int i; | |
538 | |
4574 | 539 ret = ICCompressGetFormat(encoder_hic, input_bih, output_bih); |
540 if(ret < 0){ | |
7127 | 541 unsigned char* temp=(unsigned char*)output_bih; |
4574 | 542 mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressGetFormat failed: Error %d (0x%X)\n", (int)ret, (int)ret); |
543 for (i=0; i < temp_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", temp[i]); | |
5554 | 544 return 0; |
4574 | 545 } |
546 mp_msg(MSGT_WIN32,MSGL_V,"ICCompressGetFormat OK\n"); | |
547 | |
548 if (temp_len > sizeof(BITMAPINFOHEADER)) | |
549 { | |
7127 | 550 unsigned char* temp=(unsigned char*)output_bih; |
4574 | 551 mp_msg(MSGT_WIN32, MSGL_V, "Extra info in o_bih (%d bytes)!\n", |
552 temp_len-sizeof(BITMAPINFOHEADER)); | |
553 for(i=sizeof(output_bih);i<temp_len;i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02X ",temp[i]); | |
554 } | |
555 | |
556 // if(verbose) { | |
557 printf("Starting compression:\n"); | |
558 printf(" Input format:\n"); | |
559 printf(" biSize %ld\n", input_bih->biSize); | |
560 printf(" biWidth %ld\n", input_bih->biWidth); | |
561 printf(" biHeight %ld\n", input_bih->biHeight); | |
562 printf(" biPlanes %d\n", input_bih->biPlanes); | |
563 printf(" biBitCount %d\n", input_bih->biBitCount); | |
564 printf(" biCompression 0x%lx ('%.4s')\n", input_bih->biCompression, (char *)&input_bih->biCompression); | |
565 printf(" biSizeImage %ld\n", input_bih->biSizeImage); | |
566 printf(" Output format:\n"); | |
567 printf(" biSize %ld\n", output_bih->biSize); | |
568 printf(" biWidth %ld\n", output_bih->biWidth); | |
569 printf(" biHeight %ld\n", output_bih->biHeight); | |
570 printf(" biPlanes %d\n", output_bih->biPlanes); | |
571 printf(" biBitCount %d\n", output_bih->biBitCount); | |
572 printf(" biCompression 0x%lx ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression); | |
573 printf(" biSizeImage %ld\n", output_bih->biSizeImage); | |
574 // } | |
575 | |
576 output_bih->biWidth=input_bih->biWidth; | |
577 output_bih->biHeight=input_bih->biHeight; | |
578 | |
579 ret = ICCompressQuery(encoder_hic, input_bih, output_bih); | |
580 if(ret){ | |
581 mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressQuery failed: Error %d\n", (int)ret); | |
582 return 0; | |
583 } else | |
584 mp_msg(MSGT_WIN32,MSGL_V,"ICCompressQuery OK\n"); | |
585 | |
586 ret = ICCompressBegin(encoder_hic, input_bih, output_bih); | |
587 if(ret){ | |
588 mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressBegin failed: Error %d\n", (int)ret); | |
589 // return 0; | |
590 } else | |
591 mp_msg(MSGT_WIN32,MSGL_V,"ICCompressBegin OK\n"); | |
592 | |
593 printf(" Output format after query/begin:\n"); | |
594 printf(" biSize %ld\n", output_bih->biSize); | |
595 printf(" biWidth %ld\n", output_bih->biWidth); | |
596 printf(" biHeight %ld\n", output_bih->biHeight); | |
597 printf(" biPlanes %d\n", output_bih->biPlanes); | |
598 printf(" biBitCount %d\n", output_bih->biBitCount); | |
599 printf(" biCompression 0x%lx ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression); | |
600 printf(" biSizeImage %ld\n", output_bih->biSizeImage); | |
601 | |
602 encoder_buf_size=input_bih->biSizeImage; | |
603 encoder_buf=malloc(encoder_buf_size); | |
604 encoder_frameno=0; | |
605 | |
606 mp_msg(MSGT_WIN32,MSGL_V,"VIDEO CODEC Init OK!!! ;-)\n"); | |
5554 | 607 return 1; |
4574 | 608 } |
609 | |
610 int vfw_encode_frame(BITMAPINFOHEADER* biOutput,void* OutBuf, | |
611 BITMAPINFOHEADER* biInput,void* Image, | |
612 long* keyframe, int quality){ | |
613 HRESULT ret; | |
614 | |
615 //long VFWAPIV ICCompress( | |
616 // HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpOutputBuf, | |
617 // LPBITMAPINFOHEADER lpbiInput,void* lpImage,long* lpckid, | |
618 // long* lpdwFlags,long lFrameNum,long dwFrameSize,long dwQuality, | |
619 // LPBITMAPINFOHEADER lpbiInputPrev,void* lpImagePrev | |
620 //); | |
621 | |
622 // printf("vfw_encode_frame(%p,%p, %p,%p, %p,%d)\n",biOutput,OutBuf,biInput,Image,keyframe,quality); | |
623 | |
624 ret=ICCompress(encoder_hic, 0, | |
625 biOutput, OutBuf, | |
626 biInput, Image, | |
627 NULL, keyframe, encoder_frameno, 0, quality, | |
628 biInput, encoder_buf); | |
629 | |
630 // printf("ok. size=%d\n",biOutput->biSizeImage); | |
631 | |
632 memcpy(encoder_buf,Image,encoder_buf_size); | |
633 ++encoder_frameno; | |
634 | |
635 return (int)ret; | |
636 } | |
637 |