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

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

Issue 1227383003: Remove memset from VideoFrame and mark buffer as unpoisoned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dalecurtis@ comments. Created 5 years, 5 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
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"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 class VideoFramePool::PoolImpl 15 class VideoFramePool::PoolImpl
16 : public base::RefCountedThreadSafe<VideoFramePool::PoolImpl> { 16 : public base::RefCountedThreadSafe<VideoFramePool::PoolImpl> {
17 public: 17 public:
18 PoolImpl(); 18 PoolImpl();
19 19
20 // Returns a frame from the pool that matches the specified 20 // Returns a frame from the pool that matches the specified
21 // parameters or creates a new frame if no suitable frame exists in 21 // parameters or creates a new frame if no suitable frame exists in
22 // the pool. The pool is drained if no matching frame is found. 22 // the pool. The pool is drained if no matching frame is found.
23 // If it is to create a new frame and |zero_init_new_allocations| is
DaleCurtis 2015/07/09 23:29:44 nit: If a new frame must be created and |zero_new_
emircan 2015/07/10 00:22:53 Done.
24 // true, it will zero initialize the buffer after allocation.
23 scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format, 25 scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format,
24 const gfx::Size& coded_size, 26 const gfx::Size& coded_size,
25 const gfx::Rect& visible_rect, 27 const gfx::Rect& visible_rect,
26 const gfx::Size& natural_size, 28 const gfx::Size& natural_size,
27 base::TimeDelta timestamp); 29 base::TimeDelta timestamp,
30 bool zero_init_new_allocations);
28 31
29 // Shuts down the frame pool and releases all frames in |frames_|. 32 // Shuts down the frame pool and releases all frames in |frames_|.
30 // Once this is called frames will no longer be inserted back into 33 // Once this is called frames will no longer be inserted back into
31 // |frames_|. 34 // |frames_|.
32 void Shutdown(); 35 void Shutdown();
33 36
34 size_t GetPoolSizeForTesting() const { return frames_.size(); } 37 size_t GetPoolSizeForTesting() const { return frames_.size(); }
35 38
36 private: 39 private:
37 friend class base::RefCountedThreadSafe<VideoFramePool::PoolImpl>; 40 friend class base::RefCountedThreadSafe<VideoFramePool::PoolImpl>;
(...skipping 15 matching lines...) Expand all
53 56
54 VideoFramePool::PoolImpl::~PoolImpl() { 57 VideoFramePool::PoolImpl::~PoolImpl() {
55 DCHECK(is_shutdown_); 58 DCHECK(is_shutdown_);
56 } 59 }
57 60
58 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame( 61 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame(
59 VideoFrame::Format format, 62 VideoFrame::Format format,
60 const gfx::Size& coded_size, 63 const gfx::Size& coded_size,
61 const gfx::Rect& visible_rect, 64 const gfx::Rect& visible_rect,
62 const gfx::Size& natural_size, 65 const gfx::Size& natural_size,
63 base::TimeDelta timestamp) { 66 base::TimeDelta timestamp,
67 bool zero_init_new_allocations) {
64 base::AutoLock auto_lock(lock_); 68 base::AutoLock auto_lock(lock_);
65 DCHECK(!is_shutdown_); 69 DCHECK(!is_shutdown_);
66 70
67 scoped_refptr<VideoFrame> frame; 71 scoped_refptr<VideoFrame> frame;
68 72
69 while (!frame.get() && !frames_.empty()) { 73 while (!frame.get() && !frames_.empty()) {
70 scoped_refptr<VideoFrame> pool_frame = frames_.front(); 74 scoped_refptr<VideoFrame> pool_frame = frames_.front();
71 frames_.pop_front(); 75 frames_.pop_front();
72 76
73 if (pool_frame->format() == format && 77 if (pool_frame->format() == format &&
74 pool_frame->coded_size() == coded_size && 78 pool_frame->coded_size() == coded_size &&
75 pool_frame->visible_rect() == visible_rect && 79 pool_frame->visible_rect() == visible_rect &&
76 pool_frame->natural_size() == natural_size) { 80 pool_frame->natural_size() == natural_size) {
77 frame = pool_frame; 81 frame = pool_frame;
78 frame->set_timestamp(timestamp); 82 frame->set_timestamp(timestamp);
79 break; 83 break;
80 } 84 }
81 } 85 }
82 86
83 if (!frame.get()) { 87 if (!frame.get()) {
84 frame = VideoFrame::CreateFrame( 88 frame = VideoFrame::CreateFrame(
85 format, coded_size, visible_rect, natural_size, timestamp); 89 format, coded_size, visible_rect, natural_size, timestamp);
90 if (zero_init_new_allocations)
91 memset(frame->data(0), 0, VideoFrame::AlignedAllocationSize(frame));
86 } 92 }
87 93
88 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame( 94 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame(
89 frame, frame->visible_rect(), frame->natural_size()); 95 frame, frame->visible_rect(), frame->natural_size());
90 wrapped_frame->AddDestructionObserver( 96 wrapped_frame->AddDestructionObserver(
91 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame)); 97 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame));
92 return wrapped_frame; 98 return wrapped_frame;
93 } 99 }
94 100
95 void VideoFramePool::PoolImpl::Shutdown() { 101 void VideoFramePool::PoolImpl::Shutdown() {
(...skipping 16 matching lines...) Expand all
112 118
113 VideoFramePool::~VideoFramePool() { 119 VideoFramePool::~VideoFramePool() {
114 pool_->Shutdown(); 120 pool_->Shutdown();
115 } 121 }
116 122
117 scoped_refptr<VideoFrame> VideoFramePool::CreateFrame( 123 scoped_refptr<VideoFrame> VideoFramePool::CreateFrame(
118 VideoFrame::Format format, 124 VideoFrame::Format format,
119 const gfx::Size& coded_size, 125 const gfx::Size& coded_size,
120 const gfx::Rect& visible_rect, 126 const gfx::Rect& visible_rect,
121 const gfx::Size& natural_size, 127 const gfx::Size& natural_size,
122 base::TimeDelta timestamp) { 128 base::TimeDelta timestamp,
129 bool zero_init_new_allocations) {
123 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size, 130 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size,
124 timestamp); 131 timestamp, zero_init_new_allocations);
125 } 132 }
126 133
127 size_t VideoFramePool::GetPoolSizeForTesting() const { 134 size_t VideoFramePool::GetPoolSizeForTesting() const {
128 return pool_->GetPoolSizeForTesting(); 135 return pool_->GetPoolSizeForTesting();
129 } 136 }
130 137
131 } // namespace media 138 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698