| 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 "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic. | 53 NATIVE_TEXTURE = 6, // Native texture. Pixel-format agnostic. |
| 54 YV12J = 7, // JPEG color range version of YV12 | 54 YV12J = 7, // JPEG color range version of YV12 |
| 55 HISTOGRAM_MAX, // Must always be greatest. | 55 HISTOGRAM_MAX, // Must always be greatest. |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Returns the name of a Format as a string. | 58 // Returns the name of a Format as a string. |
| 59 static std::string FormatToString(Format format); | 59 static std::string FormatToString(Format format); |
| 60 | 60 |
| 61 // 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 |
| 62 // the frame are allocated but not initialized. | 62 // the frame are allocated but not initialized. |
| 63 // |coded_size| is the width and height of the frame data in pixels. | |
| 64 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | |
| 65 // any) is applied. | |
| 66 // |natural_size| is the width and height of the frame when the frame's aspect | |
| 67 // ratio is applied to |visible_rect|. | |
| 68 static scoped_refptr<VideoFrame> CreateFrame( | 63 static scoped_refptr<VideoFrame> CreateFrame( |
| 69 Format format, | 64 Format format, |
| 70 const gfx::Size& coded_size, | 65 const gfx::Size& coded_size, |
| 71 const gfx::Rect& visible_rect, | 66 const gfx::Rect& visible_rect, |
| 72 const gfx::Size& natural_size, | 67 const gfx::Size& natural_size, |
| 73 base::TimeDelta timestamp); | 68 base::TimeDelta timestamp); |
| 74 | 69 |
| 75 // Call prior to CreateFrame to ensure validity of frame configuration. Called | 70 // Call prior to CreateFrame to ensure validity of frame configuration. Called |
| 76 // automatically by VideoDecoderConfig::IsValidConfig(). | 71 // automatically by VideoDecoderConfig::IsValidConfig(). |
| 77 // TODO(scherkus): VideoDecoderConfig shouldn't call this method | 72 // TODO(scherkus): VideoDecoderConfig shouldn't call this method |
| 78 static bool IsValidConfig(Format format, const gfx::Size& coded_size, | 73 static bool IsValidConfig(Format format, const gfx::Size& coded_size, |
| 79 const gfx::Rect& visible_rect, | 74 const gfx::Rect& visible_rect, |
| 80 const gfx::Size& natural_size); | 75 const gfx::Size& natural_size); |
| 81 | 76 |
| 82 // CB to write pixels from the texture backing this frame into the | 77 // CB to write pixels from the texture backing this frame into the |
| 83 // |const SkBitmap&| parameter. | 78 // |const SkBitmap&| parameter. |
| 84 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; | 79 typedef base::Callback<void(const SkBitmap&)> ReadPixelsCB; |
| 85 | 80 |
| 86 // CB to be called on the mailbox backing this frame when the frame is | 81 // CB to be called on the mailbox backing this frame when the frame is |
| 87 // destroyed. | 82 // destroyed. |
| 88 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB; | 83 typedef base::Callback<void(scoped_ptr<gpu::MailboxHolder>)> ReleaseMailboxCB; |
| 89 | 84 |
| 90 // Wraps a native texture of the given parameters with a VideoFrame. The | 85 // 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|, | 86 // 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 | 87 // and |mailbox_holder_release_cb| will be called with |mailbox_holder| as the |
| 93 // argument when the VideoFrame is to be destroyed. | 88 // argument when the VideoFrame is to be destroyed. |
| 94 // |coded_size| is the width and height of the frame data in pixels. | |
| 95 // |visible_rect| is the visible portion of |coded_size|, after cropping (if | |
| 96 // any) is applied. | |
| 97 // |natural_size| is the width and height of the frame when the frame's aspect | |
| 98 // ratio is applied to |visible_rect|. | |
| 99 | |
| 100 // |read_pixels_cb| may be used to do (slow!) readbacks from the | 89 // |read_pixels_cb| may be used to do (slow!) readbacks from the |
| 101 // texture to main memory. | 90 // texture to main memory. |
| 102 static scoped_refptr<VideoFrame> WrapNativeTexture( | 91 static scoped_refptr<VideoFrame> WrapNativeTexture( |
| 103 scoped_ptr<gpu::MailboxHolder> mailbox_holder, | 92 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 104 const ReleaseMailboxCB& mailbox_holder_release_cb, | 93 const ReleaseMailboxCB& mailbox_holder_release_cb, |
| 105 const gfx::Size& coded_size, | 94 const gfx::Size& coded_size, |
| 106 const gfx::Rect& visible_rect, | 95 const gfx::Rect& visible_rect, |
| 107 const gfx::Size& natural_size, | 96 const gfx::Size& natural_size, |
| 108 base::TimeDelta timestamp, | 97 base::TimeDelta timestamp, |
| 109 const ReadPixelsCB& read_pixels_cb); | 98 const ReadPixelsCB& read_pixels_cb); |
| 110 | 99 |
| 111 // Read pixels from the native texture backing |*this| and write | 100 // Read pixels from the native texture backing |*this| and write |
| 112 // them to |pixels| as BGRA. |pixels| must point to a buffer at | 101 // them to |pixels| as BGRA. |pixels| must point to a buffer at |
| 113 // least as large as 4*visible_rect().width()*visible_rect().height(). | 102 // least as large as 4 * visible_rect().size().GetArea(). |
| 114 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); | 103 void ReadPixelsFromNativeTexture(const SkBitmap& pixels); |
| 115 | 104 |
| 116 // Wraps packed image data residing in a memory buffer with a VideoFrame. | 105 // Wraps packed image data residing in a memory buffer with a VideoFrame. |
| 117 // The image data resides in |data| and is assumed to be packed tightly in a | 106 // The image data resides in |data| and is assumed to be packed tightly in a |
| 118 // buffer of logical dimensions |coded_size| with the appropriate bit depth | 107 // buffer of logical dimensions |coded_size| with the appropriate bit depth |
| 119 // and plane count as given by |format|. The shared memory handle of the | 108 // and plane count as given by |format|. The shared memory handle of the |
| 120 // backing allocation, if present, can be passed in with |handle|. When the | 109 // backing allocation, if present, can be passed in with |handle|. When the |
| 121 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. | 110 // frame is destroyed, |no_longer_needed_cb.Run()| will be called. |
| 122 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( | 111 static scoped_refptr<VideoFrame> WrapExternalPackedMemory( |
| 123 Format format, | 112 Format format, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // Allocates a hole frame. | 161 // Allocates a hole frame. |
| 173 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); | 162 static scoped_refptr<VideoFrame> CreateHoleFrame(const gfx::Size& size); |
| 174 #endif // defined(VIDEO_HOLE) | 163 #endif // defined(VIDEO_HOLE) |
| 175 | 164 |
| 176 static size_t NumPlanes(Format format); | 165 static size_t NumPlanes(Format format); |
| 177 | 166 |
| 178 // Returns the required allocation size for a (tightly packed) frame of the | 167 // Returns the required allocation size for a (tightly packed) frame of the |
| 179 // given coded size and format. | 168 // given coded size and format. |
| 180 static size_t AllocationSize(Format format, const gfx::Size& coded_size); | 169 static size_t AllocationSize(Format format, const gfx::Size& coded_size); |
| 181 | 170 |
| 171 // Returns the plane size for a plane of the given coded size and format. |
| 172 static gfx::Size PlaneSize(Format format, |
| 173 size_t plane, |
| 174 const gfx::Size& coded_size); |
| 175 |
| 182 // Returns the required allocation size for a (tightly packed) plane of the | 176 // Returns the required allocation size for a (tightly packed) plane of the |
| 183 // given coded size and format. | 177 // given coded size and format. |
| 184 static size_t PlaneAllocationSize(Format format, | 178 static size_t PlaneAllocationSize(Format format, |
| 185 size_t plane, | 179 size_t plane, |
| 186 const gfx::Size& coded_size); | 180 const gfx::Size& coded_size); |
| 187 | 181 |
| 188 Format format() const { return format_; } | 182 Format format() const { return format_; } |
| 189 | 183 |
| 190 const gfx::Size& coded_size() const { return coded_size_; } | 184 const gfx::Size& coded_size() const { return coded_size_; } |
| 191 const gfx::Rect& visible_rect() const { return visible_rect_; } | 185 const gfx::Rect& visible_rect() const { return visible_rect_; } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 base::TimeDelta timestamp, | 230 base::TimeDelta timestamp, |
| 237 bool end_of_stream); | 231 bool end_of_stream); |
| 238 virtual ~VideoFrame(); | 232 virtual ~VideoFrame(); |
| 239 | 233 |
| 240 void AllocateYUV(); | 234 void AllocateYUV(); |
| 241 | 235 |
| 242 // Used to DCHECK() plane parameters. | 236 // Used to DCHECK() plane parameters. |
| 243 bool IsValidPlane(size_t plane) const; | 237 bool IsValidPlane(size_t plane) const; |
| 244 | 238 |
| 245 // Frame format. | 239 // Frame format. |
| 246 Format format_; | 240 const Format format_; |
| 247 | 241 |
| 248 // Width and height of the video frame. | 242 // Width and height of the video frame, in pixels. This must include pixel |
| 249 gfx::Size coded_size_; | 243 // data for the whole image; i.e. for YUV formats with subsampled chroma |
| 244 // planes, in the case that the visible portion of the image does not line up |
| 245 // on a sample boundary, |coded_size_| must be rounded up appropriately and |
| 246 // the pixel data provided for the odd pixels. |
| 247 const gfx::Size coded_size_; |
| 250 | 248 |
| 251 // Width, height, and offsets of the visible portion of the video frame. | 249 // Width, height, and offsets of the visible portion of the video frame. Must |
| 252 gfx::Rect visible_rect_; | 250 // be a subrect of |coded_size_|. Can be odd with respect to the sample |
| 251 // boundaries, e.g. for formats with subsampled chroma. |
| 252 const gfx::Rect visible_rect_; |
| 253 | 253 |
| 254 // Width and height of the visible portion of the video frame with aspect | 254 // Width and height of the visible portion of the video frame |
| 255 // ratio taken into account. | 255 // (|visible_rect_.size()|) with aspect ratio taken into account. |
| 256 gfx::Size natural_size_; | 256 const gfx::Size natural_size_; |
| 257 | 257 |
| 258 // 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 |
| 259 // of the surface divided by the horizontal sampling period. Note that | 259 // of the surface divided by the horizontal sampling period. Note that |
| 260 // strides can be negative. | 260 // strides can be negative. |
| 261 int32 strides_[kMaxPlanes]; | 261 int32 strides_[kMaxPlanes]; |
| 262 | 262 |
| 263 // Array of data pointers to each plane. | 263 // Array of data pointers to each plane. |
| 264 uint8* data_[kMaxPlanes]; | 264 uint8* data_[kMaxPlanes]; |
| 265 | 265 |
| 266 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. | 266 // Native texture mailbox, if this is a NATIVE_TEXTURE frame. |
| 267 scoped_ptr<gpu::MailboxHolder> mailbox_holder_; | 267 scoped_ptr<gpu::MailboxHolder> mailbox_holder_; |
| 268 ReleaseMailboxCB mailbox_holder_release_cb_; | 268 ReleaseMailboxCB mailbox_holder_release_cb_; |
| 269 ReadPixelsCB read_pixels_cb_; | 269 ReadPixelsCB read_pixels_cb_; |
| 270 | 270 |
| 271 // Shared memory handle, if this frame was allocated from shared memory. | 271 // Shared memory handle, if this frame was allocated from shared memory. |
| 272 base::SharedMemoryHandle shared_memory_handle_; | 272 base::SharedMemoryHandle shared_memory_handle_; |
| 273 | 273 |
| 274 base::Closure no_longer_needed_cb_; | 274 base::Closure no_longer_needed_cb_; |
| 275 | 275 |
| 276 base::TimeDelta timestamp_; | 276 base::TimeDelta timestamp_; |
| 277 | 277 |
| 278 const bool end_of_stream_; | 278 const bool end_of_stream_; |
| 279 | 279 |
| 280 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 280 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 } // namespace media | 283 } // namespace media |
| 284 | 284 |
| 285 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 285 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
| OLD | NEW |