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