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

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

Issue 1267003004: Revert to zero-initializing buffers for FFmpegVideoDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Returning 0 for default. Created 5 years, 4 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 // See VideoFramePool::CreateFrame() for usage.
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.
23 scoped_refptr<VideoFrame> CreateFrame(VideoPixelFormat format, 21 scoped_refptr<VideoFrame> CreateFrame(VideoPixelFormat format,
24 const gfx::Size& coded_size, 22 const gfx::Size& coded_size,
25 const gfx::Rect& visible_rect, 23 const gfx::Rect& visible_rect,
26 const gfx::Size& natural_size, 24 const gfx::Size& natural_size,
27 base::TimeDelta timestamp); 25 base::TimeDelta timestamp,
26 bool zero_new_frames);
28 27
29 // Shuts down the frame pool and releases all frames in |frames_|. 28 // Shuts down the frame pool and releases all frames in |frames_|.
30 // Once this is called frames will no longer be inserted back into 29 // Once this is called frames will no longer be inserted back into
31 // |frames_|. 30 // |frames_|.
32 void Shutdown(); 31 void Shutdown();
33 32
34 size_t GetPoolSizeForTesting() const { return frames_.size(); } 33 size_t GetPoolSizeForTesting() const { return frames_.size(); }
35 34
36 private: 35 private:
37 friend class base::RefCountedThreadSafe<VideoFramePool::PoolImpl>; 36 friend class base::RefCountedThreadSafe<VideoFramePool::PoolImpl>;
(...skipping 15 matching lines...) Expand all
53 52
54 VideoFramePool::PoolImpl::~PoolImpl() { 53 VideoFramePool::PoolImpl::~PoolImpl() {
55 DCHECK(is_shutdown_); 54 DCHECK(is_shutdown_);
56 } 55 }
57 56
58 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame( 57 scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame(
59 VideoPixelFormat format, 58 VideoPixelFormat format,
60 const gfx::Size& coded_size, 59 const gfx::Size& coded_size,
61 const gfx::Rect& visible_rect, 60 const gfx::Rect& visible_rect,
62 const gfx::Size& natural_size, 61 const gfx::Size& natural_size,
63 base::TimeDelta timestamp) { 62 base::TimeDelta timestamp,
63 bool zero_new_frames) {
64 base::AutoLock auto_lock(lock_); 64 base::AutoLock auto_lock(lock_);
65 DCHECK(!is_shutdown_); 65 DCHECK(!is_shutdown_);
66 66
67 scoped_refptr<VideoFrame> frame; 67 scoped_refptr<VideoFrame> frame;
68 68
69 while (!frame.get() && !frames_.empty()) { 69 while (!frame.get() && !frames_.empty()) {
70 scoped_refptr<VideoFrame> pool_frame = frames_.front(); 70 scoped_refptr<VideoFrame> pool_frame = frames_.front();
71 frames_.pop_front(); 71 frames_.pop_front();
72 72
73 if (pool_frame->format() == format && 73 if (pool_frame->format() == format &&
74 pool_frame->coded_size() == coded_size && 74 pool_frame->coded_size() == coded_size &&
75 pool_frame->visible_rect() == visible_rect && 75 pool_frame->visible_rect() == visible_rect &&
76 pool_frame->natural_size() == natural_size) { 76 pool_frame->natural_size() == natural_size) {
77 frame = pool_frame; 77 frame = pool_frame;
78 frame->set_timestamp(timestamp); 78 frame->set_timestamp(timestamp);
79 break; 79 break;
80 } 80 }
81 } 81 }
82 82
83 if (!frame.get()) { 83 if (!frame.get()) {
84 frame = VideoFrame::CreateFrame( 84 frame = VideoFrame::CreateFrame(
85 format, coded_size, visible_rect, natural_size, timestamp); 85 format, coded_size, visible_rect, natural_size, timestamp);
86 if (zero_new_frames)
87 memset(frame->data(0), 0, frame->allocated_size());
miu 2015/08/04 20:16:22 You have enough information to memset() all the me
DaleCurtis 2015/08/04 21:20:52 This doesn't include the padding around the frame
miu 2015/08/06 21:23:30 Okay, but is it enough to ensure FFMPEG isn't read
86 } 88 }
87 89
88 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame( 90 scoped_refptr<VideoFrame> wrapped_frame = VideoFrame::WrapVideoFrame(
89 frame, frame->visible_rect(), frame->natural_size()); 91 frame, frame->visible_rect(), frame->natural_size());
90 wrapped_frame->AddDestructionObserver( 92 wrapped_frame->AddDestructionObserver(
91 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame)); 93 base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame));
92 return wrapped_frame; 94 return wrapped_frame;
93 } 95 }
94 96
95 void VideoFramePool::PoolImpl::Shutdown() { 97 void VideoFramePool::PoolImpl::Shutdown() {
(...skipping 16 matching lines...) Expand all
112 114
113 VideoFramePool::~VideoFramePool() { 115 VideoFramePool::~VideoFramePool() {
114 pool_->Shutdown(); 116 pool_->Shutdown();
115 } 117 }
116 118
117 scoped_refptr<VideoFrame> VideoFramePool::CreateFrame( 119 scoped_refptr<VideoFrame> VideoFramePool::CreateFrame(
118 VideoPixelFormat format, 120 VideoPixelFormat format,
119 const gfx::Size& coded_size, 121 const gfx::Size& coded_size,
120 const gfx::Rect& visible_rect, 122 const gfx::Rect& visible_rect,
121 const gfx::Size& natural_size, 123 const gfx::Size& natural_size,
122 base::TimeDelta timestamp) { 124 base::TimeDelta timestamp,
125 bool zero_new_frames) {
123 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size, 126 return pool_->CreateFrame(format, coded_size, visible_rect, natural_size,
124 timestamp); 127 timestamp, zero_new_frames);
125 } 128 }
126 129
127 size_t VideoFramePool::GetPoolSizeForTesting() const { 130 size_t VideoFramePool::GetPoolSizeForTesting() const {
128 return pool_->GetPoolSizeForTesting(); 131 return pool_->GetPoolSizeForTesting();
129 } 132 }
130 133
131 } // namespace media 134 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698