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

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: Ifdefed Created 7 years, 8 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 visible_rect.right() <= coded_size.width() && 56 visible_rect.right() <= coded_size.width() &&
57 visible_rect.bottom() <= coded_size.height() && 57 visible_rect.bottom() <= coded_size.height() &&
58 !natural_size.IsEmpty() && 58 !natural_size.IsEmpty() &&
59 natural_size.GetArea() <= limits::kMaxCanvas && 59 natural_size.GetArea() <= limits::kMaxCanvas &&
60 natural_size.width() <= limits::kMaxDimension && 60 natural_size.width() <= limits::kMaxDimension &&
61 natural_size.height() <= limits::kMaxDimension); 61 natural_size.height() <= limits::kMaxDimension);
62 } 62 }
63 63
64 // static 64 // static
65 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( 65 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture(
66 #ifdef VIDEO_FRAME_MAILBOX
67 const gpu::Mailbox& texture_mailbox,
68 uint32 sync_point,
69 #else
66 uint32 texture_id, 70 uint32 texture_id,
71 #endif
67 uint32 texture_target, 72 uint32 texture_target,
68 const gfx::Size& coded_size, 73 const gfx::Size& coded_size,
69 const gfx::Rect& visible_rect, 74 const gfx::Rect& visible_rect,
70 const gfx::Size& natural_size, 75 const gfx::Size& natural_size,
71 base::TimeDelta timestamp, 76 base::TimeDelta timestamp,
72 const ReadPixelsCB& read_pixels_cb, 77 const ReadPixelsCB& read_pixels_cb,
78 const TextureNoLongerNeededCallback& texture_no_longer_needed_cb,
73 const base::Closure& no_longer_needed_cb) { 79 const base::Closure& no_longer_needed_cb) {
74 scoped_refptr<VideoFrame> frame(new VideoFrame( 80 scoped_refptr<VideoFrame> frame(new VideoFrame(
75 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp)); 81 NATIVE_TEXTURE, coded_size, visible_rect, natural_size, timestamp));
82 #ifdef VIDEO_FRAME_MAILBOX
83 frame->texture_mailbox_ = texture_mailbox;
84 frame->texture_mailbox_sync_point_ = sync_point;
85 #else
76 frame->texture_id_ = texture_id; 86 frame->texture_id_ = texture_id;
87 #endif
77 frame->texture_target_ = texture_target; 88 frame->texture_target_ = texture_target;
78 frame->read_pixels_cb_ = read_pixels_cb; 89 frame->read_pixels_cb_ = read_pixels_cb;
79 frame->no_longer_needed_cb_ = no_longer_needed_cb; 90 frame->no_longer_needed_cb_ = no_longer_needed_cb;
91 frame->texture_no_longer_needed_cb_ = texture_no_longer_needed_cb;
80 return frame; 92 return frame;
81 } 93 }
82 94
83 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) { 95 void VideoFrame::ReadPixelsFromNativeTexture(const SkBitmap& pixels) {
84 DCHECK_EQ(format_, NATIVE_TEXTURE); 96 DCHECK_EQ(format_, NATIVE_TEXTURE);
85 if (!read_pixels_cb_.is_null()) 97 if (!read_pixels_cb_.is_null())
86 read_pixels_cb_.Run(pixels); 98 read_pixels_cb_.Run(pixels);
87 } 99 }
88 100
89 // static 101 // static
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 258
247 VideoFrame::VideoFrame(VideoFrame::Format format, 259 VideoFrame::VideoFrame(VideoFrame::Format format,
248 const gfx::Size& coded_size, 260 const gfx::Size& coded_size,
249 const gfx::Rect& visible_rect, 261 const gfx::Rect& visible_rect,
250 const gfx::Size& natural_size, 262 const gfx::Size& natural_size,
251 base::TimeDelta timestamp) 263 base::TimeDelta timestamp)
252 : format_(format), 264 : format_(format),
253 coded_size_(coded_size), 265 coded_size_(coded_size),
254 visible_rect_(visible_rect), 266 visible_rect_(visible_rect),
255 natural_size_(natural_size), 267 natural_size_(natural_size),
268 #ifndef VIDEO_FRAME_MAILBOX
256 texture_id_(0), 269 texture_id_(0),
270 #endif
257 texture_target_(0), 271 texture_target_(0),
258 timestamp_(timestamp) { 272 timestamp_(timestamp) {
259 memset(&strides_, 0, sizeof(strides_)); 273 memset(&strides_, 0, sizeof(strides_));
260 memset(&data_, 0, sizeof(data_)); 274 memset(&data_, 0, sizeof(data_));
261 } 275 }
262 276
263 VideoFrame::~VideoFrame() { 277 VideoFrame::~VideoFrame() {
278 if (!texture_no_longer_needed_cb_.is_null()) {
279 base::ResetAndReturn(&texture_no_longer_needed_cb_).Run(
280 #ifdef VIDEO_FRAME_MAILBOX
281 texture_mailbox_sync_point_);
282 #else
283 0);
284 #endif
285 }
264 if (!no_longer_needed_cb_.is_null()) 286 if (!no_longer_needed_cb_.is_null())
265 base::ResetAndReturn(&no_longer_needed_cb_).Run(); 287 base::ResetAndReturn(&no_longer_needed_cb_).Run();
266 } 288 }
267 289
268 bool VideoFrame::IsValidPlane(size_t plane) const { 290 bool VideoFrame::IsValidPlane(size_t plane) const {
269 return (plane < NumPlanes(format_)); 291 return (plane < NumPlanes(format_));
270 } 292 }
271 293
272 int VideoFrame::stride(size_t plane) const { 294 int VideoFrame::stride(size_t plane) const {
273 DCHECK(IsValidPlane(plane)); 295 DCHECK(IsValidPlane(plane));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // Intentionally leave out non-production formats. 340 // Intentionally leave out non-production formats.
319 NOTREACHED() << "Unsupported video frame format: " << format_; 341 NOTREACHED() << "Unsupported video frame format: " << format_;
320 return 0; 342 return 0;
321 } 343 }
322 344
323 uint8* VideoFrame::data(size_t plane) const { 345 uint8* VideoFrame::data(size_t plane) const {
324 DCHECK(IsValidPlane(plane)); 346 DCHECK(IsValidPlane(plane));
325 return data_[plane]; 347 return data_[plane];
326 } 348 }
327 349
350 #ifdef VIDEO_FRAME_MAILBOX
351 const gpu::Mailbox& VideoFrame::texture_mailbox() const {
352 DCHECK_EQ(format_, NATIVE_TEXTURE);
353 return texture_mailbox_;
354 }
355
356 uint32 VideoFrame::texture_mailbox_sync_point() const {
357 DCHECK_EQ(format_, NATIVE_TEXTURE);
358 return texture_mailbox_sync_point_;
359 }
360
361 void VideoFrame::set_texture_mailbox_sync_point(uint32 sync_point) {
362 DCHECK_EQ(format_, NATIVE_TEXTURE);
363 texture_mailbox_sync_point_ = sync_point;
364 }
365 #else
328 uint32 VideoFrame::texture_id() const { 366 uint32 VideoFrame::texture_id() const {
329 DCHECK_EQ(format_, NATIVE_TEXTURE); 367 DCHECK_EQ(format_, NATIVE_TEXTURE);
330 return texture_id_; 368 return texture_id_;
331 } 369 }
370 #endif
332 371
333 uint32 VideoFrame::texture_target() const { 372 uint32 VideoFrame::texture_target() const {
334 DCHECK_EQ(format_, NATIVE_TEXTURE); 373 DCHECK_EQ(format_, NATIVE_TEXTURE);
335 return texture_target_; 374 return texture_target_;
336 } 375 }
337 376
338 bool VideoFrame::IsEndOfStream() const { 377 bool VideoFrame::IsEndOfStream() const {
339 return format_ == VideoFrame::EMPTY; 378 return format_ == VideoFrame::EMPTY;
340 } 379 }
341 380
342 void VideoFrame::HashFrameForTesting(base::MD5Context* context) { 381 void VideoFrame::HashFrameForTesting(base::MD5Context* context) {
343 for (int plane = 0; plane < kMaxPlanes; ++plane) { 382 for (int plane = 0; plane < kMaxPlanes; ++plane) {
344 if (!IsValidPlane(plane)) 383 if (!IsValidPlane(plane))
345 break; 384 break;
346 for (int row = 0; row < rows(plane); ++row) { 385 for (int row = 0; row < rows(plane); ++row) {
347 base::MD5Update(context, base::StringPiece( 386 base::MD5Update(context, base::StringPiece(
348 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 387 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
349 row_bytes(plane))); 388 row_bytes(plane)));
350 } 389 }
351 } 390 }
352 } 391 }
353 392
354 } // namespace media 393 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698