Ocean
Loading...
Searching...
No Matches
PixelBufferAccessor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_MEDIA_AVF_PIXEL_BUFFER_ACCESSOR_H
9#define META_OCEAN_MEDIA_AVF_PIXEL_BUFFER_ACCESSOR_H
10
12
13#include "ocean/base/Frame.h"
14
15#include <AVFoundation/AVFoundation.h>
16
17namespace Ocean
18{
19
20namespace Media
21{
22
23namespace AVFoundation
24{
25
26/**
27 * This class allows to access a Core Video's CVPixelBuffer.
28 * @ingroup mediaavf
29 */
31{
32 public:
33
34 /**
35 * Creates an invalid accessor object.
36 */
38
39 /**
40 * Move constructor.
41 * @param pixelBufferAccessor The accessor to be moved
42 */
44
45 /**
46 * Creates a new accessor object based on a given pixel buffer.
47 * @param pixelBuffer The pixel buffer to be accessed
48 * @param readOnly True, access a read-only buffer; False, to access a writable buffer
49 */
50 explicit PixelBufferAccessor(CVPixelBufferRef pixelBuffer, const bool readOnly);
51
52 /*
53 * Creates a new accessor object based on a given pixel buffer.
54 * @param pixelBuffer The pixel buffer to be accessed
55 * @param readOnly True, access a read-only buffer; False, to access a writable buffer
56 * @papram accessYPlaneOnly True, to access the grayscale data only; False, to access the entire image data; if the underlying data does not have a Y plane, this flag is ignored, and the entire image is accessed
57 */
58 explicit PixelBufferAccessor(CVPixelBufferRef pixelBuffer, const bool readOnly, const bool accessYPlaneOnly);
59
60 /**
61 * Destructs an accessor object.
62 */
64
65 /**
66 * Returns the read-only frame providing access to the pixel buffer.
67 * @return The frame with read-only access, if any
68 */
69 inline const Frame& frame() const;
70
71 /**
72 * Returns the writable frame providing access to the pixel buffer.
73 * @return The frame with writable access, if any
74 */
75 inline Frame& frame();
76
77 /**
78 * Explicitly releases this accessor object.
79 * This function is also called in the constructor of this accessor.
80 */
81 void release();
82
83 /**
84 * Returns whether this accessor has access to a pixel buffer.
85 * @return True, if so
86 */
87 explicit inline operator bool() const;
88
89 /**
90 * Move operator
91 * @param pixelBufferAccessor The accessor to be moved
92 * @return Reference to this object
93 */
95
96 /**
97 * Translates an Apple platform pixel format type to an Ocean pixel format.
98 * @param pixelFormat The pixel format to translate
99 * @return The translated pixel format, FORMAT_UNDEFINED if the value could not be translated
100 */
101 static FrameType::PixelFormat translatePixelFormat(const OSType pixelFormat);
102
103 /**
104 * Translates an Ocean pixel format to an Apple platform pixel format type.
105 * @param pixelFormat The pixel format to translate
106 * @return The translated pixel format type, 0 if the value could not be translated
107 */
108 static OSType translatePixelFormat(const FrameType::PixelFormat pixelFormat);
109
110 protected:
111
112 /**
113 * Disabled copy constructor.
114 * @param pixelBufferAccessor The accessor which would be copied
115 */
116 PixelBufferAccessor(const PixelBufferAccessor& pixelBufferAccessor) = delete;
117
118 /**
119 * Disabled assign operator.
120 * @param pixelBufferAccessor The accessor which would be assigned
121 * @return Reference to this object
122 */
123 PixelBufferAccessor& operator=(const PixelBufferAccessor& pixelBufferAccessor) = delete;
124
125 protected:
126
127 /// The pixel buffer to be accessed.
128 CVPixelBufferRef pixelBuffer_ = nullptr;
129
130 /// The lock flags.
131 CVPixelBufferLockFlags lockFlags_ = 0;
132
133 /// The padding frame wrapping the pixel buffer.
135
136#ifdef OCEAN_DEBUG
137
138 /// Pointer to the frame's memory.
139 const void* debugFrameData_ = nullptr;
140
141#endif
142};
143
145{
146 return frame_;
147}
148
150{
151 return frame_;
152}
153
154inline PixelBufferAccessor::operator bool() const
155{
156 return frame_.isValid();
157}
158
159}
160
161}
162
163}
164
165#endif // META_OCEAN_MEDIA_AVF_PIXEL_BUFFER_ACCESSOR_H
This class implements Ocean's image class.
Definition Frame.h:1808
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4528
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
This class allows to access a Core Video's CVPixelBuffer.
Definition PixelBufferAccessor.h:31
void release()
Explicitly releases this accessor object.
PixelBufferAccessor(PixelBufferAccessor &&pixelBufferAccessor)
Move constructor.
const void * debugFrameData_
Pointer to the frame's memory.
Definition PixelBufferAccessor.h:139
CVPixelBufferLockFlags lockFlags_
The lock flags.
Definition PixelBufferAccessor.h:131
PixelBufferAccessor(CVPixelBufferRef pixelBuffer, const bool readOnly)
Creates a new accessor object based on a given pixel buffer.
static FrameType::PixelFormat translatePixelFormat(const OSType pixelFormat)
Translates an Apple platform pixel format type to an Ocean pixel format.
static OSType translatePixelFormat(const FrameType::PixelFormat pixelFormat)
Translates an Ocean pixel format to an Apple platform pixel format type.
PixelBufferAccessor & operator=(PixelBufferAccessor &&pixelBufferAccessor)
Move operator.
PixelBufferAccessor & operator=(const PixelBufferAccessor &pixelBufferAccessor)=delete
Disabled assign operator.
Frame frame_
The padding frame wrapping the pixel buffer.
Definition PixelBufferAccessor.h:134
PixelBufferAccessor()=default
Creates an invalid accessor object.
const Frame & frame() const
Returns the read-only frame providing access to the pixel buffer.
Definition PixelBufferAccessor.h:144
PixelBufferAccessor(CVPixelBufferRef pixelBuffer, const bool readOnly, const bool accessYPlaneOnly)
~PixelBufferAccessor()
Destructs an accessor object.
PixelBufferAccessor(const PixelBufferAccessor &pixelBufferAccessor)=delete
Disabled copy constructor.
CVPixelBufferRef pixelBuffer_
The pixel buffer to be accessed.
Definition PixelBufferAccessor.h:128
The namespace covering the entire Ocean framework.
Definition Accessor.h:15