| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/codec/audio_encoder_opus.h" | 5 #include "remoting/codec/audio_encoder_opus.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 resampling_data_ + resampling_data_pos_, | 130 resampling_data_ + resampling_data_pos_, |
| 131 audio_bus->frames(), kBytesPerSample); | 131 audio_bus->frames(), kBytesPerSample); |
| 132 resampling_data_pos_ += audio_bus->frames() * kBytesPerSample * channels_; | 132 resampling_data_pos_ += audio_bus->frames() * kBytesPerSample * channels_; |
| 133 DCHECK_LE(resampling_data_pos_, static_cast<int>(resampling_data_size_)); | 133 DCHECK_LE(resampling_data_pos_, static_cast<int>(resampling_data_size_)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 int AudioEncoderOpus::GetBitrate() { | 136 int AudioEncoderOpus::GetBitrate() { |
| 137 return kOutputBitrateBps; | 137 return kOutputBitrateBps; |
| 138 } | 138 } |
| 139 | 139 |
| 140 scoped_ptr<AudioPacket> AudioEncoderOpus::Encode( | 140 std::unique_ptr<AudioPacket> AudioEncoderOpus::Encode( |
| 141 scoped_ptr<AudioPacket> packet) { | 141 std::unique_ptr<AudioPacket> packet) { |
| 142 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); | 142 DCHECK_EQ(AudioPacket::ENCODING_RAW, packet->encoding()); |
| 143 DCHECK_EQ(1, packet->data_size()); | 143 DCHECK_EQ(1, packet->data_size()); |
| 144 DCHECK_EQ(kBytesPerSample, packet->bytes_per_sample()); | 144 DCHECK_EQ(kBytesPerSample, packet->bytes_per_sample()); |
| 145 | 145 |
| 146 if (!ResetForPacket(packet.get())) { | 146 if (!ResetForPacket(packet.get())) { |
| 147 LOG(ERROR) << "Encoder initialization failed"; | 147 LOG(ERROR) << "Encoder initialization failed"; |
| 148 return nullptr; | 148 return nullptr; |
| 149 } | 149 } |
| 150 | 150 |
| 151 int samples_in_packet = packet->data(0).size() / kBytesPerSample / channels_; | 151 int samples_in_packet = packet->data(0).size() / kBytesPerSample / channels_; |
| 152 const int16_t* next_sample = | 152 const int16_t* next_sample = |
| 153 reinterpret_cast<const int16_t*>(packet->data(0).data()); | 153 reinterpret_cast<const int16_t*>(packet->data(0).data()); |
| 154 | 154 |
| 155 // Create a new packet of encoded data. | 155 // Create a new packet of encoded data. |
| 156 scoped_ptr<AudioPacket> encoded_packet(new AudioPacket()); | 156 std::unique_ptr<AudioPacket> encoded_packet(new AudioPacket()); |
| 157 encoded_packet->set_encoding(AudioPacket::ENCODING_OPUS); | 157 encoded_packet->set_encoding(AudioPacket::ENCODING_OPUS); |
| 158 encoded_packet->set_sampling_rate(kOpusSamplingRate); | 158 encoded_packet->set_sampling_rate(kOpusSamplingRate); |
| 159 encoded_packet->set_channels(channels_); | 159 encoded_packet->set_channels(channels_); |
| 160 | 160 |
| 161 int prefetch_samples = | 161 int prefetch_samples = |
| 162 resampler_.get() ? media::SincResampler::kDefaultRequestSize : 0; | 162 resampler_.get() ? media::SincResampler::kDefaultRequestSize : 0; |
| 163 int samples_wanted = frame_size_ + prefetch_samples; | 163 int samples_wanted = frame_size_ + prefetch_samples; |
| 164 | 164 |
| 165 while (leftover_samples_ + samples_in_packet >= samples_wanted) { | 165 while (leftover_samples_ + samples_in_packet >= samples_wanted) { |
| 166 const int16_t* pcm_buffer = nullptr; | 166 const int16_t* pcm_buffer = nullptr; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 232 } |
| 233 | 233 |
| 234 // Return nullptr if there's nothing in the packet. | 234 // Return nullptr if there's nothing in the packet. |
| 235 if (encoded_packet->data_size() == 0) | 235 if (encoded_packet->data_size() == 0) |
| 236 return nullptr; | 236 return nullptr; |
| 237 | 237 |
| 238 return encoded_packet; | 238 return encoded_packet; |
| 239 } | 239 } |
| 240 | 240 |
| 241 } // namespace remoting | 241 } // namespace remoting |
| OLD | NEW |