home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / directshow / capture / dvapp / dvapp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-02  |  12.3 KB  |  351 lines

  1. //------------------------------------------------------------------------------
  2. // File: DVApp.h
  3. //
  4. // Desc: DirectShow sample code - DV control/capture example header file.
  5. //
  6. // Copyright (c) 1993 - 2000, Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9.  
  10. #ifndef _DVAPP_H_
  11. #define _DVAPP_H_
  12.  
  13. #include <windows.h>
  14. #include <commctrl.h>
  15. #include <commdlg.h>
  16. #include <tchar.h>
  17. #include <dbt.h>
  18.  
  19. #define __EDEVDEFS__    //don't include edevdefs.h
  20.  
  21. #include <mmreg.h>
  22. #include <streams.h>
  23. #include <initguid.h>
  24. #include <xprtdefs.h>   //include this instead of edevdefs
  25.  
  26. #include "resource.h"
  27.  
  28. typedef TCHAR *PTCHAR;
  29.  
  30. //track device mode or active 
  31. enum DV_MODE
  32. {
  33.     CameraMode  = 0L,
  34.     VcrMode     = 1L,
  35.     UnknownMode = 2L
  36. }; 
  37.  
  38. enum GRAPH_TYPE
  39. {
  40.     GRAPH_PREVIEW, GRAPH_DV_TO_FILE, GRAPH_DV_TO_FILE_NOPRE, GRAPH_FILE_TO_DV, GRAPH_FILE_TO_DV_NOPRE, GRAPH_DV_TO_FILE_TYPE2, GRAPH_DV_TO_FILE_NOPRE_TYPE2, GRAPH_FILE_TO_DV_TYPE2, GRAPH_FILE_TO_DV_NOPRE_TYPE2
  41. };
  42.  
  43. // Logging Support
  44. enum LOG_LEVEL
  45. {
  46.     LOG_LEVEL_SUCCINCT, LOG_LEVEL_MEDIUM, LOG_LEVEL_VERBOSE
  47. };
  48. enum LOG_PRIORITY
  49. {
  50.     LOG_PRIORITY_ERROR, LOG_PRIORITY_WARN, LOG_PRIORITY_INFO
  51. };
  52.  
  53. //a few macros...
  54. #define MBOX(s) MessageBox(g_hwndApp, s, APPNAME, MB_OK);
  55.  
  56. #ifdef DEBUG
  57. #define SAFE_RELEASE(pUnk) if (pUnk) \
  58. { \
  59.     pUnk->Release(); \
  60.     pUnk = NULL; \
  61. } \
  62. else \
  63. { \
  64. }
  65. #else
  66. #define SAFE_RELEASE(pUnk) if (pUnk)\
  67. {\
  68.     pUnk->Release();\
  69.     pUnk = NULL;\
  70. }
  71. #endif //DEBUG
  72.  
  73.  
  74. //our constants
  75. #define DEVICENAME_BUFSIZE 80
  76. // capture constants
  77. #define DV_CAPLIMIT_NONE         10L
  78. #define DV_CAPLIMIT_TIME         11L
  79. #define DV_CAPLIMIT_SIZE         12L
  80.  
  81. #define DV_BYTESPERMSEC          352  //DV captures at 3600K per second (3600 / 1024 == ~3.52)
  82. #define DV_TIMERFREQ             55  //milliseconds between timer ticks
  83. #define DV_BYTES_IN_MEG          1048576L  //(1024 * 1024)
  84.  
  85. // App Names
  86. #define APPNAME                  TEXT("DV App")
  87. #define DV_APPTITLE              TEXT("Digital Video Sample Application")
  88.  
  89. //Timer ID's
  90. #define DV_TIMER_ATN             1L
  91. #define DV_TIMER_CAPLIMIT        2L
  92. #define DV_TIMER_FRAMES          3L
  93.  
  94. // File Names
  95. #define         DEFAULT_CAP_FILE_NAME       TEXT(".\\DVApp.avi")
  96. #define         DEFAULT_FG_FILE_NAME        TEXT(".\\DVApp.grf")
  97.  
  98. ///////////////////////////////////////
  99. // device notification definitions
  100. #if (WINVER < 0x0500)
  101.  
  102. #define DBT_DEVTYP_DEVICEINTERFACE      0x00000005  // device interface class
  103. #define DEVICE_NOTIFY_WINDOW_HANDLE     0x00000000
  104. typedef  PVOID           HDEVNOTIFY;
  105.  
  106. #endif
  107.  
  108. //extern "C"
  109. //{
  110.     typedef BOOL (/* WINUSERAPI */ WINAPI *PUnregisterDeviceNotification)(
  111.         IN HDEVNOTIFY Handle
  112.         );
  113.  
  114.     typedef HDEVNOTIFY (/* WINUSERAPI */ WINAPI *PRegisterDeviceNotificationA)(
  115.         IN HANDLE hRecipient,
  116.         IN LPVOID NotificationFilter,
  117.         IN DWORD Flags
  118.         );
  119.  
  120.     typedef HDEVNOTIFY (/* WINUSERAPI */ WINAPI *PRegisterDeviceNotificationW)(
  121.         IN HANDLE hRecipient,
  122.         IN LPVOID NotificationFilter,
  123.         IN DWORD Flags
  124.         );
  125. //}
  126. #ifdef UNICODE
  127. #define PRegisterDeviceNotification  PRegisterDeviceNotificationW
  128. #else
  129. #define PRegisterDeviceNotification  PRegisterDeviceNotificationA
  130. #endif // !UNICODE
  131.  
  132. #if (WINVER < 0x0500)
  133.  
  134. typedef struct _DEV_BROADCAST_DEVICEINTERFACE_A {
  135.     DWORD       dbcc_size;
  136.     DWORD       dbcc_devicetype;
  137.     DWORD       dbcc_reserved;
  138.     GUID        dbcc_classguid;
  139.     char        dbcc_name[1];
  140. } DEV_BROADCAST_DEVICEINTERFACE_A, *PDEV_BROADCAST_DEVICEINTERFACE_A;
  141.  
  142. typedef struct _DEV_BROADCAST_DEVICEINTERFACE_W {
  143.     DWORD       dbcc_size;
  144.     DWORD       dbcc_devicetype;
  145.     DWORD       dbcc_reserved;
  146.     GUID        dbcc_classguid;
  147.     wchar_t     dbcc_name[1];
  148. } DEV_BROADCAST_DEVICEINTERFACE_W, *PDEV_BROADCAST_DEVICEINTERFACE_W;
  149.  
  150. #ifdef UNICODE
  151. typedef DEV_BROADCAST_DEVICEINTERFACE_W   DEV_BROADCAST_DEVICEINTERFACE;
  152. typedef PDEV_BROADCAST_DEVICEINTERFACE_W  PDEV_BROADCAST_DEVICEINTERFACE;
  153. #else
  154. typedef DEV_BROADCAST_DEVICEINTERFACE_A   DEV_BROADCAST_DEVICEINTERFACE;
  155. typedef PDEV_BROADCAST_DEVICEINTERFACE_A  PDEV_BROADCAST_DEVICEINTERFACE;
  156. #endif // UNICODE
  157. #endif // WINVER
  158.  
  159.  
  160. ///////////////////////////////////////
  161. #define     _MAX_ARGC   6
  162. #define     _MAX_SLEEP  500
  163.  
  164. // function prototypes
  165. // Initialize functions
  166. void    DV_AppSetup(void);
  167. BOOL    DV_InitDevice(void);
  168. BOOL    DV_InitWindow(void);
  169. BOOL    DV_InitControls(HWND hwnd, HINSTANCE hInst);
  170.  
  171. // clean up functions
  172. void    DV_CleanUp(void);
  173. void    DV_DisconnectAll(IBaseFilter *pBF);
  174.  
  175. // Device Type functions
  176. DV_MODE DV_GetDVMode(void);
  177. HRESULT DV_GetTapeInfo(void);
  178.  
  179. // FilterGraph State Manipulation
  180. BOOL    DV_GetGraphBuilder(void);
  181. HRESULT DV_StopGraph(void);
  182. HRESULT DV_PauseGraph(void);
  183. HRESULT DV_StartGraph(void);
  184. HRESULT DV_SaveGraph(TCHAR* swGraphFile);
  185.  
  186. // Timecode or ATN functions
  187. void    DV_DisplayTimecode(void);
  188. BOOL    DV_SeekATN(void);
  189.  
  190. // Misc helper functions
  191. HRESULT DV_SetPreview(void);
  192. HRESULT DV_SelectClock(IBaseFilter *pBaseFilter);
  193. HRESULT DV_SetAviOptions(IBaseFilter *ppf, InterleavingMode INTERLEAVE_MODE);
  194. BOOL    DV_RefreshMode(void);
  195. void    DV_GetFinalDroppedFramesStats(DWORD dwTime);
  196.  
  197. // Graph Building functions
  198. BOOL    DV_MakeSpecialGraph(GRAPH_TYPE iGraphType);
  199.  
  200. // Type 1 File (capture\playback\transmit)
  201. HRESULT DV_MakeDvToFileGraph(void);
  202. HRESULT DV_MakeDvToFileGraph_NoPre(void);
  203. HRESULT DV_MakeFileToDvGraph(void);
  204. HRESULT DV_MakeFileToDvGraph_NoPre(void);
  205.  
  206. // Type 2 File (capture\playback\transmit)
  207. HRESULT DV_MakeDvToFileGraph_Type2(void);
  208. HRESULT DV_MakeDvToFileGraph_NoPre_Type2(void);
  209. HRESULT DV_MakeFileToDvGraph_Type2(void);
  210. HRESULT DV_MakeFileToDvGraph_NoPre_Type2(void);
  211.  
  212. // Read & Write RegKeys so help remember the last known state
  213. void    DV_WriteRegKeys(void);
  214. void    DV_ReadRegKeys(void);
  215.  
  216. // Message Processing Functions
  217. LRESULT CALLBACK DV_WndProc (HWND, UINT, WPARAM, LPARAM) ;
  218. void CALLBACK DV_TansportCommand_WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
  219. void CALLBACK DV_GraphModeCommand_WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
  220.  
  221. // Timer & Dialog Processing Functions
  222. void CALLBACK DV_DroppedFrameProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
  223. BOOL CALLBACK DV_CapSizeDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  224. BOOL CALLBACK DV_ChooseModeDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  225. void CALLBACK DV_StopRecProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
  226. BOOL CALLBACK DV_AboutDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  227. void CALLBACK DV_TimecodeTimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
  228. BOOL CALLBACK DV_ChangeDecodeSizeProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  229.  
  230. // Logging Support
  231. void    __cdecl DV_LogOut(LOG_PRIORITY iPriority, LOG_LEVEL ilevel, TCHAR *szFormat, ... );
  232.  
  233. // globals
  234.  
  235. // Handles to the windows
  236. HWND                  g_hwndApp               = NULL;
  237. HWND                  g_hwndTBar              = NULL; 
  238. HWND                  g_hwndStatus            = NULL;
  239. DWORD                g_statusHeight          = 0;
  240.  
  241. // metrics of the windows
  242. int                         g_iAppHeight            = 480+95;
  243. int                         g_iAppWidth             = 720+5;        
  244. int                     g_iVWHeight             = 480;
  245. int                     g_iVWWidth              = 720;        
  246.  
  247. // Names of files & devices
  248. TCHAR                   g_InputFileName[_MAX_PATH]  = {DEFAULT_CAP_FILE_NAME};
  249. TCHAR                   g_OutputFileName[_MAX_PATH] = {DEFAULT_CAP_FILE_NAME};
  250. TCHAR                   g_FilterGraphFileName[_MAX_PATH]    = {DEFAULT_FG_FILE_NAME};
  251.  
  252. // capture variables
  253. DWORD                   g_dwCaptureLimit        = DV_CAPLIMIT_NONE; //track whether we are using time, disk, or no based capture limits
  254. DWORD                   g_dwDiskSpace           = 120;              //roughly the same
  255.  
  256. // time variables
  257. BOOL                    g_bUseAtnTimer          = FALSE;            //track if we want to constantly update the timer
  258. LONG                    g_AvgTimePerFrame       = 33L;              //default to 33
  259. DWORD                   g_dwTimeLimit           = 30;               //default to 30 seconds of capture
  260. DWORD                   g_CapStartTime          = 0;
  261. DWORD                   g_curTime               = 0;
  262.  
  263. // device notification globals
  264. TCHAR                   g_DeviceName[DEVICENAME_BUFSIZE];
  265. BOOL                    g_bDeviceFound = FALSE;
  266. HDEVNOTIFY              g_hDevNotify            = NULL;
  267. PUnregisterDeviceNotification g_pUnregisterDeviceNotification;
  268. PRegisterDeviceNotification g_pRegisterDeviceNotification;
  269.  
  270. // filtergraph variables
  271. DV_MODE                 g_CurrentMode           = UnknownMode;
  272. GRAPH_TYPE              g_iCurrentGraph         = GRAPH_PREVIEW;    //need to track the current graph
  273.  
  274. // DirectShow interfaces to help build the filter graph & control the capture device
  275. ICaptureGraphBuilder2   *g_pBuilder             = NULL;
  276. IGraphBuilder           *g_pGraphBuilder        = NULL;
  277. IBaseFilter             *g_pDVCamera            = NULL;
  278. IAMExtDevice            *g_pExtDev              = NULL;
  279. IAMExtTransport  *g_pExtTrans            = NULL;
  280. IAMTimecodeReader       *g_pTimeReader          = NULL;
  281. IAMStreamConfig         *g_pStreamConf          = NULL;
  282. IVideoWindow            *g_pVideoWindow         = NULL;
  283. IIPDVDec                *g_pDvDec               = NULL;
  284. IAMDroppedFrames        *g_pDroppedFrames       = NULL;
  285.  
  286. // Filters used in the DirectShow filtergraph
  287. IBaseFilter             *g_pAviSplitter         = NULL;
  288. IBaseFilter             *g_pInputFileFilter     = NULL;  
  289. IBaseFilter             *g_pDVMux               = NULL;
  290. IBaseFilter             *g_pDVSplitter          = NULL;
  291. IBaseFilter             *g_pDVCodec             = NULL;
  292. IBaseFilter             *g_pSmartTee            = NULL;
  293. IBaseFilter             *g_pDSound              = NULL;
  294. IBaseFilter             *g_pInfTee              = NULL;
  295. IBaseFilter             *g_pVideoRenderer       = NULL;
  296.  
  297. // Logging Support
  298. LOG_PRIORITY        g_iLogPriority                              = LOG_PRIORITY_ERROR;
  299. LOG_LEVEL               g_iLogLevel                                 = LOG_LEVEL_SUCCINCT;
  300.  
  301. //toolbar buttons 
  302. TBBUTTON g_rgTbButtons[] = 
  303.     {0, 0,                  TBSTATE_ENABLED, TBSTYLE_SEP,    0,0},     
  304.     {8, IDM_STEP_REV,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0},
  305.     {5, IDM_REW,            TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0},
  306.     {9, IDM_PLAY_FAST_REV,  TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0},
  307.     {0, IDM_PLAY,           TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0}, 
  308.     {6, IDM_PLAY_FAST_FF,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0},
  309.     {4, IDM_FF,             TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0},
  310.     {7, IDM_STEP_FWD,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0},
  311.     {0, 0,                  TBSTATE_ENABLED, TBSTYLE_SEP,    0,0},   
  312.     {1, IDM_PAUSE,          TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0}, 
  313.     {2, IDM_STOP,           TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0},
  314.     {0, 0,                  TBSTATE_ENABLED, TBSTYLE_SEP,    0,0},   
  315.     {3, IDM_RECORD,         TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, 0,0},
  316.     {0, 0,                  TBSTATE_ENABLED, TBSTYLE_SEP,    0,0},   
  317.     {0, 0,                  TBSTATE_ENABLED, TBSTYLE_SEP,    0,0},   
  318.     {0, 0,                  TBSTATE_ENABLED, TBSTYLE_SEP,    0,0},   
  319.     {0, 0,                  TBSTATE_ENABLED, TBSTYLE_SEP,    0,0},   
  320.     {10, IDM_SEEKTIMECODE,  TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0}
  321. }; 
  322.  
  323.  
  324. // inline functions
  325. // put the VCR Mode
  326. inline HRESULT DV_PutVcrMode(long Mode)
  327. {
  328.     if(!g_pExtTrans)
  329.         return S_FALSE;
  330.     return g_pExtTrans->put_Mode(Mode);
  331.  
  332. // update the status windows with appropriate text
  333. inline LRESULT DV_StatusText(LPCTSTR statusText, UINT nPart)
  334. {
  335.     return SendMessage(g_hwndStatus, SB_SETTEXT, (WPARAM) 0 | nPart, (LPARAM)statusText);
  336.  
  337. //divide the status bar into thirds, and give the middle frame an extra 100 pixels.
  338. inline LRESULT DV_StatusParts(UINT width)
  339. {
  340.     int rg[3];
  341.     rg[0] = (width / 3) - 50;
  342.     rg[1] = ((rg[0]+50) * 2) + 50;
  343.     rg[2] = -1;
  344.     return SendMessage(g_hwndStatus, SB_SETPARTS, 3, (LPARAM)(LPINT) rg);
  345. }    
  346.  
  347. #endif //_DVAPP_H_
  348.