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