2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* video_stream.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef VIDEO_STREAM_H
|
|
|
|
#define VIDEO_STREAM_H
|
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
#include "core/io/file_access.h"
|
2014-11-02 15:31:01 +01:00
|
|
|
#include "scene/resources/texture.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-09-26 19:50:42 +02:00
|
|
|
class VideoStreamPlayback : public Resource {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(VideoStreamPlayback, Resource);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
public:
|
2017-09-14 22:45:02 +02:00
|
|
|
typedef int (*AudioMixCallback)(void *p_udata, const float *p_data, int p_frames);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
protected:
|
|
|
|
AudioMixCallback mix_callback = nullptr;
|
|
|
|
void *mix_udata = nullptr;
|
|
|
|
mutable int _channel_count = 0; // Used only to assist with bounds checking in mix_audio.
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
GDVIRTUAL0(_stop);
|
|
|
|
GDVIRTUAL0(_play);
|
|
|
|
GDVIRTUAL0RC(bool, _is_playing);
|
|
|
|
GDVIRTUAL1(_set_paused, bool);
|
|
|
|
GDVIRTUAL0RC(bool, _is_paused);
|
|
|
|
GDVIRTUAL0RC(double, _get_length);
|
|
|
|
GDVIRTUAL0RC(double, _get_playback_position);
|
|
|
|
GDVIRTUAL1(_seek, double);
|
|
|
|
GDVIRTUAL1(_set_audio_track, int);
|
|
|
|
GDVIRTUAL0RC(Ref<Texture2D>, _get_texture);
|
|
|
|
GDVIRTUAL1(_update, double);
|
|
|
|
GDVIRTUAL0RC(int, _get_channels);
|
|
|
|
GDVIRTUAL0RC(int, _get_mix_rate);
|
|
|
|
|
|
|
|
int mix_audio(int num_frames, PackedFloat32Array buffer = {}, int offset = 0);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
public:
|
|
|
|
VideoStreamPlayback();
|
|
|
|
virtual ~VideoStreamPlayback();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual void stop();
|
|
|
|
virtual void play();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual bool is_playing() const;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual void set_paused(bool p_paused);
|
|
|
|
virtual bool is_paused() const;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual double get_length() const;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual double get_playback_position() const;
|
|
|
|
virtual void seek(double p_time);
|
2014-11-12 15:23:23 +01:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual void set_audio_track(int p_idx);
|
2019-06-11 20:43:37 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual Ref<Texture2D> get_texture() const;
|
|
|
|
virtual void update(double p_delta);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2022-07-29 00:23:11 +02:00
|
|
|
virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata);
|
|
|
|
virtual int get_channels() const;
|
|
|
|
virtual int get_mix_rate() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2015-09-26 19:50:42 +02:00
|
|
|
class VideoStream : public Resource {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(VideoStream, Resource);
|
2022-07-29 00:23:11 +02:00
|
|
|
OBJ_SAVE_TYPE(VideoStream);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void
|
|
|
|
_bind_methods();
|
|
|
|
|
|
|
|
GDVIRTUAL0R(Ref<VideoStreamPlayback>, _instantiate_playback);
|
|
|
|
|
|
|
|
String file;
|
|
|
|
int audio_track = 0;
|
2015-09-26 19:50:42 +02:00
|
|
|
|
|
|
|
public:
|
2022-07-29 00:23:11 +02:00
|
|
|
void set_file(const String &p_file);
|
|
|
|
String get_file();
|
|
|
|
|
|
|
|
virtual void set_audio_track(int p_track);
|
|
|
|
virtual Ref<VideoStreamPlayback> instantiate_playback();
|
|
|
|
|
|
|
|
VideoStream();
|
|
|
|
~VideoStream();
|
2015-09-26 19:50:42 +02:00
|
|
|
};
|
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#endif // VIDEO_STREAM_H
|