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