Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h

Issue 2362703002: Adding audio network adaptor to AudioEncoderOpus. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/codecs/opus/opus_interface.h" 18 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
19 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" 19 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 class AudioNetworkAdaptor;
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 {
28 kVoip = 0, 29 kVoip = 0,
29 kAudio = 1, 30 kAudio = 1,
30 }; 31 };
31 32
32 struct Config { 33 struct Config {
33 Config(); 34 Config();
34 Config(const Config&); 35 Config(const Config&);
35 ~Config(); 36 ~Config();
36 Config& operator=(const Config&); 37 Config& operator=(const Config&);
37 38
38 bool IsOk() const; 39 bool IsOk() const;
39 int GetBitrateBps() const; 40 int GetBitrateBps() const;
40 41
41 int frame_size_ms = 20; 42 int frame_size_ms = 20;
42 size_t num_channels = 1; 43 size_t num_channels = 1;
43 int payload_type = 120; 44 int payload_type = 120;
44 ApplicationMode application = kVoip; 45 ApplicationMode application = kVoip;
45 rtc::Optional<int> bitrate_bps; // Unset means to use default value. 46 rtc::Optional<int> bitrate_bps; // Unset means to use default value.
46 bool fec_enabled = false; 47 bool fec_enabled = false;
47 int max_playback_rate_hz = 48000; 48 int max_playback_rate_hz = 48000;
48 int complexity = kDefaultComplexity; 49 int complexity = kDefaultComplexity;
49 bool dtx_enabled = false; 50 bool dtx_enabled = false;
51 bool audio_network_adaptor_enabled = false;
50 52
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 };
(...skipping 15 matching lines...) Expand all
75 // being inactive. During that, it still sends 2 packets (one for content, one 77 // being inactive. During that, it still sends 2 packets (one for content, one
76 // for signaling) about every 400 ms. 78 // for signaling) about every 400 ms.
77 bool SetDtx(bool enable) override; 79 bool SetDtx(bool enable) override;
78 bool GetDtx() const override; 80 bool GetDtx() const override;
79 81
80 bool SetApplication(Application application) override; 82 bool SetApplication(Application application) override;
81 void SetMaxPlaybackRate(int frequency_hz) override; 83 void SetMaxPlaybackRate(int frequency_hz) override;
82 void SetProjectedPacketLossRate(double fraction) override; 84 void SetProjectedPacketLossRate(double fraction) override;
83 void SetTargetBitrate(int target_bps) override; 85 void SetTargetBitrate(int target_bps) override;
84 86
87 void OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) override;
88 void OnReceivedUplinkPacketLossFraction(float uplink_packet_loss_fraction) ove rride;
89 void OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) override;
90 void OnReceivedRtt(int rtt_ms) override;
91
85 // Getters for testing. 92 // Getters for testing.
86 double packet_loss_rate() const { return packet_loss_rate_; } 93 double packet_loss_rate() const { return packet_loss_rate_; }
87 ApplicationMode application() const { return config_.application; } 94 ApplicationMode application() const { return config_.application; }
88 95
89 protected: 96 protected:
90 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, 97 EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
91 rtc::ArrayView<const int16_t> audio, 98 rtc::ArrayView<const int16_t> audio,
92 rtc::Buffer* encoded) override; 99 rtc::Buffer* encoded) override;
93 100
94 private: 101 private:
95 size_t Num10msFramesPerPacket() const; 102 size_t Num10msFramesPerPacket() const;
96 size_t SamplesPer10msFrame() const; 103 size_t SamplesPer10msFrame() const;
97 size_t SufficientOutputBufferSize() const; 104 size_t SufficientOutputBufferSize() const;
98 bool RecreateEncoderInstance(const Config& config); 105 bool RecreateEncoderInstance(const Config& config);
106 void SetFrameLength(int frame_length_ms);
107 void SetNumChannelsToEncode(size_t num_channels_to_encode);
108 void ApplyAudioNetworkAdaptor();
99 109
100 Config config_; 110 Config config_;
101 double packet_loss_rate_; 111 double packet_loss_rate_;
102 std::vector<int16_t> input_buffer_; 112 std::vector<int16_t> input_buffer_;
103 OpusEncInst* inst_; 113 OpusEncInst* inst_;
104 uint32_t first_timestamp_in_buffer_; 114 uint32_t first_timestamp_in_buffer_;
115 size_t num_channels_to_encode_;
116 int next_frame_size_ms_;
117 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_;
118
105 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); 119 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus);
106 }; 120 };
107 121
108 } // namespace webrtc 122 } // namespace webrtc
109 123
110 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ 124 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698