Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "media/base/buffers.h" | 8 #include "media/base/buffers.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 class VideoFrame : public StreamSample { | 12 class VideoFrame : public StreamSample { |
| 13 public: | 13 public: |
| 14 static const size_t kMaxPlanes = 3; | 14 static const size_t kMaxPlanes = 3; |
| 15 | 15 |
| 16 static const size_t kNumRGBPlanes = 1; | 16 static const size_t kNumRGBPlanes = 1; |
| 17 static const size_t kRGBPlane = 0; | 17 static const size_t kRGBPlane = 0; |
| 18 | 18 |
| 19 static const size_t kNumYUVPlanes = 3; | 19 static const size_t kNumYUVPlanes = 3; |
| 20 static const size_t kNumNV12Planes = 2; | |
| 20 static const size_t kYPlane = 0; | 21 static const size_t kYPlane = 0; |
| 21 static const size_t kUPlane = 1; | 22 static const size_t kUPlane = 1; |
| 22 static const size_t kVPlane = 2; | 23 static const size_t kVPlane = 2; |
| 23 | 24 |
| 24 // Surface formats roughly based on FOURCC labels, see: | 25 // Surface formats roughly based on FOURCC labels, see: |
| 25 // http://www.fourcc.org/rgb.php | 26 // http://www.fourcc.org/rgb.php |
| 26 // http://www.fourcc.org/yuv.php | 27 // http://www.fourcc.org/yuv.php |
| 27 enum Format { | 28 enum Format { |
| 28 INVALID, // Invalid format value. Used for error reporting. | 29 INVALID, // Invalid format value. Used for error reporting. |
| 29 RGB555, // 16bpp RGB packed 5:5:5 | 30 RGB555, // 16bpp RGB packed 5:5:5 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 43 // this object or be provided externally. | 44 // this object or be provided externally. |
| 44 TYPE_SYSTEM_MEMORY, | 45 TYPE_SYSTEM_MEMORY, |
| 45 | 46 |
| 46 // Video frame is stored in GL texture(s). | 47 // Video frame is stored in GL texture(s). |
| 47 TYPE_GL_TEXTURE, | 48 TYPE_GL_TEXTURE, |
| 48 | 49 |
| 49 // Video frame is stored in Direct3D texture(s). | 50 // Video frame is stored in Direct3D texture(s). |
| 50 TYPE_D3D_TEXTURE, | 51 TYPE_D3D_TEXTURE, |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 public: | 54 // Defines a new type for GL texture so we don't include OpenGL headers. |
| 55 typedef unsigned int GlTexture; | |
| 56 | |
| 57 // Defines a new type for D3D texture so we don't include D3D headers and | |
| 58 // don't need to bind to a specific version of D3D. | |
| 59 typedef void* D3dTexture; | |
| 60 | |
| 54 // 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 |
| 55 // the frame are allocated but not initialized. | 62 // the frame are allocated but not initialized. |
| 56 static void CreateFrame(Format format, | 63 static void CreateFrame(Format format, |
| 57 size_t width, | 64 size_t width, |
| 58 size_t height, | 65 size_t height, |
| 59 base::TimeDelta timestamp, | 66 base::TimeDelta timestamp, |
| 60 base::TimeDelta duration, | 67 base::TimeDelta duration, |
| 61 scoped_refptr<VideoFrame>* frame_out); | 68 scoped_refptr<VideoFrame>* frame_out); |
| 62 | 69 |
| 63 // Creates a new frame with given parameters. Buffers for the frame are | 70 // Creates a new frame with given parameters. Buffers for the frame are |
| 64 // provided externally. Reference to the buffers and strides are copied | 71 // provided externally. Reference to the buffers and strides are copied |
| 65 // from |data| and |strides| respectively. | 72 // from |data| and |strides| respectively. |
| 66 static void CreateFrameExternal(SurfaceType type, | 73 static void CreateFrameExternal(SurfaceType type, |
| 67 Format format, | 74 Format format, |
| 68 size_t width, | 75 size_t width, |
| 69 size_t height, | 76 size_t height, |
| 70 size_t planes, | 77 size_t planes, |
| 71 uint8* const data[kMaxPlanes], | 78 uint8* const data[kMaxPlanes], |
| 72 const int32 strides[kMaxPlanes], | 79 const int32 strides[kMaxPlanes], |
| 73 base::TimeDelta timestamp, | 80 base::TimeDelta timestamp, |
| 74 base::TimeDelta duration, | 81 base::TimeDelta duration, |
| 75 void* private_buffer, | 82 void* private_buffer, |
| 76 scoped_refptr<VideoFrame>* frame_out); | 83 scoped_refptr<VideoFrame>* frame_out); |
| 77 | 84 |
| 85 // Creates a new frame with GL textures. | |
| 86 static void CreateFrameGlTexture(Format format, | |
| 87 size_t width, | |
| 88 size_t height, | |
| 89 GlTexture const textures[kMaxPlanes], | |
| 90 base::TimeDelta timestamp, | |
| 91 base::TimeDelta duration, | |
| 92 scoped_refptr<VideoFrame>* frame_out); | |
| 93 | |
| 94 // Creates a new frame with D3d textures. | |
| 95 static void CreateFrameD3dTexture(Format format, | |
| 96 size_t width, | |
| 97 size_t height, | |
| 98 D3dTexture const textures[kMaxPlanes], | |
| 99 base::TimeDelta timestamp, | |
| 100 base::TimeDelta duration, | |
| 101 scoped_refptr<VideoFrame>* frame_out); | |
| 102 | |
| 78 // Creates a frame with format equals to VideoFrame::EMPTY, width, height | 103 // Creates a frame with format equals to VideoFrame::EMPTY, width, height |
| 79 // timestamp and duration are all 0. | 104 // timestamp and duration are all 0. |
| 80 static void CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out); | 105 static void CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out); |
| 81 | 106 |
| 82 // Allocates YV12 frame based on |width| and |height|, and sets its data to | 107 // Allocates YV12 frame based on |width| and |height|, and sets its data to |
| 83 // the YUV equivalent of RGB(0,0,0). | 108 // the YUV equivalent of RGB(0,0,0). |
| 84 static void CreateBlackFrame(int width, int height, | 109 static void CreateBlackFrame(int width, int height, |
| 85 scoped_refptr<VideoFrame>* frame_out); | 110 scoped_refptr<VideoFrame>* frame_out); |
| 86 | 111 |
| 87 virtual SurfaceType type() const { return type_; } | 112 virtual SurfaceType type() const { return type_; } |
| 88 | 113 |
| 89 Format format() const { return format_; } | 114 Format format() const { return format_; } |
| 90 | 115 |
| 91 size_t width() const { return width_; } | 116 size_t width() const { return width_; } |
| 92 | 117 |
| 93 size_t height() const { return height_; } | 118 size_t height() const { return height_; } |
| 94 | 119 |
| 95 size_t planes() const { return planes_; } | 120 size_t planes() const { return planes_; } |
| 96 | 121 |
| 97 int32 stride(size_t plane) const { return strides_[plane]; } | 122 int32 stride(size_t plane) const { return strides_[plane]; } |
| 98 | 123 |
| 99 // Returns pointer to the buffer for a given plane. The memory is owned by | 124 // Returns pointer to the buffer for a given plane. The memory is owned by |
| 100 // VideoFrame object and must not be freed by the caller. | 125 // VideoFrame object and must not be freed by the caller. |
| 101 uint8* data(size_t plane) const { return data_[plane]; } | 126 uint8* data(size_t plane) const { return data_[plane]; } |
| 102 | 127 |
| 128 // Returns the GL texture for a given plane. | |
| 129 GlTexture gl_texture(size_t plane) const { return gl_textures_[plane]; } | |
| 130 | |
| 131 // Returns the D3D texture for a given plane. | |
| 132 D3dTexture d3d_texture(size_t plane) const { return d3d_textures_[plane]; } | |
| 133 | |
| 103 void* private_buffer() const { return private_buffer_; } | 134 void* private_buffer() const { return private_buffer_; } |
| 104 | 135 |
| 105 // StreamSample interface. | 136 // StreamSample interface. |
| 106 virtual bool IsEndOfStream() const; | 137 virtual bool IsEndOfStream() const; |
| 107 | 138 |
| 108 protected: | 139 protected: |
| 109 // Clients must use the static CreateFrame() method to create a new frame. | 140 // Clients must use the static CreateFrame() method to create a new frame. |
| 110 VideoFrame(SurfaceType type, | 141 VideoFrame(SurfaceType type, |
| 111 Format format, | 142 Format format, |
| 112 size_t video_width, | 143 size_t video_width, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 131 // Number of planes, typically 1 for packed RGB formats and 3 for planar | 162 // Number of planes, typically 1 for packed RGB formats and 3 for planar |
| 132 // YUV formats. | 163 // YUV formats. |
| 133 size_t planes_; | 164 size_t planes_; |
| 134 | 165 |
| 135 // Array of strides for each plane, typically greater or equal to the width | 166 // Array of strides for each plane, typically greater or equal to the width |
| 136 // of the surface divided by the horizontal sampling period. Note that | 167 // of the surface divided by the horizontal sampling period. Note that |
| 137 // strides can be negative. | 168 // strides can be negative. |
| 138 int32 strides_[kMaxPlanes]; | 169 int32 strides_[kMaxPlanes]; |
| 139 | 170 |
| 140 // Array of data pointers to each plane. | 171 // Array of data pointers to each plane. |
| 141 uint8* data_[kMaxPlanes]; | 172 uint8* data_[kMaxPlanes]; |
|
scherkus (not reviewing)
2010/09/13 07:19:23
at some point we may want to consider using a unio
| |
| 142 | 173 |
| 174 // Array fo GL textures. | |
| 175 GlTexture gl_textures_[kMaxPlanes]; | |
| 176 | |
| 177 // Array for D3D textures. | |
| 178 D3dTexture d3d_textures_[kMaxPlanes]; | |
| 179 | |
| 143 // True of memory referenced by |data_| is provided externally and shouldn't | 180 // True of memory referenced by |data_| is provided externally and shouldn't |
| 144 // be deleted. | 181 // be deleted. |
| 145 bool external_memory_; | 182 bool external_memory_; |
| 146 | 183 |
| 147 // Private buffer pointer, can be used for EGLImage. | 184 // Private buffer pointer, can be used for EGLImage. |
| 148 void* private_buffer_; | 185 void* private_buffer_; |
| 149 | 186 |
| 150 DISALLOW_COPY_AND_ASSIGN(VideoFrame); | 187 DISALLOW_COPY_AND_ASSIGN(VideoFrame); |
| 151 }; | 188 }; |
| 152 | 189 |
| 153 } // namespace media | 190 } // namespace media |
| 154 | 191 |
| 155 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 192 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
| OLD | NEW |