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