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

Unified Diff: content/browser/media/capture/web_contents_video_capture_device_unittest.cc

Issue 2573223002: [Mojo Video Capture] Simplify media::VideoCaptureDevice::Client:Buffer to a struct (Closed)
Patch Set: miu's comments Created 3 years, 12 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/media/capture/web_contents_video_capture_device_unittest.cc
diff --git a/content/browser/media/capture/web_contents_video_capture_device_unittest.cc b/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
index 3764d9810bce4e9a3cbb0a5c9d847a61ff24480d..3b9ec8496d40dbbe72d148217c99bccd9cea12d7 100644
--- a/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
+++ b/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
@@ -37,6 +37,7 @@
#include "media/base/yuv_convert.h"
#include "media/capture/video/video_capture_buffer_pool_impl.h"
#include "media/capture/video/video_capture_buffer_tracker_factory_impl.h"
+#include "media/capture/video/video_capture_device_client.h"
#include "media/capture/video_capture_types.h"
#include "skia/ext/platform_canvas.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -349,27 +350,25 @@ class StubClient : public media::VideoCaptureDevice::Client {
MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void));
- std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>
- ReserveOutputBuffer(const gfx::Size& dimensions,
- media::VideoPixelFormat format,
- media::VideoPixelStorage storage,
- int frame_feedback_id) override {
+ media::VideoCaptureDevice::Client::Buffer ReserveOutputBuffer(
+ const gfx::Size& dimensions,
+ media::VideoPixelFormat format,
+ media::VideoPixelStorage storage,
+ int frame_feedback_id) override {
CHECK_EQ(format, media::PIXEL_FORMAT_I420);
int buffer_id_to_drop =
media::VideoCaptureBufferPool::kInvalidId; // Ignored.
const int buffer_id = buffer_pool_->ReserveForProducer(
dimensions, format, storage, frame_feedback_id, &buffer_id_to_drop);
if (buffer_id == media::VideoCaptureBufferPool::kInvalidId)
- return NULL;
+ return media::VideoCaptureDevice::Client::Buffer();
- return std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>(
- new AutoReleaseBuffer(buffer_pool_,
- buffer_pool_->GetBufferHandle(buffer_id),
- buffer_id, frame_feedback_id));
+ return media::VideoCaptureDeviceClient::MakeBufferStruct(
+ buffer_pool_, buffer_id, frame_feedback_id);
}
// Trampoline method to workaround GMOCK problems with std::unique_ptr<>.
- void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer,
+ void OnIncomingCapturedBuffer(Buffer buffer,
const media::VideoCaptureFormat& format,
base::TimeTicks reference_time,
base::TimeDelta timestamp) override {
@@ -377,7 +376,7 @@ class StubClient : public media::VideoCaptureDevice::Client {
}
void OnIncomingCapturedBufferExt(
- std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer,
+ media::VideoCaptureDevice::Client::Buffer buffer,
const media::VideoCaptureFormat& format,
base::TimeTicks reference_time,
base::TimeDelta timestamp,
@@ -391,11 +390,11 @@ class StubClient : public media::VideoCaptureDevice::Client {
// analysis is too slow, the backlog of frames will grow without bound and
// trouble erupts. http://crbug.com/174519
using media::VideoFrame;
+ auto buffer_access = buffer.handle_provider->GetHandleForInProcessAccess();
auto frame = VideoFrame::WrapExternalSharedMemory(
media::PIXEL_FORMAT_I420, format.frame_size, visible_rect,
- format.frame_size, static_cast<uint8_t*>(buffer->data()),
- buffer->mapped_size(), base::SharedMemory::NULLHandle(), 0u,
- base::TimeDelta());
+ format.frame_size, buffer_access->data(), buffer_access->mapped_size(),
+ base::SharedMemory::NULLHandle(), 0u, base::TimeDelta());
const gfx::Point center = visible_rect.CenterPoint();
const int center_offset_y =
(frame->stride(VideoFrame::kYPlane) * center.y()) + center.x();
@@ -409,20 +408,18 @@ class StubClient : public media::VideoCaptureDevice::Client {
frame->visible_rect().size());
}
- std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>
- ResurrectLastOutputBuffer(const gfx::Size& dimensions,
- media::VideoPixelFormat format,
- media::VideoPixelStorage storage,
- int frame_feedback_id) override {
+ media::VideoCaptureDevice::Client::Buffer ResurrectLastOutputBuffer(
+ const gfx::Size& dimensions,
+ media::VideoPixelFormat format,
+ media::VideoPixelStorage storage,
+ int frame_feedback_id) override {
CHECK_EQ(format, media::PIXEL_FORMAT_I420);
const int buffer_id =
buffer_pool_->ResurrectLastForProducer(dimensions, format, storage);
if (buffer_id == media::VideoCaptureBufferPool::kInvalidId)
- return nullptr;
- return std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>(
- new AutoReleaseBuffer(buffer_pool_,
- buffer_pool_->GetBufferHandle(buffer_id),
- buffer_id, frame_feedback_id));
+ return media::VideoCaptureDevice::Client::Buffer();
+ return media::VideoCaptureDeviceClient::MakeBufferStruct(
+ buffer_pool_, buffer_id, frame_feedback_id);
}
void OnError(const tracked_objects::Location& from_here,
@@ -433,49 +430,6 @@ class StubClient : public media::VideoCaptureDevice::Client {
double GetBufferPoolUtilization() const override { return 0.0; }
private:
- class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer {
- public:
- AutoReleaseBuffer(
- const scoped_refptr<media::VideoCaptureBufferPool>& pool,
- std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle,
- int buffer_id,
- int frame_feedback_id)
- : id_(buffer_id),
- frame_feedback_id_(frame_feedback_id),
- pool_(pool),
- buffer_handle_(std::move(buffer_handle)) {
- DCHECK(pool_);
- }
- int id() const override { return id_; }
- int frame_feedback_id() const override { return frame_feedback_id_; }
- gfx::Size dimensions() const override {
- return buffer_handle_->dimensions();
- }
- size_t mapped_size() const override {
- return buffer_handle_->mapped_size();
- }
- void* data(int plane) override { return buffer_handle_->data(plane); }
-#if defined(OS_POSIX) && !defined(OS_MACOSX)
- base::FileDescriptor AsPlatformFile() override {
- return base::FileDescriptor();
- }
-#endif
- bool IsBackedByVideoFrame() const override {
- return buffer_handle_->IsBackedByVideoFrame();
- }
- scoped_refptr<media::VideoFrame> GetVideoFrame() override {
- return buffer_handle_->GetVideoFrame();
- }
-
- private:
- ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); }
-
- const int id_;
- const int frame_feedback_id_;
- const scoped_refptr<media::VideoCaptureBufferPool> pool_;
- const std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle_;
- };
-
scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
base::Callback<void(SkColor, const gfx::Size&)> report_callback_;
base::Closure error_callback_;

Powered by Google App Engine
This is Rietveld 408576698