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