MPEG1Player.h
上传用户:weiliangfb
上传日期:2007-01-23
资源大小:142k
文件大小:3k
源码类别:

多媒体

开发平台:

Visual C++

  1. // MPEG1Player.h: interface for the CMPEG1Player class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_MPEG1PLAYER_H__069604C0_9E1D_4F2D_ABAB_E5C3323AEA05__INCLUDED_)
  5. #define AFX_MPEG1PLAYER_H__069604C0_9E1D_4F2D_ABAB_E5C3323AEA05__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include "..ServerProtocalDef.h"
  10. class CMemStream : public CAsyncStream
  11. {
  12. PlayerEvent * m_EventSink;
  13. public:
  14.     CMemStream() 
  15.     {
  16.         m_llPosition = 0;
  17. m_EventSink = NULL;
  18.    }
  19. HRESULT Advise(PlayerEvent * pEvent)
  20. {
  21. if(pEvent==NULL)
  22. return E_POINTER;
  23. if(m_EventSink)//如果经跟客户端连接上,则返回错误
  24. return E_FAIL;
  25. m_EventSink = pEvent;
  26. return S_OK;
  27. }
  28.     HRESULT SetPointer(LONGLONG llPos)
  29.     {
  30.         if (llPos < 0 || llPos > m_llLength) {
  31.             return S_FALSE;
  32.         } else {
  33.             m_llPosition = llPos;
  34.             return S_OK;
  35.         }
  36.     }
  37.     HRESULT Read(PBYTE pbBuffer,
  38.                  DWORD dwBytesToRead,
  39.                  BOOL bAlign,
  40.                  LPDWORD pdwBytesRead)
  41.     {
  42. if(m_EventSink)
  43. {
  44. HRESULT hr = m_EventSink->OnPlayerNeedData(m_llPosition,dwBytesToRead,pdwBytesRead,pbBuffer);
  45. if(SUCCEEDED(hr))
  46. m_llPosition+=dwBytesToRead;
  47. return hr;
  48. }
  49. return E_POINTER;
  50.     }
  51.     LONGLONG Size(LONGLONG *pSizeAvailable)
  52.     {
  53.        *pSizeAvailable =  m_llLength;
  54.         return m_llLength;
  55.     }
  56.     DWORD Alignment()
  57.     {
  58.         return 1;
  59.     }
  60.     void Lock()
  61.     {
  62.         m_csLock.Lock();
  63.     }
  64.     void Unlock()
  65.     {
  66.         m_csLock.Unlock();
  67. }
  68. void SetMediaLength(LONGLONG lMediaLength)
  69. {
  70. m_llLength = lMediaLength;
  71. }
  72. protected:
  73.     CCritSec       m_csLock;
  74.     LONGLONG       m_llLength;
  75.     LONGLONG       m_llPosition;
  76. };
  77. class CAsyncFilter : public CAsyncReader
  78. {
  79.     CMemStream m_Stream;
  80. public:
  81. HRESULT Advise(PlayerEvent * pEvent)
  82. {
  83. return m_Stream.Advise(pEvent);
  84. }
  85. void SetMediaLength(LONGLONG llMeidaLen)
  86. {
  87. m_Stream.SetMediaLength(llMeidaLen);
  88. }
  89.     CAsyncFilter(HRESULT * phr):
  90.         CAsyncReader(NAME("Wang Peng Girl Friend Filter"), NULL, &m_Stream, phr)
  91.     {
  92. m_mt.majortype = MEDIATYPE_Stream;
  93.   m_mt.subtype = MEDIASUBTYPE_NULL;
  94.     }
  95.     static CAsyncFilter *CreateInstance( HRESULT *phr)
  96. {
  97.     return new CAsyncFilter(phr);
  98. }
  99.     ~CAsyncFilter()
  100.     {
  101.  
  102.     }
  103.     DECLARE_IUNKNOWN
  104.     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv)
  105.     {
  106.         return CAsyncReader::NonDelegatingQueryInterface(riid, ppv);
  107.     }
  108. };
  109. class CMPEG1Player  
  110. {
  111. BOOL m_bInitOk;
  112. public:
  113. HRESULT SetPlayRate(double dblFps);
  114. HRESULT Run();
  115. HRESULT Pause();
  116. BOOL InitPlayer(LONGLONG llMediaLen,PlayerEvent * pEvenSink,HWND hWnd);
  117. CAsyncFilter * m_pFilter;
  118. CMPEG1Player();
  119. virtual ~CMPEG1Player();
  120. IGraphBuilder * m_pGBuilder;
  121. IFilterGraph * m_pFGraph;
  122. double m_oldRefTime;
  123. BOOL m_bHaveGet;
  124. };
  125. #endif // !defined(AFX_MPEG1PLAYER_H__069604C0_9E1D_4F2D_ABAB_E5C3323AEA05__INCLUDED_)