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

Side by Side Diff: content/renderer/pepper/ppb_audio_impl.cc

Issue 22320004: Add a new parameter |latency| to PPB_Audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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) 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 "content/renderer/pepper/ppb_audio_impl.h" 5 #include "content/renderer/pepper/ppb_audio_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/renderer/pepper/common.h" 8 #include "content/renderer/pepper/common.h"
9 #include "content/renderer/pepper/pepper_platform_audio_output.h" 9 #include "content/renderer/pepper/pepper_platform_audio_output.h"
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
(...skipping 13 matching lines...) Expand all
24 using ppapi::thunk::PPB_Audio_API; 24 using ppapi::thunk::PPB_Audio_API;
25 using ppapi::thunk::PPB_AudioConfig_API; 25 using ppapi::thunk::PPB_AudioConfig_API;
26 using ppapi::TrackedCallback; 26 using ppapi::TrackedCallback;
27 27
28 namespace content { 28 namespace content {
29 29
30 // PPB_Audio_Impl -------------------------------------------------------------- 30 // PPB_Audio_Impl --------------------------------------------------------------
31 31
32 PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance) 32 PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance)
33 : Resource(::ppapi::OBJECT_IS_IMPL, instance), 33 : Resource(::ppapi::OBJECT_IS_IMPL, instance),
34 audio_(NULL), 34 audio_(NULL) {
35 sample_frame_count_(0) {
36 } 35 }
37 36
38 PPB_Audio_Impl::~PPB_Audio_Impl() { 37 PPB_Audio_Impl::~PPB_Audio_Impl() {
39 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and 38 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
40 // releases the audio data associated with the pointer. Note however, that 39 // releases the audio data associated with the pointer. Note however, that
41 // until ShutDown returns, StreamCreated may still be called. This will be 40 // until ShutDown returns, StreamCreated may still be called. This will be
42 // OK since we'll just immediately clean up the data it stored later in this 41 // OK since we'll just immediately clean up the data it stored later in this
43 // destructor. 42 // destructor.
44 if (audio_) { 43 if (audio_) {
45 audio_->ShutDown(); 44 audio_->ShutDown();
46 audio_ = NULL; 45 audio_ = NULL;
47 } 46 }
48 } 47 }
49 48
50 // static 49 // static
51 PP_Resource PPB_Audio_Impl::Create(PP_Instance instance, 50 PP_Resource PPB_Audio_Impl::Create(PP_Instance instance,
52 PP_Resource config, 51 PP_Resource config,
53 PPB_Audio_Callback audio_callback, 52 const ppapi::AudioCallback& audio_callback,
54 void* user_data) { 53 void* user_data) {
55 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance)); 54 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance));
56 if (!audio->Init(config, audio_callback, user_data)) 55 if (!audio->Init(config, audio_callback, user_data))
57 return 0; 56 return 0;
58 return audio->GetReference(); 57 return audio->GetReference();
59 } 58 }
60 59
61 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { 60 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() {
62 return this; 61 return this;
63 } 62 }
64 63
65 bool PPB_Audio_Impl::Init(PP_Resource config, 64 bool PPB_Audio_Impl::Init(PP_Resource config,
66 PPB_Audio_Callback callback, void* user_data) { 65 const ppapi::AudioCallback& callback,
66 void* user_data) {
67 // Validate the config and keep a reference to it. 67 // Validate the config and keep a reference to it.
68 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); 68 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true);
69 if (enter.failed()) 69 if (enter.failed())
70 return false; 70 return false;
71 config_ = config; 71 config_ = config;
72 72
73 if (!callback) 73 if (!callback.IsValid())
74 return false; 74 return false;
75 SetCallback(callback, user_data); 75 SetCallback(callback, user_data);
76 76
77 PepperPluginInstanceImpl* instance = ResourceHelper::GetPluginInstance(this); 77 PepperPluginInstanceImpl* instance = ResourceHelper::GetPluginInstance(this);
78 if (!instance) 78 if (!instance)
79 return false; 79 return false;
80 80
81 // When the stream is created, we'll get called back on StreamCreated(). 81 // When the stream is created, we'll get called back on StreamCreated().
82 CHECK(!audio_); 82 CHECK(!audio_);
83 audio_ = PepperPlatformAudioOutput::Create( 83 audio_ = PepperPlatformAudioOutput::Create(
84 static_cast<int>(enter.object()->GetSampleRate()), 84 static_cast<int>(enter.object()->GetSampleRate()),
85 static_cast<int>(enter.object()->GetSampleFrameCount()), 85 static_cast<int>(enter.object()->GetSampleFrameCount()),
86 instance->GetRenderView()->GetRoutingID(), 86 instance->GetRenderView()->GetRoutingID(),
87 this); 87 this);
88 sample_frame_count_ = enter.object()->GetSampleFrameCount();
89 return audio_ != NULL; 88 return audio_ != NULL;
90 } 89 }
91 90
92 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { 91 PP_Resource PPB_Audio_Impl::GetCurrentConfig() {
93 // AddRef on behalf of caller, while keeping a ref for ourselves. 92 // AddRef on behalf of caller, while keeping a ref for ourselves.
94 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); 93 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_);
95 return config_; 94 return config_;
96 } 95 }
97 96
98 PP_Bool PPB_Audio_Impl::StartPlayback() { 97 PP_Bool PPB_Audio_Impl::StartPlayback() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 151
153 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, 152 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle,
154 uint32_t* shm_size) { 153 uint32_t* shm_size) {
155 return GetSharedMemoryImpl(shm_handle, shm_size); 154 return GetSharedMemoryImpl(shm_handle, shm_size);
156 } 155 }
157 156
158 void PPB_Audio_Impl::OnSetStreamInfo( 157 void PPB_Audio_Impl::OnSetStreamInfo(
159 base::SharedMemoryHandle shared_memory_handle, 158 base::SharedMemoryHandle shared_memory_handle,
160 size_t shared_memory_size, 159 size_t shared_memory_size,
161 base::SyncSocket::Handle socket_handle) { 160 base::SyncSocket::Handle socket_handle) {
161 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_, true);
dmichael (off chromium) 2013/08/06 19:43:25 I think this could fail if the plugin releases con
yzshen1 2013/08/07 20:51:06 This class also holds a ref to config_, so it shou
dmichael (off chromium) 2013/08/07 21:11:38 Thanks, I missed that it's a ScopedPPResource inst
162 SetStreamInfo(pp_instance(), shared_memory_handle, shared_memory_size, 162 SetStreamInfo(pp_instance(), shared_memory_handle, shared_memory_size,
163 socket_handle, sample_frame_count_); 163 socket_handle, enter.object()->GetSampleRate(),
164 enter.object()->GetSampleFrameCount());
164 } 165 }
165 166
166 } // namespace content 167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698