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/message_filter.h"
19 #include "media/video/capture/video_capture_types.h"
27 class CONTENT_EXPORT VideoCaptureMessageFilter : public IPC::MessageFilter {
29 class CONTENT_EXPORT Delegate {
31 // Called when a video frame buffer is created in the browser process.
32 virtual void OnBufferCreated(base::SharedMemoryHandle handle,
36 virtual void OnBufferDestroyed(int buffer_id) = 0;
38 // Called when a video frame buffer is received from the browser process.
39 virtual void OnBufferReceived(int buffer_id,
40 const media::VideoCaptureFormat& format,
41 const gfx::Rect& visible_rect,
42 base::TimeTicks timestamp) = 0;
44 // Called when a video mailbox buffer is received from the browser process.
45 virtual void OnMailboxBufferReceived(
47 const gpu::MailboxHolder& mailbox_holder,
48 const media::VideoCaptureFormat& format,
49 base::TimeTicks timestamp) = 0;
51 // Called when state of a video capture device has changed in the browser
53 virtual void OnStateChanged(VideoCaptureState state) = 0;
55 // Called upon reception of device's supported formats back from browser.
56 virtual void OnDeviceSupportedFormatsEnumerated(
57 const media::VideoCaptureFormats& supported_formats) = 0;
59 // Called upon reception of format(s) in use by a device back from browser.
60 virtual void OnDeviceFormatsInUseReceived(
61 const media::VideoCaptureFormats& formats_in_use) = 0;
63 // Called when the delegate has been added to filter's delegate list.
64 // |device_id| is the device id for the delegate.
65 virtual void OnDelegateAdded(int32 device_id) = 0;
68 virtual ~Delegate() {}
71 VideoCaptureMessageFilter();
73 // Add a delegate to the map.
74 void AddDelegate(Delegate* delegate);
76 // Remove a delegate from the map.
77 void RemoveDelegate(Delegate* delegate);
79 // Send a message asynchronously.
80 virtual bool Send(IPC::Message* message);
82 // IPC::MessageFilter override. Called on IO thread.
83 bool OnMessageReceived(const IPC::Message& message) override;
84 void OnFilterAdded(IPC::Sender* sender) override;
85 void OnFilterRemoved() override;
86 void OnChannelClosing() override;
89 ~VideoCaptureMessageFilter() override;
92 typedef std::map<int32, Delegate*> Delegates;
94 // Receive a newly created buffer from browser process.
95 void OnBufferCreated(int device_id,
96 base::SharedMemoryHandle handle,
100 // Release a buffer received by OnBufferCreated.
101 void OnBufferDestroyed(int device_id,
104 // Receive a filled buffer from browser process.
105 void OnBufferReceived(int device_id,
107 const media::VideoCaptureFormat& format,
108 const gfx::Rect& visible_rect,
109 base::TimeTicks timestamp);
111 // Receive a filled texture mailbox buffer from browser process.
112 void OnMailboxBufferReceived(int device_id,
114 const gpu::MailboxHolder& mailbox_holder,
115 const media::VideoCaptureFormat& format,
116 base::TimeTicks timestamp);
118 // State of browser process' video capture device has changed.
119 void OnDeviceStateChanged(int device_id, VideoCaptureState state);
121 // Receive a device's supported formats back from browser process.
122 void OnDeviceSupportedFormatsEnumerated(
124 const media::VideoCaptureFormats& supported_formats);
126 // Receive the formats in-use by a device back from browser process.
127 void OnDeviceFormatsInUseReceived(
129 const media::VideoCaptureFormats& formats_in_use);
131 // Finds the delegate associated with |device_id|, NULL if not found.
132 Delegate* find_delegate(int device_id) const;
134 // A map of device ids to delegates.
135 Delegates delegates_;
136 Delegates pending_delegates_;
137 int32 last_device_id_;
139 IPC::Sender* sender_;
141 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMessageFilter);
144 } // namespace content
146 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_MESSAGE_FILTER_H_