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

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(
52 PP_Resource config, 51 PP_Instance instance,
53 PPB_Audio_Callback audio_callback, 52 PP_Resource config,
54 void* user_data) { 53 const ppapi::AudioCallbackCombined& audio_callback,
54 void* user_data) {
55 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance)); 55 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance));
56 if (!audio->Init(config, audio_callback, user_data)) 56 if (!audio->Init(config, audio_callback, user_data))
57 return 0; 57 return 0;
58 return audio->GetReference(); 58 return audio->GetReference();
59 } 59 }
60 60
61 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { 61 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() {
62 return this; 62 return this;
63 } 63 }
64 64
65 bool PPB_Audio_Impl::Init(PP_Resource config, 65 bool PPB_Audio_Impl::Init(PP_Resource config,
66 PPB_Audio_Callback callback, void* user_data) { 66 const ppapi::AudioCallbackCombined& callback,
67 void* user_data) {
67 // Validate the config and keep a reference to it. 68 // Validate the config and keep a reference to it.
68 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); 69 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true);
69 if (enter.failed()) 70 if (enter.failed())
70 return false; 71 return false;
71 config_ = config; 72 config_ = config;
72 73
73 if (!callback) 74 if (!callback.IsValid())
74 return false; 75 return false;
75 SetCallback(callback, user_data); 76 SetCallback(callback, user_data);
76 77
77 PepperPluginInstanceImpl* instance = ResourceHelper::GetPluginInstance(this); 78 PepperPluginInstanceImpl* instance = ResourceHelper::GetPluginInstance(this);
78 if (!instance) 79 if (!instance)
79 return false; 80 return false;
80 81
81 // When the stream is created, we'll get called back on StreamCreated(). 82 // When the stream is created, we'll get called back on StreamCreated().
82 CHECK(!audio_); 83 CHECK(!audio_);
83 audio_ = PepperPlatformAudioOutput::Create( 84 audio_ = PepperPlatformAudioOutput::Create(
84 static_cast<int>(enter.object()->GetSampleRate()), 85 static_cast<int>(enter.object()->GetSampleRate()),
85 static_cast<int>(enter.object()->GetSampleFrameCount()), 86 static_cast<int>(enter.object()->GetSampleFrameCount()),
86 instance->GetRenderView()->GetRoutingID(), 87 instance->GetRenderView()->GetRoutingID(),
87 this); 88 this);
88 sample_frame_count_ = enter.object()->GetSampleFrameCount();
89 return audio_ != NULL; 89 return audio_ != NULL;
90 } 90 }
91 91
92 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { 92 PP_Resource PPB_Audio_Impl::GetCurrentConfig() {
93 // AddRef on behalf of caller, while keeping a ref for ourselves. 93 // AddRef on behalf of caller, while keeping a ref for ourselves.
94 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); 94 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_);
95 return config_; 95 return config_;
96 } 96 }
97 97
98 PP_Bool PPB_Audio_Impl::StartPlayback() { 98 PP_Bool PPB_Audio_Impl::StartPlayback() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, 153 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle,
154 uint32_t* shm_size) { 154 uint32_t* shm_size) {
155 return GetSharedMemoryImpl(shm_handle, shm_size); 155 return GetSharedMemoryImpl(shm_handle, shm_size);
156 } 156 }
157 157
158 void PPB_Audio_Impl::OnSetStreamInfo( 158 void PPB_Audio_Impl::OnSetStreamInfo(
159 base::SharedMemoryHandle shared_memory_handle, 159 base::SharedMemoryHandle shared_memory_handle,
160 size_t shared_memory_size, 160 size_t shared_memory_size,
161 base::SyncSocket::Handle socket_handle) { 161 base::SyncSocket::Handle socket_handle) {
162 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_, true);
162 SetStreamInfo(pp_instance(), shared_memory_handle, shared_memory_size, 163 SetStreamInfo(pp_instance(), shared_memory_handle, shared_memory_size,
163 socket_handle, sample_frame_count_); 164 socket_handle, enter.object()->GetSampleRate(),
165 enter.object()->GetSampleFrameCount());
164 } 166 }
165 167
166 } // namespace content 168 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698