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

Side by Side Diff: ppapi/shared_impl/ppb_audio_shared.h

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, 3 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
« no previous file with comments | « ppapi/shared_impl/ppb_audio_config_shared.h ('k') | ppapi/shared_impl/ppb_audio_shared.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ 5 #ifndef PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_
6 #define PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ 6 #define PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "base/sync_socket.h" 10 #include "base/sync_socket.h"
11 #include "base/threading/simple_thread.h" 11 #include "base/threading/simple_thread.h"
12 #include "media/base/audio_bus.h" 12 #include "media/base/audio_bus.h"
13 #include "ppapi/c/ppb_audio.h" 13 #include "ppapi/c/ppb_audio.h"
14 #include "ppapi/c/ppb_audio_config.h"
14 #include "ppapi/shared_impl/resource.h" 15 #include "ppapi/shared_impl/resource.h"
15 #include "ppapi/thunk/ppb_audio_api.h" 16 #include "ppapi/thunk/ppb_audio_api.h"
16 17
17 #if defined(OS_NACL) 18 #if defined(OS_NACL)
18 #include "native_client/src/untrusted/irt/irt_ppapi.h" 19 #include "native_client/src/untrusted/irt/irt_ppapi.h"
19 #endif 20 #endif
20 21
21 namespace ppapi { 22 namespace ppapi {
22 23
24 class PPAPI_SHARED_EXPORT AudioCallbackCombined {
25 public:
26 AudioCallbackCombined();
27 explicit AudioCallbackCombined(PPB_Audio_Callback_1_0 callback_1_0);
28 explicit AudioCallbackCombined(PPB_Audio_Callback callback);
29
30 ~AudioCallbackCombined();
31
32 bool IsValid() const;
33
34 void Run(void* sample_buffer,
35 uint32_t buffer_size_in_bytes,
36 PP_TimeDelta latency,
37 void* user_data) const;
38
39 private:
40 PPB_Audio_Callback_1_0 callback_1_0_;
41 PPB_Audio_Callback callback_;
42 };
43
23 // Implements the logic to map shared memory and run the audio thread signaled 44 // Implements the logic to map shared memory and run the audio thread signaled
24 // from the sync socket. Both the proxy and the renderer implementation use 45 // from the sync socket. Both the proxy and the renderer implementation use
25 // this code. 46 // this code.
26 class PPAPI_SHARED_EXPORT PPB_Audio_Shared 47 class PPAPI_SHARED_EXPORT PPB_Audio_Shared
27 : public thunk::PPB_Audio_API, 48 : public thunk::PPB_Audio_API,
28 public base::DelegateSimpleThread::Delegate { 49 public base::DelegateSimpleThread::Delegate {
29 public: 50 public:
30 PPB_Audio_Shared(); 51 PPB_Audio_Shared();
31 virtual ~PPB_Audio_Shared(); 52 virtual ~PPB_Audio_Shared();
32 53
33 bool playing() const { return playing_; } 54 bool playing() const { return playing_; }
34 55
35 // Sets the callback information that the background thread will use. This 56 // Sets the callback information that the background thread will use. This
36 // is optional. Without a callback, the thread will not be run. This 57 // is optional. Without a callback, the thread will not be run. This
37 // non-callback mode is used in the renderer with the proxy, since the proxy 58 // non-callback mode is used in the renderer with the proxy, since the proxy
38 // handles the callback entirely within the plugin process. 59 // handles the callback entirely within the plugin process.
39 void SetCallback(PPB_Audio_Callback callback, void* user_data); 60 void SetCallback(const AudioCallbackCombined& callback, void* user_data);
40 61
41 // Configures the current state to be playing or not. The caller is 62 // Configures the current state to be playing or not. The caller is
42 // responsible for ensuring the new state is the opposite of the current one. 63 // responsible for ensuring the new state is the opposite of the current one.
43 // 64 //
44 // This is the implementation for PPB_Audio.Start/StopPlayback, except that 65 // This is the implementation for PPB_Audio.Start/StopPlayback, except that
45 // it does not actually notify the audio system to stop playback, it just 66 // it does not actually notify the audio system to stop playback, it just
46 // configures our object to stop generating callbacks. The actual stop 67 // configures our object to stop generating callbacks. The actual stop
47 // playback request will be done in the derived classes and will be different 68 // playback request will be done in the derived classes and will be different
48 // from the proxy and the renderer. 69 // from the proxy and the renderer.
49 void SetStartPlaybackState(); 70 void SetStartPlaybackState();
50 void SetStopPlaybackState(); 71 void SetStopPlaybackState();
51 72
52 // Sets the shared memory and socket handles. This will automatically start 73 // Sets the shared memory and socket handles. This will automatically start
53 // playback if we're currently set to play. 74 // playback if we're currently set to play.
54 void SetStreamInfo(PP_Instance instance, 75 void SetStreamInfo(PP_Instance instance,
55 base::SharedMemoryHandle shared_memory_handle, 76 base::SharedMemoryHandle shared_memory_handle,
56 size_t shared_memory_size, 77 size_t shared_memory_size,
57 base::SyncSocket::Handle socket_handle, 78 base::SyncSocket::Handle socket_handle,
79 PP_AudioSampleRate sample_rate,
58 int sample_frame_count); 80 int sample_frame_count);
59 81
60 #if defined(OS_NACL) 82 #if defined(OS_NACL)
61 // NaCl has a special API for IRT code to create threads that can call back 83 // NaCl has a special API for IRT code to create threads that can call back
62 // into user code. 84 // into user code.
63 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); 85 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions);
64 #endif 86 #endif
65 87
66 private: 88 private:
67 // Starts execution of the audio thread. 89 // Starts execution of the audio thread.
(...skipping 24 matching lines...) Expand all
92 // When the callback is set, this thread is spawned for calling it. 114 // When the callback is set, this thread is spawned for calling it.
93 scoped_ptr<base::DelegateSimpleThread> audio_thread_; 115 scoped_ptr<base::DelegateSimpleThread> audio_thread_;
94 #else 116 #else
95 uintptr_t thread_id_; 117 uintptr_t thread_id_;
96 bool thread_active_; 118 bool thread_active_;
97 119
98 static void CallRun(void* self); 120 static void CallRun(void* self);
99 #endif 121 #endif
100 122
101 // Callback to call when audio is ready to accept new samples. 123 // Callback to call when audio is ready to accept new samples.
102 PPB_Audio_Callback callback_; 124 AudioCallbackCombined callback_;
103 125
104 // User data pointer passed verbatim to the callback function. 126 // User data pointer passed verbatim to the callback function.
105 void* user_data_; 127 void* user_data_;
106 128
107 // AudioBus for shuttling data across the shared memory. 129 // AudioBus for shuttling data across the shared memory.
108 scoped_ptr<media::AudioBus> audio_bus_; 130 scoped_ptr<media::AudioBus> audio_bus_;
109 131
110 // Internal buffer for client's integer audio data. 132 // Internal buffer for client's integer audio data.
111 int client_buffer_size_bytes_; 133 int client_buffer_size_bytes_;
112 scoped_ptr<uint8_t[]> client_buffer_; 134 scoped_ptr<uint8_t[]> client_buffer_;
113 135
136 // The size (in bytes) of one second of audio data. Used to calculate latency.
137 size_t bytes_per_second_;
138
114 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); 139 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared);
115 }; 140 };
116 141
117 } // namespace ppapi 142 } // namespace ppapi
118 143
119 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ 144 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_audio_config_shared.h ('k') | ppapi/shared_impl/ppb_audio_shared.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698