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