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

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

Issue 105743004: Add gpu::MailboxHolder to hold state for a gpu::Mailbox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: c301e01d Rebase. Created 6 years, 11 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
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 "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 HOLE = 5, // Hole frame. 48 HOLE = 5, // Hole frame.
49 #endif // defined(VIDEO_HOLE) 49 #endif // defined(VIDEO_HOLE)
50 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic. 50 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic.
51 YV12J = 7, // JPEG color range version of YV12 51 YV12J = 7, // JPEG color range version of YV12
52 HISTOGRAM_MAX, // Must always be greatest. 52 HISTOGRAM_MAX, // Must always be greatest.
53 }; 53 };
54 54
55 // Returns the name of a Format as a string. 55 // Returns the name of a Format as a string.
56 static std::string FormatToString(Format format); 56 static std::string FormatToString(Format format);
57 57
58 // This class calls the TextureNoLongerNeededCallback when this class is
59 // destroyed. Users can query the current sync point associated with this
60 // mailbox with sync_point(), and should call Resync() with a new sync point
61 // to ensure the mailbox remains valid for the issued commands.
62 // valid for the issued commands.
63 class MEDIA_EXPORT MailboxHolder {
64 public:
65 typedef base::Callback<void(uint32 sync_point)>
66 TextureNoLongerNeededCallback;
67
68 MailboxHolder(const gpu::Mailbox& mailbox,
69 unsigned sync_point,
70 const TextureNoLongerNeededCallback& release_callback);
71 ~MailboxHolder();
72
73 const gpu::Mailbox& mailbox() const { return mailbox_; }
74 unsigned sync_point() const { return sync_point_; }
75
76 void Resync(unsigned sync_point) { sync_point_ = sync_point; }
77
78 private:
79
80 gpu::Mailbox mailbox_;
81 unsigned sync_point_;
82 TextureNoLongerNeededCallback release_callback_;
83 };
84
85
86 // Creates a new frame in system memory with given parameters. Buffers for 58 // Creates a new frame in system memory with given parameters. Buffers for
87 // the frame are allocated but not initialized. 59 // the frame are allocated but not initialized.
88 // |coded_size| is the width and height of the frame data in pixels. 60 // |coded_size| is the width and height of the frame data in pixels.
89 // |visible_rect| is the visible portion of |coded_size|, after cropping (if 61 // |visible_rect| is the visible portion of |coded_size|, after cropping (if
90 // any) is applied. 62 // any) is applied.
91 // |natural_size| is the width and height of the frame when the frame's aspect 63 // |natural_size| is the width and height of the frame when the frame's aspect
92 // ratio is applied to |visible_rect|. 64 // ratio is applied to |visible_rect|.
93 static scoped_refptr<VideoFrame> CreateFrame( 65 static scoped_refptr<VideoFrame> CreateFrame(
94 Format format, 66 Format format,
95 const gfx::Size& coded_size, 67 const gfx::Size& coded_size,
96 const gfx::Rect& visible_rect, 68 const gfx::Rect& visible_rect,
97 const gfx::Size& natural_size, 69 const gfx::Size& natural_size,
98 base::TimeDelta timestamp); 70 base::TimeDelta timestamp);
99 71
100 // Call prior to CreateFrame to ensure validity of frame configuration. Called 72 // Call prior to CreateFrame to ensure validity of frame configuration. Called
101 // automatically by VideoDecoderConfig::IsValidConfig(). 73 // automatically by VideoDecoderConfig::IsValidConfig().
102 // TODO(scherkus): VideoDecoderConfig shouldn't call this method 74 // TODO(scherkus): VideoDecoderConfig shouldn't call this method
103 static bool IsValidConfig(Format format, const gfx::Size& coded_size, 75 static bool IsValidConfig(Format format, const gfx::Size& coded_size,
104 const gfx::Rect& visible_rect, 76 const gfx::Rect& visible_rect,
105 const gfx::Size& natural_size); 77 const gfx::Size& natural_size);
106 78
107 // CB to write pixels from the texture backing this frame into the 79 // CB to write pixels from the texture backing this frame into the
108 // |const SkBitmap&| parameter. 80 // |const SkBitmap&| parameter.
109 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; 81 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB;
110 82
111 // Wraps a native texture of the given parameters with a VideoFrame. When the 83 // CB to be called on the mailbox backing this frame when the frame is
112 // frame is destroyed |no_longer_needed_cb.Run()| will be called. 84 // destroyed.
85 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB;
86
87 // Wraps a native texture of the given parameters with a VideoFrame. The
88 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|,
89 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the
90 // argument when the VideoFrame is to be destroyed.
113 // |coded_size| is the width and height of the frame data in pixels. 91 // |coded_size| is the width and height of the frame data in pixels.
114 // |visible_rect| is the visible portion of |coded_size|, after cropping (if 92 // |visible_rect| is the visible portion of |coded_size|, after cropping (if
115 // any) is applied. 93 // any) is applied.
116 // |natural_size| is the width and height of the frame when the frame's aspect 94 // |natural_size| is the width and height of the frame when the frame's aspect
117 // ratio is applied to |visible_rect|. 95 // ratio is applied to |visible_rect|.
118 96
119 // |read_pixels_cb| may be used to do (slow!) readbacks from the 97 // |read_pixels_cb| may be used to do (slow!) readbacks from the
120 // texture to main memory. 98 // texture to main memory.
121 static scoped_refptr<VideoFrame> WrapNativeTexture( 99 static scoped_refptr<VideoFrame> WrapNativeTexture(
122 scoped_ptr<MailboxHolder> mailbox_holder, 100 scoped_ptr<gpu::MailboxHolder> mailbox_holder,
123 uint32 texture_target, 101 const ReleaseMailboxCB& mailbox_holder_release_cb,
124 const gfx::Size& coded_size, 102 const gfx::Size& coded_size,
125 const gfx::Rect& visible_rect, 103 const gfx::Rect& visible_rect,
126 const gfx::Size& natural_size, 104 const gfx::Size& natural_size,
127 base::TimeDelta timestamp, 105 base::TimeDelta timestamp,
128 const ReadPixelsCB& read_pixels_cb, 106 const ReadPixelsCB& read_pixels_cb);
129 const base::Closure& no_longer_needed_cb);
130 107
131 // Read pixels from the native texture backing |*this| and write 108 // Read pixels from the native texture backing |*this| and write
132 // them to |pixels| as BGRA. |pixels| must point to a buffer at 109 // them to |pixels| as BGRA. |pixels| must point to a buffer at
133 // least as large as 4*visible_rect().width()*visible_rect().height(). 110 // least as large as 4*visible_rect().width()*visible_rect().height().
134 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); 111 void ReadPixelsFromNativeTexture(const SkBitmap& pixels);
135 112
136 // Wraps packed image data residing in a memory buffer with a VideoFrame. 113 // Wraps packed image data residing in a memory buffer with a VideoFrame.
137 // The image data resides in |data| and is assumed to be packed tightly in a 114 // The image data resides in |data| and is assumed to be packed tightly in a
138 // buffer of logical dimensions |coded_size| with the appropriate bit depth 115 // buffer of logical dimensions |coded_size| with the appropriate bit depth
139 // and plane count as given by |format|. The shared memory handle of the 116 // and plane count as given by |format|. The shared memory handle of the
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // 194 //
218 // As opposed to stride(), row_bytes() refers to the bytes representing 195 // As opposed to stride(), row_bytes() refers to the bytes representing
219 // frame data scanlines (coded_size.width() pixels, without stride padding). 196 // frame data scanlines (coded_size.width() pixels, without stride padding).
220 int row_bytes(size_t plane) const; 197 int row_bytes(size_t plane) const;
221 int rows(size_t plane) const; 198 int rows(size_t plane) const;
222 199
223 // Returns pointer to the buffer for a given plane. The memory is owned by 200 // Returns pointer to the buffer for a given plane. The memory is owned by
224 // VideoFrame object and must not be freed by the caller. 201 // VideoFrame object and must not be freed by the caller.
225 uint8* data(size_t plane) const; 202 uint8* data(size_t plane) const;
226 203
227 // Returns the mailbox of the native texture wrapped by this frame. Only 204 // Returns the mailbox holder of the native texture wrapped by this frame.
228 // valid to call if this is a NATIVE_TEXTURE frame. Before using the 205 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the
229 // mailbox, the caller must wait for the included sync point. 206 // mailbox, the caller must wait for the included sync point.
230 MailboxHolder* texture_mailbox() const; 207 gpu::MailboxHolder* mailbox_holder() const;
231
232 // Returns the texture target. Only valid for NATIVE_TEXTURE frames.
233 uint32 texture_target() const;
234 208
235 // Returns the shared-memory handle, if present 209 // Returns the shared-memory handle, if present
236 base::SharedMemoryHandle shared_memory_handle() const; 210 base::SharedMemoryHandle shared_memory_handle() const;
237 211
238 // Returns true if this VideoFrame represents the end of the stream. 212 // Returns true if this VideoFrame represents the end of the stream.
239 bool end_of_stream() const { return end_of_stream_; } 213 bool end_of_stream() const { return end_of_stream_; }
240 214
241 base::TimeDelta GetTimestamp() const { 215 base::TimeDelta GetTimestamp() const {
242 return timestamp_; 216 return timestamp_;
243 } 217 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 254
281 // Array of strides for each plane, typically greater or equal to the width 255 // Array of strides for each plane, typically greater or equal to the width
282 // of the surface divided by the horizontal sampling period. Note that 256 // of the surface divided by the horizontal sampling period. Note that
283 // strides can be negative. 257 // strides can be negative.
284 int32 strides_[kMaxPlanes]; 258 int32 strides_[kMaxPlanes];
285 259
286 // Array of data pointers to each plane. 260 // Array of data pointers to each plane.
287 uint8* data_[kMaxPlanes]; 261 uint8* data_[kMaxPlanes];
288 262
289 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. 263 // Native texture mailbox, if this is a NATIVE_TEXTURE frame.
290 scoped_ptr<MailboxHolder> texture_mailbox_holder_; 264 scoped_ptr<gpu::MailboxHolder> mailbox_holder_;
danakj 2014/01/06 20:13:42 There's really no reason to use a scoped_ptr here
sheu 2014/01/06 22:44:44 I made this a pointer so things that don't have a
danakj 2014/01/06 23:28:33 Ok, sure. Using a scoped_ptr here to avoid the siz
291 uint32 texture_target_; 265 ReleaseMailboxCB mailbox_holder_release_cb_;
292 ReadPixelsCB read_pixels_cb_; 266 ReadPixelsCB read_pixels_cb_;
293 267
294 // Shared memory handle, if this frame was allocated from shared memory. 268 // Shared memory handle, if this frame was allocated from shared memory.
295 base::SharedMemoryHandle shared_memory_handle_; 269 base::SharedMemoryHandle shared_memory_handle_;
296 270
297 base::Closure no_longer_needed_cb_; 271 base::Closure no_longer_needed_cb_;
298 272
299 base::TimeDelta timestamp_; 273 base::TimeDelta timestamp_;
300 274
301 const bool end_of_stream_; 275 const bool end_of_stream_;
302 276
303 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); 277 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);
304 }; 278 };
305 279
306 } // namespace media 280 } // namespace media
307 281
308 #endif // MEDIA_BASE_VIDEO_FRAME_H_ 282 #endif // MEDIA_BASE_VIDEO_FRAME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698