Skip to content

Commit 691d993

Browse files
committed
cleanup and fix windows builds
1 parent 6ca46a1 commit 691d993

4 files changed

Lines changed: 29 additions & 29 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ if (WIN32)
4545
${CMAKE_SOURCE_DIR}/lib/aom.lib
4646
${CMAKE_SOURCE_DIR}/lib/vpx.lib
4747
${CMAKE_SOURCE_DIR}/lib/openh264.lib
48-
${CMAKE_SOURCE_DIR}/lib/ws2_32.lib
49-
${CMAKE_SOURCE_DIR}/lib/mfplat.lib
50-
${CMAKE_SOURCE_DIR}/lib/mf.lib
51-
${CMAKE_SOURCE_DIR}/lib/secur32.lib
52-
${CMAKE_SOURCE_DIR}/lib/crypt32.lib
53-
${CMAKE_SOURCE_DIR}/lib/mfuuid.lib
54-
${CMAKE_SOURCE_DIR}/lib/bcrypt.lib
55-
${CMAKE_SOURCE_DIR}/lib/strmiids.lib
48+
ws2_32.lib
49+
mfplat.lib
50+
mf.lib
51+
secur32.lib
52+
crypt32.lib
53+
mfuuid.lib
54+
bcrypt.lib
55+
strmiids.lib
5656
) # windows
5757
elseif (ANDROID)
5858
if (ANDROID_ABI STREQUAL "arm64-v8a")

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "3.9.0",
2+
"geode": "4.0.0",
33
"gd": {
44
"win": "*",
55
"android": "*",

src/audio_mixer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "audio_mixer.hpp"
22

33
#include <iostream>
4+
#include <utility>
45

56
extern "C" {
67
#include <libavcodec/avcodec.h>
@@ -87,15 +88,14 @@ std::vector<float> readAudioFile(const char *filename, int targetSampleRate, AVS
8788
std::vector<float> audioFrames;
8889

8990
float *convertBuffer[2];
90-
convertBuffer[0] = (float *)av_malloc(4096 * sizeof(float));
91-
convertBuffer[1] = (float *)av_malloc(4096 * sizeof(float));
91+
convertBuffer[0] = static_cast<float *>(av_malloc(4096 * sizeof(float)));
92+
convertBuffer[1] = static_cast<float *>(av_malloc(4096 * sizeof(float)));
9293

9394
while (av_read_frame(formatContext, &packet) >= 0) {
9495
if (packet.stream_index == audioStreamIndex && avcodec_send_packet(codecContext, &packet) == 0) {
9596
while (avcodec_receive_frame(codecContext, frame) == 0) {
96-
int ret = swr_convert(swr, (uint8_t **)convertBuffer, 4096,
97-
(const uint8_t **)frame->data,
98-
frame->nb_samples);
97+
int ret = swr_convert(swr, reinterpret_cast<uint8_t **>(convertBuffer), 4096,
98+
frame->data, frame->nb_samples);
9999
if (ret < 0) {
100100
char errbuf[AV_ERROR_MAX_STRING_SIZE];
101101
av_strerror(ret, errbuf, AV_ERROR_MAX_STRING_SIZE);
@@ -125,7 +125,7 @@ std::vector<float> readAudioFile(const char *filename, int targetSampleRate, AVS
125125

126126
namespace ffmpeg {
127127
void AudioMixer::mixVideoAudio(std::filesystem::path videoFile, std::filesystem::path audioFile, std::filesystem::path outputMp4File) {
128-
const int frameSize = 1024;
128+
constexpr int frameSize = 1024;
129129

130130
AVFormatContext* wavFormatContext = nullptr;
131131
if (avformat_open_input(&wavFormatContext, audioFile.string().c_str(), nullptr, nullptr) < 0) {
@@ -137,7 +137,7 @@ namespace ffmpeg {
137137

138138
std::vector<float> raw = readAudioFile(audioFile.string().c_str(), 44100, AV_SAMPLE_FMT_FLTP, &inputAudioParams);
139139

140-
mixVideoRaw(videoFile, raw, outputMp4File, inputAudioParams.sample_rate);
140+
mixVideoRaw(std::move(videoFile), raw, std::move(outputMp4File), inputAudioParams.sample_rate);
141141

142142
avformat_close_input(&wavFormatContext);
143143
}
@@ -182,8 +182,8 @@ namespace ffmpeg {
182182
geode::log::error("Failed to create audio stream.");
183183
return;
184184
}
185-
186-
const int channels = 2;
185+
186+
constexpr int channels = 2;
187187

188188
outputAudioStream->codecpar->codec_tag = 0;
189189
outputAudioStream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -211,7 +211,7 @@ namespace ffmpeg {
211211
audio_codec_context_encoder->sample_rate = sampleRate;
212212
audio_codec_context_encoder->ch_layout = AV_CHANNEL_LAYOUT_STEREO;
213213
audio_codec_context_encoder->sample_fmt = AV_SAMPLE_FMT_FLTP;
214-
audio_codec_context_encoder->time_base = AVRational{1, (int)sampleRate};
214+
audio_codec_context_encoder->time_base = AVRational{1, static_cast<int>(sampleRate)};
215215

216216
int ret = avcodec_open2(audio_codec_context_encoder, audioCodec, nullptr);
217217
if (ret < 0) {
@@ -289,7 +289,7 @@ namespace ffmpeg {
289289

290290
AVPacket audioPacket;
291291
av_init_packet(&audioPacket);
292-
audioPacket.data = NULL;
292+
audioPacket.data = nullptr;
293293
audioPacket.size = 0;
294294

295295
while (true) {

src/recorder.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ std::vector<std::string> Recorder::getAvailableCodecs() {
2121
while ((codec = av_codec_iterate(&iter))) {
2222
if(codec->type == AVMEDIA_TYPE_VIDEO &&
2323
(codec->id == AV_CODEC_ID_H264 || codec->id == AV_CODEC_ID_HEVC || codec->id == AV_CODEC_ID_VP8 || codec->id == AV_CODEC_ID_VP9 || codec->id == AV_CODEC_ID_AV1 || codec->id == AV_CODEC_ID_MPEG4) &&
24-
avcodec_find_encoder_by_name(codec->name) != nullptr && codec->pix_fmts && std::find(vec.begin(), vec.end(), std::string(codec->name)) == vec.end())
25-
vec.push_back(codec->name);
24+
avcodec_find_encoder_by_name(codec->name) != nullptr && codec->pix_fmts && std::ranges::find(vec, std::string(codec->name)) == vec.end())
25+
vec.emplace_back(codec->name);
2626
}
2727

2828
return vec;
@@ -80,7 +80,7 @@ bool Recorder::init(const RenderSettings& settings) {
8080
const AVPixelFormat *pix_fmt = m_codec->pix_fmts;
8181
if (pix_fmt) {
8282
while (*pix_fmt != AV_PIX_FMT_NONE) {
83-
if(*pix_fmt == (AVPixelFormat)settings.m_pixelFormat)
83+
if(*pix_fmt == static_cast<AVPixelFormat>(settings.m_pixelFormat))
8484
m_codecContext->pix_fmt = *pix_fmt;
8585
++pix_fmt;
8686
}
@@ -93,7 +93,7 @@ bool Recorder::init(const RenderSettings& settings) {
9393
else
9494
geode::log::info("Codec {} supports pixel format.", settings.m_codec);
9595

96-
if (avcodec_open2(m_codecContext, m_codec, NULL) < 0) {
96+
if (avcodec_open2(m_codecContext, m_codec, nullptr) < 0) {
9797
geode::log::error("Could not open codec.");
9898
return false;
9999
}
@@ -111,13 +111,13 @@ bool Recorder::init(const RenderSettings& settings) {
111111
return false;
112112
}
113113

114-
if (avformat_write_header(m_formatContext, NULL) < 0) {
114+
if (avformat_write_header(m_formatContext, nullptr) < 0) {
115115
geode::log::error("Could not write header.");
116116
return false;
117117
}
118118

119-
m_swsCtx = sws_getContext(m_codecContext->width, m_codecContext->height, (AVPixelFormat)settings.m_pixelFormat, m_codecContext->width,
120-
m_codecContext->height, m_codecContext->pix_fmt, SWS_BILINEAR, NULL, NULL, NULL);
119+
m_swsCtx = sws_getContext(m_codecContext->width, m_codecContext->height, static_cast<AVPixelFormat>(settings.m_pixelFormat), m_codecContext->width,
120+
m_codecContext->height, m_codecContext->pix_fmt, SWS_BILINEAR, nullptr, nullptr, nullptr);
121121

122122
if (!m_swsCtx) {
123123
geode::log::error("Could not create sws context.");
@@ -178,7 +178,7 @@ bool Recorder::writeFrame(const std::vector<uint8_t>& frameData) {
178178
ret = avcodec_receive_packet(m_codecContext, m_packet);
179179
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
180180
break;
181-
else if (ret < 0)
181+
if (ret < 0)
182182
return false;
183183

184184
av_packet_rescale_ts(m_packet, m_codecContext->time_base, m_videoStream->time_base);
@@ -197,7 +197,7 @@ void Recorder::stop() {
197197

198198
m_init = false;
199199

200-
avcodec_send_frame(m_codecContext, NULL);
200+
avcodec_send_frame(m_codecContext, nullptr);
201201
while (avcodec_receive_packet(m_codecContext, m_packet) == 0) {
202202
av_packet_rescale_ts(m_packet, m_codecContext->time_base, m_videoStream->time_base);
203203
m_packet->stream_index = m_videoStream->index;

0 commit comments

Comments
 (0)