Home | History | Annotate | Download | only in include
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_
     12 #define WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_
     13 
     14 #include "webrtc/modules/interface/module.h"
     15 #include "webrtc/modules/video_capture/include/video_capture_defines.h"
     16 
     17 namespace webrtc {
     18 
     19 class VideoCaptureModule: public RefCountedModule {
     20  public:
     21   // Interface for receiving information about available camera devices.
     22   class DeviceInfo {
     23    public:
     24     virtual uint32_t NumberOfDevices() = 0;
     25 
     26     // Returns the available capture devices.
     27     // deviceNumber   - Index of capture device.
     28     // deviceNameUTF8 - Friendly name of the capture device.
     29     // deviceUniqueIdUTF8 - Unique name of the capture device if it exist.
     30     //                      Otherwise same as deviceNameUTF8.
     31     // productUniqueIdUTF8 - Unique product id if it exist.
     32     //                       Null terminated otherwise.
     33     virtual int32_t GetDeviceName(
     34         uint32_t deviceNumber,
     35         char* deviceNameUTF8,
     36         uint32_t deviceNameLength,
     37         char* deviceUniqueIdUTF8,
     38         uint32_t deviceUniqueIdUTF8Length,
     39         char* productUniqueIdUTF8 = 0,
     40         uint32_t productUniqueIdUTF8Length = 0) = 0;
     41 
     42 
     43     // Returns the number of capabilities this device.
     44     virtual int32_t NumberOfCapabilities(
     45         const char* deviceUniqueIdUTF8) = 0;
     46 
     47     // Gets the capabilities of the named device.
     48     virtual int32_t GetCapability(
     49         const char* deviceUniqueIdUTF8,
     50         const uint32_t deviceCapabilityNumber,
     51         VideoCaptureCapability& capability) = 0;
     52 
     53     // Gets clockwise angle the captured frames should be rotated in order
     54     // to be displayed correctly on a normally rotated display.
     55     virtual int32_t GetOrientation(
     56         const char* deviceUniqueIdUTF8,
     57         VideoCaptureRotation& orientation) = 0;
     58 
     59     // Gets the capability that best matches the requested width, height and
     60     // frame rate.
     61     // Returns the deviceCapabilityNumber on success.
     62     virtual int32_t GetBestMatchedCapability(
     63         const char* deviceUniqueIdUTF8,
     64         const VideoCaptureCapability& requested,
     65         VideoCaptureCapability& resulting) = 0;
     66 
     67      // Display OS /capture device specific settings dialog
     68     virtual int32_t DisplayCaptureSettingsDialogBox(
     69         const char* deviceUniqueIdUTF8,
     70         const char* dialogTitleUTF8,
     71         void* parentWindow,
     72         uint32_t positionX,
     73         uint32_t positionY) = 0;
     74 
     75     virtual ~DeviceInfo() {}
     76   };
     77 
     78   class VideoCaptureEncodeInterface {
     79    public:
     80     virtual int32_t ConfigureEncoder(const VideoCodec& codec,
     81                                      uint32_t maxPayloadSize) = 0;
     82     // Inform the encoder about the new target bit rate.
     83     //  - newBitRate       : New target bit rate in Kbit/s.
     84     //  - frameRate        : The target frame rate.
     85     virtual int32_t SetRates(int32_t newBitRate, int32_t frameRate) = 0;
     86     // Inform the encoder about the packet loss and the round-trip time.
     87     //   - packetLoss   : Fraction lost
     88     //                    (loss rate in percent = 100 * packetLoss / 255).
     89     //   - rtt          : Round-trip time in milliseconds.
     90     virtual int32_t SetChannelParameters(uint32_t packetLoss, int rtt) = 0;
     91 
     92     // Encode the next frame as key frame.
     93     virtual int32_t EncodeFrameType(const FrameType type) = 0;
     94   protected:
     95     virtual ~VideoCaptureEncodeInterface() {
     96     }
     97   };
     98 
     99   //   Register capture data callback
    100   virtual void RegisterCaptureDataCallback(
    101       VideoCaptureDataCallback& dataCallback) = 0;
    102 
    103   //  Remove capture data callback
    104   virtual void DeRegisterCaptureDataCallback() = 0;
    105 
    106   // Register capture callback.
    107   virtual void RegisterCaptureCallback(VideoCaptureFeedBack& callBack) = 0;
    108 
    109   //  Remove capture callback.
    110   virtual void DeRegisterCaptureCallback() = 0;
    111 
    112   // Start capture device
    113   virtual int32_t StartCapture(
    114       const VideoCaptureCapability& capability) = 0;
    115 
    116   virtual int32_t StopCapture() = 0;
    117 
    118   // Returns the name of the device used by this module.
    119   virtual const char* CurrentDeviceName() const = 0;
    120 
    121   // Returns true if the capture device is running
    122   virtual bool CaptureStarted() = 0;
    123 
    124   // Gets the current configuration.
    125   virtual int32_t CaptureSettings(VideoCaptureCapability& settings) = 0;
    126 
    127   virtual void SetCaptureDelay(int32_t delayMS) = 0;
    128 
    129   // Returns the current CaptureDelay. Only valid when the camera is running.
    130   virtual int32_t CaptureDelay() = 0;
    131 
    132   // Set the rotation of the captured frames.
    133   // If the rotation is set to the same as returned by
    134   // DeviceInfo::GetOrientation the captured frames are
    135   // displayed correctly if rendered.
    136   virtual int32_t SetCaptureRotation(VideoCaptureRotation rotation) = 0;
    137 
    138   // Gets a pointer to an encode interface if the capture device supports the
    139   // requested type and size.  NULL otherwise.
    140   virtual VideoCaptureEncodeInterface* GetEncodeInterface(
    141       const VideoCodec& codec) = 0;
    142 
    143   virtual void EnableFrameRateCallback(const bool enable) = 0;
    144   virtual void EnableNoPictureAlarm(const bool enable) = 0;
    145 
    146 protected:
    147   virtual ~VideoCaptureModule() {};
    148 };
    149 
    150 }  // namespace webrtc
    151 #endif  // WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_
    152