Commit a2561ee0 authored by Alexander Smorkalov's avatar Alexander Smorkalov

Code review notes fixed.

parent 4703f455
...@@ -141,7 +141,7 @@ OCV_OPTION(WITH_TIFF "Include TIFF support" ON ...@@ -141,7 +141,7 @@ OCV_OPTION(WITH_TIFF "Include TIFF support" ON
OCV_OPTION(WITH_UNICAP "Include Unicap support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_UNICAP "Include Unicap support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) )
OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON IF (UNIX AND NOT ANDROID) ) OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON IF (UNIX AND NOT ANDROID) )
OCV_OPTION(WITH_DSHOW "Build HighGUI with DirectShow support" ON IF (WIN32 AND NOT ARM) ) OCV_OPTION(WITH_DSHOW "Build HighGUI with DirectShow support" ON IF (WIN32 AND NOT ARM) )
OCV_OPTION(WITH_MSMF "Build HighGUI with Media Foundation support" OFF ) OCV_OPTION(WITH_MSMF "Build HighGUI with Media Foundation support" OFF IF WIN32 )
OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF IF (NOT ANDROID AND NOT APPLE) ) OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF IF (NOT ANDROID AND NOT APPLE) )
OCV_OPTION(WITH_XINE "Include Xine support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_XINE "Include Xine support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) )
OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" OFF IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" OFF IF (NOT ANDROID AND NOT IOS) )
......
...@@ -57,7 +57,7 @@ if(CUDA_FOUND) ...@@ -57,7 +57,7 @@ if(CUDA_FOUND)
elseif(CUDA_GENERATION STREQUAL "Kepler") elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0") set(__cuda_arch_bin "3.0")
elseif(CUDA_GENERATION STREQUAL "Auto") elseif(CUDA_GENERATION STREQUAL "Auto")
execute_process( COMMAND "${CUDA_NVCC_EXECUTABLE}" "${OpenCV_SOURCE_DIR}/cmake/OpenCVDetectCudaArch.cu" "--run" execute_process( COMMAND "${CUDA_NVCC_EXECUTABLE}" "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" "--run"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
......
...@@ -12,6 +12,7 @@ endmacro() ...@@ -12,6 +12,7 @@ endmacro()
ocv_legacy_option(BUILD_NEW_PYTHON_SUPPORT BUILD_opencv_python) ocv_legacy_option(BUILD_NEW_PYTHON_SUPPORT BUILD_opencv_python)
ocv_legacy_option(BUILD_JAVA_SUPPORT BUILD_opencv_java) ocv_legacy_option(BUILD_JAVA_SUPPORT BUILD_opencv_java)
ocv_legacy_option(WITH_ANDROID_CAMERA BUILD_opencv_androidcamera) ocv_legacy_option(WITH_ANDROID_CAMERA BUILD_opencv_androidcamera)
ocv_legacy_option(WITH_VIDEOINPUT WITH_DSHOW)
if(DEFINED OPENCV_BUILD_3RDPARTY_LIBS) if(DEFINED OPENCV_BUILD_3RDPARTY_LIBS)
set(BUILD_ZLIB ${OPENCV_BUILD_3RDPARTY_LIBS} CACHE BOOL "Set via depricated OPENCV_BUILD_3RDPARTY_LIBS" FORCE) set(BUILD_ZLIB ${OPENCV_BUILD_3RDPARTY_LIBS} CACHE BOOL "Set via depricated OPENCV_BUILD_3RDPARTY_LIBS" FORCE)
......
...@@ -136,6 +136,7 @@ CV_INLINE IppiSize ippiSize(int width, int height) ...@@ -136,6 +136,7 @@ CV_INLINE IppiSize ippiSize(int width, int height)
#ifdef __ARM_NEON__ #ifdef __ARM_NEON__
# include <arm_neon.h> # include <arm_neon.h>
# define CV_NEON 1 # define CV_NEON 1
# define CPU_HAS_NEON_FEATURE (true)
#endif #endif
#ifndef CV_SSE #ifndef CV_SSE
......
...@@ -38,20 +38,15 @@ ...@@ -38,20 +38,15 @@
// the use of this software, even if advised of the possibility of such damage. // the use of this software, even if advised of the possibility of such damage.
// //
//M*/ //M*/
#include "precomp.hpp" #include "precomp.hpp"
#if (defined WIN32 || defined _WIN32) && defined HAVE_MSMF #if (defined WIN32 || defined _WIN32) && defined HAVE_MSMF
/* /*
Media Foundation-based Video Capturing module is based on Media Foundation-based Video Capturing module is based on
videoInput library by Evgeny Pereguda: videoInput library by Evgeny Pereguda:
http://www.codeproject.com/Articles/559437/Capturing-of-video-from-web-camera-on-Windows-7-an http://www.codeproject.com/Articles/559437/Capturing-of-video-from-web-camera-on-Windows-7-an
Originaly licensed under The Code Project Open License (CPOL) 1.02: Originaly licensed under The Code Project Open License (CPOL) 1.02:
http://www.codeproject.com/info/cpol10.aspx http://www.codeproject.com/info/cpol10.aspx
*/ */
#include <windows.h> #include <windows.h>
#include <guiddef.h> #include <guiddef.h>
#include <mfidl.h> #include <mfidl.h>
...@@ -59,32 +54,25 @@ ...@@ -59,32 +54,25 @@
#include <mfplay.h> #include <mfplay.h>
#include <mfobjects.h> #include <mfobjects.h>
#include "Strsafe.h" #include "Strsafe.h"
#include <new> #include <new>
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#pragma warning(disable:4503) #pragma warning(disable:4503)
#pragma comment(lib, "mfplat") #pragma comment(lib, "mfplat")
#pragma comment(lib, "mf") #pragma comment(lib, "mf")
#pragma comment(lib, "mfuuid") #pragma comment(lib, "mfuuid")
#pragma comment(lib, "Strmiids") #pragma comment(lib, "Strmiids")
#pragma comment(lib, "MinCore_Downlevel") #pragma comment(lib, "MinCore_Downlevel")
struct IMFMediaType; struct IMFMediaType;
struct IMFActivate; struct IMFActivate;
struct IMFMediaSource; struct IMFMediaSource;
struct IMFAttributes; struct IMFAttributes;
namespace namespace
{ {
template <class T> void SafeRelease(T **ppT) template <class T> void SafeRelease(T **ppT)
{ {
if (*ppT) if (*ppT)
...@@ -93,7 +81,6 @@ template <class T> void SafeRelease(T **ppT) ...@@ -93,7 +81,6 @@ template <class T> void SafeRelease(T **ppT)
*ppT = NULL; *ppT = NULL;
} }
} }
/// Class for printing info into consol /// Class for printing info into consol
class DebugPrintOut class DebugPrintOut
{ {
...@@ -103,72 +90,43 @@ public: ...@@ -103,72 +90,43 @@ public:
void printOut(const wchar_t *format, ...); void printOut(const wchar_t *format, ...);
void setVerbose(bool state); void setVerbose(bool state);
bool verbose; bool verbose;
private:
private: DebugPrintOut(void);
DebugPrintOut(void);
}; };
// Structure for collecting info about types of video, which are supported by current video device // Structure for collecting info about types of video, which are supported by current video device
struct MediaType struct MediaType
{ {
unsigned int MF_MT_FRAME_SIZE; unsigned int MF_MT_FRAME_SIZE;
unsigned int height; unsigned int height;
unsigned int width; unsigned int width;
unsigned int MF_MT_YUV_MATRIX; unsigned int MF_MT_YUV_MATRIX;
unsigned int MF_MT_VIDEO_LIGHTING; unsigned int MF_MT_VIDEO_LIGHTING;
unsigned int MF_MT_DEFAULT_STRIDE; unsigned int MF_MT_DEFAULT_STRIDE;
unsigned int MF_MT_VIDEO_CHROMA_SITING; unsigned int MF_MT_VIDEO_CHROMA_SITING;
GUID MF_MT_AM_FORMAT_TYPE; GUID MF_MT_AM_FORMAT_TYPE;
wchar_t *pMF_MT_AM_FORMAT_TYPEName; wchar_t *pMF_MT_AM_FORMAT_TYPEName;
unsigned int MF_MT_FIXED_SIZE_SAMPLES; unsigned int MF_MT_FIXED_SIZE_SAMPLES;
unsigned int MF_MT_VIDEO_NOMINAL_RANGE; unsigned int MF_MT_VIDEO_NOMINAL_RANGE;
unsigned int MF_MT_FRAME_RATE; unsigned int MF_MT_FRAME_RATE;
unsigned int MF_MT_FRAME_RATE_low; unsigned int MF_MT_FRAME_RATE_low;
unsigned int MF_MT_PIXEL_ASPECT_RATIO; unsigned int MF_MT_PIXEL_ASPECT_RATIO;
unsigned int MF_MT_PIXEL_ASPECT_RATIO_low; unsigned int MF_MT_PIXEL_ASPECT_RATIO_low;
unsigned int MF_MT_ALL_SAMPLES_INDEPENDENT; unsigned int MF_MT_ALL_SAMPLES_INDEPENDENT;
unsigned int MF_MT_FRAME_RATE_RANGE_MIN; unsigned int MF_MT_FRAME_RATE_RANGE_MIN;
unsigned int MF_MT_FRAME_RATE_RANGE_MIN_low; unsigned int MF_MT_FRAME_RATE_RANGE_MIN_low;
unsigned int MF_MT_SAMPLE_SIZE; unsigned int MF_MT_SAMPLE_SIZE;
unsigned int MF_MT_VIDEO_PRIMARIES; unsigned int MF_MT_VIDEO_PRIMARIES;
unsigned int MF_MT_INTERLACE_MODE; unsigned int MF_MT_INTERLACE_MODE;
unsigned int MF_MT_FRAME_RATE_RANGE_MAX; unsigned int MF_MT_FRAME_RATE_RANGE_MAX;
unsigned int MF_MT_FRAME_RATE_RANGE_MAX_low; unsigned int MF_MT_FRAME_RATE_RANGE_MAX_low;
GUID MF_MT_MAJOR_TYPE; GUID MF_MT_MAJOR_TYPE;
GUID MF_MT_SUBTYPE; GUID MF_MT_SUBTYPE;
wchar_t *pMF_MT_MAJOR_TYPEName; wchar_t *pMF_MT_MAJOR_TYPEName;
wchar_t *pMF_MT_SUBTYPEName; wchar_t *pMF_MT_SUBTYPEName;
MediaType(); MediaType();
~MediaType(); ~MediaType();
void Clear(); void Clear();
}; };
/// Class for parsing info from IMFMediaType into the local MediaType /// Class for parsing info from IMFMediaType into the local MediaType
class FormatReader class FormatReader
{ {
...@@ -178,102 +136,71 @@ public: ...@@ -178,102 +136,71 @@ public:
private: private:
FormatReader(void); FormatReader(void);
}; };
DWORD WINAPI MainThreadFunction( LPVOID lpParam ); DWORD WINAPI MainThreadFunction( LPVOID lpParam );
typedef void(*emergensyStopEventCallback)(int, void *); typedef void(*emergensyStopEventCallback)(int, void *);
typedef unsigned char BYTE; typedef unsigned char BYTE;
class RawImage class RawImage
{ {
public: public:
~RawImage(void); ~RawImage(void);
// Function of creation of the instance of the class // Function of creation of the instance of the class
static long CreateInstance(RawImage **ppRImage,unsigned int size); static long CreateInstance(RawImage **ppRImage,unsigned int size);
void setCopy(const BYTE * pSampleBuffer); void setCopy(const BYTE * pSampleBuffer);
void fastCopy(const BYTE * pSampleBuffer); void fastCopy(const BYTE * pSampleBuffer);
unsigned char * getpPixels(); unsigned char * getpPixels();
bool isNew(); bool isNew();
unsigned int getSize(); unsigned int getSize();
private: private:
bool ri_new; bool ri_new;
unsigned int ri_size; unsigned int ri_size;
unsigned char *ri_pixels; unsigned char *ri_pixels;
RawImage(unsigned int size); RawImage(unsigned int size);
}; };
// Class for grabbing image from video stream // Class for grabbing image from video stream
class ImageGrabber : public IMFSampleGrabberSinkCallback class ImageGrabber : public IMFSampleGrabberSinkCallback
{ {
public: public:
~ImageGrabber(void); ~ImageGrabber(void);
HRESULT initImageGrabber(IMFMediaSource *pSource, GUID VideoFormat); HRESULT initImageGrabber(IMFMediaSource *pSource, GUID VideoFormat);
HRESULT startGrabbing(void); HRESULT startGrabbing(void);
void stopGrabbing(); void stopGrabbing();
RawImage *getRawImage(); RawImage *getRawImage();
// Function of creation of the instance of the class // Function of creation of the instance of the class
static HRESULT CreateInstance(ImageGrabber **ppIG,unsigned int deviceID); static HRESULT CreateInstance(ImageGrabber **ppIG,unsigned int deviceID);
private: private:
bool ig_RIE; bool ig_RIE;
bool ig_Close; bool ig_Close;
long m_cRef; long m_cRef;
unsigned int ig_DeviceID; unsigned int ig_DeviceID;
IMFMediaSource *ig_pSource; IMFMediaSource *ig_pSource;
IMFMediaSession *ig_pSession; IMFMediaSession *ig_pSession;
IMFTopology *ig_pTopology; IMFTopology *ig_pTopology;
RawImage *ig_RIFirst; RawImage *ig_RIFirst;
RawImage *ig_RISecond; RawImage *ig_RISecond;
RawImage *ig_RIOut; RawImage *ig_RIOut;
ImageGrabber(unsigned int deviceID); ImageGrabber(unsigned int deviceID);
HRESULT CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo); HRESULT CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo);
HRESULT AddSourceNode( HRESULT AddSourceNode(
IMFTopology *pTopology, IMFTopology *pTopology,
IMFMediaSource *pSource, IMFMediaSource *pSource,
IMFPresentationDescriptor *pPD, IMFPresentationDescriptor *pPD,
IMFStreamDescriptor *pSD, IMFStreamDescriptor *pSD,
IMFTopologyNode **ppNode); IMFTopologyNode **ppNode);
HRESULT AddOutputNode( HRESULT AddOutputNode(
IMFTopology *pTopology, IMFTopology *pTopology,
IMFActivate *pActivate, IMFActivate *pActivate,
DWORD dwId, DWORD dwId,
IMFTopologyNode **ppNode); IMFTopologyNode **ppNode);
// IUnknown methods // IUnknown methods
STDMETHODIMP QueryInterface(REFIID iid, void** ppv); STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
STDMETHODIMP_(ULONG) AddRef(); STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release(); STDMETHODIMP_(ULONG) Release();
// IMFClockStateSink methods // IMFClockStateSink methods
STDMETHODIMP OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset); STDMETHODIMP OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset);
STDMETHODIMP OnClockStop(MFTIME hnsSystemTime); STDMETHODIMP OnClockStop(MFTIME hnsSystemTime);
STDMETHODIMP OnClockPause(MFTIME hnsSystemTime); STDMETHODIMP OnClockPause(MFTIME hnsSystemTime);
STDMETHODIMP OnClockRestart(MFTIME hnsSystemTime); STDMETHODIMP OnClockRestart(MFTIME hnsSystemTime);
STDMETHODIMP OnClockSetRate(MFTIME hnsSystemTime, float flRate); STDMETHODIMP OnClockSetRate(MFTIME hnsSystemTime, float flRate);
// IMFSampleGrabberSinkCallback methods // IMFSampleGrabberSinkCallback methods
STDMETHODIMP OnSetPresentationClock(IMFPresentationClock* pClock); STDMETHODIMP OnSetPresentationClock(IMFPresentationClock* pClock);
STDMETHODIMP OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags, STDMETHODIMP OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags,
...@@ -281,66 +208,40 @@ private: ...@@ -281,66 +208,40 @@ private:
DWORD dwSampleSize); DWORD dwSampleSize);
STDMETHODIMP OnShutdown(); STDMETHODIMP OnShutdown();
}; };
/// Class for controlling of thread of the grabbing raw data from video device /// Class for controlling of thread of the grabbing raw data from video device
class ImageGrabberThread class ImageGrabberThread
{ {
friend DWORD WINAPI MainThreadFunction( LPVOID lpParam ); friend DWORD WINAPI MainThreadFunction( LPVOID lpParam );
public: public:
~ImageGrabberThread(void); ~ImageGrabberThread(void);
static HRESULT CreateInstance(ImageGrabberThread **ppIGT, IMFMediaSource *pSource, unsigned int deviceID); static HRESULT CreateInstance(ImageGrabberThread **ppIGT, IMFMediaSource *pSource, unsigned int deviceID);
void start(); void start();
void stop(); void stop();
void setEmergencyStopEvent(void *userData, void(*func)(int, void *)); void setEmergencyStopEvent(void *userData, void(*func)(int, void *));
ImageGrabber *getImageGrabber(); ImageGrabber *getImageGrabber();
protected: protected:
virtual void run(); virtual void run();
private: private:
ImageGrabberThread(IMFMediaSource *pSource, unsigned int deviceID); ImageGrabberThread(IMFMediaSource *pSource, unsigned int deviceID);
HANDLE igt_Handle; HANDLE igt_Handle;
DWORD igt_ThreadIdArray; DWORD igt_ThreadIdArray;
ImageGrabber *igt_pImageGrabber; ImageGrabber *igt_pImageGrabber;
emergensyStopEventCallback igt_func; emergensyStopEventCallback igt_func;
void *igt_userData; void *igt_userData;
bool igt_stop; bool igt_stop;
unsigned int igt_DeviceID; unsigned int igt_DeviceID;
}; };
// Structure for collecting info about one parametr of current video device // Structure for collecting info about one parametr of current video device
struct Parametr struct Parametr
{ {
long CurrentValue; long CurrentValue;
long Min; long Min;
long Max; long Max;
long Step; long Step;
long Default; long Default;
long Flag; long Flag;
Parametr(); Parametr();
}; };
// Structure for collecting info about 17 parametrs of current video device // Structure for collecting info about 17 parametrs of current video device
struct CamParametrs struct CamParametrs
{ {
...@@ -354,7 +255,6 @@ struct CamParametrs ...@@ -354,7 +255,6 @@ struct CamParametrs
Parametr WhiteBalance; Parametr WhiteBalance;
Parametr BacklightCompensation; Parametr BacklightCompensation;
Parametr Gain; Parametr Gain;
Parametr Pan; Parametr Pan;
Parametr Tilt; Parametr Tilt;
Parametr Roll; Parametr Roll;
...@@ -363,138 +263,77 @@ struct CamParametrs ...@@ -363,138 +263,77 @@ struct CamParametrs
Parametr Iris; Parametr Iris;
Parametr Focus; Parametr Focus;
}; };
typedef std::wstring String; typedef std::wstring String;
typedef std::vector<int> vectorNum; typedef std::vector<int> vectorNum;
typedef std::map<String, vectorNum> SUBTYPEMap; typedef std::map<String, vectorNum> SUBTYPEMap;
typedef std::map<UINT64, SUBTYPEMap> FrameRateMap; typedef std::map<UINT64, SUBTYPEMap> FrameRateMap;
typedef void(*emergensyStopEventCallback)(int, void *); typedef void(*emergensyStopEventCallback)(int, void *);
/// Class for controlling of video device /// Class for controlling of video device
class videoDevice class videoDevice
{ {
public: public:
videoDevice(void); videoDevice(void);
~videoDevice(void); ~videoDevice(void);
void closeDevice(); void closeDevice();
CamParametrs getParametrs(); CamParametrs getParametrs();
void setParametrs(CamParametrs parametrs); void setParametrs(CamParametrs parametrs);
void setEmergencyStopEvent(void *userData, void(*func)(int, void *)); void setEmergencyStopEvent(void *userData, void(*func)(int, void *));
long readInfoOfDevice(IMFActivate *pActivate, unsigned int Num); long readInfoOfDevice(IMFActivate *pActivate, unsigned int Num);
wchar_t *getName(); wchar_t *getName();
int getCountFormats(); int getCountFormats();
unsigned int getWidth(); unsigned int getWidth();
unsigned int getHeight(); unsigned int getHeight();
MediaType getFormat(unsigned int id); MediaType getFormat(unsigned int id);
bool setupDevice(unsigned int w, unsigned int h, unsigned int idealFramerate = 0); bool setupDevice(unsigned int w, unsigned int h, unsigned int idealFramerate = 0);
bool setupDevice(unsigned int id); bool setupDevice(unsigned int id);
bool isDeviceSetup(); bool isDeviceSetup();
bool isDeviceMediaSource(); bool isDeviceMediaSource();
bool isDeviceRawDataSource(); bool isDeviceRawDataSource();
bool isFrameNew(); bool isFrameNew();
IMFMediaSource *getMediaSource(); IMFMediaSource *getMediaSource();
RawImage *getRawImageOut(); RawImage *getRawImageOut();
private: private:
enum typeLock enum typeLock
{ {
MediaSourceLock, MediaSourceLock,
RawDataLock, RawDataLock,
OpenLock OpenLock
} vd_LockOut; } vd_LockOut;
wchar_t *vd_pFriendlyName; wchar_t *vd_pFriendlyName;
ImageGrabberThread *vd_pImGrTh; ImageGrabberThread *vd_pImGrTh;
CamParametrs vd_PrevParametrs; CamParametrs vd_PrevParametrs;
unsigned int vd_Width; unsigned int vd_Width;
unsigned int vd_Height; unsigned int vd_Height;
unsigned int vd_CurrentNumber; unsigned int vd_CurrentNumber;
bool vd_IsSetuped; bool vd_IsSetuped;
std::map<UINT64, FrameRateMap> vd_CaptureFormats; std::map<UINT64, FrameRateMap> vd_CaptureFormats;
std::vector<MediaType> vd_CurrentFormats; std::vector<MediaType> vd_CurrentFormats;
IMFMediaSource *vd_pSource; IMFMediaSource *vd_pSource;
emergensyStopEventCallback vd_func; emergensyStopEventCallback vd_func;
void *vd_userData; void *vd_userData;
long enumerateCaptureFormats(IMFMediaSource *pSource); long enumerateCaptureFormats(IMFMediaSource *pSource);
long setDeviceFormat(IMFMediaSource *pSource, unsigned long dwFormatIndex); long setDeviceFormat(IMFMediaSource *pSource, unsigned long dwFormatIndex);
void buildLibraryofTypes(); void buildLibraryofTypes();
int findType(unsigned int size, unsigned int frameRate = 0); int findType(unsigned int size, unsigned int frameRate = 0);
long resetDevice(IMFActivate *pActivate); long resetDevice(IMFActivate *pActivate);
long initDevice(); long initDevice();
long checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice); long checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice);
}; };
/// Class for managing of list of video devices /// Class for managing of list of video devices
class videoDevices class videoDevices
{ {
public: public:
~videoDevices(void); ~videoDevices(void);
long initDevices(IMFAttributes *pAttributes); long initDevices(IMFAttributes *pAttributes);
static videoDevices& getInstance(); static videoDevices& getInstance();
videoDevice *getDevice(unsigned int i); videoDevice *getDevice(unsigned int i);
unsigned int getCount(); unsigned int getCount();
void clearDevices(); void clearDevices();
private: private:
UINT32 count; UINT32 count;
std::vector<videoDevice *> vds_Devices; std::vector<videoDevice *> vds_Devices;
videoDevices(void); videoDevices(void);
}; };
// Class for creating of Media Foundation context // Class for creating of Media Foundation context
class Media_Foundation class Media_Foundation
{ {
...@@ -502,212 +341,146 @@ public: ...@@ -502,212 +341,146 @@ public:
virtual ~Media_Foundation(void); virtual ~Media_Foundation(void);
static Media_Foundation& getInstance(); static Media_Foundation& getInstance();
bool buildListOfDevices(); bool buildListOfDevices();
private: private:
Media_Foundation(void); Media_Foundation(void);
}; };
/// The only visiable class for controlling of video devices in format singelton /// The only visiable class for controlling of video devices in format singelton
class videoInput class videoInput
{ {
public: public:
virtual ~videoInput(void); virtual ~videoInput(void);
// Getting of static instance of videoInput class // Getting of static instance of videoInput class
static videoInput& getInstance(); static videoInput& getInstance();
// Closing video device with deviceID // Closing video device with deviceID
void closeDevice(int deviceID); void closeDevice(int deviceID);
// Setting callback function for emergency events(for example: removing video device with deviceID) with userData // Setting callback function for emergency events(for example: removing video device with deviceID) with userData
void setEmergencyStopEvent(int deviceID, void *userData, void(*func)(int, void *)); void setEmergencyStopEvent(int deviceID, void *userData, void(*func)(int, void *));
// Closing all devices // Closing all devices
void closeAllDevices(); void closeAllDevices();
// Getting of parametrs of video device with deviceID // Getting of parametrs of video device with deviceID
CamParametrs getParametrs(int deviceID); CamParametrs getParametrs(int deviceID);
// Setting of parametrs of video device with deviceID // Setting of parametrs of video device with deviceID
void setParametrs(int deviceID, CamParametrs parametrs); void setParametrs(int deviceID, CamParametrs parametrs);
// Getting numbers of existence videodevices with listing in consol // Getting numbers of existence videodevices with listing in consol
unsigned int listDevices(bool silent = false); unsigned int listDevices(bool silent = false);
// Getting numbers of formats, which are supported by videodevice with deviceID // Getting numbers of formats, which are supported by videodevice with deviceID
unsigned int getCountFormats(int deviceID); unsigned int getCountFormats(int deviceID);
// Getting width of image, which is getting from videodevice with deviceID // Getting width of image, which is getting from videodevice with deviceID
unsigned int getWidth(int deviceID); unsigned int getWidth(int deviceID);
// Getting height of image, which is getting from videodevice with deviceID // Getting height of image, which is getting from videodevice with deviceID
unsigned int getHeight(int deviceID); unsigned int getHeight(int deviceID);
// Getting name of videodevice with deviceID // Getting name of videodevice with deviceID
wchar_t *getNameVideoDevice(int deviceID); wchar_t *getNameVideoDevice(int deviceID);
// Getting interface MediaSource for Media Foundation from videodevice with deviceID // Getting interface MediaSource for Media Foundation from videodevice with deviceID
IMFMediaSource *getMediaSource(int deviceID); IMFMediaSource *getMediaSource(int deviceID);
// Getting format with id, which is supported by videodevice with deviceID
// Getting format with id, which is supported by videodevice with deviceID
MediaType getFormat(int deviceID, int unsigned id); MediaType getFormat(int deviceID, int unsigned id);
// Checking of existence of the suitable video devices // Checking of existence of the suitable video devices
bool isDevicesAcceable(); bool isDevicesAcceable();
// Checking of using the videodevice with deviceID // Checking of using the videodevice with deviceID
bool isDeviceSetup(int deviceID); bool isDeviceSetup(int deviceID);
// Checking of using MediaSource from videodevice with deviceID // Checking of using MediaSource from videodevice with deviceID
bool isDeviceMediaSource(int deviceID); bool isDeviceMediaSource(int deviceID);
// Checking of using Raw Data of pixels from videodevice with deviceID // Checking of using Raw Data of pixels from videodevice with deviceID
bool isDeviceRawDataSource(int deviceID); bool isDeviceRawDataSource(int deviceID);
// Setting of the state of outprinting info in console // Setting of the state of outprinting info in console
static void setVerbose(bool state); static void setVerbose(bool state);
// Initialization of video device with deviceID by media type with id // Initialization of video device with deviceID by media type with id
bool setupDevice(int deviceID, unsigned int id = 0); bool setupDevice(int deviceID, unsigned int id = 0);
// Initialization of video device with deviceID by wisth w, height h and fps idealFramerate // Initialization of video device with deviceID by wisth w, height h and fps idealFramerate
bool setupDevice(int deviceID, unsigned int w, unsigned int h, unsigned int idealFramerate = 30); bool setupDevice(int deviceID, unsigned int w, unsigned int h, unsigned int idealFramerate = 30);
// Checking of recivig of new frame from video device with deviceID
// Checking of recivig of new frame from video device with deviceID
bool isFrameNew(int deviceID); bool isFrameNew(int deviceID);
// Writing of Raw Data pixels from video device with deviceID with correction of RedAndBlue flipping flipRedAndBlue and vertical flipping flipImage // Writing of Raw Data pixels from video device with deviceID with correction of RedAndBlue flipping flipRedAndBlue and vertical flipping flipImage
bool getPixels(int deviceID, unsigned char * pixels, bool flipRedAndBlue = false, bool flipImage = false); bool getPixels(int deviceID, unsigned char * pixels, bool flipRedAndBlue = false, bool flipImage = false);
private:
private:
bool accessToDevices; bool accessToDevices;
videoInput(void); videoInput(void);
void processPixels(unsigned char * src, unsigned char * dst, unsigned int width, unsigned int height, unsigned int bpp, bool bRGB, bool bFlip); void processPixels(unsigned char * src, unsigned char * dst, unsigned int width, unsigned int height, unsigned int bpp, bool bRGB, bool bFlip);
void updateListOfDevices(); void updateListOfDevices();
}; };
DebugPrintOut::DebugPrintOut(void):verbose(true) DebugPrintOut::DebugPrintOut(void):verbose(true)
{ {
} }
DebugPrintOut::~DebugPrintOut(void) DebugPrintOut::~DebugPrintOut(void)
{ {
} }
DebugPrintOut& DebugPrintOut::getInstance() DebugPrintOut& DebugPrintOut::getInstance()
{ {
static DebugPrintOut instance; static DebugPrintOut instance;
return instance; return instance;
} }
void DebugPrintOut::printOut(const wchar_t *format, ...) void DebugPrintOut::printOut(const wchar_t *format, ...)
{ {
if(verbose) if(verbose)
{ {
int i = 0; int i = 0;
wchar_t *p = NULL; wchar_t *p = NULL;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
if(wcscmp(format, L"%i")) if(wcscmp(format, L"%i"))
{ {
i = va_arg (args, int); i = va_arg (args, int);
} }
if(wcscmp(format, L"%s")) if(wcscmp(format, L"%s"))
{ {
p = va_arg (args, wchar_t *); p = va_arg (args, wchar_t *);
} }
wprintf(format, i,p); wprintf(format, i,p);
va_end (args); va_end (args);
} }
} }
void DebugPrintOut::setVerbose(bool state) void DebugPrintOut::setVerbose(bool state)
{ {
verbose = state; verbose = state;
} }
LPCWSTR GetGUIDNameConstNew(const GUID& guid); LPCWSTR GetGUIDNameConstNew(const GUID& guid);
HRESULT GetGUIDNameNew(const GUID& guid, WCHAR **ppwsz); HRESULT GetGUIDNameNew(const GUID& guid, WCHAR **ppwsz);
HRESULT LogAttributeValueByIndexNew(IMFAttributes *pAttr, DWORD index); HRESULT LogAttributeValueByIndexNew(IMFAttributes *pAttr, DWORD index);
HRESULT SpecialCaseAttributeValueNew(GUID guid, const PROPVARIANT& var, MediaType &out); HRESULT SpecialCaseAttributeValueNew(GUID guid, const PROPVARIANT& var, MediaType &out);
unsigned int *GetParametr(GUID guid, MediaType &out) unsigned int *GetParametr(GUID guid, MediaType &out)
{ {
if(guid == MF_MT_YUV_MATRIX) if(guid == MF_MT_YUV_MATRIX)
return &(out.MF_MT_YUV_MATRIX); return &(out.MF_MT_YUV_MATRIX);
if(guid == MF_MT_VIDEO_LIGHTING)
if(guid == MF_MT_VIDEO_LIGHTING)
return &(out.MF_MT_VIDEO_LIGHTING); return &(out.MF_MT_VIDEO_LIGHTING);
if(guid == MF_MT_DEFAULT_STRIDE)
if(guid == MF_MT_DEFAULT_STRIDE)
return &(out.MF_MT_DEFAULT_STRIDE); return &(out.MF_MT_DEFAULT_STRIDE);
if(guid == MF_MT_VIDEO_CHROMA_SITING)
if(guid == MF_MT_VIDEO_CHROMA_SITING)
return &(out.MF_MT_VIDEO_CHROMA_SITING); return &(out.MF_MT_VIDEO_CHROMA_SITING);
if(guid == MF_MT_VIDEO_NOMINAL_RANGE)
if(guid == MF_MT_VIDEO_NOMINAL_RANGE)
return &(out.MF_MT_VIDEO_NOMINAL_RANGE); return &(out.MF_MT_VIDEO_NOMINAL_RANGE);
if(guid == MF_MT_ALL_SAMPLES_INDEPENDENT)
if(guid == MF_MT_ALL_SAMPLES_INDEPENDENT)
return &(out.MF_MT_ALL_SAMPLES_INDEPENDENT); return &(out.MF_MT_ALL_SAMPLES_INDEPENDENT);
if(guid == MF_MT_FIXED_SIZE_SAMPLES)
if(guid == MF_MT_FIXED_SIZE_SAMPLES)
return &(out.MF_MT_FIXED_SIZE_SAMPLES); return &(out.MF_MT_FIXED_SIZE_SAMPLES);
if(guid == MF_MT_SAMPLE_SIZE)
if(guid == MF_MT_SAMPLE_SIZE)
return &(out.MF_MT_SAMPLE_SIZE); return &(out.MF_MT_SAMPLE_SIZE);
if(guid == MF_MT_VIDEO_PRIMARIES)
if(guid == MF_MT_VIDEO_PRIMARIES)
return &(out.MF_MT_VIDEO_PRIMARIES); return &(out.MF_MT_VIDEO_PRIMARIES);
if(guid == MF_MT_INTERLACE_MODE)
if(guid == MF_MT_INTERLACE_MODE)
return &(out.MF_MT_INTERLACE_MODE); return &(out.MF_MT_INTERLACE_MODE);
return NULL; return NULL;
} }
HRESULT LogAttributeValueByIndexNew(IMFAttributes *pAttr, DWORD index, MediaType &out) HRESULT LogAttributeValueByIndexNew(IMFAttributes *pAttr, DWORD index, MediaType &out)
{ {
WCHAR *pGuidName = NULL; WCHAR *pGuidName = NULL;
WCHAR *pGuidValName = NULL; WCHAR *pGuidValName = NULL;
GUID guid = { 0 }; GUID guid = { 0 };
PROPVARIANT var; PROPVARIANT var;
PropVariantInit(&var); PropVariantInit(&var);
HRESULT hr = pAttr->GetItemByIndex(index, &guid, &var); HRESULT hr = pAttr->GetItemByIndex(index, &guid, &var);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
hr = GetGUIDNameNew(guid, &pGuidName); hr = GetGUIDNameNew(guid, &pGuidName);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
hr = SpecialCaseAttributeValueNew(guid, var, out); hr = SpecialCaseAttributeValueNew(guid, var, out);
unsigned int *p; unsigned int *p;
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
...@@ -717,118 +490,83 @@ HRESULT LogAttributeValueByIndexNew(IMFAttributes *pAttr, DWORD index, MediaType ...@@ -717,118 +490,83 @@ HRESULT LogAttributeValueByIndexNew(IMFAttributes *pAttr, DWORD index, MediaType
switch (var.vt) switch (var.vt)
{ {
case VT_UI4: case VT_UI4:
p = GetParametr(guid, out); p = GetParametr(guid, out);
if(p)
if(p)
{ {
*p = var.ulVal; *p = var.ulVal;
} }
break; break;
case VT_UI8: case VT_UI8:
break; break;
case VT_R8: case VT_R8:
break; break;
case VT_CLSID: case VT_CLSID:
if(guid == MF_MT_AM_FORMAT_TYPE) if(guid == MF_MT_AM_FORMAT_TYPE)
{ {
hr = GetGUIDNameNew(*var.puuid, &pGuidValName); hr = GetGUIDNameNew(*var.puuid, &pGuidValName);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
out.MF_MT_AM_FORMAT_TYPE = MF_MT_AM_FORMAT_TYPE; out.MF_MT_AM_FORMAT_TYPE = MF_MT_AM_FORMAT_TYPE;
out.pMF_MT_AM_FORMAT_TYPEName = pGuidValName; out.pMF_MT_AM_FORMAT_TYPEName = pGuidValName;
pGuidValName = NULL; pGuidValName = NULL;
} }
} }
if(guid == MF_MT_MAJOR_TYPE) if(guid == MF_MT_MAJOR_TYPE)
{ {
hr = GetGUIDNameNew(*var.puuid, &pGuidValName); hr = GetGUIDNameNew(*var.puuid, &pGuidValName);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
out.MF_MT_MAJOR_TYPE = MF_MT_MAJOR_TYPE; out.MF_MT_MAJOR_TYPE = MF_MT_MAJOR_TYPE;
out.pMF_MT_MAJOR_TYPEName = pGuidValName; out.pMF_MT_MAJOR_TYPEName = pGuidValName;
pGuidValName = NULL; pGuidValName = NULL;
} }
} }
if(guid == MF_MT_SUBTYPE) if(guid == MF_MT_SUBTYPE)
{ {
hr = GetGUIDNameNew(*var.puuid, &pGuidValName); hr = GetGUIDNameNew(*var.puuid, &pGuidValName);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
out.MF_MT_SUBTYPE = MF_MT_SUBTYPE; out.MF_MT_SUBTYPE = MF_MT_SUBTYPE;
out.pMF_MT_SUBTYPEName = pGuidValName; out.pMF_MT_SUBTYPEName = pGuidValName;
pGuidValName = NULL; pGuidValName = NULL;
} }
} }
break; break;
case VT_LPWSTR: case VT_LPWSTR:
break; break;
case VT_VECTOR | VT_UI1: case VT_VECTOR | VT_UI1:
break; break;
case VT_UNKNOWN: case VT_UNKNOWN:
break; break;
default: default:
break; break;
} }
} }
done: done:
CoTaskMemFree(pGuidName); CoTaskMemFree(pGuidName);
CoTaskMemFree(pGuidValName); CoTaskMemFree(pGuidValName);
PropVariantClear(&var); PropVariantClear(&var);
return hr; return hr;
} }
HRESULT GetGUIDNameNew(const GUID& guid, WCHAR **ppwsz) HRESULT GetGUIDNameNew(const GUID& guid, WCHAR **ppwsz)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
WCHAR *pName = NULL; WCHAR *pName = NULL;
LPCWSTR pcwsz = GetGUIDNameConstNew(guid); LPCWSTR pcwsz = GetGUIDNameConstNew(guid);
if (pcwsz) if (pcwsz)
{ {
size_t cchLength = 0; size_t cchLength = 0;
hr = StringCchLengthW(pcwsz, STRSAFE_MAX_CCH, &cchLength); hr = StringCchLengthW(pcwsz, STRSAFE_MAX_CCH, &cchLength);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
pName = (WCHAR*)CoTaskMemAlloc((cchLength + 1) * sizeof(WCHAR)); pName = (WCHAR*)CoTaskMemAlloc((cchLength + 1) * sizeof(WCHAR));
if (pName == NULL) if (pName == NULL)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
goto done; goto done;
} }
hr = StringCchCopyW(pName, cchLength + 1, pcwsz); hr = StringCchCopyW(pName, cchLength + 1, pcwsz);
if (FAILED(hr)) if (FAILED(hr))
{ {
...@@ -839,7 +577,6 @@ HRESULT GetGUIDNameNew(const GUID& guid, WCHAR **ppwsz) ...@@ -839,7 +577,6 @@ HRESULT GetGUIDNameNew(const GUID& guid, WCHAR **ppwsz)
{ {
hr = StringFromCLSID(guid, &pName); hr = StringFromCLSID(guid, &pName);
} }
done: done:
if (FAILED(hr)) if (FAILED(hr))
{ {
...@@ -852,97 +589,73 @@ done: ...@@ -852,97 +589,73 @@ done:
} }
return hr; return hr;
} }
void LogUINT32AsUINT64New(const PROPVARIANT& var, UINT32 &uHigh, UINT32 &uLow) void LogUINT32AsUINT64New(const PROPVARIANT& var, UINT32 &uHigh, UINT32 &uLow)
{ {
Unpack2UINT32AsUINT64(var.uhVal.QuadPart, &uHigh, &uLow); Unpack2UINT32AsUINT64(var.uhVal.QuadPart, &uHigh, &uLow);
} }
float OffsetToFloatNew(const MFOffset& offset) float OffsetToFloatNew(const MFOffset& offset)
{ {
return offset.value + (static_cast<float>(offset.fract) / 65536.0f); return offset.value + (static_cast<float>(offset.fract) / 65536.0f);
} }
HRESULT LogVideoAreaNew(const PROPVARIANT& var) HRESULT LogVideoAreaNew(const PROPVARIANT& var)
{ {
if (var.caub.cElems < sizeof(MFVideoArea)) if (var.caub.cElems < sizeof(MFVideoArea))
{ {
return S_OK; return S_OK;
} }
return S_OK; return S_OK;
} }
HRESULT SpecialCaseAttributeValueNew(GUID guid, const PROPVARIANT& var, MediaType &out) HRESULT SpecialCaseAttributeValueNew(GUID guid, const PROPVARIANT& var, MediaType &out)
{ {
if (guid == MF_MT_FRAME_SIZE) if (guid == MF_MT_FRAME_SIZE)
{ {
UINT32 uHigh = 0, uLow = 0; UINT32 uHigh = 0, uLow = 0;
LogUINT32AsUINT64New(var, uHigh, uLow); LogUINT32AsUINT64New(var, uHigh, uLow);
out.width = uHigh; out.width = uHigh;
out.height = uLow; out.height = uLow;
out.MF_MT_FRAME_SIZE = out.width * out.height; out.MF_MT_FRAME_SIZE = out.width * out.height;
} }
else else
if (guid == MF_MT_FRAME_RATE) if (guid == MF_MT_FRAME_RATE)
{ {
UINT32 uHigh = 0, uLow = 0; UINT32 uHigh = 0, uLow = 0;
LogUINT32AsUINT64New(var, uHigh, uLow); LogUINT32AsUINT64New(var, uHigh, uLow);
out.MF_MT_FRAME_RATE = uHigh; out.MF_MT_FRAME_RATE = uHigh;
out.MF_MT_FRAME_RATE_low = uLow; out.MF_MT_FRAME_RATE_low = uLow;
} }
else else
if (guid == MF_MT_FRAME_RATE_RANGE_MAX) if (guid == MF_MT_FRAME_RATE_RANGE_MAX)
{ {
UINT32 uHigh = 0, uLow = 0; UINT32 uHigh = 0, uLow = 0;
LogUINT32AsUINT64New(var, uHigh, uLow); LogUINT32AsUINT64New(var, uHigh, uLow);
out.MF_MT_FRAME_RATE_RANGE_MAX = uHigh; out.MF_MT_FRAME_RATE_RANGE_MAX = uHigh;
out.MF_MT_FRAME_RATE_RANGE_MAX_low = uLow; out.MF_MT_FRAME_RATE_RANGE_MAX_low = uLow;
} }
else else
if (guid == MF_MT_FRAME_RATE_RANGE_MIN) if (guid == MF_MT_FRAME_RATE_RANGE_MIN)
{ {
UINT32 uHigh = 0, uLow = 0; UINT32 uHigh = 0, uLow = 0;
LogUINT32AsUINT64New(var, uHigh, uLow); LogUINT32AsUINT64New(var, uHigh, uLow);
out.MF_MT_FRAME_RATE_RANGE_MIN = uHigh; out.MF_MT_FRAME_RATE_RANGE_MIN = uHigh;
out.MF_MT_FRAME_RATE_RANGE_MIN_low = uLow; out.MF_MT_FRAME_RATE_RANGE_MIN_low = uLow;
} }
else else
if (guid == MF_MT_PIXEL_ASPECT_RATIO) if (guid == MF_MT_PIXEL_ASPECT_RATIO)
{ {
UINT32 uHigh = 0, uLow = 0; UINT32 uHigh = 0, uLow = 0;
LogUINT32AsUINT64New(var, uHigh, uLow); LogUINT32AsUINT64New(var, uHigh, uLow);
out.MF_MT_PIXEL_ASPECT_RATIO = uHigh; out.MF_MT_PIXEL_ASPECT_RATIO = uHigh;
out.MF_MT_PIXEL_ASPECT_RATIO_low = uLow; out.MF_MT_PIXEL_ASPECT_RATIO_low = uLow;
} }
else else
{ {
return S_FALSE; return S_FALSE;
} }
return S_OK; return S_OK;
} }
#ifndef IF_EQUAL_RETURN #ifndef IF_EQUAL_RETURN
#define IF_EQUAL_RETURN(param, val) if(val == param) return L#val #define IF_EQUAL_RETURN(param, val) if(val == param) return L#val
#endif #endif
LPCWSTR GetGUIDNameConstNew(const GUID& guid) LPCWSTR GetGUIDNameConstNew(const GUID& guid)
{ {
IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE); IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE);
...@@ -1010,14 +723,12 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid) ...@@ -1010,14 +723,12 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid)
IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_CTRL_PACK); IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_CTRL_PACK);
IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_HEADER); IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_HEADER);
IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_FORMAT); IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_FORMAT);
IF_EQUAL_RETURN(guid, MF_MT_IMAGE_LOSS_TOLERANT); IF_EQUAL_RETURN(guid, MF_MT_IMAGE_LOSS_TOLERANT);
IF_EQUAL_RETURN(guid, MF_MT_MPEG4_SAMPLE_DESCRIPTION); IF_EQUAL_RETURN(guid, MF_MT_MPEG4_SAMPLE_DESCRIPTION);
IF_EQUAL_RETURN(guid, MF_MT_MPEG4_CURRENT_SAMPLE_ENTRY); IF_EQUAL_RETURN(guid, MF_MT_MPEG4_CURRENT_SAMPLE_ENTRY);
IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_4CC); IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_4CC);
IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_WAVE_FORMAT_TAG); IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_WAVE_FORMAT_TAG);
// Media types // Media types
IF_EQUAL_RETURN(guid, MFMediaType_Audio); IF_EQUAL_RETURN(guid, MFMediaType_Audio);
IF_EQUAL_RETURN(guid, MFMediaType_Video); IF_EQUAL_RETURN(guid, MFMediaType_Video);
IF_EQUAL_RETURN(guid, MFMediaType_Protected); IF_EQUAL_RETURN(guid, MFMediaType_Protected);
...@@ -1027,9 +738,8 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid) ...@@ -1027,9 +738,8 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid)
IF_EQUAL_RETURN(guid, MFMediaType_HTML); IF_EQUAL_RETURN(guid, MFMediaType_HTML);
IF_EQUAL_RETURN(guid, MFMediaType_Binary); IF_EQUAL_RETURN(guid, MFMediaType_Binary);
IF_EQUAL_RETURN(guid, MFMediaType_FileTransfer); IF_EQUAL_RETURN(guid, MFMediaType_FileTransfer);
IF_EQUAL_RETURN(guid, MFVideoFormat_AI44); // FCC('AI44') IF_EQUAL_RETURN(guid, MFVideoFormat_AI44); // FCC('AI44')
IF_EQUAL_RETURN(guid, MFVideoFormat_ARGB32); // D3DFMT_A8R8G8B8 IF_EQUAL_RETURN(guid, MFVideoFormat_ARGB32); // D3DFMT_A8R8G8B8
IF_EQUAL_RETURN(guid, MFVideoFormat_AYUV); // FCC('AYUV') IF_EQUAL_RETURN(guid, MFVideoFormat_AYUV); // FCC('AYUV')
IF_EQUAL_RETURN(guid, MFVideoFormat_DV25); // FCC('dv25') IF_EQUAL_RETURN(guid, MFVideoFormat_DV25); // FCC('dv25')
IF_EQUAL_RETURN(guid, MFVideoFormat_DV50); // FCC('dv50') IF_EQUAL_RETURN(guid, MFVideoFormat_DV50); // FCC('dv50')
...@@ -1053,10 +763,10 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid) ...@@ -1053,10 +763,10 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid)
IF_EQUAL_RETURN(guid, MFVideoFormat_P016); // FCC('P016') IF_EQUAL_RETURN(guid, MFVideoFormat_P016); // FCC('P016')
IF_EQUAL_RETURN(guid, MFVideoFormat_P210); // FCC('P210') IF_EQUAL_RETURN(guid, MFVideoFormat_P210); // FCC('P210')
IF_EQUAL_RETURN(guid, MFVideoFormat_P216); // FCC('P216') IF_EQUAL_RETURN(guid, MFVideoFormat_P216); // FCC('P216')
IF_EQUAL_RETURN(guid, MFVideoFormat_RGB24); // D3DFMT_R8G8B8 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB24); // D3DFMT_R8G8B8
IF_EQUAL_RETURN(guid, MFVideoFormat_RGB32); // D3DFMT_X8R8G8B8 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB32); // D3DFMT_X8R8G8B8
IF_EQUAL_RETURN(guid, MFVideoFormat_RGB555); // D3DFMT_X1R5G5B5 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB555); // D3DFMT_X1R5G5B5
IF_EQUAL_RETURN(guid, MFVideoFormat_RGB565); // D3DFMT_R5G6B5 IF_EQUAL_RETURN(guid, MFVideoFormat_RGB565); // D3DFMT_R5G6B5
IF_EQUAL_RETURN(guid, MFVideoFormat_RGB8); IF_EQUAL_RETURN(guid, MFVideoFormat_RGB8);
IF_EQUAL_RETURN(guid, MFVideoFormat_UYVY); // FCC('UYVY') IF_EQUAL_RETURN(guid, MFVideoFormat_UYVY); // FCC('UYVY')
IF_EQUAL_RETURN(guid, MFVideoFormat_v210); // FCC('v210') IF_EQUAL_RETURN(guid, MFVideoFormat_v210); // FCC('v210')
...@@ -1074,162 +784,118 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid) ...@@ -1074,162 +784,118 @@ LPCWSTR GetGUIDNameConstNew(const GUID& guid)
IF_EQUAL_RETURN(guid, MFVideoFormat_YUY2); // FCC('YUY2') IF_EQUAL_RETURN(guid, MFVideoFormat_YUY2); // FCC('YUY2')
IF_EQUAL_RETURN(guid, MFVideoFormat_YV12); // FCC('YV12') IF_EQUAL_RETURN(guid, MFVideoFormat_YV12); // FCC('YV12')
IF_EQUAL_RETURN(guid, MFVideoFormat_YVYU); IF_EQUAL_RETURN(guid, MFVideoFormat_YVYU);
IF_EQUAL_RETURN(guid, MFAudioFormat_PCM); // WAVE_FORMAT_PCM
IF_EQUAL_RETURN(guid, MFAudioFormat_PCM); // WAVE_FORMAT_PCM IF_EQUAL_RETURN(guid, MFAudioFormat_Float); // WAVE_FORMAT_IEEE_FLOAT
IF_EQUAL_RETURN(guid, MFAudioFormat_Float); // WAVE_FORMAT_IEEE_FLOAT IF_EQUAL_RETURN(guid, MFAudioFormat_DTS); // WAVE_FORMAT_DTS
IF_EQUAL_RETURN(guid, MFAudioFormat_DTS); // WAVE_FORMAT_DTS IF_EQUAL_RETURN(guid, MFAudioFormat_Dolby_AC3_SPDIF); // WAVE_FORMAT_DOLBY_AC3_SPDIF
IF_EQUAL_RETURN(guid, MFAudioFormat_Dolby_AC3_SPDIF); // WAVE_FORMAT_DOLBY_AC3_SPDIF IF_EQUAL_RETURN(guid, MFAudioFormat_DRM); // WAVE_FORMAT_DRM
IF_EQUAL_RETURN(guid, MFAudioFormat_DRM); // WAVE_FORMAT_DRM IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV8); // WAVE_FORMAT_WMAUDIO2
IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV8); // WAVE_FORMAT_WMAUDIO2 IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV9); // WAVE_FORMAT_WMAUDIO3
IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV9); // WAVE_FORMAT_WMAUDIO3 IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudio_Lossless); // WAVE_FORMAT_WMAUDIO_LOSSLESS
IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudio_Lossless); // WAVE_FORMAT_WMAUDIO_LOSSLESS IF_EQUAL_RETURN(guid, MFAudioFormat_WMASPDIF); // WAVE_FORMAT_WMASPDIF
IF_EQUAL_RETURN(guid, MFAudioFormat_WMASPDIF); // WAVE_FORMAT_WMASPDIF IF_EQUAL_RETURN(guid, MFAudioFormat_MSP1); // WAVE_FORMAT_WMAVOICE9
IF_EQUAL_RETURN(guid, MFAudioFormat_MSP1); // WAVE_FORMAT_WMAVOICE9 IF_EQUAL_RETURN(guid, MFAudioFormat_MP3); // WAVE_FORMAT_MPEGLAYER3
IF_EQUAL_RETURN(guid, MFAudioFormat_MP3); // WAVE_FORMAT_MPEGLAYER3 IF_EQUAL_RETURN(guid, MFAudioFormat_MPEG); // WAVE_FORMAT_MPEG
IF_EQUAL_RETURN(guid, MFAudioFormat_MPEG); // WAVE_FORMAT_MPEG IF_EQUAL_RETURN(guid, MFAudioFormat_AAC); // WAVE_FORMAT_MPEG_HEAAC
IF_EQUAL_RETURN(guid, MFAudioFormat_AAC); // WAVE_FORMAT_MPEG_HEAAC IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS); // WAVE_FORMAT_MPEG_ADTS_AAC
IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS); // WAVE_FORMAT_MPEG_ADTS_AAC
return NULL; return NULL;
} }
FormatReader::FormatReader(void) FormatReader::FormatReader(void)
{ {
} }
MediaType FormatReader::Read(IMFMediaType *pType) MediaType FormatReader::Read(IMFMediaType *pType)
{ {
UINT32 count = 0; UINT32 count = 0;
HRESULT hr = S_OK; HRESULT hr = S_OK;
MediaType out; MediaType out;
hr = pType->LockStore(); hr = pType->LockStore();
if (FAILED(hr)) if (FAILED(hr))
{ {
return out; return out;
} }
hr = pType->GetCount(&count); hr = pType->GetCount(&count);
if (FAILED(hr)) if (FAILED(hr))
{ {
return out; return out;
} }
for (UINT32 i = 0; i < count; i++) for (UINT32 i = 0; i < count; i++)
{ {
hr = LogAttributeValueByIndexNew(pType, i, out); hr = LogAttributeValueByIndexNew(pType, i, out);
if (FAILED(hr)) if (FAILED(hr))
{ {
break; break;
} }
} }
hr = pType->UnlockStore(); hr = pType->UnlockStore();
if (FAILED(hr)) if (FAILED(hr))
{ {
return out; return out;
} }
return out; return out;
} }
FormatReader::~FormatReader(void) FormatReader::~FormatReader(void)
{ {
} }
#define CHECK_HR(x) if (FAILED(x)) { goto done; } #define CHECK_HR(x) if (FAILED(x)) { goto done; }
ImageGrabber::ImageGrabber(unsigned int deviceID): m_cRef(1), ig_DeviceID(deviceID), ig_pSource(NULL), ig_pSession(NULL), ig_pTopology(NULL), ig_RIE(true), ig_Close(false) ImageGrabber::ImageGrabber(unsigned int deviceID): m_cRef(1), ig_DeviceID(deviceID), ig_pSource(NULL), ig_pSession(NULL), ig_pTopology(NULL), ig_RIE(true), ig_Close(false)
{ {
} }
ImageGrabber::~ImageGrabber(void) ImageGrabber::~ImageGrabber(void)
{ {
if (ig_pSession) if (ig_pSession)
{ {
ig_pSession->Shutdown(); ig_pSession->Shutdown();
} }
//SafeRelease(&ig_pSession); //SafeRelease(&ig_pSession);
//SafeRelease(&ig_pTopology); //SafeRelease(&ig_pTopology);
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Destroing instance of the ImageGrabber class \n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Destroing instance of the ImageGrabber class \n", ig_DeviceID);
} }
HRESULT ImageGrabber::initImageGrabber(IMFMediaSource *pSource, GUID VideoFormat) HRESULT ImageGrabber::initImageGrabber(IMFMediaSource *pSource, GUID VideoFormat)
{ {
IMFActivate *pSinkActivate = NULL; IMFActivate *pSinkActivate = NULL;
IMFMediaType *pType = NULL; IMFMediaType *pType = NULL;
IMFPresentationDescriptor *pPD = NULL; IMFPresentationDescriptor *pPD = NULL;
IMFStreamDescriptor *pSD = NULL; IMFStreamDescriptor *pSD = NULL;
IMFMediaTypeHandler *pHandler = NULL; IMFMediaTypeHandler *pHandler = NULL;
IMFMediaType *pCurrentType = NULL; IMFMediaType *pCurrentType = NULL;
HRESULT hr = S_OK; HRESULT hr = S_OK;
MediaType MT; MediaType MT;
// Clean up. // Clean up.
if (ig_pSession) if (ig_pSession)
{ {
ig_pSession->Shutdown(); ig_pSession->Shutdown();
} }
SafeRelease(&ig_pSession); SafeRelease(&ig_pSession);
SafeRelease(&ig_pTopology); SafeRelease(&ig_pTopology);
ig_pSource = pSource; ig_pSource = pSource;
hr = pSource->CreatePresentationDescriptor(&pPD); hr = pSource->CreatePresentationDescriptor(&pPD);
if (FAILED(hr)) if (FAILED(hr))
goto err; goto err;
BOOL fSelected; BOOL fSelected;
hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD); hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD);
if (FAILED(hr)) if (FAILED(hr))
goto err; goto err;
hr = pSD->GetMediaTypeHandler(&pHandler); hr = pSD->GetMediaTypeHandler(&pHandler);
if (FAILED(hr)) if (FAILED(hr))
goto err; goto err;
DWORD cTypes = 0; DWORD cTypes = 0;
hr = pHandler->GetMediaTypeCount(&cTypes); hr = pHandler->GetMediaTypeCount(&cTypes);
if (FAILED(hr)) if (FAILED(hr))
goto err; goto err;
if(cTypes > 0) if(cTypes > 0)
{ {
hr = pHandler->GetCurrentMediaType(&pCurrentType); hr = pHandler->GetCurrentMediaType(&pCurrentType);
if (FAILED(hr)) if (FAILED(hr))
goto err; goto err;
MT = FormatReader::Read(pCurrentType); MT = FormatReader::Read(pCurrentType);
} }
err: err:
SafeRelease(&pPD); SafeRelease(&pPD);
SafeRelease(&pSD); SafeRelease(&pSD);
SafeRelease(&pHandler); SafeRelease(&pHandler);
SafeRelease(&pCurrentType); SafeRelease(&pCurrentType);
unsigned int sizeRawImage = 0; unsigned int sizeRawImage = 0;
if(VideoFormat == MFVideoFormat_RGB24) if(VideoFormat == MFVideoFormat_RGB24)
{ {
sizeRawImage = MT.MF_MT_FRAME_SIZE * 3; sizeRawImage = MT.MF_MT_FRAME_SIZE * 3;
...@@ -1238,151 +904,103 @@ err: ...@@ -1238,151 +904,103 @@ err:
{ {
sizeRawImage = MT.MF_MT_FRAME_SIZE * 4; sizeRawImage = MT.MF_MT_FRAME_SIZE * 4;
} }
CHECK_HR(hr = RawImage::CreateInstance(&ig_RIFirst, sizeRawImage)); CHECK_HR(hr = RawImage::CreateInstance(&ig_RIFirst, sizeRawImage));
CHECK_HR(hr = RawImage::CreateInstance(&ig_RISecond, sizeRawImage)); CHECK_HR(hr = RawImage::CreateInstance(&ig_RISecond, sizeRawImage));
ig_RIOut = ig_RISecond; ig_RIOut = ig_RISecond;
// Configure the media type that the Sample Grabber will receive. // Configure the media type that the Sample Grabber will receive.
// Setting the major and subtype is usually enough for the topology loader // Setting the major and subtype is usually enough for the topology loader
// to resolve the topology. // to resolve the topology.
CHECK_HR(hr = MFCreateMediaType(&pType)); CHECK_HR(hr = MFCreateMediaType(&pType));
CHECK_HR(hr = pType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video)); CHECK_HR(hr = pType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
CHECK_HR(hr = pType->SetGUID(MF_MT_SUBTYPE, VideoFormat)); CHECK_HR(hr = pType->SetGUID(MF_MT_SUBTYPE, VideoFormat));
// Create the sample grabber sink. // Create the sample grabber sink.
CHECK_HR(hr = MFCreateSampleGrabberSinkActivate(pType, this, &pSinkActivate)); CHECK_HR(hr = MFCreateSampleGrabberSinkActivate(pType, this, &pSinkActivate));
// To run as fast as possible, set this attribute (requires Windows 7): // To run as fast as possible, set this attribute (requires Windows 7):
CHECK_HR(hr = pSinkActivate->SetUINT32(MF_SAMPLEGRABBERSINK_IGNORE_CLOCK, TRUE)); CHECK_HR(hr = pSinkActivate->SetUINT32(MF_SAMPLEGRABBERSINK_IGNORE_CLOCK, TRUE));
// Create the Media Session. // Create the Media Session.
CHECK_HR(hr = MFCreateMediaSession(NULL, &ig_pSession)); CHECK_HR(hr = MFCreateMediaSession(NULL, &ig_pSession));
// Create the topology. // Create the topology.
CHECK_HR(hr = CreateTopology(pSource, pSinkActivate, &ig_pTopology)); CHECK_HR(hr = CreateTopology(pSource, pSinkActivate, &ig_pTopology));
done: done:
// Clean up. // Clean up.
if (FAILED(hr)) if (FAILED(hr))
{ {
if (ig_pSession) if (ig_pSession)
{ {
ig_pSession->Shutdown(); ig_pSession->Shutdown();
} }
SafeRelease(&ig_pSession); SafeRelease(&ig_pSession);
SafeRelease(&ig_pTopology); SafeRelease(&ig_pTopology);
} }
SafeRelease(&pSinkActivate); SafeRelease(&pSinkActivate);
SafeRelease(&pType); SafeRelease(&pType);
return hr; return hr;
} }
void ImageGrabber::stopGrabbing() void ImageGrabber::stopGrabbing()
{ {
if(ig_pSession) if(ig_pSession)
ig_pSession->Stop(); ig_pSession->Stop();
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Stopping of of grabbing of images\n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Stopping of of grabbing of images\n", ig_DeviceID);
} }
HRESULT ImageGrabber::startGrabbing(void) HRESULT ImageGrabber::startGrabbing(void)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
IMFMediaEvent *pEvent = NULL; IMFMediaEvent *pEvent = NULL;
PROPVARIANT var; PROPVARIANT var;
PropVariantInit(&var); PropVariantInit(&var);
HRESULT hr = S_OK; HRESULT hr = S_OK;
CHECK_HR(hr = ig_pSession->SetTopology(0, ig_pTopology)); CHECK_HR(hr = ig_pSession->SetTopology(0, ig_pTopology));
CHECK_HR(hr = ig_pSession->Start(&GUID_NULL, &var)); CHECK_HR(hr = ig_pSession->Start(&GUID_NULL, &var));
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Start Grabbing of the images\n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Start Grabbing of the images\n", ig_DeviceID);
for(;;) for(;;)
{ {
HRESULT hrStatus = S_OK; HRESULT hrStatus = S_OK;
MediaEventType met; MediaEventType met;
if(!ig_pSession) break; if(!ig_pSession) break;
hr = ig_pSession->GetEvent(0, &pEvent); hr = ig_pSession->GetEvent(0, &pEvent);
if(!SUCCEEDED(hr)) if(!SUCCEEDED(hr))
{ {
hr = S_OK; hr = S_OK;
goto done; goto done;
} }
hr = pEvent->GetStatus(&hrStatus); hr = pEvent->GetStatus(&hrStatus);
if(!SUCCEEDED(hr)) if(!SUCCEEDED(hr))
{ {
hr = S_OK; hr = S_OK;
goto done; goto done;
} }
hr = pEvent->GetType(&met); hr = pEvent->GetType(&met);
if(!SUCCEEDED(hr)) if(!SUCCEEDED(hr))
{ {
hr = S_OK; hr = S_OK;
goto done; goto done;
} }
if (met == MESessionEnded) if (met == MESessionEnded)
{ {
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MESessionEnded \n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MESessionEnded \n", ig_DeviceID);
ig_pSession->Stop(); ig_pSession->Stop();
break; break;
} }
if (met == MESessionStopped) if (met == MESessionStopped)
{ {
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MESessionStopped \n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MESessionStopped \n", ig_DeviceID);
break; break;
} }
if (met == MEVideoCaptureDeviceRemoved) if (met == MEVideoCaptureDeviceRemoved)
{ {
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MEVideoCaptureDeviceRemoved \n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: MEVideoCaptureDeviceRemoved \n", ig_DeviceID);
break;
break;
} }
SafeRelease(&pEvent); SafeRelease(&pEvent);
} }
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Finish startGrabbing \n", ig_DeviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Finish startGrabbing \n", ig_DeviceID);
done: done:
SafeRelease(&pEvent); SafeRelease(&pEvent);
SafeRelease(&ig_pSession); SafeRelease(&ig_pSession);
SafeRelease(&ig_pTopology); SafeRelease(&ig_pTopology);
return hr; return hr;
} }
HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo) HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo)
{ {
IMFTopology *pTopology = NULL; IMFTopology *pTopology = NULL;
...@@ -1391,25 +1009,19 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink ...@@ -1391,25 +1009,19 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
IMFMediaTypeHandler *pHandler = NULL; IMFMediaTypeHandler *pHandler = NULL;
IMFTopologyNode *pNode1 = NULL; IMFTopologyNode *pNode1 = NULL;
IMFTopologyNode *pNode2 = NULL; IMFTopologyNode *pNode2 = NULL;
HRESULT hr = S_OK; HRESULT hr = S_OK;
DWORD cStreams = 0; DWORD cStreams = 0;
CHECK_HR(hr = MFCreateTopology(&pTopology)); CHECK_HR(hr = MFCreateTopology(&pTopology));
CHECK_HR(hr = pSource->CreatePresentationDescriptor(&pPD)); CHECK_HR(hr = pSource->CreatePresentationDescriptor(&pPD));
CHECK_HR(hr = pPD->GetStreamDescriptorCount(&cStreams)); CHECK_HR(hr = pPD->GetStreamDescriptorCount(&cStreams));
for (DWORD i = 0; i < cStreams; i++) for (DWORD i = 0; i < cStreams; i++)
{ {
// In this example, we look for audio streams and connect them to the sink. // In this example, we look for audio streams and connect them to the sink.
BOOL fSelected = FALSE; BOOL fSelected = FALSE;
GUID majorType; GUID majorType;
CHECK_HR(hr = pPD->GetStreamDescriptorByIndex(i, &fSelected, &pSD)); CHECK_HR(hr = pPD->GetStreamDescriptorByIndex(i, &fSelected, &pSD));
CHECK_HR(hr = pSD->GetMediaTypeHandler(&pHandler)); CHECK_HR(hr = pSD->GetMediaTypeHandler(&pHandler));
CHECK_HR(hr = pHandler->GetMajorType(&majorType)); CHECK_HR(hr = pHandler->GetMajorType(&majorType));
if (majorType == MFMediaType_Video && fSelected) if (majorType == MFMediaType_Video && fSelected)
{ {
CHECK_HR(hr = AddSourceNode(pTopology, pSource, pPD, pSD, &pNode1)); CHECK_HR(hr = AddSourceNode(pTopology, pSource, pPD, pSD, &pNode1));
...@@ -1424,10 +1036,8 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink ...@@ -1424,10 +1036,8 @@ HRESULT ImageGrabber::CreateTopology(IMFMediaSource *pSource, IMFActivate *pSink
SafeRelease(&pSD); SafeRelease(&pSD);
SafeRelease(&pHandler); SafeRelease(&pHandler);
} }
*ppTopo = pTopology; *ppTopo = pTopology;
(*ppTopo)->AddRef(); (*ppTopo)->AddRef();
done: done:
SafeRelease(&pTopology); SafeRelease(&pTopology);
SafeRelease(&pNode1); SafeRelease(&pNode1);
...@@ -1437,7 +1047,6 @@ done: ...@@ -1437,7 +1047,6 @@ done:
SafeRelease(&pHandler); SafeRelease(&pHandler);
return hr; return hr;
} }
HRESULT ImageGrabber::AddSourceNode( HRESULT ImageGrabber::AddSourceNode(
IMFTopology *pTopology, // Topology. IMFTopology *pTopology, // Topology.
IMFMediaSource *pSource, // Media source. IMFMediaSource *pSource, // Media source.
...@@ -1446,23 +1055,19 @@ HRESULT ImageGrabber::AddSourceNode( ...@@ -1446,23 +1055,19 @@ HRESULT ImageGrabber::AddSourceNode(
IMFTopologyNode **ppNode) // Receives the node pointer. IMFTopologyNode **ppNode) // Receives the node pointer.
{ {
IMFTopologyNode *pNode = NULL; IMFTopologyNode *pNode = NULL;
HRESULT hr = S_OK; HRESULT hr = S_OK;
CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &pNode)); CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &pNode));
CHECK_HR(hr = pNode->SetUnknown(MF_TOPONODE_SOURCE, pSource)); CHECK_HR(hr = pNode->SetUnknown(MF_TOPONODE_SOURCE, pSource));
CHECK_HR(hr = pNode->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, pPD)); CHECK_HR(hr = pNode->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, pPD));
CHECK_HR(hr = pNode->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, pSD)); CHECK_HR(hr = pNode->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, pSD));
CHECK_HR(hr = pTopology->AddNode(pNode)); CHECK_HR(hr = pTopology->AddNode(pNode));
// Return the pointer to the caller. // Return the pointer to the caller.
*ppNode = pNode; *ppNode = pNode;
(*ppNode)->AddRef(); (*ppNode)->AddRef();
done: done:
SafeRelease(&pNode); SafeRelease(&pNode);
return hr; return hr;
} }
HRESULT ImageGrabber::AddOutputNode( HRESULT ImageGrabber::AddOutputNode(
IMFTopology *pTopology, // Topology. IMFTopology *pTopology, // Topology.
IMFActivate *pActivate, // Media sink activation object. IMFActivate *pActivate, // Media sink activation object.
...@@ -1470,71 +1075,54 @@ HRESULT ImageGrabber::AddOutputNode( ...@@ -1470,71 +1075,54 @@ HRESULT ImageGrabber::AddOutputNode(
IMFTopologyNode **ppNode) // Receives the node pointer. IMFTopologyNode **ppNode) // Receives the node pointer.
{ {
IMFTopologyNode *pNode = NULL; IMFTopologyNode *pNode = NULL;
HRESULT hr = S_OK; HRESULT hr = S_OK;
CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &pNode)); CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &pNode));
CHECK_HR(hr = pNode->SetObject(pActivate)); CHECK_HR(hr = pNode->SetObject(pActivate));
CHECK_HR(hr = pNode->SetUINT32(MF_TOPONODE_STREAMID, dwId)); CHECK_HR(hr = pNode->SetUINT32(MF_TOPONODE_STREAMID, dwId));
CHECK_HR(hr = pNode->SetUINT32(MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, FALSE)); CHECK_HR(hr = pNode->SetUINT32(MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, FALSE));
CHECK_HR(hr = pTopology->AddNode(pNode)); CHECK_HR(hr = pTopology->AddNode(pNode));
// Return the pointer to the caller. // Return the pointer to the caller.
*ppNode = pNode; *ppNode = pNode;
(*ppNode)->AddRef(); (*ppNode)->AddRef();
done: done:
SafeRelease(&pNode); SafeRelease(&pNode);
return hr; return hr;
} }
HRESULT ImageGrabber::CreateInstance(ImageGrabber **ppIG, unsigned int deviceID) HRESULT ImageGrabber::CreateInstance(ImageGrabber **ppIG, unsigned int deviceID)
{ {
*ppIG = new (std::nothrow) ImageGrabber(deviceID); *ppIG = new (std::nothrow) ImageGrabber(deviceID);
if (ppIG == NULL) if (ppIG == NULL)
{ {
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Creating instance of ImageGrabber\n", deviceID); DPO->printOut(L"IMAGEGRABBER VIDEODEVICE %i: Creating instance of ImageGrabber\n", deviceID);
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::QueryInterface(REFIID riid, void** ppv) STDMETHODIMP ImageGrabber::QueryInterface(REFIID riid, void** ppv)
{ {
HRESULT hr = E_NOINTERFACE; HRESULT hr = E_NOINTERFACE;
*ppv = NULL; *ppv = NULL;
if(riid == IID_IUnknown || riid == IID_IMFSampleGrabberSinkCallback) if(riid == IID_IUnknown || riid == IID_IMFSampleGrabberSinkCallback)
{ {
*ppv = static_cast<IMFSampleGrabberSinkCallback *>(this); *ppv = static_cast<IMFSampleGrabberSinkCallback *>(this);
hr = S_OK; hr = S_OK;
} }
if(riid == IID_IMFClockStateSink) if(riid == IID_IMFClockStateSink)
{ {
*ppv = static_cast<IMFClockStateSink *>(this); *ppv = static_cast<IMFClockStateSink *>(this);
hr = S_OK; hr = S_OK;
} }
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
reinterpret_cast<IUnknown *>(*ppv)->AddRef(); reinterpret_cast<IUnknown *>(*ppv)->AddRef();
} }
return hr; return hr;
} }
STDMETHODIMP_(ULONG) ImageGrabber::AddRef() STDMETHODIMP_(ULONG) ImageGrabber::AddRef()
{ {
return InterlockedIncrement(&m_cRef); return InterlockedIncrement(&m_cRef);
} }
STDMETHODIMP_(ULONG) ImageGrabber::Release() STDMETHODIMP_(ULONG) ImageGrabber::Release()
{ {
ULONG cRef = InterlockedDecrement(&m_cRef); ULONG cRef = InterlockedDecrement(&m_cRef);
...@@ -1544,45 +1132,38 @@ STDMETHODIMP_(ULONG) ImageGrabber::Release() ...@@ -1544,45 +1132,38 @@ STDMETHODIMP_(ULONG) ImageGrabber::Release()
} }
return cRef; return cRef;
} }
STDMETHODIMP ImageGrabber::OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset) STDMETHODIMP ImageGrabber::OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset)
{ {
(void)hnsSystemTime; (void)hnsSystemTime;
(void)llClockStartOffset; (void)llClockStartOffset;
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnClockStop(MFTIME hnsSystemTime) STDMETHODIMP ImageGrabber::OnClockStop(MFTIME hnsSystemTime)
{ {
(void)hnsSystemTime; (void)hnsSystemTime;
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnClockPause(MFTIME hnsSystemTime) STDMETHODIMP ImageGrabber::OnClockPause(MFTIME hnsSystemTime)
{ {
(void)hnsSystemTime; (void)hnsSystemTime;
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnClockRestart(MFTIME hnsSystemTime) STDMETHODIMP ImageGrabber::OnClockRestart(MFTIME hnsSystemTime)
{ {
(void)hnsSystemTime; (void)hnsSystemTime;
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnClockSetRate(MFTIME hnsSystemTime, float flRate) STDMETHODIMP ImageGrabber::OnClockSetRate(MFTIME hnsSystemTime, float flRate)
{ {
(void)flRate; (void)flRate;
(void)hnsSystemTime; (void)hnsSystemTime;
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnSetPresentationClock(IMFPresentationClock* pClock) STDMETHODIMP ImageGrabber::OnSetPresentationClock(IMFPresentationClock* pClock)
{ {
(void)pClock; (void)pClock;
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags, STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags,
LONGLONG llSampleTime, LONGLONG llSampleDuration, const BYTE * pSampleBuffer, LONGLONG llSampleTime, LONGLONG llSampleDuration, const BYTE * pSampleBuffer,
DWORD dwSampleSize) DWORD dwSampleSize)
...@@ -1592,74 +1173,54 @@ STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwS ...@@ -1592,74 +1173,54 @@ STDMETHODIMP ImageGrabber::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwS
(void)dwSampleFlags; (void)dwSampleFlags;
(void)llSampleDuration; (void)llSampleDuration;
(void)dwSampleSize; (void)dwSampleSize;
if(ig_RIE) if(ig_RIE)
{ {
ig_RIFirst->fastCopy(pSampleBuffer); ig_RIFirst->fastCopy(pSampleBuffer);
ig_RIOut = ig_RIFirst; ig_RIOut = ig_RIFirst;
} }
else else
{ {
ig_RISecond->fastCopy(pSampleBuffer); ig_RISecond->fastCopy(pSampleBuffer);
ig_RIOut = ig_RISecond; ig_RIOut = ig_RISecond;
} }
ig_RIE = !ig_RIE; ig_RIE = !ig_RIE;
return S_OK; return S_OK;
} }
STDMETHODIMP ImageGrabber::OnShutdown() STDMETHODIMP ImageGrabber::OnShutdown()
{ {
return S_OK; return S_OK;
} }
RawImage *ImageGrabber::getRawImage() RawImage *ImageGrabber::getRawImage()
{ {
return ig_RIOut; return ig_RIOut;
} }
DWORD WINAPI MainThreadFunction( LPVOID lpParam ) DWORD WINAPI MainThreadFunction( LPVOID lpParam )
{ {
ImageGrabberThread *pIGT = (ImageGrabberThread *)lpParam; ImageGrabberThread *pIGT = (ImageGrabberThread *)lpParam;
pIGT->run(); pIGT->run();
return 0;
return 0;
} }
HRESULT ImageGrabberThread::CreateInstance(ImageGrabberThread **ppIGT, IMFMediaSource *pSource, unsigned int deviceID) HRESULT ImageGrabberThread::CreateInstance(ImageGrabberThread **ppIGT, IMFMediaSource *pSource, unsigned int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
*ppIGT = new (std::nothrow) ImageGrabberThread(pSource, deviceID); *ppIGT = new (std::nothrow) ImageGrabberThread(pSource, deviceID);
if (ppIGT == NULL) if (ppIGT == NULL)
{ {
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Memory cannot be allocated\n", deviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Memory cannot be allocated\n", deviceID);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
else else
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Creating of the instance of ImageGrabberThread\n", deviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Creating of the instance of ImageGrabberThread\n", deviceID);
return S_OK; return S_OK;
} }
ImageGrabberThread::ImageGrabberThread(IMFMediaSource *pSource, unsigned int deviceID): igt_Handle(NULL), igt_stop(false) ImageGrabberThread::ImageGrabberThread(IMFMediaSource *pSource, unsigned int deviceID): igt_Handle(NULL), igt_stop(false)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
HRESULT hr = ImageGrabber::CreateInstance(&igt_pImageGrabber, deviceID); HRESULT hr = ImageGrabber::CreateInstance(&igt_pImageGrabber, deviceID);
igt_DeviceID = deviceID; igt_DeviceID = deviceID;
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
hr = igt_pImageGrabber->initImageGrabber(pSource, MFVideoFormat_RGB24); hr = igt_pImageGrabber->initImageGrabber(pSource, MFVideoFormat_RGB24);
if(!SUCCEEDED(hr)) if(!SUCCEEDED(hr))
{ {
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: There is a problem with initialization of the instance of the ImageGrabber class\n", deviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: There is a problem with initialization of the instance of the ImageGrabber class\n", deviceID);
...@@ -1674,73 +1235,57 @@ ImageGrabberThread::ImageGrabberThread(IMFMediaSource *pSource, unsigned int dev ...@@ -1674,73 +1235,57 @@ ImageGrabberThread::ImageGrabberThread(IMFMediaSource *pSource, unsigned int dev
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i There is a problem with creation of the instance of the ImageGrabber class\n", deviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i There is a problem with creation of the instance of the ImageGrabber class\n", deviceID);
} }
} }
void ImageGrabberThread::setEmergencyStopEvent(void *userData, void(*func)(int, void *)) void ImageGrabberThread::setEmergencyStopEvent(void *userData, void(*func)(int, void *))
{ {
if(func) if(func)
{ {
igt_func = func; igt_func = func;
igt_userData = userData; igt_userData = userData;
} }
} }
ImageGrabberThread::~ImageGrabberThread(void) ImageGrabberThread::~ImageGrabberThread(void)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Destroing ImageGrabberThread\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Destroing ImageGrabberThread\n", igt_DeviceID);
delete igt_pImageGrabber; delete igt_pImageGrabber;
} }
void ImageGrabberThread::stop() void ImageGrabberThread::stop()
{ {
igt_stop = true; igt_stop = true;
if(igt_pImageGrabber) if(igt_pImageGrabber)
{ {
igt_pImageGrabber->stopGrabbing(); igt_pImageGrabber->stopGrabbing();
} }
} }
void ImageGrabberThread::start() void ImageGrabberThread::start()
{ {
igt_Handle = CreateThread( igt_Handle = CreateThread(
NULL, // default security attributes NULL, // default security attributes
0, // use default stack size 0, // use default stack size
MainThreadFunction, // thread function name MainThreadFunction, // thread function name
this, // argument to thread function this, // argument to thread function
0, // use default creation flags 0, // use default creation flags
&igt_ThreadIdArray); // returns the thread identifier &igt_ThreadIdArray); // returns the thread identifier
} }
void ImageGrabberThread::run() void ImageGrabberThread::run()
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if(igt_pImageGrabber) if(igt_pImageGrabber)
{ {
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Thread for grabbing images is started\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Thread for grabbing images is started\n", igt_DeviceID);
HRESULT hr = igt_pImageGrabber->startGrabbing(); HRESULT hr = igt_pImageGrabber->startGrabbing();
if(!SUCCEEDED(hr))
if(!SUCCEEDED(hr))
{ {
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: There is a problem with starting the process of grabbing\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: There is a problem with starting the process of grabbing\n", igt_DeviceID);
} }
} }
else else
{ {
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i The thread is finished without execution of grabbing\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i The thread is finished without execution of grabbing\n", igt_DeviceID);
} }
if(!igt_stop) if(!igt_stop)
{ {
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Emergency Stop thread\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Emergency Stop thread\n", igt_DeviceID);
if(igt_func) if(igt_func)
{ {
igt_func(igt_DeviceID, igt_userData); igt_func(igt_DeviceID, igt_userData);
...@@ -1749,46 +1294,34 @@ void ImageGrabberThread::run() ...@@ -1749,46 +1294,34 @@ void ImageGrabberThread::run()
else else
DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Finish thread\n", igt_DeviceID); DPO->printOut(L"IMAGEGRABBERTHREAD VIDEODEVICE %i: Finish thread\n", igt_DeviceID);
} }
ImageGrabber *ImageGrabberThread::getImageGrabber() ImageGrabber *ImageGrabberThread::getImageGrabber()
{ {
return igt_pImageGrabber; return igt_pImageGrabber;
} }
Media_Foundation::Media_Foundation(void) Media_Foundation::Media_Foundation(void)
{ {
HRESULT hr = MFStartup(MF_VERSION); HRESULT hr = MFStartup(MF_VERSION);
if(!SUCCEEDED(hr)) if(!SUCCEEDED(hr))
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"MEDIA FOUNDATION: It cannot be created!!!\n"); DPO->printOut(L"MEDIA FOUNDATION: It cannot be created!!!\n");
} }
} }
Media_Foundation::~Media_Foundation(void) Media_Foundation::~Media_Foundation(void)
{ {
HRESULT hr = MFShutdown(); HRESULT hr = MFShutdown();
if(!SUCCEEDED(hr)) if(!SUCCEEDED(hr))
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"MEDIA FOUNDATION: Resources cannot be released\n"); DPO->printOut(L"MEDIA FOUNDATION: Resources cannot be released\n");
} }
} }
bool Media_Foundation::buildListOfDevices() bool Media_Foundation::buildListOfDevices()
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
IMFAttributes *pAttributes = NULL; IMFAttributes *pAttributes = NULL;
CoInitialize(NULL); CoInitialize(NULL);
hr = MFCreateAttributes(&pAttributes, 1); hr = MFCreateAttributes(&pAttributes, 1);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = pAttributes->SetGUID( hr = pAttributes->SetGUID(
...@@ -1796,7 +1329,6 @@ bool Media_Foundation::buildListOfDevices() ...@@ -1796,7 +1329,6 @@ bool Media_Foundation::buildListOfDevices()
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
); );
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
videoDevices *vDs = &videoDevices::getInstance(); videoDevices *vDs = &videoDevices::getInstance();
...@@ -1807,80 +1339,61 @@ bool Media_Foundation::buildListOfDevices() ...@@ -1807,80 +1339,61 @@ bool Media_Foundation::buildListOfDevices()
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"MEDIA FOUNDATION: The access to the video cameras denied\n"); DPO->printOut(L"MEDIA FOUNDATION: The access to the video cameras denied\n");
} }
SafeRelease(&pAttributes); SafeRelease(&pAttributes);
return (SUCCEEDED(hr)); return (SUCCEEDED(hr));
} }
Media_Foundation& Media_Foundation::getInstance() Media_Foundation& Media_Foundation::getInstance()
{ {
static Media_Foundation instance; static Media_Foundation instance;
return instance; return instance;
} }
RawImage::RawImage(unsigned int size): ri_new(false), ri_pixels(NULL) RawImage::RawImage(unsigned int size): ri_new(false), ri_pixels(NULL)
{ {
ri_size = size; ri_size = size;
ri_pixels = new unsigned char[size]; ri_pixels = new unsigned char[size];
memset((void *)ri_pixels,0,ri_size); memset((void *)ri_pixels,0,ri_size);
} }
bool RawImage::isNew() bool RawImage::isNew()
{ {
return ri_new; return ri_new;
} }
unsigned int RawImage::getSize() unsigned int RawImage::getSize()
{ {
return ri_size; return ri_size;
} }
RawImage::~RawImage(void) RawImage::~RawImage(void)
{ {
delete []ri_pixels; delete []ri_pixels;
ri_pixels = NULL; ri_pixels = NULL;
} }
long RawImage::CreateInstance(RawImage **ppRImage,unsigned int size) long RawImage::CreateInstance(RawImage **ppRImage,unsigned int size)
{ {
*ppRImage = new (std::nothrow) RawImage(size); *ppRImage = new (std::nothrow) RawImage(size);
if (ppRImage == NULL) if (ppRImage == NULL)
{ {
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
return S_OK; return S_OK;
} }
void RawImage::setCopy(const BYTE * pSampleBuffer) void RawImage::setCopy(const BYTE * pSampleBuffer)
{ {
memcpy(ri_pixels, pSampleBuffer, ri_size); memcpy(ri_pixels, pSampleBuffer, ri_size);
ri_new = true; ri_new = true;
} }
void RawImage::fastCopy(const BYTE * pSampleBuffer) void RawImage::fastCopy(const BYTE * pSampleBuffer)
{ {
memcpy(ri_pixels, pSampleBuffer, ri_size); memcpy(ri_pixels, pSampleBuffer, ri_size);
ri_new = true; ri_new = true;
} }
unsigned char * RawImage::getpPixels() unsigned char * RawImage::getpPixels()
{ {
ri_new = false; ri_new = false;
return ri_pixels; return ri_pixels;
} }
videoDevice::videoDevice(void): vd_IsSetuped(false), vd_LockOut(OpenLock), vd_pFriendlyName(NULL), videoDevice::videoDevice(void): vd_IsSetuped(false), vd_LockOut(OpenLock), vd_pFriendlyName(NULL),
vd_Width(0), vd_Height(0), vd_pSource(NULL), vd_func(NULL), vd_userData(NULL) vd_Width(0), vd_Height(0), vd_pSource(NULL), vd_func(NULL), vd_userData(NULL)
{ {
} }
void videoDevice::setParametrs(CamParametrs parametrs) void videoDevice::setParametrs(CamParametrs parametrs)
{ {
if(vd_IsSetuped) if(vd_IsSetuped)
...@@ -1888,198 +1401,145 @@ void videoDevice::setParametrs(CamParametrs parametrs) ...@@ -1888,198 +1401,145 @@ void videoDevice::setParametrs(CamParametrs parametrs)
if(vd_pSource) if(vd_pSource)
{ {
Parametr *pParametr = (Parametr *)(&parametrs); Parametr *pParametr = (Parametr *)(&parametrs);
Parametr *pPrevParametr = (Parametr *)(&vd_PrevParametrs); Parametr *pPrevParametr = (Parametr *)(&vd_PrevParametrs);
IAMVideoProcAmp *pProcAmp = NULL; IAMVideoProcAmp *pProcAmp = NULL;
HRESULT hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcAmp)); HRESULT hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcAmp));
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
for(unsigned int i = 0; i < 10; i++) for(unsigned int i = 0; i < 10; i++)
{ {
if(pPrevParametr[i].CurrentValue != pParametr[i].CurrentValue || pPrevParametr[i].Flag != pParametr[i].Flag) if(pPrevParametr[i].CurrentValue != pParametr[i].CurrentValue || pPrevParametr[i].Flag != pParametr[i].Flag)
hr = pProcAmp->Set(VideoProcAmp_Brightness + i, pParametr[i].CurrentValue, pParametr[i].Flag); hr = pProcAmp->Set(VideoProcAmp_Brightness + i, pParametr[i].CurrentValue, pParametr[i].Flag);
} }
pProcAmp->Release(); pProcAmp->Release();
} }
IAMCameraControl *pProcControl = NULL; IAMCameraControl *pProcControl = NULL;
hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcControl)); hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcControl));
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
for(unsigned int i = 0; i < 7; i++) for(unsigned int i = 0; i < 7; i++)
{ {
if(pPrevParametr[10 + i].CurrentValue != pParametr[10 + i].CurrentValue || pPrevParametr[10 + i].Flag != pParametr[10 + i].Flag) if(pPrevParametr[10 + i].CurrentValue != pParametr[10 + i].CurrentValue || pPrevParametr[10 + i].Flag != pParametr[10 + i].Flag)
hr = pProcControl->Set(CameraControl_Pan+i, pParametr[10 + i].CurrentValue, pParametr[10 + i].Flag); hr = pProcControl->Set(CameraControl_Pan+i, pParametr[10 + i].CurrentValue, pParametr[10 + i].Flag);
} }
pProcControl->Release(); pProcControl->Release();
} }
vd_PrevParametrs = parametrs; vd_PrevParametrs = parametrs;
} }
} }
} }
CamParametrs videoDevice::getParametrs() CamParametrs videoDevice::getParametrs()
{ {
CamParametrs out; CamParametrs out;
if(vd_IsSetuped) if(vd_IsSetuped)
{ {
if(vd_pSource) if(vd_pSource)
{ {
Parametr *pParametr = (Parametr *)(&out); Parametr *pParametr = (Parametr *)(&out);
IAMVideoProcAmp *pProcAmp = NULL; IAMVideoProcAmp *pProcAmp = NULL;
HRESULT hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcAmp)); HRESULT hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcAmp));
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
for(unsigned int i = 0; i < 10; i++) for(unsigned int i = 0; i < 10; i++)
{ {
Parametr temp; Parametr temp;
hr = pProcAmp->GetRange(VideoProcAmp_Brightness+i, &temp.Min, &temp.Max, &temp.Step, &temp.Default, &temp.Flag); hr = pProcAmp->GetRange(VideoProcAmp_Brightness+i, &temp.Min, &temp.Max, &temp.Step, &temp.Default, &temp.Flag);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
temp.CurrentValue = temp.Default; temp.CurrentValue = temp.Default;
pParametr[i] = temp; pParametr[i] = temp;
} }
} }
pProcAmp->Release(); pProcAmp->Release();
} }
IAMCameraControl *pProcControl = NULL; IAMCameraControl *pProcControl = NULL;
hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcControl)); hr = vd_pSource->QueryInterface(IID_PPV_ARGS(&pProcControl));
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
for(unsigned int i = 0; i < 7; i++) for(unsigned int i = 0; i < 7; i++)
{ {
Parametr temp; Parametr temp;
hr = pProcControl->GetRange(CameraControl_Pan+i, &temp.Min, &temp.Max, &temp.Step, &temp.Default, &temp.Flag); hr = pProcControl->GetRange(CameraControl_Pan+i, &temp.Min, &temp.Max, &temp.Step, &temp.Default, &temp.Flag);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
temp.CurrentValue = temp.Default; temp.CurrentValue = temp.Default;
pParametr[10 + i] = temp; pParametr[10 + i] = temp;
} }
} }
pProcControl->Release(); pProcControl->Release();
} }
} }
} }
return out; return out;
} }
long videoDevice::resetDevice(IMFActivate *pActivate) long videoDevice::resetDevice(IMFActivate *pActivate)
{ {
HRESULT hr = -1; HRESULT hr = -1;
vd_CurrentFormats.clear(); vd_CurrentFormats.clear();
if(vd_pFriendlyName) if(vd_pFriendlyName)
CoTaskMemFree(vd_pFriendlyName); CoTaskMemFree(vd_pFriendlyName);
vd_pFriendlyName = NULL; vd_pFriendlyName = NULL;
if(pActivate) if(pActivate)
{ {
IMFMediaSource *pSource = NULL; IMFMediaSource *pSource = NULL;
hr = pActivate->GetAllocatedString( hr = pActivate->GetAllocatedString(
MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME,
&vd_pFriendlyName, &vd_pFriendlyName,
NULL NULL
); );
hr = pActivate->ActivateObject( hr = pActivate->ActivateObject(
__uuidof(IMFMediaSource), __uuidof(IMFMediaSource),
(void**)&pSource (void**)&pSource
); );
enumerateCaptureFormats(pSource); enumerateCaptureFormats(pSource);
buildLibraryofTypes(); buildLibraryofTypes();
SafeRelease(&pSource); SafeRelease(&pSource);
if(FAILED(hr))
if(FAILED(hr)) {
{
vd_pFriendlyName = NULL; vd_pFriendlyName = NULL;
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"VIDEODEVICE %i: IMFMediaSource interface cannot be created \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: IMFMediaSource interface cannot be created \n", vd_CurrentNumber);
} }
} }
return hr; return hr;
} }
long videoDevice::readInfoOfDevice(IMFActivate *pActivate, unsigned int Num) long videoDevice::readInfoOfDevice(IMFActivate *pActivate, unsigned int Num)
{ {
HRESULT hr = -1; HRESULT hr = -1;
vd_CurrentNumber = Num; vd_CurrentNumber = Num;
hr = resetDevice(pActivate); hr = resetDevice(pActivate);
return hr; return hr;
} }
long videoDevice::checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice) long videoDevice::checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
IMFActivate **ppDevices = NULL; IMFActivate **ppDevices = NULL;
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
UINT32 count; UINT32 count;
wchar_t *newFriendlyName = NULL; wchar_t *newFriendlyName = NULL;
hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count); hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
if(count > 0) if(count > 0)
{ {
if(count > vd_CurrentNumber) if(count > vd_CurrentNumber)
{ {
hr = ppDevices[vd_CurrentNumber]->GetAllocatedString( hr = ppDevices[vd_CurrentNumber]->GetAllocatedString(
MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME,
&newFriendlyName, &newFriendlyName,
NULL NULL
); );
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
if(wcscmp(newFriendlyName, vd_pFriendlyName) != 0) if(wcscmp(newFriendlyName, vd_pFriendlyName) != 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Chosen device cannot be found \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: Chosen device cannot be found \n", vd_CurrentNumber);
hr = -1; hr = -1;
pDevice = NULL; pDevice = NULL;
} }
else else
{ {
*pDevice = ppDevices[vd_CurrentNumber]; *pDevice = ppDevices[vd_CurrentNumber];
(*pDevice)->AddRef(); (*pDevice)->AddRef();
} }
} }
...@@ -2087,20 +1547,16 @@ long videoDevice::checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice) ...@@ -2087,20 +1547,16 @@ long videoDevice::checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice)
{ {
DPO->printOut(L"VIDEODEVICE %i: Name of device cannot be gotten \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: Name of device cannot be gotten \n", vd_CurrentNumber);
} }
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE %i: Number of devices more than corrent number of the device \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: Number of devices more than corrent number of the device \n", vd_CurrentNumber);
hr = -1; hr = -1;
} }
for(UINT32 i = 0; i < count; i++) for(UINT32 i = 0; i < count; i++)
{ {
SafeRelease(&ppDevices[i]); SafeRelease(&ppDevices[i]);
} }
SafeRelease(ppDevices); SafeRelease(ppDevices);
} }
else else
...@@ -2110,69 +1566,50 @@ long videoDevice::checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice) ...@@ -2110,69 +1566,50 @@ long videoDevice::checkDevice(IMFAttributes *pAttributes, IMFActivate **pDevice)
{ {
DPO->printOut(L"VIDEODEVICE %i: List of DeviceSources cannot be enumerated \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: List of DeviceSources cannot be enumerated \n", vd_CurrentNumber);
} }
return hr; return hr;
} }
long videoDevice::initDevice() long videoDevice::initDevice()
{ {
HRESULT hr = -1; HRESULT hr = -1;
IMFAttributes *pAttributes = NULL; IMFAttributes *pAttributes = NULL;
IMFActivate * vd_pActivate= NULL; IMFActivate * vd_pActivate= NULL;
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
CoInitialize(NULL); CoInitialize(NULL);
hr = MFCreateAttributes(&pAttributes, 1); hr = MFCreateAttributes(&pAttributes, 1);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = pAttributes->SetGUID( hr = pAttributes->SetGUID(
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
); );
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = checkDevice(pAttributes, &vd_pActivate); hr = checkDevice(pAttributes, &vd_pActivate);
if (SUCCEEDED(hr) && vd_pActivate) if (SUCCEEDED(hr) && vd_pActivate)
{ {
SafeRelease(&vd_pSource); SafeRelease(&vd_pSource);
hr = vd_pActivate->ActivateObject( hr = vd_pActivate->ActivateObject(
__uuidof(IMFMediaSource), __uuidof(IMFMediaSource),
(void**)&vd_pSource (void**)&vd_pSource
); );
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
} }
SafeRelease(&vd_pActivate); SafeRelease(&vd_pActivate);
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE %i: Device there is not \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: Device there is not \n", vd_CurrentNumber);
} }
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE %i: The attribute of video cameras cannot be getting \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: The attribute of video cameras cannot be getting \n", vd_CurrentNumber);
} }
SafeRelease(&pAttributes); SafeRelease(&pAttributes);
return hr; return hr;
} }
MediaType videoDevice::getFormat(unsigned int id) MediaType videoDevice::getFormat(unsigned int id)
{ {
if(id < vd_CurrentFormats.size()) if(id < vd_CurrentFormats.size())
...@@ -2180,49 +1617,35 @@ MediaType videoDevice::getFormat(unsigned int id) ...@@ -2180,49 +1617,35 @@ MediaType videoDevice::getFormat(unsigned int id)
return vd_CurrentFormats[id]; return vd_CurrentFormats[id];
} }
else return MediaType(); else return MediaType();
} }
int videoDevice::getCountFormats() int videoDevice::getCountFormats()
{ {
return vd_CurrentFormats.size(); return vd_CurrentFormats.size();
} }
void videoDevice::setEmergencyStopEvent(void *userData, void(*func)(int, void *)) void videoDevice::setEmergencyStopEvent(void *userData, void(*func)(int, void *))
{ {
vd_func = func; vd_func = func;
vd_userData = userData; vd_userData = userData;
} }
void videoDevice::closeDevice() void videoDevice::closeDevice()
{ {
if(vd_IsSetuped) if(vd_IsSetuped)
{ {
vd_IsSetuped = false; vd_IsSetuped = false;
vd_pSource->Stop(); vd_pSource->Stop();
SafeRelease(&vd_pSource); SafeRelease(&vd_pSource);
if(vd_LockOut == RawDataLock) if(vd_LockOut == RawDataLock)
{ {
vd_pImGrTh->stop(); vd_pImGrTh->stop();
Sleep(500); Sleep(500);
delete vd_pImGrTh; delete vd_pImGrTh;
} }
vd_pImGrTh = NULL; vd_pImGrTh = NULL;
vd_LockOut = OpenLock;
vd_LockOut = OpenLock;
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"VIDEODEVICE %i: Device is stopped \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: Device is stopped \n", vd_CurrentNumber);
} }
} }
unsigned int videoDevice::getWidth() unsigned int videoDevice::getWidth()
{ {
if(vd_IsSetuped) if(vd_IsSetuped)
...@@ -2230,60 +1653,46 @@ unsigned int videoDevice::getWidth() ...@@ -2230,60 +1653,46 @@ unsigned int videoDevice::getWidth()
else else
return 0; return 0;
} }
unsigned int videoDevice::getHeight() unsigned int videoDevice::getHeight()
{ {
if(vd_IsSetuped) if(vd_IsSetuped)
return vd_Height; return vd_Height;
else else
return 0; return 0;
} }
IMFMediaSource *videoDevice::getMediaSource() IMFMediaSource *videoDevice::getMediaSource()
{ {
IMFMediaSource *out = NULL; IMFMediaSource *out = NULL;
if(vd_LockOut == OpenLock) if(vd_LockOut == OpenLock)
{ {
vd_LockOut = MediaSourceLock; vd_LockOut = MediaSourceLock;
out = vd_pSource; out = vd_pSource;
} }
return out; return out;
} }
int videoDevice::findType(unsigned int size, unsigned int frameRate) int videoDevice::findType(unsigned int size, unsigned int frameRate)
{ {
if(vd_CaptureFormats.size() == 0) if(vd_CaptureFormats.size() == 0)
return 0; return 0;
FrameRateMap FRM = vd_CaptureFormats[size]; FrameRateMap FRM = vd_CaptureFormats[size];
if(FRM.size() == 0) if(FRM.size() == 0)
return 0; return 0;
UINT64 frameRateMax = 0; SUBTYPEMap STMMax; UINT64 frameRateMax = 0; SUBTYPEMap STMMax;
if(frameRate == 0) if(frameRate == 0)
{ {
std::map<UINT64, SUBTYPEMap>::iterator f = FRM.begin(); std::map<UINT64, SUBTYPEMap>::iterator f = FRM.begin();
for(; f != FRM.end(); f++) for(; f != FRM.end(); f++)
{ {
if((*f).first >= frameRateMax) if((*f).first >= frameRateMax)
{ {
frameRateMax = (*f).first; frameRateMax = (*f).first;
STMMax = (*f).second; STMMax = (*f).second;
} }
} }
} }
else else
{ {
std::map<UINT64, SUBTYPEMap>::iterator f = FRM.begin(); std::map<UINT64, SUBTYPEMap>::iterator f = FRM.begin();
for(; f != FRM.end(); f++) for(; f != FRM.end(); f++)
{ {
if((*f).first >= frameRateMax) if((*f).first >= frameRateMax)
...@@ -2291,98 +1700,68 @@ int videoDevice::findType(unsigned int size, unsigned int frameRate) ...@@ -2291,98 +1700,68 @@ int videoDevice::findType(unsigned int size, unsigned int frameRate)
if(frameRate > (*f).first) if(frameRate > (*f).first)
{ {
frameRateMax = (*f).first; frameRateMax = (*f).first;
STMMax = (*f).second; STMMax = (*f).second;
} }
} }
} }
} }
if(STMMax.size() == 0) if(STMMax.size() == 0)
return 0; return 0;
std::map<String, vectorNum>::iterator S = STMMax.begin(); std::map<String, vectorNum>::iterator S = STMMax.begin();
vectorNum VN = (*S).second; vectorNum VN = (*S).second;
if(VN.size() == 0) if(VN.size() == 0)
return 0; return 0;
return VN[0]; return VN[0];
} }
void videoDevice::buildLibraryofTypes() void videoDevice::buildLibraryofTypes()
{ {
unsigned int size; unsigned int size;
unsigned int framerate; unsigned int framerate;
std::vector<MediaType>::iterator i = vd_CurrentFormats.begin(); std::vector<MediaType>::iterator i = vd_CurrentFormats.begin();
int count = 0; int count = 0;
for(; i != vd_CurrentFormats.end(); i++) for(; i != vd_CurrentFormats.end(); i++)
{ {
size = (*i).MF_MT_FRAME_SIZE; size = (*i).MF_MT_FRAME_SIZE;
framerate = (*i).MF_MT_FRAME_RATE; framerate = (*i).MF_MT_FRAME_RATE;
FrameRateMap FRM = vd_CaptureFormats[size]; FrameRateMap FRM = vd_CaptureFormats[size];
SUBTYPEMap STM = FRM[framerate]; SUBTYPEMap STM = FRM[framerate];
String subType((*i).pMF_MT_SUBTYPEName); String subType((*i).pMF_MT_SUBTYPEName);
vectorNum VN = STM[subType]; vectorNum VN = STM[subType];
VN.push_back(count); VN.push_back(count);
STM[subType] = VN; STM[subType] = VN;
FRM[framerate] = STM; FRM[framerate] = STM;
vd_CaptureFormats[size] = FRM; vd_CaptureFormats[size] = FRM;
count++; count++;
} }
} }
long videoDevice::setDeviceFormat(IMFMediaSource *pSource, unsigned long dwFormatIndex) long videoDevice::setDeviceFormat(IMFMediaSource *pSource, unsigned long dwFormatIndex)
{ {
IMFPresentationDescriptor *pPD = NULL; IMFPresentationDescriptor *pPD = NULL;
IMFStreamDescriptor *pSD = NULL; IMFStreamDescriptor *pSD = NULL;
IMFMediaTypeHandler *pHandler = NULL; IMFMediaTypeHandler *pHandler = NULL;
IMFMediaType *pType = NULL; IMFMediaType *pType = NULL;
HRESULT hr = pSource->CreatePresentationDescriptor(&pPD); HRESULT hr = pSource->CreatePresentationDescriptor(&pPD);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
BOOL fSelected; BOOL fSelected;
hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD); hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
hr = pSD->GetMediaTypeHandler(&pHandler); hr = pSD->GetMediaTypeHandler(&pHandler);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
hr = pHandler->GetMediaTypeByIndex((DWORD)dwFormatIndex, &pType); hr = pHandler->GetMediaTypeByIndex((DWORD)dwFormatIndex, &pType);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
hr = pHandler->SetCurrentMediaType(pType); hr = pHandler->SetCurrentMediaType(pType);
done: done:
SafeRelease(&pPD); SafeRelease(&pPD);
SafeRelease(&pSD); SafeRelease(&pSD);
...@@ -2390,243 +1769,179 @@ done: ...@@ -2390,243 +1769,179 @@ done:
SafeRelease(&pType); SafeRelease(&pType);
return hr; return hr;
} }
bool videoDevice::isDeviceSetup() bool videoDevice::isDeviceSetup()
{ {
return vd_IsSetuped; return vd_IsSetuped;
} }
RawImage * videoDevice::getRawImageOut() RawImage * videoDevice::getRawImageOut()
{ {
if(!vd_IsSetuped) return NULL; if(!vd_IsSetuped) return NULL;
if(vd_pImGrTh) if(vd_pImGrTh)
return vd_pImGrTh->getImageGrabber()->getRawImage(); return vd_pImGrTh->getImageGrabber()->getRawImage();
else else
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"VIDEODEVICE %i: The instance of ImageGrabberThread class does not exist \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: The instance of ImageGrabberThread class does not exist \n", vd_CurrentNumber);
} }
return NULL; return NULL;
} }
bool videoDevice::isFrameNew() bool videoDevice::isFrameNew()
{ {
if(!vd_IsSetuped) return false; if(!vd_IsSetuped) return false;
if(vd_LockOut == RawDataLock || vd_LockOut == OpenLock)
if(vd_LockOut == RawDataLock || vd_LockOut == OpenLock)
{ {
if(vd_LockOut == OpenLock) if(vd_LockOut == OpenLock)
{ {
vd_LockOut = RawDataLock; vd_LockOut = RawDataLock;
HRESULT hr = ImageGrabberThread::CreateInstance(&vd_pImGrTh, vd_pSource, vd_CurrentNumber); HRESULT hr = ImageGrabberThread::CreateInstance(&vd_pImGrTh, vd_pSource, vd_CurrentNumber);
if(FAILED(hr)) if(FAILED(hr))
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"VIDEODEVICE %i: The instance of ImageGrabberThread class cannot be created.\n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: The instance of ImageGrabberThread class cannot be created.\n", vd_CurrentNumber);
return false; return false;
} }
vd_pImGrTh->setEmergencyStopEvent(vd_userData, vd_func); vd_pImGrTh->setEmergencyStopEvent(vd_userData, vd_func);
vd_pImGrTh->start(); vd_pImGrTh->start();
return true; return true;
} }
if(vd_pImGrTh) if(vd_pImGrTh)
return vd_pImGrTh->getImageGrabber()->getRawImage()->isNew(); return vd_pImGrTh->getImageGrabber()->getRawImage()->isNew();
} }
return false; return false;
} }
bool videoDevice::isDeviceMediaSource() bool videoDevice::isDeviceMediaSource()
{ {
if(vd_LockOut == MediaSourceLock) return true; if(vd_LockOut == MediaSourceLock) return true;
return false; return false;
} }
bool videoDevice::isDeviceRawDataSource() bool videoDevice::isDeviceRawDataSource()
{ {
if(vd_LockOut == RawDataLock) return true; if(vd_LockOut == RawDataLock) return true;
return false; return false;
} }
bool videoDevice::setupDevice(unsigned int id) bool videoDevice::setupDevice(unsigned int id)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if(!vd_IsSetuped) if(!vd_IsSetuped)
{ {
HRESULT hr = -1; HRESULT hr = -1;
hr = initDevice(); hr = initDevice();
if(SUCCEEDED(hr)) if(SUCCEEDED(hr))
{ {
vd_Width = vd_CurrentFormats[id].width; vd_Width = vd_CurrentFormats[id].width;
vd_Height = vd_CurrentFormats[id].height; vd_Height = vd_CurrentFormats[id].height;
hr = setDeviceFormat(vd_pSource, (DWORD) id); hr = setDeviceFormat(vd_pSource, (DWORD) id);
vd_IsSetuped = (SUCCEEDED(hr)); vd_IsSetuped = (SUCCEEDED(hr));
if(vd_IsSetuped) if(vd_IsSetuped)
DPO->printOut(L"\n\nVIDEODEVICE %i: Device is setuped \n", vd_CurrentNumber); DPO->printOut(L"\n\nVIDEODEVICE %i: Device is setuped \n", vd_CurrentNumber);
vd_PrevParametrs = getParametrs(); vd_PrevParametrs = getParametrs();
return vd_IsSetuped; return vd_IsSetuped;
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE %i: Interface IMFMediaSource cannot be got \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: Interface IMFMediaSource cannot be got \n", vd_CurrentNumber);
return false; return false;
} }
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE %i: Device is setuped already \n", vd_CurrentNumber); DPO->printOut(L"VIDEODEVICE %i: Device is setuped already \n", vd_CurrentNumber);
return false; return false;
} }
} }
bool videoDevice::setupDevice(unsigned int w, unsigned int h, unsigned int idealFramerate) bool videoDevice::setupDevice(unsigned int w, unsigned int h, unsigned int idealFramerate)
{ {
unsigned int id = findType(w * h, idealFramerate); unsigned int id = findType(w * h, idealFramerate);
return setupDevice(id); return setupDevice(id);
} }
wchar_t *videoDevice::getName() wchar_t *videoDevice::getName()
{ {
return vd_pFriendlyName; return vd_pFriendlyName;
} }
videoDevice::~videoDevice(void) videoDevice::~videoDevice(void)
{ {
closeDevice(); closeDevice();
SafeRelease(&vd_pSource); SafeRelease(&vd_pSource);
if(vd_pFriendlyName) if(vd_pFriendlyName)
CoTaskMemFree(vd_pFriendlyName); CoTaskMemFree(vd_pFriendlyName);
} }
long videoDevice::enumerateCaptureFormats(IMFMediaSource *pSource) long videoDevice::enumerateCaptureFormats(IMFMediaSource *pSource)
{ {
IMFPresentationDescriptor *pPD = NULL; IMFPresentationDescriptor *pPD = NULL;
IMFStreamDescriptor *pSD = NULL; IMFStreamDescriptor *pSD = NULL;
IMFMediaTypeHandler *pHandler = NULL; IMFMediaTypeHandler *pHandler = NULL;
IMFMediaType *pType = NULL; IMFMediaType *pType = NULL;
HRESULT hr = pSource->CreatePresentationDescriptor(&pPD); HRESULT hr = pSource->CreatePresentationDescriptor(&pPD);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
BOOL fSelected; BOOL fSelected;
hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD); hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
hr = pSD->GetMediaTypeHandler(&pHandler); hr = pSD->GetMediaTypeHandler(&pHandler);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
DWORD cTypes = 0; DWORD cTypes = 0;
hr = pHandler->GetMediaTypeCount(&cTypes); hr = pHandler->GetMediaTypeCount(&cTypes);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
for (DWORD i = 0; i < cTypes; i++) for (DWORD i = 0; i < cTypes; i++)
{ {
hr = pHandler->GetMediaTypeByIndex(i, &pType); hr = pHandler->GetMediaTypeByIndex(i, &pType);
if (FAILED(hr)) if (FAILED(hr))
{ {
goto done; goto done;
} }
MediaType MT = FormatReader::Read(pType); MediaType MT = FormatReader::Read(pType);
vd_CurrentFormats.push_back(MT); vd_CurrentFormats.push_back(MT);
SafeRelease(&pType); SafeRelease(&pType);
} }
done: done:
SafeRelease(&pPD); SafeRelease(&pPD);
SafeRelease(&pSD); SafeRelease(&pSD);
SafeRelease(&pHandler); SafeRelease(&pHandler);
SafeRelease(&pType); SafeRelease(&pType);
return hr; return hr;
} }
videoDevices::videoDevices(void): count(0) videoDevices::videoDevices(void): count(0)
{} {}
void videoDevices::clearDevices() void videoDevices::clearDevices()
{ {
std::vector<videoDevice *>::iterator i = vds_Devices.begin(); std::vector<videoDevice *>::iterator i = vds_Devices.begin();
for(; i != vds_Devices.end(); ++i) for(; i != vds_Devices.end(); ++i)
delete (*i); delete (*i);
vds_Devices.clear(); vds_Devices.clear();
} }
videoDevices::~videoDevices(void) videoDevices::~videoDevices(void)
{ {
clearDevices(); clearDevices();
} }
videoDevice * videoDevices::getDevice(unsigned int i) videoDevice * videoDevices::getDevice(unsigned int i)
{ {
if(i >= vds_Devices.size()) if(i >= vds_Devices.size())
{ {
return NULL; return NULL;
} }
if(i < 0) if(i < 0)
{ {
return NULL; return NULL;
} }
return vds_Devices[i]; return vds_Devices[i];
} }
long videoDevices::initDevices(IMFAttributes *pAttributes) long videoDevices::initDevices(IMFAttributes *pAttributes)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
IMFActivate **ppDevices = NULL; IMFActivate **ppDevices = NULL;
clearDevices(); clearDevices();
hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count); hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
if(count > 0) if(count > 0)
...@@ -2636,7 +1951,6 @@ long videoDevices::initDevices(IMFAttributes *pAttributes) ...@@ -2636,7 +1951,6 @@ long videoDevices::initDevices(IMFAttributes *pAttributes)
videoDevice *vd = new videoDevice; videoDevice *vd = new videoDevice;
vd->readInfoOfDevice(ppDevices[i], i); vd->readInfoOfDevice(ppDevices[i], i);
vds_Devices.push_back(vd); vds_Devices.push_back(vd);
SafeRelease(&ppDevices[i]); SafeRelease(&ppDevices[i]);
} }
SafeRelease(ppDevices); SafeRelease(ppDevices);
...@@ -2647,154 +1961,99 @@ long videoDevices::initDevices(IMFAttributes *pAttributes) ...@@ -2647,154 +1961,99 @@ long videoDevices::initDevices(IMFAttributes *pAttributes)
else else
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"VIDEODEVICES: The instances of the videoDevice class cannot be created\n"); DPO->printOut(L"VIDEODEVICES: The instances of the videoDevice class cannot be created\n");
} }
return hr; return hr;
} }
size_t videoDevices::getCount() size_t videoDevices::getCount()
{ {
return vds_Devices.size(); return vds_Devices.size();
} }
videoDevices& videoDevices::getInstance()
videoDevices& videoDevices::getInstance()
{ {
static videoDevices instance; static videoDevices instance;
return instance; return instance;
} }
Parametr::Parametr() Parametr::Parametr()
{ {
CurrentValue = 0; CurrentValue = 0;
Min = 0; Min = 0;
Max = 0; Max = 0;
Step = 0; Step = 0;
Default = 0;
Default = 0;
Flag = 0; Flag = 0;
} }
MediaType::MediaType() MediaType::MediaType()
{ {
pMF_MT_AM_FORMAT_TYPEName = NULL; pMF_MT_AM_FORMAT_TYPEName = NULL;
pMF_MT_MAJOR_TYPEName = NULL; pMF_MT_MAJOR_TYPEName = NULL;
pMF_MT_SUBTYPEName = NULL; pMF_MT_SUBTYPEName = NULL;
Clear(); Clear();
} }
MediaType::~MediaType() MediaType::~MediaType()
{ {
Clear(); Clear();
} }
void MediaType::Clear() void MediaType::Clear()
{ {
MF_MT_FRAME_SIZE = 0; MF_MT_FRAME_SIZE = 0;
height = 0; height = 0;
width = 0; width = 0;
MF_MT_YUV_MATRIX = 0; MF_MT_YUV_MATRIX = 0;
MF_MT_VIDEO_LIGHTING = 0; MF_MT_VIDEO_LIGHTING = 0;
MF_MT_DEFAULT_STRIDE = 0; MF_MT_DEFAULT_STRIDE = 0;
MF_MT_VIDEO_CHROMA_SITING = 0; MF_MT_VIDEO_CHROMA_SITING = 0;
MF_MT_FIXED_SIZE_SAMPLES = 0; MF_MT_FIXED_SIZE_SAMPLES = 0;
MF_MT_VIDEO_NOMINAL_RANGE = 0; MF_MT_VIDEO_NOMINAL_RANGE = 0;
MF_MT_FRAME_RATE = 0; MF_MT_FRAME_RATE = 0;
MF_MT_FRAME_RATE_low = 0; MF_MT_FRAME_RATE_low = 0;
MF_MT_PIXEL_ASPECT_RATIO = 0; MF_MT_PIXEL_ASPECT_RATIO = 0;
MF_MT_PIXEL_ASPECT_RATIO_low = 0; MF_MT_PIXEL_ASPECT_RATIO_low = 0;
MF_MT_ALL_SAMPLES_INDEPENDENT = 0; MF_MT_ALL_SAMPLES_INDEPENDENT = 0;
MF_MT_FRAME_RATE_RANGE_MIN = 0; MF_MT_FRAME_RATE_RANGE_MIN = 0;
MF_MT_FRAME_RATE_RANGE_MIN_low = 0; MF_MT_FRAME_RATE_RANGE_MIN_low = 0;
MF_MT_SAMPLE_SIZE = 0; MF_MT_SAMPLE_SIZE = 0;
MF_MT_VIDEO_PRIMARIES = 0; MF_MT_VIDEO_PRIMARIES = 0;
MF_MT_INTERLACE_MODE = 0; MF_MT_INTERLACE_MODE = 0;
MF_MT_FRAME_RATE_RANGE_MAX = 0; MF_MT_FRAME_RATE_RANGE_MAX = 0;
MF_MT_FRAME_RATE_RANGE_MAX_low = 0; MF_MT_FRAME_RATE_RANGE_MAX_low = 0;
memset(&MF_MT_MAJOR_TYPE, 0, sizeof(GUID)); memset(&MF_MT_MAJOR_TYPE, 0, sizeof(GUID));
memset(&MF_MT_AM_FORMAT_TYPE, 0, sizeof(GUID)); memset(&MF_MT_AM_FORMAT_TYPE, 0, sizeof(GUID));
memset(&MF_MT_SUBTYPE, 0, sizeof(GUID)); memset(&MF_MT_SUBTYPE, 0, sizeof(GUID));
} }
videoInput::videoInput(void): accessToDevices(false) videoInput::videoInput(void): accessToDevices(false)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"\n***** VIDEOINPUT LIBRARY - 2013 (Author: Evgeny Pereguda) *****\n\n"); DPO->printOut(L"\n***** VIDEOINPUT LIBRARY - 2013 (Author: Evgeny Pereguda) *****\n\n");
updateListOfDevices(); updateListOfDevices();
if(!accessToDevices) if(!accessToDevices)
DPO->printOut(L"INITIALIZATION: Ther is not any suitable video device\n"); DPO->printOut(L"INITIALIZATION: Ther is not any suitable video device\n");
} }
void videoInput::updateListOfDevices() void videoInput::updateListOfDevices()
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
Media_Foundation *MF = &Media_Foundation::getInstance(); Media_Foundation *MF = &Media_Foundation::getInstance();
accessToDevices = MF->buildListOfDevices(); accessToDevices = MF->buildListOfDevices();
if(!accessToDevices) if(!accessToDevices)
DPO->printOut(L"UPDATING: Ther is not any suitable video device\n"); DPO->printOut(L"UPDATING: Ther is not any suitable video device\n");
} }
videoInput::~videoInput(void) videoInput::~videoInput(void)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->printOut(L"\n***** CLOSE VIDEOINPUT LIBRARY - 2013 *****\n\n"); DPO->printOut(L"\n***** CLOSE VIDEOINPUT LIBRARY - 2013 *****\n\n");
} }
IMFMediaSource *videoInput::getMediaSource(int deviceID) IMFMediaSource *videoInput::getMediaSource(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
{ {
IMFMediaSource *out = VD->getMediaSource(); IMFMediaSource *out = VD->getMediaSource();
if(!out) if(!out)
DPO->printOut(L"VideoDevice %i: There is not any suitable IMFMediaSource interface\n", deviceID); DPO->printOut(L"VideoDevice %i: There is not any suitable IMFMediaSource interface\n", deviceID);
return out; return out;
} }
} }
...@@ -2802,33 +2061,25 @@ IMFMediaSource *videoInput::getMediaSource(int deviceID) ...@@ -2802,33 +2061,25 @@ IMFMediaSource *videoInput::getMediaSource(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return NULL; return NULL;
} }
bool videoInput::setupDevice(int deviceID, unsigned int id) bool videoInput::setupDevice(int deviceID, unsigned int id)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0 ) if (deviceID < 0 )
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return false; return false;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
{ {
bool out = VD->setupDevice(id); bool out = VD->setupDevice(id);
if(!out) if(!out)
DPO->printOut(L"VIDEODEVICE %i: This device cannot be started\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: This device cannot be started\n", deviceID);
return out; return out;
} }
} }
...@@ -2836,33 +2087,25 @@ bool videoInput::setupDevice(int deviceID, unsigned int id) ...@@ -2836,33 +2087,25 @@ bool videoInput::setupDevice(int deviceID, unsigned int id)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return false; return false;
} }
bool videoInput::setupDevice(int deviceID, unsigned int w, unsigned int h, unsigned int idealFramerate) bool videoInput::setupDevice(int deviceID, unsigned int w, unsigned int h, unsigned int idealFramerate)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0 ) if (deviceID < 0 )
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return false; return false;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
{ {
bool out = VD->setupDevice(w, h, idealFramerate); bool out = VD->setupDevice(w, h, idealFramerate);
if(!out) if(!out)
DPO->printOut(L"VIDEODEVICE %i: this device cannot be started\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: this device cannot be started\n", deviceID);
return out; return out;
} }
} }
...@@ -2870,53 +2113,41 @@ bool videoInput::setupDevice(int deviceID, unsigned int w, unsigned int h, unsig ...@@ -2870,53 +2113,41 @@ bool videoInput::setupDevice(int deviceID, unsigned int w, unsigned int h, unsig
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n", deviceID); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n", deviceID);
} }
return false; return false;
} }
MediaType videoInput::getFormat(int deviceID, unsigned int id) MediaType videoInput::getFormat(int deviceID, unsigned int id)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return MediaType(); return MediaType();
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD)
if(VD)
return VD->getFormat(id); return VD->getFormat(id);
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return MediaType(); return MediaType();
} }
bool videoInput::isDeviceSetup(int deviceID) bool videoInput::isDeviceSetup(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return false; return false;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
return VD->isDeviceSetup(); return VD->isDeviceSetup();
} }
...@@ -2924,26 +2155,20 @@ bool videoInput::isDeviceSetup(int deviceID) ...@@ -2924,26 +2155,20 @@ bool videoInput::isDeviceSetup(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return false; return false;
} }
bool videoInput::isDeviceMediaSource(int deviceID) bool videoInput::isDeviceMediaSource(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return false; return false;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
return VD->isDeviceMediaSource(); return VD->isDeviceMediaSource();
} }
...@@ -2951,26 +2176,20 @@ bool videoInput::isDeviceMediaSource(int deviceID) ...@@ -2951,26 +2176,20 @@ bool videoInput::isDeviceMediaSource(int deviceID)
{ {
DPO->printOut(L"Device(s): There is not any suitable video device\n"); DPO->printOut(L"Device(s): There is not any suitable video device\n");
} }
return false; return false;
} }
bool videoInput::isDeviceRawDataSource(int deviceID) bool videoInput::isDeviceRawDataSource(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return false; return false;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
{ {
bool isRaw = VD->isDeviceRawDataSource(); bool isRaw = VD->isDeviceRawDataSource();
...@@ -2981,20 +2200,16 @@ bool videoInput::isDeviceRawDataSource(int deviceID) ...@@ -2981,20 +2200,16 @@ bool videoInput::isDeviceRawDataSource(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return false; return false;
} }
bool videoInput::isFrameNew(int deviceID) bool videoInput::isFrameNew(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return false; return false;
} }
if(accessToDevices) if(accessToDevices)
{ {
if(!isDeviceSetup(deviceID)) if(!isDeviceSetup(deviceID))
...@@ -3002,11 +2217,8 @@ bool videoInput::isFrameNew(int deviceID) ...@@ -3002,11 +2217,8 @@ bool videoInput::isFrameNew(int deviceID)
if(isDeviceMediaSource(deviceID)) if(isDeviceMediaSource(deviceID))
return false; return false;
} }
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
{ {
return VD->isFrameNew(); return VD->isFrameNew();
...@@ -3016,26 +2228,20 @@ bool videoInput::isFrameNew(int deviceID) ...@@ -3016,26 +2228,20 @@ bool videoInput::isFrameNew(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return false; return false;
} }
unsigned int videoInput::getCountFormats(int deviceID) unsigned int videoInput::getCountFormats(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return 0; return 0;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
return VD->getCountFormats(); return VD->getCountFormats();
} }
...@@ -3043,34 +2249,26 @@ unsigned int videoInput::getCountFormats(int deviceID) ...@@ -3043,34 +2249,26 @@ unsigned int videoInput::getCountFormats(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return 0; return 0;
} }
void videoInput::closeAllDevices() void videoInput::closeAllDevices()
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
for(unsigned int i = 0; i < VDS->getCount(); i++) for(unsigned int i = 0; i < VDS->getCount(); i++)
closeDevice(i); closeDevice(i);
} }
void videoInput::setParametrs(int deviceID, CamParametrs parametrs) void videoInput::setParametrs(int deviceID, CamParametrs parametrs)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return; return;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice *VD = VDS->getDevice(deviceID); videoDevice *VD = VDS->getDevice(deviceID);
if(VD) if(VD)
VD->setParametrs(parametrs); VD->setParametrs(parametrs);
} }
...@@ -3079,24 +2277,19 @@ void videoInput::setParametrs(int deviceID, CamParametrs parametrs) ...@@ -3079,24 +2277,19 @@ void videoInput::setParametrs(int deviceID, CamParametrs parametrs)
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
} }
CamParametrs videoInput::getParametrs(int deviceID) CamParametrs videoInput::getParametrs(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
CamParametrs out; CamParametrs out;
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return out; return out;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice *VD = VDS->getDevice(deviceID); videoDevice *VD = VDS->getDevice(deviceID);
if(VD) if(VD)
out = VD->getParametrs(); out = VD->getParametrs();
} }
...@@ -3104,26 +2297,20 @@ CamParametrs videoInput::getParametrs(int deviceID) ...@@ -3104,26 +2297,20 @@ CamParametrs videoInput::getParametrs(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return out; return out;
} }
void videoInput::closeDevice(int deviceID) void videoInput::closeDevice(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return; return;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice *VD = VDS->getDevice(deviceID); videoDevice *VD = VDS->getDevice(deviceID);
if(VD) if(VD)
VD->closeDevice(); VD->closeDevice();
} }
...@@ -3132,50 +2319,39 @@ void videoInput::closeDevice(int deviceID) ...@@ -3132,50 +2319,39 @@ void videoInput::closeDevice(int deviceID)
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
} }
unsigned int videoInput::getWidth(int deviceID) unsigned int videoInput::getWidth(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return 0; return 0;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD)
if(VD)
return VD->getWidth(); return VD->getWidth();
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return 0; return 0;
} }
unsigned int videoInput::getHeight(int deviceID) unsigned int videoInput::getHeight(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return 0; return 0;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
return VD->getHeight(); return VD->getHeight();
} }
...@@ -3183,26 +2359,20 @@ unsigned int videoInput::getHeight(int deviceID) ...@@ -3183,26 +2359,20 @@ unsigned int videoInput::getHeight(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return 0; return 0;
} }
wchar_t *videoInput::getNameVideoDevice(int deviceID) wchar_t *videoInput::getNameVideoDevice(int deviceID)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return NULL; return NULL;
} }
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD) if(VD)
return VD->getName(); return VD->getName();
} }
...@@ -3210,81 +2380,60 @@ wchar_t *videoInput::getNameVideoDevice(int deviceID) ...@@ -3210,81 +2380,60 @@ wchar_t *videoInput::getNameVideoDevice(int deviceID)
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return L"Empty"; return L"Empty";
} }
unsigned int videoInput::listDevices(bool silent) unsigned int videoInput::listDevices(bool silent)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
int out = 0; int out = 0;
if(accessToDevices) if(accessToDevices)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
out = VDS->getCount(); out = VDS->getCount();
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if(!silent)DPO->printOut(L"\nVIDEOINPUT SPY MODE!\n\n"); if(!silent)DPO->printOut(L"\nVIDEOINPUT SPY MODE!\n\n");
if(!silent)DPO->printOut(L"SETUP: Looking For Capture Devices\n"); if(!silent)DPO->printOut(L"SETUP: Looking For Capture Devices\n");
for(int i = 0; i < out; i++) for(int i = 0; i < out; i++)
{ {
if(!silent)DPO->printOut(L"SETUP: %i) %s \n",i, getNameVideoDevice(i)); if(!silent)DPO->printOut(L"SETUP: %i) %s \n",i, getNameVideoDevice(i));
} }
if(!silent)DPO->printOut(L"SETUP: %i Device(s) found\n\n", out); if(!silent)DPO->printOut(L"SETUP: %i Device(s) found\n\n", out);
} }
else else
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return out; return out;
} }
videoInput& videoInput::getInstance()
videoInput& videoInput::getInstance()
{ {
static videoInput instance; static videoInput instance;
return instance; return instance;
} }
bool videoInput::isDevicesAcceable() bool videoInput::isDevicesAcceable()
{ {
return accessToDevices; return accessToDevices;
} }
void videoInput::setVerbose(bool state) void videoInput::setVerbose(bool state)
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
DPO->setVerbose(state); DPO->setVerbose(state);
} }
void videoInput::setEmergencyStopEvent(int deviceID, void *userData, void(*func)(int, void *)) void videoInput::setEmergencyStopEvent(int deviceID, void *userData, void(*func)(int, void *))
{ {
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return; return;
} }
if(accessToDevices) if(accessToDevices)
{ {
if(func) if(func)
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
videoDevice * VD = VDS->getDevice(deviceID); videoDevice * VD = VDS->getDevice(deviceID);
if(VD)
if(VD)
VD->setEmergencyStopEvent(userData, func); VD->setEmergencyStopEvent(userData, func);
} }
} }
...@@ -3293,19 +2442,16 @@ void videoInput::setEmergencyStopEvent(int deviceID, void *userData, void(*func) ...@@ -3293,19 +2442,16 @@ void videoInput::setEmergencyStopEvent(int deviceID, void *userData, void(*func)
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
} }
bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRedAndBlue, bool flipImage) bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRedAndBlue, bool flipImage)
{ {
bool success = false; bool success = false;
unsigned int bytes = 3; unsigned int bytes = 3;
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
if (deviceID < 0) if (deviceID < 0)
{ {
DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID); DPO->printOut(L"VIDEODEVICE %i: Invalid device ID\n", deviceID);
return success; return success;
} }
if(accessToDevices) if(accessToDevices)
{ {
bool isRaw = isDeviceRawDataSource(deviceID); bool isRaw = isDeviceRawDataSource(deviceID);
...@@ -3313,18 +2459,14 @@ bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRed ...@@ -3313,18 +2459,14 @@ bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRed
{ {
videoDevices *VDS = &videoDevices::getInstance(); videoDevices *VDS = &videoDevices::getInstance();
DebugPrintOut *DPO = &DebugPrintOut::getInstance(); DebugPrintOut *DPO = &DebugPrintOut::getInstance();
RawImage *RIOut = VDS->getDevice(deviceID)->getRawImageOut(); RawImage *RIOut = VDS->getDevice(deviceID)->getRawImageOut();
if(RIOut) if(RIOut)
{ {
unsigned int height = VDS->getDevice(deviceID)->getHeight(); unsigned int height = VDS->getDevice(deviceID)->getHeight();
unsigned int width = VDS->getDevice(deviceID)->getWidth(); unsigned int width = VDS->getDevice(deviceID)->getWidth();
unsigned int size = bytes * width * height; unsigned int size = bytes * width * height;
if(size == RIOut->getSize()) if(size == RIOut->getSize())
{ {
processPixels(RIOut->getpPixels(), dstBuffer, width, height, bytes, flipRedAndBlue, flipImage); processPixels(RIOut->getpPixels(), dstBuffer, width, height, bytes, flipRedAndBlue, flipImage);
success = true; success = true;
} }
...@@ -3336,7 +2478,7 @@ bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRed ...@@ -3336,7 +2478,7 @@ bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRed
else else
{ {
DPO->printOut(L"ERROR: GetPixels() - Unable to grab frame for device %i\n", deviceID); DPO->printOut(L"ERROR: GetPixels() - Unable to grab frame for device %i\n", deviceID);
} }
} }
else else
{ {
...@@ -3347,19 +2489,16 @@ bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRed ...@@ -3347,19 +2489,16 @@ bool videoInput::getPixels(int deviceID, unsigned char * dstBuffer, bool flipRed
{ {
DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n"); DPO->printOut(L"VIDEODEVICE(s): There is not any suitable video device\n");
} }
return success; return success;
} }
void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigned int width,
void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigned int width,
unsigned int height, unsigned int bpp, bool bRGB, bool bFlip) unsigned int height, unsigned int bpp, bool bRGB, bool bFlip)
{ {
unsigned int widthInBytes = width * bpp; unsigned int widthInBytes = width * bpp;
unsigned int numBytes = widthInBytes * height; unsigned int numBytes = widthInBytes * height;
int *dstInt, *srcInt; int *dstInt, *srcInt;
if(!bRGB) if(!bRGB)
{ {
if(bFlip) if(bFlip)
{ {
for(unsigned int y = 0; y < height; y++) for(unsigned int y = 0; y < height; y++)
...@@ -3368,7 +2507,6 @@ void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigne ...@@ -3368,7 +2507,6 @@ void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigne
srcInt = (int *)(src + ( (height -y -1) * widthInBytes)); srcInt = (int *)(src + ( (height -y -1) * widthInBytes));
memcpy(dstInt, srcInt, widthInBytes); memcpy(dstInt, srcInt, widthInBytes);
} }
} }
else else
{ {
...@@ -3379,11 +2517,9 @@ void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigne ...@@ -3379,11 +2517,9 @@ void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigne
{ {
if(bFlip) if(bFlip)
{ {
unsigned int x = 0; unsigned int x = 0;
unsigned int y = (height - 1) * widthInBytes; unsigned int y = (height - 1) * widthInBytes;
src += y; src += y;
for(unsigned int i = 0; i < numBytes; i+=3) for(unsigned int i = 0; i < numBytes; i+=3)
{ {
if(x >= width) if(x >= width)
...@@ -3391,49 +2527,38 @@ void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigne ...@@ -3391,49 +2527,38 @@ void videoInput::processPixels(unsigned char * src, unsigned char * dst, unsigne
x = 0; x = 0;
src -= widthInBytes*2; src -= widthInBytes*2;
} }
*dst = *(src+2); *dst = *(src+2);
dst++; dst++;
*dst = *(src+1); *dst = *(src+1);
dst++; dst++;
*dst = *src; *dst = *src;
dst++; dst++;
src+=3;
src+=3; x++;
x++;
} }
} }
else else
{ {
for(unsigned int i = 0; i < numBytes; i+=3) for(unsigned int i = 0; i < numBytes; i+=3)
{ {
*dst = *(src+2); *dst = *(src+2);
dst++; dst++;
*dst = *(src+1); *dst = *(src+1);
dst++; dst++;
*dst = *src; *dst = *src;
dst++; dst++;
src+=3;
src+=3;
} }
} }
} }
} }
} }
/******* Capturing video from camera via Microsoft Media Foundation **********/ /******* Capturing video from camera via Microsoft Media Foundation **********/
class CvCaptureCAM_MSMF : public CvCapture class CvCaptureCAM_MSMF : public CvCapture
{ {
public: public:
CvCaptureCAM_MSMF(); CvCaptureCAM_MSMF();
virtual ~CvCaptureCAM_MSMF(); virtual ~CvCaptureCAM_MSMF();
virtual bool open( int index ); virtual bool open( int index );
virtual void close(); virtual void close();
virtual double getProperty(int); virtual double getProperty(int);
...@@ -3441,23 +2566,18 @@ public: ...@@ -3441,23 +2566,18 @@ public:
virtual bool grabFrame(); virtual bool grabFrame();
virtual IplImage* retrieveFrame(int); virtual IplImage* retrieveFrame(int);
virtual int getCaptureDomain() { return CV_CAP_MSMF; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() { return CV_CAP_MSMF; } // Return the type of the capture object: CV_CAP_VFW, etc...
protected: protected:
void init(); void init();
int index, width, height,fourcc; int index, width, height,fourcc;
int widthSet, heightSet; int widthSet, heightSet;
IplImage* frame; IplImage* frame;
videoInput VI; videoInput VI;
}; };
struct SuppressVideoInputMessages struct SuppressVideoInputMessages
{ {
SuppressVideoInputMessages() { videoInput::setVerbose(true); } SuppressVideoInputMessages() { videoInput::setVerbose(true); }
}; };
static SuppressVideoInputMessages do_it; static SuppressVideoInputMessages do_it;
CvCaptureCAM_MSMF::CvCaptureCAM_MSMF(): CvCaptureCAM_MSMF::CvCaptureCAM_MSMF():
index(-1), index(-1),
width(-1), width(-1),
...@@ -3470,13 +2590,11 @@ CvCaptureCAM_MSMF::CvCaptureCAM_MSMF(): ...@@ -3470,13 +2590,11 @@ CvCaptureCAM_MSMF::CvCaptureCAM_MSMF():
{ {
CoInitialize(0); CoInitialize(0);
} }
CvCaptureCAM_MSMF::~CvCaptureCAM_MSMF() CvCaptureCAM_MSMF::~CvCaptureCAM_MSMF()
{ {
close(); close();
CoUninitialize(); CoUninitialize();
} }
void CvCaptureCAM_MSMF::close() void CvCaptureCAM_MSMF::close()
{ {
if( index >= 0 ) if( index >= 0 )
...@@ -3487,13 +2605,11 @@ void CvCaptureCAM_MSMF::close() ...@@ -3487,13 +2605,11 @@ void CvCaptureCAM_MSMF::close()
} }
widthSet = heightSet = width = height = -1; widthSet = heightSet = width = height = -1;
} }
// Initialize camera input // Initialize camera input
bool CvCaptureCAM_MSMF::open( int _index ) bool CvCaptureCAM_MSMF::open( int _index )
{ {
int try_index = _index; int try_index = _index;
int devices = 0; int devices = 0;
close(); close();
devices = VI.listDevices(true); devices = VI.listDevices(true);
if (devices == 0) if (devices == 0)
...@@ -3505,13 +2621,10 @@ bool CvCaptureCAM_MSMF::open( int _index ) ...@@ -3505,13 +2621,10 @@ bool CvCaptureCAM_MSMF::open( int _index )
index = try_index; index = try_index;
return true; return true;
} }
bool CvCaptureCAM_MSMF::grabFrame() bool CvCaptureCAM_MSMF::grabFrame()
{ {
return true; return true;
} }
IplImage* CvCaptureCAM_MSMF::retrieveFrame(int) IplImage* CvCaptureCAM_MSMF::retrieveFrame(int)
{ {
if( !frame || (int)VI.getWidth(index) != frame->width || (int)VI.getHeight(index) != frame->height ) if( !frame || (int)VI.getWidth(index) != frame->width || (int)VI.getHeight(index) != frame->height )
...@@ -3521,12 +2634,9 @@ IplImage* CvCaptureCAM_MSMF::retrieveFrame(int) ...@@ -3521,12 +2634,9 @@ IplImage* CvCaptureCAM_MSMF::retrieveFrame(int)
unsigned int w = VI.getWidth(index), h = VI.getHeight(index); unsigned int w = VI.getWidth(index), h = VI.getHeight(index);
frame = cvCreateImage( cvSize(w,h), 8, 3 ); frame = cvCreateImage( cvSize(w,h), 8, 3 );
} }
VI.getPixels( index, (uchar*)frame->imageData, false, true ); VI.getPixels( index, (uchar*)frame->imageData, false, true );
return frame; return frame;
} }
double CvCaptureCAM_MSMF::getProperty( int property_id ) double CvCaptureCAM_MSMF::getProperty( int property_id )
{ {
// image format proprrties // image format proprrties
...@@ -3534,21 +2644,17 @@ double CvCaptureCAM_MSMF::getProperty( int property_id ) ...@@ -3534,21 +2644,17 @@ double CvCaptureCAM_MSMF::getProperty( int property_id )
{ {
case CV_CAP_PROP_FRAME_WIDTH: case CV_CAP_PROP_FRAME_WIDTH:
return VI.getWidth(index); return VI.getWidth(index);
case CV_CAP_PROP_FRAME_HEIGHT: case CV_CAP_PROP_FRAME_HEIGHT:
return VI.getHeight(index); return VI.getHeight(index);
case CV_CAP_PROP_FOURCC: case CV_CAP_PROP_FOURCC:
// FIXME: implement method in VideoInput back end // FIXME: implement method in VideoInput back end
//return VI.getFourcc(index); //return VI.getFourcc(index);
; ;
case CV_CAP_PROP_FPS: case CV_CAP_PROP_FPS:
// FIXME: implement method in VideoInput back end // FIXME: implement method in VideoInput back end
//return VI.getFPS(index); //return VI.getFPS(index);
; ;
} }
// video filter properties // video filter properties
switch( property_id ) switch( property_id )
{ {
...@@ -3568,7 +2674,6 @@ double CvCaptureCAM_MSMF::getProperty( int property_id ) ...@@ -3568,7 +2674,6 @@ double CvCaptureCAM_MSMF::getProperty( int property_id )
// return (double)current_value; // return (double)current_value;
return 0.; return 0.;
} }
// camera properties // camera properties
switch( property_id ) switch( property_id )
{ {
...@@ -3584,11 +2689,9 @@ double CvCaptureCAM_MSMF::getProperty( int property_id ) ...@@ -3584,11 +2689,9 @@ double CvCaptureCAM_MSMF::getProperty( int property_id )
// max_value,stepping_delta,current_value,flags,defaultValue) ) return (double)current_value; // max_value,stepping_delta,current_value,flags,defaultValue) ) return (double)current_value;
return 0.; return 0.;
} }
// unknown parameter or value not available // unknown parameter or value not available
return -1; return -1;
} }
bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
{ {
// image capture properties // image capture properties
...@@ -3599,12 +2702,10 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) ...@@ -3599,12 +2702,10 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
width = cvRound(value); width = cvRound(value);
handled = true; handled = true;
break; break;
case CV_CAP_PROP_FRAME_HEIGHT: case CV_CAP_PROP_FRAME_HEIGHT:
height = cvRound(value); height = cvRound(value);
handled = true; handled = true;
break; break;
case CV_CAP_PROP_FOURCC: case CV_CAP_PROP_FOURCC:
fourcc = (int)(unsigned long)(value); fourcc = (int)(unsigned long)(value);
if ( fourcc == -1 ) { if ( fourcc == -1 ) {
...@@ -3613,7 +2714,6 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) ...@@ -3613,7 +2714,6 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
} }
handled = true; handled = true;
break; break;
case CV_CAP_PROP_FPS: case CV_CAP_PROP_FPS:
// FIXME: implement method in VideoInput back end // FIXME: implement method in VideoInput back end
// int fps = cvRound(value); // int fps = cvRound(value);
...@@ -3628,9 +2728,7 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) ...@@ -3628,9 +2728,7 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
// } // }
// return VI.isDeviceSetup(index); // return VI.isDeviceSetup(index);
; ;
} }
if ( handled ) { if ( handled ) {
// a stream setting // a stream setting
if( width > 0 && height > 0 ) if( width > 0 && height > 0 )
...@@ -3643,7 +2741,6 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) ...@@ -3643,7 +2741,6 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
// VI.setIdealFramerate(index, fps); // VI.setIdealFramerate(index, fps);
// VI.setupDeviceFourcc(index, width, height, fourcc); // VI.setupDeviceFourcc(index, width, height, fourcc);
} }
bool success = VI.isDeviceSetup(index); bool success = VI.isDeviceSetup(index);
if (success) if (success)
{ {
...@@ -3655,14 +2752,12 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) ...@@ -3655,14 +2752,12 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
} }
return true; return true;
} }
// show video/camera filter dialog // show video/camera filter dialog
// FIXME: implement method in VideoInput back end // FIXME: implement method in VideoInput back end
// if ( property_id == CV_CAP_PROP_SETTINGS ) { // if ( property_id == CV_CAP_PROP_SETTINGS ) {
// VI.showSettingsWindow(index); // VI.showSettingsWindow(index);
// return true; // return true;
// } // }
//video Filter properties //video Filter properties
switch( property_id ) switch( property_id )
{ {
...@@ -3680,7 +2775,6 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) ...@@ -3680,7 +2775,6 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
//return VI.setVideoSettingFilter(index,VI.getVideoPropertyFromCV(property_id),(long)value); //return VI.setVideoSettingFilter(index,VI.getVideoPropertyFromCV(property_id),(long)value);
; ;
} }
//camera properties //camera properties
switch( property_id ) switch( property_id )
{ {
...@@ -3695,15 +2789,11 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value ) ...@@ -3695,15 +2789,11 @@ bool CvCaptureCAM_MSMF::setProperty( int property_id, double value )
//return VI.setVideoSettingCamera(index,VI.getCameraPropertyFromCV(property_id),(long)value); //return VI.setVideoSettingCamera(index,VI.getCameraPropertyFromCV(property_id),(long)value);
; ;
} }
return false; return false;
} }
CvCapture* cvCreateCameraCapture_MSMF( int index ) CvCapture* cvCreateCameraCapture_MSMF( int index )
{ {
CvCaptureCAM_MSMF* capture = new CvCaptureCAM_MSMF; CvCaptureCAM_MSMF* capture = new CvCaptureCAM_MSMF;
try try
{ {
if( capture->open( index )) if( capture->open( index ))
...@@ -3714,9 +2804,7 @@ CvCapture* cvCreateCameraCapture_MSMF( int index ) ...@@ -3714,9 +2804,7 @@ CvCapture* cvCreateCameraCapture_MSMF( int index )
delete capture; delete capture;
throw; throw;
} }
delete capture; delete capture;
return 0; return 0;
} }
#endif
#endif \ No newline at end of file
set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR "arm-v7a") set(CMAKE_SYSTEM_PROCESSOR "arm-v7a")
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}/platforms/winrt")
set(CMAKE_REQUIRED_DEFINITIONS -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE) set(CMAKE_REQUIRED_DEFINITIONS -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE) add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment