vtrans.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //------------------------------------------------------------------------------
  2. // File: VTrans.h
  3. //
  4. // Desc: DirectShow base classes - defines a video transform class.
  5. //
  6. // Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved.
  7. //------------------------------------------------------------------------------
  8. // This class is derived from CTransformFilter, but is specialised to handle
  9. // the requirements of video quality control by frame dropping.
  10. // This is a non-in-place transform, (i.e. it copies the data) such as a decoder.
  11. class CVideoTransformFilter : public CTransformFilter
  12. {
  13. public:
  14. CVideoTransformFilter(__in_opt LPCTSTR, __inout_opt LPUNKNOWN, REFCLSID clsid);
  15. ~CVideoTransformFilter();
  16. HRESULT EndFlush();
  17. // =================================================================
  18. // ----- override these bits ---------------------------------------
  19. // =================================================================
  20. // The following methods are in CTransformFilter which is inherited.
  21. // They are mentioned here for completeness
  22. //
  23. // These MUST be supplied in a derived class
  24. //
  25. // NOTE:
  26. // virtual HRESULT Transform(IMediaSample * pIn, IMediaSample *pOut);
  27. // virtual HRESULT CheckInputType(const CMediaType* mtIn) PURE;
  28. // virtual HRESULT CheckTransform
  29. // (const CMediaType* mtIn, const CMediaType* mtOut) PURE;
  30. // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *);
  31. // virtual HRESULT DecideBufferSize
  32. // (IMemAllocator * pAllocator, ALLOCATOR_PROPERTIES *pprop) PURE;
  33. // virtual HRESULT GetMediaType(int iPosition, CMediaType *pMediaType) PURE;
  34. //
  35. // These MAY also be overridden
  36. //
  37. // virtual HRESULT StopStreaming();
  38. // virtual HRESULT SetMediaType(PIN_DIRECTION direction,const CMediaType *pmt);
  39. // virtual HRESULT CheckConnect(PIN_DIRECTION dir,IPin *pPin);
  40. // virtual HRESULT BreakConnect(PIN_DIRECTION dir);
  41. // virtual HRESULT CompleteConnect(PIN_DIRECTION direction,IPin *pReceivePin);
  42. // virtual HRESULT EndOfStream(void);
  43. // virtual HRESULT BeginFlush(void);
  44. // virtual HRESULT EndFlush(void);
  45. // virtual HRESULT NewSegment
  46. // (REFERENCE_TIME tStart,REFERENCE_TIME tStop,double dRate);
  47. #ifdef PERF
  48. // If you override this - ensure that you register all these ids
  49. // as well as any of your own,
  50. virtual void RegisterPerfId() {
  51. m_idSkip = MSR_REGISTER(TEXT("Video Transform Skip frame"));
  52. m_idFrameType = MSR_REGISTER(TEXT("Video transform frame type"));
  53. m_idLate = MSR_REGISTER(TEXT("Video Transform Lateness"));
  54. m_idTimeTillKey = MSR_REGISTER(TEXT("Video Transform Estd. time to next key"));
  55. CTransformFilter::RegisterPerfId();
  56. }
  57. #endif
  58. protected:
  59. // =========== QUALITY MANAGEMENT IMPLEMENTATION ========================
  60. // Frames are assumed to come in three types:
  61. // Type 1: an AVI key frame or an MPEG I frame.
  62. // This frame can be decoded with no history.
  63. // Dropping this frame means that no further frame can be decoded
  64. // until the next type 1 frame.
  65. // Type 1 frames are sync points.
  66. // Type 2: an AVI non-key frame or an MPEG P frame.
  67. // This frame cannot be decoded unless the previous type 1 frame was
  68. // decoded and all type 2 frames since have been decoded.
  69. // Dropping this frame means that no further frame can be decoded
  70. // until the next type 1 frame.
  71. // Type 3: An MPEG B frame.
  72. // This frame cannot be decoded unless the previous type 1 or 2 frame
  73. // has been decoded AND the subsequent type 1 or 2 frame has also
  74. // been decoded. (This requires decoding the frames out of sequence).
  75. // Dropping this frame affects no other frames. This implementation
  76. // does not allow for these. All non-sync-point frames are treated
  77. // as being type 2.
  78. //
  79. // The spacing of frames of type 1 in a file is not guaranteed. There MUST
  80. // be a type 1 frame at (well, near) the start of the file in order to start
  81. // decoding at all. After that there could be one every half second or so,
  82. // there could be one at the start of each scene (aka "cut", "shot") or
  83. // there could be no more at all.
  84. // If there is only a single type 1 frame then NO FRAMES CAN BE DROPPED
  85. // without losing all the rest of the movie. There is no way to tell whether
  86. // this is the case, so we find that we are in the gambling business.
  87. // To try to improve the odds, we record the greatest interval between type 1s
  88. // that we have seen and we bet on things being no worse than this in the
  89. // future.
  90. // You can tell if it's a type 1 frame by calling IsSyncPoint().
  91. // there is no architected way to test for a type 3, so you should override
  92. // the quality management here if you have B-frames.
  93. int m_nKeyFramePeriod; // the largest observed interval between type 1 frames
  94. // 1 means every frame is type 1, 2 means every other.
  95. int m_nFramesSinceKeyFrame; // Used to count frames since the last type 1.
  96. // becomes the new m_nKeyFramePeriod if greater.
  97. BOOL m_bSkipping; // we are skipping to the next type 1 frame
  98. #ifdef PERF
  99. int m_idFrameType; // MSR id Frame type. 1=Key, 2="non-key"
  100. int m_idSkip; // MSR id skipping
  101. int m_idLate; // MSR id lateness
  102. int m_idTimeTillKey; // MSR id for guessed time till next key frame.
  103. #endif
  104. virtual HRESULT StartStreaming();
  105. HRESULT AbortPlayback(HRESULT hr); // if something bad happens
  106. HRESULT Receive(IMediaSample *pSample);
  107. HRESULT AlterQuality(Quality q);
  108. BOOL ShouldSkipFrame(IMediaSample * pIn);
  109. int m_itrLate; // lateness from last Quality message
  110. // (this overflows at 214 secs late).
  111. int m_tDecodeStart; // timeGetTime when decode started.
  112. int m_itrAvgDecode; // Average decode time in reference units.
  113. BOOL m_bNoSkip; // debug - no skipping.
  114. // We send an EC_QUALITY_CHANGE notification to the app if we have to degrade.
  115. // We send one when we start degrading, not one for every frame, this means
  116. // we track whether we've sent one yet.
  117. BOOL m_bQualityChanged;
  118. // When non-zero, don't pass anything to renderer until next keyframe
  119. // If there are few keys, give up and eventually draw something
  120. int m_nWaitForKey;
  121. };