| 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 // THREAD SAFETY | 5 // THREAD SAFETY |
| 6 // | 6 // |
| 7 // AlsaPcmOutputStream object is *not* thread-safe and should only be used | 7 // AlsaPcmOutputStream object is *not* thread-safe and should only be used |
| 8 // from the audio thread. We DCHECK on this assumption whenever we can. | 8 // from the audio thread. We DCHECK on this assumption whenever we can. |
| 9 // | 9 // |
| 10 // SEMANTICS OF Close() | 10 // SEMANTICS OF Close() |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 int packet_size = RunDataCallback(packet->GetWritableData(), | 378 int packet_size = RunDataCallback(packet->GetWritableData(), |
| 379 packet->GetBufferSize(), | 379 packet->GetBufferSize(), |
| 380 AudioBuffersState(buffer_delay, | 380 AudioBuffersState(buffer_delay, |
| 381 hardware_delay)); | 381 hardware_delay)); |
| 382 CHECK_LE(packet_size, packet->GetBufferSize()); | 382 CHECK_LE(packet_size, packet->GetBufferSize()); |
| 383 | 383 |
| 384 // This should not happen, but in case it does, drop any trailing bytes | 384 // This should not happen, but in case it does, drop any trailing bytes |
| 385 // that aren't large enough to make a frame. Without this, packet writing | 385 // that aren't large enough to make a frame. Without this, packet writing |
| 386 // may stall because the last few bytes in the packet may never get used by | 386 // may stall because the last few bytes in the packet may never get used by |
| 387 // WritePacket. | 387 // WritePacket. |
| 388 DCHECK(packet_size % bytes_per_frame_ == 0); | 388 DCHECK_EQ(0u, packet_size % bytes_per_frame_); |
| 389 packet_size = (packet_size / bytes_per_frame_) * bytes_per_frame_; | 389 packet_size = (packet_size / bytes_per_frame_) * bytes_per_frame_; |
| 390 | 390 |
| 391 if (should_downmix_) { | 391 if (should_downmix_) { |
| 392 if (media::FoldChannels(packet->GetWritableData(), | 392 if (media::FoldChannels(packet->GetWritableData(), |
| 393 packet_size, | 393 packet_size, |
| 394 channels_, | 394 channels_, |
| 395 bytes_per_sample_, | 395 bytes_per_sample_, |
| 396 volume_)) { | 396 volume_)) { |
| 397 // Adjust packet size for downmix. | 397 // Adjust packet size for downmix. |
| 398 packet_size = packet_size / bytes_per_frame_ * bytes_per_output_frame_; | 398 packet_size = packet_size / bytes_per_frame_ * bytes_per_output_frame_; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 return !manager_->GetMessageLoop() || | 785 return !manager_->GetMessageLoop() || |
| 786 manager_->GetMessageLoop()->BelongsToCurrentThread(); | 786 manager_->GetMessageLoop()->BelongsToCurrentThread(); |
| 787 } | 787 } |
| 788 | 788 |
| 789 uint32 AlsaPcmOutputStream::RunDataCallback(uint8* dest, | 789 uint32 AlsaPcmOutputStream::RunDataCallback(uint8* dest, |
| 790 uint32 max_size, | 790 uint32 max_size, |
| 791 AudioBuffersState buffers_state) { | 791 AudioBuffersState buffers_state) { |
| 792 TRACE_EVENT0("audio", "AlsaPcmOutputStream::RunDataCallback"); | 792 TRACE_EVENT0("audio", "AlsaPcmOutputStream::RunDataCallback"); |
| 793 | 793 |
| 794 if (source_callback_) | 794 if (source_callback_) |
| 795 return source_callback_->OnMoreData(this, dest, max_size, buffers_state); | 795 return source_callback_->OnMoreData(dest, max_size, buffers_state); |
| 796 | 796 |
| 797 return 0; | 797 return 0; |
| 798 } | 798 } |
| 799 | 799 |
| 800 void AlsaPcmOutputStream::RunErrorCallback(int code) { | 800 void AlsaPcmOutputStream::RunErrorCallback(int code) { |
| 801 if (source_callback_) | 801 if (source_callback_) |
| 802 source_callback_->OnError(this, code); | 802 source_callback_->OnError(this, code); |
| 803 } | 803 } |
| 804 | 804 |
| 805 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to | 805 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to |
| 806 // release ownership of the currently registered callback. | 806 // release ownership of the currently registered callback. |
| 807 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { | 807 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { |
| 808 DCHECK(IsOnAudioThread()); | 808 DCHECK(IsOnAudioThread()); |
| 809 source_callback_ = callback; | 809 source_callback_ = callback; |
| 810 } | 810 } |
| 811 | 811 |
| 812 } // namespace media | 812 } // namespace media |
| OLD | NEW |