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 "gpu/command_buffer/common/mailbox.h" | |
10 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
11 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
12 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
13 | 14 |
14 class SkBitmap; | 15 class SkBitmap; |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { | 19 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { |
19 public: | 20 public: |
(...skipping 24 matching lines...) Expand all Loading... | |
44 YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples | 45 YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples |
45 EMPTY = 9, // An empty frame. | 46 EMPTY = 9, // An empty frame. |
46 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | 47 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
47 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. | 48 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. |
48 #if defined(GOOGLE_TV) | 49 #if defined(GOOGLE_TV) |
49 HOLE = 13, // Hole frame. | 50 HOLE = 13, // Hole frame. |
50 #endif | 51 #endif |
51 YV12A = 14, // 20bpp YUVA planar 1x1 Y, 2x2 VU, 1x1 A samples. | 52 YV12A = 14, // 20bpp YUVA planar 1x1 Y, 2x2 VU, 1x1 A samples. |
52 }; | 53 }; |
53 | 54 |
55 typedef base::Callback<void(uint32 sync_point)> TextureNoLongerNeededCallback; | |
56 | |
54 // Creates a new frame in system memory with given parameters. Buffers for | 57 // Creates a new frame in system memory with given parameters. Buffers for |
55 // the frame are allocated but not initialized. | 58 // the frame are allocated but not initialized. |
56 // |coded_size| is the width and height of the frame data in pixels. | 59 // |coded_size| is the width and height of the frame data in pixels. |
57 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | 60 // |visible_rect| is the visible portion of |coded_size|, after cropping (if |
58 // any) is applied. | 61 // any) is applied. |
59 // |natural_size| is the width and height of the frame when the frame's aspect | 62 // |natural_size| is the width and height of the frame when the frame's aspect |
60 // ratio is applied to |visible_rect|. | 63 // ratio is applied to |visible_rect|. |
61 static scoped_refptr<VideoFrame> CreateFrame( | 64 static scoped_refptr<VideoFrame> CreateFrame( |
62 Format format, | 65 Format format, |
63 const gfx::Size& coded_size, | 66 const gfx::Size& coded_size, |
(...skipping 16 matching lines...) Expand all Loading... | |
80 // frame is destroyed |no_longer_needed_cb.Run()| will be called. | 83 // frame is destroyed |no_longer_needed_cb.Run()| will be called. |
81 // |coded_size| is the width and height of the frame data in pixels. | 84 // |coded_size| is the width and height of the frame data in pixels. |
82 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | 85 // |visible_rect| is the visible portion of |coded_size|, after cropping (if |
83 // any) is applied. | 86 // any) is applied. |
84 // |natural_size| is the width and height of the frame when the frame's aspect | 87 // |natural_size| is the width and height of the frame when the frame's aspect |
85 // ratio is applied to |visible_rect|. | 88 // ratio is applied to |visible_rect|. |
86 | 89 |
87 // |read_pixels_cb| may be used to do (slow!) readbacks from the | 90 // |read_pixels_cb| may be used to do (slow!) readbacks from the |
88 // texture to main memory. | 91 // texture to main memory. |
89 static scoped_refptr<VideoFrame> WrapNativeTexture( | 92 static scoped_refptr<VideoFrame> WrapNativeTexture( |
90 uint32 texture_id, | 93 const gpu::Mailbox& texture_mailbox, |
scherkus (not reviewing)
2013/06/17 20:20:37
thoughts on replacing the 3 args with a MailboxHol
danakj
2013/06/18 00:45:05
Hm... I think that sounds like a good idea. Will d
danakj
2013/06/18 16:54:12
Done.
| |
94 uint32 texture_mailbox_sync_point, | |
91 uint32 texture_target, | 95 uint32 texture_target, |
92 const gfx::Size& coded_size, | 96 const gfx::Size& coded_size, |
93 const gfx::Rect& visible_rect, | 97 const gfx::Rect& visible_rect, |
94 const gfx::Size& natural_size, | 98 const gfx::Size& natural_size, |
95 base::TimeDelta timestamp, | 99 base::TimeDelta timestamp, |
96 const ReadPixelsCB& read_pixels_cb, | 100 const ReadPixelsCB& read_pixels_cb, |
101 const TextureNoLongerNeededCallback& texture_no_longer_needed_cb, | |
97 const base::Closure& no_longer_needed_cb); | 102 const base::Closure& no_longer_needed_cb); |
98 | 103 |
99 // Read pixels from the native texture backing |*this| and write | 104 // Read pixels from the native texture backing |*this| and write |
100 // them to |pixels| as BGRA. |pixels| must point to a buffer at | 105 // them to |pixels| as BGRA. |pixels| must point to a buffer at |
101 // least as large as 4*visible_rect().width()*visible_rect().height(). | 106 // least as large as 4*visible_rect().width()*visible_rect().height(). |
102 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); | 107 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); |
103 | 108 |
104 // Wraps external YUV data of the given parameters with a VideoFrame. | 109 // Wraps external YUV data of the given parameters with a VideoFrame. |
105 // The returned VideoFrame does not own the data passed in. When the frame | 110 // The returned VideoFrame does not own the data passed in. When the frame |
106 // is destroyed |no_longer_needed_cb.Run()| will be called. | 111 // is destroyed |no_longer_needed_cb.Run()| will be called. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 // | 156 // |
152 // As opposed to stride(), row_bytes() refers to the bytes representing | 157 // As opposed to stride(), row_bytes() refers to the bytes representing |
153 // frame data scanlines (coded_size.width() pixels, without stride padding). | 158 // frame data scanlines (coded_size.width() pixels, without stride padding). |
154 int row_bytes(size_t plane) const; | 159 int row_bytes(size_t plane) const; |
155 int rows(size_t plane) const; | 160 int rows(size_t plane) const; |
156 | 161 |
157 // Returns pointer to the buffer for a given plane. The memory is owned by | 162 // Returns pointer to the buffer for a given plane. The memory is owned by |
158 // VideoFrame object and must not be freed by the caller. | 163 // VideoFrame object and must not be freed by the caller. |
159 uint8* data(size_t plane) const; | 164 uint8* data(size_t plane) const; |
160 | 165 |
161 // Returns the ID of the native texture wrapped by this frame. Only valid to | 166 class MailboxHolder : public base::RefCountedThreadSafe<MailboxHolder> { |
162 // call if this is a NATIVE_TEXTURE frame. | 167 public: |
163 uint32 texture_id() const; | 168 MailboxHolder(const gpu::Mailbox& mailbox, |
169 unsigned sync_point, | |
170 const TextureNoLongerNeededCallback& release_callback); | |
171 | |
172 const gpu::Mailbox& mailbox() const { return mailbox_; } | |
173 unsigned sync_point() const { return sync_point_; } | |
174 | |
175 void Return(unsigned sync_point) { sync_point_ = sync_point; } | |
176 | |
177 private: | |
178 friend class base::RefCountedThreadSafe<MailboxHolder>; | |
179 ~MailboxHolder(); | |
180 | |
181 gpu::Mailbox mailbox_; | |
182 unsigned sync_point_; | |
183 TextureNoLongerNeededCallback release_callback_; | |
184 }; | |
185 | |
186 // Returns the mailbox of the native texture wrapped by this frame. Only | |
187 // valid to call if this is a NATIVE_TEXTURE frame. Before using the | |
188 // mailbox, the caller must wait for the included sync point. | |
189 const scoped_refptr<MailboxHolder>& texture_mailbox() const; | |
164 | 190 |
165 // Returns the texture target. Only valid for NATIVE_TEXTURE frames. | 191 // Returns the texture target. Only valid for NATIVE_TEXTURE frames. |
166 uint32 texture_target() const; | 192 uint32 texture_target() const; |
167 | 193 |
168 // Returns true if this VideoFrame represents the end of the stream. | 194 // Returns true if this VideoFrame represents the end of the stream. |
169 bool IsEndOfStream() const; | 195 bool IsEndOfStream() const; |
170 | 196 |
171 base::TimeDelta GetTimestamp() const { | 197 base::TimeDelta GetTimestamp() const { |
172 return timestamp_; | 198 return timestamp_; |
173 } | 199 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 gfx::Size natural_size_; | 236 gfx::Size natural_size_; |
211 | 237 |
212 // Array of strides for each plane, typically greater or equal to the width | 238 // Array of strides for each plane, typically greater or equal to the width |
213 // of the surface divided by the horizontal sampling period. Note that | 239 // of the surface divided by the horizontal sampling period. Note that |
214 // strides can be negative. | 240 // strides can be negative. |
215 int32 strides_[kMaxPlanes]; | 241 int32 strides_[kMaxPlanes]; |
216 | 242 |
217 // Array of data pointers to each plane. | 243 // Array of data pointers to each plane. |
218 uint8* data_[kMaxPlanes]; | 244 uint8* data_[kMaxPlanes]; |
219 | 245 |
220 // Native texture ID, if this is a NATIVE_TEXTURE frame. | 246 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. |
221 uint32 texture_id_; | 247 scoped_refptr<MailboxHolder> texture_mailbox_holder_; |
222 uint32 texture_target_; | 248 uint32 texture_target_; |
223 ReadPixelsCB read_pixels_cb_; | 249 ReadPixelsCB read_pixels_cb_; |
224 | 250 |
225 base::Closure no_longer_needed_cb_; | 251 base::Closure no_longer_needed_cb_; |
226 | 252 |
227 base::TimeDelta timestamp_; | 253 base::TimeDelta timestamp_; |
228 | 254 |
229 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 255 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
230 }; | 256 }; |
231 | 257 |
232 } // namespace media | 258 } // namespace media |
233 | 259 |
234 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 260 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |