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