00001
00002
00003
00004
00005
00006 #ifndef __RENBASE__
00007 #define __RENBASE__
00008
00009 class CBaseRenderer;
00010 class CBaseVideoRenderer;
00011 class CRendererInputPin;
00012
00013 class CRendererInputPin : public CBaseInputPin
00014 {
00015 protected:
00016
00017 CBaseRenderer *m_pRenderer;
00018
00019 public:
00020
00021 CRendererInputPin(CBaseRenderer *pRenderer,
00022 HRESULT *phr,
00023 LPCWSTR Name);
00024
00025 HRESULT BreakConnect();
00026 HRESULT CompleteConnect(IPin *pReceivePin);
00027 HRESULT SetMediaType(const CMediaType *pmt);
00028 HRESULT CheckMediaType(const CMediaType *pmt);
00029 HRESULT Active();
00030 HRESULT Inactive();
00031
00032 STDMETHODIMP QueryId(LPWSTR *Id);
00033 STDMETHODIMP EndOfStream();
00034 STDMETHODIMP BeginFlush();
00035 STDMETHODIMP EndFlush();
00036 STDMETHODIMP Receive(IMediaSample *pMediaSample);
00037
00038 IMemAllocator inline *Allocator() const
00039 {
00040 return m_pAllocator;
00041 }
00042 };
00043
00044 class CBaseRenderer : public CBaseFilter
00045 {
00046 protected:
00047
00048 friend class CRendererInputPin;
00049
00050 friend void CALLBACK EndOfStreamTimer(UINT uID,
00051 UINT uMsg,
00052 DWORD_PTR dwUser,
00053 DWORD_PTR dw1,
00054 DWORD_PTR dw2);
00055
00056 CRendererPosPassThru *m_pPosition;
00057 CAMEvent m_RenderEvent;
00058 CAMEvent m_ThreadSignal;
00059 CAMEvent m_evComplete;
00060 BOOL m_bAbort;
00061 BOOL m_bStreaming;
00062 DWORD_PTR m_dwAdvise;
00063 IMediaSample *m_pMediaSample;
00064 BOOL m_bEOS;
00065 BOOL m_bEOSDelivered;
00066 CRendererInputPin *m_pInputPin;
00067 CCritSec m_InterfaceLock;
00068 CCritSec m_RendererLock;
00069 IQualityControl * m_pQSink;
00070 BOOL m_bRepaintStatus;
00071
00072 volatile BOOL m_bInReceive;
00073
00074 REFERENCE_TIME m_SignalTime;
00075 UINT m_EndOfStreamTimer;
00076
00077 public:
00078
00079 CBaseRenderer(REFCLSID RenderClass,
00080 TCHAR *pName,
00081 LPUNKNOWN pUnk,
00082 HRESULT *phr);
00083
00084 ~CBaseRenderer();
00085
00086
00087
00088 virtual HRESULT GetMediaPositionInterface(REFIID riid,void **ppv);
00089 STDMETHODIMP NonDelegatingQueryInterface(REFIID, void **);
00090
00091 virtual HRESULT SourceThreadCanWait(BOOL bCanWait);
00092
00093 #ifdef DEBUG
00094
00095 void DisplayRendererState();
00096 #endif
00097 virtual HRESULT WaitForRenderTime();
00098 virtual HRESULT CompleteStateChange(FILTER_STATE OldState);
00099
00100 BOOL IsEndOfStream() { return m_bEOS; };
00101 BOOL IsEndOfStreamDelivered() { return m_bEOSDelivered; };
00102 BOOL IsStreaming() { return m_bStreaming; };
00103 void SetAbortSignal(BOOL bAbort) { m_bAbort = bAbort; };
00104 virtual void OnReceiveFirstSample(IMediaSample *pMediaSample) { };
00105 CAMEvent *GetRenderEvent() { return &m_RenderEvent; };
00106
00107 void Ready() { m_evComplete.Set(); };
00108 void NotReady() { m_evComplete.Reset(); };
00109 BOOL CheckReady() { return m_evComplete.Check(); };
00110
00111 virtual int GetPinCount();
00112 virtual CBasePin *GetPin(int n);
00113 FILTER_STATE GetRealState();
00114 void SendRepaint();
00115 void SendNotifyWindow(IPin *pPin,HWND hwnd);
00116 BOOL OnDisplayChange();
00117 void SetRepaintStatus(BOOL bRepaint);
00118
00119 STDMETHODIMP Stop();
00120 STDMETHODIMP Pause();
00121 STDMETHODIMP Run(REFERENCE_TIME StartTime);
00122 STDMETHODIMP GetState(DWORD dwMSecs,FILTER_STATE *State);
00123 STDMETHODIMP FindPin(LPCWSTR Id, IPin **ppPin);
00124
00125 virtual void OnRenderStart(IMediaSample *pMediaSample);
00126 virtual void OnRenderEnd(IMediaSample *pMediaSample);
00127 virtual HRESULT OnStartStreaming() { return NOERROR; };
00128 virtual HRESULT OnStopStreaming() { return NOERROR; };
00129 virtual void OnWaitStart() { };
00130 virtual void OnWaitEnd() { };
00131 virtual void PrepareRender() { };
00132
00133 #ifdef PERF
00134 REFERENCE_TIME m_trRenderStart;
00135
00136 int m_idBaseStamp;
00137 int m_idBaseRenderTime;
00138 int m_idBaseAccuracy;
00139 #endif
00140
00141 virtual BOOL ScheduleSample(IMediaSample *pMediaSample);
00142 virtual HRESULT GetSampleTimes(IMediaSample *pMediaSample,
00143 REFERENCE_TIME *pStartTime,
00144 REFERENCE_TIME *pEndTime);
00145
00146 virtual HRESULT ShouldDrawSampleNow(IMediaSample *pMediaSample,
00147 REFERENCE_TIME *ptrStart,
00148 REFERENCE_TIME *ptrEnd);
00149
00150 void TimerCallback();
00151 void ResetEndOfStreamTimer();
00152 HRESULT NotifyEndOfStream();
00153 virtual HRESULT SendEndOfStream();
00154 virtual HRESULT ResetEndOfStream();
00155 virtual HRESULT EndOfStream();
00156
00157 void SignalTimerFired();
00158 virtual HRESULT CancelNotification();
00159 virtual HRESULT ClearPendingSample();
00160
00161 virtual HRESULT Active();
00162 virtual HRESULT Inactive();
00163 virtual HRESULT StartStreaming();
00164 virtual HRESULT StopStreaming();
00165 virtual HRESULT BeginFlush();
00166 virtual HRESULT EndFlush();
00167
00168 virtual HRESULT BreakConnect();
00169 virtual HRESULT SetMediaType(const CMediaType *pmt);
00170 virtual HRESULT CompleteConnect(IPin *pReceivePin);
00171
00172 virtual HRESULT PrepareReceive(IMediaSample *pMediaSample);
00173 virtual HRESULT Receive(IMediaSample *pMediaSample);
00174 virtual BOOL HaveCurrentSample();
00175 virtual IMediaSample *GetCurrentSample();
00176 virtual HRESULT Render(IMediaSample *pMediaSample);
00177
00178 virtual HRESULT DoRenderSample(IMediaSample *pMediaSample) PURE;
00179 virtual HRESULT CheckMediaType(const CMediaType *) PURE;
00180
00181 void WaitForReceiveToComplete();
00182 };
00183
00184 #define AVGPERIOD 4
00185 #define DO_MOVING_AVG(avg,obs) (avg = (1024*obs + (AVGPERIOD-1)*avg)/AVGPERIOD)
00186
00187 class CBaseVideoRenderer : public CBaseRenderer,
00188 public IQualProp,
00189 public IQualityControl
00190 {
00191 protected:
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 int m_nNormal;
00211
00212
00213
00214 #ifdef PERF
00215 BOOL m_bDrawLateFrames;
00216
00217 #endif
00218
00219 BOOL m_bSupplierHandlingQuality;
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 int m_trThrottle;
00244
00245
00246
00247
00248 int m_trRenderAvg;
00249 int m_trRenderLast;
00250 int m_tRenderStart;
00251
00252
00253
00254
00255
00256
00257 int m_trEarliness;
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 int m_trTarget;
00268
00269
00270
00271
00272 int m_trWaitAvg;
00273
00274
00275
00276
00277
00278
00279 int m_trFrameAvg;
00280 int m_trDuration;
00281
00282 #ifdef PERF
00283
00284 int m_idTimeStamp;
00285 int m_idEarliness;
00286 int m_idTarget;
00287 int m_idWaitReal;
00288 int m_idWait;
00289 int m_idFrameAccuracy;
00290 int m_idRenderAvg;
00291 int m_idSchLateTime;
00292 int m_idQualityRate;
00293 int m_idQualityTime;
00294 int m_idDecision;
00295 int m_idDuration;
00296 int m_idThrottle;
00297
00298
00299 #endif
00300 REFERENCE_TIME m_trRememberStampForPerf;
00301
00302 #ifdef PERF
00303 REFERENCE_TIME m_trRememberFrameForPerf;
00304
00305
00306 int m_idFrameAvg;
00307 int m_idWaitAvg;
00308 #endif
00309
00310
00311
00312
00313
00314 int m_cFramesDropped;
00315 int m_cFramesDrawn;
00316
00317
00318
00319 LONGLONG m_iTotAcc;
00320 LONGLONG m_iSumSqAcc;
00321
00322
00323 REFERENCE_TIME m_trLastDraw;
00324 LONGLONG m_iSumSqFrameTime;
00325 LONGLONG m_iSumFrameTime;
00326
00327
00328
00329
00330
00331
00332 int m_trLate;
00333 int m_trFrame;
00334
00335 int m_tStreamingStart;
00336
00337
00338 #ifdef PERF
00339 LONGLONG m_llTimeOffset;
00340 #endif
00341
00342 public:
00343
00344 CBaseVideoRenderer(REFCLSID RenderClass,
00345 TCHAR *pName,
00346 LPUNKNOWN pUnk,
00347 HRESULT *phr);
00348
00349 ~CBaseVideoRenderer();
00350
00351
00352
00353 STDMETHODIMP SetSink( IQualityControl * piqc);
00354 STDMETHODIMP Notify( IBaseFilter * pSelf, Quality q);
00355
00356
00357
00358 void OnRenderStart(IMediaSample *pMediaSample);
00359 void OnRenderEnd(IMediaSample *pMediaSample);
00360 void OnWaitStart();
00361 void OnWaitEnd();
00362 HRESULT OnStartStreaming();
00363 HRESULT OnStopStreaming();
00364 void ThrottleWait();
00365
00366
00367
00368 void PreparePerformanceData(int trLate, int trFrame);
00369 virtual void RecordFrameLateness(int trLate, int trFrame);
00370 virtual void OnDirectRender(IMediaSample *pMediaSample);
00371 virtual HRESULT ResetStreamingTimes();
00372 BOOL ScheduleSample(IMediaSample *pMediaSample);
00373 HRESULT ShouldDrawSampleNow(IMediaSample *pMediaSample,
00374 REFERENCE_TIME *ptrStart,
00375 REFERENCE_TIME *ptrEnd);
00376
00377 virtual HRESULT SendQuality(REFERENCE_TIME trLate, REFERENCE_TIME trRealStream);
00378 STDMETHODIMP JoinFilterGraph(IFilterGraph * pGraph, LPCWSTR pName);
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 HRESULT GetStdDev(
00389 int nSamples,
00390 int *piResult,
00391 LONGLONG llSumSq,
00392 LONGLONG iTot
00393 );
00394 public:
00395
00396
00397
00398 STDMETHODIMP get_FramesDroppedInRenderer(int *cFramesDropped);
00399 STDMETHODIMP get_FramesDrawn(int *pcFramesDrawn);
00400 STDMETHODIMP get_AvgFrameRate(int *piAvgFrameRate);
00401 STDMETHODIMP get_Jitter(int *piJitter);
00402 STDMETHODIMP get_AvgSyncOffset(int *piAvg);
00403 STDMETHODIMP get_DevSyncOffset(int *piDev);
00404
00405
00406
00407 DECLARE_IUNKNOWN
00408 STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,VOID **ppv);
00409 };
00410
00411 #endif
00412