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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_INPUT_MESSAGE_FILTER_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_INPUT_MESSAGE_FILTER_H_
8 #include "base/id_map.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/sync_socket.h"
12 #include "content/common/content_export.h"
13 #include "ipc/message_filter.h"
14 #include "media/audio/audio_input_ipc.h"
17 class MessageLoopProxy
;
22 // MessageFilter that handles audio input messages and delegates them to
23 // audio capturers. Created on render thread, AudioMessageFilter is operated on
24 // IO thread (secondary thread of render process), it intercepts audio messages
25 // and process them on IO thread since these messages are time critical.
26 class CONTENT_EXPORT AudioInputMessageFilter
: public IPC::MessageFilter
{
28 explicit AudioInputMessageFilter(
29 const scoped_refptr
<base::MessageLoopProxy
>& io_message_loop
);
31 // Getter for the one AudioInputMessageFilter object.
32 static AudioInputMessageFilter
* Get();
34 // Create an AudioInputIPC to be owned by one delegate. |render_view_id| is
35 // the render view containing the entity consuming the audio.
37 // The returned object is not thread-safe, and must be used on
39 scoped_ptr
<media::AudioInputIPC
> CreateAudioInputIPC(int render_view_id
);
41 scoped_refptr
<base::MessageLoopProxy
> io_message_loop() const {
42 return io_message_loop_
;
46 // Implementation of media::AudioInputIPC which augments IPC calls with
47 // stream_id and the destination render_view_id.
48 class AudioInputIPCImpl
;
50 virtual ~AudioInputMessageFilter();
52 // Sends an IPC message using |channel_|.
53 void Send(IPC::Message
* message
);
55 // IPC::MessageFilter override. Called on |io_message_loop_|.
56 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
57 virtual void OnFilterAdded(IPC::Channel
* channel
) OVERRIDE
;
58 virtual void OnFilterRemoved() OVERRIDE
;
59 virtual void OnChannelClosing() OVERRIDE
;
61 // Received when browser process has created an audio input stream.
62 void OnStreamCreated(int stream_id
,
63 base::SharedMemoryHandle handle
,
65 base::SyncSocket::Handle socket_handle
,
67 base::FileDescriptor socket_descriptor
,
70 uint32 total_segments
);
72 // Notification of volume property of an audio input stream.
73 void OnStreamVolume(int stream_id
, double volume
);
75 // Received when internal state of browser process' audio input stream has
77 void OnStreamStateChanged(int stream_id
,
78 media::AudioInputIPCDelegate::State state
);
80 // A map of stream ids to delegates.
81 IDMap
<media::AudioInputIPCDelegate
> delegates_
;
83 // IPC channel for Send(), must only be accesed on |io_message_loop_|.
84 IPC::Channel
* channel_
;
86 // Message loop on which IPC calls are driven.
87 const scoped_refptr
<base::MessageLoopProxy
> io_message_loop_
;
89 // The singleton instance for this filter.
90 static AudioInputMessageFilter
* g_filter
;
92 DISALLOW_COPY_AND_ASSIGN(AudioInputMessageFilter
);
95 } // namespace content
97 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_MESSAGE_FILTER_H_