comparison loader/dshow/DS_VideoDecoder.c @ 29263:0f1b5b68af32

whitespace cosmetics: Remove all trailing whitespace.
author diego
date Wed, 13 May 2009 02:58:57 +0000
parents f20a11161e62
children 008338d7679f
comparison
equal deleted inserted replaced
29262:7d545a6b8aff 29263:0f1b5b68af32
12 #include "DS_Filter.h" 12 #include "DS_Filter.h"
13 13
14 struct DS_VideoDecoder 14 struct DS_VideoDecoder
15 { 15 {
16 IVideoDecoder iv; 16 IVideoDecoder iv;
17 17
18 DS_Filter* m_pDS_Filter; 18 DS_Filter* m_pDS_Filter;
19 AM_MEDIA_TYPE m_sOurType, m_sDestType; 19 AM_MEDIA_TYPE m_sOurType, m_sDestType;
20 VIDEOINFOHEADER* m_sVhdr; 20 VIDEOINFOHEADER* m_sVhdr;
21 VIDEOINFOHEADER* m_sVhdr2; 21 VIDEOINFOHEADER* m_sVhdr2;
22 int m_Caps;//CAPS m_Caps; // capabilities of DirectShow decoder 22 int m_Caps;//CAPS m_Caps; // capabilities of DirectShow decoder
51 #define false 0 51 #define false 0
52 #define true 1 52 #define true 1
53 53
54 int DS_VideoDecoder_GetCapabilities(DS_VideoDecoder *this) 54 int DS_VideoDecoder_GetCapabilities(DS_VideoDecoder *this)
55 {return this->m_Caps;} 55 {return this->m_Caps;}
56 56
57 typedef struct ct ct; 57 typedef struct ct ct;
58 58
59 struct ct { 59 struct ct {
60 unsigned int bits; 60 unsigned int bits;
61 fourcc_t fcc; 61 fourcc_t fcc;
62 const GUID *subtype; 62 const GUID *subtype;
63 int cap; 63 int cap;
64 }; 64 };
65 65
66 static ct check[] = { 66 static ct check[] = {
67 {16, fccYUY2, &MEDIASUBTYPE_YUY2, CAP_YUY2}, 67 {16, fccYUY2, &MEDIASUBTYPE_YUY2, CAP_YUY2},
68 {12, fccIYUV, &MEDIASUBTYPE_IYUV, CAP_IYUV}, 68 {12, fccIYUV, &MEDIASUBTYPE_IYUV, CAP_IYUV},
69 {16, fccUYVY, &MEDIASUBTYPE_UYVY, CAP_UYVY}, 69 {16, fccUYVY, &MEDIASUBTYPE_UYVY, CAP_UYVY},
70 {12, fccYV12, &MEDIASUBTYPE_YV12, CAP_YV12}, 70 {12, fccYV12, &MEDIASUBTYPE_YV12, CAP_YV12},
79 DS_VideoDecoder * DS_VideoDecoder_Open(char* dllname, GUID* guid, BITMAPINFOHEADER * format, int flip, int maxauto) 79 DS_VideoDecoder * DS_VideoDecoder_Open(char* dllname, GUID* guid, BITMAPINFOHEADER * format, int flip, int maxauto)
80 { 80 {
81 DS_VideoDecoder *this; 81 DS_VideoDecoder *this;
82 HRESULT result; 82 HRESULT result;
83 ct* c; 83 ct* c;
84 84
85 this = malloc(sizeof(DS_VideoDecoder)); 85 this = malloc(sizeof(DS_VideoDecoder));
86 memset( this, 0, sizeof(DS_VideoDecoder)); 86 memset( this, 0, sizeof(DS_VideoDecoder));
87 87
88 this->m_sVhdr2 = 0; 88 this->m_sVhdr2 = 0;
89 this->m_iLastQuality = -1; 89 this->m_iLastQuality = -1;
90 this->m_iMaxAuto = maxauto; 90 this->m_iMaxAuto = maxauto;
91 91
92 #ifdef WIN32_LOADER 92 #ifdef WIN32_LOADER
96 //memset(&m_obh, 0, sizeof(m_obh)); 96 //memset(&m_obh, 0, sizeof(m_obh));
97 //m_obh.biSize = sizeof(m_obh); 97 //m_obh.biSize = sizeof(m_obh);
98 /*try*/ 98 /*try*/
99 { 99 {
100 unsigned int bihs; 100 unsigned int bihs;
101 101
102 bihs = (format->biSize < (int) sizeof(BITMAPINFOHEADER)) ? 102 bihs = (format->biSize < (int) sizeof(BITMAPINFOHEADER)) ?
103 sizeof(BITMAPINFOHEADER) : format->biSize; 103 sizeof(BITMAPINFOHEADER) : format->biSize;
104 104
105 this->iv.m_bh = malloc(bihs); 105 this->iv.m_bh = malloc(bihs);
106 memcpy(this->iv.m_bh, format, bihs); 106 memcpy(this->iv.m_bh, format, bihs);
107 this->iv.m_bh->biSize = bihs; 107 this->iv.m_bh->biSize = bihs;
108 108
109 this->iv.m_State = STOP; 109 this->iv.m_State = STOP;
111 this->iv.m_Mode = DIRECT; 111 this->iv.m_Mode = DIRECT;
112 this->iv.m_iDecpos = 0; 112 this->iv.m_iDecpos = 0;
113 this->iv.m_iPlaypos = -1; 113 this->iv.m_iPlaypos = -1;
114 this->iv.m_fQuality = 0.0f; 114 this->iv.m_fQuality = 0.0f;
115 this->iv.m_bCapable16b = true; 115 this->iv.m_bCapable16b = true;
116 116
117 bihs += sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER); 117 bihs += sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER);
118 this->m_sVhdr = malloc(bihs); 118 this->m_sVhdr = malloc(bihs);
119 memset(this->m_sVhdr, 0, bihs); 119 memset(this->m_sVhdr, 0, bihs);
120 memcpy(&this->m_sVhdr->bmiHeader, this->iv.m_bh, this->iv.m_bh->biSize); 120 memcpy(&this->m_sVhdr->bmiHeader, this->iv.m_bh, this->iv.m_bh->biSize);
121 this->m_sVhdr->rcSource.left = this->m_sVhdr->rcSource.top = 0; 121 this->m_sVhdr->rcSource.left = this->m_sVhdr->rcSource.top = 0;
151 * ((this->m_sVhdr2->bmiHeader.biBitCount + 7) / 8)); 151 * ((this->m_sVhdr2->bmiHeader.biBitCount + 7) / 8));
152 this->m_sVhdr2->bmiHeader.biSizeImage = this->m_sDestType.lSampleSize; 152 this->m_sVhdr2->bmiHeader.biSizeImage = this->m_sDestType.lSampleSize;
153 this->m_sDestType.pUnk = 0; 153 this->m_sDestType.pUnk = 0;
154 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); 154 this->m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER);
155 this->m_sDestType.pbFormat = (char*)this->m_sVhdr2; 155 this->m_sDestType.pbFormat = (char*)this->m_sVhdr2;
156 156
157 memset(&this->iv.m_obh, 0, sizeof(this->iv.m_obh)); 157 memset(&this->iv.m_obh, 0, sizeof(this->iv.m_obh));
158 memcpy(&this->iv.m_obh, this->iv.m_bh, sizeof(this->iv.m_obh) < (unsigned) this->iv.m_bh->biSize 158 memcpy(&this->iv.m_obh, this->iv.m_bh, sizeof(this->iv.m_obh) < (unsigned) this->iv.m_bh->biSize
159 ? sizeof(this->iv.m_obh) : (unsigned) this->iv.m_bh->biSize); 159 ? sizeof(this->iv.m_obh) : (unsigned) this->iv.m_bh->biSize);
160 this->iv.m_obh.biBitCount=24; 160 this->iv.m_obh.biBitCount=24;
161 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER); 161 this->iv.m_obh.biSize = sizeof(BITMAPINFOHEADER);
164 this->iv.m_obh.biSizeImage = labs(this->iv.m_obh.biWidth * this->iv.m_obh.biHeight) 164 this->iv.m_obh.biSizeImage = labs(this->iv.m_obh.biWidth * this->iv.m_obh.biHeight)
165 * ((this->iv.m_obh.biBitCount + 7) / 8); 165 * ((this->iv.m_obh.biBitCount + 7) / 8);
166 166
167 167
168 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData); 168 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData);
169 169
170 if (!this->m_pDS_Filter) 170 if (!this->m_pDS_Filter)
171 { 171 {
172 printf("Failed to create DirectShow filter\n"); 172 printf("Failed to create DirectShow filter\n");
173 return 0; 173 return 0;
174 } 174 }
205 //m_Caps = CAP_I420; 205 //m_Caps = CAP_I420;
206 this->m_Caps = (CAP_YUY2 | CAP_UYVY); 206 this->m_Caps = (CAP_YUY2 | CAP_UYVY);
207 break; 207 break;
208 #endif 208 #endif
209 default: 209 default:
210 210
211 this->m_Caps = CAP_NONE; 211 this->m_Caps = CAP_NONE;
212 212
213 printf("Decoder supports the following YUV formats: "); 213 printf("Decoder supports the following YUV formats: ");
214 for (c = check; c->bits; c++) 214 for (c = check; c->bits; c++)
215 { 215 {
267 { 267 {
268 Debug printf("DS_VideoDecoder_StartInternal\n"); 268 Debug printf("DS_VideoDecoder_StartInternal\n");
269 //cout << "DSSTART" << endl; 269 //cout << "DSSTART" << endl;
270 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); 270 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll);
271 this->m_pDS_Filter->Start(this->m_pDS_Filter); 271 this->m_pDS_Filter->Start(this->m_pDS_Filter);
272 272
273 this->iv.m_State = START; 273 this->iv.m_State = START;
274 } 274 }
275 275
276 void DS_VideoDecoder_StopInternal(DS_VideoDecoder *this) 276 void DS_VideoDecoder_StopInternal(DS_VideoDecoder *this)
277 { 277 {
282 int DS_VideoDecoder_DecodeInternal(DS_VideoDecoder *this, const void* src, int size, int is_keyframe, char* pImage) 282 int DS_VideoDecoder_DecodeInternal(DS_VideoDecoder *this, const void* src, int size, int is_keyframe, char* pImage)
283 { 283 {
284 IMediaSample* sample = 0; 284 IMediaSample* sample = 0;
285 char* ptr; 285 char* ptr;
286 int result; 286 int result;
287 287
288 Debug printf("DS_VideoDecoder_DecodeInternal(%p,%p,%d,%d,%p)\n",this,src,size,is_keyframe,pImage); 288 Debug printf("DS_VideoDecoder_DecodeInternal(%p,%p,%d,%d,%p)\n",this,src,size,is_keyframe,pImage);
289 289
290 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); 290 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0);
291 291
292 if (!sample) 292 if (!sample)
293 { 293 {
294 Debug printf("ERROR: null sample\n"); 294 Debug printf("ERROR: null sample\n");
295 return -1; 295 return -1;
296 } 296 }
297 297
298 //cout << "DECODE " << (void*) pImage << " d: " << (void*) pImage->Data() << endl; 298 //cout << "DECODE " << (void*) pImage << " d: " << (void*) pImage->Data() << endl;
299 299
300 300
301 sample->vt->SetActualDataLength(sample, size); 301 sample->vt->SetActualDataLength(sample, size);
302 sample->vt->GetPointer(sample, (BYTE **)&ptr); 302 sample->vt->GetPointer(sample, (BYTE **)&ptr);
407 { 407 {
408 HRESULT result; 408 HRESULT result;
409 ALLOCATOR_PROPERTIES props,props1; 409 ALLOCATOR_PROPERTIES props,props1;
410 int should_test=1; 410 int should_test=1;
411 int stopped = 0; 411 int stopped = 0;
412 412
413 Debug printf("DS_VideoDecoder_SetDestFmt (%p, %d, %d)\n",this,bits,(int)csp); 413 Debug printf("DS_VideoDecoder_SetDestFmt (%p, %d, %d)\n",this,bits,(int)csp);
414 414
415 /* if (!CImage::Supported(csp, bits)) 415 /* if (!CImage::Supported(csp, bits))
416 return -1; 416 return -1;
417 */ 417 */
418 // BitmapInfo temp = m_obh; 418 // BitmapInfo temp = m_obh;
419 419
420 if (!csp) // RGB 420 if (!csp) // RGB
421 { 421 {
422 int ok = true; 422 int ok = true;
423 423
424 switch (bits) 424 switch (bits)
448 if( bits == 15 || bits == 16 ) { 448 if( bits == 15 || bits == 16 ) {
449 this->iv.m_obh.biSize=sizeof(BITMAPINFOHEADER)+12; 449 this->iv.m_obh.biSize=sizeof(BITMAPINFOHEADER)+12;
450 this->iv.m_obh.biCompression=3;//BI_BITFIELDS 450 this->iv.m_obh.biCompression=3;//BI_BITFIELDS
451 this->iv.m_obh.biSizeImage=abs((int)(2*this->iv.m_obh.biWidth*this->iv.m_obh.biHeight)); 451 this->iv.m_obh.biSizeImage=abs((int)(2*this->iv.m_obh.biWidth*this->iv.m_obh.biHeight));
452 } 452 }
453 453
454 if( bits == 16 ) { 454 if( bits == 16 ) {
455 this->iv.m_obh.colors[0]=0xF800; 455 this->iv.m_obh.colors[0]=0xF800;
456 this->iv.m_obh.colors[1]=0x07E0; 456 this->iv.m_obh.colors[1]=0x07E0;
457 this->iv.m_obh.colors[2]=0x001F; 457 this->iv.m_obh.colors[2]=0x001F;
458 } else if ( bits == 15 ) { 458 } else if ( bits == 15 ) {
626 } 626 }
627 627
628 if (stopped) 628 if (stopped)
629 { 629 {
630 DS_VideoDecoder_StartInternal(this); 630 DS_VideoDecoder_StartInternal(this);
631 this->iv.m_State = START; 631 this->iv.m_State = START;
632 } 632 }
633 633
634 return 0; 634 return 0;
635 } 635 }
636 636
812 { 812 {
813 this->m_iMaxAuto = value; 813 this->m_iMaxAuto = value;
814 } 814 }
815 return 0; 815 return 0;
816 } 816 }
817 #if 0 817 #if 0
818 if (strcmp((const char*)record.dll, "ir50_32.dll") == 0) 818 if (strcmp((const char*)record.dll, "ir50_32.dll") == 0)
819 { 819 {
820 IHidden2* hidden = 0; 820 IHidden2* hidden = 0;
821 if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, &IID_Iv50Hidden, (void**)&hidden)) 821 if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, &IID_Iv50Hidden, (void**)&hidden))
822 { 822 {
870 result=RegCreateKeyExA(HKEY_CURRENT_USER, keyname, 0, 0, 0, 0, 0, &newkey, &status); 870 result=RegCreateKeyExA(HKEY_CURRENT_USER, keyname, 0, 0, 0, 0, 0, &newkey, &status);
871 if(result!=0) 871 if(result!=0)
872 { 872 {
873 printf("VideoDecoder::SetExtAttr: registry failure\n"); 873 printf("VideoDecoder::SetExtAttr: registry failure\n");
874 return -1; 874 return -1;
875 } 875 }
876 result=RegSetValueExA(newkey, "Current Post Process Mode", 0, REG_DWORD, &value, 4); 876 result=RegSetValueExA(newkey, "Current Post Process Mode", 0, REG_DWORD, &value, 4);
877 if(result!=0) 877 if(result!=0)
878 { 878 {
879 printf("VideoDecoder::SetExtAttr: error writing value\n"); 879 printf("VideoDecoder::SetExtAttr: error writing value\n");
880 return -1; 880 return -1;
881 } 881 }
882 value=-1; 882 value=-1;
883 result=RegSetValueExA(newkey, "Force Post Process Mode", 0, REG_DWORD, &value, 4); 883 result=RegSetValueExA(newkey, "Force Post Process Mode", 0, REG_DWORD, &value, 4);
884 if(result!=0) 884 if(result!=0)
885 { 885 {
886 printf("VideoDecoder::SetExtAttr: error writing value\n"); 886 printf("VideoDecoder::SetExtAttr: error writing value\n");
887 return -1; 887 return -1;
888 } 888 }
889 RegCloseKey(newkey); 889 RegCloseKey(newkey);
890 return 0; 890 return 0;
891 } 891 }
892 892
893 if( 893 if(
894 (strcasecmp(attribute, "Saturation")==0) || 894 (strcasecmp(attribute, "Saturation")==0) ||
895 (strcasecmp(attribute, "Hue")==0) || 895 (strcasecmp(attribute, "Hue")==0) ||
896 (strcasecmp(attribute, "Contrast")==0) || 896 (strcasecmp(attribute, "Contrast")==0) ||
901 result=RegCreateKeyExA(HKEY_CURRENT_USER, keyname, 0, 0, 0, 0, 0, &newkey, &status); 901 result=RegCreateKeyExA(HKEY_CURRENT_USER, keyname, 0, 0, 0, 0, 0, &newkey, &status);
902 if(result!=0) 902 if(result!=0)
903 { 903 {
904 printf("VideoDecoder::SetExtAttr: registry failure\n"); 904 printf("VideoDecoder::SetExtAttr: registry failure\n");
905 return -1; 905 return -1;
906 } 906 }
907 result=RegSetValueExA(newkey, attribute, 0, REG_DWORD, &value, 4); 907 result=RegSetValueExA(newkey, attribute, 0, REG_DWORD, &value, 4);
908 if(result!=0) 908 if(result!=0)
909 { 909 {
910 printf("VideoDecoder::SetExtAttr: error writing value\n"); 910 printf("VideoDecoder::SetExtAttr: error writing value\n");
911 return -1; 911 return -1;
912 } 912 }
913 RegCloseKey(newkey); 913 RegCloseKey(newkey);
914 return 0; 914 return 0;
915 } 915 }
916 916
917 printf("Unknown attribute!\n"); 917 printf("Unknown attribute!\n");
918 return -200; 918 return -200;
919 } 919 }
920 920