OLD | NEW |
---|---|
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 scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format, | 23 scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format, |
24 const gfx::Size& coded_size, | 24 const gfx::Size& coded_size, |
25 const gfx::Rect& visible_rect, | 25 const gfx::Rect& visible_rect, |
26 const gfx::Size& natural_size, | 26 const gfx::Size& natural_size, |
27 base::TimeDelta timestamp); | 27 base::TimeDelta timestamp, |
28 bool zero_out_memory); | |
DaleCurtis
2015/07/09 22:21:16
This is a bit confusing since it would only happen
emircan
2015/07/09 23:16:27
True, I will go with "zero_init_new_allocations".
| |
28 | 29 |
29 // Shuts down the frame pool and releases all frames in |frames_|. | 30 // Shuts down the frame pool and releases all frames in |frames_|. |
30 // Once this is called frames will no longer be inserted back into | 31 // Once this is called frames will no longer be inserted back into |
31 // |frames_|. | 32 // |frames_|. |
32 void Shutdown(); | 33 void Shutdown(); |
33 | 34 |
34 size_t GetPoolSizeForTesting() const { return frames_.size(); } | 35 size_t GetPoolSizeForTesting() const { return frames_.size(); } |
35 | 36 |
36 private: | 37 private: |
37 friend class base::RefCountedThreadSafe<VideoFramePool::PoolImpl>; | 38 friend class base::RefCountedThreadSafe<VideoFramePool::PoolImpl>; |
(...skipping 15 matching lines...) Expand all Loading... | |
53 | 54 |
54 VideoFramePool::PoolImpl::~PoolImpl() { | 55 VideoFramePool::PoolImpl::~PoolImpl() { |
55 DCHECK(is_shutdown_); | 56 DCHECK(is_shutdown_); |
56 } | 57 } |
57 | 58 |
58 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame( | 59 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame( |
59 VideoFrame::Format format, | 60 VideoFrame::Format format, |
60 const gfx::Size& coded_size, | 61 const gfx::Size& coded_size, |
61 const gfx::Rect& visible_rect, | 62 const gfx::Rect& visible_rect, |
62 const gfx::Size& natural_size, | 63 const gfx::Size& natural_size, |
63 base::TimeDelta timestamp) { | 64 base::TimeDelta timestamp, |
65 bool zero_out_memory) { | |
64 base::AutoLock auto_lock(lock_); | 66 base::AutoLock auto_lock(lock_); |
65 DCHECK(!is_shutdown_); | 67 DCHECK(!is_shutdown_); |
66 | 68 |
67 scoped_refptr<VideoFrame> frame; | 69 scoped_refptr<VideoFrame> frame; |
68 | 70 |
69 while (!frame.get() && !frames_.empty()) { | 71 while (!frame.get() && !frames_.empty()) { |
70 scoped_refptr<VideoFrame> pool_frame = frames_.front(); | 72 scoped_refptr<VideoFrame> pool_frame = frames_.front(); |
71 frames_.pop_front(); | 73 frames_.pop_front(); |
72 | 74 |
73 if (pool_frame->format() == format && | 75 if (pool_frame->format() == format && |
74 pool_frame->coded_size() == coded_size && | 76 pool_frame->coded_size() == coded_size && |
75 pool_frame->visible_rect() == visible_rect && | 77 pool_frame->visible_rect() == visible_rect && |
76 pool_frame->natural_size() == natural_size) { | 78 pool_frame->natural_size() == natural_size) { |
77 frame = pool_frame; | 79 frame = pool_frame; |
78 frame->set_timestamp(timestamp); | 80 frame->set_timestamp(timestamp); |
79 break; | 81 break; |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
83 if (!frame.get()) { | 85 if (!frame.get()) { |
84 frame = VideoFrame::CreateFrame( | 86 frame = VideoFrame::CreateFrame( |
85 format, coded_size, visible_rect, natural_size, timestamp); | 87 format, coded_size, visible_rect, natural_size, timestamp); |
88 if (zero_out_memory) | |
89 memset(frame->data(0), 0, VideoFrame::AlignedAllocationSize(frame)); | |
86 } | 90 } |
87 | 91 |
88 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame( | 92 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame( |
89 frame, frame->visible_rect(), frame->natural_size()); | 93 frame, frame->visible_rect(), frame->natural_size()); |
90 wrapped_frame->AddDestructionObserver( | 94 wrapped_frame->AddDestructionObserver( |
91 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame)); | 95 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame)); |
92 return wrapped_frame; | 96 return wrapped_frame; |
93 } | 97 } |
94 | 98 |
95 void VideoFramePool::PoolImpl::Shutdown() { | 99 void VideoFramePool::PoolImpl::Shutdown() { |
(...skipping 16 matching lines...) Expand all Loading... | |
112 | 116 |
113 VideoFramePool::~VideoFramePool() { | 117 VideoFramePool::~VideoFramePool() { |
114 pool_->Shutdown(); | 118 pool_->Shutdown(); |
115 } | 119 } |
116 | 120 |
117 scoped_refptr<VideoFrame> VideoFramePool::CreateFrame( | 121 scoped_refptr<VideoFrame> VideoFramePool::CreateFrame( |
118 VideoFrame::Format format, | 122 VideoFrame::Format format, |
119 const gfx::Size& coded_size, | 123 const gfx::Size& coded_size, |
120 const gfx::Rect& visible_rect, | 124 const gfx::Rect& visible_rect, |
121 const gfx::Size& natural_size, | 125 const gfx::Size& natural_size, |
122 base::TimeDelta timestamp) { | 126 base::TimeDelta timestamp, |
127 bool zero_out_memory) { | |
123 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size, | 128 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size, |
124 timestamp); | 129 timestamp, zero_out_memory); |
125 } | 130 } |
126 | 131 |
127 size_t VideoFramePool::GetPoolSizeForTesting() const { | 132 size_t VideoFramePool::GetPoolSizeForTesting() const { |
128 return pool_->GetPoolSizeForTesting(); | 133 return pool_->GetPoolSizeForTesting(); |
129 } | 134 } |
130 | 135 |
131 } // namespace media | 136 } // namespace media |
OLD | NEW |