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

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

Issue 2384843002: VideoCapture: migrate VideoCapture renderer-->host messages to mojo, part 1 (Closed)
Patch Set: Created 4 years, 3 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 1b2757f0bdc651a7133590459af1ac643e97af4e..c3046b4077b438be7cef388686cce34743b5d994 100644
--- a/content/browser/renderer_host/media/video_capture_host.cc
+++ b/content/browser/renderer_host/media/video_capture_host.cc
@@ -17,6 +17,7 @@ namespace content {
VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager)
: BrowserMessageFilter(VideoCaptureMsgStart),
+ BrowserAssociatedInterface(this, this),
media_stream_manager_(media_stream_manager) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
@@ -25,7 +26,7 @@ VideoCaptureHost::~VideoCaptureHost() {}
void VideoCaptureHost::OnChannelClosing() {
// Since the IPC sender is gone, close all requested VideoCaptureDevices.
- for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) {
+ for (auto it = controllers_.begin(); it != controllers_.end(); ) {
const base::WeakPtr<VideoCaptureController>& controller = it->second;
if (controller) {
const VideoCaptureControllerID controller_id(it->first);
@@ -36,7 +37,7 @@ void VideoCaptureHost::OnChannelClosing() {
// 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.
- entries_.erase(it++);
+ controllers_.erase(it++);
}
}
}
@@ -45,9 +46,6 @@ void VideoCaptureHost::OnDestruct() const {
BrowserThread::DeleteOnIOThread::Destruct(this);
}
-///////////////////////////////////////////////////////////////////////////////
-
-// Implements VideoCaptureControllerEventHandler.
void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) {
DVLOG(1) << "VideoCaptureHost::OnError";
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -61,7 +59,7 @@ void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id,
int length,
int buffer_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (entries_.find(controller_id) == entries_.end())
+ if (controllers_.find(controller_id) == controllers_.end())
return;
Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id));
@@ -73,7 +71,7 @@ void VideoCaptureHost::OnBufferCreated2(
const gfx::Size& size,
int buffer_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (entries_.find(controller_id) == entries_.end())
+ if (controllers_.find(controller_id) == controllers_.end())
return;
Send(new VideoCaptureMsg_NewBuffer2(controller_id, handles, size, buffer_id));
@@ -82,7 +80,7 @@ void VideoCaptureHost::OnBufferCreated2(
void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id,
int buffer_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (entries_.find(controller_id) == entries_.end())
+ if (controllers_.find(controller_id) == controllers_.end())
return;
Send(new VideoCaptureMsg_FreeBuffer(controller_id, buffer_id));
@@ -93,7 +91,7 @@ void VideoCaptureHost::OnBufferReady(
int buffer_id,
const scoped_refptr<media::VideoFrame>& video_frame) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (entries_.find(controller_id) == entries_.end())
+ if (controllers_.find(controller_id) == controllers_.end())
return;
VideoCaptureMsg_BufferReady_Params params;
@@ -120,7 +118,7 @@ void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) {
void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) {
DVLOG(1) << "VideoCaptureHost::DoError";
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (entries_.find(controller_id) == entries_.end())
+ if (controllers_.find(controller_id) == controllers_.end())
return;
Send(new VideoCaptureMsg_StateChanged(controller_id,
@@ -131,7 +129,7 @@ void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) {
void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) {
DVLOG(1) << "VideoCaptureHost::DoEnded";
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (entries_.find(controller_id) == entries_.end())
+ if (controllers_.find(controller_id) == controllers_.end())
return;
Send(new VideoCaptureMsg_StateChanged(controller_id,
@@ -145,11 +143,7 @@ bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message) {
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,
@@ -179,13 +173,13 @@ void VideoCaptureHost::OnStartCapture(int device_id,
? "fixed aspect ratio"
: "variable resolution")) << ")";
VideoCaptureControllerID controller_id(device_id);
- if (entries_.find(controller_id) != entries_.end()) {
+ if (controllers_.find(controller_id) != controllers_.end()) {
Send(new VideoCaptureMsg_StateChanged(device_id,
VIDEO_CAPTURE_STATE_ERROR));
return;
}
- entries_[controller_id] = base::WeakPtr<VideoCaptureController>();
+ controllers_[controller_id] = base::WeakPtr<VideoCaptureController>();
media_stream_manager_->video_capture_manager()->StartCaptureForClient(
session_id,
params,
@@ -195,66 +189,16 @@ void VideoCaptureHost::OnStartCapture(int device_id,
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);
- 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)
+ auto it = controllers_.find(controller_id);
+ if (it == controllers_.end() || !it->second)
return;
media_stream_manager_->video_capture_manager()->ResumeCaptureForClient(
@@ -263,22 +207,6 @@ void VideoCaptureHost::OnResumeCapture(
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,
@@ -287,8 +215,8 @@ void VideoCaptureHost::OnRendererFinishedWithBuffer(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
VideoCaptureControllerID controller_id(device_id);
- EntryMap::iterator it = entries_.find(controller_id);
- if (it != entries_.end()) {
+ auto it = controllers_.find(controller_id);
+ if (it != controllers_.end()) {
const base::WeakPtr<VideoCaptureController>& controller = it->second;
if (controller) {
controller->ReturnBuffer(controller_id, this, buffer_id, sync_token,
@@ -299,17 +227,16 @@ void VideoCaptureHost::OnRendererFinishedWithBuffer(
void VideoCaptureHost::OnGetDeviceSupportedFormats(
int device_id,
- media::VideoCaptureSessionId capture_session_id) {
+ media::VideoCaptureSessionId session_id) {
+ DVLOG(1) << __func__ << " " << device_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(capture_session_id,
+ ->GetDeviceSupportedFormats(session_id,
&device_supported_formats)) {
DLOG(WARNING)
<< "Could not retrieve device supported formats for device_id="
- << device_id << " capture_session_id=" << capture_session_id;
+ << device_id << " session_id=" << session_id;
}
Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated(
device_id, device_supported_formats));
@@ -317,33 +244,97 @@ void VideoCaptureHost::OnGetDeviceSupportedFormats(
void VideoCaptureHost::OnGetDeviceFormatsInUse(
int device_id,
- media::VideoCaptureSessionId capture_session_id) {
+ media::VideoCaptureSessionId session_id) {
+ DVLOG(1) << __func__ << " " << device_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(
- capture_session_id, &formats_in_use)) {
+ session_id, &formats_in_use)) {
DVLOG(1) << "Could not retrieve device format(s) in use for device_id="
- << device_id << " capture_session_id=" << capture_session_id;
+ << device_id << " session_id=" << 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);
- EntryMap::iterator it = entries_.find(controller_id);
- if (it == entries_.end())
+ auto it = controllers_.find(controller_id);
+ if (it == controllers_.end())
return;
if (it->second) {
media_stream_manager_->video_capture_manager()->StopCaptureForClient(
it->second.get(), controller_id, this, on_error);
}
- entries_.erase(it);
+ controllers_.erase(it);
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698