2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* 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.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This class implements an AudioCaptureModule that can be used to detect if
|
|
|
|
|
// audio is being received properly if it is fed by another AudioCaptureModule
|
|
|
|
|
// in some arbitrary audio pipeline where they are connected. It does not play
|
|
|
|
|
// out or record any audio so it does not need access to any hardware and can
|
|
|
|
|
// therefore be used in the gtest testing framework.
|
|
|
|
|
|
|
|
|
|
// Note P postfix of a function indicates that it should only be called by the
|
|
|
|
|
// processing thread.
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#ifndef WEBRTC_API_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
|
|
|
|
#define WEBRTC_API_TEST_FAKEAUDIOCAPTUREMODULE_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-04-27 06:47:29 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/basictypes.h"
|
|
|
|
|
#include "webrtc/base/criticalsection.h"
|
|
|
|
|
#include "webrtc/base/messagehandler.h"
|
2015-08-13 14:27:18 -07:00
|
|
|
#include "webrtc/base/scoped_ptr.h"
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/scoped_ref_ptr.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
#include "webrtc/common_types.h"
|
|
|
|
|
#include "webrtc/modules/audio_device/include/audio_device.h"
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
namespace rtc {
|
2013-07-10 00:45:36 +00:00
|
|
|
class Thread;
|
2014-07-29 17:36:52 +00:00
|
|
|
} // namespace rtc
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
class FakeAudioCaptureModule
|
|
|
|
|
: public webrtc::AudioDeviceModule,
|
2014-07-29 17:36:52 +00:00
|
|
|
public rtc::MessageHandler {
|
2013-07-10 00:45:36 +00:00
|
|
|
public:
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
typedef uint16_t Sample;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// The value for the following constants have been derived by running VoE
|
|
|
|
|
// using a real ADM. The constants correspond to 10ms of mono audio at 44kHz.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
static const size_t kNumberSamples = 440;
|
|
|
|
|
static const size_t kNumberBytesPerSample = sizeof(Sample);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Creates a FakeAudioCaptureModule or returns NULL on failure.
|
2015-08-13 14:27:18 -07:00
|
|
|
static rtc::scoped_refptr<FakeAudioCaptureModule> Create();
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Returns the number of frames that have been successfully pulled by the
|
|
|
|
|
// instance. Note that correctly detecting success can only be done if the
|
|
|
|
|
// pulled frame was generated/pushed from a FakeAudioCaptureModule.
|
|
|
|
|
int frames_received() const;
|
|
|
|
|
|
|
|
|
|
// Following functions are inherited from webrtc::AudioDeviceModule.
|
|
|
|
|
// Only functions called by PeerConnection are implemented, the rest do
|
|
|
|
|
// nothing and return success. If a function is not expected to be called by
|
|
|
|
|
// PeerConnection an assertion is triggered if it is in fact called.
|
2015-03-04 12:58:35 +00:00
|
|
|
int64_t TimeUntilNextProcess() override;
|
2016-02-25 04:50:01 -08:00
|
|
|
void Process() override;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int32_t ActiveAudioLayer(AudioLayer* audio_layer) const override;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
ErrorCode LastError() const override;
|
|
|
|
|
int32_t RegisterEventObserver(
|
|
|
|
|
webrtc::AudioDeviceObserver* event_callback) override;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2013-10-22 23:09:20 +00:00
|
|
|
// Note: Calling this method from a callback may result in deadlock.
|
2015-03-04 12:58:35 +00:00
|
|
|
int32_t RegisterAudioCallback(
|
|
|
|
|
webrtc::AudioTransport* audio_callback) override;
|
|
|
|
|
|
|
|
|
|
int32_t Init() override;
|
|
|
|
|
int32_t Terminate() override;
|
|
|
|
|
bool Initialized() const override;
|
|
|
|
|
|
|
|
|
|
int16_t PlayoutDevices() override;
|
|
|
|
|
int16_t RecordingDevices() override;
|
|
|
|
|
int32_t PlayoutDeviceName(uint16_t index,
|
|
|
|
|
char name[webrtc::kAdmMaxDeviceNameSize],
|
|
|
|
|
char guid[webrtc::kAdmMaxGuidSize]) override;
|
|
|
|
|
int32_t RecordingDeviceName(uint16_t index,
|
|
|
|
|
char name[webrtc::kAdmMaxDeviceNameSize],
|
|
|
|
|
char guid[webrtc::kAdmMaxGuidSize]) override;
|
|
|
|
|
|
|
|
|
|
int32_t SetPlayoutDevice(uint16_t index) override;
|
|
|
|
|
int32_t SetPlayoutDevice(WindowsDeviceType device) override;
|
|
|
|
|
int32_t SetRecordingDevice(uint16_t index) override;
|
|
|
|
|
int32_t SetRecordingDevice(WindowsDeviceType device) override;
|
|
|
|
|
|
|
|
|
|
int32_t PlayoutIsAvailable(bool* available) override;
|
|
|
|
|
int32_t InitPlayout() override;
|
|
|
|
|
bool PlayoutIsInitialized() const override;
|
|
|
|
|
int32_t RecordingIsAvailable(bool* available) override;
|
|
|
|
|
int32_t InitRecording() override;
|
|
|
|
|
bool RecordingIsInitialized() const override;
|
|
|
|
|
|
|
|
|
|
int32_t StartPlayout() override;
|
|
|
|
|
int32_t StopPlayout() override;
|
|
|
|
|
bool Playing() const override;
|
|
|
|
|
int32_t StartRecording() override;
|
|
|
|
|
int32_t StopRecording() override;
|
|
|
|
|
bool Recording() const override;
|
|
|
|
|
|
|
|
|
|
int32_t SetAGC(bool enable) override;
|
|
|
|
|
bool AGC() const override;
|
|
|
|
|
|
|
|
|
|
int32_t SetWaveOutVolume(uint16_t volume_left,
|
|
|
|
|
uint16_t volume_right) override;
|
|
|
|
|
int32_t WaveOutVolume(uint16_t* volume_left,
|
|
|
|
|
uint16_t* volume_right) const override;
|
|
|
|
|
|
|
|
|
|
int32_t InitSpeaker() override;
|
|
|
|
|
bool SpeakerIsInitialized() const override;
|
|
|
|
|
int32_t InitMicrophone() override;
|
|
|
|
|
bool MicrophoneIsInitialized() const override;
|
|
|
|
|
|
|
|
|
|
int32_t SpeakerVolumeIsAvailable(bool* available) override;
|
|
|
|
|
int32_t SetSpeakerVolume(uint32_t volume) override;
|
|
|
|
|
int32_t SpeakerVolume(uint32_t* volume) const override;
|
|
|
|
|
int32_t MaxSpeakerVolume(uint32_t* max_volume) const override;
|
|
|
|
|
int32_t MinSpeakerVolume(uint32_t* min_volume) const override;
|
|
|
|
|
int32_t SpeakerVolumeStepSize(uint16_t* step_size) const override;
|
|
|
|
|
|
|
|
|
|
int32_t MicrophoneVolumeIsAvailable(bool* available) override;
|
|
|
|
|
int32_t SetMicrophoneVolume(uint32_t volume) override;
|
|
|
|
|
int32_t MicrophoneVolume(uint32_t* volume) const override;
|
|
|
|
|
int32_t MaxMicrophoneVolume(uint32_t* max_volume) const override;
|
|
|
|
|
|
|
|
|
|
int32_t MinMicrophoneVolume(uint32_t* min_volume) const override;
|
|
|
|
|
int32_t MicrophoneVolumeStepSize(uint16_t* step_size) const override;
|
|
|
|
|
|
|
|
|
|
int32_t SpeakerMuteIsAvailable(bool* available) override;
|
|
|
|
|
int32_t SetSpeakerMute(bool enable) override;
|
|
|
|
|
int32_t SpeakerMute(bool* enabled) const override;
|
|
|
|
|
|
|
|
|
|
int32_t MicrophoneMuteIsAvailable(bool* available) override;
|
|
|
|
|
int32_t SetMicrophoneMute(bool enable) override;
|
|
|
|
|
int32_t MicrophoneMute(bool* enabled) const override;
|
|
|
|
|
|
|
|
|
|
int32_t MicrophoneBoostIsAvailable(bool* available) override;
|
|
|
|
|
int32_t SetMicrophoneBoost(bool enable) override;
|
|
|
|
|
int32_t MicrophoneBoost(bool* enabled) const override;
|
|
|
|
|
|
|
|
|
|
int32_t StereoPlayoutIsAvailable(bool* available) const override;
|
|
|
|
|
int32_t SetStereoPlayout(bool enable) override;
|
|
|
|
|
int32_t StereoPlayout(bool* enabled) const override;
|
|
|
|
|
int32_t StereoRecordingIsAvailable(bool* available) const override;
|
|
|
|
|
int32_t SetStereoRecording(bool enable) override;
|
|
|
|
|
int32_t StereoRecording(bool* enabled) const override;
|
|
|
|
|
int32_t SetRecordingChannel(const ChannelType channel) override;
|
|
|
|
|
int32_t RecordingChannel(ChannelType* channel) const override;
|
|
|
|
|
|
|
|
|
|
int32_t SetPlayoutBuffer(const BufferType type,
|
|
|
|
|
uint16_t size_ms = 0) override;
|
|
|
|
|
int32_t PlayoutBuffer(BufferType* type, uint16_t* size_ms) const override;
|
|
|
|
|
int32_t PlayoutDelay(uint16_t* delay_ms) const override;
|
|
|
|
|
int32_t RecordingDelay(uint16_t* delay_ms) const override;
|
|
|
|
|
|
|
|
|
|
int32_t CPULoad(uint16_t* load) const override;
|
|
|
|
|
|
|
|
|
|
int32_t StartRawOutputFileRecording(
|
|
|
|
|
const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) override;
|
|
|
|
|
int32_t StopRawOutputFileRecording() override;
|
|
|
|
|
int32_t StartRawInputFileRecording(
|
|
|
|
|
const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) override;
|
|
|
|
|
int32_t StopRawInputFileRecording() override;
|
|
|
|
|
|
|
|
|
|
int32_t SetRecordingSampleRate(const uint32_t samples_per_sec) override;
|
|
|
|
|
int32_t RecordingSampleRate(uint32_t* samples_per_sec) const override;
|
|
|
|
|
int32_t SetPlayoutSampleRate(const uint32_t samples_per_sec) override;
|
|
|
|
|
int32_t PlayoutSampleRate(uint32_t* samples_per_sec) const override;
|
|
|
|
|
|
|
|
|
|
int32_t ResetAudioDevice() override;
|
|
|
|
|
int32_t SetLoudspeakerStatus(bool enable) override;
|
|
|
|
|
int32_t GetLoudspeakerStatus(bool* enabled) const override;
|
2016-04-29 06:09:15 -07:00
|
|
|
bool BuiltInAECIsAvailable() const override { return false; }
|
|
|
|
|
int32_t EnableBuiltInAEC(bool enable) override { return -1; }
|
|
|
|
|
bool BuiltInAGCIsAvailable() const override { return false; }
|
|
|
|
|
int32_t EnableBuiltInAGC(bool enable) override { return -1; }
|
|
|
|
|
bool BuiltInNSIsAvailable() const override { return false; }
|
|
|
|
|
int32_t EnableBuiltInNS(bool enable) override { return -1; }
|
2013-07-10 00:45:36 +00:00
|
|
|
// End of functions inherited from webrtc::AudioDeviceModule.
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
// The following function is inherited from rtc::MessageHandler.
|
2015-03-04 12:58:35 +00:00
|
|
|
void OnMessage(rtc::Message* msg) override;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// The constructor is protected because the class needs to be created as a
|
|
|
|
|
// reference counted object (for memory managment reasons). It could be
|
|
|
|
|
// exposed in which case the burden of proper instantiation would be put on
|
|
|
|
|
// the creator of a FakeAudioCaptureModule instance. To create an instance of
|
|
|
|
|
// this class use the Create(..) API.
|
2015-08-13 14:27:18 -07:00
|
|
|
explicit FakeAudioCaptureModule();
|
2013-07-10 00:45:36 +00:00
|
|
|
// The destructor is protected because it is reference counted and should not
|
|
|
|
|
// be deleted directly.
|
|
|
|
|
virtual ~FakeAudioCaptureModule();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Initializes the state of the FakeAudioCaptureModule. This API is called on
|
|
|
|
|
// creation by the Create() API.
|
|
|
|
|
bool Initialize();
|
|
|
|
|
// SetBuffer() sets all samples in send_buffer_ to |value|.
|
|
|
|
|
void SetSendBuffer(int value);
|
|
|
|
|
// Resets rec_buffer_. I.e., sets all rec_buffer_ samples to 0.
|
|
|
|
|
void ResetRecBuffer();
|
|
|
|
|
// Returns true if rec_buffer_ contains one or more sample greater than or
|
|
|
|
|
// equal to |value|.
|
|
|
|
|
bool CheckRecBuffer(int value);
|
|
|
|
|
|
2013-10-22 23:09:20 +00:00
|
|
|
// Returns true/false depending on if recording or playback has been
|
|
|
|
|
// enabled/started.
|
|
|
|
|
bool ShouldStartProcessing();
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2013-10-22 23:09:20 +00:00
|
|
|
// Starts or stops the pushing and pulling of audio frames.
|
|
|
|
|
void UpdateProcessing(bool start);
|
|
|
|
|
|
|
|
|
|
// Starts the periodic calling of ProcessFrame() in a thread safe way.
|
|
|
|
|
void StartProcessP();
|
2013-07-10 00:45:36 +00:00
|
|
|
// Periodcally called function that ensures that frames are pulled and pushed
|
|
|
|
|
// periodically if enabled/started.
|
|
|
|
|
void ProcessFrameP();
|
|
|
|
|
// Pulls frames from the registered webrtc::AudioTransport.
|
|
|
|
|
void ReceiveFrameP();
|
|
|
|
|
// Pushes frames to the registered webrtc::AudioTransport.
|
|
|
|
|
void SendFrameP();
|
|
|
|
|
|
|
|
|
|
// The time in milliseconds when Process() was last called or 0 if no call
|
|
|
|
|
// has been made.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t last_process_time_ms_;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Callback for playout and recording.
|
|
|
|
|
webrtc::AudioTransport* audio_callback_;
|
|
|
|
|
|
|
|
|
|
bool recording_; // True when audio is being pushed from the instance.
|
|
|
|
|
bool playing_; // True when audio is being pulled by the instance.
|
|
|
|
|
|
|
|
|
|
bool play_is_initialized_; // True when the instance is ready to pull audio.
|
|
|
|
|
bool rec_is_initialized_; // True when the instance is ready to push audio.
|
|
|
|
|
|
|
|
|
|
// Input to and output from RecordedDataIsAvailable(..) makes it possible to
|
|
|
|
|
// modify the current mic level. The implementation does not care about the
|
|
|
|
|
// mic level so it just feeds back what it receives.
|
|
|
|
|
uint32_t current_mic_level_;
|
|
|
|
|
|
|
|
|
|
// next_frame_time_ is updated in a non-drifting manner to indicate the next
|
|
|
|
|
// wall clock time the next frame should be generated and received. started_
|
|
|
|
|
// ensures that next_frame_time_ can be initialized properly on first call.
|
|
|
|
|
bool started_;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t next_frame_time_;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-04-27 06:47:29 -07:00
|
|
|
std::unique_ptr<rtc::Thread> process_thread_;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Buffer for storing samples received from the webrtc::AudioTransport.
|
|
|
|
|
char rec_buffer_[kNumberSamples * kNumberBytesPerSample];
|
|
|
|
|
// Buffer for samples to send to the webrtc::AudioTransport.
|
|
|
|
|
char send_buffer_[kNumberSamples * kNumberBytesPerSample];
|
|
|
|
|
|
|
|
|
|
// Counter of frames received that have samples of high enough amplitude to
|
|
|
|
|
// indicate that the frames are not faked somewhere in the audio pipeline
|
|
|
|
|
// (e.g. by a jitter buffer).
|
|
|
|
|
int frames_received_;
|
2013-10-22 23:09:20 +00:00
|
|
|
|
|
|
|
|
// Protects variables that are accessed from process_thread_ and
|
|
|
|
|
// the main thread.
|
2016-01-25 03:52:44 -08:00
|
|
|
rtc::CriticalSection crit_;
|
2013-10-22 23:09:20 +00:00
|
|
|
// Protects |audio_callback_| that is accessed from process_thread_ and
|
|
|
|
|
// the main thread.
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::CriticalSection crit_callback_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#endif // WEBRTC_API_TEST_FAKEAUDIOCAPTUREMODULE_H_
|