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