| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 CHECK_EQ(opus_encoder_ctl(opus_encoder_, OPUS_SET_BITRATE(bitrate)), | 235 CHECK_EQ(opus_encoder_ctl(opus_encoder_, OPUS_SET_BITRATE(bitrate)), |
| 236 OPUS_OK); | 236 OPUS_OK); |
| 237 } | 237 } |
| 238 | 238 |
| 239 private: | 239 private: |
| 240 virtual ~OpusImpl() {} | 240 virtual ~OpusImpl() {} |
| 241 | 241 |
| 242 virtual void TransferSamplesIntoBuffer(const AudioBus* audio_bus, | 242 virtual void TransferSamplesIntoBuffer(const AudioBus* audio_bus, |
| 243 int source_offset, | 243 int source_offset, |
| 244 int buffer_fill_offset, | 244 int buffer_fill_offset, |
| 245 int num_samples) OVERRIDE { | 245 int num_samples) override { |
| 246 // Opus requires channel-interleaved samples in a single array. | 246 // Opus requires channel-interleaved samples in a single array. |
| 247 for (int ch = 0; ch < audio_bus->channels(); ++ch) { | 247 for (int ch = 0; ch < audio_bus->channels(); ++ch) { |
| 248 const float* src = audio_bus->channel(ch) + source_offset; | 248 const float* src = audio_bus->channel(ch) + source_offset; |
| 249 const float* const src_end = src + num_samples; | 249 const float* const src_end = src + num_samples; |
| 250 float* dest = buffer_.get() + buffer_fill_offset * num_channels_ + ch; | 250 float* dest = buffer_.get() + buffer_fill_offset * num_channels_ + ch; |
| 251 for (; src < src_end; ++src, dest += num_channels_) | 251 for (; src < src_end; ++src, dest += num_channels_) |
| 252 *dest = *src; | 252 *dest = *src; |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 virtual bool EncodeFromFilledBuffer(std::string* out) OVERRIDE { | 256 virtual bool EncodeFromFilledBuffer(std::string* out) override { |
| 257 out->resize(kOpusMaxPayloadSize); | 257 out->resize(kOpusMaxPayloadSize); |
| 258 const opus_int32 result = | 258 const opus_int32 result = |
| 259 opus_encode_float(opus_encoder_, | 259 opus_encode_float(opus_encoder_, |
| 260 buffer_.get(), | 260 buffer_.get(), |
| 261 samples_per_frame_, | 261 samples_per_frame_, |
| 262 reinterpret_cast<uint8*>(string_as_array(out)), | 262 reinterpret_cast<uint8*>(string_as_array(out)), |
| 263 kOpusMaxPayloadSize); | 263 kOpusMaxPayloadSize); |
| 264 if (result > 1) { | 264 if (result > 1) { |
| 265 out->resize(result); | 265 out->resize(result); |
| 266 return true; | 266 return true; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 return; | 305 return; |
| 306 cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; | 306 cast_initialization_status_ = STATUS_AUDIO_INITIALIZED; |
| 307 } | 307 } |
| 308 | 308 |
| 309 private: | 309 private: |
| 310 virtual ~Pcm16Impl() {} | 310 virtual ~Pcm16Impl() {} |
| 311 | 311 |
| 312 virtual void TransferSamplesIntoBuffer(const AudioBus* audio_bus, | 312 virtual void TransferSamplesIntoBuffer(const AudioBus* audio_bus, |
| 313 int source_offset, | 313 int source_offset, |
| 314 int buffer_fill_offset, | 314 int buffer_fill_offset, |
| 315 int num_samples) OVERRIDE { | 315 int num_samples) override { |
| 316 audio_bus->ToInterleavedPartial( | 316 audio_bus->ToInterleavedPartial( |
| 317 source_offset, | 317 source_offset, |
| 318 num_samples, | 318 num_samples, |
| 319 sizeof(int16), | 319 sizeof(int16), |
| 320 buffer_.get() + buffer_fill_offset * num_channels_); | 320 buffer_.get() + buffer_fill_offset * num_channels_); |
| 321 } | 321 } |
| 322 | 322 |
| 323 virtual bool EncodeFromFilledBuffer(std::string* out) OVERRIDE { | 323 virtual bool EncodeFromFilledBuffer(std::string* out) override { |
| 324 // Output 16-bit PCM integers in big-endian byte order. | 324 // Output 16-bit PCM integers in big-endian byte order. |
| 325 out->resize(num_channels_ * samples_per_frame_ * sizeof(int16)); | 325 out->resize(num_channels_ * samples_per_frame_ * sizeof(int16)); |
| 326 const int16* src = buffer_.get(); | 326 const int16* src = buffer_.get(); |
| 327 const int16* const src_end = src + num_channels_ * samples_per_frame_; | 327 const int16* const src_end = src + num_channels_ * samples_per_frame_; |
| 328 uint16* dest = reinterpret_cast<uint16*>(&out->at(0)); | 328 uint16* dest = reinterpret_cast<uint16*>(&out->at(0)); |
| 329 for (; src < src_end; ++src, ++dest) | 329 for (; src < src_end; ++src, ++dest) |
| 330 *dest = base::HostToNet16(*src); | 330 *dest = base::HostToNet16(*src); |
| 331 return true; | 331 return true; |
| 332 } | 332 } |
| 333 | 333 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 cast_environment_->PostTask(CastEnvironment::AUDIO, | 398 cast_environment_->PostTask(CastEnvironment::AUDIO, |
| 399 FROM_HERE, | 399 FROM_HERE, |
| 400 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, | 400 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, |
| 401 impl_, | 401 impl_, |
| 402 base::Passed(&audio_bus), | 402 base::Passed(&audio_bus), |
| 403 recorded_time)); | 403 recorded_time)); |
| 404 } | 404 } |
| 405 | 405 |
| 406 } // namespace cast | 406 } // namespace cast |
| 407 } // namespace media | 407 } // namespace media |
| OLD | NEW |