chromium/media/audio/audio_output_resampler.cc

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

#include "media/audio/audio_output_resampler.h"

#include <stdint.h>

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

#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/numerics/safe_conversions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "media/audio/audio_manager.h"
#include "media/audio/audio_output_dispatcher_impl.h"
#include "media/audio/audio_output_proxy.h"
#if BUILDFLAG(IS_WIN)
#include "media/audio/win/core_audio_util_win.h"
#endif  // BUILDFLAG(IS_WIN)
#include "media/base/audio_converter.h"
#include "media/base/audio_timestamp_helper.h"
#include "media/base/limits.h"
#include "media/base/sample_rates.h"

namespace media {

class OnMoreDataConverter
    : public AudioOutputStream::AudioSourceCallback,
      public AudioConverter::InputCallback {};

namespace {

// Record UMA statistics for hardware output configuration.
static void RecordStats(const AudioParameters& output_params) {}

// Only Windows has a high latency output driver that is not the same as the low
// latency path.
#if BUILDFLAG(IS_WIN)
// Converts low latency based |output_params| into high latency appropriate
// output parameters in error situations.
AudioParameters GetFallbackHighLatencyOutputParams(
    const AudioParameters& original_output_params) {
  DCHECK_EQ(original_output_params.format(),
            AudioParameters::AUDIO_PCM_LOW_LATENCY);
  // Choose AudioParameters appropriate for opening the device in high latency
  // mode.  |kMinLowLatencyFrameSize| is arbitrarily based on Pepper Flash's
  // MAXIMUM frame size for low latency.
  static const int kMinLowLatencyFrameSize = 2048;
  const int frames_per_buffer = std::max(
      original_output_params.frames_per_buffer(), kMinLowLatencyFrameSize);

  AudioParameters fallback_params(original_output_params);
  fallback_params.set_format(AudioParameters::AUDIO_PCM_LINEAR);
  fallback_params.set_frames_per_buffer(frames_per_buffer);
  return fallback_params;
}

// Get output parameter for low latency non-offload output, which is used for
// falling back from offload mode.
AudioParameters GetFallbackLowLatencyOutputParams(
    const std::string& device_id,
    const AudioParameters& original_output_params) {
  AudioParameters output_params;

  HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(
      device_id,
      /*is_output_device=*/true, &output_params, /*is_offload_stream=*/false);
  if (SUCCEEDED(hr)) {
    // Retain the channel layout and effects of the original output parameters.
    int effects = output_params.effects();
    effects |= original_output_params.effects();
    output_params.set_effects(effects);
    output_params.SetChannelLayoutConfig(
        original_output_params.channel_layout(),
        original_output_params.channels());
    return output_params;
  }
  // If we fail to get preferred audio parameters, return empty(invalid)
  // parameters so that fallbacking to linear mode will be attempted then.
  return AudioParameters();
}
#endif

// This enum must match the numbering for
// AudioOutputResamplerOpenLowLatencyStreamResult in enums.xml. Do not reorder
// or remove items, only add new items before OPEN_STREAM_MAX.
enum class OpenStreamResult {};

OpenStreamResult GetSubsequentStreamCreationResultBucket(
    const AudioParameters& current_params,
    bool success) {}

}  // namespace

AudioOutputResampler::AudioOutputResampler(
    AudioManager* audio_manager,
    const AudioParameters& input_params,
    const AudioParameters& output_params,
    const std::string& output_device_id,
    base::TimeDelta close_delay,
    const RegisterDebugRecordingSourceCallback&
        register_debug_recording_source_callback)
    :{}

AudioOutputResampler::~AudioOutputResampler() {}

void AudioOutputResampler::Reinitialize() {}

std::unique_ptr<AudioOutputDispatcherImpl> AudioOutputResampler::MakeDispatcher(
    const std::string& output_device_id,
    const AudioParameters& params) {}

AudioOutputProxy* AudioOutputResampler::CreateStreamProxy() {}

bool AudioOutputResampler::OpenStream() {}

bool AudioOutputResampler::StartStream(
    AudioOutputStream::AudioSourceCallback* callback,
    AudioOutputProxy* stream_proxy) {}

void AudioOutputResampler::StreamVolumeSet(AudioOutputProxy* stream_proxy,
                                           double volume) {}

void AudioOutputResampler::StopStream(AudioOutputProxy* stream_proxy) {}

void AudioOutputResampler::CloseStream(AudioOutputProxy* stream_proxy) {}

void AudioOutputResampler::FlushStream(AudioOutputProxy* stream_proxy) {}

void AudioOutputResampler::StopStreamInternal(
    const CallbackMap::value_type& item) {}

OnMoreDataConverter::OnMoreDataConverter(
    const AudioParameters& input_params,
    const AudioParameters& output_params,
    std::unique_ptr<AudioDebugRecorder> debug_recorder)
    :{}

OnMoreDataConverter::~OnMoreDataConverter() {}

void OnMoreDataConverter::Start(
    AudioOutputStream::AudioSourceCallback* callback) {}

void OnMoreDataConverter::Stop() {}

int OnMoreDataConverter::OnMoreData(base::TimeDelta delay,
                                    base::TimeTicks delay_timestamp,
                                    const AudioGlitchInfo& glitch_info,
                                    AudioBus* dest) {}

double OnMoreDataConverter::ProvideInput(AudioBus* dest,
                                         uint32_t frames_delayed,
                                         const AudioGlitchInfo& glitch_info) {}

void OnMoreDataConverter::OnError(ErrorType type) {}

}  // namespace media