| 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> | 
|   11 #include <string> |   11 #include <string> | 
|   12  |   12  | 
|   13 #include "base/bind.h" |   13 #include "base/bind.h" | 
|   14 #include "base/bind_helpers.h" |   14 #include "base/bind_helpers.h" | 
|   15 #include "base/location.h" |   15 #include "base/location.h" | 
|   16 #include "base/macros.h" |   16 #include "base/macros.h" | 
|   17 #include "base/stl_util.h" |   17 #include "base/stl_util.h" | 
|   18 #include "base/sys_byteorder.h" |   18 #include "base/sys_byteorder.h" | 
|   19 #include "base/time/time.h" |   19 #include "base/time/time.h" | 
|   20 #include "base/trace_event/trace_event.h" |   20 #include "base/trace_event/trace_event.h" | 
|   21 #include "build/build_config.h" |   21 #include "build/build_config.h" | 
 |   22 #include "media/base/audio_sample_types.h" | 
|   22 #include "media/cast/common/rtp_time.h" |   23 #include "media/cast/common/rtp_time.h" | 
|   23 #include "media/cast/constants.h" |   24 #include "media/cast/constants.h" | 
|   24  |   25  | 
|   25 #if !defined(OS_IOS) |   26 #if !defined(OS_IOS) | 
|   26 #include "third_party/opus/src/include/opus.h" |   27 #include "third_party/opus/src/include/opus.h" | 
|   27 #endif |   28 #endif | 
|   28  |   29  | 
|   29 #if defined(OS_MACOSX) |   30 #if defined(OS_MACOSX) | 
|   30 #include <AudioToolbox/AudioToolbox.h> |   31 #include <AudioToolbox/AudioToolbox.h> | 
|   31 #endif |   32 #endif | 
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  274              OPUS_OK); |  275              OPUS_OK); | 
|  275   } |  276   } | 
|  276  |  277  | 
|  277  private: |  278  private: | 
|  278   ~OpusImpl() final {} |  279   ~OpusImpl() final {} | 
|  279  |  280  | 
|  280   void TransferSamplesIntoBuffer(const AudioBus* audio_bus, |  281   void TransferSamplesIntoBuffer(const AudioBus* audio_bus, | 
|  281                                  int source_offset, |  282                                  int source_offset, | 
|  282                                  int buffer_fill_offset, |  283                                  int buffer_fill_offset, | 
|  283                                  int num_samples) final { |  284                                  int num_samples) final { | 
|  284     // Opus requires channel-interleaved samples in a single array. |  285     DCHECK_EQ(audio_bus->channels(), num_channels_); | 
|  285     for (int ch = 0; ch < audio_bus->channels(); ++ch) { |  286     float* dest = buffer_.get() + (buffer_fill_offset * num_channels_); | 
|  286       const float* src = audio_bus->channel(ch) + source_offset; |  287     audio_bus->ToInterleavedPartial<Float32SampleTypeTraits>(source_offset, | 
|  287       const float* const src_end = src + num_samples; |  288                                                              num_samples, dest); | 
|  288       float* dest = buffer_.get() + buffer_fill_offset * num_channels_ + ch; |  | 
|  289       for (; src < src_end; ++src, dest += num_channels_) |  | 
|  290         *dest = *src; |  | 
|  291     } |  | 
|  292   } |  289   } | 
|  293  |  290  | 
|  294   bool EncodeFromFilledBuffer(std::string* out) final { |  291   bool EncodeFromFilledBuffer(std::string* out) final { | 
|  295     out->resize(kOpusMaxPayloadSize); |  292     out->resize(kOpusMaxPayloadSize); | 
|  296     const opus_int32 result = opus_encode_float( |  293     const opus_int32 result = opus_encode_float( | 
|  297         opus_encoder_, buffer_.get(), samples_per_frame_, |  294         opus_encoder_, buffer_.get(), samples_per_frame_, | 
|  298         reinterpret_cast<uint8_t*>(string_as_array(out)), kOpusMaxPayloadSize); |  295         reinterpret_cast<uint8_t*>(string_as_array(out)), kOpusMaxPayloadSize); | 
|  299     if (result > 1) { |  296     if (result > 1) { | 
|  300       out->resize(result); |  297       out->resize(result); | 
|  301       return true; |  298       return true; | 
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  838   cast_environment_->PostTask(CastEnvironment::AUDIO, |  835   cast_environment_->PostTask(CastEnvironment::AUDIO, | 
|  839                               FROM_HERE, |  836                               FROM_HERE, | 
|  840                               base::Bind(&AudioEncoder::ImplBase::EncodeAudio, |  837                               base::Bind(&AudioEncoder::ImplBase::EncodeAudio, | 
|  841                                          impl_, |  838                                          impl_, | 
|  842                                          base::Passed(&audio_bus), |  839                                          base::Passed(&audio_bus), | 
|  843                                          recorded_time)); |  840                                          recorded_time)); | 
|  844 } |  841 } | 
|  845  |  842  | 
|  846 }  // namespace cast |  843 }  // namespace cast | 
|  847 }  // namespace media |  844 }  // namespace media | 
| OLD | NEW |