Ocean
ImageRecorder.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_IMAGE_RECORDER_H
9 #define META_OCEAN_MEDIA_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 ImageRecorder;
23 
24 /**
25  * Definition of a object reference holding an image recorder.
26  * @see SmartObjectRef, ImageRecorder.
27  * @ingroup media
28  */
30 
31 /**
32  * This class is the base class for all image recorders.
33  * An image recorder can save simple image files.<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 filename 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 file is saved.<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 ImageRecorder :
43  virtual public FrameRecorder,
44  virtual public FileRecorder
45 {
46  public:
47 
48  /**
49  * Saves a given frame as file explicity.
50  * @param frame The frame to be saved
51  * @param filename Name of the resulting image file
52  * @return True, if succeeded
53  */
54  virtual bool saveImage(const Frame& frame, const std::string& filename) = 0;
55 
56  /**
57  * Saves an image the next time a requested framebuffer is filled with valid image data.
58  * @return True, if at this point no image save process is pending
59  * @see lockBufferToFill().
60  */
61  bool start() override;
62 
63  /**
64  * Stops the recorder, this functions is unused for image recorders.
65  * @return False always
66  * @see FileRecorder::stop().
67  */
68  bool stop() override;
69 
70  /**
71  * Returns whether this recorder will save an image the next time a framebuffer is requested.
72  * @return True, if so
73  */
74  bool isRecording() const override;
75 
76  /**
77  * Returns a pointer to a framebuffer to be filled if a image save task has been requested before.
78  * @return True, if so
79  * @see start(), FrameRecorder::lockBufferToFill().
80  */
81  bool lockBufferToFill(Frame& recorderFrame, const bool respectFrameFrequency = true) override;
82 
83  /**
84  * Unlocks the filled buffer.
85  * @see lockBufferToFill().
86  */
87  void unlockBufferToFill() override;
88 
89  protected:
90 
91  /**
92  * Creates a new image recorder object.
93  */
95 
96  /**
97  * Destructs an image recorder object.
98  */
99  ~ImageRecorder() override;
100 
101  protected:
102 
103  /// State determining whether the file recorder is asked to save a new image.
105 };
106 
107 }
108 
109 }
110 
111 #endif // META_OCEAN_MEDIA_IMAGE_RECORDER_H
This class implements Ocean's image class.
Definition: Frame.h:1760
This class is the base class for all file recorders.
Definition: FileRecorder.h:37
This class is the base class for all frame recorders.
Definition: FrameRecorder.h:38
This class is the base class for all image recorders.
Definition: ImageRecorder.h:45
bool isRecording() const override
Returns whether this recorder will save an image the next time a framebuffer is requested.
bool stop() override
Stops the recorder, this functions is unused for image recorders.
~ImageRecorder() override
Destructs an image recorder object.
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.
virtual bool saveImage(const Frame &frame, const std::string &filename)=0
Saves a given frame as file explicity.
bool start() override
Saves an image the next time a requested framebuffer is filled with valid image data.
void unlockBufferToFill() override
Unlocks the filled buffer.
bool recorderSaveImage
State determining whether the file recorder is asked to save a new image.
Definition: ImageRecorder.h:104
ImageRecorder()
Creates a new image recorder object.
This template class implements a smart object reference which is a specialization of an ObjectRef obj...
Definition: SmartObjectRef.h:90
Ocean::SmartObjectRef< ImageRecorder, Recorder > ImageRecorderRef
Definition of a object reference holding an image recorder.
Definition: ImageRecorder.h:22
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15