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 "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 12 matching lines...) Expand all Loading... |
23 using ppapi::thunk::PPB_Audio_API; | 23 using ppapi::thunk::PPB_Audio_API; |
24 using ppapi::thunk::PPB_AudioConfig_API; | 24 using ppapi::thunk::PPB_AudioConfig_API; |
25 using ppapi::TrackedCallback; | 25 using ppapi::TrackedCallback; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 // PPB_Audio_Impl -------------------------------------------------------------- | 29 // PPB_Audio_Impl -------------------------------------------------------------- |
30 | 30 |
31 PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance) | 31 PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance) |
32 : Resource(ppapi::OBJECT_IS_IMPL, instance), | 32 : Resource(ppapi::OBJECT_IS_IMPL, instance), |
33 audio_(NULL), | 33 audio_(NULL) { |
34 sample_frame_count_(0) { | |
35 } | 34 } |
36 | 35 |
37 PPB_Audio_Impl::~PPB_Audio_Impl() { | 36 PPB_Audio_Impl::~PPB_Audio_Impl() { |
38 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and | 37 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and |
39 // releases the audio data associated with the pointer. Note however, that | 38 // releases the audio data associated with the pointer. Note however, that |
40 // until ShutDown returns, StreamCreated may still be called. This will be | 39 // until ShutDown returns, StreamCreated may still be called. This will be |
41 // OK since we'll just immediately clean up the data it stored later in this | 40 // OK since we'll just immediately clean up the data it stored later in this |
42 // destructor. | 41 // destructor. |
43 if (audio_) { | 42 if (audio_) { |
44 audio_->ShutDown(); | 43 audio_->ShutDown(); |
45 audio_ = NULL; | 44 audio_ = NULL; |
46 } | 45 } |
47 } | 46 } |
48 | 47 |
49 // static | 48 // static |
50 PP_Resource PPB_Audio_Impl::Create(PP_Instance instance, | 49 PP_Resource PPB_Audio_Impl::Create( |
51 PP_Resource config, | 50 PP_Instance instance, |
52 PPB_Audio_Callback audio_callback, | 51 PP_Resource config, |
53 void* user_data) { | 52 const ppapi::AudioCallbackCombined& audio_callback, |
| 53 void* user_data) { |
54 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance)); | 54 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance)); |
55 if (!audio->Init(config, audio_callback, user_data)) | 55 if (!audio->Init(config, audio_callback, user_data)) |
56 return 0; | 56 return 0; |
57 return audio->GetReference(); | 57 return audio->GetReference(); |
58 } | 58 } |
59 | 59 |
60 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { | 60 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { |
61 return this; | 61 return this; |
62 } | 62 } |
63 | 63 |
64 bool PPB_Audio_Impl::Init(PP_Resource config, | 64 bool PPB_Audio_Impl::Init(PP_Resource config, |
65 PPB_Audio_Callback callback, void* user_data) { | 65 const ppapi::AudioCallbackCombined& callback, |
| 66 void* user_data) { |
66 // Validate the config and keep a reference to it. | 67 // Validate the config and keep a reference to it. |
67 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); | 68 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); |
68 if (enter.failed()) | 69 if (enter.failed()) |
69 return false; | 70 return false; |
70 config_ = config; | 71 config_ = config; |
71 | 72 |
72 if (!callback) | 73 if (!callback.IsValid()) |
73 return false; | 74 return false; |
74 SetCallback(callback, user_data); | 75 SetCallback(callback, user_data); |
75 | 76 |
76 PepperPluginInstance* instance = PepperPluginInstance::Get(pp_instance()); | 77 PepperPluginInstance* instance = PepperPluginInstance::Get(pp_instance()); |
77 if (!instance) | 78 if (!instance) |
78 return false; | 79 return false; |
79 | 80 |
80 // 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(). |
81 CHECK(!audio_); | 82 CHECK(!audio_); |
82 audio_ = PepperPlatformAudioOutput::Create( | 83 audio_ = PepperPlatformAudioOutput::Create( |
83 static_cast<int>(enter.object()->GetSampleRate()), | 84 static_cast<int>(enter.object()->GetSampleRate()), |
84 static_cast<int>(enter.object()->GetSampleFrameCount()), | 85 static_cast<int>(enter.object()->GetSampleFrameCount()), |
85 instance->GetRenderView()->GetRoutingID(), | 86 instance->GetRenderView()->GetRoutingID(), |
86 this); | 87 this); |
87 sample_frame_count_ = enter.object()->GetSampleFrameCount(); | |
88 return audio_ != NULL; | 88 return audio_ != NULL; |
89 } | 89 } |
90 | 90 |
91 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { | 91 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { |
92 // AddRef on behalf of caller, while keeping a ref for ourselves. | 92 // AddRef on behalf of caller, while keeping a ref for ourselves. |
93 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); | 93 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); |
94 return config_; | 94 return config_; |
95 } | 95 } |
96 | 96 |
97 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 Loading... |
151 | 151 |
152 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, | 152 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, |
153 uint32_t* shm_size) { | 153 uint32_t* shm_size) { |
154 return GetSharedMemoryImpl(shm_handle, shm_size); | 154 return GetSharedMemoryImpl(shm_handle, shm_size); |
155 } | 155 } |
156 | 156 |
157 void PPB_Audio_Impl::OnSetStreamInfo( | 157 void PPB_Audio_Impl::OnSetStreamInfo( |
158 base::SharedMemoryHandle shared_memory_handle, | 158 base::SharedMemoryHandle shared_memory_handle, |
159 size_t shared_memory_size, | 159 size_t shared_memory_size, |
160 base::SyncSocket::Handle socket_handle) { | 160 base::SyncSocket::Handle socket_handle) { |
| 161 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_, true); |
161 SetStreamInfo(pp_instance(), shared_memory_handle, shared_memory_size, | 162 SetStreamInfo(pp_instance(), shared_memory_handle, shared_memory_size, |
162 socket_handle, sample_frame_count_); | 163 socket_handle, enter.object()->GetSampleRate(), |
| 164 enter.object()->GetSampleFrameCount()); |
163 } | 165 } |
164 | 166 |
165 } // namespace content | 167 } // namespace content |
OLD | NEW |