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