blob: 8fc5c04d5a9035a8447004a39ca8f006382048ad [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
#include "media/base/multi_channel_resampler.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace media {
class AudioBus;
} // namespace media
namespace blink {
class AudioBus;
// This is a simple wrapper around the MultiChannelResampler provided by the
// media layer.
class PLATFORM_EXPORT MediaMultiChannelResampler {
// Callback type for providing more data into the resampler. Expects AudioBus
// to be completely filled with data upon return; zero padded if not enough
// frames are available to satisfy the request. |frame_delay| is the number
// of output frames already processed and can be used to estimate delay.
typedef base::RepeatingCallback<void(int frame_delay, AudioBus* audio_bus)>
// Constructs a MultiChannelResampler with the specified |read_cb|, which is
// used to acquire audio data for resampling. |io_sample_rate_ratio| is the
// ratio of input / output sample rates. |request_frames| is the size in
// frames of the AudioBus to be filled by |read_cb|.
MediaMultiChannelResampler(int channels,
double io_sample_rate_ratio,
size_t request_frames,
const ReadCB& read_cb);
// Resamples |frames| of data from |read_cb_| into AudioBus.
void Resample(int frames, media::AudioBus* audio_bus);
// Wrapper method used to provide input to the media::MultiChannelResampler
// with a media::AudioBus rather than a blink::AudioBus.
void ProvideResamplerInput(int resampler_frame_delay, media::AudioBus* dest);
// The resampler being wrapped by this class.
std::unique_ptr<media::MultiChannelResampler> resampler_;
// The callback using a blink::AudioBus that will be called by
// ProvideResamplerInput().
ReadCB read_cb_;
} // namespace blink