Ocean
Loading...
Searching...
No Matches
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
17namespace Ocean
18{
19
20namespace Media
21{
22
23namespace MediaFoundation
24{
25
26/**
27 * This class implements a MediaFoundation movie recorder object.
28 * @ingroup mediamf
29 */
30class 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 protected:
43
44 /// The default bit rate of the recorder, in bits per second.
45 static constexpr unsigned int defaultBitrate_ = 10000000u; // 10 Mbps
46
47 public:
48
49 /**
50 * Sets the filename of this recorder.
51 * The filename must be set before recordings starts.
52 * @see MovieRecorder::setFilename().
53 */
54 bool setFilename(const std::string& filename) override;
55
56 /**
57 * Sets the preferred frame type of this recorder.
58 * @see MovieRecorder::setPreferredFrameType().
59 */
60 bool setPreferredFrameType(const FrameType& type) override;
61
62 /**
63 * Sets the preferred bit rate when recording the data.
64 * @see Recorder::setPreferredBitrate().
65 */
66 bool setPreferredBitrate(const unsigned int preferredBitrate) override;
67
68 /**
69 * Sets the recorder.
70 * @see ExplicitRecorder::start().
71 */
72 bool start() override;
73
74 /**
75 * Stops the recorder.
76 * @see ExplicitRecorder::stop().
77 */
78 bool stop() override;
79
80 /**
81 * Returns whether this recorder is currently recording.
82 * @return True, if so
83 */
84 bool isRecording() const override;
85
86 /**
87 * Returns a list of possible frame encoders for this recorder.
88 * @return Encoder names
89 */
90 Encoders frameEncoders() const override;
91
92 /**
93 * Locks the most recent frame and returns it so that the image data can be written to this frame.
94 * @see FrameRecorder::lockBufferToFill().
95 */
96 bool lockBufferToFill(Frame& recorderFrame, const bool respectFrameFrequency = true) override;
97
98 /**
99 * Unlocks the filled buffer.
100 * Beware: The buffer has to be locked by lockBufferToFill() before.
101 */
102 void unlockBufferToFill() override;
103
104 /**
105 * Translate an encoder name to the corresponding video format.
106 * @param encoder The name of the encoder, must be valid
107 * @param videoFormat The resulting corresponding encoder type
108 * @return True, if succeeded
109 */
110 static bool encoderToVideoFormat(const std::string& encoder, GUID& videoFormat);
111
112 protected:
113
114 /**
115 * Creates a new movie recorder object.
116 */
118
119 /**
120 * Destructs a movie recorder object.
121 */
123
124 /**
125 * Creates the sink writer writing the movie.
126 * @return True, if succeeded
127 */
129
130 /**
131 * Releases the wink writer.
132 */
134
135 protected:
136
137 /// The sink writer to be used.
139
140 /// The index of the stream which is used.
141 DWORD streamIndex_ = DWORD(-1);
142
143 /// The media buffer in which the current frame will be copied.
145
146 /// The timestamp of the next frame.
147 double nextFrameTimestamp_ = 0.0;
148
149 /// True, if the recorder is currently actively recording.
150 bool isRecording_ = false;
151
152 /// The preferred bitrate of the recorder, in bits per second.
153 unsigned int preferredBitrate_ = defaultBitrate_;
154};
155
156}
157
158}
159
160}
161
162#endif // META_OCEAN_MEDIA_MF_MOVIE_RECORDER_H
This class implements Ocean's image class.
Definition Frame.h:1808
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:138
bool setPreferredFrameType(const FrameType &type) override
Sets the preferred frame type of this recorder.
~MFMovieRecorder() override
Destructs a movie recorder object.
ScopedIMFMediaBuffer mediaBuffer_
The media buffer in which the current frame will be copied.
Definition MFMovieRecorder.h:144
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.
bool setPreferredBitrate(const unsigned int preferredBitrate) override
Sets the preferred bit rate when recording the data.
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