OLD | NEW |
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 // MessageFilter that handles audio messages and delegates them to audio | 5 // MessageFilter that handles audio messages and delegates them to audio |
6 // renderers. Created on render thread, AudioMessageFilter is operated on | 6 // renderers. Created on render thread, AudioMessageFilter is operated on |
7 // IO thread (secondary thread of render process) it intercepts audio messages | 7 // IO thread (secondary thread of render process) it intercepts audio messages |
8 // and process them on IO thread since these messages are time critical. | 8 // and process them on IO thread since these messages are time critical. |
9 | 9 |
10 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ | 10 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ |
11 #define CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ | 11 #define CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/id_map.h" | 14 #include "base/id_map.h" |
15 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
16 #include "base/sync_socket.h" | 16 #include "base/sync_socket.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "ipc/ipc_channel_proxy.h" | 18 #include "ipc/ipc_channel_proxy.h" |
19 #include "media/audio/audio_buffers_state.h" | 19 #include "media/audio/audio_buffers_state.h" |
20 #include "media/audio/audio_output_ipc.h" | 20 #include "media/audio/audio_output_ipc.h" |
21 | 21 |
22 class CONTENT_EXPORT AudioMessageFilter | 22 class CONTENT_EXPORT AudioMessageFilter |
23 : public IPC::ChannelProxy::MessageFilter, | 23 : public IPC::ChannelProxy::MessageFilter { |
24 public NON_EXPORTED_BASE(media::AudioOutputIPC) { | |
25 public: | 24 public: |
26 AudioMessageFilter(); | 25 AudioMessageFilter(); |
27 | 26 |
28 // Getter for the one AudioMessageFilter object. | 27 // Getter for the one AudioMessageFilter object. |
29 static AudioMessageFilter* Get(); | 28 static AudioMessageFilter* Get(); |
30 | 29 |
31 // media::AudioOutputIPCDelegate implementation. | |
32 virtual int AddDelegate(media::AudioOutputIPCDelegate* delegate) OVERRIDE; | |
33 virtual void RemoveDelegate(int id) OVERRIDE; | |
34 virtual void CreateStream(int stream_id, | |
35 const media::AudioParameters& params) OVERRIDE; | |
36 virtual void PlayStream(int stream_id) OVERRIDE; | |
37 virtual void PauseStream(int stream_id) OVERRIDE; | |
38 virtual void FlushStream(int stream_id) OVERRIDE; | |
39 virtual void CloseStream(int stream_id) OVERRIDE; | |
40 virtual void SetVolume(int stream_id, double volume) OVERRIDE; | |
41 | |
42 // IPC::ChannelProxy::MessageFilter override. Called on IO thread. | 30 // IPC::ChannelProxy::MessageFilter override. Called on IO thread. |
43 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 31 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
44 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; | 32 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; |
45 virtual void OnFilterRemoved() OVERRIDE; | 33 virtual void OnFilterRemoved() OVERRIDE; |
46 virtual void OnChannelClosing() OVERRIDE; | 34 virtual void OnChannelClosing() OVERRIDE; |
47 | 35 |
| 36 // Sends an IPC message using |channel_|. |
| 37 bool Send(IPC::Message* message); |
| 38 |
| 39 int AddDelegate(media::AudioOutputIPCDelegate* delegate); |
| 40 void RemoveDelegate(int id); |
| 41 |
48 protected: | 42 protected: |
49 virtual ~AudioMessageFilter(); | 43 virtual ~AudioMessageFilter(); |
50 | 44 |
51 private: | 45 private: |
52 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Basic); | 46 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Basic); |
53 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Delegates); | 47 FRIEND_TEST_ALL_PREFIXES(AudioMessageFilterTest, Delegates); |
54 | 48 |
55 // Sends an IPC message using |channel_|. | |
56 bool Send(IPC::Message* message); | |
57 | |
58 // Received when browser process has created an audio output stream. | 49 // Received when browser process has created an audio output stream. |
59 void OnStreamCreated(int stream_id, base::SharedMemoryHandle handle, | 50 void OnStreamCreated(int stream_id, base::SharedMemoryHandle handle, |
60 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
61 base::SyncSocket::Handle socket_handle, | 52 base::SyncSocket::Handle socket_handle, |
62 #else | 53 #else |
63 base::FileDescriptor socket_descriptor, | 54 base::FileDescriptor socket_descriptor, |
64 #endif | 55 #endif |
65 uint32 length); | 56 uint32 length); |
66 | 57 |
67 // Received when internal state of browser process' audio output device has | 58 // Received when internal state of browser process' audio output device has |
68 // changed. | 59 // changed. |
69 void OnStreamStateChanged(int stream_id, | 60 void OnStreamStateChanged(int stream_id, |
70 media::AudioOutputIPCDelegate::State state); | 61 media::AudioOutputIPCDelegate::State state); |
71 | 62 |
72 // The singleton instance for this filter. | 63 // The singleton instance for this filter. |
73 static AudioMessageFilter* filter_; | 64 static AudioMessageFilter* filter_; |
74 | 65 |
75 // A map of stream ids to delegates. | 66 // A map of stream ids to delegates. |
76 IDMap<media::AudioOutputIPCDelegate> delegates_; | 67 IDMap<media::AudioOutputIPCDelegate> delegates_; |
77 | 68 |
78 IPC::Channel* channel_; | 69 IPC::Channel* channel_; |
79 | 70 |
80 DISALLOW_COPY_AND_ASSIGN(AudioMessageFilter); | 71 DISALLOW_COPY_AND_ASSIGN(AudioMessageFilter); |
81 }; | 72 }; |
82 | 73 |
83 #endif // CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ | 74 #endif // CONTENT_RENDERER_MEDIA_AUDIO_MESSAGE_FILTER_H_ |
OLD | NEW |