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

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