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 using AudioNetworkAdaptorCreator = |
| 63 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, |
| 64 const Clock*)>; |
| 65 AudioEncoderOpus( |
| 66 const Config& config, |
| 67 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr); |
| 68 |
62 explicit AudioEncoderOpus(const CodecInst& codec_inst); | 69 explicit AudioEncoderOpus(const CodecInst& codec_inst); |
| 70 |
63 ~AudioEncoderOpus() override; | 71 ~AudioEncoderOpus() override; |
64 | 72 |
65 int SampleRateHz() const override; | 73 int SampleRateHz() const override; |
66 size_t NumChannels() const override; | 74 size_t NumChannels() const override; |
67 size_t Num10MsFramesInNextPacket() const override; | 75 size_t Num10MsFramesInNextPacket() const override; |
68 size_t Max10MsFramesInAPacket() const override; | 76 size_t Max10MsFramesInAPacket() const override; |
69 int GetTargetBitrate() const override; | 77 int GetTargetBitrate() const override; |
70 | 78 |
71 void Reset() override; | 79 void Reset() override; |
72 bool SetFec(bool enable) override; | 80 bool SetFec(bool enable) override; |
73 | 81 |
74 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice | 82 // 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 | 83 // being inactive. During that, it still sends 2 packets (one for content, one |
76 // for signaling) about every 400 ms. | 84 // for signaling) about every 400 ms. |
77 bool SetDtx(bool enable) override; | 85 bool SetDtx(bool enable) override; |
78 bool GetDtx() const override; | 86 bool GetDtx() const override; |
79 | 87 |
80 bool SetApplication(Application application) override; | 88 bool SetApplication(Application application) override; |
81 void SetMaxPlaybackRate(int frequency_hz) override; | 89 void SetMaxPlaybackRate(int frequency_hz) override; |
82 void SetProjectedPacketLossRate(double fraction) override; | 90 void SetProjectedPacketLossRate(double fraction) override; |
83 void SetTargetBitrate(int target_bps) override; | 91 void SetTargetBitrate(int target_bps) override; |
84 | 92 |
| 93 bool EnableAudioNetworkAdaptor(const std::string& config_string, |
| 94 const Clock* clock) override; |
| 95 void DisableAudioNetworkAdaptor() override; |
| 96 void OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) override; |
| 97 void OnReceivedUplinkPacketLossFraction( |
| 98 float uplink_packet_loss_fraction) override; |
| 99 void OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) override; |
| 100 void OnReceivedRtt(int rtt_ms) override; |
| 101 void SetReceiverFrameLengthRange(int min_frame_length_ms, |
| 102 int max_frame_length_ms) override; |
| 103 |
85 // Getters for testing. | 104 // Getters for testing. |
86 double packet_loss_rate() const { return packet_loss_rate_; } | 105 double packet_loss_rate() const { return packet_loss_rate_; } |
87 ApplicationMode application() const { return config_.application; } | 106 ApplicationMode application() const { return config_.application; } |
| 107 bool fec_enabled() const { return config_.fec_enabled; } |
| 108 size_t num_channels_to_encode() const { return num_channels_to_encode_; } |
| 109 int next_frame_length_ms() const { return next_frame_length_ms_; } |
88 | 110 |
89 protected: | 111 protected: |
90 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, | 112 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, |
91 rtc::ArrayView<const int16_t> audio, | 113 rtc::ArrayView<const int16_t> audio, |
92 rtc::Buffer* encoded) override; | 114 rtc::Buffer* encoded) override; |
93 | 115 |
94 private: | 116 private: |
95 size_t Num10msFramesPerPacket() const; | 117 size_t Num10msFramesPerPacket() const; |
96 size_t SamplesPer10msFrame() const; | 118 size_t SamplesPer10msFrame() const; |
97 size_t SufficientOutputBufferSize() const; | 119 size_t SufficientOutputBufferSize() const; |
98 bool RecreateEncoderInstance(const Config& config); | 120 bool RecreateEncoderInstance(const Config& config); |
| 121 void SetFrameLength(int frame_length_ms); |
| 122 void SetNumChannelsToEncode(size_t num_channels_to_encode); |
| 123 void ApplyAudioNetworkAdaptor(); |
| 124 std::unique_ptr<AudioNetworkAdaptor> DefaultAudioNetworkAdaptorCreator( |
| 125 const std::string& config_string, |
| 126 const Clock* clock) const; |
99 | 127 |
100 Config config_; | 128 Config config_; |
101 double packet_loss_rate_; | 129 double packet_loss_rate_; |
102 std::vector<int16_t> input_buffer_; | 130 std::vector<int16_t> input_buffer_; |
103 OpusEncInst* inst_; | 131 OpusEncInst* inst_; |
104 uint32_t first_timestamp_in_buffer_; | 132 uint32_t first_timestamp_in_buffer_; |
| 133 size_t num_channels_to_encode_; |
| 134 int next_frame_length_ms_; |
| 135 AudioNetworkAdaptorCreator audio_network_adaptor_creator_; |
| 136 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_; |
| 137 |
105 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); | 138 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); |
106 }; | 139 }; |
107 | 140 |
108 } // namespace webrtc | 141 } // namespace webrtc |
109 | 142 |
110 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ | 143 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
OLD | NEW |