Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / renderer_host / media / video_capture_host.h
blobeb845dc62c01c19e54df8931d9702a739e29381f
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) | with 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/browser/renderer_host/media/video_capture_controller_event_handler.h"
61 #include "content/common/content_export.h"
62 #include "content/public/browser/browser_message_filter.h"
63 #include "ipc/ipc_message.h"
65 namespace content {
66 class MediaStreamManager;
68 class CONTENT_EXPORT VideoCaptureHost
69 : public BrowserMessageFilter,
70 public VideoCaptureControllerEventHandler {
71 public:
72 explicit VideoCaptureHost(MediaStreamManager* media_stream_manager);
74 // BrowserMessageFilter implementation.
75 void OnChannelClosing() override;
76 void OnDestruct() const override;
77 bool OnMessageReceived(const IPC::Message& message) override;
79 // VideoCaptureControllerEventHandler implementation.
80 void OnError(VideoCaptureControllerID id) override;
81 void OnBufferCreated(VideoCaptureControllerID id,
82 base::SharedMemoryHandle handle,
83 int length,
84 int buffer_id) override;
85 void OnBufferDestroyed(VideoCaptureControllerID id,
86 int buffer_id) override;
87 void OnBufferReady(VideoCaptureControllerID id,
88 int buffer_id,
89 const gfx::Size& coded_size,
90 const gfx::Rect& visible_rect,
91 const base::TimeTicks& timestamp,
92 scoped_ptr<base::DictionaryValue> metadata) override;
93 void OnMailboxBufferReady(
94 VideoCaptureControllerID id,
95 int buffer_id,
96 const gpu::MailboxHolder& mailbox_holder,
97 const gfx::Size& packed_frame_size,
98 const base::TimeTicks& timestamp,
99 scoped_ptr<base::DictionaryValue> metadata) override;
100 void OnEnded(VideoCaptureControllerID id) override;
102 private:
103 friend class BrowserThread;
104 friend class base::DeleteHelper<VideoCaptureHost>;
105 friend class MockVideoCaptureHost;
106 friend class VideoCaptureHostTest;
108 void DoError(VideoCaptureControllerID id);
109 void DoEnded(VideoCaptureControllerID id);
111 ~VideoCaptureHost() override;
113 // IPC message: Start capture on the VideoCaptureDevice referenced by
114 // |device_id|. |session_id| is an id created by VideoCaptureMessageFilter
115 // to identify a session between a VideoCaptureMessageFilter and a
116 // VideoCaptureHost.
117 void OnStartCapture(int device_id,
118 media::VideoCaptureSessionId session_id,
119 const media::VideoCaptureParams& params);
120 void OnControllerAdded(
121 int device_id,
122 const base::WeakPtr<VideoCaptureController>& controller);
124 // IPC message: Stop capture on device referenced by |device_id|.
125 void OnStopCapture(int device_id);
127 // IPC message: Pause capture on device referenced by |device_id|.
128 void OnPauseCapture(int device_id);
130 void OnResumeCapture(int device_id,
131 media::VideoCaptureSessionId session_id,
132 const media::VideoCaptureParams& params);
134 // IPC message: Receive an empty buffer from renderer. Send it to device
135 // referenced by |device_id|.
136 void OnReceiveEmptyBuffer(int device_id, int buffer_id, uint32 sync_point);
138 // IPC message: Get supported formats referenced by |capture_session_id|.
139 // |device_id| is needed for message back-routing purposes.
140 void OnGetDeviceSupportedFormats(
141 int device_id,
142 media::VideoCaptureSessionId capture_session_id);
144 // IPC message: Get a device's currently in use format(s), referenced by
145 // |capture_session_id|. |device_id| is needed for message back-routing
146 // purposes.
147 void OnGetDeviceFormatsInUse(int device_id,
148 media::VideoCaptureSessionId capture_session_id);
150 // Deletes the controller and notifies the VideoCaptureManager. |on_error| is
151 // true if this is triggered by VideoCaptureControllerEventHandler::OnError.
152 void DeleteVideoCaptureController(VideoCaptureControllerID controller_id,
153 bool on_error);
155 MediaStreamManager* const media_stream_manager_;
157 typedef std::map<VideoCaptureControllerID,
158 base::WeakPtr<VideoCaptureController>> EntryMap;
160 // A map of VideoCaptureControllerID to the VideoCaptureController to which it
161 // is connected. An entry in this map holds a null controller while it is in
162 // the process of starting.
163 EntryMap entries_;
165 DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost);
168 } // namespace content
170 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_HOST_H_