Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1057)

Side by Side Diff: media/cast/sender/audio_encoder.cc

Issue 1769373003: AudioBus: Add a ToInterleavedFloat() method to AudioBus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 OPUS_OK); 276 OPUS_OK);
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 DCHECK_EQ(audio_bus->channels(), num_channels_);
mcasas 2016/04/11 23:47:08 nit: Expected value goes first, and I think in th
286 // Opus requires channel-interleaved samples in a single array. 287 // Opus requires channel-interleaved samples in a single array.
287 for (int ch = 0; ch < audio_bus->channels(); ++ch) { 288 audio_bus->ToInterleavedFloat(source_offset,
288 const float* src = audio_bus->channel(ch) + source_offset; 289 buffer_fill_offset * num_channels_,
289 const float* const src_end = src + num_samples; 290 num_samples, 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 } 291 }
295 292
296 bool EncodeFromFilledBuffer(std::string* out) final { 293 bool EncodeFromFilledBuffer(std::string* out) final {
297 out->resize(kOpusMaxPayloadSize); 294 out->resize(kOpusMaxPayloadSize);
298 const opus_int32 result = opus_encode_float( 295 const opus_int32 result = opus_encode_float(
299 opus_encoder_, buffer_.get(), samples_per_frame_, 296 opus_encoder_, buffer_.get(), samples_per_frame_,
300 reinterpret_cast<uint8_t*>(string_as_array(out)), kOpusMaxPayloadSize); 297 reinterpret_cast<uint8_t*>(string_as_array(out)), kOpusMaxPayloadSize);
301 if (result > 1) { 298 if (result > 1) {
302 out->resize(result); 299 out->resize(result);
303 return true; 300 return true;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 cast_environment_->PostTask(CastEnvironment::AUDIO, 865 cast_environment_->PostTask(CastEnvironment::AUDIO,
869 FROM_HERE, 866 FROM_HERE,
870 base::Bind(&AudioEncoder::ImplBase::EncodeAudio, 867 base::Bind(&AudioEncoder::ImplBase::EncodeAudio,
871 impl_, 868 impl_,
872 base::Passed(&audio_bus), 869 base::Passed(&audio_bus),
873 recorded_time)); 870 recorded_time));
874 } 871 }
875 872
876 } // namespace cast 873 } // namespace cast
877 } // namespace media 874 } // namespace media
OLDNEW
« media/base/audio_bus_unittest.cc ('K') | « media/base/audio_bus_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698