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_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ | |
6 #define CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/files/file.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/shared_memory_handle.h" | |
14 #include "base/message_loop/message_loop.h" | |
15 #include "base/sync_socket.h" | |
16 #include "base/threading/thread_checker.h" | |
17 #include "content/common/content_export.h" | |
18 #include "media/mojo/interfaces/audio_output.mojom.h" | |
19 #include "mojo/edk/embedder/embedder.h" | |
20 #include "mojo/public/c/system/buffer.h" | |
21 #include "mojo/public/cpp/bindings/binding.h" | |
22 #include "mojo/public/cpp/bindings/binding.h" | |
23 #include "mojo/public/cpp/bindings/interface_request.h" | |
24 #include "mojo/public/cpp/system/handle.h" | |
25 | |
26 namespace base { | |
27 class SingleThreadTaskRunner; | |
28 } | |
29 | |
30 namespace media { | |
31 class AudioParameters; | |
32 } | |
33 | |
34 namespace content { | |
35 | |
36 class AudioMessageFilter; | |
37 class ServiceRegistry; | |
38 | |
39 class CONTENT_EXPORT AudioOutputClient | |
40 : public base::RefCounted<AudioOutputClient> { | |
41 public: | |
42 using AudioOutputStreamPtrMap = | |
43 std::map<int, media::mojom::AudioOutputStreamPtr>; | |
44 | |
45 // Creates a Mojo Audio Output Client. It's going to be created by | |
46 // 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.
| |
47 // future Mojo service calls and all Mojo callbacks are going to be | |
48 // performed on the RenderThread. | |
49 explicit AudioOutputClient( | |
50 ServiceRegistry* service_registry, | |
51 const scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner = | |
52 base::MessageLoop::current()->task_runner()); | |
53 | |
54 // Creates stream by calling the AudioOutput.CreateStream Mojo interface | |
55 // function using the Mojo service. This function could be called on any | |
56 // thread and is going to call itself in the RenderThread if it's not | |
57 // already running there. | |
58 void CreateStream(int stream_id, | |
59 const media::AudioParameters& params, | |
60 const media::mojom::AudioOutput::CreateStreamCallback& | |
61 create_stream_callback); | |
62 | |
63 // Callback for AudioOutput.CreateStream which contains information about | |
64 // the new created stream. Called on RenderThread. This function is going to | |
65 // notify the |audio_message_filter_| of the stream creation by calling | |
66 // StreamCreated. StreamCreated could only be ran on |io_task_runner_| and | |
67 // this is why CreateStreamOnIOThread is going to be used to do that. | |
68 void CreateStreamCallback(int stream_id, | |
69 media::mojom::AudioOutputStreamPtr stream, | |
70 mojo::ScopedSharedBufferHandle shared_buffer, | |
71 mojo::ScopedHandle socket_descriptor); | |
72 | |
73 // Closes stream by calling the AudioOutputStream.Close Mojo interface | |
74 // function using the Mojo service. This function could be called on any | |
75 // thread and is going to call itself in the RenderThread if it's not | |
76 // already running there. | |
77 void CloseStream(int stream_id); | |
78 | |
79 private: | |
80 friend class base::RefCounted<AudioOutputClient>; | |
81 friend class AudioOutputClientTest; | |
82 FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, CreateStream); | |
83 FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, | |
84 CloseAuthorizedNotCreatedStream); | |
85 FRIEND_TEST_ALL_PREFIXES(AudioOutputClientTest, CloseCreatedStream); | |
86 | |
87 ~AudioOutputClient(); | |
88 | |
89 // Notifies the |audio_message_filter_| of the stream creation. Can only be | |
90 // called on |io_task_runner_|. | |
91 void CreateStreamOnIOThread( | |
92 AudioOutputClient::AudioOutputStreamPtrMap::iterator stream, | |
93 base::SharedMemoryHandle handle, | |
94 base::SyncSocket::TransitDescriptor socket_descriptor, | |
95 uint32_t length); | |
96 | |
97 // Called when there is an error with AudioOutputStream Mojo interface in | |
98 // the renderer. This function is going to call ReportErrorOnIOThread in the | |
99 // RenderThread. | |
100 void OnStreamError(int stream_id); | |
101 | |
102 // Notifies the |audio_message_filter_| of a stream error. Can only be called | |
103 // on |io_task_runner_|. | |
104 void ReportErrorOnIOThread(int stream_id); | |
105 | |
106 const scoped_refptr<base::SingleThreadTaskRunner> thread_task_runner_; | |
107 media::mojom::AudioOutputPtr service_; | |
108 AudioOutputStreamPtrMap streams_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(AudioOutputClient); | |
111 }; | |
112 | |
113 } // namespace content | |
114 | |
115 #endif // CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_ | |
OLD | NEW |