1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
media / capture / video / shared_memory_buffer_tracker.h [blame]
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_CAPTURE_VIDEO_SHARED_MEMORY_BUFFER_TRACKER_H_
#define MEDIA_CAPTURE_VIDEO_SHARED_MEMORY_BUFFER_TRACKER_H_
#include "media/capture/video/video_capture_buffer_handle.h"
#include "media/capture/video/video_capture_buffer_tracker.h"
namespace gfx {
class Size;
}
namespace media {
// A tracker backed by unsafe shared memory. An unsafe region is necessary
// because a buffer may be used multiple times in an output media::VideoFrame to
// a decoder cross-process where it is written.
class SharedMemoryBufferTracker final : public VideoCaptureBufferTracker {
public:
// If |strict_pixel_format| is false, a tracker of a sufficient size
// may be reused for any requested pixel format.
// Otherwise, the tracker may be reused only for the same pixel format
// as was used for the initialization.
// It may be useful if the capturer is using different pixel format for
// ShMem and GpuMemory buffers.
explicit SharedMemoryBufferTracker(bool strict_pixel_format = false);
SharedMemoryBufferTracker(const SharedMemoryBufferTracker&) = delete;
SharedMemoryBufferTracker& operator=(const SharedMemoryBufferTracker&) =
delete;
~SharedMemoryBufferTracker() override;
// Implementation of VideoCaptureBufferTracker:
bool Init(const gfx::Size& dimensions,
VideoPixelFormat format,
const mojom::PlaneStridesPtr& strides) override;
bool IsReusableForFormat(const gfx::Size& dimensions,
VideoPixelFormat format,
const mojom::PlaneStridesPtr& strides) override;
uint32_t GetMemorySizeInBytes() override;
std::unique_ptr<VideoCaptureBufferHandle> GetMemoryMappedAccess() override;
base::UnsafeSharedMemoryRegion DuplicateAsUnsafeRegion() override;
gfx::GpuMemoryBufferHandle GetGpuMemoryBufferHandle() override;
VideoCaptureBufferType GetBufferType() override;
private:
base::UnsafeSharedMemoryRegion region_;
base::WritableSharedMemoryMapping mapping_;
// Pixel format for the underlying buffer.
VideoPixelFormat format_;
// Is the tracker reusable only for the same pixel format as used for
// initialization of the tracker.
const bool strict_pixel_format_;
};
} // namespace media
#endif // MEDIA_CAPTURE_VIDEO_SHARED_MEMORY_BUFFER_TRACKER_H_