├── kkapturedll ├── .gitignore ├── stdafx.cpp ├── mhook-lib │ └── mhook.h ├── sound.h ├── disasm-lib │ ├── misc.h │ ├── cpu.c │ ├── disasm.c │ ├── misc.c │ └── cpu.h ├── kkapturedll.vcproj.RYG.fg.user ├── stdafx.h ├── timing.h ├── videocapturetimer.h ├── videoencoder.cpp ├── bmp_videoencoder.h ├── intercept.h ├── avi_videoencoder_vfw.h ├── mt_proxy_videoencoder.h ├── videoencoder.h ├── avi_videoencoder_dshow.h ├── audio_resample.h ├── main.h ├── video.h ├── util.h ├── bmp_videoencoder.cpp ├── kkapturedll.vcxproj.filters ├── mt_proxy_videoencoder.cpp ├── video_direct3d10.cpp ├── util.cpp └── intercept.cpp ├── kkapture ├── .gitignore ├── stdafx.cpp ├── stdafx.h ├── kkapture.vcxproj.filters ├── kkapture.vcproj.RYG.fg.user ├── resource.h ├── kkapture.rc ├── kkapture.vcproj └── kkapture.vcxproj ├── deps └── d3d8.lib ├── CONTRIBUTORS.txt ├── working_demos.txt ├── dshow_base ├── strmbase_d.lib ├── strmbase_r.lib ├── seekpt.h ├── ddmm.h ├── sysclock.h ├── dllsetup.h ├── amextra.h ├── fourcc.h ├── cache.h ├── mtype.h ├── reftime.h ├── msgthrd.h ├── cprop.h ├── pstream.h ├── schedule.h ├── dsschedule.h ├── pullpin.h ├── outputq.h ├── source.h ├── strmctl.h ├── vtrans.h ├── refclock.h ├── streams.h └── videoctl.h ├── .gitignore └── kkapture.sln /kkapturedll/.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | Release 3 | -------------------------------------------------------------------------------- /kkapture/.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | Release 3 | *.aps 4 | -------------------------------------------------------------------------------- /deps/d3d8.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rygorous/kkapture/HEAD/deps/d3d8.lib -------------------------------------------------------------------------------- /CONTRIBUTORS.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rygorous/kkapture/HEAD/CONTRIBUTORS.txt -------------------------------------------------------------------------------- /working_demos.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rygorous/kkapture/HEAD/working_demos.txt -------------------------------------------------------------------------------- /dshow_base/strmbase_d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rygorous/kkapture/HEAD/dshow_base/strmbase_d.lib -------------------------------------------------------------------------------- /dshow_base/strmbase_r.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rygorous/kkapture/HEAD/dshow_base/strmbase_r.lib -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ncb 2 | *.suo 3 | *.sdf 4 | *.opensdf 5 | *.vcproj.*.user 6 | *.vcxproj.user 7 | ipch/ 8 | Debug/ 9 | Release/ 10 | -------------------------------------------------------------------------------- /dshow_base/seekpt.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: SeekPT.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __seekpt_h__ 11 | #define __seekpt_h__ 12 | 13 | 14 | class CSeekingPassThru : public ISeekingPassThru, public CUnknown 15 | { 16 | public: 17 | static CUnknown *CreateInstance(LPUNKNOWN pUnk, HRESULT *phr); 18 | CSeekingPassThru(TCHAR *pName, LPUNKNOWN pUnk, HRESULT *phr); 19 | ~CSeekingPassThru(); 20 | 21 | DECLARE_IUNKNOWN; 22 | STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv); 23 | 24 | STDMETHODIMP Init(BOOL bSupportRendering, IPin *pPin); 25 | 26 | private: 27 | CPosPassThru *m_pPosPassThru; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /dshow_base/ddmm.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: DDMM.h 3 | // 4 | // Desc: DirectShow base classes - efines routines for using DirectDraw 5 | // on a multimonitor system. 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------ 9 | 10 | 11 | #ifdef __cplusplus 12 | extern "C" { /* Assume C declarations for C++ */ 13 | #endif /* __cplusplus */ 14 | 15 | // DDRAW.H might not include these 16 | #ifndef DDENUM_ATTACHEDSECONDARYDEVICES 17 | #define DDENUM_ATTACHEDSECONDARYDEVICES 0x00000001L 18 | #endif 19 | 20 | typedef HRESULT (*PDRAWCREATE)(IID *,LPDIRECTDRAW *,LPUNKNOWN); 21 | typedef HRESULT (*PDRAWENUM)(LPDDENUMCALLBACKA, LPVOID); 22 | 23 | IDirectDraw * DirectDrawCreateFromDevice(LPSTR, PDRAWCREATE, PDRAWENUM); 24 | IDirectDraw * DirectDrawCreateFromDeviceEx(LPSTR, PDRAWCREATE, LPDIRECTDRAWENUMERATEEXA); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif /* __cplusplus */ 29 | -------------------------------------------------------------------------------- /kkapture/stdafx.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" -------------------------------------------------------------------------------- /kkapturedll/stdafx.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" -------------------------------------------------------------------------------- /dshow_base/sysclock.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: SysClock.h 3 | // 4 | // Desc: DirectShow base classes - defines a system clock implementation of 5 | // IReferenceClock. 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------ 9 | 10 | 11 | #ifndef __SYSTEMCLOCK__ 12 | #define __SYSTEMCLOCK__ 13 | 14 | // 15 | // Base clock. Uses timeGetTime ONLY 16 | // Uses most of the code in the base reference clock. 17 | // Provides GetTime 18 | // 19 | 20 | class CSystemClock : public CBaseReferenceClock, public IAMClockAdjust, public IPersist 21 | { 22 | public: 23 | // We must be able to create an instance of ourselves 24 | static CUnknown * WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *phr); 25 | CSystemClock(TCHAR *pName, LPUNKNOWN pUnk, HRESULT *phr); 26 | 27 | DECLARE_IUNKNOWN 28 | 29 | STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,void ** ppv); 30 | 31 | // Yield up our class id so that we can be persisted 32 | // Implement required Ipersist method 33 | STDMETHODIMP GetClassID(CLSID *pClsID); 34 | 35 | // IAMClockAdjust methods 36 | STDMETHODIMP SetClockDelta(REFERENCE_TIME rtDelta); 37 | }; //CSystemClock 38 | 39 | #endif /* __SYSTEMCLOCK__ */ 40 | -------------------------------------------------------------------------------- /kkapture/stdafx.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #define _WIN32_WINNT 0x0400 26 | #include 27 | #include 28 | -------------------------------------------------------------------------------- /kkapture.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2010 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kkapturedll", "kkapturedll\kkapturedll.vcxproj", "{8212119F-DBE1-4DA5-80A9-67FDE9A4CBD3}" 4 | EndProject 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kkapture", "kkapture\kkapture.vcxproj", "{DBA35513-DE77-4FE9-8B71-C483946E76FF}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Win32 = Debug|Win32 10 | Release|Win32 = Release|Win32 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {8212119F-DBE1-4DA5-80A9-67FDE9A4CBD3}.Debug|Win32.ActiveCfg = Debug|Win32 14 | {8212119F-DBE1-4DA5-80A9-67FDE9A4CBD3}.Debug|Win32.Build.0 = Debug|Win32 15 | {8212119F-DBE1-4DA5-80A9-67FDE9A4CBD3}.Release|Win32.ActiveCfg = Release|Win32 16 | {8212119F-DBE1-4DA5-80A9-67FDE9A4CBD3}.Release|Win32.Build.0 = Release|Win32 17 | {DBA35513-DE77-4FE9-8B71-C483946E76FF}.Debug|Win32.ActiveCfg = Debug|Win32 18 | {DBA35513-DE77-4FE9-8B71-C483946E76FF}.Debug|Win32.Build.0 = Debug|Win32 19 | {DBA35513-DE77-4FE9-8B71-C483946E76FF}.Release|Win32.ActiveCfg = Release|Win32 20 | {DBA35513-DE77-4FE9-8B71-C483946E76FF}.Release|Win32.Build.0 = Release|Win32 21 | EndGlobalSection 22 | GlobalSection(SolutionProperties) = preSolution 23 | HideSolutionNode = FALSE 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /kkapture/kkapture.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | Source Files 19 | 20 | 21 | 22 | 23 | Source Files 24 | 25 | 26 | 27 | 28 | 29 | Resource Files 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /kkapturedll/mhook-lib/mhook.h: -------------------------------------------------------------------------------- 1 | //Copyright (c) 2007-2008, Marton Anka 2 | // 3 | //Permission is hereby granted, free of charge, to any person obtaining a 4 | //copy of this software and associated documentation files (the "Software"), 5 | //to deal in the Software without restriction, including without limitation 6 | //the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | //and/or sell copies of the Software, and to permit persons to whom the 8 | //Software is furnished to do so, subject to the following conditions: 9 | // 10 | //The above copyright notice and this permission notice shall be included 11 | //in all copies or substantial portions of the Software. 12 | // 13 | //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | //OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | //THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | //FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | //IN THE SOFTWARE. 20 | 21 | #ifdef _M_IX86 22 | #define _M_IX86_X64 23 | #elif defined _M_X64 24 | #define _M_IX86_X64 25 | #endif 26 | 27 | BOOL Mhook_SetHook(PVOID *ppSystemFunction, PVOID pHookFunction); 28 | BOOL Mhook_Unhook(PVOID *ppHookedFunction); 29 | 30 | #define MHOOKS_MAX_SUPPORTED_HOOKS 256 31 | 32 | -------------------------------------------------------------------------------- /kkapturedll/sound.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #ifndef __SOUND_H__ 24 | #define __SOUND_H__ 25 | 26 | // setup 27 | void initSound(); 28 | void doneSound(); 29 | 30 | // recording 31 | void nextFrameSound(); 32 | 33 | #endif -------------------------------------------------------------------------------- /kkapturedll/disasm-lib/misc.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002, Matt Conover (mconover@gmail.com) 2 | #ifndef MISC_H 3 | #define MISC_H 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 14 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 15 | 16 | // NOTE: start is inclusive, end is exclusive (as in start <= x < end) 17 | #define IS_IN_RANGE(x, s, e) \ 18 | ( \ 19 | ((ULONG_PTR)(x) == (ULONG_PTR)(s) && (ULONG_PTR)(x) == (ULONG_PTR)(e)) || \ 20 | ((ULONG_PTR)(x) >= (ULONG_PTR)(s) && (ULONG_PTR)(x) < (ULONG_PTR)(e)) \ 21 | ) 22 | 23 | #if _MSC_VER >= 1400 24 | #pragma warning(disable:4996) 25 | #endif 26 | 27 | #if defined(_WIN64) 28 | #define VALID_ADDRESS_MAX 0x7FFEFFFFFFFFFFFF // Win64 specific 29 | typedef unsigned __int64 ULONG_PTR, *PULONG_PTR; 30 | #else 31 | #define VALID_ADDRESS_MAX 0x7FFEFFFF // Win32 specific 32 | typedef unsigned long ULONG_PTR, *PULONG_PTR; 33 | #endif 34 | 35 | #ifndef DECLSPEC_ALIGN 36 | #if (_MSC_VER >= 1300) && !defined(MIDL_PASS) 37 | #define DECLSPEC_ALIGN(x) __declspec(align(x)) 38 | #else 39 | #define DECLSPEC_ALIGN(x) 40 | #endif 41 | #endif 42 | 43 | #define VALID_ADDRESS_MIN 0x10000 // Win32 specific 44 | #define IS_VALID_ADDRESS(a) IS_IN_RANGE(a, VALID_ADDRESS_MIN, VALID_ADDRESS_MAX+1) 45 | 46 | BOOL IsHexChar(BYTE ch); 47 | BYTE *HexToBinary(char *Input, DWORD InputLength, DWORD *OutputLength); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | #endif // MISC_H 53 | -------------------------------------------------------------------------------- /dshow_base/dllsetup.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: DllSetup.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | // To be self registering, OLE servers must 11 | // export functions named DllRegisterServer 12 | // and DllUnregisterServer. To allow use of 13 | // custom and default implementations the 14 | // defaults are named AMovieDllRegisterServer 15 | // and AMovieDllUnregisterServer. 16 | // 17 | // To the use the default implementation you 18 | // must provide stub functions. 19 | // 20 | // i.e. STDAPI DllRegisterServer() 21 | // { 22 | // return AMovieDllRegisterServer(); 23 | // } 24 | // 25 | // STDAPI DllUnregisterServer() 26 | // { 27 | // return AMovieDllUnregisterServer(); 28 | // } 29 | // 30 | // 31 | // AMovieDllRegisterServer calls IAMovieSetup.Register(), and 32 | // AMovieDllUnregisterServer calls IAMovieSetup.Unregister(). 33 | 34 | STDAPI AMovieDllRegisterServer2( BOOL ); 35 | STDAPI AMovieDllRegisterServer(); 36 | STDAPI AMovieDllUnregisterServer(); 37 | 38 | // helper functions 39 | STDAPI EliminateSubKey( HKEY, LPTSTR ); 40 | 41 | 42 | STDAPI 43 | AMovieSetupRegisterFilter2( const AMOVIESETUP_FILTER * const psetupdata 44 | , IFilterMapper2 * pIFM2 45 | , BOOL bRegister ); 46 | 47 | -------------------------------------------------------------------------------- /kkapturedll/kkapturedll.vcproj.RYG.fg.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /kkapture/kkapture.vcproj.RYG.fg.user: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 35 | 36 | 39 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /kkapturedll/stdafx.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #define _WIN32_WINNT 0x0501 26 | 27 | #include 28 | 29 | #include 30 | #include "mhook-lib/mhook.h" 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "main.h" 40 | #include "sound.h" 41 | #include "timing.h" 42 | #include "util.h" 43 | -------------------------------------------------------------------------------- /kkapturedll/timing.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | // setup 24 | void initTiming(bool interceptAnything); 25 | void doneTiming(); 26 | 27 | // update timing stuff 28 | void graphicsInitTiming(); 29 | void resetTiming(); 30 | void nextFrameTiming(); 31 | 32 | int getFrameTiming(); 33 | 34 | extern VOID (__stdcall *Real_Sleep)(DWORD dwMilliseconds); 35 | extern DWORD (__stdcall *Real_WaitForSingleObject)(HANDLE hHandle,DWORD dwMilliseconds); -------------------------------------------------------------------------------- /kkapture/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by kkapture.rc 4 | // 5 | #define IDD_MAINWIN 101 6 | #define IDC_DEMO 1001 7 | #define IDC_BDEMO 1002 8 | #define IDC_ARGUMENTS 1003 9 | #define IDC_TARGET 1004 10 | #define IDC_BTARGET 1005 11 | #define IDC_FRAMERATE 1008 12 | #define IDC_ENCODER 1010 13 | #define IDC_VIDEOCODEC 1014 14 | #define IDC_VCPICK 1015 15 | #define IDC_VCAPTURE 1016 16 | #define IDC_ACAPTURE 1017 17 | #define IDC_SKIPSILENCE 1018 18 | #define IDC_SLEEPLAST 1019 19 | #define IDC_NEWINTERCEPT 1020 20 | #define IDC_AUTOSKIP 1021 21 | #define IDC_FIRSTFRAMETIMEOUT 1022 22 | #define IDC_OTHERFRAMETIMEOUT 1023 23 | #define IDC_SOUNDSYS 1024 24 | #define IDC_POWERDOWN 1025 25 | #define IDC_ENCODERTHREAD 1026 26 | #define IDC_CAPTUREGDI 1027 27 | #define IDC_AUTOSKIP2 1028 28 | #define IDC_AUTOSKIP_TIMER 1028 29 | #define IDC_ENCODERTHREAD2 1029 30 | #define IDC_VIRTFRAMEBUF 1029 31 | 32 | // Next default values for new objects 33 | // 34 | #ifdef APSTUDIO_INVOKED 35 | #ifndef APSTUDIO_READONLY_SYMBOLS 36 | #define _APS_NEXT_RESOURCE_VALUE 103 37 | #define _APS_NEXT_COMMAND_VALUE 40001 38 | #define _APS_NEXT_CONTROL_VALUE 1022 39 | #define _APS_NEXT_SYMED_VALUE 101 40 | #endif 41 | #endif 42 | -------------------------------------------------------------------------------- /dshow_base/amextra.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: AMExtra.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __AMEXTRA__ 11 | #define __AMEXTRA__ 12 | 13 | // Simple rendered input pin 14 | // 15 | // NOTE if your filter queues stuff before rendering then it may not be 16 | // appropriate to use this class 17 | // 18 | // In that case queue the end of stream condition until the last sample 19 | // is actually rendered and flush the condition appropriately 20 | 21 | class CRenderedInputPin : public CBaseInputPin 22 | { 23 | public: 24 | 25 | CRenderedInputPin(TCHAR *pObjectName, 26 | CBaseFilter *pFilter, 27 | CCritSec *pLock, 28 | HRESULT *phr, 29 | LPCWSTR pName); 30 | #ifdef UNICODE 31 | CRenderedInputPin(CHAR *pObjectName, 32 | CBaseFilter *pFilter, 33 | CCritSec *pLock, 34 | HRESULT *phr, 35 | LPCWSTR pName); 36 | #endif 37 | 38 | // Override methods to track end of stream state 39 | STDMETHODIMP EndOfStream(); 40 | STDMETHODIMP EndFlush(); 41 | 42 | HRESULT Active(); 43 | HRESULT Run(REFERENCE_TIME tStart); 44 | 45 | protected: 46 | 47 | // Member variables to track state 48 | BOOL m_bAtEndOfStream; // Set by EndOfStream 49 | BOOL m_bCompleteNotified; // Set when we notify for EC_COMPLETE 50 | 51 | private: 52 | void DoCompleteHandling(); 53 | }; 54 | 55 | #endif // __AMEXTRA__ 56 | 57 | -------------------------------------------------------------------------------- /kkapturedll/videocapturetimer.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #ifndef __VIDEOCAPTURETIMER_H__ 24 | #define __VIDEOCAPTURETIMER_H__ 25 | 26 | // This is just used for debugging and optimization purposes. 27 | 28 | extern DWORD (__stdcall *Real_timeGetTime)(); 29 | 30 | class VideoCaptureTimer 31 | { 32 | DWORD Start; 33 | const char *Desc; 34 | 35 | public: 36 | VideoCaptureTimer(const char *desc) 37 | : Desc(desc) 38 | { 39 | Start = Real_timeGetTime(); 40 | } 41 | 42 | ~VideoCaptureTimer() 43 | { 44 | printLog("video: %s took %d ms\n",Desc,Real_timeGetTime() - Start); 45 | } 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /kkapturedll/videoencoder.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" 24 | #include "videoencoder.h" 25 | 26 | VideoEncoder::~VideoEncoder() 27 | { 28 | } 29 | 30 | // --- 31 | 32 | DummyVideoEncoder::DummyVideoEncoder() 33 | { 34 | } 35 | 36 | DummyVideoEncoder::~DummyVideoEncoder() 37 | { 38 | } 39 | 40 | void DummyVideoEncoder::SetSize(int xRes,int yRes) 41 | { 42 | } 43 | 44 | void DummyVideoEncoder::WriteFrame(const unsigned char *buffer) 45 | { 46 | } 47 | 48 | void DummyVideoEncoder::SetAudioFormat(const tWAVEFORMATEX *fmt) 49 | { 50 | } 51 | 52 | tWAVEFORMATEX *DummyVideoEncoder::GetAudioFormat() 53 | { 54 | return 0; 55 | } 56 | 57 | void DummyVideoEncoder::WriteAudioFrame(const void *buffer,int samples) 58 | { 59 | } -------------------------------------------------------------------------------- /kkapturedll/bmp_videoencoder.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifndef __BMP_VIDEOENCODER_H__ 26 | #define __BMP_VIDEOENCODER_H__ 27 | 28 | #include "videoencoder.h" 29 | 30 | class BMPVideoEncoder : public VideoEncoder 31 | { 32 | struct Internal; 33 | 34 | char prefix[384]; 35 | int xRes,yRes; 36 | int frame; 37 | Internal *intn; 38 | 39 | public: 40 | BMPVideoEncoder(const char *fileName); 41 | virtual ~BMPVideoEncoder(); 42 | 43 | virtual void SetSize(int xRes,int yRes); 44 | virtual void WriteFrame(const unsigned char *buffer); 45 | 46 | virtual void SetAudioFormat(const tWAVEFORMATEX *fmt); 47 | virtual tWAVEFORMATEX *GetAudioFormat(); 48 | virtual void WriteAudioFrame(const void *buffer,int samples); 49 | }; 50 | 51 | #endif -------------------------------------------------------------------------------- /kkapturedll/intercept.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #ifndef __INTERCEPT_H__ 24 | #define __INTERCEPT_H__ 25 | 26 | #ifdef _USRDLL 27 | #define DLLEXPORT __declspec(dllexport) 28 | #else 29 | #define DLLEXPORT __declspec(dllimport) 30 | #endif 31 | 32 | enum ErrorCodes 33 | { 34 | ERR_OK = 0, 35 | ERR_INSTRUMENTATION_FAILED, 36 | ERR_COULDNT_EXECUTE 37 | }; 38 | 39 | extern "C" DLLEXPORT int CreateInstrumentedProcessA(LPCSTR appName,LPSTR cmdLine, 40 | LPSECURITY_ATTRIBUTES processAttr,LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags, 41 | LPVOID env,LPCSTR currentDir,LPSTARTUPINFO startupInfo,LPPROCESS_INFORMATION pi); 42 | 43 | extern "C" DLLEXPORT int CreateInstrumentedProcessW(LPCWSTR appName,LPWSTR cmdLine, 44 | LPSECURITY_ATTRIBUTES processAttr,LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags, 45 | LPVOID env,LPCWSTR currentDir,LPSTARTUPINFOW startupInfo,LPPROCESS_INFORMATION pi); 46 | 47 | void initProcessIntercept(); 48 | 49 | #endif -------------------------------------------------------------------------------- /kkapturedll/avi_videoencoder_vfw.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifndef __AVI_VIDEOENCODER_VFW_H__ 26 | #define __AVI_VIDEOENCODER_VFW_H__ 27 | 28 | #include "videoencoder.h" 29 | 30 | class AVIVideoEncoderVFW : public VideoEncoder 31 | { 32 | struct Internal; 33 | 34 | int xRes,yRes; 35 | int frame; 36 | int audioSample,audioBytesSample; 37 | int fpsNum,fpsDenom; 38 | Internal *d; 39 | 40 | void Init(); 41 | void Cleanup(); 42 | void StartEncode(); 43 | void StartAudioEncode(); 44 | 45 | public: 46 | AVIVideoEncoderVFW(const char *name,int fpsNum,int fpsDenom,unsigned long codec,unsigned int quality); 47 | virtual ~AVIVideoEncoderVFW(); 48 | 49 | virtual void SetSize(int xRes,int yRes); 50 | virtual void WriteFrame(const unsigned char *buffer); 51 | 52 | virtual void SetAudioFormat(const tWAVEFORMATEX *fmt); 53 | virtual tWAVEFORMATEX *GetAudioFormat(); 54 | virtual void WriteAudioFrame(const void *buffer,int samples); 55 | }; 56 | 57 | #endif -------------------------------------------------------------------------------- /kkapturedll/mt_proxy_videoencoder.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifndef __MT_PROXY_VIDEOENCODER_H__ 26 | #define __MT_PROXY_VIDEOENCODER_H__ 27 | 28 | #include "videoencoder.h" 29 | 30 | // Acts as a proxy to pass data to a real encoder running in another thread 31 | // (to increase parallelism between encoding and capturing) 32 | 33 | class MTProxyVideoEncoder : public VideoEncoder 34 | { 35 | struct Internal; 36 | Internal *d; 37 | 38 | static unsigned __stdcall QueueRunner(void *para); 39 | 40 | public: 41 | // Transfers ownership of the video encoder to this object! 42 | MTProxyVideoEncoder(VideoEncoder *actual); 43 | virtual ~MTProxyVideoEncoder(); 44 | 45 | virtual void SetSize(int xRes,int yRes); 46 | virtual void WriteFrame(const unsigned char *buffer); 47 | 48 | virtual void SetAudioFormat(const tWAVEFORMATEX *fmt); 49 | virtual tWAVEFORMATEX *GetAudioFormat(); 50 | virtual void WriteAudioFrame(const void *buffer,int samples); 51 | }; 52 | 53 | #endif -------------------------------------------------------------------------------- /kkapturedll/videoencoder.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifndef __VIDEOENCODER_H__ 26 | #define __VIDEOENCODER_H__ 27 | 28 | class VideoEncoder 29 | { 30 | public: 31 | virtual ~VideoEncoder(); 32 | 33 | virtual void SetSize(int xRes,int yRes) = 0; 34 | virtual void WriteFrame(const unsigned char *buffer) = 0; 35 | 36 | virtual void SetAudioFormat(const struct tWAVEFORMATEX *fmt) = 0; 37 | virtual tWAVEFORMATEX *GetAudioFormat() = 0; 38 | virtual void WriteAudioFrame(const void *buffer,int samples) = 0; 39 | }; 40 | 41 | class DummyVideoEncoder : public VideoEncoder 42 | { 43 | public: 44 | DummyVideoEncoder(); 45 | virtual ~DummyVideoEncoder(); 46 | 47 | virtual void SetSize(int xRes,int yRes); 48 | virtual void WriteFrame(const unsigned char *buffer); 49 | 50 | virtual void SetAudioFormat(const struct tWAVEFORMATEX *fmt); 51 | virtual tWAVEFORMATEX *GetAudioFormat(); 52 | virtual void WriteAudioFrame(const void *buffer,int samples); 53 | }; 54 | 55 | #endif -------------------------------------------------------------------------------- /kkapturedll/avi_videoencoder_dshow.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifndef __AVI_VIDEOENCODER_DSHOW_H__ 26 | #define __AVI_VIDEOENCODER_DSHOW_H__ 27 | 28 | #include "videoencoder.h" 29 | 30 | #if USE_DSHOW_AVI_WRITER 31 | 32 | class AVIVideoEncoderDShow : public VideoEncoder 33 | { 34 | struct Internal; 35 | 36 | int xRes,yRes; 37 | int frame; 38 | int audioSample,audioBytesSample; 39 | int fpsNum,fpsDenom; 40 | Internal *d; 41 | 42 | void Cleanup(); 43 | void StartEncode(); 44 | void StartAudioEncode(const tWAVEFORMATEX *fmt); 45 | 46 | public: 47 | AVIVideoEncoderDShow(const char *name,int fpsNum,int fpsDenom,unsigned long codec,unsigned quality); 48 | virtual ~AVIVideoEncoderDShow(); 49 | 50 | virtual void SetSize(int xRes,int yRes); 51 | virtual void WriteFrame(const unsigned char *buffer); 52 | 53 | virtual void SetAudioFormat(const tWAVEFORMATEX *fmt); 54 | virtual tWAVEFORMATEX *GetAudioFormat(); 55 | virtual void WriteAudioFrame(const void *buffer,int samples); 56 | }; 57 | 58 | #endif 59 | 60 | #endif -------------------------------------------------------------------------------- /dshow_base/fourcc.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: FourCC.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | // FOURCCMap 11 | // 12 | // provides a mapping between old-style multimedia format DWORDs 13 | // and new-style GUIDs. 14 | // 15 | // A range of 4 billion GUIDs has been allocated to ensure that this 16 | // mapping can be done straightforwardly one-to-one in both directions. 17 | // 18 | // January 95 19 | 20 | 21 | #ifndef __FOURCC__ 22 | #define __FOURCC__ 23 | 24 | 25 | // Multimedia format types are marked with DWORDs built from four 8-bit 26 | // chars and known as FOURCCs. New multimedia AM_MEDIA_TYPE definitions include 27 | // a subtype GUID. In order to simplify the mapping, GUIDs in the range: 28 | // XXXXXXXX-0000-0010-8000-00AA00389B71 29 | // are reserved for FOURCCs. 30 | 31 | class FOURCCMap : public GUID 32 | { 33 | 34 | public: 35 | FOURCCMap(); 36 | FOURCCMap(DWORD Fourcc); 37 | FOURCCMap(const GUID *); 38 | 39 | 40 | DWORD GetFOURCC(void); 41 | void SetFOURCC(DWORD fourcc); 42 | void SetFOURCC(const GUID *); 43 | 44 | private: 45 | void InitGUID(); 46 | }; 47 | 48 | #define GUID_Data2 0 49 | #define GUID_Data3 0x10 50 | #define GUID_Data4_1 0xaa000080 51 | #define GUID_Data4_2 0x719b3800 52 | 53 | inline void 54 | FOURCCMap::InitGUID() { 55 | Data2 = GUID_Data2; 56 | Data3 = GUID_Data3; 57 | ((DWORD *)Data4)[0] = GUID_Data4_1; 58 | ((DWORD *)Data4)[1] = GUID_Data4_2; 59 | } 60 | 61 | inline 62 | FOURCCMap::FOURCCMap() { 63 | InitGUID(); 64 | SetFOURCC( DWORD(0)); 65 | } 66 | 67 | inline 68 | FOURCCMap::FOURCCMap(DWORD fourcc) 69 | { 70 | InitGUID(); 71 | SetFOURCC(fourcc); 72 | } 73 | 74 | inline 75 | FOURCCMap::FOURCCMap(const GUID * pGuid) 76 | { 77 | InitGUID(); 78 | SetFOURCC(pGuid); 79 | } 80 | 81 | inline void 82 | FOURCCMap::SetFOURCC(const GUID * pGuid) 83 | { 84 | FOURCCMap * p = (FOURCCMap*) pGuid; 85 | SetFOURCC(p->GetFOURCC()); 86 | } 87 | 88 | inline void 89 | FOURCCMap::SetFOURCC(DWORD fourcc) 90 | { 91 | Data1 = fourcc; 92 | } 93 | 94 | inline DWORD 95 | FOURCCMap::GetFOURCC(void) 96 | { 97 | return Data1; 98 | } 99 | 100 | #endif /* __FOURCC__ */ 101 | 102 | -------------------------------------------------------------------------------- /kkapturedll/audio_resample.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | // note this is by no means a general audio resampler, it's only meant 24 | // for the purposes of kkapture... so no really good resampling routines, 25 | // only cubic spline (catmull-rom) interpolation 26 | 27 | #ifndef __AUDIO_RESAMPLE_H__ 28 | #define __AUDIO_RESAMPLE_H__ 29 | 30 | struct tWAVEFORMATEX; 31 | 32 | class AudioResampler 33 | { 34 | bool Initialized; 35 | int InBits; // currently we only have 8/16 bit integer or 32bit float 36 | int InChans; 37 | int InRate,OutRate; 38 | bool Identical; 39 | 40 | int OutChans; 41 | 42 | int tFrac; 43 | int dStep; 44 | float invScale; 45 | int InitSamples; 46 | float ChannelBuf[2][4]; 47 | 48 | template int ResampleChan(T *in,short *out,int nInSamples,float *chanBuf,int stride,bool add,float amp); 49 | template int ResampleInit(T *in,int nInSamples,float *chanBuf); 50 | template int ResampleBlock(T *in,short *out,int nInSamples); 51 | 52 | public: 53 | AudioResampler(); 54 | ~AudioResampler(); 55 | 56 | bool Init(const tWAVEFORMATEX *srcFormat,const tWAVEFORMATEX *dstFormat); 57 | int MaxOutputSamples(int nInSamples) const; 58 | int Resample(const void *src,short *out,int nInSamples,bool last); 59 | }; 60 | 61 | #endif -------------------------------------------------------------------------------- /kkapturedll/main.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #ifndef __MAIN_H__ 24 | #define __MAIN_H__ 25 | 26 | class VideoEncoder; 27 | 28 | // configuration options 29 | 30 | // writing AVIs using DShow (please read top of avi_videoencoder_dshow.cpp) 31 | #define USE_DSHOW_AVI_WRITER 1 32 | 33 | // global variables 34 | extern VideoEncoder *encoder; 35 | extern int frameRateScaled,frameRateDenom; 36 | extern bool exitNextFrame; 37 | extern void *hModule; 38 | 39 | // parameter block submitted by main app 40 | static const int PARAMVERSION = 5; 41 | 42 | enum EncoderType 43 | { 44 | DummyEncoder, 45 | BMPEncoder, 46 | AVIEncoderVFW, 47 | AVIEncoderDShow, 48 | }; 49 | 50 | struct ParameterBlock 51 | { 52 | unsigned VersionTag; 53 | TCHAR FileName[_MAX_PATH]; 54 | int FrameRateNum,FrameRateDenom; 55 | EncoderType Encoder; 56 | DWORD VideoCodec; 57 | DWORD VideoQuality; 58 | 59 | BOOL CaptureVideo; 60 | BOOL CaptureAudio; 61 | 62 | DWORD SoundMaxSkip; // in milliseconds 63 | BOOL MakeSleepsLastOneFrame; 64 | DWORD SleepTimeout; 65 | BOOL NewIntercept; 66 | BOOL SoundsysInterception; 67 | 68 | BOOL EnableAutoSkip; 69 | DWORD FirstFrameTimeout; 70 | DWORD FrameTimeout; 71 | 72 | BOOL IsDebugged; 73 | BOOL PowerDownAfterwards; 74 | BOOL UseEncoderThread; 75 | BOOL EnableGDICapture; 76 | BOOL FrequentTimerCheck; 77 | BOOL VirtualFramebuffer; 78 | 79 | DWORD CodecDataSize; 80 | UCHAR CodecSpecificData[16384]; 81 | }; 82 | 83 | extern ParameterBlock params; 84 | 85 | #endif -------------------------------------------------------------------------------- /kkapturedll/disasm-lib/cpu.c: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003, Matt Conover (mconover@gmail.com) 2 | #include "cpu.h" 3 | #include 4 | 5 | // NOTE: this assumes default scenarios (i.e., we assume CS/DS/ES/SS and flat 6 | // and all have a base of 0 and limit of 0xffffffff, we don't try to verify 7 | // that in the GDT) 8 | // 9 | // TODO: use inline assembly to get selector for segment 10 | // Segment = x86 segment register (SEG_ES = 0, SEG_CS = 1, ...) 11 | BYTE *GetAbsoluteAddressFromSegment(BYTE Segment, DWORD Offset) 12 | { 13 | switch (Segment) 14 | { 15 | // Windows uses a flat address space (except FS for x86 and GS for x64) 16 | case 0: // SEG_ES 17 | case 1: // SEG_CS 18 | case 2: // SEG_SS 19 | case 3: // SEG_DS 20 | return (BYTE *)(DWORD_PTR)Offset; 21 | case 4: // SEG_FS 22 | case 5: // SEG_GS 23 | return (BYTE *)(DWORD_PTR)Offset; 24 | // Note: we're really supposed to do this, but get_teb is not implemented 25 | // in this bastardized version of the disassembler. 26 | // return (BYTE *)get_teb() + Offset; 27 | default: 28 | assert(0); 29 | return (BYTE *)(DWORD_PTR)Offset; 30 | } 31 | } 32 | 33 | // This is an GDT/LDT selector (pGDT+Selector) 34 | BYTE *GetAbsoluteAddressFromSelector(WORD Selector, DWORD Offset) 35 | { 36 | DESCRIPTOR_ENTRY Entry; 37 | GATE_ENTRY *Gate; 38 | ULONG_PTR Base; 39 | 40 | assert(Selector < 0x10000); 41 | if (!GetThreadSelectorEntry(GetCurrentThread(), Selector, (LDT_ENTRY *)&Entry)) return NULL; 42 | if (!Entry.Present) return NULL; 43 | if (Entry.System) 44 | { 45 | Base = 0; 46 | #ifdef _WIN64 47 | Base |= (ULONG_PTR)Entry.HighOffset64 << 32; 48 | #endif 49 | Base |= Entry.BaseHi << 24; 50 | Base |= Entry.BaseMid << 16; 51 | Base |= Entry.BaseLow; 52 | } 53 | else 54 | { 55 | switch (Entry.Type) 56 | { 57 | case 1: // 16-bit TSS (available) 58 | case 2: // LDT 59 | case 3: // 16-bit TSS (busy) 60 | case 9: // 32-bit TSS (available) 61 | case 11: // 32-bit TSS (busy) 62 | Base = 0; 63 | #ifdef _WIN64 64 | Base |= (ULONG_PTR)Entry.HighOffset64 << 32; 65 | #endif 66 | Base |= Entry.BaseHi << 24; 67 | Base |= Entry.BaseMid << 16; 68 | Base |= Entry.BaseLow; 69 | break; 70 | 71 | case 4: // 16-bit call gate 72 | case 5: // task gate 73 | case 6: // 16-bit interrupt gate 74 | case 7: // 16-bit task gate 75 | case 12: // 32-bit call gate 76 | case 14: // 32-bit interrupt gate 77 | case 15: // 32-bit trap gate 78 | Gate = (GATE_ENTRY *)&Entry; 79 | #ifdef _WIN64 80 | Base = ((ULONG_PTR)Gate->HighOffset64 << 32) | (Gate->HighOffset << 16) | Gate->LowOffset; 81 | #else 82 | Base = (Gate->HighOffset << 16) | Gate->LowOffset; 83 | #endif 84 | assert(!Offset); Offset = 0; 85 | break; 86 | default: 87 | assert(0); 88 | return NULL; 89 | } 90 | } 91 | return (BYTE *)Base + Offset; 92 | } 93 | 94 | -------------------------------------------------------------------------------- /dshow_base/cache.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: Cache.h 3 | // 4 | // Desc: DirectShow base classes - efines a non-MFC generic cache class. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | /* This class implements a simple cache. A cache object is instantiated 11 | with the number of items it is to hold. An item is a pointer to an 12 | object derived from CBaseObject (helps reduce memory leaks). The cache 13 | can then have objects added to it and removed from it. The cache size 14 | is fixed at construction time and may therefore run out or be flooded. 15 | If it runs out it returns a NULL pointer, if it fills up it also returns 16 | a NULL pointer instead of a pointer to the object just inserted */ 17 | 18 | /* Making these classes inherit from CBaseObject does nothing for their 19 | functionality but it allows us to check there are no memory leaks */ 20 | 21 | /* WARNING Be very careful when using this class, what it lets you do is 22 | store and retrieve objects so that you can minimise object creation 23 | which in turns improves efficiency. However the object you store is 24 | exactly the same as the object you get back which means that it short 25 | circuits the constructor initialisation phase. This means any class 26 | variables the object has (eg pointers) are highly likely to be invalid. 27 | Therefore ensure you reinitialise the object before using it again */ 28 | 29 | 30 | #ifndef __CACHE__ 31 | #define __CACHE__ 32 | 33 | 34 | class CCache : CBaseObject { 35 | 36 | /* Make copy constructor and assignment operator inaccessible */ 37 | 38 | CCache(const CCache &refCache); 39 | CCache &operator=(const CCache &refCache); 40 | 41 | private: 42 | 43 | /* These are initialised in the constructor. The first variable points to 44 | an array of pointers, each of which points to a CBaseObject derived 45 | object. The m_iCacheSize is the static fixed size for the cache and the 46 | m_iUsed defines the number of places filled with objects at any time. 47 | We fill the array of pointers from the start (ie m_ppObjects[0] first) 48 | and then only add and remove objects from the end position, so in this 49 | respect the array of object pointers should be treated as a stack */ 50 | 51 | CBaseObject **m_ppObjects; 52 | const INT m_iCacheSize; 53 | INT m_iUsed; 54 | 55 | public: 56 | 57 | CCache(TCHAR *pName,INT iItems); 58 | virtual ~CCache(); 59 | 60 | /* Add an item to the cache */ 61 | CBaseObject *AddToCache(CBaseObject *pObject); 62 | 63 | /* Remove an item from the cache */ 64 | CBaseObject *RemoveFromCache(); 65 | 66 | /* Delete all the objects held in the cache */ 67 | void RemoveAll(void); 68 | 69 | /* Return the cache size which is set during construction */ 70 | INT GetCacheSize(void) const {return m_iCacheSize;}; 71 | }; 72 | 73 | #endif /* __CACHE__ */ 74 | 75 | -------------------------------------------------------------------------------- /dshow_base/mtype.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: MtType.h 3 | // 4 | // Desc: DirectShow base classes - defines a class that holds and manages 5 | // media type information. 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------ 9 | 10 | 11 | #ifndef __MTYPE__ 12 | #define __MTYPE__ 13 | 14 | /* Helper class that derived pin objects can use to compare media 15 | types etc. Has same data members as the struct AM_MEDIA_TYPE defined 16 | in the streams IDL file, but also has (non-virtual) functions */ 17 | 18 | class CMediaType : public _AMMediaType { 19 | 20 | public: 21 | 22 | ~CMediaType(); 23 | CMediaType(); 24 | CMediaType(const GUID * majortype); 25 | CMediaType(const AM_MEDIA_TYPE&, HRESULT* phr = NULL); 26 | CMediaType(const CMediaType&, HRESULT* phr = NULL); 27 | 28 | CMediaType& operator=(const CMediaType&); 29 | CMediaType& operator=(const AM_MEDIA_TYPE&); 30 | 31 | BOOL operator == (const CMediaType&) const; 32 | BOOL operator != (const CMediaType&) const; 33 | 34 | HRESULT Set(const CMediaType& rt); 35 | HRESULT Set(const AM_MEDIA_TYPE& rt); 36 | 37 | BOOL IsValid() const; 38 | 39 | const GUID *Type() const { return &majortype;} ; 40 | void SetType(const GUID *); 41 | const GUID *Subtype() const { return &subtype;} ; 42 | void SetSubtype(const GUID *); 43 | 44 | BOOL IsFixedSize() const {return bFixedSizeSamples; }; 45 | BOOL IsTemporalCompressed() const {return bTemporalCompression; }; 46 | ULONG GetSampleSize() const; 47 | 48 | void SetSampleSize(ULONG sz); 49 | void SetVariableSize(); 50 | void SetTemporalCompression(BOOL bCompressed); 51 | 52 | // read/write pointer to format - can't change length without 53 | // calling SetFormat, AllocFormatBuffer or ReallocFormatBuffer 54 | 55 | BYTE* Format() const {return pbFormat; }; 56 | ULONG FormatLength() const { return cbFormat; }; 57 | 58 | void SetFormatType(const GUID *); 59 | const GUID *FormatType() const {return &formattype; }; 60 | BOOL SetFormat(BYTE *pFormat, ULONG length); 61 | void ResetFormatBuffer(); 62 | BYTE* AllocFormatBuffer(ULONG length); 63 | BYTE* ReallocFormatBuffer(ULONG length); 64 | 65 | void InitMediaType(); 66 | 67 | BOOL MatchesPartial(const CMediaType* ppartial) const; 68 | BOOL IsPartiallySpecified(void) const; 69 | }; 70 | 71 | 72 | /* General purpose functions to copy and delete a task allocated AM_MEDIA_TYPE 73 | structure which is useful when using the IEnumMediaFormats interface as 74 | the implementation allocates the structures which you must later delete */ 75 | 76 | void WINAPI DeleteMediaType(AM_MEDIA_TYPE *pmt); 77 | AM_MEDIA_TYPE * WINAPI CreateMediaType(AM_MEDIA_TYPE const *pSrc); 78 | HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE *pmtTarget, const AM_MEDIA_TYPE *pmtSource); 79 | void WINAPI FreeMediaType(AM_MEDIA_TYPE& mt); 80 | 81 | // Initialize a media type from a WAVEFORMATEX 82 | 83 | STDAPI CreateAudioMediaType( 84 | const WAVEFORMATEX *pwfx, 85 | AM_MEDIA_TYPE *pmt, 86 | BOOL bSetFormat); 87 | 88 | #endif /* __MTYPE__ */ 89 | 90 | -------------------------------------------------------------------------------- /dshow_base/reftime.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: RefTime.h 3 | // 4 | // Desc: DirectShow base classes - defines CRefTime, a class that manages 5 | // reference times. 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------ 9 | 10 | 11 | // 12 | // CRefTime 13 | // 14 | // Manage reference times. 15 | // Shares same data layout as REFERENCE_TIME, but adds some (nonvirtual) 16 | // functions providing simple comparison, conversion and arithmetic. 17 | // 18 | // A reference time (at the moment) is a unit of seconds represented in 19 | // 100ns units as is used in the Win32 FILETIME structure. BUT the time 20 | // a REFERENCE_TIME represents is NOT the time elapsed since 1/1/1601 it 21 | // will either be stream time or reference time depending upon context 22 | // 23 | // This class provides simple arithmetic operations on reference times 24 | // 25 | // keep non-virtual otherwise the data layout will not be the same as 26 | // REFERENCE_TIME 27 | 28 | 29 | // ----- 30 | // note that you are safe to cast a CRefTime* to a REFERENCE_TIME*, but 31 | // you will need to do so explicitly 32 | // ----- 33 | 34 | 35 | #ifndef __REFTIME__ 36 | #define __REFTIME__ 37 | 38 | 39 | const LONGLONG MILLISECONDS = (1000); // 10 ^ 3 40 | const LONGLONG NANOSECONDS = (1000000000); // 10 ^ 9 41 | const LONGLONG UNITS = (NANOSECONDS / 100); // 10 ^ 7 42 | 43 | /* Unfortunately an inline function here generates a call to __allmul 44 | - even for constants! 45 | */ 46 | #define MILLISECONDS_TO_100NS_UNITS(lMs) \ 47 | Int32x32To64((lMs), (UNITS / MILLISECONDS)) 48 | 49 | class CRefTime 50 | { 51 | public: 52 | 53 | // *MUST* be the only data member so that this class is exactly 54 | // equivalent to a REFERENCE_TIME. 55 | // Also, must be *no virtual functions* 56 | 57 | REFERENCE_TIME m_time; 58 | 59 | inline CRefTime() 60 | { 61 | // default to 0 time 62 | m_time = 0; 63 | }; 64 | 65 | inline CRefTime(LONG msecs) 66 | { 67 | m_time = MILLISECONDS_TO_100NS_UNITS(msecs); 68 | }; 69 | 70 | inline CRefTime(REFERENCE_TIME rt) 71 | { 72 | m_time = rt; 73 | }; 74 | 75 | inline operator REFERENCE_TIME() const 76 | { 77 | return m_time; 78 | }; 79 | 80 | inline CRefTime& operator=(const CRefTime& rt) 81 | { 82 | m_time = rt.m_time; 83 | return *this; 84 | }; 85 | 86 | inline CRefTime& operator=(const LONGLONG ll) 87 | { 88 | m_time = ll; 89 | return *this; 90 | }; 91 | 92 | inline CRefTime& operator+=(const CRefTime& rt) 93 | { 94 | return (*this = *this + rt); 95 | }; 96 | 97 | inline CRefTime& operator-=(const CRefTime& rt) 98 | { 99 | return (*this = *this - rt); 100 | }; 101 | 102 | inline LONG Millisecs(void) 103 | { 104 | return (LONG)(m_time / (UNITS / MILLISECONDS)); 105 | }; 106 | 107 | inline LONGLONG GetUnits(void) 108 | { 109 | return m_time; 110 | }; 111 | }; 112 | 113 | const LONGLONG TimeZero = 0; 114 | 115 | #endif /* __REFTIME__ */ 116 | 117 | -------------------------------------------------------------------------------- /kkapturedll/video.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #ifndef __VIDEO_H__ 24 | #define __VIDEO_H__ 25 | 26 | class VideoEncoder; 27 | 28 | class VideoCaptureDataLock 29 | { 30 | public: 31 | VideoCaptureDataLock(); 32 | ~VideoCaptureDataLock(); 33 | }; 34 | 35 | // encoder 36 | VideoEncoder *createVideoEncoder(const char *filename); 37 | void videoStartNextPart(bool autoSize=true); 38 | 39 | void videoNeedEncoder(); 40 | 41 | // setup 42 | void initVideo(); 43 | void doneVideo(); 44 | 45 | // init functions 46 | void initVideo_OpenGL(); 47 | void initVideo_Direct3D8(); 48 | void initVideo_Direct3D9(); 49 | void initVideo_Direct3D10(); 50 | void initVideo_DirectDraw(); 51 | void initVideo_GDI(); 52 | 53 | // helpers 54 | void setCaptureResolution(int width,int height); 55 | void nextFrame(); 56 | void skipFrame(); 57 | 58 | // capture helpers 59 | void blitAndFlipBGRAToCaptureData(unsigned char *source,unsigned pitch); 60 | void blitAndFlipRGBAToCaptureData(unsigned char *source,unsigned pitch); 61 | 62 | extern int captureWidth, captureHeight; 63 | extern unsigned char *captureData; 64 | 65 | // generic blitter class. always outputs 24bit pixels, BGR byte order. 66 | class GenericBlitter 67 | { 68 | unsigned char RTab[256],GTab[256],BTab[256]; 69 | int RShift,GShift,BShift; 70 | int RMask,GMask,BMask; 71 | int BytesPerPixel; 72 | bool Paletted; 73 | 74 | // the inner loops for different bytes per source pixel 75 | void Blit1ByteSrc(unsigned char *src,unsigned char *dst,int count); 76 | void Blit2ByteSrc(unsigned char *src,unsigned char *dst,int count); 77 | void Blit3ByteSrc(unsigned char *src,unsigned char *dst,int count); 78 | void Blit4ByteSrc(unsigned char *src,unsigned char *dst,int count); 79 | 80 | public: 81 | GenericBlitter(); 82 | 83 | void SetInvalidFormat(); 84 | void SetRGBFormat(int bits,unsigned redMask,unsigned greenMask,unsigned blueMask); 85 | void SetPalettedFormat(int bits); 86 | void SetPalette(const struct tagPALETTEENTRY *palette,int nEntries); 87 | 88 | bool IsPaletted() const; 89 | int GetBytesPerPixel() const; 90 | 91 | void BlitOneLine(unsigned char *src,unsigned char *dst,int nPixels); 92 | }; 93 | 94 | #endif -------------------------------------------------------------------------------- /dshow_base/msgthrd.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: MsgThrd.h 3 | // 4 | // Desc: DirectShow base classes - provides support for a worker thread 5 | // class to which one can asynchronously post messages. 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------ 9 | 10 | 11 | // Message class - really just a structure. 12 | // 13 | class CMsg { 14 | public: 15 | UINT uMsg; 16 | DWORD dwFlags; 17 | LPVOID lpParam; 18 | CAMEvent *pEvent; 19 | 20 | CMsg(UINT u, DWORD dw, LPVOID lp, CAMEvent *pEvnt) 21 | : uMsg(u), dwFlags(dw), lpParam(lp), pEvent(pEvnt) {} 22 | 23 | CMsg() 24 | : uMsg(0), dwFlags(0L), lpParam(NULL), pEvent(NULL) {} 25 | }; 26 | 27 | // This is the actual thread class. It exports all the usual thread control 28 | // functions. The created thread is different from a normal WIN32 thread in 29 | // that it is prompted to perform particaular tasks by responding to messages 30 | // posted to its message queue. 31 | // 32 | class AM_NOVTABLE CMsgThread { 33 | private: 34 | static DWORD WINAPI DefaultThreadProc(LPVOID lpParam); 35 | DWORD m_ThreadId; 36 | HANDLE m_hThread; 37 | 38 | protected: 39 | 40 | // if you want to override GetThreadMsg to block on other things 41 | // as well as this queue, you need access to this 42 | CGenericList m_ThreadQueue; 43 | CCritSec m_Lock; 44 | HANDLE m_hSem; 45 | LONG m_lWaiting; 46 | 47 | public: 48 | CMsgThread() 49 | : m_ThreadId(0), 50 | m_hThread(NULL), 51 | m_lWaiting(0), 52 | m_hSem(NULL), 53 | // make a list with a cache of 5 items 54 | m_ThreadQueue(NAME("MsgThread list"), 5) 55 | { 56 | } 57 | 58 | ~CMsgThread(); 59 | // override this if you want to block on other things as well 60 | // as the message loop 61 | void virtual GetThreadMsg(CMsg *msg); 62 | 63 | // override this if you want to do something on thread startup 64 | virtual void OnThreadInit() { 65 | }; 66 | 67 | BOOL CreateThread(); 68 | 69 | BOOL WaitForThreadExit(LPDWORD lpdwExitCode) { 70 | if (m_hThread != NULL) { 71 | WaitForSingleObject(m_hThread, INFINITE); 72 | return GetExitCodeThread(m_hThread, lpdwExitCode); 73 | } 74 | return FALSE; 75 | } 76 | 77 | DWORD ResumeThread() { 78 | return ::ResumeThread(m_hThread); 79 | } 80 | 81 | DWORD SuspendThread() { 82 | return ::SuspendThread(m_hThread); 83 | } 84 | 85 | int GetThreadPriority() { 86 | return ::GetThreadPriority(m_hThread); 87 | } 88 | 89 | BOOL SetThreadPriority(int nPriority) { 90 | return ::SetThreadPriority(m_hThread, nPriority); 91 | } 92 | 93 | HANDLE GetThreadHandle() { 94 | return m_hThread; 95 | } 96 | 97 | DWORD GetThreadId() { 98 | return m_ThreadId; 99 | } 100 | 101 | 102 | void PutThreadMsg(UINT uMsg, DWORD dwMsgFlags, 103 | LPVOID lpMsgParam, CAMEvent *pEvent = NULL) { 104 | CAutoLock lck(&m_Lock); 105 | CMsg* pMsg = new CMsg(uMsg, dwMsgFlags, lpMsgParam, pEvent); 106 | m_ThreadQueue.AddTail(pMsg); 107 | if (m_lWaiting != 0) { 108 | ReleaseSemaphore(m_hSem, m_lWaiting, 0); 109 | m_lWaiting = 0; 110 | } 111 | } 112 | 113 | // This is the function prototype of the function that the client 114 | // supplies. It is always called on the created thread, never on 115 | // the creator thread. 116 | // 117 | virtual LRESULT ThreadMessageProc( 118 | UINT uMsg, DWORD dwFlags, LPVOID lpParam, CAMEvent *pEvent) = 0; 119 | }; 120 | 121 | -------------------------------------------------------------------------------- /kkapturedll/util.h: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #ifndef __UTIL_H__ 24 | #define __UTIL_H__ 25 | 26 | // ---- logging functions 27 | void initLog(); 28 | void closeLog(); 29 | void printLog(const char *format,...); 30 | void printLogHex(void *buffer,int size); 31 | 32 | // ---- logging used to debug kkapture 33 | //#define TRACE(x) printLog x 34 | #define TRACE(x) 35 | 36 | // ---- lock holder for critical sections 37 | class Lock 38 | { 39 | CRITICAL_SECTION* CS; 40 | 41 | public: 42 | Lock(CRITICAL_SECTION *cs) : CS(cs) { EnterCriticalSection(CS); } 43 | Lock(CRITICAL_SECTION &cs) : CS(&cs) { EnterCriticalSection(CS); } 44 | 45 | ~Lock() { LeaveCriticalSection(CS); } 46 | }; 47 | 48 | // ---- hooking helpers 49 | 50 | // Semi-typesafe hooking functions 51 | template bool HookFunction(T *target,T hook) { return HookFunction((void **) target,(void *) hook); } 52 | template bool HookFunctionInit(T *target,T orig,T hook) { return HookFunctionInit((void **) target,(void *) orig,(void *) hook); } 53 | template bool HookFunctionInitOnce(T *target,T orig,T hook) { return *target || HookFunctionInit((void **) target,(void *) orig,(void *) hook); } 54 | template bool GetDLLFunction(T *target,HMODULE module,char *name) { return GetDLLFunction((void **) target,module,name); } 55 | template bool HookDLLFunction(T *target,HMODULE module,char *name,T hook) { return HookDLLFunction((void **) target,module,name,(void *) hook); } 56 | template bool HookCOM(T *target,IUnknown *obj,int vtableOffs,T hook) { return HookCOM((void **) target,obj,vtableOffs,(void *) hook); } 57 | template bool HookCOMOnce(T *target,IUnknown *obj,int vtableOffs,T hook) { return *target || HookCOM((void **) target,obj,vtableOffs,(void *) hook); } 58 | 59 | template bool UnhookFunction(T *target) { return UnhookFunction((void **) target); } 60 | 61 | // The "back end" 62 | template<> bool HookFunction(void **target,void *hook); 63 | template<> bool HookFunctionInit(void **target,void *orig,void *hook); 64 | template<> bool GetDLLFunction(void **target,HMODULE module,char *name); 65 | template<> bool HookDLLFunction(void **target,HMODULE module,char *name,void *hook); 66 | template<> bool HookCOM(void **target,IUnknown *obj,int vtableOffs,void *hook); 67 | 68 | template<> bool UnhookFunction(void **target); 69 | 70 | // ---- long integer arithmetic 71 | // multiply two 32-bit numbers, yielding a 64-bit temporary result, 72 | // then divide by another 32-bit number 73 | DWORD UMulDiv(DWORD a,DWORD b,DWORD c); 74 | 75 | // multiply a 64-bit number by a 32-bit number, yielding a 96-bit 76 | // temporary result, then divide by a 32-bit number 77 | ULONGLONG ULongMulDiv(ULONGLONG a,DWORD b,DWORD c); 78 | 79 | // ---- really misc stuff 80 | void *MakeCopy(const void *src,int size); // copy allocated as unsigned char[] 81 | 82 | // Copies and simplifies a WAVEFORMATEX 83 | struct tWAVEFORMATEX *CopyFormat(const tWAVEFORMATEX *src); 84 | 85 | // Get downmix (bounce) format for a source WAVEFORMATEX 86 | struct tWAVEFORMATEX *BounceFormat(const tWAVEFORMATEX *src); 87 | 88 | #endif -------------------------------------------------------------------------------- /dshow_base/cprop.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: CProp.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __CPROP__ 11 | #define __CPROP__ 12 | 13 | // Base property page class. Filters typically expose custom properties by 14 | // implementing special control interfaces, examples are IDirectDrawVideo 15 | // and IQualProp on renderers. This allows property pages to be built that 16 | // use the given interface. Applications such as the ActiveMovie OCX query 17 | // filters for the property pages they support and expose them to the user 18 | // 19 | // This class provides all the framework for a property page. A property 20 | // page is a COM object that supports IPropertyPage. We should be created 21 | // with a resource ID for the dialog which we will load when required. We 22 | // should also be given in the constructor a resource ID for a title string 23 | // we will load from the DLLs STRINGTABLE. The property page titles must be 24 | // stored in resource files so that they can be easily internationalised 25 | // 26 | // We have a number of virtual methods (not PURE) that may be overriden in 27 | // derived classes to query for interfaces and so on. These functions have 28 | // simple implementations here that just return NOERROR. Derived classes 29 | // will almost definately have to override the message handler method called 30 | // OnReceiveMessage. We have a static dialog procedure that calls the method 31 | // so that derived classes don't have to fiddle around with the this pointer 32 | 33 | class AM_NOVTABLE CBasePropertyPage : public IPropertyPage, public CUnknown 34 | { 35 | protected: 36 | 37 | LPPROPERTYPAGESITE m_pPageSite; // Details for our property site 38 | HWND m_hwnd; // Window handle for the page 39 | HWND m_Dlg; // Actual dialog window handle 40 | BOOL m_bDirty; // Has anything been changed 41 | int m_TitleId; // Resource identifier for title 42 | int m_DialogId; // Dialog resource identifier 43 | 44 | static INT_PTR CALLBACK DialogProc(HWND hwnd, 45 | UINT uMsg, 46 | WPARAM wParam, 47 | LPARAM lParam); 48 | 49 | private: 50 | BOOL m_bObjectSet ; // SetObject has been called or not. 51 | public: 52 | 53 | CBasePropertyPage(TCHAR *pName, // Debug only name 54 | LPUNKNOWN pUnk, // COM Delegator 55 | int DialogId, // Resource ID 56 | int TitleId); // To get tital 57 | 58 | #ifdef UNICODE 59 | CBasePropertyPage(CHAR *pName, 60 | LPUNKNOWN pUnk, 61 | int DialogId, 62 | int TitleId); 63 | #endif 64 | virtual ~CBasePropertyPage() { }; 65 | DECLARE_IUNKNOWN 66 | 67 | // Override these virtual methods 68 | 69 | virtual HRESULT OnConnect(IUnknown *pUnknown) { return NOERROR; }; 70 | virtual HRESULT OnDisconnect() { return NOERROR; }; 71 | virtual HRESULT OnActivate() { return NOERROR; }; 72 | virtual HRESULT OnDeactivate() { return NOERROR; }; 73 | virtual HRESULT OnApplyChanges() { return NOERROR; }; 74 | virtual INT_PTR OnReceiveMessage(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam); 75 | 76 | // These implement an IPropertyPage interface 77 | 78 | STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,void **ppv); 79 | STDMETHODIMP_(ULONG) NonDelegatingRelease(); 80 | STDMETHODIMP_(ULONG) NonDelegatingAddRef(); 81 | STDMETHODIMP SetPageSite(LPPROPERTYPAGESITE pPageSite); 82 | STDMETHODIMP Activate(HWND hwndParent,LPCRECT prect,BOOL fModal); 83 | STDMETHODIMP Deactivate(void); 84 | STDMETHODIMP GetPageInfo(LPPROPPAGEINFO pPageInfo); 85 | STDMETHODIMP SetObjects(ULONG cObjects, LPUNKNOWN *ppUnk); 86 | STDMETHODIMP Show(UINT nCmdShow); 87 | STDMETHODIMP Move(LPCRECT prect); 88 | STDMETHODIMP IsPageDirty(void) { return m_bDirty ? S_OK : S_FALSE; } 89 | STDMETHODIMP Apply(void); 90 | STDMETHODIMP Help(LPCWSTR lpszHelpDir) { return E_NOTIMPL; } 91 | STDMETHODIMP TranslateAccelerator(LPMSG lpMsg) { return E_NOTIMPL; } 92 | }; 93 | 94 | #endif // __CPROP__ 95 | 96 | -------------------------------------------------------------------------------- /kkapturedll/disasm-lib/disasm.c: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2004, Matt Conover (mconover@gmail.com) 2 | #undef NDEBUG 3 | #include 4 | #include 5 | #include "disasm.h" 6 | 7 | #ifdef NO_SANITY_CHECKS 8 | #define NDEBUG 9 | #undef assert 10 | #define assert(x) 11 | #endif 12 | 13 | ////////////////////////////////////////////////////////////////////// 14 | // Global variables 15 | ////////////////////////////////////////////////////////////////////// 16 | 17 | ARCHITECTURE_FORMAT SupportedArchitectures[] = 18 | { 19 | { ARCH_X86, &X86 }, 20 | { ARCH_X86_16, &X86 }, 21 | { ARCH_X64, &X86 }, 22 | { ARCH_UNKNOWN, NULL } 23 | }; 24 | 25 | typedef struct _DISASM_ARG_INFO 26 | { 27 | INSTRUCTION *MatchedInstruction; 28 | BOOL MatchPrefix; 29 | U8 *Opcode; 30 | U32 OpcodeLength; 31 | INSTRUCTION_TYPE InstructionType; 32 | U32 Count; 33 | } DISASM_ARG_INFO; 34 | 35 | ////////////////////////////////////////////////////////////////////// 36 | // Function prototypes 37 | ////////////////////////////////////////////////////////////////////// 38 | 39 | BOOL InitInstruction(INSTRUCTION *Instruction, DISASSEMBLER *Disassembler); 40 | struct _ARCHITECTURE_FORMAT *GetArchitectureFormat(ARCHITECTURE_TYPE Type); 41 | 42 | ////////////////////////////////////////////////////////////////////// 43 | // Disassembler setup 44 | ////////////////////////////////////////////////////////////////////// 45 | 46 | BOOL InitDisassembler(DISASSEMBLER *Disassembler, ARCHITECTURE_TYPE Architecture) 47 | { 48 | ARCHITECTURE_FORMAT *ArchFormat; 49 | 50 | memset(Disassembler, 0, sizeof(DISASSEMBLER)); 51 | Disassembler->Initialized = DISASSEMBLER_INITIALIZED; 52 | 53 | ArchFormat = GetArchitectureFormat(Architecture); 54 | if (!ArchFormat) { assert(0); return FALSE; } 55 | Disassembler->ArchType = ArchFormat->Type; 56 | Disassembler->Functions = ArchFormat->Functions; 57 | return TRUE; 58 | } 59 | 60 | void CloseDisassembler(DISASSEMBLER *Disassembler) 61 | { 62 | memset(Disassembler, 0, sizeof(DISASSEMBLER)); 63 | } 64 | 65 | ////////////////////////////////////////////////////////////////////// 66 | // Instruction setup 67 | ////////////////////////////////////////////////////////////////////// 68 | 69 | BOOL InitInstruction(INSTRUCTION *Instruction, DISASSEMBLER *Disassembler) 70 | { 71 | memset(Instruction, 0, sizeof(INSTRUCTION)); 72 | Instruction->Initialized = INSTRUCTION_INITIALIZED; 73 | Instruction->Disassembler = Disassembler; 74 | memset(Instruction->String, ' ', MAX_OPCODE_DESCRIPTION-1); 75 | Instruction->String[MAX_OPCODE_DESCRIPTION-1] = '\0'; 76 | return TRUE; 77 | } 78 | 79 | // If Decode = FALSE, only the following fields are valid: 80 | // Instruction->Length, Instruction->Address, Instruction->Prefixes, Instruction->PrefixCount, 81 | // Instruction->OpcodeBytes, Instruction->Instruction->OpcodeLength, Instruction->Groups, 82 | // Instruction->Type, Instruction->OperandCount 83 | // 84 | // If Disassemble = TRUE, then Instruction->String is valid (also requires Decode = TRUE) 85 | // 86 | // WARNING: This will overwrite the previously obtained instruction 87 | INSTRUCTION *GetInstruction(DISASSEMBLER *Disassembler, U64 VirtualAddress, U8 *Address, U32 Flags) 88 | { 89 | if (Disassembler->Initialized != DISASSEMBLER_INITIALIZED) { assert(0); return NULL; } 90 | assert(Address); 91 | InitInstruction(&Disassembler->Instruction, Disassembler); 92 | Disassembler->Instruction.Address = Address; 93 | Disassembler->Instruction.VirtualAddressDelta = VirtualAddress - (U64)Address; 94 | if (!Disassembler->Functions->GetInstruction(&Disassembler->Instruction, Address, Flags)) 95 | { 96 | assert(Disassembler->Instruction.Address == Address); 97 | assert(Disassembler->Instruction.Length < MAX_INSTRUCTION_LENGTH); 98 | 99 | // Save the address that failed, in case the lower-level disassembler didn't 100 | Disassembler->Instruction.Address = Address; 101 | Disassembler->Instruction.ErrorOccurred = TRUE; 102 | return NULL; 103 | } 104 | return &Disassembler->Instruction; 105 | } 106 | 107 | /////////////////////////////////////////////////////////////////////////// 108 | // Miscellaneous 109 | /////////////////////////////////////////////////////////////////////////// 110 | 111 | static ARCHITECTURE_FORMAT *GetArchitectureFormat(ARCHITECTURE_TYPE Type) 112 | { 113 | ARCHITECTURE_FORMAT *Format; 114 | for (Format = SupportedArchitectures; Format->Type != ARCH_UNKNOWN; Format++) 115 | { 116 | if (Format->Type == Type) return Format; 117 | } 118 | 119 | assert(0); 120 | return NULL; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /dshow_base/pstream.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: PStream.h 3 | // 4 | // Desc: DirectShow base classes - defines a class for persistent properties 5 | // of filters. 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | //------------------------------------------------------------------------------ 9 | 10 | 11 | #ifndef __PSTREAM__ 12 | #define __PSTREAM__ 13 | 14 | // Base class for persistent properties of filters 15 | // (i.e. filter properties in saved graphs) 16 | 17 | // The simplest way to use this is: 18 | // 1. Arrange for your filter to inherit this class 19 | // 2. Implement in your class WriteToStream and ReadFromStream 20 | // These will override the "do nothing" functions here. 21 | // 3. Change your NonDelegatingQueryInterface to handle IPersistStream 22 | // 4. Implement SizeMax to return the number of bytes of data you save. 23 | // If you save UNICODE data, don't forget a char is 2 bytes. 24 | // 5. Whenever your data changes, call SetDirty() 25 | // 26 | // At some point you may decide to alter, or extend the format of your data. 27 | // At that point you will wish that you had a version number in all the old 28 | // saved graphs, so that you can tell, when you read them, whether they 29 | // represent the old or new form. To assist you in this, this class 30 | // writes and reads a version number. 31 | // When it writes, it calls GetSoftwareVersion() to enquire what version 32 | // of the software we have at the moment. (In effect this is a version number 33 | // of the data layout in the file). It writes this as the first thing in the data. 34 | // If you want to change the version, implement (override) GetSoftwareVersion(). 35 | // It reads this from the file into mPS_dwFileVersion before calling ReadFromStream, 36 | // so in ReadFromStream you can check mPS_dwFileVersion to see if you are reading 37 | // an old version file. 38 | // Normally you should accept files whose version is no newer than the software 39 | // version that's reading them. 40 | 41 | 42 | // CPersistStream 43 | // 44 | // Implements IPersistStream. 45 | // See 'OLE Programmers Reference (Vol 1):Structured Storage Overview' for 46 | // more implementation information. 47 | class CPersistStream : public IPersistStream { 48 | private: 49 | 50 | // Internal state: 51 | 52 | protected: 53 | DWORD mPS_dwFileVersion; // version number of file (being read) 54 | BOOL mPS_fDirty; 55 | 56 | public: 57 | 58 | // IPersistStream methods 59 | 60 | STDMETHODIMP IsDirty() 61 | {return (mPS_fDirty ? S_OK : S_FALSE);} // note FALSE means clean 62 | STDMETHODIMP Load(LPSTREAM pStm); 63 | STDMETHODIMP Save(LPSTREAM pStm, BOOL fClearDirty); 64 | STDMETHODIMP GetSizeMax(ULARGE_INTEGER * pcbSize) 65 | // Allow 24 bytes for version. 66 | { pcbSize->QuadPart = 12*sizeof(WCHAR)+SizeMax(); return NOERROR; } 67 | 68 | // implementation 69 | 70 | CPersistStream(IUnknown *punk, HRESULT *phr); 71 | ~CPersistStream(); 72 | 73 | HRESULT SetDirty(BOOL fDirty) 74 | { mPS_fDirty = fDirty; return NOERROR;} 75 | 76 | 77 | // override to reveal IPersist & IPersistStream 78 | // STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv); 79 | 80 | // --- IPersist --- 81 | 82 | // You must override this to provide your own class id 83 | STDMETHODIMP GetClassID(CLSID *pClsid) PURE; 84 | 85 | // overrideable if you want 86 | // file version number. Override it if you ever change format 87 | virtual DWORD GetSoftwareVersion(void) { return 0; } 88 | 89 | 90 | //========================================================================= 91 | // OVERRIDE THESE to read and write your data 92 | // OVERRIDE THESE to read and write your data 93 | // OVERRIDE THESE to read and write your data 94 | 95 | virtual int SizeMax() {return 0;} 96 | virtual HRESULT WriteToStream(IStream *pStream); 97 | virtual HRESULT ReadFromStream(IStream *pStream); 98 | //========================================================================= 99 | 100 | private: 101 | 102 | }; 103 | 104 | 105 | // --- Useful helpers --- 106 | 107 | 108 | // Writes an int to an IStream as UNICODE. 109 | STDAPI WriteInt(IStream *pIStream, int n); 110 | 111 | // inverse of WriteInt 112 | STDAPI_(int) ReadInt(IStream *pIStream, HRESULT &hr); 113 | 114 | #endif // __PSTREAM__ 115 | -------------------------------------------------------------------------------- /dshow_base/schedule.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: Schedule.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __CAMSchedule__ 11 | #define __CAMSchedule__ 12 | 13 | class CAMSchedule : private CBaseObject 14 | { 15 | public: 16 | virtual ~CAMSchedule(); 17 | // ev is the event we should fire if the advise time needs re-evaluating 18 | CAMSchedule( HANDLE ev ); 19 | 20 | DWORD GetAdviseCount(); 21 | REFERENCE_TIME GetNextAdviseTime(); 22 | 23 | // We need a method for derived classes to add advise packets, we return the cookie 24 | DWORD_PTR AddAdvisePacket( const REFERENCE_TIME & time1, const REFERENCE_TIME & time2, HANDLE h, BOOL periodic ); 25 | // And a way to cancel 26 | HRESULT Unadvise(DWORD_PTR dwAdviseCookie); 27 | 28 | // Tell us the time please, and we'll dispatch the expired events. We return the time of the next event. 29 | // NB: The time returned will be "useless" if you start adding extra Advises. But that's the problem of 30 | // whoever is using this helper class (typically a clock). 31 | REFERENCE_TIME Advise( const REFERENCE_TIME & rtTime ); 32 | 33 | // Get the event handle which will be set if advise time requires re-evaluation. 34 | HANDLE GetEvent() const { return m_ev; } 35 | 36 | private: 37 | // We define the nodes that will be used in our singly linked list 38 | // of advise packets. The list is ordered by time, with the 39 | // elements that will expire first at the front. 40 | class CAdvisePacket 41 | { 42 | public: 43 | CAdvisePacket() 44 | {} 45 | 46 | CAdvisePacket * m_next; 47 | DWORD_PTR m_dwAdviseCookie; 48 | REFERENCE_TIME m_rtEventTime; // Time at which event should be set 49 | REFERENCE_TIME m_rtPeriod; // Periodic time 50 | HANDLE m_hNotify; // Handle to event or semephore 51 | BOOL m_bPeriodic; // TRUE => Periodic event 52 | 53 | CAdvisePacket( CAdvisePacket * next, LONGLONG time ) : m_next(next), m_rtEventTime(time) 54 | {} 55 | 56 | void InsertAfter( CAdvisePacket * p ) 57 | { 58 | p->m_next = m_next; 59 | m_next = p; 60 | } 61 | 62 | int IsZ() const // That is, is it the node that represents the end of the list 63 | { return m_next == 0; } 64 | 65 | CAdvisePacket * RemoveNext() 66 | { 67 | CAdvisePacket *const next = m_next; 68 | CAdvisePacket *const new_next = next->m_next; 69 | m_next = new_next; 70 | return next; 71 | } 72 | 73 | void DeleteNext() 74 | { 75 | delete RemoveNext(); 76 | } 77 | 78 | CAdvisePacket * Next() const 79 | { 80 | CAdvisePacket * result = m_next; 81 | if (result->IsZ()) result = 0; 82 | return result; 83 | } 84 | 85 | DWORD_PTR Cookie() const 86 | { return m_dwAdviseCookie; } 87 | }; 88 | 89 | // Structure is: 90 | // head -> elmt1 -> elmt2 -> z -> null 91 | // So an empty list is: head -> z -> null 92 | // Having head & z as links makes insertaion, 93 | // deletion and shunting much easier. 94 | CAdvisePacket head, z; // z is both a tail and a sentry 95 | 96 | volatile DWORD_PTR m_dwNextCookie; // Strictly increasing 97 | volatile DWORD m_dwAdviseCount; // Number of elements on list 98 | 99 | CCritSec m_Serialize; 100 | 101 | // AddAdvisePacket: adds the packet, returns the cookie (0 if failed) 102 | DWORD_PTR AddAdvisePacket( CAdvisePacket * pPacket ); 103 | // Event that we should set if the packed added above will be the next to fire. 104 | const HANDLE m_ev; 105 | 106 | // A Shunt is where we have changed the first element in the 107 | // list and want it re-evaluating (i.e. repositioned) in 108 | // the list. 109 | void ShuntHead(); 110 | 111 | // Rather than delete advise packets, we cache them for future use 112 | CAdvisePacket * m_pAdviseCache; 113 | DWORD m_dwCacheCount; 114 | enum { dwCacheMax = 5 }; // Don't bother caching more than five 115 | 116 | void Delete( CAdvisePacket * pLink );// This "Delete" will cache the Link 117 | 118 | // Attributes and methods for debugging 119 | public: 120 | #ifdef DEBUG 121 | void DumpLinkedList(); 122 | #else 123 | void DumpLinkedList() {} 124 | #endif 125 | 126 | }; 127 | 128 | #endif // __CAMSchedule__ 129 | -------------------------------------------------------------------------------- /dshow_base/dsschedule.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: DSSchedule.h (replaces DirectX 8's schedule.h) 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __CAMSchedule__ 11 | #define __CAMSchedule__ 12 | 13 | class CAMSchedule : private CBaseObject 14 | { 15 | public: 16 | virtual ~CAMSchedule(); 17 | // ev is the event we should fire if the advise time needs re-evaluating 18 | CAMSchedule( HANDLE ev ); 19 | 20 | DWORD GetAdviseCount(); 21 | REFERENCE_TIME GetNextAdviseTime(); 22 | 23 | // We need a method for derived classes to add advise packets, we return the cookie 24 | DWORD_PTR AddAdvisePacket( const REFERENCE_TIME & time1, const REFERENCE_TIME & time2, HANDLE h, BOOL periodic ); 25 | // And a way to cancel 26 | HRESULT Unadvise(DWORD_PTR dwAdviseCookie); 27 | 28 | // Tell us the time please, and we'll dispatch the expired events. We return the time of the next event. 29 | // NB: The time returned will be "useless" if you start adding extra Advises. But that's the problem of 30 | // whoever is using this helper class (typically a clock). 31 | REFERENCE_TIME Advise( const REFERENCE_TIME & rtTime ); 32 | 33 | // Get the event handle which will be set if advise time requires re-evaluation. 34 | HANDLE GetEvent() const { return m_ev; } 35 | 36 | private: 37 | // We define the nodes that will be used in our singly linked list 38 | // of advise packets. The list is ordered by time, with the 39 | // elements that will expire first at the front. 40 | class CAdvisePacket 41 | { 42 | public: 43 | CAdvisePacket() 44 | {} 45 | 46 | CAdvisePacket * m_next; 47 | DWORD_PTR m_dwAdviseCookie; 48 | REFERENCE_TIME m_rtEventTime; // Time at which event should be set 49 | REFERENCE_TIME m_rtPeriod; // Periodic time 50 | HANDLE m_hNotify; // Handle to event or semephore 51 | BOOL m_bPeriodic; // TRUE => Periodic event 52 | 53 | CAdvisePacket( CAdvisePacket * next, LONGLONG time ) : m_next(next), m_rtEventTime(time) 54 | {} 55 | 56 | void InsertAfter( CAdvisePacket * p ) 57 | { 58 | p->m_next = m_next; 59 | m_next = p; 60 | } 61 | 62 | int IsZ() const // That is, is it the node that represents the end of the list 63 | { return m_next == 0; } 64 | 65 | CAdvisePacket * RemoveNext() 66 | { 67 | CAdvisePacket *const next = m_next; 68 | CAdvisePacket *const new_next = next->m_next; 69 | m_next = new_next; 70 | return next; 71 | } 72 | 73 | void DeleteNext() 74 | { 75 | delete RemoveNext(); 76 | } 77 | 78 | CAdvisePacket * Next() const 79 | { 80 | CAdvisePacket * result = m_next; 81 | if (result->IsZ()) result = 0; 82 | return result; 83 | } 84 | 85 | DWORD_PTR Cookie() const 86 | { return m_dwAdviseCookie; } 87 | }; 88 | 89 | // Structure is: 90 | // head -> elmt1 -> elmt2 -> z -> null 91 | // So an empty list is: head -> z -> null 92 | // Having head & z as links makes insertaion, 93 | // deletion and shunting much easier. 94 | CAdvisePacket head, z; // z is both a tail and a sentry 95 | 96 | volatile DWORD_PTR m_dwNextCookie; // Strictly increasing 97 | volatile DWORD m_dwAdviseCount; // Number of elements on list 98 | 99 | CCritSec m_Serialize; 100 | 101 | // AddAdvisePacket: adds the packet, returns the cookie (0 if failed) 102 | DWORD_PTR AddAdvisePacket( CAdvisePacket * pPacket ); 103 | // Event that we should set if the packed added above will be the next to fire. 104 | const HANDLE m_ev; 105 | 106 | // A Shunt is where we have changed the first element in the 107 | // list and want it re-evaluating (i.e. repositioned) in 108 | // the list. 109 | void ShuntHead(); 110 | 111 | // Rather than delete advise packets, we cache them for future use 112 | CAdvisePacket * m_pAdviseCache; 113 | DWORD m_dwCacheCount; 114 | enum { dwCacheMax = 5 }; // Don't bother caching more than five 115 | 116 | void Delete( CAdvisePacket * pLink );// This "Delete" will cache the Link 117 | 118 | // Attributes and methods for debugging 119 | public: 120 | #ifdef DEBUG 121 | void DumpLinkedList(); 122 | #else 123 | void DumpLinkedList() {} 124 | #endif 125 | 126 | }; 127 | 128 | #endif // __CAMSchedule__ 129 | -------------------------------------------------------------------------------- /dshow_base/pullpin.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: PullPin.h 3 | // 4 | // Desc: DirectShow base classes - defines CPullPin class. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __PULLPIN_H__ 11 | #define __PULLPIN_H__ 12 | 13 | // 14 | // CPullPin 15 | // 16 | // object supporting pulling data from an IAsyncReader interface. 17 | // Given a start/stop position, calls a pure Receive method with each 18 | // IMediaSample received. 19 | // 20 | // This is essentially for use in a MemInputPin when it finds itself 21 | // connected to an IAsyncReader pin instead of a pushing pin. 22 | // 23 | 24 | class CPullPin : public CAMThread 25 | { 26 | IAsyncReader* m_pReader; 27 | REFERENCE_TIME m_tStart; 28 | REFERENCE_TIME m_tStop; 29 | REFERENCE_TIME m_tDuration; 30 | BOOL m_bSync; 31 | 32 | enum ThreadMsg { 33 | TM_Pause, // stop pulling and wait for next message 34 | TM_Start, // start pulling 35 | TM_Exit, // stop and exit 36 | }; 37 | 38 | ThreadMsg m_State; 39 | 40 | // override pure thread proc from CAMThread 41 | DWORD ThreadProc(void); 42 | 43 | // running pull method (check m_bSync) 44 | void Process(void); 45 | 46 | // clean up any cancelled i/o after a flush 47 | void CleanupCancelled(void); 48 | 49 | // suspend thread from pulling, eg during seek 50 | HRESULT PauseThread(); 51 | 52 | // start thread pulling - create thread if necy 53 | HRESULT StartThread(); 54 | 55 | // stop and close thread 56 | HRESULT StopThread(); 57 | 58 | // called from ProcessAsync to queue and collect requests 59 | HRESULT QueueSample( 60 | REFERENCE_TIME& tCurrent, 61 | REFERENCE_TIME tAlignStop, 62 | BOOL bDiscontinuity); 63 | 64 | HRESULT CollectAndDeliver( 65 | REFERENCE_TIME tStart, 66 | REFERENCE_TIME tStop); 67 | 68 | HRESULT DeliverSample( 69 | IMediaSample* pSample, 70 | REFERENCE_TIME tStart, 71 | REFERENCE_TIME tStop); 72 | 73 | protected: 74 | IMemAllocator * m_pAlloc; 75 | 76 | public: 77 | CPullPin(); 78 | virtual ~CPullPin(); 79 | 80 | // returns S_OK if successfully connected to an IAsyncReader interface 81 | // from this object 82 | // Optional allocator should be proposed as a preferred allocator if 83 | // necessary 84 | // bSync is TRUE if we are to use sync reads instead of the 85 | // async methods. 86 | HRESULT Connect(IUnknown* pUnk, IMemAllocator* pAlloc, BOOL bSync); 87 | 88 | // disconnect any connection made in Connect 89 | HRESULT Disconnect(); 90 | 91 | // agree an allocator using RequestAllocator - optional 92 | // props param specifies your requirements (non-zero fields). 93 | // returns an error code if fail to match requirements. 94 | // optional IMemAllocator interface is offered as a preferred allocator 95 | // but no error occurs if it can't be met. 96 | virtual HRESULT DecideAllocator( 97 | IMemAllocator* pAlloc, 98 | ALLOCATOR_PROPERTIES * pProps); 99 | 100 | // set start and stop position. if active, will start immediately at 101 | // the new position. Default is 0 to duration 102 | HRESULT Seek(REFERENCE_TIME tStart, REFERENCE_TIME tStop); 103 | 104 | // return the total duration 105 | HRESULT Duration(REFERENCE_TIME* ptDuration); 106 | 107 | // start pulling data 108 | HRESULT Active(void); 109 | 110 | // stop pulling data 111 | HRESULT Inactive(void); 112 | 113 | // helper functions 114 | LONGLONG AlignDown(LONGLONG ll, LONG lAlign) { 115 | // aligning downwards is just truncation 116 | return ll & ~(lAlign-1); 117 | }; 118 | 119 | LONGLONG AlignUp(LONGLONG ll, LONG lAlign) { 120 | // align up: round up to next boundary 121 | return (ll + (lAlign -1)) & ~(lAlign -1); 122 | }; 123 | 124 | // GetReader returns the (addrefed) IAsyncReader interface 125 | // for SyncRead etc 126 | IAsyncReader* GetReader() { 127 | m_pReader->AddRef(); 128 | return m_pReader; 129 | }; 130 | 131 | // -- pure -- 132 | 133 | // override this to handle data arrival 134 | // return value other than S_OK will stop data 135 | virtual HRESULT Receive(IMediaSample*) PURE; 136 | 137 | // override this to handle end-of-stream 138 | virtual HRESULT EndOfStream(void) PURE; 139 | 140 | // called on runtime errors that will have caused pulling 141 | // to stop 142 | // these errors are all returned from the upstream filter, who 143 | // will have already reported any errors to the filtergraph. 144 | virtual void OnError(HRESULT hr) PURE; 145 | 146 | // flush this pin and all downstream 147 | virtual HRESULT BeginFlush() PURE; 148 | virtual HRESULT EndFlush() PURE; 149 | 150 | }; 151 | 152 | #endif //__PULLPIN_H__ 153 | -------------------------------------------------------------------------------- /dshow_base/outputq.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: OutputQ.h 3 | // 4 | // Desc: DirectShow base classes - defines the COutputQueue class, which 5 | // makes a queue of samples and sends them to an output pin. The 6 | // class will optionally send the samples to the pin directly. 7 | // 8 | // Copyright (c) Microsoft Corporation. All rights reserved. 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | typedef CGenericList CSampleList; 13 | 14 | class COutputQueue : public CCritSec 15 | { 16 | public: 17 | // Constructor 18 | COutputQueue(IPin *pInputPin, // Pin to send stuff to 19 | HRESULT *phr, // 'Return code' 20 | BOOL bAuto = TRUE, // Ask pin if blocks 21 | BOOL bQueue = TRUE, // Send through queue (ignored if 22 | // bAuto set) 23 | LONG lBatchSize = 1, // Batch 24 | BOOL bBatchExact = FALSE,// Batch exactly to BatchSize 25 | LONG lListSize = // Likely number in the list 26 | DEFAULTCACHE, 27 | DWORD dwPriority = // Priority of thread to create 28 | THREAD_PRIORITY_NORMAL, 29 | bool bFlushingOpt = false // flushing optimization 30 | ); 31 | ~COutputQueue(); 32 | 33 | // enter flush state - discard all data 34 | void BeginFlush(); // Begin flushing samples 35 | 36 | // re-enable receives (pass this downstream) 37 | void EndFlush(); // Complete flush of samples - downstream 38 | // pin guaranteed not to block at this stage 39 | 40 | void EOS(); // Call this on End of stream 41 | 42 | void SendAnyway(); // Send batched samples anyway (if bBatchExact set) 43 | 44 | void NewSegment( 45 | REFERENCE_TIME tStart, 46 | REFERENCE_TIME tStop, 47 | double dRate); 48 | 49 | HRESULT Receive(IMediaSample *pSample); 50 | 51 | // do something with these media samples 52 | HRESULT ReceiveMultiple ( 53 | IMediaSample **pSamples, 54 | long nSamples, 55 | long *nSamplesProcessed); 56 | 57 | void Reset(); // Reset m_hr ready for more data 58 | 59 | // See if its idle or not 60 | BOOL IsIdle(); 61 | 62 | // give the class an event to fire after everything removed from the queue 63 | void SetPopEvent(HANDLE hEvent); 64 | 65 | protected: 66 | static DWORD WINAPI InitialThreadProc(LPVOID pv); 67 | DWORD ThreadProc(); 68 | BOOL IsQueued() 69 | { 70 | return m_List != NULL; 71 | } 72 | 73 | // The critical section MUST be held when this is called 74 | void QueueSample(IMediaSample *pSample); 75 | 76 | BOOL IsSpecialSample(IMediaSample *pSample) 77 | { 78 | return (DWORD_PTR)pSample > (DWORD_PTR)(LONG_PTR)(-16); 79 | } 80 | 81 | // Remove and Release() batched and queued samples 82 | void FreeSamples(); 83 | 84 | // Notify the thread there is something to do 85 | void NotifyThread(); 86 | 87 | 88 | protected: 89 | // Queue 'messages' 90 | #define SEND_PACKET ((IMediaSample *)(LONG_PTR)(-2)) // Send batch 91 | #define EOS_PACKET ((IMediaSample *)(LONG_PTR)(-3)) // End of stream 92 | #define RESET_PACKET ((IMediaSample *)(LONG_PTR)(-4)) // Reset m_hr 93 | #define NEW_SEGMENT ((IMediaSample *)(LONG_PTR)(-5)) // send NewSegment 94 | 95 | // new segment packet is always followed by one of these 96 | struct NewSegmentPacket { 97 | REFERENCE_TIME tStart; 98 | REFERENCE_TIME tStop; 99 | double dRate; 100 | }; 101 | 102 | // Remember input stuff 103 | IPin * const m_pPin; 104 | IMemInputPin * m_pInputPin; 105 | BOOL const m_bBatchExact; 106 | LONG const m_lBatchSize; 107 | 108 | CSampleList * m_List; 109 | HANDLE m_hSem; 110 | CAMEvent m_evFlushComplete; 111 | HANDLE m_hThread; 112 | IMediaSample ** m_ppSamples; 113 | LONG m_nBatched; 114 | 115 | // Wait optimization 116 | LONG m_lWaiting; 117 | // Flush synchronization 118 | BOOL m_bFlushing; 119 | 120 | // flushing optimization. some downstream filters have trouble 121 | // with the queue's flushing optimization. other rely on it 122 | BOOL m_bFlushed; 123 | bool m_bFlushingOpt; 124 | 125 | // Terminate now 126 | BOOL m_bTerminate; 127 | 128 | // Send anyway flag for batching 129 | BOOL m_bSendAnyway; 130 | 131 | // Deferred 'return code' 132 | BOOL volatile m_hr; 133 | 134 | // an event that can be fired after every deliver 135 | HANDLE m_hEventPop; 136 | }; 137 | 138 | -------------------------------------------------------------------------------- /kkapturedll/disasm-lib/misc.c: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2002, Matt Conover (mconover@gmail.com) 2 | #include "misc.h" 3 | 4 | BOOL IsHexChar(BYTE ch) 5 | { 6 | switch (ch) 7 | { 8 | case '0': case '1': case '2': case '3': 9 | case '4': case '5': case '6': case '7': 10 | case '8': case '9': 11 | case 'A': case 'a': case 'B': case 'b': 12 | case 'C': case 'c': case 'D': case 'd': 13 | case 'E': case 'e': case 'F': case 'f': 14 | return TRUE; 15 | default: 16 | return FALSE; 17 | } 18 | } 19 | 20 | // NOTE: caller must free the buffer returned 21 | BYTE *HexToBinary(char *Input, DWORD InputLength, DWORD *OutputLength) 22 | { 23 | DWORD i, j, ByteCount = 0; 24 | char temp_byte[3]; 25 | BYTE *p, *ByteString = NULL; 26 | 27 | if (!InputLength || !OutputLength) return NULL; 28 | else *OutputLength = 0; 29 | 30 | while (*Input && isspace(*Input)) { Input++; InputLength--; } 31 | if (!*Input) return NULL; 32 | if (Input[0] == '\"') { Input++; InputLength--; } 33 | p = (BYTE *)strchr(Input, '\"'); 34 | if (p) InputLength--; 35 | 36 | if (InputLength > 2 && Input[2] == ' ') // assume spaces 37 | { 38 | for (i = 0; i < InputLength; i += 3) 39 | { 40 | while (i < InputLength && isspace(Input[i])) i++; // skip over extra space, \r, and \n 41 | if (i >= InputLength) break; 42 | 43 | if (!IsHexChar(Input[i])) 44 | { 45 | //fprintf(stderr, "ERROR: invalid hex character at offset %lu (0x%04x)\n", i, i); 46 | goto abort; 47 | } 48 | 49 | if (i+1 >= InputLength || !Input[i+1]) 50 | { 51 | //fprintf(stderr, "ERROR: hex string terminates unexpectedly at offset %lu (0x%04x)\n", i+1, i+1); 52 | goto abort; 53 | } 54 | 55 | if (i+2 < InputLength && Input[i+2] && !isspace(Input[i+2])) 56 | { 57 | //fprintf(stderr, "ERROR: Hex string is malformed at offset %lu (0x%04x)\n", i, i); 58 | //fprintf(stderr, "Found '%c' (0x%02x) instead of space\n", Input[i+2], Input[i+2]); 59 | goto abort; 60 | } 61 | 62 | ByteCount++; 63 | } 64 | 65 | if (!ByteCount) 66 | { 67 | //fprintf(stderr, "Error: no input (byte count = 0)\n"); 68 | goto abort; 69 | } 70 | 71 | ByteString = malloc(ByteCount+1); 72 | if (!ByteString) 73 | { 74 | //fprintf(stderr, "ERROR: failed to allocate %lu bytes\n", ByteCount); 75 | goto abort; 76 | } 77 | 78 | memset(ByteString, 0, ByteCount+1); 79 | for (i = 0, j = 0; j < ByteCount; i += 3, j++) 80 | { 81 | while (isspace(Input[i])) i++; // skip over extra space, \r, and \n 82 | temp_byte[0] = Input[i]; 83 | temp_byte[1] = Input[i+1]; 84 | temp_byte[2] = 0; 85 | ByteString[j] = (BYTE)strtoul(temp_byte, NULL, 16); 86 | } 87 | } 88 | else if (InputLength > 2 && Input[0] == '\\') 89 | { 90 | for (i = 0; i < InputLength; i += 2) 91 | { 92 | if (Input[i] != '\\' || (Input[i+1] != 'x' && Input[i+1] != '0')) 93 | { 94 | //fprintf(stderr, "ERROR: invalid hex character at offset %lu (0x%04x)\n", i, i); 95 | goto abort; 96 | } 97 | i += 2; 98 | 99 | if (!IsHexChar(Input[i])) 100 | { 101 | //fprintf(stderr, "ERROR: invalid hex character at offset %lu (0x%04x)\n", i, i); 102 | goto abort; 103 | } 104 | if (i+1 >= InputLength || !Input[i+1]) 105 | { 106 | //fprintf(stderr, "ERROR: hex string terminates unexpectedly at offset %lu (0x%04x)\n", i+1, i+1); 107 | goto abort; 108 | } 109 | 110 | ByteCount++; 111 | } 112 | 113 | if (!ByteCount) 114 | { 115 | //fprintf(stderr, "Error: no input (byte count = 0)\n"); 116 | goto abort; 117 | } 118 | 119 | ByteString = malloc(ByteCount+1); 120 | if (!ByteString) 121 | { 122 | //fprintf(stderr, "ERROR: failed to allocate %lu bytes\n", ByteCount); 123 | goto abort; 124 | } 125 | 126 | memset(ByteString, 0, ByteCount+1); 127 | for (i = j = 0; j < ByteCount; i += 2, j++) 128 | { 129 | i += 2; 130 | temp_byte[0] = Input[i]; 131 | temp_byte[1] = Input[i+1]; 132 | temp_byte[2] = 0; 133 | ByteString[j] = (BYTE)strtoul(temp_byte, NULL, 16); 134 | } 135 | } 136 | else // assume it is a hex string with no spaces with 2 bytes per character 137 | { 138 | for (i = 0; i < InputLength; i += 2) 139 | { 140 | if (!IsHexChar(Input[i])) 141 | { 142 | //fprintf(stderr, "ERROR: invalid hex character at offset %lu (0x%04x)\n", i, i); 143 | goto abort; 144 | } 145 | if (i+1 >= InputLength || !Input[i+1]) 146 | { 147 | //fprintf(stderr, "ERROR: hex string terminates unexpectedly at offset %lu (0x%04x)\n", i+1, i+1); 148 | goto abort; 149 | } 150 | 151 | ByteCount++; 152 | } 153 | 154 | if (!ByteCount) 155 | { 156 | //fprintf(stderr, "Error: no input (byte count = 0)\n"); 157 | goto abort; 158 | } 159 | 160 | ByteString = malloc(ByteCount+1); 161 | if (!ByteString) 162 | { 163 | //fprintf(stderr, "ERROR: failed to allocate %lu bytes\n", ByteCount); 164 | goto abort; 165 | } 166 | 167 | memset(ByteString, 0, ByteCount+1); 168 | for (i = 0, j = 0; j < ByteCount; i += 2, j++) 169 | { 170 | temp_byte[0] = Input[i]; 171 | temp_byte[1] = Input[i+1]; 172 | temp_byte[2] = 0; 173 | ByteString[j] = (BYTE)strtoul(temp_byte, NULL, 16); 174 | } 175 | } 176 | 177 | *OutputLength = ByteCount; 178 | return ByteString; 179 | 180 | abort: 181 | if (OutputLength) *OutputLength = 0; 182 | if (ByteString) free(ByteString); 183 | return NULL; 184 | } 185 | 186 | -------------------------------------------------------------------------------- /kkapturedll/bmp_videoencoder.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" 24 | #include "bmp_videoencoder.h" 25 | 26 | // internal data 27 | struct BMPVideoEncoder::Internal 28 | { 29 | BITMAPFILEHEADER bmfh; 30 | BITMAPINFOHEADER bmih; 31 | WAVEFORMATEX *wfx; 32 | FILE *wave; 33 | }; 34 | 35 | BMPVideoEncoder::BMPVideoEncoder(const char *fileName) 36 | { 37 | char drive[_MAX_DRIVE],dir[_MAX_DIR],fname[_MAX_FNAME],ext[_MAX_EXT]; 38 | 39 | _splitpath(fileName,drive,dir,fname,ext); 40 | _makepath(prefix,drive,dir,fname,""); 41 | xRes = yRes = 0; 42 | 43 | intn = new Internal; 44 | intn->wave = 0; 45 | intn->wfx = 0; 46 | 47 | ZeroMemory(&intn->bmfh,sizeof(BITMAPFILEHEADER)); 48 | ZeroMemory(&intn->bmih,sizeof(BITMAPINFOHEADER)); 49 | 50 | intn->bmfh.bfType = 0x4d42; 51 | intn->bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 52 | intn->bmfh.bfSize = intn->bmfh.bfOffBits; 53 | 54 | intn->bmih.biSize = sizeof(BITMAPINFOHEADER); 55 | intn->bmih.biPlanes = 1; 56 | intn->bmih.biBitCount = 24; 57 | intn->bmih.biCompression = BI_RGB; 58 | } 59 | 60 | BMPVideoEncoder::~BMPVideoEncoder() 61 | { 62 | if(intn->wave) 63 | { 64 | // finish the wave file by writing overall and data chunk lengths 65 | long fileLen = ftell(intn->wave); 66 | 67 | long riffLen = fileLen - 8; 68 | fseek(intn->wave,4,SEEK_SET); 69 | fwrite(&riffLen,1,sizeof(long),intn->wave); 70 | 71 | long dataLen = fileLen - 44; 72 | fseek(intn->wave,40,SEEK_SET); 73 | fwrite(&dataLen,1,sizeof(long),intn->wave); 74 | 75 | fclose(intn->wave); 76 | } 77 | 78 | delete[] (unsigned char *) intn->wfx; 79 | delete intn; 80 | } 81 | 82 | void BMPVideoEncoder::SetSize(int _xRes,int _yRes) 83 | { 84 | xRes = _xRes; 85 | yRes = _yRes; 86 | 87 | intn->bmfh.bfSize = xRes * yRes * 3 + intn->bmfh.bfOffBits; 88 | intn->bmih.biWidth = xRes; 89 | intn->bmih.biHeight = yRes; 90 | 91 | frame = 0; 92 | } 93 | 94 | void BMPVideoEncoder::WriteFrame(const unsigned char *buffer) 95 | { 96 | if(xRes && yRes) 97 | { 98 | // create filename 99 | char filename[512]; 100 | _snprintf_s(filename,sizeof(filename)/sizeof(*filename),"%s%06d.bmp",prefix,frame); 101 | 102 | // create file, write headers+image 103 | FILE *f = fopen(filename,"wb"); 104 | fwrite(&intn->bmfh,sizeof(BITMAPFILEHEADER),1,f); 105 | fwrite(&intn->bmih,sizeof(BITMAPINFOHEADER),1,f); 106 | fwrite(buffer,xRes*yRes,3,f); 107 | fclose(f); 108 | 109 | // frame is finished. 110 | frame++; 111 | } 112 | } 113 | 114 | void BMPVideoEncoder::SetAudioFormat(const tWAVEFORMATEX *fmt) 115 | { 116 | if(params.CaptureAudio && !intn->wave) 117 | { 118 | char filename[512]; 119 | strcpy_s(filename,prefix); 120 | strcat_s(filename,".wav"); 121 | 122 | delete intn->wfx; 123 | intn->wfx = CopyFormat(fmt); 124 | intn->wave = fopen(filename,"wb"); 125 | 126 | if(intn->wave) 127 | { 128 | static unsigned char header[] = "RIFF\0\0\0\0WAVEfmt "; 129 | static unsigned char data[] = "data\0\0\0\0"; 130 | 131 | fwrite(header,1,sizeof(header)-1,intn->wave); 132 | DWORD len = fmt->cbSize ? sizeof(WAVEFORMATEX)+fmt->cbSize : sizeof(WAVEFORMATEX)-2; 133 | fwrite(&len,1,sizeof(DWORD),intn->wave); 134 | fwrite(fmt,1,len,intn->wave); 135 | fwrite(data,1,sizeof(data)-1,intn->wave); 136 | } 137 | 138 | // fill already written frames with no sound 139 | unsigned char *buffer = new unsigned char[fmt->nBlockAlign * 1024]; 140 | int sampleFill = MulDiv(frame,fmt->nSamplesPerSec*frameRateDenom,frameRateScaled); 141 | 142 | memset(buffer,0,fmt->nBlockAlign * 1024); 143 | for(int samplePos=0;samplePoswave || !intn->wfx) return 0; 151 | return CopyFormat(intn->wfx); 152 | } 153 | 154 | void BMPVideoEncoder::WriteAudioFrame(const void *buffer,int samples) 155 | { 156 | if(intn->wave) 157 | fwrite(buffer,intn->wfx->nBlockAlign,samples,intn->wave); 158 | } -------------------------------------------------------------------------------- /kkapture/kkapture.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""afxres.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | #endif // English (U.S.) resources 50 | ///////////////////////////////////////////////////////////////////////////// 51 | 52 | 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // Neutral (Sys. Default) resources 55 | 56 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUSD) 57 | #ifdef _WIN32 58 | LANGUAGE LANG_NEUTRAL, SUBLANG_SYS_DEFAULT 59 | #pragma code_page(1252) 60 | #endif //_WIN32 61 | 62 | ///////////////////////////////////////////////////////////////////////////// 63 | // 64 | // Dialog 65 | // 66 | 67 | IDD_MAINWIN DIALOGEX 0, 0, 258, 278 68 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 69 | CAPTION ".kkapture 1.01" 70 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 71 | BEGIN 72 | DEFPUSHBUTTON "kkapture!",IDOK,149,257,50,14 73 | PUSHBUTTON "Exit",IDCANCEL,201,257,50,14 74 | EDITTEXT IDC_DEMO,51,7,146,13,ES_AUTOHSCROLL 75 | LTEXT "Demo:",IDC_STATIC,9,9,22,8 76 | PUSHBUTTON "Browse...",IDC_BDEMO,201,7,50,13 77 | EDITTEXT IDC_ARGUMENTS,51,23,146,13,ES_AUTOHSCROLL 78 | LTEXT "Arguments:",IDC_STATIC,9,25,38,8 79 | EDITTEXT IDC_TARGET,51,39,146,13,ES_AUTOHSCROLL 80 | LTEXT "Target:",IDC_STATIC,9,41,25,8 81 | PUSHBUTTON "Browse...",IDC_BTARGET,201,39,50,13 82 | LTEXT "Frame rate:",IDC_STATIC,10,57,39,8 83 | EDITTEXT IDC_FRAMERATE,51,55,31,13,ES_AUTOHSCROLL 84 | LTEXT "Encoder:",IDC_STATIC,95,57,28,8 85 | COMBOBOX IDC_ENCODER,130,55,121,100,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_TABSTOP 86 | GROUPBOX "AVI Encoding Options",IDC_STATIC,7,73,244,26 87 | LTEXT "Video Codec:",IDC_VIDEOCODEC,14,84,176,8 88 | PUSHBUTTON "Pick...",IDC_VCPICK,214,82,30,12 89 | GROUPBOX "Tweaking",IDC_STATIC,7,103,244,73 90 | CONTROL "Capture Video",IDC_VCAPTURE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,114,61,10 91 | CONTROL "Capture Audio",IDC_ACAPTURE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,126,62,10 92 | CONTROL "Skip digital silence at start",IDC_SKIPSILENCE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,121,114,99,10 93 | CONTROL "Make Sleep() last one frame",IDC_SLEEPLAST,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,121,126,105,10 94 | CONTROL "Intercept Windows GDI",IDC_CAPTUREGDI,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,138,95,10 95 | CONTROL "BASS/FMOD interception",IDC_SOUNDSYS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,121,138,120,10 96 | CONTROL "Power down on completion",IDC_POWERDOWN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,150,105,10 97 | CONTROL "Separate encoder thread",IDC_ENCODERTHREAD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,121,150,117,10 98 | CONTROL "DDraw virtual framebuffer",IDC_VIRTFRAMEBUF,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,163,117,10 99 | GROUPBOX "Auto-skip",IDC_STATIC,7,180,244,72 100 | CONTROL "Skip frames on frequent timer checks",IDC_AUTOSKIP_TIMER, 101 | "Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,192,150,10 102 | CONTROL "Enable automatic frameskip on timeout",IDC_AUTOSKIP, 103 | "Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,205,150,10 104 | LTEXT "Initial frame timeout (seconds):",IDC_STATIC,14,219,140,8 105 | EDITTEXT IDC_FIRSTFRAMETIMEOUT,130,217,31,13,ES_AUTOHSCROLL 106 | LTEXT "Other frames timeout (seconds):",IDC_STATIC,14,235,140,8 107 | EDITTEXT IDC_OTHERFRAMETIMEOUT,130,233,31,13,ES_AUTOHSCROLL 108 | END 109 | 110 | 111 | ///////////////////////////////////////////////////////////////////////////// 112 | // 113 | // DESIGNINFO 114 | // 115 | 116 | #ifdef APSTUDIO_INVOKED 117 | GUIDELINES DESIGNINFO 118 | BEGIN 119 | IDD_MAINWIN, DIALOG 120 | BEGIN 121 | LEFTMARGIN, 7 122 | RIGHTMARGIN, 251 123 | TOPMARGIN, 7 124 | BOTTOMMARGIN, 271 125 | END 126 | END 127 | #endif // APSTUDIO_INVOKED 128 | 129 | #endif // Neutral (Sys. Default) resources 130 | ///////////////////////////////////////////////////////////////////////////// 131 | 132 | 133 | 134 | #ifndef APSTUDIO_INVOKED 135 | ///////////////////////////////////////////////////////////////////////////// 136 | // 137 | // Generated from the TEXTINCLUDE 3 resource. 138 | // 139 | 140 | 141 | ///////////////////////////////////////////////////////////////////////////// 142 | #endif // not APSTUDIO_INVOKED 143 | 144 | -------------------------------------------------------------------------------- /kkapturedll/kkapturedll.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 10 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx 11 | 12 | 13 | {38002c5b-c421-4ecd-a310-fffe2126dd41} 14 | 15 | 16 | {ef94d408-0150-468f-94ad-a3580e691129} 17 | 18 | 19 | 20 | 21 | Source Files 22 | 23 | 24 | Source Files 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | mhook 79 | 80 | 81 | tdisasm 82 | 83 | 84 | tdisasm 85 | 86 | 87 | tdisasm 88 | 89 | 90 | tdisasm 91 | 92 | 93 | 94 | 95 | Source Files 96 | 97 | 98 | Source Files 99 | 100 | 101 | Source Files 102 | 103 | 104 | Source Files 105 | 106 | 107 | Source Files 108 | 109 | 110 | Source Files 111 | 112 | 113 | Source Files 114 | 115 | 116 | Source Files 117 | 118 | 119 | Source Files 120 | 121 | 122 | Source Files 123 | 124 | 125 | Source Files 126 | 127 | 128 | Source Files 129 | 130 | 131 | Source Files 132 | 133 | 134 | Source Files 135 | 136 | 137 | mhook 138 | 139 | 140 | tdisasm 141 | 142 | 143 | tdisasm 144 | 145 | 146 | tdisasm 147 | 148 | 149 | tdisasm 150 | 151 | 152 | tdisasm 153 | 154 | 155 | -------------------------------------------------------------------------------- /kkapture/kkapture.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 26 | 29 | 32 | 35 | 38 | 41 | 54 | 57 | 60 | 63 | 76 | 79 | 82 | 85 | 88 | 91 | 94 | 97 | 98 | 106 | 109 | 112 | 115 | 118 | 121 | 131 | 134 | 137 | 140 | 153 | 156 | 159 | 162 | 165 | 168 | 171 | 174 | 175 | 176 | 177 | 178 | 179 | 184 | 187 | 188 | 191 | 194 | 198 | 199 | 200 | 203 | 204 | 205 | 210 | 213 | 214 | 215 | 218 | 219 | 222 | 223 | 226 | 227 | 230 | 231 | 234 | 235 | 236 | 237 | 238 | 239 | -------------------------------------------------------------------------------- /kkapture/kkapture.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {DBA35513-DE77-4FE9-8B71-C483946E76FF} 15 | Win32Proj 16 | 17 | 18 | 19 | Application 20 | MultiByte 21 | 22 | 23 | Application 24 | MultiByte 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | <_ProjectFileVersion>10.0.40219.1 40 | true 41 | false 42 | 43 | 44 | 45 | Disabled 46 | ..\include;%(AdditionalIncludeDirectories) 47 | WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) 48 | true 49 | EnableFastChecks 50 | MultiThreadedDebug 51 | Use 52 | Level3 53 | EditAndContinue 54 | 55 | 56 | kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;comdlg32.lib;%(AdditionalDependencies) 57 | $(OutDir)kkapture.exe 58 | ..\lib;%(AdditionalLibraryDirectories) 59 | true 60 | $(OutDir)kkapture.pdb 61 | Windows 62 | false 63 | 64 | 65 | MachineX86 66 | 67 | 68 | 69 | 70 | MaxSpeed 71 | WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) 72 | MultiThreaded 73 | 74 | 75 | Level3 76 | ProgramDatabase 77 | 78 | 79 | $(OutDir)kkapture.exe 80 | true 81 | Windows 82 | true 83 | true 84 | 0x410000 85 | false 86 | 87 | 88 | MachineX86 89 | 90 | 91 | 92 | 93 | 94 | Create 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | {8212119f-dbe1-4da5-80a9-67fde9a4cbd3} 113 | false 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /dshow_base/source.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: Source.h 3 | // 4 | // Desc: DirectShow base classes - defines classes to simplify creation of 5 | // ActiveX source filters that support continuous generation of data. 6 | // No support is provided for IMediaControl or IMediaPosition. 7 | // 8 | // Copyright (c) Microsoft Corporation. All rights reserved. 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | // 13 | // Derive your source filter from CSource. 14 | // During construction either: 15 | // Create some CSourceStream objects to manage your pins 16 | // Provide the user with a means of doing so eg, an IPersistFile interface. 17 | // 18 | // CSource provides: 19 | // IBaseFilter interface management 20 | // IMediaFilter interface management, via CBaseFilter 21 | // Pin counting for CBaseFilter 22 | // 23 | // Derive a class from CSourceStream to manage your output pin types 24 | // Implement GetMediaType/1 to return the type you support. If you support multiple 25 | // types then overide GetMediaType/3, CheckMediaType and GetMediaTypeCount. 26 | // Implement Fillbuffer() to put data into one buffer. 27 | // 28 | // CSourceStream provides: 29 | // IPin management via CBaseOutputPin 30 | // Worker thread management 31 | 32 | #ifndef __CSOURCE__ 33 | #define __CSOURCE__ 34 | 35 | class CSourceStream; // The class that will handle each pin 36 | 37 | 38 | // 39 | // CSource 40 | // 41 | // Override construction to provide a means of creating 42 | // CSourceStream derived objects - ie a way of creating pins. 43 | class CSource : public CBaseFilter { 44 | public: 45 | 46 | CSource(TCHAR *pName, LPUNKNOWN lpunk, CLSID clsid, HRESULT *phr); 47 | CSource(TCHAR *pName, LPUNKNOWN lpunk, CLSID clsid); 48 | #ifdef UNICODE 49 | CSource(CHAR *pName, LPUNKNOWN lpunk, CLSID clsid, HRESULT *phr); 50 | CSource(CHAR *pName, LPUNKNOWN lpunk, CLSID clsid); 51 | #endif 52 | ~CSource(); 53 | 54 | int GetPinCount(void); 55 | CBasePin *GetPin(int n); 56 | 57 | // -- Utilities -- 58 | 59 | CCritSec* pStateLock(void) { return &m_cStateLock; } // provide our critical section 60 | 61 | HRESULT AddPin(CSourceStream *); 62 | HRESULT RemovePin(CSourceStream *); 63 | 64 | STDMETHODIMP FindPin( 65 | LPCWSTR Id, 66 | IPin ** ppPin 67 | ); 68 | 69 | int FindPinNumber(IPin *iPin); 70 | 71 | protected: 72 | 73 | int m_iPins; // The number of pins on this filter. Updated by CSourceStream 74 | // constructors & destructors. 75 | CSourceStream **m_paStreams; // the pins on this filter. 76 | 77 | CCritSec m_cStateLock; // Lock this to serialize function accesses to the filter state 78 | 79 | }; 80 | 81 | 82 | // 83 | // CSourceStream 84 | // 85 | // Use this class to manage a stream of data that comes from a 86 | // pin. 87 | // Uses a worker thread to put data on the pin. 88 | class CSourceStream : public CAMThread, public CBaseOutputPin { 89 | public: 90 | 91 | CSourceStream(TCHAR *pObjectName, 92 | HRESULT *phr, 93 | CSource *pms, 94 | LPCWSTR pName); 95 | #ifdef UNICODE 96 | CSourceStream(CHAR *pObjectName, 97 | HRESULT *phr, 98 | CSource *pms, 99 | LPCWSTR pName); 100 | #endif 101 | virtual ~CSourceStream(void); // virtual destructor ensures derived class destructors are called too. 102 | 103 | protected: 104 | 105 | CSource *m_pFilter; // The parent of this stream 106 | 107 | // * 108 | // * Data Source 109 | // * 110 | // * The following three functions: FillBuffer, OnThreadCreate/Destroy, are 111 | // * called from within the ThreadProc. They are used in the creation of 112 | // * the media samples this pin will provide 113 | // * 114 | 115 | // Override this to provide the worker thread a means 116 | // of processing a buffer 117 | virtual HRESULT FillBuffer(IMediaSample *pSamp) PURE; 118 | 119 | // Called as the thread is created/destroyed - use to perform 120 | // jobs such as start/stop streaming mode 121 | // If OnThreadCreate returns an error the thread will exit. 122 | virtual HRESULT OnThreadCreate(void) {return NOERROR;}; 123 | virtual HRESULT OnThreadDestroy(void) {return NOERROR;}; 124 | virtual HRESULT OnThreadStartPlay(void) {return NOERROR;}; 125 | 126 | // * 127 | // * Worker Thread 128 | // * 129 | 130 | HRESULT Active(void); // Starts up the worker thread 131 | HRESULT Inactive(void); // Exits the worker thread. 132 | 133 | public: 134 | // thread commands 135 | enum Command {CMD_INIT, CMD_PAUSE, CMD_RUN, CMD_STOP, CMD_EXIT}; 136 | HRESULT Init(void) { return CallWorker(CMD_INIT); } 137 | HRESULT Exit(void) { return CallWorker(CMD_EXIT); } 138 | HRESULT Run(void) { return CallWorker(CMD_RUN); } 139 | HRESULT Pause(void) { return CallWorker(CMD_PAUSE); } 140 | HRESULT Stop(void) { return CallWorker(CMD_STOP); } 141 | 142 | protected: 143 | Command GetRequest(void) { return (Command) CAMThread::GetRequest(); } 144 | BOOL CheckRequest(Command *pCom) { return CAMThread::CheckRequest( (DWORD *) pCom); } 145 | 146 | // override these if you want to add thread commands 147 | virtual DWORD ThreadProc(void); // the thread function 148 | 149 | virtual HRESULT DoBufferProcessingLoop(void); // the loop executed whilst running 150 | 151 | 152 | // * 153 | // * AM_MEDIA_TYPE support 154 | // * 155 | 156 | // If you support more than one media type then override these 2 functions 157 | virtual HRESULT CheckMediaType(const CMediaType *pMediaType); 158 | virtual HRESULT GetMediaType(int iPosition, CMediaType *pMediaType); // List pos. 0-n 159 | 160 | // If you support only one type then override this fn. 161 | // This will only be called by the default implementations 162 | // of CheckMediaType and GetMediaType(int, CMediaType*) 163 | // You must override this fn. or the above 2! 164 | virtual HRESULT GetMediaType(CMediaType *pMediaType) {return E_UNEXPECTED;} 165 | 166 | STDMETHODIMP QueryId( 167 | LPWSTR * Id 168 | ); 169 | }; 170 | 171 | #endif // __CSOURCE__ 172 | 173 | -------------------------------------------------------------------------------- /dshow_base/strmctl.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: StrmCtl.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __strmctl_h__ 11 | #define __strmctl_h__ 12 | 13 | class CBaseStreamControl : public IAMStreamControl 14 | { 15 | public: 16 | // Used by the implementation 17 | enum StreamControlState 18 | { STREAM_FLOWING = 0x1000, 19 | STREAM_DISCARDING 20 | }; 21 | 22 | private: 23 | enum StreamControlState m_StreamState; // Current stream state 24 | enum StreamControlState m_StreamStateOnStop; // State after next stop 25 | // (i.e.Blocking or Discarding) 26 | 27 | REFERENCE_TIME m_tStartTime; // MAX_TIME implies none 28 | REFERENCE_TIME m_tStopTime; // MAX_TIME implies none 29 | DWORD m_dwStartCookie; // Cookie for notification to app 30 | DWORD m_dwStopCookie; // Cookie for notification to app 31 | volatile BOOL m_bIsFlushing; // No optimization pls! 32 | volatile BOOL m_bStopSendExtra; // bSendExtra was set 33 | volatile BOOL m_bStopExtraSent; // the extra one was sent 34 | 35 | CCritSec m_CritSec; // CritSec to guard above attributes 36 | 37 | // Event to fire when we can come 38 | // out of blocking, or to come out of waiting 39 | // to discard if we change our minds. 40 | // 41 | CAMEvent m_StreamEvent; 42 | 43 | // All of these methods execute immediately. Helpers for others. 44 | // 45 | void ExecuteStop(); 46 | void ExecuteStart(); 47 | void CancelStop(); 48 | void CancelStart(); 49 | 50 | // Some things we need to be told by our owning filter 51 | // Your pin must also expose IAMStreamControl when QI'd for it! 52 | // 53 | IReferenceClock * m_pRefClock; // Need it to set advises 54 | // Filter must tell us via 55 | // SetSyncSource 56 | IMediaEventSink * m_pSink; // Event sink 57 | // Filter must tell us after it 58 | // creates it in JoinFilterGraph() 59 | FILTER_STATE m_FilterState; // Just need it! 60 | // Filter must tell us via 61 | // NotifyFilterState 62 | REFERENCE_TIME m_tRunStart; // Per the Run call to the filter 63 | 64 | // This guy will return one of the three StreamControlState's. Here's what 65 | // the caller should do for each one: 66 | // 67 | // STREAM_FLOWING: Proceed as usual (render or pass the sample on) 68 | // STREAM_DISCARDING: Calculate the time 'til *pSampleStop and wait 69 | // that long for the event handle 70 | // (GetStreamEventHandle()). If the wait 71 | // expires, throw the sample away. If the event 72 | // fires, call me back - I've changed my mind. 73 | // 74 | enum StreamControlState CheckSampleTimes( const REFERENCE_TIME * pSampleStart, 75 | const REFERENCE_TIME * pSampleStop ); 76 | 77 | public: 78 | // You don't have to tell us much when we're created, but there are other 79 | // obligations that must be met. See SetSyncSource & NotifyFilterState 80 | // below. 81 | // 82 | CBaseStreamControl(); 83 | ~CBaseStreamControl(); 84 | 85 | // If you want this class to work properly, there are thing you need to 86 | // (keep) telling it. Filters with pins that use this class 87 | // should ensure that they pass through to this method any calls they 88 | // receive on their SetSyncSource. 89 | 90 | // We need a clock to see what time it is. This is for the 91 | // "discard in a timely fashion" logic. If we discard everything as 92 | // quick as possible, a whole 60 minute file could get discarded in the 93 | // first 10 seconds, and if somebody wants to turn streaming on at 30 94 | // minutes into the file, and they make the call more than a few seconds 95 | // after the graph is run, it may be too late! 96 | // So we hold every sample until it's time has gone, then we discard it. 97 | // The filter should call this when it gets a SetSyncSource 98 | // 99 | void SetSyncSource( IReferenceClock * pRefClock ) 100 | { 101 | CAutoLock lck(&m_CritSec); 102 | if (m_pRefClock) m_pRefClock->Release(); 103 | m_pRefClock = pRefClock; 104 | if (m_pRefClock) m_pRefClock->AddRef(); 105 | } 106 | 107 | // Set event sink for notifications 108 | // The filter should call this in its JoinFilterGraph after it creates the 109 | // IMediaEventSink 110 | // 111 | void SetFilterGraph( IMediaEventSink *pSink ) { 112 | m_pSink = pSink; 113 | } 114 | 115 | // Since we schedule in stream time, we need the tStart and must track the 116 | // state of our owning filter. 117 | // The app should call this ever state change 118 | // 119 | void NotifyFilterState( FILTER_STATE new_state, REFERENCE_TIME tStart = 0 ); 120 | 121 | // Filter should call Flushing(TRUE) in BeginFlush, 122 | // and Flushing(FALSE) in EndFlush. 123 | // 124 | void Flushing( BOOL bInProgress ); 125 | 126 | 127 | // The two main methods of IAMStreamControl 128 | 129 | // Class adds default values suitable for immediate 130 | // muting and unmuting of the stream. 131 | 132 | STDMETHODIMP StopAt( const REFERENCE_TIME * ptStop = NULL, 133 | BOOL bSendExtra = FALSE, 134 | DWORD dwCookie = 0 ); 135 | STDMETHODIMP StartAt( const REFERENCE_TIME * ptStart = NULL, 136 | DWORD dwCookie = 0 ); 137 | STDMETHODIMP GetInfo( AM_STREAM_INFO *pInfo); 138 | 139 | // Helper function for pin's receive method. Call this with 140 | // the sample and we'll tell you what to do with it. We'll do a 141 | // WaitForSingleObject within this call if one is required. This is 142 | // a "What should I do with this sample?" kind of call. We'll tell the 143 | // caller to either flow it or discard it. 144 | // If pSample is NULL we evaluate based on the current state 145 | // settings 146 | enum StreamControlState CheckStreamState( IMediaSample * pSample ); 147 | 148 | private: 149 | // These don't require locking, but we are relying on the fact that 150 | // m_StreamState can be retrieved with integrity, and is a snap shot that 151 | // may have just been, or may be just about to be, changed. 152 | HANDLE GetStreamEventHandle() const { return m_StreamEvent; } 153 | enum StreamControlState GetStreamState() const { return m_StreamState; } 154 | BOOL IsStreaming() const { return m_StreamState == STREAM_FLOWING; } 155 | }; 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /kkapturedll/mt_proxy_videoencoder.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" 24 | #include "mt_proxy_videoencoder.h" 25 | #include 26 | 27 | static const int MAX_QUEUED = 8; // max num of commands in queue 28 | 29 | enum QueueCommand 30 | { 31 | QC_SETSIZE, 32 | QC_WRITEFRAME, 33 | QC_SETAUDIOFORMAT, 34 | QC_WRITEAUDIOFRAME, 35 | }; 36 | 37 | struct QueueEntry 38 | { 39 | QueueEntry *next; 40 | QueueCommand cmd; 41 | const void *ptr; 42 | int para1, para2; 43 | }; 44 | 45 | struct MTProxyVideoEncoder::Internal 46 | { 47 | QueueEntry *queue_head; 48 | QueueEntry *queue_tail; 49 | CRITICAL_SECTION queue_lock; 50 | HANDLE queue_semaphore; 51 | HANDLE queue_exit; 52 | HANDLE queue_thread; 53 | WAVEFORMATEX *wfx; 54 | int xRes, yRes; 55 | VideoEncoder *actualEncoder; 56 | 57 | void QueueAppend(QueueCommand cmd, const void *ptr, int para1, int para2) 58 | { 59 | // create queue entry 60 | QueueEntry* entry = new QueueEntry; 61 | entry->next = 0; 62 | entry->cmd = cmd; 63 | entry->ptr = ptr; 64 | entry->para1 = para1; 65 | entry->para2 = para2; 66 | 67 | // wait till we can submit something again 68 | if(Real_WaitForSingleObject(queue_semaphore, 15*1000) == WAIT_TIMEOUT) 69 | { 70 | printLog("mt_proxy_encoder: couldn't add to queue within 15 seconds, giving up and dropping frame.\n"); 71 | delete entry; 72 | return; 73 | } 74 | 75 | // actually append to list 76 | Lock lock(queue_lock); 77 | if(queue_tail) 78 | { 79 | queue_tail->next = entry; 80 | queue_tail = entry; 81 | } 82 | else 83 | queue_head = queue_tail = entry; 84 | } 85 | 86 | // you need to free the QueueEntry afterwards! 87 | QueueEntry *QueuePop() 88 | { 89 | // pop entry off front of list 90 | QueueEntry *entry; 91 | { 92 | Lock lock(queue_lock); 93 | 94 | entry = queue_head; 95 | if(queue_head) 96 | queue_head = queue_head->next; 97 | 98 | if(!queue_head) 99 | queue_tail = 0; 100 | } 101 | 102 | // if we popped something, increase semaphore count 103 | if(entry) 104 | ReleaseSemaphore(queue_semaphore, 1, 0); 105 | 106 | return entry; 107 | } 108 | 109 | void QueueFree(QueueEntry *entry) 110 | { 111 | unsigned char* entryData = (unsigned char *) entry->ptr; 112 | 113 | delete[] entryData; 114 | delete entry; 115 | } 116 | }; 117 | 118 | unsigned MTProxyVideoEncoder::QueueRunner(void *para) 119 | { 120 | Internal *d = (Internal *) para; 121 | 122 | printLog("mt_proxy_encoder: queue runner started.\n"); 123 | while(Real_WaitForSingleObject(d->queue_exit,10) != WAIT_OBJECT_0) 124 | { 125 | while(QueueEntry *entry=d->QueuePop()) 126 | { 127 | switch(entry->cmd) 128 | { 129 | case QC_SETSIZE: 130 | d->actualEncoder->SetSize(entry->para1,entry->para2); 131 | break; 132 | 133 | case QC_WRITEFRAME: 134 | d->actualEncoder->WriteFrame((const unsigned char *) entry->ptr); 135 | break; 136 | 137 | case QC_SETAUDIOFORMAT: 138 | d->actualEncoder->SetAudioFormat((const tWAVEFORMATEX *) entry->ptr); 139 | break; 140 | 141 | case QC_WRITEAUDIOFRAME: 142 | d->actualEncoder->WriteAudioFrame(entry->ptr,entry->para1); 143 | break; 144 | } 145 | 146 | d->QueueFree(entry); 147 | } 148 | } 149 | 150 | printLog("mt_proxy_encoder: draining queue and exiting queue runner.\n"); 151 | while(QueueEntry *entry=d->QueuePop()) 152 | d->QueueFree(entry); 153 | 154 | return 0; 155 | } 156 | 157 | MTProxyVideoEncoder::MTProxyVideoEncoder(VideoEncoder *actual) 158 | { 159 | d = new Internal; 160 | 161 | InitializeCriticalSection(&d->queue_lock); 162 | d->queue_head = d->queue_tail = 0; 163 | d->queue_semaphore = CreateSemaphore(0, MAX_QUEUED, MAX_QUEUED, 0); 164 | d->queue_exit = CreateEvent(0,FALSE,FALSE,0); 165 | d->actualEncoder = actual; 166 | d->xRes = d->yRes = 0; 167 | 168 | d->wfx = 0; 169 | 170 | // kick off queue runner 171 | d->queue_thread = (HANDLE) _beginthreadex(0, 0, QueueRunner, d, 0, 0); 172 | } 173 | 174 | MTProxyVideoEncoder::~MTProxyVideoEncoder() 175 | { 176 | // shut down queue runner thread 177 | SetEvent(d->queue_exit); 178 | Real_WaitForSingleObject(d->queue_thread, INFINITE); 179 | 180 | // finally, clean up the rest 181 | CloseHandle(d->queue_semaphore); 182 | CloseHandle(d->queue_exit); 183 | DeleteCriticalSection(&d->queue_lock); 184 | 185 | delete[] (unsigned char*) d->wfx; 186 | delete d->actualEncoder; 187 | delete d; 188 | } 189 | 190 | void MTProxyVideoEncoder::SetSize(int xRes,int yRes) 191 | { 192 | d->QueueAppend(QC_SETSIZE, 0, xRes, yRes); 193 | d->xRes = xRes; 194 | d->yRes = yRes; 195 | } 196 | 197 | void MTProxyVideoEncoder::WriteFrame(const unsigned char *buffer) 198 | { 199 | if(d->xRes && d->yRes) 200 | d->QueueAppend(QC_WRITEFRAME,MakeCopy(buffer,d->xRes*d->yRes*3),0,0); 201 | } 202 | 203 | void MTProxyVideoEncoder::SetAudioFormat(const tWAVEFORMATEX *fmt) 204 | { 205 | d->QueueAppend(QC_SETAUDIOFORMAT,CopyFormat(fmt),0,0); 206 | 207 | delete d->wfx; 208 | d->wfx = CopyFormat(fmt); 209 | } 210 | 211 | tWAVEFORMATEX *MTProxyVideoEncoder::GetAudioFormat() 212 | { 213 | if(!d->wfx) return 0; 214 | return CopyFormat(d->wfx); 215 | } 216 | 217 | void MTProxyVideoEncoder::WriteAudioFrame(const void *buffer, int samples) 218 | { 219 | d->QueueAppend(QC_WRITEAUDIOFRAME, 220 | MakeCopy(buffer,samples*d->wfx->nBlockAlign),samples,0); 221 | } -------------------------------------------------------------------------------- /kkapturedll/video_direct3d10.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" 24 | #include "video.h" 25 | #include "videoencoder.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | static HRESULT (__stdcall *Real_CreateDXGIFactory)(REFIID riid,void **ppFactory) = 0; 33 | static HRESULT (__stdcall *Real_Factory_CreateSwapChain)(IUnknown *me,IUnknown *dev,DXGI_SWAP_CHAIN_DESC *desc,IDXGISwapChain **chain) = 0; 34 | static HRESULT (__stdcall *Real_SwapChain_Present)(IDXGISwapChain *me,UINT SyncInterval,UINT Flags) = 0; 35 | 36 | static bool grabFrameD3D10(IDXGISwapChain *swap) 37 | { 38 | ID3D10Device *device = 0; 39 | ID3D10Texture2D *tex = 0, *captureTex = 0; 40 | 41 | if (FAILED(swap->GetBuffer(0, IID_ID3D10Texture2D, (void**)&tex))) 42 | return false; 43 | 44 | D3D10_TEXTURE2D_DESC desc; 45 | tex->GetDevice(&device); 46 | tex->GetDesc(&desc); 47 | 48 | // re-creating the capture staging texture each frame is definitely not the most efficient 49 | // way to handle things, but it frees me of all kind of resource management trouble, so 50 | // here goes... 51 | desc.MipLevels = 1; 52 | desc.ArraySize = 1; 53 | desc.SampleDesc.Count = 1; 54 | desc.SampleDesc.Quality = 0; 55 | desc.Usage = D3D10_USAGE_STAGING; 56 | desc.BindFlags = 0; 57 | desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; 58 | desc.MiscFlags = 0; 59 | 60 | if(FAILED(device->CreateTexture2D(&desc,0,&captureTex))) 61 | printLog("video/d3d10: couldn't create staging texture for gpu->cpu download!\n"); 62 | else 63 | setCaptureResolution(desc.Width,desc.Height); 64 | 65 | if(device) 66 | device->CopySubresourceRegion(captureTex,0,0,0,0,tex,0,0); 67 | 68 | D3D10_MAPPED_TEXTURE2D mapped; 69 | bool grabOk = false; 70 | 71 | if(captureTex && SUCCEEDED(captureTex->Map(0,D3D10_MAP_READ,0,&mapped))) 72 | { 73 | switch(desc.Format) 74 | { 75 | case DXGI_FORMAT_R8G8B8A8_UNORM: 76 | blitAndFlipRGBAToCaptureData((unsigned char *) mapped.pData,mapped.RowPitch); 77 | grabOk = true; 78 | break; 79 | 80 | default: 81 | printLog("video/d3d10: unsupported backbuffer format, can't grab pixels!\n"); 82 | break; 83 | } 84 | 85 | captureTex->Unmap(0); 86 | } 87 | 88 | tex->Release(); 89 | if(captureTex) captureTex->Release(); 90 | if(device) device->Release(); 91 | 92 | return grabOk; 93 | } 94 | 95 | static bool grabFrameD3D11(IDXGISwapChain *swap) 96 | { 97 | ID3D11Device *device = 0; 98 | ID3D11DeviceContext *context = 0; 99 | ID3D11Texture2D *tex = 0, *captureTex = 0; 100 | 101 | if (FAILED(swap->GetBuffer(0, IID_ID3D11Texture2D, (void**)&tex))) 102 | return false; 103 | 104 | D3D11_TEXTURE2D_DESC desc; 105 | tex->GetDevice(&device); 106 | tex->GetDesc(&desc); 107 | 108 | // re-creating the capture staging texture each frame is definitely not the most efficient 109 | // way to handle things, but it frees me of all kind of resource management trouble, so 110 | // here goes... 111 | desc.MipLevels = 1; 112 | desc.ArraySize = 1; 113 | desc.SampleDesc.Count = 1; 114 | desc.SampleDesc.Quality = 0; 115 | desc.Usage = D3D11_USAGE_STAGING; 116 | desc.BindFlags = 0; 117 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; 118 | desc.MiscFlags = 0; 119 | 120 | if(FAILED(device->CreateTexture2D(&desc,0,&captureTex))) 121 | printLog("video/d3d11: couldn't create staging texture for gpu->cpu download!\n"); 122 | else 123 | setCaptureResolution(desc.Width,desc.Height); 124 | 125 | device->GetImmediateContext(&context); 126 | context->CopySubresourceRegion(captureTex,0,0,0,0,tex,0,0); 127 | 128 | D3D11_MAPPED_SUBRESOURCE mapped; 129 | bool grabOk = false; 130 | 131 | if(captureTex && SUCCEEDED(context->Map(captureTex,0,D3D11_MAP_READ,0,&mapped))) 132 | { 133 | switch(desc.Format) 134 | { 135 | case DXGI_FORMAT_R8G8B8A8_UNORM: 136 | blitAndFlipRGBAToCaptureData((unsigned char *) mapped.pData,mapped.RowPitch); 137 | grabOk = true; 138 | break; 139 | 140 | default: 141 | printLog("video/d3d11: unsupported backbuffer format, can't grab pixels!\n"); 142 | break; 143 | } 144 | 145 | context->Unmap(captureTex,0); 146 | } 147 | 148 | tex->Release(); 149 | if(captureTex) captureTex->Release(); 150 | context->Release(); 151 | device->Release(); 152 | 153 | return grabOk; 154 | } 155 | 156 | static HRESULT __stdcall Mine_SwapChain_Present(IDXGISwapChain *me,UINT SyncInterval,UINT Flags) 157 | { 158 | 159 | if(params.CaptureVideo) 160 | { 161 | if (grabFrameD3D11(me) || grabFrameD3D10(me)) 162 | encoder->WriteFrame(captureData); 163 | } 164 | 165 | HRESULT hr = Real_SwapChain_Present(me,0,Flags); 166 | 167 | nextFrame(); 168 | return hr; 169 | } 170 | 171 | static HRESULT __stdcall Mine_Factory_CreateSwapChain(IUnknown *me,IUnknown *dev,DXGI_SWAP_CHAIN_DESC *desc,IDXGISwapChain **chain) 172 | { 173 | HRESULT hr = Real_Factory_CreateSwapChain(me,dev,desc,chain); 174 | if(SUCCEEDED(hr)) 175 | { 176 | printLog("video/d3d10: swap chain created.\n"); 177 | HookCOMOnce(&Real_SwapChain_Present,*chain,8,Mine_SwapChain_Present); 178 | } 179 | 180 | return hr; 181 | } 182 | 183 | static HRESULT __stdcall Mine_CreateDXGIFactory(REFIID riid,void **ppFactory) 184 | { 185 | HRESULT hr = Real_CreateDXGIFactory(riid,ppFactory); 186 | if(SUCCEEDED(hr) && riid == IID_IDXGIFactory) 187 | HookCOMOnce(&Real_Factory_CreateSwapChain,(IUnknown *) *ppFactory,10,Mine_Factory_CreateSwapChain); 188 | 189 | return hr; 190 | } 191 | 192 | void initVideo_Direct3D10() 193 | { 194 | HMODULE dxgi = LoadLibraryA("dxgi.dll"); 195 | if(dxgi) 196 | HookDLLFunction(&Real_CreateDXGIFactory,dxgi,"CreateDXGIFactory",Mine_CreateDXGIFactory); 197 | } -------------------------------------------------------------------------------- /dshow_base/vtrans.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: VTrans.h 3 | // 4 | // Desc: DirectShow base classes - defines a video transform class. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | // This class is derived from CTransformFilter, but is specialised to handle 11 | // the requirements of video quality control by frame dropping. 12 | // This is a non-in-place transform, (i.e. it copies the data) such as a decoder. 13 | 14 | class CVideoTransformFilter : public CTransformFilter 15 | { 16 | public: 17 | 18 | CVideoTransformFilter(TCHAR *, LPUNKNOWN, REFCLSID clsid); 19 | ~CVideoTransformFilter(); 20 | HRESULT EndFlush(); 21 | 22 | // ================================================================= 23 | // ----- override these bits --------------------------------------- 24 | // ================================================================= 25 | // The following methods are in CTransformFilter which is inherited. 26 | // They are mentioned here for completeness 27 | // 28 | // These MUST be supplied in a derived class 29 | // 30 | // NOTE: 31 | // virtual HRESULT Transform(IMediaSample * pIn, IMediaSample *pOut); 32 | // virtual HRESULT CheckInputType(const CMediaType* mtIn) PURE; 33 | // virtual HRESULT CheckTransform 34 | // (const CMediaType* mtIn, const CMediaType* mtOut) PURE; 35 | // static CCOMObject * CreateInstance(LPUNKNOWN, HRESULT *); 36 | // virtual HRESULT DecideBufferSize 37 | // (IMemAllocator * pAllocator, ALLOCATOR_PROPERTIES *pprop) PURE; 38 | // virtual HRESULT GetMediaType(int iPosition, CMediaType *pMediaType) PURE; 39 | // 40 | // These MAY also be overridden 41 | // 42 | // virtual HRESULT StopStreaming(); 43 | // virtual HRESULT SetMediaType(PIN_DIRECTION direction,const CMediaType *pmt); 44 | // virtual HRESULT CheckConnect(PIN_DIRECTION dir,IPin *pPin); 45 | // virtual HRESULT BreakConnect(PIN_DIRECTION dir); 46 | // virtual HRESULT CompleteConnect(PIN_DIRECTION direction,IPin *pReceivePin); 47 | // virtual HRESULT EndOfStream(void); 48 | // virtual HRESULT BeginFlush(void); 49 | // virtual HRESULT EndFlush(void); 50 | // virtual HRESULT NewSegment 51 | // (REFERENCE_TIME tStart,REFERENCE_TIME tStop,double dRate); 52 | #ifdef PERF 53 | 54 | // If you override this - ensure that you register all these ids 55 | // as well as any of your own, 56 | virtual void RegisterPerfId() { 57 | m_idSkip = MSR_REGISTER(TEXT("Video Transform Skip frame")); 58 | m_idFrameType = MSR_REGISTER(TEXT("Video transform frame type")); 59 | m_idLate = MSR_REGISTER(TEXT("Video Transform Lateness")); 60 | m_idTimeTillKey = MSR_REGISTER(TEXT("Video Transform Estd. time to next key")); 61 | CTransformFilter::RegisterPerfId(); 62 | } 63 | #endif 64 | 65 | protected: 66 | 67 | // =========== QUALITY MANAGEMENT IMPLEMENTATION ======================== 68 | // Frames are assumed to come in three types: 69 | // Type 1: an AVI key frame or an MPEG I frame. 70 | // This frame can be decoded with no history. 71 | // Dropping this frame means that no further frame can be decoded 72 | // until the next type 1 frame. 73 | // Type 1 frames are sync points. 74 | // Type 2: an AVI non-key frame or an MPEG P frame. 75 | // This frame cannot be decoded unless the previous type 1 frame was 76 | // decoded and all type 2 frames since have been decoded. 77 | // Dropping this frame means that no further frame can be decoded 78 | // until the next type 1 frame. 79 | // Type 3: An MPEG B frame. 80 | // This frame cannot be decoded unless the previous type 1 or 2 frame 81 | // has been decoded AND the subsequent type 1 or 2 frame has also 82 | // been decoded. (This requires decoding the frames out of sequence). 83 | // Dropping this frame affects no other frames. This implementation 84 | // does not allow for these. All non-sync-point frames are treated 85 | // as being type 2. 86 | // 87 | // The spacing of frames of type 1 in a file is not guaranteed. There MUST 88 | // be a type 1 frame at (well, near) the start of the file in order to start 89 | // decoding at all. After that there could be one every half second or so, 90 | // there could be one at the start of each scene (aka "cut", "shot") or 91 | // there could be no more at all. 92 | // If there is only a single type 1 frame then NO FRAMES CAN BE DROPPED 93 | // without losing all the rest of the movie. There is no way to tell whether 94 | // this is the case, so we find that we are in the gambling business. 95 | // To try to improve the odds, we record the greatest interval between type 1s 96 | // that we have seen and we bet on things being no worse than this in the 97 | // future. 98 | 99 | // You can tell if it's a type 1 frame by calling IsSyncPoint(). 100 | // there is no architected way to test for a type 3, so you should override 101 | // the quality management here if you have B-frames. 102 | 103 | int m_nKeyFramePeriod; // the largest observed interval between type 1 frames 104 | // 1 means every frame is type 1, 2 means every other. 105 | 106 | int m_nFramesSinceKeyFrame; // Used to count frames since the last type 1. 107 | // becomes the new m_nKeyFramePeriod if greater. 108 | 109 | BOOL m_bSkipping; // we are skipping to the next type 1 frame 110 | 111 | #ifdef PERF 112 | int m_idFrameType; // MSR id Frame type. 1=Key, 2="non-key" 113 | int m_idSkip; // MSR id skipping 114 | int m_idLate; // MSR id lateness 115 | int m_idTimeTillKey; // MSR id for guessed time till next key frame. 116 | #endif 117 | 118 | virtual HRESULT StartStreaming(); 119 | 120 | HRESULT AbortPlayback(HRESULT hr); // if something bad happens 121 | 122 | HRESULT Receive(IMediaSample *pSample); 123 | 124 | HRESULT AlterQuality(Quality q); 125 | 126 | BOOL ShouldSkipFrame(IMediaSample * pIn); 127 | 128 | int m_itrLate; // lateness from last Quality message 129 | // (this overflows at 214 secs late). 130 | int m_tDecodeStart; // timeGetTime when decode started. 131 | int m_itrAvgDecode; // Average decode time in reference units. 132 | 133 | BOOL m_bNoSkip; // debug - no skipping. 134 | 135 | // We send an EC_QUALITY_CHANGE notification to the app if we have to degrade. 136 | // We send one when we start degrading, not one for every frame, this means 137 | // we track whether we've sent one yet. 138 | BOOL m_bQualityChanged; 139 | 140 | // When non-zero, don't pass anything to renderer until next keyframe 141 | // If there are few keys, give up and eventually draw something 142 | int m_nWaitForKey; 143 | }; 144 | -------------------------------------------------------------------------------- /kkapturedll/util.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" 24 | 25 | // ---- logging functions 26 | 27 | static FILE *logFile = 0; 28 | 29 | void initLog() 30 | { 31 | TCHAR logname[_MAX_PATH+32]; 32 | GetModuleFileName(GetModuleHandle(0),logname,_MAX_PATH); 33 | _tcscat_s(logname,_T(".kklog.txt")); 34 | 35 | logFile = _tfopen(logname,_T("w")); 36 | } 37 | 38 | void closeLog() 39 | { 40 | if(logFile) 41 | { 42 | fclose(logFile); 43 | logFile = 0; 44 | } 45 | } 46 | 47 | void printLog(const char *format,...) 48 | { 49 | if(logFile) 50 | { 51 | va_list arg; 52 | va_start(arg,format); 53 | vfprintf(logFile,format,arg); 54 | va_end(arg); 55 | 56 | fflush(logFile); 57 | } 58 | } 59 | 60 | void printLogHex(void *buffer,int size) 61 | { 62 | static const char hex2ch[] = "0123456789ABCDEF"; 63 | 64 | unsigned char *p = (unsigned char*) buffer; 65 | char linebuf[128]; // yes, this is enough. 66 | 67 | // process in lines of 16 bytes each 68 | while(size) 69 | { 70 | int bytes = min(size,16); 71 | memset(linebuf,' ',sizeof(linebuf)); 72 | linebuf[16*3] = '|'; 73 | 74 | // prepare hexdump of one line 75 | for(int i=0;i> 4]; 80 | linebuf[i*3+1] = hex2ch[byte & 15]; 81 | linebuf[16*3+2+i] = (byte >= 32 && byte <= 126) ? byte : '.'; 82 | } 83 | 84 | // finish and print it 85 | linebuf[16*3+2+bytes] = 0; 86 | printLog("%s\n",linebuf); 87 | 88 | p += bytes; 89 | size -= bytes; 90 | } 91 | } 92 | 93 | // ---- hooking helpers 94 | 95 | template<> bool HookFunction(void **target,void *hook) 96 | { 97 | return Mhook_SetHook(target,hook) != FALSE; 98 | } 99 | 100 | template<> bool HookFunctionInit(void **target,void *orig,void *hook) 101 | { 102 | *target = orig; 103 | return HookFunction(target,hook); 104 | } 105 | 106 | template<> bool GetDLLFunction(void **target,HMODULE module,char *name) 107 | { 108 | *target = GetProcAddress(module,name); 109 | return *target != 0; 110 | } 111 | 112 | template<> bool HookDLLFunction(void **target,HMODULE module,char *name,void *hook) 113 | { 114 | if (!GetDLLFunction(target,module,name) || !Mhook_SetHook(target,hook)) 115 | *target = 0; 116 | return *target != 0; 117 | } 118 | 119 | template<> bool HookCOM(void **target,IUnknown *obj,int vtableOffs,void *hook) 120 | { 121 | PVOID **vtblPtr = (PVOID **) obj; 122 | PVOID *vtbl = *vtblPtr; 123 | *target = vtbl[vtableOffs]; 124 | return Mhook_SetHook(target,hook) != FALSE; 125 | } 126 | 127 | template<> bool UnhookFunction(void **target) 128 | { 129 | return Mhook_Unhook(target) != FALSE; 130 | } 131 | 132 | // ---- long integer arithmetic 133 | 134 | DWORD UMulDiv(DWORD a,DWORD b,DWORD c) 135 | { 136 | __asm 137 | { 138 | mov eax, [a]; 139 | mul [b]; 140 | div [c]; 141 | mov [a], eax; 142 | } 143 | 144 | return a; 145 | } 146 | 147 | ULONGLONG ULongMulDiv(ULONGLONG a,DWORD b,DWORD c) 148 | { 149 | __asm 150 | { 151 | mov eax, dword ptr [a+4]; 152 | mul [b]; 153 | mov ecx, edx; // ecx=top 32 bits 154 | mov ebx, eax; // ebx=middle 32 bits 155 | mov eax, dword ptr [a]; 156 | mul [b]; 157 | add ebx, edx; 158 | 159 | // now eax=lower 32 bits, ebx=middle 32 bits, ecx=top 32 bits 160 | mov edx, ecx; 161 | xchg eax, ebx; 162 | div [c]; // high divide 163 | mov dword ptr [a+4], eax; 164 | mov eax, ebx; 165 | div [c]; // low divide 166 | mov dword ptr [a], eax; 167 | } 168 | 169 | return a; 170 | } 171 | 172 | // ---- really misc stuff 173 | 174 | void *MakeCopy(const void *src,int size) 175 | { 176 | unsigned char *buffer = new unsigned char[size]; 177 | memcpy(buffer,src,size); 178 | return buffer; 179 | } 180 | 181 | WAVEFORMATEX *CopyFormat(const WAVEFORMATEX *src) 182 | { 183 | if(!src) 184 | return 0; 185 | 186 | // try to simplify audio format if possible 187 | if(src->wFormatTag == WAVE_FORMAT_EXTENSIBLE) 188 | { 189 | static unsigned char WaveFormatTag[8] = { 0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71 }; 190 | 191 | WAVEFORMATEXTENSIBLE *wfe = (WAVEFORMATEXTENSIBLE *) src; 192 | if(wfe->Samples.wValidBitsPerSample == wfe->Format.wBitsPerSample 193 | && wfe->dwChannelMask == (1 << wfe->Format.nChannels)-1 194 | && wfe->SubFormat.Data1 < 0x10000 195 | && wfe->SubFormat.Data2 == 0x0000 && wfe->SubFormat.Data3 == 0x0010 196 | && memcmp(wfe->SubFormat.Data4,WaveFormatTag,8)==0) 197 | { 198 | // just drop the WAVEFORMATEXTENSIBLE part entirely 199 | WAVEFORMATEX *out = new WAVEFORMATEX; 200 | memcpy(out,src,sizeof(WAVEFORMATEX)); 201 | out->wFormatTag = (WORD) wfe->SubFormat.Data1; 202 | out->cbSize = 0; 203 | return out; 204 | } 205 | } 206 | 207 | int size = sizeof(WAVEFORMATEX)+src->cbSize; 208 | if(src->wFormatTag == WAVE_FORMAT_PCM) // a common bug is leaving cbSize uninitialized. work around it. 209 | size = sizeof(WAVEFORMATEX); 210 | 211 | // general case 212 | unsigned char *buffer = new unsigned char[size]; 213 | memcpy(buffer,src,size); 214 | 215 | // modify the format, if necessary. 216 | WAVEFORMATEX *outFmt = (WAVEFORMATEX*) buffer; 217 | if(src->wFormatTag == WAVE_FORMAT_PCM) // workaround part two 218 | outFmt->cbSize = 0; 219 | 220 | return outFmt; 221 | } 222 | 223 | WAVEFORMATEX *BounceFormat(const WAVEFORMATEX *src) 224 | { 225 | WAVEFORMATEX *out = CopyFormat(src); 226 | 227 | // downmix 32bit float data to 16bit pcm since the former is mostly unsupported 228 | if(out && out->wFormatTag == WAVE_FORMAT_IEEE_FLOAT && out->wBitsPerSample == 32) 229 | { 230 | printLog("audio: downmixing 32bit float audio to 16bit pcm\n"); 231 | 232 | out->wFormatTag = WAVE_FORMAT_PCM; 233 | out->wBitsPerSample = 16; 234 | out->nBlockAlign = out->nChannels * 2; 235 | out->nAvgBytesPerSec = out->nSamplesPerSec * out->nBlockAlign; 236 | } 237 | 238 | return out; 239 | } -------------------------------------------------------------------------------- /kkapturedll/intercept.cpp: -------------------------------------------------------------------------------- 1 | /* kkapture: intrusive demo video capturing. 2 | * Copyright (c) 2005-2010 Fabian "ryg/farbrausch" Giesen. 3 | * 4 | * This program is free software; you can redistribute and/or modify it under 5 | * the terms of the Artistic License, Version 2.0beta5, or (at your opinion) 6 | * any later version; all distributions of this program should contain this 7 | * license in a file named "LICENSE.txt". 8 | * 9 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 10 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 11 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT UNLESS REQUIRED BY 13 | * LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER OR CONTRIBUTOR 14 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 15 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 16 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | 23 | #include "stdafx.h" 24 | #include "intercept.h" 25 | #include "main.h" 26 | #include 27 | 28 | #define COUNTOF(x) (sizeof(x)/sizeof(*x)) 29 | 30 | static bool InjectDLL(HANDLE hProcess,WCHAR *dllName) 31 | { 32 | WCHAR name[2048]; // one page 33 | void *workArea; 34 | void *loadLibrary = GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"LoadLibraryW"); 35 | 36 | // Copy DLL name over 37 | int len = 0; 38 | while(dllName[len]) 39 | { 40 | name[len] = dllName[len]; 41 | if(++len == COUNTOF(name)) // DLL name is too long 42 | return false; 43 | } 44 | 45 | name[len] = 0; // zero-terminate 46 | 47 | // Write DLL name into process memory and generate LoadLibraryW call via CreateRemoteThread 48 | return (workArea = VirtualAllocEx(hProcess,0,4096,MEM_COMMIT,PAGE_READWRITE)) 49 | && WriteProcessMemory(hProcess,workArea,name,sizeof(name),0) 50 | && CreateRemoteThread(hProcess,NULL,0,(LPTHREAD_START_ROUTINE) loadLibrary,workArea,0,0); 51 | } 52 | 53 | static void __cdecl WaitProcessThreadProc(void *arg) 54 | { 55 | // just wait for the process to exit 56 | WaitForSingleObject((HANDLE) arg,INFINITE); 57 | } 58 | 59 | static BOOL (__stdcall *Real_CreateProcessA)(LPCSTR appName,LPSTR cmdLine,LPSECURITY_ATTRIBUTES processAttr,LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags,LPVOID env,LPCSTR currentDir,LPSTARTUPINFOA startupInfo,LPPROCESS_INFORMATION processInfo) = CreateProcessA; 60 | static BOOL (__stdcall *Real_CreateProcessW)(LPCWSTR appName,LPWSTR cmdLine,LPSECURITY_ATTRIBUTES processAttr,LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags,LPVOID env,LPCWSTR currentDir,LPSTARTUPINFOW startupInfo,LPPROCESS_INFORMATION processInfo) = CreateProcessW; 61 | 62 | static BOOL __stdcall Mine_CreateProcessA(LPCSTR appName,LPSTR cmdLine,LPSECURITY_ATTRIBUTES processAttr, 63 | LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags,LPVOID env,LPCSTR currentDir, 64 | LPSTARTUPINFOA startupInfo,LPPROCESS_INFORMATION processInfo) 65 | { 66 | PROCESS_INFORMATION localInfo; 67 | PROCESS_INFORMATION *pi = processInfo; 68 | 69 | // we always need a process info. 70 | if(!pi) 71 | { 72 | ZeroMemory(&localInfo,sizeof(localInfo)); 73 | pi = &localInfo; 74 | } 75 | 76 | printLog("system: launching process \"%s\" with command line \"%s\"\n",appName,cmdLine); 77 | int err = CreateInstrumentedProcessA(appName,cmdLine,processAttr,threadAttr,TRUE, 78 | flags,env,currentDir,startupInfo,pi); 79 | 80 | if(err == ERR_OK) 81 | { 82 | // spawn the "wait for exit" thread for the called process 83 | // we need this because otherwise kkapture.exe might quit if this process decides to 84 | // exit soon afterwards, losing the parameter block in the process. 85 | _beginthread(WaitProcessThreadProc,65536,(void*)pi->hProcess); 86 | } 87 | 88 | return err == ERR_OK; 89 | } 90 | 91 | static BOOL __stdcall Mine_CreateProcessW(LPCWSTR appName,LPWSTR cmdLine,LPSECURITY_ATTRIBUTES processAttr, 92 | LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags,LPVOID env,LPCWSTR currentDir, 93 | LPSTARTUPINFOW startupInfo,LPPROCESS_INFORMATION processInfo) 94 | { 95 | PROCESS_INFORMATION localInfo; 96 | PROCESS_INFORMATION *pi = processInfo; 97 | 98 | // we always need a process info. 99 | if(!pi) 100 | { 101 | ZeroMemory(&localInfo,sizeof(localInfo)); 102 | pi = &localInfo; 103 | } 104 | 105 | printLog("system: launching process \"%S\" with command line \"%S\"\n",appName,cmdLine); 106 | int err = CreateInstrumentedProcessW(appName,cmdLine,processAttr,threadAttr,TRUE, 107 | flags,env,currentDir,startupInfo,pi); 108 | 109 | if(err == ERR_OK) 110 | { 111 | // spawn the "wait for exit" thread for the called process 112 | // we need this because otherwise kkapture.exe might quit if this process decides to 113 | // exit soon afterwards, losing the parameter block in the process. 114 | _beginthread(WaitProcessThreadProc,65536,(void*)pi->hProcess); 115 | } 116 | 117 | return err == ERR_OK; 118 | } 119 | 120 | static int FinishCreateInstrumentedProcess(LPPROCESS_INFORMATION pi,WCHAR *dllPath,DWORD flags) 121 | { 122 | // inject our DLL into the target process 123 | if(InjectDLL(pi->hProcess,dllPath)) 124 | { 125 | // we're done with our evil machinations, so let the process run 126 | if(!(flags & CREATE_SUSPENDED)) 127 | ResumeThread(pi->hThread); 128 | 129 | return ERR_OK; 130 | } 131 | else 132 | { 133 | TerminateProcess(pi->hProcess,0); 134 | return ERR_INSTRUMENTATION_FAILED; 135 | } 136 | } 137 | 138 | int CreateInstrumentedProcessA(LPCSTR appName,LPSTR cmdLine, 139 | LPSECURITY_ATTRIBUTES processAttr,LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags, 140 | LPVOID env,LPCSTR currentDir,LPSTARTUPINFOA startupInfo,LPPROCESS_INFORMATION pi) 141 | { 142 | // get dll path 143 | WCHAR dllPath[_MAX_PATH]; 144 | GetModuleFileNameW((HMODULE) hModule,dllPath,_MAX_PATH); 145 | 146 | // actual process creation 147 | if(Real_CreateProcessA(appName,cmdLine,processAttr,threadAttr,inheritHandles,flags|CREATE_SUSPENDED, 148 | env,currentDir,startupInfo,pi)) 149 | { 150 | return FinishCreateInstrumentedProcess(pi,dllPath,flags); 151 | } 152 | else 153 | { 154 | if(pi) pi->hProcess = INVALID_HANDLE_VALUE; 155 | return ERR_COULDNT_EXECUTE; 156 | } 157 | } 158 | 159 | 160 | int CreateInstrumentedProcessW(LPCWSTR appName,LPWSTR cmdLine, 161 | LPSECURITY_ATTRIBUTES processAttr,LPSECURITY_ATTRIBUTES threadAttr,BOOL inheritHandles,DWORD flags, 162 | LPVOID env,LPCWSTR currentDir,LPSTARTUPINFOW startupInfo,LPPROCESS_INFORMATION pi) 163 | { 164 | // get dll path 165 | WCHAR dllPath[_MAX_PATH]; 166 | GetModuleFileNameW((HMODULE) hModule,dllPath,_MAX_PATH); 167 | 168 | // actual process creation 169 | if(Real_CreateProcessW(appName,cmdLine,processAttr,threadAttr,inheritHandles,flags|CREATE_SUSPENDED, 170 | env,currentDir,startupInfo,pi)) 171 | { 172 | return FinishCreateInstrumentedProcess(pi,dllPath,flags); 173 | } 174 | else 175 | { 176 | if(pi) pi->hProcess = INVALID_HANDLE_VALUE; 177 | return ERR_COULDNT_EXECUTE; 178 | } 179 | } 180 | 181 | void initProcessIntercept() 182 | { 183 | HookFunction(&Real_CreateProcessA,Mine_CreateProcessA); 184 | HookFunction(&Real_CreateProcessW,Mine_CreateProcessW); 185 | } -------------------------------------------------------------------------------- /dshow_base/refclock.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: RefClock.h 3 | // 4 | // Desc: DirectShow base classes - defines the IReferenceClock interface. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __BASEREFCLOCK__ 11 | #define __BASEREFCLOCK__ 12 | 13 | #include "dsschedule.h" 14 | 15 | const UINT RESOLUTION = 1; /* High resolution timer */ 16 | const INT ADVISE_CACHE = 4; /* Default cache size */ 17 | const LONGLONG MAX_TIME = 0x7FFFFFFFFFFFFFFF; /* Maximum LONGLONG value */ 18 | 19 | inline LONGLONG WINAPI ConvertToMilliseconds(const REFERENCE_TIME& RT) 20 | { 21 | /* This converts an arbitrary value representing a reference time 22 | into a MILLISECONDS value for use in subsequent system calls */ 23 | 24 | return (RT / (UNITS / MILLISECONDS)); 25 | } 26 | 27 | /* This class hierarchy will support an IReferenceClock interface so 28 | that an audio card (or other externally driven clock) can update the 29 | system wide clock that everyone uses. 30 | 31 | The interface will be pretty thin with probably just one update method 32 | This interface has not yet been defined. 33 | */ 34 | 35 | /* This abstract base class implements the IReferenceClock 36 | * interface. Classes that actually provide clock signals (from 37 | * whatever source) have to be derived from this class. 38 | * 39 | * The abstract class provides implementations for: 40 | * CUnknown support 41 | * locking support (CCritSec) 42 | * client advise code (creates a thread) 43 | * 44 | * Question: what can we do about quality? Change the timer 45 | * resolution to lower the system load? Up the priority of the 46 | * timer thread to force more responsive signals? 47 | * 48 | * During class construction we create a worker thread that is destroyed during 49 | * destuction. This thread executes a series of WaitForSingleObject calls, 50 | * waking up when a command is given to the thread or the next wake up point 51 | * is reached. The wakeup points are determined by clients making Advise 52 | * calls. 53 | * 54 | * Each advise call defines a point in time when they wish to be notified. A 55 | * periodic advise is a series of these such events. We maintain a list of 56 | * advise links and calculate when the nearest event notification is due for. 57 | * We then call WaitForSingleObject with a timeout equal to this time. The 58 | * handle we wait on is used by the class to signal that something has changed 59 | * and that we must reschedule the next event. This typically happens when 60 | * someone comes in and asks for an advise link while we are waiting for an 61 | * event to timeout. 62 | * 63 | * While we are modifying the list of advise requests we 64 | * are protected from interference through a critical section. Clients are NOT 65 | * advised through callbacks. One shot clients have an event set, while 66 | * periodic clients have a semaphore released for each event notification. A 67 | * semaphore allows a client to be kept up to date with the number of events 68 | * actually triggered and be assured that they can't miss multiple events being 69 | * set. 70 | * 71 | * Keeping track of advises is taken care of by the CAMSchedule class. 72 | */ 73 | 74 | class CBaseReferenceClock 75 | : public CUnknown, public IReferenceClock, public CCritSec 76 | { 77 | protected: 78 | virtual ~CBaseReferenceClock(); // Don't let me be created on the stack! 79 | public: 80 | CBaseReferenceClock(TCHAR *pName, LPUNKNOWN pUnk, HRESULT *phr, CAMSchedule * pSched = 0 ); 81 | 82 | STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,void ** ppv); 83 | 84 | DECLARE_IUNKNOWN 85 | 86 | /* IReferenceClock methods */ 87 | // Derived classes must implement GetPrivateTime(). All our GetTime 88 | // does is call GetPrivateTime and then check so that time does not 89 | // go backwards. A return code of S_FALSE implies that the internal 90 | // clock has gone backwards and GetTime time has halted until internal 91 | // time has caught up. (Don't know if this will be much use to folk, 92 | // but it seems odd not to use the return code for something useful.) 93 | STDMETHODIMP GetTime(REFERENCE_TIME *pTime); 94 | // When this is called, it sets m_rtLastGotTime to the time it returns. 95 | 96 | /* Provide standard mechanisms for scheduling events */ 97 | 98 | /* Ask for an async notification that a time has elapsed */ 99 | STDMETHODIMP AdviseTime( 100 | REFERENCE_TIME baseTime, // base reference time 101 | REFERENCE_TIME streamTime, // stream offset time 102 | HEVENT hEvent, // advise via this event 103 | DWORD_PTR *pdwAdviseCookie // where your cookie goes 104 | ); 105 | 106 | /* Ask for an asynchronous periodic notification that a time has elapsed */ 107 | STDMETHODIMP AdvisePeriodic( 108 | REFERENCE_TIME StartTime, // starting at this time 109 | REFERENCE_TIME PeriodTime, // time between notifications 110 | HSEMAPHORE hSemaphore, // advise via a semaphore 111 | DWORD_PTR *pdwAdviseCookie // where your cookie goes 112 | ); 113 | 114 | /* Cancel a request for notification(s) - if the notification was 115 | * a one shot timer then this function doesn't need to be called 116 | * as the advise is automatically cancelled, however it does no 117 | * harm to explicitly cancel a one-shot advise. It is REQUIRED that 118 | * clients call Unadvise to clear a Periodic advise setting. 119 | */ 120 | 121 | STDMETHODIMP Unadvise(DWORD_PTR dwAdviseCookie); 122 | 123 | /* Methods for the benefit of derived classes or outer objects */ 124 | 125 | // GetPrivateTime() is the REAL clock. GetTime is just a cover for 126 | // it. Derived classes will probably override this method but not 127 | // GetTime() itself. 128 | // The important point about GetPrivateTime() is it's allowed to go 129 | // backwards. Our GetTime() will keep returning the LastGotTime 130 | // until GetPrivateTime() catches up. 131 | virtual REFERENCE_TIME GetPrivateTime(); 132 | 133 | /* Provide a method for correcting drift */ 134 | STDMETHODIMP SetTimeDelta( const REFERENCE_TIME& TimeDelta ); 135 | 136 | CAMSchedule * GetSchedule() const { return m_pSchedule; } 137 | 138 | private: 139 | REFERENCE_TIME m_rtPrivateTime; // Current best estimate of time 140 | DWORD m_dwPrevSystemTime; // Last vaule we got from timeGetTime 141 | REFERENCE_TIME m_rtLastGotTime; // Last time returned by GetTime 142 | REFERENCE_TIME m_rtNextAdvise; // Time of next advise 143 | UINT m_TimerResolution; 144 | 145 | #ifdef PERF 146 | int m_idGetSystemTime; 147 | #endif 148 | 149 | // Thread stuff 150 | public: 151 | void TriggerThread() // Wakes thread up. Need to do this if 152 | { // time to next advise needs reevaluating. 153 | EXECUTE_ASSERT(SetEvent(m_pSchedule->GetEvent())); 154 | } 155 | 156 | 157 | private: 158 | BOOL m_bAbort; // Flag used for thread shutdown 159 | HANDLE m_hThread; // Thread handle 160 | 161 | HRESULT AdviseThread(); // Method in which the advise thread runs 162 | static DWORD __stdcall AdviseThreadFunction(LPVOID); // Function used to get there 163 | 164 | protected: 165 | CAMSchedule * const m_pSchedule; 166 | 167 | void Restart (IN REFERENCE_TIME rtMinTime = 0I64) ; 168 | }; 169 | 170 | #endif 171 | 172 | -------------------------------------------------------------------------------- /kkapturedll/disasm-lib/cpu.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003, Matt Conover (mconover@gmail.com) 2 | #ifndef CPU_H 3 | #define CPU_H 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | #pragma pack(push,1) 8 | 9 | #include 10 | #include "misc.h" 11 | 12 | //////////////////////////////////////////////////////// 13 | // System descriptors 14 | //////////////////////////////////////////////////////// 15 | 16 | #define GDT_NULL 0 17 | #define GDT_R0_CODE 0x08 18 | #define GDT_R0_DATA 0x10 19 | #define GDT_R3_CODE 0x18 20 | #define GDT_R3_DATA 0x20 21 | #define GDT_TSS 0x28 22 | #define GDT_PCR 0x30 23 | #define GDT_R3_TEB 0x38 24 | #define GDT_VDM 0x40 25 | #define GDT_LDT 0x48 26 | #define GDT_DOUBLEFAULT_TSS 0x50 27 | #define GDT_NMI_TSS 0x58 28 | 29 | // 16-bit GDT entries: 30 | // TODO: #define GDT_ABIOS_UNKNOWN 0x60 (22F30-32F2F) 31 | #define GDT_ABIOS_VIDEO 0x68 32 | #define GDT_ABIOS_GDT 0x70 // descriptor describing ABIOS GDT itself 33 | #define GDT_ABIOS_NTOS 0x78 // first 64K of NTOSKRNL 34 | #define GDT_ABIOS_CDA 0xE8 // common data area 35 | #define GDT_ABIOS_CODE 0xF0 // KiI386AbiosCall 36 | #define GDT_ABIOS_STACK 0xF8 37 | 38 | #define SELECTOR_RPL_MASK 0x03 // bits 0-1 39 | #define SELECTOR_LDT 0x04 // bit 2 40 | 41 | // for data selectors 42 | #define DATA_ACCESS_MASK (1<<0) 43 | #define DATA_WRITE_ENABLE_MASK (1<<1) 44 | #define DATA_EXPAND_DOWN_MASK (1<<2) 45 | 46 | // for code selectors 47 | #define CODE_ACCESS_MASK (1<<0) 48 | #define CODE_READ_MASK (1<<1) 49 | #define CODE_CONFORMING_MASK (1<<2) 50 | #define CODE_FLAG (1<<3) 51 | 52 | #define TASK_GATE 5 53 | #define INTERRUPT_GATE 6 54 | #define TRAP_GATE 7 55 | 56 | typedef struct _IDT_ENTRY 57 | { 58 | USHORT LowOffset; 59 | USHORT Selector; 60 | UCHAR Ignored : 5; 61 | UCHAR Zero : 3; 62 | UCHAR Type : 3; 63 | UCHAR Is32Bit : 1; 64 | UCHAR Ignored2 : 1; 65 | UCHAR DPL : 2; 66 | UCHAR Present : 1; 67 | USHORT HighOffset; 68 | #ifdef _WIN64 69 | ULONG HighOffset64; 70 | ULONG Reserved; 71 | #endif 72 | } IDT_ENTRY, TRAP_GATE_ENTRY; 73 | 74 | typedef struct _CALL_GATE_ENTRY 75 | { 76 | USHORT LowOffset; 77 | USHORT Selector; 78 | UCHAR ParameterCount: 4; 79 | UCHAR Ignored : 3; 80 | UCHAR Type : 5; 81 | UCHAR DPL : 2; 82 | UCHAR Present : 1; 83 | USHORT HighOffset; 84 | #ifdef _WIN64 85 | ULONG HighOffset64; 86 | ULONG Reserved; 87 | #endif 88 | } CALL_GATE_ENTRY; 89 | 90 | typedef struct _TASK_GATE_ENTRY 91 | { 92 | USHORT Ignored; 93 | USHORT Selector; 94 | UCHAR Ignored2 : 5; 95 | UCHAR Zero : 3; 96 | UCHAR Type : 5; 97 | UCHAR DPL : 2; 98 | UCHAR Present : 1; 99 | USHORT Ignored3; 100 | } TASK_GATE_ENTRY; 101 | 102 | typedef struct _DESCRIPTOR_ENTRY 103 | { 104 | USHORT LimitLow; 105 | USHORT BaseLow; 106 | UCHAR BaseMid; 107 | UCHAR Type : 4; // 10EWA (code), E=ExpandDown, W=Writable, A=Accessed 108 | // 11CRA (data), C=Conforming, R=Readable, A=Accessed 109 | UCHAR System : 1; // if 1 then it is a gate or LDT 110 | UCHAR DPL : 2; // descriptor privilege level; 111 | // for data selectors, MAX(CPL, RPL) must be <= DPL to access (or else GP# fault) 112 | // for non-conforming code selectors (without callgate), MAX(CPL, RPL) must be <= DPL to access (or else GP# fault) 113 | // for conforming code selectors, MAX(CPL, RPL) must be >= DPL (i.e., CPL 0-2 cannot access if DPL is 3) 114 | // for non-conforming code selectors (with call gate), DPL indicates lowest privilege allowed to access gate 115 | UCHAR Present : 1; 116 | UCHAR LimitHigh : 4; 117 | UCHAR Available: 1; // aka AVL 118 | UCHAR Reserved : 1; 119 | UCHAR Is32Bit : 1; // aka B flag 120 | UCHAR Granularity : 1; // aka G flag 121 | UCHAR BaseHi : 8; 122 | #ifdef _WIN64 123 | ULONG HighOffset64; 124 | ULONG Reserved2; 125 | #endif 126 | } DESCRIPTOR_ENTRY; 127 | 128 | typedef struct _GATE_ENTRY 129 | { 130 | USHORT LowOffset; 131 | UCHAR Skip; 132 | UCHAR Type : 5; 133 | UCHAR DPL : 2; 134 | UCHAR Present : 1; 135 | USHORT HighOffset; 136 | #ifdef _WIN64 137 | ULONG HighOffset64; 138 | ULONG Reserved; 139 | #endif 140 | } GATE_ENTRY; 141 | 142 | // TODO: update for X64 143 | typedef struct _PTE_ENTRY 144 | { 145 | ULONG Present : 1; 146 | ULONG Write : 1; 147 | ULONG Owner : 1; // E.g., user mode or supervisor mode 148 | ULONG WriteThrough : 1; 149 | ULONG CacheDisable : 1; 150 | ULONG Accessed : 1; 151 | ULONG Dirty : 1; 152 | ULONG PAT : 1; 153 | ULONG Global : 1; 154 | ULONG CopyOnWrite : 1; 155 | ULONG Prototype : 1; 156 | ULONG Transition : 1; 157 | ULONG Address : 20; 158 | } PTE_ENTRY; 159 | 160 | // TODO: update for X64 161 | typedef struct _PDE_ENTRY 162 | { 163 | ULONG Present : 1; 164 | ULONG Write : 1; 165 | ULONG Owner : 1; 166 | ULONG WriteThrough : 1; 167 | ULONG CacheDisable : 1; 168 | ULONG Accessed : 1; 169 | ULONG Reserved1 : 1; 170 | ULONG PageSize : 1; 171 | ULONG Global : 1; 172 | ULONG Reserved : 3; 173 | ULONG Address : 20; 174 | } PDE_ENTRY; 175 | 176 | // TODO: update for X64 177 | typedef struct _IO_ACCESS_MAP 178 | { 179 | UCHAR DirectionMap[32]; 180 | UCHAR IoMap[8196]; 181 | } IO_ACCESS_MAP; 182 | 183 | #define MIN_TSS_SIZE FIELD_OFFSET(TSS_ENTRY, IoMaps) 184 | // TODO: update for X64 185 | typedef struct _TSS_ENTRY 186 | { 187 | USHORT Backlink; 188 | USHORT Reserved0; 189 | ULONG Esp0; 190 | USHORT Ss0; 191 | USHORT Reserved1; 192 | ULONG NotUsed1[4]; 193 | ULONG CR3; 194 | ULONG Eip; 195 | ULONG NotUsed2[9]; 196 | USHORT Es; 197 | USHORT Reserved2; 198 | USHORT Cs; 199 | USHORT Reserved3; 200 | USHORT Ss; 201 | USHORT Reserved4; 202 | USHORT Ds; 203 | USHORT Reserved5; 204 | USHORT Fs; 205 | USHORT Reserved6; 206 | USHORT Gs; 207 | USHORT Reserved7; 208 | USHORT LDT; 209 | USHORT Reserved8; 210 | USHORT Flags; 211 | USHORT IoMapBase; 212 | IO_ACCESS_MAP IoMaps[1]; 213 | UCHAR IntDirectionMap[32]; 214 | } TSS_ENTRY; 215 | 216 | // TODO: update for X64 217 | typedef struct _TSS16_ENTRY 218 | { 219 | USHORT Backlink; 220 | USHORT Sp0; 221 | USHORT Ss0; 222 | USHORT Sp1; 223 | USHORT Ss1; 224 | USHORT Sp2; 225 | USHORT Ss3; 226 | USHORT Ip; 227 | USHORT Flags; 228 | USHORT Ax; 229 | USHORT Cx; 230 | USHORT Dx; 231 | USHORT Bx; 232 | USHORT Sp; 233 | USHORT Bp; 234 | USHORT Si; 235 | USHORT Di; 236 | USHORT Es; 237 | USHORT Cs; 238 | USHORT Ss; 239 | USHORT Ds; 240 | USHORT LDT; 241 | } TSS16_ENTRY; 242 | 243 | // TODO: update for X64 244 | typedef struct _GDT_ENTRY 245 | { 246 | USHORT LimitLow; 247 | USHORT BaseLow; 248 | union { 249 | struct { 250 | UCHAR BaseMid; 251 | UCHAR Flags1; 252 | UCHAR Flags2; 253 | UCHAR BaseHi; 254 | } Bytes; 255 | struct { 256 | ULONG BaseMid : 8; 257 | ULONG Type : 5; 258 | ULONG Dpl : 2; 259 | ULONG Pres : 1; 260 | ULONG LimitHi : 4; 261 | ULONG Sys : 1; 262 | ULONG Reserved_0 : 1; 263 | ULONG Default_Big : 1; 264 | ULONG Granularity : 1; 265 | ULONG BaseHi : 8; 266 | } Bits; 267 | } HighWord; 268 | } GDT_ENTRY; 269 | 270 | BYTE *GetAbsoluteAddressFromSegment(BYTE Segment, DWORD Offset); 271 | BYTE *GetAbsoluteAddressFromSelector(WORD Selector, DWORD Offset); 272 | 273 | #pragma pack(pop) 274 | #ifdef __cplusplus 275 | } 276 | #endif 277 | #endif // CPU_H -------------------------------------------------------------------------------- /dshow_base/streams.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: Streams.h 3 | // 4 | // Desc: DirectShow base classes - defines overall streams architecture. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __STREAMS__ 11 | #define __STREAMS__ 12 | 13 | #ifdef _MSC_VER 14 | // disable some level-4 warnings, use #pragma warning(enable:###) to re-enable 15 | #pragma warning(disable:4100) // warning C4100: unreferenced formal parameter 16 | #pragma warning(disable:4127) // warning C4127: conditional expression is constant 17 | #pragma warning(disable:4189) // warning C4189: local variable is initialized but not referenced 18 | #pragma warning(disable:4201) // warning C4201: nonstandard extension used : nameless struct/union 19 | #pragma warning(disable:4511) // warning C4511: copy constructor could not be generated 20 | #pragma warning(disable:4512) // warning C4512: assignment operator could not be generated 21 | #pragma warning(disable:4514) // warning C4514: unreferenced inline function has been removed 22 | #pragma warning(disable:4710) // warning C4710: 'function' not inlined 23 | 24 | #if _MSC_VER>=1100 25 | #define AM_NOVTABLE __declspec(novtable) 26 | #else 27 | #define AM_NOVTABLE 28 | #endif 29 | #endif // MSC_VER 30 | 31 | // Because of differences between Visual C++ and older Microsoft SDKs, 32 | // you may have defined _DEBUG without defining DEBUG. This logic 33 | // ensures that both will be set if Visual C++ sets _DEBUG. 34 | #ifdef _DEBUG 35 | #ifndef DEBUG 36 | #define DEBUG 37 | #endif 38 | #endif 39 | 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | // Disable warning message for C4201 - use of nameless struct/union 47 | // Otherwise, strmif.h will generate warnings for Win32 debug builds 48 | #pragma warning( disable : 4201 ) 49 | 50 | #include 51 | 52 | #ifndef NUMELMS 53 | #define NUMELMS(aa) (sizeof(aa)/sizeof((aa)[0])) 54 | #endif 55 | 56 | /////////////////////////////////////////////////////////////////////////// 57 | // The following definitions come from the Platform SDK and are required if 58 | // the applicaiton is being compiled with the headers from Visual C++ 6.0. 59 | /////////////////////////////////////////////////////////////////////////// 60 | #ifndef InterlockedExchangePointer 61 | #define InterlockedExchangePointer(Target, Value) \ 62 | (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value)) 63 | #endif 64 | 65 | #ifndef _WAVEFORMATEXTENSIBLE_ 66 | #define _WAVEFORMATEXTENSIBLE_ 67 | typedef struct { 68 | WAVEFORMATEX Format; 69 | union { 70 | WORD wValidBitsPerSample; /* bits of precision */ 71 | WORD wSamplesPerBlock; /* valid if wBitsPerSample==0 */ 72 | WORD wReserved; /* If neither applies, set to zero. */ 73 | } Samples; 74 | DWORD dwChannelMask; /* which channels are */ 75 | /* present in stream */ 76 | GUID SubFormat; 77 | } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE; 78 | #endif // !_WAVEFORMATEXTENSIBLE_ 79 | 80 | #if !defined(WAVE_FORMAT_EXTENSIBLE) 81 | #define WAVE_FORMAT_EXTENSIBLE 0xFFFE 82 | #endif // !defined(WAVE_FORMAT_EXTENSIBLE) 83 | 84 | #ifndef GetWindowLongPtr 85 | #define GetWindowLongPtrA GetWindowLongA 86 | #define GetWindowLongPtrW GetWindowLongW 87 | #ifdef UNICODE 88 | #define GetWindowLongPtr GetWindowLongPtrW 89 | #else 90 | #define GetWindowLongPtr GetWindowLongPtrA 91 | #endif // !UNICODE 92 | #endif // !GetWindowLongPtr 93 | 94 | #ifndef SetWindowLongPtr 95 | #define SetWindowLongPtrA SetWindowLongA 96 | #define SetWindowLongPtrW SetWindowLongW 97 | #ifdef UNICODE 98 | #define SetWindowLongPtr SetWindowLongPtrW 99 | #else 100 | #define SetWindowLongPtr SetWindowLongPtrA 101 | #endif // !UNICODE 102 | #endif // !SetWindowLongPtr 103 | 104 | #ifndef GWLP_WNDPROC 105 | #define GWLP_WNDPROC (-4) 106 | #endif 107 | #ifndef GWLP_HINSTANCE 108 | #define GWLP_HINSTANCE (-6) 109 | #endif 110 | #ifndef GWLP_HWNDPARENT 111 | #define GWLP_HWNDPARENT (-8) 112 | #endif 113 | #ifndef GWLP_USERDATA 114 | #define GWLP_USERDATA (-21) 115 | #endif 116 | #ifndef GWLP_ID 117 | #define GWLP_ID (-12) 118 | #endif 119 | #ifndef DWLP_MSGRESULT 120 | #define DWLP_MSGRESULT 0 121 | #endif 122 | #ifndef DWLP_DLGPROC 123 | #define DWLP_DLGPROC DWLP_MSGRESULT + sizeof(LRESULT) 124 | #endif 125 | #ifndef DWLP_USER 126 | #define DWLP_USER DWLP_DLGPROC + sizeof(DLGPROC) 127 | #endif 128 | /////////////////////////////////////////////////////////////////////////// 129 | // End Platform SDK definitions 130 | /////////////////////////////////////////////////////////////////////////// 131 | 132 | 133 | #pragma warning(disable:4201) // warning C4201: nonstandard extension used : nameless struct/union 134 | #include // Generated IDL header file for streams interfaces 135 | 136 | #include // Helper class for REFERENCE_TIME management 137 | #include // Debug support for logging and ASSERTs 138 | #include // ActiveMovie video interfaces and definitions 139 | //include amaudio.h explicitly if you need it. it requires the DirectX SDK. 140 | //#include // ActiveMovie audio interfaces and definitions 141 | #include // General helper classes for threads etc 142 | #include // Base COM classes to support IUnknown 143 | #include // Filter registration support functions 144 | #include // Performance measurement 145 | #include // Light weight com function prototypes 146 | 147 | #include // Simple cache container class 148 | #include // Non MFC generic list class 149 | #include // CMsgThread 150 | #include // Helper class for managing media types 151 | #include // conversions between FOURCCs and GUIDs 152 | #include // generated from control.odl 153 | #include // control interface utility classes 154 | #include // event code definitions 155 | #include // Main streams architecture class hierachy 156 | #include // Generic transform filter 157 | #include // Generic transform-in-place filter 158 | #include // declaration of type GUIDs and well-known clsids 159 | #include // Generic source filter 160 | #include // Output pin queueing 161 | #include // HRESULT status and error definitions 162 | #include // Base class for writing ActiveX renderers 163 | #include // Helps with filters that manage windows 164 | #include // Implements the IVideoWindow interface 165 | #include // Specifically video related classes 166 | #include // Base clock class 167 | #include // System clock 168 | #include // IPersistStream helper class 169 | #include // Video Transform Filter base class 170 | #include 171 | #include // Base property page class 172 | #include // IAMStreamControl support 173 | #include // External device control interface defines 174 | #include // audio filter device error event codes 175 | 176 | #include 177 | 178 | #define NO_SHLWAPI_STRFCNS 179 | #include 180 | #include 181 | 182 | #ifndef NUMELMS 183 | #define NUMELMS(aa) (sizeof(aa)/sizeof((aa)[0])) 184 | #endif 185 | 186 | #else 187 | #ifdef DEBUG 188 | #pragma message("STREAMS.H included TWICE") 189 | #endif 190 | #endif // __STREAMS__ 191 | 192 | -------------------------------------------------------------------------------- /dshow_base/videoctl.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // File: VideoCtl.h 3 | // 4 | // Desc: DirectShow base classes. 5 | // 6 | // Copyright (c) Microsoft Corporation. All rights reserved. 7 | //------------------------------------------------------------------------------ 8 | 9 | 10 | #ifndef __VIDEOCTL__ 11 | #define __VIDEOCTL__ 12 | 13 | // These help with property page implementations. The first can be used to 14 | // load any string from a resource file. The buffer to load into is passed 15 | // as an input parameter. The same buffer is the return value if the string 16 | // was found otherwise it returns TEXT(""). The GetDialogSize is passed the 17 | // resource ID of a dialog box and returns the size of it in screen pixels 18 | 19 | #define STR_MAX_LENGTH 256 20 | TCHAR * WINAPI StringFromResource(TCHAR *pBuffer, int iResourceID); 21 | 22 | #ifdef UNICODE 23 | #define WideStringFromResource StringFromResource 24 | char* WINAPI StringFromResource(char*pBuffer, int iResourceID); 25 | #else 26 | WCHAR * WINAPI WideStringFromResource(WCHAR *pBuffer, int iResourceID); 27 | #endif 28 | 29 | 30 | BOOL WINAPI GetDialogSize(int iResourceID, // Dialog box resource identifier 31 | DLGPROC pDlgProc, // Pointer to dialog procedure 32 | LPARAM lParam, // Any user data wanted in pDlgProc 33 | SIZE *pResult); // Returns the size of dialog box 34 | 35 | // Class that aggregates an IDirectDraw interface 36 | 37 | class CAggDirectDraw : public IDirectDraw, public CUnknown 38 | { 39 | protected: 40 | 41 | LPDIRECTDRAW m_pDirectDraw; 42 | 43 | public: 44 | 45 | DECLARE_IUNKNOWN 46 | STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,void **ppv); 47 | 48 | // Constructor and destructor 49 | 50 | CAggDirectDraw(TCHAR *pName,LPUNKNOWN pUnk) : 51 | CUnknown(pName,pUnk), 52 | m_pDirectDraw(NULL) { }; 53 | 54 | virtual CAggDirectDraw::~CAggDirectDraw() { }; 55 | 56 | // Set the object we should be aggregating 57 | void SetDirectDraw(LPDIRECTDRAW pDirectDraw) { 58 | m_pDirectDraw = pDirectDraw; 59 | } 60 | 61 | // IDirectDraw methods 62 | 63 | STDMETHODIMP Compact(); 64 | STDMETHODIMP CreateClipper(DWORD dwFlags,LPDIRECTDRAWCLIPPER *lplpDDClipper,IUnknown *pUnkOuter); 65 | STDMETHODIMP CreatePalette(DWORD dwFlags,LPPALETTEENTRY lpColorTable,LPDIRECTDRAWPALETTE *lplpDDPalette,IUnknown *pUnkOuter); 66 | STDMETHODIMP CreateSurface(LPDDSURFACEDESC lpDDSurfaceDesc,LPDIRECTDRAWSURFACE *lplpDDSurface,IUnknown *pUnkOuter); 67 | STDMETHODIMP DuplicateSurface(LPDIRECTDRAWSURFACE lpDDSurface,LPDIRECTDRAWSURFACE *lplpDupDDSurface); 68 | STDMETHODIMP EnumDisplayModes(DWORD dwSurfaceDescCount,LPDDSURFACEDESC lplpDDSurfaceDescList,LPVOID lpContext,LPDDENUMMODESCALLBACK lpEnumCallback); 69 | STDMETHODIMP EnumSurfaces(DWORD dwFlags,LPDDSURFACEDESC lpDDSD,LPVOID lpContext,LPDDENUMSURFACESCALLBACK lpEnumCallback); 70 | STDMETHODIMP FlipToGDISurface(); 71 | STDMETHODIMP GetCaps(LPDDCAPS lpDDDriverCaps,LPDDCAPS lpDDHELCaps); 72 | STDMETHODIMP GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc); 73 | STDMETHODIMP GetFourCCCodes(LPDWORD lpNumCodes,LPDWORD lpCodes); 74 | STDMETHODIMP GetGDISurface(LPDIRECTDRAWSURFACE *lplpGDIDDSurface); 75 | STDMETHODIMP GetMonitorFrequency(LPDWORD lpdwFrequency); 76 | STDMETHODIMP GetScanLine(LPDWORD lpdwScanLine); 77 | STDMETHODIMP GetVerticalBlankStatus(LPBOOL lpblsInVB); 78 | STDMETHODIMP Initialize(GUID *lpGUID); 79 | STDMETHODIMP RestoreDisplayMode(); 80 | STDMETHODIMP SetCooperativeLevel(HWND hWnd,DWORD dwFlags); 81 | STDMETHODIMP SetDisplayMode(DWORD dwWidth,DWORD dwHeight,DWORD dwBpp); 82 | STDMETHODIMP WaitForVerticalBlank(DWORD dwFlags,HANDLE hEvent); 83 | }; 84 | 85 | 86 | // Class that aggregates an IDirectDrawSurface interface 87 | 88 | class CAggDrawSurface : public IDirectDrawSurface, public CUnknown 89 | { 90 | protected: 91 | 92 | LPDIRECTDRAWSURFACE m_pDirectDrawSurface; 93 | 94 | public: 95 | 96 | DECLARE_IUNKNOWN 97 | STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,void **ppv); 98 | 99 | // Constructor and destructor 100 | 101 | CAggDrawSurface(TCHAR *pName,LPUNKNOWN pUnk) : 102 | CUnknown(pName,pUnk), 103 | m_pDirectDrawSurface(NULL) { }; 104 | 105 | virtual ~CAggDrawSurface() { }; 106 | 107 | // Set the object we should be aggregating 108 | void SetDirectDrawSurface(LPDIRECTDRAWSURFACE pDirectDrawSurface) { 109 | m_pDirectDrawSurface = pDirectDrawSurface; 110 | } 111 | 112 | // IDirectDrawSurface methods 113 | 114 | STDMETHODIMP AddAttachedSurface(LPDIRECTDRAWSURFACE lpDDSAttachedSurface); 115 | STDMETHODIMP AddOverlayDirtyRect(LPRECT lpRect); 116 | STDMETHODIMP Blt(LPRECT lpDestRect,LPDIRECTDRAWSURFACE lpDDSrcSurface,LPRECT lpSrcRect,DWORD dwFlags,LPDDBLTFX lpDDBltFx); 117 | STDMETHODIMP BltBatch(LPDDBLTBATCH lpDDBltBatch,DWORD dwCount,DWORD dwFlags); 118 | STDMETHODIMP BltFast(DWORD dwX,DWORD dwY,LPDIRECTDRAWSURFACE lpDDSrcSurface,LPRECT lpSrcRect,DWORD dwTrans); 119 | STDMETHODIMP DeleteAttachedSurface(DWORD dwFlags,LPDIRECTDRAWSURFACE lpDDSAttachedSurface); 120 | STDMETHODIMP EnumAttachedSurfaces(LPVOID lpContext,LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback); 121 | STDMETHODIMP EnumOverlayZOrders(DWORD dwFlags,LPVOID lpContext,LPDDENUMSURFACESCALLBACK lpfnCallback); 122 | STDMETHODIMP Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride,DWORD dwFlags); 123 | STDMETHODIMP GetAttachedSurface(LPDDSCAPS lpDDSCaps,LPDIRECTDRAWSURFACE *lplpDDAttachedSurface); 124 | STDMETHODIMP GetBltStatus(DWORD dwFlags); 125 | STDMETHODIMP GetCaps(LPDDSCAPS lpDDSCaps); 126 | STDMETHODIMP GetClipper(LPDIRECTDRAWCLIPPER *lplpDDClipper); 127 | STDMETHODIMP GetColorKey(DWORD dwFlags,LPDDCOLORKEY lpDDColorKey); 128 | STDMETHODIMP GetDC(HDC *lphDC); 129 | STDMETHODIMP GetFlipStatus(DWORD dwFlags); 130 | STDMETHODIMP GetOverlayPosition(LPLONG lpdwX,LPLONG lpdwY); 131 | STDMETHODIMP GetPalette(LPDIRECTDRAWPALETTE *lplpDDPalette); 132 | STDMETHODIMP GetPixelFormat(LPDDPIXELFORMAT lpDDPixelFormat); 133 | STDMETHODIMP GetSurfaceDesc(LPDDSURFACEDESC lpDDSurfaceDesc); 134 | STDMETHODIMP Initialize(LPDIRECTDRAW lpDD,LPDDSURFACEDESC lpDDSurfaceDesc); 135 | STDMETHODIMP IsLost(); 136 | STDMETHODIMP Lock(LPRECT lpDestRect,LPDDSURFACEDESC lpDDSurfaceDesc,DWORD dwFlags,HANDLE hEvent); 137 | STDMETHODIMP ReleaseDC(HDC hDC); 138 | STDMETHODIMP Restore(); 139 | STDMETHODIMP SetClipper(LPDIRECTDRAWCLIPPER lpDDClipper); 140 | STDMETHODIMP SetColorKey(DWORD dwFlags,LPDDCOLORKEY lpDDColorKey); 141 | STDMETHODIMP SetOverlayPosition(LONG dwX,LONG dwY); 142 | STDMETHODIMP SetPalette(LPDIRECTDRAWPALETTE lpDDPalette); 143 | STDMETHODIMP Unlock(LPVOID lpSurfaceData); 144 | STDMETHODIMP UpdateOverlay(LPRECT lpSrcRect,LPDIRECTDRAWSURFACE lpDDDestSurface,LPRECT lpDestRect,DWORD dwFlags,LPDDOVERLAYFX lpDDOverlayFX); 145 | STDMETHODIMP UpdateOverlayDisplay(DWORD dwFlags); 146 | STDMETHODIMP UpdateOverlayZOrder(DWORD dwFlags,LPDIRECTDRAWSURFACE lpDDSReference); 147 | }; 148 | 149 | 150 | // DirectShow must work on multiple platforms. In particular, it also runs on 151 | // Windows NT 3.51 which does not have DirectDraw capabilities. The filters 152 | // cannot therefore link statically to the DirectDraw library. To make their 153 | // lives that little bit easier we provide this class that manages loading 154 | // and unloading the library and creating the initial IDirectDraw interface 155 | 156 | typedef DWORD (WINAPI *PGETFILEVERSIONINFOSIZE)(LPTSTR,LPDWORD); 157 | typedef BOOL (WINAPI *PGETFILEVERSIONINFO)(LPTSTR,DWORD,DWORD,LPVOID); 158 | typedef BOOL (WINAPI *PVERQUERYVALUE)(LPVOID,LPTSTR,LPVOID,PUINT); 159 | 160 | class CLoadDirectDraw 161 | { 162 | LPDIRECTDRAW m_pDirectDraw; // The DirectDraw driver instance 163 | HINSTANCE m_hDirectDraw; // Handle to the loaded library 164 | 165 | public: 166 | 167 | CLoadDirectDraw(); 168 | ~CLoadDirectDraw(); 169 | 170 | HRESULT LoadDirectDraw(LPSTR szDevice); 171 | void ReleaseDirectDraw(); 172 | HRESULT IsDirectDrawLoaded(); 173 | LPDIRECTDRAW GetDirectDraw(); 174 | BOOL IsDirectDrawVersion1(); 175 | }; 176 | 177 | #endif // __VIDEOCTL__ 178 | 179 | --------------------------------------------------------------------------------