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 #include "media/base/video_frame.h" | 5 #include "media/base/video_frame.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace media { | 9 namespace media { |
10 | 10 |
11 // static | 11 // static |
12 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( | 12 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( |
13 VideoFrame::Format format, | 13 VideoFrame::Format format, |
14 size_t width, | 14 size_t width, |
15 size_t height, | 15 size_t height, |
16 base::TimeDelta timestamp, | 16 base::TimeDelta timestamp, |
17 base::TimeDelta duration) { | 17 base::TimeDelta duration) { |
18 DCHECK(width > 0 && height > 0); | 18 DCHECK(width > 0 && height > 0); |
19 DCHECK(width * height < 100000000); | 19 DCHECK(width * height < 100000000); |
20 scoped_refptr<VideoFrame> frame(new VideoFrame(format, width, height)); | 20 scoped_refptr<VideoFrame> frame(new VideoFrame( |
21 frame->SetTimestamp(timestamp); | 21 format, width, height, timestamp, duration)); |
22 frame->SetDuration(duration); | |
23 switch (format) { | 22 switch (format) { |
24 case VideoFrame::RGB555: | 23 case VideoFrame::RGB555: |
25 case VideoFrame::RGB565: | 24 case VideoFrame::RGB565: |
26 frame->AllocateRGB(2u); | 25 frame->AllocateRGB(2u); |
27 break; | 26 break; |
28 case VideoFrame::RGB24: | 27 case VideoFrame::RGB24: |
29 frame->AllocateRGB(3u); | 28 frame->AllocateRGB(3u); |
30 break; | 29 break; |
31 case VideoFrame::RGB32: | 30 case VideoFrame::RGB32: |
32 case VideoFrame::RGBA: | 31 case VideoFrame::RGBA: |
33 frame->AllocateRGB(4u); | 32 frame->AllocateRGB(4u); |
34 break; | 33 break; |
35 case VideoFrame::YV12: | 34 case VideoFrame::YV12: |
36 case VideoFrame::YV16: | 35 case VideoFrame::YV16: |
37 frame->AllocateYUV(); | 36 frame->AllocateYUV(); |
38 break; | 37 break; |
39 case VideoFrame::ASCII: | 38 case VideoFrame::ASCII: |
40 frame->AllocateRGB(1u); | 39 frame->AllocateRGB(1u); |
41 break; | 40 break; |
42 default: | 41 default: |
43 NOTREACHED(); | 42 NOTREACHED(); |
44 return NULL; | 43 return NULL; |
45 } | 44 } |
46 return frame; | 45 return frame; |
47 } | 46 } |
48 | 47 |
49 // static | 48 // static |
49 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( | |
50 uint32 texture_id, | |
51 size_t width, | |
52 size_t height, | |
53 base::TimeDelta timestamp, | |
54 base::TimeDelta duration, | |
55 const base::Closure& no_longer_needed) { | |
56 scoped_refptr<VideoFrame> frame( | |
57 new VideoFrame(NATIVE_TEXTURE, width, height, timestamp, duration)); | |
58 frame->planes_ = 0; | |
59 frame->texture_id_ = texture_id; | |
60 frame->texture_no_longer_needed_ = no_longer_needed; | |
61 return frame; | |
62 } | |
63 | |
64 // static | |
50 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { | 65 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { |
51 return new VideoFrame(VideoFrame::EMPTY, 0, 0); | 66 return new VideoFrame( |
67 VideoFrame::EMPTY, 0, 0, base::TimeDelta(), base::TimeDelta()); | |
52 } | 68 } |
53 | 69 |
54 // static | 70 // static |
55 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) { | 71 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) { |
56 DCHECK_GT(width, 0); | 72 DCHECK_GT(width, 0); |
57 DCHECK_GT(height, 0); | 73 DCHECK_GT(height, 0); |
58 | 74 |
59 // Create our frame. | 75 // Create our frame. |
60 const base::TimeDelta kZero; | 76 const base::TimeDelta kZero; |
61 scoped_refptr<VideoFrame> frame = | 77 scoped_refptr<VideoFrame> frame = |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 data_[VideoFrame::kYPlane] = data; | 147 data_[VideoFrame::kYPlane] = data; |
132 data_[VideoFrame::kUPlane] = data + y_bytes; | 148 data_[VideoFrame::kUPlane] = data + y_bytes; |
133 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; | 149 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; |
134 strides_[VideoFrame::kYPlane] = y_stride; | 150 strides_[VideoFrame::kYPlane] = y_stride; |
135 strides_[VideoFrame::kUPlane] = uv_stride; | 151 strides_[VideoFrame::kUPlane] = uv_stride; |
136 strides_[VideoFrame::kVPlane] = uv_stride; | 152 strides_[VideoFrame::kVPlane] = uv_stride; |
137 } | 153 } |
138 | 154 |
139 VideoFrame::VideoFrame(VideoFrame::Format format, | 155 VideoFrame::VideoFrame(VideoFrame::Format format, |
140 size_t width, | 156 size_t width, |
141 size_t height) | 157 size_t height, |
158 base::TimeDelta timestamp, | |
159 base::TimeDelta duration) | |
142 : format_(format), | 160 : format_(format), |
143 width_(width), | 161 width_(width), |
144 height_(height), | 162 height_(height), |
145 planes_(0) { | 163 planes_(0), |
164 texture_id_(0) { | |
165 SetTimestamp(timestamp); | |
166 SetDuration(duration); | |
146 memset(&strides_, 0, sizeof(strides_)); | 167 memset(&strides_, 0, sizeof(strides_)); |
147 memset(&data_, 0, sizeof(data_)); | 168 memset(&data_, 0, sizeof(data_)); |
148 } | 169 } |
149 | 170 |
150 VideoFrame::~VideoFrame() { | 171 VideoFrame::~VideoFrame() { |
172 if (format_ == NATIVE_TEXTURE && !texture_no_longer_needed_.is_null()) { | |
173 texture_no_longer_needed_.Run(); | |
174 texture_no_longer_needed_.Reset(); | |
175 } | |
176 | |
151 // In multi-plane allocations, only a single block of memory is allocated | 177 // In multi-plane allocations, only a single block of memory is allocated |
152 // on the heap, and other |data| pointers point inside the same, single block | 178 // on the heap, and other |data| pointers point inside the same, single block |
153 // so just delete index 0. | 179 // so just delete index 0. |
154 delete[] data_[0]; | 180 delete[] data_[0]; |
155 } | 181 } |
156 | 182 |
157 bool VideoFrame::IsValidPlane(size_t plane) const { | 183 bool VideoFrame::IsValidPlane(size_t plane) const { |
158 switch (format_) { | 184 switch (format_) { |
159 case RGB555: | 185 case RGB555: |
160 case RGB565: | 186 case RGB565: |
161 case RGB24: | 187 case RGB24: |
162 case RGB32: | 188 case RGB32: |
163 case RGBA: | 189 case RGBA: |
164 return plane == kRGBPlane; | 190 return plane == kRGBPlane; |
165 | 191 |
166 case YV12: | 192 case YV12: |
167 case YV16: | 193 case YV16: |
168 return plane == kYPlane || plane == kUPlane || plane == kVPlane; | 194 return plane == kYPlane || plane == kUPlane || plane == kVPlane; |
169 | 195 |
196 case NATIVE_TEXTURE: | |
197 // Native textures shouldn't be accessing the plane-related methods of | |
198 // this class! | |
199 return false; | |
scherkus (not reviewing)
2011/12/06 00:27:44
DCHECK?
Ami GONE FROM CHROMIUM
2011/12/07 00:03:04
Done.
| |
200 | |
170 default: | 201 default: |
171 break; | 202 break; |
172 } | 203 } |
173 | 204 |
174 // Intentionally leave out non-production formats. | 205 // Intentionally leave out non-production formats. |
175 NOTREACHED() << "Unsupported video frame format: " << format_; | 206 NOTREACHED() << "Unsupported video frame format: " << format_; |
176 return false; | 207 return false; |
177 } | 208 } |
178 | 209 |
179 int VideoFrame::stride(size_t plane) const { | 210 int VideoFrame::stride(size_t plane) const { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 // Intentionally leave out non-production formats. | 260 // Intentionally leave out non-production formats. |
230 NOTREACHED() << "Unsupported video frame format: " << format_; | 261 NOTREACHED() << "Unsupported video frame format: " << format_; |
231 return 0; | 262 return 0; |
232 } | 263 } |
233 | 264 |
234 uint8* VideoFrame::data(size_t plane) const { | 265 uint8* VideoFrame::data(size_t plane) const { |
235 DCHECK(IsValidPlane(plane)); | 266 DCHECK(IsValidPlane(plane)); |
236 return data_[plane]; | 267 return data_[plane]; |
237 } | 268 } |
238 | 269 |
270 uint32 VideoFrame::texture_id() const { | |
271 DCHECK_EQ(format_, NATIVE_TEXTURE); | |
272 DCHECK_EQ(planes_, 0U); | |
273 return texture_id_; | |
274 } | |
275 | |
239 bool VideoFrame::IsEndOfStream() const { | 276 bool VideoFrame::IsEndOfStream() const { |
240 return format_ == VideoFrame::EMPTY; | 277 return format_ == VideoFrame::EMPTY; |
241 } | 278 } |
242 | 279 |
243 } // namespace media | 280 } // namespace media |
OLD | NEW |