[Vm-dev] [commit] r2211 - Import of Scratch CameraPlugin support code.

commits at squeakvm.org commits at squeakvm.org
Fri May 28 20:36:30 UTC 2010


Author: andreas
Date: 2010-05-28 13:36:27 -0700 (Fri, 28 May 2010)
New Revision: 2211

Added:
   trunk/platforms/win32/plugins/CameraPlugin/
   trunk/platforms/win32/plugins/CameraPlugin/Building Windows CameraPlugin.txt
   trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.cpp
   trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.dll
   trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.vcproj
   trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/
   trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.sln
   trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.vcproj
   trunk/platforms/win32/plugins/CameraPlugin/STRMBASE.lib
   trunk/platforms/win32/plugins/CameraPlugin/cameraOps.h
   trunk/platforms/win32/plugins/CameraPlugin/sqVirtualMachine.h
   trunk/platforms/win32/plugins/CameraPlugin/winCameraOps.cpp
Log:
Import of Scratch CameraPlugin support code.

Added: trunk/platforms/win32/plugins/CameraPlugin/Building Windows CameraPlugin.txt
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/Building Windows CameraPlugin.txt	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/Building Windows CameraPlugin.txt	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,31 @@
+1. Installs:
+	Visual Studio .NET (2003) v7.1
+	Microsoft Platform SDK for Windows Server 2003 R2
+	(You do not need to install DirectX)
+
+2. Build the base class library
+	Download the VS project files from:
+		http://tmhare.mvps.org/downloads.htm
+	Place in folder:
+		C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Samples\Multimedia\DirectShow\BaseClasses
+	Open project (allow it to update if asked)
+	Set configuration to "release"
+	Build the project
+	Get STRMBASE.lib from the Release folder
+
+3. Create CameraPlugin project
+	a. Open VisualStudio
+	b. New -> Project
+	c. select template "MFC DLL" (under Visual C++ Projects/MFC)
+	d. Under "Application Settings", select "Regular DLL with MFC statically linked"
+	e. remove all .cpp, .h, and resource files
+	f. add camera plugin source files
+	e. disable "precompiled headers" option
+	f. under "Linker/Input" options, remove "Module Definition File"
+	g. copy STRMBASE.lib to folder and add to project
+
+
+Useful links:
+	http://www.ptgrey.com/support/downloads/documents/TAN2007003_Developing_DirectShow_applications_with_FlyStream.pdf
+	http://tmhare.mvps.org/downloads.htm (VC projects for base classes)
+

Added: trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.cpp
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.cpp	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.cpp	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,160 @@
+/* Automatically generated from Squeak on (29 April 2009 6:59:14 am) */
+
+#if defined(WIN32) || defined(_WIN32) || defined(Win32)
+ #ifdef __cplusplus
+  #define DLLEXPORT extern "C" __declspec(dllexport)
+ #else
+  #define DLLEXPORT __declspec(dllexport)
+ #endif /* C++ */
+#else
+ #define DLLEXPORT
+#endif /* WIN32 */
+
+#include "sqVirtualMachine.h"
+
+/* memory access macros */
+#define byteAt(i) (*((unsigned char *) (i)))
+#define byteAtput(i, val) (*((unsigned char *) (i)) = val)
+#define longAt(i) (*((int *) (i)))
+#define longAtput(i, val) (*((int *) (i)) = val)
+
+#include "cameraOps.h"
+#include <string.h>
+
+
+/*** Variables ***/
+struct VirtualMachine* interpreterProxy;
+const char *moduleName = "CameraPlugin 29 April 2009 (e)";
+
+/*** Functions ***/
+DLLEXPORT int primCameraName(void);
+DLLEXPORT int primCloseCamera(void);
+DLLEXPORT int primFrameExtent(void);
+DLLEXPORT int primGetFrame(void);
+DLLEXPORT int primGetParam(void);
+DLLEXPORT int primOpenCamera(void);
+DLLEXPORT int setInterpreter(struct VirtualMachine* anInterpreter);
+
+DLLEXPORT int primCameraName(void) {
+	char* nameStr;
+	int i;
+	int count;
+	int resultOop;
+	int cameraNum;
+	char* dst;
+
+	cameraNum = interpreterProxy->stackIntegerValue(0);
+	if (interpreterProxy->failed()) {
+		return 0;
+	}
+	nameStr = CameraName(cameraNum);
+	if (nameStr == 0) {
+		interpreterProxy->success(0);
+		return 0;
+	}
+	count = (int) strlen(nameStr);
+	resultOop = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classString(), count);
+	dst = ((char *) (interpreterProxy->firstIndexableField(resultOop)));
+	for (i = 0; i <= (count - 1); i += 1) {
+		dst[i] = (nameStr[i]);
+	}
+	interpreterProxy->popthenPush(2, resultOop);
+	return 0;
+}
+
+DLLEXPORT int primCloseCamera(void) {
+	int cameraNum;
+
+	cameraNum = interpreterProxy->stackIntegerValue(0);
+	if (interpreterProxy->failed()) {
+		return 0;
+	}
+	CameraClose(cameraNum);
+	interpreterProxy->pop(1);
+	return 0;
+}
+
+DLLEXPORT int primFrameExtent(void) {
+	int cameraNum;
+	int e;
+
+	cameraNum = interpreterProxy->stackIntegerValue(0);
+	if (interpreterProxy->failed()) {
+		return 0;
+	}
+	e = CameraExtent(cameraNum);
+	interpreterProxy->popthenPush(2, ((e << 1) | 1));
+	return 0;
+}
+
+DLLEXPORT int primGetFrame(void) {
+	int cameraNum;
+	int bitmapOop;
+	unsigned char *bitmap;
+	int pixCount;
+	int result;
+
+	cameraNum = interpreterProxy->stackIntegerValue(1);
+	bitmapOop = interpreterProxy->stackValue(0);
+	if (((bitmapOop & 1)) || (!(interpreterProxy->isWords(bitmapOop)))) {
+		interpreterProxy->success(0);
+		return 0;
+	}
+	bitmap = ((unsigned char *) (interpreterProxy->firstIndexableField(bitmapOop)));
+	pixCount = interpreterProxy->stSizeOf(bitmapOop);
+	result = CameraGetFrame(cameraNum, bitmap, pixCount);
+	if (result < 0) {
+		interpreterProxy->success(0);
+		return 0;
+	}
+	interpreterProxy->popthenPush(3, ((result << 1) | 1));
+	return 0;
+}
+
+DLLEXPORT int primGetParam(void) {
+	int cameraNum;
+	int result;
+	int paramNum;
+
+	cameraNum = interpreterProxy->stackIntegerValue(1);
+	paramNum = interpreterProxy->stackIntegerValue(0);
+	if (interpreterProxy->failed()) {
+		return 0;
+	}
+	result = CameraGetParam(cameraNum, paramNum);
+	interpreterProxy->popthenPush(3, ((result << 1) | 1));
+	return 0;
+}
+
+DLLEXPORT int primOpenCamera(void) {
+	int cameraNum;
+	int desiredFrameWidth;
+	int ok;
+	int desiredFrameHeight;
+
+	cameraNum = interpreterProxy->stackIntegerValue(2);
+	desiredFrameWidth = interpreterProxy->stackIntegerValue(1);
+	desiredFrameHeight = interpreterProxy->stackIntegerValue(0);
+	if (interpreterProxy->failed()) {
+		return 0;
+	}
+	ok = CameraOpen(cameraNum, desiredFrameWidth, desiredFrameHeight);
+	if (ok == 0) {
+		interpreterProxy->success(0);
+		return 0;
+	}
+	interpreterProxy->pop(3);
+	return 0;
+}
+
+DLLEXPORT int setInterpreter(struct VirtualMachine* anInterpreter) {
+	int ok;
+
+	interpreterProxy = anInterpreter;
+	ok = interpreterProxy->majorVersion() == VM_PROXY_MAJOR;
+	if (ok == 0) {
+		return 0;
+	}
+	ok = interpreterProxy->minorVersion() >= VM_PROXY_MINOR;
+	return ok;
+}

Added: trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.dll
===================================================================
(Binary files differ)


Property changes on: trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.dll
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.vcproj
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.vcproj	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/CameraPlugin.vcproj	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="CameraPlugin"
+	ProjectGUID="{E075D391-317C-4CC9-9E40-7DEABF0BF7E0}"
+	Keyword="MFCDLLProj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="2"
+			UseOfMFC="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;_USRDLL"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				TreatWChar_tAsBuiltInType="TRUE"
+				UsePrecompiledHeader="3"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/CameraPlugin.dll"
+				LinkIncremental="2"
+				ModuleDefinitionFile=".\CameraPlugin.def"
+				GenerateDebugInformation="TRUE"
+				SubSystem="2"
+				ImportLibrary="$(OutDir)/CameraPlugin.lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="_DEBUG"
+				MkTypLibCompatible="FALSE"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG"
+				Culture="1033"
+				AdditionalIncludeDirectories="$(IntDir)"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="2"
+			UseOfMFC="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;_USRDLL"
+				RuntimeLibrary="0"
+				TreatWChar_tAsBuiltInType="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/CameraPlugin.dll"
+				LinkIncremental="1"
+				ModuleDefinitionFile=""
+				GenerateDebugInformation="TRUE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				ImportLibrary="$(OutDir)/CameraPlugin.lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="NDEBUG"
+				MkTypLibCompatible="FALSE"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG"
+				Culture="1033"
+				AdditionalIncludeDirectories="$(IntDir)"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\CameraPlugin.cpp">
+			</File>
+			<File
+				RelativePath=".\winCameraOps.cpp">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="">
+			<File
+				RelativePath=".\cameraOps.h">
+			</File>
+			<File
+				RelativePath=".\sqVirtualMachine.h">
+			</File>
+		</Filter>
+		<File
+			RelativePath=".\STRMBASE.lib">
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

Added: trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.sln
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.sln	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.sln	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,27 @@
+Microsoft Visual Studio Solution File, Format Version 7.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BaseClasses", "baseclasses.vcproj", "{C14D9535-35E5-4B7F-8614-B772A214EB0B}"
+EndProject
+Global
+	GlobalSection(SolutionConfiguration) = preSolution
+		ConfigName.0 = Debug
+		ConfigName.1 = Debug Unicode
+		ConfigName.2 = Release
+		ConfigName.3 = Release Unicode
+	EndGlobalSection
+	GlobalSection(ProjectDependencies) = postSolution
+	EndGlobalSection
+	GlobalSection(ProjectConfiguration) = postSolution
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Debug.ActiveCfg = Debug|Win32
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Debug.Build.0 = Debug|Win32
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Debug Unicode.ActiveCfg = Debug Unicode|Win32
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Debug Unicode.Build.0 = Debug Unicode|Win32
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Release.ActiveCfg = Release|Win32
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Release.Build.0 = Release|Win32
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Release Unicode.ActiveCfg = Release Unicode|Win32
+		{C14D9535-35E5-4B7F-8614-B772A214EB0B}.Release Unicode.Build.0 = Release Unicode|Win32
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+	EndGlobalSection
+	GlobalSection(ExtensibilityAddIns) = postSolution
+	EndGlobalSection
+EndGlobal

Added: trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.vcproj
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.vcproj	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/DirectShow BaseClasses project/baseclasses.vcproj	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,413 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.00"
+	Name="BaseClasses"
+	SccProjectName=""
+	SccLocalPath="">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory=".\Release"
+			IntermediateDirectory=".\Release"
+			ConfigurationType="4"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="FALSE"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				InlineFunctionExpansion="1"
+				AdditionalIncludeDirectories=".,..\..\..\..\include"
+				PreprocessorDefinitions="NDEBUG,WIN32,_LIB,_WIN32_DCOM,WINVER=0x400"
+				StringPooling="TRUE"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="TRUE"
+				UsePrecompiledHeader="3"
+				PrecompiledHeaderThrough="streams.h"
+				PrecompiledHeaderFile=".\Release/baseclasses.pch"
+				AssemblerListingLocation=".\Release/"
+				ObjectFile=".\Release/"
+				ProgramDataBaseFileName=".\Release/"
+				WarningLevel="3"
+				SuppressStartupBanner="TRUE"
+				CallingConvention="2"
+				CompileAs="0"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				AdditionalOptions="..\..\..\..\lib\strmiids.lib  /nodefaultlib "
+				OutputFile="Release\STRMBASE.lib"
+				SuppressStartupBanner="TRUE"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG,WIN32"
+				Culture="1033"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug Unicode|Win32"
+			OutputDirectory=".\Debug_Unicode"
+			IntermediateDirectory=".\Debug_Unicode"
+			ConfigurationType="4"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="FALSE"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".,..\..\..\..\include"
+				PreprocessorDefinitions="_DEBUG,_MBCS,_LIB,_WIN32_DCOM,DEBUG,WINVER=0x400,WIN32,UNICODE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="3"
+				PrecompiledHeaderThrough="streams.h"
+				PrecompiledHeaderFile=".\Debug_Unicode/baseclasses.pch"
+				AssemblerListingLocation=".\Debug_Unicode/"
+				ObjectFile=".\Debug_Unicode/"
+				ProgramDataBaseFileName=".\Debug_Unicode/"
+				WarningLevel="3"
+				SuppressStartupBanner="TRUE"
+				DebugInformationFormat="3"
+				CallingConvention="2"
+				CompileAs="0"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				AdditionalOptions="..\..\..\..\lib\strmiids.lib  /nodefaultlib "
+				OutputFile="Debug_Unicode\strmbasd.lib"
+				SuppressStartupBanner="TRUE"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG,WIN32"
+				Culture="1033"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release Unicode|Win32"
+			OutputDirectory=".\Release_Unicode"
+			IntermediateDirectory=".\Release_Unicode"
+			ConfigurationType="4"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="FALSE"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				InlineFunctionExpansion="1"
+				AdditionalIncludeDirectories=".,..\..\..\..\include"
+				PreprocessorDefinitions="NDEBUG,_MBCS,_LIB,_WIN32_DCOM,WINVER=0x400,WIN32,UNICODE"
+				StringPooling="TRUE"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="TRUE"
+				UsePrecompiledHeader="3"
+				PrecompiledHeaderThrough="streams.h"
+				PrecompiledHeaderFile=".\Release_Unicode/baseclasses.pch"
+				AssemblerListingLocation=".\Release_Unicode/"
+				ObjectFile=".\Release_Unicode/"
+				ProgramDataBaseFileName=".\Release_Unicode/"
+				WarningLevel="3"
+				SuppressStartupBanner="TRUE"
+				CallingConvention="2"
+				CompileAs="0"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				AdditionalOptions="..\..\..\..\lib\strmiids.lib  /nodefaultlib "
+				OutputFile="Release_Unicode\STRMBASE.lib"
+				SuppressStartupBanner="TRUE"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG,WIN32"
+				Culture="1033"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory=".\Debug"
+			IntermediateDirectory=".\Debug"
+			ConfigurationType="4"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="FALSE"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".,..\..\..\..\include"
+				PreprocessorDefinitions="_DEBUG,WIN32,_LIB,_WIN32_DCOM,DEBUG,WINVER=0x400"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="3"
+				PrecompiledHeaderThrough="streams.h"
+				PrecompiledHeaderFile=".\Debug/baseclasses.pch"
+				AssemblerListingLocation=".\Debug/"
+				ObjectFile=".\Debug/"
+				ProgramDataBaseFileName=".\Debug/"
+				WarningLevel="3"
+				SuppressStartupBanner="TRUE"
+				DebugInformationFormat="3"
+				CallingConvention="2"
+				CompileAs="0"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				AdditionalOptions="..\..\..\..\lib\strmiids.lib  /nodefaultlib "
+				OutputFile="debug\strmbasd.lib"
+				SuppressStartupBanner="TRUE"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG,WIN32"
+				Culture="1033"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+			<File
+				RelativePath=".\amextra.cpp">
+			</File>
+			<File
+				RelativePath=".\amfilter.cpp">
+			</File>
+			<File
+				RelativePath=".\amvideo.cpp">
+			</File>
+			<File
+				RelativePath=".\combase.cpp">
+			</File>
+			<File
+				RelativePath=".\cprop.cpp">
+			</File>
+			<File
+				RelativePath=".\ctlutil.cpp">
+			</File>
+			<File
+				RelativePath=".\ddmm.cpp">
+			</File>
+			<File
+				RelativePath=".\dllentry.cpp">
+				<FileConfiguration
+					Name="Release|Win32">
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug Unicode|Win32">
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release Unicode|Win32">
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32">
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath=".\dllsetup.cpp">
+			</File>
+			<File
+				RelativePath=".\mtype.cpp">
+			</File>
+			<File
+				RelativePath=".\outputq.cpp">
+			</File>
+			<File
+				RelativePath=".\pstream.cpp">
+			</File>
+			<File
+				RelativePath=".\pullpin.cpp">
+			</File>
+			<File
+				RelativePath=".\refclock.cpp">
+			</File>
+			<File
+				RelativePath=".\renbase.cpp">
+			</File>
+			<File
+				RelativePath=".\schedule.cpp">
+			</File>
+			<File
+				RelativePath=".\seekpt.cpp">
+			</File>
+			<File
+				RelativePath=".\source.cpp">
+			</File>
+			<File
+				RelativePath=".\strmctl.cpp">
+			</File>
+			<File
+				RelativePath=".\sysclock.cpp">
+			</File>
+			<File
+				RelativePath=".\transfrm.cpp">
+			</File>
+			<File
+				RelativePath=".\transip.cpp">
+			</File>
+			<File
+				RelativePath=".\videoctl.cpp">
+			</File>
+			<File
+				RelativePath=".\vtrans.cpp">
+			</File>
+			<File
+				RelativePath=".\winctrl.cpp">
+			</File>
+			<File
+				RelativePath=".\winutil.cpp">
+			</File>
+			<File
+				RelativePath=".\wxdebug.cpp">
+			</File>
+			<File
+				RelativePath=".\wxlist.cpp">
+			</File>
+			<File
+				RelativePath=".\wxutil.cpp">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl">
+			<File
+				RelativePath=".\activex.rcv">
+			</File>
+			<File
+				RelativePath=".\activex.ver">
+			</File>
+			<File
+				RelativePath=".\dllsetup.h">
+			</File>
+			<File
+				RelativePath=".\dsschedule.h">
+			</File>
+			<File
+				RelativePath=".\fourcc.h">
+			</File>
+			<File
+				RelativePath=".\measure.h">
+			</File>
+			<File
+				RelativePath=".\msgthrd.h">
+			</File>
+			<File
+				RelativePath=".\mtype.h">
+			</File>
+			<File
+				RelativePath=".\outputq.h">
+			</File>
+			<File
+				RelativePath=".\pstream.h">
+			</File>
+			<File
+				RelativePath=".\pullpin.h">
+			</File>
+			<File
+				RelativePath=".\refclock.h">
+			</File>
+			<File
+				RelativePath=".\reftime.h">
+			</File>
+			<File
+				RelativePath=".\renbase.h">
+			</File>
+			<File
+				RelativePath=".\seekpt.h">
+			</File>
+			<File
+				RelativePath=".\source.h">
+			</File>
+			<File
+				RelativePath=".\streams.h">
+			</File>
+			<File
+				RelativePath=".\strmctl.h">
+			</File>
+			<File
+				RelativePath=".\sysclock.h">
+			</File>
+			<File
+				RelativePath=".\transfrm.h">
+			</File>
+			<File
+				RelativePath=".\transip.h">
+			</File>
+			<File
+				RelativePath=".\videoctl.h">
+			</File>
+			<File
+				RelativePath=".\vtrans.h">
+			</File>
+			<File
+				RelativePath=".\winctrl.h">
+			</File>
+			<File
+				RelativePath=".\winutil.h">
+			</File>
+			<File
+				RelativePath=".\wxdebug.h">
+			</File>
+			<File
+				RelativePath=".\wxlist.h">
+			</File>
+			<File
+				RelativePath=".\wxutil.h">
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

Added: trunk/platforms/win32/plugins/CameraPlugin/STRMBASE.lib
===================================================================
(Binary files differ)


Property changes on: trunk/platforms/win32/plugins/CameraPlugin/STRMBASE.lib
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/platforms/win32/plugins/CameraPlugin/cameraOps.h
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/cameraOps.h	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/cameraOps.h	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,10 @@
+extern "C" {
+
+int CameraOpen(int cameraNum, int desiredWidth, int desiredHeight);
+void CameraClose(int cameraNum);
+int CameraExtent(int cameraNum);
+int CameraGetFrame(int cameraNum, unsigned char* buf, int pixelCount);
+char* CameraName(int cameraNum);
+int CameraGetParam(int cameraNum, int paramNum);
+
+}
\ No newline at end of file

Added: trunk/platforms/win32/plugins/CameraPlugin/sqVirtualMachine.h
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/sqVirtualMachine.h	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/sqVirtualMachine.h	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,141 @@
+#ifndef _SqueakVM_H
+#define _SqueakVM_H
+
+/* Increment the following number if you change the order of
+   functions listed or if you remove functions */
+#define VM_PROXY_MAJOR 1
+
+/* Increment the following number if you add functions at the end */
+#define VM_PROXY_MINOR 1
+
+typedef int (*CompilerHook)();
+
+struct VirtualMachine* sqGetInterpreterProxy(void);
+
+typedef struct VirtualMachine {
+	int (*minorVersion) (void);
+	int (*majorVersion) (void);
+
+
+	/* InterpreterProxy methodsFor: 'stack access' */
+
+	int (*pop)(int nItems);
+	int (*popthenPush)(int nItems, int oop);
+	int (*push)(int object);
+	int (*pushBool)(int trueOrFalse);
+	int (*pushFloat)(double f);
+	int (*pushInteger)(int integerValue);
+	double (*stackFloatValue)(int offset);
+	int (*stackIntegerValue)(int offset);
+	int (*stackObjectValue)(int offset);
+	int (*stackValue)(int offset);
+	
+
+	/* InterpreterProxy methodsFor: 'object access' */
+
+	int (*argumentCountOf)(int methodPointer);
+	void * (*arrayValueOf)(int oop);
+	int (*byteSizeOf)(int oop);
+	void * (*fetchArrayofObject)(int fieldIndex, int objectPointer);
+	int (*fetchClassOf)(int oop);
+	double (*fetchFloatofObject)(int fieldIndex, int objectPointer);
+	int (*fetchIntegerofObject)(int fieldIndex, int objectPointer);
+	int (*fetchPointerofObject)(int index, int oop);
+	int (*fetchWordofObject)(int fieldIndex, int oop);
+	void * (*firstFixedField)(int oop);
+	void * (*firstIndexableField)(int oop);
+	int (*literalofMethod)(int offset, int methodPointer);
+	int (*literalCountOf)(int methodPointer);
+	int (*methodArgumentCount)(void);
+	int (*methodPrimitiveIndex)(void);
+	int (*primitiveIndexOf)(int methodPointer);
+	int (*sizeOfSTArrayFromCPrimitive)(void *cPtr);
+	int (*slotSizeOf)(int oop);
+	int (*stObjectat)(int array, int index);
+	int (*stObjectatput)(int array, int index, int value);
+	int (*stSizeOf)(int oop);
+	int (*storeIntegerofObjectwithValue)(int index, int oop, int integer);
+	int (*storePointerofObjectwithValue)(int index, int oop, int valuePointer);
+	
+
+	/* InterpreterProxy methodsFor: 'testing' */
+
+	int (*isKindOf)(int oop, char *aString);
+	int (*isMemberOf)(int oop, char *aString);
+	int (*isBytes)(int oop);
+	int (*isFloatObject)(int oop);
+	int (*isIndexable)(int oop);
+	int (*isIntegerObject)(int objectPointer);
+	int (*isIntegerValue)(int intValue);
+	int (*isPointers)(int oop);
+	int (*isWeak)(int oop);
+	int (*isWords)(int oop);
+	int (*isWordsOrBytes)(int oop);
+	
+
+	/* InterpreterProxy methodsFor: 'converting' */
+
+	int (*booleanValueOf)(int obj);
+	int (*checkedIntegerValueOf)(int intOop);
+	int (*floatObjectOf)(double aFloat);
+	double (*floatValueOf)(int oop);
+	int (*integerObjectOf)(int value);
+	int (*integerValueOf)(int oop);
+	int (*positive32BitIntegerFor)(int integerValue);
+	int (*positive32BitValueOf)(int oop);
+	
+
+	/* InterpreterProxy methodsFor: 'special objects' */
+
+	int (*characterTable)(void);
+	int (*displayObject)(void);
+	int (*falseObject)(void);
+	int (*nilObject)(void);
+	int (*trueObject)(void);
+	
+
+	/* InterpreterProxy methodsFor: 'special classes' */
+
+	int (*classArray)(void);
+	int (*classBitmap)(void);
+	int (*classByteArray)(void);
+	int (*classCharacter)(void);
+	int (*classFloat)(void);
+	int (*classLargePositiveInteger)(void);
+	int (*classPoint)(void);
+	int (*classSemaphore)(void);
+	int (*classSmallInteger)(void);
+	int (*classString)(void);
+	
+
+	/* InterpreterProxy methodsFor: 'instance creation' */
+
+	int (*clone)(int oop);
+	int (*instantiateClassindexableSize)(int classPointer, int size);
+	int (*makePointwithxValueyValue)(int xValue, int yValue);
+	int (*popRemappableOop)(void);
+	int (*pushRemappableOop)(int oop);
+	
+
+	/* InterpreterProxy methodsFor: 'other' */
+
+	int (*becomewith)(int array1, int array2);
+	int (*byteSwapped)(int w);
+	int (*failed)(void);
+	int (*fullDisplayUpdate)(void);
+	int (*fullGC)(void);
+	int (*incrementalGC)(void);
+	int (*primitiveFail)(void);
+	int (*showDisplayBitsLeftTopRightBottom)(int aForm, int l, int t, int r, int b);
+	int (*signalSemaphoreWithIndex)(int semaIndex);
+	int (*success)(int aBoolean);
+	int (*superclassOf)(int classPointer);
+	
+	/* InterpreterProxy methodsFor: 'compiler' */
+
+	CompilerHook *(*compilerHookVector)(void);
+	int (*setCompilerInitialized)(int initFlag);
+
+} VirtualMachine;
+
+#endif /* _SqueakVM_H */

Added: trunk/platforms/win32/plugins/CameraPlugin/winCameraOps.cpp
===================================================================
--- trunk/platforms/win32/plugins/CameraPlugin/winCameraOps.cpp	                        (rev 0)
+++ trunk/platforms/win32/plugins/CameraPlugin/winCameraOps.cpp	2010-05-28 20:36:27 UTC (rev 2211)
@@ -0,0 +1,476 @@
+#include <windows.h>
+
+#include <atlbase.h>
+#include <dshow.h>
+#include <stdio.h>
+#include <qedit.h>
+
+extern "C" {
+#include "cameraOps.h"
+}
+
+//////////////////////////////////////////////
+// Sample Grabber Class
+//////////////////////////////////////////////
+
+class CSampleGrabberCB : public ISampleGrabberCB {
+public:
+	int frameCount;			// number of frames received since last GetFrame() call
+	long lFrameBufSize;		// size of buffer
+	BYTE *pFrameBuf;
+
+	// fake out any COM ref counting
+	STDMETHODIMP_(ULONG) AddRef() { return 2; }
+	STDMETHODIMP_(ULONG) Release()
+	{
+		frameCount = 0;
+		lFrameBufSize = 0;
+		pFrameBuf = NULL;
+		return 1;
+	}
+
+	// fake out any COM QI'ing
+	STDMETHODIMP QueryInterface(REFIID riid, void ** ppv)
+	{
+		if (riid == IID_ISampleGrabberCB || riid == IID_IUnknown) {
+			*ppv = (void *) static_cast<ISampleGrabberCB*> (this);
+			return NOERROR;
+		}
+		return E_NOINTERFACE;
+	}
+
+	STDMETHODIMP SampleCB(double SampleTime, IMediaSample * pSample) { return 0; } // noop
+
+	STDMETHODIMP BufferCB(double dblThisSampleTime, BYTE * pThisBuf, long lThisBufSize)
+	{
+		if ((pThisBuf == NULL) || (lThisBufSize == 0)) return E_POINTER;
+
+		// if the buffer sizes don't match, discard ours to force creating a new one
+		if (lFrameBufSize != lThisBufSize) {
+			lFrameBufSize = 0;
+			delete [] pFrameBuf;
+			pFrameBuf = NULL;
+		}
+
+		// if we haven't yet created the data buffer, do it now.
+		if (!pFrameBuf) {
+			pFrameBuf = new BYTE[lThisBufSize];
+			lFrameBufSize = lThisBufSize;
+			if (!pFrameBuf) lFrameBufSize = 0;
+		}
+
+		// Copy the bitmap data into our global buffer
+		if (pFrameBuf) memcpy(pFrameBuf, pThisBuf, lFrameBufSize);
+		frameCount++;
+
+		return 0;
+	}
+};
+
+//////////////////////////////////////////////
+// Data
+//////////////////////////////////////////////
+
+typedef struct Camera {
+	IBaseFilter *pCamera;
+	IGraphBuilder *pGraph;
+	ICaptureGraphBuilder2 *pCapture;
+	IMediaControl *pMediaControl;
+	IBaseFilter *ppf;
+	ISampleGrabber *pGrabber;
+	CSampleGrabberCB mCB;
+	int width;
+	int height;
+} Camera;
+
+#define CAMERA_COUNT 8
+Camera theCamera;
+
+//////////////////////////////////////////////
+// Local functions and macros
+//////////////////////////////////////////////
+
+int CameraIsOpen();
+void FindBestWidth(IAMStreamConfig *pCameraStream, int desiredWidth);
+HRESULT FindCamera(IBaseFilter ** ppSrcFilter, int num);
+void FreeMediaType(AM_MEDIA_TYPE *pMediaType);
+void FreeMediaTypeFields(AM_MEDIA_TYPE *pMediaType);
+char* GetCameraName(int num);
+HRESULT InitCamera(int num, int desiredWidth);
+void Msg(TCHAR *szFormat, ...);
+void SetCameraWidth(ICaptureGraphBuilder2 *pCaptureGraphBuilder, IBaseFilter *pSrcFilter, int desiredWidth);
+void SetOutputToRGB(void);
+
+#define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }
+
+//////////////////////////////////////////////
+// Entry Points
+//////////////////////////////////////////////
+
+int CameraOpen(int cameraNum, int desiredWidth, int desiredHeight)
+{
+	CameraClose(cameraNum);
+	int hr = InitCamera(cameraNum, desiredWidth);
+	return SUCCEEDED(hr);
+}
+
+void CameraClose(int cameraNum)
+{
+	if (!CameraIsOpen()) return;
+
+	// stop getting video
+	if (theCamera.pMediaControl) theCamera.pMediaControl->StopWhenReady();
+
+	// release DirectShow objects
+	SAFE_RELEASE(theCamera.pMediaControl);
+	SAFE_RELEASE(theCamera.pGraph);
+	SAFE_RELEASE(theCamera.pCapture);
+	SAFE_RELEASE(theCamera.pGrabber);
+	SAFE_RELEASE(theCamera.ppf);
+	SAFE_RELEASE(theCamera.pCamera);
+	theCamera.width = theCamera.height = 0;
+}
+
+int CameraExtent(int cameraNum)
+{
+	if (!CameraIsOpen()) return 0;
+
+	return (theCamera.width << 16) + theCamera.height;
+}
+
+int CameraGetFrame(int cameraNum, unsigned char* buf, int pixelCount)
+{
+	if (!CameraIsOpen()) return -1;
+
+	int framesSinceLastCall = theCamera.mCB.frameCount;
+	if (framesSinceLastCall == 0) return 0;  // no frame available
+	theCamera.mCB.frameCount = 0;  // clear frame count
+
+	if (pixelCount > (theCamera.mCB.lFrameBufSize / 3)) pixelCount = (theCamera.mCB.lFrameBufSize / 3);
+
+	// flip image vertically while copying to Squeak buf
+	unsigned char* pSrc = theCamera.mCB.pFrameBuf;
+	for (int y = theCamera.height - 1; y >= 0; y--) {
+		unsigned char* pDst = &buf[4 * y * theCamera.width];
+		for (int x = 0; x < theCamera.width; x++) {
+			*pDst++ = *pSrc++;		// red
+			*pDst++ = *pSrc++;		// green
+			*pDst++ = *pSrc++;		// blue
+			*pDst++ = 255;			// alpha
+		}
+	}
+
+	return framesSinceLastCall;
+}
+
+char* CameraName(int cameraNum)
+{
+	if ((cameraNum < 1) || (cameraNum > CAMERA_COUNT)) return NULL;
+	return GetCameraName(cameraNum);
+}
+
+int CameraGetParam(int cameraNum, int paramNum)  // for debugging and testing
+{
+	if (!CameraIsOpen()) return -1;
+	if (paramNum == 1) return theCamera.mCB.frameCount;
+	if (paramNum == 2) return theCamera.mCB.lFrameBufSize;
+
+	return -2;
+}
+
+//////////////////////////////////////////////
+// Local functions
+//////////////////////////////////////////////
+
+int CameraIsOpen()
+{
+	return theCamera.mCB.pFrameBuf != NULL;
+}
+
+HRESULT FindCamera(IBaseFilter ** ppSrcFilter, int cameraNum)
+{
+	HRESULT hr;
+	IBaseFilter *pSrc = NULL;
+	CComPtr <IMoniker> pMoniker = NULL;
+	ULONG cFetched;
+
+	if (!ppSrcFilter) return E_POINTER;
+
+	*ppSrcFilter = NULL;  // clear output in case we return early with an error
+
+	// Create system device enumerator
+	CComPtr <ICreateDevEnum> pDevEnum = NULL;
+	hr = CoCreateInstance(
+		CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
+		IID_ICreateDevEnum, (void **) &pDevEnum);
+	if (FAILED(hr)) return hr;
+
+	// Create enumerator for the video capture devices
+	CComPtr <IEnumMoniker> pClassEnum = NULL;
+	hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
+	if (FAILED(hr)) return hr;
+
+	// If there are no enumerators for the requested type, then
+	// CreateClassEnumerator will succeed, but pClassEnum will be NULL.
+	if (pClassEnum == NULL) return E_FAIL;
+
+	// Find the nth video capture device on the device list.
+	// Note that if the Next() call succeeds but there are no monikers,
+	// it will return S_FALSE (which is not a failure). Therefore, we
+	// check that the return code is S_OK instead of using SUCCEEDED() macro
+	for (int i = 1; i <= cameraNum; i++) {
+		if (S_OK != pClassEnum->Next (1, &pMoniker, &cFetched)) return E_FAIL;
+	}
+
+	// Bind Moniker to a filter object
+	hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**) &pSrc);
+	if (FAILED(hr)) return hr;
+
+	// Copy the found filter pointer to the output parameter.
+	// Do NOT Release() the reference, since it will still be used
+	// by the calling function.
+	*ppSrcFilter = pSrc;
+	return hr;
+}
+
+void FreeMediaType(AM_MEDIA_TYPE *pMediaType)  // free fields and structure
+{
+	if (!pMediaType) return;
+	FreeMediaTypeFields(pMediaType);
+	CoTaskMemFree((void *) pMediaType);
+}
+
+void FreeMediaTypeFields(AM_MEDIA_TYPE *pMediaType)  // free format and pUnk fields
+{
+	if (pMediaType->cbFormat != 0) {
+		CoTaskMemFree((PVOID) pMediaType->pbFormat);
+		pMediaType->cbFormat = 0;
+		pMediaType->pbFormat = NULL;
+	}
+	if (pMediaType->pUnk != NULL) {
+		// pUnk should be unused, but this is safest
+		pMediaType->pUnk->Release();
+		pMediaType->pUnk = NULL;
+	}
+}
+
+char* GetCameraName(int cameraNum)
+{
+	CComPtr <ICreateDevEnum> pDevEnum = NULL;
+	CComPtr <IEnumMoniker> pClassEnum = NULL;
+	CComPtr <IMoniker> pMoniker = NULL;
+	IPropertyBag* pPropBag;
+	VARIANT varName;
+	HRESULT hr;
+	ULONG cFetched;
+	char* result = NULL;
+
+	// Create the system device enumerator
+	hr = CoCreateInstance(
+		CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
+		IID_ICreateDevEnum, (void **) &pDevEnum);
+	if (FAILED(hr)) return NULL;
+
+	// Create an enumerator for the video capture devices
+	hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
+	if (FAILED(hr)) return NULL;
+
+	// If there are no enumerators for the requested type, then
+	// CreateClassEnumerator will succeed, but pClassEnum will be NULL.
+	if (pClassEnum == NULL) return NULL;
+
+	// Note that if the Next() call succeeds but there are no monikers,
+	// it will return S_FALSE, which is not a failure. Therefore, we check
+	// that the return code is S_OK instead of using the SUCCEEDED() macro.
+	for (int i = 0; i < cameraNum; i++) {
+		hr = pClassEnum->Next(1, &pMoniker, &cFetched);
+		if (hr != S_OK) return NULL;
+	}
+
+	hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)(&pPropBag));
+
+	// Find the description or friendly name
+	VariantInit(&varName);
+	hr = pPropBag->Read(L"Description", &varName, 0);
+	if (FAILED(hr)) {
+		hr = pPropBag->Read(L"FriendlyName", &varName, 0);
+	}
+
+	if (SUCCEEDED(hr)) {
+		int n = SysStringLen(varName.bstrVal);
+		result = new char[n + 1];
+		for (int i = 0; i < n; i++) {
+			result[i] = (char) varName.bstrVal[i];
+		}
+		result[n] = 0;
+		VariantClear(&varName);
+	}
+
+	pPropBag->Release();
+	return result;
+}
+
+HRESULT InitCamera(int num, int desiredWidth)
+{
+	HRESULT hr;
+
+	// get USB camera or other video capture device
+	hr = FindCamera(&theCamera.pCamera, num);
+	if (FAILED(hr)) return hr;
+
+	// create filter graph
+	hr = CoCreateInstance (
+		CLSID_FilterGraph, NULL, CLSCTX_INPROC,
+		IID_IGraphBuilder, (void **) &theCamera.pGraph);
+	if (FAILED(hr)) return hr;
+
+	// create capture graph builder
+	hr = CoCreateInstance (
+		CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
+		IID_ICaptureGraphBuilder2, (void **) &theCamera.pCapture);
+	if (FAILED(hr)) return hr;
+
+	// get media control interface
+	hr = theCamera.pGraph->QueryInterface(IID_IMediaControl,(LPVOID *) &theCamera.pMediaControl);
+	if (FAILED(hr)) return hr;
+
+	// create SampleGrabber
+	hr = CoCreateInstance(
+		CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
+		IID_IBaseFilter, (void**) &theCamera.ppf);
+	if (FAILED(hr)) return hr;
+
+	theCamera.ppf->QueryInterface(IID_ISampleGrabber, (void**) &theCamera.pGrabber);
+
+	// attach the filter graph to the capture graph
+	hr = theCamera.pCapture->SetFiltergraph(theCamera.pGraph);
+	if (FAILED(hr)) return hr;
+
+	hr = theCamera.pGraph->AddFilter(theCamera.ppf, L"Scratch Frame Grabber");
+	if (FAILED(hr)) return hr;
+
+	// add the camera
+	hr = theCamera.pGraph->AddFilter(theCamera.pCamera, L"Camera");
+	if (FAILED(hr)) return hr;
+
+	// set the desired framesize and image format
+	SetCameraWidth(theCamera.pCapture, theCamera.pCamera, desiredWidth);
+	SetOutputToRGB();
+
+	// connect the camera to the sample grabber, possibly inserting format conversion filters
+	hr = theCamera.pCapture->RenderStream(
+		&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
+		theCamera.pCamera, NULL, theCamera.ppf);
+
+	// record the actual camera frame dimensions
+	AM_MEDIA_TYPE mt;
+	hr = theCamera.pGrabber->GetConnectedMediaType(&mt);
+	if (FAILED(hr)) return hr;
+
+	theCamera.width  = ((VIDEOINFOHEADER*) mt.pbFormat)->bmiHeader.biWidth;
+	theCamera.height = ((VIDEOINFOHEADER*) mt.pbFormat)->bmiHeader.biHeight;
+	FreeMediaTypeFields(&mt);
+
+	hr = theCamera.pGrabber->SetOneShot(FALSE);
+	hr = theCamera.pGrabber->SetBufferSamples(FALSE);
+	hr = theCamera.pGrabber->SetCallback(&theCamera.mCB, 1);
+
+	// start getting video
+	hr = theCamera.pMediaControl->Run();
+	if (FAILED(hr)) return hr;
+
+	return S_OK;
+}
+
+void SetOutputToRGB() {
+	AM_MEDIA_TYPE mediaType;
+	mediaType.majortype = MEDIATYPE_Video;
+	mediaType.subtype = MEDIASUBTYPE_RGB24;
+	mediaType.formattype = GUID_NULL;
+	mediaType.pbFormat = NULL;
+	mediaType.cbFormat = 0;
+	theCamera.pGrabber->SetMediaType(&mediaType);
+}
+
+void SetCameraWidth(ICaptureGraphBuilder2 *pCaptureGraphBuilder, IBaseFilter *pSrcFilter, int desiredWidth)
+{
+	IAMStreamConfig *pCameraStream = NULL;
+	HRESULT hr;
+
+	// get the stream configuration interface
+	hr = pCaptureGraphBuilder->FindInterface(
+		&PIN_CATEGORY_CAPTURE, 0, pSrcFilter,
+		IID_IAMStreamConfig, (void**) &pCameraStream);
+	if (FAILED(hr)) return;
+
+	FindBestWidth(pCameraStream, desiredWidth);
+
+	SAFE_RELEASE(pCameraStream);
+}
+
+void FindBestWidth(IAMStreamConfig *pCameraStream, int desiredWidth)
+{
+	int iCount = 0, iSize = 0;
+	int bestWidth = 1000000;
+	AM_MEDIA_TYPE *selectedMediaType = NULL;
+	HRESULT hr;
+
+	// iterate through all possible camera frame formats to find the best frame size
+	hr = pCameraStream->GetNumberOfCapabilities(&iCount, &iSize);
+	for (int i = 0; i < iCount; i++) {
+		AM_MEDIA_TYPE *thisMediaType = NULL;
+		VIDEO_STREAM_CONFIG_CAPS scc;
+		hr = pCameraStream->GetStreamCaps(i, &thisMediaType, (BYTE*) &scc);
+		if (SUCCEEDED(hr)) {
+			if ((thisMediaType->majortype == MEDIATYPE_Video) &&
+				(thisMediaType->formattype == FORMAT_VideoInfo) &&
+				(thisMediaType->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
+				(thisMediaType->pbFormat != NULL))
+			{
+				VIDEOINFOHEADER* info = (VIDEOINFOHEADER*) thisMediaType->pbFormat;
+				int thisWidth = info->bmiHeader.biWidth;
+				if (abs(thisWidth - desiredWidth) < abs(bestWidth - desiredWidth)) {
+					// select the format closest to the desired width
+					if (!selectedMediaType) FreeMediaType(selectedMediaType);
+					selectedMediaType = thisMediaType;
+					bestWidth = thisWidth;
+				}
+			}
+
+			// Delete the media type unless it's the selected one
+			if (thisMediaType != selectedMediaType) FreeMediaType(thisMediaType);
+			thisMediaType = NULL;
+		}
+	}
+
+	// if we found a matching format, set the camera to that format
+	if (selectedMediaType) {
+		hr = pCameraStream->SetFormat(selectedMediaType);
+		FreeMediaType(selectedMediaType);
+	}
+}
+
+//////////////////////////////////////////////
+// Debugging function
+//////////////////////////////////////////////
+
+void Msg(TCHAR *szFormat, ...)
+{
+	TCHAR szBuffer[1024];	// Large buffer for long filenames or URLs
+	const size_t NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]);
+	const int LASTCHAR = NUMCHARS - 1;
+
+	// Format the input string
+	va_list pArgs;
+	va_start(pArgs, szFormat);
+
+	// Use a bounded buffer size to prevent buffer overruns. Limit count to
+	// character size minus one to allow for a NULL terminating character.
+	_vsntprintf(szBuffer, NUMCHARS - 1, szFormat, pArgs);
+	va_end(pArgs);
+
+	// Ensure that the formatted string is NULL-terminated
+	szBuffer[LASTCHAR] = TEXT('\0');
+
+	MessageBox(NULL, szBuffer, TEXT("Debug"), 0);
+}



More information about the Vm-dev mailing list