Changeset 5:c3a6367d6347
- Timestamp:
- 05/24/06 11:47:53 (3 years ago)
- Children:
- Files:
-
- SConstruct (modified) (1 diff)
- libs/webcam/include/IWebcamDriver.h (modified) (1 diff)
- libs/webcam/include/webcam/IWebcamDriver.h (modified) (15 diffs)
- libs/webcam/include/webcam/V4LWebcamDriver.h (modified) (1 diff)
- libs/webcam/include/webcam/WebcamDriver.h (modified) (7 diffs)
- libs/webcam/src/WebcamDriver.cpp (modified) (7 diffs)
- libs/webcam/src/quicktime/QuicktimeWebcamDriver.cpp (modified) (10 diffs)
- libs/webcam/src/v4l/V4LWebcamDriver.cpp (modified) (7 diffs)
- libs/webcam/src/webcam.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
SConstruct
r1 r5 17 17 env.Alias('dist',[x]) 18 18 19 #------- 20 #------ 19 20 21 21 env.SConscript('SConscript', build_dir = env.GlobalGetRootBuildDir(), duplicate = 0) 22 22 libs/webcam/include/IWebcamDriver.h
r4 r5 50 50 #if 0 51 51 /** 52 * A frame has been captured 52 * A frame has been captured. 53 53 * 54 54 * @param sender sender of the event libs/webcam/include/webcam/IWebcamDriver.h
r4 r5 47 47 * Gets default webcam device. 48 48 * 49 * @return the name of the device ; WEBCAM_NULL if no webcam or error49 * @return the name of the device. WEBCAM_NULL if no webcam or error. 50 50 */ 51 51 virtual std::string getDefaultDevice() = 0; … … 97 97 98 98 /** 99 * Is given flag set? .99 * Is given flag set? 100 100 * 101 101 * @param flag flag to check … … 105 105 106 106 /** 107 * Sets webcam device to use .107 * Sets webcam device to use 108 108 * 109 109 * @param deviceName name of the device to use, if name == "" then use the default device 110 * @return WEBCAM_OK if no error ;WEBCAM_NOK otherwise110 * @return WEBCAM_OK if no error, WEBCAM_NOK otherwise 111 111 */ 112 112 virtual webcamerrorcode setDevice(const std::string & deviceName) = 0; … … 118 118 119 119 /** 120 * Starts capture of video frames .120 * Starts capture of video frames 121 121 */ 122 122 virtual void startCapture() = 0; 123 123 124 124 /** 125 * Pauses capture of video frames .125 * Pauses capture of video frames 126 126 */ 127 127 virtual void pauseCapture() = 0; 128 128 129 129 /** 130 * Stops capture of video frames .130 * Stops capture of video frames 131 131 */ 132 132 virtual void stopCapture() = 0; 133 133 134 134 /** 135 * Sets palette .135 * Sets palette 136 136 * 137 137 * @param palette palette to use … … 140 140 141 141 /** 142 * Gets palette .142 * Gets palette 143 143 * 144 144 * @return current palette … … 147 147 148 148 /** 149 * Sets capture rate .149 * Sets capture rate 150 150 * 151 151 * @param fps desired frame per seconds … … 154 154 155 155 /** 156 * Gets capture rate .156 * Gets capture rate 157 157 * 158 158 * @return current frame per seconds … … 161 161 162 162 /** 163 * Sets capture resolution .163 * Sets capture resolution 164 164 * 165 165 * @param width desired width … … 169 169 170 170 /** 171 * Gets captured frame width .171 * Gets captured frame width 172 172 * 173 173 * @return captured frame width … … 176 176 177 177 /** 178 * Gets captured frame height .178 * Gets captured frame height 179 179 * 180 180 * @return captured frame height … … 183 183 184 184 /** 185 * Sets capture brightness .185 * Sets capture brightness 186 186 * 187 187 * @param brightness brightness value … … 190 190 191 191 /** 192 * Gets capture brightness .192 * Gets capture brightness 193 193 * 194 194 * @param brightness brightness value … … 197 197 198 198 /** 199 * Sets capture contrast .199 * Sets capture contrast 200 200 * 201 201 * @param contrast contrast value … … 204 204 205 205 /** 206 * Gets capture contrast .206 * Gets capture contrast 207 207 * 208 208 * @param contrast contrast value … … 211 211 212 212 /** 213 * Flips captured frame horizontally .213 * Flips captured frame horizontally 214 214 * 215 215 * @param flip if true the picture will be flipped horizontally libs/webcam/include/webcam/V4LWebcamDriver.h
r4 r5 88 88 89 89 void flipHorizontally(bool flip); 90 91 //************************************************* 92 void start() { 93 // _thread = new boost::thread(boost::bind(&Thread::run, this)); 94 } 95 96 static void msleep(unsigned long milliseconds) { 97 static const unsigned int MILLISECONDS_PER_SECOND = 1000; 98 static const unsigned int NANOSECONDS_PER_MILLISECOND = 1000000; 99 100 /* if (milliseconds == 0) { 101 boost::thread::yield(); 102 return; 103 } 104 105 unsigned int sec = 0; 106 //If larger than 1 second, do some voodoo for the boost::xtime struct 107 if (milliseconds >= MILLISECONDS_PER_SECOND) { 108 //Converts ms > 1000 into secs + remaining ms 109 unsigned int secs = milliseconds / MILLISECONDS_PER_SECOND; 110 milliseconds = milliseconds - secs * MILLISECONDS_PER_SECOND; 111 sec += secs; 112 } 113 milliseconds *= NANOSECONDS_PER_MILLISECOND; 114 115 boost::xtime xt; 116 boost::xtime_get(&xt, boost::TIME_UTC); 117 xt.nsec += milliseconds; 118 xt.sec += sec; 119 boost::thread::sleep(xt); 120 */ } 121 90 122 91 123 private: libs/webcam/include/webcam/WebcamDriver.h
r4 r5 51 51 * @param factory factory to use 52 52 */ 53 static void setFactory(WebcamDriverFactory * factory) {53 static void setFactory(WebcamDriverFactory *factory) { 54 54 _factory = factory; 55 55 } … … 61 61 * WEBCAM_FORCE_IMAGE_FORMAT flag. 62 62 */ 63 static WebcamDriver * getInstance(); 63 static WebcamDriver *getInstance() { 64 static WebcamDriver *instance = new WebcamDriver(WEBCAM_FORCE_IMAGE_FORMAT); 65 return instance; 66 } 64 67 65 68 /** Do not use: this is an internal method. */ … … 119 122 private: 120 123 121 static WebcamDriver * instance;122 123 124 WebcamDriver(int flags); 124 125 … … 141 142 * @param image captured image 142 143 */ 143 void frameBufferAvailable(piximage * image);144 void frameBufferAvailable(piximage *image); 144 145 145 146 /** … … 156 157 157 158 /** Pointer to factory to use. */ 158 static WebcamDriverFactory * _factory;159 static WebcamDriverFactory *_factory; 159 160 160 161 /** Pointer to paltform dependent webcam driver. */ 161 IWebcamDriver * _webcamPrivate;162 IWebcamDriver *_webcamPrivate; 162 163 163 164 /** Desired FPS. */ … … 175 176 pixosi _desiredPalette; 176 177 177 /** Desired width .*/178 /** Desired width */ 178 179 unsigned _desiredWidth; 179 180 … … 181 182 unsigned _desiredHeight; 182 183 183 /** Flags .*/184 /** Flags */ 184 185 int _flags; 185 186 186 /** Contains the converted captured frame .*/187 piximage * _convImage;187 /** Contains the converted captured frame */ 188 piximage *_convImage; 188 189 189 /** Conversion flags .*/190 /** Conversion flags */ 190 191 int _convFlags; 191 192 /** True if the WebcamDriver is running and used. */193 bool _isRunning;194 192 }; 195 193 libs/webcam/src/WebcamDriver.cpp
r4 r5 29 29 using namespace std; 30 30 31 WebcamDriver * WebcamDriver::instance = NULL;32 33 WebcamDriver * WebcamDriver::getInstance() {34 if (!instance) {35 instance = new WebcamDriver(WEBCAM_FORCE_IMAGE_FORMAT);36 }37 38 return instance;39 }40 41 31 WebcamDriver::WebcamDriver(int flags) 42 32 : IWebcamDriver(flags) { … … 62 52 63 53 _convFlags = PIX_NO_FLAG; 64 65 _isRunning = false;66 54 } 67 55 … … 90 78 91 79 webcamerrorcode WebcamDriver::setDevice(const std::string & deviceName) { 92 if (!_isRunning) { 93 cleanup(); 94 95 std::string actualDeviceName = deviceName; 96 if (actualDeviceName.empty()) { 97 actualDeviceName = getDefaultDevice(); 98 } 99 100 LOG_DEBUG("desired device: " + deviceName + ", actual device: " + actualDeviceName); 101 return _webcamPrivate->setDevice(actualDeviceName); 102 } else { 103 LOG_WARN("WebcamDriver is running. Can't set a device."); 104 return WEBCAM_NOK; 105 } 80 cleanup(); 81 82 std::string actualDeviceName = deviceName; 83 if (actualDeviceName.empty()) { 84 actualDeviceName = getDefaultDevice(); 85 } 86 87 LOG_DEBUG("desired device: " + deviceName + ", actual device: " + actualDeviceName); 88 return _webcamPrivate->setDevice(actualDeviceName); 106 89 } 107 90 … … 111 94 112 95 void WebcamDriver::startCapture() { 113 if (!_isRunning) { 114 LOG_DEBUG("Starting capture"); 115 _webcamPrivate->startCapture(); 116 _isRunning = true; 117 } else { 118 LOG_INFO("Capture is already started"); 119 } 96 LOG_DEBUG("Starting capture"); 97 _webcamPrivate->startCapture(); 120 98 } 121 99 … … 126 104 127 105 void WebcamDriver::stopCapture() { 128 if (_isRunning) { 129 LOG_DEBUG("Stopping capture"); 130 _webcamPrivate->stopCapture(); 131 cleanup(); 132 _isRunning = false; 133 } 106 LOG_DEBUG("Stopping capture"); 107 _webcamPrivate->stopCapture(); 108 cleanup(); 134 109 } 135 110 136 111 webcamerrorcode WebcamDriver::setPalette(pixosi palette) { 137 if (!_isRunning) { 138 if (_webcamPrivate->setPalette(palette) == WEBCAM_NOK) { 139 LOG_DEBUG("This webcam does not support palette #" + String::fromNumber(palette)); 140 if (isFormatForced()) { 141 LOG_DEBUG("Palette conversion will be forced"); 142 _desiredPalette = palette; 143 initializeConvImage(); 144 return WEBCAM_OK; 145 } else { 146 return WEBCAM_NOK; 147 } 112 if (_webcamPrivate->setPalette(palette) == WEBCAM_NOK) { 113 LOG_DEBUG("This webcam does not support palette #" + String::fromNumber(palette)); 114 if (isFormatForced()) { 115 LOG_DEBUG("Palette conversion will be forced"); 116 _desiredPalette = palette; 117 initializeConvImage(); 118 return WEBCAM_OK; 148 119 } else { 149 LOG_DEBUG("This webcam supports palette #" + String::fromNumber(palette)); 150 _desiredPalette = palette; 151 return WEBCAM_OK; 120 return WEBCAM_NOK; 152 121 } 153 122 } else { 154 LOG_INFO("WebcamDriver is running. Can't set palette."); 155 return WEBCAM_NOK; 123 LOG_DEBUG("This webcam supports palette #" + String::fromNumber(palette)); 124 _desiredPalette = palette; 125 return WEBCAM_OK; 156 126 } 157 127 } … … 166 136 167 137 webcamerrorcode WebcamDriver::setFPS(unsigned fps) { 168 if (!_isRunning) { 169 if (_webcamPrivate->setFPS(fps) == WEBCAM_NOK) { 170 LOG_DEBUG("This webcam does not support the desired fps(" + String::fromNumber(fps) + "). Will force it"); 171 _forceFPS = true; 172 } else { 173 LOG_DEBUG("Webcam FPS changed to " + String::fromNumber(fps)); 174 _forceFPS = false; 175 } 176 177 _forcedFPS = fps; 178 179 return WEBCAM_OK; 180 } else { 181 LOG_INFO("WebcamDriver is running. Can't set FPS."); 182 return WEBCAM_NOK; 183 } 138 if (_webcamPrivate->setFPS(fps) == WEBCAM_NOK) { 139 LOG_DEBUG("This webcam does not support the desired fps(" + String::fromNumber(fps) + "). Will force it"); 140 _forceFPS = true; 141 } else { 142 LOG_DEBUG("Webcam FPS changed to " + String::fromNumber(fps)); 143 _forceFPS = false; 144 } 145 146 _forcedFPS = fps; 147 148 return WEBCAM_OK; 184 149 } 185 150 … … 189 154 190 155 webcamerrorcode WebcamDriver::setResolution(unsigned width, unsigned height) { 191 if (!_isRunning) { 192 LOG_DEBUG("try to change resolution: (width, height) = " + String::fromNumber(width) + "," + String::fromNumber(height)); 193 if (_webcamPrivate->setResolution(width, height) == WEBCAM_NOK) { 194 if (isFormatForced()) { 195 _desiredWidth = width; 196 _desiredHeight = height; 197 initializeConvImage(); 198 return WEBCAM_OK; 199 } else { 200 return WEBCAM_NOK; 201 } 202 } else { 156 if (_webcamPrivate->setResolution(width, height) == WEBCAM_NOK) { 157 if (isFormatForced()) { 203 158 _desiredWidth = width; 204 159 _desiredHeight = height; 160 initializeConvImage(); 205 161 return WEBCAM_OK; 162 } else { 163 return WEBCAM_NOK; 206 164 } 207 165 } else { 208 LOG_INFO("WebcamDriver is running. Can't set resolution."); 209 return WEBCAM_NOK; 166 _desiredWidth = width; 167 _desiredHeight = height; 168 return WEBCAM_OK; 210 169 } 211 170 } libs/webcam/src/quicktime/QuicktimeWebcamDriver.cpp
r4 r5 1 /*1 /* 2 2 * WengoPhone, a voice over Internet phone 3 3 * Copyright (C) 2004-2005 Wengo … … 244 244 245 245 pixosi pixTable[] = { 246 PIX_OSI_BGR24, 246 PIX_OSI_RGBA32, 247 PIX_OSI_RGB32, 247 248 PIX_OSI_ARGB32, 248 PIX_OSI_RGB A32249 PIX_OSI_RGB24 249 250 }; 250 251 251 /* FIXME: These formats are not supported because of offset suppressor in 252 252 * mySGDataProc. 253 253 254 PIX_OSI_RGB24,255 254 PIX_OSI_YUV420P, 256 255 PIX_OSI_I420, … … 269 268 PIX_OSI_RGB565, 270 269 PIX_OSI_RGB555, 271 PIX_OSI_ARGB32,272 270 PIX_OSI_RGB8, 273 271 PIX_OSI_RGB4, … … 276 274 */ 277 275 278 /*279 The webcam will always be initialized with the first recognized palette280 usually:281 MacOSX G5 PPC knows282 k32ARGBPixelFormat (OSI 20)283 imac intel knows284 k32ARGBPixelFormat (OSI 20)285 k24BGRPixelFormat (OSI 22)286 287 */288 276 for (register unsigned i = 0 ; i < sizeof(pixTable) / sizeof(pixosi) ; i++) { 289 277 LOG_DEBUG("Attempting to create a GWorld with palette #" + String::fromNumber(pixTable[i])); 290 LOG_DEBUG("trying resolution: (top, left, right, bottom) = ("+String::fromNumber(_boundsRect.top)+","+String::fromNumber(_boundsRect.left)+","+String::fromNumber(_boundsRect.right)+","+String::fromNumber(_boundsRect.bottom)+")");291 278 err = QTNewGWorld(&_PGWorld, //Does'nt work with planar format 292 279 pix_quicktime_from_pix_osi(pixTable[i]), … … 296 283 0); 297 284 if (err == noErr) { 298 LOG_DEBUG("success with palette #" + String::fromNumber(pixTable[i]));299 285 _palette = pixTable[i]; 300 286 break; … … 413 399 newBounds.bottom = height; 414 400 415 LOG_DEBUG("try to change resolution: (width, height) = " + String::fromNumber(width) + "," + String::fromNumber(height));416 401 err = SGSetChannelBounds(_SGChanVideo, &newBounds); 417 402 if (err != noErr) { 418 LOG_DEBUG("could not change resolution...");419 403 err = SGGetSrcVideoBounds(_SGChanVideo, &_boundsRect); 420 404 if (err != noErr) { 421 405 LOG_WARN("can't get source video bounds"); 422 406 } 407 423 408 return WEBCAM_NOK; 424 409 } else { … … 427 412 _boundsRect.right = newBounds.right; 428 413 _boundsRect.bottom = newBounds.bottom; 429 LOG_DEBUG("new resolution: (top, left, right, bottom) = ("+String::fromNumber(newBounds.top)+","+String::fromNumber(newBounds.left)+","+String::fromNumber(newBounds.right)+","+String::fromNumber(newBounds.bottom)+")");430 414 } 431 415 … … 521 505 // FIXME: This shift does work only with RGB format 522 506 image = pix_alloc(webcamDriver->_palette, webcamDriver->getWidth(), webcamDriver->getHeight()); 523 LOG_DEBUG("allocated a trimmed image: palette: " + String::fromNumber(webcamDriver->_palette)524 + ", width: " + String::fromNumber(webcamDriver->getWidth())525 + ", height: " + String::fromNumber(webcamDriver->getHeight()));526 507 527 508 PixMap *pixmap = *GetGWorldPixMap(webcamDriver->_PGWorld); … … 554 535 Rect sourceRect = { 0, 0, getWidth(), getHeight() }; 555 536 MatrixRecord scaleMatrix; 556 ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle( sizeof(ImageDescription));537 ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(0); 557 538 558 539 err = SGGetChannelSampleDescription(_SGChanVideo, (Handle)imageDesc); 559 560 if (err != noErr) { 561 LOG_ERROR("can't get channel sample description:" + String::fromNumber(err)); 540 if (err != noErr) { 541 LOG_ERROR("can't get channel sample description"); 562 542 return; 563 543 } … … 584 564 585 565 DisposeHandle((Handle)imageDesc); 586 imageDesc = NULL;587 566 } 588 567 libs/webcam/src/v4l/V4LWebcamDriver.cpp
r4 r5 43 43 44 44 void V4LWebcamDriver::cleanup() { 45 if (_fhandle > 0) {45 if (_fhandle > 0) 46 46 close(_fhandle); 47 }48 47 _fhandle = 0; 49 48 _isOpened = false; … … 52 51 } 53 52 54 55 void V4LWebcamDriver::terminate() {56 _terminate = true;57 }58 59 53 StringList V4LWebcamDriver::getDeviceList() { 60 54 StringList deviceList; … … 83 77 //TODO: test if a webcam is already opened 84 78 85 std::string device = "/dev/" + deviceName.substr(deviceName.size() - 6, deviceName.size() - 1);86 87 #if 088 79 //Looking for the device path 89 80 //FIXME: the current device naming scheme allows different devices to have … … 100 91 i++; 101 92 } 102 #endif 103 93 104 94 _fhandle = open(device.c_str(), O_RDWR); 105 95 if (_fhandle <= 0) { … … 135 125 int depth; 136 126 int v4l_palette = pix_v4l_from_pix_osi(palette); 137 127 138 128 switch (palette) { 139 129 case PIX_OSI_YUV420P: … … 257 247 } 258 248 249 void V4LWebcamDriver::terminate() { 250 _terminate = true; 251 } 252 259 253 V4LWebcamDriver::DevNameArray V4LWebcamDriver::getDevices() { 260 254 return getDevices2_6(); … … 267 261 StringList list = sysDir.getDirectoryList(); 268 262 269 270 263 for (register unsigned i = 0 ; i < list.size() ; i++) { 271 264 if (list[i][0] != '.') { 272 ifstream nameFile((dir + "/" +list[i] + "/name").c_str());265 ifstream nameFile((dir + list[i] + "/name").c_str()); 273 266 char buffer[512]; 274 267 nameFile.getline(buffer, 512); 275 276 strncat(buffer, (" : " + list[i]).c_str(), list[i].size() + 3);277 268 278 269 array[list[i]] = buffer; libs/webcam/src/webcam.cpp
r4 r5 95 95 wc->driver = WebcamDriver::getInstance(); 96 96 wc->driver->captureCallback = webcam_frame_captured_event_handler; 97 //wc->driver->frameCapturedEvent += &webcam_frame_captured_event_handler;97 // wc->driver->frameCapturedEvent += &webcam_frame_captured_event_handler; 98 98 99 99 return wc; … … 186 186 } 187 187 188 void webcam_stop_capture(webcam * wc) {188 void webcam_stop_capture(webcam *wc) { 189 189 wc->driver->stopCapture(); 190 190 }
