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

Side by Side Diff: media/base/video_frame.h

Issue 1117423002: media: Let VideoFrame carry more than one native texture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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) 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
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 number and the pixel format of the textures in the mailbox
70 // holders.
reveman 2015/05/03 16:13:27 hm, this defines the subsampling factor and intern
Daniele Castagna 2015/05/04 15:00:15 Changed the comment.
71 enum TextureFormat {
72 TEXTURE_NONE = 0, // This frame doesn't contain any native texture.
reveman 2015/05/03 16:13:27 I think the code would be cleaner if this enum con
Daniele Castagna 2015/05/04 15:00:15 Done.
DaleCurtis 2015/05/04 16:00:14 Hmm, I think that's fine so long as we still initi
73 TEXTURE_RGBA = 1, // One RGBA texture.
DaleCurtis 2015/05/02 18:21:33 Doesn't android use ARGB or something?
reveman 2015/05/03 16:13:27 I think the idea is that this just describes the i
Daniele Castagna 2015/05/04 15:00:15 Agreed.
74 TEXTURE_YUV_R8R8R8 = 2, // Three R8 textures one per YUV channel.
reveman 2015/05/03 16:13:27 s/YUV_R8R8R8/YUV_420/ as that would make it clear
Daniele Castagna 2015/05/04 15:00:15 Done.
75 TEXTURE_FORMAT_MAX = TEXTURE_YUV_R8R8R8,
76 };
77
72 // Returns the name of a Format as a string. 78 // Returns the name of a Format as a string.
73 static std::string FormatToString(Format format); 79 static std::string FormatToString(Format format);
74 80
75 // Creates a new frame in system memory with given parameters. Buffers for 81 // Creates a new frame in system memory with given parameters. Buffers for
76 // the frame are allocated but not initialized. 82 // the frame are allocated but not initialized.
77 static scoped_refptr<VideoFrame> CreateFrame( 83 static scoped_refptr<VideoFrame> CreateFrame(
78 Format format, 84 Format format,
79 const gfx::Size& coded_size, 85 const gfx::Size& coded_size,
80 const gfx::Rect& visible_rect, 86 const gfx::Rect& visible_rect,
81 const gfx::Size& natural_size, 87 const gfx::Size& natural_size,
82 base::TimeDelta timestamp); 88 base::TimeDelta timestamp);
83 89
84 // Returns true if |plane| is a valid plane number for the given format. This 90 // Returns true if |plane| is a valid plane number for the given format. This
85 // can be used to DCHECK() plane parameters. 91 // can be used to DCHECK() plane parameters.
86 static bool IsValidPlane(size_t plane, VideoFrame::Format format); 92 static bool IsValidPlane(size_t plane, VideoFrame::Format format);
87 93
88 // Call prior to CreateFrame to ensure validity of frame configuration. Called 94 // Call prior to CreateFrame to ensure validity of frame configuration. Called
89 // automatically by VideoDecoderConfig::IsValidConfig(). 95 // automatically by VideoDecoderConfig::IsValidConfig().
90 // TODO(scherkus): VideoDecoderConfig shouldn't call this method 96 // TODO(scherkus): VideoDecoderConfig shouldn't call this method
91 static bool IsValidConfig(Format format, const gfx::Size& coded_size, 97 static bool IsValidConfig(Format format,
98 TextureFormat texture_format,
99 const gfx::Size& coded_size,
92 const gfx::Rect& visible_rect, 100 const gfx::Rect& visible_rect,
93 const gfx::Size& natural_size); 101 const gfx::Size& natural_size);
94 102
95 // CB to be called on the mailbox backing this frame when the frame is 103 // CB to be called on the mailbox backing this frame when the frame is
96 // destroyed. 104 // destroyed.
97 typedef base::Callback<void(uint32)> ReleaseMailboxCB; 105 typedef base::Callback<void(uint32)> ReleaseMailboxCB;
98 106
99 // Wraps a native texture of the given parameters with a VideoFrame. The 107 // 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|, 108 // 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 109 // |mailbox_holder|, and |mailbox_holder_release_cb| will be called with
102 // argument when the VideoFrame is to be destroyed. 110 // 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( 111 static scoped_refptr<VideoFrame> WrapNativeTexture(
106 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 112 const gpu::MailboxHolder& mailbox_holder,
107 const ReleaseMailboxCB& mailbox_holder_release_cb, 113 const ReleaseMailboxCB& mailbox_holder_release_cb,
108 const gfx::Size& coded_size, 114 const gfx::Size& coded_size,
109 const gfx::Rect& visible_rect, 115 const gfx::Rect& visible_rect,
110 const gfx::Size& natural_size, 116 const gfx::Size& natural_size,
111 base::TimeDelta timestamp, 117 base::TimeDelta timestamp,
112 bool allow_overlay); 118 bool allow_overlay);
113 119
120 // Wraps a set of native textures representing YUV data with a VideoFrame.
121 // |mailbox_holders_release_cb| will be called with a syncpoint as the
122 // argument when the VideoFrame is to be destroyed.
123 static scoped_refptr<VideoFrame> WrapYUVNativeTextures(
reveman 2015/05/03 16:13:27 WrapYUV420NativeTextures? Or pass the texture form
Daniele Castagna 2015/05/04 15:00:15 Renamed to WrapYUV420NativeTextures. I decided not
124 const gpu::MailboxHolder& y_mailbox_holder,
125 const gpu::MailboxHolder& u_mailbox_holder,
126 const gpu::MailboxHolder& v_mailbox_holder,
127 const ReleaseMailboxCB& mailbox_holders_release_cb,
128 const gfx::Size& coded_size,
129 const gfx::Rect& visible_rect,
130 const gfx::Size& natural_size,
131 base::TimeDelta timestamp,
132 bool allow_overlay);
133
114 // Wraps packed image data residing in a memory buffer with a VideoFrame. 134 // 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 135 // 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 136 // 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 137 // 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 138 // backing allocation, if present, can be passed in with |handle|. When the
119 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. 139 // frame is destroyed, |no_longer_needed_cb.Run()| will be called.
120 // Returns NULL on failure. 140 // Returns NULL on failure.
121 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( 141 static scoped_refptr<VideoFrame> WrapExternalPackedMemory(
122 Format format, 142 Format format,
123 const gfx::Size& coded_size, 143 const gfx::Size& coded_size,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 static scoped_refptr<VideoFrame> CreateTransparentFrame( 230 static scoped_refptr<VideoFrame> CreateTransparentFrame(
211 const gfx::Size& size); 231 const gfx::Size& size);
212 232
213 #if defined(VIDEO_HOLE) 233 #if defined(VIDEO_HOLE)
214 // Allocates a hole frame. 234 // Allocates a hole frame.
215 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); 235 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size);
216 #endif // defined(VIDEO_HOLE) 236 #endif // defined(VIDEO_HOLE)
217 237
218 static size_t NumPlanes(Format format); 238 static size_t NumPlanes(Format format);
219 239
240 static size_t NumTextures(TextureFormat texture_format);
241
220 // Returns the required allocation size for a (tightly packed) frame of the 242 // Returns the required allocation size for a (tightly packed) frame of the
221 // given coded size and format. 243 // given coded size and format.
222 static size_t AllocationSize(Format format, const gfx::Size& coded_size); 244 static size_t AllocationSize(Format format, const gfx::Size& coded_size);
223 245
224 // Returns the plane size (in bytes) for a plane of the given coded size and 246 // Returns the plane size (in bytes) for a plane of the given coded size and
225 // format. 247 // format.
226 static gfx::Size PlaneSize(Format format, 248 static gfx::Size PlaneSize(Format format,
227 size_t plane, 249 size_t plane,
228 const gfx::Size& coded_size); 250 const gfx::Size& coded_size);
229 251
(...skipping 16 matching lines...) Expand all
246 // Returns the number of rows for the given plane, format, and height. 268 // Returns the number of rows for the given plane, format, and height.
247 // The height may be aligned to format requirements. 269 // The height may be aligned to format requirements.
248 static size_t Rows(size_t plane, Format format, int height); 270 static size_t Rows(size_t plane, Format format, int height);
249 271
250 // Returns the number of columns for the given plane, format, and width. 272 // Returns the number of columns for the given plane, format, and width.
251 // The width may be aligned to format requirements. 273 // The width may be aligned to format requirements.
252 static size_t Columns(size_t plane, Format format, int width); 274 static size_t Columns(size_t plane, Format format, int width);
253 275
254 Format format() const { return format_; } 276 Format format() const { return format_; }
255 277
278 TextureFormat texture_format() const { return texture_format_; }
279
256 const gfx::Size& coded_size() const { return coded_size_; } 280 const gfx::Size& coded_size() const { return coded_size_; }
257 const gfx::Rect& visible_rect() const { return visible_rect_; } 281 const gfx::Rect& visible_rect() const { return visible_rect_; }
258 const gfx::Size& natural_size() const { return natural_size_; } 282 const gfx::Size& natural_size() const { return natural_size_; }
259 283
260 int stride(size_t plane) const; 284 int stride(size_t plane) const;
261 285
262 // Returns the number of bytes per row and number of rows for a given plane. 286 // Returns the number of bytes per row and number of rows for a given plane.
263 // 287 //
264 // As opposed to stride(), row_bytes() refers to the bytes representing 288 // As opposed to stride(), row_bytes() refers to the bytes representing
265 // frame data scanlines (coded_size.width() pixels, without stride padding). 289 // frame data scanlines (coded_size.width() pixels, without stride padding).
266 int row_bytes(size_t plane) const; 290 int row_bytes(size_t plane) const;
267 int rows(size_t plane) const; 291 int rows(size_t plane) const;
268 292
269 // Returns pointer to the buffer for a given plane. The memory is owned by 293 // 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. 294 // VideoFrame object and must not be freed by the caller.
271 const uint8* data(size_t plane) const; 295 const uint8* data(size_t plane) const;
272 uint8* data(size_t plane); 296 uint8* data(size_t plane);
273 297
274 // Returns pointer to the data in the visible region of the frame. I.e. the 298 // 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 299 // returned pointer is offsetted into the plane buffer specified by
276 // visible_rect().origin(). Memory is owned by VideoFrame object and must not 300 // visible_rect().origin(). Memory is owned by VideoFrame object and must not
277 // be freed by the caller. 301 // be freed by the caller.
278 const uint8* visible_data(size_t plane) const; 302 const uint8* visible_data(size_t plane) const;
279 uint8* visible_data(size_t plane); 303 uint8* visible_data(size_t plane);
280 304
281 // Returns the mailbox holder of the native texture wrapped by this frame. 305 // Returns a mailbox holder for a given texture.
282 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the 306 // 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. 307 // mailbox, the caller must wait for the included sync point.
284 const gpu::MailboxHolder* mailbox_holder() const; 308 const gpu::MailboxHolder& mailbox_holder(size_t texture) const;
285 309
286 // Returns the shared-memory handle, if present 310 // Returns the shared-memory handle, if present
287 base::SharedMemoryHandle shared_memory_handle() const; 311 base::SharedMemoryHandle shared_memory_handle() const;
288 312
289 // Returns the offset into the shared memory where the frame data begins. 313 // Returns the offset into the shared memory where the frame data begins.
290 size_t shared_memory_offset() const; 314 size_t shared_memory_offset() const;
291 315
292 // Returns a dictionary of optional metadata. This contains information 316 // Returns a dictionary of optional metadata. This contains information
293 // associated with the frame that downstream clients might use for frame-level 317 // associated with the frame that downstream clients might use for frame-level
294 // logging, quality/performance optimizations, signaling, etc. 318 // logging, quality/performance optimizations, signaling, etc.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 void HashFrameForTesting(base::MD5Context* context); 366 void HashFrameForTesting(base::MD5Context* context);
343 367
344 private: 368 private:
345 friend class base::RefCountedThreadSafe<VideoFrame>; 369 friend class base::RefCountedThreadSafe<VideoFrame>;
346 370
347 // Clients must use the static CreateFrame() method to create a new frame. 371 // Clients must use the static CreateFrame() method to create a new frame.
348 VideoFrame(Format format, 372 VideoFrame(Format format,
349 const gfx::Size& coded_size, 373 const gfx::Size& coded_size,
350 const gfx::Rect& visible_rect, 374 const gfx::Rect& visible_rect,
351 const gfx::Size& natural_size, 375 const gfx::Size& natural_size,
352 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 376 const gpu::MailboxHolder mailbox_holders[kMaxPlanes],
reveman 2015/05/03 16:13:27 Pass by reference instead of value.
Daniele Castagna 2015/05/04 15:00:15 Done. git cl format seems to be confused by the s
377 TextureFormat texture_format,
353 base::TimeDelta timestamp, 378 base::TimeDelta timestamp,
354 bool end_of_stream); 379 bool end_of_stream);
355 virtual ~VideoFrame(); 380 virtual ~VideoFrame();
356 381
357 void AllocateYUV(); 382 void AllocateYUV();
358 383
359 // Frame format. 384 // Frame format.
360 const Format format_; 385 const Format format_;
361 386
387 // Format of the native textures associated with this frames.
reveman 2015/05/03 16:13:27 nit: s/frames/frame/
Daniele Castagna 2015/05/04 15:00:15 Done.
388 const TextureFormat texture_format_;
389
362 // Width and height of the video frame, in pixels. This must include pixel 390 // 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 391 // 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 392 // 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 393 // on a sample boundary, |coded_size_| must be rounded up appropriately and
366 // the pixel data provided for the odd pixels. 394 // the pixel data provided for the odd pixels.
367 const gfx::Size coded_size_; 395 const gfx::Size coded_size_;
368 396
369 // Width, height, and offsets of the visible portion of the video frame. Must 397 // 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 398 // be a subrect of |coded_size_|. Can be odd with respect to the sample
371 // boundaries, e.g. for formats with subsampled chroma. 399 // boundaries, e.g. for formats with subsampled chroma.
372 const gfx::Rect visible_rect_; 400 const gfx::Rect visible_rect_;
373 401
374 // Width and height of the visible portion of the video frame 402 // Width and height of the visible portion of the video frame
375 // (|visible_rect_.size()|) with aspect ratio taken into account. 403 // (|visible_rect_.size()|) with aspect ratio taken into account.
376 const gfx::Size natural_size_; 404 const gfx::Size natural_size_;
377 405
378 // Array of strides for each plane, typically greater or equal to the width 406 // 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 407 // of the surface divided by the horizontal sampling period. Note that
380 // strides can be negative. 408 // strides can be negative.
381 int32 strides_[kMaxPlanes]; 409 int32 strides_[kMaxPlanes];
382 410
383 // Array of data pointers to each plane. 411 // Array of data pointers to each plane.
384 uint8* data_[kMaxPlanes]; 412 uint8* data_[kMaxPlanes];
385 413
386 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. 414 // Native texture mailboxes, if this is a NATIVE_TEXTURE frame.
387 const scoped_ptr<gpu::MailboxHolder> mailbox_holder_; 415 gpu::MailboxHolder mailbox_holders_[kMaxPlanes];
388 ReleaseMailboxCB mailbox_holder_release_cb_; 416 ReleaseMailboxCB mailbox_holders_release_cb_;
389 417
390 // Shared memory handle, if this frame was allocated from shared memory. 418 // Shared memory handle, if this frame was allocated from shared memory.
391 base::SharedMemoryHandle shared_memory_handle_; 419 base::SharedMemoryHandle shared_memory_handle_;
392 420
393 // Offset in shared memory buffer. 421 // Offset in shared memory buffer.
394 size_t shared_memory_offset_; 422 size_t shared_memory_offset_;
395 423
396 #if defined(OS_POSIX) 424 #if defined(OS_POSIX)
397 // Dmabufs for each plane, if this frame is wrapping memory 425 // Dmabufs for each plane, if this frame is wrapping memory
398 // acquired via dmabuf. 426 // acquired via dmabuf.
(...skipping 17 matching lines...) Expand all
416 VideoFrameMetadata metadata_; 444 VideoFrameMetadata metadata_;
417 445
418 bool allow_overlay_; 446 bool allow_overlay_;
419 447
420 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); 448 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);
421 }; 449 };
422 450
423 } // namespace media 451 } // namespace media
424 452
425 #endif // MEDIA_BASE_VIDEO_FRAME_H_ 453 #endif // MEDIA_BASE_VIDEO_FRAME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698