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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 LOG(ERROR) << "Failure preparing stream (" | 300 LOG(ERROR) << "Failure preparing stream (" |
301 << wrapper_->PcmName(playback_handle_) << "): " | 301 << wrapper_->PcmName(playback_handle_) << "): " |
302 << wrapper_->StrError(error); | 302 << wrapper_->StrError(error); |
303 stop_stream_ = true; | 303 stop_stream_ = true; |
304 return; | 304 return; |
305 } | 305 } |
306 | 306 |
307 // Ensure the first buffer is silence to avoid startup glitches. | 307 // Ensure the first buffer is silence to avoid startup glitches. |
308 int buffer_size = GetAvailableFrames() * bytes_per_output_frame_; | 308 int buffer_size = GetAvailableFrames() * bytes_per_output_frame_; |
309 scoped_refptr<DataBuffer> silent_packet = new DataBuffer(buffer_size); | 309 scoped_refptr<DataBuffer> silent_packet = new DataBuffer(buffer_size); |
310 silent_packet->SetDataSize(buffer_size); | 310 silent_packet->set_data_size(buffer_size); |
311 memset(silent_packet->GetWritableData(), 0, silent_packet->GetDataSize()); | 311 memset(silent_packet->writable_data(), 0, silent_packet->data_size()); |
312 buffer_->Append(silent_packet); | 312 buffer_->Append(silent_packet); |
313 WritePacket(); | 313 WritePacket(); |
314 | 314 |
315 // Start the callback chain. | 315 // Start the callback chain. |
316 set_source_callback(callback); | 316 set_source_callback(callback); |
317 WriteTask(); | 317 WriteTask(); |
318 } | 318 } |
319 | 319 |
320 void AlsaPcmOutputStream::Stop() { | 320 void AlsaPcmOutputStream::Stop() { |
321 DCHECK(IsOnAudioThread()); | 321 DCHECK(IsOnAudioThread()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 output_bus = mixed_audio_bus_.get(); | 373 output_bus = mixed_audio_bus_.get(); |
374 channel_mixer_->Transform(audio_bus_.get(), output_bus); | 374 channel_mixer_->Transform(audio_bus_.get(), output_bus); |
375 // Adjust packet size for downmix. | 375 // Adjust packet size for downmix. |
376 packet_size = packet_size / bytes_per_frame_ * bytes_per_output_frame_; | 376 packet_size = packet_size / bytes_per_frame_ * bytes_per_output_frame_; |
377 } | 377 } |
378 | 378 |
379 // Note: If this ever changes to output raw float the data must be clipped | 379 // Note: If this ever changes to output raw float the data must be clipped |
380 // and sanitized since it may come from an untrusted source such as NaCl. | 380 // and sanitized since it may come from an untrusted source such as NaCl. |
381 output_bus->Scale(volume_); | 381 output_bus->Scale(volume_); |
382 output_bus->ToInterleaved( | 382 output_bus->ToInterleaved( |
383 frames_filled, bytes_per_sample_, packet->GetWritableData()); | 383 frames_filled, bytes_per_sample_, packet->writable_data()); |
384 | 384 |
385 if (packet_size > 0) { | 385 if (packet_size > 0) { |
386 packet->SetDataSize(packet_size); | 386 packet->set_data_size(packet_size); |
387 // Add the packet to the buffer. | 387 // Add the packet to the buffer. |
388 buffer_->Append(packet); | 388 buffer_->Append(packet); |
389 } else { | 389 } else { |
390 *source_exhausted = true; | 390 *source_exhausted = true; |
391 } | 391 } |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 void AlsaPcmOutputStream::WritePacket() { | 395 void AlsaPcmOutputStream::WritePacket() { |
396 DCHECK(IsOnAudioThread()); | 396 DCHECK(IsOnAudioThread()); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } | 756 } |
757 | 757 |
758 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to | 758 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to |
759 // release ownership of the currently registered callback. | 759 // release ownership of the currently registered callback. |
760 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { | 760 void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { |
761 DCHECK(IsOnAudioThread()); | 761 DCHECK(IsOnAudioThread()); |
762 source_callback_ = callback; | 762 source_callback_ = callback; |
763 } | 763 } |
764 | 764 |
765 } // namespace media | 765 } // namespace media |
OLD | NEW |