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

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: cleanup 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
(...skipping 10 matching lines...) Expand all
21 #include "webrtc/common_audio/resampler/include/push_resampler.h" 21 #include "webrtc/common_audio/resampler/include/push_resampler.h"
22 #include "webrtc/common_types.h" 22 #include "webrtc/common_types.h"
23 #include "webrtc/modules/audio_coding/acm2/codec_manager.h" 23 #include "webrtc/modules/audio_coding/acm2/codec_manager.h"
24 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" 24 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
25 #include "webrtc/modules/audio_coding/include/audio_coding_module.h" 25 #include "webrtc/modules/audio_coding/include/audio_coding_module.h"
26 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_d efines.h" 26 #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_d efines.h"
27 #include "webrtc/modules/audio_processing/rms_level.h" 27 #include "webrtc/modules/audio_processing/rms_level.h"
28 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h" 28 #include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
29 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" 29 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
30 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 30 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
31 #include "webrtc/voice_engine/audio_frame_pool.h"
31 #include "webrtc/voice_engine/audio_level.h" 32 #include "webrtc/voice_engine/audio_level.h"
32 #include "webrtc/voice_engine/file_player.h" 33 #include "webrtc/voice_engine/file_player.h"
33 #include "webrtc/voice_engine/file_recorder.h" 34 #include "webrtc/voice_engine/file_recorder.h"
34 #include "webrtc/voice_engine/include/voe_base.h" 35 #include "webrtc/voice_engine/include/voe_base.h"
35 #include "webrtc/voice_engine/include/voe_network.h" 36 #include "webrtc/voice_engine/include/voe_network.h"
36 #include "webrtc/voice_engine/shared_data.h" 37 #include "webrtc/voice_engine/shared_data.h"
37 #include "webrtc/voice_engine/voice_engine_defines.h" 38 #include "webrtc/voice_engine/voice_engine_defines.h"
38 39
39 namespace rtc { 40 namespace rtc {
40 class TimestampWrapAroundHandler; 41 class TimestampWrapAroundHandler;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 Channel(int32_t channelId, 151 Channel(int32_t channelId,
151 uint32_t instanceId, 152 uint32_t instanceId,
152 const VoEBase::ChannelConfig& config); 153 const VoEBase::ChannelConfig& config);
153 int32_t Init(); 154 int32_t Init();
154 void Terminate(); 155 void Terminate();
155 int32_t SetEngineInformation(Statistics& engineStatistics, 156 int32_t SetEngineInformation(Statistics& engineStatistics,
156 OutputMixer& outputMixer, 157 OutputMixer& outputMixer,
157 ProcessThread& moduleProcessThread, 158 ProcessThread& moduleProcessThread,
158 AudioDeviceModule& audioDeviceModule, 159 AudioDeviceModule& audioDeviceModule,
159 VoiceEngineObserver* voiceEngineObserver, 160 VoiceEngineObserver* voiceEngineObserver,
160 rtc::CriticalSection* callbackCritSect); 161 rtc::CriticalSection* callbackCritSect,
161 int32_t UpdateLocalTimeStamp(); 162 rtc::TaskQueue* encoder_queue);
162 163
163 void SetSink(std::unique_ptr<AudioSinkInterface> sink); 164 void SetSink(std::unique_ptr<AudioSinkInterface> sink);
164 165
165 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory 166 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory
166 // passed into AudioReceiveStream is the same as the one set when creating the 167 // passed into AudioReceiveStream is the same as the one set when creating the
167 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can 168 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can
168 // go. 169 // go.
169 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const; 170 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const;
170 171
171 // API methods 172 // API methods
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 uint32_t InstanceId() const { return _instanceId; } 346 uint32_t InstanceId() const { return _instanceId; }
346 int32_t ChannelId() const { return _channelId; } 347 int32_t ChannelId() const { return _channelId; }
347 bool Playing() const { return channel_state_.Get().playing; } 348 bool Playing() const { return channel_state_.Get().playing; }
348 bool Sending() const { return channel_state_.Get().sending; } 349 bool Sending() const { return channel_state_.Get().sending; }
349 bool ExternalTransport() const { 350 bool ExternalTransport() const {
350 rtc::CritScope cs(&_callbackCritSect); 351 rtc::CritScope cs(&_callbackCritSect);
351 return _externalTransport; 352 return _externalTransport;
352 } 353 }
353 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); } 354 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); }
354 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); } 355 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); }
355 uint32_t Demultiplex(const AudioFrame& audioFrame); 356
356 // Demultiplex the data to the channel's |_audioFrame|. The difference 357 // ProcessAndEncodeAudio() creates an audio frame copy and posts a task
357 // between this method and the overloaded method above is that |audio_data| 358 // on the shared encoder task queue, wich in turn calls (on the queue)
358 // does not go through transmit_mixer and APM. 359 // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the
359 void Demultiplex(const int16_t* audio_data, 360 // audio takes place. The processing mainly consists of encoding and preparing
360 int sample_rate, 361 // the result for sending by adding it to a send queue.
361 size_t number_of_frames, 362 // The main reason for using a task queue here is to release the native,
362 size_t number_of_channels); 363 // OS-specific, audio capture thread as soon as possible to ensure that it
363 uint32_t PrepareEncodeAndSend(int mixingFrequency); 364 // can go back to sleep and be prepared to deliver an new captured audio
364 uint32_t EncodeAndSend(); 365 // packet.
366 void ProcessAndEncodeAudio(const AudioFrame& audio_input);
367
368 // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in
369 // VoEBase and the audio in |audio_data| has not been subject to any APM
370 // processing. Some extra steps are therfore needed when building up the
371 // audio frame copy before using the same task as in the default call to
372 // ProcessAndEncodeAudio(const AudioFrame& audio_input).
373 void ProcessAndEncodeAudio(const int16_t* audio_data,
374 int sample_rate,
375 size_t number_of_frames,
376 size_t number_of_channels);
377
378 // Called on the encoder task queue when a new input audio frame is ready
379 // for encoding.
380 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input);
381
382 // Internal helper methods used by ProcessAndEncodeAudioOnTaskQueue().
383 // Both are called on the encoder task queue.
384 uint32_t PrepareEncodeAndSend(AudioFrame* audio_input);
385 uint32_t EncodeAndSend(AudioFrame* audio_input);
365 386
366 // Associate to a send channel. 387 // Associate to a send channel.
367 // Used for obtaining RTT for a receive-only channel. 388 // Used for obtaining RTT for a receive-only channel.
368 void set_associate_send_channel(const ChannelOwner& channel); 389 void set_associate_send_channel(const ChannelOwner& channel);
369 // Disassociate a send channel if it was associated. 390 // Disassociate a send channel if it was associated.
370 void DisassociateSendChannel(int channel_id); 391 void DisassociateSendChannel(int channel_id);
371 392
372 // Set a RtcEventLog logging object. 393 // Set a RtcEventLog logging object.
373 void SetRtcEventLog(RtcEventLog* event_log); 394 void SetRtcEventLog(RtcEventLog* event_log);
374 395
375 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats); 396 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats);
376 void SetTransportOverhead(size_t transport_overhead_per_packet); 397 void SetTransportOverhead(size_t transport_overhead_per_packet);
377 398
378 // From OverheadObserver in the RTP/RTCP module 399 // From OverheadObserver in the RTP/RTCP module
379 void OnOverheadChanged(size_t overhead_bytes_per_packet) override; 400 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
380 401
381 protected: 402 protected:
382 void OnIncomingFractionLoss(int fraction_lost); 403 void OnIncomingFractionLoss(int fraction_lost);
383 404
384 private: 405 private:
406 class ProcessAndEncodeAudioTask;
407
385 bool InputMute() const; 408 bool InputMute() const;
386 bool OnRtpPacketWithHeader(const uint8_t* received_packet, 409 bool OnRtpPacketWithHeader(const uint8_t* received_packet,
387 size_t length, 410 size_t length,
388 RTPHeader *header); 411 RTPHeader *header);
389 bool ReceivePacket(const uint8_t* packet, 412 bool ReceivePacket(const uint8_t* packet,
390 size_t packet_length, 413 size_t packet_length,
391 const RTPHeader& header, 414 const RTPHeader& header,
392 bool in_order); 415 bool in_order);
393 bool HandleRtxPacket(const uint8_t* packet, 416 bool HandleRtxPacket(const uint8_t* packet,
394 size_t packet_length, 417 size_t packet_length,
395 const RTPHeader& header); 418 const RTPHeader& header);
396 bool IsPacketInOrder(const RTPHeader& header) const; 419 bool IsPacketInOrder(const RTPHeader& header) const;
397 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; 420 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
398 int ResendPackets(const uint16_t* sequence_numbers, int length); 421 int ResendPackets(const uint16_t* sequence_numbers, int length);
399 int32_t MixOrReplaceAudioWithFile(int mixingFrequency); 422 int32_t MixOrReplaceAudioWithFile(AudioFrame* audio_frame);
400 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency); 423 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency);
401 void UpdatePlayoutTimestamp(bool rtcp); 424 void UpdatePlayoutTimestamp(bool rtcp);
402 void RegisterReceiveCodecsToRTPModule(); 425 void RegisterReceiveCodecsToRTPModule();
403 426
404 int SetSendRtpHeaderExtension(bool enable, 427 int SetSendRtpHeaderExtension(bool enable,
405 RTPExtensionType type, 428 RTPExtensionType type,
406 unsigned char id); 429 unsigned char id);
407 430
408 void UpdateOverheadForEncoder() 431 void UpdateOverheadForEncoder()
409 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_); 432 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_);
(...skipping 17 matching lines...) Expand all
427 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; 450 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
428 std::unique_ptr<RtpReceiver> rtp_receiver_; 451 std::unique_ptr<RtpReceiver> rtp_receiver_;
429 TelephoneEventHandler* telephone_event_handler_; 452 TelephoneEventHandler* telephone_event_handler_;
430 std::unique_ptr<RtpRtcp> _rtpRtcpModule; 453 std::unique_ptr<RtpRtcp> _rtpRtcpModule;
431 std::unique_ptr<AudioCodingModule> audio_coding_; 454 std::unique_ptr<AudioCodingModule> audio_coding_;
432 acm2::CodecManager codec_manager_; 455 acm2::CodecManager codec_manager_;
433 acm2::RentACodec rent_a_codec_; 456 acm2::RentACodec rent_a_codec_;
434 std::unique_ptr<AudioSinkInterface> audio_sink_; 457 std::unique_ptr<AudioSinkInterface> audio_sink_;
435 AudioLevel _outputAudioLevel; 458 AudioLevel _outputAudioLevel;
436 bool _externalTransport; 459 bool _externalTransport;
437 AudioFrame _audioFrame;
438 // Downsamples to the codec rate if necessary. 460 // Downsamples to the codec rate if necessary.
439 PushResampler<int16_t> input_resampler_; 461 PushResampler<int16_t> input_resampler_;
440 std::unique_ptr<FilePlayer> input_file_player_; 462 std::unique_ptr<FilePlayer> input_file_player_;
441 std::unique_ptr<FilePlayer> output_file_player_; 463 std::unique_ptr<FilePlayer> output_file_player_;
442 std::unique_ptr<FileRecorder> output_file_recorder_; 464 std::unique_ptr<FileRecorder> output_file_recorder_;
443 int _inputFilePlayerId; 465 int _inputFilePlayerId;
444 int _outputFilePlayerId; 466 int _outputFilePlayerId;
445 int _outputFileRecorderId; 467 int _outputFileRecorderId;
446 bool _outputFileRecording; 468 bool _outputFileRecording;
447 uint32_t _timeStamp; 469 uint32_t _timeStamp;
(...skipping 18 matching lines...) Expand all
466 // frame. 488 // frame.
467 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_); 489 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_);
468 490
469 // uses 491 // uses
470 Statistics* _engineStatisticsPtr; 492 Statistics* _engineStatisticsPtr;
471 OutputMixer* _outputMixerPtr; 493 OutputMixer* _outputMixerPtr;
472 ProcessThread* _moduleProcessThreadPtr; 494 ProcessThread* _moduleProcessThreadPtr;
473 AudioDeviceModule* _audioDeviceModulePtr; 495 AudioDeviceModule* _audioDeviceModulePtr;
474 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base 496 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base
475 rtc::CriticalSection* _callbackCritSectPtr; // owned by base 497 rtc::CriticalSection* _callbackCritSectPtr; // owned by base
498 rtc::TaskQueue* encoder_queue_;
476 Transport* _transportPtr; // WebRtc socket or external transport 499 Transport* _transportPtr; // WebRtc socket or external transport
477 RmsLevel rms_level_; 500 RmsLevel rms_level_;
478 bool input_mute_ GUARDED_BY(volume_settings_critsect_); 501 bool input_mute_ GUARDED_BY(volume_settings_critsect_);
479 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend(). 502 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend().
480 float _outputGain GUARDED_BY(volume_settings_critsect_); 503 float _outputGain GUARDED_BY(volume_settings_critsect_);
481 // VoEBase 504 // VoEBase
482 bool _mixFileWithMicrophone; 505 bool _mixFileWithMicrophone;
483 // VoeRTP_RTCP 506 // VoeRTP_RTCP
484 uint32_t _lastLocalTimeStamp; 507 uint32_t _lastLocalTimeStamp;
485 int8_t _lastPayloadType; 508 int8_t _lastPayloadType;
(...skipping 11 matching lines...) Expand all
497 rtc::CriticalSection assoc_send_channel_lock_; 520 rtc::CriticalSection assoc_send_channel_lock_;
498 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_); 521 ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_);
499 522
500 bool pacing_enabled_; 523 bool pacing_enabled_;
501 PacketRouter* packet_router_ = nullptr; 524 PacketRouter* packet_router_ = nullptr;
502 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_; 525 std::unique_ptr<TransportFeedbackProxy> feedback_observer_proxy_;
503 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_; 526 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_;
504 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_; 527 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_;
505 std::unique_ptr<RateLimiter> retransmission_rate_limiter_; 528 std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
506 529
530 // Pool of preallocated audio frames for temporary storage of recorded audio
531 // to be encoded on the encoder queue.
532 AudioFramePool audio_frame_pool_;
533
507 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed. 534 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
508 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; 535 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
509 536
510 rtc::ThreadChecker construction_thread_; 537 rtc::ThreadChecker construction_thread_;
511 }; 538 };
512 539
513 } // namespace voe 540 } // namespace voe
514 } // namespace webrtc 541 } // namespace webrtc
515 542
516 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_ 543 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698