DSPushSource.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. //------------------------------------------------------------------------------
  2. // File: PushSource.H
  3. //
  4. // Desc: DirectShow sample code - In-memory push mode source filter
  5. //
  6. // Copyright (c) Microsoft Corporation. All rights reserved.
  7. //------------------------------------------------------------------------------
  8. #ifndef PLUGIN_DSHOW_DSPUSHSOURCE_H
  9. #define PLUGIN_DSHOW_DSPUSHSOURCE_H
  10. #include "plugin_dshow_config.h"
  11. #include <strsafe.h>
  12. // UNITS = 10 ^ 7
  13. // UNITS / 30 = 30 fps;
  14. // UNITS / 20 = 20 fps, etc
  15. const REFERENCE_TIME FPS_30 = UNITS / 30;
  16. const REFERENCE_TIME FPS_20 = UNITS / 20;
  17. const REFERENCE_TIME FPS_10 = UNITS / 10;
  18. const REFERENCE_TIME FPS_5 = UNITS / 5;
  19. const REFERENCE_TIME FPS_4 = UNITS / 4;
  20. const REFERENCE_TIME FPS_3 = UNITS / 3;
  21. const REFERENCE_TIME FPS_2 = UNITS / 2;
  22. const REFERENCE_TIME FPS_1 = UNITS / 1;
  23. const REFERENCE_TIME rtDefaultFrameLength = FPS_10;
  24. // Filter name strings
  25. #define g_wszPushBitmap L"PushSource Bitmap Filter"
  26. #define g_wszPushBitmapSet L"PushSource BitmapSet Filter"
  27. #define g_wszPushDesktop L"PushSource Desktop Filter"
  28. // Number of bitmap files to load in the CPushPinBitmapSet class
  29. #define NUM_FILES 5
  30. // {3FD3081A-A8C9-4958-9F75-07EC89690024}
  31. TDSHOW_DEFINE_GUID(CLSID_PushSourceDesktop,
  32. 0x3fd3081a, 0xa8c9, 0x4958, 0x9f, 0x75, 0x7, 0xec, 0x89, 0x69, 0x0, 0x24);
  33. /**********************************************
  34. *
  35. * Class declarations
  36. *
  37. **********************************************/
  38. class CPushPinBitmap : public CSourceStream
  39. {
  40. protected:
  41. int m_FramesWritten; // To track where we are in the file
  42. BOOL m_bZeroMemory; // Do we need to clear the buffer?
  43. CRefTime m_rtSampleTime; // The time stamp for each sample
  44. BITMAPINFO *m_pBmi; // Pointer to the bitmap header
  45. DWORD m_cbBitmapInfo; // Size of the bitmap header
  46. // File opening variables
  47. HANDLE m_hFile; // Handle returned from CreateFile
  48. BYTE * m_pFile; // Points to beginning of file buffer
  49. BYTE * m_pImage; // Points to pixel bits
  50. int m_iFrameNumber;
  51. const REFERENCE_TIME m_rtFrameLength;
  52. CCritSec m_cSharedState; // Protects our internal state
  53. CImageDisplay m_Display; // Figures out our media type for us
  54. public:
  55. CPushPinBitmap(HRESULT *phr, CSource *pFilter);
  56. ~CPushPinBitmap();
  57. // Override the version that offers exactly one media type
  58. HRESULT GetMediaType(CMediaType *pMediaType);
  59. HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
  60. HRESULT FillBuffer(IMediaSample *pSample);
  61. // Quality control
  62. // Not implemented because we aren't going in real time.
  63. // If the file-writing filter slows the graph down, we just do nothing, which means
  64. // wait until we're unblocked. No frames are ever dropped.
  65. STDMETHODIMP Notify(IBaseFilter *pSelf, Quality q) {
  66. return E_FAIL;
  67. }
  68. };
  69. class CPushPinBitmapSet : public CSourceStream
  70. {
  71. protected:
  72. int m_FramesWritten; // To track where we are in the file
  73. BOOL m_bZeroMemory; // Do we need to clear the buffer?
  74. CRefTime m_rtSampleTime; // The time stamp for each sample
  75. BITMAPINFO *m_pBmi[NUM_FILES]; // Pointer to the bitmap headers
  76. DWORD m_cbBitmapInfo[NUM_FILES]; // Size of the bitmap headers
  77. // File opening variables
  78. HANDLE m_hFile[NUM_FILES]; // Handles returned from CreateFile
  79. BYTE * m_pFile[NUM_FILES]; // Points to beginning of file buffers
  80. BYTE * m_pImage[NUM_FILES]; // Points to pixel bits
  81. BOOL m_bFilesLoaded;
  82. int m_iCurrentBitmap; // Which bitmap is being displayed
  83. int m_iFrameNumber; // How many frames have been displayed
  84. const REFERENCE_TIME m_rtFrameLength; // Duration of one frame
  85. CCritSec m_cSharedState; // Protects our internal state
  86. CImageDisplay m_Display; // Figures out our media type for us
  87. public:
  88. CPushPinBitmapSet(HRESULT *phr, CSource *pFilter);
  89. ~CPushPinBitmapSet();
  90. // Override the version that offers exactly one media type
  91. HRESULT GetMediaType(CMediaType *pMediaType);
  92. HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
  93. HRESULT FillBuffer(IMediaSample *pSample);
  94. // Quality control
  95. // Not implemented because we aren't going in real time.
  96. // If the file-writing filter slows the graph down, we just do nothing, which means
  97. // wait until we're unblocked. No frames are ever dropped.
  98. STDMETHODIMP Notify(IBaseFilter *pSelf, Quality q) {
  99. return E_FAIL;
  100. }
  101. };
  102. class CPushPinDesktop : public CSourceStream
  103. {
  104. protected:
  105. int m_FramesWritten; // To track where we are in the file
  106. BOOL m_bZeroMemory; // Do we need to clear the buffer?
  107. CRefTime m_rtSampleTime; // The time stamp for each sample
  108. int m_iFrameNumber;
  109. const REFERENCE_TIME m_rtFrameLength;
  110. RECT m_rScreen; // Rect containing entire screen coordinates
  111. int m_iImageHeight; // The current image height
  112. int m_iImageWidth; // And current image width
  113. int m_iRepeatTime; // Time in msec between frames
  114. int m_nCurrentBitDepth; // Screen bit depth
  115. CMediaType m_MediaType;
  116. CCritSec m_cSharedState; // Protects our internal state
  117. CImageDisplay m_Display; // Figures out our media type for us
  118. HWND m_hSrcHwnd; // Handle to the window to grab
  119. public:
  120. CPushPinDesktop(HRESULT *phr, CSource *pFilter);
  121. ~CPushPinDesktop();
  122. // Override the version that offers exactly one media type
  123. HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
  124. HRESULT FillBuffer(IMediaSample *pSample);
  125. // Set the agreed media type and set up the necessary parameters
  126. HRESULT SetMediaType(const CMediaType *pMediaType);
  127. // Support multiple display formats
  128. HRESULT CheckMediaType(const CMediaType *pMediaType);
  129. HRESULT GetMediaType(int iPosition, CMediaType *pmt);
  130. // Quality control
  131. // Not implemented because we aren't going in real time.
  132. // If the file-writing filter slows the graph down, we just do nothing, which means
  133. // wait until we're unblocked. No frames are ever dropped.
  134. STDMETHODIMP Notify(IBaseFilter *pSelf, Quality q) {
  135. return E_FAIL;
  136. }
  137. HRESULT SetSrcHwnd(HWND hWnd) {
  138. m_hSrcHwnd = hWnd;
  139. return S_OK;
  140. }
  141. };
  142. class CPushSourceBitmap : public CSource
  143. {
  144. private:
  145. // Constructor is private because you have to use CreateInstance
  146. CPushSourceBitmap(IUnknown *pUnk, HRESULT *phr);
  147. ~CPushSourceBitmap();
  148. CPushPinBitmap *m_pPin;
  149. public:
  150. static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  151. };
  152. class CPushSourceBitmapSet : public CSource
  153. {
  154. private:
  155. // Constructor is private because you have to use CreateInstance
  156. CPushSourceBitmapSet(IUnknown *pUnk, HRESULT *phr);
  157. ~CPushSourceBitmapSet();
  158. CPushPinBitmapSet *m_pPin;
  159. public:
  160. static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  161. };
  162. class CPushSourceDesktop : public CSource
  163. {
  164. private:
  165. // Constructor is private because you have to use CreateInstance
  166. CPushSourceDesktop(IUnknown *pUnk, HRESULT *phr);
  167. ~CPushSourceDesktop();
  168. CPushPinDesktop *m_pPin;
  169. public:
  170. static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  171. DECLARE_IUNKNOWN;
  172. HRESULT SetSrcHwnd(HWND hWnd);
  173. };
  174. #endif /* PLUGIN_DSHOW_DSPUSHSOURCE_H */
  175. //------------------------------------------------------------------------------
  176. // File: PushSource.H
  177. //
  178. // Desc: DirectShow sample code - In-memory push mode source filter
  179. //
  180. // Copyright (c) Microsoft Corporation. All rights reserved.
  181. //------------------------------------------------------------------------------
  182. #ifndef PLUGIN_DSHOW_DSPUSHSOURCE_H
  183. #define PLUGIN_DSHOW_DSPUSHSOURCE_H
  184. #include "plugin_dshow_config.h"
  185. #include <strsafe.h>
  186. // UNITS = 10 ^ 7
  187. // UNITS / 30 = 30 fps;
  188. // UNITS / 20 = 20 fps, etc
  189. const REFERENCE_TIME FPS_30 = UNITS / 30;
  190. const REFERENCE_TIME FPS_20 = UNITS / 20;
  191. const REFERENCE_TIME FPS_10 = UNITS / 10;
  192. const REFERENCE_TIME FPS_5 = UNITS / 5;
  193. const REFERENCE_TIME FPS_4 = UNITS / 4;
  194. const REFERENCE_TIME FPS_3 = UNITS / 3;
  195. const REFERENCE_TIME FPS_2 = UNITS / 2;
  196. const REFERENCE_TIME FPS_1 = UNITS / 1;
  197. const REFERENCE_TIME rtDefaultFrameLength = FPS_10;
  198. // Filter name strings
  199. #define g_wszPushBitmap L"PushSource Bitmap Filter"
  200. #define g_wszPushBitmapSet L"PushSource BitmapSet Filter"
  201. #define g_wszPushDesktop L"PushSource Desktop Filter"
  202. // Number of bitmap files to load in the CPushPinBitmapSet class
  203. #define NUM_FILES 5
  204. // {3FD3081A-A8C9-4958-9F75-07EC89690024}
  205. TDSHOW_DEFINE_GUID(CLSID_PushSourceDesktop,
  206. 0x3fd3081a, 0xa8c9, 0x4958, 0x9f, 0x75, 0x7, 0xec, 0x89, 0x69, 0x0, 0x24);
  207. /**********************************************
  208. *
  209. * Class declarations
  210. *
  211. **********************************************/
  212. class CPushPinBitmap : public CSourceStream
  213. {
  214. protected:
  215. int m_FramesWritten; // To track where we are in the file
  216. BOOL m_bZeroMemory; // Do we need to clear the buffer?
  217. CRefTime m_rtSampleTime; // The time stamp for each sample
  218. BITMAPINFO *m_pBmi; // Pointer to the bitmap header
  219. DWORD m_cbBitmapInfo; // Size of the bitmap header
  220. // File opening variables
  221. HANDLE m_hFile; // Handle returned from CreateFile
  222. BYTE * m_pFile; // Points to beginning of file buffer
  223. BYTE * m_pImage; // Points to pixel bits
  224. int m_iFrameNumber;
  225. const REFERENCE_TIME m_rtFrameLength;
  226. CCritSec m_cSharedState; // Protects our internal state
  227. CImageDisplay m_Display; // Figures out our media type for us
  228. public:
  229. CPushPinBitmap(HRESULT *phr, CSource *pFilter);
  230. ~CPushPinBitmap();
  231. // Override the version that offers exactly one media type
  232. HRESULT GetMediaType(CMediaType *pMediaType);
  233. HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
  234. HRESULT FillBuffer(IMediaSample *pSample);
  235. // Quality control
  236. // Not implemented because we aren't going in real time.
  237. // If the file-writing filter slows the graph down, we just do nothing, which means
  238. // wait until we're unblocked. No frames are ever dropped.
  239. STDMETHODIMP Notify(IBaseFilter *pSelf, Quality q) {
  240. return E_FAIL;
  241. }
  242. };
  243. class CPushPinBitmapSet : public CSourceStream
  244. {
  245. protected:
  246. int m_FramesWritten; // To track where we are in the file
  247. BOOL m_bZeroMemory; // Do we need to clear the buffer?
  248. CRefTime m_rtSampleTime; // The time stamp for each sample
  249. BITMAPINFO *m_pBmi[NUM_FILES]; // Pointer to the bitmap headers
  250. DWORD m_cbBitmapInfo[NUM_FILES]; // Size of the bitmap headers
  251. // File opening variables
  252. HANDLE m_hFile[NUM_FILES]; // Handles returned from CreateFile
  253. BYTE * m_pFile[NUM_FILES]; // Points to beginning of file buffers
  254. BYTE * m_pImage[NUM_FILES]; // Points to pixel bits
  255. BOOL m_bFilesLoaded;
  256. int m_iCurrentBitmap; // Which bitmap is being displayed
  257. int m_iFrameNumber; // How many frames have been displayed
  258. const REFERENCE_TIME m_rtFrameLength; // Duration of one frame
  259. CCritSec m_cSharedState; // Protects our internal state
  260. CImageDisplay m_Display; // Figures out our media type for us
  261. public:
  262. CPushPinBitmapSet(HRESULT *phr, CSource *pFilter);
  263. ~CPushPinBitmapSet();
  264. // Override the version that offers exactly one media type
  265. HRESULT GetMediaType(CMediaType *pMediaType);
  266. HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
  267. HRESULT FillBuffer(IMediaSample *pSample);
  268. // Quality control
  269. // Not implemented because we aren't going in real time.
  270. // If the file-writing filter slows the graph down, we just do nothing, which means
  271. // wait until we're unblocked. No frames are ever dropped.
  272. STDMETHODIMP Notify(IBaseFilter *pSelf, Quality q) {
  273. return E_FAIL;
  274. }
  275. };
  276. class CPushPinDesktop : public CSourceStream
  277. {
  278. protected:
  279. int m_FramesWritten; // To track where we are in the file
  280. BOOL m_bZeroMemory; // Do we need to clear the buffer?
  281. CRefTime m_rtSampleTime; // The time stamp for each sample
  282. int m_iFrameNumber;
  283. const REFERENCE_TIME m_rtFrameLength;
  284. RECT m_rScreen; // Rect containing entire screen coordinates
  285. int m_iImageHeight; // The current image height
  286. int m_iImageWidth; // And current image width
  287. int m_iRepeatTime; // Time in msec between frames
  288. int m_nCurrentBitDepth; // Screen bit depth
  289. CMediaType m_MediaType;
  290. CCritSec m_cSharedState; // Protects our internal state
  291. CImageDisplay m_Display; // Figures out our media type for us
  292. HWND m_hSrcHwnd; // Handle to the window to grab
  293. public:
  294. CPushPinDesktop(HRESULT *phr, CSource *pFilter);
  295. ~CPushPinDesktop();
  296. // Override the version that offers exactly one media type
  297. HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
  298. HRESULT FillBuffer(IMediaSample *pSample);
  299. // Set the agreed media type and set up the necessary parameters
  300. HRESULT SetMediaType(const CMediaType *pMediaType);
  301. // Support multiple display formats
  302. HRESULT CheckMediaType(const CMediaType *pMediaType);
  303. HRESULT GetMediaType(int iPosition, CMediaType *pmt);
  304. // Quality control
  305. // Not implemented because we aren't going in real time.
  306. // If the file-writing filter slows the graph down, we just do nothing, which means
  307. // wait until we're unblocked. No frames are ever dropped.
  308. STDMETHODIMP Notify(IBaseFilter *pSelf, Quality q) {
  309. return E_FAIL;
  310. }
  311. HRESULT SetSrcHwnd(HWND hWnd) {
  312. m_hSrcHwnd = hWnd;
  313. return S_OK;
  314. }
  315. };
  316. class CPushSourceBitmap : public CSource
  317. {
  318. private:
  319. // Constructor is private because you have to use CreateInstance
  320. CPushSourceBitmap(IUnknown *pUnk, HRESULT *phr);
  321. ~CPushSourceBitmap();
  322. CPushPinBitmap *m_pPin;
  323. public:
  324. static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  325. };
  326. class CPushSourceBitmapSet : public CSource
  327. {
  328. private:
  329. // Constructor is private because you have to use CreateInstance
  330. CPushSourceBitmapSet(IUnknown *pUnk, HRESULT *phr);
  331. ~CPushSourceBitmapSet();
  332. CPushPinBitmapSet *m_pPin;
  333. public:
  334. static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  335. };
  336. class CPushSourceDesktop : public CSource
  337. {
  338. private:
  339. // Constructor is private because you have to use CreateInstance
  340. CPushSourceDesktop(IUnknown *pUnk, HRESULT *phr);
  341. ~CPushSourceDesktop();
  342. CPushPinDesktop *m_pPin;
  343. public:
  344. static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
  345. DECLARE_IUNKNOWN;
  346. HRESULT SetSrcHwnd(HWND hWnd);
  347. };
  348. #endif /* PLUGIN_DSHOW_DSPUSHSOURCE_H */