Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: ppapi/shared_impl/ppb_audio_input_shared.cc

Issue 8790004: Rename the shared impl files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/ppb_audio_input_shared.h ('k') | ppapi/shared_impl/ppb_audio_shared.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_input_impl.h" 5 #include "ppapi/shared_impl/ppb_audio_input_shared.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace ppapi { 9 namespace ppapi {
10 10
11 AudioInputImpl::AudioInputImpl() 11 PPB_AudioInput_Shared::PPB_AudioInput_Shared()
12 : capturing_(false), 12 : capturing_(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 AudioInputImpl::~AudioInputImpl() { 18 PPB_AudioInput_Shared::~PPB_AudioInput_Shared() {
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_input_thread_.get()) { 22 if (audio_input_thread_.get()) {
23 audio_input_thread_->Join(); 23 audio_input_thread_->Join();
24 audio_input_thread_.reset(); 24 audio_input_thread_.reset();
25 } 25 }
26 } 26 }
27 27
28 void AudioInputImpl::SetCallback(PPB_AudioInput_Callback callback, 28 void PPB_AudioInput_Shared::SetCallback(PPB_AudioInput_Callback callback,
29 void* user_data) { 29 void* user_data) {
30 callback_ = callback; 30 callback_ = callback;
31 user_data_ = user_data; 31 user_data_ = user_data;
32 } 32 }
33 33
34 void AudioInputImpl::SetStartCaptureState() { 34 void PPB_AudioInput_Shared::SetStartCaptureState() {
35 DCHECK(!capturing_); 35 DCHECK(!capturing_);
36 DCHECK(!audio_input_thread_.get()); 36 DCHECK(!audio_input_thread_.get());
37 37
38 // If the socket doesn't exist, that means that the plugin has started before 38 // If the socket doesn't exist, that means that the plugin has started before
39 // the browser has had a chance to create all the shared memory info and 39 // the browser has had a chance to create all the shared memory info and
40 // notify us. This is a common case. In this case, we just set the playing_ 40 // notify us. This is a common case. In this case, we just set the playing_
41 // flag and the capture will automatically start when that data is available 41 // flag and the capture will automatically start when that data is available
42 // in SetStreamInfo. 42 // in SetStreamInfo.
43 if (socket_.get()) 43 if (socket_.get())
44 StartThread(); 44 StartThread();
45 capturing_ = true; 45 capturing_ = true;
46 } 46 }
47 47
48 void AudioInputImpl::SetStopCaptureState() { 48 void PPB_AudioInput_Shared::SetStopCaptureState() {
49 DCHECK(capturing_); 49 DCHECK(capturing_);
50 50
51 if (audio_input_thread_.get()) { 51 if (audio_input_thread_.get()) {
52 audio_input_thread_->Join(); 52 audio_input_thread_->Join();
53 audio_input_thread_.reset(); 53 audio_input_thread_.reset();
54 } 54 }
55 capturing_ = false; 55 capturing_ = false;
56 } 56 }
57 57
58 void AudioInputImpl::SetStreamInfo( 58 void PPB_AudioInput_Shared::SetStreamInfo(
59 base::SharedMemoryHandle shared_memory_handle, 59 base::SharedMemoryHandle shared_memory_handle,
60 size_t shared_memory_size, 60 size_t shared_memory_size,
61 base::SyncSocket::Handle socket_handle) { 61 base::SyncSocket::Handle socket_handle) {
62 socket_.reset(new base::SyncSocket(socket_handle)); 62 socket_.reset(new base::SyncSocket(socket_handle));
63 shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false)); 63 shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false));
64 shared_memory_size_ = shared_memory_size; 64 shared_memory_size_ = shared_memory_size;
65 65
66 if (callback_) { 66 if (callback_) {
67 shared_memory_->Map(shared_memory_size_); 67 shared_memory_->Map(shared_memory_size_);
68 68
69 // In common case StartCapture() was called before StreamCreated(). 69 // In common case StartCapture() was called before StreamCreated().
70 if (capturing_) 70 if (capturing_)
71 StartThread(); 71 StartThread();
72 } 72 }
73 } 73 }
74 74
75 void AudioInputImpl::StartThread() { 75 void PPB_AudioInput_Shared::StartThread() {
76 DCHECK(callback_); 76 DCHECK(callback_);
77 DCHECK(!audio_input_thread_.get()); 77 DCHECK(!audio_input_thread_.get());
78 audio_input_thread_.reset(new base::DelegateSimpleThread( 78 audio_input_thread_.reset(new base::DelegateSimpleThread(
79 this, "plugin_audio_input_thread")); 79 this, "plugin_audio_input_thread"));
80 audio_input_thread_->Start(); 80 audio_input_thread_->Start();
81 } 81 }
82 82
83 void AudioInputImpl::Run() { 83 void PPB_AudioInput_Shared::Run() {
84 int pending_data; 84 int pending_data;
85 void* buffer = shared_memory_->memory(); 85 void* buffer = shared_memory_->memory();
86 86
87 while (sizeof(pending_data) == socket_->Receive(&pending_data, 87 while (sizeof(pending_data) == socket_->Receive(&pending_data,
88 sizeof(pending_data)) && 88 sizeof(pending_data)) &&
89 pending_data >= 0) { 89 pending_data >= 0) {
90 callback_(buffer, shared_memory_size_, user_data_); 90 callback_(buffer, shared_memory_size_, user_data_);
91 } 91 }
92 } 92 }
93 93
94 } // namespace ppapi 94 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_audio_input_shared.h ('k') | ppapi/shared_impl/ppb_audio_shared.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698