| 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_G711_INCLUDE_AUDIO_ENCODER_PCM_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_INCLUDE_AUDIO_ENCODER_PCM_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_INCLUDE_AUDIO_ENCODER_PCM_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_INCLUDE_AUDIO_ENCODER_PCM_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/modules/audio_coding/codecs/audio_encoder.h" | 17 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
| 18 #include "webrtc/modules/audio_coding/codecs/audio_encoder_mutable_impl.h" | |
| 19 | 18 |
| 20 namespace webrtc { | 19 namespace webrtc { |
| 21 | 20 |
| 22 class AudioEncoderPcm : public AudioEncoder { | 21 class AudioEncoderPcm : public AudioEncoder { |
| 23 public: | 22 public: |
| 24 struct Config { | 23 struct Config { |
| 25 public: | 24 public: |
| 26 bool IsOk() const; | 25 bool IsOk() const; |
| 27 | 26 |
| 28 int frame_size_ms; | 27 int frame_size_ms; |
| 29 int num_channels; | 28 int num_channels; |
| 30 int payload_type; | 29 int payload_type; |
| 31 | 30 |
| 32 protected: | 31 protected: |
| 33 explicit Config(int pt) | 32 explicit Config(int pt) |
| 34 : frame_size_ms(20), num_channels(1), payload_type(pt) {} | 33 : frame_size_ms(20), num_channels(1), payload_type(pt) {} |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 ~AudioEncoderPcm() override; | 36 ~AudioEncoderPcm() override; |
| 38 | 37 |
| 38 size_t MaxEncodedBytes() const override; |
| 39 int SampleRateHz() const override; | 39 int SampleRateHz() const override; |
| 40 int NumChannels() const override; | 40 int NumChannels() const override; |
| 41 size_t MaxEncodedBytes() const override; | |
| 42 size_t Num10MsFramesInNextPacket() const override; | 41 size_t Num10MsFramesInNextPacket() const override; |
| 43 size_t Max10MsFramesInAPacket() const override; | 42 size_t Max10MsFramesInAPacket() const override; |
| 44 int GetTargetBitrate() const override; | 43 int GetTargetBitrate() const override; |
| 45 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, | 44 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, |
| 46 const int16_t* audio, | 45 const int16_t* audio, |
| 47 size_t max_encoded_bytes, | 46 size_t max_encoded_bytes, |
| 48 uint8_t* encoded) override; | 47 uint8_t* encoded) override; |
| 48 void Reset() override; |
| 49 | 49 |
| 50 protected: | 50 protected: |
| 51 AudioEncoderPcm(const Config& config, int sample_rate_hz); | 51 AudioEncoderPcm(const Config& config, int sample_rate_hz); |
| 52 | 52 |
| 53 virtual size_t EncodeCall(const int16_t* audio, | 53 virtual size_t EncodeCall(const int16_t* audio, |
| 54 size_t input_len, | 54 size_t input_len, |
| 55 uint8_t* encoded) = 0; | 55 uint8_t* encoded) = 0; |
| 56 | 56 |
| 57 virtual int BytesPerSample() const = 0; | 57 virtual int BytesPerSample() const = 0; |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 const int sample_rate_hz_; | 60 const int sample_rate_hz_; |
| 61 const int num_channels_; | 61 const int num_channels_; |
| 62 const int payload_type_; | 62 const int payload_type_; |
| 63 const size_t num_10ms_frames_per_packet_; | 63 const size_t num_10ms_frames_per_packet_; |
| 64 const size_t full_frame_samples_; | 64 const size_t full_frame_samples_; |
| 65 std::vector<int16_t> speech_buffer_; | 65 std::vector<int16_t> speech_buffer_; |
| 66 uint32_t first_timestamp_in_buffer_; | 66 uint32_t first_timestamp_in_buffer_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 struct CodecInst; |
| 70 |
| 69 class AudioEncoderPcmA final : public AudioEncoderPcm { | 71 class AudioEncoderPcmA final : public AudioEncoderPcm { |
| 70 public: | 72 public: |
| 71 struct Config : public AudioEncoderPcm::Config { | 73 struct Config : public AudioEncoderPcm::Config { |
| 72 Config() : AudioEncoderPcm::Config(8) {} | 74 Config() : AudioEncoderPcm::Config(8) {} |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 explicit AudioEncoderPcmA(const Config& config) | 77 explicit AudioEncoderPcmA(const Config& config) |
| 76 : AudioEncoderPcm(config, kSampleRateHz) {} | 78 : AudioEncoderPcm(config, kSampleRateHz) {} |
| 79 explicit AudioEncoderPcmA(const CodecInst& codec_inst); |
| 77 | 80 |
| 78 protected: | 81 protected: |
| 79 size_t EncodeCall(const int16_t* audio, | 82 size_t EncodeCall(const int16_t* audio, |
| 80 size_t input_len, | 83 size_t input_len, |
| 81 uint8_t* encoded) override; | 84 uint8_t* encoded) override; |
| 82 | 85 |
| 83 int BytesPerSample() const override; | 86 int BytesPerSample() const override; |
| 84 | 87 |
| 85 private: | 88 private: |
| 86 static const int kSampleRateHz = 8000; | 89 static const int kSampleRateHz = 8000; |
| 87 }; | 90 }; |
| 88 | 91 |
| 89 class AudioEncoderPcmU final : public AudioEncoderPcm { | 92 class AudioEncoderPcmU final : public AudioEncoderPcm { |
| 90 public: | 93 public: |
| 91 struct Config : public AudioEncoderPcm::Config { | 94 struct Config : public AudioEncoderPcm::Config { |
| 92 Config() : AudioEncoderPcm::Config(0) {} | 95 Config() : AudioEncoderPcm::Config(0) {} |
| 93 }; | 96 }; |
| 94 | 97 |
| 95 explicit AudioEncoderPcmU(const Config& config) | 98 explicit AudioEncoderPcmU(const Config& config) |
| 96 : AudioEncoderPcm(config, kSampleRateHz) {} | 99 : AudioEncoderPcm(config, kSampleRateHz) {} |
| 100 explicit AudioEncoderPcmU(const CodecInst& codec_inst); |
| 97 | 101 |
| 98 protected: | 102 protected: |
| 99 size_t EncodeCall(const int16_t* audio, | 103 size_t EncodeCall(const int16_t* audio, |
| 100 size_t input_len, | 104 size_t input_len, |
| 101 uint8_t* encoded) override; | 105 uint8_t* encoded) override; |
| 102 | 106 |
| 103 int BytesPerSample() const override; | 107 int BytesPerSample() const override; |
| 104 | 108 |
| 105 private: | 109 private: |
| 106 static const int kSampleRateHz = 8000; | 110 static const int kSampleRateHz = 8000; |
| 107 }; | 111 }; |
| 108 | 112 |
| 109 struct CodecInst; | |
| 110 | |
| 111 class AudioEncoderMutablePcmU | |
| 112 : public AudioEncoderMutableImpl<AudioEncoderPcmU> { | |
| 113 public: | |
| 114 explicit AudioEncoderMutablePcmU(const CodecInst& codec_inst); | |
| 115 }; | |
| 116 | |
| 117 class AudioEncoderMutablePcmA | |
| 118 : public AudioEncoderMutableImpl<AudioEncoderPcmA> { | |
| 119 public: | |
| 120 explicit AudioEncoderMutablePcmA(const CodecInst& codec_inst); | |
| 121 }; | |
| 122 | |
| 123 } // namespace webrtc | 113 } // namespace webrtc |
| 124 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_INCLUDE_AUDIO_ENCODER_PCM_H_ | 114 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_G711_INCLUDE_AUDIO_ENCODER_PCM_H_ |
| OLD | NEW |