2011-07-07 08:21:25 +00:00
|
|
|
|
/*
|
2012-03-05 17:12:41 +00:00
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
*
|
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// This sub-API supports the following functionalities:
|
|
|
|
|
|
//
|
|
|
|
|
|
// - Creating and deleting VideoEngine instances.
|
|
|
|
|
|
// - Creating and deleting channels.
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// - Connect a video channel with a corresponding voice channel for audio/video
|
|
|
|
|
|
// synchronization.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
// - Start and stop sending and receiving.
|
|
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
#ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_BASE_H_
|
|
|
|
|
|
#define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_BASE_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2013-05-17 13:44:48 +00:00
|
|
|
|
#include "webrtc/common_types.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2013-10-03 18:23:13 +00:00
|
|
|
|
#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2013-05-13 10:50:50 +00:00
|
|
|
|
class Config;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
class VoiceEngine;
|
|
|
|
|
|
|
2013-07-23 11:35:00 +00:00
|
|
|
|
// CpuOveruseObserver is called when a system overuse is detected and
|
|
|
|
|
|
// VideoEngine cannot keep up the encoding frequency.
|
|
|
|
|
|
class CpuOveruseObserver {
|
|
|
|
|
|
public:
|
|
|
|
|
|
// Called as soon as an overuse is detected.
|
|
|
|
|
|
virtual void OveruseDetected() = 0;
|
|
|
|
|
|
// Called periodically when the system is not overused any longer.
|
|
|
|
|
|
virtual void NormalUsage() = 0;
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
virtual ~CpuOveruseObserver() {}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2014-03-20 13:15:01 +00:00
|
|
|
|
// Limits on standard deviation for under/overuse.
|
|
|
|
|
|
#ifdef WEBRTC_ANDROID
|
|
|
|
|
|
const float kOveruseStdDevMs = 32.0f;
|
|
|
|
|
|
const float kNormalUseStdDevMs = 27.0f;
|
|
|
|
|
|
#elif WEBRTC_LINUX
|
|
|
|
|
|
const float kOveruseStdDevMs = 20.0f;
|
|
|
|
|
|
const float kNormalUseStdDevMs = 14.0f;
|
|
|
|
|
|
#elif WEBRTC_MAC
|
|
|
|
|
|
const float kOveruseStdDevMs = 27.0f;
|
|
|
|
|
|
const float kNormalUseStdDevMs = 21.0f;
|
|
|
|
|
|
#elif WEBRTC_WIN
|
|
|
|
|
|
const float kOveruseStdDevMs = 20.0f;
|
|
|
|
|
|
const float kNormalUseStdDevMs = 14.0f;
|
|
|
|
|
|
#else
|
|
|
|
|
|
const float kOveruseStdDevMs = 30.0f;
|
|
|
|
|
|
const float kNormalUseStdDevMs = 20.0f;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
struct CpuOveruseOptions {
|
|
|
|
|
|
CpuOveruseOptions()
|
|
|
|
|
|
: enable_capture_jitter_method(true),
|
|
|
|
|
|
low_capture_jitter_threshold_ms(kNormalUseStdDevMs),
|
|
|
|
|
|
high_capture_jitter_threshold_ms(kOveruseStdDevMs),
|
2014-03-24 21:59:16 +00:00
|
|
|
|
enable_encode_usage_method(false),
|
|
|
|
|
|
low_encode_usage_threshold_percent(60),
|
|
|
|
|
|
high_encode_usage_threshold_percent(90),
|
2014-03-20 13:15:01 +00:00
|
|
|
|
frame_timeout_interval_ms(1500),
|
|
|
|
|
|
min_frame_samples(120),
|
|
|
|
|
|
min_process_count(3),
|
|
|
|
|
|
high_threshold_consecutive_count(2) {}
|
|
|
|
|
|
|
|
|
|
|
|
// Method based on inter-arrival jitter of captured frames.
|
|
|
|
|
|
bool enable_capture_jitter_method;
|
|
|
|
|
|
float low_capture_jitter_threshold_ms; // Threshold for triggering underuse.
|
|
|
|
|
|
float high_capture_jitter_threshold_ms; // Threshold for triggering overuse.
|
2014-03-24 21:59:16 +00:00
|
|
|
|
// Method based on encode time of frames.
|
|
|
|
|
|
bool enable_encode_usage_method;
|
|
|
|
|
|
int low_encode_usage_threshold_percent; // Threshold for triggering underuse.
|
|
|
|
|
|
int high_encode_usage_threshold_percent; // Threshold for triggering overuse.
|
2014-03-20 13:15:01 +00:00
|
|
|
|
// General settings.
|
|
|
|
|
|
int frame_timeout_interval_ms; // The maximum allowed interval between two
|
|
|
|
|
|
// frames before resetting estimations.
|
|
|
|
|
|
int min_frame_samples; // The minimum number of frames required.
|
|
|
|
|
|
int min_process_count; // The number of initial process times required before
|
|
|
|
|
|
// triggering an overuse/underuse.
|
|
|
|
|
|
int high_threshold_consecutive_count; // The number of consecutive checks
|
|
|
|
|
|
// above the high threshold before
|
|
|
|
|
|
// triggering an overuse.
|
|
|
|
|
|
|
|
|
|
|
|
bool Equals(const CpuOveruseOptions& o) const {
|
|
|
|
|
|
return enable_capture_jitter_method == o.enable_capture_jitter_method &&
|
|
|
|
|
|
low_capture_jitter_threshold_ms == o.low_capture_jitter_threshold_ms &&
|
|
|
|
|
|
high_capture_jitter_threshold_ms ==
|
|
|
|
|
|
o.high_capture_jitter_threshold_ms &&
|
2014-03-24 21:59:16 +00:00
|
|
|
|
enable_encode_usage_method == o.enable_encode_usage_method &&
|
|
|
|
|
|
low_encode_usage_threshold_percent ==
|
|
|
|
|
|
o.low_encode_usage_threshold_percent &&
|
|
|
|
|
|
high_encode_usage_threshold_percent ==
|
|
|
|
|
|
o.high_encode_usage_threshold_percent &&
|
2014-03-20 13:15:01 +00:00
|
|
|
|
frame_timeout_interval_ms == o.frame_timeout_interval_ms &&
|
|
|
|
|
|
min_frame_samples == o.min_frame_samples &&
|
|
|
|
|
|
min_process_count == o.min_process_count &&
|
|
|
|
|
|
high_threshold_consecutive_count == o.high_threshold_consecutive_count;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2013-07-23 11:35:00 +00:00
|
|
|
|
|
2014-05-27 07:43:15 +00:00
|
|
|
|
struct CpuOveruseMetrics {
|
|
|
|
|
|
CpuOveruseMetrics()
|
|
|
|
|
|
: capture_jitter_ms(-1),
|
|
|
|
|
|
avg_encode_time_ms(-1),
|
|
|
|
|
|
encode_usage_percent(-1),
|
|
|
|
|
|
capture_queue_delay_ms_per_s(-1) {}
|
|
|
|
|
|
|
|
|
|
|
|
int capture_jitter_ms; // The current estimated jitter in ms based on
|
|
|
|
|
|
// incoming captured frames.
|
|
|
|
|
|
int avg_encode_time_ms; // The average encode time in ms.
|
|
|
|
|
|
int encode_usage_percent; // The average encode time divided by the average
|
|
|
|
|
|
// time difference between incoming captured frames.
|
|
|
|
|
|
int capture_queue_delay_ms_per_s; // The current time delay between an
|
|
|
|
|
|
// incoming captured frame until the frame
|
|
|
|
|
|
// is being processed. The delay is
|
|
|
|
|
|
// expressed in ms delay per second.
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
class WEBRTC_DLLEXPORT VideoEngine {
|
|
|
|
|
|
public:
|
|
|
|
|
|
// Creates a VideoEngine object, which can then be used to acquire sub‐APIs.
|
|
|
|
|
|
static VideoEngine* Create();
|
2013-05-13 10:50:50 +00:00
|
|
|
|
static VideoEngine* Create(const Config& config);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Deletes a VideoEngine instance.
|
|
|
|
|
|
static bool Delete(VideoEngine*& video_engine);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Specifies the amount and type of trace information, which will be created
|
|
|
|
|
|
// by the VideoEngine.
|
|
|
|
|
|
static int SetTraceFilter(const unsigned int filter);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Sets the name of the trace file and enables non‐encrypted trace messages.
|
|
|
|
|
|
static int SetTraceFile(const char* file_nameUTF8,
|
|
|
|
|
|
const bool add_file_counter = false);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Installs the TraceCallback implementation to ensure that the VideoEngine
|
|
|
|
|
|
// user receives callbacks for generated trace messages.
|
|
|
|
|
|
static int SetTraceCallback(TraceCallback* callback);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2013-10-03 18:23:13 +00:00
|
|
|
|
#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Android specific.
|
2014-06-06 18:40:44 +00:00
|
|
|
|
static int SetAndroidObjects(JavaVM* java_vm, jobject context);
|
2013-10-03 18:23:13 +00:00
|
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
protected:
|
|
|
|
|
|
VideoEngine() {}
|
|
|
|
|
|
virtual ~VideoEngine() {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
class WEBRTC_DLLEXPORT ViEBase {
|
|
|
|
|
|
public:
|
|
|
|
|
|
// Factory for the ViEBase sub‐API and increases an internal reference
|
|
|
|
|
|
// counter if successful. Returns NULL if the API is not supported or if
|
|
|
|
|
|
// construction fails.
|
|
|
|
|
|
static ViEBase* GetInterface(VideoEngine* video_engine);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Releases the ViEBase sub-API and decreases an internal reference counter.
|
|
|
|
|
|
// Returns the new reference count. This value should be zero
|
|
|
|
|
|
// for all sub-API:s before the VideoEngine object can be safely deleted.
|
|
|
|
|
|
virtual int Release() = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Initiates all common parts of the VideoEngine.
|
|
|
|
|
|
virtual int Init() = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Connects a VideoEngine instance to a VoiceEngine instance for audio video
|
|
|
|
|
|
// synchronization.
|
|
|
|
|
|
virtual int SetVoiceEngine(VoiceEngine* voice_engine) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-03-05 17:12:41 +00:00
|
|
|
|
// Creates a new channel.
|
2012-01-02 13:04:05 +00:00
|
|
|
|
virtual int CreateChannel(int& video_channel) = 0;
|
2012-03-05 17:12:41 +00:00
|
|
|
|
|
|
|
|
|
|
// Creates a new channel grouped together with |original_channel|. The channel
|
|
|
|
|
|
// can both send and receive video. It is assumed the channel is sending
|
|
|
|
|
|
// and/or receiving video to the same end-point.
|
|
|
|
|
|
// Note: |CreateReceiveChannel| will give better performance and network
|
|
|
|
|
|
// properties for receive only channels.
|
|
|
|
|
|
virtual int CreateChannel(int& video_channel,
|
|
|
|
|
|
int original_channel) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Creates a new channel grouped together with |original_channel|. The channel
|
|
|
|
|
|
// can only receive video and it is assumed the remote end-point is the same
|
|
|
|
|
|
// as for |original_channel|.
|
|
|
|
|
|
virtual int CreateReceiveChannel(int& video_channel,
|
|
|
|
|
|
int original_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Deletes an existing channel and releases the utilized resources.
|
|
|
|
|
|
virtual int DeleteChannel(const int video_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2013-07-23 11:35:00 +00:00
|
|
|
|
// Registers an observer to be called when an overuse is detected, see
|
|
|
|
|
|
// 'CpuOveruseObserver' for details.
|
|
|
|
|
|
// NOTE: This is still very experimental functionality.
|
|
|
|
|
|
virtual int RegisterCpuOveruseObserver(int channel,
|
|
|
|
|
|
CpuOveruseObserver* observer) = 0;
|
|
|
|
|
|
|
2014-03-20 13:15:01 +00:00
|
|
|
|
// Sets options for cpu overuse detector.
|
|
|
|
|
|
// TODO(asapersson): Remove default implementation.
|
|
|
|
|
|
virtual int SetCpuOveruseOptions(int channel,
|
|
|
|
|
|
const CpuOveruseOptions& options) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-12-04 13:47:44 +00:00
|
|
|
|
// Gets cpu overuse measures.
|
2013-11-20 13:51:40 +00:00
|
|
|
|
// TODO(asapersson): Remove default implementation.
|
2014-05-27 07:43:15 +00:00
|
|
|
|
virtual int GetCpuOveruseMetrics(int channel,
|
|
|
|
|
|
CpuOveruseMetrics* metrics) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
// TODO(asapersson): Remove this function when libjingle has been updated.
|
2013-12-04 13:47:44 +00:00
|
|
|
|
virtual int CpuOveruseMeasures(int channel,
|
|
|
|
|
|
int* capture_jitter_ms,
|
|
|
|
|
|
int* avg_encode_time_ms,
|
|
|
|
|
|
int* encode_usage_percent,
|
|
|
|
|
|
int* capture_queue_delay_ms_per_s) {
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Specifies the VoiceEngine and VideoEngine channel pair to use for
|
|
|
|
|
|
// audio/video synchronization.
|
|
|
|
|
|
virtual int ConnectAudioChannel(const int video_channel,
|
|
|
|
|
|
const int audio_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Disconnects a previously paired VideoEngine and VoiceEngine channel pair.
|
|
|
|
|
|
virtual int DisconnectAudioChannel(const int video_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Starts sending packets to an already specified IP address and port number
|
|
|
|
|
|
// for a specified channel.
|
|
|
|
|
|
virtual int StartSend(const int video_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Stops packets from being sent for a specified channel.
|
|
|
|
|
|
virtual int StopSend(const int video_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Prepares VideoEngine for receiving packets on the specified channel.
|
|
|
|
|
|
virtual int StartReceive(const int video_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Stops receiving incoming RTP and RTCP packets on the specified channel.
|
|
|
|
|
|
virtual int StopReceive(const int video_channel) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Retrieves the version information for VideoEngine and its components.
|
|
|
|
|
|
virtual int GetVersion(char version[1024]) = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
// Returns the last VideoEngine error code.
|
|
|
|
|
|
virtual int LastError() = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
protected:
|
|
|
|
|
|
ViEBase() {}
|
|
|
|
|
|
virtual ~ViEBase() {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2012-01-02 13:04:05 +00:00
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
|
#endif // #define WEBRTC_VIDEO_ENGINE_MAIN_INTERFACE_VIE_BASE_H_
|