Ocean
MFMovieRecorder.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_MF_MOVIE_RECORDER_H
9 #define META_OCEAN_MEDIA_MF_MOVIE_RECORDER_H
10 
12 
14 
15 #include <mfreadwrite.h>
16 
17 namespace Ocean
18 {
19 
20 namespace Media
21 {
22 
23 namespace MediaFoundation
24 {
25 
26 /**
27  * This class implements a MediaFoundation movie recorder object.
28  * @ingroup mediamf
29  */
30 class OCEAN_MEDIA_MF_EXPORT MFMovieRecorder : public virtual MovieRecorder
31 {
32  friend class MFLibrary;
33 
34  public:
35 
36  /**
37  * Definition of a scoped object holding a IMFSinkWriter object.
38  * The wrapped IMFSinkWriter object will be released automatically once the scoped object does not exist anymore.
39  */
41 
42  public:
43 
44  /**
45  * Sets the filename of this recorder.
46  * The filename must be set before recordings starts.
47  * @see MovieRecorder::setFilename().
48  */
49  bool setFilename(const std::string& filename) override;
50 
51  /**
52  * Sets the preferred frame type of this recorder.
53  * @see MovieRecorder::setPreferredFrameType().
54  */
55  bool setPreferredFrameType(const FrameType& type) override;
56 
57  /**
58  * Sets the recorder.
59  * @see ExplicitRecorder::start().
60  */
61  bool start() override;
62 
63  /**
64  * Stops the recorder.
65  * @see ExplicitRecorder::stop().
66  */
67  bool stop() override;
68 
69  /**
70  * Returns whether this recorder is currently recording.
71  * @return True, if so
72  */
73  bool isRecording() const override;
74 
75  /**
76  * Returns a list of possible frame encoders for this recorder.
77  * @return Encoder names
78  */
79  Encoders frameEncoders() const override;
80 
81  /**
82  * Locks the most recent frame and returns it so that the image data can be written to this frame.
83  * @see FrameRecorder::lockBufferToFill().
84  */
85  bool lockBufferToFill(Frame& recorderFrame, const bool respectFrameFrequency = true) override;
86 
87  /**
88  * Unlocks the filled buffer.
89  * Beware: The buffer has to be locked by lockBufferToFill() before.
90  */
91  void unlockBufferToFill() override;
92 
93  /**
94  * Translate an encoder name to the corresponding video format.
95  * @param encoder The name of the encoder, must be valid
96  * @param videoFormat The resulting corresponding encoder type
97  * @return True, if succeeded
98  */
99  static bool encoderToVideoFormat(const std::string& encoder, GUID& videoFormat);
100 
101  protected:
102 
103  /**
104  * Creates a new movie recorder object.
105  */
107 
108  /**
109  * Destructs a movie recorder object.
110  */
111  ~MFMovieRecorder() override;
112 
113  /**
114  * Creates the sink writer writing the movie.
115  * @return True, if succeeded
116  */
118 
119  /**
120  * Releases the wink writer.
121  */
123 
124  protected:
125 
126  /// The sink writer to be used.
128 
129  /// The index of the stream which is used.
130  DWORD streamIndex_ = DWORD(-1);
131 
132  /// The media buffer in which the current frame will be copied.
134 
135  /// The timestamp of the next frame.
136  double nextFrameTimestamp_ = 0.0;
137 
138  /// True, if the recorder is currently actively recording.
139  bool isRecording_ = false;
140 };
141 
142 }
143 
144 }
145 
146 }
147 
148 #endif // META_OCEAN_MEDIA_MF_MOVIE_RECORDER_H
This class implements Ocean's image class.
Definition: Frame.h:1792
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
This class implements the MediaFoundation library.
Definition: MFLibrary.h:30
This class implements a MediaFoundation movie recorder object.
Definition: MFMovieRecorder.h:31
void releaseSinkWriter()
Releases the wink writer.
ScopedIMFSinkWriter sinkWriter_
The sink writer to be used.
Definition: MFMovieRecorder.h:127
bool setPreferredFrameType(const FrameType &type) override
Sets the preferred frame type of this recorder.
~MFMovieRecorder() override
Destructs a movie recorder object.
ScopedMediaFoundationObject< IMFSinkWriter > ScopedIMFSinkWriter
Definition of a scoped object holding a IMFSinkWriter object.
Definition: MFMovieRecorder.h:40
ScopedIMFMediaBuffer mediaBuffer_
The media buffer in which the current frame will be copied.
Definition: MFMovieRecorder.h:133
bool start() override
Sets the recorder.
bool lockBufferToFill(Frame &recorderFrame, const bool respectFrameFrequency=true) override
Locks the most recent frame and returns it so that the image data can be written to this frame.
Encoders frameEncoders() const override
Returns a list of possible frame encoders for this recorder.
bool isRecording() const override
Returns whether this recorder is currently recording.
bool setFilename(const std::string &filename) override
Sets the filename of this recorder.
bool stop() override
Stops the recorder.
bool createSinkWriter()
Creates the sink writer writing the movie.
static bool encoderToVideoFormat(const std::string &encoder, GUID &videoFormat)
Translate an encoder name to the corresponding video format.
void unlockBufferToFill() override
Unlocks the filled buffer.
MFMovieRecorder()
Creates a new movie recorder object.
This class is the base class for all movie recorder.
Definition: MovieRecorder.h:40
std::vector< std::string > Encoders
Definition of a vector holding encoder names.
Definition: Recorder.h:80
This class wraps an unmanaged object (or reference) which needs to be released after usage.
Definition: ScopedObject.h:166
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15