| 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 "ppapi/shared_impl/ppb_audio_shared.h" | 5 #include "ppapi/shared_impl/ppb_audio_shared.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/audio/shared_memory_util.h" | 8 #include "media/audio/shared_memory_util.h" |
| 9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 shared_memory_size_(0), | 22 shared_memory_size_(0), |
| 23 #if defined(OS_NACL) | 23 #if defined(OS_NACL) |
| 24 thread_id_(0), | 24 thread_id_(0), |
| 25 thread_active_(false), | 25 thread_active_(false), |
| 26 #endif | 26 #endif |
| 27 callback_(NULL), | 27 callback_(NULL), |
| 28 user_data_(NULL) { | 28 user_data_(NULL) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 PPB_Audio_Shared::~PPB_Audio_Shared() { | 31 PPB_Audio_Shared::~PPB_Audio_Shared() { |
| 32 // Shut down the socket to escape any hanging |Receive|s. |
| 33 if (socket_.get()) |
| 34 socket_->Shutdown(); |
| 32 StopThread(); | 35 StopThread(); |
| 33 } | 36 } |
| 34 | 37 |
| 35 void PPB_Audio_Shared::SetCallback(PPB_Audio_Callback callback, | 38 void PPB_Audio_Shared::SetCallback(PPB_Audio_Callback callback, |
| 36 void* user_data) { | 39 void* user_data) { |
| 37 callback_ = callback; | 40 callback_ = callback; |
| 38 user_data_ = user_data; | 41 user_data_ = user_data; |
| 39 } | 42 } |
| 40 | 43 |
| 41 void PPB_Audio_Shared::SetStartPlaybackState() { | 44 void PPB_Audio_Shared::SetStartPlaybackState() { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 NULL == thread_functions.thread_join) | 101 NULL == thread_functions.thread_join) |
| 99 return; | 102 return; |
| 100 | 103 |
| 101 int result = thread_functions.thread_create(&thread_id_, CallRun, this); | 104 int result = thread_functions.thread_create(&thread_id_, CallRun, this); |
| 102 DCHECK_EQ(result, 0); | 105 DCHECK_EQ(result, 0); |
| 103 thread_active_ = true; | 106 thread_active_ = true; |
| 104 #endif | 107 #endif |
| 105 } | 108 } |
| 106 | 109 |
| 107 void PPB_Audio_Shared::StopThread() { | 110 void PPB_Audio_Shared::StopThread() { |
| 108 // Shut down the socket to escape any hanging |Receive|s. | 111 #if !defined(OS_NACL) |
| 109 if (socket_.get()) | |
| 110 socket_->Shutdown(); | |
| 111 #if !defined(OS_NACL) | |
| 112 if (audio_thread_.get()) { | 112 if (audio_thread_.get()) { |
| 113 audio_thread_->Join(); | 113 audio_thread_->Join(); |
| 114 audio_thread_.reset(); | 114 audio_thread_.reset(); |
| 115 } | 115 } |
| 116 #else | 116 #else |
| 117 if (thread_active_) { | 117 if (thread_active_) { |
| 118 int result = thread_functions.thread_join(thread_id_); | 118 int result = thread_functions.thread_join(thread_id_); |
| 119 DCHECK_EQ(0, result); | 119 DCHECK_EQ(0, result); |
| 120 thread_active_ = false; | 120 thread_active_ = false; |
| 121 } | 121 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 147 pending_data != media::kPauseMark) { | 147 pending_data != media::kPauseMark) { |
| 148 callback_(buffer, shared_memory_size_, user_data_); | 148 callback_(buffer, shared_memory_size_, user_data_); |
| 149 | 149 |
| 150 // Let the host know we are done. | 150 // Let the host know we are done. |
| 151 media::SetActualDataSizeInBytes( | 151 media::SetActualDataSizeInBytes( |
| 152 shared_memory_.get(), shared_memory_size_, shared_memory_size_); | 152 shared_memory_.get(), shared_memory_size_, shared_memory_size_); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace ppapi | 156 } // namespace ppapi |
| OLD | NEW |