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 |
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_ |
13 | 13 |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/common_audio/vad/include/vad.h" | 17 #include "webrtc/common_audio/vad/include/vad.h" |
18 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 18 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
19 #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" | 19 #include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
23 class Vad; | 23 class Vad; |
24 | 24 |
25 class AudioEncoderCng final : public AudioEncoder { | 25 class AudioEncoderCng final : public AudioEncoder { |
26 public: | 26 public: |
27 struct Config { | 27 struct Config { |
28 Config(); | |
29 bool IsOk() const; | 28 bool IsOk() const; |
30 | 29 |
31 int num_channels; | 30 int num_channels = 1; |
32 int payload_type; | 31 int payload_type = 13; |
33 // Caller keeps ownership of the AudioEncoder object. | 32 // Caller keeps ownership of the AudioEncoder object. |
34 AudioEncoder* speech_encoder; | 33 AudioEncoder* speech_encoder = nullptr; |
35 Vad::Aggressiveness vad_mode; | 34 Vad::Aggressiveness vad_mode = Vad::kVadNormal; |
36 int sid_frame_interval_ms; | 35 int sid_frame_interval_ms = 100; |
37 int num_cng_coefficients; | 36 int num_cng_coefficients = 8; |
38 // The Vad pointer is mainly for testing. If a NULL pointer is passed, the | 37 // The Vad pointer is mainly for testing. If a NULL pointer is passed, the |
39 // AudioEncoderCng creates (and destroys) a Vad object internally. If an | 38 // AudioEncoderCng creates (and destroys) a Vad object internally. If an |
40 // object is passed, the AudioEncoderCng assumes ownership of the Vad | 39 // object is passed, the AudioEncoderCng assumes ownership of the Vad |
41 // object. | 40 // object. |
42 Vad* vad; | 41 Vad* vad = nullptr; |
43 }; | 42 }; |
44 | 43 |
45 explicit AudioEncoderCng(const Config& config); | 44 explicit AudioEncoderCng(const Config& config); |
46 | |
47 ~AudioEncoderCng() override; | 45 ~AudioEncoderCng() override; |
48 | 46 |
| 47 size_t MaxEncodedBytes() const override; |
49 int SampleRateHz() const override; | 48 int SampleRateHz() const override; |
50 int NumChannels() const override; | 49 int NumChannels() const override; |
51 size_t MaxEncodedBytes() const override; | |
52 int RtpTimestampRateHz() const override; | 50 int RtpTimestampRateHz() const override; |
53 size_t Num10MsFramesInNextPacket() const override; | 51 size_t Num10MsFramesInNextPacket() const override; |
54 size_t Max10MsFramesInAPacket() const override; | 52 size_t Max10MsFramesInAPacket() const override; |
55 int GetTargetBitrate() const override; | 53 int GetTargetBitrate() const override; |
56 void SetTargetBitrate(int bits_per_second) override; | |
57 void SetProjectedPacketLossRate(double fraction) override; | |
58 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, | 54 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, |
59 const int16_t* audio, | 55 const int16_t* audio, |
60 size_t max_encoded_bytes, | 56 size_t max_encoded_bytes, |
61 uint8_t* encoded) override; | 57 uint8_t* encoded) override; |
| 58 void Reset() override; |
| 59 bool SetFec(bool enable) override; |
| 60 bool SetDtx(bool enable) override; |
| 61 bool SetApplication(Application application) override; |
| 62 bool SetMaxPlaybackRate(int frequency_hz) override; |
| 63 void SetProjectedPacketLossRate(double fraction) override; |
| 64 void SetTargetBitrate(int target_bps) override; |
| 65 void SetMaxBitrate(int max_bps) override; |
| 66 void SetMaxPayloadSize(int max_payload_size_bytes) override; |
62 | 67 |
63 private: | 68 private: |
64 // Deleter for use with scoped_ptr. E.g., use as | 69 // Deleter for use with scoped_ptr. E.g., use as |
65 // rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_; | 70 // rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_; |
66 struct CngInstDeleter { | 71 struct CngInstDeleter { |
67 inline void operator()(CNG_enc_inst* ptr) const { WebRtcCng_FreeEnc(ptr); } | 72 inline void operator()(CNG_enc_inst* ptr) const { WebRtcCng_FreeEnc(ptr); } |
68 }; | 73 }; |
69 | 74 |
70 EncodedInfo EncodePassive(size_t frames_to_encode, | 75 EncodedInfo EncodePassive(size_t frames_to_encode, |
71 size_t max_encoded_bytes, | 76 size_t max_encoded_bytes, |
72 uint8_t* encoded); | 77 uint8_t* encoded); |
73 EncodedInfo EncodeActive(size_t frames_to_encode, | 78 EncodedInfo EncodeActive(size_t frames_to_encode, |
74 size_t max_encoded_bytes, | 79 size_t max_encoded_bytes, |
75 uint8_t* encoded); | 80 uint8_t* encoded); |
76 size_t SamplesPer10msFrame() const; | 81 size_t SamplesPer10msFrame() const; |
77 | 82 |
78 AudioEncoder* speech_encoder_; | 83 AudioEncoder* speech_encoder_; |
79 const int cng_payload_type_; | 84 const int cng_payload_type_; |
80 const int num_cng_coefficients_; | 85 const int num_cng_coefficients_; |
81 std::vector<int16_t> speech_buffer_; | 86 std::vector<int16_t> speech_buffer_; |
82 std::vector<uint32_t> rtp_timestamps_; | 87 std::vector<uint32_t> rtp_timestamps_; |
83 bool last_frame_active_; | 88 bool last_frame_active_; |
84 rtc::scoped_ptr<Vad> vad_; | 89 rtc::scoped_ptr<Vad> vad_; |
85 rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_; | 90 rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst_; |
86 }; | 91 }; |
87 | 92 |
88 } // namespace webrtc | 93 } // namespace webrtc |
89 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_ | 94 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_INCLUDE_AUDIO_ENCODER_CNG_H_ |
OLD | NEW |