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

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

Issue 1313413010: Add VideoFrame::CreateZeroInitializedFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « media/base/video_frame.cc ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_pool.h" 5 #include "media/base/video_frame_pool.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame( 56 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame(
57 VideoPixelFormat format, 57 VideoPixelFormat format,
58 const gfx::Size& coded_size, 58 const gfx::Size& coded_size,
59 const gfx::Rect& visible_rect, 59 const gfx::Rect& visible_rect,
60 const gfx::Size& natural_size, 60 const gfx::Size& natural_size,
61 base::TimeDelta timestamp) { 61 base::TimeDelta timestamp) {
62 base::AutoLock auto_lock(lock_); 62 base::AutoLock auto_lock(lock_);
63 DCHECK(!is_shutdown_); 63 DCHECK(!is_shutdown_);
64 64
65 scoped_refptr<VideoFrame> frame; 65 scoped_refptr<VideoFrame> frame;
66
67 while (!frame.get() && !frames_.empty()) { 66 while (!frame.get() && !frames_.empty()) {
68 scoped_refptr<VideoFrame> pool_frame = frames_.front(); 67 scoped_refptr<VideoFrame> pool_frame = frames_.front();
69 frames_.pop_front(); 68 frames_.pop_front();
70 69
71 if (pool_frame->format() == format && 70 if (pool_frame->format() == format &&
72 pool_frame->coded_size() == coded_size && 71 pool_frame->coded_size() == coded_size &&
73 pool_frame->visible_rect() == visible_rect && 72 pool_frame->visible_rect() == visible_rect &&
74 pool_frame->natural_size() == natural_size) { 73 pool_frame->natural_size() == natural_size) {
75 frame = pool_frame; 74 frame = pool_frame;
76 frame->set_timestamp(timestamp); 75 frame->set_timestamp(timestamp);
77 break; 76 break;
78 } 77 }
79 } 78 }
80 79
81 if (!frame.get()) { 80 if (!frame.get()) {
82 frame = VideoFrame::CreateFrame(format, coded_size, visible_rect, 81 frame = VideoFrame::CreateZeroInitializedFrame(
83 natural_size, timestamp); 82 format, coded_size, visible_rect, natural_size, timestamp);
84
85 // Zero-initialize each plane of the buffer.
86 const size_t num_planes = VideoFrame::NumPlanes(frame->format());
87 for (size_t i = 0; i < num_planes; ++i) {
88 memset(frame->data(i),
89 0,
90 VideoFrame::PlaneSize(frame->format(),
91 i,
92 frame->coded_size()).GetArea());
93 }
94 } 83 }
95 84
96 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame( 85 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame(
97 frame, frame->visible_rect(), frame->natural_size()); 86 frame, frame->visible_rect(), frame->natural_size());
98 wrapped_frame->AddDestructionObserver( 87 wrapped_frame->AddDestructionObserver(
99 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame)); 88 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame));
100 return wrapped_frame; 89 return wrapped_frame;
101 } 90 }
102 91
103 void VideoFramePool::PoolImpl::Shutdown() { 92 void VideoFramePool::PoolImpl::Shutdown() {
(...skipping 26 matching lines...) Expand all
130 base::TimeDelta timestamp) { 119 base::TimeDelta timestamp) {
131 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size, 120 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size,
132 timestamp); 121 timestamp);
133 } 122 }
134 123
135 size_t VideoFramePool::GetPoolSizeForTesting() const { 124 size_t VideoFramePool::GetPoolSizeForTesting() const {
136 return pool_->GetPoolSizeForTesting(); 125 return pool_->GetPoolSizeForTesting();
137 } 126 }
138 127
139 } // namespace media 128 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame.cc ('k') | media/base/video_frame_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698