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

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: cc2a95fe Android fixes. Created 7 years 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 49 #endif
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 // Wraps a native texture of the given parameters with a VideoFrame. The
112 // frame is destroyed |no_longer_needed_cb.Run()| will be called. 84 // backing of the VideoFrame is held in the mailbox held by |mailbox_holder|,
85 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the
86 // argument when the VideoFrame is to be destroyed.
113 // |coded_size| is the width and height of the frame data in pixels. 87 // |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 88 // |visible_rect| is the visible portion of |coded_size|, after cropping (if
115 // any) is applied. 89 // any) is applied.
116 // |natural_size| is the width and height of the frame when the frame's aspect 90 // |natural_size| is the width and height of the frame when the frame's aspect
117 // ratio is applied to |visible_rect|. 91 // ratio is applied to |visible_rect|.
118 92
119 // |read_pixels_cb| may be used to do (slow!) readbacks from the 93 // |read_pixels_cb| may be used to do (slow!) readbacks from the
120 // texture to main memory. 94 // texture to main memory.
121 static scoped_refptr<VideoFrame> WrapNativeTexture( 95 static scoped_refptr<VideoFrame> WrapNativeTexture(
122 scoped_ptr<MailboxHolder> mailbox_holder, 96 scoped_ptr<gpu::MailboxHolder> mailbox_holder,
123 uint32 texture_target, 97 const gpu::MailboxHolder::ReleaseCallback& mailbox_holder_release_cb,
124 const gfx::Size& coded_size, 98 const gfx::Size& coded_size,
125 const gfx::Rect& visible_rect, 99 const gfx::Rect& visible_rect,
126 const gfx::Size& natural_size, 100 const gfx::Size& natural_size,
127 base::TimeDelta timestamp, 101 base::TimeDelta timestamp,
128 const ReadPixelsCB& read_pixels_cb, 102 const ReadPixelsCB& read_pixels_cb);
129 const base::Closure& no_longer_needed_cb);
130 103
131 // Read pixels from the native texture backing |*this| and write 104 // Read pixels from the native texture backing |*this| and write
132 // 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
133 // least as large as 4*visible_rect().width()*visible_rect().height(). 106 // least as large as 4*visible_rect().width()*visible_rect().height().
134 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); 107 void ReadPixelsFromNativeTexture(const SkBitmap& pixels);
135 108
136 // Wraps packed image data residing in a memory buffer with a VideoFrame. 109 // 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 110 // 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 111 // 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 112 // and plane count as given by |format|. The shared memory handle of the
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // 184 //
212 // As opposed to stride(), row_bytes() refers to the bytes representing 185 // As opposed to stride(), row_bytes() refers to the bytes representing
213 // frame data scanlines (coded_size.width() pixels, without stride padding). 186 // frame data scanlines (coded_size.width() pixels, without stride padding).
214 int row_bytes(size_t plane) const; 187 int row_bytes(size_t plane) const;
215 int rows(size_t plane) const; 188 int rows(size_t plane) const;
216 189
217 // Returns pointer to the buffer for a given plane. The memory is owned by 190 // Returns pointer to the buffer for a given plane. The memory is owned by
218 // VideoFrame object and must not be freed by the caller. 191 // VideoFrame object and must not be freed by the caller.
219 uint8* data(size_t plane) const; 192 uint8* data(size_t plane) const;
220 193
221 // Returns the mailbox of the native texture wrapped by this frame. Only 194 // Returns the mailbox holder of the native texture wrapped by this frame.
222 // valid to call if this is a NATIVE_TEXTURE frame. Before using the 195 // Only valid to call if this is a NATIVE_TEXTURE frame. Before using the
223 // mailbox, the caller must wait for the included sync point. 196 // mailbox, the caller must wait for the included sync point.
224 MailboxHolder* texture_mailbox() const; 197 gpu::MailboxHolder* mailbox_holder() const;
225
226 // Returns the texture target. Only valid for NATIVE_TEXTURE frames.
227 uint32 texture_target() const;
228 198
229 // Returns the shared-memory handle, if present 199 // Returns the shared-memory handle, if present
230 base::SharedMemoryHandle shared_memory_handle() const; 200 base::SharedMemoryHandle shared_memory_handle() const;
231 201
232 // Returns true if this VideoFrame represents the end of the stream. 202 // Returns true if this VideoFrame represents the end of the stream.
233 bool end_of_stream() const { return end_of_stream_; } 203 bool end_of_stream() const { return end_of_stream_; }
234 204
235 base::TimeDelta GetTimestamp() const { 205 base::TimeDelta GetTimestamp() const {
236 return timestamp_; 206 return timestamp_;
237 } 207 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 244
275 // 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
276 // of the surface divided by the horizontal sampling period. Note that 246 // of the surface divided by the horizontal sampling period. Note that
277 // strides can be negative. 247 // strides can be negative.
278 int32 strides_[kMaxPlanes]; 248 int32 strides_[kMaxPlanes];
279 249
280 // Array of data pointers to each plane. 250 // Array of data pointers to each plane.
281 uint8* data_[kMaxPlanes]; 251 uint8* data_[kMaxPlanes];
282 252
283 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. 253 // Native texture mailbox, if this is a NATIVE_TEXTURE frame.
284 scoped_ptr<MailboxHolder> texture_mailbox_holder_; 254 scoped_ptr<gpu::MailboxHolder> mailbox_holder_;
285 uint32 texture_target_; 255 gpu::MailboxHolder::ReleaseCallback mailbox_holder_release_cb_;
286 ReadPixelsCB read_pixels_cb_; 256 ReadPixelsCB read_pixels_cb_;
287 257
288 // Shared memory handle, if this frame was allocated from shared memory. 258 // Shared memory handle, if this frame was allocated from shared memory.
289 base::SharedMemoryHandle shared_memory_handle_; 259 base::SharedMemoryHandle shared_memory_handle_;
290 260
291 base::Closure no_longer_needed_cb_; 261 base::Closure no_longer_needed_cb_;
292 262
293 base::TimeDelta timestamp_; 263 base::TimeDelta timestamp_;
294 264
295 const bool end_of_stream_; 265 const bool end_of_stream_;
296 266
297 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); 267 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame);
298 }; 268 };
299 269
300 } // namespace media 270 } // namespace media
301 271
302 #endif // MEDIA_BASE_VIDEO_FRAME_H_ 272 #endif // MEDIA_BASE_VIDEO_FRAME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698