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

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

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

Powered by Google App Engine
This is Rietveld 408576698