Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.9 KiB

  1. //==========================================================================;
  2. //
  3. // fileplaybackimpl.h : additional infrastructure to support implementing IMSVidPlayback
  4. // nicely from c++
  5. // Copyright (c) Microsoft Corporation 1999.
  6. //
  7. /////////////////////////////////////////////////////////////////////////////
  8. #pragma once
  9. #ifndef FILEPLAYBACKIMPL_H
  10. #define FILEPLAYBACKIMPL_H
  11. #include "playbackimpl.h"
  12. namespace MSVideoControl {
  13. template<class T, LPCGUID LibID, LPCGUID KSCategory, class MostDerivedInterface = IMSVidFilePlayback>
  14. class DECLSPEC_NOVTABLE IMSVidFilePlaybackImpl :
  15. public IMSVidPlaybackImpl<T, LibID, KSCategory, MostDerivedInterface> {
  16. protected:
  17. CComBSTR m_FileName;
  18. int m_iReader;
  19. bool m_fGraphInit;
  20. public:
  21. IMSVidFilePlaybackImpl() :
  22. m_iReader(-1),
  23. m_fGraphInit(false)
  24. {}
  25. virtual ~IMSVidFilePlaybackImpl() {}
  26. STDMETHOD(get_FileName)(BSTR * pFileName) {
  27. if (!m_fInit) {
  28. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidFilePlayback), CO_E_NOTINITIALIZED);
  29. }
  30. if (!pFileName) {
  31. return E_POINTER;
  32. }
  33. *pFileName = m_FileName.Copy();
  34. return NOERROR;
  35. }
  36. STDMETHOD(InitGraph)(){
  37. TRACELM(TRACE_DETAIL, "MSVidFilePlaybackImpl::InitGraph()");
  38. HRESULT hr = put_CurrentPosition(0);
  39. if(FAILED(hr)){
  40. //ASSERT(SUCCEEDED(hr)); // This fails sometimes, we should just ignore it.
  41. TRACELM(TRACE_ERROR, "MSVidFilePlaybackImpl::InitGraph() put_CurrentPosition(0) failed");
  42. }
  43. hr = put_Rate(1);
  44. if(FAILED(hr)){
  45. //ASSERT(SUCCEEDED(hr)); // This fails sometimes, we should just ignore it.
  46. TRACELM(TRACE_ERROR, "MSVidFilePlaybackImpl::InitGraph() put_Rate(1) Normal failed");
  47. }
  48. hr = IMSVidPlaybackImpl<T, LibID, KSCategory, MostDerivedInterface>::put_Rate(1);
  49. if(FAILED(hr)){
  50. //ASSERT(SUCCEEDED(hr)); // This fails sometimes, we should just ignore it.
  51. TRACELM(TRACE_ERROR, "MSVidFilePlaybackImpl::InitGraph() put_Rate(1) Base class failed");
  52. }
  53. return NOERROR;
  54. }
  55. STDMETHOD(put_FileName) (BSTR FileName) {
  56. if (!FileName) {
  57. return E_POINTER;
  58. }
  59. if (!m_fInit) {
  60. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidFilePlayback), CO_E_NOTINITIALIZED);
  61. }
  62. try {
  63. HRESULT hr;
  64. TRACELSM(TRACE_DETAIL, (dbgDump << "MSVidFilePlaybackImpl::put_FileName() name = " << FileName), "");
  65. if (m_pGraph && !m_pGraph.IsStopped()) {
  66. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidFilePlayback), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  67. }
  68. if (m_pContainer) {
  69. InitGraph();
  70. T* pT = static_cast<T*>(this);
  71. hr = m_pContainer->Decompose(pT);
  72. if (FAILED(hr)) {
  73. return ImplReportError(__uuidof(T), IDS_CANT_REMOVE_SEG, __uuidof(IMSVidFilePlayback), hr);
  74. }
  75. }
  76. if (m_Filters.size() && m_pContainer) {
  77. for (DSFilterList::iterator i = m_Filters.begin(); i != m_Filters.end(); ++i) {
  78. bool rc = m_pGraph.RemoveFilter(*i);
  79. if (!rc) {
  80. TRACELM(TRACE_ERROR, "MSVidFilePlaybackImpl::put_FileName() can't remove filter");
  81. return ImplReportError(__uuidof(T), IDS_CANT_REMOVE_FILTER, __uuidof(IMSVidFilePlayback), E_UNEXPECTED);
  82. }
  83. }
  84. m_Filters.clear();
  85. }
  86. m_FileName = FileName;
  87. m_fGraphInit = true;
  88. } catch(ComException &e) {
  89. m_Filters.clear();
  90. m_iReader = -1;
  91. return e;
  92. }
  93. return NOERROR;
  94. }
  95. };
  96. }; // namespace
  97. #endif
  98. // end of file - fileplaybackimpl.h