chromium/third_party/blink/renderer/modules/webcodecs/codec_pressure_gauge.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/webcodecs/codec_pressure_gauge.h"

#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"

#if !BUILDFLAG(IS_WIN)
#define USE_SHARED_INSTANCE
#endif

// These numbers were picked as roughly 1/4th of the empirical lower limit at
// which we start getting errors when allocating new codecs. Some platforms have
// a decoder limit and an encoder limit, whereas others have a common shared
// limit. These estimates are conservative, but they take into account the fact
// that the true limits are OS-wide, while these thresholds are per-process. It
// also takes into account that we never actually gate codec creation, and we
// only vary the eagerness with which we will try to reclaim codecs instead.
#if BUILDFLAG(IS_WIN)
constexpr int kDecoderPressureThreshold = 6;
constexpr int kEncoderPressureThreshold = 0;
#elif BUILDFLAG(IS_CHROMEOS)
constexpr int kSharedPressureThreshold = 3;
#elif BUILDFLAG(IS_MAC)
constexpr int kSharedPressureThreshold = 24;
#elif BUILDFLAG(IS_ANDROID)
constexpr int kSharedPressureThreshold = 4;
#else
// By default (e.g. for Linux, Fuschia, Chromecast...), any codec with pressure
// should be reclaimable, regardless of global presure.
constexpr int kSharedPressureThreshold =;
#endif

namespace blink {

CodecPressureGauge::CodecPressureGauge(size_t pressure_threshold)
    :{}

// static
CodecPressureGauge& CodecPressureGauge::GetInstance(
    ReclaimableCodec::CodecType type) {}

#if defined(USE_SHARED_INSTANCE)
// static
CodecPressureGauge& CodecPressureGauge::SharedInstance() {}
#else
// static
CodecPressureGauge& CodecPressureGauge::DecoderInstance() {
  DEFINE_THREAD_SAFE_STATIC_LOCAL(CodecPressureGauge, decoder_instance,
                                  (kDecoderPressureThreshold));

  return decoder_instance;
}

// static
CodecPressureGauge& CodecPressureGauge::EncoderInstance() {
  DEFINE_THREAD_SAFE_STATIC_LOCAL(CodecPressureGauge, encoder_instance,
                                  (kEncoderPressureThreshold));

  return encoder_instance;
}
#endif

#undef USE_SHARED_INSTANCE

void CodecPressureGauge::Increment() {}

void CodecPressureGauge::Decrement() {}

std::pair<CodecPressureGauge::PressureCallbackId, bool>
CodecPressureGauge::RegisterPressureCallback(
    PressureThresholdChangedCallback pressure_callback) {}

void CodecPressureGauge::UnregisterPressureCallback(
    PressureCallbackId callback_id,
    size_t pressure_released) {}

void CodecPressureGauge::CheckForThresholdChanges_Locked() {}

}  // namespace blink