Mercurial > mplayer.hg
annotate loader/dshow/DS_VideoDecoder.c @ 9889:9dc39697e3b3
channel finetuning cmdline support, patch by Ivan Szanto <szivan@duticai.TWI.TUDelft.NL>
author | alex |
---|---|
date | Wed, 09 Apr 2003 16:07:45 +0000 |
parents | 0ef45318414a |
children | b0d1b415320c |
rev | line source |
---|---|
1545 | 1 /******************************************************** |
2 | |
3 DirectShow Video decoder implementation | |
4 Copyright 2000 Eugene Kuznetsov (divx@euro.ru) | |
5 | |
6 *********************************************************/ | |
7 | |
8 #include "guids.h" | |
9 #include "interfaces.h" | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7316
diff
changeset
|
10 #include "registry.h" |
1545 | 11 |
3946 | 12 #ifndef NOAVIFILE_HEADERS |
13 #include "videodecoder.h" | |
14 #else | |
15 #include "libwin32.h" | |
16 #endif | |
17 #include "DS_Filter.h" | |
18 | |
19 struct _DS_VideoDecoder | |
20 { | |
21 IVideoDecoder iv; | |
22 | |
23 DS_Filter* m_pDS_Filter; | |
24 AM_MEDIA_TYPE m_sOurType, m_sDestType; | |
25 VIDEOINFOHEADER* m_sVhdr; | |
26 VIDEOINFOHEADER* m_sVhdr2; | |
27 int m_Caps;//CAPS m_Caps; // capabilities of DirectShow decoder | |
28 int m_iLastQuality; // remember last quality as integer | |
29 int m_iMinBuffers; | |
30 int m_iMaxAuto; | |
31 int m_bIsDivX; // for speed | |
32 int m_bIsDivX4; // for speed | |
33 }; | |
34 | |
1545 | 35 #include "DS_VideoDecoder.h" |
3946 | 36 |
3059 | 37 #include "../wine/winerror.h" |
8451 | 38 #include "../ldt_keeper.h" |
3059 | 39 |
40 #ifndef NOAVIFILE_HEADERS | |
41 #define VFW_E_NOT_RUNNING 0x80040226 | |
42 #include "fourcc.h" | |
43 #include "except.h" | |
44 #endif | |
1545 | 45 |
46 #include <unistd.h> | |
47 #include <fcntl.h> | |
48 #include <errno.h> | |
49 #include <sys/types.h> | |
50 #include <sys/mman.h> | |
3059 | 51 #include <stdio.h> |
52 #include <stdlib.h> // labs | |
2072 | 53 |
3059 | 54 // strcmp((const char*)info.dll,...) is used instead of (... == ...) |
55 // so Arpi could use char* pointer in his simplified DS_VideoDecoder class | |
1545 | 56 |
57 #define __MODULE__ "DirectShow_VideoDecoder" | |
58 | |
3059 | 59 #define false 0 |
60 #define true 1 | |
61 | |
62 int DS_VideoDecoder_GetCapabilities(DS_VideoDecoder *this) | |
63 {return this->m_Caps;} | |
64 | |
65 typedef struct _ct ct; | |
1545 | 66 |
3059 | 67 struct _ct { |
68 unsigned int bits; | |
69 fourcc_t fcc; | |
8451 | 70 const GUID *subtype; |
3059 | 71 int cap; |
72 }; | |
73 | |
74 static ct check[] = { | |
75 {16, fccYUY2, &MEDIASUBTYPE_YUY2, CAP_YUY2}, | |
76 {12, fccIYUV, &MEDIASUBTYPE_IYUV, CAP_IYUV}, | |
77 {16, fccUYVY, &MEDIASUBTYPE_UYVY, CAP_UYVY}, | |
78 {12, fccYV12, &MEDIASUBTYPE_YV12, CAP_YV12}, | |
6527 | 79 //{16, fccYV12, &MEDIASUBTYPE_YV12, CAP_YV12}, |
3059 | 80 {16, fccYVYU, &MEDIASUBTYPE_YVYU, CAP_YVYU}, |
6527 | 81 {12, fccI420, &MEDIASUBTYPE_I420, CAP_I420}, |
82 {9, fccYVU9, &MEDIASUBTYPE_YVU9, CAP_YVU9}, | |
9581 | 83 {0, 0, 0, 0}, |
3059 | 84 }; |
85 | |
86 | |
3444 | 87 DS_VideoDecoder * DS_VideoDecoder_Open(char* dllname, GUID* guid, BITMAPINFOHEADER * format, int flip, int maxauto) |
1545 | 88 { |
3059 | 89 DS_VideoDecoder *this; |
90 HRESULT result; | |
91 ct* c; | |
92 | |
93 this = malloc(sizeof(DS_VideoDecoder)); | |
94 memset( this, 0, sizeof(DS_VideoDecoder)); | |
95 | |
96 this->m_sVhdr2 = 0; | |
97 this->m_iLastQuality = -1; | |
98 this->m_iMaxAuto = maxauto; | |
99 | |
3063 | 100 Setup_LDT_Keeper(); |
101 | |
1545 | 102 //memset(&m_obh, 0, sizeof(m_obh)); |
103 //m_obh.biSize = sizeof(m_obh); | |
3059 | 104 /*try*/ |
1545 | 105 { |
3059 | 106 unsigned int bihs; |
107 | |
108 bihs = (format->biSize < (int) sizeof(BITMAPINFOHEADER)) ? | |
109 sizeof(BITMAPINFOHEADER) : format->biSize; | |
110 | |
111 this->iv.m_bh = (BITMAPINFOHEADER*)malloc(bihs); | |
112 memcpy(this->iv.m_bh, format, bihs); | |
4205
c42ab0e5bbbc
possible sig11 fixed - noticed by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
3978
diff
changeset
|
113 |
3059 | 114 this->iv.m_State = STOP; |
115 //this->iv.m_pFrame = 0; | |
116 this->iv.m_Mode = DIRECT; | |
117 this->iv.m_iDecpos = 0; | |
118 this->iv.m_iPlaypos = -1; | |
119 this->iv.m_fQuality = 0.0f; | |
120 this->iv.m_bCapable16b = true; | |
121 | |
4205
c42ab0e5bbbc
possible sig11 fixed - noticed by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
3978
diff
changeset
|
122 bihs += sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER); |
3059 | 123 this->m_sVhdr = (VIDEOINFOHEADER*)malloc(bihs); |
124 memset(this->m_sVhdr, 0, bihs); | |
125 memcpy(&this->m_sVhdr->bmiHeader, this->iv.m_bh, this->iv.m_bh->biSize); | |
126 this->m_sVhdr->rcSource.left = this->m_sVhdr->rcSource.top = 0; | |
127 this->m_sVhdr->rcSource.right = this->m_sVhdr->bmiHeader.biWidth; | |
128 this->m_sVhdr->rcSource.bottom = this->m_sVhdr->bmiHeader.biHeight; | |
129 //this->m_sVhdr->rcSource.right = 0; | |
130 //this->m_sVhdr->rcSource.bottom = 0; | |
131 this->m_sVhdr->rcTarget = this->m_sVhdr->rcSource; | |
1545 | 132 |
3059 | 133 this->m_sOurType.majortype = MEDIATYPE_Video; |
134 this->m_sOurType.subtype = MEDIATYPE_Video; | |
135 this->m_sOurType.subtype.f1 = this->m_sVhdr->bmiHeader.biCompression; | |
136 this->m_sOurType.formattype = FORMAT_VideoInfo; | |
137 this->m_sOurType.bFixedSizeSamples = false; | |
138 this->m_sOurType.bTemporalCompression = true; | |
139 this->m_sOurType.pUnk = 0; | |
140 this->m_sOurType.cbFormat = bihs; | |
141 this->m_sOurType.pbFormat = (char*)this->m_sVhdr; | |
142 | |
143 this->m_sVhdr2 = (VIDEOINFOHEADER*)(malloc(sizeof(VIDEOINFOHEADER)+12)); | |
144 memcpy(this->m_sVhdr2, this->m_sVhdr, sizeof(VIDEOINFOHEADER)); | |
145 memset((char*)this->m_sVhdr2 + sizeof(VIDEOINFOHEADER), 0, 12); | |
146 this->m_sVhdr2->bmiHeader.biCompression = 0; | |
147 this->m_sVhdr2->bmiHeader.biBitCount = 24; | |
1545 | 148 |
3059 | 149 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); |
150 this->m_sDestType.majortype = MEDIATYPE_Video; | |
151 this->m_sDestType.subtype = MEDIASUBTYPE_RGB24; | |
152 this->m_sDestType.formattype = FORMAT_VideoInfo; | |
153 this->m_sDestType.bFixedSizeSamples = true; | |
154 this->m_sDestType.bTemporalCompression = false; | |
155 this->m_sDestType.lSampleSize = labs(this->m_sVhdr2->bmiHeader.biWidth*this->m_sVhdr2->bmiHeader.biHeight | |
156 * ((this->m_sVhdr2->bmiHeader.biBitCount + 7) / 8)); | |
157 this->m_sVhdr2->bmiHeader.biSizeImage = this->m_sDestType.lSampleSize; | |
158 this->m_sDestType.pUnk = 0; | |
159 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); | |
160 this->m_sDestType.pbFormat = (char*)this->m_sVhdr2; | |
161 | |
162 memset(&this->iv.m_obh, 0, sizeof(this->iv.m_obh)); | |
163 memcpy(&this->iv.m_obh, this->iv.m_bh, sizeof(this->iv.m_obh) < (unsigned) this->iv.m_bh->biSize | |
164 ? sizeof(this->iv.m_obh) : (unsigned) this->iv.m_bh->biSize); | |
165 this->iv.m_obh.biBitCount=24; | |
166 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER); | |
167 this->iv.m_obh.biCompression = 0; //BI_RGB | |
168 //this->iv.m_obh.biHeight = labs(this->iv.m_obh.biHeight); | |
169 this->iv.m_obh.biSizeImage = labs(this->iv.m_obh.biWidth * this->iv.m_obh.biHeight) | |
170 * ((this->iv.m_obh.biBitCount + 7) / 8); | |
1545 | 171 |
172 | |
3444 | 173 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); |
3456 | 174 |
175 if (!this->m_pDS_Filter) | |
176 { | |
177 printf("Failed to create DirectShow filter\n"); | |
178 return 0; | |
179 } | |
1545 | 180 |
181 if (!flip) | |
182 { | |
3059 | 183 this->iv.m_obh.biHeight *= -1; |
3466 | 184 this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight; |
3059 | 185 result = this->m_pDS_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDS_Filter->m_pOutputPin, &this->m_sDestType); |
1545 | 186 if (result) |
187 { | |
3466 | 188 printf("Decoder does not support upside-down RGB frames\n"); |
3059 | 189 this->iv.m_obh.biHeight *= -1; |
3466 | 190 this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight; |
1545 | 191 } |
192 } | |
193 | |
3059 | 194 memcpy( &this->iv.m_decoder, &this->iv.m_obh, sizeof(this->iv.m_obh) ); |
1545 | 195 |
3059 | 196 switch (this->iv.m_bh->biCompression) |
1545 | 197 { |
6527 | 198 #if 0 |
1545 | 199 case fccDIV3: |
200 case fccDIV4: | |
201 case fccDIV5: | |
3059 | 202 case fccDIV6: |
1545 | 203 case fccMP42: |
204 case fccWMV2: | |
205 //YV12 seems to be broken for DivX :-) codec | |
3060 | 206 // case fccIV50: |
1545 | 207 //produces incorrect picture |
208 //m_Caps = (CAPS) (m_Caps & ~CAP_YV12); | |
3059 | 209 //m_Caps = CAP_UYVY;//CAP_YUY2; // | CAP_I420; |
210 //m_Caps = CAP_I420; | |
211 this->m_Caps = (CAP_YUY2 | CAP_UYVY); | |
1545 | 212 break; |
6527 | 213 #endif |
1545 | 214 default: |
3059 | 215 |
216 this->m_Caps = CAP_NONE; | |
1545 | 217 |
6527 | 218 printf("Decoder supports the following YUV formats: "); |
3059 | 219 for (c = check; c->bits; c++) |
1545 | 220 { |
3059 | 221 this->m_sVhdr2->bmiHeader.biBitCount = c->bits; |
222 this->m_sVhdr2->bmiHeader.biCompression = c->fcc; | |
223 this->m_sDestType.subtype = *c->subtype; | |
224 result = this->m_pDS_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDS_Filter->m_pOutputPin, &this->m_sDestType); | |
1545 | 225 if (!result) |
6527 | 226 { |
3059 | 227 this->m_Caps = (this->m_Caps | c->cap); |
8451 | 228 printf("%.4s ", (char *)&c->fcc); |
6527 | 229 } |
1545 | 230 } |
6527 | 231 printf("\n"); |
1545 | 232 } |
233 | |
3059 | 234 if (this->m_Caps != CAP_NONE) |
6527 | 235 printf("Decoder is capable of YUV output (flags 0x%x)\n", (int)this->m_Caps); |
1545 | 236 |
3059 | 237 this->m_sVhdr2->bmiHeader.biBitCount = 24; |
238 this->m_sVhdr2->bmiHeader.biCompression = 0; | |
239 this->m_sDestType.subtype = MEDIASUBTYPE_RGB24; | |
1545 | 240 |
3059 | 241 this->m_iMinBuffers = this->iv.VBUFSIZE; |
3444 | 242 this->m_bIsDivX = (strcmp(dllname, "divxcvki.ax") == 0 |
243 || strcmp(dllname, "divx_c32.ax") == 0 | |
244 || strcmp(dllname, "wmvds32.ax") == 0 | |
245 || strcmp(dllname, "wmv8ds32.ax") == 0); | |
246 this->m_bIsDivX4 = (strcmp(dllname, "divxdec.ax") == 0); | |
3059 | 247 if (this->m_bIsDivX) |
248 this->iv.VBUFSIZE += 7; | |
249 else if (this->m_bIsDivX4) | |
250 this->iv.VBUFSIZE += 9; | |
1545 | 251 } |
3059 | 252 /*catch (FatalError& error) |
1545 | 253 { |
3059 | 254 delete[] m_sVhdr; |
1545 | 255 delete[] m_sVhdr2; |
256 delete m_pDS_Filter; | |
257 throw; | |
3059 | 258 }*/ |
259 return this; | |
1545 | 260 } |
261 | |
3059 | 262 void DS_VideoDecoder_Destroy(DS_VideoDecoder *this) |
1545 | 263 { |
3059 | 264 DS_VideoDecoder_StopInternal(this); |
265 this->iv.m_State = STOP; | |
266 free(this->m_sVhdr); | |
267 free(this->m_sVhdr2); | |
268 DS_Filter_Destroy(this->m_pDS_Filter); | |
1545 | 269 } |
270 | |
3059 | 271 void DS_VideoDecoder_StartInternal(DS_VideoDecoder *this) |
1545 | 272 { |
3059 | 273 ALLOCATOR_PROPERTIES props, props1; |
274 Debug printf("DS_VideoDecoder_StartInternal\n"); | |
1545 | 275 //cout << "DSSTART" << endl; |
3063 | 276 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
3059 | 277 |
1545 | 278 props.cBuffers = 1; |
3059 | 279 props.cbBuffer = this->m_sDestType.lSampleSize; |
9503
f47d484d8f28
cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents:
8451
diff
changeset
|
280 props.cbAlign = 1; |
f47d484d8f28
cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents:
8451
diff
changeset
|
281 props.cbPrefix = 0; |
3059 | 282 this->m_pDS_Filter->m_pAll->vt->SetProperties(this->m_pDS_Filter->m_pAll, &props, &props1); |
283 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); | |
284 | |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
285 this->iv.m_State = START; |
1545 | 286 } |
287 | |
3059 | 288 void DS_VideoDecoder_StopInternal(DS_VideoDecoder *this) |
1545 | 289 { |
3063 | 290 this->m_pDS_Filter->Stop(this->m_pDS_Filter); |
1545 | 291 //??? why was this here ??? m_pOurOutput->SetFramePointer(0); |
292 } | |
293 | |
3063 | 294 int DS_VideoDecoder_DecodeInternal(DS_VideoDecoder *this, const void* src, int size, int is_keyframe, char* pImage) |
1545 | 295 { |
296 IMediaSample* sample = 0; | |
3059 | 297 char* ptr; |
298 int result; | |
299 | |
3063 | 300 Debug printf("DS_VideoDecoder_DecodeInternal(%p,%p,%d,%d,%p)\n",this,src,size,is_keyframe,pImage); |
3059 | 301 |
302 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); | |
303 | |
1545 | 304 if (!sample) |
305 { | |
3059 | 306 Debug printf("ERROR: null sample\n"); |
1545 | 307 return -1; |
308 } | |
3059 | 309 |
1545 | 310 //cout << "DECODE " << (void*) pImage << " d: " << (void*) pImage->Data() << endl; |
311 if (pImage) | |
312 { | |
3063 | 313 this->m_pDS_Filter->m_pOurOutput->SetPointer2(this->m_pDS_Filter->m_pOurOutput,pImage); |
1545 | 314 } |
315 | |
3059 | 316 |
3466 | 317 sample->vt->SetActualDataLength(sample, size); |
1545 | 318 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
319 memcpy(ptr, src, size); | |
320 sample->vt->SetSyncPoint(sample, is_keyframe); | |
321 sample->vt->SetPreroll(sample, pImage ? 0 : 1); | |
322 // sample->vt->SetMediaType(sample, &m_sOurType); | |
323 | |
324 // FIXME: - crashing with YV12 at this place decoder will crash | |
325 // while doing this call | |
326 // %FS register was not setup for calling into win32 dll. Are all | |
327 // crashes inside ...->Receive() fixed now? | |
328 // | |
329 // nope - but this is surely helpfull - I'll try some more experiments | |
3060 | 330 Setup_FS_Segment(); |
1545 | 331 #if 0 |
3059 | 332 if (!this->m_pDS_Filter || !this->m_pDS_Filter->m_pImp |
333 || !this->m_pDS_Filter->m_pImp->vt | |
334 || !this->m_pDS_Filter->m_pImp->vt->Receive) | |
1545 | 335 printf("DecodeInternal ERROR???\n"); |
336 #endif | |
3059 | 337 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 338 if (result) |
339 { | |
340 Debug printf("DS_VideoDecoder::DecodeInternal() error putting data into input pin %x\n", result); | |
341 } | |
342 | |
343 sample->vt->Release((IUnknown*)sample); | |
344 | |
3059 | 345 #if 0 |
346 if (this->m_bIsDivX) | |
1545 | 347 { |
348 int q; | |
3059 | 349 IHidden* hidden=(IHidden*)((int)this->m_pDS_Filter->m_pFilter + 0xb8); |
1545 | 350 // always check for actual value |
351 // this seems to be the only way to know the actual value | |
3059 | 352 hidden->vt->GetSmth2(hidden, &this->m_iLastQuality); |
353 if (this->m_iLastQuality > 9) | |
354 this->m_iLastQuality -= 10; | |
355 | |
356 if (this->m_iLastQuality < 0) | |
357 this->m_iLastQuality = 0; | |
358 else if (this->m_iLastQuality > this->m_iMaxAuto) | |
359 this->m_iLastQuality = this->m_iMaxAuto; | |
1545 | 360 |
3059 | 361 //cout << " Qual: " << this->m_iLastQuality << endl; |
362 this->iv.m_fQuality = this->m_iLastQuality / 4.0; | |
363 } | |
364 else if (this->m_bIsDivX4) | |
365 { | |
366 | |
367 // maybe access methods directly to safe some cpu cycles... | |
368 DS_VideoDecoder_GetValue(this, "Postprocessing", this->m_iLastQuality); | |
369 if (this->m_iLastQuality < 0) | |
370 this->m_iLastQuality = 0; | |
371 else if (this->m_iLastQuality > this->m_iMaxAuto) | |
372 this->m_iLastQuality = this->m_iMaxAuto; | |
1545 | 373 |
374 //cout << " Qual: " << m_iLastQuality << endl; | |
3059 | 375 this->iv.m_fQuality = this->m_iLastQuality / 6.0; |
1545 | 376 } |
377 | |
3059 | 378 if (this->iv.m_Mode == -1 ) // ???BUFFERED_QUALITY_AUTO) |
1545 | 379 { |
380 // adjust Quality - depends on how many cached frames we have | |
3059 | 381 int buffered = this->iv.m_iDecpos - this->iv.m_iPlaypos; |
1545 | 382 |
3059 | 383 if (this->m_bIsDivX || this->m_bIsDivX4) |
384 { | |
385 int to = buffered - this->m_iMinBuffers; | |
386 if (to < 0) | |
387 to = 0; | |
388 if (to != this->m_iLastQuality) | |
389 { | |
390 if (to > this->m_iMaxAuto) | |
391 to = this->m_iMaxAuto; | |
392 if (this->m_iLastQuality != to) | |
1545 | 393 { |
3059 | 394 if (this->m_bIsDivX) |
395 { | |
396 IHidden* hidden=(IHidden*)((int)this->m_pDS_Filter->m_pFilter + 0xb8); | |
397 hidden->vt->SetSmth(hidden, to, 0); | |
398 } | |
399 else | |
400 DS_VideoDecoder_SetValue(this, "Postprocessing", to); | |
1545 | 401 #ifndef QUIET |
3059 | 402 //printf("Switching quality %d -> %d b:%d\n",m_iLastQuality, to, buffered); |
1545 | 403 #endif |
404 } | |
405 } | |
406 } | |
407 } | |
3059 | 408 #endif |
1545 | 409 |
410 return 0; | |
411 } | |
412 | |
413 /* | |
414 * bits == 0 - leave unchanged | |
415 */ | |
3059 | 416 //int SetDestFmt(DS_VideoDecoder * this, int bits = 24, fourcc_t csp = 0); |
3946 | 417 int DS_VideoDecoder_SetDestFmt(DS_VideoDecoder *this, int bits, unsigned int csp) |
1545 | 418 { |
3059 | 419 HRESULT result; |
420 int should_test=1; | |
421 int stoped = 0; | |
422 | |
423 Debug printf("DS_VideoDecoder_SetDestFmt (%p, %d, %d)\n",this,bits,(int)csp); | |
424 | |
425 /* if (!CImage::Supported(csp, bits)) | |
1545 | 426 return -1; |
3059 | 427 */ |
1545 | 428 // BitmapInfo temp = m_obh; |
3059 | 429 |
3063 | 430 if (!csp) // RGB |
1545 | 431 { |
3059 | 432 int ok = true; |
1545 | 433 |
434 switch (bits) | |
435 { | |
436 case 15: | |
3059 | 437 this->m_sDestType.subtype = MEDIASUBTYPE_RGB555; |
1545 | 438 break; |
439 case 16: | |
3059 | 440 this->m_sDestType.subtype = MEDIASUBTYPE_RGB565; |
1545 | 441 break; |
442 case 24: | |
3059 | 443 this->m_sDestType.subtype = MEDIASUBTYPE_RGB24; |
1545 | 444 break; |
445 case 32: | |
3059 | 446 this->m_sDestType.subtype = MEDIASUBTYPE_RGB32; |
1545 | 447 break; |
448 default: | |
449 ok = false; | |
450 break; | |
451 } | |
452 | |
3059 | 453 if (ok) { |
9581 | 454 if (bits == 15) |
455 this->iv.m_obh.biBitCount=16; | |
456 else | |
457 this->iv.m_obh.biBitCount=bits; | |
3059 | 458 if( bits == 15 || bits == 16 ) { |
459 this->iv.m_obh.biSize=sizeof(BITMAPINFOHEADER)+12; | |
460 this->iv.m_obh.biCompression=3;//BI_BITFIELDS | |
461 this->iv.m_obh.biSizeImage=abs((int)(2*this->iv.m_obh.biWidth*this->iv.m_obh.biHeight)); | |
462 } | |
463 | |
464 if( bits == 16 ) { | |
465 this->iv.m_obh.colors[0]=0xF800; | |
466 this->iv.m_obh.colors[1]=0x07E0; | |
467 this->iv.m_obh.colors[2]=0x001F; | |
468 } else if ( bits == 15 ) { | |
469 this->iv.m_obh.colors[0]=0x7C00; | |
470 this->iv.m_obh.colors[1]=0x03E0; | |
471 this->iv.m_obh.colors[2]=0x001F; | |
472 } else { | |
473 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER); | |
474 this->iv.m_obh.biCompression = 0; //BI_RGB | |
475 //this->iv.m_obh.biHeight = labs(this->iv.m_obh.biHeight); | |
476 this->iv.m_obh.biSizeImage = labs(this->iv.m_obh.biWidth * this->iv.m_obh.biHeight) | |
477 * ((this->iv.m_obh.biBitCount + 7) / 8); | |
478 } | |
479 } | |
1545 | 480 //.biSizeImage=abs(temp.biWidth*temp.biHeight*((temp.biBitCount+7)/8)); |
3063 | 481 } else |
482 { // YUV | |
3059 | 483 int ok = true; |
1545 | 484 switch (csp) |
485 { | |
486 case fccYUY2: | |
3059 | 487 this->m_sDestType.subtype = MEDIASUBTYPE_YUY2; |
1545 | 488 break; |
489 case fccYV12: | |
3059 | 490 this->m_sDestType.subtype = MEDIASUBTYPE_YV12; |
1545 | 491 break; |
492 case fccIYUV: | |
3059 | 493 this->m_sDestType.subtype = MEDIASUBTYPE_IYUV; |
1545 | 494 break; |
6527 | 495 case fccI420: |
496 this->m_sDestType.subtype = MEDIASUBTYPE_I420; | |
497 break; | |
1545 | 498 case fccUYVY: |
3059 | 499 this->m_sDestType.subtype = MEDIASUBTYPE_UYVY; |
1545 | 500 break; |
501 case fccYVYU: | |
3059 | 502 this->m_sDestType.subtype = MEDIASUBTYPE_YVYU; |
1545 | 503 break; |
6527 | 504 case fccYVU9: |
505 this->m_sDestType.subtype = MEDIASUBTYPE_YVU9; | |
1545 | 506 default: |
507 ok = false; | |
508 break; | |
509 } | |
510 | |
3059 | 511 if (ok) { |
512 if (csp != 0 && csp != 3 && this->iv.m_obh.biHeight > 0) | |
513 this->iv.m_obh.biHeight *= -1; // YUV formats uses should have height < 0 | |
514 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER); | |
515 this->iv.m_obh.biCompression=csp; | |
516 this->iv.m_obh.biBitCount=bits; | |
517 this->iv.m_obh.biSizeImage=labs(this->iv.m_obh.biBitCount* | |
518 this->iv.m_obh.biWidth*this->iv.m_obh.biHeight)>>3; | |
519 } | |
1545 | 520 } |
3059 | 521 this->m_sDestType.lSampleSize = this->iv.m_obh.biSizeImage; |
522 memcpy(&(this->m_sVhdr2->bmiHeader), &this->iv.m_obh, sizeof(this->iv.m_obh)); | |
523 this->m_sVhdr2->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
524 if (this->m_sVhdr2->bmiHeader.biCompression == 3) | |
525 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER) + 12; | |
1545 | 526 else |
3059 | 527 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); |
1545 | 528 |
3059 | 529 |
1545 | 530 switch(csp) |
531 { | |
532 case fccYUY2: | |
3059 | 533 if(!(this->m_Caps & CAP_YUY2)) |
1545 | 534 should_test=false; |
535 break; | |
536 case fccYV12: | |
3059 | 537 if(!(this->m_Caps & CAP_YV12)) |
1545 | 538 should_test=false; |
539 break; | |
540 case fccIYUV: | |
3059 | 541 if(!(this->m_Caps & CAP_IYUV)) |
1545 | 542 should_test=false; |
543 break; | |
6527 | 544 case fccI420: |
545 if(!(this->m_Caps & CAP_I420)) | |
546 should_test=false; | |
547 break; | |
1545 | 548 case fccUYVY: |
3059 | 549 if(!(this->m_Caps & CAP_UYVY)) |
1545 | 550 should_test=false; |
551 break; | |
552 case fccYVYU: | |
3059 | 553 if(!(this->m_Caps & CAP_YVYU)) |
1545 | 554 should_test=false; |
555 break; | |
6527 | 556 case fccYVU9: |
557 if(!(this->m_Caps & CAP_YVU9)) | |
558 should_test=false; | |
559 break; | |
1545 | 560 } |
561 if(should_test) | |
3059 | 562 result = this->m_pDS_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDS_Filter->m_pOutputPin, &this->m_sDestType); |
1545 | 563 else |
564 result = -1; | |
565 | |
566 if (result != 0) | |
567 { | |
568 if (csp) | |
3059 | 569 printf("Warning: unsupported color space\n"); |
1545 | 570 else |
3059 | 571 printf("Warning: unsupported bit depth\n"); |
1545 | 572 |
3059 | 573 this->m_sDestType.lSampleSize = this->iv.m_decoder.biSizeImage; |
574 memcpy(&(this->m_sVhdr2->bmiHeader), &this->iv.m_decoder, sizeof(this->iv.m_decoder)); | |
575 this->m_sVhdr2->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
576 if (this->m_sVhdr2->bmiHeader.biCompression == 3) | |
577 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER) + 12; | |
1545 | 578 else |
3059 | 579 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); |
1545 | 580 |
3059 | 581 return -1; |
1545 | 582 } |
583 | |
3059 | 584 memcpy( &this->iv.m_decoder, &this->iv.m_obh, sizeof(this->iv.m_obh)); |
1545 | 585 |
586 // m_obh=temp; | |
587 // if(csp) | |
588 // m_obh.biBitCount=BitmapInfo::BitCount(csp); | |
3059 | 589 this->iv.m_bh->biBitCount = bits; |
590 | |
591 //DS_VideoDecoder_Restart(this); | |
1545 | 592 |
3059 | 593 if (this->iv.m_State == START) |
1545 | 594 { |
3059 | 595 DS_VideoDecoder_StopInternal(this); |
596 this->iv.m_State = STOP; | |
1545 | 597 stoped = true; |
598 } | |
599 | |
3059 | 600 this->m_pDS_Filter->m_pInputPin->vt->Disconnect(this->m_pDS_Filter->m_pInputPin); |
601 this->m_pDS_Filter->m_pOutputPin->vt->Disconnect(this->m_pDS_Filter->m_pOutputPin); | |
3063 | 602 this->m_pDS_Filter->m_pOurOutput->SetNewFormat(this->m_pDS_Filter->m_pOurOutput,&this->m_sDestType); |
3059 | 603 result = this->m_pDS_Filter->m_pInputPin->vt->ReceiveConnection(this->m_pDS_Filter->m_pInputPin, |
604 this->m_pDS_Filter->m_pOurInput, | |
605 &this->m_sOurType); | |
1545 | 606 if (result) |
607 { | |
3059 | 608 printf("Error reconnecting input pin 0x%x\n", (int)result); |
1545 | 609 return -1; |
610 } | |
3059 | 611 result = this->m_pDS_Filter->m_pOutputPin->vt->ReceiveConnection(this->m_pDS_Filter->m_pOutputPin, |
612 (IPin *)this->m_pDS_Filter->m_pOurOutput, | |
613 &this->m_sDestType); | |
1545 | 614 if (result) |
615 { | |
3059 | 616 printf("Error reconnecting output pin 0x%x\n", (int)result); |
1545 | 617 return -1; |
618 } | |
619 | |
620 if (stoped) | |
3059 | 621 { |
622 DS_VideoDecoder_StartInternal(this); | |
623 this->iv.m_State = START; | |
624 } | |
1545 | 625 |
626 return 0; | |
627 } | |
628 | |
3059 | 629 |
630 int DS_VideoDecoder_SetDirection(DS_VideoDecoder *this, int d) | |
631 { | |
632 this->iv.m_obh.biHeight = (d) ? this->iv.m_bh->biHeight : -this->iv.m_bh->biHeight; | |
633 this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight; | |
634 return 0; | |
635 } | |
636 | |
3946 | 637 int DS_VideoDecoder_GetValue(DS_VideoDecoder *this, const char* name, int* value) |
1545 | 638 { |
3059 | 639 /* |
640 if (m_bIsDivX4) | |
641 { | |
642 IDivxFilterInterface* pIDivx; | |
643 if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, &IID_IDivxFilterInterface, (void**)&pIDivx)) | |
644 { | |
645 Debug printf("No such interface\n"); | |
646 return -1; | |
647 } | |
648 if (strcmp(name, "Postprocessing") == 0) | |
649 { | |
650 pIDivx->vt->get_PPLevel(pIDivx, &value); | |
651 value /= 10; | |
652 } | |
653 else if (strcmp(name, "Brightness") == 0) | |
654 pIDivx->vt->get_Brightness(pIDivx, &value); | |
655 else if (strcmp(name, "Contrast") == 0) | |
656 pIDivx->vt->get_Contrast(pIDivx, &value); | |
657 else if (strcmp(name, "Saturation") == 0) | |
658 pIDivx->vt->get_Saturation(pIDivx, &value); | |
659 else if (strcmp(name, "MaxAuto") == 0) | |
660 value = m_iMaxAuto; | |
661 pIDivx->vt->Release((IUnknown*)pIDivx); | |
662 return 0; | |
663 } | |
664 else if (m_bIsDivX) | |
1545 | 665 { |
666 if (m_State != START) | |
667 return VFW_E_NOT_RUNNING; | |
668 // brightness 87 | |
669 // contrast 74 | |
670 // hue 23 | |
671 // saturation 20 | |
672 // post process mode 0 | |
673 // get1 0x01 | |
674 // get2 10 | |
675 // get3=set2 86 | |
676 // get4=set3 73 | |
677 // get5=set4 19 | |
678 // get6=set5 23 | |
679 IHidden* hidden=(IHidden*)((int)m_pDS_Filter->m_pFilter+0xb8); | |
3059 | 680 if (strcmp(name, "Quality") == 0) |
681 { | |
682 #warning NOT SURE | |
683 int r = hidden->vt->GetSmth2(hidden, &value); | |
684 if (value >= 10) | |
685 value -= 10; | |
686 return 0; | |
687 } | |
1545 | 688 if (strcmp(name, "Brightness") == 0) |
689 return hidden->vt->GetSmth3(hidden, &value); | |
690 if (strcmp(name, "Contrast") == 0) | |
691 return hidden->vt->GetSmth4(hidden, &value); | |
692 if (strcmp(name, "Hue") == 0) | |
693 return hidden->vt->GetSmth6(hidden, &value); | |
694 if (strcmp(name, "Saturation") == 0) | |
695 return hidden->vt->GetSmth5(hidden, &value); | |
3059 | 696 if (strcmp(name, "MaxAuto") == 0) |
1545 | 697 { |
3059 | 698 value = m_iMaxAuto; |
699 return 0; | |
1545 | 700 } |
701 } | |
3059 | 702 else if (strcmp((const char*)record.dll, "ir50_32.dll") == 0) |
1545 | 703 { |
704 IHidden2* hidden = 0; | |
705 if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, &IID_Iv50Hidden, (void**)&hidden)) | |
706 { | |
3059 | 707 Debug printf("No such interface\n"); |
1545 | 708 return -1; |
709 } | |
710 #warning FIXME | |
711 int recordpar[30]; | |
712 recordpar[0]=0x7c; | |
713 recordpar[1]=fccIV50; | |
714 recordpar[2]=0x10005; | |
715 recordpar[3]=2; | |
716 recordpar[4]=1; | |
717 recordpar[5]=0x80000000; | |
718 | |
719 if (strcmp(name, "Brightness") == 0) | |
720 recordpar[5]|=0x20; | |
721 else if (strcmp(name, "Saturation") == 0) | |
722 recordpar[5]|=0x40; | |
723 else if (strcmp(name, "Contrast") == 0) | |
724 recordpar[5]|=0x80; | |
725 if (!recordpar[5]) | |
726 { | |
727 hidden->vt->Release((IUnknown*)hidden); | |
728 return -1; | |
729 } | |
730 if (hidden->vt->DecodeSet(hidden, recordpar)) | |
731 return -1; | |
732 | |
733 if (strcmp(name, "Brightness") == 0) | |
734 value = recordpar[18]; | |
735 else if (strcmp(name, "Saturation") == 0) | |
736 value = recordpar[19]; | |
737 else if (strcmp(name, "Contrast") == 0) | |
738 value = recordpar[20]; | |
739 | |
740 hidden->vt->Release((IUnknown*)hidden); | |
741 } | |
3059 | 742 */ |
1545 | 743 return 0; |
744 } | |
745 | |
3946 | 746 int DS_VideoDecoder_SetValue(DS_VideoDecoder *this, const char* name, int value) |
1545 | 747 { |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
748 if (this->m_bIsDivX4) { |
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
749 IDivxFilterInterface* pIDivx=NULL; |
3978 | 750 // printf("DS_SetValue for DIVX4, name=%s value=%d\n",name,value); |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
751 if (this->m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)this->m_pDS_Filter->m_pFilter, &IID_IDivxFilterInterface, (void**)&pIDivx)) |
3059 | 752 { |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
753 printf("No such interface\n"); |
3059 | 754 return -1; |
755 } | |
6801 | 756 if (strcasecmp(name, "Postprocessing") == 0) |
3059 | 757 pIDivx->vt->put_PPLevel(pIDivx, value * 10); |
6801 | 758 else if (strcasecmp(name, "Brightness") == 0) |
3059 | 759 pIDivx->vt->put_Brightness(pIDivx, value); |
6801 | 760 else if (strcasecmp(name, "Contrast") == 0) |
3059 | 761 pIDivx->vt->put_Contrast(pIDivx, value); |
6801 | 762 else if (strcasecmp(name, "Saturation") == 0) |
3059 | 763 pIDivx->vt->put_Saturation(pIDivx, value); |
6801 | 764 else if (strcasecmp(name, "MaxAuto") == 0) |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
765 this->m_iMaxAuto = value; |
3059 | 766 pIDivx->vt->Release((IUnknown*)pIDivx); |
767 //printf("Set %s %d\n", name, value); | |
768 return 0; | |
769 } | |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
770 |
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
771 if (this->m_bIsDivX) { |
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
772 IHidden* hidden; |
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
773 if (this->iv.m_State != START) |
1545 | 774 return VFW_E_NOT_RUNNING; |
775 | |
776 //cout << "set value " << name << " " << value << endl; | |
777 // brightness 87 | |
778 // contrast 74 | |
779 // hue 23 | |
780 // saturation 20 | |
781 // post process mode 0 | |
782 // get1 0x01 | |
783 // get2 10 | |
784 // get3=set2 86 | |
785 // get4=set3 73 | |
786 // get5=set4 19 | |
3059 | 787 // get6=set5 23 |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
788 hidden = (IHidden*)((int)this->m_pDS_Filter->m_pFilter + 0xb8); |
7316 | 789 //printf("DS_SetValue for DIVX, name=%s value=%d\n",name,value); |
6801 | 790 if (strcasecmp(name, "Quality") == 0) |
1545 | 791 { |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
792 this->m_iLastQuality = value; |
1545 | 793 return hidden->vt->SetSmth(hidden, value, 0); |
794 } | |
6801 | 795 if (strcasecmp(name, "Brightness") == 0) |
1545 | 796 return hidden->vt->SetSmth2(hidden, value, 0); |
6801 | 797 if (strcasecmp(name, "Contrast") == 0) |
1545 | 798 return hidden->vt->SetSmth3(hidden, value, 0); |
6801 | 799 if (strcasecmp(name, "Saturation") == 0) |
1545 | 800 return hidden->vt->SetSmth4(hidden, value, 0); |
6801 | 801 if (strcasecmp(name, "Hue") == 0) |
1545 | 802 return hidden->vt->SetSmth5(hidden, value, 0); |
6801 | 803 if (strcasecmp(name, "MaxAuto") == 0) |
3059 | 804 { |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
805 this->m_iMaxAuto = value; |
3059 | 806 } |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
807 return 0; |
1545 | 808 } |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
809 #if 0 |
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
810 if (strcmp((const char*)record.dll, "ir50_32.dll") == 0) |
1545 | 811 { |
812 IHidden2* hidden = 0; | |
813 if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, &IID_Iv50Hidden, (void**)&hidden)) | |
814 { | |
3059 | 815 Debug printf("No such interface\n"); |
1545 | 816 return -1; |
817 } | |
818 int recordpar[30]; | |
819 recordpar[0]=0x7c; | |
820 recordpar[1]=fccIV50; | |
821 recordpar[2]=0x10005; | |
822 recordpar[3]=2; | |
823 recordpar[4]=1; | |
824 recordpar[5]=0x80000000; | |
825 if (strcmp(name, "Brightness") == 0) | |
826 { | |
827 recordpar[5]|=0x20; | |
828 recordpar[18]=value; | |
829 } | |
830 else if (strcmp(name, "Saturation") == 0) | |
831 { | |
832 recordpar[5]|=0x40; | |
833 recordpar[19]=value; | |
834 } | |
835 else if (strcmp(name, "Contrast") == 0) | |
836 { | |
837 recordpar[5]|=0x80; | |
838 recordpar[20]=value; | |
839 } | |
840 if(!recordpar[5]) | |
841 { | |
842 hidden->vt->Release((IUnknown*)hidden); | |
843 return -1; | |
844 } | |
845 HRESULT result = hidden->vt->DecodeSet(hidden, recordpar); | |
846 hidden->vt->Release((IUnknown*)hidden); | |
847 | |
848 return result; | |
849 } | |
3957
49290522ab06
SetValue fixed, iv_State=START enabled (silly xine developers disabled for unknown reason)
arpi
parents:
3946
diff
changeset
|
850 #endif |
3978 | 851 // printf("DS_SetValue for ????, name=%s value=%d\n",name,value); |
1545 | 852 return 0; |
853 } | |
854 /* | |
3063 | 855 vim: vi* sux. |
1545 | 856 */ |
3063 | 857 |
858 int DS_SetAttr_DivX(char* attribute, int value){ | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7316
diff
changeset
|
859 int result, status, newkey; |
6801 | 860 if(strcasecmp(attribute, "Quality")==0){ |
3063 | 861 char* keyname="SOFTWARE\\Microsoft\\Scrunch"; |
862 result=RegCreateKeyExA(HKEY_CURRENT_USER, keyname, 0, 0, 0, 0, 0, &newkey, &status); | |
863 if(result!=0) | |
864 { | |
865 printf("VideoDecoder::SetExtAttr: registry failure\n"); | |
866 return -1; | |
867 } | |
868 result=RegSetValueExA(newkey, "Current Post Process Mode", 0, REG_DWORD, &value, 4); | |
869 if(result!=0) | |
870 { | |
871 printf("VideoDecoder::SetExtAttr: error writing value\n"); | |
872 return -1; | |
873 } | |
874 value=-1; | |
875 result=RegSetValueExA(newkey, "Force Post Process Mode", 0, REG_DWORD, &value, 4); | |
876 if(result!=0) | |
877 { | |
878 printf("VideoDecoder::SetExtAttr: error writing value\n"); | |
879 return -1; | |
880 } | |
881 RegCloseKey(newkey); | |
882 return 0; | |
883 } | |
884 | |
885 if( | |
6801 | 886 (strcasecmp(attribute, "Saturation")==0) || |
887 (strcasecmp(attribute, "Hue")==0) || | |
888 (strcasecmp(attribute, "Contrast")==0) || | |
889 (strcasecmp(attribute, "Brightness")==0) | |
3063 | 890 ) |
891 { | |
892 char* keyname="SOFTWARE\\Microsoft\\Scrunch\\Video"; | |
893 result=RegCreateKeyExA(HKEY_CURRENT_USER, keyname, 0, 0, 0, 0, 0, &newkey, &status); | |
894 if(result!=0) | |
895 { | |
896 printf("VideoDecoder::SetExtAttr: registry failure\n"); | |
897 return -1; | |
898 } | |
899 result=RegSetValueExA(newkey, attribute, 0, REG_DWORD, &value, 4); | |
900 if(result!=0) | |
901 { | |
902 printf("VideoDecoder::SetExtAttr: error writing value\n"); | |
903 return -1; | |
904 } | |
905 RegCloseKey(newkey); | |
906 return 0; | |
907 } | |
908 | |
909 printf("Unknown attribute!\n"); | |
910 return -200; | |
911 } | |
912 | |
913 | |
914 | |
915 |