webrtc_m130/modules/audio_device/include/test_audio_device.h
Jeremy Leconte b035dcc0a2 Revert "Reland "Migrate TestAudioDeviceModule on AudioDeviceModuleImpl""
This reverts commit eeae96299784515f573379a64655eb07a5973a3a.

Reason for revert: breaks WebRTC Chromium FYI ios-device
https://ci.chromium.org/ui/p/chromium/builders/webrtc.fyi/WebRTC%20Chromium%20FYI%20ios-device/14896/overview

Original change's description:
> Reland "Migrate TestAudioDeviceModule on AudioDeviceModuleImpl"
>
> This reverts commit 69c8d3c843326aff9dee32cc639741c1cd7f8ae9.
>
> Reason for revert: Reland with a fix
>
> Original change's description:
> > Revert "Migrate TestAudioDeviceModule on AudioDeviceModuleImpl"
> >
> > This reverts commit e42bf81486d2f08b6dcbf1442287202e937ce52b.
> >
> > Reason for revert: Breaks iOS simulator bots and thus blocks chromium roll, https://chromium-review.googlesource.com/c/chromium/src/+/4433814
> >
> > Original change's description:
> > > Migrate TestAudioDeviceModule on AudioDeviceModuleImpl
> > >
> > > Bug: b/272350185
> > > Change-Id: Ia3d85d6fa3b0d4809e987a39d60d3eb022687132
> > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300363
> > > Commit-Queue: Artem Titov <titovartem@webrtc.org>
> > > Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
> > > Cr-Commit-Position: refs/heads/main@{#39877}
> >
> > Bug: b/272350185
> > Change-Id: I1e3b542fc1278797f283afedeae01cbb7412d353
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/301701
> > Commit-Queue: Jeremy Leconte <jleconte@google.com>
> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
> > Reviewed-by: Jeremy Leconte <jleconte@google.com>
> > Auto-Submit: Christoffer Jansson <jansson@google.com>
> > Owners-Override: Christoffer Jansson <jansson@google.com>
> > Cr-Commit-Position: refs/heads/main@{#39881}
>
> Bug: b/272350185
> Change-Id: I809466306b2e1fd54c44b90311059c98a53ef8ee
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/301704
> Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
> Commit-Queue: Artem Titov <titovartem@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#39936}

Bug: b/272350185
Change-Id: If0a10717bf14a0a618e52728fc3a61b9c55f3bd2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/303460
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Owners-Override: Jeremy Leconte <jleconte@google.com>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#39947}
2023-04-25 10:24:56 +00:00

153 lines
5.8 KiB
C++

/*
* Copyright (c) 2018 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.
*/
#ifndef MODULES_AUDIO_DEVICE_INCLUDE_TEST_AUDIO_DEVICE_H_
#define MODULES_AUDIO_DEVICE_INCLUDE_TEST_AUDIO_DEVICE_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "api/scoped_refptr.h"
#include "api/task_queue/task_queue_factory.h"
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_device/include/audio_device_defines.h"
#include "rtc_base/buffer.h"
namespace webrtc {
// This is test API and is in development, so it can be changed/removed without
// notice.
// TestAudioDeviceModule implements an AudioDevice module that can act both as a
// capturer and a renderer. It will use 10ms audio frames.
class TestAudioDeviceModule : public AudioDeviceModule {
public:
// Returns the number of samples that Capturers and Renderers with this
// sampling frequency will work with every time Capture or Render is called.
static size_t SamplesPerFrame(int sampling_frequency_in_hz);
class Capturer {
public:
virtual ~Capturer() {}
// Returns the sampling frequency in Hz of the audio data that this
// capturer produces.
virtual int SamplingFrequency() const = 0;
// Returns the number of channels of captured audio data.
virtual int NumChannels() const = 0;
// Replaces the contents of `buffer` with 10ms of captured audio data
// (see TestAudioDeviceModule::SamplesPerFrame). Returns true if the
// capturer can keep producing data, or false when the capture finishes.
virtual bool Capture(rtc::BufferT<int16_t>* buffer) = 0;
};
class Renderer {
public:
virtual ~Renderer() {}
// Returns the sampling frequency in Hz of the audio data that this
// renderer receives.
virtual int SamplingFrequency() const = 0;
// Returns the number of channels of audio data to be required.
virtual int NumChannels() const = 0;
// Renders the passed audio data and returns true if the renderer wants
// to keep receiving data, or false otherwise.
virtual bool Render(rtc::ArrayView<const int16_t> data) = 0;
};
// A fake capturer that generates pulses with random samples between
// -max_amplitude and +max_amplitude.
class PulsedNoiseCapturer : public Capturer {
public:
~PulsedNoiseCapturer() override {}
virtual void SetMaxAmplitude(int16_t amplitude) = 0;
};
~TestAudioDeviceModule() override {}
// Creates a new TestAudioDeviceModule. When capturing or playing, 10 ms audio
// frames will be processed every 10ms / `speed`.
// `capturer` is an object that produces audio data. Can be nullptr if this
// device is never used for recording.
// `renderer` is an object that receives audio data that would have been
// played out. Can be nullptr if this device is never used for playing.
// Use one of the Create... functions to get these instances.
static rtc::scoped_refptr<AudioDeviceModule> Create(
TaskQueueFactory* task_queue_factory,
std::unique_ptr<Capturer> capturer,
std::unique_ptr<Renderer> renderer,
float speed = 1);
// Returns a Capturer instance that generates a signal of `num_channels`
// channels where every second frame is zero and every second frame is evenly
// distributed random noise with max amplitude `max_amplitude`.
static std::unique_ptr<PulsedNoiseCapturer> CreatePulsedNoiseCapturer(
int16_t max_amplitude,
int sampling_frequency_in_hz,
int num_channels = 1);
// Returns a Renderer instance that does nothing with the audio data.
static std::unique_ptr<Renderer> CreateDiscardRenderer(
int sampling_frequency_in_hz,
int num_channels = 1);
// WavReader and WavWriter creation based on file name.
// Returns a Capturer instance that gets its data from a file. The sample rate
// and channels will be checked against the Wav file.
static std::unique_ptr<Capturer> CreateWavFileReader(
absl::string_view filename,
int sampling_frequency_in_hz,
int num_channels = 1);
// Returns a Capturer instance that gets its data from a file.
// Automatically detects sample rate and num of channels.
// `repeat` - if true, the file will be replayed from the start when we reach
// the end of file.
static std::unique_ptr<Capturer> CreateWavFileReader(
absl::string_view filename,
bool repeat = false);
// Returns a Renderer instance that writes its data to a file.
static std::unique_ptr<Renderer> CreateWavFileWriter(
absl::string_view filename,
int sampling_frequency_in_hz,
int num_channels = 1);
// Returns a Renderer instance that writes its data to a WAV file, cutting
// off silence at the beginning (not necessarily perfect silence, see
// kAmplitudeThreshold) and at the end (only actual 0 samples in this case).
static std::unique_ptr<Renderer> CreateBoundedWavFileWriter(
absl::string_view filename,
int sampling_frequency_in_hz,
int num_channels = 1);
int32_t Init() override = 0;
int32_t RegisterAudioCallback(AudioTransport* callback) override = 0;
int32_t StartPlayout() override = 0;
int32_t StopPlayout() override = 0;
int32_t StartRecording() override = 0;
int32_t StopRecording() override = 0;
bool Playing() const override = 0;
bool Recording() const override = 0;
// Blocks forever until the Recorder stops producing data.
virtual void WaitForRecordingEnd() = 0;
};
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_INCLUDE_TEST_AUDIO_DEVICE_H_