Chromium Code Reviews| Index: content/renderer/media/audio_output_client.h |
| diff --git a/content/renderer/media/audio_output_client.h b/content/renderer/media/audio_output_client.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1bcc2b54d455fe0f63fd05d48cd0165e76e2a8cd |
| --- /dev/null |
| +++ b/content/renderer/media/audio_output_client.h |
| @@ -0,0 +1,115 @@ |
| +// 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_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ |
| +#define CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/files/file.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/shared_memory_handle.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/sync_socket.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "content/common/content_export.h" |
| +#include "media/mojo/interfaces/audio_output.mojom.h" |
| +#include "mojo/edk/embedder/embedder.h" |
| +#include "mojo/public/c/system/buffer.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "mojo/public/cpp/bindings/interface_request.h" |
| +#include "mojo/public/cpp/system/handle.h" |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +} |
| + |
| +namespace media { |
| +class AudioParameters; |
| +} |
| + |
| +namespace content { |
| + |
| +class AudioMessageFilter; |
| +class ServiceRegistry; |
| + |
| +class CONTENT_EXPORT AudioOutputClient |
| + : public base::RefCounted<AudioOutputClient> { |
| + public: |
| + using AudioOutputStreamPtrMap = |
| + std::map<int, media::mojom::AudioOutputStreamPtr>; |
| + |
| + // Creates a Mojo Audio Output Client. It's going to be created by |
| + // RenderThreadImpl::init() and be bound to RenderThread. This means that all |
|
nasko
2016/05/25 20:50:42
nit: Init.
rchtara
2016/05/27 15:24:39
Done.
|
| + // future Mojo service calls and all Mojo callbacks are going to be |
| + // performed on the RenderThread. |
| + explicit AudioOutputClient( |
| + ServiceRegistry* service_registry, |
| + const scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner = |
| + base::MessageLoop::current()->task_runner()); |
| + |
| + // Creates stream by calling the AudioOutput.CreateStream Mojo interface |
| + // function using the Mojo service. This function could be called on any |
| + // thread and is going to call itself in the RenderThread if it's not |
| + // already running there. |
| + void CreateStream(int stream_id, |
| + const media::AudioParameters& params, |
| + const media::mojom::AudioOutput::CreateStreamCallback& |
| + create_stream_callback); |
| + |
| + // Callback for AudioOutput.CreateStream which contains information about |
| + // the new created stream. Called on RenderThread. This function is going to |
| + // notify the |audio_message_filter_| of the stream creation by calling |
| + // StreamCreated. StreamCreated could only be ran on |io_task_runner_| and |
| + // this is why CreateStreamOnIOThread is going to be used to do that. |
| + void CreateStreamCallback(int stream_id, |
| + media::mojom::AudioOutputStreamPtr stream, |
| + mojo::ScopedSharedBufferHandle shared_buffer, |
| + mojo::ScopedHandle socket_descriptor); |
| + |
| + // Closes stream by calling the AudioOutputStream.Close Mojo interface |
| + // function using the Mojo service. This function could be called on any |
| + // thread and is going to call itself in the RenderThread if it's not |
| + // already running there. |
| + void CloseStream(int stream_id); |
| + |
| + private: |
| + friend class base::RefCounted<AudioOutputClient>; |
| + friend class AudioOutputClientTest; |
| + FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, CreateStream); |
| + FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, |
| + CloseAuthorizedNotCreatedStream); |
| + FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, CloseCreatedStream); |
| + |
| + ~AudioOutputClient(); |
| + |
| + // Notifies the |audio_message_filter_| of the stream creation. Can only be |
| + // called on |io_task_runner_|. |
| + void CreateStreamOnIOThread( |
| + AudioOutputClient::AudioOutputStreamPtrMap::iterator stream, |
| + base::SharedMemoryHandle handle, |
| + base::SyncSocket::TransitDescriptor socket_descriptor, |
| + uint32_t length); |
| + |
| + // Called when there is an error with AudioOutputStream Mojo interface in |
| + // the renderer. This function is going to call ReportErrorOnIOThread in the |
| + // RenderThread. |
| + void OnStreamError(int stream_id); |
| + |
| + // Notifies the |audio_message_filter_| of a stream error. Can only be called |
| + // on |io_task_runner_|. |
| + void ReportErrorOnIOThread(int stream_id); |
| + |
| + const scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner_; |
| + media::mojom::AudioOutputPtr service_; |
| + AudioOutputStreamPtrMap streams_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioOutputClient); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ |