| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | #include <stdio.h> |
|---|
| 123 | #include <assert.h> |
|---|
| 124 | #include <stdlib.h> |
|---|
| 125 | #include "config.h" |
|---|
| 126 | #include <windows.h> |
|---|
| 127 | |
|---|
| 128 | #include "grabber.h" |
|---|
| 129 | #include "device-input.h" |
|---|
| 130 | #include "module.h" |
|---|
| 131 | #include "rgb-converter.h" |
|---|
| 132 | |
|---|
| 133 | #include "grabber-win32DS.h" |
|---|
| 134 | |
|---|
| 135 | #ifndef VIDE0_FOR_WINDOWS |
|---|
| 136 | static DirectShowScanner findDirectShowDevices; |
|---|
| 137 | #endif |
|---|
| 138 | |
|---|
| 139 | IBaseFilter *pCaptureFilter[NUM_DEVS]; |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | IAMCrossbar *pXBar = NULL; |
|---|
| 143 | IBaseFilter *pFilter = NULL; |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | STDMETHODIMP Callback::SampleCB(double sampleTime, IMediaSample *pSample) { |
|---|
| 150 | return E_NOTIMPL; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | STDMETHODIMP Callback::BufferCB(double sampleTime, BYTE *pBuffer, long bufferLen) { |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | WaitForSingleObject(grabber->cb_mutex_, INFINITE); |
|---|
| 158 | grabber->capture(pBuffer, bufferLen); |
|---|
| 159 | ReleaseMutex(grabber->cb_mutex_); |
|---|
| 160 | return S_OK; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | STDMETHODIMP Callback::QueryInterface(REFIID riid, void **ppvObject) { |
|---|
| 166 | if (NULL == ppvObject) |
|---|
| 167 | return E_POINTER; |
|---|
| 168 | if (riid == __uuidof(IUnknown)) |
|---|
| 169 | *ppvObject = static_cast<IUnknown*>(this); |
|---|
| 170 | else if (riid == __uuidof(ISampleGrabberCB)) |
|---|
| 171 | *ppvObject = static_cast<ISampleGrabberCB*>(this); |
|---|
| 172 | else |
|---|
| 173 | return E_NOTIMPL; |
|---|
| 174 | AddRef(); |
|---|
| 175 | return S_OK; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | DirectShowGrabber::DirectShowGrabber(IBaseFilter *filt) { |
|---|
| 182 | HRESULT hr; |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | debug_msg("new DirectShowGrabber()\n"); |
|---|
| 190 | svideoPort = -1; |
|---|
| 191 | compositePort = -1; |
|---|
| 192 | decimate_ =-1; |
|---|
| 193 | converter_=0; |
|---|
| 194 | cb_mutex_=0; |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | crossbar = crossbarCursor = NULL; |
|---|
| 198 | |
|---|
| 199 | pCaptureFilter_ = filt; |
|---|
| 200 | setport("external"); |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | callback = new Callback(); |
|---|
| 217 | callback->grabber = this; |
|---|
| 218 | debug_msg("DirectShowGrabber::DirectShowGrabber(): callback created, grabber set\n"); |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, |
|---|
| 222 | IID_IGraphBuilder, (void **)&pGraph_); |
|---|
| 223 | if (FAILED(hr)) { |
|---|
| 224 | Grabber::status_=-1; |
|---|
| 225 | return; |
|---|
| 226 | } |
|---|
| 227 | debug_msg("DirectShowGrabber::DirectShowGrabber(): graph instance acquired\n"); |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | hr = pGraph_->QueryInterface(IID_IMediaControl, (void **)&pMediaControl_); |
|---|
| 231 | |
|---|
| 232 | if (FAILED(hr)) { |
|---|
| 233 | Grabber::status_=-1; |
|---|
| 234 | return; |
|---|
| 235 | } |
|---|
| 236 | debug_msg("DirectShowGrabber::DirectShowGrabber(): graph media control interface acquired\n"); |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, |
|---|
| 240 | IID_ICaptureGraphBuilder2, (void **)&pBuild_); |
|---|
| 241 | |
|---|
| 242 | if (FAILED(hr)) { |
|---|
| 243 | Grabber::status_=-1; |
|---|
| 244 | return; |
|---|
| 245 | } |
|---|
| 246 | debug_msg("DirectShowGrabber::DirectShowGrabber(): graph builder interface acquired\n"); |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | hr = pBuild_->SetFiltergraph(pGraph_); |
|---|
| 250 | |
|---|
| 251 | if (FAILED(hr)) { |
|---|
| 252 | Grabber::status_=-1; |
|---|
| 253 | return; |
|---|
| 254 | } |
|---|
| 255 | debug_msg("DirectShowGrabber::DirectShowGrabber(): graph associated with builder\n"); |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | hr = pGraph_->AddFilter(pCaptureFilter_, L"VicCaptureFilter"); |
|---|
| 259 | |
|---|
| 260 | debug_msg("DirectShowGrabber::DirectShowGrabber(): capture filter added to graph\n"); |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, |
|---|
| 264 | IID_IBaseFilter, (LPVOID *)&pGrabberBaseFilter_); |
|---|
| 265 | |
|---|
| 266 | debug_msg("DirectShowGrabber::DirectShowGrabber(): grabber base filter instance acquired\n"); |
|---|
| 267 | |
|---|
| 268 | hr = pGrabberBaseFilter_->QueryInterface(IID_ISampleGrabber, (void**)&pSampleGrabber_); |
|---|
| 269 | |
|---|
| 270 | debug_msg("DirectShowGrabber::DirectShowGrabber(): Sample Grabber interface acquired\n"); |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | hr = pSampleGrabber_->SetOneShot(FALSE); |
|---|
| 274 | hr = pSampleGrabber_->SetCallback(callback, 1); |
|---|
| 275 | hr = pGraph_->AddFilter(pGrabberBaseFilter_,L"VicSampleGrabber"); |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, |
|---|
| 279 | IID_IBaseFilter, (LPVOID *)&pNullBaseFilter_); |
|---|
| 280 | |
|---|
| 281 | if (FAILED(hr)) { |
|---|
| 282 | Grabber::status_=-1; |
|---|
| 283 | return; |
|---|
| 284 | } |
|---|
| 285 | debug_msg("DirectShowGrabber::DirectShowGrabber(): Null Renderer interface acquired\n"); |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | hr = pGraph_->AddFilter(pNullBaseFilter_,L"VicNullRenderer"); |
|---|
| 289 | if (FAILED(hr)) { |
|---|
| 290 | Grabber::status_=-1; |
|---|
| 291 | return; |
|---|
| 292 | } |
|---|
| 293 | debug_msg("DirectShowGrabber::DirectShowGrabber(): Null Renderer added to graph\n"); |
|---|
| 294 | |
|---|
| 295 | if (!getCaptureCapabilities()) { |
|---|
| 296 | Grabber::status_=-1; |
|---|
| 297 | return; |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | findCrossbar(pCaptureFilter_); |
|---|
| 303 | routeCrossbar(); |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | ZeroMemory(&mt_, sizeof(AM_MEDIA_TYPE)); |
|---|
| 308 | mt_.majortype = MEDIATYPE_Video; |
|---|
| 309 | mt_.subtype = MEDIASUBTYPE_RGB24; |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | hr = pSampleGrabber_->SetMediaType(&mt_); |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | if (FAILED(hr)) { |
|---|
| 322 | debug_msg("DirectShowGrabber::DirectShowGrabber(): FAILed to build render stream\n"); |
|---|
| 323 | status_=-1; |
|---|
| 324 | return; |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | DirectShowGrabber::~DirectShowGrabber() { |
|---|
| 331 | HRESULT hr; |
|---|
| 332 | |
|---|
| 333 | debug_msg("~DirectShowGrabber()\n"); |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | if (capturing_) |
|---|
| 337 | hr = pMediaControl_->Stop(); |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | callback->Release(); |
|---|
| 342 | pNullBaseFilter_.Release(); |
|---|
| 343 | pSampleGrabber_.Release(); |
|---|
| 344 | pGrabberBaseFilter_.Release(); |
|---|
| 345 | pBuild_.Release(); |
|---|
| 346 | pMediaControl_.Release(); |
|---|
| 347 | pGraph_.Release(); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | void DirectShowGrabber::findCrossbar(IBaseFilter *pCapF) { |
|---|
| 353 | HRESULT hr; |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | |
|---|
| 357 | debug_msg("DirectShowGrabber::FindCrossbar()...\n"); |
|---|
| 358 | |
|---|
| 359 | hr = pBuild_->FindInterface(&LOOK_UPSTREAM_ONLY, NULL, pCapF, IID_IAMCrossbar, |
|---|
| 360 | (void**)&pXBar); |
|---|
| 361 | |
|---|
| 362 | if ( SUCCEEDED(hr) ) { |
|---|
| 363 | addCrossbar(pXBar); |
|---|
| 364 | hr = pXBar->QueryInterface(IID_IBaseFilter, (void**)&pFilter); |
|---|
| 365 | if ( SUCCEEDED(hr) ) { |
|---|
| 366 | debug_msg("DirectShowGrabber::FindCrossbar()...Found and added\n"); |
|---|
| 367 | findCrossbar(pFilter); |
|---|
| 368 | pFilter->Release(); |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | } |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | void DirectShowGrabber::addCrossbar(IAMCrossbar *xbar) { |
|---|
| 377 | Crossbar *pCross; |
|---|
| 378 | |
|---|
| 379 | debug_msg("DirectShowGrabber::addCrossbar()\n"); |
|---|
| 380 | |
|---|
| 381 | pCross = new Crossbar(xbar); |
|---|
| 382 | |
|---|
| 383 | if( crossbar == NULL ) { |
|---|
| 384 | crossbar = pCross; |
|---|
| 385 | } |
|---|
| 386 | else { |
|---|
| 387 | crossbarCursor->next = pCross; |
|---|
| 388 | } |
|---|
| 389 | crossbarCursor = pCross; |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | void DirectShowGrabber::routeCrossbar() { |
|---|
| 395 | HRESULT hr; |
|---|
| 396 | long output = -1; |
|---|
| 397 | long input = -1; |
|---|
| 398 | int videoDecoderPort = -1; |
|---|
| 399 | int port; |
|---|
| 400 | long related; |
|---|
| 401 | long pinType; |
|---|
| 402 | IAMCrossbar *xb; |
|---|
| 403 | |
|---|
| 404 | if( crossbar == NULL ) return; |
|---|
| 405 | |
|---|
| 406 | xb = crossbar->getXBar(); |
|---|
| 407 | |
|---|
| 408 | xb->get_IsRoutedTo(0, &input); |
|---|
| 409 | debug_msg("DirectShowGrabber::routeCrossbar(): pin %d is routed to output pin 0\n", input); |
|---|
| 410 | |
|---|
| 411 | hr = xb->get_PinCounts(&output, &input); |
|---|
| 412 | |
|---|
| 413 | for( int i = 0; i < input; ++i ) { |
|---|
| 414 | xb->get_CrossbarPinInfo(TRUE, i, &related, &pinType); |
|---|
| 415 | if( pinType == PhysConn_Video_SVideo ) { |
|---|
| 416 | svideoPort = i; |
|---|
| 417 | } |
|---|
| 418 | if( pinType == PhysConn_Video_Composite ) { |
|---|
| 419 | compositePort = i; |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | for( int i = 0; i < output; ++i ) { |
|---|
| 423 | xb->get_CrossbarPinInfo(FALSE, i, &related, &pinType); |
|---|
| 424 | if( pinType == PhysConn_Video_VideoDecoder ) { |
|---|
| 425 | videoDecoderPort = i; |
|---|
| 426 | break; |
|---|
| 427 | } |
|---|
| 428 | } |
|---|
| 429 | if(strcmp(input_port_, "S-Video")==0){ |
|---|
| 430 | port = svideoPort; |
|---|
| 431 | }else if(strcmp(input_port_, "Composite")==0){ |
|---|
| 432 | port = compositePort; |
|---|
| 433 | }else{ |
|---|
| 434 | port = 0; |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | if( xb->CanRoute(videoDecoderPort, port) == S_FALSE ) |
|---|
| 438 | debug_msg("DirectShowGrabber::routeCrossbar(): cannot route input pin %d to output pin %d\n", port, videoDecoderPort); |
|---|
| 439 | else { |
|---|
| 440 | debug_msg("DirectShowGrabber::routeCrossbar() routing pin %d to pin %d\n", port, videoDecoderPort); |
|---|
| 441 | hr = xb->Route(videoDecoderPort, port); |
|---|
| 442 | |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | xb->get_IsRoutedTo(0, &input); |
|---|
| 446 | debug_msg("DirectShowGrabber::routeCrossbar(): pin %d is now routed to output pin 0\n", input); |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | void DirectShowGrabber::start() { |
|---|
| 452 | HRESULT hr; |
|---|
| 453 | |
|---|
| 454 | setsize(); |
|---|
| 455 | setCaptureOutputFormat(); |
|---|
| 456 | hr = pBuild_->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, |
|---|
| 457 | pCaptureFilter_, pGrabberBaseFilter_, pNullBaseFilter_); |
|---|
| 458 | |
|---|
| 459 | if (SUCCEEDED(hr) ) |
|---|
| 460 | debug_msg("DirectShowGrabber::DirectShowGrabber(): builder render stream\n"); |
|---|
| 461 | else { |
|---|
| 462 | debug_msg("DirectShowGrabber::DirectShowGrabber(): FAILED to builder render stream: %x\n", hr); |
|---|
| 463 | stop(); |
|---|
| 464 | return; |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | cb_mutex_ = CreateMutex(NULL, FALSE, NULL); |
|---|
| 468 | WaitForSingleObject(cb_mutex_, INFINITE); |
|---|
| 469 | |
|---|
| 470 | capturing_ = 1; |
|---|
| 471 | last_frame_ = NULL; |
|---|
| 472 | |
|---|
| 473 | debug_msg("DirectShowGrabber::start(): starting capture graph...\n"); |
|---|
| 474 | |
|---|
| 475 | |
|---|
| 476 | hr = pMediaControl_->Run(); |
|---|
| 477 | if (SUCCEEDED(hr) ) |
|---|
| 478 | debug_msg("DirectShowGrabber::DirectShowGrabber(): Graph set to Run\n"); |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | Grabber::start(); |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | void DirectShowGrabber::stop() { |
|---|
| 488 | HRESULT hr; |
|---|
| 489 | |
|---|
| 490 | debug_msg("DirectShowGrabber::stop() thread=%x\n", GetCurrentThreadId()); |
|---|
| 491 | |
|---|
| 492 | if (capturing_) { |
|---|
| 493 | hr = pMediaControl_->Stop(); |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | CloseHandle(cb_mutex_); |
|---|
| 498 | delete[] converter_; |
|---|
| 499 | capturing_ = 0; |
|---|
| 500 | converter_ = 0; |
|---|
| 501 | last_frame_ = 0; |
|---|
| 502 | |
|---|
| 503 | Grabber::stop(); |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | void DirectShowGrabber::fps(int f) { |
|---|
| 509 | if (f <= 0) |
|---|
| 510 | f = 1; |
|---|
| 511 | else if (u_int(f) > max_fps_) |
|---|
| 512 | f = max_fps_; |
|---|
| 513 | |
|---|
| 514 | Grabber::fps(f); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | void DirectShowGrabber::capture(BYTE *frameBuf, long bufLen) { |
|---|
| 520 | last_frame_ = frameBuf; |
|---|
| 521 | |
|---|
| 522 | } |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | int DirectShowGrabber::grab() { |
|---|
| 527 | int rval; |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | debug_msg("DirectShowGrabber::grab: thread=%x w=%d h=%d bw=%d bh=%d frame_=%p fsize_=%d in=%dx%d out=%dx%d\n", |
|---|
| 531 | GetCurrentThreadId(), |
|---|
| 532 | width_, height_, basewidth_, baseheight_, frame_, framesize_, |
|---|
| 533 | inw_, inh_, outw_, outh_); |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | WaitForSingleObject(cb_mutex_, INFINITE); |
|---|
| 537 | |
|---|
| 538 | if( last_frame_ == NULL || capturing_ == 0 ) { |
|---|
| 539 | ReleaseMutex(cb_mutex_); |
|---|
| 540 | return FALSE; |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | converter_->convert((u_int8_t*)last_frame_, width_, |
|---|
| 544 | height_, frame_, outw_, outh_, TRUE); |
|---|
| 545 | |
|---|
| 546 | last_frame_ = NULL; |
|---|
| 547 | |
|---|
| 548 | suppress(frame_); |
|---|
| 549 | saveblks(frame_); |
|---|
| 550 | YuvFrame f(media_ts(), frame_, crvec_, outw_, outh_); |
|---|
| 551 | |
|---|
| 552 | rval = (target_->consume(&f)); |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | ReleaseMutex(cb_mutex_); |
|---|
| 556 | |
|---|
| 557 | return rval; |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | void DirectShowGrabber::setport(const char *port) { |
|---|
| 563 | |
|---|
| 564 | debug_msg("DirectShowGrabber::setport: %s thread=%x\n", port, GetCurrentThreadId()); |
|---|
| 565 | strcpy(input_port_, port); |
|---|
| 566 | routeCrossbar(); |
|---|
| 567 | |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | int DirectShowGrabber::getCaptureCapabilities() { |
|---|
| 573 | IAMStreamConfig *pConfig; |
|---|
| 574 | AM_MEDIA_TYPE *pmtConfig; |
|---|
| 575 | int iCount; |
|---|
| 576 | int iSize; |
|---|
| 577 | VIDEO_STREAM_CONFIG_CAPS scc; |
|---|
| 578 | HRESULT hr; |
|---|
| 579 | VIDEOINFOHEADER *pVih; |
|---|
| 580 | |
|---|
| 581 | pConfig = NULL; |
|---|
| 582 | hr = pBuild_->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, |
|---|
| 583 | pCaptureFilter_, IID_IAMStreamConfig, (void**)&pConfig); |
|---|
| 584 | if (FAILED(hr)) { |
|---|
| 585 | return FALSE; |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | max_width_ = 0; |
|---|
| 589 | max_height_ = 0; |
|---|
| 590 | iCount = iSize = 0; |
|---|
| 591 | hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize); |
|---|
| 592 | |
|---|
| 593 | |
|---|
| 594 | if ( iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS) ) { |
|---|
| 595 | |
|---|
| 596 | for (int iFormat = 0; iFormat < iCount; iFormat++) { |
|---|
| 597 | hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc); |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | if( SUCCEEDED(hr) ) { |
|---|
| 603 | if ((pmtConfig->majortype == MEDIATYPE_Video) && |
|---|
| 604 | |
|---|
| 605 | (pmtConfig->formattype == FORMAT_VideoInfo) && |
|---|
| 606 | (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) && |
|---|
| 607 | (pmtConfig->pbFormat != NULL)) { |
|---|
| 608 | |
|---|
| 609 | if(scc.MaxOutputSize.cx > max_width_){ |
|---|
| 610 | max_width_ = scc.MaxOutputSize.cx; |
|---|
| 611 | max_height_ = scc.MaxOutputSize.cy; |
|---|
| 612 | |
|---|
| 613 | } |
|---|
| 614 | debug_msg("Windows GDI BITMAPINFOHEADER follows:\n"); |
|---|
| 615 | pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat; |
|---|
| 616 | debug_msg("biWidth= %d\n", pVih->bmiHeader.biWidth); |
|---|
| 617 | debug_msg("biHeight= %d\n", pVih->bmiHeader.biHeight); |
|---|
| 618 | debug_msg("biSize= %d\n", pVih->bmiHeader.biSize); |
|---|
| 619 | debug_msg("biPlanes= %d\n", pVih->bmiHeader.biPlanes); |
|---|
| 620 | debug_msg("biBitCount= %d\n", pVih->bmiHeader.biBitCount); |
|---|
| 621 | debug_msg("biCompression= %d\n", pVih->bmiHeader.biCompression); |
|---|
| 622 | debug_msg("biSizeImage= %d\n", pVih->bmiHeader.biSizeImage); |
|---|
| 623 | debug_msg("biXPelsPerMeter=%d\n", pVih->bmiHeader.biXPelsPerMeter); |
|---|
| 624 | debug_msg("biYPelsPerMeter=%d\n", pVih->bmiHeader.biYPelsPerMeter); |
|---|
| 625 | } |
|---|
| 626 | } |
|---|
| 627 | } |
|---|
| 628 | } |
|---|
| 629 | if (max_width_>0) |
|---|
| 630 | return TRUE; |
|---|
| 631 | |
|---|
| 632 | return FALSE; |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | void DirectShowGrabber::setCaptureOutputFormat() { |
|---|
| 636 | IAMStreamConfig *pConfig; |
|---|
| 637 | int iCount; |
|---|
| 638 | int iSize; |
|---|
| 639 | int curr_w=0; |
|---|
| 640 | int curr_h=0; |
|---|
| 641 | int temp_w, temp_h; |
|---|
| 642 | VIDEOINFOHEADER *pVih; |
|---|
| 643 | VIDEO_STREAM_CONFIG_CAPS scc; |
|---|
| 644 | AM_MEDIA_TYPE *pmtConfig; |
|---|
| 645 | int formatSet; |
|---|
| 646 | HRESULT hr; |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | debug_msg("DirectShowGrabber::setCaptureOutputFormat(): enter...\n"); |
|---|
| 651 | |
|---|
| 652 | formatSet = 0; |
|---|
| 653 | pConfig = NULL; |
|---|
| 654 | hr = pBuild_->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, |
|---|
| 655 | pCaptureFilter_, IID_IAMStreamConfig, (void**)&pConfig); |
|---|
| 656 | if (FAILED(hr)) { |
|---|
| 657 | debug_msg("Failed to FindInterface\n"); |
|---|
| 658 | Grabber::status_=-1; |
|---|
| 659 | return; |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | debug_msg("DirectShowGrabber::setCaptureOutputFormat(): IAMStreamConfig interface acquired\n"); |
|---|
| 663 | |
|---|
| 664 | iCount = iSize = 0; |
|---|
| 665 | hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize); |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | if ( iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS) ) { |
|---|
| 669 | |
|---|
| 670 | for (int iFormat = 0; iFormat < iCount; iFormat++) { |
|---|
| 671 | hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc); |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | if( SUCCEEDED(hr) ) { |
|---|
| 675 | if ((pmtConfig->majortype == MEDIATYPE_Video) && |
|---|
| 676 | |
|---|
| 677 | (pmtConfig->formattype == FORMAT_VideoInfo) && |
|---|
| 678 | (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) && |
|---|
| 679 | (pmtConfig->pbFormat != NULL) |
|---|
| 680 | |
|---|
| 681 | ){ |
|---|
| 682 | |
|---|
| 683 | if ((abs(width_ - scc.MaxOutputSize.cx) + abs(height_ - scc.MaxOutputSize.cy))< |
|---|
| 684 | (abs(width_ - curr_w) +abs(height_ - curr_h))) { |
|---|
| 685 | |
|---|
| 686 | pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat; |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | debug_msg("fps_= %d\n", fps_); |
|---|
| 698 | |
|---|
| 699 | debug_msg("Windows GDI BITMAPINFOHEADER follows:\n"); |
|---|
| 700 | debug_msg("biWidth= %d\n", pVih->bmiHeader.biWidth); |
|---|
| 701 | debug_msg("biHeight= %d\n", pVih->bmiHeader.biHeight); |
|---|
| 702 | debug_msg("biSize= %d\n", pVih->bmiHeader.biSize); |
|---|
| 703 | debug_msg("biPlanes= %d\n", pVih->bmiHeader.biPlanes); |
|---|
| 704 | debug_msg("biBitCount= %d\n", pVih->bmiHeader.biBitCount); |
|---|
| 705 | debug_msg("biCompression= %d\n", pVih->bmiHeader.biCompression); |
|---|
| 706 | debug_msg("biSizeImage= %d\n", pVih->bmiHeader.biSizeImage); |
|---|
| 707 | debug_msg("biXPelsPerMeter=%d\n", pVih->bmiHeader.biXPelsPerMeter); |
|---|
| 708 | debug_msg("biYPelsPerMeter=%d\n", pVih->bmiHeader.biYPelsPerMeter); |
|---|
| 709 | debug_msg("biClrUsed= %d\n", pVih->bmiHeader.biClrUsed); |
|---|
| 710 | debug_msg("biClrImportant= %d\n", pVih->bmiHeader.biClrImportant); |
|---|
| 711 | |
|---|
| 712 | |
|---|
| 713 | temp_w = pVih->bmiHeader.biWidth; |
|---|
| 714 | temp_h = pVih->bmiHeader.biHeight; |
|---|
| 715 | pVih->bmiHeader.biWidth = width_; |
|---|
| 716 | pVih->bmiHeader.biHeight = height_; |
|---|
| 717 | hr = pConfig->SetFormat(pmtConfig); |
|---|
| 718 | if (SUCCEEDED(hr)) { |
|---|
| 719 | curr_w = width_; |
|---|
| 720 | curr_h = height_; |
|---|
| 721 | formatSet = 1; |
|---|
| 722 | debug_msg("Set(wxh): %dx%d, and Got: %dx%d\n",width_,height_, pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight); |
|---|
| 723 | break; |
|---|
| 724 | } else { |
|---|
| 725 | if ((temp_w < width_) && (temp_h < height_)) { |
|---|
| 726 | pVih->bmiHeader.biWidth = temp_w; |
|---|
| 727 | pVih->bmiHeader.biHeight = temp_h; |
|---|
| 728 | hr = pConfig->SetFormat(pmtConfig); |
|---|
| 729 | if (SUCCEEDED(hr)) { |
|---|
| 730 | curr_w = temp_w; |
|---|
| 731 | curr_h = temp_h; |
|---|
| 732 | formatSet = 1; |
|---|
| 733 | debug_msg("Set(wxh): %dx%d, and Got: %dx%d\n",width_,height_, pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight); |
|---|
| 734 | } |
|---|
| 735 | } else { |
|---|
| 736 | debug_msg("Failed to Set format this time - trying again\n"); |
|---|
| 737 | } |
|---|
| 738 | } |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | } |
|---|
| 743 | } |
|---|
| 744 | } |
|---|
| 745 | } |
|---|
| 746 | pConfig->Release(); |
|---|
| 747 | |
|---|
| 748 | if ( formatSet ) { |
|---|
| 749 | if ( (curr_w != width_) || (curr_h != height_ )) { |
|---|
| 750 | width_ = curr_w; |
|---|
| 751 | height_ = curr_h; |
|---|
| 752 | debug_msg("DirectShowGrabber::setCaptureOutputFormat: format set to near res: %dx%d\n",width_,height_); |
|---|
| 753 | } else |
|---|
| 754 | debug_msg("DirectShowGrabber::setCaptureOutputFormat: format set\n"); |
|---|
| 755 | } |
|---|
| 756 | else |
|---|
| 757 | debug_msg("DirectShowGrabber::setCaptureOutputFormat: format not set\n"); |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | int DirectShowGrabber::command(int argc, const char* const* argv) { |
|---|
| 763 | |
|---|
| 764 | if (argc == 3) { |
|---|
| 765 | if (strcmp(argv[1], "decimate") == 0) { |
|---|
| 766 | u_int dec = (u_int)atoi(argv[2]); |
|---|
| 767 | Tcl& tcl = Tcl::instance(); |
|---|
| 768 | if (dec <= 0) { |
|---|
| 769 | tcl.resultf("%s: divide by zero", argv[0]); |
|---|
| 770 | return (TCL_ERROR); |
|---|
| 771 | } |
|---|
| 772 | debug_msg("DirectShowGrabber::command: decimate=%d (dec)=%d\n", dec, decimate_); |
|---|
| 773 | if (dec != decimate_) { |
|---|
| 774 | decimate_ = dec; |
|---|
| 775 | if (running_) { |
|---|
| 776 | stop(); |
|---|
| 777 | setsize(); |
|---|
| 778 | setCaptureOutputFormat(); |
|---|
| 779 | start(); |
|---|
| 780 | } else{ |
|---|
| 781 | setsize(); |
|---|
| 782 | setCaptureOutputFormat(); |
|---|
| 783 | } |
|---|
| 784 | } |
|---|
| 785 | return (TCL_OK); |
|---|
| 786 | } else if (strcmp(argv[1], "port") == 0) { |
|---|
| 787 | setport(argv[2]); |
|---|
| 788 | return (TCL_OK); |
|---|
| 789 | } else if (strcmp(argv[1], "type") == 0) { |
|---|
| 790 | if (strcmp(argv[2], "auto") == 0) |
|---|
| 791 | ; |
|---|
| 792 | else if (strcmp(argv[2], "pal") == 0) { |
|---|
| 793 | basewidth_ = CIF_BASE_WIDTH; |
|---|
| 794 | baseheight_ = CIF_BASE_HEIGHT; |
|---|
| 795 | } else if (strcmp(argv[2], "ntsc") == 0) { |
|---|
| 796 | basewidth_ = NTSC_BASE_WIDTH; |
|---|
| 797 | baseheight_ = NTSC_BASE_HEIGHT; |
|---|
| 798 | } |
|---|
| 799 | if (running_) { |
|---|
| 800 | stop(); |
|---|
| 801 | setsize(); |
|---|
| 802 | setCaptureOutputFormat(); |
|---|
| 803 | start(); |
|---|
| 804 | } else if (decimate_!=-1) { |
|---|
| 805 | setsize(); |
|---|
| 806 | setCaptureOutputFormat(); |
|---|
| 807 | } |
|---|
| 808 | return (TCL_OK); |
|---|
| 809 | } else if (strcmp(argv[1], "useconfig") ==0) { |
|---|
| 810 | if (strcmp(argv[2], "1") == 0) |
|---|
| 811 | useconfig_=1; |
|---|
| 812 | if (strcmp(argv[2], "0") == 0) |
|---|
| 813 | useconfig_=0; |
|---|
| 814 | } |
|---|
| 815 | } |
|---|
| 816 | return (Grabber::command(argc, argv)); |
|---|
| 817 | |
|---|
| 818 | } |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | DirectShowCIFGrabber::DirectShowCIFGrabber(IBaseFilter *f) : DirectShowGrabber(f) { |
|---|
| 824 | debug_msg("DirectShowCIFGrabber\n"); |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | DirectShowCIFGrabber::~DirectShowCIFGrabber() { |
|---|
| 830 | debug_msg("~DirectShowCIFGrabber\n"); |
|---|
| 831 | } |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | void DirectShowCIFGrabber::start() { |
|---|
| 836 | DirectShowGrabber::start(); |
|---|
| 837 | converter(new RGB_Converter_411(24, (u_int8_t *)NULL, 0)); |
|---|
| 838 | ReleaseMutex(cb_mutex_); |
|---|
| 839 | Grabber::timeout(); |
|---|
| 840 | } |
|---|
| 841 | |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | void DirectShowCIFGrabber::setsize() { |
|---|
| 845 | |
|---|
| 846 | if(max_width_ >= D1_BASE_WIDTH){ |
|---|
| 847 | max_width_ = D1_BASE_WIDTH; |
|---|
| 848 | max_height_ = D1_BASE_HEIGHT; |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | if(decimate_ == 1){ |
|---|
| 852 | width_ = max_width_; |
|---|
| 853 | height_ = max_height_; |
|---|
| 854 | } else { |
|---|
| 855 | width_ = basewidth_ / decimate_; |
|---|
| 856 | height_ = baseheight_ / decimate_; |
|---|
| 857 | } |
|---|
| 858 | |
|---|
| 859 | debug_msg("DirectShowCIFGrabber::setsize: %dx%d\n", width_, height_); |
|---|
| 860 | |
|---|
| 861 | set_size_cif(width_, height_); |
|---|
| 862 | allocref(); |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | DirectShowDevice::DirectShowDevice(char *friendlyName, IBaseFilter *pCapFilt) : InputDevice(friendlyName) { |
|---|
| 869 | |
|---|
| 870 | attri = new char[100]; |
|---|
| 871 | attri[0] = 0; |
|---|
| 872 | |
|---|
| 873 | debug_msg("new DirectShowDevice(): friendlyName=%s\n", friendlyName); |
|---|
| 874 | directShowFilter_ = pCapFilt; |
|---|
| 875 | |
|---|
| 876 | attributes_ = "format { 411 } size { large small cif } port { external-in } type {pal ntsc} "; |
|---|
| 877 | DirectShowCIFGrabber o(directShowFilter_); |
|---|
| 878 | |
|---|
| 879 | strcat(attri, "format { 411 } size { large small cif } type { pal ntsc } port { "); |
|---|
| 880 | if(o.hasSVideo() || o.hasComposite()){ |
|---|
| 881 | if(o.hasSVideo()){ |
|---|
| 882 | strcat(attri, "S-Video "); |
|---|
| 883 | } |
|---|
| 884 | if(o.hasComposite()){ |
|---|
| 885 | strcat(attri, "Composite "); |
|---|
| 886 | } |
|---|
| 887 | }else{ |
|---|
| 888 | strcat(attri, "extern-in "); |
|---|
| 889 | } |
|---|
| 890 | |
|---|
| 891 | strcat(attri, "} "); |
|---|
| 892 | attributes_ = attri; |
|---|
| 893 | } |
|---|
| 894 | |
|---|
| 895 | DirectShowDevice::~DirectShowDevice(){ |
|---|
| 896 | delete attri; |
|---|
| 897 | } |
|---|
| 898 | |
|---|
| 899 | |
|---|
| 900 | int DirectShowDevice::command(int argc, const char* const* argv) { |
|---|
| 901 | Tcl& tcl = Tcl::instance(); |
|---|
| 902 | if ((argc == 3) && (strcmp(argv[1], "open") == 0)) { |
|---|
| 903 | TclObject* o = 0; |
|---|
| 904 | if (strcmp(argv[2], "cif") == 0){ |
|---|
| 905 | o = directShowGrabber_ = new DirectShowCIFGrabber(directShowFilter_); |
|---|
| 906 | }else if (strcmp(argv[2], "422") == 0) |
|---|
| 907 | o = directShowGrabber_ = 0; |
|---|
| 908 | |
|---|
| 909 | if (o != 0) |
|---|
| 910 | Tcl::instance().result(o->name()); |
|---|
| 911 | return (TCL_OK); |
|---|
| 912 | } |
|---|
| 913 | return (InputDevice::command(argc, argv)); |
|---|
| 914 | } |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | DirectShowScanner::DirectShowScanner() { |
|---|
| 920 | ICreateDevEnum *pDevEnum = 0; |
|---|
| 921 | int hr; |
|---|
| 922 | int devNum; |
|---|
| 923 | char nameBuf[80]; |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | debug_msg("new DirectShowScanner()\n"); |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | hr=CoInitialize(NULL); |
|---|
| 931 | if (FAILED(hr)) { |
|---|
| 932 | debug_msg("Failed COM subsystem initialisation.\n"); |
|---|
| 933 | return; |
|---|
| 934 | } |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (LPVOID*)&pDevEnum); |
|---|
| 938 | if (FAILED(hr)) { |
|---|
| 939 | debug_msg("Failed to Create a helper object to find the DS capture devices.\n"); |
|---|
| 940 | CoUninitialize(); |
|---|
| 941 | return; |
|---|
| 942 | } |
|---|
| 943 | |
|---|
| 944 | IEnumMoniker *pEnum = 0; |
|---|
| 945 | IMoniker *pMoniker = 0; |
|---|
| 946 | IPropertyBag *pPropBag = 0; |
|---|
| 947 | VARIANT varName; |
|---|
| 948 | CLSID clsid; |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0); |
|---|
| 952 | |
|---|
| 953 | if (FAILED(hr) || pEnum == 0) { |
|---|
| 954 | debug_msg("Failed to Get an enumerator over DS video capture filters.\n"); |
|---|
| 955 | CoUninitialize(); |
|---|
| 956 | return; |
|---|
| 957 | } |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | for( devNum=0; devNum < NUM_DEVS; ++devNum) { |
|---|
| 961 | if ( pEnum->Next(1, &pMoniker, NULL) == S_OK ) { |
|---|
| 962 | |
|---|
| 963 | hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); |
|---|
| 964 | if (FAILED(hr)) { |
|---|
| 965 | debug_msg("Failed to Get propbag bound to storage on DS dev: %d\n", devNum); |
|---|
| 966 | continue; |
|---|
| 967 | } |
|---|
| 968 | |
|---|
| 969 | debug_msg("propbag bound to storage ok= %d\n", hr); |
|---|
| 970 | |
|---|
| 971 | VariantInit(&varName); |
|---|
| 972 | hr = pPropBag->Read(L"FriendlyName", &varName, 0); |
|---|
| 973 | if (FAILED(hr)) { |
|---|
| 974 | debug_msg("Failed to Get friendly name read on DS dev: %d\n", devNum); |
|---|
| 975 | continue; |
|---|
| 976 | } |
|---|
| 977 | |
|---|
| 978 | debug_msg("friendly name read ok= %d\n", hr); |
|---|
| 979 | |
|---|
| 980 | |
|---|
| 981 | USES_CONVERSION; |
|---|
| 982 | strcpy(nameBuf, W2A(varName.bstrVal)); |
|---|
| 983 | |
|---|
| 984 | debug_msg("DirectShowScanner::DirectShowScanner(): found nameBuf/FriendlyName=%s\n", nameBuf); |
|---|
| 985 | |
|---|
| 986 | |
|---|
| 987 | |
|---|
| 988 | hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void **)(pCaptureFilter+devNum)); |
|---|
| 989 | if (FAILED(hr)) { |
|---|
| 990 | debug_msg("Failed to Get friendly name read on DS dev: %d\n", devNum); |
|---|
| 991 | continue; |
|---|
| 992 | } |
|---|
| 993 | debug_msg("capture filter bound ok= [%d} %s\n", hr, nameBuf); |
|---|
| 994 | pCaptureFilter[devNum]->GetClassID(&clsid); |
|---|
| 995 | if (!IsEqualGUID(clsid,CLSID_VfwCapture)) { |
|---|
| 996 | debug_msg("Adding capture filter %d\n", hr); |
|---|
| 997 | devs_[devNum] = new DirectShowDevice(strdup(nameBuf), pCaptureFilter[devNum]); |
|---|
| 998 | } else { |
|---|
| 999 | debug_msg("discarding an apparent VFW device= %s\n", nameBuf); |
|---|
| 1000 | devs_[devNum] = NULL; |
|---|
| 1001 | } |
|---|
| 1002 | VariantClear(&varName); |
|---|
| 1003 | pPropBag->Release(); |
|---|
| 1004 | } |
|---|
| 1005 | } |
|---|
| 1006 | |
|---|
| 1007 | |
|---|
| 1008 | pMoniker->Release(); |
|---|
| 1009 | pEnum->Release(); |
|---|
| 1010 | pDevEnum->Release(); |
|---|
| 1011 | } |
|---|
| 1012 | |
|---|
| 1013 | |
|---|
| 1014 | |
|---|
| 1015 | DirectShowScanner::~DirectShowScanner() { |
|---|
| 1016 | |
|---|
| 1017 | CoUninitialize(); |
|---|
| 1018 | debug_msg("~DirectShowScanner()\n"); |
|---|
| 1019 | } |
|---|