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