Changeset 489
- Timestamp:
- Jul 21, 2015, 11:24:44 AM (8 years ago)
- Location:
- trunk/DirectShowSpy
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DirectShowSpy/FilterGraphSpy.h
r441 r489 400 400 } 401 401 return S_OK; 402 } 403 }; 404 405 //////////////////////////////////////////////////////// 406 // CLogFilter 407 408 class __declspec(uuid("{DC544824-CC2C-4CEF-AABC-9FA815530733}")) CLogFilterBase; 409 410 class ATL_NO_VTABLE CLogFilter : 411 public CComObjectRootEx<CComMultiThreadModelNoCS>, 412 public CComCoClass<CLogFilter, &__uuidof(CLogFilterBase)>, 413 public CTransformationFilterT<CLogFilter>, 414 public CBasePersistT<CLogFilter> 415 { 416 public: 417 //enum { IDR = }; 418 419 //DECLARE_REGISTRY_RESOURCEID(IDR) 420 421 DECLARE_PROTECT_FINAL_CONSTRUCT() 422 423 //DECLARE_QI_TRACE(CLogFilter) 424 425 BEGIN_COM_MAP(CLogFilter) 426 COM_INTERFACE_ENTRY(IBaseFilter) 427 COM_INTERFACE_ENTRY(IMediaFilter) 428 COM_INTERFACE_ENTRY_IID(__uuidof(IPersist), IBaseFilter) 429 END_COM_MAP() 430 431 BEGIN_PROP_MAP(CLogFilter) 432 END_PROP_MAP() 433 434 public: 435 436 //////////////////////////////////////////////////////// 437 // CInputPin 438 439 class ATL_NO_VTABLE CInputPin : 440 public CComObjectRootEx<CComMultiThreadModelNoCS>, 441 public CInputPinT<CInputPin, CLogFilter> 442 { 443 public: 444 445 //DECLARE_QI_TRACE(CInspectionFilter::CLogFilter) 446 447 BEGIN_COM_MAP(CInputPin) 448 COM_INTERFACE_ENTRY(IPin) 449 COM_INTERFACE_ENTRY(IMemInputPin) 450 END_COM_MAP() 451 452 public: 453 // CInputPin 454 CInputPin() 455 { 456 _Z5_THIS(); 457 } 458 ~CInputPin() 459 { 460 _Z5_THIS(); 461 } 462 BOOL CheckMediaType(const CMediaType& pMediaType) const 463 { 464 _A(pMediaType); 465 return TRUE; 466 } 467 VOID ResetPeerPin() 468 { 469 CRoCriticalSectionLock DataLock(GetDataCriticalSection()); 470 __super::ResetPeerPin(); 471 GetFilter()->DisconnectPin(GetFilter()->GetOutputPin()); 472 } 473 }; 474 475 //////////////////////////////////////////////////////// 476 // COutputPin 477 478 class ATL_NO_VTABLE COutputPin : 479 public CComObjectRootEx<CComMultiThreadModelNoCS>, 480 public COutputPinT<COutputPin, CLogFilter>, 481 public CUpstreamMediaPositionAwareOutputPinT<COutputPin> 482 { 483 public: 484 485 //DECLARE_QI_TRACE(CInspectionFilter::COutputPin) 486 487 BEGIN_COM_MAP(COutputPin) 488 COM_INTERFACE_ENTRY(IPin) 489 COM_INTERFACE_ENTRY_FUNC(__uuidof(IMediaSeeking), 0, QueryUpstreamMediaPositionInterface) 490 COM_INTERFACE_ENTRY_FUNC(__uuidof(IMediaPosition), 0, QueryUpstreamMediaPositionInterface) 491 COM_INTERFACE_ENTRY_FUNC(__uuidof(IDispatch), 0, QueryUpstreamMediaPositionInterface) 492 END_COM_MAP() 493 494 public: 495 // COutputPin 496 COutputPin() 497 { 498 _Z5_THIS(); 499 } 500 ~COutputPin() 501 { 502 _Z5_THIS(); 503 } 504 HRESULT FinalConstruct() 505 { 506 _ATLTRY 507 { 508 CreateUpstreamMediaPosition(); 509 } 510 _ATLCATCH(Exception) 511 { 512 _C(Exception); 513 } 514 return S_OK; 515 } 516 VOID FinalRelease() 517 { 518 DestroyUpstreamMediaPosition(); 519 } 520 VOID EnumerateMediaTypes(CRoListT<CMediaType>& MediaTypeList) const 521 { 522 CRoCriticalSectionLock DataLock(GetDataCriticalSection()); 523 const CMediaType& pInputMediaType = GetFilter()->GetInputPin()->GetMediaTypeReference(); 524 if(pInputMediaType) 525 _W(MediaTypeList.AddTail(pInputMediaType)); 526 } 527 BOOL CheckMediaType(const CMediaType& pMediaType) const 528 { 529 _A(pMediaType); 530 const CObjectPtr<CInputPin>& pInputPin = GetFilter()->GetInputPin(); 531 CRoCriticalSectionLock DataLock(GetDataCriticalSection()); 532 const CComPtr<IPin>& pInputPeerPin = pInputPin->GetPeerPinReference(); 533 if(!pInputPeerPin) 534 return FALSE; // No Input Connected 535 const CMediaType& pInputMediaType = pInputPin->GetMediaTypeReference(); 536 if(!pInputMediaType.Compare(pMediaType)) 537 return FALSE; // Input Media Type Mismatch 538 return TRUE; 539 } 540 BOOL DecideMemAllocator(const CMediaType& pMediaType) 541 { 542 _A(VerifyCriticalSectionLocked(GetDataCriticalSection())); 543 _A(GetPeerMemInputPinReference()); 544 const CObjectPtr<CInputPin>& pInputPin = GetFilter()->GetInputPin(); 545 const CComPtr<IMemAllocator>& pMemAllocator = pInputPin->GetMemAllocatorReference(); 546 const HRESULT nNotifyAllocatorResult = GetPeerMemInputPinReference()->NotifyAllocator(pMemAllocator, pInputPin->GetMemAllocatorReadOnly()); 547 _Z45_DSHRESULT(nNotifyAllocatorResult); 548 if(FAILED(nNotifyAllocatorResult)) 549 return FALSE; 550 SetMemAllocator(pMemAllocator); 551 return TRUE; 552 } 553 }; 554 555 private: 556 CObjectPtr<CInputPin> m_pInputPin; 557 CObjectPtr<COutputPin> m_pOutputPin; 558 559 public: 560 // CLogFilter 561 CLogFilter() : 562 CBasePersistT<CLogFilter>(GetDataCriticalSection()) 563 { 564 _Z4_THIS(); 565 } 566 ~CLogFilter() 567 { 568 _Z4_THIS(); 569 } 570 HRESULT FinalConstruct() 571 { 572 _ATLTRY 573 { 574 m_pInputPin.Construct()->Initialize(this, L"Input"); 575 m_pOutputPin.Construct()->Initialize(this, L"Output"); 576 AddPins(2, (IPin*) m_pInputPin, (IPin*) m_pOutputPin); 577 } 578 _ATLCATCH(Exception) 579 { 580 _C(Exception); 581 } 582 return S_OK; 583 } 584 VOID FinalRelease() 585 { 586 m_pInputPin.Release(); 587 m_pOutputPin.Release(); 588 } 589 VOID DeliverEndOfStream(CInputPin*) 590 { 591 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\"\n"), this, GetName()); 592 CRoCriticalSectionLock ReceiveLock(GetReceiveCriticalSection()); 593 m_pOutputPin->DeliverEndOfStream(); 594 } 595 VOID DeliverBeginFlush(CInputPin*) 596 { 597 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\"\n"), this, GetName()); 598 m_pOutputPin->DeliverBeginFlush(); 599 } 600 VOID DeliverEndFlush(CInputPin*) 601 { 602 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\"\n"), this, GetName()); 603 m_pOutputPin->DeliverEndFlush(); 604 } 605 VOID DeliverNewSegment(CInputPin*, REFERENCE_TIME nStartTime, REFERENCE_TIME nStopTime, DOUBLE fRate) 606 { 607 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\", nStartTime %s, nStopTime %s, fRate %.3f\n"), this, GetName(), _FilterGraphHelper::FormatReferenceTime(nStartTime), _FilterGraphHelper::FormatReferenceTime(nStopTime), fRate); 608 m_pOutputPin->DeliverNewSegment(nStartTime, nStopTime, fRate); 609 } 610 VOID CueFilter() 611 { 612 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\"\n"), this, GetName()); 613 CRoCriticalSectionLock ReceiveLock(GetReceiveCriticalSection()); 614 StartStreaming(); 615 } 616 VOID RunFilter(REFERENCE_TIME nStartTime) 617 { 618 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\"\n"), this, GetName()); 619 nStartTime; 620 } 621 VOID PauseFilter() 622 { 623 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\"\n"), this, GetName()); 624 } 625 VOID StopFilter() 626 { 627 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\"\n"), this, GetName()); 628 CRoCriticalSectionLock ReceiveLock(GetReceiveCriticalSection()); 629 StopStreaming(); 630 } 631 VOID ReceiveMediaSample(CInputPin* pInputPin, IMediaSample2* pMediaSample, HRESULT& nReceiveResult) 632 { 633 _A(pInputPin == m_pInputPin); 634 _A(pMediaSample); 635 CRoCriticalSectionLock ReceiveLock(GetReceiveCriticalSection()); 636 if(!IsStreaming()) 637 return; 638 CMediaSampleProperties Properties(pMediaSample); 639 { 640 CRoArrayT<CString> Array1, Array2; 641 Array2.Add(AtlFormatString(_T("%d"), GetTickCount())); 642 Array2.Add(GetName()); 643 Array1.Add(AtlFormatString(_T("dwSampleFlags %s"), _FilterGraphHelper::FormatSampleFlags(Properties.dwSampleFlags))); 644 Array2.Add(AtlFormatString(_T("0x%X"), Properties.dwSampleFlags)); 645 if(Properties.dwSampleFlags & AM_SAMPLE_TIMEVALID) 646 { 647 Array1.Add(AtlFormatString(_T("tStart %s"), _FilterGraphHelper::FormatReferenceTime(Properties.tStart))); 648 Array2.Add(AtlFormatString(_T("%I64d"), Properties.tStart)); 649 if(Properties.dwSampleFlags & AM_SAMPLE_STOPVALID) 650 { 651 Array1.Add(AtlFormatString(_T("tStop %s (+ %s)"), _FilterGraphHelper::FormatReferenceTime(Properties.tStop), _FilterGraphHelper::FormatReferenceTime(Properties.tStop - Properties.tStart))); 652 Array2.Add(AtlFormatString(_T("%I64d"), Properties.tStop)); 653 Array2.Add(AtlFormatString(_T("%I64d"), Properties.tStop - Properties.tStart)); 654 } 655 } 656 Array1.Add(AtlFormatString(_T("lActual %s"), _StringHelper::FormatNumber(Properties.lActual))); 657 _Z2(atlTraceGeneral, 2, _T("this 0x%p, \"%ls\", %s") _T("\t\t%s\t") _T("\n"), this, GetName(), _StringHelper::Join(Array1, _T(", ")), _StringHelper::Join(Array2, _T("\t"))); 658 } 659 HandleMediaTypeChange<CInputPin, COutputPin>(Properties, m_pInputPin, m_pOutputPin); 660 DeliverMediaSample(m_pOutputPin->GetPeerMemInputPin(), pMediaSample, nReceiveResult); 661 } 662 const CObjectPtr<CInputPin>& GetInputPin() const 663 { 664 return m_pInputPin; 665 } 666 const CObjectPtr<COutputPin>& GetOutputPin() const 667 { 668 return m_pOutputPin; 402 669 } 403 670 }; … … 1030 1297 if(pMediaType) 1031 1298 _FilterGraphHelper::TraceMediaType(pMediaType); 1299 #pragma region Log Filter 1300 // NOTE: This inserts additional filter without graph owner's will, for troubleshooting purposes; CLogFilter logs streaming details 1301 #if FALSE 1302 const CComPtr<IBaseFilter> pOutputBaseFilter = _FilterGraphHelper::GetPinFilter(pOutputPin); 1303 const CComPtr<IBaseFilter> pInputBaseFilter = _FilterGraphHelper::GetPinFilter(pInputPin); 1304 class __declspec(uuid("{09075D10-D7EC-420f-A8F9-940E1602A371}")) AudioSplitter; 1305 if(_FilterGraphHelper::GetFilterClassIdentifier(pOutputBaseFilter) == __uuidof(AudioSplitter) || _FilterGraphHelper::GetFilterClassIdentifier(pInputBaseFilter) == __uuidof(AudioSplitter)) 1306 _ATLTRY 1307 { 1308 _A(_FilterGraphHelper::GetPinDirection(pOutputPin) == PINDIR_OUTPUT); 1309 CObjectPtr<CLogFilter> pLogFilter; 1310 pLogFilter.Construct(); 1311 CString sName = AtlFormatString(_T("Log (%s; %s)"), _FilterGraphHelper::GetFilterName(pOutputBaseFilter), _FilterGraphHelper::GetFilterName(pInputBaseFilter)); 1312 __C(m_pInnerFilterGraph2->AddFilter(pLogFilter, CStringW(sName))); 1313 _ATLTRY 1314 { 1315 __C(m_pInnerFilterGraph2->ConnectDirect(pOutputPin, pLogFilter->GetInputPin(), pMediaType)); 1316 __C(m_pInnerFilterGraph2->ConnectDirect(pLogFilter->GetOutputPin(), pInputPin, pMediaType)); 1317 _Z4(atlTraceGeneral, 4, _T("this 0x%p, pLogFilter->GetName() \"%ls\"\n"), this, pLogFilter->GetName()); 1318 return S_OK; 1319 } 1320 _ATLCATCHALL() 1321 { 1322 __C(m_pInnerFilterGraph2->RemoveFilter(pLogFilter)); 1323 _ATLRETHROW; 1324 } 1325 } 1326 _ATLCATCHALL() 1327 { 1328 _Z_EXCEPTION(); 1329 } 1330 #endif 1331 #pragma endregion 1032 1332 } 1033 1333 _ATLCATCHALL()
Note: See TracChangeset
for help on using the changeset viewer.