OLD | NEW |
---|---|
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 44 matching lines...) Loading... | |
73 class Statistics; | 74 class Statistics; |
74 class TransportFeedbackProxy; | 75 class TransportFeedbackProxy; |
75 class TransportSequenceNumberProxy; | 76 class TransportSequenceNumberProxy; |
76 class VoERtcpObserver; | 77 class VoERtcpObserver; |
77 | 78 |
78 // Helper class to simplify locking scheme for members that are accessed from | 79 // Helper class to simplify locking scheme for members that are accessed from |
79 // multiple threads. | 80 // multiple threads. |
80 // Example: a member can be set on thread T1 and read by an internal audio | 81 // Example: a member can be set on thread T1 and read by an internal audio |
81 // thread T2. Accessing the member via this class ensures that we are | 82 // thread T2. Accessing the member via this class ensures that we are |
82 // safe and also avoid TSan v2 warnings. | 83 // safe and also avoid TSan v2 warnings. |
83 class ChannelState { | 84 class ChannelState { |
tommi
2017/03/28 13:47:20
I don't suppose you see a way to make this class s
| |
84 public: | 85 public: |
85 struct State { | 86 struct State { |
86 bool output_file_playing = false; | 87 bool output_file_playing = false; |
87 bool input_file_playing = false; | 88 bool input_file_playing = false; |
88 bool playing = false; | 89 bool playing = false; |
89 bool sending = false; | 90 bool sending = false; |
91 bool sending_has_been_activated = false; | |
tommi
2017/03/28 13:47:20
what's the difference between this variable and se
| |
90 }; | 92 }; |
91 | 93 |
92 ChannelState() {} | 94 ChannelState() {} |
93 virtual ~ChannelState() {} | 95 virtual ~ChannelState() {} |
94 | 96 |
95 void Reset() { | 97 void Reset() { |
96 rtc::CritScope lock(&lock_); | 98 rtc::CritScope lock(&lock_); |
97 state_ = State(); | 99 state_ = State(); |
98 } | 100 } |
99 | 101 |
(...skipping 13 matching lines...) Loading... | |
113 } | 115 } |
114 | 116 |
115 void SetPlaying(bool enable) { | 117 void SetPlaying(bool enable) { |
116 rtc::CritScope lock(&lock_); | 118 rtc::CritScope lock(&lock_); |
117 state_.playing = enable; | 119 state_.playing = enable; |
118 } | 120 } |
119 | 121 |
120 void SetSending(bool enable) { | 122 void SetSending(bool enable) { |
121 rtc::CritScope lock(&lock_); | 123 rtc::CritScope lock(&lock_); |
122 state_.sending = enable; | 124 state_.sending = enable; |
125 state_.sending_has_been_activated = enable; | |
123 } | 126 } |
124 | 127 |
125 private: | 128 private: |
126 rtc::CriticalSection lock_; | 129 rtc::CriticalSection lock_; |
127 State state_; | 130 State state_; |
128 }; | 131 }; |
129 | 132 |
130 class Channel | 133 class Channel |
131 : public RtpData, | 134 : public RtpData, |
132 public RtpFeedback, | 135 public RtpFeedback, |
(...skipping 19 matching lines...) Loading... | |
152 uint32_t instanceId, | 155 uint32_t instanceId, |
153 const VoEBase::ChannelConfig& config); | 156 const VoEBase::ChannelConfig& config); |
154 int32_t Init(); | 157 int32_t Init(); |
155 void RegisterLegacyReceiveCodecs(); | 158 void RegisterLegacyReceiveCodecs(); |
156 void Terminate(); | 159 void Terminate(); |
157 int32_t SetEngineInformation(Statistics& engineStatistics, | 160 int32_t SetEngineInformation(Statistics& engineStatistics, |
158 OutputMixer& outputMixer, | 161 OutputMixer& outputMixer, |
159 ProcessThread& moduleProcessThread, | 162 ProcessThread& moduleProcessThread, |
160 AudioDeviceModule& audioDeviceModule, | 163 AudioDeviceModule& audioDeviceModule, |
161 VoiceEngineObserver* voiceEngineObserver, | 164 VoiceEngineObserver* voiceEngineObserver, |
162 rtc::CriticalSection* callbackCritSect); | 165 rtc::CriticalSection* callbackCritSect, |
163 int32_t UpdateLocalTimeStamp(); | 166 rtc::TaskQueue* encoder_queue); |
164 | 167 |
165 void SetSink(std::unique_ptr<AudioSinkInterface> sink); | 168 void SetSink(std::unique_ptr<AudioSinkInterface> sink); |
166 | 169 |
167 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory | 170 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory |
168 // passed into AudioReceiveStream is the same as the one set when creating the | 171 // passed into AudioReceiveStream is the same as the one set when creating the |
169 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can | 172 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can |
170 // go. | 173 // go. |
171 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const; | 174 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const; |
172 | 175 |
173 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs); | 176 void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs); |
(...skipping 173 matching lines...) Loading... | |
347 uint32_t InstanceId() const { return _instanceId; } | 350 uint32_t InstanceId() const { return _instanceId; } |
348 int32_t ChannelId() const { return _channelId; } | 351 int32_t ChannelId() const { return _channelId; } |
349 bool Playing() const { return channel_state_.Get().playing; } | 352 bool Playing() const { return channel_state_.Get().playing; } |
350 bool Sending() const { return channel_state_.Get().sending; } | 353 bool Sending() const { return channel_state_.Get().sending; } |
351 bool ExternalTransport() const { | 354 bool ExternalTransport() const { |
352 rtc::CritScope cs(&_callbackCritSect); | 355 rtc::CritScope cs(&_callbackCritSect); |
353 return _externalTransport; | 356 return _externalTransport; |
354 } | 357 } |
355 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); } | 358 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); } |
356 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); } | 359 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); } |
357 uint32_t Demultiplex(const AudioFrame& audioFrame); | 360 PushResampler<int16_t>* input_resampler() { return &input_resampler_; } |
the sun
2017/03/28 12:57:50
Not needed anymore?
henrika_webrtc
2017/03/29 10:35:12
Acknowledged.
| |
358 // Demultiplex the data to the channel's |_audioFrame|. The difference | 361 |
359 // between this method and the overloaded method above is that |audio_data| | 362 // ProcessAndEncodeAudio() creates an audio frame copy and posts a task |
360 // does not go through transmit_mixer and APM. | 363 // on the shared encoder task queue, wich in turn calls (on the queue) |
361 void Demultiplex(const int16_t* audio_data, | 364 // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the |
362 int sample_rate, | 365 // audio takes place. The processing mainly consists of encoding and preparing |
363 size_t number_of_frames, | 366 // the result for sending by adding it to a send queue. |
364 size_t number_of_channels); | 367 // The main reason for using a task queue here is to release the native, |
365 uint32_t PrepareEncodeAndSend(int mixingFrequency); | 368 // OS-specific, audio capture thread as soon as possible to ensure that it |
366 uint32_t EncodeAndSend(); | 369 // can go back to sleep and be prepared to deliver an new captured audio |
370 // packet. | |
371 void ProcessAndEncodeAudio(const AudioFrame& audio_input); | |
372 | |
373 // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in | |
374 // VoEBase and the audio in |audio_data| has not been subject to any APM | |
375 // processing. Some extra steps are therfore needed when building up the | |
376 // audio frame copy before using the same task as in the default call to | |
377 // ProcessAndEncodeAudio(const AudioFrame& audio_input). | |
378 void ProcessAndEncodeAudio(const int16_t* audio_data, | |
379 int sample_rate, | |
380 size_t number_of_frames, | |
381 size_t number_of_channels); | |
382 | |
383 // Called on the encoder task queue when a new input audio frame is ready | |
384 // for encoding. | |
385 void ProcessAndEncodeAudioOnTaskQueue(AudioFrame* audio_input); | |
tommi
2017/03/28 13:47:20
Will the frame be modified by this function? If n
| |
386 | |
387 // Internal helper methods used by ProcessAndEncodeAudioOnTaskQueue(). | |
388 // Both are called on the encoder task queue. | |
389 uint32_t PrepareEncodeAndSend(AudioFrame* audio_input); | |
the sun
2017/03/28 12:57:50
Fuse them into ProcessAndEncodeAudioOnTaskQueue()
henrika_webrtc
2017/03/29 10:35:12
Great idea ;-)
| |
390 uint32_t EncodeAndSend(AudioFrame* audio_input); | |
367 | 391 |
368 // Associate to a send channel. | 392 // Associate to a send channel. |
369 // Used for obtaining RTT for a receive-only channel. | 393 // Used for obtaining RTT for a receive-only channel. |
370 void set_associate_send_channel(const ChannelOwner& channel); | 394 void set_associate_send_channel(const ChannelOwner& channel); |
371 // Disassociate a send channel if it was associated. | 395 // Disassociate a send channel if it was associated. |
372 void DisassociateSendChannel(int channel_id); | 396 void DisassociateSendChannel(int channel_id); |
373 | 397 |
374 // Set a RtcEventLog logging object. | 398 // Set a RtcEventLog logging object. |
375 void SetRtcEventLog(RtcEventLog* event_log); | 399 void SetRtcEventLog(RtcEventLog* event_log); |
376 | 400 |
377 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats); | 401 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats); |
378 void SetTransportOverhead(size_t transport_overhead_per_packet); | 402 void SetTransportOverhead(size_t transport_overhead_per_packet); |
379 | 403 |
380 // From OverheadObserver in the RTP/RTCP module | 404 // From OverheadObserver in the RTP/RTCP module |
381 void OnOverheadChanged(size_t overhead_bytes_per_packet) override; | 405 void OnOverheadChanged(size_t overhead_bytes_per_packet) override; |
382 | 406 |
383 // The existence of this function alongside OnUplinkPacketLossRate is | 407 // The existence of this function alongside OnUplinkPacketLossRate is |
384 // a compromise. We want the encoder to be agnostic of the PLR source, but | 408 // a compromise. We want the encoder to be agnostic of the PLR source, but |
385 // we also don't want it to receive conflicting information from TWCC and | 409 // we also don't want it to receive conflicting information from TWCC and |
386 // from RTCP-XR. | 410 // from RTCP-XR. |
387 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate); | 411 void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate); |
388 | 412 |
389 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate); | 413 void OnRecoverableUplinkPacketLossRate(float recoverable_packet_loss_rate); |
390 | 414 |
391 private: | 415 private: |
416 class ProcessAndEncodeAudioTask; | |
417 | |
392 void OnUplinkPacketLossRate(float packet_loss_rate); | 418 void OnUplinkPacketLossRate(float packet_loss_rate); |
393 | |
394 bool InputMute() const; | 419 bool InputMute() const; |
395 bool OnRtpPacketWithHeader(const uint8_t* received_packet, | 420 bool OnRtpPacketWithHeader(const uint8_t* received_packet, |
396 size_t length, | 421 size_t length, |
397 RTPHeader *header); | 422 RTPHeader *header); |
398 bool ReceivePacket(const uint8_t* packet, | 423 bool ReceivePacket(const uint8_t* packet, |
399 size_t packet_length, | 424 size_t packet_length, |
400 const RTPHeader& header, | 425 const RTPHeader& header, |
401 bool in_order); | 426 bool in_order); |
402 bool HandleRtxPacket(const uint8_t* packet, | 427 bool HandleRtxPacket(const uint8_t* packet, |
403 size_t packet_length, | 428 size_t packet_length, |
404 const RTPHeader& header); | 429 const RTPHeader& header); |
405 bool IsPacketInOrder(const RTPHeader& header) const; | 430 bool IsPacketInOrder(const RTPHeader& header) const; |
406 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; | 431 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; |
407 int ResendPackets(const uint16_t* sequence_numbers, int length); | 432 int ResendPackets(const uint16_t* sequence_numbers, int length); |
408 int32_t MixOrReplaceAudioWithFile(int mixingFrequency); | 433 int32_t MixOrReplaceAudioWithFile(AudioFrame* audio_frame); |
409 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency); | 434 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency); |
410 void UpdatePlayoutTimestamp(bool rtcp); | 435 void UpdatePlayoutTimestamp(bool rtcp); |
411 void RegisterReceiveCodecsToRTPModule(); | 436 void RegisterReceiveCodecsToRTPModule(); |
412 | 437 |
413 int SetSendRtpHeaderExtension(bool enable, | 438 int SetSendRtpHeaderExtension(bool enable, |
414 RTPExtensionType type, | 439 RTPExtensionType type, |
415 unsigned char id); | 440 unsigned char id); |
416 | 441 |
417 void UpdateOverheadForEncoder() | 442 void UpdateOverheadForEncoder() |
418 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_); | 443 EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_); |
(...skipping 17 matching lines...) Loading... | |
436 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; | 461 std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_; |
437 std::unique_ptr<RtpReceiver> rtp_receiver_; | 462 std::unique_ptr<RtpReceiver> rtp_receiver_; |
438 TelephoneEventHandler* telephone_event_handler_; | 463 TelephoneEventHandler* telephone_event_handler_; |
439 std::unique_ptr<RtpRtcp> _rtpRtcpModule; | 464 std::unique_ptr<RtpRtcp> _rtpRtcpModule; |
440 std::unique_ptr<AudioCodingModule> audio_coding_; | 465 std::unique_ptr<AudioCodingModule> audio_coding_; |
441 acm2::CodecManager codec_manager_; | 466 acm2::CodecManager codec_manager_; |
442 acm2::RentACodec rent_a_codec_; | 467 acm2::RentACodec rent_a_codec_; |
443 std::unique_ptr<AudioSinkInterface> audio_sink_; | 468 std::unique_ptr<AudioSinkInterface> audio_sink_; |
444 AudioLevel _outputAudioLevel; | 469 AudioLevel _outputAudioLevel; |
445 bool _externalTransport; | 470 bool _externalTransport; |
446 AudioFrame _audioFrame; | |
447 // Downsamples to the codec rate if necessary. | 471 // Downsamples to the codec rate if necessary. |
448 PushResampler<int16_t> input_resampler_; | 472 PushResampler<int16_t> input_resampler_; |
449 std::unique_ptr<FilePlayer> input_file_player_; | 473 std::unique_ptr<FilePlayer> input_file_player_; |
450 std::unique_ptr<FilePlayer> output_file_player_; | 474 std::unique_ptr<FilePlayer> output_file_player_; |
451 std::unique_ptr<FileRecorder> output_file_recorder_; | 475 std::unique_ptr<FileRecorder> output_file_recorder_; |
452 int _inputFilePlayerId; | 476 int _inputFilePlayerId; |
453 int _outputFilePlayerId; | 477 int _outputFilePlayerId; |
454 int _outputFileRecorderId; | 478 int _outputFileRecorderId; |
455 bool _outputFileRecording; | 479 bool _outputFileRecording; |
456 uint32_t _timeStamp; | 480 uint32_t _timeStamp; |
(...skipping 18 matching lines...) Loading... | |
475 // frame. | 499 // frame. |
476 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_); | 500 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_); |
477 | 501 |
478 // uses | 502 // uses |
479 Statistics* _engineStatisticsPtr; | 503 Statistics* _engineStatisticsPtr; |
480 OutputMixer* _outputMixerPtr; | 504 OutputMixer* _outputMixerPtr; |
481 ProcessThread* _moduleProcessThreadPtr; | 505 ProcessThread* _moduleProcessThreadPtr; |
482 AudioDeviceModule* _audioDeviceModulePtr; | 506 AudioDeviceModule* _audioDeviceModulePtr; |
483 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base | 507 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base |
484 rtc::CriticalSection* _callbackCritSectPtr; // owned by base | 508 rtc::CriticalSection* _callbackCritSectPtr; // owned by base |
509 rtc::TaskQueue* encoder_queue_; | |
485 Transport* _transportPtr; // WebRtc socket or external transport | 510 Transport* _transportPtr; // WebRtc socket or external transport |
486 RmsLevel rms_level_; | 511 RmsLevel rms_level_; |
487 bool input_mute_ GUARDED_BY(volume_settings_critsect_); | 512 bool input_mute_ GUARDED_BY(volume_settings_critsect_); |
488 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend(). | 513 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend(). |
489 float _outputGain GUARDED_BY(volume_settings_critsect_); | 514 float _outputGain GUARDED_BY(volume_settings_critsect_); |
490 // VoEBase | 515 // VoEBase |
491 bool _mixFileWithMicrophone; | 516 bool _mixFileWithMicrophone; |
492 // VoeRTP_RTCP | 517 // VoeRTP_RTCP |
493 uint32_t _lastLocalTimeStamp; | 518 uint32_t _lastLocalTimeStamp; |
494 int8_t _lastPayloadType; | 519 int8_t _lastPayloadType; |
(...skipping 17 matching lines...) Loading... | |
512 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_; | 537 std::unique_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_; |
513 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_; | 538 std::unique_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_; |
514 std::unique_ptr<RateLimiter> retransmission_rate_limiter_; | 539 std::unique_ptr<RateLimiter> retransmission_rate_limiter_; |
515 | 540 |
516 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed. | 541 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed. |
517 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; | 542 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
518 | 543 |
519 rtc::ThreadChecker construction_thread_; | 544 rtc::ThreadChecker construction_thread_; |
520 | 545 |
521 const bool use_twcc_plr_for_ana_; | 546 const bool use_twcc_plr_for_ana_; |
547 | |
548 rtc::Event stop_send_event_; | |
522 }; | 549 }; |
523 | 550 |
524 } // namespace voe | 551 } // namespace voe |
525 } // namespace webrtc | 552 } // namespace webrtc |
526 | 553 |
527 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_ | 554 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_ |
OLD | NEW |