/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2012 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLIO/src/UnicapDevice.cpp ** ** Module : ICLIO ** ** Authors: Christof Elbrechter ** ** ** ** ** ** Commercial License ** ** ICL can be used commercially, please refer to our website ** ** www.iclcv.org for more details. ** ** ** ** GNU General Public License Usage ** ** Alternatively, this file may be used under the terms of the ** ** GNU General Public License version 3.0 as published by the ** ** Free Software Foundation and appearing in the file LICENSE.GPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the GNU General Public License ** ** version 3.0 requirements will be met: ** ** http://www.gnu.org/copyleft/gpl.html. ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** *********************************************************************/ #include #include using namespace std; namespace icl{ UnicapDevice::UnicapDevice(int deviceIndex) : m_oUnicapDevicePtr((unicap_device_t*)malloc(sizeof(unicap_device_t))),m_oUnicapHandle(NULL), m_bOpen(false), m_bValid(false){ // {{{ open if(deviceIndex == -1 ){ unicap_void_device( m_oUnicapDevicePtr.get() ); return; } unicap_status_t status = unicap_enumerate_devices (NULL,m_oUnicapDevicePtr.get(),deviceIndex); if(!SUCCESS(status)){ unicap_void_device( m_oUnicapDevicePtr.get() ); return; } #define DEACTIVATE_PWC_CAM_IN_UNICAP #ifdef DEACTIVATE_PWC_CAM_IN_UNICAP if(getModelName() == "Philips 740 webcam"){ unicap_void_device( m_oUnicapDevicePtr.get() ); return; } #endif if(open()){ /* unicap_property_t property; for(int i = 0; SUCCESS( unicap_enumerate_properties( m_oUnicapHandle, NULL, &property, i ) ); i++ ){ printf("enumerated property: %s \n",property.identifier); } */ // properties unicap_status_t status = STATUS_SUCCESS; //for(int i=0;SUCCESS(status);i++){ for(int i=0;SUCCESS (status);i++){ m_oProperties.push_back(UnicapProperty(m_oUnicapHandle)); status = unicap_enumerate_properties(m_oUnicapHandle, NULL, m_oProperties[i].getUnicapProperty(),i); if (!SUCCESS (status)){ m_oProperties.pop_back(); } } // formats status = STATUS_SUCCESS; for(int i=0;SUCCESS(status);i++){ m_oFormats.push_back(UnicapFormat(m_oUnicapHandle)); status = unicap_enumerate_formats (m_oUnicapHandle, NULL, m_oFormats[i].getUnicapFormat(), i); if (!SUCCESS (status)){ m_oFormats.pop_back(); } } m_bValid = true; }else{ unicap_void_device( m_oUnicapDevicePtr.get() ); ERROR_LOG("Unable to open Unicap Device"); return; } } // }}} UnicapDevice::~UnicapDevice(){ if(m_bOpen) close(); } bool UnicapDevice::open(){ // {{{ open if(m_bOpen){ WARNING_LOG("Unicap Device already open (proceeding)"); }else{ unicap_open(&m_oUnicapHandle,m_oUnicapDevicePtr.get()); } return true; } // }}} bool UnicapDevice::close(){ // {{{ open if(!m_bOpen){ WARNING_LOG("Unicap Device already closed (proceeding)"); }else{ unicap_close(m_oUnicapHandle); } return true; } // }}} bool UnicapDevice::isValid() const { return m_bValid; } string UnicapDevice::getID()const { return m_oUnicapDevicePtr->identifier; } string UnicapDevice::getModelName()const { return m_oUnicapDevicePtr->model_name;} string UnicapDevice::getVendorName()const { return m_oUnicapDevicePtr->vendor_name;} unsigned long long UnicapDevice::getModelID()const { return m_oUnicapDevicePtr->model_id; } unsigned int UnicapDevice::getVendorID()const { return m_oUnicapDevicePtr->vendor_id;} string UnicapDevice::getCPILayer()const { return m_oUnicapDevicePtr->cpi_layer;} string UnicapDevice::getDevice() const { return m_oUnicapDevicePtr->device;} unsigned int UnicapDevice::getFlags() const { return m_oUnicapDevicePtr->flags;} const vector UnicapDevice::getProperties() const{ return m_oProperties; } vector UnicapDevice::getProperties(){ return m_oProperties; } const vector UnicapDevice::getFormats() const{ return m_oFormats; } vector UnicapDevice::getFormats(){ return m_oFormats; } const unicap_handle_t UnicapDevice::getUnicapHandle()const { return m_oUnicapHandle; } unicap_handle_t UnicapDevice::getUnicapHandle() { return m_oUnicapHandle; } const unicap_device_t *UnicapDevice::getUnicapDevice()const { return m_oUnicapDevicePtr.get(); } unicap_device_t *UnicapDevice::getUnicapDevice(){ return m_oUnicapDevicePtr.get(); } bool UnicapDevice::hasProperty(const string &id) const{ // {{{ open for(unsigned int i=0;iNote: use hasProperty to enshure that this device supports this property @param id property id to get **/ UnicapProperty UnicapDevice::getProperty(const string &id)const{ // {{{ open for(unsigned int i=0;i UnicapDevice::getFilteredFormats(const Size &size) const{ // {{{ open vector v; const vector v2=getFormats(); for(unsigned int i=0;i UnicapDevice::getFilteredFormats(const Size &size){ // {{{ open vector v,v2=getFormats(); for(unsigned int i=0;i UnicapDevice::getFilteredProperties(UnicapProperty::type t, const string &category)const{ // {{{ open const vector v=getProperties(); vector v2; bool useType=t!=UnicapProperty::anytype; bool useCategory=category!=""; for(unsigned int i=0;i UnicapDevice::getFilteredProperties(UnicapProperty::type t, const string &category){ // {{{ open const vector v=getProperties(); vector v2; bool useType=t!=UnicapProperty::anytype; bool useCategory=category!=""; for(unsigned int i=0;isize; *f.getUnicapFormat() = *fi.getUnicapFormat(); if(f.checkSize(Size(size.width,size.height))){ f.getUnicapFormat()->size = size; } // old, but we need to copy the whole format // sprintf(f.getUnicapFormat()->identifier,fmtID.c_str()); // f.getUnicapFormat()->fourcc = fi.getUnicapFormat()->fourcc; setFormat(f); return; } } ERROR_LOG("could not set unicap format to: " << fmtID << " (unknown format id)"); } // }}} void UnicapDevice::setFormatSize(const Size &newSize){ // {{{ open UnicapFormat f = getCurrentUnicapFormat(); if(f.checkSize(newSize)){ f.getUnicapFormat()->size.width = newSize.width; f.getUnicapFormat()->size.height = newSize.height; setFormat(f); }else{ ERROR_LOG("this size is not supported for current format"); } } // }}} void UnicapDevice::setFormat(const string &fmtID, const Size &newSize){ // {{{ open for(unsigned int i=0;iidentifier,"%s",fmtID.c_str()); f.getUnicapFormat()->size.width = newSize.width; f.getUnicapFormat()->size.width = newSize.height; setFormat(f); return; }else{ ERROR_LOG("combination of format and size is not supported \n"); return; } } } ERROR_LOG("could not set unicap format to: " << fmtID << " (unknown format id)"); } // }}} void UnicapDevice::setProperty(UnicapProperty &prop){ // {{{ open unicap_set_property(m_oUnicapHandle, prop.getUnicapProperty()); } // }}} void UnicapDevice::listProperties()const{ // {{{ open vector v = getProperties(); for(unsigned int i=0;i v = getFormats(); for(unsigned int i=0;i>i) & 0x1) ? '1' : '0'; } string s(buf); delete buf; return s; } // }}} } string UnicapDevice::toString() const{ // {{{ open char buf[10000]; sprintf(buf, "UnicapDevice:\n" " ID = %s\n" " ModelName = %s\n" " VendorName = %s\n" " ModelID = %lld\n" " VendorID = %d\n" " CPILayer = %s\n" " Device = %s\n" " Flags = %s\n", getID().c_str(), getModelName().c_str(), getVendorName().c_str(), getModelID(),getVendorID(),getCPILayer().c_str(),getDevice().c_str(), ui_to_bin(getFlags()).c_str()); return buf; } // }}} } // end of namespace icl