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

Side by Side Diff: media/capture/video/video_capture_buffer_pool_impl.h

Issue 2361173002: Move classses VideoCaptureDeviceClient and VideoCaptureBufferPool to media/capture/video (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_
6 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_
7
8 #include <stddef.h>
9
10 #include <map>
11
12 #include "base/files/file.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/shared_memory.h"
16 #include "base/process/process.h"
17 #include "base/synchronization/lock.h"
18 #include "build/build_config.h"
19 #include "media/base/video_capture_types.h"
20 #include "media/base/video_frame.h"
21 #include "media/capture/capture_export.h"
22 #include "media/capture/video/video_capture_buffer_handle.h"
23 #include "media/capture/video/video_capture_buffer_pool.h"
24 #include "media/capture/video/video_capture_buffer_tracker_factory.h"
25 #include "ui/gfx/geometry/size.h"
26 #include "ui/gfx/gpu_memory_buffer.h"
27
28 namespace media {
29
30 // A thread-safe class that does the bookkeeping and lifetime management for a
31 // pool of pixel buffers cycled between an in-process producer (e.g. a
32 // VideoCaptureDevice) and a set of out-of-process consumers. The pool is
33 // intended to be orchestrated by a VideoCaptureDevice::Client, but is designed
34 // to outlive the controller if necessary. The pixel buffers may be backed by a
35 // SharedMemory, but this is not compulsory.
36 //
37 // Producers get a buffer by calling ReserveForProducer(), and may pass on their
38 // ownership to the consumer by calling HoldForConsumers(), or drop the buffer
39 // (without further processing) by calling RelinquishProducerReservation().
40 // Consumers signal that they are done with the buffer by calling
41 // RelinquishConsumerHold().
42 //
43 // Buffers are allocated on demand, but there will never be more than |count|
44 // buffers in existence at any time. Buffers are identified by an int value
45 // called |buffer_id|. -1 (kInvalidId) is never a valid ID, and is returned by
46 // some methods to indicate failure. The active set of buffer ids may change
47 // over the lifetime of the buffer pool, as existing buffers are freed and
48 // reallocated at larger size. When reallocation occurs, new buffer IDs will
49 // circulate.
mcasas 2016/09/22 21:41:58 I think these class-comments should go in VideoCa
chfremer 2016/09/22 23:41:52 Done.
50 class CAPTURE_EXPORT VideoCaptureBufferPoolImpl
51 : public VideoCaptureBufferPool {
52 public:
53 explicit VideoCaptureBufferPoolImpl(
54 std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory,
55 int count);
56
57 // Implementation of VideoCaptureBufferPool interface:
58 bool ShareToProcess(int buffer_id,
59 base::ProcessHandle process_handle,
60 base::SharedMemoryHandle* new_handle) override;
61 bool ShareToProcess2(int buffer_id,
62 int plane,
63 base::ProcessHandle process_handle,
64 gfx::GpuMemoryBufferHandle* new_handle) override;
65 std::unique_ptr<VideoCaptureBufferHandle> GetBufferHandle(
66 int buffer_id) override;
67 int ReserveForProducer(const gfx::Size& dimensions,
68 media::VideoPixelFormat format,
69 media::VideoPixelStorage storage,
70 int* buffer_id_to_drop) override;
71 void RelinquishProducerReservation(int buffer_id) override;
72 int ResurrectLastForProducer(const gfx::Size& dimensions,
73 media::VideoPixelFormat format,
74 media::VideoPixelStorage storage) override;
75 double GetBufferPoolUtilization() const override;
76 void HoldForConsumers(int buffer_id, int num_clients) override;
77 void RelinquishConsumerHold(int buffer_id, int num_clients) override;
78
79 private:
80 friend class base::RefCountedThreadSafe<VideoCaptureBufferPoolImpl>;
81 ~VideoCaptureBufferPoolImpl() override;
82
83 int ReserveForProducerInternal(const gfx::Size& dimensions,
84 media::VideoPixelFormat format,
85 media::VideoPixelStorage storage,
86 int* tracker_id_to_drop);
87
88 VideoCaptureBufferTracker* GetTracker(int buffer_id);
89
90 // The max number of buffers that the pool is allowed to have at any moment.
91 const int count_;
92
93 // Protects everything below it.
94 mutable base::Lock lock_;
95
96 // The ID of the next buffer.
97 int next_buffer_id_;
98
99 // The ID of the buffer last relinquished by the producer (a candidate for
100 // resurrection).
101 int last_relinquished_buffer_id_;
102
103 // The buffers, indexed by the first parameter, a buffer id.
104 using TrackerMap = std::map<int, VideoCaptureBufferTracker*>;
105 TrackerMap trackers_;
106
107 std::unique_ptr<VideoCaptureBufferTrackerFactory> buffer_tracker_factory_;
mcasas 2016/09/22 21:41:58 nit: Probably can be made const.
chfremer 2016/09/22 23:41:52 Done.
108
109 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPoolImpl);
110 };
111
112 } // namespace media
113
114 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_BUFFER_POOL_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698