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

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

Issue 2695243005: Injectable audio encoders: BuiltinAudioEncoderFactory (Closed)
Patch Set: Cleaned up Opus code a bit. kHz -> Hz in comment picked a bunch of lint Created 3 years, 9 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 <functional> 14 #include <functional>
15 #include <memory> 15 #include <memory>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/api/audio_codecs/audio_format.h"
19 #include "webrtc/base/constructormagic.h" 20 #include "webrtc/base/constructormagic.h"
20 #include "webrtc/base/optional.h" 21 #include "webrtc/base/optional.h"
21 #include "webrtc/common_audio/smoothing_filter.h" 22 #include "webrtc/common_audio/smoothing_filter.h"
22 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ k_adaptor.h" 23 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ k_adaptor.h"
23 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" 24 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
24 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" 25 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
25 26
26 namespace webrtc { 27 namespace webrtc {
27 28
28 class RtcEventLog; 29 class RtcEventLog;
(...skipping 14 matching lines...) Expand all
43 Config& operator=(const Config&); 44 Config& operator=(const Config&);
44 45
45 bool IsOk() const; 46 bool IsOk() const;
46 int GetBitrateBps() const; 47 int GetBitrateBps() const;
47 // Returns empty if the current bitrate falls within the hysteresis window, 48 // Returns empty if the current bitrate falls within the hysteresis window,
48 // defined by complexity_threshold_bps +/- complexity_threshold_window_bps. 49 // defined by complexity_threshold_bps +/- complexity_threshold_window_bps.
49 // Otherwise, returns the current complexity depending on whether the 50 // Otherwise, returns the current complexity depending on whether the
50 // current bitrate is above or below complexity_threshold_bps. 51 // current bitrate is above or below complexity_threshold_bps.
51 rtc::Optional<int> GetNewComplexity() const; 52 rtc::Optional<int> GetNewComplexity() const;
52 53
53 int frame_size_ms = 20; 54 static constexpr int kDefaultFrameSizeMs = 20;
55 int frame_size_ms = kDefaultFrameSizeMs;
54 size_t num_channels = 1; 56 size_t num_channels = 1;
55 int payload_type = 120; 57 int payload_type = 120;
56 ApplicationMode application = kVoip; 58 ApplicationMode application = kVoip;
57 rtc::Optional<int> bitrate_bps; // Unset means to use default value. 59 rtc::Optional<int> bitrate_bps; // Unset means to use default value.
58 bool fec_enabled = false; 60 bool fec_enabled = false;
59 int max_playback_rate_hz = 48000; 61 int max_playback_rate_hz = 48000;
60 int complexity = kDefaultComplexity; 62 int complexity = kDefaultComplexity;
61 // This value may change in the struct's constructor. 63 // This value may change in the struct's constructor.
62 int low_rate_complexity = kDefaultComplexity; 64 int low_rate_complexity = kDefaultComplexity;
63 // low_rate_complexity is used when the bitrate is below this threshold. 65 // low_rate_complexity is used when the bitrate is below this threshold.
64 int complexity_threshold_bps = 12500; 66 int complexity_threshold_bps = 12500;
65 int complexity_threshold_window_bps = 1500; 67 int complexity_threshold_window_bps = 1500;
66 bool dtx_enabled = false; 68 bool dtx_enabled = false;
67 std::vector<int> supported_frame_lengths_ms; 69 std::vector<int> supported_frame_lengths_ms;
68 const Clock* clock = Clock::GetRealTimeClock(); 70 const Clock* clock = Clock::GetRealTimeClock();
69 int uplink_bandwidth_update_interval_ms = 200; 71 int uplink_bandwidth_update_interval_ms = 200;
70 72
71 private: 73 private:
72 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) 74 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM)
73 // If we are on Android, iOS and/or ARM, use a lower complexity setting as 75 // If we are on Android, iOS and/or ARM, use a lower complexity setting as
74 // default, to save encoder complexity. 76 // default, to save encoder complexity.
75 static const int kDefaultComplexity = 5; 77 static const int kDefaultComplexity = 5;
76 #else 78 #else
77 static const int kDefaultComplexity = 9; 79 static const int kDefaultComplexity = 9;
78 #endif 80 #endif
79 }; 81 };
80 82
83 static Config CreateConfig(int payload_type, const SdpAudioFormat& format);
84 static Config CreateConfig(const CodecInst& codec_inst);
85
81 using AudioNetworkAdaptorCreator = 86 using AudioNetworkAdaptorCreator =
82 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, 87 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&,
83 RtcEventLog*, 88 RtcEventLog*,
84 const Clock*)>; 89 const Clock*)>;
85 AudioEncoderOpus( 90 AudioEncoderOpus(
86 const Config& config, 91 const Config& config,
87 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr, 92 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr,
88 std::unique_ptr<SmoothingFilter> bitrate_smoother = nullptr); 93 std::unique_ptr<SmoothingFilter> bitrate_smoother = nullptr);
89 94
90 explicit AudioEncoderOpus(const CodecInst& codec_inst); 95 explicit AudioEncoderOpus(const CodecInst& codec_inst);
96 AudioEncoderOpus(int payload_type, const SdpAudioFormat& format);
97 ~AudioEncoderOpus() override;
91 98
92 ~AudioEncoderOpus() override; 99 // Static interface for use by BuiltinAudioEncoderFactory.
100 static constexpr const char* GetPayloadName() { return "opus"; }
101 static rtc::Optional<AudioCodecInfo> QueryAudioEncoder(
102 const SdpAudioFormat& format);
93 103
94 int SampleRateHz() const override; 104 int SampleRateHz() const override;
95 size_t NumChannels() const override; 105 size_t NumChannels() const override;
96 size_t Num10MsFramesInNextPacket() const override; 106 size_t Num10MsFramesInNextPacket() const override;
97 size_t Max10MsFramesInAPacket() const override; 107 size_t Max10MsFramesInAPacket() const override;
98 int GetTargetBitrate() const override; 108 int GetTargetBitrate() const override;
99 109
100 void Reset() override; 110 void Reset() override;
101 bool SetFec(bool enable) override; 111 bool SetFec(bool enable) override;
102 112
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 rtc::Optional<size_t> overhead_bytes_per_packet_; 185 rtc::Optional<size_t> overhead_bytes_per_packet_;
176 const std::unique_ptr<SmoothingFilter> bitrate_smoother_; 186 const std::unique_ptr<SmoothingFilter> bitrate_smoother_;
177 rtc::Optional<int64_t> bitrate_smoother_last_update_time_; 187 rtc::Optional<int64_t> bitrate_smoother_last_update_time_;
178 188
179 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); 189 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus);
180 }; 190 };
181 191
182 } // namespace webrtc 192 } // namespace webrtc
183 193
184 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ 194 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698