blob: ca04fb7ba664244fd764fb73abcc11f7e1bebc5c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mallinath@webrtc.org12984f02012-02-16 18:18:21 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
andrew@webrtc.org94caca72012-10-30 21:58:00 +000011#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_
12#define WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
andrew@webrtc.org94caca72012-10-30 21:58:00 +000014#include "webrtc/modules/interface/module.h"
15#include "webrtc/modules/video_capture/include/video_capture_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000018
leozwang@webrtc.org77609632012-07-13 22:00:43 +000019#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000020int32_t SetCaptureAndroidVM(void* javaVM, void* javaContext);
leozwang@webrtc.org77609632012-07-13 22:00:43 +000021#endif
22
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000023class VideoCaptureModule: public RefCountedModule {
24 public:
25 // Interface for receiving information about available camera devices.
26 class DeviceInfo {
27 public:
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000028 virtual uint32_t NumberOfDevices() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000029
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000030 // Returns the available capture devices.
31 // deviceNumber - Index of capture device.
32 // deviceNameUTF8 - Friendly name of the capture device.
33 // deviceUniqueIdUTF8 - Unique name of the capture device if it exist.
34 // Otherwise same as deviceNameUTF8.
35 // productUniqueIdUTF8 - Unique product id if it exist.
36 // Null terminated otherwise.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000037 virtual int32_t GetDeviceName(
38 uint32_t deviceNumber,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000039 char* deviceNameUTF8,
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000040 uint32_t deviceNameLength,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000041 char* deviceUniqueIdUTF8,
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000042 uint32_t deviceUniqueIdUTF8Length,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000043 char* productUniqueIdUTF8 = 0,
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000044 uint32_t productUniqueIdUTF8Length = 0) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
niklase@google.com470e71d2011-07-07 08:21:25 +000046
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000047 // Returns the number of capabilities this device.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000048 virtual int32_t NumberOfCapabilities(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000049 const char* deviceUniqueIdUTF8) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000051 // Gets the capabilities of the named device.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000052 virtual int32_t GetCapability(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000053 const char* deviceUniqueIdUTF8,
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000054 const uint32_t deviceCapabilityNumber,
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000055 VideoCaptureCapability& capability) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000057 // Gets clockwise angle the captured frames should be rotated in order
58 // to be displayed correctly on a normally rotated display.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000059 virtual int32_t GetOrientation(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000060 const char* deviceUniqueIdUTF8,
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000061 VideoCaptureRotation& orientation) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000062
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000063 // Gets the capability that best matches the requested width, height and
64 // frame rate.
65 // Returns the deviceCapabilityNumber on success.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000066 virtual int32_t GetBestMatchedCapability(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000067 const char* deviceUniqueIdUTF8,
mallinath@webrtc.org12984f02012-02-16 18:18:21 +000068 const VideoCaptureCapability& requested,
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000069 VideoCaptureCapability& resulting) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000070
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000071 // Display OS /capture device specific settings dialog
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000072 virtual int32_t DisplayCaptureSettingsDialogBox(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000073 const char* deviceUniqueIdUTF8,
74 const char* dialogTitleUTF8,
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000075 void* parentWindow,
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000076 uint32_t positionX,
77 uint32_t positionY) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000079 virtual ~DeviceInfo() {}
80 };
niklase@google.com470e71d2011-07-07 08:21:25 +000081
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000082 class VideoCaptureEncodeInterface {
83 public:
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000084 virtual int32_t ConfigureEncoder(const VideoCodec& codec,
85 uint32_t maxPayloadSize) = 0;
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000086 // Inform the encoder about the new target bit rate.
87 // - newBitRate : New target bit rate in Kbit/s.
88 // - frameRate : The target frame rate.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000089 virtual int32_t SetRates(int32_t newBitRate, int32_t frameRate) = 0;
stefan@webrtc.orga4a88f92011-12-02 08:34:05 +000090 // Inform the encoder about the packet loss and the round-trip time.
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000091 // - packetLoss : Fraction lost
92 // (loss rate in percent = 100 * packetLoss / 255).
stefan@webrtc.orga4a88f92011-12-02 08:34:05 +000093 // - rtt : Round-trip time in milliseconds.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000094 virtual int32_t SetChannelParameters(uint32_t packetLoss, int rtt) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000095
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000096 // Encode the next frame as key frame.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +000097 virtual int32_t EncodeFrameType(const FrameType type) = 0;
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000098 protected:
99 virtual ~VideoCaptureEncodeInterface() {
100 }
101 };
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000103 // Register capture data callback
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000104 virtual int32_t RegisterCaptureDataCallback(
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000105 VideoCaptureDataCallback& dataCallback) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000107 // Remove capture data callback
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000108 virtual int32_t DeRegisterCaptureDataCallback() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000110 // Register capture callback.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000111 virtual int32_t RegisterCaptureCallback(
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000112 VideoCaptureFeedBack& callBack) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000114 // Remove capture callback.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000115 virtual int32_t DeRegisterCaptureCallback() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000117 // Start capture device
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000118 virtual int32_t StartCapture(
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000119 const VideoCaptureCapability& capability) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000121 virtual int32_t StopCapture() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000123 // Returns the name of the device used by this module.
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000124 virtual const char* CurrentDeviceName() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000126 // Returns true if the capture device is running
127 virtual bool CaptureStarted() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000129 // Gets the current configuration.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000130 virtual int32_t CaptureSettings(VideoCaptureCapability& settings) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000132 virtual int32_t SetCaptureDelay(int32_t delayMS) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000134 // Returns the current CaptureDelay. Only valid when the camera is running.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000135 virtual int32_t CaptureDelay() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000137 // Set the rotation of the captured frames.
138 // If the rotation is set to the same as returned by
139 // DeviceInfo::GetOrientation the captured frames are
140 // displayed correctly if rendered.
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000141 virtual int32_t SetCaptureRotation(VideoCaptureRotation rotation) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000143 // Gets a pointer to an encode interface if the capture device supports the
144 // requested type and size. NULL otherwise.
145 virtual VideoCaptureEncodeInterface* GetEncodeInterface(
146 const VideoCodec& codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
pbos@webrtc.orgdfc5bb92013-04-10 08:23:13 +0000148 virtual int32_t EnableFrameRateCallback(const bool enable) = 0;
149 virtual int32_t EnableNoPictureAlarm(const bool enable) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000151protected:
152 virtual ~VideoCaptureModule() {};
niklase@google.com470e71d2011-07-07 08:21:25 +0000153};
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000154
155} // namespace webrtc
andrew@webrtc.org94caca72012-10-30 21:58:00 +0000156#endif // WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_