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

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

Issue 14199002: Send hardware video frames with mailboxes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: video-mailbox: merge create/gen/produce Created 7 years, 6 months 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
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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 visible_rect.right() <= coded_size.width() && 57 visible_rect.right() <= coded_size.width() &&
58 visible_rect.bottom() <= coded_size.height() && 58 visible_rect.bottom() <= coded_size.height() &&
59 !natural_size.IsEmpty() && 59 !natural_size.IsEmpty() &&
60 natural_size.GetArea() <= limits::kMaxCanvas && 60 natural_size.GetArea() <= limits::kMaxCanvas &&
61 natural_size.width() <= limits::kMaxDimension && 61 natural_size.width() <= limits::kMaxDimension &&
62 natural_size.height() <= limits::kMaxDimension); 62 natural_size.height() <= limits::kMaxDimension);
63 } 63 }
64 64
65 // static 65 // static
66 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( 66 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture(
67 uint32 texture_id, 67 const gpu::Mailbox& texture_mailbox,
68 uint32 sync_point,
68 uint32 texture_target, 69 uint32 texture_target,
69 const gfx::Size& coded_size, 70 const gfx::Size& coded_size,
70 const gfx::Rect& visible_rect, 71 const gfx::Rect& visible_rect,
71 const gfx::Size& natural_size, 72 const gfx::Size& natural_size,
72 base::TimeDelta timestamp, 73 base::TimeDelta timestamp,
73 const ReadPixelsCB& read_pixels_cb, 74 const ReadPixelsCB& read_pixels_cb,
75 const TextureNoLongerNeededCallback& texture_no_longer_needed_cb,
74 const base::Closure& no_longer_needed_cb) { 76 const base::Closure& no_longer_needed_cb) {
75 scoped_refptr<VideoFrame> frame(new VideoFrame( 77 scoped_refptr<VideoFrame> frame(new VideoFrame(
76 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); 78 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp));
77 frame->texture_id_ = texture_id; 79 frame->texture_mailbox_holder_ = new MailboxHolder(
80 texture_mailbox, sync_point, texture_no_longer_needed_cb);
78 frame->texture_target_ = texture_target; 81 frame->texture_target_ = texture_target;
79 frame->read_pixels_cb_ = read_pixels_cb; 82 frame->read_pixels_cb_ = read_pixels_cb;
80 frame->no_longer_needed_cb_ = no_longer_needed_cb; 83 frame->no_longer_needed_cb_ = no_longer_needed_cb;
84
81 return frame; 85 return frame;
82 } 86 }
83 87
84 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { 88 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) {
85 DCHECK_EQ(format_, NATIVE_TEXTURE); 89 DCHECK_EQ(format_, NATIVE_TEXTURE);
86 if (!read_pixels_cb_.is_null()) 90 if (!read_pixels_cb_.is_null())
87 read_pixels_cb_.Run(pixels); 91 read_pixels_cb_.Run(pixels);
88 } 92 }
89 93
90 // static 94 // static
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 263
260 VideoFrame::VideoFrame(VideoFrame::Format format, 264 VideoFrame::VideoFrame(VideoFrame::Format format,
261 const gfx::Size& coded_size, 265 const gfx::Size& coded_size,
262 const gfx::Rect& visible_rect, 266 const gfx::Rect& visible_rect,
263 const gfx::Size& natural_size, 267 const gfx::Size& natural_size,
264 base::TimeDelta timestamp) 268 base::TimeDelta timestamp)
265 : format_(format), 269 : format_(format),
266 coded_size_(coded_size), 270 coded_size_(coded_size),
267 visible_rect_(visible_rect), 271 visible_rect_(visible_rect),
268 natural_size_(natural_size), 272 natural_size_(natural_size),
269 texture_id_(0),
270 texture_target_(0), 273 texture_target_(0),
271 timestamp_(timestamp) { 274 timestamp_(timestamp) {
272 memset(&strides_, 0, sizeof(strides_)); 275 memset(&strides_, 0, sizeof(strides_));
273 memset(&data_, 0, sizeof(data_)); 276 memset(&data_, 0, sizeof(data_));
274 } 277 }
275 278
276 VideoFrame::~VideoFrame() { 279 VideoFrame::~VideoFrame() {
277 if (!no_longer_needed_cb_.is_null()) 280 if (!no_longer_needed_cb_.is_null())
278 base::ResetAndReturn(&no_longer_needed_cb_).Run(); 281 base::ResetAndReturn(&no_longer_needed_cb_).Run();
279 } 282 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Intentionally leave out non-production formats. 336 // Intentionally leave out non-production formats.
334 NOTREACHED() << "Unsupported video frame format: " << format_; 337 NOTREACHED() << "Unsupported video frame format: " << format_;
335 return 0; 338 return 0;
336 } 339 }
337 340
338 uint8* VideoFrame::data(size_t plane) const { 341 uint8* VideoFrame::data(size_t plane) const {
339 DCHECK(IsValidPlane(plane)); 342 DCHECK(IsValidPlane(plane));
340 return data_[plane]; 343 return data_[plane];
341 } 344 }
342 345
343 uint32 VideoFrame::texture_id() const { 346 const scoped_refptr<VideoFrame::MailboxHolder>& VideoFrame::texture_mailbox()
347 const {
344 DCHECK_EQ(format_, NATIVE_TEXTURE); 348 DCHECK_EQ(format_, NATIVE_TEXTURE);
345 return texture_id_; 349 return texture_mailbox_holder_;
346 } 350 }
347 351
348 uint32 VideoFrame::texture_target() const { 352 uint32 VideoFrame::texture_target() const {
349 DCHECK_EQ(format_, NATIVE_TEXTURE); 353 DCHECK_EQ(format_, NATIVE_TEXTURE);
350 return texture_target_; 354 return texture_target_;
351 } 355 }
352 356
353 bool VideoFrame::IsEndOfStream() const { 357 bool VideoFrame::IsEndOfStream() const {
354 return format_ == VideoFrame::EMPTY; 358 return format_ == VideoFrame::EMPTY;
355 } 359 }
356 360
357 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 361 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
358 for (int plane = 0; plane < kMaxPlanes; ++plane) { 362 for (int plane = 0; plane < kMaxPlanes; ++plane) {
359 if (!IsValidPlane(plane)) 363 if (!IsValidPlane(plane))
360 break; 364 break;
361 for (int row = 0; row < rows(plane); ++row) { 365 for (int row = 0; row < rows(plane); ++row) {
362 base::MD5Update(context, base::StringPiece( 366 base::MD5Update(context, base::StringPiece(
363 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 367 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
364 row_bytes(plane))); 368 row_bytes(plane)));
365 } 369 }
366 } 370 }
367 } 371 }
368 372
373 VideoFrame::MailboxHolder::MailboxHolder(
374 const gpu::Mailbox& mailbox,
375 unsigned sync_point,
376 const TextureNoLongerNeededCallback& release_callback)
377 : mailbox_(mailbox),
378 sync_point_(sync_point),
379 release_callback_(release_callback) {}
380
381 VideoFrame::MailboxHolder::~MailboxHolder() {
382 if (!release_callback_.is_null())
383 release_callback_.Run(sync_point_);
scherkus (not reviewing) 2013/06/17 20:20:37 are we worried about clients calling texture_mailb
danakj 2013/06/18 00:45:05 That is intended. The compositor may hold onto the
scherkus (not reviewing) 2013/06/18 00:52:18 Gotcha -- thanks for the background info! Seeing
danakj 2013/06/18 16:54:12 Done.
384 }
385
369 } // namespace media 386 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698