| 1 |
/******************************************************** |
| 2 |
|
| 3 |
DirectShow Video decoder implementation |
| 4 |
Copyright 2000 Eugene Kuznetsov ([email protected]) |
| 5 |
|
| 6 |
*********************************************************/ |
| 7 |
|
| 8 |
#include "dshow/guids.h" |
| 9 |
#include "dshow/interfaces.h" |
| 10 |
#include "avm_output.h" |
| 11 |
|
| 12 |
#include "DS_VideoDecoder.h" |
| 13 |
#include "ldt_keeper.h" |
| 14 |
#include "configfile.h" |
| 15 |
#include "avm_cpuinfo.h" |
| 16 |
|
| 17 |
#include "wine/windef.h" |
| 18 |
#include "wine/winreg.h" |
| 19 |
#include "wine/vfw.h" |
| 20 |
#include "registry.h" |
| 21 |
|
| 22 |
#ifndef NOAVIFILE_HEADERS |
| 23 |
#define VFW_E_NOT_RUNNING 0x80040226 |
| 24 |
#include "avm_fourcc.h" |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <unistd.h> |
| 28 |
#include <fcntl.h> |
| 29 |
#include <errno.h> |
| 30 |
#include <sys/types.h> |
| 31 |
#include <sys/mman.h> |
| 32 |
#include <stdio.h> |
| 33 |
#include <stdlib.h> // labs |
| 34 |
|
| 35 |
AVM_BEGIN_NAMESPACE; |
| 36 |
|
| 37 |
DS_VideoDecoder::DS_VideoDecoder(const CodecInfo& info, const BITMAPINFOHEADER& format, int flip) |
| 38 |
:IVideoDecoder(info, format), m_sVhdr2(0), m_pIDivx4(0), m_iStatus(0), |
| 39 |
m_iLastPPMode(0), m_iLastBrightness(0), m_iLastContrast(0), |
| 40 |
m_iLastSaturation(0), m_iLastHue(0), |
| 41 |
m_CType(CT_NONE), m_bHaveUpsideDownRGB(true), |
| 42 |
m_bSetFlg(false), m_bFlip(flip) |
| 43 |
{ |
| 44 |
unsigned bihs = (m_pFormat->biSize < (int) sizeof(BITMAPINFOHEADER)) ? |
| 45 |
sizeof(BITMAPINFOHEADER) : m_pFormat->biSize; |
| 46 |
bihs = sizeof(VIDEOINFOHEADER) - sizeof(BITMAPINFOHEADER) + bihs; |
| 47 |
|
| 48 |
//int ss = 0;for (unsigned i = 0; i < m_pFormat->biSize; i++) { ss += ((unsigned char*) m_pFormat)[i]; printf(" %2x", ((unsigned char*) m_pFormat)[i]); if (!(i%16)) printf("\n"); } |
| 49 |
//printf("\nBITMAPINFOHEADER %d %d %d\n", m_pFormat->biSize, bihs, ss); |
| 50 |
//m_Dest.biHeight = labs(m_Dest.biHeight); |
| 51 |
|
| 52 |
// parent: |
| 53 |
//m_Dest = *m_pFormat; |
| 54 |
//m_Dest.SetBits(24); |
| 55 |
|
| 56 |
m_sVhdr = (VIDEOINFOHEADER*) malloc(bihs); |
| 57 |
memset(m_sVhdr, 0, bihs); |
| 58 |
memcpy(&m_sVhdr->bmiHeader, m_pFormat, m_pFormat->biSize); |
| 59 |
m_sVhdr->rcSource.left = m_sVhdr->rcSource.top = 0; |
| 60 |
m_sVhdr->rcSource.right = m_sVhdr->bmiHeader.biWidth; |
| 61 |
m_sVhdr->rcSource.bottom = m_sVhdr->bmiHeader.biHeight; |
| 62 |
m_sVhdr->rcTarget = m_sVhdr->rcSource; |
| 63 |
|
| 64 |
m_sOurType.majortype = MEDIATYPE_Video; |
| 65 |
m_sOurType.subtype = MEDIATYPE_Video; |
| 66 |
m_sOurType.subtype.f1 = m_sVhdr->bmiHeader.biCompression; |
| 67 |
m_sOurType.formattype = FORMAT_VideoInfo; |
| 68 |
m_sOurType.bFixedSizeSamples = false; |
| 69 |
m_sOurType.bTemporalCompression = true; |
| 70 |
m_sOurType.pUnk = 0; |
| 71 |
m_sOurType.cbFormat = bihs; |
| 72 |
m_sOurType.pbFormat = (char*)m_sVhdr; |
| 73 |
|
| 74 |
m_sVhdr2 = (VIDEOINFOHEADER*) malloc(sizeof(VIDEOINFOHEADER) + 12); |
| 75 |
// basicaly copy of m_Dest - but staying friendly to other players.. |
| 76 |
memset(m_sVhdr2, 0, sizeof(VIDEOINFOHEADER) + 12); |
| 77 |
m_sVhdr2->bmiHeader.biBitCount = 24; |
| 78 |
m_sVhdr2->bmiHeader.biWidth = m_Dest.biWidth; |
| 79 |
m_sVhdr2->bmiHeader.biHeight = m_Dest.biHeight; |
| 80 |
m_sVhdr2->bmiHeader.biSizeImage = m_sVhdr2->bmiHeader.biWidth |
| 81 |
* labs(m_sVhdr2->bmiHeader.biHeight) |
| 82 |
* m_sVhdr2->bmiHeader.biBitCount / 8; |
| 83 |
m_sVhdr2->rcSource = m_sVhdr->rcSource; |
| 84 |
m_sVhdr2->rcTarget = m_sVhdr->rcTarget; |
| 85 |
|
| 86 |
memset(&m_sDestType, 0, sizeof(m_sDestType)); |
| 87 |
m_sDestType.majortype = MEDIATYPE_Video; |
| 88 |
m_sDestType.formattype = FORMAT_VideoInfo; |
| 89 |
m_sDestType.subtype = MEDIASUBTYPE_RGB24; |
| 90 |
m_sDestType.bFixedSizeSamples = true; |
| 91 |
m_sDestType.bTemporalCompression = false; |
| 92 |
m_sDestType.lSampleSize = m_sVhdr2->bmiHeader.biSizeImage; |
| 93 |
m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); |
| 94 |
m_sDestType.pbFormat = (char*)m_sVhdr2; |
| 95 |
} |
| 96 |
|
| 97 |
// this is cruel hack to avoid problems with throws - |
| 98 |
// could anyone explain me why GNU people can't build reliable |
| 99 |
// C++ compiler |
| 100 |
int DS_VideoDecoder::init() |
| 101 |
{ |
| 102 |
Setup_FS_Segment(); |
| 103 |
|
| 104 |
m_pDS_Filter = DS_FilterCreate(m_Info.dll.c_str(), &m_Info.guid, &m_sOurType, &m_sDestType); |
| 105 |
|
| 106 |
if (!m_pDS_Filter) |
| 107 |
{ |
| 108 |
AVM_WRITE("Win32 DS video decoder", "WARNING: format not accepted!\n"); |
| 109 |
return -1; |
| 110 |
} |
| 111 |
|
| 112 |
if (m_Dest.biHeight < 0) |
| 113 |
{ |
| 114 |
int r = m_pDS_Filter->m_pOutputPin->vt->QueryAccept(m_pDS_Filter->m_pOutputPin, &m_sDestType); |
| 115 |
if (r) |
| 116 |
{ |
| 117 |
AVM_WRITE("Win32 DS video decoder", "WARNING: decoder does not support upside-down RGB frames!\n"); |
| 118 |
m_Dest.biHeight = -m_Dest.biHeight; |
| 119 |
m_sVhdr2->bmiHeader.biHeight = m_Dest.biHeight; |
| 120 |
m_bHaveUpsideDownRGB = false; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
switch (m_Info.fourcc) |
| 125 |
{ |
| 126 |
//case fccIV50: works normaly with YV12 (kabi) |
| 127 |
// IV50 doesn't support I420 |
| 128 |
case fccTM20: |
| 129 |
m_Caps = CAP_NONE; |
| 130 |
break; |
| 131 |
case fccDIV3: |
| 132 |
case fccDIV4: |
| 133 |
case fccDIV5: |
| 134 |
case fccDIV6: |
| 135 |
case fccMP42: |
| 136 |
//YV12 seems to be broken for DivX :-) codec |
| 137 |
//produces incorrect picture |
| 138 |
//m_Caps = (CAPS) (m_Caps & ~CAP_YV12); |
| 139 |
//m_Caps = CAP_UYVY;//CAP_YUY2; // | CAP_I420; |
| 140 |
//m_Caps = CAP_I420; |
| 141 |
m_Caps = (CAPS) (CAP_YUY2 | CAP_UYVY); |
| 142 |
break; |
| 143 |
default: |
| 144 |
{ |
| 145 |
static const struct ct { |
| 146 |
unsigned int bits; |
| 147 |
fourcc_t fcc; |
| 148 |
GUID subtype; |
| 149 |
CAPS cap; |
| 150 |
} check[] = { |
| 151 |
{16, fccYUY2, MEDIASUBTYPE_YUY2, CAP_YUY2}, |
| 152 |
{12, fccIYUV, MEDIASUBTYPE_IYUV, CAP_IYUV}, |
| 153 |
{16, fccUYVY, MEDIASUBTYPE_UYVY, CAP_UYVY}, |
| 154 |
{12, fccYV12, MEDIASUBTYPE_YV12, CAP_YV12}, |
| 155 |
{16, fccYV12, MEDIASUBTYPE_YV12, CAP_YV12}, |
| 156 |
{16, fccYVYU, MEDIASUBTYPE_YVYU, CAP_YVYU}, |
| 157 |
//{12, fccI420, MEDIASUBTYPE_I420, CAP_I420}, |
| 158 |
{0}, |
| 159 |
}; |
| 160 |
m_Caps = CAP_NONE; |
| 161 |
|
| 162 |
for (const ct* c = check; c->bits; c++) |
| 163 |
{ |
| 164 |
m_sVhdr2->bmiHeader.biBitCount = c->bits; |
| 165 |
m_sVhdr2->bmiHeader.biCompression = c->fcc; |
| 166 |
m_sDestType.subtype = c->subtype; |
| 167 |
if (0 == m_pDS_Filter->m_pOutputPin->vt->QueryAccept(m_pDS_Filter->m_pOutputPin, &m_sDestType)) |
| 168 |
m_Caps = (CAPS)(m_Caps | c->cap); |
| 169 |
} |
| 170 |
m_sVhdr2->bmiHeader.biBitCount = 24; |
| 171 |
m_sVhdr2->bmiHeader.biCompression = 0; |
| 172 |
m_sDestType.subtype = MEDIASUBTYPE_RGB24; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
const char* dll = m_Info.dll.c_str(); |
| 177 |
if (strcmp(dll, "divxcvki.ax") == 0 |
| 178 |
|| strcmp(dll, "divx_c32.ax") == 0 |
| 179 |
|| strcmp(dll, "wmvds32.ax") == 0 |
| 180 |
|| strcmp(dll, "wmv8ds32.ax") == 0) |
| 181 |
{ |
| 182 |
m_CType = CT_DIVX3; |
| 183 |
m_iMaxAuto = RegReadInt("win32", "maxauto", 4); |
| 184 |
} |
| 185 |
else if (strcmp(dll, "divxdec.ax") == 0) |
| 186 |
{ |
| 187 |
m_CType = CT_DIVX4; |
| 188 |
m_iMaxAuto = RegReadInt("win32DivX4", "maxauto", 6); |
| 189 |
if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, |
| 190 |
&IID_IDivxFilterInterface, (void**)&m_pIDivx4)) |
| 191 |
{ |
| 192 |
AVM_WRITE("Win32 video decoder", 1, "No such interface\n"); |
| 193 |
m_CType = CT_NONE; |
| 194 |
} |
| 195 |
} |
| 196 |
else if (strcmp(dll, "ir50_32.dll") == 0) |
| 197 |
m_CType = CT_IV50; |
| 198 |
|
| 199 |
getCodecValues(); |
| 200 |
|
| 201 |
if (m_Caps != CAP_NONE) |
| 202 |
AVM_WRITE("Win32 DS video decoder", "Decoder is capable of YUV output ( flags 0x%x )\n", (int)m_Caps); |
| 203 |
|
| 204 |
SetDirection(m_bFlip); |
| 205 |
//m_Dest.Print(); |
| 206 |
return 0; |
| 207 |
} |
| 208 |
|
| 209 |
DS_VideoDecoder::~DS_VideoDecoder() |
| 210 |
{ |
| 211 |
Stop(); |
| 212 |
if (m_pIDivx4) |
| 213 |
m_pIDivx4->vt->Release((IUnknown*)m_pIDivx4); |
| 214 |
|
| 215 |
if (m_sVhdr) |
| 216 |
free(m_sVhdr); |
| 217 |
if (m_sVhdr2) |
| 218 |
free(m_sVhdr2); |
| 219 |
if (m_pDS_Filter) |
| 220 |
DS_Filter_Destroy(m_pDS_Filter); |
| 221 |
} |
| 222 |
|
| 223 |
int DS_VideoDecoder::Start() |
| 224 |
{ |
| 225 |
if (!m_iStatus) |
| 226 |
{ |
| 227 |
Setup_FS_Segment(); |
| 228 |
//AVM_WRITE("Win32 video decoder", "DSSTART %p %d\n", this, m_sVhdr2->bmiHeader.biHeight); |
| 229 |
m_iStatus = 1; |
| 230 |
m_pDS_Filter->Start(m_pDS_Filter); |
| 231 |
ALLOCATOR_PROPERTIES props, props1; |
| 232 |
props.cBuffers = 1; |
| 233 |
props.cbBuffer = m_sDestType.lSampleSize; |
| 234 |
|
| 235 |
//don't know how to do this correctly |
| 236 |
props.cbAlign = 1; // Sascha Sommer thinks this is the right value |
| 237 |
props.cbPrefix = 0; |
| 238 |
m_pDS_Filter->m_pAll->vt->SetProperties(m_pDS_Filter->m_pAll, &props, &props1); |
| 239 |
m_pDS_Filter->m_pAll->vt->Commit(m_pDS_Filter->m_pAll); |
| 240 |
} |
| 241 |
return 0; |
| 242 |
} |
| 243 |
|
| 244 |
int DS_VideoDecoder::Stop() |
| 245 |
{ |
| 246 |
if (m_iStatus) |
| 247 |
{ |
| 248 |
Setup_FS_Segment(); |
| 249 |
m_pDS_Filter->Stop(m_pDS_Filter); |
| 250 |
m_iStatus = 0; |
| 251 |
//AVM_WRITE("Win32 video decoder", "DSSTOP %p\n", this); |
| 252 |
} |
| 253 |
return 0; |
| 254 |
} |
| 255 |
|
| 256 |
int DS_VideoDecoder::DecodeFrame(CImage* dest, const void* src, size_t size, |
| 257 |
int is_keyframe, bool render, CImage** pOut) |
| 258 |
{ |
| 259 |
IMediaSample* sample = 0; |
| 260 |
|
| 261 |
if (!m_iStatus) |
| 262 |
{ |
| 263 |
AVM_WRITE("Win32 DS video decoder", "not started!\n"); |
| 264 |
return -1; |
| 265 |
} |
| 266 |
Setup_FS_Segment(); |
| 267 |
|
| 268 |
if (!dest->IsFmt(&m_Dest)) printf("\n\nERRRRRRRRR\n\n"); |
| 269 |
|
| 270 |
m_pDS_Filter->m_pAll->vt->GetBuffer(m_pDS_Filter->m_pAll, &sample, 0, 0, 0); |
| 271 |
|
| 272 |
if (!sample) |
| 273 |
{ |
| 274 |
AVM_WRITE("Win32 video decoder", 1, "ERROR: null sample\n"); |
| 275 |
return -1; |
| 276 |
} |
| 277 |
|
| 278 |
//printf("DECODE this:%p img: %p\n", this, dest); |
| 279 |
if (dest) |
| 280 |
{ |
| 281 |
if (!(dest->Data())) |
| 282 |
{ |
| 283 |
AVM_WRITE("Win32 DS video decoder", 1, "no m_outFrame??\n"); |
| 284 |
} |
| 285 |
else |
| 286 |
m_pDS_Filter->m_pOurOutput->SetPointer2(m_pDS_Filter->m_pOurOutput, (char*)dest->Data()); |
| 287 |
} |
| 288 |
//printf("W32 from -> to\n"); m_Dest.Print(); dest->GetFmt()->Print(); |
| 289 |
char* ptr; |
| 290 |
sample->vt->SetActualDataLength(sample, size); |
| 291 |
sample->vt->GetPointer(sample, (BYTE **)&ptr); |
| 292 |
memcpy(ptr, src, size); |
| 293 |
sample->vt->SetSyncPoint(sample, is_keyframe); |
| 294 |
sample->vt->SetPreroll(sample, dest ? 0 : 1); |
| 295 |
// sample->vt->SetMediaType(sample, &m_sOurType); |
| 296 |
|
| 297 |
int check = 0; |
| 298 |
if (m_bSetFlg) |
| 299 |
{ |
| 300 |
//printf("SETFLG %d \n", m_iLastPPMode); |
| 301 |
if (m_iLastPPMode >= 0 && m_iLastHue != -1) |
| 302 |
{ |
| 303 |
m_bSetFlg = false; |
| 304 |
setCodecValues(); |
| 305 |
} |
| 306 |
check++; |
| 307 |
} |
| 308 |
|
| 309 |
int hr = m_pDS_Filter->m_pImp->vt->Receive(m_pDS_Filter->m_pImp, sample); |
| 310 |
if (hr) |
| 311 |
{ |
| 312 |
AVM_WRITE("Win32 DS video encoder", 1, "DS_VideoDecoder::DecodeInternal() error putting data into input pin %x\n", hr); |
| 313 |
hr = -1; |
| 314 |
} |
| 315 |
|
| 316 |
sample->vt->Release((IUnknown*)sample); |
| 317 |
|
| 318 |
if (check) |
| 319 |
getCodecValues(); |
| 320 |
|
| 321 |
switch (m_CType) |
| 322 |
{ |
| 323 |
case CT_DIVX4: |
| 324 |
dest->SetQuality(m_iLastPPMode / 6.0); |
| 325 |
break; |
| 326 |
case CT_DIVX3: |
| 327 |
dest->SetQuality(m_iLastPPMode / 4.0); |
| 328 |
break; |
| 329 |
default: |
| 330 |
; |
| 331 |
} |
| 332 |
|
| 333 |
return hr; |
| 334 |
} |
| 335 |
|
| 336 |
/* |
| 337 |
* bits == 0 - leave unchanged |
| 338 |
*/ |
| 339 |
int DS_VideoDecoder::SetDestFmt(int bits, fourcc_t csp) |
| 340 |
{ |
| 341 |
if ((bits || csp) && !CImage::Supported(csp, bits)) |
| 342 |
return -1; |
| 343 |
|
| 344 |
AVM_WRITE("Win32 DS video decoder", 1, "SetDestFmt %d %.4s\n", bits, (char*)&csp); |
| 345 |
BitmapInfo temp = m_Dest; |
| 346 |
if (bits != 0) |
| 347 |
{ |
| 348 |
bool ok = true; |
| 349 |
|
| 350 |
switch (bits) |
| 351 |
{ |
| 352 |
case 15: |
| 353 |
m_sDestType.subtype = MEDIASUBTYPE_RGB555; |
| 354 |
break; |
| 355 |
case 16: |
| 356 |
m_sDestType.subtype = MEDIASUBTYPE_RGB565; |
| 357 |
break; |
| 358 |
case 24: |
| 359 |
m_sDestType.subtype = MEDIASUBTYPE_RGB24; |
| 360 |
break; |
| 361 |
case 32: |
| 362 |
m_sDestType.subtype = MEDIASUBTYPE_RGB32; |
| 363 |
break; |
| 364 |
default: |
| 365 |
ok = false; |
| 366 |
break; |
| 367 |
} |
| 368 |
if (ok) |
| 369 |
{ |
| 370 |
m_Dest.SetBits(bits); |
| 371 |
if (!m_bHaveUpsideDownRGB) |
| 372 |
m_Dest.biHeight = labs(m_Dest.biHeight); |
| 373 |
|
| 374 |
//m_Dest.biHeight = labs(m_Dest.biHeight); |
| 375 |
} |
| 376 |
} |
| 377 |
else if (csp != 0) |
| 378 |
{ |
| 379 |
bool ok = true; |
| 380 |
switch (csp) |
| 381 |
{ |
| 382 |
case fccYUY2: |
| 383 |
m_sDestType.subtype = MEDIASUBTYPE_YUY2; |
| 384 |
break; |
| 385 |
case fccYV12: |
| 386 |
m_sDestType.subtype = MEDIASUBTYPE_YV12; |
| 387 |
break; |
| 388 |
case fccIYUV: |
| 389 |
m_sDestType.subtype = MEDIASUBTYPE_IYUV; |
| 390 |
break; |
| 391 |
case fccUYVY: |
| 392 |
m_sDestType.subtype = MEDIASUBTYPE_UYVY; |
| 393 |
break; |
| 394 |
case fccYVYU: |
| 395 |
m_sDestType.subtype = MEDIASUBTYPE_YVYU; |
| 396 |
break; |
| 397 |
default: |
| 398 |
ok = false; |
| 399 |
break; |
| 400 |
} |
| 401 |
|
| 402 |
if (ok) |
| 403 |
m_Dest.SetSpace(csp); |
| 404 |
} |
| 405 |
|
| 406 |
Setup_FS_Segment(); |
| 407 |
m_sDestType.lSampleSize = m_Dest.biSizeImage; |
| 408 |
memcpy(&(m_sVhdr2->bmiHeader), &m_Dest, sizeof(m_Dest)); |
| 409 |
m_sVhdr2->bmiHeader.biHeight = m_Dest.biHeight; |
| 410 |
m_sVhdr2->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 411 |
m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); |
| 412 |
if (m_sVhdr2->bmiHeader.biCompression == 3) |
| 413 |
m_sDestType.cbFormat += 12; |
| 414 |
|
| 415 |
static const struct ct { |
| 416 |
fourcc_t fcc; |
| 417 |
CAPS cap; |
| 418 |
} map[] = |
| 419 |
{ |
| 420 |
{ fccYUY2, CAP_YUY2 }, |
| 421 |
{ fccYV12, CAP_YV12 }, |
| 422 |
{ fccIYUV, CAP_IYUV }, |
| 423 |
{ fccUYVY, CAP_UYVY }, |
| 424 |
{ fccYVYU, CAP_YVYU }, |
| 425 |
{ 0 } |
| 426 |
}; |
| 427 |
|
| 428 |
int result; |
| 429 |
bool should_test = true; |
| 430 |
for (const ct* c = map; c->fcc; c++) |
| 431 |
{ |
| 432 |
if (c->fcc == csp) |
| 433 |
{ |
| 434 |
if (!(m_Caps & c->cap)) |
| 435 |
should_test = false; |
| 436 |
break; |
| 437 |
} |
| 438 |
} |
| 439 |
result = (should_test) ? m_pDS_Filter->m_pOutputPin->vt->QueryAccept(m_pDS_Filter->m_pOutputPin, &m_sDestType) : 0; |
| 440 |
|
| 441 |
if (result != 0) |
| 442 |
{ |
| 443 |
if (csp) |
| 444 |
AVM_WRITE("Win32 video decoder", "Warning: unsupported color space\n"); |
| 445 |
else |
| 446 |
AVM_WRITE("Win32 video decoder", "Warning: unsupported bit depth\n"); |
| 447 |
m_Dest = temp; |
| 448 |
m_sDestType.lSampleSize = m_Dest.biSizeImage; |
| 449 |
memcpy(&(m_sVhdr2->bmiHeader), &m_Dest, sizeof(temp)); |
| 450 |
m_sVhdr2->bmiHeader.biHeight = m_Dest.biHeight; |
| 451 |
m_sVhdr2->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 452 |
m_sDestType.cbFormat = sizeof(VIDEOINFOHEADER); |
| 453 |
if (m_sVhdr2->bmiHeader.biCompression == 3) |
| 454 |
m_sDestType.cbFormat += 12; |
| 455 |
|
| 456 |
return -1; |
| 457 |
} |
| 458 |
|
| 459 |
m_pFormat->biBitCount = bits; |
| 460 |
|
| 461 |
//Restart(); |
| 462 |
bool stoped = false; |
| 463 |
if (m_iStatus) |
| 464 |
{ |
| 465 |
Stop(); |
| 466 |
stoped = true; |
| 467 |
} |
| 468 |
|
| 469 |
m_pDS_Filter->m_pInputPin->vt->Disconnect(m_pDS_Filter->m_pInputPin); |
| 470 |
m_pDS_Filter->m_pOutputPin->vt->Disconnect(m_pDS_Filter->m_pOutputPin); |
| 471 |
m_pDS_Filter->m_pOurOutput->SetNewFormat(m_pDS_Filter->m_pOurOutput, &m_sDestType); |
| 472 |
result = m_pDS_Filter->m_pInputPin->vt->ReceiveConnection(m_pDS_Filter->m_pInputPin, |
| 473 |
m_pDS_Filter->m_pOurInput, |
| 474 |
&m_sOurType); |
| 475 |
if (result) |
| 476 |
{ |
| 477 |
AVM_WRITE("Win32 video decoder", "Error reconnecting input pin 0x%x\n", (int)result); |
| 478 |
return -1; |
| 479 |
} |
| 480 |
result = m_pDS_Filter->m_pOutputPin->vt->ReceiveConnection(m_pDS_Filter->m_pOutputPin, |
| 481 |
(IPin*)m_pDS_Filter->m_pOurOutput, |
| 482 |
&m_sDestType); |
| 483 |
if (result) |
| 484 |
{ |
| 485 |
AVM_WRITE("Win32 video decoder", "Error reconnecting output pin 0x%x\n", (int)result); |
| 486 |
return -1; |
| 487 |
} |
| 488 |
|
| 489 |
if (stoped) |
| 490 |
Start(); |
| 491 |
|
| 492 |
return 0; |
| 493 |
} |
| 494 |
int DS_VideoDecoder::SetDirection(int d) |
| 495 |
{ |
| 496 |
if (m_Dest.biHeight < 0) |
| 497 |
m_Dest.biHeight = -m_Dest.biHeight; |
| 498 |
|
| 499 |
if (!d && m_bHaveUpsideDownRGB) |
| 500 |
m_Dest.biHeight = -m_Dest.biHeight; |
| 501 |
|
| 502 |
m_sVhdr2->bmiHeader.biHeight = m_Dest.biHeight; |
| 503 |
|
| 504 |
//printf("SETDIRECTION %d\n", m_sVhdr2->bmiHeader.biHeight); m_Dest.Print(); |
| 505 |
if (m_pDS_Filter) |
| 506 |
SetDestFmt(0, 0); |
| 507 |
return 0; |
| 508 |
} |
| 509 |
|
| 510 |
int DS_VideoDecoder::GetValue(const char* name, int* value) const |
| 511 |
{ |
| 512 |
if (strcmp(name, "postprocessing") == 0) // Pp |
| 513 |
*value = m_iLastPPMode; |
| 514 |
else if (strcmp(name, "Brightness") == 0) |
| 515 |
*value = m_iLastBrightness; |
| 516 |
else if (strcmp(name, "Contrast") == 0) |
| 517 |
*value = m_iLastContrast; |
| 518 |
else if (strcmp(name, "Saturation") == 0) |
| 519 |
*value = m_iLastSaturation; |
| 520 |
else if (strcmp(name, "Hue") == 0) |
| 521 |
*value = m_iLastHue; |
| 522 |
else if (strcmp(name, "maxauto") == 0) |
| 523 |
*value = m_iMaxAuto; |
| 524 |
else |
| 525 |
return -1; |
| 526 |
|
| 527 |
//printf("BR %d C %d S %d H %d PP: %d (%s)\n", m_iLastBrightness, |
| 528 |
// m_iLastContrast, m_iLastSaturation, m_iLastHue, m_iLastPPMode, name); |
| 529 |
|
| 530 |
return 0; |
| 531 |
} |
| 532 |
|
| 533 |
int DS_VideoDecoder::getCodecValues() |
| 534 |
{ |
| 535 |
switch (m_CType) |
| 536 |
{ |
| 537 |
case CT_DIVX4: |
| 538 |
m_pIDivx4->vt->get_PPLevel(m_pIDivx4, &m_iLastPPMode); |
| 539 |
m_iLastPPMode /= 10; |
| 540 |
m_pIDivx4->vt->get_Brightness(m_pIDivx4, &m_iLastBrightness); |
| 541 |
m_pIDivx4->vt->get_Contrast(m_pIDivx4, &m_iLastContrast); |
| 542 |
m_pIDivx4->vt->get_Saturation(m_pIDivx4, &m_iLastSaturation); |
| 543 |
break; |
| 544 |
case CT_DIVX3: |
| 545 |
{ |
| 546 |
// brightness 87 |
| 547 |
// contrast 74 |
| 548 |
// hue 23 |
| 549 |
// saturation 20 |
| 550 |
// post process mode 0 |
| 551 |
// get1 0x01 |
| 552 |
// get2 10 |
| 553 |
// get3=set2 86 |
| 554 |
// get4=set3 73 |
| 555 |
// get5=set4 19 |
| 556 |
// get6=set5 23 |
| 557 |
IHidden* hidden = (IHidden*)((int)m_pDS_Filter->m_pFilter + 0xb8); |
| 558 |
//#warning NOT SURE |
| 559 |
hidden->vt->GetSmth2(hidden, &m_iLastPPMode); |
| 560 |
if (m_iLastPPMode >= 10) |
| 561 |
m_iLastPPMode -= 10; |
| 562 |
if (m_iLastPPMode < 0 || m_iLastHue < 0) |
| 563 |
{ |
| 564 |
hidden->vt->GetSmth3(hidden, &m_iLastBrightness); |
| 565 |
//printf("BRGET %d\n", m_iLastBrightness); |
| 566 |
hidden->vt->GetSmth4(hidden, &m_iLastContrast); |
| 567 |
hidden->vt->GetSmth5(hidden, &m_iLastSaturation); |
| 568 |
hidden->vt->GetSmth6(hidden, &m_iLastHue); |
| 569 |
} |
| 570 |
break; |
| 571 |
} |
| 572 |
case CT_IV50: |
| 573 |
{ |
| 574 |
IHidden2* hidden = 0; |
| 575 |
if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, &IID_Iv50Hidden, (void**)&hidden)) |
| 576 |
{ |
| 577 |
AVM_WRITE("Win32 video decoder", 0, "No such interface\n"); |
| 578 |
return -1; |
| 579 |
} |
| 580 |
else |
| 581 |
{ |
| 582 |
int recordpar[30]; |
| 583 |
memset(&recordpar, 0, sizeof(recordpar)); |
| 584 |
recordpar[0]=0x7c; |
| 585 |
recordpar[1]=fccIV50; |
| 586 |
recordpar[2]=0x10005; |
| 587 |
recordpar[3]=2; |
| 588 |
recordpar[4]=1; |
| 589 |
recordpar[5]=0x80000000 | 0x20 | 0x40 | 0x80; |
| 590 |
hidden->vt->DecodeGet(hidden, recordpar); |
| 591 |
m_iLastBrightness = recordpar[18]; |
| 592 |
m_iLastSaturation = recordpar[19]; |
| 593 |
m_iLastContrast = recordpar[20]; |
| 594 |
hidden->vt->Release((IUnknown*)hidden); |
| 595 |
} |
| 596 |
} |
| 597 |
default: |
| 598 |
; |
| 599 |
} |
| 600 |
return 0; |
| 601 |
} |
| 602 |
|
| 603 |
int DS_VideoDecoder::SetValue(const char* name, int value) |
| 604 |
{ |
| 605 |
m_bSetFlg = true; |
| 606 |
if (strcmp(name, "postprocessing") == 0) // Pp |
| 607 |
m_iLastPPMode = value; |
| 608 |
else if (strcmp(name, "Brightness") == 0) |
| 609 |
m_iLastBrightness = value; |
| 610 |
else if (strcmp(name, "Contrast") == 0) |
| 611 |
m_iLastContrast = value; |
| 612 |
else if (strcmp(name, "Saturation") == 0) |
| 613 |
m_iLastSaturation = value; |
| 614 |
else if (strcmp(name, "Hue") == 0) |
| 615 |
m_iLastHue = value; |
| 616 |
else if (strcmp(name, "maxauto") == 0) |
| 617 |
m_iMaxAuto = value; |
| 618 |
//printf("SETVAL B %d C %d S %d H %d \n", m_iLastBrightness, |
| 619 |
// m_iLastContrast, m_iLastSaturation, m_iLastHue); |
| 620 |
//else AVM_WRITE("Win32 video decoder", "Set %s %d\n", name, value); |
| 621 |
return 0; |
| 622 |
} |
| 623 |
|
| 624 |
int DS_VideoDecoder::setCodecValues() |
| 625 |
{ |
| 626 |
if (!m_iStatus) |
| 627 |
return -1; |
| 628 |
|
| 629 |
switch (m_CType) |
| 630 |
{ |
| 631 |
case CT_DIVX4: |
| 632 |
m_pIDivx4->vt->put_PPLevel(m_pIDivx4, m_iLastPPMode * 10); |
| 633 |
m_pIDivx4->vt->put_Brightness(m_pIDivx4, m_iLastBrightness); |
| 634 |
m_pIDivx4->vt->put_Contrast(m_pIDivx4, m_iLastContrast); |
| 635 |
m_pIDivx4->vt->put_Saturation(m_pIDivx4, m_iLastSaturation); |
| 636 |
break; |
| 637 |
case CT_DIVX3: |
| 638 |
{ |
| 639 |
// brightness 87 |
| 640 |
// contrast 74 |
| 641 |
// hue 23 |
| 642 |
// saturation 20 |
| 643 |
// post process mode 0 |
| 644 |
// get1 0x01 |
| 645 |
// get2 10 |
| 646 |
// get3=set2 86 |
| 647 |
// get4=set3 73 |
| 648 |
// get5=set4 19 |
| 649 |
// get6=set5 23 |
| 650 |
IHidden* hidden = (IHidden*)((int)m_pDS_Filter->m_pFilter + 0xb8); |
| 651 |
hidden->vt->SetSmth(hidden, m_iLastPPMode, 0); |
| 652 |
hidden->vt->SetSmth2(hidden, m_iLastBrightness, 0); |
| 653 |
hidden->vt->SetSmth3(hidden, m_iLastContrast, 0); |
| 654 |
hidden->vt->SetSmth4(hidden, m_iLastSaturation, 0); |
| 655 |
hidden->vt->SetSmth5(hidden, m_iLastHue, 0); |
| 656 |
} |
| 657 |
break; |
| 658 |
case CT_IV50: |
| 659 |
{ |
| 660 |
IHidden2* hidden = 0; |
| 661 |
if (m_pDS_Filter->m_pFilter->vt->QueryInterface((IUnknown*)m_pDS_Filter->m_pFilter, &IID_Iv50Hidden, (void**)&hidden)) |
| 662 |
{ |
| 663 |
AVM_WRITE("Win32 video decoder", 1, "No such interface\n"); |
| 664 |
return -1; |
| 665 |
} |
| 666 |
int recordpar[30]; |
| 667 |
memset(&recordpar, 0, sizeof(recordpar)); |
| 668 |
recordpar[0]=0x7c; |
| 669 |
recordpar[1]=fccIV50; |
| 670 |
recordpar[2]=0x10005; |
| 671 |
recordpar[3]=2; |
| 672 |
recordpar[4]=1; |
| 673 |
recordpar[5]=0x80000000 | 0x20 | 0x40 | 0x80; |
| 674 |
|
| 675 |
recordpar[18] = m_iLastBrightness; |
| 676 |
recordpar[19] = m_iLastSaturation; |
| 677 |
recordpar[20] = m_iLastContrast; |
| 678 |
int hr = hidden->vt->DecodeSet(hidden, recordpar); |
| 679 |
hidden->vt->Release((IUnknown*)hidden); |
| 680 |
return hr; |
| 681 |
} |
| 682 |
default: |
| 683 |
; |
| 684 |
} |
| 685 |
return 0; |
| 686 |
} |
| 687 |
|
| 688 |
AVM_END_NAMESPACE; |