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" |
11 #include "base/md5.h" | 11 #include "base/md5.h" |
12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "gpu/command_buffer/common/mailbox_holder.h" | |
14 #include "media/base/buffers.h" | 15 #include "media/base/buffers.h" |
15 #include "media/base/video_frame_metadata.h" | 16 #include "media/base/video_frame_metadata.h" |
16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
18 | 19 |
19 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
20 #include <CoreVideo/CVPixelBuffer.h> | 21 #include <CoreVideo/CVPixelBuffer.h> |
21 #include "base/mac/scoped_cftyperef.h" | 22 #include "base/mac/scoped_cftyperef.h" |
22 #endif | 23 #endif |
23 | 24 |
24 namespace gpu { | |
25 struct MailboxHolder; | |
26 } // namespace gpu | |
27 | |
28 namespace media { | 25 namespace media { |
29 | 26 |
30 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { | 27 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { |
31 public: | 28 public: |
32 enum { | 29 enum { |
33 kFrameSizeAlignment = 16, | 30 kFrameSizeAlignment = 16, |
34 kFrameSizePadding = 16, | 31 kFrameSizePadding = 16, |
35 kFrameAddressAlignment = 32 | 32 kFrameAddressAlignment = 32 |
36 }; | 33 }; |
37 | 34 |
(...skipping 24 matching lines...) Expand all Loading... | |
62 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic. | 59 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic. |
63 YV12J = 7, // JPEG color range version of YV12 | 60 YV12J = 7, // JPEG color range version of YV12 |
64 NV12 = 8, // 12bpp 1x1 Y plane followed by an interleaved 2x2 UV plane. | 61 NV12 = 8, // 12bpp 1x1 Y plane followed by an interleaved 2x2 UV plane. |
65 YV24 = 9, // 24bpp YUV planar, no subsampling. | 62 YV24 = 9, // 24bpp YUV planar, no subsampling. |
66 ARGB = 10, // 32bpp ARGB, 1 plane. | 63 ARGB = 10, // 32bpp ARGB, 1 plane. |
67 YV12HD = 11, // Rec709 "HD" color space version of YV12 | 64 YV12HD = 11, // Rec709 "HD" color space version of YV12 |
68 // Please update UMA histogram enumeration when adding new formats here. | 65 // Please update UMA histogram enumeration when adding new formats here. |
69 FORMAT_MAX = YV12HD, // Must always be equal to largest entry logged. | 66 FORMAT_MAX = YV12HD, // Must always be equal to largest entry logged. |
70 }; | 67 }; |
71 | 68 |
69 // Defines the internal format and the number of the textures in the mailbox | |
70 // holders. | |
71 enum TextureFormat { | |
72 TEXTURE_RGBA = 1, // One RGBA texture. | |
DaleCurtis
2015/05/04 16:12:06
Remove =1, =2 ?
Daniele Castagna
2015/05/04 17:59:59
All the other enums in the class seem to explicitl
DaleCurtis
2015/05/04 18:12:54
That's because they're used in UMA calculations.
Daniele Castagna
2015/05/04 20:51:55
Got it.
Done.
| |
73 TEXTURE_YUV_420 = 2, // Three R8 textures one per YUV channel. | |
hubbe
2015/05/04 16:26:31
FYI: In the tab capture pipeline we use RGBA inste
Daniele Castagna
2015/05/04 17:59:59
Got it, we should add another texture format after
hubbe
2015/05/04 18:28:27
If by "draws", you mean "displays on the screen",
| |
74 TEXTURE_FORMAT_MAX = TEXTURE_YUV_420, | |
75 }; | |
mcasas
2015/05/04 16:23:42
I see here that we're creating a second layer of
t
Daniele Castagna
2015/05/04 17:59:59
We thought about the solution you're suggesting to
DaleCurtis
2015/05/04 18:12:54
I don't have a strong preference either way. NATIV
| |
76 | |
72 // Returns the name of a Format as a string. | 77 // Returns the name of a Format as a string. |
73 static std::string FormatToString(Format format); | 78 static std::string FormatToString(Format format); |
74 | 79 |
75 // Creates a new frame in system memory with given parameters. Buffers for | 80 // Creates a new frame in system memory with given parameters. Buffers for |
76 // the frame are allocated but not initialized. | 81 // the frame are allocated but not initialized. |
77 static scoped_refptr<VideoFrame> CreateFrame( | 82 static scoped_refptr<VideoFrame> CreateFrame( |
78 Format format, | 83 Format format, |
79 const gfx::Size& coded_size, | 84 const gfx::Size& coded_size, |
80 const gfx::Rect& visible_rect, | 85 const gfx::Rect& visible_rect, |
81 const gfx::Size& natural_size, | 86 const gfx::Size& natural_size, |
82 base::TimeDelta timestamp); | 87 base::TimeDelta timestamp); |
83 | 88 |
84 // Returns true if |plane| is a valid plane number for the given format. This | 89 // Returns true if |plane| is a valid plane number for the given format. This |
85 // can be used to DCHECK() plane parameters. | 90 // can be used to DCHECK() plane parameters. |
86 static bool IsValidPlane(size_t plane, VideoFrame::Format format); | 91 static bool IsValidPlane(size_t plane, VideoFrame::Format format); |
87 | 92 |
88 // Call prior to CreateFrame to ensure validity of frame configuration. Called | 93 // Call prior to CreateFrame to ensure validity of frame configuration. Called |
89 // automatically by VideoDecoderConfig::IsValidConfig(). | 94 // automatically by VideoDecoderConfig::IsValidConfig(). |
90 // TODO(scherkus): VideoDecoderConfig shouldn't call this method | 95 // TODO(scherkus): VideoDecoderConfig shouldn't call this method |
91 static bool IsValidConfig(Format format, const gfx::Size& coded_size, | 96 static bool IsValidConfig(Format format, |
97 const gfx::Size& coded_size, | |
92 const gfx::Rect& visible_rect, | 98 const gfx::Rect& visible_rect, |
93 const gfx::Size& natural_size); | 99 const gfx::Size& natural_size); |
94 | 100 |
95 // CB to be called on the mailbox backing this frame when the frame is | 101 // CB to be called on the mailbox backing this frame when the frame is |
96 // destroyed. | 102 // destroyed. |
97 typedef base::Callback<void(uint32)> ReleaseMailboxCB; | 103 typedef base::Callback<void(uint32)> ReleaseMailboxCB; |
98 | 104 |
99 // Wraps a native texture of the given parameters with a VideoFrame. The | 105 // Wraps a native texture of the given parameters with a VideoFrame. |
100 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, | 106 // The backing of the VideoFrame is held in the mailbox held by |
101 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the | 107 // |mailbox_holder|, and |mailbox_holder_release_cb| will be called with |
102 // argument when the VideoFrame is to be destroyed. | 108 // a syncpoint as the argument when the VideoFrame is to be destroyed. |
103 // |read_pixels_cb| may be used to do (slow!) readbacks from the | |
104 // texture to main memory. | |
105 static scoped_refptr<VideoFrame> WrapNativeTexture( | 109 static scoped_refptr<VideoFrame> WrapNativeTexture( |
106 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 110 const gpu::MailboxHolder& mailbox_holder, |
107 const ReleaseMailboxCB& mailbox_holder_release_cb, | 111 const ReleaseMailboxCB& mailbox_holder_release_cb, |
108 const gfx::Size& coded_size, | 112 const gfx::Size& coded_size, |
109 const gfx::Rect& visible_rect, | 113 const gfx::Rect& visible_rect, |
110 const gfx::Size& natural_size, | 114 const gfx::Size& natural_size, |
111 base::TimeDelta timestamp, | 115 base::TimeDelta timestamp, |
112 bool allow_overlay); | 116 bool allow_overlay); |
113 | 117 |
118 // Wraps a set of native textures representing YUV data with a VideoFrame. | |
119 // |mailbox_holders_release_cb| will be called with a syncpoint as the | |
120 // argument when the VideoFrame is to be destroyed. | |
121 static scoped_refptr<VideoFrame> WrapYUV420NativeTextures( | |
122 const gpu::MailboxHolder& y_mailbox_holder, | |
123 const gpu::MailboxHolder& u_mailbox_holder, | |
124 const gpu::MailboxHolder& v_mailbox_holder, | |
125 const ReleaseMailboxCB& mailbox_holders_release_cb, | |
126 const gfx::Size& coded_size, | |
127 const gfx::Rect& visible_rect, | |
128 const gfx::Size& natural_size, | |
129 base::TimeDelta timestamp, | |
130 bool allow_overlay); | |
131 | |
114 // Wraps packed image data residing in a memory buffer with a VideoFrame. | 132 // Wraps packed image data residing in a memory buffer with a VideoFrame. |
115 // The image data resides in |data| and is assumed to be packed tightly in a | 133 // The image data resides in |data| and is assumed to be packed tightly in a |
116 // buffer of logical dimensions |coded_size| with the appropriate bit depth | 134 // buffer of logical dimensions |coded_size| with the appropriate bit depth |
117 // and plane count as given by |format|. The shared memory handle of the | 135 // and plane count as given by |format|. The shared memory handle of the |
118 // backing allocation, if present, can be passed in with |handle|. When the | 136 // backing allocation, if present, can be passed in with |handle|. When the |
119 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. | 137 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. |
120 // Returns NULL on failure. | 138 // Returns NULL on failure. |
121 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( | 139 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( |
122 Format format, | 140 Format format, |
123 const gfx::Size& coded_size, | 141 const gfx::Size& coded_size, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 static scoped_refptr<VideoFrame> CreateTransparentFrame( | 228 static scoped_refptr<VideoFrame> CreateTransparentFrame( |
211 const gfx::Size& size); | 229 const gfx::Size& size); |
212 | 230 |
213 #if defined(VIDEO_HOLE) | 231 #if defined(VIDEO_HOLE) |
214 // Allocates a hole frame. | 232 // Allocates a hole frame. |
215 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); | 233 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); |
216 #endif // defined(VIDEO_HOLE) | 234 #endif // defined(VIDEO_HOLE) |
217 | 235 |
218 static size_t NumPlanes(Format format); | 236 static size_t NumPlanes(Format format); |
219 | 237 |
238 static size_t NumTextures(TextureFormat texture_format); | |
mcasas
2015/05/04 16:23:41
Isn't NumTextures() going to be the same as NumPla
Daniele Castagna
2015/05/04 17:59:59
NumPlanes is generally used to determine how data_
| |
239 | |
220 // Returns the required allocation size for a (tightly packed) frame of the | 240 // Returns the required allocation size for a (tightly packed) frame of the |
221 // given coded size and format. | 241 // given coded size and format. |
222 static size_t AllocationSize(Format format, const gfx::Size& coded_size); | 242 static size_t AllocationSize(Format format, const gfx::Size& coded_size); |
223 | 243 |
224 // Returns the plane size (in bytes) for a plane of the given coded size and | 244 // Returns the plane size (in bytes) for a plane of the given coded size and |
225 // format. | 245 // format. |
226 static gfx::Size PlaneSize(Format format, | 246 static gfx::Size PlaneSize(Format format, |
227 size_t plane, | 247 size_t plane, |
228 const gfx::Size& coded_size); | 248 const gfx::Size& coded_size); |
229 | 249 |
(...skipping 16 matching lines...) Expand all Loading... | |
246 // Returns the number of rows for the given plane, format, and height. | 266 // Returns the number of rows for the given plane, format, and height. |
247 // The height may be aligned to format requirements. | 267 // The height may be aligned to format requirements. |
248 static size_t Rows(size_t plane, Format format, int height); | 268 static size_t Rows(size_t plane, Format format, int height); |
249 | 269 |
250 // Returns the number of columns for the given plane, format, and width. | 270 // Returns the number of columns for the given plane, format, and width. |
251 // The width may be aligned to format requirements. | 271 // The width may be aligned to format requirements. |
252 static size_t Columns(size_t plane, Format format, int width); | 272 static size_t Columns(size_t plane, Format format, int width); |
253 | 273 |
254 Format format() const { return format_; } | 274 Format format() const { return format_; } |
255 | 275 |
276 TextureFormat texture_format() const { return texture_format_; } | |
277 | |
256 const gfx::Size& coded_size() const { return coded_size_; } | 278 const gfx::Size& coded_size() const { return coded_size_; } |
257 const gfx::Rect& visible_rect() const { return visible_rect_; } | 279 const gfx::Rect& visible_rect() const { return visible_rect_; } |
258 const gfx::Size& natural_size() const { return natural_size_; } | 280 const gfx::Size& natural_size() const { return natural_size_; } |
259 | 281 |
260 int stride(size_t plane) const; | 282 int stride(size_t plane) const; |
261 | 283 |
262 // Returns the number of bytes per row and number of rows for a given plane. | 284 // Returns the number of bytes per row and number of rows for a given plane. |
263 // | 285 // |
264 // As opposed to stride(), row_bytes() refers to the bytes representing | 286 // As opposed to stride(), row_bytes() refers to the bytes representing |
265 // frame data scanlines (coded_size.width() pixels, without stride padding). | 287 // frame data scanlines (coded_size.width() pixels, without stride padding). |
266 int row_bytes(size_t plane) const; | 288 int row_bytes(size_t plane) const; |
267 int rows(size_t plane) const; | 289 int rows(size_t plane) const; |
268 | 290 |
269 // Returns pointer to the buffer for a given plane. The memory is owned by | 291 // Returns pointer to the buffer for a given plane. The memory is owned by |
270 // VideoFrame object and must not be freed by the caller. | 292 // VideoFrame object and must not be freed by the caller. |
271 const uint8* data(size_t plane) const; | 293 const uint8* data(size_t plane) const; |
272 uint8* data(size_t plane); | 294 uint8* data(size_t plane); |
273 | 295 |
274 // Returns pointer to the data in the visible region of the frame. I.e. the | 296 // Returns pointer to the data in the visible region of the frame. I.e. the |
275 // returned pointer is offsetted into the plane buffer specified by | 297 // returned pointer is offsetted into the plane buffer specified by |
276 // visible_rect().origin(). Memory is owned by VideoFrame object and must not | 298 // visible_rect().origin(). Memory is owned by VideoFrame object and must not |
277 // be freed by the caller. | 299 // be freed by the caller. |
278 const uint8* visible_data(size_t plane) const; | 300 const uint8* visible_data(size_t plane) const; |
279 uint8* visible_data(size_t plane); | 301 uint8* visible_data(size_t plane); |
280 | 302 |
281 // Returns the mailbox holder of the native texture wrapped by this frame. | 303 // Returns a mailbox holder for a given texture. |
282 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the | 304 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the |
283 // mailbox, the caller must wait for the included sync point. | 305 // mailbox, the caller must wait for the included sync point. |
284 const gpu::MailboxHolder* mailbox_holder() const; | 306 const gpu::MailboxHolder& mailbox_holder(size_t texture) const; |
285 | 307 |
286 // Returns the shared-memory handle, if present | 308 // Returns the shared-memory handle, if present |
287 base::SharedMemoryHandle shared_memory_handle() const; | 309 base::SharedMemoryHandle shared_memory_handle() const; |
288 | 310 |
289 // Returns the offset into the shared memory where the frame data begins. | 311 // Returns the offset into the shared memory where the frame data begins. |
290 size_t shared_memory_offset() const; | 312 size_t shared_memory_offset() const; |
291 | 313 |
292 // Returns a dictionary of optional metadata. This contains information | 314 // Returns a dictionary of optional metadata. This contains information |
293 // associated with the frame that downstream clients might use for frame-level | 315 // associated with the frame that downstream clients might use for frame-level |
294 // logging, quality/performance optimizations, signaling, etc. | 316 // logging, quality/performance optimizations, signaling, etc. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 void HashFrameForTesting(base::MD5Context* context); | 364 void HashFrameForTesting(base::MD5Context* context); |
343 | 365 |
344 private: | 366 private: |
345 friend class base::RefCountedThreadSafe<VideoFrame>; | 367 friend class base::RefCountedThreadSafe<VideoFrame>; |
346 | 368 |
347 // Clients must use the static CreateFrame() method to create a new frame. | 369 // Clients must use the static CreateFrame() method to create a new frame. |
348 VideoFrame(Format format, | 370 VideoFrame(Format format, |
349 const gfx::Size& coded_size, | 371 const gfx::Size& coded_size, |
350 const gfx::Rect& visible_rect, | 372 const gfx::Rect& visible_rect, |
351 const gfx::Size& natural_size, | 373 const gfx::Size& natural_size, |
352 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 374 const gpu::MailboxHolder(&mailbox_holders)[kMaxPlanes], |
mcasas
2015/05/04 16:23:41
This is an unexpected change to me. Why
change the
Daniele Castagna
2015/05/04 17:59:59
MailboxHolder contains two integers and a Mailbox.
| |
375 TextureFormat texture_format, | |
353 base::TimeDelta timestamp, | 376 base::TimeDelta timestamp, |
354 bool end_of_stream); | 377 bool end_of_stream); |
355 virtual ~VideoFrame(); | 378 virtual ~VideoFrame(); |
356 | 379 |
357 void AllocateYUV(); | 380 void AllocateYUV(); |
358 | 381 |
359 // Frame format. | 382 // Frame format. |
360 const Format format_; | 383 const Format format_; |
361 | 384 |
385 // Format of the native textures associated with this frame. | |
386 const TextureFormat texture_format_; | |
387 | |
362 // Width and height of the video frame, in pixels. This must include pixel | 388 // Width and height of the video frame, in pixels. This must include pixel |
363 // data for the whole image; i.e. for YUV formats with subsampled chroma | 389 // data for the whole image; i.e. for YUV formats with subsampled chroma |
364 // planes, in the case that the visible portion of the image does not line up | 390 // planes, in the case that the visible portion of the image does not line up |
365 // on a sample boundary, |coded_size_| must be rounded up appropriately and | 391 // on a sample boundary, |coded_size_| must be rounded up appropriately and |
366 // the pixel data provided for the odd pixels. | 392 // the pixel data provided for the odd pixels. |
367 const gfx::Size coded_size_; | 393 const gfx::Size coded_size_; |
368 | 394 |
369 // Width, height, and offsets of the visible portion of the video frame. Must | 395 // Width, height, and offsets of the visible portion of the video frame. Must |
370 // be a subrect of |coded_size_|. Can be odd with respect to the sample | 396 // be a subrect of |coded_size_|. Can be odd with respect to the sample |
371 // boundaries, e.g. for formats with subsampled chroma. | 397 // boundaries, e.g. for formats with subsampled chroma. |
372 const gfx::Rect visible_rect_; | 398 const gfx::Rect visible_rect_; |
373 | 399 |
374 // Width and height of the visible portion of the video frame | 400 // Width and height of the visible portion of the video frame |
375 // (|visible_rect_.size()|) with aspect ratio taken into account. | 401 // (|visible_rect_.size()|) with aspect ratio taken into account. |
376 const gfx::Size natural_size_; | 402 const gfx::Size natural_size_; |
377 | 403 |
378 // Array of strides for each plane, typically greater or equal to the width | 404 // Array of strides for each plane, typically greater or equal to the width |
379 // of the surface divided by the horizontal sampling period. Note that | 405 // of the surface divided by the horizontal sampling period. Note that |
380 // strides can be negative. | 406 // strides can be negative. |
381 int32 strides_[kMaxPlanes]; | 407 int32 strides_[kMaxPlanes]; |
382 | 408 |
383 // Array of data pointers to each plane. | 409 // Array of data pointers to each plane. |
384 uint8* data_[kMaxPlanes]; | 410 uint8* data_[kMaxPlanes]; |
385 | 411 |
386 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. | 412 // Native texture mailboxes, if this is a NATIVE_TEXTURE frame. |
387 const scoped_ptr<gpu::MailboxHolder> mailbox_holder_; | 413 gpu::MailboxHolder mailbox_holders_[kMaxPlanes]; |
388 ReleaseMailboxCB mailbox_holder_release_cb_; | 414 ReleaseMailboxCB mailbox_holders_release_cb_; |
389 | 415 |
390 // Shared memory handle, if this frame was allocated from shared memory. | 416 // Shared memory handle, if this frame was allocated from shared memory. |
391 base::SharedMemoryHandle shared_memory_handle_; | 417 base::SharedMemoryHandle shared_memory_handle_; |
392 | 418 |
393 // Offset in shared memory buffer. | 419 // Offset in shared memory buffer. |
394 size_t shared_memory_offset_; | 420 size_t shared_memory_offset_; |
395 | 421 |
396 #if defined(OS_POSIX) | 422 #if defined(OS_POSIX) |
397 // Dmabufs for each plane, if this frame is wrapping memory | 423 // Dmabufs for each plane, if this frame is wrapping memory |
398 // acquired via dmabuf. | 424 // acquired via dmabuf. |
(...skipping 17 matching lines...) Expand all Loading... | |
416 VideoFrameMetadata metadata_; | 442 VideoFrameMetadata metadata_; |
417 | 443 |
418 bool allow_overlay_; | 444 bool allow_overlay_; |
419 | 445 |
420 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 446 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
421 }; | 447 }; |
422 | 448 |
423 } // namespace media | 449 } // namespace media |
424 | 450 |
425 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 451 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |