8294
|
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 #include "registry.h"
|
|
11
|
|
12 #ifndef NOAVIFILE_HEADERS
|
|
13 #include "videodecoder.h"
|
|
14 #else
|
|
15 #include "libwin32.h"
|
|
16 #endif
|
|
17 #include "DMO_Filter.h"
|
|
18
|
|
19 #include "DMO_VideoDecoder.h"
|
|
20
|
|
21 struct _DMO_VideoDecoder
|
|
22 {
|
|
23 IVideoDecoder iv;
|
|
24
|
|
25 DMO_Filter* m_pDMO_Filter;
|
|
26 AM_MEDIA_TYPE m_sOurType, m_sDestType;
|
|
27 VIDEOINFOHEADER* m_sVhdr;
|
|
28 VIDEOINFOHEADER* m_sVhdr2;
|
|
29 int m_Caps;//CAPS m_Caps; // capabilities of DirectShow decoder
|
|
30 int m_iLastQuality; // remember last quality as integer
|
|
31 int m_iMinBuffers;
|
|
32 int m_iMaxAuto;
|
|
33 };
|
|
34
|
|
35 //#include "DMO_VideoDecoder.h"
|
|
36
|
|
37 #include "../wine/winerror.h"
|
|
38
|
|
39 #ifndef NOAVIFILE_HEADERS
|
|
40 #define VFW_E_NOT_RUNNING 0x80040226
|
|
41 #include "fourcc.h"
|
|
42 #include "except.h"
|
|
43 #endif
|
|
44
|
|
45 #include <unistd.h>
|
|
46 #include <fcntl.h>
|
|
47 #include <errno.h>
|
|
48 #include <sys/types.h>
|
|
49 #include <sys/mman.h>
|
|
50 #include <stdio.h>
|
|
51 #include <stdlib.h> // labs
|
|
52
|
|
53 // strcmp((const char*)info.dll,...) is used instead of (... == ...)
|
|
54 // so Arpi could use char* pointer in his simplified DMO_VideoDecoder class
|
|
55
|
|
56 #define __MODULE__ "DirectShow_VideoDecoder"
|
|
57
|
|
58 #define false 0
|
|
59 #define true 1
|
|
60
|
|
61
|
|
62 //int DMO_VideoDecoder_GetCapabilities(DMO_VideoDecoder *this){return this->m_Caps;}
|
|
63
|
|
64 typedef struct _ct ct;
|
|
65
|
|
66 struct _ct {
|
|
67 fourcc_t fcc;
|
|
68 unsigned int bits;
|
|
69 const GUID* subtype;
|
|
70 int cap;
|
|
71 };
|
|
72
|
|
73 static ct check[] = {
|
|
74 { fccI420, 12, &MEDIASUBTYPE_I420, CAP_I420 },
|
|
75 { fccYV12, 12, &MEDIASUBTYPE_YV12, CAP_YV12 },
|
|
76 { fccYUY2, 16, &MEDIASUBTYPE_YUY2, CAP_YUY2 },
|
|
77 { fccUYVY, 16, &MEDIASUBTYPE_UYVY, CAP_UYVY },
|
|
78 { fccYVYU, 16, &MEDIASUBTYPE_YVYU, CAP_YVYU },
|
|
79 { fccIYUV, 24, &MEDIASUBTYPE_IYUV, CAP_IYUV },
|
|
80
|
|
81 { 8, 8, &MEDIASUBTYPE_RGB8, CAP_NONE },
|
|
82 { 15, 16, &MEDIASUBTYPE_RGB555, CAP_NONE },
|
|
83 { 16, 16, &MEDIASUBTYPE_RGB565, CAP_NONE },
|
|
84 { 24, 24, &MEDIASUBTYPE_RGB24, CAP_NONE },
|
|
85 { 32, 32, &MEDIASUBTYPE_RGB32, CAP_NONE },
|
|
86
|
|
87 {0},
|
|
88 };
|
|
89
|
|
90 DMO_VideoDecoder * DMO_VideoDecoder_Open(char* dllname, GUID* guid, BITMAPINFOHEADER * format, int flip, int maxauto)
|
|
91 {
|
|
92 DMO_VideoDecoder *this;
|
|
93 HRESULT result;
|
|
94 ct* c;
|
|
95
|
|
96 this = malloc(sizeof(DMO_VideoDecoder));
|
|
97 memset( this, 0, sizeof(DMO_VideoDecoder));
|
|
98
|
|
99 this->m_sVhdr2 = 0;
|
|
100 this->m_iLastQuality = -1;
|
|
101 this->m_iMaxAuto = maxauto;
|
|
102
|
|
103 Setup_LDT_Keeper();
|
|
104
|
|
105 //memset(&m_obh, 0, sizeof(m_obh));
|
|
106 //m_obh.biSize = sizeof(m_obh);
|
|
107 /*try*/
|
|
108 {
|
|
109 unsigned int bihs;
|
|
110
|
|
111 bihs = (format->biSize < (int) sizeof(BITMAPINFOHEADER)) ?
|
|
112 sizeof(BITMAPINFOHEADER) : format->biSize;
|
|
113
|
|
114 this->iv.m_bh = (BITMAPINFOHEADER*)malloc(bihs);
|
|
115 memcpy(this->iv.m_bh, format, bihs);
|
|
116
|
|
117 this->iv.m_State = STOP;
|
|
118 //this->iv.m_pFrame = 0;
|
|
119 this->iv.m_Mode = DIRECT;
|
|
120 this->iv.m_iDecpos = 0;
|
|
121 this->iv.m_iPlaypos = -1;
|
|
122 this->iv.m_fQuality = 0.0f;
|
|
123 this->iv.m_bCapable16b = true;
|
|
124
|
|
125 bihs += sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER);
|
|
126 this->m_sVhdr = (VIDEOINFOHEADER*)malloc(bihs);
|
|
127 memset(this->m_sVhdr, 0, bihs);
|
|
128 memcpy(&this->m_sVhdr->bmiHeader, this->iv.m_bh, this->iv.m_bh->biSize);
|
|
129 this->m_sVhdr->rcSource.left = this->m_sVhdr->rcSource.top = 0;
|
|
130 this->m_sVhdr->rcSource.right = this->m_sVhdr->bmiHeader.biWidth;
|
|
131 this->m_sVhdr->rcSource.bottom = this->m_sVhdr->bmiHeader.biHeight;
|
|
132 //this->m_sVhdr->rcSource.right = 0;
|
|
133 //this->m_sVhdr->rcSource.bottom = 0;
|
|
134 this->m_sVhdr->rcTarget = this->m_sVhdr->rcSource;
|
|
135
|
|
136 this->m_sOurType.majortype = MEDIATYPE_Video;
|
|
137 this->m_sOurType.subtype = MEDIATYPE_Video;
|
|
138 this->m_sOurType.subtype.f1 = this->m_sVhdr->bmiHeader.biCompression;
|
|
139 this->m_sOurType.formattype = FORMAT_VideoInfo;
|
|
140 this->m_sOurType.bFixedSizeSamples = false;
|
|
141 this->m_sOurType.bTemporalCompression = true;
|
|
142 this->m_sOurType.pUnk = 0;
|
|
143 this->m_sOurType.cbFormat = bihs;
|
|
144 this->m_sOurType.pbFormat = (char*)this->m_sVhdr;
|
|
145
|
|
146 this->m_sVhdr2 = (VIDEOINFOHEADER*)(malloc(sizeof(VIDEOINFOHEADER)+12));
|
|
147 memcpy(this->m_sVhdr2, this->m_sVhdr, sizeof(VIDEOINFOHEADER));
|
|
148 memset((char*)this->m_sVhdr2 + sizeof(VIDEOINFOHEADER), 0, 12);
|
|
149 this->m_sVhdr2->bmiHeader.biCompression = 0;
|
|
150 this->m_sVhdr2->bmiHeader.biBitCount = 24;
|
|
151
|
|
152 // memset((char*)this->m_sVhdr2, 0, sizeof(VIDEOINFOHEADER)+12);
|
|
153 this->m_sVhdr2->rcTarget = this->m_sVhdr->rcTarget;
|
|
154 // this->m_sVhdr2->rcSource = this->m_sVhdr->rcSource;
|
|
155
|
|
156 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType));
|
|
157 this->m_sDestType.majortype = MEDIATYPE_Video;
|
|
158 this->m_sDestType.subtype = MEDIASUBTYPE_RGB24;
|
|
159 this->m_sDestType.formattype = FORMAT_VideoInfo;
|
|
160 this->m_sDestType.bFixedSizeSamples = true;
|
|
161 this->m_sDestType.bTemporalCompression = false;
|
|
162 this->m_sDestType.lSampleSize = labs(this->m_sVhdr2->bmiHeader.biWidth*this->m_sVhdr2->bmiHeader.biHeight
|
|
163 * ((this->m_sVhdr2->bmiHeader.biBitCount + 7) / 8));
|
|
164 this->m_sVhdr2->bmiHeader.biSizeImage = this->m_sDestType.lSampleSize;
|
|
165 this->m_sDestType.pUnk = 0;
|
|
166 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER);
|
|
167 this->m_sDestType.pbFormat = (char*)this->m_sVhdr2;
|
|
168
|
|
169 memset(&this->iv.m_obh, 0, sizeof(this->iv.m_obh));
|
|
170 memcpy(&this->iv.m_obh, this->iv.m_bh, sizeof(this->iv.m_obh) < (unsigned) this->iv.m_bh->biSize
|
|
171 ? sizeof(this->iv.m_obh) : (unsigned) this->iv.m_bh->biSize);
|
|
172 this->iv.m_obh.biBitCount=24;
|
|
173 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER);
|
|
174 this->iv.m_obh.biCompression = 0; //BI_RGB
|
|
175 //this->iv.m_obh.biHeight = labs(this->iv.m_obh.biHeight);
|
|
176 this->iv.m_obh.biSizeImage = labs(this->iv.m_obh.biWidth * this->iv.m_obh.biHeight)
|
|
177 * ((this->iv.m_obh.biBitCount + 7) / 8);
|
|
178
|
|
179
|
|
180 this->m_pDMO_Filter = DMO_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType);
|
|
181
|
|
182 if (!this->m_pDMO_Filter)
|
|
183 {
|
|
184 printf("Failed to create DMO filter\n");
|
|
185 return 0;
|
|
186 }
|
|
187
|
|
188 if (!flip)
|
|
189 {
|
|
190 this->iv.m_obh.biHeight *= -1;
|
|
191 this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight;
|
|
192 // result = this->m_pDMO_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDMO_Filter->m_pOutputPin, &this->m_sDestType);
|
|
193 result = this->m_pDMO_Filter->m_pMedia->vt->SetOutputType(this->m_pDMO_Filter->m_pMedia, 0, &this->m_sDestType, DMO_SET_TYPEF_TEST_ONLY);
|
|
194 if (result)
|
|
195 {
|
|
196 printf("Decoder does not support upside-down RGB frames\n");
|
|
197 this->iv.m_obh.biHeight *= -1;
|
|
198 this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight;
|
|
199 }
|
|
200 }
|
|
201
|
|
202 memcpy( &this->iv.m_decoder, &this->iv.m_obh, sizeof(this->iv.m_obh) );
|
|
203
|
|
204 switch (this->iv.m_bh->biCompression)
|
|
205 {
|
|
206 #if 0
|
|
207 case fccDIV3:
|
|
208 case fccDIV4:
|
|
209 case fccDIV5:
|
|
210 case fccDIV6:
|
|
211 case fccMP42:
|
|
212 case fccWMV2:
|
|
213 //YV12 seems to be broken for DivX :-) codec
|
|
214 // case fccIV50:
|
|
215 //produces incorrect picture
|
|
216 //m_Caps = (CAPS) (m_Caps & ~CAP_YV12);
|
|
217 //m_Caps = CAP_UYVY;//CAP_YUY2; // | CAP_I420;
|
|
218 //m_Caps = CAP_I420;
|
|
219 this->m_Caps = (CAP_YUY2 | CAP_UYVY);
|
|
220 break;
|
|
221 #endif
|
|
222 default:
|
|
223
|
|
224 this->m_Caps = CAP_NONE;
|
|
225
|
|
226 printf("Decoder supports the following YUV formats: ");
|
|
227 for (c = check; c->bits; c++)
|
|
228 {
|
|
229 this->m_sVhdr2->bmiHeader.biBitCount = c->bits;
|
|
230 this->m_sVhdr2->bmiHeader.biCompression = c->fcc;
|
|
231 this->m_sDestType.subtype = *c->subtype;
|
|
232 //result = this->m_pDMO_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDMO_Filter->m_pOutputPin, &this->m_sDestType);
|
|
233 result = this->m_pDMO_Filter->m_pMedia->vt->SetOutputType(this->m_pDMO_Filter->m_pMedia, 0, &this->m_sDestType, DMO_SET_TYPEF_TEST_ONLY);
|
|
234 if (!result)
|
|
235 {
|
|
236 this->m_Caps = (this->m_Caps | c->cap);
|
|
237 printf("%.4s ", &c->fcc);
|
|
238 }
|
|
239 }
|
|
240 printf("\n");
|
|
241 }
|
|
242
|
|
243 if (this->m_Caps != CAP_NONE)
|
|
244 printf("Decoder is capable of YUV output (flags 0x%x)\n", (int)this->m_Caps);
|
|
245
|
|
246 this->m_sVhdr2->bmiHeader.biBitCount = 24;
|
|
247 this->m_sVhdr2->bmiHeader.biCompression = 0;
|
|
248 this->m_sDestType.subtype = MEDIASUBTYPE_RGB24;
|
|
249
|
|
250 this->m_iMinBuffers = this->iv.VBUFSIZE;
|
|
251 }
|
|
252 /*catch (FatalError& error)
|
|
253 {
|
|
254 delete[] m_sVhdr;
|
|
255 delete[] m_sVhdr2;
|
|
256 delete m_pDMO_Filter;
|
|
257 throw;
|
|
258 }*/
|
|
259 return this;
|
|
260 }
|
|
261
|
|
262 void DMO_VideoDecoder_Destroy(DMO_VideoDecoder *this)
|
|
263 {
|
|
264 DMO_VideoDecoder_StopInternal(this);
|
|
265 this->iv.m_State = STOP;
|
|
266 free(this->m_sVhdr);
|
|
267 free(this->m_sVhdr2);
|
|
268 DMO_Filter_Destroy(this->m_pDMO_Filter);
|
|
269 }
|
|
270
|
|
271 void DMO_VideoDecoder_StartInternal(DMO_VideoDecoder *this)
|
|
272 {
|
|
273 #if 0
|
|
274 ALLOCATOR_PROPERTIES props, props1;
|
|
275 Debug printf("DMO_VideoDecoder_StartInternal\n");
|
|
276 //cout << "DSSTART" << endl;
|
|
277 this->m_pDMO_Filter->Start(this->m_pDMO_Filter);
|
|
278
|
|
279 props.cBuffers = 1;
|
|
280 props.cbBuffer = this->m_sDestType.lSampleSize;
|
|
281
|
|
282 //don't know how to do this correctly
|
|
283 props.cbAlign = props.cbPrefix = 0;
|
|
284 this->m_pDMO_Filter->m_pAll->vt->SetProperties(this->m_pDMO_Filter->m_pAll, &props, &props1);
|
|
285 this->m_pDMO_Filter->m_pAll->vt->Commit(this->m_pDMO_Filter->m_pAll);
|
|
286 #endif
|
|
287 this->iv.m_State = START;
|
|
288 }
|
|
289
|
|
290 void DMO_VideoDecoder_StopInternal(DMO_VideoDecoder *this)
|
|
291 {
|
|
292 // this->m_pDMO_Filter->Stop(this->m_pDMO_Filter);
|
|
293 //??? why was this here ??? m_pOurOutput->SetFramePointer(0);
|
|
294 }
|
|
295
|
|
296 int DMO_VideoDecoder_DecodeInternal(DMO_VideoDecoder *this, const void* src, int size, int is_keyframe, char* imdata)
|
|
297 {
|
|
298 // IMediaSample* sample = 0;
|
|
299 char* ptr;
|
|
300 int result;
|
|
301 unsigned long status; // to be ignored by M$ specs
|
|
302 DMO_OUTPUT_DATA_BUFFER db;
|
|
303 CMediaBuffer* bufferin;
|
|
304 //+ uint8_t* imdata = dest ? dest->Data() : 0;
|
|
305
|
|
306 Debug printf("DMO_VideoDecoder_DecodeInternal(%p,%p,%d,%d,%p)\n",this,src,size,is_keyframe,imdata);
|
|
307
|
|
308 // this->m_pDMO_Filter->m_pAll->vt->GetBuffer(this->m_pDMO_Filter->m_pAll, &sample, 0, 0, 0);
|
|
309 // if (!sample)
|
|
310 // {
|
|
311 // Debug printf("ERROR: null sample\n");
|
|
312 // return -1;
|
|
313 // }
|
|
314
|
|
315 Setup_FS_Segment();
|
|
316
|
|
317 bufferin = CMediaBufferCreate(size, (void*)src, size, 0);
|
|
318 result = this->m_pDMO_Filter->m_pMedia->vt->ProcessInput(this->m_pDMO_Filter->m_pMedia, 0,
|
|
319 (IMediaBuffer*)bufferin,
|
|
320 (is_keyframe) ? DMO_INPUT_DATA_BUFFERF_SYNCPOINT : 0,
|
|
321 0, 0);
|
|
322 ((IMediaBuffer*)bufferin)->vt->Release((IUnknown*)bufferin);
|
|
323
|
|
324 if (result != S_OK)
|
|
325 {
|
|
326 /* something for process */
|
|
327 if (result != S_FALSE)
|
|
328 printf("ProcessInputError r:0x%x=%d (keyframe: %d)\n", result, result, is_keyframe);
|
|
329 else
|
|
330 printf("ProcessInputError FALSE ?? (keyframe: %d)\n", is_keyframe);
|
|
331 return size;
|
|
332 }
|
|
333
|
|
334 db.rtTimestamp = 0;
|
|
335 db.rtTimelength = 0;
|
|
336 db.dwStatus = 0;
|
|
337 db.pBuffer = (IMediaBuffer*) CMediaBufferCreate(this->m_sDestType.lSampleSize,
|
|
338 imdata, 0, 0);
|
|
339 result = this->m_pDMO_Filter->m_pMedia->vt->ProcessOutput(this->m_pDMO_Filter->m_pMedia,
|
|
340 (imdata) ? 0 : DMO_PROCESS_OUTPUT_DISCARD_WHEN_NO_BUFFER,
|
|
341 1, &db, &status);
|
|
342 //m_pDMO_Filter->m_pMedia->vt->Lock(m_pDMO_Filter->m_pMedia, 0);
|
|
343 if ((unsigned)result == DMO_E_NOTACCEPTING)
|
|
344 printf("ProcessOutputError: Not accepting\n");
|
|
345 else if (result)
|
|
346 printf("ProcessOutputError: r:0x%x=%d %ld stat:%ld\n", result, result, status, db.dwStatus);
|
|
347
|
|
348 ((IMediaBuffer*)db.pBuffer)->vt->Release((IUnknown*)db.pBuffer);
|
|
349
|
|
350 //int r = m_pDMO_Filter->m_pMedia->vt->Flush(m_pDMO_Filter->m_pMedia);
|
|
351 //printf("FLUSH %d\n", r);
|
|
352
|
|
353 return 0;
|
|
354 }
|
|
355
|
|
356 /*
|
|
357 * bits == 0 - leave unchanged
|
|
358 */
|
|
359 //int SetDestFmt(DMO_VideoDecoder * this, int bits = 24, fourcc_t csp = 0);
|
|
360 int DMO_VideoDecoder_SetDestFmt(DMO_VideoDecoder *this, int bits, unsigned int csp)
|
|
361 {
|
|
362 HRESULT result;
|
|
363 int should_test=1;
|
|
364 int stoped = 0;
|
|
365
|
|
366 Debug printf("DMO_VideoDecoder_SetDestFmt (%p, %d, %d)\n",this,bits,(int)csp);
|
|
367
|
|
368 /* if (!CImage::Supported(csp, bits))
|
|
369 return -1;
|
|
370 */
|
|
371 // BitmapInfo temp = m_obh;
|
|
372
|
|
373 if (!csp) // RGB
|
|
374 {
|
|
375 int ok = true;
|
|
376
|
|
377 switch (bits)
|
|
378 {
|
|
379 case 15:
|
|
380 this->m_sDestType.subtype = MEDIASUBTYPE_RGB555;
|
|
381 break;
|
|
382 case 16:
|
|
383 this->m_sDestType.subtype = MEDIASUBTYPE_RGB565;
|
|
384 break;
|
|
385 case 24:
|
|
386 this->m_sDestType.subtype = MEDIASUBTYPE_RGB24;
|
|
387 break;
|
|
388 case 32:
|
|
389 this->m_sDestType.subtype = MEDIASUBTYPE_RGB32;
|
|
390 break;
|
|
391 default:
|
|
392 ok = false;
|
|
393 break;
|
|
394 }
|
|
395
|
|
396 if (ok) {
|
|
397 this->iv.m_obh.biBitCount=bits;
|
|
398 if( bits == 15 || bits == 16 ) {
|
|
399 this->iv.m_obh.biSize=sizeof(BITMAPINFOHEADER)+12;
|
|
400 this->iv.m_obh.biCompression=3;//BI_BITFIELDS
|
|
401 this->iv.m_obh.biSizeImage=abs((int)(2*this->iv.m_obh.biWidth*this->iv.m_obh.biHeight));
|
|
402 }
|
|
403
|
|
404 if( bits == 16 ) {
|
|
405 this->iv.m_obh.colors[0]=0xF800;
|
|
406 this->iv.m_obh.colors[1]=0x07E0;
|
|
407 this->iv.m_obh.colors[2]=0x001F;
|
|
408 } else if ( bits == 15 ) {
|
|
409 this->iv.m_obh.colors[0]=0x7C00;
|
|
410 this->iv.m_obh.colors[1]=0x03E0;
|
|
411 this->iv.m_obh.colors[2]=0x001F;
|
|
412 } else {
|
|
413 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER);
|
|
414 this->iv.m_obh.biCompression = 0; //BI_RGB
|
|
415 //this->iv.m_obh.biHeight = labs(this->iv.m_obh.biHeight);
|
|
416 this->iv.m_obh.biSizeImage = labs(this->iv.m_obh.biWidth * this->iv.m_obh.biHeight)
|
|
417 * ((this->iv.m_obh.biBitCount + 7) / 8);
|
|
418 }
|
|
419 }
|
|
420 //.biSizeImage=abs(temp.biWidth*temp.biHeight*((temp.biBitCount+7)/8));
|
|
421 } else
|
|
422 { // YUV
|
|
423 int ok = true;
|
|
424 switch (csp)
|
|
425 {
|
|
426 case fccYUY2:
|
|
427 this->m_sDestType.subtype = MEDIASUBTYPE_YUY2;
|
|
428 break;
|
|
429 case fccYV12:
|
|
430 this->m_sDestType.subtype = MEDIASUBTYPE_YV12;
|
|
431 break;
|
|
432 case fccIYUV:
|
|
433 this->m_sDestType.subtype = MEDIASUBTYPE_IYUV;
|
|
434 break;
|
|
435 case fccI420:
|
|
436 this->m_sDestType.subtype = MEDIASUBTYPE_I420;
|
|
437 break;
|
|
438 case fccUYVY:
|
|
439 this->m_sDestType.subtype = MEDIASUBTYPE_UYVY;
|
|
440 break;
|
|
441 case fccYVYU:
|
|
442 this->m_sDestType.subtype = MEDIASUBTYPE_YVYU;
|
|
443 break;
|
|
444 case fccYVU9:
|
|
445 this->m_sDestType.subtype = MEDIASUBTYPE_YVU9;
|
|
446 default:
|
|
447 ok = false;
|
|
448 break;
|
|
449 }
|
|
450
|
|
451 if (ok) {
|
|
452 if (csp != 0 && csp != 3 && this->iv.m_obh.biHeight > 0)
|
|
453 this->iv.m_obh.biHeight *= -1; // YUV formats uses should have height < 0
|
|
454 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER);
|
|
455 this->iv.m_obh.biCompression=csp;
|
|
456 this->iv.m_obh.biBitCount=bits;
|
|
457 this->iv.m_obh.biSizeImage=labs(this->iv.m_obh.biBitCount*
|
|
458 this->iv.m_obh.biWidth*this->iv.m_obh.biHeight)>>3;
|
|
459 }
|
|
460 }
|
|
461 this->m_sDestType.lSampleSize = this->iv.m_obh.biSizeImage;
|
|
462 memcpy(&(this->m_sVhdr2->bmiHeader), &this->iv.m_obh, sizeof(this->iv.m_obh));
|
|
463 this->m_sVhdr2->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
464 if (this->m_sVhdr2->bmiHeader.biCompression == 3)
|
|
465 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER) + 12;
|
|
466 else
|
|
467 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER);
|
|
468
|
|
469
|
|
470 switch(csp)
|
|
471 {
|
|
472 case fccYUY2:
|
|
473 if(!(this->m_Caps & CAP_YUY2))
|
|
474 should_test=false;
|
|
475 break;
|
|
476 case fccYV12:
|
|
477 if(!(this->m_Caps & CAP_YV12))
|
|
478 should_test=false;
|
|
479 break;
|
|
480 case fccIYUV:
|
|
481 if(!(this->m_Caps & CAP_IYUV))
|
|
482 should_test=false;
|
|
483 break;
|
|
484 case fccI420:
|
|
485 if(!(this->m_Caps & CAP_I420))
|
|
486 should_test=false;
|
|
487 break;
|
|
488 case fccUYVY:
|
|
489 if(!(this->m_Caps & CAP_UYVY))
|
|
490 should_test=false;
|
|
491 break;
|
|
492 case fccYVYU:
|
|
493 if(!(this->m_Caps & CAP_YVYU))
|
|
494 should_test=false;
|
|
495 break;
|
|
496 case fccYVU9:
|
|
497 if(!(this->m_Caps & CAP_YVU9))
|
|
498 should_test=false;
|
|
499 break;
|
|
500 }
|
|
501
|
|
502 Setup_FS_Segment();
|
|
503
|
|
504 // if(should_test)
|
|
505 // result = this->m_pDMO_Filter->m_pOutputPin->vt->QueryAccept(this->m_pDMO_Filter->m_pOutputPin, &this->m_sDestType);
|
|
506 // else
|
|
507 // result = -1;
|
|
508
|
|
509 // test accept
|
|
510 if(!this->m_pDMO_Filter) return 0;
|
|
511 result = this->m_pDMO_Filter->m_pMedia->vt->SetOutputType(this->m_pDMO_Filter->m_pMedia, 0, &this->m_sDestType, DMO_SET_TYPEF_TEST_ONLY);
|
|
512
|
|
513 if (result != 0)
|
|
514 {
|
|
515 if (csp)
|
|
516 printf("Warning: unsupported color space\n");
|
|
517 else
|
|
518 printf("Warning: unsupported bit depth\n");
|
|
519
|
|
520 this->m_sDestType.lSampleSize = this->iv.m_decoder.biSizeImage;
|
|
521 memcpy(&(this->m_sVhdr2->bmiHeader), &this->iv.m_decoder, sizeof(this->iv.m_decoder));
|
|
522 this->m_sVhdr2->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
523 if (this->m_sVhdr2->bmiHeader.biCompression == 3)
|
|
524 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER) + 12;
|
|
525 else
|
|
526 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER);
|
|
527
|
|
528 return -1;
|
|
529 }
|
|
530
|
|
531 memcpy( &this->iv.m_decoder, &this->iv.m_obh, sizeof(this->iv.m_obh));
|
|
532
|
|
533 // m_obh=temp;
|
|
534 // if(csp)
|
|
535 // m_obh.biBitCount=BitmapInfo::BitCount(csp);
|
|
536 this->iv.m_bh->biBitCount = bits;
|
|
537
|
|
538 //DMO_VideoDecoder_Restart(this);
|
|
539
|
|
540 this->m_pDMO_Filter->m_pMedia->vt->SetOutputType(this->m_pDMO_Filter->m_pMedia, 0, &this->m_sDestType, 0);
|
|
541
|
|
542 return 0;
|
|
543 }
|
|
544
|
|
545
|
|
546 int DMO_VideoDecoder_SetDirection(DMO_VideoDecoder *this, int d)
|
|
547 {
|
|
548 this->iv.m_obh.biHeight = (d) ? this->iv.m_bh->biHeight : -this->iv.m_bh->biHeight;
|
|
549 this->m_sVhdr2->bmiHeader.biHeight = this->iv.m_obh.biHeight;
|
|
550 return 0;
|
|
551 }
|
|
552
|