Skip to content

Commit

Permalink
Fix potential crash when playing video without audio stream and rando…
Browse files Browse the repository at this point in the history
…m error messages.
  • Loading branch information
EIREXE committed Nov 11, 2024
1 parent d08a36b commit ed018fb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ffmpeg_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extern "C" {
}

class FFmpegFrame : public RefCounted {
GDCLASS(FFmpegFrame, RefCounted);

protected:
static void _bind_methods();

Expand Down
5 changes: 5 additions & 0 deletions ffmpeg_video_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,12 @@ void YUVGPUConverter::convert() {

ComputeListID compute_list = rd->compute_list_begin();
rd->compute_list_bind_compute_pipeline(compute_list, pipeline);

#ifdef GDEXTENSION
rd->compute_list_set_push_constant(compute_list, push_constant_data, push_constant_data.size());
#else
rd->compute_list_set_push_constant(compute_list, push_constant_data.ptr(), push_constant_data.size());
#endif
rd->compute_list_bind_uniform_set(compute_list, yuv_planes_uniform_sets[0], 0);
rd->compute_list_bind_uniform_set(compute_list, yuv_planes_uniform_sets[1], 1);
rd->compute_list_bind_uniform_set(compute_list, yuv_planes_uniform_sets[2], 2);
Expand Down
2 changes: 2 additions & 0 deletions register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "register_types.h"
#include "godot_cpp/core/class_db.hpp"

#ifdef GDEXTENSION
#include "gdextension_build/gdex_print.h"
Expand Down Expand Up @@ -77,6 +78,7 @@ void initialize_ffmpeg_module(ModuleInitializationLevel p_level) {
GDREGISTER_ABSTRACT_CLASS(FFmpegVideoStreamPlayback);
GDREGISTER_ABSTRACT_CLASS(VideoStreamFFMpegLoader);
GDREGISTER_CLASS(FFmpegVideoStream);
GDREGISTER_INTERNAL_CLASS(FFmpegFrame);
ffmpeg_loader.instantiate();
#ifdef GDEXTENSION
ResourceLoader::get_singleton()->add_resource_format_loader(ffmpeg_loader);
Expand Down
3 changes: 1 addition & 2 deletions video_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void VideoDecoder::_decode_next_frame(AVPacket *p_packet, AVFrame *p_receive_fra

bool unref_packet = true;

if (p_packet->stream_index == video_stream->index || p_packet->stream_index == audio_stream->index) {
if ((video_stream && p_packet->stream_index == video_stream->index) || (audio_stream && p_packet->stream_index == audio_stream->index)) {
AVCodecContext *codec_ctx = video_codec_context;
if (has_audio && p_packet->stream_index == audio_stream->index) {
codec_ctx = audio_codec_context;
Expand Down Expand Up @@ -516,7 +516,6 @@ void VideoDecoder::_scaler_frame_return(Ref<FFmpegFrame> p_scaler_frame) {
Ref<FFmpegFrame> VideoDecoder::_ensure_frame_pixel_format(Ref<FFmpegFrame> p_frame, AVPixelFormat p_target_pixel_format) {
ZoneScopedN("Video decoder rescale");

print_line(p_frame->get_frame()->format);
if (p_frame->get_frame()->format == p_target_pixel_format) {
return p_frame;
}
Expand Down

0 comments on commit ed018fb

Please sign in to comment.