Skip to content

Commit c804be3

Browse files
committed
improve memory stuff a bit
1 parent 6768ca0 commit c804be3

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

include/events.hpp

+30-28
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ namespace impl {
2727

2828
class InitRecorderEvent : public geode::Event {
2929
public:
30-
InitRecorderEvent(void* ptr, RenderSettings&& settings) {
30+
InitRecorderEvent(void* ptr, const RenderSettings* settings) {
3131
m_ptr = ptr;
32-
m_renderSettings = std::move(settings);
32+
m_renderSettings = settings;
3333
}
3434

3535
void setResult(geode::Result<>&& result) {m_result = std::move(result);}
3636
geode::Result<> getResult() {return m_result;}
3737

3838
void* getPtr() const {return m_ptr;}
3939

40-
const RenderSettings& getRenderSettings() {return m_renderSettings;}
40+
const RenderSettings& getRenderSettings() const {return *m_renderSettings;}
4141

4242
private:
43-
RenderSettings m_renderSettings;
43+
const RenderSettings* m_renderSettings;
4444
void* m_ptr;
45-
geode::Result<> m_result = geode::Ok();
45+
geode::Result<> m_result = DEFAULT_RESULT_ERROR;
4646
};
4747

4848
class StopRecorderEvent : public geode::Event {
@@ -85,45 +85,45 @@ namespace impl {
8585

8686
class MixVideoAudioEvent : public geode::Event {
8787
public:
88-
MixVideoAudioEvent(std::filesystem::path&& videoFile, std::filesystem::path&& audioFile, std::filesystem::path&& outputMp4File) {
89-
m_videoFile = std::move(videoFile);
90-
m_audioFile = std::move(audioFile);
91-
m_outputMp4File = std::move(outputMp4File);
88+
MixVideoAudioEvent(const std::filesystem::path& videoFile, const std::filesystem::path& audioFile, const std::filesystem::path& outputMp4File) {
89+
m_videoFile = &videoFile;
90+
m_audioFile = &audioFile;
91+
m_outputMp4File = &outputMp4File;
9292
}
9393

9494
void setResult(geode::Result<>&& result) {m_result = std::move(result);}
9595
geode::Result<> getResult() {return m_result;}
9696

97-
std::filesystem::path const& getVideoFile() {return m_videoFile;}
98-
std::filesystem::path const& getAudioFile() {return m_audioFile;}
99-
std::filesystem::path const& getOutputMp4File() {return m_outputMp4File;}
97+
std::filesystem::path const& getVideoFile() const {return *m_videoFile;}
98+
std::filesystem::path const& getAudioFile() const {return *m_audioFile;}
99+
std::filesystem::path const& getOutputMp4File() const {return *m_outputMp4File;}
100100

101101
private:
102-
std::filesystem::path m_videoFile;
103-
std::filesystem::path m_audioFile;
104-
std::filesystem::path m_outputMp4File;
102+
const std::filesystem::path* m_videoFile;
103+
const std::filesystem::path* m_audioFile;
104+
const std::filesystem::path* m_outputMp4File;
105105
geode::Result<> m_result = DEFAULT_RESULT_ERROR;
106106
};
107107

108108
class MixVideoRawEvent : public geode::Event {
109109
public:
110-
MixVideoRawEvent(std::filesystem::path&& videoFile, const std::vector<float>& raw, std::filesystem::path&& outputMp4File) {
111-
m_videoFile = std::move(videoFile);
110+
MixVideoRawEvent(const std::filesystem::path& videoFile, const std::vector<float>& raw, const std::filesystem::path& outputMp4File) {
111+
m_videoFile = &videoFile;
112112
m_raw = &raw;
113-
m_outputMp4File = std::move(outputMp4File);
113+
m_outputMp4File = &outputMp4File;
114114
}
115115

116116
void setResult(const geode::Result<>& result) {m_result = geode::Result(result);}
117117
geode::Result<> getResult() {return m_result;}
118118

119-
std::filesystem::path const& getVideoFile() const {return m_videoFile;}
119+
std::filesystem::path const& getVideoFile() const {return *m_videoFile;}
120120
std::vector<float> const& getRaw() const {return *m_raw;}
121-
std::filesystem::path const& getOutputMp4File() const {return m_outputMp4File;}
121+
std::filesystem::path const& getOutputMp4File() const {return *m_outputMp4File;}
122122

123123
private:
124-
std::filesystem::path m_videoFile;
124+
const std::filesystem::path* m_videoFile;
125125
const std::vector<float>* m_raw;
126-
std::filesystem::path m_outputMp4File;
126+
const std::filesystem::path* m_outputMp4File;
127127
geode::Result<> m_result = DEFAULT_RESULT_ERROR;
128128
};
129129
#undef DEFAULT_RESULT_ERROR
@@ -142,6 +142,8 @@ class Recorder {
142142
deleteEvent.post();
143143
}
144144

145+
bool isValid() const {return m_ptr != nullptr;}
146+
145147
/**
146148
* @brief Initializes the Recorder with the specified rendering settings.
147149
*
@@ -153,8 +155,8 @@ class Recorder {
153155
*
154156
* @return true if initialization is successful, false otherwise.
155157
*/
156-
geode::Result<> init(RenderSettings&& settings) {
157-
impl::InitRecorderEvent initEvent(m_ptr, std::move(settings));
158+
geode::Result<> init(RenderSettings const& settings) {
159+
impl::InitRecorderEvent initEvent(m_ptr, &settings);
158160
initEvent.post();
159161
return initEvent.getResult();
160162
}
@@ -221,8 +223,8 @@ class AudioMixer {
221223
* @warning The audio file is expected to contain stereo (dual-channel) audio. Using other formats might lead to unexpected results.
222224
* @warning The video file is expected to contain a single video stream. Only the first video stream will be copied.
223225
*/
224-
static geode::Result<> mixVideoAudio(std::filesystem::path videoFile, std::filesystem::path audioFile, std::filesystem::path outputMp4File) {
225-
impl::MixVideoAudioEvent mixEvent(std::move(videoFile), std::move(audioFile), std::move(outputMp4File));
226+
static geode::Result<> mixVideoAudio(std::filesystem::path const& videoFile, std::filesystem::path const& audioFile, std::filesystem::path const& outputMp4File) {
227+
impl::MixVideoAudioEvent mixEvent(videoFile, audioFile, outputMp4File);
226228
mixEvent.post();
227229
return mixEvent.getResult();
228230
}
@@ -240,8 +242,8 @@ class AudioMixer {
240242
* @warning The raw audio data is expected to be stereo (dual-channel). Using mono or multi-channel audio might lead to issues.
241243
* @warning The video file is expected to contain a single video stream. Only the first video stream will be copied.
242244
*/
243-
static geode::Result<> mixVideoRaw(std::filesystem::path videoFile, const std::vector<float>& raw, std::filesystem::path outputMp4File) {
244-
impl::MixVideoRawEvent mixEvent(std::move(videoFile), raw, std::move(outputMp4File));
245+
static geode::Result<> mixVideoRaw(std::filesystem::path const& videoFile, const std::vector<float>& raw, std::filesystem::path const& outputMp4File) {
246+
impl::MixVideoRawEvent mixEvent(videoFile, raw, outputMp4File);
245247
mixEvent.post();
246248
return mixEvent.getResult();
247249
}

src/event-api/events.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using namespace geode::prelude;
3636
});
3737

3838
new EventListener<EventFilter<CodecRecorderEvent>>(+[](CodecRecorderEvent* e) {
39-
e->setCodecs(ffmpeg::Recorder::getAvailableCodecs());
39+
e->setCodecs(std::move(ffmpeg::Recorder::getAvailableCodecs()));
4040
return ListenerResult::Stop;
4141
});
4242

0 commit comments

Comments
 (0)