Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: webrtc/voice_engine/channel.h

Issue 2665693002: Moves channel-dependent audio input processing to separate encoder task queue (Closed)
Patch Set: nit Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_H_ 11 #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_H_
12 #define WEBRTC_VOICE_ENGINE_CHANNEL_H_ 12 #define WEBRTC_VOICE_ENGINE_CHANNEL_H_
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include "webrtc/api/audio/audio_mixer.h" 16 #include "webrtc/api/audio/audio_mixer.h"
17 #include "webrtc/api/call/audio_sink.h" 17 #include "webrtc/api/call/audio_sink.h"
18 #include "webrtc/base/criticalsection.h" 18 #include "webrtc/base/criticalsection.h"
19 #include "webrtc/base/event.h"
19 #include "webrtc/base/optional.h" 20 #include "webrtc/base/optional.h"
20 #include "webrtc/base/thread_checker.h" 21 #include "webrtc/base/thread_checker.h"
21 #include "webrtc/common_audio/resampler/include/push_resampler.h" 22 #include "webrtc/common_audio/resampler/include/push_resampler.h"
22 #include "webrtc/common_types.h" 23 #include "webrtc/common_types.h"
23 #include "webrtc/modules/audio_coding/acm2/codec_manager.h" 24 #include "webrtc/modules/audio_coding/acm2/codec_manager.h"
24 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" 25 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
25 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" 26 #include "webrtc/modules/audio_coding/include/audio_coding_module.h"
26 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_d efines.h" 27 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_d efines.h"
27 #include "webrtc/modules/audio_processing/rms_level.h" 28 #include "webrtc/modules/audio_processing/rms_level.h"
28 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h" 29 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Example: a member can be set on thread T1 and read by an internal audio 80 // Example: a member can be set on thread T1 and read by an internal audio
80 // thread T2. Accessing the member via this class ensures that we are 81 // thread T2. Accessing the member via this class ensures that we are
81 // safe and also avoid TSan v2 warnings. 82 // safe and also avoid TSan v2 warnings.
82 class ChannelState { 83 class ChannelState {
83 public: 84 public:
84 struct State { 85 struct State {
85 bool output_file_playing = false; 86 bool output_file_playing = false;
86 bool input_file_playing = false; 87 bool input_file_playing = false;
87 bool playing = false; 88 bool playing = false;
88 bool sending = false; 89 bool sending = false;
90 bool sending_has_been_activated = false;
89 }; 91 };
90 92
91 ChannelState() {} 93 ChannelState() {}
92 virtual ~ChannelState() {} 94 virtual ~ChannelState() {}
93 95
94 void Reset() { 96 void Reset() {
95 rtc::CritScope lock(&lock_); 97 rtc::CritScope lock(&lock_);
96 state_ = State(); 98 state_ = State();
97 } 99 }
98 100
(...skipping 13 matching lines...) Expand all
112 } 114 }
113 115
114 void SetPlaying(bool enable) { 116 void SetPlaying(bool enable) {
115 rtc::CritScope lock(&lock_); 117 rtc::CritScope lock(&lock_);
116 state_.playing = enable; 118 state_.playing = enable;
117 } 119 }
118 120
119 void SetSending(bool enable) { 121 void SetSending(bool enable) {
120 rtc::CritScope lock(&lock_); 122 rtc::CritScope lock(&lock_);
121 state_.sending = enable; 123 state_.sending = enable;
124 state_.sending_has_been_activated = enable;
122 } 125 }
123 126
124 private: 127 private:
125 rtc::CriticalSection lock_; 128 rtc::CriticalSection lock_;
126 State state_; 129 State state_;
127 }; 130 };
128 131
129 class Channel 132 class Channel
130 : public RtpData, 133 : public RtpData,
131 public RtpFeedback, 134 public RtpFeedback,
(...skipping 19 matching lines...) Expand all
151 uint32_t instanceId, 154 uint32_t instanceId,
152 const VoEBase::ChannelConfig& config); 155 const VoEBase::ChannelConfig& config);
153 int32_t Init(); 156 int32_t Init();
154 void RegisterLegacyCodecs(); 157 void RegisterLegacyCodecs();
155 void Terminate(); 158 void Terminate();
156 int32_t SetEngineInformation(Statistics& engineStatistics, 159 int32_t SetEngineInformation(Statistics& engineStatistics,
157 OutputMixer& outputMixer, 160 OutputMixer& outputMixer,
158 ProcessThread& moduleProcessThread, 161 ProcessThread& moduleProcessThread,
159 AudioDeviceModule& audioDeviceModule, 162 AudioDeviceModule& audioDeviceModule,
160 VoiceEngineObserver* voiceEngineObserver, 163 VoiceEngineObserver* voiceEngineObserver,
161 rtc::CriticalSection* callbackCritSect); 164 rtc::CriticalSection* callbackCritSect,
162 int32_t UpdateLocalTimeStamp(); 165 rtc::TaskQueue* encoder_queue);
163 166
164 void SetSink(std::unique_ptr<AudioSinkInterface> sink); 167 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
165 168
166 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory 169 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
167 // passed into AudioReceiveStream is the same as the one set when creating the 170 // passed into AudioReceiveStream is the same as the one set when creating the
168 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can 171 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
169 // go. 172 // go.
170 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const; 173 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
171 174
172 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs); 175 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 uint32_t InstanceId() const { return _instanceId; } 351 uint32_t InstanceId() const { return _instanceId; }
349 int32_t ChannelId() const { return _channelId; } 352 int32_t ChannelId() const { return _channelId; }
350 bool Playing() const { return channel_state_.Get().playing; } 353 bool Playing() const { return channel_state_.Get().playing; }
351 bool Sending() const { return channel_state_.Get().sending; } 354 bool Sending() const { return channel_state_.Get().sending; }
352 bool ExternalTransport() const { 355 bool ExternalTransport() const {
353 rtc::CritScope cs(&_callbackCritSect); 356 rtc::CritScope cs(&_callbackCritSect);
354 return _externalTransport; 357 return _externalTransport;
355 } 358 }
356 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); } 359 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
357 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); } 360 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
358 uint32_t Demultiplex(const AudioFrame& audioFrame); 361 PushResampler<int16_t>* input_resampler() { return &input_resampler_; }
359 // Demultiplex the data to the channel's |_audioFrame|. The difference 362
360 // between this method and the overloaded method above is that |audio_data| 363 // ProcessAndEncodeAudio() creates an audio frame copy and posts a task
361 // does not go through transmit_mixer and APM. 364 // on the shared encoder task queue, wich in turn calls (on the queue)
362 void Demultiplex(const int16_t* audio_data, 365 // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the
363 int sample_rate, 366 // audio takes place. The processing mainly consists of encoding and preparing
364 size_t number_of_frames, 367 // the result for sending by adding it to a send queue.
365 size_t number_of_channels); 368 // The main reason for using a task queue here is to release the native,
366 uint32_t PrepareEncodeAndSend(int mixingFrequency); 369 // OS-specific, audio capture thread as soon as possible to ensure that it
367 uint32_t EncodeAndSend(); 370 // can go back to sleep and be prepared to deliver an new captured audio
371 // packet.
372 void ProcessAndEncodeAudio(const AudioFrame& audio_input);
373
374 // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in
375 // VoEBase and the audio in |audio_data| has not been subject to any APM
376 // processing. Some extra steps are therfore needed when building up the
377 // audio frame copy before using the same task as in the default call to
378 // ProcessAndEncodeAudio(const AudioFrame& audio_input).
379 void ProcessAndEncodeAudio(const int16_t* audio_data,
380 int sample_rate,
381 size_t number_of_frames,
382 size_t number_of_channels);
383
384 // Called on the encoder task queue when a new input audio frame is ready
385 // for encoding.
386 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
387
388 // Internal helper methods used by ProcessAndEncodeAudioOnTaskQueue().
389 // Both are called on the encoder task queue.
390 uint32_t PrepareEncodeAndSend(AudioFrame* audio_input);
391 uint32_t EncodeAndSend(AudioFrame* audio_input);
368 392
369 // Associate to a send channel. 393 // Associate to a send channel.
370 // Used for obtaining RTT for a receive-only channel. 394 // Used for obtaining RTT for a receive-only channel.
371 void set_associate_send_channel(const ChannelOwner& channel); 395 void set_associate_send_channel(const ChannelOwner& channel);
372 // Disassociate a send channel if it was associated. 396 // Disassociate a send channel if it was associated.
373 void DisassociateSendChannel(int channel_id); 397 void DisassociateSendChannel(int channel_id);
374 398
375 // Set a RtcEventLog logging object. 399 // Set a RtcEventLog logging object.
376 void SetRtcEventLog(RtcEventLog* event_log); 400 void SetRtcEventLog(RtcEventLog* event_log);
377 401
378 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats); 402 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
379 void SetTransportOverhead(size_t transport_overhead_per_packet); 403 void SetTransportOverhead(size_t transport_overhead_per_packet);
380 404
381 // From OverheadObserver in the RTP/RTCP module 405 // From OverheadObserver in the RTP/RTCP module
382 void OnOverheadChanged(size_t overhead_bytes_per_packet) override; 406 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
383 407
384 // The existence of this function alongside OnUplinkPacketLossRate is 408 // The existence of this function alongside OnUplinkPacketLossRate is
385 // a compromise. We want the encoder to be agnostic of the PLR source, but 409 // a compromise. We want the encoder to be agnostic of the PLR source, but
386 // we also don't want it to receive conflicting information from TWCC and 410 // we also don't want it to receive conflicting information from TWCC and
387 // from RTCP-XR. 411 // from RTCP-XR.
388 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate); 412 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate);
389 413
390 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate); 414 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate);
391 415
392 private: 416 private:
417 class ProcessAndEncodeAudioTask;
aleloi 2017/03/24 16:59:50 This declaration is only letting the task DCHECK t
henrika_webrtc 2017/03/24 17:09:36 Sorry but I don't understand. What do you suggest
418
393 void OnUplinkPacketLossRate(float packet_loss_rate); 419 void OnUplinkPacketLossRate(float packet_loss_rate);
394
395 bool InputMute() const; 420 bool InputMute() const;
396 bool OnRtpPacketWithHeader(const uint8_t* received_packet, 421 bool OnRtpPacketWithHeader(const uint8_t* received_packet,
397 size_t length, 422 size_t length,
398 RTPHeader *header); 423 RTPHeader *header);
399 bool ReceivePacket(const uint8_t* packet, 424 bool ReceivePacket(const uint8_t* packet,
400 size_t packet_length, 425 size_t packet_length,
401 const RTPHeader& header, 426 const RTPHeader& header,
402 bool in_order); 427 bool in_order);
403 bool HandleRtxPacket(const uint8_t* packet, 428 bool HandleRtxPacket(const uint8_t* packet,
404 size_t packet_length, 429 size_t packet_length,
405 const RTPHeader& header); 430 const RTPHeader& header);
406 bool IsPacketInOrder(const RTPHeader& header) const; 431 bool IsPacketInOrder(const RTPHeader& header) const;
407 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; 432 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
408 int ResendPackets(const uint16_t* sequence_numbers, int length); 433 int ResendPackets(const uint16_t* sequence_numbers, int length);
409 int32_t MixOrReplaceAudioWithFile(int mixingFrequency); 434 int32_t MixOrReplaceAudioWithFile(AudioFrame* audio_frame);
410 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency); 435 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
411 void UpdatePlayoutTimestamp(bool rtcp); 436 void UpdatePlayoutTimestamp(bool rtcp);
412 void RegisterReceiveCodecsToRTPModule(); 437 void RegisterReceiveCodecsToRTPModule();
413 438
414 int SetSendRtpHeaderExtension(bool enable, 439 int SetSendRtpHeaderExtension(bool enable,
415 RTPExtensionType type, 440 RTPExtensionType type,
416 unsigned char id); 441 unsigned char id);
417 442
418 void UpdateOverheadForEncoder() 443 void UpdateOverheadForEncoder()
419 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_); 444 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
(...skipping 17 matching lines...) Expand all
437 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; 462 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
438 std::unique_ptr<RtpReceiver> rtp_receiver_; 463 std::unique_ptr<RtpReceiver> rtp_receiver_;
439 TelephoneEventHandler* telephone_event_handler_; 464 TelephoneEventHandler* telephone_event_handler_;
440 std::unique_ptr<RtpRtcp> _rtpRtcpModule; 465 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
441 std::unique_ptr<AudioCodingModule> audio_coding_; 466 std::unique_ptr<AudioCodingModule> audio_coding_;
442 acm2::CodecManager codec_manager_; 467 acm2::CodecManager codec_manager_;
443 acm2::RentACodec rent_a_codec_; 468 acm2::RentACodec rent_a_codec_;
444 std::unique_ptr<AudioSinkInterface> audio_sink_; 469 std::unique_ptr<AudioSinkInterface> audio_sink_;
445 AudioLevel _outputAudioLevel; 470 AudioLevel _outputAudioLevel;
446 bool _externalTransport; 471 bool _externalTransport;
447 AudioFrame _audioFrame;
448 // Downsamples to the codec rate if necessary. 472 // Downsamples to the codec rate if necessary.
449 PushResampler<int16_t> input_resampler_; 473 PushResampler<int16_t> input_resampler_;
450 std::unique_ptr<FilePlayer> input_file_player_; 474 std::unique_ptr<FilePlayer> input_file_player_;
451 std::unique_ptr<FilePlayer> output_file_player_; 475 std::unique_ptr<FilePlayer> output_file_player_;
452 std::unique_ptr<FileRecorder> output_file_recorder_; 476 std::unique_ptr<FileRecorder> output_file_recorder_;
453 int _inputFilePlayerId; 477 int _inputFilePlayerId;
454 int _outputFilePlayerId; 478 int _outputFilePlayerId;
455 int _outputFileRecorderId; 479 int _outputFileRecorderId;
456 bool _outputFileRecording; 480 bool _outputFileRecording;
457 uint32_t _timeStamp; 481 uint32_t _timeStamp;
(...skipping 18 matching lines...) Expand all
476 // frame. 500 // frame.
477 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_); 501 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
478 502
479 // uses 503 // uses
480 Statistics* _engineStatisticsPtr; 504 Statistics* _engineStatisticsPtr;
481 OutputMixer* _outputMixerPtr; 505 OutputMixer* _outputMixerPtr;
482 ProcessThread* _moduleProcessThreadPtr; 506 ProcessThread* _moduleProcessThreadPtr;
483 AudioDeviceModule* _audioDeviceModulePtr; 507 AudioDeviceModule* _audioDeviceModulePtr;
484 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base 508 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
485 rtc::CriticalSection* _callbackCritSectPtr; // owned by base 509 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
510 rtc::TaskQueue* encoder_queue_;
486 Transport* _transportPtr; // WebRtc socket or external transport 511 Transport* _transportPtr; // WebRtc socket or external transport
487 RmsLevel rms_level_; 512 RmsLevel rms_level_;
488 bool input_mute_ GUARDED_BY(volume_settings_critsect_); 513 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
489 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend(). 514 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
490 float _outputGain GUARDED_BY(volume_settings_critsect_); 515 float _outputGain GUARDED_BY(volume_settings_critsect_);
491 // VoEBase 516 // VoEBase
492 bool _mixFileWithMicrophone; 517 bool _mixFileWithMicrophone;
493 // VoeRTP_RTCP 518 // VoeRTP_RTCP
494 uint32_t _lastLocalTimeStamp; 519 uint32_t _lastLocalTimeStamp;
495 int8_t _lastPayloadType; 520 int8_t _lastPayloadType;
(...skipping 17 matching lines...) Expand all
513 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_; 538 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
514 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_; 539 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
515 std::unique_ptr<RateLimiter> retransmission_rate_limiter_; 540 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
516 541
517 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed. 542 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
518 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; 543 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
519 544
520 rtc::ThreadChecker construction_thread_; 545 rtc::ThreadChecker construction_thread_;
521 546
522 const bool use_twcc_plr_for_ana_; 547 const bool use_twcc_plr_for_ana_;
548
549 rtc::Event stop_send_event_;
523 }; 550 };
524 551
525 } // namespace voe 552 } // namespace voe
526 } // namespace webrtc 553 } // namespace webrtc
527 554
528 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_ 555 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698