OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 // Deleter for use with unique_ptr. | 24 // Deleter for use with unique_ptr. |
25 struct CngInstDeleter { | 25 struct CngInstDeleter { |
26 void operator()(CNG_enc_inst* ptr) const { WebRtcCng_FreeEnc(ptr); } | 26 void operator()(CNG_enc_inst* ptr) const { WebRtcCng_FreeEnc(ptr); } |
27 }; | 27 }; |
28 | 28 |
29 class Vad; | 29 class Vad; |
30 | 30 |
31 class AudioEncoderCng final : public AudioEncoder { | 31 class AudioEncoderCng final : public AudioEncoder { |
32 public: | 32 public: |
33 struct Config { | 33 struct Config { |
| 34 Config(); |
| 35 Config(Config&&); |
| 36 ~Config(); |
34 bool IsOk() const; | 37 bool IsOk() const; |
35 | 38 |
36 size_t num_channels = 1; | 39 size_t num_channels = 1; |
37 int payload_type = 13; | 40 int payload_type = 13; |
38 // Caller keeps ownership of the AudioEncoder object. | 41 std::unique_ptr<AudioEncoder> speech_encoder; |
39 AudioEncoder* speech_encoder = nullptr; | |
40 Vad::Aggressiveness vad_mode = Vad::kVadNormal; | 42 Vad::Aggressiveness vad_mode = Vad::kVadNormal; |
41 int sid_frame_interval_ms = 100; | 43 int sid_frame_interval_ms = 100; |
42 int num_cng_coefficients = 8; | 44 int num_cng_coefficients = 8; |
43 // The Vad pointer is mainly for testing. If a NULL pointer is passed, the | 45 // The Vad pointer is mainly for testing. If a NULL pointer is passed, the |
44 // AudioEncoderCng creates (and destroys) a Vad object internally. If an | 46 // AudioEncoderCng creates (and destroys) a Vad object internally. If an |
45 // object is passed, the AudioEncoderCng assumes ownership of the Vad | 47 // object is passed, the AudioEncoderCng assumes ownership of the Vad |
46 // object. | 48 // object. |
47 Vad* vad = nullptr; | 49 Vad* vad = nullptr; |
48 }; | 50 }; |
49 | 51 |
50 explicit AudioEncoderCng(const Config& config); | 52 explicit AudioEncoderCng(Config&& config); |
51 ~AudioEncoderCng() override; | 53 ~AudioEncoderCng() override; |
52 | 54 |
53 size_t MaxEncodedBytes() const override; | 55 size_t MaxEncodedBytes() const override; |
54 int SampleRateHz() const override; | 56 int SampleRateHz() const override; |
55 size_t NumChannels() const override; | 57 size_t NumChannels() const override; |
56 int RtpTimestampRateHz() const override; | 58 int RtpTimestampRateHz() const override; |
57 size_t Num10MsFramesInNextPacket() const override; | 59 size_t Num10MsFramesInNextPacket() const override; |
58 size_t Max10MsFramesInAPacket() const override; | 60 size_t Max10MsFramesInAPacket() const override; |
59 int GetTargetBitrate() const override; | 61 int GetTargetBitrate() const override; |
60 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, | 62 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, |
61 rtc::ArrayView<const int16_t> audio, | 63 rtc::ArrayView<const int16_t> audio, |
62 rtc::Buffer* encoded) override; | 64 rtc::Buffer* encoded) override; |
63 void Reset() override; | 65 void Reset() override; |
64 bool SetFec(bool enable) override; | 66 bool SetFec(bool enable) override; |
65 bool SetDtx(bool enable) override; | 67 bool SetDtx(bool enable) override; |
66 bool SetApplication(Application application) override; | 68 bool SetApplication(Application application) override; |
67 void SetMaxPlaybackRate(int frequency_hz) override; | 69 void SetMaxPlaybackRate(int frequency_hz) override; |
68 void SetProjectedPacketLossRate(double fraction) override; | 70 void SetProjectedPacketLossRate(double fraction) override; |
69 void SetTargetBitrate(int target_bps) override; | 71 void SetTargetBitrate(int target_bps) override; |
70 | 72 |
71 private: | 73 private: |
72 EncodedInfo EncodePassive(size_t frames_to_encode, | 74 EncodedInfo EncodePassive(size_t frames_to_encode, |
73 rtc::Buffer* encoded); | 75 rtc::Buffer* encoded); |
74 EncodedInfo EncodeActive(size_t frames_to_encode, | 76 EncodedInfo EncodeActive(size_t frames_to_encode, |
75 rtc::Buffer* encoded); | 77 rtc::Buffer* encoded); |
76 size_t SamplesPer10msFrame() const; | 78 size_t SamplesPer10msFrame() const; |
77 | 79 |
78 AudioEncoder* speech_encoder_; | 80 std::unique_ptr<AudioEncoder> speech_encoder_; |
79 const int cng_payload_type_; | 81 const int cng_payload_type_; |
80 const int num_cng_coefficients_; | 82 const int num_cng_coefficients_; |
81 const int sid_frame_interval_ms_; | 83 const int sid_frame_interval_ms_; |
82 std::vector<int16_t> speech_buffer_; | 84 std::vector<int16_t> speech_buffer_; |
83 std::vector<uint32_t> rtp_timestamps_; | 85 std::vector<uint32_t> rtp_timestamps_; |
84 bool last_frame_active_; | 86 bool last_frame_active_; |
85 std::unique_ptr<Vad> vad_; | 87 std::unique_ptr<Vad> vad_; |
86 std::unique_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_; | 88 std::unique_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_; |
87 | 89 |
88 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderCng); | 90 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderCng); |
89 }; | 91 }; |
90 | 92 |
91 } // namespace webrtc | 93 } // namespace webrtc |
92 | 94 |
93 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_AUDIO_ENCODER_CNG_H_ | 95 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_AUDIO_ENCODER_CNG_H_ |
OLD | NEW |