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

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

Issue 1154153003: Relanding 1143663007: VideoFrame: Separate Pixel Format from Storage Type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added NV12 support in CrOS Created 5 years, 6 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 | « media/base/video_decoder_config.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"
(...skipping 30 matching lines...) Expand all
41 kUVPlane = kUPlane, 41 kUVPlane = kUPlane,
42 kVPlane = 2, 42 kVPlane = 2,
43 kAPlane = 3, 43 kAPlane = 3,
44 }; 44 };
45 45
46 // Pixel formats roughly based on FOURCC labels, see: 46 // Pixel formats roughly based on FOURCC labels, see:
47 // http://www.fourcc.org/rgb.php 47 // http://www.fourcc.org/rgb.php
48 // http://www.fourcc.org/yuv.php 48 // http://www.fourcc.org/yuv.php
49 // Logged to UMA, so never reuse values. Leave gaps if necessary. 49 // Logged to UMA, so never reuse values. Leave gaps if necessary.
50 enum Format { 50 enum Format {
51 UNKNOWN = 0, // Unknown format value. 51 UNKNOWN = 0, // Unknown or unspecified format value.
52 YV12 = 1, // 12bpp YVU planar 1x1 Y, 2x2 VU samples. 52 YV12 = 1, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
53 I420 = 2, // 12bpp YVU planar 1x1 Y, 2x2 UV samples, a.k.a. YU12. 53 I420 = 2, // 12bpp YUV planar 1x1 Y, 2x2 UV samples, a.k.a. YU12.
54 YV16 = 3, // 16bpp YVU planar 1x1 Y, 2x1 VU samples. 54 YV16 = 3, // 16bpp YVU planar 1x1 Y, 2x1 VU samples.
55 YV12A = 4, // 20bpp YUVA planar 1x1 Y, 2x2 VU, 1x1 A samples. 55 YV12A = 4, // 20bpp YUVA planar 1x1 Y, 2x2 VU, 1x1 A samples.
56 YV24 = 5, // 24bpp YUV planar, no subsampling. 56 YV24 = 5, // 24bpp YUV planar, no subsampling.
57 NV12 = 6, // 12bpp 1x1 Y plane followed by an interleaved 2x2 UV plane. 57 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
58 NV12 = 6, // 12bpp with Y plane followed by a 2x2 interleaved UV plane.
59 #endif
58 ARGB = 7, // 32bpp ARGB, 1 plane. 60 ARGB = 7, // 32bpp ARGB, 1 plane.
59 #if defined(VIDEO_HOLE) 61 XRGB = 8, // 24bpp XRGB, 1 plane.
60 HOLE = 8, // Hole frame.
61 #endif
62 NATIVE_TEXTURE = 9, // Native texture. Pixel-format agnostic.
63 // Please update UMA histogram enumeration when adding new formats here. 62 // Please update UMA histogram enumeration when adding new formats here.
64 // Must always be equal to largest entry logged. 63 FORMAT_MAX = XRGB, // Must always be equal to largest entry logged.
65 FORMAT_MAX = NATIVE_TEXTURE,
66 };
67
68 // Defines the internal format and the number of the textures in the mailbox
69 // holders.
70 enum TextureFormat {
71 TEXTURE_RGBA, // One RGBA texture.
72 TEXTURE_RGB, // One RGB texture.
73 TEXTURE_YUV_420, // 3 RED textures one per channel. UV are 2x2 subsampled.
74 }; 64 };
75 65
76 // Color space or color range used for the pixels, in general this is left 66 // Color space or color range used for the pixels, in general this is left
77 // unspecified, meaning SD is assumed. 67 // unspecified, meaning Rec601 (SD) is assumed.
78 enum ColorSpace { 68 enum ColorSpace {
79 COLOR_SPACE_UNSPECIFIED = 0, // In general this is Rec601. 69 COLOR_SPACE_UNSPECIFIED = 0, // In general this is Rec601.
80 COLOR_SPACE_JPEG = 1, // JPEG color range. 70 COLOR_SPACE_JPEG = 1, // JPEG color range.
81 COLOR_SPACE_HD_REC709 = 2, // Rec709 "HD" color space. 71 COLOR_SPACE_HD_REC709 = 2, // Rec709 "HD" color space.
82 COLOR_SPACE_MAX = COLOR_SPACE_HD_REC709, 72 COLOR_SPACE_MAX = COLOR_SPACE_HD_REC709,
83 }; 73 };
84 74
75 // Defines the pixel storage type. STORAGE_{OWNED, UNOWNED}_MEMORY and
76 // STORAGE_SHMEM have in common that are mappable, i.e. can be accessed from
77 // the VideoFrame memory space, whereas the rest, in principle, can't.
78 enum StorageType {
79 STORAGE_UNKNOWN = 0,
80 STORAGE_UNOWNED_MEMORY = 1, // External, non owned data pointers.
81 STORAGE_OWNED_MEMORY = 2, // VideoFrame has allocated its own data buffer.
82 STORAGE_SHMEM = 3, // Pixels are backed by Shared Memory.
83 #if defined(OS_LINUX)
84 STORAGE_DMABUFS = 4, // Each plane is stored into a DmaBuf.
85 #endif
86 #if defined(VIDEO_HOLE)
87 // Opaque storage.
88 STORAGE_HOLE = 5,
89 #endif
90 // Pixels are stored in textures, one per plane, referred by MailboxHolders.
91 STORAGE_TEXTURE = 6,
92 STORAGE_MAX = STORAGE_TEXTURE, // Always equal to the last StorageType.
93 };
94
95 // CB to be called on the mailbox backing this frame when the frame is
96 // destroyed.
97 typedef base::Callback<void(uint32)> ReleaseMailboxCB;
98
85 // Returns the name of a Format as a string. 99 // Returns the name of a Format as a string.
86 static std::string FormatToString(Format format); 100 static std::string FormatToString(Format format);
87 101
88 // Creates a new frame in system memory with given parameters. Buffers for 102 // Returns true if |format| is a YUV non interleaved format.
89 // the frame are allocated but not initialized. 103 static bool IsYuvPlanar(Format format);
104
105 // Returns true if |storage_type| is mappable in the VideoFrame memory space.
106 static bool IsMappable(StorageType storage_type);
107
108 // Returns true if |plane| is a valid plane number for the given format.
109 static bool IsValidPlane(size_t plane, VideoFrame::Format format);
110
111 // Call prior to CreateFrame to ensure validity of frame configuration. Called
112 // automatically by VideoDecoderConfig::IsValidConfig().
113 // TODO(scherkus): VideoDecoderConfig shouldn't call this method
114 static bool IsValidConfig(Format format,
115 StorageType storage_type,
116 const gfx::Size& coded_size,
117 const gfx::Rect& visible_rect,
118 const gfx::Size& natural_size);
119
120 // Creates a new YUV frame in system memory with given parameters (|format|
121 // must be YUV). Buffers for the frame are allocated but not initialized. The
122 // caller most not make assumptions about the actual underlying size(s), but
123 // check the returned VideoFrame instead.
124 // TODO(mcasas): implement the RGB version of this factory method.
90 static scoped_refptr<VideoFrame> CreateFrame( 125 static scoped_refptr<VideoFrame> CreateFrame(
91 Format format, 126 Format format,
92 const gfx::Size& coded_size, 127 const gfx::Size& coded_size,
93 const gfx::Rect& visible_rect, 128 const gfx::Rect& visible_rect,
94 const gfx::Size& natural_size, 129 const gfx::Size& natural_size,
95 base::TimeDelta timestamp); 130 base::TimeDelta timestamp);
96 131
97 // Returns true if |plane| is a valid plane number for the given format. This
98 // can be used to DCHECK() plane parameters.
99 static bool IsValidPlane(size_t plane, VideoFrame::Format format);
100
101 // Call prior to CreateFrame to ensure validity of frame configuration. Called
102 // automatically by VideoDecoderConfig::IsValidConfig().
103 // TODO(scherkus): VideoDecoderConfig shouldn't call this method
104 static bool IsValidConfig(Format format,
105 const gfx::Size& coded_size,
106 const gfx::Rect& visible_rect,
107 const gfx::Size& natural_size);
108
109 // CB to be called on the mailbox backing this frame when the frame is
110 // destroyed.
111 typedef base::Callback<void(uint32)> ReleaseMailboxCB;
112
113 // Wraps a native texture of the given parameters with a VideoFrame. 132 // Wraps a native texture of the given parameters with a VideoFrame.
114 // The backing of the VideoFrame is held in the mailbox held by 133 // The backing of the VideoFrame is held in the mailbox held by
115 // |mailbox_holder|, and |mailbox_holder_release_cb| will be called with 134 // |mailbox_holder|, and |mailbox_holder_release_cb| will be called with
116 // a syncpoint as the argument when the VideoFrame is to be destroyed. 135 // a syncpoint as the argument when the VideoFrame is to be destroyed.
117 static scoped_refptr<VideoFrame> WrapNativeTexture( 136 static scoped_refptr<VideoFrame> WrapNativeTexture(
118 const gpu::MailboxHolder& mailbox_holder, 137 const gpu::MailboxHolder& mailbox_holder,
119 const ReleaseMailboxCB& mailbox_holder_release_cb, 138 const ReleaseMailboxCB& mailbox_holder_release_cb,
120 const gfx::Size& coded_size, 139 const gfx::Size& coded_size,
121 const gfx::Rect& visible_rect, 140 const gfx::Rect& visible_rect,
122 const gfx::Size& natural_size, 141 const gfx::Size& natural_size,
(...skipping 11 matching lines...) Expand all
134 const ReleaseMailboxCB& mailbox_holders_release_cb, 153 const ReleaseMailboxCB& mailbox_holders_release_cb,
135 const gfx::Size& coded_size, 154 const gfx::Size& coded_size,
136 const gfx::Rect& visible_rect, 155 const gfx::Rect& visible_rect,
137 const gfx::Size& natural_size, 156 const gfx::Size& natural_size,
138 base::TimeDelta timestamp, 157 base::TimeDelta timestamp,
139 bool allow_overlay); 158 bool allow_overlay);
140 159
141 // Wraps packed image data residing in a memory buffer with a VideoFrame. 160 // Wraps packed image data residing in a memory buffer with a VideoFrame.
142 // The image data resides in |data| and is assumed to be packed tightly in a 161 // The image data resides in |data| and is assumed to be packed tightly in a
143 // buffer of logical dimensions |coded_size| with the appropriate bit depth 162 // buffer of logical dimensions |coded_size| with the appropriate bit depth
144 // and plane count as given by |format|. The shared memory handle of the 163 // and plane count as given by |format|. Returns NULL on failure.
145 // backing allocation, if present, can be passed in with |handle|. 164 static scoped_refptr<VideoFrame> WrapExternalData(
146 // Returns NULL on failure.
147 static scoped_refptr<VideoFrame> WrapExternalPackedMemory(
148 Format format, 165 Format format,
149 const gfx::Size& coded_size, 166 const gfx::Size& coded_size,
150 const gfx::Rect& visible_rect, 167 const gfx::Rect& visible_rect,
168 const gfx::Size& natural_size,
169 uint8* data,
170 size_t data_size,
171 base::TimeDelta timestamp);
172
173 // Same as WrapExternalData() with SharedMemoryHandle and its offset.
174 static scoped_refptr<VideoFrame> WrapExternalSharedMemory(
175 Format format,
176 const gfx::Size& coded_size,
177 const gfx::Rect& visible_rect,
151 const gfx::Size& natural_size, 178 const gfx::Size& natural_size,
152 uint8* data, 179 uint8* data,
153 size_t data_size, 180 size_t data_size,
154 base::SharedMemoryHandle handle, 181 base::SharedMemoryHandle handle,
155 size_t shared_memory_offset, 182 size_t shared_memory_offset,
156 base::TimeDelta timestamp); 183 base::TimeDelta timestamp);
157 184
158 // Wraps external YUV data of the given parameters with a VideoFrame. 185 // Wraps external YUV data of the given parameters with a VideoFrame.
159 // The returned VideoFrame does not own the data passed in. 186 // The returned VideoFrame does not own the data passed in.
160 static scoped_refptr<VideoFrame> WrapExternalYuvData( 187 static scoped_refptr<VideoFrame> WrapExternalYuvData(
161 Format format, 188 Format format,
162 const gfx::Size& coded_size, 189 const gfx::Size& coded_size,
163 const gfx::Rect& visible_rect, 190 const gfx::Rect& visible_rect,
164 const gfx::Size& natural_size, 191 const gfx::Size& natural_size,
165 int32 y_stride, 192 int32 y_stride,
166 int32 u_stride, 193 int32 u_stride,
167 int32 v_stride, 194 int32 v_stride,
168 uint8* y_data, 195 uint8* y_data,
169 uint8* u_data, 196 uint8* u_data,
170 uint8* v_data, 197 uint8* v_data,
171 base::TimeDelta timestamp); 198 base::TimeDelta timestamp);
172 199
173 #if defined(OS_POSIX) 200 #if defined(OS_LINUX)
174 // Wraps provided dmabufs 201 // Wraps provided dmabufs
175 // (https://www.kernel.org/doc/Documentation/dma-buf-sharing.txt) with a 202 // (https://www.kernel.org/doc/Documentation/dma-buf-sharing.txt) with a
176 // VideoFrame. The dmabuf fds are dup()ed on creation, so that the VideoFrame 203 // VideoFrame. The dmabuf fds are dup()ed on creation, so that the VideoFrame
177 // retains a reference to them, and are automatically close()d on destruction, 204 // retains a reference to them, and are automatically close()d on destruction,
178 // dropping the reference. The caller may safely close() its reference after 205 // dropping the reference. The caller may safely close() its reference after
179 // calling WrapExternalDmabufs(). 206 // calling WrapExternalDmabufs().
180 // The image data is only accessible via dmabuf fds, which are usually passed 207 // The image data is only accessible via dmabuf fds, which are usually passed
181 // directly to a hardware device and/or to another process, or can also be 208 // directly to a hardware device and/or to another process, or can also be
182 // mapped via mmap() for CPU access. 209 // mapped via mmap() for CPU access.
183 // Returns NULL on failure. 210 // Returns NULL on failure.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 static scoped_refptr<VideoFrame> CreateTransparentFrame( 256 static scoped_refptr<VideoFrame> CreateTransparentFrame(
230 const gfx::Size& size); 257 const gfx::Size& size);
231 258
232 #if defined(VIDEO_HOLE) 259 #if defined(VIDEO_HOLE)
233 // Allocates a hole frame. 260 // Allocates a hole frame.
234 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); 261 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size);
235 #endif // defined(VIDEO_HOLE) 262 #endif // defined(VIDEO_HOLE)
236 263
237 static size_t NumPlanes(Format format); 264 static size_t NumPlanes(Format format);
238 265
239 static size_t NumTextures(TextureFormat texture_format);
240
241 // Returns the required allocation size for a (tightly packed) frame of the 266 // Returns the required allocation size for a (tightly packed) frame of the
242 // given coded size and format. 267 // given coded size and format.
243 static size_t AllocationSize(Format format, const gfx::Size& coded_size); 268 static size_t AllocationSize(Format format, const gfx::Size& coded_size);
244 269
245 // Returns the plane size (in bytes) for a plane of the given coded size and 270 // Returns the plane size (in bytes) for a plane of the given coded size and
246 // format. 271 // format.
247 static gfx::Size PlaneSize(Format format, 272 static gfx::Size PlaneSize(Format format,
248 size_t plane, 273 size_t plane,
249 const gfx::Size& coded_size); 274 const gfx::Size& coded_size);
250 275
(...skipping 16 matching lines...) Expand all
267 // Returns the number of rows for the given plane, format, and height. 292 // Returns the number of rows for the given plane, format, and height.
268 // The height may be aligned to format requirements. 293 // The height may be aligned to format requirements.
269 static size_t Rows(size_t plane, Format format, int height); 294 static size_t Rows(size_t plane, Format format, int height);
270 295
271 // Returns the number of columns for the given plane, format, and width. 296 // Returns the number of columns for the given plane, format, and width.
272 // The width may be aligned to format requirements. 297 // The width may be aligned to format requirements.
273 static size_t Columns(size_t plane, Format format, int width); 298 static size_t Columns(size_t plane, Format format, int width);
274 299
275 Format format() const { return format_; } 300 Format format() const { return format_; }
276 301
277 TextureFormat texture_format() const { return texture_format_; } 302 StorageType storage_type() const { return storage_type_; }
278 303
279 const gfx::Size& coded_size() const { return coded_size_; } 304 const gfx::Size& coded_size() const { return coded_size_; }
280 const gfx::Rect& visible_rect() const { return visible_rect_; } 305 const gfx::Rect& visible_rect() const { return visible_rect_; }
281 const gfx::Size& natural_size() const { return natural_size_; } 306 const gfx::Size& natural_size() const { return natural_size_; }
282 307
283 int stride(size_t plane) const; 308 int stride(size_t plane) const;
284 309
285 // Returns the number of bytes per row and number of rows for a given plane. 310 // Returns the number of bytes per row and number of rows for a given plane.
286 // 311 //
287 // As opposed to stride(), row_bytes() refers to the bytes representing 312 // As opposed to stride(), row_bytes() refers to the bytes representing
288 // frame data scanlines (coded_size.width() pixels, without stride padding). 313 // frame data scanlines (coded_size.width() pixels, without stride padding).
289 int row_bytes(size_t plane) const; 314 int row_bytes(size_t plane) const;
290 int rows(size_t plane) const; 315 int rows(size_t plane) const;
291 316
292 // Returns pointer to the buffer for a given plane. The memory is owned by 317 // Returns pointer to the buffer for a given plane, if this is an IsMappable()
293 // VideoFrame object and must not be freed by the caller. 318 // frame type. The memory is owned by VideoFrame object and must not be freed
319 // by the caller.
294 const uint8* data(size_t plane) const; 320 const uint8* data(size_t plane) const;
295 uint8* data(size_t plane); 321 uint8* data(size_t plane);
296 322
297 // Returns pointer to the data in the visible region of the frame. I.e. the 323 // Returns pointer to the data in the visible region of the frame, for
298 // returned pointer is offsetted into the plane buffer specified by 324 // IsMappable() storage types. The returned pointer is offsetted into the
299 // visible_rect().origin(). Memory is owned by VideoFrame object and must not 325 // plane buffer specified by visible_rect().origin(). Memory is owned by
300 // be freed by the caller. 326 // VideoFrame object and must not be freed by the caller.
301 const uint8* visible_data(size_t plane) const; 327 const uint8* visible_data(size_t plane) const;
302 uint8* visible_data(size_t plane); 328 uint8* visible_data(size_t plane);
303 329
304 // Returns a mailbox holder for a given texture. 330 // Returns a mailbox holder for a given texture.
305 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the 331 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the
306 // mailbox, the caller must wait for the included sync point. 332 // mailbox, the caller must wait for the included sync point.
307 const gpu::MailboxHolder& mailbox_holder(size_t texture) const; 333 const gpu::MailboxHolder& mailbox_holder(size_t texture_index) const;
308 334
309 // Returns the shared-memory handle, if present 335 // Returns the shared-memory handle, if present
310 base::SharedMemoryHandle shared_memory_handle() const; 336 base::SharedMemoryHandle shared_memory_handle() const;
311 337
312 // Returns the offset into the shared memory where the frame data begins. 338 // Returns the offset into the shared memory where the frame data begins.
313 size_t shared_memory_offset() const; 339 size_t shared_memory_offset() const;
314 340
315 // Adds a callback to be run when the VideoFrame is about to be destroyed. 341 // Adds a callback to be run when the VideoFrame is about to be destroyed.
316 // The callback may be run from ANY THREAD, and so it is up to the client to 342 // The callback may be run from ANY THREAD, and so it is up to the client to
317 // ensure thread safety. Although read-only access to the members of this 343 // ensure thread safety. Although read-only access to the members of this
318 // VideoFrame is permitted while the callback executes (including 344 // VideoFrame is permitted while the callback executes (including
319 // VideoFrameMetadata), clients should not assume the data pointers are 345 // VideoFrameMetadata), clients should not assume the data pointers are
320 // valid. 346 // valid.
321 void AddDestructionObserver(const base::Closure& callback); 347 void AddDestructionObserver(const base::Closure& callback);
322 348
323 // Returns a dictionary of optional metadata. This contains information 349 // Returns a dictionary of optional metadata. This contains information
324 // associated with the frame that downstream clients might use for frame-level 350 // associated with the frame that downstream clients might use for frame-level
325 // logging, quality/performance optimizations, signaling, etc. 351 // logging, quality/performance optimizations, signaling, etc.
326 // 352 //
327 // TODO(miu): Move some of the "extra" members of VideoFrame (below) into 353 // TODO(miu): Move some of the "extra" members of VideoFrame (below) into
328 // here as a later clean-up step. 354 // here as a later clean-up step.
329 const VideoFrameMetadata* metadata() const { return &metadata_; } 355 const VideoFrameMetadata* metadata() const { return &metadata_; }
330 VideoFrameMetadata* metadata() { return &metadata_; } 356 VideoFrameMetadata* metadata() { return &metadata_; }
331 357
332 bool allow_overlay() const { return allow_overlay_; } 358 bool allow_overlay() const { return allow_overlay_; }
333 359
334 #if defined(OS_POSIX) 360 #if defined(OS_LINUX)
335 // Returns backing dmabuf file descriptor for given |plane|, if present. 361 // Returns backing dmabuf file descriptor for given |plane|, if present.
336 int dmabuf_fd(size_t plane) const; 362 int dmabuf_fd(size_t plane) const;
337 #endif 363 #endif
338 364
339 #if defined(OS_MACOSX) 365 #if defined(OS_MACOSX)
340 // Returns the backing CVPixelBuffer, if present. 366 // Returns the backing CVPixelBuffer, if present.
341 CVPixelBufferRef cv_pixel_buffer() const; 367 CVPixelBufferRef cv_pixel_buffer() const;
342 #endif 368 #endif
343 369
344 // Returns true if this VideoFrame represents the end of the stream. 370 // Returns true if this VideoFrame represents the end of the stream.
345 bool end_of_stream() const { return end_of_stream_; } 371 bool end_of_stream() const { return end_of_stream_; }
346 372
347 base::TimeDelta timestamp() const { 373 base::TimeDelta timestamp() const { return timestamp_; }
348 return timestamp_; 374 void set_timestamp(base::TimeDelta timestamp) {
349 }
350 void set_timestamp(const base::TimeDelta& timestamp) {
351 timestamp_ = timestamp; 375 timestamp_ = timestamp;
352 } 376 }
353 377
354 class SyncPointClient { 378 class SyncPointClient {
355 public: 379 public:
356 SyncPointClient() {} 380 SyncPointClient() {}
357 virtual uint32 InsertSyncPoint() = 0; 381 virtual uint32 InsertSyncPoint() = 0;
358 virtual void WaitSyncPoint(uint32 sync_point) = 0; 382 virtual void WaitSyncPoint(uint32 sync_point) = 0;
359 383
360 protected: 384 protected:
361 virtual ~SyncPointClient() {} 385 virtual ~SyncPointClient() {}
362 386
363 DISALLOW_COPY_AND_ASSIGN(SyncPointClient); 387 DISALLOW_COPY_AND_ASSIGN(SyncPointClient);
364 }; 388 };
365 // It uses |client| to insert a new sync point and potentially waits on a 389 // It uses |client| to insert a new sync point and potentially waits on a
366 // older sync point. The final sync point will be used to release this 390 // older sync point. The final sync point will be used to release this
367 // VideoFrame. 391 // VideoFrame.
368 // This method is thread safe. Both blink and compositor threads can call it. 392 // This method is thread safe. Both blink and compositor threads can call it.
369 void UpdateReleaseSyncPoint(SyncPointClient* client); 393 void UpdateReleaseSyncPoint(SyncPointClient* client);
370 394
371 // Used to keep a running hash of seen frames. Expects an initialized MD5 395 // Used to keep a running hash of seen frames. Expects an initialized MD5
372 // context. Calls MD5Update with the context and the contents of the frame. 396 // context. Calls MD5Update with the context and the contents of the frame.
373 void HashFrameForTesting(base::MD5Context* context); 397 void HashFrameForTesting(base::MD5Context* context);
374 398
375 private: 399 private:
376 friend class base::RefCountedThreadSafe<VideoFrame>; 400 friend class base::RefCountedThreadSafe<VideoFrame>;
377 401
378 // Clients must use the static CreateFrame() method to create a new frame. 402 // Clients must use the static CreateFrame() method to create a new frame.
379 VideoFrame(Format format, 403 VideoFrame(Format format,
404 StorageType storage_type,
405 const gfx::Size& coded_size,
406 const gfx::Rect& visible_rect,
407 const gfx::Size& natural_size,
408 base::TimeDelta timestamp,
409 bool end_of_stream);
410 VideoFrame(Format format,
411 StorageType storage_type,
412 const gfx::Size& coded_size,
413 const gfx::Rect& visible_rect,
414 const gfx::Size& natural_size,
415 base::TimeDelta timestamp,
416 bool end_of_stream,
417 base::SharedMemoryHandle handle,
418 size_t shared_memory_offset);
419 VideoFrame(Format format,
420 StorageType storage_type,
380 const gfx::Size& coded_size, 421 const gfx::Size& coded_size,
381 const gfx::Rect& visible_rect, 422 const gfx::Rect& visible_rect,
382 const gfx::Size& natural_size, 423 const gfx::Size& natural_size,
383 const gpu::MailboxHolder(&mailbox_holders)[kMaxPlanes], 424 const gpu::MailboxHolder(&mailbox_holders)[kMaxPlanes],
384 TextureFormat texture_format,
385 base::TimeDelta timestamp, 425 base::TimeDelta timestamp,
386 bool end_of_stream); 426 bool end_of_stream);
387 virtual ~VideoFrame(); 427 virtual ~VideoFrame();
388 428
429 static scoped_refptr<VideoFrame> WrapExternalStorage(
430 Format format,
431 StorageType storage_type,
432 const gfx::Size& coded_size,
433 const gfx::Rect& visible_rect,
434 const gfx::Size& natural_size,
435 uint8* data,
436 size_t data_size,
437 base::TimeDelta timestamp,
438 base::SharedMemoryHandle handle,
439 size_t data_offset);
440
389 void AllocateYUV(); 441 void AllocateYUV();
390 442
391 // Frame format. 443 // Frame format.
392 const Format format_; 444 const Format format_;
393 445
394 // Format of the native textures associated with this frame. 446 // Storage type for the different planes.
395 const TextureFormat texture_format_; 447 const StorageType storage_type_;
396 448
397 // Width and height of the video frame, in pixels. This must include pixel 449 // Width and height of the video frame, in pixels. This must include pixel
398 // data for the whole image; i.e. for YUV formats with subsampled chroma 450 // data for the whole image; i.e. for YUV formats with subsampled chroma
399 // planes, in the case that the visible portion of the image does not line up 451 // planes, in the case that the visible portion of the image does not line up
400 // on a sample boundary, |coded_size_| must be rounded up appropriately and 452 // on a sample boundary, |coded_size_| must be rounded up appropriately and
401 // the pixel data provided for the odd pixels. 453 // the pixel data provided for the odd pixels.
402 const gfx::Size coded_size_; 454 const gfx::Size coded_size_;
403 455
404 // Width, height, and offsets of the visible portion of the video frame. Must 456 // Width, height, and offsets of the visible portion of the video frame. Must
405 // be a subrect of |coded_size_|. Can be odd with respect to the sample 457 // be a subrect of |coded_size_|. Can be odd with respect to the sample
406 // boundaries, e.g. for formats with subsampled chroma. 458 // boundaries, e.g. for formats with subsampled chroma.
407 const gfx::Rect visible_rect_; 459 const gfx::Rect visible_rect_;
408 460
409 // Width and height of the visible portion of the video frame 461 // Width and height of the visible portion of the video frame
410 // (|visible_rect_.size()|) with aspect ratio taken into account. 462 // (|visible_rect_.size()|) with aspect ratio taken into account.
411 const gfx::Size natural_size_; 463 const gfx::Size natural_size_;
412 464
413 // Array of strides for each plane, typically greater or equal to the width 465 // Array of strides for each plane, typically greater or equal to the width
414 // of the surface divided by the horizontal sampling period. Note that 466 // of the surface divided by the horizontal sampling period. Note that
415 // strides can be negative. 467 // strides can be negative.
416 int32 strides_[kMaxPlanes]; 468 int32 strides_[kMaxPlanes];
417 469
418 // Array of data pointers to each plane. 470 // Array of data pointers to each plane.
471 // TODO(mcasas): we don't know on ctor if we own |data_| or not. After
472 // refactoring VideoFrame, change to scoped_ptr<uint8, AlignedFreeDeleter>.
419 uint8* data_[kMaxPlanes]; 473 uint8* data_[kMaxPlanes];
420 474
421 // Native texture mailboxes, if this is a NATIVE_TEXTURE frame. 475 // Native texture mailboxes, if this is a STORAGE_TEXTURE frame.
422 gpu::MailboxHolder mailbox_holders_[kMaxPlanes]; 476 gpu::MailboxHolder mailbox_holders_[kMaxPlanes];
423 ReleaseMailboxCB mailbox_holders_release_cb_; 477 ReleaseMailboxCB mailbox_holders_release_cb_;
424 478
425 // Shared memory handle, if this frame was allocated from shared memory. 479 // Shared memory handle and associated offset inside it, if this frame was
480 // constructed as STORAGE_SHMEM.
426 base::SharedMemoryHandle shared_memory_handle_; 481 base::SharedMemoryHandle shared_memory_handle_;
427
428 // Offset in shared memory buffer.
429 size_t shared_memory_offset_; 482 size_t shared_memory_offset_;
430 483
431 #if defined(OS_POSIX) 484 #if defined(OS_LINUX)
432 // Dmabufs for each plane, if this frame is wrapping memory 485 // Dmabufs for each plane, if this frame is wrapping memory
433 // acquired via dmabuf. 486 // acquired via dmabuf.
434 base::ScopedFD dmabuf_fds_[kMaxPlanes]; 487 base::ScopedFD dmabuf_fds_[kMaxPlanes];
435 #endif 488 #endif
436 489
437 #if defined(OS_MACOSX) 490 #if defined(OS_MACOSX)
438 // CVPixelBuffer, if this frame is wrapping one. 491 // CVPixelBuffer, if this frame is wrapping one.
439 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer_; 492 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer_;
440 #endif 493 #endif
441 494
442 std::vector<base::Closure> done_callbacks_; 495 std::vector<base::Closure> done_callbacks_;
443 496
444 base::TimeDelta timestamp_; 497 base::TimeDelta timestamp_;
445 498
446 base::Lock release_sync_point_lock_; 499 base::Lock release_sync_point_lock_;
447 uint32 release_sync_point_; 500 uint32 release_sync_point_;
448 501
449 const bool end_of_stream_; 502 const bool end_of_stream_;
450 503
451 VideoFrameMetadata metadata_; 504 VideoFrameMetadata metadata_;
452 505
453 bool allow_overlay_; 506 bool allow_overlay_;
454 507
455 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); 508 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);
456 }; 509 };
457 510
458 } // namespace media 511 } // namespace media
459 512
460 #endif // MEDIA_BASE_VIDEO_FRAME_H_ 513 #endif // MEDIA_BASE_VIDEO_FRAME_H_
OLDNEW
« no previous file with comments | « media/base/video_decoder_config.cc ('k') | media/base/video_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698