OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/cast/sender/audio_encoder.h" | 5 #include "media/cast/sender/audio_encoder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 | 278 |
279 private: | 279 private: |
280 ~OpusImpl() final {} | 280 ~OpusImpl() final {} |
281 | 281 |
282 void TransferSamplesIntoBuffer(const AudioBus* audio_bus, | 282 void TransferSamplesIntoBuffer(const AudioBus* audio_bus, |
283 int source_offset, | 283 int source_offset, |
284 int buffer_fill_offset, | 284 int buffer_fill_offset, |
285 int num_samples) final { | 285 int num_samples) final { |
286 // Opus requires channel-interleaved samples in a single array. | 286 // Opus requires channel-interleaved samples in a single array. |
287 for (int ch = 0; ch < audio_bus->channels(); ++ch) { | 287 audio_bus->ToInterleavedFloat(source_offset, |
288 const float* src = audio_bus->channel(ch) + source_offset; | 288 buffer_fill_offset * num_channels_, |
289 const float* const src_end = src + num_samples; | 289 num_samples, num_channels_, buffer_.get()); |
290 float* dest = buffer_.get() + buffer_fill_offset * num_channels_ + ch; | |
291 for (; src < src_end; ++src, dest += num_channels_) | |
292 *dest = *src; | |
293 } | |
294 } | 290 } |
295 | 291 |
296 bool EncodeFromFilledBuffer(std::string* out) final { | 292 bool EncodeFromFilledBuffer(std::string* out) final { |
297 out->resize(kOpusMaxPayloadSize); | 293 out->resize(kOpusMaxPayloadSize); |
298 const opus_int32 result = opus_encode_float( | 294 const opus_int32 result = opus_encode_float( |
299 opus_encoder_, buffer_.get(), samples_per_frame_, | 295 opus_encoder_, buffer_.get(), samples_per_frame_, |
300 reinterpret_cast<uint8_t*>(string_as_array(out)), kOpusMaxPayloadSize); | 296 reinterpret_cast<uint8_t*>(string_as_array(out)), kOpusMaxPayloadSize); |
301 if (result > 1) { | 297 if (result > 1) { |
302 out->resize(result); | 298 out->resize(result); |
303 return true; | 299 return true; |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 cast_environment_->PostTask(CastEnvironment::AUDIO, | 864 cast_environment_->PostTask(CastEnvironment::AUDIO, |
869 FROM_HERE, | 865 FROM_HERE, |
870 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, | 866 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, |
871 impl_, | 867 impl_, |
872 base::Passed(&audio_bus), | 868 base::Passed(&audio_bus), |
873 recorded_time)); | 869 recorded_time)); |
874 } | 870 } |
875 | 871 |
876 } // namespace cast | 872 } // namespace cast |
877 } // namespace media | 873 } // namespace media |
OLD | NEW |