#include "third_party/blink/renderer/platform/peerconnection/webrtc_audio_sink.h"
#include <limits>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/ranges/algorithm.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "media/base/audio_timestamp_helper.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/webrtc/rtc_base/ref_counted_object.h"
namespace {
void SendLogMessage(const std::string& message) { … }
}
namespace WTF {
template <>
struct CrossThreadCopier<scoped_refptr<webrtc::AudioProcessorInterface>>
: public CrossThreadCopierByValuePassThrough<
scoped_refptr<webrtc::AudioProcessorInterface>> { … };
template <>
struct CrossThreadCopier<scoped_refptr<blink::WebRtcAudioSink::Adapter>>
: public CrossThreadCopierPassThrough<
scoped_refptr<blink::WebRtcAudioSink::Adapter>> { … };
}
namespace blink {
WebRtcAudioSink::WebRtcAudioSink(
const std::string& label,
scoped_refptr<webrtc::AudioSourceInterface> track_source,
scoped_refptr<base::SingleThreadTaskRunner> signaling_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
: … { … }
WebRtcAudioSink::~WebRtcAudioSink() { … }
void WebRtcAudioSink::SetAudioProcessor(
scoped_refptr<webrtc::AudioProcessorInterface> processor) { … }
void WebRtcAudioSink::SetLevel(
scoped_refptr<MediaStreamAudioLevelCalculator::Level> level) { … }
void WebRtcAudioSink::OnEnabledChanged(bool enabled) { … }
void WebRtcAudioSink::OnData(const media::AudioBus& audio_bus,
base::TimeTicks estimated_capture_time) { … }
void WebRtcAudioSink::OnSetFormat(const media::AudioParameters& params) { … }
void WebRtcAudioSink::DeliverRebufferedAudio(const media::AudioBus& audio_bus,
int frame_delay) { … }
namespace {
void DereferenceOnMainThread(
scoped_refptr<webrtc::AudioProcessorInterface> processor) { … }
}
WebRtcAudioSink::Adapter::Adapter(
const std::string& label,
scoped_refptr<webrtc::AudioSourceInterface> source,
scoped_refptr<base::SingleThreadTaskRunner> signaling_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
: … { … }
WebRtcAudioSink::Adapter::~Adapter() { … }
int WebRtcAudioSink::Adapter::DeliverPCMToWebRtcSinks(
const int16_t* audio_data,
int sample_rate,
size_t number_of_channels,
size_t number_of_frames,
base::TimeTicks estimated_capture_time) { … }
std::string WebRtcAudioSink::Adapter::kind() const { … }
bool WebRtcAudioSink::Adapter::set_enabled(bool enable) { … }
void WebRtcAudioSink::Adapter::AddSink(webrtc::AudioTrackSinkInterface* sink) { … }
void WebRtcAudioSink::Adapter::RemoveSink(
webrtc::AudioTrackSinkInterface* sink) { … }
bool WebRtcAudioSink::Adapter::GetSignalLevel(int* level) { … }
rtc::scoped_refptr<webrtc::AudioProcessorInterface>
WebRtcAudioSink::Adapter::GetAudioProcessor() { … }
webrtc::AudioSourceInterface* WebRtcAudioSink::Adapter::GetSource() const { … }
void WebRtcAudioSink::Adapter::UpdateTimestampAligner(
base::TimeTicks capture_time) { … }
}