2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-03-30 09:53:54 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00: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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
|
|
|
|
|
#define WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
|
|
|
|
|
|
2016-08-17 07:31:12 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2013-05-02 00:30:36 +00:00
|
|
|
#include "webrtc/common_audio/resampler/include/push_resampler.h"
|
|
|
|
|
#include "webrtc/common_types.h"
|
2014-01-30 09:50:46 +00:00
|
|
|
#include "webrtc/modules/audio_processing/typing_detection.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/include/module_common_types.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/criticalsection.h"
|
2017-03-07 01:58:55 -08:00
|
|
|
#include "webrtc/voice_engine/audio_level.h"
|
2017-01-10 01:12:51 -08:00
|
|
|
#include "webrtc/voice_engine/file_player.h"
|
|
|
|
|
#include "webrtc/voice_engine/file_recorder.h"
|
2013-05-02 00:30:36 +00:00
|
|
|
#include "webrtc/voice_engine/include/voe_base.h"
|
|
|
|
|
#include "webrtc/voice_engine/monitor_module.h"
|
|
|
|
|
#include "webrtc/voice_engine/voice_engine_defines.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-12-05 02:22:12 -08:00
|
|
|
#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_IOS)
|
|
|
|
|
#define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 1
|
|
|
|
|
#else
|
|
|
|
|
#define WEBRTC_VOICE_ENGINE_TYPING_DETECTION 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
class AudioProcessing;
|
|
|
|
|
class ProcessThread;
|
|
|
|
|
|
|
|
|
|
namespace voe {
|
|
|
|
|
|
|
|
|
|
class ChannelManager;
|
|
|
|
|
class MixedAudio;
|
|
|
|
|
class Statistics;
|
|
|
|
|
|
2017-02-28 01:16:48 -08:00
|
|
|
class TransmitMixer : public FileCallback {
|
2011-07-07 08:21:25 +00:00
|
|
|
public:
|
2013-05-14 08:31:39 +00:00
|
|
|
static int32_t Create(TransmitMixer*& mixer, uint32_t instanceId);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
static void Destroy(TransmitMixer*& mixer);
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t SetEngineInformation(ProcessThread& processThread,
|
|
|
|
|
Statistics& engineStatistics,
|
|
|
|
|
ChannelManager& channelManager);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t SetAudioProcessingModule(
|
2011-07-07 08:21:25 +00:00
|
|
|
AudioProcessing* audioProcessingModule);
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t PrepareDemux(const void* audioSamples,
|
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
|
|
|
size_t nSamples,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t nChannels,
|
2013-05-14 08:31:39 +00:00
|
|
|
uint32_t samplesPerSec,
|
|
|
|
|
uint16_t totalDelayMS,
|
|
|
|
|
int32_t clockDrift,
|
|
|
|
|
uint16_t currentMicLevel,
|
|
|
|
|
bool keyPressed);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-03-31 05:43:36 -07:00
|
|
|
void ProcessAndEncodeAudio();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-01-11 01:25:53 +00:00
|
|
|
// Must be called on the same thread as PrepareDemux().
|
2013-04-09 10:09:10 +00:00
|
|
|
uint32_t CaptureLevel() const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t StopSend();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-03-08 01:52:20 -08:00
|
|
|
// TODO(solenberg): Remove, once AudioMonitor is gone.
|
2013-04-09 10:09:10 +00:00
|
|
|
int8_t AudioLevel() const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-03-01 17:02:23 -08:00
|
|
|
// 'virtual' to allow mocking.
|
|
|
|
|
virtual int16_t AudioLevelFullRange() const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-07-14 12:17:49 -07:00
|
|
|
// See description of "totalAudioEnergy" in the WebRTC stats spec:
|
|
|
|
|
// https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy
|
|
|
|
|
// 'virtual' to allow mocking.
|
|
|
|
|
virtual double GetTotalInputEnergy() const;
|
|
|
|
|
|
|
|
|
|
// 'virtual' to allow mocking.
|
|
|
|
|
virtual double GetTotalInputDuration() const;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
bool IsRecordingCall();
|
|
|
|
|
|
|
|
|
|
bool IsRecordingMic();
|
|
|
|
|
|
|
|
|
|
int StartPlayingFileAsMicrophone(const char* fileName,
|
2013-05-14 08:31:39 +00:00
|
|
|
bool loop,
|
|
|
|
|
FileFormats format,
|
|
|
|
|
int startPosition,
|
|
|
|
|
float volumeScaling,
|
|
|
|
|
int stopPosition,
|
2011-07-07 08:21:25 +00:00
|
|
|
const CodecInst* codecInst);
|
|
|
|
|
|
|
|
|
|
int StartPlayingFileAsMicrophone(InStream* stream,
|
2013-05-14 08:31:39 +00:00
|
|
|
FileFormats format,
|
|
|
|
|
int startPosition,
|
|
|
|
|
float volumeScaling,
|
|
|
|
|
int stopPosition,
|
2011-07-07 08:21:25 +00:00
|
|
|
const CodecInst* codecInst);
|
|
|
|
|
|
|
|
|
|
int StopPlayingFileAsMicrophone();
|
|
|
|
|
|
|
|
|
|
int IsPlayingFileAsMicrophone() const;
|
|
|
|
|
|
|
|
|
|
int StartRecordingMicrophone(const char* fileName,
|
|
|
|
|
const CodecInst* codecInst);
|
|
|
|
|
|
|
|
|
|
int StartRecordingMicrophone(OutStream* stream,
|
|
|
|
|
const CodecInst* codecInst);
|
|
|
|
|
|
|
|
|
|
int StopRecordingMicrophone();
|
|
|
|
|
|
|
|
|
|
int StartRecordingCall(const char* fileName, const CodecInst* codecInst);
|
|
|
|
|
|
|
|
|
|
int StartRecordingCall(OutStream* stream, const CodecInst* codecInst);
|
|
|
|
|
|
|
|
|
|
int StopRecordingCall();
|
|
|
|
|
|
|
|
|
|
void SetMixWithMicStatus(bool mix);
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
virtual ~TransmitMixer();
|
|
|
|
|
|
2017-02-28 08:25:11 -08:00
|
|
|
#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
|
2017-02-28 01:16:48 -08:00
|
|
|
// Periodic callback from the MonitorModule.
|
2011-07-07 08:21:25 +00:00
|
|
|
void OnPeriodicProcess();
|
2017-02-28 08:25:11 -08:00
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-04-24 19:47:00 +00:00
|
|
|
// FileCallback
|
2017-02-21 00:54:31 -08:00
|
|
|
void PlayNotification(const int32_t id,
|
|
|
|
|
const uint32_t durationMs);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-02-21 00:54:31 -08:00
|
|
|
void RecordNotification(const int32_t id,
|
|
|
|
|
const uint32_t durationMs);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-02-21 00:54:31 -08:00
|
|
|
void PlayFileEnded(const int32_t id);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-02-21 00:54:31 -08:00
|
|
|
void RecordFileEnded(const int32_t id);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-02-21 00:54:31 -08:00
|
|
|
// Virtual to allow mocking.
|
|
|
|
|
virtual void EnableStereoChannelSwapping(bool enable);
|
2012-04-24 19:47:00 +00:00
|
|
|
bool IsStereoChannelSwappingEnabled();
|
|
|
|
|
|
2017-02-21 00:54:31 -08:00
|
|
|
protected:
|
2017-02-28 08:25:11 -08:00
|
|
|
#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
|
2017-02-28 01:16:48 -08:00
|
|
|
TransmitMixer() : _monitorModule(this) {}
|
2017-02-28 08:25:11 -08:00
|
|
|
#else
|
|
|
|
|
TransmitMixer() = default;
|
|
|
|
|
#endif
|
2017-02-21 00:54:31 -08:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
private:
|
2013-05-14 08:31:39 +00:00
|
|
|
TransmitMixer(uint32_t instanceId);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-03-02 00:14:46 +00:00
|
|
|
// Gets the maximum sample rate and number of channels over all currently
|
|
|
|
|
// sending codecs.
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels);
|
2012-06-27 03:25:31 +00:00
|
|
|
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
void GenerateAudioFrame(const int16_t audioSamples[],
|
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
|
|
|
size_t nSamples,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t nChannels,
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
int samplesPerSec);
|
2013-05-14 08:31:39 +00:00
|
|
|
int32_t RecordAudioToFile(uint32_t mixingFrequency);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t MixOrReplaceAudioWithFile(
|
2013-05-14 08:31:39 +00:00
|
|
|
int mixingFrequency);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-02-11 20:52:30 +00:00
|
|
|
void ProcessAudio(int delay_ms, int clock_drift, int current_mic_level,
|
|
|
|
|
bool key_pressed);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-12-05 02:22:12 -08:00
|
|
|
#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
|
2014-01-30 09:50:46 +00:00
|
|
|
void TypingDetection(bool keyPressed);
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-04-24 19:47:00 +00:00
|
|
|
// uses
|
2017-02-21 00:54:31 -08:00
|
|
|
Statistics* _engineStatisticsPtr = nullptr;
|
|
|
|
|
ChannelManager* _channelManagerPtr = nullptr;
|
|
|
|
|
AudioProcessing* audioproc_ = nullptr;
|
|
|
|
|
VoiceEngineObserver* _voiceEngineObserverPtr = nullptr;
|
|
|
|
|
ProcessThread* _processThreadPtr = nullptr;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-04-24 19:47:00 +00:00
|
|
|
// owns
|
2011-07-07 08:21:25 +00:00
|
|
|
AudioFrame _audioFrame;
|
2014-04-19 00:32:07 +00:00
|
|
|
PushResampler<int16_t> resampler_; // ADM sample rate -> mixing rate
|
2016-08-17 07:31:12 -07:00
|
|
|
std::unique_ptr<FilePlayer> file_player_;
|
|
|
|
|
std::unique_ptr<FileRecorder> file_recorder_;
|
|
|
|
|
std::unique_ptr<FileRecorder> file_call_recorder_;
|
2017-02-21 00:54:31 -08:00
|
|
|
int _filePlayerId = 0;
|
|
|
|
|
int _fileRecorderId = 0;
|
|
|
|
|
int _fileCallRecorderId = 0;
|
|
|
|
|
bool _filePlaying = false;
|
|
|
|
|
bool _fileRecording = false;
|
|
|
|
|
bool _fileCallRecording = false;
|
2011-07-07 08:21:25 +00:00
|
|
|
voe::AudioLevel _audioLevel;
|
|
|
|
|
// protect file instances and their variables in MixedParticipants()
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CriticalSection _critSect;
|
|
|
|
|
rtc::CriticalSection _callbackCritSect;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-12-05 02:22:12 -08:00
|
|
|
#if WEBRTC_VOICE_ENGINE_TYPING_DETECTION
|
2017-02-28 08:25:11 -08:00
|
|
|
MonitorModule<TransmitMixer> _monitorModule;
|
2014-01-30 09:50:46 +00:00
|
|
|
webrtc::TypingDetection _typingDetection;
|
2017-02-21 00:54:31 -08:00
|
|
|
bool _typingNoiseWarningPending = false;
|
|
|
|
|
bool _typingNoiseDetected = false;
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
2017-02-21 00:54:31 -08:00
|
|
|
|
|
|
|
|
int _instanceId = 0;
|
|
|
|
|
bool _mixFileWithMicrophone = false;
|
|
|
|
|
uint32_t _captureLevel = 0;
|
|
|
|
|
bool stereo_codec_ = false;
|
|
|
|
|
bool swap_stereo_channels_ = false;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace voe
|
2011-07-07 08:21:25 +00:00
|
|
|
} // namespace webrtc
|
2013-12-24 03:39:10 +00:00
|
|
|
|
2013-12-24 03:58:51 +00:00
|
|
|
#endif // WEBRTC_VOICE_ENGINE_TRANSMIT_MIXER_H
|