Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 22 matching lines...) Expand all Loading... | |
| 42 YV12 = 6, // 12bpp YVU planar 1x1 Y, 2x2 VU samples | 43 YV12 = 6, // 12bpp YVU planar 1x1 Y, 2x2 VU samples |
| 43 YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples | 44 YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples |
| 44 EMPTY = 9, // An empty frame. | 45 EMPTY = 9, // An empty frame. |
| 45 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | 46 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
| 46 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. | 47 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. |
| 47 #if defined(GOOGLE_TV) | 48 #if defined(GOOGLE_TV) |
| 48 HOLE = 13, // Hole frame. | 49 HOLE = 13, // Hole frame. |
| 49 #endif | 50 #endif |
| 50 }; | 51 }; |
| 51 | 52 |
| 53 typedef base::Callback<void(uint32 sync_point)> TextureNoLongerNeededCallback; | |
| 54 | |
| 52 // Creates a new frame in system memory with given parameters. Buffers for | 55 // Creates a new frame in system memory with given parameters. Buffers for |
| 53 // the frame are allocated but not initialized. | 56 // the frame are allocated but not initialized. |
| 54 // |coded_size| is the width and height of the frame data in pixels. | 57 // |coded_size| is the width and height of the frame data in pixels. |
| 55 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | 58 // |visible_rect| is the visible portion of |coded_size|, after cropping (if |
| 56 // any) is applied. | 59 // any) is applied. |
| 57 // |natural_size| is the width and height of the frame when the frame's aspect | 60 // |natural_size| is the width and height of the frame when the frame's aspect |
| 58 // ratio is applied to |visible_rect|. | 61 // ratio is applied to |visible_rect|. |
| 59 static scoped_refptr<VideoFrame> CreateFrame( | 62 static scoped_refptr<VideoFrame> CreateFrame( |
| 60 Format format, | 63 Format format, |
| 61 const gfx::Size& coded_size, | 64 const gfx::Size& coded_size, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 78 // frame is destroyed |no_longer_needed_cb.Run()| will be called. | 81 // frame is destroyed |no_longer_needed_cb.Run()| will be called. |
| 79 // |coded_size| is the width and height of the frame data in pixels. | 82 // |coded_size| is the width and height of the frame data in pixels. |
| 80 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | 83 // |visible_rect| is the visible portion of |coded_size|, after cropping (if |
| 81 // any) is applied. | 84 // any) is applied. |
| 82 // |natural_size| is the width and height of the frame when the frame's aspect | 85 // |natural_size| is the width and height of the frame when the frame's aspect |
| 83 // ratio is applied to |visible_rect|. | 86 // ratio is applied to |visible_rect|. |
| 84 | 87 |
| 85 // |read_pixels_cb| may be used to do (slow!) readbacks from the | 88 // |read_pixels_cb| may be used to do (slow!) readbacks from the |
| 86 // texture to main memory. | 89 // texture to main memory. |
| 87 static scoped_refptr<VideoFrame> WrapNativeTexture( | 90 static scoped_refptr<VideoFrame> WrapNativeTexture( |
| 91 #ifdef VIDEO_FRAME_MAILBOX | |
| 92 const gpu::Mailbox& texture_mailbox, | |
| 93 uint32 texture_mailbox_sync_point, | |
| 94 #else | |
| 88 uint32 texture_id, | 95 uint32 texture_id, |
| 96 #endif | |
| 89 uint32 texture_target, | 97 uint32 texture_target, |
| 90 const gfx::Size& coded_size, | 98 const gfx::Size& coded_size, |
| 91 const gfx::Rect& visible_rect, | 99 const gfx::Rect& visible_rect, |
| 92 const gfx::Size& natural_size, | 100 const gfx::Size& natural_size, |
| 93 base::TimeDelta timestamp, | 101 base::TimeDelta timestamp, |
| 94 const ReadPixelsCB& read_pixels_cb, | 102 const ReadPixelsCB& read_pixels_cb, |
| 103 const TextureNoLongerNeededCallback& texture_no_longer_needed_cb, | |
|
scherkus (not reviewing)
2013/04/17 20:09:34
OOC think we can remove the non-mailbox path after
danakj
2013/04/17 20:12:37
Yes absolutely. The no_longer_needed_cb is used fo
scherkus (not reviewing)
2013/04/17 20:16:58
Slick!
| |
| 95 const base::Closure& no_longer_needed_cb); | 104 const base::Closure& no_longer_needed_cb); |
| 96 | 105 |
| 97 // Read pixels from the native texture backing |*this| and write | 106 // Read pixels from the native texture backing |*this| and write |
| 98 // them to |pixels| as BGRA. |pixels| must point to a buffer at | 107 // them to |pixels| as BGRA. |pixels| must point to a buffer at |
| 99 // least as large as 4*visible_rect().width()*visible_rect().height(). | 108 // least as large as 4*visible_rect().width()*visible_rect().height(). |
| 100 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); | 109 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); |
| 101 | 110 |
| 102 // Wraps external YUV data of the given parameters with a VideoFrame. | 111 // Wraps external YUV data of the given parameters with a VideoFrame. |
| 103 // The returned VideoFrame does not own the data passed in. When the frame | 112 // The returned VideoFrame does not own the data passed in. When the frame |
| 104 // is destroyed |no_longer_needed_cb.Run()| will be called. | 113 // is destroyed |no_longer_needed_cb.Run()| will be called. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 // | 158 // |
| 150 // As opposed to stride(), row_bytes() refers to the bytes representing | 159 // As opposed to stride(), row_bytes() refers to the bytes representing |
| 151 // frame data scanlines (coded_size.width() pixels, without stride padding). | 160 // frame data scanlines (coded_size.width() pixels, without stride padding). |
| 152 int row_bytes(size_t plane) const; | 161 int row_bytes(size_t plane) const; |
| 153 int rows(size_t plane) const; | 162 int rows(size_t plane) const; |
| 154 | 163 |
| 155 // Returns pointer to the buffer for a given plane. The memory is owned by | 164 // Returns pointer to the buffer for a given plane. The memory is owned by |
| 156 // VideoFrame object and must not be freed by the caller. | 165 // VideoFrame object and must not be freed by the caller. |
| 157 uint8* data(size_t plane) const; | 166 uint8* data(size_t plane) const; |
| 158 | 167 |
| 159 // Returns the ID of the native texture wrapped by this frame. Only valid to | 168 #ifdef VIDEO_FRAME_MAILBOX |
| 160 // call if this is a NATIVE_TEXTURE frame. | 169 // Returns the mailbox of the native texture wrapped by this frame. Only |
| 161 uint32 texture_id() const; | 170 // valid to call if this is a NATIVE_TEXTURE frame. |
| 171 const gpu::Mailbox& texture_mailbox() const; | |
| 172 | |
| 173 // Before using the texture_mailbox, the consumer must wait on this sync | |
| 174 // point. Only valid to call if this is a NATIVE_TEXTURE frame. | |
| 175 uint32 texture_mailbox_sync_point() const; | |
| 176 | |
| 177 // Reset the sync point to a new value. Only valid to call if this is a | |
| 178 // NATIVE_TEXTURE frame. | |
| 179 void set_texture_mailbox_sync_point(uint32 sync_point); | |
| 180 #else | |
| 181 // Returns the native texture wrapped by this frame. Only valid to call if | |
| 182 // this is a NATIVE_TEXTURE frame. | |
| 183 uint32 texture_id() const; | |
| 184 #endif | |
| 162 | 185 |
| 163 // Returns the texture target. Only valid for NATIVE_TEXTURE frames. | 186 // Returns the texture target. Only valid for NATIVE_TEXTURE frames. |
| 164 uint32 texture_target() const; | 187 uint32 texture_target() const; |
| 165 | 188 |
| 166 // Returns true if this VideoFrame represents the end of the stream. | 189 // Returns true if this VideoFrame represents the end of the stream. |
| 167 bool IsEndOfStream() const; | 190 bool IsEndOfStream() const; |
| 168 | 191 |
| 169 base::TimeDelta GetTimestamp() const { | 192 base::TimeDelta GetTimestamp() const { |
| 170 return timestamp_; | 193 return timestamp_; |
| 171 } | 194 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 gfx::Size natural_size_; | 231 gfx::Size natural_size_; |
| 209 | 232 |
| 210 // Array of strides for each plane, typically greater or equal to the width | 233 // Array of strides for each plane, typically greater or equal to the width |
| 211 // of the surface divided by the horizontal sampling period. Note that | 234 // of the surface divided by the horizontal sampling period. Note that |
| 212 // strides can be negative. | 235 // strides can be negative. |
| 213 int32 strides_[kMaxPlanes]; | 236 int32 strides_[kMaxPlanes]; |
| 214 | 237 |
| 215 // Array of data pointers to each plane. | 238 // Array of data pointers to each plane. |
| 216 uint8* data_[kMaxPlanes]; | 239 uint8* data_[kMaxPlanes]; |
| 217 | 240 |
| 218 // Native texture ID, if this is a NATIVE_TEXTURE frame. | 241 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. |
| 242 #ifdef VIDEO_FRAME_MAILBOX | |
| 243 gpu::Mailbox texture_mailbox_; | |
| 244 uint32 texture_mailbox_sync_point_; | |
| 245 #else | |
| 219 uint32 texture_id_; | 246 uint32 texture_id_; |
| 247 #endif | |
| 220 uint32 texture_target_; | 248 uint32 texture_target_; |
| 221 ReadPixelsCB read_pixels_cb_; | 249 ReadPixelsCB read_pixels_cb_; |
| 250 TextureNoLongerNeededCallback texture_no_longer_needed_cb_; | |
| 222 | 251 |
| 223 base::Closure no_longer_needed_cb_; | 252 base::Closure no_longer_needed_cb_; |
| 224 | 253 |
| 225 base::TimeDelta timestamp_; | 254 base::TimeDelta timestamp_; |
| 226 | 255 |
| 227 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 256 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
| 228 }; | 257 }; |
| 229 | 258 |
| 230 } // namespace media | 259 } // namespace media |
| 231 | 260 |
| 232 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 261 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
| OLD | NEW |