audioswitch.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #ifndef _AUDIOSWITCH_H
  2. #define _AUDIOSWITCH_H
  3. #include <streams.h>
  4. class CAudioSwitchRenderer;
  5. class CAudioSwitchRendererInputPin;
  6. class CAudioSwitchRendererInputPin : public CBaseInputPin
  7. {
  8. protected:
  9. CAudioSwitchRenderer *m_pRenderer;
  10. CMediaType m_mt;
  11. public:
  12. HRESULT NotifyMediaType();
  13. CAudioSwitchRendererInputPin(CAudioSwitchRenderer *pRenderer,
  14. HRESULT *phr,
  15. LPCWSTR Name);
  16. // Overriden from the base pin classes
  17. HRESULT BreakConnect();
  18. HRESULT CompleteConnect(IPin *pReceivePin);
  19. HRESULT SetMediaType(const CMediaType *pmt);
  20. HRESULT CheckMediaType(const CMediaType *pmt);
  21. HRESULT Active();
  22. HRESULT Inactive();
  23. // Add rendering behaviour to interface functions
  24. STDMETHODIMP QueryId(LPWSTR *Id);
  25. STDMETHODIMP EndOfStream();
  26. STDMETHODIMP BeginFlush();
  27. STDMETHODIMP EndFlush();
  28. STDMETHODIMP Receive(IMediaSample *pMediaSample);
  29. // Helper
  30. IMemAllocator inline *Allocator() const
  31. {
  32. return m_pAllocator;
  33. }
  34. };
  35. class CAudioSwitchRenderer : public CBaseFilter
  36. {
  37. protected:
  38. friend class CAudioSwitchRendererInputPin;
  39. friend void CALLBACK EndOfStreamTimer(UINT uID, // Timer identifier
  40. UINT uMsg, // Not currently used
  41. DWORD_PTR dwUser, // User information
  42. DWORD_PTR dw1, // Windows reserved
  43. DWORD_PTR dw2); // Is also reserved
  44. CRendererPosPassThru *m_pPosition; // Media seeking pass by object
  45. CAMEvent m_RenderEvent; // Used to signal timer events
  46. CAMEvent m_ThreadSignal; // Signalled to release worker thread
  47. CAMEvent m_evComplete; // Signalled when state complete
  48. BOOL m_bAbort; // Stop us from rendering more data
  49. BOOL m_bStreaming; // Are we currently streaming
  50. DWORD_PTR m_dwAdvise; // Timer advise cookie
  51. IMediaSample *m_pMediaSample[16]; // Current image media samples
  52. BOOL m_bEOS; // Any more samples in the stream
  53. BOOL m_bEOSDelivered; // Have we delivered an EC_COMPLETE
  54. CAudioSwitchRendererInputPin *m_pInputPin[16]; // Our renderer input pin objects
  55. CCritSec m_InterfaceLock; // Critical section for interfaces
  56. CCritSec m_RendererLock; // Controls access to internals
  57. IQualityControl * m_pQSink; // QualityControl sink
  58. BOOL m_bRepaintStatus; // Can we signal an EC_REPAINT
  59. // Avoid some deadlocks by tracking filter during stop
  60. volatile BOOL m_bInReceive; // Inside Receive between PrepareReceive
  61. // And actually processing the sample
  62. REFERENCE_TIME m_SignalTime; // Time when we signal EC_COMPLETE
  63. UINT m_EndOfStreamTimer; // Used to signal end of stream
  64. int m_inputSelected; // input selected for rendering (0 to 16)
  65. public:
  66. CAudioSwitchRenderer(REFCLSID RenderClass, // CLSID for this renderer
  67. TCHAR *pName, // Debug ONLY description
  68. LPUNKNOWN pUnk, // Aggregated owner object
  69. HRESULT *phr); // General OLE return code
  70. virtual ~CAudioSwitchRenderer();
  71. // Overriden to say what interfaces we support and where
  72. virtual HRESULT GetMediaPositionInterface(REFIID riid,void **ppv);
  73. STDMETHODIMP NonDelegatingQueryInterface(REFIID, void **);
  74. virtual HRESULT SourceThreadCanWait(BOOL bCanWait);
  75. #ifdef DEBUG
  76. // Debug only dump of the renderer state
  77. void DisplayRendererState();
  78. #endif
  79. virtual HRESULT WaitForRenderTime();
  80. virtual HRESULT CompleteStateChange(FILTER_STATE OldState);
  81. // Return internal information about this filter
  82. BOOL IsEndOfStream() { return m_bEOS; };
  83. BOOL IsEndOfStreamDelivered() { return m_bEOSDelivered; };
  84. BOOL IsStreaming() { return m_bStreaming; };
  85. void SetAbortSignal(BOOL bAbort) { m_bAbort = bAbort; };
  86. CAMEvent *GetRenderEvent() { return &m_RenderEvent; };
  87. // Permit access to the transition state
  88. void Ready() { m_evComplete.Set(); };
  89. void NotReady() { m_evComplete.Reset(); };
  90. BOOL CheckReady() { return m_evComplete.Check(); };
  91. virtual int GetPinCount();
  92. virtual CBasePin *GetPin(int n);
  93. FILTER_STATE GetRealState();
  94. void SendRepaint();
  95. void SendNotifyWindow(IPin *pPin,HWND hwnd);
  96. BOOL OnDisplayChange();
  97. void SetRepaintStatus(BOOL bRepaint);
  98. // Override the filter and pin interface functions
  99. STDMETHODIMP Stop();
  100. STDMETHODIMP Pause();
  101. STDMETHODIMP Run(REFERENCE_TIME StartTime);
  102. STDMETHODIMP GetState(DWORD dwMSecs,FILTER_STATE *State);
  103. STDMETHODIMP FindPin(LPCWSTR Id, IPin **ppPin);
  104. // These are available for a quality management implementation
  105. virtual void OnRenderStart(IMediaSample *pMediaSample);
  106. virtual void OnRenderEnd(IMediaSample *pMediaSample);
  107. virtual HRESULT OnStartStreaming() { return NOERROR; };
  108. virtual HRESULT OnStopStreaming() { return NOERROR; };
  109. virtual void OnWaitStart() { };
  110. virtual void OnWaitEnd() { };
  111. virtual void PrepareRender() { };
  112. #ifdef PERF
  113. REFERENCE_TIME m_trRenderStart; // Just before we started drawing
  114. // Set in OnRenderStart, Used in OnRenderEnd
  115. int m_idBaseStamp; // MSR_id for frame time stamp
  116. int m_idBaseRenderTime; // MSR_id for true wait time
  117. int m_idBaseAccuracy; // MSR_id for time frame is late (int)
  118. #endif
  119. // Quality management implementation for scheduling rendering
  120. virtual BOOL ScheduleSample(IMediaSample *pMediaSample);
  121. virtual HRESULT GetSampleTimes(IMediaSample *pMediaSample,
  122. REFERENCE_TIME *pStartTime,
  123. REFERENCE_TIME *pEndTime);
  124. virtual HRESULT ShouldDrawSampleNow(IMediaSample *pMediaSample,
  125. REFERENCE_TIME *ptrStart,
  126. REFERENCE_TIME *ptrEnd);
  127. // Lots of end of stream complexities
  128. void TimerCallback();
  129. void ResetEndOfStreamTimer();
  130. HRESULT NotifyEndOfStream();
  131. virtual HRESULT SendEndOfStream();
  132. virtual HRESULT ResetEndOfStream();
  133. virtual HRESULT EndOfStream();
  134. // Rendering is based around the clock
  135. void SignalTimerFired();
  136. virtual HRESULT CancelNotification();
  137. virtual HRESULT ClearPendingSample();
  138. // Called when the filter changes state
  139. virtual HRESULT Active();
  140. virtual HRESULT Inactive();
  141. virtual HRESULT StartStreaming();
  142. virtual HRESULT StopStreaming();
  143. virtual HRESULT BeginFlush();
  144. virtual HRESULT EndFlush();
  145. // Deal with connections and type changes
  146. virtual HRESULT BreakConnect();
  147. virtual HRESULT SetMediaType(const CMediaType *pmt);
  148. virtual HRESULT CompleteConnect(IPin *pReceivePin);
  149. // These look after the handling of data samples
  150. virtual HRESULT PrepareReceive(IMediaSample *pMediaSample);
  151. virtual HRESULT Receive(IMediaSample *pMediaSample);
  152. virtual BOOL HaveCurrentSample();
  153. virtual IMediaSample *GetCurrentSample();
  154. virtual HRESULT Render(IMediaSample *pMediaSample);
  155. // Derived classes MUST override these
  156. virtual HRESULT DoRenderSample(IMediaSample *pMediaSample) PURE;
  157. virtual HRESULT CheckMediaType(const CMediaType *) PURE;
  158. // Helper
  159. void WaitForReceiveToComplete();
  160. CAudioSwitchRendererInputPin *GetSelectedPin() { return m_pInputPin[m_inputSelected]; }
  161. int GetConnectedInputsCount();
  162. int GetSelectedInput();
  163. void SetSelectedInput(int n);
  164. };
  165. #endif