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 <list> 18 #include <memory> 19 #include <utility> 20 21 #include "absl/types/optional.h" 22 #include "api/array_view.h" 23 #include "api/audio_codecs/audio_encoder.h" 24 #include "api/field_trials_view.h" 25 #include "api/units/time_delta.h" 26 #include "rtc_base/buffer.h" 27 28 namespace webrtc { 29 30 // This class implements redundant audio coding as described in 31 // https://tools.ietf.org/html/rfc2198 32 // The class object will have an underlying AudioEncoder object that performs 33 // the actual encodings. The current class will gather the N latest encodings 34 // from the underlying codec into one packet. Currently N is hard-coded to 2. 35 36 class AudioEncoderCopyRed final : public AudioEncoder { 37 public: 38 struct Config { 39 Config(); 40 Config(Config&&); 41 ~Config(); 42 int payload_type; 43 std::unique_ptr<AudioEncoder> speech_encoder; 44 }; 45 46 AudioEncoderCopyRed(Config&& config, const FieldTrialsView& field_trials); 47 48 ~AudioEncoderCopyRed() override; 49 50 AudioEncoderCopyRed(const AudioEncoderCopyRed&) = delete; 51 AudioEncoderCopyRed& operator=(const AudioEncoderCopyRed&) = delete; 52 53 int SampleRateHz() const override; 54 size_t NumChannels() const override; 55 int RtpTimestampRateHz() const override; 56 size_t Num10MsFramesInNextPacket() const override; 57 size_t Max10MsFramesInAPacket() const override; 58 int GetTargetBitrate() const override; 59 60 void Reset() override; 61 bool SetFec(bool enable) override; 62 63 bool SetDtx(bool enable) override; 64 bool GetDtx() const override; 65 66 bool SetApplication(Application application) override; 67 void SetMaxPlaybackRate(int frequency_hz) override; 68 bool EnableAudioNetworkAdaptor(const std::string& config_string, 69 RtcEventLog* event_log) override; 70 void DisableAudioNetworkAdaptor() override; 71 void OnReceivedUplinkPacketLossFraction( 72 float uplink_packet_loss_fraction) override; 73 void OnReceivedUplinkBandwidth( 74 int target_audio_bitrate_bps, 75 absl::optional<int64_t> bwe_period_ms) override; 76 void OnReceivedUplinkAllocation(BitrateAllocationUpdate update) override; 77 void OnReceivedRtt(int rtt_ms) override; 78 void OnReceivedOverhead(size_t overhead_bytes_per_packet) override; 79 void SetReceiverFrameLengthRange(int min_frame_length_ms, 80 int max_frame_length_ms) override; 81 ANAStats GetANAStats() const override; 82 absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange() 83 const override; 84 rtc::ArrayView<std::unique_ptr<AudioEncoder>> ReclaimContainedEncoders() 85 override; 86 87 protected: 88 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, 89 rtc::ArrayView<const int16_t> audio, 90 rtc::Buffer* encoded) override; 91 92 private: 93 std::unique_ptr<AudioEncoder> speech_encoder_; 94 rtc::Buffer primary_encoded_; 95 size_t max_packet_length_; 96 int red_payload_type_; 97 std::list<std::pair<EncodedInfo, rtc::Buffer>> redundant_encodings_; 98 }; 99 100 } // namespace webrtc 101 102 #endif // MODULES_AUDIO_CODING_CODECS_RED_AUDIO_ENCODER_COPY_RED_H_ 103