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

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

Issue 2429503002: Simplifying audio network adaptor by moving receiver frame length range to ctor. (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
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) 55 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM)
56 // If we are on Android, iOS and/or ARM, use a lower complexity setting as 56 // If we are on Android, iOS and/or ARM, use a lower complexity setting as
57 // default, to save encoder complexity. 57 // default, to save encoder complexity.
58 static const int kDefaultComplexity = 5; 58 static const int kDefaultComplexity = 5;
59 #else 59 #else
60 static const int kDefaultComplexity = 9; 60 static const int kDefaultComplexity = 9;
61 #endif 61 #endif
62 }; 62 };
63 63
64 using AudioNetworkAdaptorCreator = 64 using AudioNetworkAdaptorCreator =
65 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, 65 std::function<std::unique_ptr<AudioNetworkAdaptor>(
66 const Clock*)>; 66 const std::string&,
67 int min_receiver_frame_length_ms,
68 int max_receiver_frame_length_ms,
69 const Clock*)>;
67 AudioEncoderOpus( 70 AudioEncoderOpus(
68 const Config& config, 71 const Config& config,
69 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr); 72 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr);
70 73
71 explicit AudioEncoderOpus(const CodecInst& codec_inst); 74 explicit AudioEncoderOpus(const CodecInst& codec_inst);
72 75
73 ~AudioEncoderOpus() override; 76 ~AudioEncoderOpus() override;
74 77
75 int SampleRateHz() const override; 78 int SampleRateHz() const override;
76 size_t NumChannels() const override; 79 size_t NumChannels() const override;
77 size_t Num10MsFramesInNextPacket() const override; 80 size_t Num10MsFramesInNextPacket() const override;
78 size_t Max10MsFramesInAPacket() const override; 81 size_t Max10MsFramesInAPacket() const override;
79 int GetTargetBitrate() const override; 82 int GetTargetBitrate() const override;
80 83
81 void Reset() override; 84 void Reset() override;
82 bool SetFec(bool enable) override; 85 bool SetFec(bool enable) override;
83 86
84 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice 87 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice
85 // being inactive. During that, it still sends 2 packets (one for content, one 88 // being inactive. During that, it still sends 2 packets (one for content, one
86 // for signaling) about every 400 ms. 89 // for signaling) about every 400 ms.
87 bool SetDtx(bool enable) override; 90 bool SetDtx(bool enable) override;
88 bool GetDtx() const override; 91 bool GetDtx() const override;
89 92
90 bool SetApplication(Application application) override; 93 bool SetApplication(Application application) override;
91 void SetMaxPlaybackRate(int frequency_hz) override; 94 void SetMaxPlaybackRate(int frequency_hz) override;
92 void SetProjectedPacketLossRate(double fraction) override; 95 void SetProjectedPacketLossRate(double fraction) override;
93 void SetTargetBitrate(int target_bps) override; 96 void SetTargetBitrate(int target_bps) override;
94 97
95 bool EnableAudioNetworkAdaptor(const std::string& config_string, 98 bool EnableAudioNetworkAdaptor(const std::string& config_string,
99 int min_receiver_frame_length_ms,
100 int max_receiver_frame_length_ms,
96 const Clock* clock) override; 101 const Clock* clock) override;
97 void DisableAudioNetworkAdaptor() override; 102 void DisableAudioNetworkAdaptor() override;
98 void OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) override; 103 void OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) override;
99 void OnReceivedUplinkPacketLossFraction( 104 void OnReceivedUplinkPacketLossFraction(
100 float uplink_packet_loss_fraction) override; 105 float uplink_packet_loss_fraction) override;
101 void OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) override; 106 void OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) override;
102 void OnReceivedRtt(int rtt_ms) override; 107 void OnReceivedRtt(int rtt_ms) override;
103 void SetReceiverFrameLengthRange(int min_frame_length_ms,
104 int max_frame_length_ms) override;
105 108
106 // Getters for testing. 109 // Getters for testing.
107 double packet_loss_rate() const { return packet_loss_rate_; } 110 double packet_loss_rate() const { return packet_loss_rate_; }
108 ApplicationMode application() const { return config_.application; } 111 ApplicationMode application() const { return config_.application; }
109 bool fec_enabled() const { return config_.fec_enabled; } 112 bool fec_enabled() const { return config_.fec_enabled; }
110 size_t num_channels_to_encode() const { return num_channels_to_encode_; } 113 size_t num_channels_to_encode() const { return num_channels_to_encode_; }
111 int next_frame_length_ms() const { return next_frame_length_ms_; } 114 int next_frame_length_ms() const { return next_frame_length_ms_; }
112 115
113 protected: 116 protected:
114 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, 117 EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
115 rtc::ArrayView<const int16_t> audio, 118 rtc::ArrayView<const int16_t> audio,
116 rtc::Buffer* encoded) override; 119 rtc::Buffer* encoded) override;
117 120
118 private: 121 private:
119 class PacketLossFractionSmoother; 122 class PacketLossFractionSmoother;
120 123
121 size_t Num10msFramesPerPacket() const; 124 size_t Num10msFramesPerPacket() const;
122 size_t SamplesPer10msFrame() const; 125 size_t SamplesPer10msFrame() const;
123 size_t SufficientOutputBufferSize() const; 126 size_t SufficientOutputBufferSize() const;
124 bool RecreateEncoderInstance(const Config& config); 127 bool RecreateEncoderInstance(const Config& config);
125 void SetFrameLength(int frame_length_ms); 128 void SetFrameLength(int frame_length_ms);
126 void SetNumChannelsToEncode(size_t num_channels_to_encode); 129 void SetNumChannelsToEncode(size_t num_channels_to_encode);
127 void ApplyAudioNetworkAdaptor(); 130 void ApplyAudioNetworkAdaptor();
128 std::unique_ptr<AudioNetworkAdaptor> DefaultAudioNetworkAdaptorCreator( 131 std::unique_ptr<AudioNetworkAdaptor> DefaultAudioNetworkAdaptorCreator(
129 const std::string& config_string, 132 const std::string& config_string,
133 int min_receiver_frame_length_ms,
134 int max_receiver_frame_length_ms,
130 const Clock* clock) const; 135 const Clock* clock) const;
131 136
132 Config config_; 137 Config config_;
133 double packet_loss_rate_; 138 double packet_loss_rate_;
134 std::vector<int16_t> input_buffer_; 139 std::vector<int16_t> input_buffer_;
135 OpusEncInst* inst_; 140 OpusEncInst* inst_;
136 uint32_t first_timestamp_in_buffer_; 141 uint32_t first_timestamp_in_buffer_;
137 size_t num_channels_to_encode_; 142 size_t num_channels_to_encode_;
138 int next_frame_length_ms_; 143 int next_frame_length_ms_;
139 std::unique_ptr<PacketLossFractionSmoother> packet_loss_fraction_smoother_; 144 std::unique_ptr<PacketLossFractionSmoother> packet_loss_fraction_smoother_;
140 AudioNetworkAdaptorCreator audio_network_adaptor_creator_; 145 AudioNetworkAdaptorCreator audio_network_adaptor_creator_;
141 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_; 146 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_;
142 147
143 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); 148 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus);
144 }; 149 };
145 150
146 } // namespace webrtc 151 } // namespace webrtc
147 152
148 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ 153 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698