OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef MEDIA_BASE_VIDEO_FRAME_H_ | 5 #ifndef MEDIA_BASE_VIDEO_FRAME_H_ |
6 #define MEDIA_BASE_VIDEO_FRAME_H_ | 6 #define MEDIA_BASE_VIDEO_FRAME_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 // Wraps packed image data residing in a memory buffer with a VideoFrame. | 146 // Wraps packed image data residing in a memory buffer with a VideoFrame. |
147 // The image data resides in |data| and is assumed to be packed tightly in a | 147 // The image data resides in |data| and is assumed to be packed tightly in a |
148 // buffer of logical dimensions |coded_size| with the appropriate bit depth | 148 // buffer of logical dimensions |coded_size| with the appropriate bit depth |
149 // and plane count as given by |format|. Returns NULL on failure. | 149 // and plane count as given by |format|. Returns NULL on failure. |
150 static scoped_refptr<VideoFrame> WrapExternalData( | 150 static scoped_refptr<VideoFrame> WrapExternalData( |
151 VideoPixelFormat format, | 151 VideoPixelFormat format, |
152 const gfx::Size& coded_size, | 152 const gfx::Size& coded_size, |
153 const gfx::Rect& visible_rect, | 153 const gfx::Rect& visible_rect, |
154 const gfx::Size& natural_size, | 154 const gfx::Size& natural_size, |
155 uint8* data, | 155 uint8_t* data, |
156 size_t data_size, | 156 size_t data_size, |
157 base::TimeDelta timestamp); | 157 base::TimeDelta timestamp); |
158 | 158 |
159 // Same as WrapExternalData() with SharedMemoryHandle and its offset. | 159 // Same as WrapExternalData() with SharedMemoryHandle and its offset. |
160 static scoped_refptr<VideoFrame> WrapExternalSharedMemory( | 160 static scoped_refptr<VideoFrame> WrapExternalSharedMemory( |
161 VideoPixelFormat format, | 161 VideoPixelFormat format, |
162 const gfx::Size& coded_size, | 162 const gfx::Size& coded_size, |
163 const gfx::Rect& visible_rect, | 163 const gfx::Rect& visible_rect, |
164 const gfx::Size& natural_size, | 164 const gfx::Size& natural_size, |
165 uint8* data, | 165 uint8_t* data, |
166 size_t data_size, | 166 size_t data_size, |
167 base::SharedMemoryHandle handle, | 167 base::SharedMemoryHandle handle, |
168 size_t shared_memory_offset, | 168 size_t shared_memory_offset, |
169 base::TimeDelta timestamp); | 169 base::TimeDelta timestamp); |
170 | 170 |
171 // Wraps external YUV data of the given parameters with a VideoFrame. | 171 // Wraps external YUV data of the given parameters with a VideoFrame. |
172 // The returned VideoFrame does not own the data passed in. | 172 // The returned VideoFrame does not own the data passed in. |
173 static scoped_refptr<VideoFrame> WrapExternalYuvData( | 173 static scoped_refptr<VideoFrame> WrapExternalYuvData( |
174 VideoPixelFormat format, | 174 VideoPixelFormat format, |
175 const gfx::Size& coded_size, | 175 const gfx::Size& coded_size, |
176 const gfx::Rect& visible_rect, | 176 const gfx::Rect& visible_rect, |
177 const gfx::Size& natural_size, | 177 const gfx::Size& natural_size, |
178 int32 y_stride, | 178 int32_t y_stride, |
179 int32 u_stride, | 179 int32_t u_stride, |
180 int32 v_stride, | 180 int32_t v_stride, |
181 uint8* y_data, | 181 uint8_t* y_data, |
182 uint8* u_data, | 182 uint8_t* u_data, |
183 uint8* v_data, | 183 uint8_t* v_data, |
184 base::TimeDelta timestamp); | 184 base::TimeDelta timestamp); |
185 | 185 |
186 // Wraps external YUV data with the given parameters with a VideoFrame. | 186 // Wraps external YUV data with the given parameters with a VideoFrame. |
187 // The returned VideoFrame does not own the GpuMemoryBuffers passed in. | 187 // The returned VideoFrame does not own the GpuMemoryBuffers passed in. |
188 static scoped_refptr<VideoFrame> WrapExternalYuvGpuMemoryBuffers( | 188 static scoped_refptr<VideoFrame> WrapExternalYuvGpuMemoryBuffers( |
189 VideoPixelFormat format, | 189 VideoPixelFormat format, |
190 const gfx::Size& coded_size, | 190 const gfx::Size& coded_size, |
191 const gfx::Rect& visible_rect, | 191 const gfx::Rect& visible_rect, |
192 const gfx::Size& natural_size, | 192 const gfx::Size& natural_size, |
193 int32 y_stride, | 193 int32_t y_stride, |
194 int32 u_stride, | 194 int32_t u_stride, |
195 int32 v_stride, | 195 int32_t v_stride, |
196 uint8* y_data, | 196 uint8_t* y_data, |
197 uint8* u_data, | 197 uint8_t* u_data, |
198 uint8* v_data, | 198 uint8_t* v_data, |
199 const gfx::GpuMemoryBufferHandle& y_handle, | 199 const gfx::GpuMemoryBufferHandle& y_handle, |
200 const gfx::GpuMemoryBufferHandle& u_handle, | 200 const gfx::GpuMemoryBufferHandle& u_handle, |
201 const gfx::GpuMemoryBufferHandle& v_handle, | 201 const gfx::GpuMemoryBufferHandle& v_handle, |
202 base::TimeDelta timestamp); | 202 base::TimeDelta timestamp); |
203 | 203 |
204 #if defined(OS_LINUX) | 204 #if defined(OS_LINUX) |
205 // Wraps provided dmabufs | 205 // Wraps provided dmabufs |
206 // (https://www.kernel.org/doc/Documentation/dma-buf-sharing.txt) with a | 206 // (https://www.kernel.org/doc/Documentation/dma-buf-sharing.txt) with a |
207 // VideoFrame. The dmabuf fds are dup()ed on creation, so that the VideoFrame | 207 // VideoFrame. The dmabuf fds are dup()ed on creation, so that the VideoFrame |
208 // retains a reference to them, and are automatically close()d on destruction, | 208 // retains a reference to them, and are automatically close()d on destruction, |
(...skipping 30 matching lines...) Expand all Loading... |
239 // frame->visible_rect(). | 239 // frame->visible_rect(). |
240 static scoped_refptr<VideoFrame> WrapVideoFrame( | 240 static scoped_refptr<VideoFrame> WrapVideoFrame( |
241 const scoped_refptr<VideoFrame>& frame, | 241 const scoped_refptr<VideoFrame>& frame, |
242 const gfx::Rect& visible_rect, | 242 const gfx::Rect& visible_rect, |
243 const gfx::Size& natural_size); | 243 const gfx::Size& natural_size); |
244 | 244 |
245 // Creates a frame which indicates end-of-stream. | 245 // Creates a frame which indicates end-of-stream. |
246 static scoped_refptr<VideoFrame> CreateEOSFrame(); | 246 static scoped_refptr<VideoFrame> CreateEOSFrame(); |
247 | 247 |
248 // Allocates YV12 frame based on |size|, and sets its data to the YUV(y,u,v). | 248 // Allocates YV12 frame based on |size|, and sets its data to the YUV(y,u,v). |
249 static scoped_refptr<VideoFrame> CreateColorFrame( | 249 static scoped_refptr<VideoFrame> CreateColorFrame(const gfx::Size& size, |
250 const gfx::Size& size, | 250 uint8_t y, |
251 uint8 y, uint8 u, uint8 v, | 251 uint8_t u, |
252 base::TimeDelta timestamp); | 252 uint8_t v, |
| 253 base::TimeDelta timestamp); |
253 | 254 |
254 // Allocates YV12 frame based on |size|, and sets its data to the YUV | 255 // Allocates YV12 frame based on |size|, and sets its data to the YUV |
255 // equivalent of RGB(0,0,0). | 256 // equivalent of RGB(0,0,0). |
256 static scoped_refptr<VideoFrame> CreateBlackFrame(const gfx::Size& size); | 257 static scoped_refptr<VideoFrame> CreateBlackFrame(const gfx::Size& size); |
257 | 258 |
258 // Allocates YV12A frame based on |size|, and sets its data to the YUVA | 259 // Allocates YV12A frame based on |size|, and sets its data to the YUVA |
259 // equivalent of RGBA(0,0,0,0). | 260 // equivalent of RGBA(0,0,0,0). |
260 static scoped_refptr<VideoFrame> CreateTransparentFrame( | 261 static scoped_refptr<VideoFrame> CreateTransparentFrame( |
261 const gfx::Size& size); | 262 const gfx::Size& size); |
262 | 263 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 // Returns the number of bytes per row and number of rows for a given plane. | 323 // Returns the number of bytes per row and number of rows for a given plane. |
323 // | 324 // |
324 // As opposed to stride(), row_bytes() refers to the bytes representing | 325 // As opposed to stride(), row_bytes() refers to the bytes representing |
325 // frame data scanlines (coded_size.width() pixels, without stride padding). | 326 // frame data scanlines (coded_size.width() pixels, without stride padding). |
326 int row_bytes(size_t plane) const; | 327 int row_bytes(size_t plane) const; |
327 int rows(size_t plane) const; | 328 int rows(size_t plane) const; |
328 | 329 |
329 // Returns pointer to the buffer for a given plane, if this is an | 330 // Returns pointer to the buffer for a given plane, if this is an |
330 // IsMappable() frame type. The memory is owned by VideoFrame object and must | 331 // IsMappable() frame type. The memory is owned by VideoFrame object and must |
331 // not be freed by the caller. | 332 // not be freed by the caller. |
332 const uint8* data(size_t plane) const; | 333 const uint8_t* data(size_t plane) const; |
333 uint8* data(size_t plane); | 334 uint8_t* data(size_t plane); |
334 | 335 |
335 // Returns pointer to the data in the visible region of the frame, for | 336 // Returns pointer to the data in the visible region of the frame, for |
336 // IsMappable() storage types. The returned pointer is offsetted into the | 337 // IsMappable() storage types. The returned pointer is offsetted into the |
337 // plane buffer specified by visible_rect().origin(). Memory is owned by | 338 // plane buffer specified by visible_rect().origin(). Memory is owned by |
338 // VideoFrame object and must not be freed by the caller. | 339 // VideoFrame object and must not be freed by the caller. |
339 const uint8* visible_data(size_t plane) const; | 340 const uint8_t* visible_data(size_t plane) const; |
340 uint8* visible_data(size_t plane); | 341 uint8_t* visible_data(size_t plane); |
341 | 342 |
342 // Returns a mailbox holder for a given texture. | 343 // Returns a mailbox holder for a given texture. |
343 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the | 344 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the |
344 // mailbox, the caller must wait for the included sync point. | 345 // mailbox, the caller must wait for the included sync point. |
345 const gpu::MailboxHolder& mailbox_holder(size_t texture_index) const; | 346 const gpu::MailboxHolder& mailbox_holder(size_t texture_index) const; |
346 | 347 |
347 // Returns the shared-memory handle, if present | 348 // Returns the shared-memory handle, if present |
348 base::SharedMemoryHandle shared_memory_handle() const; | 349 base::SharedMemoryHandle shared_memory_handle() const; |
349 | 350 |
350 // Returns the offset into the shared memory where the frame data begins. | 351 // Returns the offset into the shared memory where the frame data begins. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 407 |
407 private: | 408 private: |
408 friend class base::RefCountedThreadSafe<VideoFrame>; | 409 friend class base::RefCountedThreadSafe<VideoFrame>; |
409 | 410 |
410 static scoped_refptr<VideoFrame> WrapExternalStorage( | 411 static scoped_refptr<VideoFrame> WrapExternalStorage( |
411 VideoPixelFormat format, | 412 VideoPixelFormat format, |
412 StorageType storage_type, | 413 StorageType storage_type, |
413 const gfx::Size& coded_size, | 414 const gfx::Size& coded_size, |
414 const gfx::Rect& visible_rect, | 415 const gfx::Rect& visible_rect, |
415 const gfx::Size& natural_size, | 416 const gfx::Size& natural_size, |
416 uint8* data, | 417 uint8_t* data, |
417 size_t data_size, | 418 size_t data_size, |
418 base::TimeDelta timestamp, | 419 base::TimeDelta timestamp, |
419 base::SharedMemoryHandle handle, | 420 base::SharedMemoryHandle handle, |
420 size_t data_offset); | 421 size_t data_offset); |
421 | 422 |
422 // Clients must use the static factory/wrapping methods to create a new frame. | 423 // Clients must use the static factory/wrapping methods to create a new frame. |
423 VideoFrame(VideoPixelFormat format, | 424 VideoFrame(VideoPixelFormat format, |
424 StorageType storage_type, | 425 StorageType storage_type, |
425 const gfx::Size& coded_size, | 426 const gfx::Size& coded_size, |
426 const gfx::Rect& visible_rect, | 427 const gfx::Rect& visible_rect, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // boundaries, e.g. for formats with subsampled chroma. | 473 // boundaries, e.g. for formats with subsampled chroma. |
473 const gfx::Rect visible_rect_; | 474 const gfx::Rect visible_rect_; |
474 | 475 |
475 // Width and height of the visible portion of the video frame | 476 // Width and height of the visible portion of the video frame |
476 // (|visible_rect_.size()|) with aspect ratio taken into account. | 477 // (|visible_rect_.size()|) with aspect ratio taken into account. |
477 const gfx::Size natural_size_; | 478 const gfx::Size natural_size_; |
478 | 479 |
479 // Array of strides for each plane, typically greater or equal to the width | 480 // Array of strides for each plane, typically greater or equal to the width |
480 // of the surface divided by the horizontal sampling period. Note that | 481 // of the surface divided by the horizontal sampling period. Note that |
481 // strides can be negative. | 482 // strides can be negative. |
482 int32 strides_[kMaxPlanes]; | 483 int32_t strides_[kMaxPlanes]; |
483 | 484 |
484 // Array of data pointers to each plane. | 485 // Array of data pointers to each plane. |
485 // TODO(mcasas): we don't know on ctor if we own |data_| or not. After | 486 // TODO(mcasas): we don't know on ctor if we own |data_| or not. After |
486 // refactoring VideoFrame, change to scoped_ptr<uint8, AlignedFreeDeleter>. | 487 // refactoring VideoFrame, change to scoped_ptr<uint8_t, AlignedFreeDeleter>. |
487 uint8* data_[kMaxPlanes]; | 488 uint8_t* data_[kMaxPlanes]; |
488 | 489 |
489 // Native texture mailboxes, if this is a IsTexture() frame. | 490 // Native texture mailboxes, if this is a IsTexture() frame. |
490 gpu::MailboxHolder mailbox_holders_[kMaxPlanes]; | 491 gpu::MailboxHolder mailbox_holders_[kMaxPlanes]; |
491 ReleaseMailboxCB mailbox_holders_release_cb_; | 492 ReleaseMailboxCB mailbox_holders_release_cb_; |
492 | 493 |
493 // Shared memory handle and associated offset inside it, if this frame is | 494 // Shared memory handle and associated offset inside it, if this frame is |
494 // a STORAGE_SHMEM one. | 495 // a STORAGE_SHMEM one. |
495 base::SharedMemoryHandle shared_memory_handle_; | 496 base::SharedMemoryHandle shared_memory_handle_; |
496 size_t shared_memory_offset_; | 497 size_t shared_memory_offset_; |
497 | 498 |
(...skipping 18 matching lines...) Expand all Loading... |
516 gpu::SyncToken release_sync_token_; | 517 gpu::SyncToken release_sync_token_; |
517 | 518 |
518 VideoFrameMetadata metadata_; | 519 VideoFrameMetadata metadata_; |
519 | 520 |
520 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 521 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
521 }; | 522 }; |
522 | 523 |
523 } // namespace media | 524 } // namespace media |
524 | 525 |
525 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 526 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |