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..07daf0c7a40b8046ea479323993524b74948deb7 100644 |
--- a/content/renderer/media/video_capture_impl.cc |
+++ b/content/renderer/media/video_capture_impl.cc |
@@ -7,6 +7,7 @@ |
#include "base/bind.h" |
#include "base/stl_util.h" |
#include "content/child/child_process.h" |
+#include "content/common/media/encoded_video_source_messages.h" |
#include "content/common/media/video_capture_messages.h" |
#include "media/base/limits.h" |
@@ -101,6 +102,91 @@ void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler) { |
base::Unretained(this), handler)); |
} |
+void VideoCaptureImpl::RequestCapabilities( |
+ const media::EncodedVideoSource::RequestCapabilitiesCallback& callback) { |
+ DCHECK(callback_.is_null()); |
+ callback_ = callback; |
+ |
+ // Invoke callback immediately if capabilities is already available. |
+ if (!capabilities_.empty()) |
+ callback_.Run(capabilities_); |
+} |
+ |
+void VideoCaptureImpl::StartFetchCapabilities() { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoStartFetchCapabilitiesOnCaptureThread, |
+ base::Unretained(this))); |
+} |
+ |
+void VideoCaptureImpl::OpenBitstream( |
+ media::EncodedVideoSource::Client* client, |
+ const media::VideoEncodingParameters& params) { |
+ DCHECK(!client_); |
+ client_ = client; |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoOpenBitstreamOnCaptureThread, |
+ base::Unretained(this), params)); |
+} |
+ |
+void VideoCaptureImpl::CloseBitstream() { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoCloseBitstreamOnCaptureThread, |
+ base::Unretained(this))); |
+ client_ = NULL; |
+} |
+ |
+void VideoCaptureImpl::ReturnBitstreamBuffer( |
+ scoped_refptr<const media::EncodedBitstreamBuffer> buffer) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoReturnBitstreamBufferOnCaptureThread, |
+ base::Unretained(this), buffer->buffer_id())); |
+} |
+ |
+void VideoCaptureImpl::TrySetBitstreamConfig( |
+ const media::RuntimeVideoEncodingParameters& params) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoTrySetBitstreamConfigOnCaptureThread, |
+ base::Unretained(this), params)); |
+} |
+ |
+void VideoCaptureImpl::OnCapabilitiesAvailable( |
+ const media::VideoEncodingCapabilities& capabilities) { |
+ capabilities_ = capabilities; |
+ if (!callback_.is_null()) |
+ callback_.Run(capabilities_); |
+} |
+ |
+void VideoCaptureImpl::OnBitstreamOpened( |
+ const media::VideoEncodingParameters& params, |
+ const std::map<int, base::SharedMemoryHandle>& buffers) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoNotifyBitstreamOpenedOnCaptureThread, |
+ base::Unretained(this), params, buffers)); |
+} |
+ |
+void VideoCaptureImpl::OnBitstreamClosed() { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind(&VideoCaptureImpl::DoNotifyBitstreamClosedOnCaptureThread, |
+ base::Unretained(this))); |
+} |
+ |
+void VideoCaptureImpl::OnBitstreamConfigChanged( |
+ const media::RuntimeVideoEncodingParameters& params) { |
+ capture_message_loop_proxy_->PostTask(FROM_HERE, |
+ base::Bind( |
+ &VideoCaptureImpl::DoNotifyBitstreamConfigChangedOnCaptureThread, |
+ base::Unretained(this), params)); |
+} |
+ |
+void VideoCaptureImpl::OnBitstreamReady( |
+ 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 +392,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 +467,78 @@ void VideoCaptureImpl::DoSuspendCaptureOnCaptureThread(bool suspend) { |
suspended_ = suspend; |
} |
+void VideoCaptureImpl::DoStartFetchCapabilitiesOnCaptureThread() { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ Send(new EncodedVideoSourceHostMsg_GetCapabilities(device_id_)); |
+} |
+ |
+void VideoCaptureImpl::DoOpenBitstreamOnCaptureThread( |
+ const media::VideoEncodingParameters& params) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ Send(new EncodedVideoSourceHostMsg_OpenBitstream(device_id_, params)); |
+} |
+ |
+void VideoCaptureImpl::DoCloseBitstreamOnCaptureThread() { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ Send(new EncodedVideoSourceHostMsg_CloseBitstream(device_id_)); |
+} |
+ |
+void VideoCaptureImpl::DoReturnBitstreamBufferOnCaptureThread(int buffer_id) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ Send(new EncodedVideoSourceHostMsg_BitstreamBufferConsumed(device_id_, |
+ buffer_id)); |
+} |
+ |
+void VideoCaptureImpl::DoTrySetBitstreamConfigOnCaptureThread( |
+ const media::RuntimeVideoEncodingParameters& params) { |
+ DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
+ Send(new EncodedVideoSourceHostMsg_TryConfigureBitstream(device_id_, params)); |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamOpenedOnCaptureThread( |
+ const media::VideoEncodingParameters& params, |
+ const std::map<int, base::SharedMemoryHandle>& buffers) { |
+ std::map<int, base::SharedMemoryHandle>::const_iterator it; |
+ for (it = buffers.begin(); it != buffers.end(); ++it) { |
+ int buffer_id = it->first; |
+ buffers_[buffer_id] = new base::SharedMemory(it->second, true); |
+ } |
+ client_->OnStreaming(params); |
+} |
+ |
+void VideoCaptureImpl::DoNotifyBitstreamClosedOnCaptureThread() { |
+ std::map<int, base::SharedMemory*>::iterator it; |
+ for (it = buffers_.begin(); it != buffers_.end(); ++it) { |
+ if (it->second) { |
+ it->second->Close(); |
+ delete it->second; |
+ } |
+ } |
+ 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 (buffers_.find(buffer_id) != buffers_.end()) { |
+ base::SharedMemory* shm = buffers_[buffer_id]; |
+ if (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::StopDevice() { |
DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |