| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/audio_renderer_impl.h" | 5 #include "media/filters/audio_renderer_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 int bytes_per_frame = audio_parameters_.GetBytesPerFrame(); | 347 int bytes_per_frame = audio_parameters_.GetBytesPerFrame(); |
| 348 | 348 |
| 349 const int buf_size = audio_bus->frames() * bytes_per_frame; | 349 const int buf_size = audio_bus->frames() * bytes_per_frame; |
| 350 scoped_array<uint8> buf(new uint8[buf_size]); | 350 scoped_array<uint8> buf(new uint8[buf_size]); |
| 351 | 351 |
| 352 int frames_filled = FillBuffer(buf.get(), audio_bus->frames(), request_delay); | 352 int frames_filled = FillBuffer(buf.get(), audio_bus->frames(), request_delay); |
| 353 int bytes_filled = frames_filled * bytes_per_frame; | 353 int bytes_filled = frames_filled * bytes_per_frame; |
| 354 DCHECK_LE(bytes_filled, buf_size); | 354 DCHECK_LE(bytes_filled, buf_size); |
| 355 UpdateEarliestEndTime(bytes_filled, request_delay, base::Time::Now()); | 355 UpdateEarliestEndTime(bytes_filled, request_delay, base::Time::Now()); |
| 356 | 356 |
| 357 // Deinterleave each audio channel. | 357 // Deinterleave audio data into the output bus. |
| 358 int channels = audio_bus->channels(); | 358 audio_bus->FromInterleaved( |
| 359 for (int channel_index = 0; channel_index < channels; ++channel_index) { | 359 buf.get(), frames_filled, audio_parameters_.bits_per_sample() / 8); |
| 360 media::DeinterleaveAudioChannel(buf.get(), | |
| 361 audio_bus->channel(channel_index), | |
| 362 channels, | |
| 363 channel_index, | |
| 364 bytes_per_frame / channels, | |
| 365 frames_filled); | |
| 366 | 360 |
| 367 // If FillBuffer() didn't give us enough data then zero out the remainder. | |
| 368 if (frames_filled < audio_bus->frames()) { | |
| 369 int frames_to_zero = audio_bus->frames() - frames_filled; | |
| 370 memset(audio_bus->channel(channel_index) + frames_filled, 0, | |
| 371 sizeof(*audio_bus->channel(channel_index)) * frames_to_zero); | |
| 372 } | |
| 373 } | |
| 374 return frames_filled; | 361 return frames_filled; |
| 375 } | 362 } |
| 376 | 363 |
| 377 uint32 AudioRendererImpl::FillBuffer(uint8* dest, | 364 uint32 AudioRendererImpl::FillBuffer(uint8* dest, |
| 378 uint32 requested_frames, | 365 uint32 requested_frames, |
| 379 const base::TimeDelta& playback_delay) { | 366 const base::TimeDelta& playback_delay) { |
| 380 base::TimeDelta current_time = kNoTimestamp(); | 367 base::TimeDelta current_time = kNoTimestamp(); |
| 381 base::TimeDelta max_time = kNoTimestamp(); | 368 base::TimeDelta max_time = kNoTimestamp(); |
| 382 | 369 |
| 383 size_t frames_written = 0; | 370 size_t frames_written = 0; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 case kUnderflow: | 518 case kUnderflow: |
| 532 case kRebuffering: | 519 case kRebuffering: |
| 533 case kStopped: | 520 case kStopped: |
| 534 if (status != PIPELINE_OK) | 521 if (status != PIPELINE_OK) |
| 535 error_cb_.Run(status); | 522 error_cb_.Run(status); |
| 536 return; | 523 return; |
| 537 } | 524 } |
| 538 } | 525 } |
| 539 | 526 |
| 540 } // namespace media | 527 } // namespace media |
| OLD | NEW |