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

Side by Side Diff: content/renderer/media/audio_message_filter.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: unique_ptr for Binding Created 4 years, 6 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
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/media/audio_message_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ 6 #define CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/id_map.h" 13 #include "base/id_map.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/shared_memory.h" 15 #include "base/memory/shared_memory.h"
16 #include "base/sync_socket.h" 16 #include "base/sync_socket.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/renderer/media/audio_output_client.h"
19 #include "ipc/message_filter.h" 20 #include "ipc/message_filter.h"
20 #include "media/audio/audio_output_ipc.h" 21 #include "media/audio/audio_output_ipc.h"
21 #include "media/base/audio_hardware_config.h" 22 #include "media/base/audio_hardware_config.h"
23 #include "media/mojo/interfaces/audio_output.mojom.h"
22 24
23 namespace base { 25 namespace base {
24 class SingleThreadTaskRunner; 26 class SingleThreadTaskRunner;
25 } 27 }
26 28
27 namespace content { 29 namespace content {
28 30
29 // MessageFilter that handles audio messages and delegates them to audio 31 // MessageFilter that handles audio messages and delegates them to audio
30 // renderers. Created on render thread, AudioMessageFilter is operated on 32 // renderers. Created on render thread, AudioMessageFilter is operated on
31 // IO thread (secondary thread of render process) it intercepts audio messages 33 // IO thread (secondary thread of render process) it intercepts audio messages
32 // and process them on IO thread since these messages are time critical. 34 // and process them on IO thread since these messages are time critical.
33 class CONTENT_EXPORT AudioMessageFilter : public IPC::MessageFilter { 35 class CONTENT_EXPORT AudioMessageFilter : public IPC::MessageFilter {
34 public: 36 public:
35 explicit AudioMessageFilter( 37 explicit AudioMessageFilter(
36 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); 38 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
37 39
38 // Getter for the one AudioMessageFilter object. 40 // Getter for the one AudioMessageFilter object.
39 static AudioMessageFilter* Get(); 41 static AudioMessageFilter* Get();
40 42
41 // Create an AudioOutputIPC to be owned by one delegate. |render_frame_id| is 43 // Create an AudioOutputIPC to be owned by one delegate. |render_frame_id| is
42 // the RenderFrame containing the entity producing the audio. 44 // the RenderFrame containing the entity producing the audio.
43 // 45 //
44 // The returned object is not thread-safe, and must be used on 46 // The returned object is not thread-safe, and must be used on
45 // |io_task_runner|. 47 // |io_task_runner|.
46 std::unique_ptr<media::AudioOutputIPC> CreateAudioOutputIPC( 48 std::unique_ptr<media::AudioOutputIPC> CreateAudioOutputIPC(
47 int render_frame_id); 49 int render_frame_id);
48 50
51 virtual void CloseStream(int stream_id);
52
49 // IO task runner associated with this message filter. 53 // IO task runner associated with this message filter.
50 base::SingleThreadTaskRunner* io_task_runner() const { 54 base::SingleThreadTaskRunner* io_task_runner() const {
51 return io_task_runner_.get(); 55 return io_task_runner_.get();
52 } 56 }
53 57
58 // Received when browser process has created an audio output stream.
59 virtual void StreamCreated(
60 int stream_id,
61 base::SharedMemoryHandle handle,
62 base::SyncSocket::TransitDescriptor socket_descriptor,
63 uint32_t length);
64
65 // Received when internal state of browser process' audio output device has
66 // changed.
67 virtual void OnStreamStateChanged(int stream_id,
68 media::AudioOutputIPCDelegateState state);
69
70 // Register |audio_output_client_| for a frame.
71 void RegisterAudioOutputClient(
72 int id,
73 scoped_refptr<content::AudioOutputClient> audio_output_client) {
74 audio_output_clients_.insert(std::make_pair(id, audio_output_client));
75 }
76
54 protected: 77 protected:
55 ~AudioMessageFilter() override; 78 ~AudioMessageFilter() override;
56 79
57 private: 80 private:
58 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Basic); 81 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Basic);
59 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Delegates); 82 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Delegates);
60 83
61 // Implementation of media::AudioOutputIPC which augments IPC calls with 84 // Implementation of media::AudioOutputIPC which augments IPC calls with
62 // stream_id and the source render_frame_id. 85 // stream_id and the source render_frame_id.
63 class AudioOutputIPCImpl; 86 class AudioOutputIPCImpl;
64 87
65 // Sends an IPC message using |sender_|. 88 // Sends an IPC message using |sender_|.
66 void Send(IPC::Message* message); 89 void Send(IPC::Message* message);
67 90
68 // IPC::MessageFilter override. Called on |io_task_runner_|. 91 // IPC::MessageFilter override. Called on |io_task_runner_|.
69 bool OnMessageReceived(const IPC::Message& message) override; 92 bool OnMessageReceived(const IPC::Message& message) override;
70 void OnFilterAdded(IPC::Sender* sender) override; 93 void OnFilterAdded(IPC::Sender* sender) override;
71 void OnFilterRemoved() override; 94 void OnFilterRemoved() override;
72 void OnChannelClosing() override; 95 void OnChannelClosing() override;
73 96
74 // Received when the browser process has checked authorization to use an 97 // Received when the browser process has checked authorization to use an
75 // audio output device. 98 // audio output device.
76 void OnDeviceAuthorized(int stream_id, 99 void OnDeviceAuthorized(int stream_id,
77 media::OutputDeviceStatus device_status, 100 media::OutputDeviceStatus device_status,
78 const media::AudioParameters& output_params, 101 const media::AudioParameters& output_params,
79 const std::string& matched_device_id); 102 const std::string& matched_device_id);
80 103
81 // Received when browser process has created an audio output stream.
82 void OnStreamCreated(int stream_id,
83 base::SharedMemoryHandle handle,
84 base::SyncSocket::TransitDescriptor socket_descriptor,
85 uint32_t length);
86
87 // Received when internal state of browser process' audio output device has
88 // changed.
89 void OnStreamStateChanged(int stream_id,
90 media::AudioOutputIPCDelegateState state);
91
92 // IPC sender for Send(); must only be accessed on |io_task_runner_|. 104 // IPC sender for Send(); must only be accessed on |io_task_runner_|.
93 IPC::Sender* sender_; 105 IPC::Sender* sender_;
94 106
95 // A map of stream ids to delegates; must only be accessed on 107 // A map of stream ids to delegates; must only be accessed on
96 // |io_task_runner_|. 108 // |io_task_runner_|.
97 IDMap<media::AudioOutputIPCDelegate> delegates_; 109 IDMap<media::AudioOutputIPCDelegate> delegates_;
110 std::map<int, scoped_refptr<content::AudioOutputClient>>
111 audio_output_clients_;
98 112
99 // Task runner on which IPC calls are executed. 113 // Task runner on which IPC calls are executed.
100 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 114 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
101 115
102 // The singleton instance for this filter. 116 // The singleton instance for this filter.
103 static AudioMessageFilter* g_filter; 117 static AudioMessageFilter* g_filter;
104 118
105 DISALLOW_COPY_AND_ASSIGN(AudioMessageFilter); 119 DISALLOW_COPY_AND_ASSIGN(AudioMessageFilter);
106 }; 120 };
107 121
108 } // namespace content 122 } // namespace content
109 123
110 #endif // CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ 124 #endif // CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/media/audio_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698