//------------------------------------------------------------------------------
// File: AMCap.cpp
//
// Desc: Audio/Video Capture sample for DirectShow
//
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
#include "stdafx.h"
#include <dbt.h>
#include <mmreg.h>
#include <msacm.h>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <commdlg.h>
#include <strsafe.h>
#include "stdafx.h"
#include "amcap.h"
#include "status.h"
#include "crossbar.h"
#include "SampleCGB.h"
//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
#define ABS(x) (((x) > 0) ? (x) : -(x))
// An application can advertise the existence of its filter graph
// by registering the graph with a global Running Object Table (ROT).
// The GraphEdit application can detect and remotely view the running
// filter graph, allowing you to 'spy' on the graph with GraphEdit.
//
// To enable registration in this sample, define REGISTER_FILTERGRAPH.
//
#ifdef DEBUG
#define REGISTER_FILTERGRAPH
#endif
//------------------------------------------------------------------------------
// Global data
//------------------------------------------------------------------------------
HINSTANCE ghInstApp=0;
HACCEL ghAccel=0;
HFONT ghfontApp=0;
TEXTMETRIC gtm={0};
TCHAR gszAppName[]=TEXT("AMCAP");
HWND ghwndApp=0, ghwndStatus=0;
HDEVNOTIFY ghDevNotify=0;
PUnregisterDeviceNotification gpUnregisterDeviceNotification=0;
PRegisterDeviceNotification gpRegisterDeviceNotification=0;
DWORD g_dwGraphRegister=0;
struct _capstuff
{
WCHAR wszCaptureFile[_MAX_PATH];
WORD wCapFileSize; // size in Meg
ISampleCaptureGraphBuilder *pBuilder;
IVideoWindow *pVW;
IMediaEventEx *pME;
IAMDroppedFrames *pDF;
IAMVideoCompression *pVC;
IAMVfwCaptureDialogs *pDlg;
IAMStreamConfig *pASC; // for audio cap
IAMStreamConfig *pVSC; // for video cap
IBaseFilter *pRender;
IBaseFilter *pVCap, *pACap; //采集设备filter
IGraphBuilder *pFg;
IFileSinkFilter *pSink;
IConfigAviMux *pConfigAviMux;
int iMasterStream;
BOOL fCaptureGraphBuilt;
BOOL fPreviewGraphBuilt;
BOOL fCapturing;
BOOL fPreviewing;
BOOL fMPEG2;
BOOL fCapAudio;
BOOL fCapCC;
BOOL fCCAvail;
BOOL fCapAudioIsRelevant;
bool fDeviceMenuPopulated;
IMoniker *rgpmVideoMenu[10];
IMoniker *rgpmAudioMenu[10];
IMoniker *pmVideo; //视频采集设备Moniker
IMoniker *pmAudio;
double FrameRate;
BOOL fWantPreview;
long lCapStartTime;
long lCapStopTime;
WCHAR wachFriendlyName[120]; //保存当前采集设备的FriendlyName
BOOL fUseTimeLimit;
BOOL fUseFrameRate;
DWORD dwTimeLimit;
int iFormatDialogPos;
int iSourceDialogPos;
int iDisplayDialogPos;
int iVCapDialogPos;
int iVCrossbarDialogPos;
int iTVTunerDialogPos;
int iACapDialogPos;
int iACrossbarDialogPos;
int iTVAudioDialogPos;
int iVCapCapturePinDialogPos;
int iVCapPreviewPinDialogPos;
int iACapCapturePinDialogPos;
long lDroppedBase;
long lNotBase;
BOOL fPreviewFaked;
CCrossbar *pCrossbar;
int iVideoInputMenuPos;
LONG NumberOfVideoInputs;
HMENU hMenuPopup;
int iNumVCapDevices;
} gcap;
// implements IAMCopyCaptureFileProgress
//
class CProgress : public IAMCopyCaptureFileProgress
{
public:
CProgress()
{
};
~CProgress()
{
};
STDMETHODIMP_(ULONG) AddRef()
{
return 1;
};
STDMETHODIMP_(ULONG) Release()
{
return 0;
};
STDMETHODIMP QueryInterface(REFIID iid, void **p)
{
if (p == NULL)
{
return E_POINTER;
}
if (iid == IID_IUnknown)
{
*p = reinterpret_cast<IUnknown*>(this);
AddRef();
return S_OK;
}
else if (iid == IID_IAMCopyCaptureFileProgress)
{
*p = reinterpret_cast<IAMCopyCaptureFileProgress*>(this);
AddRef();
return S_OK;
}
else
{
return E_NOINTERFACE;
}
};
STDMETHODIMP Progress(int i)
{
TCHAR tach[80];
HRESULT hr = StringCchPrintf(tach, 80, TEXT("Save File Progress: %d%%\0"), i);
statusUpdateStatus(ghwndStatus, tach);
return S_OK;
};
};
//------------------------------------------------------------------------------
// Function Prototypes
//------------------------------------------------------------------------------
typedef LONG(PASCAL *LPWNDPROC)(HWND, UINT, WPARAM, LPARAM); // pointer to a window procedure
LONG WINAPI AppWndProc(HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam);
LONG PASCAL AppCommand(HWND hwnd, unsigned msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void ErrMsg(LPTSTR sz,...);
BOOL SetCaptureFile(HWND hWnd);
BOOL SaveCaptureFile(HWND hWnd);
BOOL AllocCaptureFile(HWND hWnd);
int DoDialog(HWND hwndParent, int DialogID, DLGPROC fnDialog, long lParam);
int FAR PASCAL AllocCapFileProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam);
int FAR PASCAL FrameRateProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam);
int FAR PASCAL TimeLimitProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam);
int FAR PASCAL PressAKeyProc(HWND hDlg, UINT Message, UINT wParam, LONG lParam);
void TearDownGraph(void);
BOOL BuildCaptureGraph();
BOOL BuildPreviewGraph();
void UpdateStatus(BOOL fAllStats);
void AddDevicesToMenu();
void ChooseDevices(TCHAR *szVideo, TCHAR *szAudio);
void ChooseDevices(IMoniker *pmVideo, IMoniker *pmAudio);
void ChooseFrameRate();
BOOL InitCapFilters();
void FreeCapFilters();
BOOL StopPreview();
BOOL StartPreview();
BOOL StopCapture();
DWORDLONG GetSize(LPCTSTR tach);
void MakeMenuOptions();
void OnClose();
//------------------------------------------------------------------------------
// Name: SetAppCaption()
// Desc: Set the caption to be the application name followed by the capture file
//------------------------------------------------------------------------------
void SetAppCaption()
{
TCHAR tach[_MAX_PATH + 80];
StringCchCopy(tach, NUMELMS(tach), gszAppName);
if(gcap.wszCaptureFile[0] != 0)
{
HRESULT hr = StringCchCat(tach, _MAX_PATH + 80, TEXT(" - "));
hr = StringCchCat(tach, _MAX_PATH + 80, gcap.wszCaptureFile);
}
SetWindowText(ghwndApp, tach);
}
/*----------------------------------------------------------------------------*\
| AppInit( hInst, hPrev) |
| |
| Description: |
| This is called when the application is first loaded into |
| memory. It performs all initialization that doesn't need to be done |
| once per instance. |
| |
| Arguments: |
| hInstance instance handle of current instance |
| hPrev instance handle of previous instance |
| |
| Returns: |
| TRUE if successful, FALSE if not |
| |
\*----------------------------------------------------------------------------*/
BOOL AppInit(HINSTANCE hInst, HINSTANCE hPrev, int sw)
{
WNDCLASS cls;
HDC hdc;
const DWORD dwExStyle = 0;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
/* Save instance handle for DialogBoxs */
ghInstApp = hInst;
ghAccel = LoadAccelerators(hInst, MAKEI
没有合适的资源?快使用搜索试试~ 我知道了~
DirectShow AmCap源码
共54个文件
svn-base:21个
h:5个
cpp:5个
5星 · 超过95%的资源 需积分: 49 772 下载量 85 浏览量
2014-09-25
11:36:50
上传
评论 2
收藏 16.16MB ZIP 举报
温馨提示
Microsoft DirectShow 官方源码示例,使用VS2012/2013编译无问题。
资源推荐
资源详情
资源评论
收起资源包目录
amcap.zip (54个子文件)
amcap
Release
UpgradeLog.XML 2KB
amcap.v12.suo 132KB
amcap.suo 15KB
ipch
amcap-df3155f0
amcap-703035ee.ipch 34.25MB
amcap.sln.docstates.suo 1KB
amcap.sln 1KB
AmCap.vcxproj.filters 2KB
amcap.sdf 29.56MB
amcap.cpp 124KB
stdafx.h 945B
amcap.h 3KB
amcap.v11.suo 130KB
amcap.sln.old 1KB
status.h 832B
amcap.vcproj 8KB
Debug
stdafx.cpp 25B
crossbar.cpp 18KB
amcap.rc 6KB
AmCap.vcxproj 11KB
crossbar.h 2KB
AmCap.vcxproj.user 143B
_UpgradeReport_Files
UpgradeReport.css 3KB
UpgradeReport_Plus.gif 71B
UpgradeReport.xslt 12KB
UpgradeReport_Minus.gif 69B
amcap.aps 77KB
SampleCGB.cpp 37KB
.svn
pristine
69
698a4bec923c9b8c5ae7362ce7c9769be8fad28f.svn-base 6KB
eb
eb536ba3d26a4280971b5c8dd7ff655b1d21db0c.svn-base 1KB
ad
ad12b288ff73e8a8847ad817e01f9f1dc204a66c.svn-base 8KB
da
dab5a061c27dee1397415ce3bca8195d1316b6b0.svn-base 123KB
b6
b6341fae7cd84d56c5396b88e7701597cc63e9bd.svn-base 3KB
7f
7f9006ee8afa2f9e8e957599caa5928139ecce21.svn-base 122KB
e3
e30621a19464dfd5e22c71424e40e32cc7f80528.svn-base 25B
aa
aa776ada28881db8d8a8efbcd1341be5ee041a71.svn-base 8KB
01
0140d4dbb5f9149c44bcc3931e5f5e992787fc7a.svn-base 11KB
fc
fc14006c2c7da5effb6508885699cd09ac240a74.svn-base 123KB
00
005e17e96ca6326a34a24d8412ef7cf136f74b57.svn-base 3KB
1d
1d74c70d3f128bdf3d787b7942d5dc457a7bc4e3.svn-base 37KB
3c
3c54a7b9e66404ce7eb8d31b825f78e2eaa4a251.svn-base 6KB
05
057ca9e0f112660ea63f850ae979371527a4cfc4.svn-base 954B
7e
7e3cbc4d046f57ee099d1bba32e4883cedb09d98.svn-base 44KB
f3
f3b6bab5d270381efa7eb7ac8e356231ea07b471.svn-base 2KB
3d
3d54245c84801c4c0a745c0c82aed6dc031ec452.svn-base 1KB
3df125a376b37c3547fadbc3e041f614d37f8719.svn-base 148KB
41
418b9b5fc912dac9ff8e9f38c7e46734ae3effa4.svn-base 832B
23
23c99fce7a5718e99f68da1448abc48eec63c5bb.svn-base 9KB
03
0348d90677cf52930c9766f36197f8feba970988.svn-base 18KB
wc.db 43KB
format 3B
tmp
entries 3B
AmCap.idc 1KB
x64
Release
Debug
status.cpp 9KB
SampleCGB.h 7KB
共 54 条
- 1
hanzi_lin
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页