This repository has been archived by the owner on Aug 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is ScottOrange's original code with posted to the MSDN for other…
…s to work on after the skype functionality stopped working for him. A link to the MSDN forum: http://social.msdn.microsoft.com/Forums/en-US/kinectsdk/thread/4ee6e7ca-123d-4838-82b6-e5816bf6529c I have added my .gitignore file to ensure the workspace removes free of VS2010's clutter.
- Loading branch information
wildbillcat
committed
Jun 22, 2012
0 parents
commit e32dbb0
Showing
12 changed files
with
963 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
bin/* | ||
obj/* | ||
ipch/* | ||
debug/* | ||
release/* | ||
*.sou | ||
*.user | ||
*.ncb | ||
*.sbr | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
////////////////////////////////////////////////////////////////////////// | ||
// This file contains routines to register / Unregister the | ||
// Directshow filter 'Virtual Cam' | ||
// We do not use the inbuilt BaseClasses routines as we need to register as | ||
// a capture source | ||
////////////////////////////////////////////////////////////////////////// | ||
#pragma comment(lib, "kernel32") | ||
#pragma comment(lib, "user32") | ||
#pragma comment(lib, "gdi32") | ||
#pragma comment(lib, "advapi32") | ||
#pragma comment(lib, "winmm") | ||
#pragma comment(lib, "ole32") | ||
#pragma comment(lib, "oleaut32") | ||
|
||
#ifdef _DEBUG | ||
#pragma comment(lib, "strmbasd") | ||
#else | ||
#pragma comment(lib, "strmbase") | ||
#endif | ||
|
||
|
||
#include <streams.h> | ||
#include <olectl.h> | ||
#include <initguid.h> | ||
#include <dllsetup.h> | ||
#include "Vcam.h" | ||
|
||
#define CreateComObject(clsid, iid, var) CoCreateInstance( clsid, NULL, CLSCTX_INPROC_SERVER, iid, (void **)&var); | ||
|
||
STDAPI AMovieSetupRegisterServer( CLSID clsServer, LPCWSTR szDescription, LPCWSTR szFileName, LPCWSTR szThreadingModel = L"Both", LPCWSTR szServerType = L"InprocServer32" ); | ||
STDAPI AMovieSetupUnregisterServer( CLSID clsServer ); | ||
|
||
|
||
|
||
// {8E14549A-DB61-4309-AFA1-3578E927E933} | ||
DEFINE_GUID(CLSID_VirtualCam, | ||
0x8e14549a, 0xdb61, 0x4309, 0xaf, 0xa1, 0x35, 0x78, 0xe9, 0x27, 0xe9, 0x33); | ||
|
||
|
||
const AMOVIESETUP_MEDIATYPE AMSMediaTypesVCam = | ||
{ | ||
&MEDIATYPE_Video, | ||
&MEDIASUBTYPE_NULL | ||
}; | ||
|
||
const AMOVIESETUP_PIN AMSPinVCam= | ||
{ | ||
L"Output", // Pin string name | ||
FALSE, // Is it rendered | ||
TRUE, // Is it an output | ||
FALSE, // Can we have none | ||
FALSE, // Can we have many | ||
&CLSID_NULL, // Connects to filter | ||
NULL, // Connects to pin | ||
1, // Number of types | ||
&AMSMediaTypesVCam // Pin Media types | ||
}; | ||
|
||
const AMOVIESETUP_FILTER AMSFilterVCam = | ||
{ | ||
&CLSID_VirtualCam, // Filter CLSID | ||
L"Kinect Cam", // String name | ||
MERIT_DO_NOT_USE, // Filter merit | ||
1, // Number pins | ||
&AMSPinVCam // Pin details | ||
}; | ||
|
||
CFactoryTemplate g_Templates[] = | ||
{ | ||
{ | ||
L"Kinect Cam", | ||
&CLSID_VirtualCam, | ||
CVCam::CreateInstance, | ||
NULL, | ||
&AMSFilterVCam | ||
}, | ||
|
||
}; | ||
|
||
int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); | ||
|
||
STDAPI RegisterFilters( BOOL bRegister ) | ||
{ | ||
HRESULT hr = NOERROR; | ||
WCHAR achFileName[MAX_PATH]; | ||
char achTemp[MAX_PATH]; | ||
ASSERT(g_hInst != 0); | ||
|
||
if( 0 == GetModuleFileNameA(g_hInst, achTemp, sizeof(achTemp))) | ||
return AmHresultFromWin32(GetLastError()); | ||
|
||
MultiByteToWideChar(CP_ACP, 0L, achTemp, lstrlenA(achTemp) + 1, | ||
achFileName, NUMELMS(achFileName)); | ||
|
||
hr = CoInitialize(0); | ||
if(bRegister) | ||
{ | ||
hr = AMovieSetupRegisterServer(CLSID_VirtualCam, L"Kinect Cam", achFileName, L"Both", L"InprocServer32"); | ||
} | ||
|
||
if( SUCCEEDED(hr) ) | ||
{ | ||
IFilterMapper2 *fm = 0; | ||
hr = CreateComObject( CLSID_FilterMapper2, IID_IFilterMapper2, fm ); | ||
if( SUCCEEDED(hr) ) | ||
{ | ||
if(bRegister) | ||
{ | ||
IMoniker *pMoniker = 0; | ||
REGFILTER2 rf2; | ||
rf2.dwVersion = 1; | ||
rf2.dwMerit = MERIT_DO_NOT_USE; | ||
rf2.cPins = 1; | ||
rf2.rgPins = &AMSPinVCam; | ||
hr = fm->RegisterFilter(CLSID_VirtualCam, L"Kinect Cam", &pMoniker, &CLSID_VideoInputDeviceCategory, NULL, &rf2); | ||
} | ||
else | ||
{ | ||
hr = fm->UnregisterFilter(&CLSID_VideoInputDeviceCategory, 0, CLSID_VirtualCam); | ||
} | ||
} | ||
|
||
// release interface | ||
// | ||
if(fm) | ||
fm->Release(); | ||
} | ||
|
||
if( SUCCEEDED(hr) && !bRegister ) | ||
hr = AMovieSetupUnregisterServer( CLSID_VirtualCam ); | ||
|
||
CoFreeUnusedLibraries(); | ||
CoUninitialize(); | ||
return hr; | ||
} | ||
|
||
STDAPI DllRegisterServer() | ||
{ | ||
return RegisterFilters(TRUE); | ||
} | ||
|
||
STDAPI DllUnregisterServer() | ||
{ | ||
return RegisterFilters(FALSE); | ||
} | ||
|
||
extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID); | ||
|
||
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) | ||
{ | ||
return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "KinectCam.h" | ||
#include "stdio.h" | ||
#include <shlobj.h> | ||
|
||
bool g_flipImage = false; | ||
|
||
HRESULT KinectCam::Nui_Init() | ||
{ | ||
HRESULT hr; | ||
|
||
m_hNextVideoFrameEvent = NULL; | ||
m_pVideoStreamHandle = NULL; | ||
m_hNextVideoFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); | ||
|
||
hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR); | ||
if( FAILED( hr ) ) | ||
{ | ||
return hr; | ||
} | ||
|
||
// Set camera angle | ||
char iniFile[MAX_PATH]; | ||
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, iniFile); | ||
strcat(iniFile, "\\KinectCam"); | ||
CreateDirectory(iniFile, NULL); | ||
strcat(iniFile, "\\config.ini"); | ||
if (_access(iniFile, 0) != 0) | ||
{ | ||
FILE *f = fopen(iniFile, "w"); | ||
if (f) | ||
{ | ||
fprintf(f, "[KinectCam]\n"); | ||
fprintf(f, "CameraElevationAngle=0\n"); | ||
fprintf(f, "CameraShutdownAngle=0\n"); | ||
fprintf(f, "FlipImage=0\n"); | ||
fclose(f); | ||
} | ||
} | ||
|
||
char val[256]; | ||
GetPrivateProfileString("KinectCam", "CameraElevationAngle", "999", val, 256, iniFile); | ||
int angle = atoi(val); | ||
if (angle != 999) | ||
NuiCameraElevationSetAngle(angle); | ||
|
||
GetPrivateProfileString("KinectCam", "FlipImage", "0", val, 256, iniFile); | ||
g_flipImage = (atoi(val) != 0); | ||
|
||
NUI_IMAGE_RESOLUTION resolution; | ||
resolution = NUI_IMAGE_RESOLUTION_640x480; | ||
|
||
hr = NuiImageStreamOpen( | ||
NUI_IMAGE_TYPE_COLOR, | ||
resolution, | ||
0, | ||
2, | ||
m_hNextVideoFrameEvent, | ||
&m_pVideoStreamHandle ); | ||
|
||
return hr; | ||
} | ||
|
||
|
||
|
||
void KinectCam::Nui_UnInit() | ||
{ | ||
// Reset camera angle | ||
char iniFile[MAX_PATH]; | ||
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, iniFile); | ||
strcat(iniFile, "\\KinectCam"); | ||
strcat(iniFile, "\\config.ini"); | ||
|
||
char val[256]; | ||
GetPrivateProfileString("KinectCam", "CameraShutdownAngle", "999", val, 256, iniFile); | ||
int angle = atoi(val); | ||
if (angle != 999) | ||
NuiCameraElevationSetAngle(angle); | ||
|
||
NuiShutdown( ); | ||
|
||
if( m_hNextVideoFrameEvent && ( m_hNextVideoFrameEvent != INVALID_HANDLE_VALUE ) ) | ||
{ | ||
CloseHandle( m_hNextVideoFrameEvent ); | ||
m_hNextVideoFrameEvent = NULL; | ||
} | ||
} | ||
|
||
|
||
void KinectCam::Nui_GetCamFrame(BYTE *frameBuffer, int frameSize) | ||
{ | ||
const NUI_IMAGE_FRAME *pImageFrame = NULL; | ||
|
||
WaitForSingleObject(m_hNextVideoFrameEvent, INFINITE); | ||
|
||
HRESULT hr = NuiImageStreamGetNextFrame( | ||
m_pVideoStreamHandle, | ||
0, | ||
&pImageFrame ); | ||
if( FAILED( hr ) ) | ||
{ | ||
return; | ||
} | ||
|
||
INuiFrameTexture *pTexture = pImageFrame->pFrameTexture; | ||
NUI_LOCKED_RECT LockedRect; | ||
pTexture->LockRect( 0, &LockedRect, NULL, 0 ); | ||
if( LockedRect.Pitch != 0 ) | ||
{ | ||
BYTE * pBuffer = (BYTE*) LockedRect.pBits; | ||
memcpy(frameBuffer, pBuffer, frameSize); | ||
} | ||
|
||
NuiImageStreamReleaseFrame( m_pVideoStreamHandle, pImageFrame ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
LIBRARY KinectCam.ax | ||
EXPORTS | ||
DllMain PRIVATE | ||
DllGetClassObject PRIVATE | ||
DllCanUnloadNow PRIVATE | ||
DllRegisterServer PRIVATE | ||
DllUnregisterServer PRIVATE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#include <io.h> | ||
#include "NuiApi.h" | ||
|
||
class KinectCam | ||
{ | ||
public: | ||
HRESULT Nui_Init(); | ||
void Nui_UnInit(); | ||
void Nui_GetCamFrame(BYTE *frameBuffer, int frameSize); | ||
|
||
private: | ||
HANDLE m_hNextVideoFrameEvent; | ||
HANDLE m_pVideoStreamHandle; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KinectCam", "KinectCam.vcxproj", "{A5ED309D-F36E-63BC-9EBD-99E1422BBEA5}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Win32 = Debug|Win32 | ||
Release|Win32 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A5ED309D-F36E-63BC-9EBD-99E1422BBEA5}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
{A5ED309D-F36E-63BC-9EBD-99E1422BBEA5}.Debug|Win32.Build.0 = Debug|Win32 | ||
{A5ED309D-F36E-63BC-9EBD-99E1422BBEA5}.Release|Win32.ActiveCfg = Release|Win32 | ||
{A5ED309D-F36E-63BC-9EBD-99E1422BBEA5}.Release|Win32.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.