Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "media/base/buffers.h" | 9 #include "media/base/buffers.h" |
| 9 | 10 |
| 10 namespace media { | 11 namespace media { |
| 11 | 12 |
| 12 class MEDIA_EXPORT VideoFrame : public StreamSample { | 13 class MEDIA_EXPORT VideoFrame : public StreamSample { |
| 13 public: | 14 public: |
| 14 static const size_t kMaxPlanes = 3; | 15 static const size_t kMaxPlanes = 3; |
| 15 | 16 |
| 16 static const size_t kNumRGBPlanes = 1; | 17 static const size_t kNumRGBPlanes = 1; |
| 17 static const size_t kRGBPlane = 0; | 18 static const size_t kRGBPlane = 0; |
| 18 | 19 |
| 19 static const size_t kNumYUVPlanes = 3; | 20 static const size_t kNumYUVPlanes = 3; |
| 20 static const size_t kNumNV12Planes = 2; | 21 static const size_t kNumNV12Planes = 2; |
| 21 static const size_t kYPlane = 0; | 22 static const size_t kYPlane = 0; |
| 22 static const size_t kUPlane = 1; | 23 static const size_t kUPlane = 1; |
| 23 static const size_t kVPlane = 2; | 24 static const size_t kVPlane = 2; |
| 24 | 25 |
| 25 // Surface formats roughly based on FOURCC labels, see: | 26 // Surface formats roughly based on FOURCC labels, see: |
| 26 // http://www.fourcc.org/rgb.php | 27 // http://www.fourcc.org/rgb.php |
| 27 // http://www.fourcc.org/yuv.php | 28 // http://www.fourcc.org/yuv.php |
| 29 // Keep in sync with WebKit::WebVideoFrame! | |
|
scherkus (not reviewing)
2011/12/06 00:27:44
arg!
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done!
| |
| 28 enum Format { | 30 enum Format { |
| 29 INVALID, // Invalid format value. Used for error reporting. | 31 INVALID, // Invalid format value. Used for error reporting. |
| 30 RGB555, // 16bpp RGB packed 5:5:5 | 32 RGB555, // 16bpp RGB packed 5:5:5 |
| 31 RGB565, // 16bpp RGB packed 5:6:5 | 33 RGB565, // 16bpp RGB packed 5:6:5 |
| 32 RGB24, // 24bpp RGB packed 8:8:8 | 34 RGB24, // 24bpp RGB packed 8:8:8 |
| 33 RGB32, // 32bpp RGB packed with extra byte 8:8:8 | 35 RGB32, // 32bpp RGB packed with extra byte 8:8:8 |
| 34 RGBA, // 32bpp RGBA packed 8:8:8:8 | 36 RGBA, // 32bpp RGBA packed 8:8:8:8 |
| 35 YV12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples | 37 YV12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples |
| 36 YV16, // 16bpp YVU planar 1x1 Y, 2x1 VU samples | 38 YV16, // 16bpp YVU planar 1x1 Y, 2x1 VU samples |
| 37 NV12, // 12bpp YVU planar 1x1 Y, 2x2 UV interleaving samples | 39 NV12, // 12bpp YVU planar 1x1 Y, 2x2 UV interleaving samples |
| 38 EMPTY, // An empty frame. | 40 EMPTY, // An empty frame. |
| 39 ASCII, // A frame with ASCII content. For testing only. | 41 ASCII, // A frame with ASCII content. For testing only. |
| 40 I420, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | 42 I420, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
| 43 NATIVE_TEXTURE, // Opaque native texture. Pixel-format agnostic. | |
| 41 }; | 44 }; |
| 42 | 45 |
| 43 // Creates a new frame in system memory with given parameters. Buffers for | 46 // Creates a new frame in system memory with given parameters. Buffers for |
| 44 // the frame are allocated but not initialized. | 47 // the frame are allocated but not initialized. |
| 45 static scoped_refptr<VideoFrame> CreateFrame( | 48 static scoped_refptr<VideoFrame> CreateFrame( |
| 46 Format format, | 49 Format format, |
| 47 size_t width, | 50 size_t width, |
| 48 size_t height, | 51 size_t height, |
| 49 base::TimeDelta timestamp, | 52 base::TimeDelta timestamp, |
| 50 base::TimeDelta duration); | 53 base::TimeDelta duration); |
| 51 | 54 |
| 55 // Wraps a native texture of the given parameters with a VideoFrame. When the | |
| 56 // frame is destroyed |no_longer_needed.Run()| will be called. | |
| 57 static scoped_refptr<VideoFrame> WrapNativeTexture( | |
| 58 uint32 texture_id, | |
| 59 size_t width, | |
| 60 size_t height, | |
| 61 base::TimeDelta timestamp, | |
| 62 base::TimeDelta duration, | |
| 63 const base::Closure& no_longer_needed); | |
| 64 | |
| 52 // Creates a frame with format equals to VideoFrame::EMPTY, width, height | 65 // Creates a frame with format equals to VideoFrame::EMPTY, width, height |
| 53 // timestamp and duration are all 0. | 66 // timestamp and duration are all 0. |
| 54 static scoped_refptr<VideoFrame> CreateEmptyFrame(); | 67 static scoped_refptr<VideoFrame> CreateEmptyFrame(); |
| 55 | 68 |
| 56 // Allocates YV12 frame based on |width| and |height|, and sets its data to | 69 // Allocates YV12 frame based on |width| and |height|, and sets its data to |
| 57 // the YUV equivalent of RGB(0,0,0). | 70 // the YUV equivalent of RGB(0,0,0). |
| 58 static scoped_refptr<VideoFrame> CreateBlackFrame(int width, int height); | 71 static scoped_refptr<VideoFrame> CreateBlackFrame(int width, int height); |
| 59 | 72 |
| 60 Format format() const { return format_; } | 73 Format format() const { return format_; } |
| 61 | 74 |
| 62 size_t width() const { return width_; } | 75 size_t width() const { return width_; } |
| 63 | 76 |
| 64 size_t height() const { return height_; } | 77 size_t height() const { return height_; } |
| 65 | 78 |
| 66 size_t planes() const { return planes_; } | 79 size_t planes() const { return planes_; } |
| 67 | 80 |
| 68 int stride(size_t plane) const; | 81 int stride(size_t plane) const; |
| 69 | 82 |
| 70 // Returns the number of bytes per row and number of rows for a given plane. | 83 // Returns the number of bytes per row and number of rows for a given plane. |
| 71 // | 84 // |
| 72 // As opposed to stride(), row_bytes() refers to the bytes representing | 85 // As opposed to stride(), row_bytes() refers to the bytes representing |
| 73 // visible pixels. | 86 // visible pixels. |
| 74 int row_bytes(size_t plane) const; | 87 int row_bytes(size_t plane) const; |
| 75 int rows(size_t plane) const; | 88 int rows(size_t plane) const; |
| 76 | 89 |
| 77 // Returns pointer to the buffer for a given plane. The memory is owned by | 90 // Returns pointer to the buffer for a given plane. The memory is owned by |
| 78 // VideoFrame object and must not be freed by the caller. | 91 // VideoFrame object and must not be freed by the caller. |
| 79 uint8* data(size_t plane) const; | 92 uint8* data(size_t plane) const; |
| 80 | 93 |
| 94 // Returns the ID of the native texture wrapped by this frame. Only valid to | |
| 95 // call if this is a NATIVE_TEXTURE frame. | |
| 96 uint32 texture_id() const; | |
| 97 | |
| 81 // StreamSample interface. | 98 // StreamSample interface. |
| 82 virtual bool IsEndOfStream() const OVERRIDE; | 99 virtual bool IsEndOfStream() const OVERRIDE; |
| 83 | 100 |
| 84 protected: | 101 private: |
| 85 // Clients must use the static CreateFrame() method to create a new frame. | 102 // Clients must use the static CreateFrame() method to create a new frame. |
| 86 VideoFrame(Format format, | 103 VideoFrame(Format format, |
| 87 size_t video_width, | 104 size_t video_width, |
| 88 size_t video_height); | 105 size_t video_height, |
| 106 base::TimeDelta timestamp, | |
| 107 base::TimeDelta duration); | |
| 89 | 108 |
| 90 virtual ~VideoFrame(); | 109 virtual ~VideoFrame(); |
| 91 | 110 |
| 92 // Used internally by CreateFrame(). | 111 // Used internally by CreateFrame(). |
| 93 void AllocateRGB(size_t bytes_per_pixel); | 112 void AllocateRGB(size_t bytes_per_pixel); |
| 94 void AllocateYUV(); | 113 void AllocateYUV(); |
| 95 | 114 |
| 96 // Used to DCHECK() plane parameters. | 115 // Used to DCHECK() plane parameters. |
| 97 bool IsValidPlane(size_t plane) const; | 116 bool IsValidPlane(size_t plane) const; |
| 98 | 117 |
| 99 // Frame format. | 118 // Frame format. |
| 100 Format format_; | 119 Format format_; |
| 101 | 120 |
| 102 // Width and height of surface. | 121 // Width and height of surface. |
| 103 size_t width_; | 122 size_t width_; |
| 104 size_t height_; | 123 size_t height_; |
| 105 | 124 |
| 106 // Number of planes, typically 1 for packed RGB formats and 3 for planar | 125 // Number of planes, typically 1 for packed RGB formats, 3 for planar |
| 107 // YUV formats. | 126 // YUV formats, and 0 for native textures. |
| 108 size_t planes_; | 127 size_t planes_; |
| 109 | 128 |
| 110 // Array of strides for each plane, typically greater or equal to the width | 129 // Array of strides for each plane, typically greater or equal to the width |
| 111 // of the surface divided by the horizontal sampling period. Note that | 130 // of the surface divided by the horizontal sampling period. Note that |
| 112 // strides can be negative. | 131 // strides can be negative. |
| 113 int32 strides_[kMaxPlanes]; | 132 int32 strides_[kMaxPlanes]; |
| 114 | 133 |
| 115 // Array of data pointers to each plane. | 134 // Array of data pointers to each plane. |
| 116 uint8* data_[kMaxPlanes]; | 135 uint8* data_[kMaxPlanes]; |
| 117 | 136 |
| 118 DISALLOW_COPY_AND_ASSIGN(VideoFrame); | 137 // Native texture ID, if this is a NATIVE_TEXTURE frame. |
| 138 uint32 texture_id_; | |
| 139 base::Closure texture_no_longer_needed_; | |
| 140 | |
| 141 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | |
| 119 }; | 142 }; |
| 120 | 143 |
| 121 } // namespace media | 144 } // namespace media |
| 122 | 145 |
| 123 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 146 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
| OLD | NEW |