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