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

Side by Side Diff: ppapi/proxy/audio_output_resource.h

Issue 2755613002: Support audio output device enumeration and selection in PPAPI (Closed)
Patch Set: Should not include local change to ppapi/generators/idl_outfile.py Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2017 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 #ifndef PPAPI_PROXY_AUDIO_OUTPUT_RESOURCE_H_
6 #define PPAPI_PROXY_AUDIO_OUTPUT_RESOURCE_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12
13 #include "base/compiler_specific.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/shared_memory.h"
17 #include "base/sync_socket.h"
18 #include "base/threading/simple_thread.h"
19 #include "ppapi/c/ppb_audio_config.h"
20 #include "ppapi/proxy/device_enumeration_resource_helper.h"
21 #include "ppapi/proxy/plugin_resource.h"
22 #include "ppapi/shared_impl/scoped_pp_resource.h"
23 #include "ppapi/thunk/ppb_audio_output_api.h"
24
25 namespace media {
26 class AudioBus;
27 }
28
29 namespace ppapi {
30 namespace proxy {
31
32 class ResourceMessageReplyParams;
33
34 class AudioOutputResource : public PluginResource,
35 public thunk::PPB_AudioOutput_API,
36 public base::DelegateSimpleThread::Delegate {
37 public:
38 AudioOutputResource(Connection connection, PP_Instance instance);
39 ~AudioOutputResource() override;
40
41 // Resource overrides.
42 thunk::PPB_AudioOutput_API* AsPPB_AudioOutput_API() override;
43 void OnReplyReceived(const ResourceMessageReplyParams& params,
44 const IPC::Message& msg) override;
45
46 // PPB_AudioOutput_API implementation.
47 int32_t EnumerateDevices(const PP_ArrayOutput& output,
48 scoped_refptr<TrackedCallback> callback) override;
49 int32_t MonitorDeviceChange(PP_MonitorDeviceChangeCallback callback,
50 void* user_data) override;
51 int32_t Open(PP_Resource device_ref,
52 PP_Resource config,
53 PPB_AudioOutput_Callback audio_output_callback,
54 void* user_data,
55 scoped_refptr<TrackedCallback> callback) override;
56
57 PP_Resource GetCurrentConfig() override;
58
59 bool playing() const { return playing_; }
60
61 PP_Bool StartPlayback() override;
62 PP_Bool StopPlayback() override;
63 void Close() override;
64
65 protected:
66 // Resource override.
67 void LastPluginRefWasDeleted() override;
68
69 private:
70 enum OpenState {
71 BEFORE_OPEN,
72 OPENED,
73 CLOSED
74 };
75
76 void OnPluginMsgOpenReply(const ResourceMessageReplyParams& params);
77
78 // Sets the shared memory and socket handles.
79 void SetStreamInfo(base::SharedMemoryHandle shared_memory_handle,
80 size_t shared_memory_size,
81 base::SyncSocket::Handle socket_handle);
82
83 // Starts execution of the audio output thread.
84 void StartThread();
85
86 // Stops execution of the audio output thread.
87 void StopThread();
88
89 // DelegateSimpleThread::Delegate implementation.
90 // Run on the audio output thread.
91 void Run() override;
92
93 int32_t CommonOpen(PP_Resource device_ref,
94 PP_Resource config,
95 PPB_AudioOutput_Callback audio_output_callback,
96 void* user_data,
97 scoped_refptr<TrackedCallback> callback);
98
99 OpenState open_state_;
100
101 // True if playing the stream.
102 bool playing_;
103
104 // Socket used to notify us when new samples are available. This pointer is
105 // created in SetStreamInfo().
106 std::unique_ptr<base::CancelableSyncSocket> socket_;
107
108 // Sample buffer in shared memory. This pointer is created in
109 // SetStreamInfo(). The memory is only mapped when the audio thread is
110 // created.
111 std::unique_ptr<base::SharedMemory> shared_memory_;
112
113 // The size of the sample buffer in bytes.
114 size_t shared_memory_size_;
115
116 // When the callback is set, this thread is spawned for calling it.
117 std::unique_ptr<base::DelegateSimpleThread> audio_output_thread_;
118
119 // Callback to call when new samples are available.
120 PPB_AudioOutput_Callback audio_output_callback_;
121
122 // User data pointer passed verbatim to the callback function.
123 void* user_data_;
124
125 // The callback is not directly passed to OnPluginMsgOpenReply() because we
126 // would like to be able to cancel it early in Close().
127 scoped_refptr<TrackedCallback> open_callback_;
128
129 // Owning reference to the current config object. This isn't actually used,
130 // we just dish it out as requested by the plugin.
131 ScopedPPResource config_;
132
133 DeviceEnumerationResourceHelper enumeration_helper_;
134
135 // The data size (in bytes) of one second of audio output. Used to calculate
136 // latency.
137 size_t bytes_per_second_;
138
139 // AudioBus for shuttling data across the shared memory.
140 std::unique_ptr<media::AudioBus> audio_bus_;
141 int sample_frame_count_;
142
143 // Internal buffer for client's integer audio data.
144 int client_buffer_size_bytes_;
145 std::unique_ptr<uint8_t[]> client_buffer_;
146
147 DISALLOW_COPY_AND_ASSIGN(AudioOutputResource);
148 };
149
150 } // namespace proxy
151 } // namespace ppapi
152
153 #endif // PPAPI_PROXY_AUDIO_OUTPUT_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698