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

Side by Side Diff: webkit/plugins/ppapi/ppb_audio_impl.cc

Issue 7669055: Remove webkit::ppapi::Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix self-assignment Created 9 years, 4 months 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
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 "webkit/plugins/ppapi/ppb_audio_impl.h" 5 #include "webkit/plugins/ppapi/ppb_audio_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/c/pp_completion_callback.h" 8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/ppb_audio.h" 9 #include "ppapi/c/ppb_audio.h"
10 #include "ppapi/c/ppb_audio_config.h" 10 #include "ppapi/c/ppb_audio_config.h"
11 #include "ppapi/c/trusted/ppb_audio_trusted.h" 11 #include "ppapi/c/trusted/ppb_audio_trusted.h"
12 #include "ppapi/shared_impl/resource_tracker.h"
13 #include "ppapi/shared_impl/tracker_base.h"
12 #include "ppapi/thunk/enter.h" 14 #include "ppapi/thunk/enter.h"
13 #include "ppapi/thunk/ppb_audio_config_api.h" 15 #include "ppapi/thunk/ppb_audio_config_api.h"
14 #include "ppapi/thunk/thunk.h" 16 #include "ppapi/thunk/thunk.h"
15 #include "webkit/plugins/ppapi/common.h" 17 #include "webkit/plugins/ppapi/common.h"
18 #include "webkit/plugins/ppapi/resource_helper.h"
16 19
17 using ppapi::thunk::EnterResourceNoLock; 20 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_Audio_API; 21 using ppapi::thunk::PPB_Audio_API;
19 using ppapi::thunk::PPB_AudioConfig_API; 22 using ppapi::thunk::PPB_AudioConfig_API;
20 23
21 namespace webkit { 24 namespace webkit {
22 namespace ppapi { 25 namespace ppapi {
23 26
24 // PPB_AudioConfig ------------------------------------------------------------- 27 // PPB_AudioConfig -------------------------------------------------------------
25 28
26 PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(PluginInstance* instance) 29 PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(PP_Instance instance)
27 : Resource(instance) { 30 : Resource(instance) {
28 } 31 }
29 32
30 PPB_AudioConfig_Impl::~PPB_AudioConfig_Impl() { 33 PPB_AudioConfig_Impl::~PPB_AudioConfig_Impl() {
31 } 34 }
32 35
33 // static 36 // static
34 PP_Resource PPB_AudioConfig_Impl::Create(PluginInstance* instance, 37 PP_Resource PPB_AudioConfig_Impl::Create(PP_Instance instance,
35 PP_AudioSampleRate sample_rate, 38 PP_AudioSampleRate sample_rate,
36 uint32_t sample_frame_count) { 39 uint32_t sample_frame_count) {
37 scoped_refptr<PPB_AudioConfig_Impl> config( 40 scoped_refptr<PPB_AudioConfig_Impl> config(
38 new PPB_AudioConfig_Impl(instance)); 41 new PPB_AudioConfig_Impl(instance));
39 if (!config->Init(sample_rate, sample_frame_count)) 42 if (!config->Init(sample_rate, sample_frame_count))
40 return 0; 43 return 0;
41 return config->GetReference(); 44 return config->GetReference();
42 } 45 }
43 46
44 PPB_AudioConfig_API* PPB_AudioConfig_Impl::AsPPB_AudioConfig_API() { 47 PPB_AudioConfig_API* PPB_AudioConfig_Impl::AsPPB_AudioConfig_API() {
45 return this; 48 return this;
46 } 49 }
47 50
48 // PPB_Audio_Impl -------------------------------------------------------------- 51 // PPB_Audio_Impl --------------------------------------------------------------
49 52
50 PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance) 53 PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance)
51 : Resource(instance), 54 : Resource(instance),
52 config_id_(0),
53 audio_(NULL), 55 audio_(NULL),
54 create_callback_pending_(false), 56 create_callback_pending_(false),
55 shared_memory_size_for_create_callback_(0) { 57 shared_memory_size_for_create_callback_(0) {
56 create_callback_ = PP_MakeCompletionCallback(NULL, NULL); 58 create_callback_ = PP_MakeCompletionCallback(NULL, NULL);
57 } 59 }
58 60
59 PPB_Audio_Impl::~PPB_Audio_Impl() { 61 PPB_Audio_Impl::~PPB_Audio_Impl() {
60 if (config_id_)
61 ResourceTracker::Get()->ReleaseResource(config_id_);
62
63 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and 62 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
64 // releases the audio data associated with the pointer. Note however, that 63 // releases the audio data associated with the pointer. Note however, that
65 // until ShutDown returns, StreamCreated may still be called. This will be 64 // until ShutDown returns, StreamCreated may still be called. This will be
66 // OK since we'll just immediately clean up the data it stored later in this 65 // OK since we'll just immediately clean up the data it stored later in this
67 // destructor. 66 // destructor.
68 if (audio_) { 67 if (audio_) {
69 audio_->ShutDown(); 68 audio_->ShutDown();
70 audio_ = NULL; 69 audio_ = NULL;
71 } 70 }
72 71
73 // If the completion callback hasn't fired yet, do so here 72 // If the completion callback hasn't fired yet, do so here
74 // with an error condition. 73 // with an error condition.
75 if (create_callback_pending_) { 74 if (create_callback_pending_) {
76 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED); 75 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED);
77 create_callback_pending_ = false; 76 create_callback_pending_ = false;
78 } 77 }
79 } 78 }
80 79
81 // static 80 // static
82 PP_Resource PPB_Audio_Impl::Create(PluginInstance* instance, 81 PP_Resource PPB_Audio_Impl::Create(PP_Instance instance,
83 PP_Resource config_id, 82 PP_Resource config_id,
viettrungluu 2011/08/22 23:19:46 I think you should rename s/config_id/config/.
84 PPB_Audio_Callback audio_callback, 83 PPB_Audio_Callback audio_callback,
85 void* user_data) { 84 void* user_data) {
86 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance)); 85 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance));
87 if (!audio->Init(config_id, audio_callback, user_data)) 86 if (!audio->Init(config_id, audio_callback, user_data))
88 return 0; 87 return 0;
89 return audio->GetReference(); 88 return audio->GetReference();
90 } 89 }
91 90
92 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { 91 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() {
93 return this; 92 return this;
94 } 93 }
95 94
96 bool PPB_Audio_Impl::Init(PP_Resource config_id, 95 bool PPB_Audio_Impl::Init(PP_Resource config_id,
viettrungluu 2011/08/22 23:19:46 "
97 PPB_Audio_Callback callback, void* user_data) { 96 PPB_Audio_Callback callback, void* user_data) {
98 // Validate the config and keep a reference to it. 97 // Validate the config and keep a reference to it.
99 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true); 98 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true);
100 if (enter.failed()) 99 if (enter.failed())
101 return false; 100 return false;
102 config_id_ = config_id; 101 config_ = config_id;
103 ResourceTracker::Get()->AddRefResource(config_id);
104 102
105 if (!callback) 103 if (!callback)
106 return false; 104 return false;
107 SetCallback(callback, user_data); 105 SetCallback(callback, user_data);
108 106
109 // When the stream is created, we'll get called back on StreamCreated(). 107 // When the stream is created, we'll get called back on StreamCreated().
110 CHECK(!audio_); 108 CHECK(!audio_);
111 audio_ = instance()->delegate()->CreateAudio( 109 audio_ = ResourceHelper::GetPluginDelegate(this)->CreateAudio(
112 enter.object()->GetSampleRate(), 110 enter.object()->GetSampleRate(),
113 enter.object()->GetSampleFrameCount(), 111 enter.object()->GetSampleFrameCount(),
114 this); 112 this);
115 return audio_ != NULL; 113 return audio_ != NULL;
116 } 114 }
117 115
118 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { 116 PP_Resource PPB_Audio_Impl::GetCurrentConfig() {
119 // AddRef on behalf of caller. 117 // AddRef on behalf of caller, while keeping a ref for ourselves.
120 ResourceTracker::Get()->AddRefResource(config_id_); 118 ::ppapi::TrackerBase::Get()->GetResourceTracker()->AddRefResource(config_);
121 return config_id_; 119 return config_;
122 } 120 }
123 121
124 PP_Bool PPB_Audio_Impl::StartPlayback() { 122 PP_Bool PPB_Audio_Impl::StartPlayback() {
125 if (!audio_) 123 if (!audio_)
126 return PP_FALSE; 124 return PP_FALSE;
127 if (playing()) 125 if (playing())
128 return PP_TRUE; 126 return PP_TRUE;
129 SetStartPlaybackState(); 127 SetStartPlaybackState();
130 return BoolToPPBool(audio_->StartPlayback()); 128 return BoolToPPBool(audio_->StartPlayback());
131 } 129 }
132 130
133 PP_Bool PPB_Audio_Impl::StopPlayback() { 131 PP_Bool PPB_Audio_Impl::StopPlayback() {
134 if (!audio_) 132 if (!audio_)
135 return PP_FALSE; 133 return PP_FALSE;
136 if (!playing()) 134 if (!playing())
137 return PP_TRUE; 135 return PP_TRUE;
138 if (!audio_->StopPlayback()) 136 if (!audio_->StopPlayback())
139 return PP_FALSE; 137 return PP_FALSE;
140 SetStopPlaybackState(); 138 SetStopPlaybackState();
141 return PP_TRUE; 139 return PP_TRUE;
142 } 140 }
143 141
144 int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config_id, 142 int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config_id,
viettrungluu 2011/08/22 23:19:46 "
145 PP_CompletionCallback create_callback) { 143 PP_CompletionCallback create_callback) {
146 144
147 // Validate the config and keep a reference to it. 145 // Validate the config and keep a reference to it.
148 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true); 146 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true);
149 if (enter.failed()) 147 if (enter.failed())
150 return false; 148 return false;
151 config_id_ = config_id; 149 config_ = config_id;
152 ResourceTracker::Get()->AddRefResource(config_id);
153 150
154 // When the stream is created, we'll get called back on StreamCreated(). 151 // When the stream is created, we'll get called back on StreamCreated().
155 DCHECK(!audio_); 152 DCHECK(!audio_);
156 audio_ = instance()->delegate()->CreateAudio( 153 audio_ = ResourceHelper::GetPluginDelegate(this)->CreateAudio(
157 enter.object()->GetSampleRate(), 154 enter.object()->GetSampleRate(),
158 enter.object()->GetSampleFrameCount(), 155 enter.object()->GetSampleFrameCount(),
159 this); 156 this);
160 if (!audio_) 157 if (!audio_)
161 return PP_ERROR_FAILED; 158 return PP_ERROR_FAILED;
162 159
163 // At this point, we are guaranteeing ownership of the completion 160 // At this point, we are guaranteeing ownership of the completion
164 // callback. Audio promises to fire the completion callback 161 // callback. Audio promises to fire the completion callback
165 // once and only once. 162 // once and only once.
166 create_callback_ = create_callback; 163 create_callback_ = create_callback;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // something more elaborate like an ACK from the plugin or post a task to 218 // something more elaborate like an ACK from the plugin or post a task to
222 // the I/O thread and back, but this extra complexity doesn't seem worth it 219 // the I/O thread and back, but this extra complexity doesn't seem worth it
223 // just to clean up these handles faster. 220 // just to clean up these handles faster.
224 } else { 221 } else {
225 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); 222 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
226 } 223 }
227 } 224 }
228 225
229 } // namespace ppapi 226 } // namespace ppapi
230 } // namespace webkit 227 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698