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

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: some updates 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/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 12 matching lines...) Expand all
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;
kwiberg-webrtc 2016/09/27 09:35:55 Do you need this? Isn't it enough that the constru
minyue-webrtc 2016/09/27 16:02:33 I wanted to do that. But it will need a lot of oth
minyue-webrtc 2016/09/29 15:34:25 But I removed due to another reason: it becomes re
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 };
60 62
61 explicit AudioEncoderOpus(const Config& config); 63 AudioEncoderOpus(
62 explicit AudioEncoderOpus(const CodecInst& codec_inst); 64 const Config& config,
65 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor = nullptr);
66
67 AudioEncoderOpus(const CodecInst& codec_inst);
kwiberg-webrtc 2016/09/27 09:35:55 This constructor should still be explicit, right?
minyue-webrtc 2016/09/27 16:02:33 oh, right, I tried to add audio network adaptor ar
68
63 ~AudioEncoderOpus() override; 69 ~AudioEncoderOpus() override;
64 70
65 int SampleRateHz() const override; 71 int SampleRateHz() const override;
66 size_t NumChannels() const override; 72 size_t NumChannels() const override;
67 size_t Num10MsFramesInNextPacket() const override; 73 size_t Num10MsFramesInNextPacket() const override;
68 size_t Max10MsFramesInAPacket() const override; 74 size_t Max10MsFramesInAPacket() const override;
69 int GetTargetBitrate() const override; 75 int GetTargetBitrate() const override;
70 76
71 void Reset() override; 77 void Reset() override;
72 bool SetFec(bool enable) override; 78 bool SetFec(bool enable) override;
73 79
74 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice 80 // 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 81 // being inactive. During that, it still sends 2 packets (one for content, one
76 // for signaling) about every 400 ms. 82 // for signaling) about every 400 ms.
77 bool SetDtx(bool enable) override; 83 bool SetDtx(bool enable) override;
78 bool GetDtx() const override; 84 bool GetDtx() const override;
79 85
80 bool SetApplication(Application application) override; 86 bool SetApplication(Application application) override;
81 void SetMaxPlaybackRate(int frequency_hz) override; 87 void SetMaxPlaybackRate(int frequency_hz) override;
82 void SetProjectedPacketLossRate(double fraction) override; 88 void SetProjectedPacketLossRate(double fraction) override;
83 void SetTargetBitrate(int target_bps) override; 89 void SetTargetBitrate(int target_bps) override;
84 90
91 bool SetAudioNetworkAdaptor(bool enable) override;
92 void OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) override;
93 void OnReceivedUplinkPacketLossFraction(
94 float uplink_packet_loss_fraction) override;
95 void OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) override;
96 void OnReceivedRtt(int rtt_ms) override;
97 void SetReceiverFrameLengthRange(int min_frame_length_ms,
98 int max_frame_length_ms) override;
99
85 // Getters for testing. 100 // Getters for testing.
86 double packet_loss_rate() const { return packet_loss_rate_; } 101 double packet_loss_rate() const { return packet_loss_rate_; }
87 ApplicationMode application() const { return config_.application; } 102 ApplicationMode application() const { return config_.application; }
103 bool fec_enabled() const { return config_.fec_enabled; }
104 size_t num_channels_to_encode() const { return num_channels_to_encode_; }
105 int next_frame_length_ms() const { return next_frame_size_ms_; }
88 106
89 protected: 107 protected:
90 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, 108 EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
91 rtc::ArrayView<const int16_t> audio, 109 rtc::ArrayView<const int16_t> audio,
92 rtc::Buffer* encoded) override; 110 rtc::Buffer* encoded) override;
93 111
94 private: 112 private:
95 size_t Num10msFramesPerPacket() const; 113 size_t Num10msFramesPerPacket() const;
96 size_t SamplesPer10msFrame() const; 114 size_t SamplesPer10msFrame() const;
97 size_t SufficientOutputBufferSize() const; 115 size_t SufficientOutputBufferSize() const;
98 bool RecreateEncoderInstance(const Config& config); 116 bool RecreateEncoderInstance(const Config& config);
117 void SetFrameLength(int frame_length_ms);
118 void SetNumChannelsToEncode(size_t num_channels_to_encode);
119 void ApplyAudioNetworkAdaptor();
99 120
100 Config config_; 121 Config config_;
101 double packet_loss_rate_; 122 double packet_loss_rate_;
102 std::vector<int16_t> input_buffer_; 123 std::vector<int16_t> input_buffer_;
103 OpusEncInst* inst_; 124 OpusEncInst* inst_;
104 uint32_t first_timestamp_in_buffer_; 125 uint32_t first_timestamp_in_buffer_;
126 size_t num_channels_to_encode_;
127 int next_frame_size_ms_;
128 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_;
129
105 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); 130 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus);
106 }; 131 };
107 132
108 } // namespace webrtc 133 } // namespace webrtc
109 134
110 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ 135 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698