| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/shared_impl/audio_impl.h" | 5 #include "ppapi/shared_impl/audio_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace ppapi { | 9 namespace ppapi { |
| 10 | 10 |
| 11 AudioImpl::AudioImpl() | 11 AudioImpl::AudioImpl() |
| 12 : playing_(false), | 12 : playing_(false), |
| 13 shared_memory_size_(0), | 13 shared_memory_size_(0), |
| 14 callback_(NULL), | 14 callback_(NULL), |
| 15 user_data_(NULL) { | 15 user_data_(NULL) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 AudioImpl::~AudioImpl() { | 18 AudioImpl::~AudioImpl() { |
| 19 // Closing the socket causes the thread to exit - wait for it. | 19 // Closing the socket causes the thread to exit - wait for it. |
| 20 if (socket_.get()) | 20 if (socket_.get()) |
| 21 socket_->Close(); | 21 socket_->Close(); |
| 22 if (audio_thread_.get()) { | 22 if (audio_thread_.get()) { |
| 23 audio_thread_->Join(); | 23 audio_thread_->Join(); |
| 24 audio_thread_.reset(); | 24 audio_thread_.reset(); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 ::ppapi::thunk::PPB_Audio_API* AudioImpl::AsPPB_Audio_API() { | |
| 29 return this; | |
| 30 } | |
| 31 | |
| 32 void AudioImpl::SetCallback(PPB_Audio_Callback callback, void* user_data) { | 28 void AudioImpl::SetCallback(PPB_Audio_Callback callback, void* user_data) { |
| 33 callback_ = callback; | 29 callback_ = callback; |
| 34 user_data_ = user_data; | 30 user_data_ = user_data; |
| 35 } | 31 } |
| 36 | 32 |
| 37 void AudioImpl::SetStartPlaybackState() { | 33 void AudioImpl::SetStartPlaybackState() { |
| 38 DCHECK(!playing_); | 34 DCHECK(!playing_); |
| 39 DCHECK(!audio_thread_.get()); | 35 DCHECK(!audio_thread_.get()); |
| 40 | 36 |
| 41 // If the socket doesn't exist, that means that the plugin has started before | 37 // If the socket doesn't exist, that means that the plugin has started before |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void* buffer = shared_memory_->memory(); | 83 void* buffer = shared_memory_->memory(); |
| 88 | 84 |
| 89 while (sizeof(pending_data) == | 85 while (sizeof(pending_data) == |
| 90 socket_->Receive(&pending_data, sizeof(pending_data)) && | 86 socket_->Receive(&pending_data, sizeof(pending_data)) && |
| 91 pending_data >= 0) { | 87 pending_data >= 0) { |
| 92 callback_(buffer, shared_memory_size_, user_data_); | 88 callback_(buffer, shared_memory_size_, user_data_); |
| 93 } | 89 } |
| 94 } | 90 } |
| 95 | 91 |
| 96 } // namespace ppapi | 92 } // namespace ppapi |
| OLD | NEW |