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

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

Issue 57403003: Remove EMPTY from VideoFrame::Format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@vframe_rgb
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « media/base/video_frame.h ('k') | media/base/video_frame_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/aligned_memory.h" 12 #include "base/memory/aligned_memory.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "media/base/limits.h" 14 #include "media/base/limits.h"
15 #include "media/base/video_util.h" 15 #include "media/base/video_util.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
17 17
18 namespace media { 18 namespace media {
19 19
20 // static 20 // static
21 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( 21 scoped_refptr<VideoFrame> VideoFrame::CreateFrame(
22 VideoFrame::Format format, 22 VideoFrame::Format format,
23 const gfx::Size& coded_size, 23 const gfx::Size& coded_size,
24 const gfx::Rect& visible_rect, 24 const gfx::Rect& visible_rect,
25 const gfx::Size& natural_size, 25 const gfx::Size& natural_size,
26 base::TimeDelta timestamp) { 26 base::TimeDelta timestamp) {
27 DCHECK(IsValidConfig(format, coded_size, visible_rect, natural_size)); 27 DCHECK(IsValidConfig(format, coded_size, visible_rect, natural_size));
28 scoped_refptr<VideoFrame> frame(new VideoFrame( 28 scoped_refptr<VideoFrame> frame(new VideoFrame(
29 format, coded_size, visible_rect, natural_size, timestamp)); 29 format, coded_size, visible_rect, natural_size, timestamp, false));
30 switch (format) { 30 switch (format) {
31 case VideoFrame::YV12: 31 case VideoFrame::YV12:
32 case VideoFrame::YV12A: 32 case VideoFrame::YV12A:
33 case VideoFrame::YV16: 33 case VideoFrame::YV16:
34 case VideoFrame::I420: 34 case VideoFrame::I420:
35 frame->AllocateYUV(); 35 frame->AllocateYUV();
36 break; 36 break;
37 default: 37 default:
38 LOG(FATAL) << "Unsupported frame format: " << format; 38 LOG(FATAL) << "Unsupported frame format: " << format;
39 } 39 }
40 return frame; 40 return frame;
41 } 41 }
42 42
43 // static 43 // static
44 std::string VideoFrame::FormatToString(VideoFrame::Format format) { 44 std::string VideoFrame::FormatToString(VideoFrame::Format format) {
45 switch (format) { 45 switch (format) {
46 case VideoFrame::UNKNOWN: 46 case VideoFrame::UNKNOWN:
47 return "UNKNOWN"; 47 return "UNKNOWN";
48 case VideoFrame::YV12: 48 case VideoFrame::YV12:
49 return "YV12"; 49 return "YV12";
50 case VideoFrame::YV16: 50 case VideoFrame::YV16:
51 return "YV16"; 51 return "YV16";
52 case VideoFrame::EMPTY:
53 return "EMPTY";
54 case VideoFrame::I420: 52 case VideoFrame::I420:
55 return "I420"; 53 return "I420";
56 case VideoFrame::NATIVE_TEXTURE: 54 case VideoFrame::NATIVE_TEXTURE:
57 return "NATIVE_TEXTURE"; 55 return "NATIVE_TEXTURE";
58 #if defined(GOOGLE_TV) 56 #if defined(GOOGLE_TV)
59 case VideoFrame::HOLE: 57 case VideoFrame::HOLE:
60 return "HOLE"; 58 return "HOLE";
61 #endif 59 #endif
62 case VideoFrame::YV12A: 60 case VideoFrame::YV12A:
63 return "YV12A"; 61 return "YV12A";
(...skipping 25 matching lines...) Expand all
89 // static 87 // static
90 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( 88 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture(
91 const scoped_refptr<MailboxHolder>& mailbox_holder, 89 const scoped_refptr<MailboxHolder>& mailbox_holder,
92 uint32 texture_target, 90 uint32 texture_target,
93 const gfx::Size& coded_size, 91 const gfx::Size& coded_size,
94 const gfx::Rect& visible_rect, 92 const gfx::Rect& visible_rect,
95 const gfx::Size& natural_size, 93 const gfx::Size& natural_size,
96 base::TimeDelta timestamp, 94 base::TimeDelta timestamp,
97 const ReadPixelsCB& read_pixels_cb, 95 const ReadPixelsCB& read_pixels_cb,
98 const base::Closure& no_longer_needed_cb) { 96 const base::Closure& no_longer_needed_cb) {
99 scoped_refptr<VideoFrame> frame(new VideoFrame( 97 scoped_refptr<VideoFrame> frame(new VideoFrame(NATIVE_TEXTURE,
100 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); 98 coded_size,
99 visible_rect,
100 natural_size,
101 timestamp,
102 false));
101 frame->texture_mailbox_holder_ = mailbox_holder; 103 frame->texture_mailbox_holder_ = mailbox_holder;
102 frame->texture_target_ = texture_target; 104 frame->texture_target_ = texture_target;
103 frame->read_pixels_cb_ = read_pixels_cb; 105 frame->read_pixels_cb_ = read_pixels_cb;
104 frame->no_longer_needed_cb_ = no_longer_needed_cb; 106 frame->no_longer_needed_cb_ = no_longer_needed_cb;
105 107
106 return frame; 108 return frame;
107 } 109 }
108 110
109 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { 111 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) {
110 DCHECK_EQ(format_, NATIVE_TEXTURE); 112 DCHECK_EQ(format_, NATIVE_TEXTURE);
(...skipping 11 matching lines...) Expand all
122 size_t data_size, 124 size_t data_size,
123 base::SharedMemoryHandle handle, 125 base::SharedMemoryHandle handle,
124 base::TimeDelta timestamp, 126 base::TimeDelta timestamp,
125 const base::Closure& no_longer_needed_cb) { 127 const base::Closure& no_longer_needed_cb) {
126 if (data_size < AllocationSize(format, coded_size)) 128 if (data_size < AllocationSize(format, coded_size))
127 return NULL; 129 return NULL;
128 130
129 switch (format) { 131 switch (format) {
130 case I420: { 132 case I420: {
131 scoped_refptr<VideoFrame> frame(new VideoFrame( 133 scoped_refptr<VideoFrame> frame(new VideoFrame(
132 format, coded_size, visible_rect, natural_size, timestamp)); 134 format, coded_size, visible_rect, natural_size, timestamp, false));
133 frame->shared_memory_handle_ = handle; 135 frame->shared_memory_handle_ = handle;
134 frame->strides_[kYPlane] = coded_size.width(); 136 frame->strides_[kYPlane] = coded_size.width();
135 frame->strides_[kUPlane] = coded_size.width() / 2; 137 frame->strides_[kUPlane] = coded_size.width() / 2;
136 frame->strides_[kVPlane] = coded_size.width() / 2; 138 frame->strides_[kVPlane] = coded_size.width() / 2;
137 frame->data_[kYPlane] = data; 139 frame->data_[kYPlane] = data;
138 frame->data_[kUPlane] = data + coded_size.GetArea(); 140 frame->data_[kUPlane] = data + coded_size.GetArea();
139 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4); 141 frame->data_[kVPlane] = data + (coded_size.GetArea() * 5 / 4);
140 frame->no_longer_needed_cb_ = no_longer_needed_cb; 142 frame->no_longer_needed_cb_ = no_longer_needed_cb;
141 return frame; 143 return frame;
142 } 144 }
(...skipping 12 matching lines...) Expand all
155 int32 y_stride, 157 int32 y_stride,
156 int32 u_stride, 158 int32 u_stride,
157 int32 v_stride, 159 int32 v_stride,
158 uint8* y_data, 160 uint8* y_data,
159 uint8* u_data, 161 uint8* u_data,
160 uint8* v_data, 162 uint8* v_data,
161 base::TimeDelta timestamp, 163 base::TimeDelta timestamp,
162 const base::Closure& no_longer_needed_cb) { 164 const base::Closure& no_longer_needed_cb) {
163 DCHECK(format == YV12 || format == YV16 || format == I420) << format; 165 DCHECK(format == YV12 || format == YV16 || format == I420) << format;
164 scoped_refptr<VideoFrame> frame(new VideoFrame( 166 scoped_refptr<VideoFrame> frame(new VideoFrame(
165 format, coded_size, visible_rect, natural_size, timestamp)); 167 format, coded_size, visible_rect, natural_size, timestamp, false));
166 frame->strides_[kYPlane] = y_stride; 168 frame->strides_[kYPlane] = y_stride;
167 frame->strides_[kUPlane] = u_stride; 169 frame->strides_[kUPlane] = u_stride;
168 frame->strides_[kVPlane] = v_stride; 170 frame->strides_[kVPlane] = v_stride;
169 frame->data_[kYPlane] = y_data; 171 frame->data_[kYPlane] = y_data;
170 frame->data_[kUPlane] = u_data; 172 frame->data_[kUPlane] = u_data;
171 frame->data_[kVPlane] = v_data; 173 frame->data_[kVPlane] = v_data;
172 frame->no_longer_needed_cb_ = no_longer_needed_cb; 174 frame->no_longer_needed_cb_ = no_longer_needed_cb;
173 return frame; 175 return frame;
174 } 176 }
175 177
176 // static 178 // static
177 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { 179 scoped_refptr<VideoFrame> VideoFrame::CreateEOSFrame() {
178 return new VideoFrame( 180 return new VideoFrame(VideoFrame::UNKNOWN,
179 VideoFrame::EMPTY, gfx::Size(), gfx::Rect(), gfx::Size(), 181 gfx::Size(),
180 base::TimeDelta()); 182 gfx::Rect(),
183 gfx::Size(),
184 kNoTimestamp(),
185 true);
181 } 186 }
182 187
183 // static 188 // static
184 scoped_refptr<VideoFrame> VideoFrame::CreateColorFrame( 189 scoped_refptr<VideoFrame> VideoFrame::CreateColorFrame(
185 const gfx::Size& size, 190 const gfx::Size& size,
186 uint8 y, uint8 u, uint8 v, 191 uint8 y, uint8 u, uint8 v,
187 base::TimeDelta timestamp) { 192 base::TimeDelta timestamp) {
188 DCHECK(IsValidConfig(VideoFrame::YV12, size, gfx::Rect(size), size)); 193 DCHECK(IsValidConfig(VideoFrame::YV12, size, gfx::Rect(size), size));
189 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame( 194 scoped_refptr<VideoFrame> frame = VideoFrame::CreateFrame(
190 VideoFrame::YV12, size, gfx::Rect(size), size, timestamp); 195 VideoFrame::YV12, size, gfx::Rect(size), size, timestamp);
(...skipping 15 matching lines...) Expand all
206 // people instead: 211 // people instead:
207 // 212 //
208 // wonsik@chromium.org 213 // wonsik@chromium.org
209 // ycheo@chromium.org 214 // ycheo@chromium.org
210 215
211 // static 216 // static
212 scoped_refptr<VideoFrame> VideoFrame::CreateHoleFrame( 217 scoped_refptr<VideoFrame> VideoFrame::CreateHoleFrame(
213 const gfx::Size& size) { 218 const gfx::Size& size) {
214 DCHECK(IsValidConfig(VideoFrame::HOLE, size, gfx::Rect(size), size)); 219 DCHECK(IsValidConfig(VideoFrame::HOLE, size, gfx::Rect(size), size));
215 scoped_refptr<VideoFrame> frame(new VideoFrame( 220 scoped_refptr<VideoFrame> frame(new VideoFrame(
216 VideoFrame::HOLE, size, gfx::Rect(size), size, base::TimeDelta())); 221 VideoFrame::HOLE, size, gfx::Rect(size), size, base::TimeDelta(), false));
217 return frame; 222 return frame;
218 } 223 }
219 #endif 224 #endif
220 225
221 // static 226 // static
222 size_t VideoFrame::NumPlanes(Format format) { 227 size_t VideoFrame::NumPlanes(Format format) {
223 switch (format) { 228 switch (format) {
224 case VideoFrame::NATIVE_TEXTURE: 229 case VideoFrame::NATIVE_TEXTURE:
225 #if defined(GOOGLE_TV) 230 #if defined(GOOGLE_TV)
226 case VideoFrame::HOLE: 231 case VideoFrame::HOLE:
227 #endif 232 #endif
228 return 0; 233 return 0;
229 case VideoFrame::YV12: 234 case VideoFrame::YV12:
230 case VideoFrame::YV16: 235 case VideoFrame::YV16:
231 case VideoFrame::I420: 236 case VideoFrame::I420:
232 return 3; 237 return 3;
233 case VideoFrame::YV12A: 238 case VideoFrame::YV12A:
234 return 4; 239 return 4;
235 case VideoFrame::EMPTY:
236 case VideoFrame::UNKNOWN: 240 case VideoFrame::UNKNOWN:
237 break; 241 break;
238 } 242 }
239 NOTREACHED() << "Unsupported video frame format: " << format; 243 NOTREACHED() << "Unsupported video frame format: " << format;
240 return 0; 244 return 0;
241 } 245 }
242 246
243 static inline size_t RoundUp(size_t value, size_t alignment) { 247 static inline size_t RoundUp(size_t value, size_t alignment) {
244 // Check that |alignment| is a power of 2. 248 // Check that |alignment| is a power of 2.
245 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); 249 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
(...skipping 13 matching lines...) Expand all
259 const size_t rounded_size = 263 const size_t rounded_size =
260 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); 264 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
261 return rounded_size * 5 / 2; 265 return rounded_size * 5 / 2;
262 } 266 }
263 case VideoFrame::YV16: { 267 case VideoFrame::YV16: {
264 const size_t rounded_size = 268 const size_t rounded_size =
265 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2); 269 RoundUp(coded_size.width(), 2) * RoundUp(coded_size.height(), 2);
266 return rounded_size * 2; 270 return rounded_size * 2;
267 } 271 }
268 case VideoFrame::UNKNOWN: 272 case VideoFrame::UNKNOWN:
269 case VideoFrame::EMPTY:
270 case VideoFrame::NATIVE_TEXTURE: 273 case VideoFrame::NATIVE_TEXTURE:
271 #if defined(GOOGLE_TV) 274 #if defined(GOOGLE_TV)
272 case VideoFrame::HOLE: 275 case VideoFrame::HOLE:
273 #endif 276 #endif
274 break; 277 break;
275 } 278 }
276 NOTREACHED() << "Unsupported video frame format: " << format; 279 NOTREACHED() << "Unsupported video frame format: " << format;
277 return 0; 280 return 0;
278 } 281 }
279 282
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (format_ == YV12A) { 336 if (format_ == YV12A) {
334 data_[VideoFrame::kAPlane] = data + y_bytes + (2 * uv_bytes); 337 data_[VideoFrame::kAPlane] = data + y_bytes + (2 * uv_bytes);
335 strides_[VideoFrame::kAPlane] = y_stride; 338 strides_[VideoFrame::kAPlane] = y_stride;
336 } 339 }
337 } 340 }
338 341
339 VideoFrame::VideoFrame(VideoFrame::Format format, 342 VideoFrame::VideoFrame(VideoFrame::Format format,
340 const gfx::Size& coded_size, 343 const gfx::Size& coded_size,
341 const gfx::Rect& visible_rect, 344 const gfx::Rect& visible_rect,
342 const gfx::Size& natural_size, 345 const gfx::Size& natural_size,
343 base::TimeDelta timestamp) 346 base::TimeDelta timestamp,
347 bool end_of_stream)
344 : format_(format), 348 : format_(format),
345 coded_size_(coded_size), 349 coded_size_(coded_size),
346 visible_rect_(visible_rect), 350 visible_rect_(visible_rect),
347 natural_size_(natural_size), 351 natural_size_(natural_size),
348 texture_target_(0), 352 texture_target_(0),
349 shared_memory_handle_(base::SharedMemory::NULLHandle()), 353 shared_memory_handle_(base::SharedMemory::NULLHandle()),
350 timestamp_(timestamp) { 354 timestamp_(timestamp),
355 end_of_stream_(end_of_stream) {
351 memset(&strides_, 0, sizeof(strides_)); 356 memset(&strides_, 0, sizeof(strides_));
352 memset(&data_, 0, sizeof(data_)); 357 memset(&data_, 0, sizeof(data_));
353 } 358 }
354 359
355 VideoFrame::~VideoFrame() { 360 VideoFrame::~VideoFrame() {
356 if (!no_longer_needed_cb_.is_null()) 361 if (!no_longer_needed_cb_.is_null())
357 base::ResetAndReturn(&no_longer_needed_cb_).Run(); 362 base::ResetAndReturn(&no_longer_needed_cb_).Run();
358 } 363 }
359 364
360 bool VideoFrame::IsValidPlane(size_t plane) const { 365 bool VideoFrame::IsValidPlane(size_t plane) const {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 435
431 uint32 VideoFrame::texture_target() const { 436 uint32 VideoFrame::texture_target() const {
432 DCHECK_EQ(format_, NATIVE_TEXTURE); 437 DCHECK_EQ(format_, NATIVE_TEXTURE);
433 return texture_target_; 438 return texture_target_;
434 } 439 }
435 440
436 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const { 441 base::SharedMemoryHandle VideoFrame::shared_memory_handle() const {
437 return shared_memory_handle_; 442 return shared_memory_handle_;
438 } 443 }
439 444
440 bool VideoFrame::IsEndOfStream() const {
441 return format_ == VideoFrame::EMPTY;
442 }
443
444 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 445 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
445 for (int plane = 0; plane < kMaxPlanes; ++plane) { 446 for (int plane = 0; plane < kMaxPlanes; ++plane) {
446 if (!IsValidPlane(plane)) 447 if (!IsValidPlane(plane))
447 break; 448 break;
448 for (int row = 0; row < rows(plane); ++row) { 449 for (int row = 0; row < rows(plane); ++row) {
449 base::MD5Update(context, base::StringPiece( 450 base::MD5Update(context, base::StringPiece(
450 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 451 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
451 row_bytes(plane))); 452 row_bytes(plane)));
452 } 453 }
453 } 454 }
454 } 455 }
455 456
456 VideoFrame::MailboxHolder::MailboxHolder( 457 VideoFrame::MailboxHolder::MailboxHolder(
457 const gpu::Mailbox& mailbox, 458 const gpu::Mailbox& mailbox,
458 unsigned sync_point, 459 unsigned sync_point,
459 const TextureNoLongerNeededCallback& release_callback) 460 const TextureNoLongerNeededCallback& release_callback)
460 : mailbox_(mailbox), 461 : mailbox_(mailbox),
461 sync_point_(sync_point), 462 sync_point_(sync_point),
462 release_callback_(release_callback) {} 463 release_callback_(release_callback) {}
463 464
464 VideoFrame::MailboxHolder::~MailboxHolder() { 465 VideoFrame::MailboxHolder::~MailboxHolder() {
465 if (!release_callback_.is_null()) 466 if (!release_callback_.is_null())
466 release_callback_.Run(sync_point_); 467 release_callback_.Run(sync_point_);
467 } 468 }
468 469
469 } // namespace media 470 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.h ('k') | media/base/video_frame_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698