Changeset 5:c3a6367d6347

Show
Ignore:
Timestamp:
05/24/06 11:47:53 (3 years ago)
Author:
emilie@ada
Children:

6:959c2f6e19a7 10:762f6ca30d40 11:6ec38f264485

Message:

update phapi-libutil

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • SConstruct

    r1 r5  
    1717env.Alias('dist',[x]) 
    1818 
    19 #------- 
    20 #------ 
     19 
     20 
    2121env.SConscript('SConscript', build_dir = env.GlobalGetRootBuildDir(), duplicate = 0) 
    2222 
  • libs/webcam/include/IWebcamDriver.h

    r4 r5  
    5050#if 0 
    5151        /** 
    52          * A frame has been captured 
     52         * A frame has been captured. 
    5353         * 
    5454         * @param sender sender of the event 
  • libs/webcam/include/webcam/IWebcamDriver.h

    r4 r5  
    4747         * Gets default webcam device. 
    4848         * 
    49          * @return the name of the device; WEBCAM_NULL if no webcam or error 
     49         * @return the name of the device. WEBCAM_NULL if no webcam or error. 
    5050         */ 
    5151        virtual std::string getDefaultDevice() = 0; 
     
    9797 
    9898        /** 
    99          * Is given flag set?. 
     99         * Is given flag set? 
    100100         * 
    101101         * @param flag flag to check 
     
    105105 
    106106        /** 
    107          * Sets webcam device to use. 
     107         * Sets webcam device to use 
    108108         * 
    109109         * @param deviceName name of the device to use, if name == "" then use the default device 
    110          * @return WEBCAM_OK if no error; WEBCAM_NOK otherwise 
     110         * @return WEBCAM_OK if no error, WEBCAM_NOK otherwise 
    111111         */ 
    112112        virtual webcamerrorcode setDevice(const std::string & deviceName) = 0; 
     
    118118 
    119119        /** 
    120          * Starts capture of video frames. 
     120         * Starts capture of video frames 
    121121         */ 
    122122        virtual void startCapture() = 0; 
    123123 
    124124        /** 
    125          * Pauses capture of video frames. 
     125         * Pauses capture of video frames 
    126126         */ 
    127127        virtual void pauseCapture() = 0; 
    128128 
    129129        /** 
    130          * Stops capture of video frames. 
     130         * Stops capture of video frames 
    131131         */ 
    132132        virtual void stopCapture() = 0; 
    133133 
    134134        /** 
    135          * Sets palette. 
     135         * Sets palette 
    136136         * 
    137137         * @param palette palette to use 
     
    140140 
    141141        /** 
    142          * Gets palette. 
     142         * Gets palette 
    143143         * 
    144144         * @return current palette 
     
    147147 
    148148        /** 
    149          * Sets capture rate. 
     149         * Sets capture rate 
    150150         * 
    151151         * @param fps desired frame per seconds 
     
    154154 
    155155        /** 
    156          * Gets capture rate. 
     156         * Gets capture rate 
    157157         * 
    158158         * @return current frame per seconds 
     
    161161 
    162162        /** 
    163          * Sets capture resolution. 
     163         * Sets capture resolution 
    164164         * 
    165165         * @param width desired width 
     
    169169 
    170170        /** 
    171          * Gets captured frame width. 
     171         * Gets captured frame width 
    172172         * 
    173173         * @return captured frame width 
     
    176176 
    177177        /** 
    178          * Gets captured frame height. 
     178         * Gets captured frame height 
    179179         * 
    180180         * @return captured frame height 
     
    183183 
    184184        /** 
    185          * Sets capture brightness. 
     185         * Sets capture brightness 
    186186         * 
    187187         * @param brightness brightness value 
     
    190190 
    191191        /** 
    192          * Gets capture brightness. 
     192         * Gets capture brightness 
    193193         * 
    194194         * @param brightness brightness value 
     
    197197 
    198198        /** 
    199          * Sets capture contrast. 
     199         * Sets capture contrast 
    200200         * 
    201201         * @param contrast contrast value 
     
    204204 
    205205        /** 
    206          * Gets capture contrast. 
     206         * Gets capture contrast 
    207207         * 
    208208         * @param contrast contrast value 
     
    211211 
    212212        /** 
    213          * Flips captured frame horizontally. 
     213         * Flips captured frame horizontally 
    214214         * 
    215215         * @param flip if true the picture will be flipped horizontally 
  • libs/webcam/include/webcam/V4LWebcamDriver.h

    r4 r5  
    8888 
    8989        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                 
    90122 
    91123private: 
  • libs/webcam/include/webcam/WebcamDriver.h

    r4 r5  
    5151         * @param factory factory to use 
    5252         */ 
    53         static void setFactory(WebcamDriverFactory * factory) { 
     53        static void setFactory(WebcamDriverFactory *factory) { 
    5454                _factory = factory; 
    5555        } 
     
    6161         * WEBCAM_FORCE_IMAGE_FORMAT flag. 
    6262         */ 
    63         static WebcamDriver * getInstance(); 
     63        static WebcamDriver *getInstance() { 
     64                static WebcamDriver *instance = new WebcamDriver(WEBCAM_FORCE_IMAGE_FORMAT); 
     65                return instance; 
     66        } 
    6467 
    6568        /** Do not use: this is an internal method. */ 
     
    119122private: 
    120123 
    121         static WebcamDriver * instance; 
    122  
    123124        WebcamDriver(int flags); 
    124125 
     
    141142         * @param image captured image 
    142143         */ 
    143         void frameBufferAvailable(piximage * image); 
     144        void frameBufferAvailable(piximage *image); 
    144145 
    145146        /** 
     
    156157 
    157158        /** Pointer to factory to use. */ 
    158         static WebcamDriverFactory * _factory; 
     159        static WebcamDriverFactory *_factory; 
    159160 
    160161        /** Pointer to paltform dependent webcam driver. */ 
    161         IWebcamDriver * _webcamPrivate; 
     162        IWebcamDriver *_webcamPrivate; 
    162163 
    163164        /** Desired FPS. */ 
     
    175176        pixosi _desiredPalette; 
    176177 
    177         /** Desired width. */ 
     178        /** Desired width */ 
    178179        unsigned _desiredWidth; 
    179180 
     
    181182        unsigned _desiredHeight; 
    182183 
    183         /** Flags. */ 
     184        /** Flags */ 
    184185        int _flags; 
    185186 
    186         /** Contains the converted captured frame. */ 
    187         piximage * _convImage; 
     187        /** Contains the converted captured frame */ 
     188        piximage *_convImage; 
    188189 
    189         /** Conversion flags. */ 
     190        /** Conversion flags */ 
    190191        int _convFlags; 
    191  
    192         /** True if the WebcamDriver is running and used. */ 
    193         bool _isRunning; 
    194192}; 
    195193 
  • libs/webcam/src/WebcamDriver.cpp

    r4 r5  
    2929using namespace std; 
    3030 
    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  
    4131WebcamDriver::WebcamDriver(int flags) 
    4232: IWebcamDriver(flags) { 
     
    6252 
    6353        _convFlags = PIX_NO_FLAG; 
    64  
    65         _isRunning = false; 
    6654} 
    6755 
     
    9078 
    9179webcamerrorcode 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); 
    10689} 
    10790 
     
    11194 
    11295void 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(); 
    12098} 
    12199 
     
    126104 
    127105void 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(); 
    134109} 
    135110 
    136111webcamerrorcode 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; 
    148119                } else { 
    149                         LOG_DEBUG("This webcam supports palette #" + String::fromNumber(palette)); 
    150                         _desiredPalette = palette; 
    151                         return WEBCAM_OK; 
     120                        return WEBCAM_NOK; 
    152121                } 
    153122        } 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; 
    156126        } 
    157127} 
     
    166136 
    167137webcamerrorcode 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; 
    184149} 
    185150 
     
    189154 
    190155webcamerrorcode 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()) { 
    203158                        _desiredWidth = width; 
    204159                        _desiredHeight = height; 
     160                        initializeConvImage(); 
    205161                        return WEBCAM_OK; 
     162                } else { 
     163                        return WEBCAM_NOK; 
    206164                } 
    207165        } 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; 
    210169        } 
    211170} 
  • libs/webcam/src/quicktime/QuicktimeWebcamDriver.cpp

    r4 r5  
    1  /* 
     1/* 
    22 * WengoPhone, a voice over Internet phone 
    33 * Copyright (C) 2004-2005  Wengo 
     
    244244 
    245245        pixosi pixTable[] = { 
    246                 PIX_OSI_BGR24, 
     246                PIX_OSI_RGBA32, 
     247                PIX_OSI_RGB32, 
    247248                PIX_OSI_ARGB32, 
    248                 PIX_OSI_RGBA32 
     249                PIX_OSI_RGB24 
    249250        }; 
    250  
    251251        /* FIXME: These formats are not supported because of offset suppressor in 
    252252         * mySGDataProc. 
    253253 
    254                 PIX_OSI_RGB24, 
    255254                PIX_OSI_YUV420P, 
    256255                PIX_OSI_I420, 
     
    269268                PIX_OSI_RGB565, 
    270269                PIX_OSI_RGB555, 
    271                 PIX_OSI_ARGB32, 
    272270                PIX_OSI_RGB8, 
    273271                PIX_OSI_RGB4, 
     
    276274        */ 
    277275 
    278         /* 
    279         The webcam will always be initialized with the first recognized palette 
    280         usually: 
    281                 MacOSX G5 PPC   knows 
    282                                                                 k32ARGBPixelFormat      (OSI 20) 
    283                 imac intel              knows 
    284                                                                 k32ARGBPixelFormat      (OSI 20) 
    285                                                                 k24BGRPixelFormat       (OSI 22) 
    286                                                                  
    287         */ 
    288276        for (register unsigned i = 0 ; i < sizeof(pixTable) / sizeof(pixosi) ; i++) { 
    289277                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)+")"); 
    291278                err = QTNewGWorld(&_PGWorld, //Does'nt work with planar format 
    292279                        pix_quicktime_from_pix_osi(pixTable[i]), 
     
    296283                        0); 
    297284                if (err == noErr) { 
    298                         LOG_DEBUG("success with palette #" + String::fromNumber(pixTable[i])); 
    299285                        _palette = pixTable[i]; 
    300286                        break; 
     
    413399        newBounds.bottom = height; 
    414400 
    415         LOG_DEBUG("try to change resolution: (width, height) = " + String::fromNumber(width) + "," + String::fromNumber(height)); 
    416401        err = SGSetChannelBounds(_SGChanVideo, &newBounds); 
    417402        if (err != noErr) { 
    418                 LOG_DEBUG("could not change resolution..."); 
    419403                err = SGGetSrcVideoBounds(_SGChanVideo, &_boundsRect); 
    420404                if (err != noErr) { 
    421405                        LOG_WARN("can't get source video bounds"); 
    422406                } 
     407 
    423408                return WEBCAM_NOK; 
    424409        } else { 
     
    427412                _boundsRect.right = newBounds.right; 
    428413                _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)+")"); 
    430414        } 
    431415 
     
    521505        // FIXME: This shift does work only with RGB format 
    522506        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())); 
    526507 
    527508        PixMap *pixmap = *GetGWorldPixMap(webcamDriver->_PGWorld); 
     
    554535        Rect sourceRect = { 0, 0, getWidth(), getHeight() }; 
    555536        MatrixRecord scaleMatrix; 
    556         ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(sizeof(ImageDescription)); 
     537        ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(0); 
    557538 
    558539        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"); 
    562542                return; 
    563543        } 
     
    584564 
    585565        DisposeHandle((Handle)imageDesc); 
    586         imageDesc = NULL; 
    587566} 
    588567 
  • libs/webcam/src/v4l/V4LWebcamDriver.cpp

    r4 r5  
    4343 
    4444void V4LWebcamDriver::cleanup() { 
    45         if (_fhandle > 0) { 
     45        if (_fhandle > 0) 
    4646                close(_fhandle); 
    47         } 
    4847        _fhandle = 0; 
    4948        _isOpened = false; 
     
    5251} 
    5352 
    54  
    55 void V4LWebcamDriver::terminate() { 
    56         _terminate = true; 
    57 } 
    58  
    5953StringList V4LWebcamDriver::getDeviceList() { 
    6054        StringList deviceList; 
     
    8377        //TODO: test if a webcam is already opened 
    8478 
    85         std::string device = "/dev/" + deviceName.substr(deviceName.size() - 6, deviceName.size() - 1); 
    86  
    87 #if 0 
    8879        //Looking for the device path 
    8980        //FIXME: the current device naming scheme allows different devices to have 
     
    10091                i++; 
    10192        } 
    102 #endif 
    103          
     93 
    10494        _fhandle = open(device.c_str(), O_RDWR); 
    10595        if (_fhandle <= 0) { 
     
    135125        int depth; 
    136126        int v4l_palette = pix_v4l_from_pix_osi(palette); 
    137          
     127 
    138128        switch (palette) { 
    139129        case PIX_OSI_YUV420P: 
     
    257247} 
    258248 
     249void V4LWebcamDriver::terminate() { 
     250        _terminate = true; 
     251} 
     252 
    259253V4LWebcamDriver::DevNameArray V4LWebcamDriver::getDevices() { 
    260254        return getDevices2_6(); 
     
    267261        StringList list = sysDir.getDirectoryList(); 
    268262 
    269          
    270263        for (register unsigned i = 0 ; i < list.size() ; i++) { 
    271264                if (list[i][0] != '.') { 
    272                         ifstream nameFile((dir + "/" + list[i] + "/name").c_str()); 
     265                        ifstream nameFile((dir + list[i] + "/name").c_str()); 
    273266                        char buffer[512]; 
    274267                        nameFile.getline(buffer, 512); 
    275                          
    276                         strncat(buffer, (" : " + list[i]).c_str(), list[i].size() + 3);  
    277268 
    278269                        array[list[i]] = buffer; 
  • libs/webcam/src/webcam.cpp

    r4 r5  
    9595        wc->driver = WebcamDriver::getInstance(); 
    9696        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; 
    9898 
    9999        return wc; 
     
    186186} 
    187187 
    188 void webcam_stop_capture(webcam * wc) { 
     188void webcam_stop_capture(webcam *wc) { 
    189189        wc->driver->stopCapture(); 
    190190}