| 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 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 int AudioEncoderPcm::SampleRateHz() const { | 54 int AudioEncoderPcm::SampleRateHz() const { |
| 55 return sample_rate_hz_; | 55 return sample_rate_hz_; |
| 56 } | 56 } |
| 57 | 57 |
| 58 int AudioEncoderPcm::NumChannels() const { | 58 int AudioEncoderPcm::NumChannels() const { |
| 59 return num_channels_; | 59 return num_channels_; |
| 60 } | 60 } |
| 61 | 61 |
| 62 size_t AudioEncoderPcm::MaxEncodedBytes() const { | 62 size_t AudioEncoderPcm::MaxEncodedBytes() const { |
| 63 return full_frame_samples_; | 63 return full_frame_samples_ * BytesPerSample(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 int AudioEncoderPcm::Num10MsFramesInNextPacket() const { | 66 int AudioEncoderPcm::Num10MsFramesInNextPacket() const { |
| 67 return num_10ms_frames_per_packet_; | 67 return num_10ms_frames_per_packet_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 int AudioEncoderPcm::Max10MsFramesInAPacket() const { | 70 int AudioEncoderPcm::Max10MsFramesInAPacket() const { |
| 71 return num_10ms_frames_per_packet_; | 71 return num_10ms_frames_per_packet_; |
| 72 } | 72 } |
| 73 | 73 |
| 74 int AudioEncoderPcm::GetTargetBitrate() const { |
| 75 return 8 * BytesPerSample() * SampleRateHz() * NumChannels(); |
| 76 } |
| 77 |
| 74 AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeInternal( | 78 AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeInternal( |
| 75 uint32_t rtp_timestamp, | 79 uint32_t rtp_timestamp, |
| 76 const int16_t* audio, | 80 const int16_t* audio, |
| 77 size_t max_encoded_bytes, | 81 size_t max_encoded_bytes, |
| 78 uint8_t* encoded) { | 82 uint8_t* encoded) { |
| 79 const int num_samples = SampleRateHz() / 100 * NumChannels(); | 83 const int num_samples = SampleRateHz() / 100 * NumChannels(); |
| 80 if (speech_buffer_.empty()) { | 84 if (speech_buffer_.empty()) { |
| 81 first_timestamp_in_buffer_ = rtp_timestamp; | 85 first_timestamp_in_buffer_ = rtp_timestamp; |
| 82 } | 86 } |
| 83 for (int i = 0; i < num_samples; ++i) { | 87 for (int i = 0; i < num_samples; ++i) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 97 speech_buffer_.clear(); | 101 speech_buffer_.clear(); |
| 98 return info; | 102 return info; |
| 99 } | 103 } |
| 100 | 104 |
| 101 int16_t AudioEncoderPcmA::EncodeCall(const int16_t* audio, | 105 int16_t AudioEncoderPcmA::EncodeCall(const int16_t* audio, |
| 102 size_t input_len, | 106 size_t input_len, |
| 103 uint8_t* encoded) { | 107 uint8_t* encoded) { |
| 104 return WebRtcG711_EncodeA(audio, static_cast<int16_t>(input_len), encoded); | 108 return WebRtcG711_EncodeA(audio, static_cast<int16_t>(input_len), encoded); |
| 105 } | 109 } |
| 106 | 110 |
| 111 int AudioEncoderPcmA::BytesPerSample() const { |
| 112 return 1; |
| 113 } |
| 114 |
| 107 int16_t AudioEncoderPcmU::EncodeCall(const int16_t* audio, | 115 int16_t AudioEncoderPcmU::EncodeCall(const int16_t* audio, |
| 108 size_t input_len, | 116 size_t input_len, |
| 109 uint8_t* encoded) { | 117 uint8_t* encoded) { |
| 110 return WebRtcG711_EncodeU(audio, static_cast<int16_t>(input_len), encoded); | 118 return WebRtcG711_EncodeU(audio, static_cast<int16_t>(input_len), encoded); |
| 111 } | 119 } |
| 112 | 120 |
| 121 int AudioEncoderPcmU::BytesPerSample() const { |
| 122 return 1; |
| 123 } |
| 124 |
| 113 namespace { | 125 namespace { |
| 114 template <typename T> | 126 template <typename T> |
| 115 typename T::Config CreateConfig(const CodecInst& codec_inst) { | 127 typename T::Config CreateConfig(const CodecInst& codec_inst) { |
| 116 typename T::Config config; | 128 typename T::Config config; |
| 117 config.frame_size_ms = codec_inst.pacsize / 8; | 129 config.frame_size_ms = codec_inst.pacsize / 8; |
| 118 config.num_channels = codec_inst.channels; | 130 config.num_channels = codec_inst.channels; |
| 119 config.payload_type = codec_inst.pltype; | 131 config.payload_type = codec_inst.pltype; |
| 120 return config; | 132 return config; |
| 121 } | 133 } |
| 122 } // namespace | 134 } // namespace |
| 123 | 135 |
| 124 AudioEncoderMutablePcmU::AudioEncoderMutablePcmU(const CodecInst& codec_inst) | 136 AudioEncoderMutablePcmU::AudioEncoderMutablePcmU(const CodecInst& codec_inst) |
| 125 : AudioEncoderMutableImpl<AudioEncoderPcmU>( | 137 : AudioEncoderMutableImpl<AudioEncoderPcmU>( |
| 126 CreateConfig<AudioEncoderPcmU>(codec_inst)) { | 138 CreateConfig<AudioEncoderPcmU>(codec_inst)) { |
| 127 } | 139 } |
| 128 | 140 |
| 129 AudioEncoderMutablePcmA::AudioEncoderMutablePcmA(const CodecInst& codec_inst) | 141 AudioEncoderMutablePcmA::AudioEncoderMutablePcmA(const CodecInst& codec_inst) |
| 130 : AudioEncoderMutableImpl<AudioEncoderPcmA>( | 142 : AudioEncoderMutableImpl<AudioEncoderPcmA>( |
| 131 CreateConfig<AudioEncoderPcmA>(codec_inst)) { | 143 CreateConfig<AudioEncoderPcmA>(codec_inst)) { |
| 132 } | 144 } |
| 133 | 145 |
| 134 } // namespace webrtc | 146 } // namespace webrtc |
| OLD | NEW |