Ocean
BufferImageRecorder.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_BUFFER_IMAGE_RECORDER_H
9 #define META_OCEAN_MEDIA_BUFFER_IMAGE_RECORDER_H
10 
11 #include "ocean/media/Media.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Media
19 {
20 
21 // Forward declaration.
22 class BufferImageRecorder;
23 
24 /**
25  * Definition of a object reference holding an buffer recorder.
26  * @see SmartObjectRef, BufferRecorder.
27  * @ingroup media
28  */
30 
31 /**
32  * This class is the base class for all buffer recorders.
33  * A buffer recorder can store (compressed) images in memory buffers.<br>
34  * The recorder supports two different save modes: An explicit mode and an implicit one.<br>
35  * The explicit mode takes a frame and a memory buffer and saves the image directly.<br>
36  * Use the saveImage() function for the explicit mode.<br>
37  * The implicit mode provides an internal buffer to be filled. After the internal buffer is filled the image memory buffer is stored.<br>
38  * Use the lockBufferToFill() and unlockBufferToFill() functions for the implicit mode.<br>
39  * @see saveImage(), lockBufferToFill(), unlockBuffertoFill().
40  * @ingroup media
41  */
42 class OCEAN_MEDIA_EXPORT BufferImageRecorder :
43  virtual public FrameRecorder,
44  virtual public BufferRecorder
45 {
46  public:
47 
48  /**
49  * Encodes a given frame into a memory buffer.
50  * @param frame The frame to be saved, must be valid
51  * @param imageType The file extension of the image to be created (e.g. bmp, jpg, png, ...)
52  * @param buffer Resulting memory buffer which will be extended so that already existing data stays untouched
53  * @return True, if succeeded
54  * @see releaseBuffer().
55  */
56  virtual bool saveImage(const Frame& frame, const std::string& imageType, std::vector<uint8_t>& buffer) = 0;
57 
58  /**
59  * Saves an image the next time a requested framebuffer is filled with valid image data.
60  * @return True, if at this point no image save process is pending
61  * @see lockBufferToFill().
62  */
63  bool start() override;
64 
65  /**
66  * Stops the recorder, this functions is unused for image recorders.
67  * @return False always
68  * @see BufferRecorder::stop().
69  */
70  bool stop() override;
71 
72  /**
73  * Returns whether this recorder will save an image the next time a framebuffer is requested.
74  * @return True, if so
75  */
76  bool isRecording() const override;
77 
78  /**
79  * Returns a pointer to a framebuffer to be filled if a image save task has been requested before.
80  * @return True, if so
81  * @see start(), FrameRecorder::lockBufferToFill().
82  */
83  bool lockBufferToFill(Frame& recorderFrame, const bool respectFrameFrequency = true) override;
84 
85  /**
86  * Unlocks the filled buffer.
87  * @see lockBufferToFill().
88  */
89  void unlockBufferToFill() override;
90 
91  protected:
92 
93  /**
94  * Creates a new buffer image recorder object.
95  */
97 
98  /**
99  * Destructs a buffer image recorder object.
100  */
102 
103  protected:
104 
105  /// State determining whether the buffer recorder is asked to save a new image.
107 };
108 
109 }
110 
111 }
112 
113 #endif // META_OCEAN_MEDIA_BUFFER_IMAGE_RECORDER_H
This class implements Ocean's image class.
Definition: Frame.h:1792
This class is the base class for all buffer recorders.
Definition: BufferImageRecorder.h:45
bool stop() override
Stops the recorder, this functions is unused for image recorders.
bool recorderSaveImage
State determining whether the buffer recorder is asked to save a new image.
Definition: BufferImageRecorder.h:106
bool lockBufferToFill(Frame &recorderFrame, const bool respectFrameFrequency=true) override
Returns a pointer to a framebuffer to be filled if a image save task has been requested before.
BufferImageRecorder()
Creates a new buffer image recorder object.
void unlockBufferToFill() override
Unlocks the filled buffer.
bool start() override
Saves an image the next time a requested framebuffer is filled with valid image data.
bool isRecording() const override
Returns whether this recorder will save an image the next time a framebuffer is requested.
virtual bool saveImage(const Frame &frame, const std::string &imageType, std::vector< uint8_t > &buffer)=0
Encodes a given frame into a memory buffer.
~BufferImageRecorder() override
Destructs a buffer image recorder object.
This class is the base class for all buffer recorders.
Definition: BufferRecorder.h:37
This class is the base class for all frame recorders.
Definition: FrameRecorder.h:38
This template class implements a smart object reference which is a specialization of an ObjectRef obj...
Definition: SmartObjectRef.h:90
Ocean::SmartObjectRef< BufferImageRecorder, Recorder > BufferImageRecorderRef
Definition of a object reference holding an buffer recorder.
Definition: BufferImageRecorder.h:22
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15