OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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_SHARED_IMPL_AUDIO_IMPL_H_ |
| 6 #define PPAPI_SHARED_IMPL_AUDIO_IMPL_H_ |
| 7 |
| 8 #include "base/scoped_ptr.h" |
| 9 #include "base/simple_thread.h" |
| 10 #include "base/shared_memory.h" |
| 11 #include "base/sync_socket.h" |
| 12 #include "ppapi/c/dev/ppb_audio_dev.h" |
| 13 |
| 14 namespace pp { |
| 15 namespace shared_impl { |
| 16 |
| 17 // Implements the logic to map shared memory and run the audio thread signaled |
| 18 // from the sync socket. Both the proxy and the renderer implementation use |
| 19 // this code. |
| 20 class AudioImpl : public base::DelegateSimpleThread::Delegate { |
| 21 public: |
| 22 AudioImpl(); |
| 23 virtual ~AudioImpl(); |
| 24 |
| 25 bool playing() const { return playing_; } |
| 26 |
| 27 // Sets the callback information that the background thread will use. This |
| 28 // is optional. Without a callback, the thread will not be run. This |
| 29 // non-callback mode is used in the renderer with the proxy, since the proxy |
| 30 // handles the callback entirely within the plugin process. |
| 31 void SetCallback(PPB_Audio_Callback callback, void* user_data); |
| 32 |
| 33 // Configures the current state to be playing or not. The caller is |
| 34 // responsible for ensuring the new state is the opposite of the current one. |
| 35 // |
| 36 // This is the implementation for PPB_Audio.Start/StopPlayback, except that |
| 37 // it does not actually notify the audio system to stop playback, it just |
| 38 // configures our object to stop generating callbacks. The actual stop |
| 39 // playback request will be done in the derived classes and will be different |
| 40 // from the proxy and the renderer. |
| 41 void SetStartPlaybackState(); |
| 42 void SetStopPlaybackState(); |
| 43 |
| 44 // Sets the shared memory and socket handles. This will automatically start |
| 45 // playback if we're currently set to play. |
| 46 void SetStreamInfo(base::SharedMemoryHandle shared_memory_handle, |
| 47 size_t shared_memory_size, |
| 48 base::SyncSocket::Handle socket_handle); |
| 49 |
| 50 private: |
| 51 // Starts execution of the audio thread. |
| 52 void StartThread(); |
| 53 |
| 54 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. |
| 55 void Run(); |
| 56 |
| 57 // True if playing the stream. |
| 58 bool playing_; |
| 59 |
| 60 // Socket used to notify us when audio is ready to accept new samples. This |
| 61 // pointer is created in StreamCreated(). |
| 62 scoped_ptr<base::SyncSocket> socket_; |
| 63 |
| 64 // Sample buffer in shared memory. This pointer is created in |
| 65 // StreamCreated(). The memory is only mapped when the audio thread is |
| 66 // created. |
| 67 scoped_ptr<base::SharedMemory> shared_memory_; |
| 68 |
| 69 // The size of the sample buffer in bytes. |
| 70 size_t shared_memory_size_; |
| 71 |
| 72 // When the callback is set, this thread is spawned for calling it. |
| 73 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
| 74 |
| 75 // Callback to call when audio is ready to accept new samples. |
| 76 PPB_Audio_Callback callback_; |
| 77 |
| 78 // User data pointer passed verbatim to the callback function. |
| 79 void* user_data_; |
| 80 }; |
| 81 |
| 82 } // namespace shared_impl |
| 83 } // namespace pp |
| 84 |
| 85 #endif // PPAPI_SHARED_IMPL_AUDIO_IMPL_H_ |
OLD | NEW |