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

Side by Side Diff: content/browser/renderer_host/media/video_capture_buffer_pool_unittest.cc

Issue 2573223002: [Mojo Video Capture] Simplify media::VideoCaptureDevice::Client:Buffer to a struct (Closed)
Patch Set: miu's comments Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Unit test for VideoCaptureBufferPool. 5 // Unit test for VideoCaptureBufferPool.
6 6
7 #include "media/capture/video/video_capture_buffer_pool.h" 7 #include "media/capture/video/video_capture_buffer_pool.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // This is a generic Buffer tracker 55 // This is a generic Buffer tracker
56 class Buffer { 56 class Buffer {
57 public: 57 public:
58 Buffer(const scoped_refptr<media::VideoCaptureBufferPool> pool, 58 Buffer(const scoped_refptr<media::VideoCaptureBufferPool> pool,
59 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle, 59 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle,
60 int id) 60 int id)
61 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {} 61 : id_(id), pool_(pool), buffer_handle_(std::move(buffer_handle)) {}
62 ~Buffer() { pool_->RelinquishProducerReservation(id()); } 62 ~Buffer() { pool_->RelinquishProducerReservation(id()); }
63 int id() const { return id_; } 63 int id() const { return id_; }
64 size_t mapped_size() { return buffer_handle_->mapped_size(); } 64 size_t mapped_size() { return buffer_handle_->mapped_size(); }
65 void* data() { return buffer_handle_->data(0); } 65 void* data() { return buffer_handle_->data(); }
66 66
67 private: 67 private:
68 const int id_; 68 const int id_;
69 const scoped_refptr<media::VideoCaptureBufferPool> pool_; 69 const scoped_refptr<media::VideoCaptureBufferPool> pool_;
70 const std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle_; 70 const std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle_;
71 }; 71 };
72 72
73 VideoCaptureBufferPoolTest() 73 VideoCaptureBufferPoolTest()
74 : expected_dropped_id_(0), 74 : expected_dropped_id_(0),
75 pool_(new media::VideoCaptureBufferPoolImpl( 75 pool_(new media::VideoCaptureBufferPoolImpl(
(...skipping 17 matching lines...) Expand all
93 const int arbitrary_frame_feedback_id = 0; 93 const int arbitrary_frame_feedback_id = 0;
94 const int buffer_id = pool_->ReserveForProducer( 94 const int buffer_id = pool_->ReserveForProducer(
95 dimensions, format_and_storage.pixel_format, 95 dimensions, format_and_storage.pixel_format,
96 format_and_storage.pixel_storage, arbitrary_frame_feedback_id, 96 format_and_storage.pixel_storage, arbitrary_frame_feedback_id,
97 &buffer_id_to_drop); 97 &buffer_id_to_drop);
98 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId) 98 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId)
99 return std::unique_ptr<Buffer>(); 99 return std::unique_ptr<Buffer>();
100 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop); 100 EXPECT_EQ(expected_dropped_id_, buffer_id_to_drop);
101 101
102 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle = 102 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle =
103 pool_->GetBufferHandle(buffer_id); 103 pool_->GetHandleForInProcessAccess(buffer_id);
104 return std::unique_ptr<Buffer>( 104 return std::unique_ptr<Buffer>(
105 new Buffer(pool_, std::move(buffer_handle), buffer_id)); 105 new Buffer(pool_, std::move(buffer_handle), buffer_id));
106 } 106 }
107 107
108 std::unique_ptr<Buffer> ResurrectLastBuffer( 108 std::unique_ptr<Buffer> ResurrectLastBuffer(
109 const gfx::Size& dimensions, 109 const gfx::Size& dimensions,
110 PixelFormatAndStorage format_and_storage) { 110 PixelFormatAndStorage format_and_storage) {
111 const int buffer_id = pool_->ResurrectLastForProducer( 111 const int buffer_id = pool_->ResurrectLastForProducer(
112 dimensions, format_and_storage.pixel_format, 112 dimensions, format_and_storage.pixel_format,
113 format_and_storage.pixel_storage); 113 format_and_storage.pixel_storage);
114 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId) 114 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId)
115 return std::unique_ptr<Buffer>(); 115 return std::unique_ptr<Buffer>();
116 return std::unique_ptr<Buffer>( 116 return std::unique_ptr<Buffer>(new Buffer(
117 new Buffer(pool_, pool_->GetBufferHandle(buffer_id), buffer_id)); 117 pool_, pool_->GetHandleForInProcessAccess(buffer_id), buffer_id));
118 } 118 }
119 119
120 base::MessageLoop loop_; 120 base::MessageLoop loop_;
121 int expected_dropped_id_; 121 int expected_dropped_id_;
122 scoped_refptr<media::VideoCaptureBufferPool> pool_; 122 scoped_refptr<media::VideoCaptureBufferPool> pool_;
123 123
124 private: 124 private:
125 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest); 125 DISALLOW_COPY_AND_ASSIGN(VideoCaptureBufferPoolTest);
126 }; 126 };
127 127
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 ASSERT_NE(nullptr, held_buffers.back().get()); 410 ASSERT_NE(nullptr, held_buffers.back().get());
411 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam()); 411 resurrected = ResurrectLastBuffer(gfx::Size(10, 10), GetParam());
412 ASSERT_EQ(nullptr, resurrected.get()); 412 ASSERT_EQ(nullptr, resurrected.get());
413 } 413 }
414 414
415 INSTANTIATE_TEST_CASE_P(, 415 INSTANTIATE_TEST_CASE_P(,
416 VideoCaptureBufferPoolTest, 416 VideoCaptureBufferPoolTest,
417 testing::ValuesIn(kCapturePixelFormatAndStorages)); 417 testing::ValuesIn(kCapturePixelFormatAndStorages));
418 418
419 } // namespace content 419 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698