Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1576)

Unified Diff: content/browser/renderer_host/media/video_capture_host.cc

Issue 2393483002: Revert of VideoCapture: migrate VideoCapture renderer-->host messages to mojo, part 1 (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/video_capture_host.cc
diff --git a/content/browser/renderer_host/media/video_capture_host.cc b/content/browser/renderer_host/media/video_capture_host.cc
index c3046b4077b438be7cef388686cce34743b5d994..1b2757f0bdc651a7133590459af1ac643e97af4e 100644
--- a/content/browser/renderer_host/media/video_capture_host.cc
+++ b/content/browser/renderer_host/media/video_capture_host.cc
@@ -17,7 +17,6 @@
VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager)
: BrowserMessageFilter(VideoCaptureMsgStart),
- BrowserAssociatedInterface(this, this),
media_stream_manager_(media_stream_manager) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
@@ -26,7 +25,7 @@
void VideoCaptureHost::OnChannelClosing() {
// Since the IPC sender is gone, close all requested VideoCaptureDevices.
- for (auto it = controllers_.begin(); it != controllers_.end(); ) {
+ for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) {
const base::WeakPtr<VideoCaptureController>& controller = it->second;
if (controller) {
const VideoCaptureControllerID controller_id(it->first);
@@ -37,7 +36,7 @@
// Remove the entry for this controller_id so that when the controller
// is added, the controller will be notified to stop for this client
// in DoControllerAdded.
- controllers_.erase(it++);
+ entries_.erase(it++);
}
}
}
@@ -46,6 +45,9 @@
BrowserThread::DeleteOnIOThread::Destruct(this);
}
+///////////////////////////////////////////////////////////////////////////////
+
+// Implements VideoCaptureControllerEventHandler.
void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) {
DVLOG(1) << "VideoCaptureHost::OnError";
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -59,7 +61,7 @@
int length,
int buffer_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (controllers_.find(controller_id) == controllers_.end())
+ if (entries_.find(controller_id) == entries_.end())
return;
Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id));
@@ -71,7 +73,7 @@
const gfx::Size& size,
int buffer_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (controllers_.find(controller_id) == controllers_.end())
+ if (entries_.find(controller_id) == entries_.end())
return;
Send(new VideoCaptureMsg_NewBuffer2(controller_id, handles, size, buffer_id));
@@ -80,7 +82,7 @@
void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id,
int buffer_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (controllers_.find(controller_id) == controllers_.end())
+ if (entries_.find(controller_id) == entries_.end())
return;
Send(new VideoCaptureMsg_FreeBuffer(controller_id, buffer_id));
@@ -91,7 +93,7 @@
int buffer_id,
const scoped_refptr<media::VideoFrame>& video_frame) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (controllers_.find(controller_id) == controllers_.end())
+ if (entries_.find(controller_id) == entries_.end())
return;
VideoCaptureMsg_BufferReady_Params params;
@@ -118,7 +120,7 @@
void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) {
DVLOG(1) << "VideoCaptureHost::DoError";
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (controllers_.find(controller_id) == controllers_.end())
+ if (entries_.find(controller_id) == entries_.end())
return;
Send(new VideoCaptureMsg_StateChanged(controller_id,
@@ -129,7 +131,7 @@
void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) {
DVLOG(1) << "VideoCaptureHost::DoEnded";
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (controllers_.find(controller_id) == controllers_.end())
+ if (entries_.find(controller_id) == entries_.end())
return;
Send(new VideoCaptureMsg_StateChanged(controller_id,
@@ -143,7 +145,11 @@
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(VideoCaptureHost, message)
IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture)
+ IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture)
IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Resume, OnResumeCapture)
+ IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_RequestRefreshFrame,
+ OnRequestRefreshFrame)
+ IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture)
IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady,
OnRendererFinishedWithBuffer)
IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats,
@@ -173,13 +179,13 @@
? "fixed aspect ratio"
: "variable resolution")) << ")";
VideoCaptureControllerID controller_id(device_id);
- if (controllers_.find(controller_id) != controllers_.end()) {
+ if (entries_.find(controller_id) != entries_.end()) {
Send(new VideoCaptureMsg_StateChanged(device_id,
VIDEO_CAPTURE_STATE_ERROR));
return;
}
- controllers_[controller_id] = base::WeakPtr<VideoCaptureController>();
+ entries_[controller_id] = base::WeakPtr<VideoCaptureController>();
media_stream_manager_->video_capture_manager()->StartCaptureForClient(
session_id,
params,
@@ -189,16 +195,66 @@
base::Bind(&VideoCaptureHost::OnControllerAdded, this, device_id));
}
+void VideoCaptureHost::OnControllerAdded(
+ int device_id,
+ const base::WeakPtr<VideoCaptureController>& controller) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ VideoCaptureControllerID controller_id(device_id);
+ EntryMap::iterator it = entries_.find(controller_id);
+ if (it == entries_.end()) {
+ if (controller) {
+ media_stream_manager_->video_capture_manager()->StopCaptureForClient(
+ controller.get(), controller_id, this, false);
+ }
+ return;
+ }
+
+ if (!controller) {
+ Send(new VideoCaptureMsg_StateChanged(device_id,
+ VIDEO_CAPTURE_STATE_ERROR));
+ entries_.erase(controller_id);
+ return;
+ }
+
+ DCHECK(!it->second);
+ it->second = controller;
+}
+
+void VideoCaptureHost::OnStopCapture(int device_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id;
+
+ VideoCaptureControllerID controller_id(device_id);
+
+ Send(new VideoCaptureMsg_StateChanged(device_id,
+ VIDEO_CAPTURE_STATE_STOPPED));
+ DeleteVideoCaptureController(controller_id, false);
+}
+
+void VideoCaptureHost::OnPauseCapture(int device_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id;
+
+ VideoCaptureControllerID controller_id(device_id);
+ EntryMap::iterator it = entries_.find(controller_id);
+ if (it == entries_.end() || !it->second)
+ return;
+
+ media_stream_manager_->video_capture_manager()->PauseCaptureForClient(
+ it->second.get(), controller_id, this);
+ Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED));
+}
+
void VideoCaptureHost::OnResumeCapture(
int device_id,
media::VideoCaptureSessionId session_id,
const media::VideoCaptureParams& params) {
- DVLOG(1) << __func__ << " " << device_id;
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- VideoCaptureControllerID controller_id(device_id);
- auto it = controllers_.find(controller_id);
- if (it == controllers_.end() || !it->second)
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DVLOG(1) << "VideoCaptureHost::OnResumeCapture, device_id " << device_id;
+
+ VideoCaptureControllerID controller_id(device_id);
+ EntryMap::iterator it = entries_.find(controller_id);
+ if (it == entries_.end() || !it->second)
return;
media_stream_manager_->video_capture_manager()->ResumeCaptureForClient(
@@ -207,6 +263,22 @@
VIDEO_CAPTURE_STATE_RESUMED));
}
+void VideoCaptureHost::OnRequestRefreshFrame(int device_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DVLOG(1) << "VideoCaptureHost::OnRequestRefreshFrame, device_id "
+ << device_id;
+
+ VideoCaptureControllerID controller_id(device_id);
+ EntryMap::iterator it = entries_.find(controller_id);
+ if (it == entries_.end())
+ return;
+
+ if (VideoCaptureController* controller = it->second.get()) {
+ media_stream_manager_->video_capture_manager()
+ ->RequestRefreshFrameForClient(controller);
+ }
+}
+
void VideoCaptureHost::OnRendererFinishedWithBuffer(
int device_id,
int buffer_id,
@@ -215,8 +287,8 @@
DCHECK_CURRENTLY_ON(BrowserThread::IO);
VideoCaptureControllerID controller_id(device_id);
- auto it = controllers_.find(controller_id);
- if (it != controllers_.end()) {
+ EntryMap::iterator it = entries_.find(controller_id);
+ if (it != entries_.end()) {
const base::WeakPtr<VideoCaptureController>& controller = it->second;
if (controller) {
controller->ReturnBuffer(controller_id, this, buffer_id, sync_token,
@@ -227,16 +299,17 @@
void VideoCaptureHost::OnGetDeviceSupportedFormats(
int device_id,
- media::VideoCaptureSessionId session_id) {
- DVLOG(1) << __func__ << " " << device_id;
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ media::VideoCaptureSessionId capture_session_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormats, capture_session_id "
+ << capture_session_id;
media::VideoCaptureFormats device_supported_formats;
if (!media_stream_manager_->video_capture_manager()
- ->GetDeviceSupportedFormats(session_id,
+ ->GetDeviceSupportedFormats(capture_session_id,
&device_supported_formats)) {
DLOG(WARNING)
<< "Could not retrieve device supported formats for device_id="
- << device_id << " session_id=" << session_id;
+ << device_id << " capture_session_id=" << capture_session_id;
}
Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated(
device_id, device_supported_formats));
@@ -244,97 +317,33 @@
void VideoCaptureHost::OnGetDeviceFormatsInUse(
int device_id,
- media::VideoCaptureSessionId session_id) {
- DVLOG(1) << __func__ << " " << device_id;
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ media::VideoCaptureSessionId capture_session_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormatsInUse, capture_session_id "
+ << capture_session_id;
media::VideoCaptureFormats formats_in_use;
if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse(
- session_id, &formats_in_use)) {
+ capture_session_id, &formats_in_use)) {
DVLOG(1) << "Could not retrieve device format(s) in use for device_id="
- << device_id << " session_id=" << session_id;
+ << device_id << " capture_session_id=" << capture_session_id;
}
Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id,
formats_in_use));
}
-void VideoCaptureHost::StopCapture(int32_t device_id) {
- DVLOG(1) << __func__ << " " << device_id;
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- VideoCaptureControllerID controller_id(device_id);
-
- Send(new VideoCaptureMsg_StateChanged(device_id,
- VIDEO_CAPTURE_STATE_STOPPED));
- DeleteVideoCaptureController(controller_id, false);
-}
-
-void VideoCaptureHost::PauseCapture(int32_t device_id) {
- DVLOG(1) << __func__ << " " << device_id;
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- VideoCaptureControllerID controller_id(device_id);
- auto it = controllers_.find(controller_id);
- if (it == controllers_.end() || !it->second)
- return;
-
- media_stream_manager_->video_capture_manager()->PauseCaptureForClient(
- it->second.get(), controller_id, this);
- Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED));
-}
-
-void VideoCaptureHost::RequestRefreshFrame(int32_t device_id) {
- DVLOG(1) << __func__ << " " << device_id;
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- VideoCaptureControllerID controller_id(device_id);
- auto it = controllers_.find(controller_id);
- if (it == controllers_.end())
- return;
-
- if (VideoCaptureController* controller = it->second.get()) {
- media_stream_manager_->video_capture_manager()
- ->RequestRefreshFrameForClient(controller);
- }
-}
-
-void VideoCaptureHost::OnControllerAdded(
- int device_id,
- const base::WeakPtr<VideoCaptureController>& controller) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- VideoCaptureControllerID controller_id(device_id);
- auto it = controllers_.find(controller_id);
- if (it == controllers_.end()) {
- if (controller) {
- media_stream_manager_->video_capture_manager()->StopCaptureForClient(
- controller.get(), controller_id, this, false);
- }
- return;
- }
-
- if (!controller) {
- Send(new VideoCaptureMsg_StateChanged(device_id,
- VIDEO_CAPTURE_STATE_ERROR));
- controllers_.erase(controller_id);
- return;
- }
-
- DCHECK(!it->second);
- it->second = controller;
-}
-
void VideoCaptureHost::DeleteVideoCaptureController(
VideoCaptureControllerID controller_id, bool on_error) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- auto it = controllers_.find(controller_id);
- if (it == controllers_.end())
+ EntryMap::iterator it = entries_.find(controller_id);
+ if (it == entries_.end())
return;
if (it->second) {
media_stream_manager_->video_capture_manager()->StopCaptureForClient(
it->second.get(), controller_id, this, on_error);
}
- controllers_.erase(it);
+ entries_.erase(it);
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698