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

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

Issue 8138008: Implementation of ppapi audio. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/c/pp_completion_callback.h"
6 #include "webkit/plugins/ppapi/audio_helper.h"
7 #include "webkit/plugins/ppapi/common.h"
8 #include "webkit/plugins/ppapi/resource_helper.h"
9
10 namespace webkit {
11 namespace ppapi {
12
13 // AudioHelper ------------------------------------------------
14
15 AudioHelper::AudioHelper()
16 : create_callback_pending_(false),
17 shared_memory_size_for_create_callback_(0) {
18 create_callback_ = PP_MakeCompletionCallback(NULL, NULL);
19 }
20
21 AudioHelper::~AudioHelper() {
22 // If the completion callback hasn't fired yet, do so here
23 // with an error condition.
24 if (create_callback_pending_) {
25 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED);
26 create_callback_pending_ = false;
27 }
28 }
29
30 int32_t AudioHelper::GetSyncSocket(int* sync_socket) {
31 if (socket_for_create_callback_.get()) {
32 #if defined(OS_POSIX)
33 *sync_socket = socket_for_create_callback_->handle();
34 #elif defined(OS_WIN)
35 *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle());
36 #else
37 #error "Platform not supported."
38 #endif
39 return PP_OK;
40 }
41 return PP_ERROR_FAILED;
42 }
43
44 int32_t AudioHelper::GetSharedMemory(int* shm_handle,
45 uint32_t* shm_size) {
46 if (shared_memory_for_create_callback_.get()) {
47 #if defined(OS_POSIX)
48 *shm_handle = shared_memory_for_create_callback_->handle().fd;
49 #elif defined(OS_WIN)
50 *shm_handle = reinterpret_cast<int>(
51 shared_memory_for_create_callback_->handle());
52 #else
53 #error "Platform not supported."
54 #endif
55 *shm_size = shared_memory_size_for_create_callback_;
56 return PP_OK;
57 }
58 return PP_ERROR_FAILED;
59 }
60
61 void AudioHelper::StreamCreated_(
62 base::SharedMemoryHandle shared_memory_handle,
63 size_t shared_memory_size,
64 base::SyncSocket::Handle socket_handle) {
65 if (create_callback_pending_) {
66 // Trusted side of proxy can specify a callback to recieve handles. In
67 // this case we don't need to map any data or start the thread since it
68 // will be handled by the proxy.
69 shared_memory_for_create_callback_.reset(
70 new base::SharedMemory(shared_memory_handle, false));
71 shared_memory_size_for_create_callback_ = shared_memory_size;
72 socket_for_create_callback_.reset(new base::SyncSocket(socket_handle));
73
74 PP_RunCompletionCallback(&create_callback_, 0);
75 create_callback_pending_ = false;
76
77 // It might be nice to close the handles here to free up some system
78 // resources, but we can't since there's a race condition. The handles must
79 // be valid until they're sent over IPC, which is done from the I/O thread
80 // which will often get done after this code executes. We could do
81 // something more elaborate like an ACK from the plugin or post a task to
82 // the I/O thread and back, but this extra complexity doesn't seem worth it
83 // just to clean up these handles faster.
84 } else {
85 OnSetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
86 }
87 }
88
89 void AudioHelper::SetCallbackInfo(bool create_callback_pending,
90 PP_CompletionCallback create_callback) {
91 create_callback_pending_ = create_callback_pending;
92 create_callback_ = create_callback;
93 }
94
95 } // namespace ppapi
96 } // namespace webkit
97
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698