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 "media/base/buffers.h" | 14 #include "media/base/buffers.h" |
15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
17 | 17 |
18 class SkBitmap; | 18 class SkBitmap; |
19 | 19 |
| 20 #if defined(OS_MACOSX) |
| 21 #include <CoreVideo/CoreVideo.h> |
| 22 |
| 23 #include "base/mac/scoped_cftyperef.h" |
| 24 #endif |
| 25 |
20 namespace gpu { | 26 namespace gpu { |
21 struct MailboxHolder; | 27 struct MailboxHolder; |
22 } // namespace gpu | 28 } // namespace gpu |
23 | 29 |
24 namespace media { | 30 namespace media { |
25 | 31 |
26 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { | 32 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { |
27 public: | 33 public: |
28 enum { | 34 enum { |
29 kFrameSizeAlignment = 16, | 35 kFrameSizeAlignment = 16, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 static scoped_refptr<VideoFrame> WrapExternalDmabufs( | 147 static scoped_refptr<VideoFrame> WrapExternalDmabufs( |
142 Format format, | 148 Format format, |
143 const gfx::Size& coded_size, | 149 const gfx::Size& coded_size, |
144 const gfx::Rect& visible_rect, | 150 const gfx::Rect& visible_rect, |
145 const gfx::Size& natural_size, | 151 const gfx::Size& natural_size, |
146 const std::vector<int> dmabuf_fds, | 152 const std::vector<int> dmabuf_fds, |
147 base::TimeDelta timestamp, | 153 base::TimeDelta timestamp, |
148 const base::Closure& no_longer_needed_cb); | 154 const base::Closure& no_longer_needed_cb); |
149 #endif | 155 #endif |
150 | 156 |
| 157 #if defined(OS_MACOSX) |
| 158 // Wraps a provided CVPixelBuffer with a VideoFrame. The pixel buffer is |
| 159 // retained for the lifetime of the VideoFrame and released upon destruction. |
| 160 // The image data is only accessible via the pixel buffer, which could be |
| 161 // backed by an IOSurface from another process. All the attributes of the |
| 162 // VideoFrame are derived from the pixel buffer, with the exception of the |
| 163 // timestamp. If information is missing or is incompatible (for example, a |
| 164 // pixel format that has no VideoFrame match), NULL is returned. |
| 165 // http://crbug.com/401308 |
| 166 static scoped_refptr<VideoFrame> WrapCVPixelBuffer( |
| 167 CVPixelBufferRef cv_pixel_buffer, |
| 168 base::TimeDelta timestamp); |
| 169 #endif |
| 170 |
151 // Wraps external YUV data of the given parameters with a VideoFrame. | 171 // Wraps external YUV data of the given parameters with a VideoFrame. |
152 // The returned VideoFrame does not own the data passed in. When the frame | 172 // The returned VideoFrame does not own the data passed in. When the frame |
153 // is destroyed |no_longer_needed_cb.Run()| will be called. | 173 // is destroyed |no_longer_needed_cb.Run()| will be called. |
154 // TODO(sheu): merge this into WrapExternalSharedMemory(). | 174 // TODO(sheu): merge this into WrapExternalSharedMemory(). |
155 // http://crbug.com/270217 | 175 // http://crbug.com/270217 |
156 static scoped_refptr<VideoFrame> WrapExternalYuvData( | 176 static scoped_refptr<VideoFrame> WrapExternalYuvData( |
157 Format format, | 177 Format format, |
158 const gfx::Size& coded_size, | 178 const gfx::Size& coded_size, |
159 const gfx::Rect& visible_rect, | 179 const gfx::Rect& visible_rect, |
160 const gfx::Size& natural_size, | 180 const gfx::Size& natural_size, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 const gpu::MailboxHolder* mailbox_holder() const; | 264 const gpu::MailboxHolder* mailbox_holder() const; |
245 | 265 |
246 // Returns the shared-memory handle, if present | 266 // Returns the shared-memory handle, if present |
247 base::SharedMemoryHandle shared_memory_handle() const; | 267 base::SharedMemoryHandle shared_memory_handle() const; |
248 | 268 |
249 #if defined(OS_POSIX) | 269 #if defined(OS_POSIX) |
250 // Returns backing dmabuf file descriptor for given |plane|, if present. | 270 // Returns backing dmabuf file descriptor for given |plane|, if present. |
251 int dmabuf_fd(size_t plane) const; | 271 int dmabuf_fd(size_t plane) const; |
252 #endif | 272 #endif |
253 | 273 |
| 274 #if defined(OS_MACOSX) |
| 275 // Returns the backing CVPixelBuffer, if present. |
| 276 CVPixelBufferRef cv_pixel_buffer() const; |
| 277 #endif |
| 278 |
254 // Returns true if this VideoFrame represents the end of the stream. | 279 // Returns true if this VideoFrame represents the end of the stream. |
255 bool end_of_stream() const { return end_of_stream_; } | 280 bool end_of_stream() const { return end_of_stream_; } |
256 | 281 |
257 base::TimeDelta timestamp() const { | 282 base::TimeDelta timestamp() const { |
258 return timestamp_; | 283 return timestamp_; |
259 } | 284 } |
260 void set_timestamp(const base::TimeDelta& timestamp) { | 285 void set_timestamp(const base::TimeDelta& timestamp) { |
261 timestamp_ = timestamp; | 286 timestamp_ = timestamp; |
262 } | 287 } |
263 | 288 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 358 |
334 // Shared memory handle, if this frame was allocated from shared memory. | 359 // Shared memory handle, if this frame was allocated from shared memory. |
335 base::SharedMemoryHandle shared_memory_handle_; | 360 base::SharedMemoryHandle shared_memory_handle_; |
336 | 361 |
337 #if defined(OS_POSIX) | 362 #if defined(OS_POSIX) |
338 // Dmabufs for each plane, if this frame is wrapping memory | 363 // Dmabufs for each plane, if this frame is wrapping memory |
339 // acquired via dmabuf. | 364 // acquired via dmabuf. |
340 base::ScopedFD dmabuf_fds_[kMaxPlanes]; | 365 base::ScopedFD dmabuf_fds_[kMaxPlanes]; |
341 #endif | 366 #endif |
342 | 367 |
| 368 #if defined(OS_MACOSX) |
| 369 // CVPixelBuffer, if this frame is wrapping one. |
| 370 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer_; |
| 371 #endif |
| 372 |
343 base::Closure no_longer_needed_cb_; | 373 base::Closure no_longer_needed_cb_; |
344 | 374 |
345 base::TimeDelta timestamp_; | 375 base::TimeDelta timestamp_; |
346 | 376 |
347 base::Lock release_sync_point_lock_; | 377 base::Lock release_sync_point_lock_; |
348 uint32 release_sync_point_; | 378 uint32 release_sync_point_; |
349 | 379 |
350 const bool end_of_stream_; | 380 const bool end_of_stream_; |
351 | 381 |
352 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 382 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
353 }; | 383 }; |
354 | 384 |
355 } // namespace media | 385 } // namespace media |
356 | 386 |
357 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 387 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |