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 // MessageFilter that handles video capture messages and delegates them to
6 // video captures. VideoCaptureMessageFilter is operated on IO thread of
7 // render process. It intercepts video capture messages and process them on
8 // IO thread since these messages are time critical.
10 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_MESSAGE_FILTER_H_
11 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_MESSAGE_FILTER_H_
15 #include "base/memory/shared_memory.h"
16 #include "content/common/content_export.h"
17 #include "content/common/media/video_capture.h"
18 #include "ipc/ipc_channel_proxy.h"
19 #include "media/video/capture/video_capture.h"
23 class CONTENT_EXPORT VideoCaptureMessageFilter
24 : public IPC::ChannelProxy::MessageFilter {
26 class CONTENT_EXPORT Delegate {
28 // Called when a video frame buffer is created in the browser process.
29 virtual void OnBufferCreated(base::SharedMemoryHandle handle,
33 virtual void OnBufferDestroyed(int buffer_id) = 0;
35 // Called when a video frame buffer is received from the browser process.
36 virtual void OnBufferReceived(int buffer_id,
38 const media::VideoCaptureFormat& format) = 0;
40 // Called when state of a video capture device has changed in the browser
42 virtual void OnStateChanged(VideoCaptureState state) = 0;
44 // Called when the delegate has been added to filter's delegate list.
45 // |device_id| is the device id for the delegate.
46 virtual void OnDelegateAdded(int32 device_id) = 0;
49 virtual ~Delegate() {}
52 VideoCaptureMessageFilter();
54 // Add a delegate to the map.
55 void AddDelegate(Delegate* delegate);
57 // Remove a delegate from the map.
58 void RemoveDelegate(Delegate* delegate);
60 // Send a message asynchronously.
61 virtual bool Send(IPC::Message* message);
63 // IPC::ChannelProxy::MessageFilter override. Called on IO thread.
64 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
65 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE;
66 virtual void OnFilterRemoved() OVERRIDE;
67 virtual void OnChannelClosing() OVERRIDE;
70 virtual ~VideoCaptureMessageFilter();
73 typedef std::map<int32, Delegate*> Delegates;
75 // Receive a newly created buffer from browser process.
76 void OnBufferCreated(int device_id,
77 base::SharedMemoryHandle handle,
81 // Release a buffer received by OnBufferCreated.
82 void OnBufferDestroyed(int device_id,
85 // Receive a filled buffer from browser process.
86 void OnBufferReceived(int device_id,
89 const media::VideoCaptureFormat& format);
91 // State of browser process' video capture device has changed.
92 void OnDeviceStateChanged(int device_id, VideoCaptureState state);
94 // Finds the delegate associated with |device_id|, NULL if not found.
95 Delegate* find_delegate(int device_id) const;
97 // A map of device ids to delegates.
99 Delegates pending_delegates_;
100 int32 last_device_id_;
102 IPC::Channel* channel_;
104 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMessageFilter);
107 } // namespace content
109 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_MESSAGE_FILTER_H_