Index: src/player/CameraNode.cpp =================================================================== --- src/player/CameraNode.cpp (revision 3364) +++ src/player/CameraNode.cpp (working copy) @@ -35,6 +35,9 @@ #ifdef AVG_ENABLE_V4L2 #include "../imaging/V4LCamera.h" #endif +#ifdef AVG_ENABLE_CMU1394 +#include "../imaging/CMUCamera.h" +#endif #ifdef AVG_ENABLE_DSHOW #include "../imaging/DSCamera.h" #endif @@ -87,6 +90,9 @@ || defined(AVG_ENABLE_1394_2) m_pCamera = CameraPtr(new FWCamera(sDevice, IntPoint(Width, Height), sPF, FrameRate, true)); +#elif defined(AVG_ENABLE_CMU1394) + m_pCamera = CameraPtr(new CMUCamera(sDevice, IntPoint(Width, Height), sPF, + FrameRate, true)); #else AVG_TRACE(Logger::ERROR, "Firewire camera specified, but firewire " "support not compiled in."); Index: src/player/Player.cpp =================================================================== --- src/player/Player.cpp (revision 3364) +++ src/player/Player.cpp (working copy) @@ -60,6 +60,9 @@ #ifdef AVG_ENABLE_V4L2 #include "../imaging/V4LCamera.h" #endif +#ifdef AVG_ENABLE_CMU1394 +#include "../imaging/CMUCamera.h" +#endif #ifdef AVG_ENABLE_DSHOW #include "../imaging/DSCamera.h" #endif @@ -432,9 +435,19 @@ exit(1); #endif } else if (sSource == "fw") { +#if defined(AVG_ENABLE_1394) || defined(AVG_ENABLE_1394_2) AVG_TRACE(Logger::CONFIG, "Adding a Tracker for FW camera " << sDevice << " size=" << Size << " format=" << sPixFmt); pCamera = CameraPtr(new FWCamera(sDevice, Size, sPixFmt, FPS, false)); +#elif defined(AVG_ENABLE_CMU1394) + AVG_TRACE(Logger::CONFIG, "Adding a Tracker for FW camera " << + sDevice << " size=" << Size << " format=" << sPixFmt); + pCamera = CameraPtr(new CMUCamera(sDevice, Size, sPixFmt, FPS, false)); +#else + AVG_TRACE(Logger::ERROR, "FW camera tracker requested, but " + "FW support not compiled in."); + exit(1); +#endif } else if (sSource == "ds") { #ifdef AVG_ENABLE_DSHOW AVG_TRACE(Logger::CONFIG, "Adding a Tracker for DS camera " << Index: src/avgconfig_win.h =================================================================== --- src/avgconfig_win.h (revision 3364) +++ src/avgconfig_win.h (working copy) @@ -3,6 +3,9 @@ /* Enable DirectShow camera support */ #define AVG_ENABLE_DSHOW +/* Enable CMU 1394 Digital Camera Driver support */ +#define AVG_ENABLE_CMU1394 + /* Enable firewire camera support */ #undef AVG_ENABLE_1394 Index: src/imaging/CMUCameraUtils.cpp =================================================================== --- src/imaging/CMUCameraUtils.cpp (revision 0) +++ src/imaging/CMUCameraUtils.cpp (revision 0) @@ -0,0 +1,181 @@ +// +// libavg - Media Playback Engine. +// Copyright (C) 2003-2008 Ulrich von Zadow +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Current versions can be found at www.libavg.de +// +// Original author of this file is Nick Hebner (hebnern@gmail.com). +// + +#include "CMUCameraUtils.h" + +#include "../base/Logger.h" + +namespace avg { + +using namespace std; + +#define FORMAT_0 0 +// Format 0 Modes +#define MODE_320x240_YUV422 1 +#define MODE_640x480_MONO 5 +#define MODE_640x480_MONO16 6 +#define MODE_640x480_YUV411 2 +#define MODE_640x480_YUV422 3 +#define MODE_640x480_RGB 4 + +#define FORMAT_1 1 +// Format 1 Modes +#define MODE_800x600_MONO 2 +#define MODE_800x600_MONO16 6 +#define MODE_800x600_YUV422 0 +#define MODE_800x600_RGB 1 +#define MODE_1024x768_MONO 5 +#define MODE_1024x768_MONO16 6 +#define MODE_1024x768_YUV422 3 +#define MODE_1024x768_RGB 4 + +// Framerates +#define FRAMERATE_1_875 0 +#define FRAMERATE_3_75 1 +#define FRAMERATE_7_5 2 +#define FRAMERATE_15 3 +#define FRAMERATE_30 4 +#define FRAMERATE_60 5 + +void getVideoFormatAndMode(IntPoint& Size, std::string& sPF, + unsigned long* pVideoFormat, + unsigned long* pVideoMode) +{ + if (Size.x == 320 && Size.y == 240) { + *pVideoFormat = FORMAT_0; + if (sPF == "MONO8") { + *pVideoMode = MODE_320x240_YUV422; + } else if (sPF == "YUV422") { + *pVideoMode = MODE_320x240_YUV422; + } + } else if (Size.x == 640 && Size.y == 480) { + *pVideoFormat = FORMAT_0; + if (sPF == "MONO8") { + *pVideoMode = MODE_640x480_MONO; + } else if (sPF == "MONO16") { + *pVideoMode = MODE_640x480_MONO16; + } else if (sPF == "YUV411") { + *pVideoMode = MODE_640x480_YUV411; + } else if (sPF == "YUV422") { + *pVideoMode = MODE_640x480_YUV422; + } else if (sPF == "RGB" || sPF == "BGR") { + *pVideoMode = MODE_640x480_RGB; + } + } else if (Size.x == 800 && Size.y == 600) { + *pVideoFormat = FORMAT_1; + if (sPF == "MONO8") { + *pVideoMode = MODE_800x600_MONO; + } else if (sPF == "MONO16") { + *pVideoMode = MODE_800x600_MONO16; + } else if (sPF == "YUV422") { + *pVideoMode = MODE_800x600_YUV422; + } else if (sPF == "RGB" || sPF == "BGR") { + *pVideoMode = MODE_800x600_RGB; + } + } else if (Size.x == 1024 && Size.y == 768) { + *pVideoFormat = FORMAT_1; + if (sPF == "MONO8" || sPF == "BY8_GBRG") { + *pVideoMode = MODE_1024x768_MONO; + } else if (sPF == "MONO16") { + *pVideoMode = MODE_1024x768_MONO16; + } else if (sPF == "YUV422") { + *pVideoMode = MODE_1024x768_YUV422; + } else if (sPF == "RGB" || sPF == "BGR") { + *pVideoMode = MODE_1024x768_RGB; + } + } else { + AVG_TRACE (Logger::WARNING, + std::string("Unsupported or illegal value for camera mode.")); + *pVideoFormat = FORMAT_0; + *pVideoMode = MODE_640x480_RGB; + } +} + +unsigned long getFrameRateConst(double FrameRate) +{ + if (FrameRate == 1.875) { + return FRAMERATE_1_875; + } else if (FrameRate == 3.75) { + return FRAMERATE_3_75; + } else if (FrameRate == 7.5) { + return FRAMERATE_7_5; + } else if (FrameRate == 15) { + return FRAMERATE_15; + } else if (FrameRate == 30) { + return FRAMERATE_30; + } else if (FrameRate == 60) { + return FRAMERATE_60; + } else { + AVG_TRACE (Logger::WARNING, + std::string("Unsupported or illegal value for camera framerate.")); + return FRAMERATE_15; + } +} + +CAMERA_FEATURE getFeatureID(CameraFeature Feature) +{ + switch(Feature) { + case CAM_FEATURE_BRIGHTNESS: + return FEATURE_BRIGHTNESS; + case CAM_FEATURE_EXPOSURE: + return FEATURE_AUTO_EXPOSURE; + case CAM_FEATURE_SHARPNESS: + return FEATURE_SHARPNESS; + case CAM_FEATURE_WHITE_BALANCE: + return FEATURE_WHITE_BALANCE; + case CAM_FEATURE_HUE: + return FEATURE_HUE; + case CAM_FEATURE_SATURATION: + return FEATURE_SATURATION; + case CAM_FEATURE_GAMMA: + return FEATURE_GAMMA; + case CAM_FEATURE_SHUTTER: + return FEATURE_SHUTTER; + case CAM_FEATURE_GAIN: + return FEATURE_GAIN; + case CAM_FEATURE_IRIS: + return FEATURE_IRIS; + case CAM_FEATURE_FOCUS: + return FEATURE_FOCUS; + case CAM_FEATURE_TEMPERATURE: + return FEATURE_TEMPERATURE; + case CAM_FEATURE_TRIGGER: + return FEATURE_TRIGGER_MODE; + case CAM_FEATURE_ZOOM: + return FEATURE_ZOOM; + case CAM_FEATURE_PAN: + return FEATURE_PAN; + case CAM_FEATURE_TILT: + return FEATURE_TILT; + case CAM_FEATURE_OPTICAL_FILTER: + return FEATURE_OPTICAL_FILTER; + case CAM_FEATURE_CAPTURE_SIZE: + return FEATURE_CAPTURE_SIZE; + case CAM_FEATURE_CAPTURE_QUALITY: + return FEATURE_CAPTURE_QUALITY; + default: + return FEATURE_INVALID_FEATURE; + } +} + +} Index: src/imaging/Camera.h =================================================================== --- src/imaging/Camera.h (revision 3364) +++ src/imaging/Camera.h (working copy) @@ -78,6 +78,7 @@ }; typedef boost::shared_ptr CameraPtr; +typedef std::map FeatureMap; } Index: src/imaging/CMUCamera.h =================================================================== --- src/imaging/CMUCamera.h (revision 0) +++ src/imaging/CMUCamera.h (revision 0) @@ -0,0 +1,75 @@ +// +// libavg - Media Playback Engine. +// Copyright (C) 2003-2008 Ulrich von Zadow +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Current versions can be found at www.libavg.de +// +// Original author of this file is Nick Hebner (hebnern@gmail.com). +// + +#ifndef _CMUCamera_H_ +#define _CMUCamera_H_ + +#include "../api.h" +#include "Camera.h" + +#include +#include <1394Camera.h> + +#include + +namespace avg { + +class CMUCamera : public Camera { +public: + CMUCamera(std::string sDevice, IntPoint Size, std::string sPF, + double FrameRate, bool bColor); + virtual ~CMUCamera(); + virtual void open(); + virtual void close(); + + virtual IntPoint getImgSize(); + virtual BitmapPtr getImage(bool bWait); + virtual bool isCameraAvailable(); + + virtual const std::string& getDevice() const; + virtual const std::string& getDriverName() const; + virtual double getFrameRate() const; + + virtual unsigned int getFeature(CameraFeature Feature) const; + virtual void setFeature(CameraFeature Feature, int Value, bool bIgnoreOldValue=false); + +private: + void fatalError(const std::string& sMsg); + + bool m_bCameraAvailable; + std::string m_sDevice; + std::string m_sPF; + IntPoint m_Size; + double m_FrameRate; + bool m_bFlipRGB; + + PixelFormat m_FramePixelFormat; + PixelFormat m_OutputPixelFormat; + + C1394Camera m_Camera; + FeatureMap m_Features; +}; + +} + +#endif Index: src/imaging/CMUCameraUtils.h =================================================================== --- src/imaging/CMUCameraUtils.h (revision 0) +++ src/imaging/CMUCameraUtils.h (revision 0) @@ -0,0 +1,45 @@ +// +// libavg - Media Playback Engine. +// Copyright (C) 2003-2008 Ulrich von Zadow +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Current versions can be found at www.libavg.de +// +// Original author of this file is Nick Hebner (hebnern@gmail.com). +// + +#ifndef _CMUCameraUtils_H_ +#define _CMUCameraUtils_H_ + +#include "../api.h" +#include "Camera.h" + +#include +#include <1394Camera.h> + +#include + +namespace avg { + +void getVideoFormatAndMode(IntPoint& Size, std::string& sPF, + unsigned long* pVideoFormat, + unsigned long* pVideoMode); +unsigned long getFrameRateConst(double FrameRate); +CAMERA_FEATURE getFeatureID(CameraFeature Feature); + +} + +#endif Index: src/imaging/FWCamera.h =================================================================== --- src/imaging/FWCamera.h (revision 3364) +++ src/imaging/FWCamera.h (working copy) @@ -100,7 +100,6 @@ void dumpCameraInfo(); bool m_bCameraAvailable; - typedef std::map FeatureMap; FeatureMap m_Features; }; Index: src/imaging/CMUCamera.cpp =================================================================== --- src/imaging/CMUCamera.cpp (revision 0) +++ src/imaging/CMUCamera.cpp (revision 0) @@ -0,0 +1,222 @@ +// +// libavg - Media Playback Engine. +// Copyright (C) 2003-2008 Ulrich von Zadow +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Current versions can be found at www.libavg.de +// +// Original author of this file is Nick Hebner (hebnern@gmail.com). +// + +#include "CMUCamera.h" +#include "CMUCameraUtils.h" + +#include "../base/Logger.h" +#include "../graphics/Filterfliprgb.h" + + +using namespace std; + +namespace avg { + +CMUCamera::CMUCamera(std::string sDevice, IntPoint Size, std::string sPF, + double FrameRate, bool bColor) + : m_sDevice(sDevice), + m_sPF(sPF), + m_Size(Size), + m_FrameRate(FrameRate), + m_bCameraAvailable(false), + m_bFlipRGB(false) +{ + if (m_sPF == "MONO8") { + m_FramePixelFormat = I8; + } else if (m_sPF == "MONO16") { + m_FramePixelFormat = I16; + } else if (m_sPF == "YUV411") { + m_FramePixelFormat = YCbCr411; + } else if (m_sPF == "YUV422") { + m_FramePixelFormat = YCbCr422; + } else if (m_sPF == "RGB") { + m_FramePixelFormat = R8G8B8; + m_bFlipRGB = true; + } else if (m_sPF == "BGR") { + m_FramePixelFormat = B8G8R8; + m_bFlipRGB = false; + } else if (m_sPF == "BY8_GBRG") { + m_FramePixelFormat = BAYER8_GBRG; + } else { + fatalError(string("Invalid pixel format '") + m_sPF + "'"); + } + + if (bColor || m_sPF == "BY8_GBRG") { + if (m_bFlipRGB) + m_OutputPixelFormat = R8G8B8X8; + else + m_OutputPixelFormat = B8G8R8X8; + } else { + m_OutputPixelFormat = I8; + } +} + +CMUCamera::~CMUCamera() +{ + close(); +} + +void CMUCamera::open() +{ + unsigned long videoFormat, videoMode; + getVideoFormatAndMode(m_Size, m_sPF, &videoFormat, &videoMode); + + // Find and open camera + if (m_Camera.RefreshCameraList() <= 0) + fatalError("No cameras detected"); + if (m_Camera.SelectCamera(atoi(m_sDevice.c_str())) != CAM_SUCCESS) + fatalError(string("Error selecting camera") + m_sDevice); + if (m_Camera.InitCamera(TRUE) != CAM_SUCCESS) + fatalError("Error initializing camera"); + + // Setup video format and rate + if (m_Camera.SetVideoFormat(videoFormat) != CAM_SUCCESS) + fatalError("Error setting video format"); + if (m_Camera.SetVideoMode(videoMode) != CAM_SUCCESS) + fatalError("Error setting video mode"); + if (m_Camera.SetVideoFrameRate(getFrameRateConst(m_FrameRate)) != CAM_SUCCESS) + fatalError("Error setting frame rate"); + + // Start capturing images + if (m_Camera.StartImageAcquisition() != CAM_SUCCESS) + fatalError("Error starting image acquisition"); + + m_bCameraAvailable = true; + + AVG_TRACE(Logger::CONFIG, "Firewire camera opened."); + + // Set camera features + for (FeatureMap::iterator it=m_Features.begin(); it != m_Features.end(); it++) { + setFeature(it->first, it->second, true); + } +} + +void CMUCamera::close() +{ + if (m_bCameraAvailable) { + m_Camera.StopImageAcquisition(); + m_bCameraAvailable = false; + } +} + +IntPoint CMUCamera::getImgSize() +{ + return m_Size; +} + +BitmapPtr CMUCamera::getImage(bool bWait) +{ + if ((bWait || WaitForSingleObject(m_Camera.GetFrameEvent(), 0) == WAIT_OBJECT_0) && + (m_Camera.AcquireImageEx(TRUE, NULL) == CAM_SUCCESS)) + { + unsigned long captureBufferLength; + unsigned char* pCaptureBuffer = m_Camera.GetRawData(&captureBufferLength); + + Bitmap frame(m_Size, m_FramePixelFormat, pCaptureBuffer, + captureBufferLength / m_Size.y, false, "TempCameraBmp"); + + BitmapPtr pFrameBuffer = BitmapPtr(new Bitmap(m_Size, m_OutputPixelFormat)); + pFrameBuffer->copyPixels(frame); + if (m_bFlipRGB) + FilterFlipRGB().applyInPlace(pFrameBuffer); + + return pFrameBuffer; + } else { + return BitmapPtr(); + } +} + +bool CMUCamera::isCameraAvailable() +{ + return m_bCameraAvailable; +} + +const string& CMUCamera::getDevice() const +{ + return m_sDevice; +} + +const std::string& CMUCamera::getDriverName() const +{ + static string sDriverName = "CMU 1394 Digital Camera Driver"; + return sDriverName; +} + +double CMUCamera::getFrameRate() const +{ + return m_FrameRate; +} + +unsigned int CMUCamera::getFeature(CameraFeature Feature) const +{ + FeatureMap::const_iterator it = m_Features.find(Feature); + if (it == m_Features.end()) { + return 0; + } else { + return it->second; + } +} + +void CMUCamera::setFeature(CameraFeature Feature, int Value, bool bIgnoreOldValue) +{ + if (bIgnoreOldValue || m_Features[Feature] != Value) { + m_Features[Feature] = Value; + if (m_bCameraAvailable) { + if (Feature == CAM_FEATURE_STROBE_DURATION) { + if (m_Camera.HasStrobe()) { + C1394CameraControlStrobe* control = m_Camera.GetStrobeControl(0); + if (control->SetValue(Value) != CAM_SUCCESS) + AVG_TRACE(Logger::WARNING, "Error setting strobe"); + } else { + AVG_TRACE(Logger::WARNING, + "Camera does not support strobe"); + } + } else { + CAMERA_FEATURE cmuFeature = getFeatureID(Feature); + if (cmuFeature != FEATURE_INVALID_FEATURE && m_Camera.HasFeature(cmuFeature)) { + bool bAuto = (Value == -1); + + C1394CameraControl* control = m_Camera.GetCameraControl(cmuFeature); + + if ((control->SetAutoMode(bAuto) != CAM_SUCCESS) || + (!bAuto && control->SetValue(Value) != CAM_SUCCESS)) + AVG_TRACE(Logger::WARNING, + string("Error setting feature: ") + cameraFeatureToString(Feature)); + } else { + AVG_TRACE(Logger::WARNING, + string("Camera does not support feature: ") + + cameraFeatureToString(Feature)); + } + } + } + } +} + +void CMUCamera::fatalError(const string & sMsg) +{ + AVG_TRACE(Logger::ERROR, sMsg); + close(); + exit(1); +} + +}