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

Side by Side Diff: webrtc/common_video/include/i420_buffer_pool.h

Issue 2370653003: Add limitations of number of frames that can be created in I420BufferPool::CreateBuffer. (Closed)
Patch Set: Created 4 years, 2 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 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ 11 #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_
12 #define WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ 12 #define WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_
13 13
14 #include <list> 14 #include <list>
15 15
16 #include "webrtc/base/race_checker.h" 16 #include "webrtc/base/race_checker.h"
17 #include "webrtc/common_video/include/video_frame_buffer.h" 17 #include "webrtc/common_video/include/video_frame_buffer.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 // Simple buffer pool to avoid unnecessary allocations of I420Buffer objects. 21 // Simple buffer pool to avoid unnecessary allocations of I420Buffer objects.
22 // The pool manages the memory of the I420Buffer returned from CreateBuffer. 22 // The pool manages the memory of the I420Buffer returned from CreateBuffer.
23 // When the I420Buffer is destructed, the memory is returned to the pool for use 23 // When the I420Buffer is destructed, the memory is returned to the pool for use
24 // by subsequent calls to CreateBuffer. If the resolution passed to CreateBuffer 24 // by subsequent calls to CreateBuffer. If the resolution passed to CreateBuffer
25 // changes, old buffers will be purged from the pool. 25 // changes, old buffers will be purged from the pool.
26 // Note that CreateBuffer will crash if more than kMaxNumberOfFramesBeforeCrash
27 // are created. This is to prevent memory leaks where frames are not returned.
26 class I420BufferPool { 28 class I420BufferPool {
27 public: 29 public:
28 I420BufferPool() : I420BufferPool(false) {} 30 I420BufferPool() : I420BufferPool(false) {}
29 explicit I420BufferPool(bool zero_initialize); 31 explicit I420BufferPool(bool zero_initialize);
30 32
31 // Returns a buffer from the pool, or creates a new buffer if no suitable 33 // Returns a buffer from the pool, or creates a new buffer if no suitable
32 // buffer exists in the pool. 34 // buffer exists in the pool.
33 rtc::scoped_refptr<I420Buffer> CreateBuffer(int width, int height); 35 rtc::scoped_refptr<I420Buffer> CreateBuffer(int width, int height);
34 // Clears buffers_ and detaches the thread checker so that it can be reused 36 // Clears buffers_ and detaches the thread checker so that it can be reused
35 // later from another thread. 37 // later from another thread.
36 void Release(); 38 void Release();
37 39
38 private: 40 private:
41 static const int kMaxNumberOfFramesBeforeCrash = 60;
mflodman 2016/09/26 14:36:47 I'd like to raise this limit a bit higher. Normall
perkj_webrtc 2016/09/27 07:41:41 ok- set to 300.
39 // Explicitly use a RefCountedObject to get access to HasOneRef, 42 // Explicitly use a RefCountedObject to get access to HasOneRef,
40 // needed by the pool to check exclusive access. 43 // needed by the pool to check exclusive access.
41 using PooledI420Buffer = rtc::RefCountedObject<I420Buffer>; 44 using PooledI420Buffer = rtc::RefCountedObject<I420Buffer>;
42 45
43 rtc::RaceChecker race_checker_; 46 rtc::RaceChecker race_checker_;
44 std::list<rtc::scoped_refptr<PooledI420Buffer>> buffers_; 47 std::list<rtc::scoped_refptr<PooledI420Buffer>> buffers_;
45 // If true, newly allocated buffers are zero-initialized. Note that recycled 48 // If true, newly allocated buffers are zero-initialized. Note that recycled
46 // buffers are not zero'd before reuse. This is required of buffers used by 49 // buffers are not zero'd before reuse. This is required of buffers used by
47 // FFmpeg according to http://crbug.com/390941, which only requires it for the 50 // FFmpeg according to http://crbug.com/390941, which only requires it for the
48 // initial allocation (as shown by FFmpeg's own buffer allocation code). It 51 // initial allocation (as shown by FFmpeg's own buffer allocation code). It
49 // has to do with "Use-of-uninitialized-value" on "Linux_msan_chrome". 52 // has to do with "Use-of-uninitialized-value" on "Linux_msan_chrome".
50 bool zero_initialize_; 53 bool zero_initialize_;
51 }; 54 };
52 55
53 } // namespace webrtc 56 } // namespace webrtc
54 57
55 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ 58 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_
OLDNEW
« webrtc/common_video/i420_buffer_pool.cc ('K') | « webrtc/common_video/i420_buffer_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698