OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_SERVICE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_SERVICE_IMPL_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 #include <string> |
| 11 #include <utility> |
| 12 |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "media/audio_output.mojom.h" |
| 15 #include "mojo/public/cpp/bindings/string.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 class CONTENT_EXPORT AudioOutputServiceImpl : public mojom::AudioOutputService, |
| 20 public RefCountedThreadSafe, |
| 21 public AudioOutputServiceBase { |
| 22 public: |
| 23 AudioOutputServiceImpl(int render_process_id, |
| 24 media::AudioManager* audio_manager, |
| 25 AudioMirroringManager* mirroring_manager, |
| 26 MediaInternals* media_internals, |
| 27 MediaStreamManager* media_stream_manager, |
| 28 const std::string& salt); |
| 29 |
| 30 // AudioOutputServiceBase implementation. |
| 31 // Calls |callback| with the list of AudioOutputControllers for this object. |
| 32 void GetOutputControllers( |
| 33 const RenderProcessHost::GetAudioOutputControllersCallback& callback) |
| 34 override const; |
| 35 // Returns true if any streams managed by this host are actively playing. Can |
| 36 // be called from any thread. |
| 37 bool HasActiveAudio(); |
| 38 |
| 39 // AudioOutputService implementation. |
| 40 void RequestDeviceAuthorization( |
| 41 int64_t render_frame_id, |
| 42 int64_t session_id, |
| 43 const mojo::String& device_id, |
| 44 AudioOutputRequest audio_output, |
| 45 const url::Origin& origin, |
| 46 const RequestDeviceAuthorizationCallback& callback) override; |
| 47 |
| 48 void AudioRendererHost::NotifyStreamCreated(BindingId binding); |
| 49 void AudioRendererHost::NotifyStreamStateChanged(BindingId binding, |
| 50 bool is_playing); |
| 51 |
| 52 private: |
| 53 void AudioRendererHost::DoNotifyStreamCreated(BindingId binding); |
| 54 void AudioRendererHost::DoNotifyStreamStateChanged(BindingId binding, |
| 55 bool is_playing); |
| 56 |
| 57 void RegisterStartedStream(BindingId binding_id); |
| 58 |
| 59 // Threadsafe. |
| 60 std::unique_ptr<media::AudioLog> audio_log_; |
| 61 |
| 62 scoped_refptr<base::SingleThreadedTaskRunner> task_runner_; |
| 63 |
| 64 // ID of the RenderProcessHost that owns this instance. |
| 65 const int render_process_id_; |
| 66 |
| 67 media::AudioManager* const audio_manager_; |
| 68 AudioMirroringManager* const mirroring_manager_; |
| 69 |
| 70 // Used to access to AudioInputDeviceManager. |
| 71 MediaStreamManager* const media_stream_manager_; |
| 72 |
| 73 // The number of streams in the playing state. Atomic read safe from any |
| 74 // thread, but should only be updated from the creation thread. |
| 75 base::AtomicRefCount num_playing_streams_; |
| 76 |
| 77 // Salt required to translate renderer device IDs to raw device unique IDs |
| 78 const std::string salt_; |
| 79 |
| 80 // Map of device authorizations for streams that are not yet created |
| 81 // The key is the stream ID, and the value is a pair. The pair's first element |
| 82 // is a bool that is true if the authorization process completes successfully. |
| 83 // The second element contains the unique ID of the authorized device. |
| 84 std::map<int, std::pair<bool, std::string>> authorizations_; |
| 85 |
| 86 #if DCHECK_IS_ON() |
| 87 // When DCHECKs are turned on, AudioRendererHost will call this function on |
| 88 // the UI thread to validate render frame IDs. A default is set by the |
| 89 // constructor, but this can be overridden by unit tests. |
| 90 ValidateRenderFrameIdFunction validate_render_frame_id_function_; |
| 91 #endif // DCHECK_IS_ON() |
| 92 |
| 93 // The maximum number of simultaneous streams during the lifetime of this |
| 94 // host. Reported as UMA stat at shutdown. |
| 95 size_t max_simultaneous_streams_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(AudioOutputServiceImpl); |
| 98 }; |
| 99 |
| 100 } // namespace content |
| 101 |
| 102 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_SERVICE_IMPL_H_ |
OLD | NEW |