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