/** * @class vetDirectXInput * * @brief This class is the bridge between VETLib and DirecX system, * designed for capturing data from compatible devices, such as * WebCams, TV Tuners and more.. * * DirectX 10 cuts the backward compatibility with older versions, * this module has been developed and tested on DirectX 9.0. * DX10 has not been released yet, probably you need to upgrade * few lines (or nothing) to make this run on new platform, this * because of we use only very standard objects and they might * be compatible with older definitions. * * DirectX 8.1 or later is compatible with IEEE1394 OHCI * (Open Host Controller Interface) so you may acquire also * from firewire devices. * * @bug each first frame after processing is blank, following ok. * * @warning required DirecX library: amstrmid.lib * @todo * * @see vetInput * @example ../../tests/test_vetDirectXInput.cpp * @example ../../tests/app_vetDirectXLamePlayer.cpp * * @version 0.75 * @date 24/11/2005 * @author Alessandro Polo * * **************************************************************************** * VETLib Framework 1.0.2 * Copyright (C) Alessandro Polo 2006 * http://www.ewgate.net/vetlib * ****************************************************************************/ #ifndef __VETLIB_VETDIRECTXINPUT_H__ #define __VETLIB_VETDIRECTXINPUT_H__ #include "../vetDefs.h" #include "../vetInput.h" #include "../vetFrameYUV420.h" #include "../vetFrameRGB24.h" #include "../vetFrameT.h" // just for HWND // #include #define VETDX_MAXDEVICES 20 struct vetDXCapture; //defined in vetDirectXInput.cpp class vetDirectXInput : public vetInput { protected: vetDXCapture* cCap; /** * @brief DirectX compatible device count. */ int deviceCount; /** * @brief DirectX compatible devices' description. */ char deviceDesc[VETDX_MAXDEVICES][160]; int height; // for control check only int width; // for control check only int vetCheckVideoPort(vetDXCapture* vdx); int initCaptureGraphBuilder(vetDXCapture* vdx); int vetUpdateFormatList(vetDXCapture* vdx); /** * @brief Disconnect filter graph and free objects. * * @param[in] vdx vetDXCapture object to release. */ void doReleaseMixer(vetDXCapture* vdx); public: /** Creates a new imVideoCapture object. \n * Returns NULL if there is no capture device available. \n * In Windows returns NULL if DirectX version is older than 8. * */ /** * @brief Default costructor, initialize variables and connect to * device if requested. * * @param device device id: [0, getDeviceCount()[ * @param fps frame rate value (0 = max possible) */ vetDirectXInput(int device = -1); vetDirectXInput(int device, float fps); /** * @brief Default destructor, release objects and buffers * and destroy the imVideoCapture object. */ ~vetDirectXInput(); /** * @brief Read (update) windows' connected device list. * * @see getDeviceCount(void); * @see getDeviceDescription(int device); */ void enumerateDevices(void); /** * @brief Return current device count, call enumerateDevices(void) first. * * @see enumerateDevices(void); */ int getDeviceCount(void) { return deviceCount; }; /** * @brief Returns the device description. Returns NULL in the last device. * * @see enumerateDevices(void); * @see getDeviceCount(void); */ const char* getDeviceDescription(int device); /** * @brief Get current device id. * @return current device id, if disconnected return -1 * @see enumerateDevices(void); * @see getDeviceCount(void); */ int getCurrentDevice(); /** * @brief Set current device * * @param[in] device device id: [0, getDeviceCount()[ * * @return VETRET_ILLEGAL_USE if stream is playing, VETRET_PARAM_ERR * if device id is not valid, VETRET_OK else. */ VETRESULT setDevice(int device); VETRESULT openPropertyPage(void* HWND_Owner); /** * @brief Connect to device. * * @return VETRET_PARAMS_ERR if device is not valid, VET_ILLEGAL_USE * if a device is already connected, VETRET_INTERNAL_ERR * if any error occured, VETRET_OK else. */ VETRESULT connectTo(int device); /** * @brief Connect to current device. * * @return VET_ILLEGAL_USE if a device is already connected, * VETRET_INTERNAL_ERR if any error occured, VETRET_OK else. * * @see setDevice(int device); */ VETRESULT connect(void); /** * @brief Disconnect from current capture device. * * @return VETRET_ILLEGAL_USE if no device is connected, VETRET_OK else. */ VETRESULT disconnect(void); /** * @brief Stop stream media control. * * @return VETRET_ILLEGAL_USE if stream is already stopped, VETRET_OK else. */ VETRESULT doStopLive(); /** * @brief Start stream media control. * * @return VETRET_ILLEGAL_USE if stream is already playing, * VETRET_INTERNAL_ERR if an error occured, VETRET_OK else. */ VETRESULT doStartLive(); /** * @brief Return current media control state. * * @return true is stream is playing live. */ bool isLive(); /** * @brief Get current canvas' width. * * @return width in pixel. */ unsigned int getWidth() const { return width; }; /** * @brief Get current canvas' height. * * @return height in pixel. */ unsigned int getHeight() const { return height; }; /** * @brief Set capture stream size. * * @return VETRET_INTERNAL_ERR if any error occured, VETRET_OK else. */ VETRESULT setImageSize(int width, int height); /** * @brief Read current image size and store to passed arguments. * * @param[out] width image's width in pixel * @param[out] height image's height in pixel */ void getImageSize(int *width, int *height); /** * @brief Read current format's id. * * @return format's id */ int getFormat(); /** * @brief Set current format's id. * * @param[in] format format's id * * @return VETRET_PARAM_ERR if format id is not valid, * VETRET_INTERNAL_ERR if an error occured, VETRET_OK else. */ VETRESULT setFormat(int format); /** * @brief Read format's informations. * * @param[in] format's id * @param[out] width selected format's width * @param[out] height selected format's height * @param[out] desc selected format's description * * @return VETRET_PARAM_ERR if format id is not valid, * VETRET_INTERNAL_ERR if an error occured, VETRET_OK else. */ VETRESULT getFormat(int format, int *width, int *height, char* desc); /** * @brief Read support format's count. * * @return valid format's count */ int getFormatCount(); /** * @brief Get the state of current data source. * * @return true is there are no more frames to load, false else. */ bool EoF(); /** * @brief Disconnect and reset the module. * * @return VETRET_INTERNAL_ERR if any error occur, VETRET_OK else. */ VETRESULT reset(); /** * @brief Grab a frame and copy to VETLib standard format. * * @param[out] img VETLib Cache Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR if any * device reading error occurs, VETRET_NOT_IMPLEMENTED if color * format is not support. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameYUV420&) */ VETRESULT extractTo(vetFrameYUV420& img); /** * @brief Grab a frame and copy to VETLib standard format. * * @param[out] img VETLib Cache24 Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR if any * device reading error occurs, VETRET_NOT_IMPLEMENTED if color * format is not support. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameRGB24&) */ VETRESULT extractTo(vetFrameRGB24& img); /** * @brief Grab a frame and copy to VETLib standard format. * * @param[out] img Greyscale VETLib Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR if any * device reading error occurs, VETRET_NOT_IMPLEMENTED if color * format is not support. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameT&) */ VETRESULT extractTo(vetFrameT& img); }; #endif //__VETLIB_VETDIRECTXINPUT_H__