1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// VideoCaptureHost serves video capture related messages from
// VideCaptureMessageFilter which lives inside the render process.
//
// This class is owned by BrowserRenderProcessHost, and instantiated on UI
// thread, but all other operations and method calls happen on IO thread.
//
// Here's an example of a typical IPC dialog for video capture:
//
// Renderer VideoCaptureHost
// | |
// | VideoCaptureHostMsg_Start > |
// | < VideoCaptureMsg_DeviceInfo |
// | |
// | < VideoCaptureMsg_StateChanged |
// | (kStarted) |
// | < VideoCaptureMsg_BufferReady |
// | ... |
// | < VideoCaptureMsg_BufferReady |
// | ... |
// | VideoCaptureHostMsg_BufferReady > |
// | VideoCaptureHostMsg_BufferReady > |
// | |
// | ... |
// | |
// | < VideoCaptureMsg_BufferReady |
// | VideoCaptureHostMsg_Stop > |
// | VideoCaptureHostMsg_BufferReady > |
// | < VideoCaptureMsg_StateChanged |
// | (kStopped) |
// v v
#ifndef CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_HOST_H_
#define CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_HOST_H_
#include <map>
#include "base/memory/ref_counted.h"
#include "content/browser/browser_message_filter.h"
#include "content/browser/renderer_host/video_capture_controller.h"
#include "ipc/ipc_message.h"
class VideoCaptureHost : public BrowserMessageFilter,
public VideoCaptureControllerEventHandler {
public:
VideoCaptureHost();
// BrowserMessageFilter implementation.
virtual void OnChannelClosing();
virtual void OnDestruct() const;
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok);
// VideoCaptureControllerEventHandler implementation.
virtual void OnError(const VideoCaptureControllerID& id);
virtual void OnBufferCreated(const VideoCaptureControllerID& id,
base::SharedMemoryHandle handle,
int length, int buffer_id);
virtual void OnBufferReady(const VideoCaptureControllerID& id,
int buffer_id,
base::Time timestamp);
virtual void OnFrameInfo(const VideoCaptureControllerID& id,
int width,
int height,
int frame_per_second);
virtual void OnReadyToDelete(const VideoCaptureControllerID& id);
private:
friend class BrowserThread;
friend class DeleteTask<VideoCaptureHost>;
friend class MockVideoCaptureHost;
friend class VideoCaptureHostTest;
virtual ~VideoCaptureHost();
// IPC message: Start capture on the VideoCaptureDevice referenced by
// VideoCaptureParams::session_id. device_id is an id created by
// VideCaptureMessageFilter to identify a session
// between a VideCaptureMessageFilter and a VideoCaptureHost.
void OnStartCapture(const IPC::Message& msg, int device_id,
const media::VideoCaptureParams& params);
// IPC message: Stop capture on device referenced by device_id.
void OnStopCapture(const IPC::Message& msg, int device_id);
// IPC message: Pause capture on device referenced by device_id.
void OnPauseCapture(const IPC::Message& msg, int device_id);
// IPC message: Receive an empty buffer from renderer. Send it to device
// referenced by |device_id|.
void OnReceiveEmptyBuffer(const IPC::Message& msg,
int device_id,
int buffer_id);
// Called on the IO thread when VideoCaptureController have
// reported that all DIBs have been returned.
void DoDeleteVideoCaptureController(const VideoCaptureControllerID& id);
// Send a newly created buffer to the VideoCaptureMessageFilter.
void DoSendNewBuffer(int32 routing_id,
int device_id,
base::SharedMemoryHandle handle,
int length,
int buffer_id);
// Send a filled buffer to the VideoCaptureMessageFilter.
void DoSendFilledBuffer(int32 routing_id,
int device_id,
int buffer_id,
base::Time timestamp);
// Send a information about frame resolution and frame rate
// to the VideoCaptureMessageFilter.
void DoSendFrameInfo(int32 routing_id,
int device_id,
int width,
int height,
int frame_per_second);
// Handle error coming from VideoCaptureDevice.
void DoHandleError(int32 routing_id, int device_id);
typedef std::map<VideoCaptureControllerID,
scoped_refptr<VideoCaptureController> >EntryMap;
// A map of VideoCaptureControllerID to VideoCaptureController
// objects that is currently active.
EntryMap entries_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureHost);
};
#endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_HOST_H_
|