chromium/third_party/webrtc/video/adaptation/overuse_frame_detector.cc

/*
 *  Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
 *
 *  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.
 */

#include "video/adaptation/overuse_frame_detector.h"

#include <math.h>
#include <stdio.h>

#include <algorithm>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <utility>

#include "api/environment/environment.h"
#include "api/field_trials_view.h"
#include "api/video/video_frame.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/exp_filter.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"

#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
#include <mach/mach.h>
#endif  // defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)

namespace webrtc {

namespace {
const int64_t kCheckForOveruseIntervalMs =;
const int64_t kTimeToFirstCheckForOveruseMs =;

// Delay between consecutive rampups. (Used for quick recovery.)
const int kQuickRampUpDelayMs =;
// Delay between rampup attempts. Initially uses standard, scales up to max.
const int kStandardRampUpDelayMs =;
const int kMaxRampUpDelayMs =;
// Expontential back-off factor, to prevent annoying up-down behaviour.
const double kRampUpBackoffFactor =;

// Max number of overuses detected before always applying the rampup delay.
const int kMaxOverusesBeforeApplyRampupDelay =;

// The maximum exponent to use in VCMExpFilter.
const float kMaxExp =;
// Default value used before first reconfiguration.
const int kDefaultFrameRate =;
// Default sample diff, default frame rate.
const float kDefaultSampleDiffMs =;
// A factor applied to the sample diff on OnTargetFramerateUpdated to determine
// a max limit for the sample diff. For instance, with a framerate of 30fps,
// the sample diff is capped to (1000 / 30) * 1.35 = 45ms. This prevents
// triggering too soon if there are individual very large outliers.
const float kMaxSampleDiffMarginFactor =;
// Minimum framerate allowed for usage calculation. This prevents crazy long
// encode times from being accepted if the frame rate happens to be low.
const int kMinFramerate =;
const int kMaxFramerate =;

// Class for calculating the processing usage on the send-side (the average
// processing time of a frame divided by the average time difference between
// captured frames).
class SendProcessingUsage1 : public OveruseFrameDetector::ProcessingUsage {};

// New cpu load estimator.
// TODO(bugs.webrtc.org/8504): For some period of time, we need to
// switch between the two versions of the estimator for experiments.
// When problems are sorted out, the old estimator should be deleted.
class SendProcessingUsage2 : public OveruseFrameDetector::ProcessingUsage {};

// Class used for manual testing of overuse, enabled via field trial flag.
class OverdoseInjector : public OveruseFrameDetector::ProcessingUsage {};

}  // namespace

std::unique_ptr<OveruseFrameDetector::ProcessingUsage>
OveruseFrameDetector::CreateProcessingUsage(const FieldTrialsView& field_trials,
                                            const CpuOveruseOptions& options) {}

OveruseFrameDetector::OveruseFrameDetector(
    const Environment& env,
    CpuOveruseMetricsObserver* metrics_observer)
    :{}

OveruseFrameDetector::~OveruseFrameDetector() {}

void OveruseFrameDetector::StartCheckForOveruse(
    TaskQueueBase* task_queue_base,
    const CpuOveruseOptions& options,
    OveruseFrameDetectorObserverInterface* overuse_observer) {}
void OveruseFrameDetector::StopCheckForOveruse() {}

void OveruseFrameDetector::EncodedFrameTimeMeasured(int encode_duration_ms) {}

bool OveruseFrameDetector::FrameSizeChanged(int num_pixels) const {}

bool OveruseFrameDetector::FrameTimeoutDetected(int64_t now_us) const {}

void OveruseFrameDetector::ResetAll(int num_pixels) {}

void OveruseFrameDetector::OnTargetFramerateUpdated(int framerate_fps) {}

void OveruseFrameDetector::FrameCaptured(const VideoFrame& frame,
                                         int64_t time_when_first_seen_us) {}

void OveruseFrameDetector::FrameSent(uint32_t timestamp,
                                     int64_t time_sent_in_us,
                                     int64_t capture_time_us,
                                     absl::optional<int> encode_duration_us) {}

void OveruseFrameDetector::CheckForOveruse(
    OveruseFrameDetectorObserverInterface* observer) {}

void OveruseFrameDetector::SetOptions(const CpuOveruseOptions& options) {}

bool OveruseFrameDetector::IsOverusing(int usage_percent) {}

bool OveruseFrameDetector::IsUnderusing(int usage_percent, int64_t time_now) {}
}  // namespace webrtc