Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: content/renderer/media/audio_output_client.h

Issue 1930393002: Switch stream creation and closing in Chrome audio rendering from IPC to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + tests in progress Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/sync_socket.h"
15 #include "base/threading/thread_checker.h"
16 #include "content/common/content_export.h"
17 #include "media/mojo/interfaces/audio_output.mojom.h"
18 #include "mojo/edk/embedder/embedder.h"
19 #include "mojo/public/c/system/buffer.h"
20 #include "mojo/public/cpp/bindings/binding.h"
21 #include "mojo/public/cpp/bindings/binding.h"
22 #include "mojo/public/cpp/bindings/interface_request.h"
23 #include "mojo/public/cpp/system/handle.h"
24
25 namespace base {
26 class SingleThreadTaskRunner;
27 }
28
29 namespace media {
30 class AudioParameters;
31 }
32
33 namespace content {
34
35 class AudioMessageFilter;
36 class ServiceRegistry;
37
38 class CONTENT_EXPORT AudioOutputClient
39 : public base::RefCounted<AudioOutputClient> {
40 public:
41 using AudioOutputStreamPtrMap =
42 std::map<int, media::mojom::AudioOutputStreamPtr>;
43
44 // Creates a Mojo Audio Output Client. It's going to be created by
45 // RenderThreadImpl::init() and be bound to RenderThread. This means that all
46 // future Mojo service calls and all Mojo callbacks are going to be
47 // performed on the RenderThread.
48 explicit AudioOutputClient(ServiceRegistry* service_registry);
49
50 // Creates stream by calling the AudioOutput.CreateStream Mojo interface
51 // function using the Mojo service. This function could be called on any
52 // thread and is going to call itself in the RenderThread if it's not
53 // already running there.
54 void CreateStream(int stream_id, const media::AudioParameters& params);
55
56 // Closes stream by calling the AudioOutputStream.Close Mojo interface
57 // function using the Mojo service. This function could be called on any
58 // thread and is going to call itself in the RenderThread if it's not
59 // already running there.
60 void CloseStream(int stream_id);
61
62 private:
63 friend class base::RefCounted<AudioOutputClient>;
64
65 ~AudioOutputClient();
66
67 // Callback for AudioOutput.CreateStream which contains information about
68 // the new created stream. Called on RenderThread. This function is going to
69 // notify the |audio_message_filter_| of the stream creation by calling
70 // StreamCreated. StreamCreated could only be ran on |io_task_runner_| and
71 // this is why CreateStreamOnIOThread is going to be used to do that.
72 void CreateStreamCallback(int stream_id,
73 media::mojom::AudioOutputStreamPtr stream,
74 mojo::ScopedSharedBufferHandle shared_buffer,
75 mojo::ScopedHandle socket_descriptor);
76
77 // Notifies the |audio_message_filter_| of the stream creation. Can only be
78 // called on |io_task_runner_|.
79 void CreateStreamOnIOThread(
80 AudioOutputClient::AudioOutputStreamPtrMap::iterator stream,
81 base::SharedMemoryHandle handle,
82 base::SyncSocket::TransitDescriptor socket_descriptor,
83 uint32_t length);
84
85 // Called when there is an error with AudioOutputStream Mojo interface in
86 // the renderer. This function is going to call ReportErrorOnIOThread in the
87 // RenderThread.
88 void OnStreamError(int stream_id);
89
90 // Notifies the |audio_message_filter_| of a stream error. Can only be called
91 // on |io_task_runner_|.
92 void ReportErrorOnIOThread(int stream_id);
93
94 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
95 media::mojom::AudioOutputPtr service_;
96 AudioOutputStreamPtrMap streams_;
97
98 DISALLOW_COPY_AND_ASSIGN(AudioOutputClient);
99 };
100
101 } // namespace content
102
103 #endif // CONTENT_RENDERER_MEDIA_AUDIO_OUTPUT_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698