Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1829)

Side by Side Diff: media/base/video_frame.cc

Issue 8897022: Revert 113895 - <video> decode in hardware! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/video_frame.h ('k') | media/ffmpeg/ffmpeg_common.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
OLDNEW
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( 20 scoped_refptr<VideoFrame> frame(new VideoFrame(format, width, height));
21 format, width, height, timestamp, duration)); 21 frame->SetTimestamp(timestamp);
22 frame->SetDuration(duration);
22 switch (format) { 23 switch (format) {
23 case VideoFrame::RGB555: 24 case VideoFrame::RGB555:
24 case VideoFrame::RGB565: 25 case VideoFrame::RGB565:
25 frame->AllocateRGB(2u); 26 frame->AllocateRGB(2u);
26 break; 27 break;
27 case VideoFrame::RGB24: 28 case VideoFrame::RGB24:
28 frame->AllocateRGB(3u); 29 frame->AllocateRGB(3u);
29 break; 30 break;
30 case VideoFrame::RGB32: 31 case VideoFrame::RGB32:
31 case VideoFrame::RGBA: 32 case VideoFrame::RGBA:
32 frame->AllocateRGB(4u); 33 frame->AllocateRGB(4u);
33 break; 34 break;
34 case VideoFrame::YV12: 35 case VideoFrame::YV12:
35 case VideoFrame::YV16: 36 case VideoFrame::YV16:
36 frame->AllocateYUV(); 37 frame->AllocateYUV();
37 break; 38 break;
38 case VideoFrame::ASCII: 39 case VideoFrame::ASCII:
39 frame->AllocateRGB(1u); 40 frame->AllocateRGB(1u);
40 break; 41 break;
41 default: 42 default:
42 NOTREACHED(); 43 NOTREACHED();
43 return NULL; 44 return NULL;
44 } 45 }
45 return frame; 46 return frame;
46 } 47 }
47 48
48 // static 49 // 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
65 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { 50 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() {
66 return new VideoFrame( 51 return new VideoFrame(VideoFrame::EMPTY, 0, 0);
67 VideoFrame::EMPTY, 0, 0, base::TimeDelta(), base::TimeDelta());
68 } 52 }
69 53
70 // static 54 // static
71 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) { 55 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) {
72 DCHECK_GT(width, 0); 56 DCHECK_GT(width, 0);
73 DCHECK_GT(height, 0); 57 DCHECK_GT(height, 0);
74 58
75 // Create our frame. 59 // Create our frame.
76 const base::TimeDelta kZero; 60 const base::TimeDelta kZero;
77 scoped_refptr<VideoFrame> frame = 61 scoped_refptr<VideoFrame> frame =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 data_[VideoFrame::kYPlane] = data; 131 data_[VideoFrame::kYPlane] = data;
148 data_[VideoFrame::kUPlane] = data + y_bytes; 132 data_[VideoFrame::kUPlane] = data + y_bytes;
149 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; 133 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
150 strides_[VideoFrame::kYPlane] = y_stride; 134 strides_[VideoFrame::kYPlane] = y_stride;
151 strides_[VideoFrame::kUPlane] = uv_stride; 135 strides_[VideoFrame::kUPlane] = uv_stride;
152 strides_[VideoFrame::kVPlane] = uv_stride; 136 strides_[VideoFrame::kVPlane] = uv_stride;
153 } 137 }
154 138
155 VideoFrame::VideoFrame(VideoFrame::Format format, 139 VideoFrame::VideoFrame(VideoFrame::Format format,
156 size_t width, 140 size_t width,
157 size_t height, 141 size_t height)
158 base::TimeDelta timestamp,
159 base::TimeDelta duration)
160 : format_(format), 142 : format_(format),
161 width_(width), 143 width_(width),
162 height_(height), 144 height_(height),
163 planes_(0), 145 planes_(0) {
164 texture_id_(0) {
165 SetTimestamp(timestamp);
166 SetDuration(duration);
167 memset(&strides_, 0, sizeof(strides_)); 146 memset(&strides_, 0, sizeof(strides_));
168 memset(&data_, 0, sizeof(data_)); 147 memset(&data_, 0, sizeof(data_));
169 } 148 }
170 149
171 VideoFrame::~VideoFrame() { 150 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
177 // In multi-plane allocations, only a single block of memory is allocated 151 // In multi-plane allocations, only a single block of memory is allocated
178 // on the heap, and other |data| pointers point inside the same, single block 152 // on the heap, and other |data| pointers point inside the same, single block
179 // so just delete index 0. 153 // so just delete index 0.
180 delete[] data_[0]; 154 delete[] data_[0];
181 } 155 }
182 156
183 bool VideoFrame::IsValidPlane(size_t plane) const { 157 bool VideoFrame::IsValidPlane(size_t plane) const {
184 switch (format_) { 158 switch (format_) {
185 case RGB555: 159 case RGB555:
186 case RGB565: 160 case RGB565:
187 case RGB24: 161 case RGB24:
188 case RGB32: 162 case RGB32:
189 case RGBA: 163 case RGBA:
190 return plane == kRGBPlane; 164 return plane == kRGBPlane;
191 165
192 case YV12: 166 case YV12:
193 case YV16: 167 case YV16:
194 return plane == kYPlane || plane == kUPlane || plane == kVPlane; 168 return plane == kYPlane || plane == kUPlane || plane == kVPlane;
195 169
196 case NATIVE_TEXTURE:
197 NOTREACHED() << "NATIVE_TEXTUREs don't use plane-related methods!";
198 return false;
199
200 default: 170 default:
201 break; 171 break;
202 } 172 }
203 173
204 // Intentionally leave out non-production formats. 174 // Intentionally leave out non-production formats.
205 NOTREACHED() << "Unsupported video frame format: " << format_; 175 NOTREACHED() << "Unsupported video frame format: " << format_;
206 return false; 176 return false;
207 } 177 }
208 178
209 int VideoFrame::stride(size_t plane) const { 179 int VideoFrame::stride(size_t plane) const {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // Intentionally leave out non-production formats. 229 // Intentionally leave out non-production formats.
260 NOTREACHED() << "Unsupported video frame format: " << format_; 230 NOTREACHED() << "Unsupported video frame format: " << format_;
261 return 0; 231 return 0;
262 } 232 }
263 233
264 uint8* VideoFrame::data(size_t plane) const { 234 uint8* VideoFrame::data(size_t plane) const {
265 DCHECK(IsValidPlane(plane)); 235 DCHECK(IsValidPlane(plane));
266 return data_[plane]; 236 return data_[plane];
267 } 237 }
268 238
269 uint32 VideoFrame::texture_id() const {
270 DCHECK_EQ(format_, NATIVE_TEXTURE);
271 DCHECK_EQ(planes_, 0U);
272 return texture_id_;
273 }
274
275 bool VideoFrame::IsEndOfStream() const { 239 bool VideoFrame::IsEndOfStream() const {
276 return format_ == VideoFrame::EMPTY; 240 return format_ == VideoFrame::EMPTY;
277 } 241 }
278 242
279 } // namespace media 243 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | media/ffmpeg/ffmpeg_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698