OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
13 | 13 |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/base/optional.h" | 17 #include "webrtc/base/optional.h" |
| 18 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ
k_adaptor.h" |
18 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" | 19 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" |
19 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 20 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 | 23 |
23 struct CodecInst; | 24 struct CodecInst; |
24 | 25 |
25 class AudioEncoderOpus final : public AudioEncoder { | 26 class AudioEncoderOpus final : public AudioEncoder { |
26 public: | 27 public: |
27 enum ApplicationMode { | 28 enum ApplicationMode { |
(...skipping 23 matching lines...) Expand all Loading... |
51 private: | 52 private: |
52 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) | 53 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) |
53 // If we are on Android, iOS and/or ARM, use a lower complexity setting as | 54 // If we are on Android, iOS and/or ARM, use a lower complexity setting as |
54 // default, to save encoder complexity. | 55 // default, to save encoder complexity. |
55 static const int kDefaultComplexity = 5; | 56 static const int kDefaultComplexity = 5; |
56 #else | 57 #else |
57 static const int kDefaultComplexity = 9; | 58 static const int kDefaultComplexity = 9; |
58 #endif | 59 #endif |
59 }; | 60 }; |
60 | 61 |
61 explicit AudioEncoderOpus(const Config& config); | 62 AudioEncoderOpus( |
| 63 const Config& config, |
| 64 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor = nullptr); |
| 65 |
62 explicit AudioEncoderOpus(const CodecInst& codec_inst); | 66 explicit AudioEncoderOpus(const CodecInst& codec_inst); |
| 67 |
63 ~AudioEncoderOpus() override; | 68 ~AudioEncoderOpus() override; |
64 | 69 |
65 int SampleRateHz() const override; | 70 int SampleRateHz() const override; |
66 size_t NumChannels() const override; | 71 size_t NumChannels() const override; |
67 size_t Num10MsFramesInNextPacket() const override; | 72 size_t Num10MsFramesInNextPacket() const override; |
68 size_t Max10MsFramesInAPacket() const override; | 73 size_t Max10MsFramesInAPacket() const override; |
69 int GetTargetBitrate() const override; | 74 int GetTargetBitrate() const override; |
70 | 75 |
71 void Reset() override; | 76 void Reset() override; |
72 bool SetFec(bool enable) override; | 77 bool SetFec(bool enable) override; |
73 | 78 |
74 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice | 79 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice |
75 // being inactive. During that, it still sends 2 packets (one for content, one | 80 // being inactive. During that, it still sends 2 packets (one for content, one |
76 // for signaling) about every 400 ms. | 81 // for signaling) about every 400 ms. |
77 bool SetDtx(bool enable) override; | 82 bool SetDtx(bool enable) override; |
78 bool GetDtx() const override; | 83 bool GetDtx() const override; |
79 | 84 |
80 bool SetApplication(Application application) override; | 85 bool SetApplication(Application application) override; |
81 void SetMaxPlaybackRate(int frequency_hz) override; | 86 void SetMaxPlaybackRate(int frequency_hz) override; |
82 void SetProjectedPacketLossRate(double fraction) override; | 87 void SetProjectedPacketLossRate(double fraction) override; |
83 void SetTargetBitrate(int target_bps) override; | 88 void SetTargetBitrate(int target_bps) override; |
84 | 89 |
| 90 bool EnableAudioNetworkAdaptor(const std::string& config_string, |
| 91 const Clock* clock) override; |
| 92 void DisableAudioNetworkAdaptor() override; |
| 93 void OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) override; |
| 94 void OnReceivedUplinkPacketLossFraction( |
| 95 float uplink_packet_loss_fraction) override; |
| 96 void OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) override; |
| 97 void OnReceivedRtt(int rtt_ms) override; |
| 98 void SetReceiverFrameLengthRange(int min_frame_length_ms, |
| 99 int max_frame_length_ms) override; |
| 100 |
85 // Getters for testing. | 101 // Getters for testing. |
86 double packet_loss_rate() const { return packet_loss_rate_; } | 102 double packet_loss_rate() const { return packet_loss_rate_; } |
87 ApplicationMode application() const { return config_.application; } | 103 ApplicationMode application() const { return config_.application; } |
| 104 bool fec_enabled() const { return config_.fec_enabled; } |
| 105 size_t num_channels_to_encode() const { return num_channels_to_encode_; } |
| 106 int next_frame_length_ms() const { return next_frame_length_ms_; } |
88 | 107 |
89 protected: | 108 protected: |
90 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, | 109 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, |
91 rtc::ArrayView<const int16_t> audio, | 110 rtc::ArrayView<const int16_t> audio, |
92 rtc::Buffer* encoded) override; | 111 rtc::Buffer* encoded) override; |
93 | 112 |
94 private: | 113 private: |
95 size_t Num10msFramesPerPacket() const; | 114 size_t Num10msFramesPerPacket() const; |
96 size_t SamplesPer10msFrame() const; | 115 size_t SamplesPer10msFrame() const; |
97 size_t SufficientOutputBufferSize() const; | 116 size_t SufficientOutputBufferSize() const; |
98 bool RecreateEncoderInstance(const Config& config); | 117 bool RecreateEncoderInstance(const Config& config); |
| 118 void SetFrameLength(int frame_length_ms); |
| 119 void SetNumChannelsToEncode(size_t num_channels_to_encode); |
| 120 void ApplyAudioNetworkAdaptor(); |
99 | 121 |
100 Config config_; | 122 Config config_; |
101 double packet_loss_rate_; | 123 double packet_loss_rate_; |
102 std::vector<int16_t> input_buffer_; | 124 std::vector<int16_t> input_buffer_; |
103 OpusEncInst* inst_; | 125 OpusEncInst* inst_; |
104 uint32_t first_timestamp_in_buffer_; | 126 uint32_t first_timestamp_in_buffer_; |
| 127 size_t num_channels_to_encode_; |
| 128 int next_frame_length_ms_; |
| 129 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_; |
| 130 |
105 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); | 131 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); |
106 }; | 132 }; |
107 | 133 |
108 } // namespace webrtc | 134 } // namespace webrtc |
109 | 135 |
110 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ | 136 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
OLD | NEW |