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

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

Issue 14199002: Send hardware video frames with mailboxes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: video-mailbox: virtualandroid Created 7 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 | Annotate | Revision Log
« no previous file with comments | « media/DEPS ('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 "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
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 // This class calls the TextureNoLongerNeededCallback when the last reference
56 // on the class is destroyed. The VideoFrame holds a reference to the mailbox
57 // but anyone else who queries the mailbox should also hold a reference while
58 // it is uses the mailbox, to ensure it remains valid. When finished with the
59 // mailbox, call Return() with a new sync point, to ensure the mailbox remains
60 // valid for the issued commands.
61 class MEDIA_EXPORT MailboxHolder
62 : public base::RefCountedThreadSafe<MailboxHolder> {
63 public:
64 typedef base::Callback<void(uint32 sync_point)>
65 TextureNoLongerNeededCallback;
66
67 MailboxHolder(const gpu::Mailbox& mailbox,
68 unsigned sync_point,
69 const TextureNoLongerNeededCallback& release_callback);
70
71 const gpu::Mailbox& mailbox() const { return mailbox_; }
72 unsigned sync_point() const { return sync_point_; }
73
74 void Return(unsigned sync_point) { sync_point_ = sync_point; }
75
76 private:
77 friend class base::RefCountedThreadSafe<MailboxHolder>;
78 ~MailboxHolder();
79
80 gpu::Mailbox mailbox_;
81 unsigned sync_point_;
82 TextureNoLongerNeededCallback release_callback_;
83 };
84
85
54 // Creates a new frame in system memory with given parameters. Buffers for 86 // Creates a new frame in system memory with given parameters. Buffers for
55 // the frame are allocated but not initialized. 87 // the frame are allocated but not initialized.
56 // |coded_size| is the width and height of the frame data in pixels. 88 // |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 89 // |visible_rect| is the visible portion of |coded_size|, after cropping (if
58 // any) is applied. 90 // any) is applied.
59 // |natural_size| is the width and height of the frame when the frame's aspect 91 // |natural_size| is the width and height of the frame when the frame's aspect
60 // ratio is applied to |visible_rect|. 92 // ratio is applied to |visible_rect|.
61 static scoped_refptr<VideoFrame> CreateFrame( 93 static scoped_refptr<VideoFrame> CreateFrame(
62 Format format, 94 Format format,
63 const gfx::Size& coded_size, 95 const gfx::Size& coded_size,
(...skipping 16 matching lines...) Expand all
80 // frame is destroyed |no_longer_needed_cb.Run()| will be called. 112 // 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. 113 // |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 114 // |visible_rect| is the visible portion of |coded_size|, after cropping (if
83 // any) is applied. 115 // any) is applied.
84 // |natural_size| is the width and height of the frame when the frame's aspect 116 // |natural_size| is the width and height of the frame when the frame's aspect
85 // ratio is applied to |visible_rect|. 117 // ratio is applied to |visible_rect|.
86 118
87 // |read_pixels_cb| may be used to do (slow!) readbacks from the 119 // |read_pixels_cb| may be used to do (slow!) readbacks from the
88 // texture to main memory. 120 // texture to main memory.
89 static scoped_refptr<VideoFrame> WrapNativeTexture( 121 static scoped_refptr<VideoFrame> WrapNativeTexture(
90 uint32 texture_id, 122 const scoped_refptr<MailboxHolder>& mailbox_holder,
91 uint32 texture_target, 123 uint32 texture_target,
92 const gfx::Size& coded_size, 124 const gfx::Size& coded_size,
93 const gfx::Rect& visible_rect, 125 const gfx::Rect& visible_rect,
94 const gfx::Size& natural_size, 126 const gfx::Size& natural_size,
95 base::TimeDelta timestamp, 127 base::TimeDelta timestamp,
96 const ReadPixelsCB& read_pixels_cb, 128 const ReadPixelsCB& read_pixels_cb,
97 const base::Closure& no_longer_needed_cb); 129 const base::Closure& no_longer_needed_cb);
98 130
99 // Read pixels from the native texture backing |*this| and write 131 // Read pixels from the native texture backing |*this| and write
100 // them to |pixels| as BGRA. |pixels| must point to a buffer at 132 // them to |pixels| as BGRA. |pixels| must point to a buffer at
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // 183 //
152 // As opposed to stride(), row_bytes() refers to the bytes representing 184 // As opposed to stride(), row_bytes() refers to the bytes representing
153 // frame data scanlines (coded_size.width() pixels, without stride padding). 185 // frame data scanlines (coded_size.width() pixels, without stride padding).
154 int row_bytes(size_t plane) const; 186 int row_bytes(size_t plane) const;
155 int rows(size_t plane) const; 187 int rows(size_t plane) const;
156 188
157 // Returns pointer to the buffer for a given plane. The memory is owned by 189 // 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. 190 // VideoFrame object and must not be freed by the caller.
159 uint8* data(size_t plane) const; 191 uint8* data(size_t plane) const;
160 192
161 // Returns the ID of the native texture wrapped by this frame. Only valid to 193 // Returns the mailbox of the native texture wrapped by this frame. Only
162 // call if this is a NATIVE_TEXTURE frame. 194 // valid to call if this is a NATIVE_TEXTURE frame. Before using the
163 uint32 texture_id() const; 195 // mailbox, the caller must wait for the included sync point.
196 const scoped_refptr<MailboxHolder>& texture_mailbox() const;
164 197
165 // Returns the texture target. Only valid for NATIVE_TEXTURE frames. 198 // Returns the texture target. Only valid for NATIVE_TEXTURE frames.
166 uint32 texture_target() const; 199 uint32 texture_target() const;
167 200
168 // Returns true if this VideoFrame represents the end of the stream. 201 // Returns true if this VideoFrame represents the end of the stream.
169 bool IsEndOfStream() const; 202 bool IsEndOfStream() const;
170 203
171 base::TimeDelta GetTimestamp() const { 204 base::TimeDelta GetTimestamp() const {
172 return timestamp_; 205 return timestamp_;
173 } 206 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 gfx::Size natural_size_; 243 gfx::Size natural_size_;
211 244
212 // Array of strides for each plane, typically greater or equal to the width 245 // 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 246 // of the surface divided by the horizontal sampling period. Note that
214 // strides can be negative. 247 // strides can be negative.
215 int32 strides_[kMaxPlanes]; 248 int32 strides_[kMaxPlanes];
216 249
217 // Array of data pointers to each plane. 250 // Array of data pointers to each plane.
218 uint8* data_[kMaxPlanes]; 251 uint8* data_[kMaxPlanes];
219 252
220 // Native texture ID, if this is a NATIVE_TEXTURE frame. 253 // Native texture mailbox, if this is a NATIVE_TEXTURE frame.
221 uint32 texture_id_; 254 scoped_refptr<MailboxHolder> texture_mailbox_holder_;
222 uint32 texture_target_; 255 uint32 texture_target_;
223 ReadPixelsCB read_pixels_cb_; 256 ReadPixelsCB read_pixels_cb_;
224 257
225 base::Closure no_longer_needed_cb_; 258 base::Closure no_longer_needed_cb_;
226 259
227 base::TimeDelta timestamp_; 260 base::TimeDelta timestamp_;
228 261
229 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); 262 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);
230 }; 263 };
231 264
232 } // namespace media 265 } // namespace media
233 266
234 #endif // MEDIA_BASE_VIDEO_FRAME_H_ 267 #endif // MEDIA_BASE_VIDEO_FRAME_H_
OLDNEW
« no previous file with comments | « media/DEPS ('k') | media/base/video_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698