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 "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic. | 53 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic. |
54 YV12J = 7, // JPEG color range version of YV12 | 54 YV12J = 7, // JPEG color range version of YV12 |
55 FORMAT_MAX = YV12J, // Must always be equal to largest entry logged. | 55 FORMAT_MAX = YV12J, // Must always be equal to largest entry logged. |
56 }; | 56 }; |
57 | 57 |
58 // Returns the name of a Format as a string. | 58 // Returns the name of a Format as a string. |
59 static std::string FormatToString(Format format); | 59 static std::string FormatToString(Format format); |
60 | 60 |
61 // Creates a new frame in system memory with given parameters. Buffers for | 61 // Creates a new frame in system memory with given parameters. Buffers for |
62 // the frame are allocated but not initialized. | 62 // the frame are allocated but not initialized. |
63 // |coded_size| is the width and height of the frame data in pixels. | |
64 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | |
65 // any) is applied. | |
66 // |natural_size| is the width and height of the frame when the frame's aspect | |
67 // ratio is applied to |visible_rect|. | |
68 static scoped_refptr<VideoFrame> CreateFrame( | 63 static scoped_refptr<VideoFrame> CreateFrame( |
69 Format format, | 64 Format format, |
70 const gfx::Size& coded_size, | 65 const gfx::Size& coded_size, |
71 const gfx::Rect& visible_rect, | 66 const gfx::Rect& visible_rect, |
72 const gfx::Size& natural_size, | 67 const gfx::Size& natural_size, |
73 base::TimeDelta timestamp); | 68 base::TimeDelta timestamp); |
74 | 69 |
75 // Call prior to CreateFrame to ensure validity of frame configuration. Called | 70 // Call prior to CreateFrame to ensure validity of frame configuration. Called |
76 // automatically by VideoDecoderConfig::IsValidConfig(). | 71 // automatically by VideoDecoderConfig::IsValidConfig(). |
77 // TODO(scherkus): VideoDecoderConfig shouldn't call this method | 72 // TODO(scherkus): VideoDecoderConfig shouldn't call this method |
78 static bool IsValidConfig(Format format, const gfx::Size& coded_size, | 73 static bool IsValidConfig(Format format, const gfx::Size& coded_size, |
79 const gfx::Rect& visible_rect, | 74 const gfx::Rect& visible_rect, |
80 const gfx::Size& natural_size); | 75 const gfx::Size& natural_size); |
81 | 76 |
82 // CB to write pixels from the texture backing this frame into the | 77 // CB to write pixels from the texture backing this frame into the |
83 // |const SkBitmap&| parameter. | 78 // |const SkBitmap&| parameter. |
84 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; | 79 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; |
85 | 80 |
86 // CB to be called on the mailbox backing this frame when the frame is | 81 // CB to be called on the mailbox backing this frame when the frame is |
87 // destroyed. | 82 // destroyed. |
88 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB; | 83 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB; |
89 | 84 |
90 // Wraps a native texture of the given parameters with a VideoFrame. The | 85 // Wraps a native texture of the given parameters with a VideoFrame. The |
91 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, | 86 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|, |
92 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the | 87 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the |
93 // argument when the VideoFrame is to be destroyed. | 88 // argument when the VideoFrame is to be destroyed. |
94 // |coded_size| is the width and height of the frame data in pixels. | |
95 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | |
96 // any) is applied. | |
97 // |natural_size| is the width and height of the frame when the frame's aspect | |
98 // ratio is applied to |visible_rect|. | |
99 | |
100 // |read_pixels_cb| may be used to do (slow!) readbacks from the | 89 // |read_pixels_cb| may be used to do (slow!) readbacks from the |
101 // texture to main memory. | 90 // texture to main memory. |
102 static scoped_refptr<VideoFrame> WrapNativeTexture( | 91 static scoped_refptr<VideoFrame> WrapNativeTexture( |
103 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 92 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
104 const ReleaseMailboxCB& mailbox_holder_release_cb, | 93 const ReleaseMailboxCB& mailbox_holder_release_cb, |
105 const gfx::Size& coded_size, | 94 const gfx::Size& coded_size, |
106 const gfx::Rect& visible_rect, | 95 const gfx::Rect& visible_rect, |
107 const gfx::Size& natural_size, | 96 const gfx::Size& natural_size, |
108 base::TimeDelta timestamp, | 97 base::TimeDelta timestamp, |
109 const ReadPixelsCB& read_pixels_cb); | 98 const ReadPixelsCB& read_pixels_cb); |
110 | 99 |
111 // Read pixels from the native texture backing |*this| and write | 100 // Read pixels from the native texture backing |*this| and write |
112 // them to |pixels| as BGRA. |pixels| must point to a buffer at | 101 // them to |pixels| as BGRA. |pixels| must point to a buffer at |
113 // least as large as 4*visible_rect().width()*visible_rect().height(). | 102 // least as large as 4 * visible_rect().size().GetArea(). |
114 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); | 103 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); |
115 | 104 |
116 // Wraps packed image data residing in a memory buffer with a VideoFrame. | 105 // Wraps packed image data residing in a memory buffer with a VideoFrame. |
117 // The image data resides in |data| and is assumed to be packed tightly in a | 106 // The image data resides in |data| and is assumed to be packed tightly in a |
118 // buffer of logical dimensions |coded_size| with the appropriate bit depth | 107 // buffer of logical dimensions |coded_size| with the appropriate bit depth |
119 // and plane count as given by |format|. The shared memory handle of the | 108 // and plane count as given by |format|. The shared memory handle of the |
120 // backing allocation, if present, can be passed in with |handle|. When the | 109 // backing allocation, if present, can be passed in with |handle|. When the |
121 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. | 110 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. |
122 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( | 111 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( |
123 Format format, | 112 Format format, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // Allocates a hole frame. | 164 // Allocates a hole frame. |
176 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); | 165 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); |
177 #endif // defined(VIDEO_HOLE) | 166 #endif // defined(VIDEO_HOLE) |
178 | 167 |
179 static size_t NumPlanes(Format format); | 168 static size_t NumPlanes(Format format); |
180 | 169 |
181 // Returns the required allocation size for a (tightly packed) frame of the | 170 // Returns the required allocation size for a (tightly packed) frame of the |
182 // given coded size and format. | 171 // given coded size and format. |
183 static size_t AllocationSize(Format format, const gfx::Size& coded_size); | 172 static size_t AllocationSize(Format format, const gfx::Size& coded_size); |
184 | 173 |
| 174 // Returns the plane size for a plane of the given coded size and format. |
| 175 static gfx::Size PlaneSize(Format format, |
| 176 size_t plane, |
| 177 const gfx::Size& coded_size); |
| 178 |
185 // Returns the required allocation size for a (tightly packed) plane of the | 179 // Returns the required allocation size for a (tightly packed) plane of the |
186 // given coded size and format. | 180 // given coded size and format. |
187 static size_t PlaneAllocationSize(Format format, | 181 static size_t PlaneAllocationSize(Format format, |
188 size_t plane, | 182 size_t plane, |
189 const gfx::Size& coded_size); | 183 const gfx::Size& coded_size); |
190 | 184 |
191 Format format() const { return format_; } | 185 Format format() const { return format_; } |
192 | 186 |
193 const gfx::Size& coded_size() const { return coded_size_; } | 187 const gfx::Size& coded_size() const { return coded_size_; } |
194 const gfx::Rect& visible_rect() const { return visible_rect_; } | 188 const gfx::Rect& visible_rect() const { return visible_rect_; } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 base::TimeDelta timestamp, | 233 base::TimeDelta timestamp, |
240 bool end_of_stream); | 234 bool end_of_stream); |
241 virtual ~VideoFrame(); | 235 virtual ~VideoFrame(); |
242 | 236 |
243 void AllocateYUV(); | 237 void AllocateYUV(); |
244 | 238 |
245 // Used to DCHECK() plane parameters. | 239 // Used to DCHECK() plane parameters. |
246 bool IsValidPlane(size_t plane) const; | 240 bool IsValidPlane(size_t plane) const; |
247 | 241 |
248 // Frame format. | 242 // Frame format. |
249 Format format_; | 243 const Format format_; |
250 | 244 |
251 // Width and height of the video frame. | 245 // Width and height of the video frame, in pixels. This must include pixel |
252 gfx::Size coded_size_; | 246 // data for the whole image; i.e. for YUV formats with subsampled chroma |
| 247 // planes, in the case that the visible portion of the image does not line up |
| 248 // on a sample boundary, |coded_size_| must be rounded up appropriately and |
| 249 // the pixel data provided for the odd pixels. |
| 250 const gfx::Size coded_size_; |
253 | 251 |
254 // Width, height, and offsets of the visible portion of the video frame. | 252 // Width, height, and offsets of the visible portion of the video frame. Must |
255 gfx::Rect visible_rect_; | 253 // be a subrect of |coded_size_|. Can be odd with respect to the sample |
| 254 // boundaries, e.g. for formats with subsampled chroma. |
| 255 const gfx::Rect visible_rect_; |
256 | 256 |
257 // Width and height of the visible portion of the video frame with aspect | 257 // Width and height of the visible portion of the video frame |
258 // ratio taken into account. | 258 // (|visible_rect_.size()|) with aspect ratio taken into account. |
259 gfx::Size natural_size_; | 259 const gfx::Size natural_size_; |
260 | 260 |
261 // Array of strides for each plane, typically greater or equal to the width | 261 // Array of strides for each plane, typically greater or equal to the width |
262 // of the surface divided by the horizontal sampling period. Note that | 262 // of the surface divided by the horizontal sampling period. Note that |
263 // strides can be negative. | 263 // strides can be negative. |
264 int32 strides_[kMaxPlanes]; | 264 int32 strides_[kMaxPlanes]; |
265 | 265 |
266 // Array of data pointers to each plane. | 266 // Array of data pointers to each plane. |
267 uint8* data_[kMaxPlanes]; | 267 uint8* data_[kMaxPlanes]; |
268 | 268 |
269 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. | 269 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. |
270 scoped_ptr<gpu::MailboxHolder> mailbox_holder_; | 270 scoped_ptr<gpu::MailboxHolder> mailbox_holder_; |
271 ReleaseMailboxCB mailbox_holder_release_cb_; | 271 ReleaseMailboxCB mailbox_holder_release_cb_; |
272 ReadPixelsCB read_pixels_cb_; | 272 ReadPixelsCB read_pixels_cb_; |
273 | 273 |
274 // Shared memory handle, if this frame was allocated from shared memory. | 274 // Shared memory handle, if this frame was allocated from shared memory. |
275 base::SharedMemoryHandle shared_memory_handle_; | 275 base::SharedMemoryHandle shared_memory_handle_; |
276 | 276 |
277 base::Closure no_longer_needed_cb_; | 277 base::Closure no_longer_needed_cb_; |
278 | 278 |
279 base::TimeDelta timestamp_; | 279 base::TimeDelta timestamp_; |
280 | 280 |
281 const bool end_of_stream_; | 281 const bool end_of_stream_; |
282 | 282 |
283 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 283 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
284 }; | 284 }; |
285 | 285 |
286 } // namespace media | 286 } // namespace media |
287 | 287 |
288 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 288 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |