Chromium Code Reviews| 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 1382c8fe169b188b707d156009172e05981e0a29..404638e2c980b2ccbc6908e388448d50cc9d2202 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/common/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. |
|
Ami GONE FROM CHROMIUM
2013/06/12 01:44:06
s/is/are/
hshi1
2013/06/12 17:52:39
Done.
|
| + if (!capabilities_.empty()) |
| + callback_.Run(capabilities_); |
|
Ami GONE FROM CHROMIUM
2013/06/12 01:44:06
Don't you want to clear the callback once it's run
hshi1
2013/06/12 17:52:39
Done. Thanks for the suggestion!
|
| +} |
| + |
| +void VideoCaptureImpl::StartFetchCapabilities() { |
| + capture_message_loop_proxy_->PostTask(FROM_HERE, |
| + base::Bind(&VideoCaptureImpl::DoStartFetchCapabilitiesOnCaptureThread, |
| + base::Unretained(this))); |
|
Ami GONE FROM CHROMIUM
2013/06/12 01:44:06
Is it obvious why Unretained is safe here and belo
hshi1
2013/06/12 17:52:39
No it is not obvious. I'm using Unretained only be
|
| +} |
| + |
| +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, |
| + size_t 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_)); |
|
Ami GONE FROM CHROMIUM
2013/06/12 01:44:06
Why proxy through this thread just to jump to the
hshi1
2013/06/12 17:52:39
I am puzzled as well but all the existing function
|
| +} |
| + |
| +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, |
| + size_t size, |
| + const media::BufferEncodingMetadata& metadata) { |
| + if (buffers_.find(buffer_id) != buffers_.end()) { |
| + base::SharedMemory* shm = buffers_[buffer_id]; |
| + if (shm->Map(size)) { |
|
Ami GONE FROM CHROMIUM
2013/06/12 01:44:06
what if this fails?
better yet, why not map all SH
hshi1
2013/06/12 17:52:39
This wasn't possible with the IPC messages I defin
|
| + 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()); |