1 /* 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_CODING_CODECS_RED_AUDIO_ENCODER_COPY_RED_H_ 12 #define MODULES_AUDIO_CODING_CODECS_RED_AUDIO_ENCODER_COPY_RED_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <memory> 18 #include <utility> 19 20 #include "absl/types/optional.h" 21 #include "api/array_view.h" 22 #include "api/audio_codecs/audio_encoder.h" 23 #include "api/units/time_delta.h" 24 #include "rtc_base/buffer.h" 25 #include "rtc_base/constructor_magic.h" 26 27 namespace webrtc { 28 29 // This class implements redundant audio coding. The class object will have an 30 // underlying AudioEncoder object that performs the actual encodings. The 31 // current class will gather the two latest encodings from the underlying codec 32 // into one packet. 33 class AudioEncoderCopyRed final : public AudioEncoder { 34 public: 35 struct Config { 36 Config(); 37 Config(Config&&); 38 ~Config(); 39 int payload_type; 40 std::unique_ptr<AudioEncoder> speech_encoder; 41 }; 42 43 explicit AudioEncoderCopyRed(Config&& config); 44 45 ~AudioEncoderCopyRed() override; 46 47 int SampleRateHz() const override; 48 size_t NumChannels() const override; 49 int RtpTimestampRateHz() const override; 50 size_t Num10MsFramesInNextPacket() const override; 51 size_t Max10MsFramesInAPacket() const override; 52 int GetTargetBitrate() const override; 53 void Reset() override; 54 bool SetFec(bool enable) override; 55 bool SetDtx(bool enable) override; 56 bool SetApplication(Application application) override; 57 void SetMaxPlaybackRate(int frequency_hz) override; 58 rtc::ArrayView<std::unique_ptr<AudioEncoder>> ReclaimContainedEncoders() 59 override; 60 void OnReceivedUplinkPacketLossFraction( 61 float uplink_packet_loss_fraction) override; 62 void OnReceivedUplinkBandwidth( 63 int target_audio_bitrate_bps, 64 absl::optional<int64_t> bwe_period_ms) override; 65 absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange() 66 const override; 67 68 protected: 69 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, 70 rtc::ArrayView<const int16_t> audio, 71 rtc::Buffer* encoded) override; 72 73 private: 74 size_t CalculateHeaderLength() const; 75 std::unique_ptr<AudioEncoder> speech_encoder_; 76 int red_payload_type_; 77 rtc::Buffer secondary_encoded_; 78 EncodedInfoLeaf secondary_info_; 79 rtc::Buffer tertiary_encoded_; 80 EncodedInfoLeaf tertiary_info_; 81 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderCopyRed); 82 }; 83 84 } // namespace webrtc 85 86 #endif // MODULES_AUDIO_CODING_CODECS_RED_AUDIO_ENCODER_COPY_RED_H_ 87