| Index: webrtc/voice_engine/channel.h
|
| diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h
|
| index 24a7d6bfa0dc91457758d1f1aaeb0dc464ac7521..1d2b089a16eca8f62f73c1a813713b787ef96030 100644
|
| --- a/webrtc/voice_engine/channel.h
|
| +++ b/webrtc/voice_engine/channel.h
|
| @@ -16,6 +16,7 @@
|
| #include "webrtc/api/audio/audio_mixer.h"
|
| #include "webrtc/api/call/audio_sink.h"
|
| #include "webrtc/base/criticalsection.h"
|
| +#include "webrtc/base/event.h"
|
| #include "webrtc/base/optional.h"
|
| #include "webrtc/base/thread_checker.h"
|
| #include "webrtc/common_audio/resampler/include/push_resampler.h"
|
| @@ -143,11 +144,10 @@ class Channel
|
| enum { KNumSocketThreads = 1 };
|
| enum { KNumberOfSocketBuffers = 8 };
|
| virtual ~Channel();
|
| - static int32_t CreateChannel(
|
| - Channel*& channel,
|
| - int32_t channelId,
|
| - uint32_t instanceId,
|
| - const VoEBase::ChannelConfig& config);
|
| + static int32_t CreateChannel(Channel*& channel,
|
| + int32_t channelId,
|
| + uint32_t instanceId,
|
| + const VoEBase::ChannelConfig& config);
|
| Channel(int32_t channelId,
|
| uint32_t instanceId,
|
| const VoEBase::ChannelConfig& config);
|
| @@ -159,8 +159,8 @@ class Channel
|
| ProcessThread& moduleProcessThread,
|
| AudioDeviceModule& audioDeviceModule,
|
| VoiceEngineObserver* voiceEngineObserver,
|
| - rtc::CriticalSection* callbackCritSect);
|
| - int32_t UpdateLocalTimeStamp();
|
| + rtc::CriticalSection* callbackCritSect,
|
| + rtc::TaskQueue* encoder_queue);
|
|
|
| void SetSink(std::unique_ptr<AudioSinkInterface> sink);
|
|
|
| @@ -178,7 +178,7 @@ class Channel
|
| int32_t StartPlayout();
|
| int32_t StopPlayout();
|
| int32_t StartSend();
|
| - int32_t StopSend();
|
| + void StopSend();
|
| int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer);
|
| int32_t DeRegisterVoiceEngineObserver();
|
|
|
| @@ -354,16 +354,27 @@ class Channel
|
| }
|
| RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
|
| int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
|
| - uint32_t Demultiplex(const AudioFrame& audioFrame);
|
| - // Demultiplex the data to the channel's |_audioFrame|. The difference
|
| - // between this method and the overloaded method above is that |audio_data|
|
| - // does not go through transmit_mixer and APM.
|
| - void Demultiplex(const int16_t* audio_data,
|
| - int sample_rate,
|
| - size_t number_of_frames,
|
| - size_t number_of_channels);
|
| - uint32_t PrepareEncodeAndSend(int mixingFrequency);
|
| - uint32_t EncodeAndSend();
|
| +
|
| + // ProcessAndEncodeAudio() creates an audio frame copy and posts a task
|
| + // on the shared encoder task queue, wich in turn calls (on the queue)
|
| + // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the
|
| + // audio takes place. The processing mainly consists of encoding and preparing
|
| + // the result for sending by adding it to a send queue.
|
| + // The main reason for using a task queue here is to release the native,
|
| + // OS-specific, audio capture thread as soon as possible to ensure that it
|
| + // can go back to sleep and be prepared to deliver an new captured audio
|
| + // packet.
|
| + void ProcessAndEncodeAudio(const AudioFrame& audio_input);
|
| +
|
| + // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in
|
| + // VoEBase and the audio in |audio_data| has not been subject to any APM
|
| + // processing. Some extra steps are therfore needed when building up the
|
| + // audio frame copy before using the same task as in the default call to
|
| + // ProcessAndEncodeAudio(const AudioFrame& audio_input).
|
| + void ProcessAndEncodeAudio(const int16_t* audio_data,
|
| + int sample_rate,
|
| + size_t number_of_frames,
|
| + size_t number_of_channels);
|
|
|
| // Associate to a send channel.
|
| // Used for obtaining RTT for a receive-only channel.
|
| @@ -389,8 +400,9 @@ class Channel
|
| void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
|
|
|
| private:
|
| - void OnUplinkPacketLossRate(float packet_loss_rate);
|
| + class ProcessAndEncodeAudioTask;
|
|
|
| + void OnUplinkPacketLossRate(float packet_loss_rate);
|
| bool InputMute() const;
|
| bool OnRtpPacketWithHeader(const uint8_t* received_packet,
|
| size_t length,
|
| @@ -405,7 +417,7 @@ class Channel
|
| bool IsPacketInOrder(const RTPHeader& header) const;
|
| bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
|
| int ResendPackets(const uint16_t* sequence_numbers, int length);
|
| - int32_t MixOrReplaceAudioWithFile(int mixingFrequency);
|
| + int32_t MixOrReplaceAudioWithFile(AudioFrame* audio_frame);
|
| int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
|
| void UpdatePlayoutTimestamp(bool rtcp);
|
| void RegisterReceiveCodecsToRTPModule();
|
| @@ -420,11 +432,16 @@ class Channel
|
| int GetRtpTimestampRateHz() const;
|
| int64_t GetRTT(bool allow_associate_channel) const;
|
|
|
| + // Called on the encoder task queue when a new input audio frame is ready
|
| + // for encoding.
|
| + void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
|
| +
|
| + uint32_t _instanceId;
|
| + int32_t _channelId;
|
| +
|
| rtc::CriticalSection _fileCritSect;
|
| rtc::CriticalSection _callbackCritSect;
|
| rtc::CriticalSection volume_settings_critsect_;
|
| - uint32_t _instanceId;
|
| - int32_t _channelId;
|
|
|
| ChannelState channel_state_;
|
|
|
| @@ -443,7 +460,6 @@ class Channel
|
| std::unique_ptr<AudioSinkInterface> audio_sink_;
|
| AudioLevel _outputAudioLevel;
|
| bool _externalTransport;
|
| - AudioFrame _audioFrame;
|
| // Downsamples to the codec rate if necessary.
|
| PushResampler<int16_t> input_resampler_;
|
| std::unique_ptr<FilePlayer> input_file_player_;
|
| @@ -453,7 +469,7 @@ class Channel
|
| int _outputFilePlayerId;
|
| int _outputFileRecorderId;
|
| bool _outputFileRecording;
|
| - uint32_t _timeStamp;
|
| + uint32_t _timeStamp ACCESS_ON(encoder_queue_);
|
|
|
| RemoteNtpTimeEstimator ntp_estimator_ GUARDED_BY(ts_stats_lock_);
|
|
|
| @@ -483,15 +499,15 @@ class Channel
|
| VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
|
| rtc::CriticalSection* _callbackCritSectPtr; // owned by base
|
| Transport* _transportPtr; // WebRtc socket or external transport
|
| - RmsLevel rms_level_;
|
| + RmsLevel rms_level_ ACCESS_ON(encoder_queue_);
|
| bool input_mute_ GUARDED_BY(volume_settings_critsect_);
|
| - bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
|
| + bool previous_frame_muted_ ACCESS_ON(encoder_queue_);
|
| float _outputGain GUARDED_BY(volume_settings_critsect_);
|
| // VoEBase
|
| bool _mixFileWithMicrophone;
|
| // VoeRTP_RTCP
|
| - uint32_t _lastLocalTimeStamp;
|
| - int8_t _lastPayloadType;
|
| + // TODO(henrika): can today be accessed on the main thread and on the
|
| + // task queue; hence potential race.
|
| bool _includeAudioLevelIndication;
|
| size_t transport_overhead_per_packet_ GUARDED_BY(overhead_per_packet_lock_);
|
| size_t rtp_overhead_per_packet_ GUARDED_BY(overhead_per_packet_lock_);
|
| @@ -519,6 +535,8 @@ class Channel
|
| rtc::ThreadChecker construction_thread_;
|
|
|
| const bool use_twcc_plr_for_ana_;
|
| +
|
| + rtc::TaskQueue* encoder_queue_ = nullptr;
|
| };
|
|
|
| } // namespace voe
|
|
|