| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 DCHECK_EQ(audio_bus->channels(), num_channels_); | 285 DCHECK_EQ(audio_bus->channels(), num_channels_); |
| 286 float* dest = buffer_.get() + (buffer_fill_offset * num_channels_); | 286 float* dest = buffer_.get() + (buffer_fill_offset * num_channels_); |
| 287 audio_bus->ToInterleavedPartial<Float32SampleTypeTraits>(source_offset, | 287 audio_bus->ToInterleavedPartial<Float32SampleTypeTraits>(source_offset, |
| 288 num_samples, dest); | 288 num_samples, dest); |
| 289 } | 289 } |
| 290 | 290 |
| 291 bool EncodeFromFilledBuffer(std::string* out) final { | 291 bool EncodeFromFilledBuffer(std::string* out) final { |
| 292 out->resize(kOpusMaxPayloadSize); | 292 out->resize(kOpusMaxPayloadSize); |
| 293 const opus_int32 result = opus_encode_float( | 293 const opus_int32 result = opus_encode_float( |
| 294 opus_encoder_, buffer_.get(), samples_per_frame_, | 294 opus_encoder_, buffer_.get(), samples_per_frame_, |
| 295 reinterpret_cast<uint8_t*>(string_as_array(out)), kOpusMaxPayloadSize); | 295 reinterpret_cast<uint8_t*>(base::string_as_array(out)), |
| 296 kOpusMaxPayloadSize); |
| 296 if (result > 1) { | 297 if (result > 1) { |
| 297 out->resize(result); | 298 out->resize(result); |
| 298 return true; | 299 return true; |
| 299 } else if (result < 0) { | 300 } else if (result < 0) { |
| 300 LOG(ERROR) << "Error code from opus_encode_float(): " << result; | 301 LOG(ERROR) << "Error code from opus_encode_float(): " << result; |
| 301 return false; | 302 return false; |
| 302 } else { | 303 } else { |
| 303 // Do nothing: The documentation says that a return value of zero or | 304 // Do nothing: The documentation says that a return value of zero or |
| 304 // one byte means the packet does not need to be transmitted. | 305 // one byte means the packet does not need to be transmitted. |
| 305 return false; | 306 return false; |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 cast_environment_->PostTask(CastEnvironment::AUDIO, | 836 cast_environment_->PostTask(CastEnvironment::AUDIO, |
| 836 FROM_HERE, | 837 FROM_HERE, |
| 837 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, | 838 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, |
| 838 impl_, | 839 impl_, |
| 839 base::Passed(&audio_bus), | 840 base::Passed(&audio_bus), |
| 840 recorded_time)); | 841 recorded_time)); |
| 841 } | 842 } |
| 842 | 843 |
| 843 } // namespace cast | 844 } // namespace cast |
| 844 } // namespace media | 845 } // namespace media |
| OLD | NEW |