static dc1394error_t free_resources(platform_camera_t * cam) { DWORD ret = t1394IsochTearDownStream(cam->device->device_path); if (ret) { dc1394_log_warning("t1394IsochTearDownStream: Error %ld\n", ret); return DC1394_FAILURE; } return DC1394_SUCCESS; }
/**\brief Performs General initialization of the C1394Camera class for the currently selected camera * \ingroup camcore * \param reset If TRUE, this will poke the camera init register to restore it to powerup defaults * \return * CAM_SUCCESS: The camera is ready to start capturing Frames. * CAM_ERROR_NOT_INITIALIZED: No camera selected (this is poorly named and may be changed) * CAM_ERROR_BUSY: Usualy indicates broken invariants, but in and of itself prevents an * init in the middle of image acquisition * CAM_ERROR: Some register IO failed, GetLastError will tell why * * This Function currently causes a lot of I/O on the 1394 bus to populate the configuration and capability * information about the camera and all the available controllable features. If there are any standard video * formats available (e.g. not format 7), then the first available format, mode and rate are selected by default. */ int C1394Camera::InitCamera(BOOL reset) { GET_MAX_SPEED_BETWEEN_DEVICES maxSpeed; DWORD dwRet; int ret = CAM_ERROR; ULONG maxSpeedNotLocal, maxSpeedLocal; DllTrace(DLL_TRACE_ENTER,"ENTER InitCamera\n"); if(m_cameraInitialized) // this isn't really an error, but should be reported DllTrace(DLL_TRACE_WARNING,"InitCamera: Warning: Duplicate Call to InitCamera\n"); // clear it for another pass m_cameraInitialized = false; if(!m_pName) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error: no camera selected\n"); ret = CAM_ERROR_NOT_INITIALIZED; goto _exit; } if(m_hDeviceAcquisition != INVALID_HANDLE_VALUE) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error: Camera is busy, stop image acquisition first\n"); ret = CAM_ERROR_BUSY; goto _exit; } // this frees up any isoch resources that may be left behind // from a previous program that didn't clean up after itself // properly (i.e. crashed) // This is an ugly way to deal with it, but will have to work for now t1394IsochTearDownStream(m_pName); // determine max speed // this is used for allocating bandwidth and stuff maxSpeed.fulFlags = 0; maxSpeed.ulNumberOfDestinations = 0; if (dwRet = GetMaxSpeedBetweenDevices(m_pName, &maxSpeed)) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error %08x on GetMaxSpeedBetweenDevices (NotLocal)\n",dwRet); goto _exit; } maxSpeedNotLocal = maxSpeed.fulSpeed; maxSpeed.fulFlags = 1; if (dwRet = GetMaxSpeedBetweenDevices(m_pName, &maxSpeed)) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error %08x on GetMaxSpeedBetweenDevices (Local)\n",dwRet); goto _exit; } maxSpeedLocal = maxSpeed.fulSpeed; // select the smaller of the two m_maxSpeed = (maxSpeedLocal < maxSpeedNotLocal ? maxSpeedLocal : maxSpeedNotLocal); // reset to defaults if we want if(reset == TRUE) { if(WriteQuadlet(0x000,0x80000000) != CAM_SUCCESS) DllTrace(DLL_TRACE_WARNING,"InitCamera: Warning: Reset to defaults failed: %08x\n",GetLastError()); } // determine video formats/modes/rates // private functions return bools and do their own respective tracing if(!InquireVideoFormats()) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error on InquireVideoFormats\n"); goto _exit; } if(!InquireVideoModes()) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error on InquireVideoModes\n"); goto _exit; } if(!InquireVideoRates()) { DllTrace(DLL_TRACE_ERROR,"InitCamera: Error on InquireVideoRates\n"); goto _exit; } if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x400,&m_InqBasicFunc))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x400)\n",dwRet); goto _exit; } if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x404,&m_InqFeatureHi))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x404)\n",dwRet); goto _exit; } if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x408,&m_InqFeatureLo))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x408)\n",dwRet); goto _exit; } // Poke the error bits, if available this->StatusVideoErrors(TRUE); this->StatusFeatureError(FEATURE_BRIGHTNESS,TRUE); // the core registers have been updated, so it's safe to set this here // NOTE: this flag is very hackish, and should be replaced by explicitly nuking // the toplevel registers on Construction and SelectCamera() m_cameraInitialized = true; if(this->HasPowerControl()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x610,&this->m_StatusPowerControl))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x reading Power Register\n"); goto _exit; } } if(this->HasAdvancedFeature()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x480,&this->m_AdvFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x480)\n",dwRet); goto _exit; } m_AdvFuncOffset <<= 2; m_AdvFuncOffset |= 0xf0000000; } if(this->HasOptionalFeatures()) { // Read the Optional Function Bitmask if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x40C,&m_InqOptionalFunc))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x40C)\n",dwRet); goto _exit; } // And Check the Individual Features if(this->HasPIO()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x484,&this->m_PIOFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x484)\n",dwRet); goto _exit; } m_PIOFuncOffset <<= 2; m_PIOFuncOffset |= 0xf0000000; } if(this->HasSIO()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x488,&this->m_SIOFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x488)\n",dwRet); goto _exit; } m_SIOFuncOffset <<= 2; m_SIOFuncOffset |= 0xf0000000; } if(this->HasStrobe()) { if(CAM_SUCCESS != (dwRet = ReadQuadlet(0x48C,&this->m_StrobeFuncOffset))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x48C)\n",dwRet); goto _exit; } m_StrobeFuncOffset <<= 2; m_StrobeFuncOffset |= 0xf0000000; if(CAM_SUCCESS != (dwRet = ReadQuadlet(this->m_StrobeFuncOffset,&this->m_StrobeRootCaps))) { DllTrace(DLL_TRACE_ERROR,"InitCamera: error %08x on ReadQuadlet(0x%08x)\n", dwRet,this->m_StrobeFuncOffset); goto _exit; } } } RefreshControlRegisters(FALSE); UpdateParameters(); ret = CAM_SUCCESS; _exit: if(ret != CAM_SUCCESS) m_cameraInitialized = false; DllTrace(DLL_TRACE_EXIT,"EXIT InitCamera (%d)\n",ret); return ret; }