OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "media/video/gpu_memory_buffer_video_frame_pool.h" | 5 #include "media/video/gpu_memory_buffer_video_frame_pool.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // GL context provided by |gpu_factories| | 45 // GL context provided by |gpu_factories| |
46 // |worker_task_runner| is a task runner used to asynchronously copy | 46 // |worker_task_runner| is a task runner used to asynchronously copy |
47 // video frame's planes. | 47 // video frame's planes. |
48 // |gpu_factories| is an interface to GPU related operation and can be | 48 // |gpu_factories| is an interface to GPU related operation and can be |
49 // null if a GL context is not available. | 49 // null if a GL context is not available. |
50 PoolImpl(const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, | 50 PoolImpl(const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
51 const scoped_refptr<base::TaskRunner>& worker_task_runner, | 51 const scoped_refptr<base::TaskRunner>& worker_task_runner, |
52 GpuVideoAcceleratorFactories* gpu_factories) | 52 GpuVideoAcceleratorFactories* gpu_factories) |
53 : media_task_runner_(media_task_runner), | 53 : media_task_runner_(media_task_runner), |
54 worker_task_runner_(worker_task_runner), | 54 worker_task_runner_(worker_task_runner), |
55 gpu_factories_(gpu_factories), | 55 gpu_factories_(gpu_factories) { |
56 output_format_(GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED) { | |
57 DCHECK(media_task_runner_); | 56 DCHECK(media_task_runner_); |
58 DCHECK(worker_task_runner_); | 57 DCHECK(worker_task_runner_); |
59 } | 58 } |
60 | 59 |
61 // Takes a software VideoFrame and calls |frame_ready_cb| with a VideoFrame | 60 // Takes a software VideoFrame and calls |frame_ready_cb| with a VideoFrame |
62 // backed by native textures if possible. | 61 // backed by native textures if possible. |
63 // The data contained in video_frame is copied into the returned frame | 62 // The data contained in video_frame is copied into the returned frame |
64 // asynchronously posting tasks to |worker_task_runner_|, while | 63 // asynchronously posting tasks to |worker_task_runner_|, while |
65 // |frame_ready_cb| will be called on |media_task_runner_| once all the data | 64 // |frame_ready_cb| will be called on |media_task_runner_| once all the data |
66 // has been copied. | 65 // has been copied. |
(...skipping 12 matching lines...) Expand all Loading... |
79 struct PlaneResource { | 78 struct PlaneResource { |
80 gfx::Size size; | 79 gfx::Size size; |
81 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; | 80 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; |
82 unsigned texture_id = 0u; | 81 unsigned texture_id = 0u; |
83 unsigned image_id = 0u; | 82 unsigned image_id = 0u; |
84 gpu::Mailbox mailbox; | 83 gpu::Mailbox mailbox; |
85 }; | 84 }; |
86 | 85 |
87 // All the resources needed to compose a frame. | 86 // All the resources needed to compose a frame. |
88 struct FrameResources { | 87 struct FrameResources { |
89 explicit FrameResources(const gfx::Size& size) : size(size) {} | 88 explicit FrameResources(const gfx::Size& size, |
| 89 GpuVideoAcceleratorFactories::OutputFormat format) |
| 90 : size(size), format(format) {} |
90 void SetIsInUse(bool in_use) { in_use_ = in_use; } | 91 void SetIsInUse(bool in_use) { in_use_ = in_use; } |
91 bool IsInUse() const { return in_use_; } | 92 bool IsInUse() const { return in_use_; } |
92 | 93 |
93 const gfx::Size size; | 94 const gfx::Size size; |
| 95 GpuVideoAcceleratorFactories::OutputFormat format; |
94 PlaneResource plane_resources[VideoFrame::kMaxPlanes]; | 96 PlaneResource plane_resources[VideoFrame::kMaxPlanes]; |
95 | 97 |
96 private: | 98 private: |
97 bool in_use_ = true; | 99 bool in_use_ = true; |
98 }; | 100 }; |
99 | 101 |
100 // Copy |video_frame| data into |frame_resouces| | 102 // Copy |video_frame| data into |frame_resouces| |
101 // and calls |done| when done. | 103 // and calls |done| when done. |
102 void CopyVideoFrameToGpuMemoryBuffers( | 104 void CopyVideoFrameToGpuMemoryBuffers( |
103 const scoped_refptr<VideoFrame>& video_frame, | 105 const scoped_refptr<VideoFrame>& video_frame, |
104 FrameResources* frame_resources, | 106 FrameResources* frame_resources, |
105 const FrameReadyCB& frame_ready_cb); | 107 const FrameReadyCB& frame_ready_cb); |
106 | 108 |
107 // Called when all the data has been copied. | 109 // Called when all the data has been copied. |
108 void OnCopiesDone(const scoped_refptr<VideoFrame>& video_frame, | 110 void OnCopiesDone(const scoped_refptr<VideoFrame>& video_frame, |
109 FrameResources* frame_resources, | 111 FrameResources* frame_resources, |
110 const FrameReadyCB& frame_ready_cb); | 112 const FrameReadyCB& frame_ready_cb); |
111 | 113 |
112 // Prepares GL resources, mailboxes and calls |frame_ready_cb| with the new | 114 // Prepares GL resources, mailboxes and calls |frame_ready_cb| with the new |
113 // VideoFrame. | 115 // VideoFrame. |
114 // This has to be run on |media_task_runner_| where |frame_ready_cb| will also | 116 // This has to be run on |media_task_runner_| where |frame_ready_cb| will also |
115 // be run. | 117 // be run. |
116 void BindAndCreateMailboxesHardwareFrameResources( | 118 void BindAndCreateMailboxesHardwareFrameResources( |
117 const scoped_refptr<VideoFrame>& video_frame, | 119 const scoped_refptr<VideoFrame>& video_frame, |
118 FrameResources* frame_resources, | 120 FrameResources* frame_resources, |
119 const FrameReadyCB& frame_ready_cb); | 121 const FrameReadyCB& frame_ready_cb); |
120 | 122 |
121 // Return true if |resources| can be used to represent a frame for | 123 // Return true if |resources| can be used to represent a frame for |
122 // specific |format| and |size|. | 124 // specific |format| and |size|. |
123 static bool AreFrameResourcesCompatible(const FrameResources* resources, | 125 static bool AreFrameResourcesCompatible( |
124 const gfx::Size& size) { | 126 const FrameResources* resources, |
125 return size == resources->size; | 127 const gfx::Size& size, |
| 128 GpuVideoAcceleratorFactories::OutputFormat format) { |
| 129 return size == resources->size && format == resources->format; |
126 } | 130 } |
127 | 131 |
128 // Get the resources needed for a frame out of the pool, or create them if | 132 // Get the resources needed for a frame out of the pool, or create them if |
129 // necessary. | 133 // necessary. |
130 // This also drops the LRU resources that can't be reuse for this frame. | 134 // This also drops the LRU resources that can't be reuse for this frame. |
131 FrameResources* GetOrCreateFrameResources( | 135 FrameResources* GetOrCreateFrameResources( |
132 const gfx::Size& size, | 136 const gfx::Size& size, |
133 GpuVideoAcceleratorFactories::OutputFormat format); | 137 GpuVideoAcceleratorFactories::OutputFormat format); |
134 | 138 |
135 // Callback called when a VideoFrame generated with GetFrameResources is no | 139 // Callback called when a VideoFrame generated with GetFrameResources is no |
(...skipping 11 matching lines...) Expand all Loading... |
147 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 151 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
148 // Task runner used to asynchronously copy planes. | 152 // Task runner used to asynchronously copy planes. |
149 scoped_refptr<base::TaskRunner> worker_task_runner_; | 153 scoped_refptr<base::TaskRunner> worker_task_runner_; |
150 | 154 |
151 // Interface to GPU related operations. | 155 // Interface to GPU related operations. |
152 GpuVideoAcceleratorFactories* gpu_factories_; | 156 GpuVideoAcceleratorFactories* gpu_factories_; |
153 | 157 |
154 // Pool of resources. | 158 // Pool of resources. |
155 std::list<FrameResources*> resources_pool_; | 159 std::list<FrameResources*> resources_pool_; |
156 | 160 |
157 GpuVideoAcceleratorFactories::OutputFormat output_format_; | 161 // Cache gpu_factories_->VideoFrameOutputFormat(VideoPixelFormat). |
| 162 GpuVideoAcceleratorFactories::OutputFormat output_format_ = |
| 163 GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED; |
| 164 |
| 165 // Pixel format used to to calculate |output_format_|. |
| 166 VideoPixelFormat current_pixel_format_ = PIXEL_FORMAT_UNKNOWN; |
158 | 167 |
159 DISALLOW_COPY_AND_ASSIGN(PoolImpl); | 168 DISALLOW_COPY_AND_ASSIGN(PoolImpl); |
160 }; | 169 }; |
161 | 170 |
162 namespace { | 171 namespace { |
163 | 172 |
164 // VideoFrame copies to GpuMemoryBuffers will be split in copies where the | 173 // VideoFrame copies to GpuMemoryBuffers will be split in copies where the |
165 // output size is |kBytesPerCopyTarget| bytes and run in parallel. | 174 // output size is |kBytesPerCopyTarget| bytes and run in parallel. |
166 const size_t kBytesPerCopyTarget = 1024 * 1024; // 1MB | 175 const size_t kBytesPerCopyTarget = 1024 * 1024; // 1MB |
167 | 176 |
168 // Return the GpuMemoryBuffer format to use for a specific VideoPixelFormat | 177 // Return the GpuMemoryBuffer format to use for a specific OutputFormat |
169 // and plane. | 178 // and plane. |
170 gfx::BufferFormat GpuMemoryBufferFormat( | 179 gfx::BufferFormat GpuMemoryBufferFormat( |
171 media::GpuVideoAcceleratorFactories::OutputFormat format, | 180 media::GpuVideoAcceleratorFactories::OutputFormat format, |
172 size_t plane) { | 181 size_t plane) { |
173 switch (format) { | 182 switch (format) { |
174 case GpuVideoAcceleratorFactories::OutputFormat::I420: | 183 case GpuVideoAcceleratorFactories::OutputFormat::I420: |
175 DCHECK_LE(plane, 2u); | 184 DCHECK_LE(plane, 2u); |
176 return gfx::BufferFormat::R_8; | 185 return gfx::BufferFormat::R_8; |
177 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: | 186 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: |
178 DCHECK_LE(plane, 1u); | 187 DCHECK_LE(plane, 1u); |
179 return gfx::BufferFormat::YUV_420_BIPLANAR; | 188 return gfx::BufferFormat::YUV_420_BIPLANAR; |
180 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: | 189 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: |
181 DCHECK_LE(plane, 1u); | 190 DCHECK_LE(plane, 1u); |
182 return plane == 0 ? gfx::BufferFormat::R_8 : gfx::BufferFormat::RG_88; | 191 return plane == 0 ? gfx::BufferFormat::R_8 : gfx::BufferFormat::RG_88; |
183 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: | 192 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: |
184 DCHECK_EQ(0u, plane); | 193 DCHECK_EQ(0u, plane); |
185 return gfx::BufferFormat::UYVY_422; | 194 return gfx::BufferFormat::UYVY_422; |
| 195 case GpuVideoAcceleratorFactories::OutputFormat::Y16: |
| 196 DCHECK_EQ(0u, plane); |
| 197 return gfx::BufferFormat::RG_88; |
186 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: | 198 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: |
187 NOTREACHED(); | 199 NOTREACHED(); |
188 break; | 200 break; |
189 } | 201 } |
190 return gfx::BufferFormat::BGRA_8888; | 202 return gfx::BufferFormat::BGRA_8888; |
191 } | 203 } |
192 | 204 |
193 unsigned ImageInternalFormat(GpuVideoAcceleratorFactories::OutputFormat format, | 205 unsigned ImageInternalFormat(GpuVideoAcceleratorFactories::OutputFormat format, |
194 size_t plane) { | 206 size_t plane) { |
195 switch (format) { | 207 switch (format) { |
196 case GpuVideoAcceleratorFactories::OutputFormat::I420: | 208 case GpuVideoAcceleratorFactories::OutputFormat::I420: |
197 DCHECK_LE(plane, 2u); | 209 DCHECK_LE(plane, 2u); |
198 return GL_RED_EXT; | 210 return GL_RED_EXT; |
199 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: | 211 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: |
200 DCHECK_LE(plane, 1u); | 212 DCHECK_LE(plane, 1u); |
201 return plane == 0 ? GL_RED_EXT : GL_RG_EXT; | 213 return plane == 0 ? GL_RED_EXT : GL_RG_EXT; |
202 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: | 214 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: |
203 DCHECK_LE(plane, 1u); | 215 DCHECK_LE(plane, 1u); |
204 return GL_RGB_YCBCR_420V_CHROMIUM; | 216 return GL_RGB_YCBCR_420V_CHROMIUM; |
205 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: | 217 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: |
206 DCHECK_EQ(0u, plane); | 218 DCHECK_EQ(0u, plane); |
207 return GL_RGB_YCBCR_422_CHROMIUM; | 219 return GL_RGB_YCBCR_422_CHROMIUM; |
| 220 case GpuVideoAcceleratorFactories::OutputFormat::Y16: |
| 221 DCHECK_EQ(0u, plane); |
| 222 return GL_RG_EXT; |
208 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: | 223 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: |
209 NOTREACHED(); | 224 NOTREACHED(); |
210 break; | 225 break; |
211 } | 226 } |
212 return 0; | 227 return 0; |
213 } | 228 } |
214 | 229 |
215 // The number of output planes to be copied in each iteration. | 230 // The number of output planes to be copied in each iteration. |
216 size_t PlanesPerCopy(GpuVideoAcceleratorFactories::OutputFormat format) { | 231 size_t PlanesPerCopy(GpuVideoAcceleratorFactories::OutputFormat format) { |
217 switch (format) { | 232 switch (format) { |
218 case GpuVideoAcceleratorFactories::OutputFormat::I420: | 233 case GpuVideoAcceleratorFactories::OutputFormat::I420: |
219 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: | 234 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: |
| 235 case GpuVideoAcceleratorFactories::OutputFormat::Y16: |
220 return 1; | 236 return 1; |
221 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: | 237 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: |
222 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: | 238 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: |
223 return 2; | 239 return 2; |
224 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: | 240 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: |
225 NOTREACHED(); | 241 NOTREACHED(); |
226 break; | 242 break; |
227 } | 243 } |
228 return 0; | 244 return 0; |
229 } | 245 } |
230 | 246 |
231 VideoPixelFormat VideoFormat( | 247 VideoPixelFormat VideoFormat( |
232 GpuVideoAcceleratorFactories::OutputFormat format) { | 248 GpuVideoAcceleratorFactories::OutputFormat format) { |
233 switch (format) { | 249 switch (format) { |
234 case GpuVideoAcceleratorFactories::OutputFormat::I420: | 250 case GpuVideoAcceleratorFactories::OutputFormat::I420: |
235 return PIXEL_FORMAT_I420; | 251 return PIXEL_FORMAT_I420; |
236 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: | 252 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: |
237 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: | 253 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: |
238 return PIXEL_FORMAT_NV12; | 254 return PIXEL_FORMAT_NV12; |
239 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: | 255 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: |
240 return PIXEL_FORMAT_UYVY; | 256 return PIXEL_FORMAT_UYVY; |
| 257 case GpuVideoAcceleratorFactories::OutputFormat::Y16: |
| 258 return PIXEL_FORMAT_Y16; |
241 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: | 259 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: |
242 NOTREACHED(); | 260 NOTREACHED(); |
243 break; | 261 break; |
244 } | 262 } |
245 return PIXEL_FORMAT_UNKNOWN; | 263 return PIXEL_FORMAT_UNKNOWN; |
246 } | 264 } |
247 | 265 |
248 VideoPixelFormat FinalVideoFormat( | 266 VideoPixelFormat FinalVideoFormat( |
249 GpuVideoAcceleratorFactories::OutputFormat format) { | 267 GpuVideoAcceleratorFactories::OutputFormat format) { |
250 // Consumers should sample from NV12 textures as if they're XRGB. | 268 // Consumers should sample from NV12 textures as if they're XRGB. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 first_row / 2 * source_frame->stride(VideoFrame::kUPlane), | 365 first_row / 2 * source_frame->stride(VideoFrame::kUPlane), |
348 source_frame->stride(VideoFrame::kUPlane), | 366 source_frame->stride(VideoFrame::kUPlane), |
349 source_frame->visible_data(VideoFrame::kVPlane) + | 367 source_frame->visible_data(VideoFrame::kVPlane) + |
350 first_row / 2 * source_frame->stride(VideoFrame::kVPlane), | 368 first_row / 2 * source_frame->stride(VideoFrame::kVPlane), |
351 source_frame->stride(VideoFrame::kVPlane), | 369 source_frame->stride(VideoFrame::kVPlane), |
352 output + first_row * dest_stride, dest_stride, width, rows); | 370 output + first_row * dest_stride, dest_stride, width, rows); |
353 } | 371 } |
354 done.Run(); | 372 done.Run(); |
355 } | 373 } |
356 | 374 |
| 375 // Used for pixel-order formats: e.g. Y16, Y8, etc. |
| 376 void CopyRowsToGenericSinglePlaneGPUBuffer( |
| 377 int first_row, |
| 378 int rows, |
| 379 int width, |
| 380 const scoped_refptr<VideoFrame>& source_frame, |
| 381 uint8_t* output, |
| 382 int dest_stride, |
| 383 const base::Closure& done) { |
| 384 int row_bytes = VideoFrame::RowBytes(0, source_frame->format(), width); |
| 385 TRACE_EVENT2("media", "CopyRowsToGenericSinglePlaneGPUBuffer", |
| 386 "bytes_per_row", row_bytes, "rows", rows); |
| 387 if (output) { |
| 388 DCHECK_NE(dest_stride, 0); |
| 389 DCHECK_LE(row_bytes, std::abs(dest_stride)); |
| 390 const int source_stride = source_frame->stride(0); |
| 391 const uint8_t* source = |
| 392 source_frame->visible_data(0) + first_row * source_stride; |
| 393 uint8_t* dest = output + first_row * dest_stride; |
| 394 for (int i = 0; i < rows; ++i) |
| 395 memcpy(dest + i * dest_stride, source + i * source_stride, row_bytes); |
| 396 } |
| 397 done.Run(); |
| 398 } |
| 399 |
357 gfx::Size CodedSize(const scoped_refptr<VideoFrame>& video_frame, | 400 gfx::Size CodedSize(const scoped_refptr<VideoFrame>& video_frame, |
358 GpuVideoAcceleratorFactories::OutputFormat output_format) { | 401 GpuVideoAcceleratorFactories::OutputFormat output_format) { |
359 DCHECK(gfx::Rect(video_frame->coded_size()) | 402 DCHECK(gfx::Rect(video_frame->coded_size()) |
360 .Contains(video_frame->visible_rect())); | 403 .Contains(video_frame->visible_rect())); |
361 DCHECK((video_frame->visible_rect().x() & 1) == 0); | 404 DCHECK((video_frame->visible_rect().x() & 1) == 0); |
362 gfx::Size output; | 405 gfx::Size output; |
363 switch (output_format) { | 406 switch (output_format) { |
364 case GpuVideoAcceleratorFactories::OutputFormat::I420: | 407 case GpuVideoAcceleratorFactories::OutputFormat::I420: |
365 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: | 408 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: |
366 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: | 409 case GpuVideoAcceleratorFactories::OutputFormat::NV12_DUAL_GMB: |
367 DCHECK((video_frame->visible_rect().y() & 1) == 0); | 410 DCHECK((video_frame->visible_rect().y() & 1) == 0); |
368 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1, | 411 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1, |
369 (video_frame->visible_rect().height() + 1) & ~1); | 412 (video_frame->visible_rect().height() + 1) & ~1); |
370 break; | 413 break; |
371 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: | 414 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: |
372 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1, | 415 output = gfx::Size((video_frame->visible_rect().width() + 1) & ~1, |
373 video_frame->visible_rect().height()); | 416 video_frame->visible_rect().height()); |
374 break; | 417 break; |
| 418 case GpuVideoAcceleratorFactories::OutputFormat::Y16: |
| 419 output = video_frame->visible_rect().size(); |
| 420 break; |
375 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: | 421 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: |
376 NOTREACHED(); | 422 NOTREACHED(); |
377 } | 423 } |
378 DCHECK(gfx::Rect(video_frame->coded_size()).Contains(gfx::Rect(output))); | 424 DCHECK(gfx::Rect(video_frame->coded_size()).Contains(gfx::Rect(output))); |
379 return output; | 425 return output; |
380 } | 426 } |
381 } // unnamed namespace | 427 } // unnamed namespace |
382 | 428 |
383 // Creates a VideoFrame backed by native textures starting from a software | 429 // Creates a VideoFrame backed by native textures starting from a software |
384 // VideoFrame. | 430 // VideoFrame. |
385 // The data contained in |video_frame| is copied into the VideoFrame passed to | 431 // The data contained in |video_frame| is copied into the VideoFrame passed to |
386 // |frame_ready_cb|. | 432 // |frame_ready_cb|. |
387 // This has to be called on the thread where |media_task_runner_| is current. | 433 // This has to be called on the thread where |media_task_runner_| is current. |
388 void GpuMemoryBufferVideoFramePool::PoolImpl::CreateHardwareFrame( | 434 void GpuMemoryBufferVideoFramePool::PoolImpl::CreateHardwareFrame( |
389 const scoped_refptr<VideoFrame>& video_frame, | 435 const scoped_refptr<VideoFrame>& video_frame, |
390 const FrameReadyCB& frame_ready_cb) { | 436 const FrameReadyCB& frame_ready_cb) { |
391 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 437 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
392 // Lazily initialize output_format_ since VideoFrameOutputFormat() has to be | 438 // Lazily initialize output_format_ since VideoFrameOutputFormat() has to be |
393 // called on the media_thread while this object might be instantiated on any. | 439 // called on the media_thread while this object might be instantiated on any. |
394 if (output_format_ == GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED) | 440 if (current_pixel_format_ != video_frame->format()) { |
395 output_format_ = gpu_factories_->VideoFrameOutputFormat(); | 441 output_format_ = |
| 442 gpu_factories_->VideoFrameOutputFormat(video_frame->format()); |
| 443 current_pixel_format_ = video_frame->format(); |
| 444 } |
396 | 445 |
397 if (output_format_ == GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED) { | 446 if (output_format_ == GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED) { |
398 frame_ready_cb.Run(video_frame); | 447 frame_ready_cb.Run(video_frame); |
399 return; | 448 return; |
400 } | 449 } |
401 switch (video_frame->format()) { | 450 switch (video_frame->format()) { |
402 // Supported cases. | 451 // Supported cases. |
403 case PIXEL_FORMAT_YV12: | 452 case PIXEL_FORMAT_YV12: |
404 case PIXEL_FORMAT_I420: | 453 case PIXEL_FORMAT_I420: |
| 454 case PIXEL_FORMAT_Y16: |
405 break; | 455 break; |
406 // Unsupported cases. | 456 // Unsupported cases. |
407 case PIXEL_FORMAT_YV12A: | 457 case PIXEL_FORMAT_YV12A: |
408 case PIXEL_FORMAT_YV16: | 458 case PIXEL_FORMAT_YV16: |
409 case PIXEL_FORMAT_YV24: | 459 case PIXEL_FORMAT_YV24: |
410 case PIXEL_FORMAT_NV12: | 460 case PIXEL_FORMAT_NV12: |
411 case PIXEL_FORMAT_NV21: | 461 case PIXEL_FORMAT_NV21: |
412 case PIXEL_FORMAT_UYVY: | 462 case PIXEL_FORMAT_UYVY: |
413 case PIXEL_FORMAT_YUY2: | 463 case PIXEL_FORMAT_YUY2: |
414 case PIXEL_FORMAT_ARGB: | 464 case PIXEL_FORMAT_ARGB: |
415 case PIXEL_FORMAT_XRGB: | 465 case PIXEL_FORMAT_XRGB: |
416 case PIXEL_FORMAT_RGB24: | 466 case PIXEL_FORMAT_RGB24: |
417 case PIXEL_FORMAT_RGB32: | 467 case PIXEL_FORMAT_RGB32: |
418 case PIXEL_FORMAT_MJPEG: | 468 case PIXEL_FORMAT_MJPEG: |
419 case PIXEL_FORMAT_MT21: | 469 case PIXEL_FORMAT_MT21: |
420 case PIXEL_FORMAT_YUV420P9: | 470 case PIXEL_FORMAT_YUV420P9: |
421 case PIXEL_FORMAT_YUV422P9: | 471 case PIXEL_FORMAT_YUV422P9: |
422 case PIXEL_FORMAT_YUV444P9: | 472 case PIXEL_FORMAT_YUV444P9: |
423 case PIXEL_FORMAT_YUV420P10: | 473 case PIXEL_FORMAT_YUV420P10: |
424 case PIXEL_FORMAT_YUV422P10: | 474 case PIXEL_FORMAT_YUV422P10: |
425 case PIXEL_FORMAT_YUV444P10: | 475 case PIXEL_FORMAT_YUV444P10: |
426 case PIXEL_FORMAT_YUV420P12: | 476 case PIXEL_FORMAT_YUV420P12: |
427 case PIXEL_FORMAT_YUV422P12: | 477 case PIXEL_FORMAT_YUV422P12: |
428 case PIXEL_FORMAT_YUV444P12: | 478 case PIXEL_FORMAT_YUV444P12: |
429 case PIXEL_FORMAT_Y8: | 479 case PIXEL_FORMAT_Y8: |
430 case PIXEL_FORMAT_Y16: | |
431 case PIXEL_FORMAT_UNKNOWN: | 480 case PIXEL_FORMAT_UNKNOWN: |
432 frame_ready_cb.Run(video_frame); | 481 frame_ready_cb.Run(video_frame); |
433 return; | 482 return; |
434 } | 483 } |
435 | 484 |
436 const gfx::Size coded_size = CodedSize(video_frame, output_format_); | 485 const gfx::Size coded_size = CodedSize(video_frame, output_format_); |
437 // Acquire resources. Incompatible ones will be dropped from the pool. | 486 // Acquire resources. Incompatible ones will be dropped from the pool. |
438 FrameResources* frame_resources = | 487 FrameResources* frame_resources = |
439 GetOrCreateFrameResources(coded_size, output_format_); | 488 GetOrCreateFrameResources(coded_size, output_format_); |
440 if (!frame_resources) { | 489 if (!frame_resources) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 } | 551 } |
503 | 552 |
504 // Copies |video_frame| into |frame_resources| asynchronously, posting n tasks | 553 // Copies |video_frame| into |frame_resources| asynchronously, posting n tasks |
505 // that will be synchronized by a barrier. | 554 // that will be synchronized by a barrier. |
506 // After the barrier is passed OnCopiesDone will be called. | 555 // After the barrier is passed OnCopiesDone will be called. |
507 void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers( | 556 void GpuMemoryBufferVideoFramePool::PoolImpl::CopyVideoFrameToGpuMemoryBuffers( |
508 const scoped_refptr<VideoFrame>& video_frame, | 557 const scoped_refptr<VideoFrame>& video_frame, |
509 FrameResources* frame_resources, | 558 FrameResources* frame_resources, |
510 const FrameReadyCB& frame_ready_cb) { | 559 const FrameReadyCB& frame_ready_cb) { |
511 // Compute the number of tasks to post and create the barrier. | 560 // Compute the number of tasks to post and create the barrier. |
512 const size_t num_planes = VideoFrame::NumPlanes(VideoFormat(output_format_)); | 561 const size_t num_planes = |
513 const size_t planes_per_copy = PlanesPerCopy(output_format_); | 562 VideoFrame::NumPlanes(VideoFormat(frame_resources->format)); |
514 const gfx::Size coded_size = CodedSize(video_frame, output_format_); | 563 const size_t planes_per_copy = PlanesPerCopy(frame_resources->format); |
| 564 const gfx::Size coded_size = CodedSize(video_frame, frame_resources->format); |
515 size_t copies = 0; | 565 size_t copies = 0; |
516 for (size_t i = 0; i < num_planes; i += planes_per_copy) { | 566 for (size_t i = 0; i < num_planes; i += planes_per_copy) { |
517 const int rows = | 567 const int rows = VideoFrame::Rows(i, VideoFormat(frame_resources->format), |
518 VideoFrame::Rows(i, VideoFormat(output_format_), coded_size.height()); | 568 coded_size.height()); |
519 const int rows_per_copy = | 569 const int rows_per_copy = RowsPerCopy( |
520 RowsPerCopy(i, VideoFormat(output_format_), coded_size.width()); | 570 i, VideoFormat(frame_resources->format), coded_size.width()); |
521 copies += rows / rows_per_copy; | 571 copies += rows / rows_per_copy; |
522 if (rows % rows_per_copy) | 572 if (rows % rows_per_copy) |
523 ++copies; | 573 ++copies; |
524 } | 574 } |
525 | 575 |
526 const base::Closure copies_done = | 576 const base::Closure copies_done = |
527 base::Bind(&PoolImpl::OnCopiesDone, this, video_frame, frame_resources, | 577 base::Bind(&PoolImpl::OnCopiesDone, this, video_frame, frame_resources, |
528 frame_ready_cb); | 578 frame_ready_cb); |
529 const base::Closure barrier = base::BarrierClosure(copies, copies_done); | 579 const base::Closure barrier = base::BarrierClosure(copies, copies_done); |
530 | 580 |
531 // Map the buffers. | 581 // Map the buffers. |
532 for (size_t i = 0; i < NumGpuMemoryBuffers(output_format_); i++) { | 582 for (size_t i = 0; i < NumGpuMemoryBuffers(frame_resources->format); i++) { |
533 gfx::GpuMemoryBuffer* buffer = | 583 gfx::GpuMemoryBuffer* buffer = |
534 frame_resources->plane_resources[i].gpu_memory_buffer.get(); | 584 frame_resources->plane_resources[i].gpu_memory_buffer.get(); |
535 | 585 |
536 if (!buffer || !buffer->Map()) { | 586 if (!buffer || !buffer->Map()) { |
537 DLOG(ERROR) << "Could not get or Map() buffer"; | 587 DLOG(ERROR) << "Could not get or Map() buffer"; |
538 return; | 588 return; |
539 } | 589 } |
540 } | 590 } |
541 | 591 |
542 // Post all the async tasks. | 592 // Post all the async tasks. |
543 for (size_t i = 0; i < num_planes; i += planes_per_copy) { | 593 for (size_t i = 0; i < num_planes; i += planes_per_copy) { |
544 gfx::GpuMemoryBuffer* buffer = | 594 gfx::GpuMemoryBuffer* buffer = |
545 frame_resources->plane_resources[i].gpu_memory_buffer.get(); | 595 frame_resources->plane_resources[i].gpu_memory_buffer.get(); |
546 const int rows = | 596 const int rows = VideoFrame::Rows(i, VideoFormat(frame_resources->format), |
547 VideoFrame::Rows(i, VideoFormat(output_format_), coded_size.height()); | 597 coded_size.height()); |
548 const int rows_per_copy = | 598 const int rows_per_copy = RowsPerCopy( |
549 RowsPerCopy(i, VideoFormat(output_format_), coded_size.width()); | 599 i, VideoFormat(frame_resources->format), coded_size.width()); |
550 | 600 |
551 for (int row = 0; row < rows; row += rows_per_copy) { | 601 for (int row = 0; row < rows; row += rows_per_copy) { |
552 const int rows_to_copy = std::min(rows_per_copy, rows - row); | 602 const int rows_to_copy = std::min(rows_per_copy, rows - row); |
553 switch (output_format_) { | 603 switch (frame_resources->format) { |
554 case GpuVideoAcceleratorFactories::OutputFormat::I420: { | 604 case GpuVideoAcceleratorFactories::OutputFormat::I420: { |
555 const int bytes_per_row = VideoFrame::RowBytes( | 605 const int bytes_per_row = VideoFrame::RowBytes( |
556 i, VideoFormat(output_format_), coded_size.width()); | 606 i, VideoFormat(frame_resources->format), coded_size.width()); |
557 worker_task_runner_->PostTask( | 607 worker_task_runner_->PostTask( |
558 FROM_HERE, base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy, | 608 FROM_HERE, base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy, |
559 bytes_per_row, video_frame->visible_data(i), | 609 bytes_per_row, video_frame->visible_data(i), |
560 video_frame->stride(i), | 610 video_frame->stride(i), |
561 static_cast<uint8_t*>(buffer->memory(0)), | 611 static_cast<uint8_t*>(buffer->memory(0)), |
562 buffer->stride(0), barrier)); | 612 buffer->stride(0), barrier)); |
563 break; | 613 break; |
564 } | 614 } |
565 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: | 615 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: |
566 worker_task_runner_->PostTask( | 616 worker_task_runner_->PostTask( |
(...skipping 17 matching lines...) Expand all Loading... |
584 break; | 634 break; |
585 } | 635 } |
586 | 636 |
587 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: | 637 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: |
588 worker_task_runner_->PostTask( | 638 worker_task_runner_->PostTask( |
589 FROM_HERE, base::Bind(&CopyRowsToUYVYBuffer, row, rows_to_copy, | 639 FROM_HERE, base::Bind(&CopyRowsToUYVYBuffer, row, rows_to_copy, |
590 coded_size.width(), video_frame, | 640 coded_size.width(), video_frame, |
591 static_cast<uint8_t*>(buffer->memory(0)), | 641 static_cast<uint8_t*>(buffer->memory(0)), |
592 buffer->stride(0), barrier)); | 642 buffer->stride(0), barrier)); |
593 break; | 643 break; |
| 644 case GpuVideoAcceleratorFactories::OutputFormat::Y16: |
| 645 worker_task_runner_->PostTask( |
| 646 FROM_HERE, |
| 647 base::Bind(&CopyRowsToGenericSinglePlaneGPUBuffer, row, |
| 648 rows_to_copy, coded_size.width(), video_frame, |
| 649 static_cast<uint8_t*>(buffer->memory(0)), |
| 650 buffer->stride(0), barrier)); |
| 651 break; |
594 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: | 652 case GpuVideoAcceleratorFactories::OutputFormat::UNDEFINED: |
595 NOTREACHED(); | 653 NOTREACHED(); |
596 } | 654 } |
597 } | 655 } |
598 } | 656 } |
599 } | 657 } |
600 | 658 |
601 void GpuMemoryBufferVideoFramePool::PoolImpl:: | 659 void GpuMemoryBufferVideoFramePool::PoolImpl:: |
602 BindAndCreateMailboxesHardwareFrameResources( | 660 BindAndCreateMailboxesHardwareFrameResources( |
603 const scoped_refptr<VideoFrame>& video_frame, | 661 const scoped_refptr<VideoFrame>& video_frame, |
604 FrameResources* frame_resources, | 662 FrameResources* frame_resources, |
605 const FrameReadyCB& frame_ready_cb) { | 663 const FrameReadyCB& frame_ready_cb) { |
606 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( | 664 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( |
607 gpu_factories_->GetGLContextLock()); | 665 gpu_factories_->GetGLContextLock()); |
608 if (!lock) { | 666 if (!lock) { |
609 frame_ready_cb.Run(video_frame); | 667 frame_ready_cb.Run(video_frame); |
610 return; | 668 return; |
611 } | 669 } |
612 gpu::gles2::GLES2Interface* gles2 = lock->ContextGL(); | 670 gpu::gles2::GLES2Interface* gles2 = lock->ContextGL(); |
613 | 671 |
614 const gfx::Size coded_size = CodedSize(video_frame, output_format_); | 672 const gfx::Size coded_size = CodedSize(video_frame, frame_resources->format); |
615 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; | 673 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; |
616 // Set up the planes creating the mailboxes needed to refer to the textures. | 674 // Set up the planes creating the mailboxes needed to refer to the textures. |
617 for (size_t i = 0; i < NumGpuMemoryBuffers(output_format_); i++) { | 675 for (size_t i = 0; i < NumGpuMemoryBuffers(frame_resources->format); i++) { |
618 PlaneResource& plane_resource = frame_resources->plane_resources[i]; | 676 PlaneResource& plane_resource = frame_resources->plane_resources[i]; |
619 const gfx::BufferFormat buffer_format = | 677 const gfx::BufferFormat buffer_format = |
620 GpuMemoryBufferFormat(output_format_, i); | 678 GpuMemoryBufferFormat(frame_resources->format, i); |
621 unsigned texture_target = gpu_factories_->ImageTextureTarget(buffer_format); | 679 unsigned texture_target = gpu_factories_->ImageTextureTarget(buffer_format); |
622 // Bind the texture and create or rebind the image. | 680 // Bind the texture and create or rebind the image. |
623 gles2->BindTexture(texture_target, plane_resource.texture_id); | 681 gles2->BindTexture(texture_target, plane_resource.texture_id); |
624 if (plane_resource.gpu_memory_buffer && !plane_resource.image_id) { | 682 if (plane_resource.gpu_memory_buffer && !plane_resource.image_id) { |
625 const size_t width = VideoFrame::Columns(i, VideoFormat(output_format_), | 683 const size_t width = VideoFrame::Columns( |
626 coded_size.width()); | 684 i, VideoFormat(frame_resources->format), coded_size.width()); |
627 const size_t height = | 685 const size_t height = VideoFrame::Rows( |
628 VideoFrame::Rows(i, VideoFormat(output_format_), coded_size.height()); | 686 i, VideoFormat(frame_resources->format), coded_size.height()); |
629 plane_resource.image_id = gles2->CreateImageCHROMIUM( | 687 plane_resource.image_id = gles2->CreateImageCHROMIUM( |
630 plane_resource.gpu_memory_buffer->AsClientBuffer(), width, height, | 688 plane_resource.gpu_memory_buffer->AsClientBuffer(), width, height, |
631 ImageInternalFormat(output_format_, i)); | 689 ImageInternalFormat(frame_resources->format, i)); |
632 } else if (plane_resource.image_id) { | 690 } else if (plane_resource.image_id) { |
633 gles2->ReleaseTexImage2DCHROMIUM(texture_target, plane_resource.image_id); | 691 gles2->ReleaseTexImage2DCHROMIUM(texture_target, plane_resource.image_id); |
634 } | 692 } |
635 if (plane_resource.image_id) | 693 if (plane_resource.image_id) |
636 gles2->BindTexImage2DCHROMIUM(texture_target, plane_resource.image_id); | 694 gles2->BindTexImage2DCHROMIUM(texture_target, plane_resource.image_id); |
637 mailbox_holders[i] = gpu::MailboxHolder(plane_resource.mailbox, | 695 mailbox_holders[i] = gpu::MailboxHolder(plane_resource.mailbox, |
638 gpu::SyncToken(), texture_target); | 696 gpu::SyncToken(), texture_target); |
639 } | 697 } |
640 | 698 |
641 // Insert a sync_token, this is needed to make sure that the textures the | 699 // Insert a sync_token, this is needed to make sure that the textures the |
642 // mailboxes refer to will be used only after all the previous commands posted | 700 // mailboxes refer to will be used only after all the previous commands posted |
643 // in the command buffer have been processed. | 701 // in the command buffer have been processed. |
644 const GLuint64 fence_sync = gles2->InsertFenceSyncCHROMIUM(); | 702 const GLuint64 fence_sync = gles2->InsertFenceSyncCHROMIUM(); |
645 gles2->OrderingBarrierCHROMIUM(); | 703 gles2->OrderingBarrierCHROMIUM(); |
646 | 704 |
647 gpu::SyncToken sync_token; | 705 gpu::SyncToken sync_token; |
648 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 706 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
649 for (size_t i = 0; i < NumGpuMemoryBuffers(output_format_); i++) | 707 for (size_t i = 0; i < NumGpuMemoryBuffers(frame_resources->format); i++) |
650 mailbox_holders[i].sync_token = sync_token; | 708 mailbox_holders[i].sync_token = sync_token; |
651 | 709 |
652 auto release_mailbox_callback = BindToCurrentLoop( | 710 auto release_mailbox_callback = BindToCurrentLoop( |
653 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources)); | 711 base::Bind(&PoolImpl::MailboxHoldersReleased, this, frame_resources)); |
654 | 712 |
655 VideoPixelFormat frame_format = FinalVideoFormat(output_format_); | 713 VideoPixelFormat frame_format = FinalVideoFormat(frame_resources->format); |
656 | 714 |
657 // Create the VideoFrame backed by native textures. | 715 // Create the VideoFrame backed by native textures. |
658 gfx::Size visible_size = video_frame->visible_rect().size(); | 716 gfx::Size visible_size = video_frame->visible_rect().size(); |
659 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures( | 717 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTextures( |
660 frame_format, mailbox_holders, release_mailbox_callback, coded_size, | 718 frame_format, mailbox_holders, release_mailbox_callback, coded_size, |
661 gfx::Rect(visible_size), video_frame->natural_size(), | 719 gfx::Rect(visible_size), video_frame->natural_size(), |
662 video_frame->timestamp()); | 720 video_frame->timestamp()); |
663 | 721 |
664 if (!frame) { | 722 if (!frame) { |
665 release_mailbox_callback.Run(gpu::SyncToken()); | 723 release_mailbox_callback.Run(gpu::SyncToken()); |
666 frame_ready_cb.Run(video_frame); | 724 frame_ready_cb.Run(video_frame); |
667 return; | 725 return; |
668 } | 726 } |
669 | 727 |
670 frame->set_color_space(video_frame->ColorSpace()); | 728 frame->set_color_space(video_frame->ColorSpace()); |
671 | 729 |
672 bool allow_overlay = false; | 730 bool allow_overlay = false; |
673 switch (output_format_) { | 731 switch (frame_resources->format) { |
674 case GpuVideoAcceleratorFactories::OutputFormat::I420: | 732 case GpuVideoAcceleratorFactories::OutputFormat::I420: |
675 allow_overlay = | 733 allow_overlay = |
676 video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY); | 734 video_frame->metadata()->IsTrue(VideoFrameMetadata::ALLOW_OVERLAY); |
677 break; | 735 break; |
678 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: | 736 case GpuVideoAcceleratorFactories::OutputFormat::NV12_SINGLE_GMB: |
679 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: | 737 case GpuVideoAcceleratorFactories::OutputFormat::UYVY: |
680 allow_overlay = true; | 738 allow_overlay = true; |
681 break; | 739 break; |
682 default: | 740 default: |
683 break; | 741 break; |
(...skipping 30 matching lines...) Expand all Loading... |
714 // Tries to find the resources in the pool or create them. | 772 // Tries to find the resources in the pool or create them. |
715 // Incompatible resources will be dropped. | 773 // Incompatible resources will be dropped. |
716 GpuMemoryBufferVideoFramePool::PoolImpl::FrameResources* | 774 GpuMemoryBufferVideoFramePool::PoolImpl::FrameResources* |
717 GpuMemoryBufferVideoFramePool::PoolImpl::GetOrCreateFrameResources( | 775 GpuMemoryBufferVideoFramePool::PoolImpl::GetOrCreateFrameResources( |
718 const gfx::Size& size, | 776 const gfx::Size& size, |
719 GpuVideoAcceleratorFactories::OutputFormat format) { | 777 GpuVideoAcceleratorFactories::OutputFormat format) { |
720 auto it = resources_pool_.begin(); | 778 auto it = resources_pool_.begin(); |
721 while (it != resources_pool_.end()) { | 779 while (it != resources_pool_.end()) { |
722 FrameResources* frame_resources = *it; | 780 FrameResources* frame_resources = *it; |
723 if (!frame_resources->IsInUse()) { | 781 if (!frame_resources->IsInUse()) { |
724 if (AreFrameResourcesCompatible(frame_resources, size)) { | 782 if (AreFrameResourcesCompatible(frame_resources, size, format)) { |
725 frame_resources->SetIsInUse(true); | 783 frame_resources->SetIsInUse(true); |
726 return frame_resources; | 784 return frame_resources; |
727 } else { | 785 } else { |
728 resources_pool_.erase(it++); | 786 resources_pool_.erase(it++); |
729 DeleteFrameResources(gpu_factories_, frame_resources); | 787 DeleteFrameResources(gpu_factories_, frame_resources); |
730 delete frame_resources; | 788 delete frame_resources; |
731 } | 789 } |
732 } else { | 790 } else { |
733 it++; | 791 it++; |
734 } | 792 } |
735 } | 793 } |
736 | 794 |
737 // Create the resources. | 795 // Create the resources. |
738 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( | 796 std::unique_ptr<GpuVideoAcceleratorFactories::ScopedGLContextLock> lock( |
739 gpu_factories_->GetGLContextLock()); | 797 gpu_factories_->GetGLContextLock()); |
740 if (!lock) | 798 if (!lock) |
741 return nullptr; | 799 return nullptr; |
742 | 800 |
743 gpu::gles2::GLES2Interface* gles2 = lock->ContextGL(); | 801 gpu::gles2::GLES2Interface* gles2 = lock->ContextGL(); |
744 gles2->ActiveTexture(GL_TEXTURE0); | 802 gles2->ActiveTexture(GL_TEXTURE0); |
745 FrameResources* frame_resources = new FrameResources(size); | 803 FrameResources* frame_resources = new FrameResources(size, format); |
746 resources_pool_.push_back(frame_resources); | 804 resources_pool_.push_back(frame_resources); |
747 for (size_t i = 0; i < NumGpuMemoryBuffers(output_format_); i++) { | 805 for (size_t i = 0; i < NumGpuMemoryBuffers(format); i++) { |
748 PlaneResource& plane_resource = frame_resources->plane_resources[i]; | 806 PlaneResource& plane_resource = frame_resources->plane_resources[i]; |
749 const size_t width = | 807 const size_t width = |
750 VideoFrame::Columns(i, VideoFormat(format), size.width()); | 808 VideoFrame::Columns(i, VideoFormat(format), size.width()); |
751 const size_t height = | 809 const size_t height = |
752 VideoFrame::Rows(i, VideoFormat(format), size.height()); | 810 VideoFrame::Rows(i, VideoFormat(format), size.height()); |
753 plane_resource.size = gfx::Size(width, height); | 811 plane_resource.size = gfx::Size(width, height); |
754 | 812 |
755 const gfx::BufferFormat buffer_format = GpuMemoryBufferFormat(format, i); | 813 const gfx::BufferFormat buffer_format = GpuMemoryBufferFormat(format, i); |
756 plane_resource.gpu_memory_buffer = gpu_factories_->AllocateGpuMemoryBuffer( | 814 plane_resource.gpu_memory_buffer = gpu_factories_->AllocateGpuMemoryBuffer( |
757 plane_resource.size, buffer_format, | 815 plane_resource.size, buffer_format, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 } | 884 } |
827 | 885 |
828 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( | 886 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( |
829 const scoped_refptr<VideoFrame>& video_frame, | 887 const scoped_refptr<VideoFrame>& video_frame, |
830 const FrameReadyCB& frame_ready_cb) { | 888 const FrameReadyCB& frame_ready_cb) { |
831 DCHECK(video_frame); | 889 DCHECK(video_frame); |
832 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); | 890 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); |
833 } | 891 } |
834 | 892 |
835 } // namespace media | 893 } // namespace media |
OLD | NEW |