[email protected] | aed9653 | 2012-06-23 14:27:42 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_ |
6 | #define CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_ | ||||
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 7 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 8 | #include <stddef.h> |
9 | #include <stdint.h> | ||||
10 | |||||
11 | #include "base/macros.h" | ||||
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 8299b71 | 2013-07-17 19:55:23 | [diff] [blame] | 13 | #include "base/memory/shared_memory.h" |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 14 | #include "base/sync_socket.h" |
tommycli | 43d8cc4 | 2015-03-20 17:48:19 | [diff] [blame] | 15 | #include "content/public/renderer/plugin_instance_throttler.h" |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 16 | #include "content/renderer/pepper/audio_helper.h" |
[email protected] | 0641727 | 2010-11-25 00:29:25 | [diff] [blame] | 17 | #include "ppapi/c/pp_completion_callback.h" |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 18 | #include "ppapi/c/ppb_audio.h" |
19 | #include "ppapi/c/ppb_audio_config.h" | ||||
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 20 | #include "ppapi/shared_impl/ppb_audio_config_shared.h" |
21 | #include "ppapi/shared_impl/ppb_audio_shared.h" | ||||
[email protected] | 56d7ad4 | 2011-12-07 00:01:30 | [diff] [blame] | 22 | #include "ppapi/shared_impl/resource.h" |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 23 | #include "ppapi/shared_impl/scoped_pp_resource.h" |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 24 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 25 | namespace content { |
[email protected] | c0cf2f1 | 2013-07-28 21:22:30 | [diff] [blame] | 26 | class PepperPlatformAudioOutput; |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 27 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 28 | // Some of the backend functionality of this class is implemented by the |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 29 | // PPB_Audio_Shared so it can be shared with the proxy. |
[email protected] | 79d816c | 2014-02-25 09:49:20 | [diff] [blame] | 30 | // |
31 | // TODO(teravest): PPB_Audio is no longer supported in-process. Clean this up | ||||
32 | // to look more like typical HostResource implementations. | ||||
[email protected] | 49323b3 | 2013-08-09 16:05:06 | [diff] [blame] | 33 | class PPB_Audio_Impl : public ppapi::Resource, |
34 | public ppapi::PPB_Audio_Shared, | ||||
tommycli | 43d8cc4 | 2015-03-20 17:48:19 | [diff] [blame] | 35 | public AudioHelper, |
36 | public PluginInstanceThrottler::Observer { | ||||
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 37 | public: |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 38 | explicit PPB_Audio_Impl(PP_Instance instance); |
[email protected] | 6328a5b | 2011-06-22 21:48:36 | [diff] [blame] | 39 | |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 40 | // Resource overrides. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 41 | ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API() override; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 42 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 43 | // PPB_Audio_API implementation. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 44 | PP_Resource GetCurrentConfig() override; |
45 | PP_Bool StartPlayback() override; | ||||
46 | PP_Bool StopPlayback() override; | ||||
47 | int32_t Open(PP_Resource config_id, | ||||
48 | scoped_refptr<ppapi::TrackedCallback> create_callback) override; | ||||
49 | int32_t GetSyncSocket(int* sync_socket) override; | ||||
erikchen | 4fc32d5 | 2015-06-02 02:16:38 | [diff] [blame] | 50 | int32_t GetSharedMemory(base::SharedMemory** shm, |
51 | uint32_t* shm_size) override; | ||||
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 52 | |
53 | private: | ||||
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 54 | ~PPB_Audio_Impl() override; |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 55 | |
[email protected] | 1f8a089 | 2011-11-18 00:14:24 | [diff] [blame] | 56 | // AudioHelper implementation. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 57 | void OnSetStreamInfo(base::SharedMemoryHandle shared_memory_handle, |
58 | size_t shared_memory_size_, | ||||
59 | base::SyncSocket::Handle socket) override; | ||||
[email protected] | b0deb15 | 2010-08-31 17:37:35 | [diff] [blame] | 60 | |
tommycli | 43d8cc4 | 2015-03-20 17:48:19 | [diff] [blame] | 61 | // PluginInstanceThrottler::Observer implementation. |
62 | void OnThrottleStateChange() override; | ||||
63 | |||||
64 | // Starts the deferred playback and unsubscribes from the throttler. | ||||
65 | void StartDeferredPlayback(); | ||||
66 | |||||
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 67 | // AudioConfig used for creating this Audio object. We own a ref. |
[email protected] | 49323b3 | 2013-08-09 16:05:06 | [diff] [blame] | 68 | ppapi::ScopedPPResource config_; |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 69 | |
[email protected] | 9ca245e | 2011-03-18 01:50:31 | [diff] [blame] | 70 | // PluginDelegate audio object that we delegate audio IPC through. We don't |
71 | // own this pointer but are responsible for calling Shutdown on it. | ||||
[email protected] | c0cf2f1 | 2013-07-28 21:22:30 | [diff] [blame] | 72 | PepperPlatformAudioOutput* audio_; |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 73 | |
tommycli | 43d8cc4 | 2015-03-20 17:48:19 | [diff] [blame] | 74 | // Stream is playing, but throttled due to Plugin Power Saver. |
75 | bool playback_throttled_; | ||||
76 | |||||
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 78 | }; |
79 | |||||
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 80 | } // namespace content |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 81 | |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 82 | #endif // CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_ |