Index: content/browser/renderer_host/media/audio_output_service_impl.h |
diff --git a/content/browser/renderer_host/media/audio_output_service_impl.h b/content/browser/renderer_host/media/audio_output_service_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e5fca67847edad82e6ae07c06ced7f010077e630 |
--- /dev/null |
+++ b/content/browser/renderer_host/media/audio_output_service_impl.h |
@@ -0,0 +1,102 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_SERVICE_IMPL_H_ |
+#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_SERVICE_IMPL_H_ |
+ |
+#include <map> |
+#include <memory> |
+#include <string> |
+#include <utility> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "media/audio_output.mojom.h" |
+#include "mojo/public/cpp/bindings/string.h" |
+ |
+namespace content { |
+ |
+class CONTENT_EXPORT AudioOutputServiceImpl : public mojom::AudioOutputService, |
+ public RefCountedThreadSafe, |
+ public AudioOutputServiceBase { |
+ public: |
+ AudioOutputServiceImpl(int render_process_id, |
+ media::AudioManager* audio_manager, |
+ AudioMirroringManager* mirroring_manager, |
+ MediaInternals* media_internals, |
+ MediaStreamManager* media_stream_manager, |
+ const std::string& salt); |
+ |
+ // AudioOutputServiceBase implementation. |
+ // Calls |callback| with the list of AudioOutputControllers for this object. |
+ void GetOutputControllers( |
+ const RenderProcessHost::GetAudioOutputControllersCallback& callback) |
+ override const; |
+ // Returns true if any streams managed by this host are actively playing. Can |
+ // be called from any thread. |
+ bool HasActiveAudio(); |
+ |
+ // AudioOutputService implementation. |
+ void RequestDeviceAuthorization( |
+ int64_t render_frame_id, |
+ int64_t session_id, |
+ const mojo::String& device_id, |
+ AudioOutputRequest audio_output, |
+ const url::Origin& origin, |
+ const RequestDeviceAuthorizationCallback& callback) override; |
+ |
+ void AudioRendererHost::NotifyStreamCreated(BindingId binding); |
+ void AudioRendererHost::NotifyStreamStateChanged(BindingId binding, |
+ bool is_playing); |
+ |
+ private: |
+ void AudioRendererHost::DoNotifyStreamCreated(BindingId binding); |
+ void AudioRendererHost::DoNotifyStreamStateChanged(BindingId binding, |
+ bool is_playing); |
+ |
+ void RegisterStartedStream(BindingId binding_id); |
+ |
+ // Threadsafe. |
+ std::unique_ptr<media::AudioLog> audio_log_; |
+ |
+ scoped_refptr<base::SingleThreadedTaskRunner> task_runner_; |
+ |
+ // ID of the RenderProcessHost that owns this instance. |
+ const int render_process_id_; |
+ |
+ media::AudioManager* const audio_manager_; |
+ AudioMirroringManager* const mirroring_manager_; |
+ |
+ // Used to access to AudioInputDeviceManager. |
+ MediaStreamManager* const media_stream_manager_; |
+ |
+ // The number of streams in the playing state. Atomic read safe from any |
+ // thread, but should only be updated from the creation thread. |
+ base::AtomicRefCount num_playing_streams_; |
+ |
+ // Salt required to translate renderer device IDs to raw device unique IDs |
+ const std::string salt_; |
+ |
+ // Map of device authorizations for streams that are not yet created |
+ // The key is the stream ID, and the value is a pair. The pair's first element |
+ // is a bool that is true if the authorization process completes successfully. |
+ // The second element contains the unique ID of the authorized device. |
+ std::map<int, std::pair<bool, std::string>> authorizations_; |
+ |
+#if DCHECK_IS_ON() |
+ // When DCHECKs are turned on, AudioRendererHost will call this function on |
+ // the UI thread to validate render frame IDs. A default is set by the |
+ // constructor, but this can be overridden by unit tests. |
+ ValidateRenderFrameIdFunction validate_render_frame_id_function_; |
+#endif // DCHECK_IS_ON() |
+ |
+ // The maximum number of simultaneous streams during the lifetime of this |
+ // host. Reported as UMA stat at shutdown. |
+ size_t max_simultaneous_streams_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputServiceImpl); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_OUTPUT_SERVICE_IMPL_H_ |