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

Unified Diff: content/browser/renderer_host/media/video_capture_device_client.cc

Issue 2308533003: Break tight coupling of VideoCaptureDeviceClient to renderer_host (Closed)
Patch Set: mcasas' comments Created 4 years, 3 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
Index: content/browser/renderer_host/media/video_capture_device_client.cc
diff --git a/content/browser/renderer_host/media/video_capture_device_client.cc b/content/browser/renderer_host/media/video_capture_device_client.cc
index cd39c5fa750dc48da1fc151b6c00d2f4b628e120..bd99194d8adb7be1ce7f843c085e6a4d2ee6a75f 100644
--- a/content/browser/renderer_host/media/video_capture_device_client.cc
+++ b/content/browser/renderer_host/media/video_capture_device_client.cc
@@ -17,7 +17,6 @@
#include "content/browser/renderer_host/media/video_capture_buffer_pool.h"
#include "content/browser/renderer_host/media/video_capture_controller.h"
#include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h"
-#include "content/public/browser/browser_thread.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/media_switches.h"
#include "media/base/video_capture_types.h"
@@ -34,7 +33,7 @@ namespace content {
// implementation to guarantee proper cleanup on destruction on our side.
class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer {
public:
- AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool,
+ AutoReleaseBuffer(const scoped_refptr<ProducerVideoCaptureBufferPool>& pool,
int buffer_id)
: id_(buffer_id),
pool_(pool),
miu 2016/09/12 20:16:46 For example, when passing scoped_refptr by value,
chfremer 2016/09/12 22:23:33 Acknowledged.
@@ -58,21 +57,21 @@ class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer {
~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); }
const int id_;
- const scoped_refptr<VideoCaptureBufferPool> pool_;
- const std::unique_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_;
+ const scoped_refptr<ProducerVideoCaptureBufferPool> pool_;
+ const std::unique_ptr<VideoCaptureBufferPoolBufferHandle> buffer_handle_;
};
VideoCaptureDeviceClient::VideoCaptureDeviceClient(
- const base::WeakPtr<VideoCaptureController>& controller,
- const scoped_refptr<VideoCaptureBufferPool>& buffer_pool)
- : controller_(controller),
+ std::unique_ptr<VideoFrameReceiver> receiver,
+ const scoped_refptr<ProducerVideoCaptureBufferPool>& buffer_pool,
+ const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory)
+ : receiver_(std::move(receiver)),
+ jpeg_decoder_factory_callback_(jpeg_decoder_factory),
external_jpeg_decoder_initialized_(false),
buffer_pool_(buffer_pool),
use_gpu_memory_buffers_(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseGpuMemoryBuffersForCapture)),
- last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-}
+ last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {}
VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {
// This should be on the platform auxiliary thread since
@@ -98,9 +97,7 @@ void VideoCaptureDeviceClient::OnIncomingCapturedData(
if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG &&
!external_jpeg_decoder_initialized_) {
external_jpeg_decoder_initialized_ = true;
- external_jpeg_decoder_.reset(new VideoCaptureGpuJpegDecoder(base::Bind(
- &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread,
- controller_)));
+ external_jpeg_decoder_ = jpeg_decoder_factory_callback_.Run();
external_jpeg_decoder_->Initialize();
}
}
@@ -276,16 +273,12 @@ VideoCaptureDeviceClient::ReserveOutputBuffer(
// TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if
// it's a ShMem GMB or a DmaBuf GMB.
- int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId;
+ int buffer_id_to_drop = ProducerVideoCaptureBufferPool::kInvalidId;
const int buffer_id = buffer_pool_->ReserveForProducer(
frame_size, pixel_format, pixel_storage, &buffer_id_to_drop);
- if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) {
- BrowserThread::PostTask(BrowserThread::IO,
- FROM_HERE,
- base::Bind(&VideoCaptureController::DoBufferDestroyedOnIOThread,
- controller_, buffer_id_to_drop));
- }
- if (buffer_id == VideoCaptureBufferPool::kInvalidId)
+ if (buffer_id_to_drop != ProducerVideoCaptureBufferPool::kInvalidId)
+ receiver_->OnBufferDestroyed(buffer_id_to_drop);
+ if (buffer_id == ProducerVideoCaptureBufferPool::kInvalidId)
return nullptr;
return base::WrapUnique<Buffer>(
new AutoReleaseBuffer(buffer_pool_, buffer_id));
@@ -335,11 +328,7 @@ void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
void VideoCaptureDeviceClient::OnIncomingCapturedVideoFrame(
std::unique_ptr<Buffer> buffer,
const scoped_refptr<VideoFrame>& frame) {
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(
- &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread,
- controller_, base::Passed(&buffer), frame));
+ receiver_->OnIncomingCapturedVideoFrame(std::move(buffer), frame);
}
std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>
@@ -349,7 +338,7 @@ VideoCaptureDeviceClient::ResurrectLastOutputBuffer(
media::VideoPixelStorage storage) {
const int buffer_id =
buffer_pool_->ResurrectLastForProducer(dimensions, format, storage);
- if (buffer_id == VideoCaptureBufferPool::kInvalidId)
+ if (buffer_id == ProducerVideoCaptureBufferPool::kInvalidId)
return nullptr;
return base::WrapUnique<Buffer>(
new AutoReleaseBuffer(buffer_pool_, buffer_id));
@@ -365,20 +354,15 @@ void VideoCaptureDeviceClient::OnError(
.c_str());
DLOG(ERROR) << log_message;
OnLog(log_message);
- BrowserThread::PostTask(BrowserThread::IO,
- FROM_HERE,
- base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_));
+ receiver_->OnError();
}
void VideoCaptureDeviceClient::OnLog(
const std::string& message) {
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- base::Bind(&VideoCaptureController::DoLogOnIOThread,
- controller_, message));
+ receiver_->OnLog(message);
}
double VideoCaptureDeviceClient::GetBufferPoolUtilization() const {
- // VideoCaptureBufferPool::GetBufferPoolUtilization() is thread-safe.
return buffer_pool_->GetBufferPoolUtilization();
}

Powered by Google App Engine
This is Rietveld 408576698