home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / vtrans.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-28  |  6.8 KB  |  145 lines

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