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

Unified Diff: content/renderer/media/video_capture_impl.cc

Issue 2409893003: VideoCapture: more migration IPC-->mojo, part 5 (Closed)
Patch Set: rebase content/common/BUILD.gn 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
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/video_capture_impl.cc
diff --git a/content/renderer/media/video_capture_impl.cc b/content/renderer/media/video_capture_impl.cc
index e7fd2b98f2ad596db86c55493adb4de9955c396d..48dab4cbb1d143564c71fad9b4030cc36a1d968a 100644
--- a/content/renderer/media/video_capture_impl.cc
+++ b/content/renderer/media/video_capture_impl.cc
@@ -201,32 +201,72 @@ void VideoCaptureImpl::OnBufferCreated(base::SharedMemoryHandle handle,
DCHECK(inserted);
}
-void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) {
+void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) {
+ DVLOG(1) << __func__ << " " << device_id;
DCHECK(io_task_runner_->BelongsToCurrentThread());
- const auto& cb_iter = client_buffers_.find(buffer_id);
- if (cb_iter != client_buffers_.end()) {
- DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef())
- << "Instructed to delete buffer we are still using.";
- client_buffers_.erase(cb_iter);
+ device_id_ = device_id;
+ ClientInfoMap::iterator it = clients_pending_on_filter_.begin();
+ while (it != clients_pending_on_filter_.end()) {
+ const int client_id = it->first;
+ const ClientInfo client_info = it->second;
+ clients_pending_on_filter_.erase(it++);
+ StartCapture(client_id, client_info.params, client_info.state_update_cb,
+ client_info.deliver_frame_cb);
}
}
-void VideoCaptureImpl::OnBufferReceived(
- int buffer_id,
- base::TimeDelta timestamp,
- const base::DictionaryValue& metadata,
- media::VideoPixelFormat pixel_format,
- media::VideoFrame::StorageType storage_type,
- const gfx::Size& coded_size,
- const gfx::Rect& visible_rect) {
+void VideoCaptureImpl::OnStateChanged(mojom::VideoCaptureState state) {
+ DVLOG(1) << __func__ << " state: " << state;
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
+
+ switch (state) {
+ case mojom::VideoCaptureState::STARTED:
+ // Capture has started in the browser process. Since we have already
+ // told all clients that we have started there's nothing to do.
+ break;
+ case mojom::VideoCaptureState::STOPPED:
+ state_ = VIDEO_CAPTURE_STATE_STOPPED;
+ client_buffers_.clear();
+ weak_factory_.InvalidateWeakPtrs();
+ if (!clients_.empty() || !clients_pending_on_restart_.empty())
+ RestartCapture();
+ break;
+ case mojom::VideoCaptureState::PAUSED:
+ for (const auto& client : clients_)
+ client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_PAUSED);
+ break;
+ case mojom::VideoCaptureState::RESUMED:
+ for (const auto& client : clients_)
+ client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_RESUMED);
+ break;
+ case mojom::VideoCaptureState::FAILED:
+ for (const auto& client : clients_)
+ client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR);
+ clients_.clear();
+ state_ = VIDEO_CAPTURE_STATE_ERROR;
+ break;
+ case mojom::VideoCaptureState::ENDED:
+ // We'll only notify the client that the stream has stopped.
+ for (const auto& client : clients_)
+ client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
+ clients_.clear();
+ state_ = VIDEO_CAPTURE_STATE_ENDED;
+ break;
+ }
+}
+
+void VideoCaptureImpl::OnBufferReady(int32_t buffer_id,
+ mojom::VideoFrameInfoPtr info) {
+ DVLOG(1) << __func__ << " buffer_id: " << buffer_id;
+
DCHECK(io_task_runner_->BelongsToCurrentThread());
- DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format);
- DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, storage_type);
+ DCHECK_EQ(media::mojom::VideoFormat::I420, info->pixel_format);
+ DCHECK_EQ(media::PIXEL_STORAGE_CPU, info->storage_type);
if (state_ != VIDEO_CAPTURE_STATE_STARTED ||
- pixel_format != media::PIXEL_FORMAT_I420 ||
- storage_type != media::VideoFrame::STORAGE_SHMEM) {
+ info->pixel_format != media::mojom::VideoFormat::I420 ||
+ info->storage_type != media::PIXEL_STORAGE_CPU) {
GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id,
gpu::SyncToken(), -1.0);
return;
@@ -234,7 +274,7 @@ void VideoCaptureImpl::OnBufferReceived(
base::TimeTicks reference_time;
media::VideoFrameMetadata frame_metadata;
- frame_metadata.MergeInternalValuesFrom(metadata);
+ frame_metadata.MergeInternalValuesFrom(info->metadata);
const bool success = frame_metadata.GetTimeTicks(
media::VideoFrameMetadata::REFERENCE_TIME, &reference_time);
DCHECK(success);
@@ -246,8 +286,8 @@ void VideoCaptureImpl::OnBufferReceived(
// estimate. e.g. ThreadSafeCaptureOracle::DidCaptureFrame().
// TODO(miu): Fix upstream capturers to always set timestamp and reference
// time. See http://crbug/618407/ for tracking.
- if (timestamp.is_zero())
- timestamp = reference_time - first_frame_ref_time_;
+ if (info->timestamp.is_zero())
+ info->timestamp = reference_time - first_frame_ref_time_;
// TODO(qiangchen): Change the metric name to "reference_time" and
// "timestamp", so that we have consistent naming everywhere.
@@ -255,18 +295,18 @@ void VideoCaptureImpl::OnBufferReceived(
TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived",
TRACE_EVENT_SCOPE_THREAD, "timestamp",
(reference_time - base::TimeTicks()).InMicroseconds(),
- "time_delta", timestamp.InMicroseconds());
+ "time_delta", info->timestamp.InMicroseconds());
const auto& iter = client_buffers_.find(buffer_id);
DCHECK(iter != client_buffers_.end());
const scoped_refptr<ClientBuffer> buffer = iter->second;
scoped_refptr<media::VideoFrame> frame =
media::VideoFrame::WrapExternalSharedMemory(
- pixel_format, coded_size, visible_rect,
- gfx::Size(visible_rect.width(), visible_rect.height()),
+ static_cast<media::VideoPixelFormat>(info->pixel_format),
+ info->coded_size, info->visible_rect, info->visible_rect.size(),
reinterpret_cast<uint8_t*>(buffer->buffer()->memory()),
buffer->buffer_size(), buffer->buffer()->handle(),
- 0 /* shared_memory_offset */, timestamp);
+ 0 /* shared_memory_offset */, info->timestamp);
if (!frame) {
GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id,
gpu::SyncToken(), -1.0);
@@ -281,7 +321,7 @@ void VideoCaptureImpl::OnBufferReceived(
base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(),
base::Passed(&release_sync_token), buffer_finished_callback));
- frame->metadata()->MergeInternalValuesFrom(metadata);
+ frame->metadata()->MergeInternalValuesFrom(info->metadata);
// TODO(qiangchen): Dive into the full code path to let frame metadata hold
// reference time rather than using an extra parameter.
@@ -289,58 +329,14 @@ void VideoCaptureImpl::OnBufferReceived(
client.second.deliver_frame_cb.Run(frame, reference_time);
}
-void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) {
- DVLOG(1) << __func__ << " " << device_id;
- DCHECK(io_task_runner_->BelongsToCurrentThread());
-
- device_id_ = device_id;
- ClientInfoMap::iterator it = clients_pending_on_filter_.begin();
- while (it != clients_pending_on_filter_.end()) {
- const int client_id = it->first;
- const ClientInfo client_info = it->second;
- clients_pending_on_filter_.erase(it++);
- StartCapture(client_id, client_info.params, client_info.state_update_cb,
- client_info.deliver_frame_cb);
- }
-}
-
-void VideoCaptureImpl::OnStateChanged(mojom::VideoCaptureState state) {
- DVLOG(1) << __func__ << " state: " << state;
+void VideoCaptureImpl::OnBufferDestroyed(int32_t buffer_id) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
- switch (state) {
- case mojom::VideoCaptureState::STARTED:
- // Capture has started in the browser process. Since we have already
- // told all clients that we have started there's nothing to do.
- break;
- case mojom::VideoCaptureState::STOPPED:
- state_ = VIDEO_CAPTURE_STATE_STOPPED;
- client_buffers_.clear();
- weak_factory_.InvalidateWeakPtrs();
- if (!clients_.empty() || !clients_pending_on_restart_.empty())
- RestartCapture();
- break;
- case mojom::VideoCaptureState::PAUSED:
- for (const auto& client : clients_)
- client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_PAUSED);
- break;
- case mojom::VideoCaptureState::RESUMED:
- for (const auto& client : clients_)
- client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_RESUMED);
- break;
- case mojom::VideoCaptureState::FAILED:
- for (const auto& client : clients_)
- client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR);
- clients_.clear();
- state_ = VIDEO_CAPTURE_STATE_ERROR;
- break;
- case mojom::VideoCaptureState::ENDED:
- // We'll only notify the client that the stream has stopped.
- for (const auto& client : clients_)
- client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
- clients_.clear();
- state_ = VIDEO_CAPTURE_STATE_ENDED;
- break;
+ const auto& cb_iter = client_buffers_.find(buffer_id);
+ if (cb_iter != client_buffers_.end()) {
+ DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef())
+ << "Instructed to delete buffer we are still using.";
+ client_buffers_.erase(cb_iter);
}
}
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698