niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | // This sub-API supports the following functionalities: |
| 12 | // |
| 13 | // - Creating and deleting VideoEngine instances. |
| 14 | // - Creating and deleting channels. |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 15 | // - Connect a video channel with a corresponding voice channel for audio/video |
| 16 | // synchronization. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | // - Start and stop sending and receiving. |
| 18 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 19 | #ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_BASE_H_ |
| 20 | #define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_BASE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 22 | #include "webrtc/common_types.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 24 | #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
| 25 | #include <jni.h> |
| 26 | #endif |
| 27 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 28 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
andresp@webrtc.org | 7707d06 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 30 | class Config; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | class VoiceEngine; |
| 32 | |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 33 | // CpuOveruseObserver is called when a system overuse is detected and |
| 34 | // VideoEngine cannot keep up the encoding frequency. |
| 35 | class CpuOveruseObserver { |
| 36 | public: |
| 37 | // Called as soon as an overuse is detected. |
| 38 | virtual void OveruseDetected() = 0; |
| 39 | // Called periodically when the system is not overused any longer. |
| 40 | virtual void NormalUsage() = 0; |
| 41 | |
| 42 | protected: |
| 43 | virtual ~CpuOveruseObserver() {} |
| 44 | }; |
| 45 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 46 | // Limits on standard deviation for under/overuse. |
| 47 | #ifdef WEBRTC_ANDROID |
| 48 | const float kOveruseStdDevMs = 32.0f; |
| 49 | const float kNormalUseStdDevMs = 27.0f; |
| 50 | #elif WEBRTC_LINUX |
| 51 | const float kOveruseStdDevMs = 20.0f; |
| 52 | const float kNormalUseStdDevMs = 14.0f; |
| 53 | #elif WEBRTC_MAC |
| 54 | const float kOveruseStdDevMs = 27.0f; |
| 55 | const float kNormalUseStdDevMs = 21.0f; |
| 56 | #elif WEBRTC_WIN |
| 57 | const float kOveruseStdDevMs = 20.0f; |
| 58 | const float kNormalUseStdDevMs = 14.0f; |
| 59 | #else |
| 60 | const float kOveruseStdDevMs = 30.0f; |
| 61 | const float kNormalUseStdDevMs = 20.0f; |
| 62 | #endif |
| 63 | |
| 64 | struct CpuOveruseOptions { |
| 65 | CpuOveruseOptions() |
| 66 | : enable_capture_jitter_method(true), |
| 67 | low_capture_jitter_threshold_ms(kNormalUseStdDevMs), |
| 68 | high_capture_jitter_threshold_ms(kOveruseStdDevMs), |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 69 | enable_encode_usage_method(false), |
| 70 | low_encode_usage_threshold_percent(60), |
| 71 | high_encode_usage_threshold_percent(90), |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 72 | frame_timeout_interval_ms(1500), |
| 73 | min_frame_samples(120), |
| 74 | min_process_count(3), |
| 75 | high_threshold_consecutive_count(2) {} |
| 76 | |
| 77 | // Method based on inter-arrival jitter of captured frames. |
| 78 | bool enable_capture_jitter_method; |
| 79 | float low_capture_jitter_threshold_ms; // Threshold for triggering underuse. |
| 80 | float high_capture_jitter_threshold_ms; // Threshold for triggering overuse. |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 81 | // Method based on encode time of frames. |
| 82 | bool enable_encode_usage_method; |
| 83 | int low_encode_usage_threshold_percent; // Threshold for triggering underuse. |
| 84 | int high_encode_usage_threshold_percent; // Threshold for triggering overuse. |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 85 | // General settings. |
| 86 | int frame_timeout_interval_ms; // The maximum allowed interval between two |
| 87 | // frames before resetting estimations. |
| 88 | int min_frame_samples; // The minimum number of frames required. |
| 89 | int min_process_count; // The number of initial process times required before |
| 90 | // triggering an overuse/underuse. |
| 91 | int high_threshold_consecutive_count; // The number of consecutive checks |
| 92 | // above the high threshold before |
| 93 | // triggering an overuse. |
| 94 | |
| 95 | bool Equals(const CpuOveruseOptions& o) const { |
| 96 | return enable_capture_jitter_method == o.enable_capture_jitter_method && |
| 97 | low_capture_jitter_threshold_ms == o.low_capture_jitter_threshold_ms && |
| 98 | high_capture_jitter_threshold_ms == |
| 99 | o.high_capture_jitter_threshold_ms && |
asapersson@webrtc.org | ce12f1f | 2014-03-24 21:59:16 +0000 | [diff] [blame] | 100 | enable_encode_usage_method == o.enable_encode_usage_method && |
| 101 | low_encode_usage_threshold_percent == |
| 102 | o.low_encode_usage_threshold_percent && |
| 103 | high_encode_usage_threshold_percent == |
| 104 | o.high_encode_usage_threshold_percent && |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 105 | frame_timeout_interval_ms == o.frame_timeout_interval_ms && |
| 106 | min_frame_samples == o.min_frame_samples && |
| 107 | min_process_count == o.min_process_count && |
| 108 | high_threshold_consecutive_count == o.high_threshold_consecutive_count; |
| 109 | } |
| 110 | }; |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 111 | |
asapersson@webrtc.org | ab6bf4f | 2014-05-27 07:43:15 +0000 | [diff] [blame] | 112 | struct CpuOveruseMetrics { |
| 113 | CpuOveruseMetrics() |
| 114 | : capture_jitter_ms(-1), |
| 115 | avg_encode_time_ms(-1), |
| 116 | encode_usage_percent(-1), |
| 117 | capture_queue_delay_ms_per_s(-1) {} |
| 118 | |
| 119 | int capture_jitter_ms; // The current estimated jitter in ms based on |
| 120 | // incoming captured frames. |
| 121 | int avg_encode_time_ms; // The average encode time in ms. |
| 122 | int encode_usage_percent; // The average encode time divided by the average |
| 123 | // time difference between incoming captured frames. |
| 124 | int capture_queue_delay_ms_per_s; // The current time delay between an |
| 125 | // incoming captured frame until the frame |
| 126 | // is being processed. The delay is |
| 127 | // expressed in ms delay per second. |
| 128 | }; |
| 129 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 130 | class WEBRTC_DLLEXPORT VideoEngine { |
| 131 | public: |
| 132 | // Creates a VideoEngine object, which can then be used to acquire sub‐APIs. |
| 133 | static VideoEngine* Create(); |
andresp@webrtc.org | 7707d06 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 134 | static VideoEngine* Create(const Config& config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 136 | // Deletes a VideoEngine instance. |
| 137 | static bool Delete(VideoEngine*& video_engine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 139 | // Specifies the amount and type of trace information, which will be created |
| 140 | // by the VideoEngine. |
| 141 | static int SetTraceFilter(const unsigned int filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 143 | // Sets the name of the trace file and enables non‐encrypted trace messages. |
| 144 | static int SetTraceFile(const char* file_nameUTF8, |
| 145 | const bool add_file_counter = false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 146 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 147 | // Installs the TraceCallback implementation to ensure that the VideoEngine |
| 148 | // user receives callbacks for generated trace messages. |
| 149 | static int SetTraceCallback(TraceCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 151 | #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 152 | // Android specific. |
fischman@webrtc.org | 9512719 | 2014-06-06 18:40:44 +0000 | [diff] [blame] | 153 | static int SetAndroidObjects(JavaVM* java_vm, jobject context); |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 154 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 156 | protected: |
| 157 | VideoEngine() {} |
| 158 | virtual ~VideoEngine() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 161 | class WEBRTC_DLLEXPORT ViEBase { |
| 162 | public: |
| 163 | // Factory for the ViEBase sub‐API and increases an internal reference |
| 164 | // counter if successful. Returns NULL if the API is not supported or if |
| 165 | // construction fails. |
| 166 | static ViEBase* GetInterface(VideoEngine* video_engine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 168 | // Releases the ViEBase sub-API and decreases an internal reference counter. |
| 169 | // Returns the new reference count. This value should be zero |
| 170 | // for all sub-API:s before the VideoEngine object can be safely deleted. |
| 171 | virtual int Release() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 173 | // Initiates all common parts of the VideoEngine. |
| 174 | virtual int Init() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 175 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 176 | // Connects a VideoEngine instance to a VoiceEngine instance for audio video |
| 177 | // synchronization. |
| 178 | virtual int SetVoiceEngine(VoiceEngine* voice_engine) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 180 | // Creates a new channel. |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 181 | virtual int CreateChannel(int& video_channel) = 0; |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 182 | |
| 183 | // Creates a new channel grouped together with |original_channel|. The channel |
| 184 | // can both send and receive video. It is assumed the channel is sending |
| 185 | // and/or receiving video to the same end-point. |
| 186 | // Note: |CreateReceiveChannel| will give better performance and network |
| 187 | // properties for receive only channels. |
| 188 | virtual int CreateChannel(int& video_channel, |
| 189 | int original_channel) = 0; |
| 190 | |
| 191 | // Creates a new channel grouped together with |original_channel|. The channel |
| 192 | // can only receive video and it is assumed the remote end-point is the same |
| 193 | // as for |original_channel|. |
| 194 | virtual int CreateReceiveChannel(int& video_channel, |
| 195 | int original_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 197 | // Deletes an existing channel and releases the utilized resources. |
| 198 | virtual int DeleteChannel(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 200 | // Registers an observer to be called when an overuse is detected, see |
| 201 | // 'CpuOveruseObserver' for details. |
| 202 | // NOTE: This is still very experimental functionality. |
| 203 | virtual int RegisterCpuOveruseObserver(int channel, |
| 204 | CpuOveruseObserver* observer) = 0; |
| 205 | |
asapersson@webrtc.org | 8a8c3ef | 2014-03-20 13:15:01 +0000 | [diff] [blame] | 206 | // Sets options for cpu overuse detector. |
| 207 | // TODO(asapersson): Remove default implementation. |
| 208 | virtual int SetCpuOveruseOptions(int channel, |
| 209 | const CpuOveruseOptions& options) { |
| 210 | return -1; |
| 211 | } |
| 212 | |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 213 | // Gets cpu overuse measures. |
asapersson@webrtc.org | b24d335 | 2013-11-20 13:51:40 +0000 | [diff] [blame] | 214 | // TODO(asapersson): Remove default implementation. |
asapersson@webrtc.org | ab6bf4f | 2014-05-27 07:43:15 +0000 | [diff] [blame] | 215 | virtual int GetCpuOveruseMetrics(int channel, |
| 216 | CpuOveruseMetrics* metrics) { |
| 217 | return -1; |
| 218 | } |
| 219 | // TODO(asapersson): Remove this function when libjingle has been updated. |
asapersson@webrtc.org | 9e5b034 | 2013-12-04 13:47:44 +0000 | [diff] [blame] | 220 | virtual int CpuOveruseMeasures(int channel, |
| 221 | int* capture_jitter_ms, |
| 222 | int* avg_encode_time_ms, |
| 223 | int* encode_usage_percent, |
| 224 | int* capture_queue_delay_ms_per_s) { |
| 225 | return -1; |
| 226 | } |
| 227 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 228 | // Specifies the VoiceEngine and VideoEngine channel pair to use for |
| 229 | // audio/video synchronization. |
| 230 | virtual int ConnectAudioChannel(const int video_channel, |
| 231 | const int audio_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 233 | // Disconnects a previously paired VideoEngine and VoiceEngine channel pair. |
| 234 | virtual int DisconnectAudioChannel(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 235 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 236 | // Starts sending packets to an already specified IP address and port number |
| 237 | // for a specified channel. |
| 238 | virtual int StartSend(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 240 | // Stops packets from being sent for a specified channel. |
| 241 | virtual int StopSend(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 242 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 243 | // Prepares VideoEngine for receiving packets on the specified channel. |
| 244 | virtual int StartReceive(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 245 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 246 | // Stops receiving incoming RTP and RTCP packets on the specified channel. |
| 247 | virtual int StopReceive(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 248 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 249 | // Retrieves the version information for VideoEngine and its components. |
| 250 | virtual int GetVersion(char version[1024]) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 251 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 252 | // Returns the last VideoEngine error code. |
| 253 | virtual int LastError() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 254 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 255 | protected: |
| 256 | ViEBase() {} |
| 257 | virtual ~ViEBase() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | }; |
| 259 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 260 | } // namespace webrtc |
| 261 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 262 | #endif // #define WEBRTC_VIDEO_ENGINE_MAIN_INTERFACE_VIE_BASE_H_ |