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..3495d603bc8b7cee06fe7d80e3e0d0e76bf48ba7 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,86 @@ void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler) { |
base::Unretained(this), handler)); |
} |
+void VideoCaptureImpl::RequestCapabilities( |
+ const media::EncodedVideoSource::RequestCapabilitiesCallback& callback) { |
sheu
2013/06/13 05:36:51
We're assuming that this is called always on captu
hshi1
2013/06/13 19:18:46
I'm afraid that the DCHECK failed. During my testi
|
+ DCHECK(callback_.is_null()); |
+ callback_ = callback; |
+ |
+ // Invoke callback immediately if capabilities are already available. |
+ if (!capabilities_.empty()) |
+ base::ResetAndReturn(&callback_).Run(capabilities_); |
+} |
+ |
+void VideoCaptureImpl::StartFetchCapabilities() { |
+ Send(new EncodedVideoCaptureHostMsg_GetCapabilities( |
+ device_id_, current_params_.session_id)); |
+} |
+ |
+void VideoCaptureImpl::OpenBitstream( |
sheu
2013/06/13 05:36:51
We're assuming that this is called always on captu
hshi1
2013/06/13 19:18:46
I'm afraid that the DCHECK failed. I see this call
|
+ media::EncodedVideoSource::Client* client, |
+ const media::VideoEncodingParameters& params) { |
+ DCHECK(!client_); |
+ client_ = client; |
+ Send(new EncodedVideoCaptureHostMsg_OpenBitstream( |
+ device_id_, current_params_.session_id, params)); |
+} |
+ |
+void VideoCaptureImpl::CloseBitstream() { |
sheu
2013/06/13 05:36:51
This and other entry points that don't require tra
hshi1
2013/06/13 19:18:46
I'm posting this to capture thread as well, becaus
|
+ Send(new EncodedVideoCaptureHostMsg_CloseBitstream(device_id_)); |
+ client_ = NULL; |
+} |
+ |
+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, |
+ int 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, |
+ int 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 +388,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 +463,55 @@ void VideoCaptureImpl::DoSuspendCaptureOnCaptureThread(bool suspend) { |
suspended_ = suspend; |
} |
+void VideoCaptureImpl::DoNotifyBitstreamOpenedOnCaptureThread( |
+ const media::VideoEncodingParameters& params, |
+ const std::vector<base::SharedMemoryHandle>& buffers, |
+ int buffer_size) { |
+ 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() { |
+ for (size_t i = 0; i < bitstream_buffers_.size(); ++i) { |
+ bitstream_buffers_[i]->Close(); |
+ delete bitstream_buffers_[i]; |
+ } |
+ bitstream_buffers_.clear(); |
+ client_->OnClosed(); |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamConfigChangedOnCaptureThread( |
+ const media::RuntimeVideoEncodingParameters& params) { |
+ client_->OnConfigChanged(params); |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamBufferReadyOnCaptureThread( |
+ int buffer_id, |
+ int size, |
+ const media::BufferEncodingMetadata& metadata) { |
+ if (buffer_id >= 0 && buffer_id < (int)bitstream_buffers_.size()) { |
+ base::SharedMemory* shm = bitstream_buffers_[buffer_id]; |
+ if (shm && shm->Map(size)) { |
+ scoped_refptr<media::EncodedBitstreamBuffer> buffer = |
+ new media::EncodedBitstreamBuffer( |
+ buffer_id, (uint8*)shm->memory(), size, metadata); |
+ client_->OnBufferReady(buffer); |
+ shm->Unmap(); |
+ } |
+ } |
+} |
+ |
+void VideoCaptureImpl::DoNotifyCapabilitiesAvailableOnCaptureThread( |
+ const media::VideoEncodingCapabilities& capabilities) { |
+ capabilities_ = capabilities; |
+ if (!callback_.is_null()) |
+ base::ResetAndReturn(&callback_).Run(capabilities_); |
+} |
+ |
void VideoCaptureImpl::StopDevice() { |
DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |