You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Fix includes and initialization for GDNative Videodecoder
Fixes warnings and a crash when running the destructor with an uninitialized pcm pointer.
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os
|
|
||||||
import methods
|
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
Import('env_modules')
|
Import('env_modules')
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,9 @@
|
|||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#include "class_db.h"
|
#include "register_types.h"
|
||||||
|
|
||||||
|
#include "core/class_db.h"
|
||||||
#include "resource_importer_av_gdnative.h"
|
#include "resource_importer_av_gdnative.h"
|
||||||
#include "video_stream_gdnative.h"
|
#include "video_stream_gdnative.h"
|
||||||
|
|
||||||
@@ -41,5 +43,6 @@ void register_videodecoder_types() {
|
|||||||
#endif
|
#endif
|
||||||
ClassDB::register_class<VideoStreamGDNative>();
|
ClassDB::register_class<VideoStreamGDNative>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_videodecoder_types() {
|
void unregister_videodecoder_types() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
#include "resource_importer_av_gdnative.h"
|
#include "resource_importer_av_gdnative.h"
|
||||||
|
|
||||||
#include "io/resource_saver.h"
|
#include "core/io/resource_saver.h"
|
||||||
#include "os/file_access.h"
|
#include "core/os/file_access.h"
|
||||||
#include "scene/resources/texture.h"
|
#include "scene/resources/texture.h"
|
||||||
|
|
||||||
String ResourceImporterAVGDNative::get_importer_name() const {
|
String ResourceImporterAVGDNative::get_importer_name() const {
|
||||||
|
|||||||
@@ -31,9 +31,8 @@
|
|||||||
#ifndef RESOURCE_IMPORTER_AV_GDNATIVE_H
|
#ifndef RESOURCE_IMPORTER_AV_GDNATIVE_H
|
||||||
#define RESOURCE_IMPORTER_AV_GDNATIVE_H
|
#define RESOURCE_IMPORTER_AV_GDNATIVE_H
|
||||||
|
|
||||||
#include "video_stream_gdnative.h"
|
|
||||||
|
|
||||||
#include "core/io/resource_import.h"
|
#include "core/io/resource_import.h"
|
||||||
|
#include "video_stream_gdnative.h"
|
||||||
|
|
||||||
class ResourceImporterAVGDNative : public ResourceImporter {
|
class ResourceImporterAVGDNative : public ResourceImporter {
|
||||||
GDCLASS(ResourceImporterAVGDNative, ResourceImporter)
|
GDCLASS(ResourceImporterAVGDNative, ResourceImporter)
|
||||||
|
|||||||
@@ -29,13 +29,16 @@
|
|||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#include "video_stream_gdnative.h"
|
#include "video_stream_gdnative.h"
|
||||||
#include <project_settings.h>
|
|
||||||
#include <servers/audio_server.h>
|
#include "core/project_settings.h"
|
||||||
|
#include "servers/audio_server.h"
|
||||||
|
|
||||||
VideoDecoderServer *VideoDecoderServer::instance = NULL;
|
VideoDecoderServer *VideoDecoderServer::instance = NULL;
|
||||||
|
|
||||||
static VideoDecoderServer decoder_server;
|
static VideoDecoderServer decoder_server;
|
||||||
|
|
||||||
|
const int AUX_BUFFER_SIZE = 1024; // Buffer 1024 samples.
|
||||||
|
|
||||||
// NOTE: Callbacks for the GDNative libraries.
|
// NOTE: Callbacks for the GDNative libraries.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
godot_int GDAPI godot_videodecoder_file_read(void *ptr, uint8_t *buf, int buf_size) {
|
godot_int GDAPI godot_videodecoder_file_read(void *ptr, uint8_t *buf, int buf_size) {
|
||||||
@@ -184,12 +187,20 @@ void VideoStreamPlaybackGDNative::update_texture() {
|
|||||||
|
|
||||||
VideoStreamPlaybackGDNative::VideoStreamPlaybackGDNative() :
|
VideoStreamPlaybackGDNative::VideoStreamPlaybackGDNative() :
|
||||||
texture(Ref<ImageTexture>(memnew(ImageTexture))),
|
texture(Ref<ImageTexture>(memnew(ImageTexture))),
|
||||||
time(0),
|
playing(false),
|
||||||
|
paused(false),
|
||||||
mix_udata(NULL),
|
mix_udata(NULL),
|
||||||
mix_callback(NULL),
|
mix_callback(NULL),
|
||||||
num_channels(-1),
|
num_channels(-1),
|
||||||
|
time(0),
|
||||||
mix_rate(0),
|
mix_rate(0),
|
||||||
playing(false) {}
|
delay_compensation(0),
|
||||||
|
pcm(NULL),
|
||||||
|
pcm_write_idx(0),
|
||||||
|
samples_decoded(0),
|
||||||
|
file(NULL),
|
||||||
|
interface(NULL),
|
||||||
|
data_struct(NULL) {}
|
||||||
|
|
||||||
VideoStreamPlaybackGDNative::~VideoStreamPlaybackGDNative() {
|
VideoStreamPlaybackGDNative::~VideoStreamPlaybackGDNative() {
|
||||||
cleanup();
|
cleanup();
|
||||||
@@ -198,7 +209,8 @@ VideoStreamPlaybackGDNative::~VideoStreamPlaybackGDNative() {
|
|||||||
void VideoStreamPlaybackGDNative::cleanup() {
|
void VideoStreamPlaybackGDNative::cleanup() {
|
||||||
if (data_struct)
|
if (data_struct)
|
||||||
interface->destructor(data_struct);
|
interface->destructor(data_struct);
|
||||||
memfree(pcm);
|
if (pcm)
|
||||||
|
memfree(pcm);
|
||||||
pcm = NULL;
|
pcm = NULL;
|
||||||
time = 0;
|
time = 0;
|
||||||
num_channels = -1;
|
num_channels = -1;
|
||||||
|
|||||||
@@ -31,15 +31,15 @@
|
|||||||
#ifndef VIDEO_STREAM_GDNATIVE_H
|
#ifndef VIDEO_STREAM_GDNATIVE_H
|
||||||
#define VIDEO_STREAM_GDNATIVE_H
|
#define VIDEO_STREAM_GDNATIVE_H
|
||||||
|
|
||||||
#include <modules/gdnative/gdnative.h>
|
#include "../gdnative.h"
|
||||||
#include <os/file_access.h>
|
#include "core/os/file_access.h"
|
||||||
#include <scene/resources/texture.h>
|
#include "scene/resources/texture.h"
|
||||||
#include <scene/resources/video_stream.h>
|
#include "scene/resources/video_stream.h"
|
||||||
|
|
||||||
struct VideoDecoderGDNative {
|
struct VideoDecoderGDNative {
|
||||||
|
const godot_videodecoder_interface_gdnative *interface;
|
||||||
String plugin_name;
|
String plugin_name;
|
||||||
Vector<String> supported_extensions;
|
Vector<String> supported_extensions;
|
||||||
const godot_videodecoder_interface_gdnative *interface;
|
|
||||||
|
|
||||||
VideoDecoderGDNative() :
|
VideoDecoderGDNative() :
|
||||||
interface(NULL),
|
interface(NULL),
|
||||||
@@ -124,7 +124,6 @@ class VideoStreamPlaybackGDNative : public VideoStreamPlayback {
|
|||||||
int mix_rate;
|
int mix_rate;
|
||||||
double delay_compensation;
|
double delay_compensation;
|
||||||
|
|
||||||
const int AUX_BUFFER_SIZE = 1024; // Buffer 1024 samples.
|
|
||||||
float *pcm;
|
float *pcm;
|
||||||
int pcm_write_idx;
|
int pcm_write_idx;
|
||||||
int samples_decoded;
|
int samples_decoded;
|
||||||
@@ -135,10 +134,10 @@ class VideoStreamPlaybackGDNative : public VideoStreamPlayback {
|
|||||||
protected:
|
protected:
|
||||||
String file_name;
|
String file_name;
|
||||||
|
|
||||||
FileAccess *file = NULL;
|
FileAccess *file;
|
||||||
|
|
||||||
const godot_videodecoder_interface_gdnative *interface = NULL;
|
const godot_videodecoder_interface_gdnative *interface;
|
||||||
void *data_struct = NULL;
|
void *data_struct;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VideoStreamPlaybackGDNative();
|
VideoStreamPlaybackGDNative();
|
||||||
|
|||||||
Reference in New Issue
Block a user