audio_encoder_g722.h (2461B)
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_G722_AUDIO_ENCODER_G722_H_ 12 #define MODULES_AUDIO_CODING_CODECS_G722_AUDIO_ENCODER_G722_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 #include <memory> 17 #include <optional> 18 #include <utility> 19 20 #include "api/array_view.h" 21 #include "api/audio_codecs/audio_encoder.h" 22 #include "api/audio_codecs/g722/audio_encoder_g722_config.h" 23 #include "api/units/time_delta.h" 24 #include "modules/audio_coding/codecs/g722/g722_interface.h" 25 #include "rtc_base/buffer.h" 26 27 namespace webrtc { 28 29 class AudioEncoderG722Impl final : public AudioEncoder { 30 public: 31 AudioEncoderG722Impl(const AudioEncoderG722Config& config, int payload_type); 32 ~AudioEncoderG722Impl() override; 33 34 AudioEncoderG722Impl(const AudioEncoderG722Impl&) = delete; 35 AudioEncoderG722Impl& operator=(const AudioEncoderG722Impl&) = delete; 36 37 int SampleRateHz() const override; 38 size_t NumChannels() const override; 39 int RtpTimestampRateHz() const override; 40 size_t Num10MsFramesInNextPacket() const override; 41 size_t Max10MsFramesInAPacket() const override; 42 int GetTargetBitrate() const override; 43 void Reset() override; 44 std::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange() 45 const override; 46 47 protected: 48 EncodedInfo EncodeImpl(uint32_t rtp_timestamp, 49 ArrayView<const int16_t> audio, 50 Buffer* encoded) override; 51 52 private: 53 // The encoder state for one channel. 54 struct EncoderState { 55 G722EncInst* encoder; 56 std::unique_ptr<int16_t[]> speech_buffer; // Queued up for encoding. 57 Buffer encoded_buffer; // Already encoded. 58 EncoderState(); 59 ~EncoderState(); 60 }; 61 62 size_t SamplesPerChannel() const; 63 64 const size_t num_channels_; 65 const int payload_type_; 66 const size_t num_10ms_frames_per_packet_; 67 size_t num_10ms_frames_buffered_; 68 uint32_t first_timestamp_in_buffer_; 69 const std::unique_ptr<EncoderState[]> encoders_; 70 Buffer interleave_buffer_; 71 }; 72 73 } // namespace webrtc 74 #endif // MODULES_AUDIO_CODING_CODECS_G722_AUDIO_ENCODER_G722_H_