Skip to content

Commit

Permalink
Fixing compile errors for Windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
voylin committed Jul 30, 2024
1 parent 742b942 commit dc31f8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ int Renderer::open() {
av_codec_ctx_audio->sample_rate = 44100;
}
}
AVChannelLayout l_chlayout = AV_CHANNEL_LAYOUT_STEREO;
av_channel_layout_copy(&av_codec_ctx_audio->ch_layout, &(l_chlayout)); //&(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);

av_channel_layout_copy(&av_codec_ctx_audio->ch_layout, &(chlayout_stereo));
}

// Some formats want stream headers separated
Expand All @@ -191,7 +189,7 @@ int Renderer::open() {
// Opening the video encoder codec
response = avcodec_open2(av_codec_ctx_video, av_codec_video, NULL);
if (response < 0) {
UtilityFunctions::printerr("Couldn't open video codec!", av_err2str(response));
UtilityFunctions::printerr("Couldn't open video codec!", get_av_error());
return -3;
}

Expand Down Expand Up @@ -232,7 +230,7 @@ int Renderer::open() {
// Opening the audio encoder codec
response = avcodec_open2(av_codec_ctx_audio, av_codec_audio, NULL);
if (response < 0) {
UtilityFunctions::printerr("Couldn't open audio codec!", av_err2str(response));
UtilityFunctions::printerr("Couldn't open audio codec!", get_av_error());
return -4;
}

Expand Down Expand Up @@ -270,15 +268,15 @@ int Renderer::open() {
if (!(av_out_format->flags & AVFMT_NOFILE)) {
response = avio_open(&av_format_ctx->pb, file_path.utf8(), AVIO_FLAG_WRITE);
if (response < 0) {
UtilityFunctions::printerr("Couldn't open output file!", av_err2str(response));
UtilityFunctions::printerr("Couldn't open output file!", get_av_error());
return -5;
}
}

// Write stream header - if any
response = avformat_write_header(av_format_ctx, NULL);
if (response < 0) {
UtilityFunctions::printerr("Error when writing header!", av_err2str(response));
UtilityFunctions::printerr("Error when writing header!", get_av_error());
return -6;
}

Expand Down Expand Up @@ -309,7 +307,7 @@ int Renderer::send_frame(Ref<Image> a_frame_image) {
// Adding frame
response = avcodec_send_frame(av_codec_ctx_video, av_frame_video);
if (response < 0) {
UtilityFunctions::printerr("Error sending video frame!", av_err2str(response));
UtilityFunctions::printerr("Error sending video frame!", get_av_error());
return -1;
}

Expand All @@ -318,7 +316,7 @@ int Renderer::send_frame(Ref<Image> a_frame_image) {
if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)
break;
else if (response < 0) {
UtilityFunctions::printerr("Error encoding video frame", av_err2str(response));
UtilityFunctions::printerr("Error encoding video frame!", get_av_error());
return -1;
}

Expand All @@ -331,7 +329,7 @@ int Renderer::send_frame(Ref<Image> a_frame_image) {
// Packet is now blank as function above takes ownership of it, so no unreferencing is necessary.
// When using av_write_frame this would be needed.
if (response < 0) {
UtilityFunctions::printerr("Error whilst writing output packet!", av_err2str(response));
UtilityFunctions::printerr("Error whilst writing output packet!", get_av_error());
return -1;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/renderer.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <godot_cpp/classes/audio_stream_wav.hpp>
#include <godot_cpp/classes/image.hpp>
#include <godot_cpp/classes/resource.hpp>
#include <godot_cpp/classes/audio_stream_wav.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

extern "C" {
Expand Down Expand Up @@ -35,6 +35,7 @@ class Renderer : public Resource {

private:
static const int byte_per_pixel = 4;
static constexpr AVChannelLayout chlayout_stereo = AV_CHANNEL_LAYOUT_STEREO;
AVFormatContext *av_format_ctx = nullptr;
const AVOutputFormat *av_out_format = nullptr;
struct SwsContext *sws_ctx = nullptr;
Expand All @@ -45,6 +46,7 @@ class Renderer : public Resource {
AVStream *av_stream_video, *av_stream_audio;
AVPacket *av_packet_video = nullptr, *av_packet_audio = nullptr;
AVFrame *av_frame_video = nullptr, *av_frame_audio = nullptr;
char error_str[AV_ERROR_MAX_STRING_SIZE];
int i = 0, x = 0, y = 0, response = 0;

/* Render requirements */
Expand Down Expand Up @@ -106,6 +108,8 @@ class Renderer : public Resource {
inline void set_render_audio(bool a_value) { render_audio = a_value; }
inline bool get_render_audio() { return render_audio; }

inline char *get_av_error() { return av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, response); }

bool ready_check();

int open();
Expand Down

0 comments on commit dc31f8b

Please sign in to comment.