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