OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_ | 5 #ifndef MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_ |
6 #define MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_ | 6 #define MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
20 #include "media/capture/capture_export.h" | 20 #include "media/capture/capture_export.h" |
21 #include "media/capture/video/video_capture_buffer_handle.h" | 21 #include "media/capture/video/video_capture_buffer_handle.h" |
22 #include "media/capture/video/video_capture_buffer_pool.h" | 22 #include "media/capture/video/video_capture_buffer_pool.h" |
23 #include "media/capture/video/video_capture_buffer_tracker_factory.h" | 23 #include "media/capture/video/video_capture_buffer_tracker_factory.h" |
24 #include "media/capture/video_capture_types.h" | 24 #include "media/capture/video_capture_types.h" |
25 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
26 #include "ui/gfx/gpu_memory_buffer.h" | 26 #include "ui/gfx/gpu_memory_buffer.h" |
27 | 27 |
28 namespace media { | 28 namespace media { |
29 | 29 |
| 30 // This implementation guarantees that, even when creating new instances, |
| 31 // a previously used |buffer_id| is never reused without first cycling through |
| 32 // the complete int range. |
30 class CAPTURE_EXPORT VideoCaptureBufferPoolImpl | 33 class CAPTURE_EXPORT VideoCaptureBufferPoolImpl |
31 : public VideoCaptureBufferPool { | 34 : public VideoCaptureBufferPool { |
32 public: | 35 public: |
33 explicit VideoCaptureBufferPoolImpl( | 36 explicit VideoCaptureBufferPoolImpl( |
34 std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory, | 37 std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory, |
35 int count); | 38 int count); |
36 | 39 |
37 // VideoCaptureBufferPool implementation. | 40 // VideoCaptureBufferPool implementation. |
38 mojo::ScopedSharedBufferHandle GetHandleForInterProcessTransit( | 41 mojo::ScopedSharedBufferHandle GetHandleForInterProcessTransit( |
39 int buffer_id) override; | 42 int buffer_id) override; |
(...skipping 26 matching lines...) Expand all Loading... |
66 | 69 |
67 VideoCaptureBufferTracker* GetTracker(int buffer_id); | 70 VideoCaptureBufferTracker* GetTracker(int buffer_id); |
68 | 71 |
69 // The max number of buffers that the pool is allowed to have at any moment. | 72 // The max number of buffers that the pool is allowed to have at any moment. |
70 const int count_; | 73 const int count_; |
71 | 74 |
72 // Protects everything below it. | 75 // Protects everything below it. |
73 mutable base::Lock lock_; | 76 mutable base::Lock lock_; |
74 | 77 |
75 // The ID of the next buffer. | 78 // The ID of the next buffer. |
76 int next_buffer_id_; | 79 static int next_buffer_id_; |
77 | 80 |
78 // The ID of the buffer last relinquished by the producer (a candidate for | 81 // The ID of the buffer last relinquished by the producer (a candidate for |
79 // resurrection). | 82 // resurrection). |
80 int last_relinquished_buffer_id_; | 83 int last_relinquished_buffer_id_; |
81 | 84 |
82 // The buffers, indexed by the first parameter, a buffer id. | 85 // The buffers, indexed by the first parameter, a buffer id. |
83 std::map<int, std::unique_ptr<VideoCaptureBufferTracker>> trackers_; | 86 std::map<int, std::unique_ptr<VideoCaptureBufferTracker>> trackers_; |
84 | 87 |
85 const std::unique_ptr<VideoCaptureBufferTrackerFactory> | 88 const std::unique_ptr<VideoCaptureBufferTrackerFactory> |
86 buffer_tracker_factory_; | 89 buffer_tracker_factory_; |
87 | 90 |
88 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPoolImpl); | 91 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPoolImpl); |
89 }; | 92 }; |
90 | 93 |
91 } // namespace media | 94 } // namespace media |
92 | 95 |
93 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_ | 96 #endif // MEDIA_CAPTURE_VIDEO_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_ |
OLD | NEW |