Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / media / video_capture_host.h
blob095d3c91f2724aa14a244ebc41b7c6b4fde038d2
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.
4 //
5 // VideoCaptureHost serves video capture related messages from
6 // VideoCaptureMessageFilter which lives inside the render process.
7 //
8 // This class is owned by RenderProcessHostImpl, and instantiated on UI
9 // thread, but all other operations and method calls happen on IO thread.
11 // Here's an example of a typical IPC dialog for video capture:
13 // Renderer VideoCaptureHost
14 // | |
15 // | VideoCaptureHostMsg_Start > |
16 // | < VideoCaptureMsg_StateChanged |
17 // | (VIDEO_CAPTURE_STATE_STARTED) |
18 // | < VideoCaptureMsg_NewBuffer(1) |
19 // | < VideoCaptureMsg_NewBuffer(2) |
20 // | < VideoCaptureMsg_NewBuffer(3) |
21 // | |
22 // | < VideoCaptureMsg_BufferReady(1) |
23 // | < VideoCaptureMsg_BufferReady(2) |
24 // | VideoCaptureHostMsg_BufferReady(1) > |
25 // | < VideoCaptureMsg_BufferReady(3) |
26 // | VideoCaptureHostMsg_BufferReady(2) > |
27 // | < VideoCaptureMsg_BufferReady(1) |
28 // | VideoCaptureHostMsg_BufferReady(3) > |
29 // | < VideoCaptureMsg_BufferReady(2) |
30 // | VideoCaptureHostMsg_BufferReady(1) > |
31 // | ... |
32 // | < VideoCaptureMsg_BufferReady(3) |
33 // | |
34 // | ... (resolution change) |
35 // | < VideoCaptureMsg_FreeBuffer(1) | Buffers are re-allocated
36 // | < VideoCaptureMsg_NewBuffer(4) | at a larger size, as
37 // | < VideoCaptureMsg_BufferReady(4) | needed.
38 // | VideoCaptureHostMsg_BufferReady(2) > |
39 // | < VideoCaptureMsg_FreeBuffer(2) |
40 // | < VideoCaptureMsg_NewBuffer(5) |
41 // | < VideoCaptureMsg_BufferReady(5) |
42 // | ... |
43 // | |
44 // | < VideoCaptureMsg_BufferReady |
45 // | VideoCaptureHostMsg_Stop > |
46 // | VideoCaptureHostMsg_BufferReady > |
47 // | < VideoCaptureMsg_StateChanged |
48 // | (VIDEO_CAPTURE_STATE_STOPPED) |
49 // v v
51 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_
52 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_
54 #include <map>
56 #include "base/memory/ref_counted.h"
57 #include "base/memory/weak_ptr.h"
58 #include "base/sequenced_task_runner_helpers.h"
59 #include "content/browser/renderer_host/media/video_capture_controller.h"
60 #include "content/common/content_export.h"
61 #include "content/public/browser/browser_message_filter.h"
62 #include "ipc/ipc_message.h"
64 namespace content {
65 class MediaStreamManager;
67 class CONTENT_EXPORT VideoCaptureHost
68 : public BrowserMessageFilter,
69 public VideoCaptureControllerEventHandler {
70 public:
71 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager);
73 // BrowserMessageFilter implementation.
74 virtual void OnChannelClosing() OVERRIDE;
75 virtual void OnDestruct() const OVERRIDE;
76 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
78 // VideoCaptureControllerEventHandler implementation.
79 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE;
80 virtual void OnBufferCreated(const VideoCaptureControllerID& id,
81 base::SharedMemoryHandle handle,
82 int length,
83 int buffer_id) OVERRIDE;
84 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id,
85 int buffer_id) OVERRIDE;
86 virtual void OnBufferReady(const VideoCaptureControllerID& id,
87 int buffer_id,
88 const media::VideoCaptureFormat& format,
89 base::TimeTicks timestamp) OVERRIDE;
90 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id,
91 int buffer_id,
92 const gpu::MailboxHolder& mailbox_holder,
93 const media::VideoCaptureFormat& format,
94 base::TimeTicks timestamp) OVERRIDE;
95 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE;
97 private:
98 friend class BrowserThread;
99 friend class base::DeleteHelper<VideoCaptureHost>;
100 friend class MockVideoCaptureHost;
101 friend class VideoCaptureHostTest;
103 virtual ~VideoCaptureHost();
105 // IPC message: Start capture on the VideoCaptureDevice referenced by
106 // |session_id|. |device_id| is an id created by VideoCaptureMessageFilter
107 // to identify a session between a VideoCaptureMessageFilter and a
108 // VideoCaptureHost.
109 void OnStartCapture(int device_id,
110 media::VideoCaptureSessionId session_id,
111 const media::VideoCaptureParams& params);
112 void OnControllerAdded(
113 int device_id,
114 const base::WeakPtr<VideoCaptureController>& controller);
115 void DoControllerAddedOnIOThread(
116 int device_id,
117 const base::WeakPtr<VideoCaptureController>& controller);
119 // IPC message: Stop capture on device referenced by |device_id|.
120 void OnStopCapture(int device_id);
122 // IPC message: Pause capture on device referenced by |device_id|.
123 void OnPauseCapture(int device_id);
125 // IPC message: Receive an empty buffer from renderer. Send it to device
126 // referenced by |device_id|.
127 void OnReceiveEmptyBuffer(int device_id, int buffer_id, uint32 sync_point);
129 // IPC message: Get supported formats referenced by |capture_session_id|.
130 // |device_id| is needed for message back-routing purposes.
131 void OnGetDeviceSupportedFormats(
132 int device_id,
133 media::VideoCaptureSessionId capture_session_id);
135 // IPC message: Get a device's currently in use format(s), referenced by
136 // |capture_session_id|. |device_id| is needed for message back-routing
137 // purposes.
138 void OnGetDeviceFormatsInUse(
139 int device_id,
140 media::VideoCaptureSessionId capture_session_id);
142 // Sends a newly created buffer to the VideoCaptureMessageFilter.
143 void DoSendNewBufferOnIOThread(
144 const VideoCaptureControllerID& controller_id,
145 base::SharedMemoryHandle handle,
146 int length,
147 int buffer_id);
149 void DoSendFreeBufferOnIOThread(
150 const VideoCaptureControllerID& controller_id,
151 int buffer_id);
153 // Sends a filled buffer to the VideoCaptureMessageFilter.
154 void DoSendFilledBufferOnIOThread(
155 const VideoCaptureControllerID& controller_id,
156 int buffer_id,
157 const media::VideoCaptureFormat& format,
158 base::TimeTicks timestamp);
160 // Sends a filled texture mailbox buffer to the VideoCaptureMessageFilter.
161 void DoSendFilledMailboxBufferOnIOThread(
162 const VideoCaptureControllerID& controller_id,
163 int buffer_id,
164 const gpu::MailboxHolder& mailbox_holder,
165 const media::VideoCaptureFormat& format,
166 base::TimeTicks timestamp);
168 // Handles error coming from VideoCaptureDevice.
169 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id);
171 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id);
173 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is
174 // true if this is triggered by VideoCaptureControllerEventHandler::OnError.
175 void DeleteVideoCaptureControllerOnIOThread(
176 const VideoCaptureControllerID& controller_id, bool on_error);
178 MediaStreamManager* media_stream_manager_;
180 typedef std::map<VideoCaptureControllerID,
181 base::WeakPtr<VideoCaptureController> > EntryMap;
183 // A map of VideoCaptureControllerID to the VideoCaptureController to which it
184 // is connected. An entry in this map holds a null controller while it is in
185 // the process of starting.
186 EntryMap entries_;
188 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost);
191 } // namespace content
193 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_