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

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: Address reveman's comments. 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
« no previous file with comments | « content/renderer/media/video_capture_impl.cc ('k') | media/base/video_frame.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 internal format and the number of the textures in the mailbox
70 // holders.
71 enum TextureFormat {
Pawel Osciak 2015/05/06 02:14:29 Would it perhaps be possible to use an existing se
Daniele Castagna 2015/05/06 18:50:24 I'm afraid the existing defines/enums are not a go
72 TEXTURE_RGBA, // One RGBA texture.
73 TEXTURE_YUV_420, // 3 RED textures one per channel. UV are 2x2 subsampled.
74 };
75
72 // Returns the name of a Format as a string. 76 // Returns the name of a Format as a string.
73 static std::string FormatToString(Format format); 77 static std::string FormatToString(Format format);
74 78
75 // Creates a new frame in system memory with given parameters. Buffers for 79 // Creates a new frame in system memory with given parameters. Buffers for
76 // the frame are allocated but not initialized. 80 // the frame are allocated but not initialized.
77 static scoped_refptr<VideoFrame> CreateFrame( 81 static scoped_refptr<VideoFrame> CreateFrame(
78 Format format, 82 Format format,
79 const gfx::Size& coded_size, 83 const gfx::Size& coded_size,
80 const gfx::Rect& visible_rect, 84 const gfx::Rect& visible_rect,
81 const gfx::Size& natural_size, 85 const gfx::Size& natural_size,
82 base::TimeDelta timestamp); 86 base::TimeDelta timestamp);
83 87
84 // Returns true if |plane| is a valid plane number for the given format. This 88 // Returns true if |plane| is a valid plane number for the given format. This
85 // can be used to DCHECK() plane parameters. 89 // can be used to DCHECK() plane parameters.
86 static bool IsValidPlane(size_t plane, VideoFrame::Format format); 90 static bool IsValidPlane(size_t plane, VideoFrame::Format format);
87 91
88 // Call prior to CreateFrame to ensure validity of frame configuration. Called 92 // Call prior to CreateFrame to ensure validity of frame configuration. Called
89 // automatically by VideoDecoderConfig::IsValidConfig(). 93 // automatically by VideoDecoderConfig::IsValidConfig().
90 // TODO(scherkus): VideoDecoderConfig shouldn't call this method 94 // TODO(scherkus): VideoDecoderConfig shouldn't call this method
91 static bool IsValidConfig(Format format, const gfx::Size& coded_size, 95 static bool IsValidConfig(Format format,
96 const gfx::Size& coded_size,
92 const gfx::Rect& visible_rect, 97 const gfx::Rect& visible_rect,
93 const gfx::Size& natural_size); 98 const gfx::Size& natural_size);
94 99
95 // CB to be called on the mailbox backing this frame when the frame is 100 // CB to be called on the mailbox backing this frame when the frame is
96 // destroyed. 101 // destroyed.
97 typedef base::Callback<void(uint32)> ReleaseMailboxCB; 102 typedef base::Callback<void(uint32)> ReleaseMailboxCB;
98 103
99 // Wraps a native texture of the given parameters with a VideoFrame. The 104 // 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|, 105 // 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 106 // |mailbox_holder|, and |mailbox_holder_release_cb| will be called with
102 // argument when the VideoFrame is to be destroyed. 107 // 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( 108 static scoped_refptr<VideoFrame> WrapNativeTexture(
106 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 109 const gpu::MailboxHolder& mailbox_holder,
107 const ReleaseMailboxCB& mailbox_holder_release_cb, 110 const ReleaseMailboxCB& mailbox_holder_release_cb,
108 const gfx::Size& coded_size, 111 const gfx::Size& coded_size,
109 const gfx::Rect& visible_rect, 112 const gfx::Rect& visible_rect,
110 const gfx::Size& natural_size, 113 const gfx::Size& natural_size,
111 base::TimeDelta timestamp, 114 base::TimeDelta timestamp,
112 bool allow_overlay); 115 bool allow_overlay);
113 116
117 // Wraps a set of native textures representing YUV data with a VideoFrame.
118 // |mailbox_holders_release_cb| will be called with a syncpoint as the
119 // argument when the VideoFrame is to be destroyed.
120 static scoped_refptr<VideoFrame> WrapYUV420NativeTextures(
121 const gpu::MailboxHolder& y_mailbox_holder,
122 const gpu::MailboxHolder& u_mailbox_holder,
123 const gpu::MailboxHolder& v_mailbox_holder,
124 const ReleaseMailboxCB& mailbox_holders_release_cb,
125 const gfx::Size& coded_size,
126 const gfx::Rect& visible_rect,
127 const gfx::Size& natural_size,
128 base::TimeDelta timestamp,
129 bool allow_overlay);
130
114 // Wraps packed image data residing in a memory buffer with a VideoFrame. 131 // 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 132 // 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 133 // 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 134 // 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 135 // backing allocation, if present, can be passed in with |handle|. When the
119 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. 136 // frame is destroyed, |no_longer_needed_cb.Run()| will be called.
120 // Returns NULL on failure. 137 // Returns NULL on failure.
121 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( 138 static scoped_refptr<VideoFrame> WrapExternalPackedMemory(
122 Format format, 139 Format format,
123 const gfx::Size& coded_size, 140 const gfx::Size& coded_size,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 static scoped_refptr<VideoFrame> CreateTransparentFrame( 227 static scoped_refptr<VideoFrame> CreateTransparentFrame(
211 const gfx::Size& size); 228 const gfx::Size& size);
212 229
213 #if defined(VIDEO_HOLE) 230 #if defined(VIDEO_HOLE)
214 // Allocates a hole frame. 231 // Allocates a hole frame.
215 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); 232 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size);
216 #endif // defined(VIDEO_HOLE) 233 #endif // defined(VIDEO_HOLE)
217 234
218 static size_t NumPlanes(Format format); 235 static size_t NumPlanes(Format format);
219 236
237 static size_t NumTextures(TextureFormat texture_format);
238
220 // Returns the required allocation size for a (tightly packed) frame of the 239 // Returns the required allocation size for a (tightly packed) frame of the
221 // given coded size and format. 240 // given coded size and format.
222 static size_t AllocationSize(Format format, const gfx::Size& coded_size); 241 static size_t AllocationSize(Format format, const gfx::Size& coded_size);
223 242
224 // Returns the plane size (in bytes) for a plane of the given coded size and 243 // Returns the plane size (in bytes) for a plane of the given coded size and
225 // format. 244 // format.
226 static gfx::Size PlaneSize(Format format, 245 static gfx::Size PlaneSize(Format format,
227 size_t plane, 246 size_t plane,
228 const gfx::Size& coded_size); 247 const gfx::Size& coded_size);
229 248
(...skipping 16 matching lines...) Expand all
246 // Returns the number of rows for the given plane, format, and height. 265 // Returns the number of rows for the given plane, format, and height.
247 // The height may be aligned to format requirements. 266 // The height may be aligned to format requirements.
248 static size_t Rows(size_t plane, Format format, int height); 267 static size_t Rows(size_t plane, Format format, int height);
249 268
250 // Returns the number of columns for the given plane, format, and width. 269 // Returns the number of columns for the given plane, format, and width.
251 // The width may be aligned to format requirements. 270 // The width may be aligned to format requirements.
252 static size_t Columns(size_t plane, Format format, int width); 271 static size_t Columns(size_t plane, Format format, int width);
253 272
254 Format format() const { return format_; } 273 Format format() const { return format_; }
255 274
275 TextureFormat texture_format() const { return texture_format_; }
276
256 const gfx::Size& coded_size() const { return coded_size_; } 277 const gfx::Size& coded_size() const { return coded_size_; }
257 const gfx::Rect& visible_rect() const { return visible_rect_; } 278 const gfx::Rect& visible_rect() const { return visible_rect_; }
258 const gfx::Size& natural_size() const { return natural_size_; } 279 const gfx::Size& natural_size() const { return natural_size_; }
259 280
260 int stride(size_t plane) const; 281 int stride(size_t plane) const;
261 282
262 // Returns the number of bytes per row and number of rows for a given plane. 283 // Returns the number of bytes per row and number of rows for a given plane.
263 // 284 //
264 // As opposed to stride(), row_bytes() refers to the bytes representing 285 // As opposed to stride(), row_bytes() refers to the bytes representing
265 // frame data scanlines (coded_size.width() pixels, without stride padding). 286 // frame data scanlines (coded_size.width() pixels, without stride padding).
266 int row_bytes(size_t plane) const; 287 int row_bytes(size_t plane) const;
267 int rows(size_t plane) const; 288 int rows(size_t plane) const;
268 289
269 // Returns pointer to the buffer for a given plane. The memory is owned by 290 // 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. 291 // VideoFrame object and must not be freed by the caller.
271 const uint8* data(size_t plane) const; 292 const uint8* data(size_t plane) const;
272 uint8* data(size_t plane); 293 uint8* data(size_t plane);
273 294
274 // Returns pointer to the data in the visible region of the frame. I.e. the 295 // 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 296 // returned pointer is offsetted into the plane buffer specified by
276 // visible_rect().origin(). Memory is owned by VideoFrame object and must not 297 // visible_rect().origin(). Memory is owned by VideoFrame object and must not
277 // be freed by the caller. 298 // be freed by the caller.
278 const uint8* visible_data(size_t plane) const; 299 const uint8* visible_data(size_t plane) const;
279 uint8* visible_data(size_t plane); 300 uint8* visible_data(size_t plane);
280 301
281 // Returns the mailbox holder of the native texture wrapped by this frame. 302 // Returns a mailbox holder for a given texture.
282 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the 303 // 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. 304 // mailbox, the caller must wait for the included sync point.
284 const gpu::MailboxHolder* mailbox_holder() const; 305 const gpu::MailboxHolder& mailbox_holder(size_t texture) const;
285 306
286 // Returns the shared-memory handle, if present 307 // Returns the shared-memory handle, if present
287 base::SharedMemoryHandle shared_memory_handle() const; 308 base::SharedMemoryHandle shared_memory_handle() const;
288 309
289 // Returns the offset into the shared memory where the frame data begins. 310 // Returns the offset into the shared memory where the frame data begins.
290 size_t shared_memory_offset() const; 311 size_t shared_memory_offset() const;
291 312
292 // Returns a dictionary of optional metadata. This contains information 313 // Returns a dictionary of optional metadata. This contains information
293 // associated with the frame that downstream clients might use for frame-level 314 // associated with the frame that downstream clients might use for frame-level
294 // logging, quality/performance optimizations, signaling, etc. 315 // logging, quality/performance optimizations, signaling, etc.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 void HashFrameForTesting(base::MD5Context* context); 363 void HashFrameForTesting(base::MD5Context* context);
343 364
344 private: 365 private:
345 friend class base::RefCountedThreadSafe<VideoFrame>; 366 friend class base::RefCountedThreadSafe<VideoFrame>;
346 367
347 // Clients must use the static CreateFrame() method to create a new frame. 368 // Clients must use the static CreateFrame() method to create a new frame.
348 VideoFrame(Format format, 369 VideoFrame(Format format,
349 const gfx::Size& coded_size, 370 const gfx::Size& coded_size,
350 const gfx::Rect& visible_rect, 371 const gfx::Rect& visible_rect,
351 const gfx::Size& natural_size, 372 const gfx::Size& natural_size,
352 scoped_ptr<gpu::MailboxHolder> mailbox_holder, 373 const gpu::MailboxHolder(&mailbox_holders)[kMaxPlanes],
374 TextureFormat texture_format,
353 base::TimeDelta timestamp, 375 base::TimeDelta timestamp,
354 bool end_of_stream); 376 bool end_of_stream);
355 virtual ~VideoFrame(); 377 virtual ~VideoFrame();
356 378
357 void AllocateYUV(); 379 void AllocateYUV();
358 380
359 // Frame format. 381 // Frame format.
360 const Format format_; 382 const Format format_;
361 383
384 // Format of the native textures associated with this frame.
385 const TextureFormat texture_format_;
386
362 // Width and height of the video frame, in pixels. This must include pixel 387 // 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 388 // 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 389 // 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 390 // on a sample boundary, |coded_size_| must be rounded up appropriately and
366 // the pixel data provided for the odd pixels. 391 // the pixel data provided for the odd pixels.
367 const gfx::Size coded_size_; 392 const gfx::Size coded_size_;
368 393
369 // Width, height, and offsets of the visible portion of the video frame. Must 394 // 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 395 // be a subrect of |coded_size_|. Can be odd with respect to the sample
371 // boundaries, e.g. for formats with subsampled chroma. 396 // boundaries, e.g. for formats with subsampled chroma.
372 const gfx::Rect visible_rect_; 397 const gfx::Rect visible_rect_;
373 398
374 // Width and height of the visible portion of the video frame 399 // Width and height of the visible portion of the video frame
375 // (|visible_rect_.size()|) with aspect ratio taken into account. 400 // (|visible_rect_.size()|) with aspect ratio taken into account.
376 const gfx::Size natural_size_; 401 const gfx::Size natural_size_;
377 402
378 // Array of strides for each plane, typically greater or equal to the width 403 // 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 404 // of the surface divided by the horizontal sampling period. Note that
380 // strides can be negative. 405 // strides can be negative.
381 int32 strides_[kMaxPlanes]; 406 int32 strides_[kMaxPlanes];
382 407
383 // Array of data pointers to each plane. 408 // Array of data pointers to each plane.
384 uint8* data_[kMaxPlanes]; 409 uint8* data_[kMaxPlanes];
385 410
386 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. 411 // Native texture mailboxes, if this is a NATIVE_TEXTURE frame.
387 const scoped_ptr<gpu::MailboxHolder> mailbox_holder_; 412 gpu::MailboxHolder mailbox_holders_[kMaxPlanes];
piman 2015/05/06 01:08:09 drive-by: FYI, gpu::Mailbox is 64 bytes, so Mailbo
Daniele Castagna 2015/05/06 01:29:19 I think it's fine. We don't have many VideoFrames
388 ReleaseMailboxCB mailbox_holder_release_cb_; 413 ReleaseMailboxCB mailbox_holders_release_cb_;
389 414
390 // Shared memory handle, if this frame was allocated from shared memory. 415 // Shared memory handle, if this frame was allocated from shared memory.
391 base::SharedMemoryHandle shared_memory_handle_; 416 base::SharedMemoryHandle shared_memory_handle_;
392 417
393 // Offset in shared memory buffer. 418 // Offset in shared memory buffer.
394 size_t shared_memory_offset_; 419 size_t shared_memory_offset_;
395 420
396 #if defined(OS_POSIX) 421 #if defined(OS_POSIX)
397 // Dmabufs for each plane, if this frame is wrapping memory 422 // Dmabufs for each plane, if this frame is wrapping memory
398 // acquired via dmabuf. 423 // acquired via dmabuf.
(...skipping 17 matching lines...) Expand all
416 VideoFrameMetadata metadata_; 441 VideoFrameMetadata metadata_;
417 442
418 bool allow_overlay_; 443 bool allow_overlay_;
419 444
420 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); 445 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);
421 }; 446 };
422 447
423 } // namespace media 448 } // namespace media
424 449
425 #endif // MEDIA_BASE_VIDEO_FRAME_H_ 450 #endif // MEDIA_BASE_VIDEO_FRAME_H_
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.cc ('k') | media/base/video_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698