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::EnterResourceNoLock; | 23 using ppapi::thunk::EnterResourceNoLock; |
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), audio_(NULL) {} |
34 audio_(NULL) { | |
35 } | |
36 | 34 |
37 PPB_Audio_Impl::~PPB_Audio_Impl() { | 35 PPB_Audio_Impl::~PPB_Audio_Impl() { |
38 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and | 36 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and |
39 // releases the audio data associated with the pointer. Note however, that | 37 // releases the audio data associated with the pointer. Note however, that |
40 // until ShutDown returns, StreamCreated may still be called. This will be | 38 // 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 | 39 // OK since we'll just immediately clean up the data it stored later in this |
42 // destructor. | 40 // destructor. |
43 if (audio_) { | 41 if (audio_) { |
44 audio_->ShutDown(); | 42 audio_->ShutDown(); |
45 audio_ = NULL; | 43 audio_ = NULL; |
46 } | 44 } |
47 } | 45 } |
48 | 46 |
49 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { | 47 PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { return this; } |
50 return this; | |
51 } | |
52 | 48 |
53 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { | 49 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { |
54 // AddRef on behalf of caller, while keeping a ref for ourselves. | 50 // AddRef on behalf of caller, while keeping a ref for ourselves. |
55 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); | 51 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); |
56 return config_; | 52 return config_; |
57 } | 53 } |
58 | 54 |
59 PP_Bool PPB_Audio_Impl::StartPlayback() { | 55 PP_Bool PPB_Audio_Impl::StartPlayback() { |
60 if (!audio_) | 56 if (!audio_) |
61 return PP_FALSE; | 57 return PP_FALSE; |
62 if (playing()) | 58 if (playing()) |
63 return PP_TRUE; | 59 return PP_TRUE; |
64 SetStartPlaybackState(); | 60 SetStartPlaybackState(); |
65 return BoolToPPBool(audio_->StartPlayback()); | 61 return BoolToPPBool(audio_->StartPlayback()); |
66 } | 62 } |
67 | 63 |
68 PP_Bool PPB_Audio_Impl::StopPlayback() { | 64 PP_Bool PPB_Audio_Impl::StopPlayback() { |
69 if (!audio_) | 65 if (!audio_) |
70 return PP_FALSE; | 66 return PP_FALSE; |
71 if (!playing()) | 67 if (!playing()) |
72 return PP_TRUE; | 68 return PP_TRUE; |
73 if (!audio_->StopPlayback()) | 69 if (!audio_->StopPlayback()) |
74 return PP_FALSE; | 70 return PP_FALSE; |
75 SetStopPlaybackState(); | 71 SetStopPlaybackState(); |
76 return PP_TRUE; | 72 return PP_TRUE; |
77 } | 73 } |
78 | 74 |
79 int32_t PPB_Audio_Impl::Open( | 75 int32_t PPB_Audio_Impl::Open(PP_Resource config, |
80 PP_Resource config, | 76 scoped_refptr<TrackedCallback> create_callback) { |
81 scoped_refptr<TrackedCallback> create_callback) { | |
82 // Validate the config and keep a reference to it. | 77 // Validate the config and keep a reference to it. |
83 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); | 78 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); |
84 if (enter.failed()) | 79 if (enter.failed()) |
85 return PP_ERROR_FAILED; | 80 return PP_ERROR_FAILED; |
86 config_ = config; | 81 config_ = config; |
87 | 82 |
88 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( | 83 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( |
89 PepperPluginInstance::Get(pp_instance())); | 84 PepperPluginInstance::Get(pp_instance())); |
90 if (!instance) | 85 if (!instance) |
91 return PP_ERROR_FAILED; | 86 return PP_ERROR_FAILED; |
(...skipping 14 matching lines...) Expand all Loading... |
106 // once and only once. | 101 // once and only once. |
107 SetCreateCallback(create_callback); | 102 SetCreateCallback(create_callback); |
108 | 103 |
109 return PP_OK_COMPLETIONPENDING; | 104 return PP_OK_COMPLETIONPENDING; |
110 } | 105 } |
111 | 106 |
112 int32_t PPB_Audio_Impl::GetSyncSocket(int* sync_socket) { | 107 int32_t PPB_Audio_Impl::GetSyncSocket(int* sync_socket) { |
113 return GetSyncSocketImpl(sync_socket); | 108 return GetSyncSocketImpl(sync_socket); |
114 } | 109 } |
115 | 110 |
116 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, | 111 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { |
117 uint32_t* shm_size) { | |
118 return GetSharedMemoryImpl(shm_handle, shm_size); | 112 return GetSharedMemoryImpl(shm_handle, shm_size); |
119 } | 113 } |
120 | 114 |
121 void PPB_Audio_Impl::OnSetStreamInfo( | 115 void PPB_Audio_Impl::OnSetStreamInfo( |
122 base::SharedMemoryHandle shared_memory_handle, | 116 base::SharedMemoryHandle shared_memory_handle, |
123 size_t shared_memory_size, | 117 size_t shared_memory_size, |
124 base::SyncSocket::Handle socket_handle) { | 118 base::SyncSocket::Handle socket_handle) { |
125 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_, true); | 119 EnterResourceNoLock<PPB_AudioConfig_API> enter(config_, true); |
126 SetStreamInfo(pp_instance(), shared_memory_handle, shared_memory_size, | 120 SetStreamInfo(pp_instance(), |
127 socket_handle, enter.object()->GetSampleRate(), | 121 shared_memory_handle, |
| 122 shared_memory_size, |
| 123 socket_handle, |
| 124 enter.object()->GetSampleRate(), |
128 enter.object()->GetSampleFrameCount()); | 125 enter.object()->GetSampleFrameCount()); |
129 } | 126 } |
130 | 127 |
131 } // namespace content | 128 } // namespace content |
OLD | NEW |