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 c6b7bf27cd5a4f8bfe7599368b14f54211c8952f..2871959b17f14aa0731962b0d02f0f10abbe6ca6 100644 |
--- a/content/renderer/media/video_capture_impl.cc |
+++ b/content/renderer/media/video_capture_impl.cc |
@@ -5,8 +5,10 @@ |
#include "content/renderer/media/video_capture_impl.h" |
#include "base/bind.h" |
+#include "base/callback_helpers.h" |
#include "base/stl_util.h" |
#include "content/child/child_process.h" |
+#include "content/common/media/encoded_video_capture_messages.h" |
#include "content/common/media/video_capture_messages.h" |
#include "media/base/limits.h" |
@@ -101,6 +103,83 @@ void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler) { |
base::Unretained(this), handler)); |
} |
+void VideoCaptureImpl::RequestCapabilities( |
+ const media::EncodedVideoSource::RequestCapabilitiesCallback& callback) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoRequestCapabilitiesOnCaptureThread, |
+ base::Unretained(this), callback)); |
Ami GONE FROM CHROMIUM
2013/06/13 22:56:58
Yowza. So, Unretained(this) is safe (even though
hshi1
2013/06/13 23:33:40
Ok so I assume there's no action item for me then.
Ami GONE FROM CHROMIUM
2013/06/18 20:56:27
If you felt like adding this comment to the class
hshi1
2013/06/18 23:01:19
I'd feel more comfortable if you add the appropria
|
+} |
+ |
+void VideoCaptureImpl::StartFetchCapabilities() { |
+ Send(new EncodedVideoCaptureHostMsg_GetCapabilities( |
+ device_id_, current_params_.session_id)); |
+} |
+ |
+void VideoCaptureImpl::OpenBitstream( |
+ media::EncodedVideoSource::Client* client, |
+ const media::VideoEncodingParameters& params) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoOpenBitstreamOnCaptureThread, |
+ base::Unretained(this), client, params)); |
+} |
+ |
+void VideoCaptureImpl::CloseBitstream() { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoCloseBitstreamOnCaptureThread, |
+ base::Unretained(this))); |
+} |
+ |
+void VideoCaptureImpl::ReturnBitstreamBuffer( |
+ scoped_refptr<const media::EncodedBitstreamBuffer> buffer) { |
+ Send(new EncodedVideoCaptureHostMsg_BitstreamBufferConsumed( |
+ device_id_, buffer->buffer_id())); |
+} |
+ |
+void VideoCaptureImpl::TrySetBitstreamConfig( |
+ const media::RuntimeVideoEncodingParameters& params) { |
+ Send(new EncodedVideoCaptureHostMsg_TryConfigureBitstream( |
+ device_id_, params)); |
+} |
+ |
+void VideoCaptureImpl::OnEncodingCapabilitiesAvailable( |
+ const media::VideoEncodingCapabilities& capabilities) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
+ &VideoCaptureImpl::DoNotifyCapabilitiesAvailableOnCaptureThread, |
+ base::Unretained(this), capabilities)); |
+} |
+ |
+void VideoCaptureImpl::OnEncodedBitstreamOpened( |
+ const media::VideoEncodingParameters& params, |
+ const std::vector<base::SharedMemoryHandle>& buffers, |
+ uint32 buffer_size) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoNotifyBitstreamOpenedOnCaptureThread, |
+ base::Unretained(this), params, buffers, buffer_size)); |
+} |
+ |
+void VideoCaptureImpl::OnEncodedBitstreamClosed() { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoNotifyBitstreamClosedOnCaptureThread, |
+ base::Unretained(this))); |
+} |
+ |
+void VideoCaptureImpl::OnEncodingConfigChanged( |
+ const media::RuntimeVideoEncodingParameters& params) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind( |
+ &VideoCaptureImpl::DoNotifyBitstreamConfigChangedOnCaptureThread, |
+ base::Unretained(this), params)); |
+} |
+ |
+void VideoCaptureImpl::OnEncodedBufferReady( |
+ int buffer_id, |
+ uint32 size, |
+ const media::BufferEncodingMetadata& metadata) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoNotifyBitstreamBufferReadyOnCaptureThread, |
+ base::Unretained(this), buffer_id, size, metadata)); |
+} |
+ |
void VideoCaptureImpl::FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) { |
capture_message_loop_proxy_->PostTask(FROM_HERE, |
base::Bind(&VideoCaptureImpl::DoFeedBufferOnCaptureThread, |
@@ -306,6 +385,7 @@ void VideoCaptureImpl::DoStateChangedOnCaptureThread(VideoCaptureState state) { |
switch (state) { |
case VIDEO_CAPTURE_STATE_STARTED: |
+ StartFetchCapabilities(); |
break; |
case VIDEO_CAPTURE_STATE_STOPPED: |
state_ = VIDEO_CAPTURE_STATE_STOPPED; |
@@ -380,6 +460,90 @@ void VideoCaptureImpl::DoSuspendCaptureOnCaptureThread(bool suspend) { |
suspended_ = suspend; |
} |
+void VideoCaptureImpl::DoRequestCapabilitiesOnCaptureThread( |
+ const RequestCapabilitiesCallback& callback) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ DCHECK(callback_.is_null()); |
+ callback_ = callback; |
+ |
+ // Invoke callback immediately if capabilities are already available. |
+ if (!capabilities_.empty()) |
+ base::ResetAndReturn(&callback_).Run(capabilities_); |
+} |
+ |
+void VideoCaptureImpl::DoOpenBitstreamOnCaptureThread( |
+ media::EncodedVideoSource::Client* client, |
+ const media::VideoEncodingParameters& params) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ DCHECK(!client_); |
+ client_ = client; |
+ Send(new EncodedVideoCaptureHostMsg_OpenBitstream( |
+ device_id_, current_params_.session_id, params)); |
+} |
+ |
+void VideoCaptureImpl::DoCloseBitstreamOnCaptureThread() { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ Send(new EncodedVideoCaptureHostMsg_CloseBitstream(device_id_)); |
+ client_ = NULL; |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamOpenedOnCaptureThread( |
+ const media::VideoEncodingParameters& params, |
+ const std::vector<base::SharedMemoryHandle>& buffers, |
+ uint32 buffer_size) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ DCHECK(bitstream_buffers_.empty()); |
+ for (size_t i = 0; i < buffers.size(); ++i) { |
+ base::SharedMemory* shm = new base::SharedMemory(buffers[i], true); |
+ bitstream_buffers_.push_back(shm); |
+ } |
+ client_->OnOpened(params); |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamClosedOnCaptureThread() { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ for (size_t i = 0; i < bitstream_buffers_.size(); ++i) { |
+ bitstream_buffers_[i]->Close(); |
+ delete bitstream_buffers_[i]; |
+ } |
+ bitstream_buffers_.clear(); |
+ if (client_) { |
+ client_->OnClosed(); |
+ client_ = NULL; |
+ } |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamConfigChangedOnCaptureThread( |
+ const media::RuntimeVideoEncodingParameters& params) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ client_->OnConfigChanged(params); |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamBufferReadyOnCaptureThread( |
+ int buffer_id, |
+ uint32 size, |
+ const media::BufferEncodingMetadata& metadata) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ if (buffer_id >= 0 && buffer_id < (int)bitstream_buffers_.size()) { |
Ami GONE FROM CHROMIUM
2013/06/13 22:56:58
s/(int)/static_cast<int>/ but that risks overflow;
hshi1
2013/06/13 23:33:40
Done.
|
+ base::SharedMemory* shm = bitstream_buffers_[buffer_id]; |
+ if (shm && shm->Map(size)) { |
Ami GONE FROM CHROMIUM
2013/06/13 22:56:58
shm can't be NULL here.
Ami GONE FROM CHROMIUM
2013/06/13 22:56:58
You test shm->Map() for failing but you don't do a
hshi1
2013/06/13 23:33:40
Done.
hshi1
2013/06/13 23:33:40
Done.
|
+ scoped_refptr<media::EncodedBitstreamBuffer> buffer = |
+ new media::EncodedBitstreamBuffer( |
+ buffer_id, (uint8*)shm->memory(), size, metadata); |
+ client_->OnBufferReady(buffer); |
+ shm->Unmap(); |
Ami GONE FROM CHROMIUM
2013/06/13 22:56:58
Is it clear why you want to Map & Unmap on every b
hshi1
2013/06/13 23:33:40
Done. (Notice: no need to Unmap on close - bitstre
|
+ } |
+ } |
+} |
+ |
+void VideoCaptureImpl::DoNotifyCapabilitiesAvailableOnCaptureThread( |
+ const media::VideoEncodingCapabilities& capabilities) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ capabilities_ = capabilities; |
+ if (!callback_.is_null()) |
+ base::ResetAndReturn(&callback_).Run(capabilities_); |
+} |
+ |
void VideoCaptureImpl::StopDevice() { |
DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |