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 "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
11 #include "ui/gfx/size.h" | |
11 | 12 |
12 namespace media { | 13 namespace media { |
13 | 14 |
14 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { | 15 class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { |
15 public: | 16 public: |
16 enum { | 17 enum { |
17 kMaxPlanes = 3, | 18 kMaxPlanes = 3, |
18 | 19 |
19 kRGBPlane = 0, | 20 kRGBPlane = 0, |
20 | 21 |
(...skipping 13 matching lines...) Expand all Loading... | |
34 YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples | 35 YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples |
35 EMPTY = 9, // An empty frame. | 36 EMPTY = 9, // An empty frame. |
36 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. | 37 I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
37 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. | 38 NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. |
38 }; | 39 }; |
39 | 40 |
40 // Creates a new frame in system memory with given parameters. Buffers for | 41 // Creates a new frame in system memory with given parameters. Buffers for |
41 // the frame are allocated but not initialized. | 42 // the frame are allocated but not initialized. |
42 static scoped_refptr<VideoFrame> CreateFrame( | 43 static scoped_refptr<VideoFrame> CreateFrame( |
43 Format format, | 44 Format format, |
44 size_t width, | 45 size_t width, |
Ami GONE FROM CHROMIUM
2012/08/02 00:16:14
this width/height pair should be gfx::Size'ified.
acolwell GONE FROM CHROMIUM
2012/08/02 02:16:30
Done, but named size since it technically is the v
| |
45 size_t height, | 46 size_t height, |
47 const gfx::Size& natural_size, | |
46 base::TimeDelta timestamp); | 48 base::TimeDelta timestamp); |
47 | 49 |
48 // Call prior to CreateFrame to ensure validity of frame configuration. Called | 50 // Call prior to CreateFrame to ensure validity of frame configuration. Called |
49 // automatically by VideoDecoderConfig::IsValidConfig(). | 51 // automatically by VideoDecoderConfig::IsValidConfig(). |
50 // TODO(scherkus): VideoDecoderConfig shouldn't call this method | 52 // TODO(scherkus): VideoDecoderConfig shouldn't call this method |
51 static bool IsValidConfig( | 53 static bool IsValidConfig( |
52 Format format, | 54 Format format, |
53 size_t width, | 55 size_t width, |
54 size_t height); | 56 size_t height); |
55 | 57 |
56 // Wraps a native texture of the given parameters with a VideoFrame. When the | 58 // Wraps a native texture of the given parameters with a VideoFrame. When the |
57 // frame is destroyed |no_longer_needed.Run()| will be called. | 59 // frame is destroyed |no_longer_needed.Run()| will be called. |
58 static scoped_refptr<VideoFrame> WrapNativeTexture( | 60 static scoped_refptr<VideoFrame> WrapNativeTexture( |
59 uint32 texture_id, | 61 uint32 texture_id, |
60 uint32 texture_target, | 62 uint32 texture_target, |
61 size_t width, | 63 size_t width, |
62 size_t height, | 64 size_t height, |
65 const gfx::Size& natural_size, | |
63 base::TimeDelta timestamp, | 66 base::TimeDelta timestamp, |
64 const base::Closure& no_longer_needed); | 67 const base::Closure& no_longer_needed); |
65 | 68 |
66 // Creates a frame with format equals to VideoFrame::EMPTY, width, height, | 69 // Creates a frame with format equals to VideoFrame::EMPTY, width, height, |
67 // and timestamp are all 0. | 70 // and timestamp are all 0. |
68 static scoped_refptr<VideoFrame> CreateEmptyFrame(); | 71 static scoped_refptr<VideoFrame> CreateEmptyFrame(); |
69 | 72 |
70 // Allocates YV12 frame based on |width| and |height|, and sets its data to | 73 // Allocates YV12 frame based on |width| and |height|, and sets its data to |
71 // the YUV equivalent of RGB(0,0,0). | 74 // the YUV equivalent of RGB(0,0,0). |
72 static scoped_refptr<VideoFrame> CreateBlackFrame(int width, int height); | 75 static scoped_refptr<VideoFrame> CreateBlackFrame(int width, int height); |
73 | 76 |
74 Format format() const { return format_; } | 77 Format format() const { return format_; } |
75 | 78 |
76 size_t width() const { return width_; } | 79 size_t width() const { return width_; } |
77 | 80 |
78 size_t height() const { return height_; } | 81 size_t height() const { return height_; } |
79 | 82 |
83 const gfx::Size& natural_size() const { return natural_size_; } | |
84 | |
80 int stride(size_t plane) const; | 85 int stride(size_t plane) const; |
81 | 86 |
82 // Returns the number of bytes per row and number of rows for a given plane. | 87 // Returns the number of bytes per row and number of rows for a given plane. |
83 // | 88 // |
84 // As opposed to stride(), row_bytes() refers to the bytes representing | 89 // As opposed to stride(), row_bytes() refers to the bytes representing |
85 // visible pixels. | 90 // visible pixels. |
86 int row_bytes(size_t plane) const; | 91 int row_bytes(size_t plane) const; |
87 int rows(size_t plane) const; | 92 int rows(size_t plane) const; |
88 | 93 |
89 // Returns pointer to the buffer for a given plane. The memory is owned by | 94 // Returns pointer to the buffer for a given plane. The memory is owned by |
(...skipping 20 matching lines...) Expand all Loading... | |
110 // Used to keep a running hash of seen frames. Expects an initialized MD5 | 115 // Used to keep a running hash of seen frames. Expects an initialized MD5 |
111 // context. Calls MD5Update with the context and the contents of the frame. | 116 // context. Calls MD5Update with the context and the contents of the frame. |
112 void HashFrameForTesting(base::MD5Context* context); | 117 void HashFrameForTesting(base::MD5Context* context); |
113 | 118 |
114 private: | 119 private: |
115 friend class base::RefCountedThreadSafe<VideoFrame>; | 120 friend class base::RefCountedThreadSafe<VideoFrame>; |
116 // Clients must use the static CreateFrame() method to create a new frame. | 121 // Clients must use the static CreateFrame() method to create a new frame. |
117 VideoFrame(Format format, | 122 VideoFrame(Format format, |
118 size_t video_width, | 123 size_t video_width, |
119 size_t video_height, | 124 size_t video_height, |
125 const gfx::Size& natural_size, | |
120 base::TimeDelta timestamp); | 126 base::TimeDelta timestamp); |
121 virtual ~VideoFrame(); | 127 virtual ~VideoFrame(); |
122 | 128 |
123 // Used internally by CreateFrame(). | 129 // Used internally by CreateFrame(). |
124 void AllocateRGB(size_t bytes_per_pixel); | 130 void AllocateRGB(size_t bytes_per_pixel); |
125 void AllocateYUV(); | 131 void AllocateYUV(); |
126 | 132 |
127 // Used to DCHECK() plane parameters. | 133 // Used to DCHECK() plane parameters. |
128 bool IsValidPlane(size_t plane) const; | 134 bool IsValidPlane(size_t plane) const; |
129 | 135 |
130 // Frame format. | 136 // Frame format. |
131 Format format_; | 137 Format format_; |
132 | 138 |
133 // Width and height of surface. | 139 // Width and height of surface. |
Ami GONE FROM CHROMIUM
2012/08/02 00:16:14
"surface" is particularly unenlightening in this c
| |
134 size_t width_; | 140 size_t width_; |
135 size_t height_; | 141 size_t height_; |
136 | 142 |
143 // Width and height of the video frame with aspect ratio taken | |
144 // into account. | |
145 gfx::Size natural_size_; | |
146 | |
137 // Array of strides for each plane, typically greater or equal to the width | 147 // Array of strides for each plane, typically greater or equal to the width |
138 // of the surface divided by the horizontal sampling period. Note that | 148 // of the surface divided by the horizontal sampling period. Note that |
139 // strides can be negative. | 149 // strides can be negative. |
140 int32 strides_[kMaxPlanes]; | 150 int32 strides_[kMaxPlanes]; |
141 | 151 |
142 // Array of data pointers to each plane. | 152 // Array of data pointers to each plane. |
143 uint8* data_[kMaxPlanes]; | 153 uint8* data_[kMaxPlanes]; |
144 | 154 |
145 // Native texture ID, if this is a NATIVE_TEXTURE frame. | 155 // Native texture ID, if this is a NATIVE_TEXTURE frame. |
146 uint32 texture_id_; | 156 uint32 texture_id_; |
147 uint32 texture_target_; | 157 uint32 texture_target_; |
148 base::Closure texture_no_longer_needed_; | 158 base::Closure texture_no_longer_needed_; |
149 | 159 |
150 base::TimeDelta timestamp_; | 160 base::TimeDelta timestamp_; |
151 | 161 |
152 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); | 162 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); |
153 }; | 163 }; |
154 | 164 |
155 } // namespace media | 165 } // namespace media |
156 | 166 |
157 #endif // MEDIA_BASE_VIDEO_FRAME_H_ | 167 #endif // MEDIA_BASE_VIDEO_FRAME_H_ |
OLD | NEW |