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