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 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 Channel(int32_t channelId, | 159 Channel(int32_t channelId, |
160 uint32_t instanceId, | 160 uint32_t instanceId, |
161 const VoEBase::ChannelConfig& config); | 161 const VoEBase::ChannelConfig& config); |
162 int32_t Init(); | 162 int32_t Init(); |
163 int32_t SetEngineInformation(Statistics& engineStatistics, | 163 int32_t SetEngineInformation(Statistics& engineStatistics, |
164 OutputMixer& outputMixer, | 164 OutputMixer& outputMixer, |
165 TransmitMixer& transmitMixer, | 165 TransmitMixer& transmitMixer, |
166 ProcessThread& moduleProcessThread, | 166 ProcessThread& moduleProcessThread, |
167 AudioDeviceModule& audioDeviceModule, | 167 AudioDeviceModule& audioDeviceModule, |
168 VoiceEngineObserver* voiceEngineObserver, | 168 VoiceEngineObserver* voiceEngineObserver, |
169 rtc::CriticalSection* callbackCritSect); | 169 rtc::CriticalSection* callbackCritSect, |
170 int32_t UpdateLocalTimeStamp(); | 170 rtc::TaskQueue* encoder_queue); |
171 | 171 |
172 void SetSink(std::unique_ptr<AudioSinkInterface> sink); | 172 void SetSink(std::unique_ptr<AudioSinkInterface> sink); |
173 | 173 |
174 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory | 174 // TODO(ossu): Don't use! It's only here to confirm that the decoder factory |
175 // passed into AudioReceiveStream is the same as the one set when creating the | 175 // passed into AudioReceiveStream is the same as the one set when creating the |
176 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can | 176 // ADM. Once Channel creation is moved into Audio{Send,Receive}Stream this can |
177 // go. | 177 // go. |
178 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const; | 178 const rtc::scoped_refptr<AudioDecoderFactory>& GetAudioDecoderFactory() const; |
179 | 179 |
180 // API methods | 180 // API methods |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 int32_t ChannelId() const { return _channelId; } | 387 int32_t ChannelId() const { return _channelId; } |
388 bool Playing() const { return channel_state_.Get().playing; } | 388 bool Playing() const { return channel_state_.Get().playing; } |
389 bool Sending() const { return channel_state_.Get().sending; } | 389 bool Sending() const { return channel_state_.Get().sending; } |
390 bool ExternalTransport() const { | 390 bool ExternalTransport() const { |
391 rtc::CritScope cs(&_callbackCritSect); | 391 rtc::CritScope cs(&_callbackCritSect); |
392 return _externalTransport; | 392 return _externalTransport; |
393 } | 393 } |
394 bool ExternalMixing() const { return _externalMixing; } | 394 bool ExternalMixing() const { return _externalMixing; } |
395 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); } | 395 RtpRtcp* RtpRtcpModulePtr() const { return _rtpRtcpModule.get(); } |
396 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); } | 396 int8_t OutputEnergyLevel() const { return _outputAudioLevel.Level(); } |
397 uint32_t Demultiplex(const AudioFrame& audioFrame); | 397 |
398 // Demultiplex the data to the channel's |_audioFrame|. The difference | 398 // ProcessAndEncodeAudio() creates an audio frame copy and posts a task |
399 // between this method and the overloaded method above is that |audio_data| | 399 // on the shared encoder task queue, wich in turn calls (on the queue) |
400 // does not go through transmit_mixer and APM. | 400 // ProcessAndEncodeAudioOnTaskQueue() where the actual processing of the |
401 void Demultiplex(const int16_t* audio_data, | 401 // audio takes place. The processing mainly consists of encoding and preparing |
402 int sample_rate, | 402 // the result for sending by adding it to a send queue. |
403 size_t number_of_frames, | 403 // The main reason for using a task queue here is to release the native, |
404 size_t number_of_channels); | 404 // OS-specific, audio capture thread as soon as possible to ensure that it |
405 uint32_t PrepareEncodeAndSend(int mixingFrequency); | 405 // can go back to sleep and be prepared to deliver an new captured audio |
406 uint32_t EncodeAndSend(); | 406 // packet. |
| 407 void ProcessAndEncodeAudio(const AudioFrame& audio_input); |
| 408 // This version of ProcessAndEncodeAudio() is used by PushCaptureData() in |
| 409 // VoEBase and the audio in |audio_data| has not been subject to any APM |
| 410 // processing. Some extra steps are therfore needed when building up the |
| 411 // audio frame copy before using the same task as in the default call to |
| 412 // ProcessAndEncodeAudio(const AudioFrame& audio_input). |
| 413 void ProcessAndEncodeAudio(const int16_t* audio_data, |
| 414 int sample_rate, |
| 415 size_t number_of_frames, |
| 416 size_t number_of_channels); |
| 417 // Called on the encoder task queue when a new input audio frame is ready |
| 418 // for encoding. |
| 419 void ProcessAndEncodeAudioOnTaskQueue( |
| 420 std::unique_ptr<AudioFrame> audio_input); |
| 421 // Internal helper methods used by ProcessAndEncodeAudioOnTaskQueue(). |
| 422 // Both are called on the encoder task queue. |
| 423 uint32_t PrepareEncodeAndSend(AudioFrame* audio_input); |
| 424 uint32_t EncodeAndSend(AudioFrame* audio_input); |
407 | 425 |
408 // Associate to a send channel. | 426 // Associate to a send channel. |
409 // Used for obtaining RTT for a receive-only channel. | 427 // Used for obtaining RTT for a receive-only channel. |
410 void set_associate_send_channel(const ChannelOwner& channel); | 428 void set_associate_send_channel(const ChannelOwner& channel); |
411 // Disassociate a send channel if it was associated. | 429 // Disassociate a send channel if it was associated. |
412 void DisassociateSendChannel(int channel_id); | 430 void DisassociateSendChannel(int channel_id); |
413 | 431 |
414 // Set a RtcEventLog logging object. | 432 // Set a RtcEventLog logging object. |
415 void SetRtcEventLog(RtcEventLog* event_log); | 433 void SetRtcEventLog(RtcEventLog* event_log); |
416 | 434 |
417 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats); | 435 void SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats); |
418 void SetTransportOverhead(size_t transport_overhead_per_packet); | 436 void SetTransportOverhead(size_t transport_overhead_per_packet); |
419 | 437 |
420 // From OverheadObserver in the RTP/RTCP module | 438 // From OverheadObserver in the RTP/RTCP module |
421 void OnOverheadChanged(size_t overhead_bytes_per_packet) override; | 439 void OnOverheadChanged(size_t overhead_bytes_per_packet) override; |
422 | 440 |
423 protected: | 441 protected: |
424 void OnIncomingFractionLoss(int fraction_lost); | 442 void OnIncomingFractionLoss(int fraction_lost); |
425 | 443 |
426 private: | 444 private: |
| 445 class ProcessAndEncodeAudioTask; |
| 446 |
427 bool ReceivePacket(const uint8_t* packet, | 447 bool ReceivePacket(const uint8_t* packet, |
428 size_t packet_length, | 448 size_t packet_length, |
429 const RTPHeader& header, | 449 const RTPHeader& header, |
430 bool in_order); | 450 bool in_order); |
431 bool HandleRtxPacket(const uint8_t* packet, | 451 bool HandleRtxPacket(const uint8_t* packet, |
432 size_t packet_length, | 452 size_t packet_length, |
433 const RTPHeader& header); | 453 const RTPHeader& header); |
434 bool IsPacketInOrder(const RTPHeader& header) const; | 454 bool IsPacketInOrder(const RTPHeader& header) const; |
435 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; | 455 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; |
436 int ResendPackets(const uint16_t* sequence_numbers, int length); | 456 int ResendPackets(const uint16_t* sequence_numbers, int length); |
437 int32_t MixOrReplaceAudioWithFile(int mixingFrequency); | 457 int32_t MixOrReplaceAudioWithFile(AudioFrame* audio_frame); |
438 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency); | 458 int32_t MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency); |
439 void UpdatePlayoutTimestamp(bool rtcp); | 459 void UpdatePlayoutTimestamp(bool rtcp); |
440 void RegisterReceiveCodecsToRTPModule(); | 460 void RegisterReceiveCodecsToRTPModule(); |
441 | 461 |
442 int SetSendRtpHeaderExtension(bool enable, | 462 int SetSendRtpHeaderExtension(bool enable, |
443 RTPExtensionType type, | 463 RTPExtensionType type, |
444 unsigned char id); | 464 unsigned char id); |
445 | 465 |
446 void UpdateOverheadForEncoder(); | 466 void UpdateOverheadForEncoder(); |
447 | 467 |
(...skipping 17 matching lines...) Expand all Loading... |
465 std::unique_ptr<StatisticsProxy> statistics_proxy_; | 485 std::unique_ptr<StatisticsProxy> statistics_proxy_; |
466 std::unique_ptr<RtpReceiver> rtp_receiver_; | 486 std::unique_ptr<RtpReceiver> rtp_receiver_; |
467 TelephoneEventHandler* telephone_event_handler_; | 487 TelephoneEventHandler* telephone_event_handler_; |
468 std::unique_ptr<RtpRtcp> _rtpRtcpModule; | 488 std::unique_ptr<RtpRtcp> _rtpRtcpModule; |
469 std::unique_ptr<AudioCodingModule> audio_coding_; | 489 std::unique_ptr<AudioCodingModule> audio_coding_; |
470 acm2::CodecManager codec_manager_; | 490 acm2::CodecManager codec_manager_; |
471 acm2::RentACodec rent_a_codec_; | 491 acm2::RentACodec rent_a_codec_; |
472 std::unique_ptr<AudioSinkInterface> audio_sink_; | 492 std::unique_ptr<AudioSinkInterface> audio_sink_; |
473 AudioLevel _outputAudioLevel; | 493 AudioLevel _outputAudioLevel; |
474 bool _externalTransport; | 494 bool _externalTransport; |
475 AudioFrame _audioFrame; | |
476 // Downsamples to the codec rate if necessary. | 495 // Downsamples to the codec rate if necessary. |
477 PushResampler<int16_t> input_resampler_; | 496 PushResampler<int16_t> input_resampler_; |
478 std::unique_ptr<FilePlayer> input_file_player_; | 497 std::unique_ptr<FilePlayer> input_file_player_; |
479 std::unique_ptr<FilePlayer> output_file_player_; | 498 std::unique_ptr<FilePlayer> output_file_player_; |
480 std::unique_ptr<FileRecorder> output_file_recorder_; | 499 std::unique_ptr<FileRecorder> output_file_recorder_; |
481 int _inputFilePlayerId; | 500 int _inputFilePlayerId; |
482 int _outputFilePlayerId; | 501 int _outputFilePlayerId; |
483 int _outputFileRecorderId; | 502 int _outputFileRecorderId; |
484 bool _outputFileRecording; | 503 bool _outputFileRecording; |
485 bool _outputExternalMedia; | 504 bool _outputExternalMedia; |
(...skipping 22 matching lines...) Expand all Loading... |
508 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_); | 527 int64_t capture_start_ntp_time_ms_ GUARDED_BY(ts_stats_lock_); |
509 | 528 |
510 // uses | 529 // uses |
511 Statistics* _engineStatisticsPtr; | 530 Statistics* _engineStatisticsPtr; |
512 OutputMixer* _outputMixerPtr; | 531 OutputMixer* _outputMixerPtr; |
513 TransmitMixer* _transmitMixerPtr; | 532 TransmitMixer* _transmitMixerPtr; |
514 ProcessThread* _moduleProcessThreadPtr; | 533 ProcessThread* _moduleProcessThreadPtr; |
515 AudioDeviceModule* _audioDeviceModulePtr; | 534 AudioDeviceModule* _audioDeviceModulePtr; |
516 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base | 535 VoiceEngineObserver* _voiceEngineObserverPtr; // owned by base |
517 rtc::CriticalSection* _callbackCritSectPtr; // owned by base | 536 rtc::CriticalSection* _callbackCritSectPtr; // owned by base |
| 537 rtc::TaskQueue* encoder_queue_; |
518 Transport* _transportPtr; // WebRtc socket or external transport | 538 Transport* _transportPtr; // WebRtc socket or external transport |
519 RmsLevel rms_level_; | 539 RmsLevel rms_level_; |
520 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise | 540 int32_t _sendFrameType; // Send data is voice, 1-voice, 0-otherwise |
521 // VoEBase | 541 // VoEBase |
522 bool _externalMixing; | 542 bool _externalMixing; |
523 bool _mixFileWithMicrophone; | 543 bool _mixFileWithMicrophone; |
524 // VoEVolumeControl | 544 // VoEVolumeControl |
525 bool input_mute_ GUARDED_BY(volume_settings_critsect_); | 545 bool input_mute_ GUARDED_BY(volume_settings_critsect_); |
526 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend(). | 546 bool previous_frame_muted_; // Only accessed from PrepareEncodeAndSend(). |
527 float _panLeft GUARDED_BY(volume_settings_critsect_); | 547 float _panLeft GUARDED_BY(volume_settings_critsect_); |
(...skipping 25 matching lines...) Expand all Loading... |
553 std::unique_ptr<RateLimiter> retransmission_rate_limiter_; | 573 std::unique_ptr<RateLimiter> retransmission_rate_limiter_; |
554 | 574 |
555 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed. | 575 // TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed. |
556 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; | 576 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
557 }; | 577 }; |
558 | 578 |
559 } // namespace voe | 579 } // namespace voe |
560 } // namespace webrtc | 580 } // namespace webrtc |
561 | 581 |
562 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_ | 582 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_H_ |
OLD | NEW |