Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / content / browser / renderer_host / media / video_capture_host.h
blobc1f8e3c9e0b35016cbecf9839ee3c42e64c95c26
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 media {
65 class VideoCaptureCapability;
68 namespace content {
69 class MediaStreamManager;
71 class CONTENT_EXPORT VideoCaptureHost
72 : public BrowserMessageFilter,
73 public VideoCaptureControllerEventHandler {
74 public:
75 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager);
77 // BrowserMessageFilter implementation.
78 virtual void OnChannelClosing() OVERRIDE;
79 virtual void OnDestruct() const OVERRIDE;
80 virtual bool OnMessageReceived(const IPC::Message& message,
81 bool* message_was_ok) OVERRIDE;
83 // VideoCaptureControllerEventHandler implementation.
84 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE;
85 virtual void OnBufferCreated(const VideoCaptureControllerID& id,
86 base::SharedMemoryHandle handle,
87 int length,
88 int buffer_id) OVERRIDE;
89 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id,
90 int buffer_id) OVERRIDE;
91 virtual void OnBufferReady(
92 const VideoCaptureControllerID& id,
93 int buffer_id,
94 base::Time timestamp,
95 const media::VideoCaptureFormat& format) OVERRIDE;
96 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE;
98 private:
99 friend class BrowserThread;
100 friend class base::DeleteHelper<VideoCaptureHost>;
101 friend class MockVideoCaptureHost;
102 friend class VideoCaptureHostTest;
104 virtual ~VideoCaptureHost();
106 // IPC message: Start capture on the VideoCaptureDevice referenced by
107 // |session_id|. |device_id| is an id created by VideoCaptureMessageFilter
108 // to identify a session between a VideoCaptureMessageFilter and a
109 // VideoCaptureHost.
110 void OnStartCapture(int device_id,
111 media::VideoCaptureSessionId session_id,
112 const media::VideoCaptureParams& params);
113 void OnControllerAdded(
114 int device_id,
115 const base::WeakPtr<VideoCaptureController>& controller);
116 void DoControllerAddedOnIOThread(
117 int device_id,
118 const base::WeakPtr<VideoCaptureController>& controller);
120 // IPC message: Stop capture on device referenced by |device_id|.
121 void OnStopCapture(int device_id);
123 // IPC message: Pause capture on device referenced by |device_id|.
124 void OnPauseCapture(int device_id);
126 // IPC message: Receive an empty buffer from renderer. Send it to device
127 // referenced by |device_id|.
128 void OnReceiveEmptyBuffer(int device_id, int buffer_id);
130 // Send a newly created buffer to the VideoCaptureMessageFilter.
131 void DoSendNewBufferOnIOThread(
132 const VideoCaptureControllerID& controller_id,
133 base::SharedMemoryHandle handle,
134 int length,
135 int buffer_id);
137 void DoSendFreeBufferOnIOThread(
138 const VideoCaptureControllerID& controller_id,
139 int buffer_id);
141 // Send a filled buffer to the VideoCaptureMessageFilter.
142 void DoSendFilledBufferOnIOThread(
143 const VideoCaptureControllerID& controller_id,
144 int buffer_id,
145 base::Time timestamp,
146 const media::VideoCaptureFormat& format);
148 // Handle error coming from VideoCaptureDevice.
149 void DoHandleErrorOnIOThread(const VideoCaptureControllerID& controller_id);
151 void DoEndedOnIOThread(const VideoCaptureControllerID& controller_id);
153 void DeleteVideoCaptureControllerOnIOThread(
154 const VideoCaptureControllerID& controller_id);
156 MediaStreamManager* media_stream_manager_;
158 typedef std::map<VideoCaptureControllerID,
159 base::WeakPtr<VideoCaptureController> > EntryMap;
161 // A map of VideoCaptureControllerID to the VideoCaptureController to which it
162 // is connected. An entry in this map holds a null controller while it is in
163 // the process of starting.
164 EntryMap entries_;
166 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost);
169 } // namespace content
171 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_