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

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

Issue 1322973004: Fold AudioEncoderMutable into AudioEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: review fixes Created 5 years, 3 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_INTERFACE_AUDIO_ENCODER_OPUS_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_INTERFACE_AUDIO_ENCODER_OPUS_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_INTERFACE_AUDIO_ENCODER_OPUS_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_INTERFACE_AUDIO_ENCODER_OPUS_H_
13 13
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/base/checks.h"
16 #include "webrtc/base/scoped_ptr.h" 17 #include "webrtc/base/scoped_ptr.h"
17 #include "webrtc/modules/audio_coding/codecs/audio_encoder_mutable_impl.h"
18 #include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h" 18 #include "webrtc/modules/audio_coding/codecs/opus/interface/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 // NOTE: This class has neither ThreadChecker, nor locks. The owner of an 23 struct CodecInst;
24 // AudioEncoderOpus object must ensure that it is not accessed concurrently.
25 24
26 class AudioEncoderOpus final : public AudioEncoder { 25 class AudioEncoderOpus final : public AudioEncoder {
27 public: 26 public:
28 enum ApplicationMode { 27 enum ApplicationMode {
29 kVoip = 0, 28 kVoip = 0,
30 kAudio = 1, 29 kAudio = 1,
31 }; 30 };
32 31
33 struct Config { 32 struct Config {
34 Config();
35 bool IsOk() const; 33 bool IsOk() const;
36 int frame_size_ms; 34 int frame_size_ms = 20;
37 int num_channels; 35 int num_channels = 1;
38 int payload_type; 36 int payload_type = 120;
39 ApplicationMode application; 37 ApplicationMode application = kVoip;
40 int bitrate_bps; 38 int bitrate_bps = 64000;
41 bool fec_enabled; 39 bool fec_enabled = false;
42 int max_playback_rate_hz; 40 int max_playback_rate_hz = 48000;
43 int complexity; 41 int complexity = kDefaultComplexity;
44 bool dtx_enabled; 42 bool dtx_enabled = false;
43
44 private:
45 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM)
46 // If we are on Android, iOS and/or ARM, use a lower complexity setting as
47 // default, to save encoder complexity.
48 static const int kDefaultComplexity = 5;
49 #else
50 static const int kDefaultComplexity = 9;
51 #endif
45 }; 52 };
46 53
47 explicit AudioEncoderOpus(const Config& config); 54 explicit AudioEncoderOpus(const Config& config);
55 explicit AudioEncoderOpus(const CodecInst& codec_inst);
48 ~AudioEncoderOpus() override; 56 ~AudioEncoderOpus() override;
49 57
58 size_t MaxEncodedBytes() const override;
50 int SampleRateHz() const override; 59 int SampleRateHz() const override;
51 int NumChannels() const override; 60 int NumChannels() const override;
52 size_t MaxEncodedBytes() const override;
53 size_t Num10MsFramesInNextPacket() const override; 61 size_t Num10MsFramesInNextPacket() const override;
54 size_t Max10MsFramesInAPacket() const override; 62 size_t Max10MsFramesInAPacket() const override;
55 int GetTargetBitrate() const override; 63 int GetTargetBitrate() const override;
56 void SetTargetBitrate(int bits_per_second) override;
57 void SetProjectedPacketLossRate(double fraction) override;
58
59 double packet_loss_rate() const { return packet_loss_rate_; }
60 ApplicationMode application() const { return application_; }
61 bool dtx_enabled() const { return dtx_enabled_; }
62 64
63 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, 65 EncodedInfo EncodeInternal(uint32_t rtp_timestamp,
64 const int16_t* audio, 66 const int16_t* audio,
65 size_t max_encoded_bytes, 67 size_t max_encoded_bytes,
66 uint8_t* encoded) override; 68 uint8_t* encoded) override;
67 69
68 private: 70 void Reset() override;
69 const size_t num_10ms_frames_per_packet_;
70 const int num_channels_;
71 const int payload_type_;
72 const ApplicationMode application_;
73 int bitrate_bps_;
74 const bool dtx_enabled_;
75 const size_t samples_per_10ms_frame_;
76 std::vector<int16_t> input_buffer_;
77 OpusEncInst* inst_;
78 uint32_t first_timestamp_in_buffer_;
79 double packet_loss_rate_;
80 };
81
82 struct CodecInst;
83
84 class AudioEncoderMutableOpus
85 : public AudioEncoderMutableImpl<AudioEncoderOpus> {
86 public:
87 explicit AudioEncoderMutableOpus(const CodecInst& codec_inst);
88 bool SetFec(bool enable) override; 71 bool SetFec(bool enable) override;
89 72
90 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice 73 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice
91 // being inactive. During that, it still sends 2 packets (one for content, one 74 // being inactive. During that, it still sends 2 packets (one for content, one
92 // for signaling) about every 400 ms. 75 // for signaling) about every 400 ms.
93 bool SetDtx(bool enable) override; 76 bool SetDtx(bool enable) override;
94 77
95 bool SetApplication(Application application) override; 78 bool SetApplication(Application application) override;
96 bool SetMaxPlaybackRate(int frequency_hz) override; 79 bool SetMaxPlaybackRate(int frequency_hz) override;
97 AudioEncoderOpus::ApplicationMode application() const { 80 void SetProjectedPacketLossRate(double fraction) override;
98 CriticalSectionScoped cs(encoder_lock_.get()); 81 void SetTargetBitrate(int target_bps) override;
99 return encoder()->application(); 82
100 } 83 // Getters for testing.
101 double packet_loss_rate() const { 84 double packet_loss_rate() const { return packet_loss_rate_; }
102 CriticalSectionScoped cs(encoder_lock_.get()); 85 ApplicationMode application() const { return config_.application; }
103 return encoder()->packet_loss_rate(); 86 bool dtx_enabled() const { return config_.dtx_enabled; }
104 } 87
105 bool dtx_enabled() const { 88 private:
106 CriticalSectionScoped cs(encoder_lock_.get()); 89 int Num10msFramesPerPacket() const;
107 return encoder()->dtx_enabled(); 90 int SamplesPer10msFrame() const;
108 } 91 bool RecreateEncoderInstance(const Config& config);
92
93 Config config_;
94 double packet_loss_rate_;
95 std::vector<int16_t> input_buffer_;
96 OpusEncInst* inst_;
97 uint32_t first_timestamp_in_buffer_;
109 }; 98 };
110 99
111 } // namespace webrtc 100 } // namespace webrtc
112 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_INTERFACE_AUDIO_ENCODER_OPUS_ H_ 101 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_INTERFACE_AUDIO_ENCODER_OPUS_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698