2023-01-05 12:25:55 +00: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-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef VIDEO_STREAM_H
|
|
|
|
#define VIDEO_STREAM_H
|
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
#include "core/io/file_access.h"
|
2014-11-02 14:31:01 +00:00
|
|
|
#include "scene/resources/texture.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-09-26 17:50:42 +00:00
|
|
|
class VideoStreamPlayback : public Resource {
|
2017-01-03 02:03:46 +00:00
|
|
|
GDCLASS(VideoStreamPlayback, Resource);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
public:
|
2017-09-14 20:45:02 +00:00
|
|
|
typedef int (*AudioMixCallback)(void *p_udata, const float *p_data, int p_frames);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00: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 14:33:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
public:
|
|
|
|
VideoStreamPlayback();
|
|
|
|
virtual ~VideoStreamPlayback();
|
2014-09-15 14:33:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
virtual void stop();
|
|
|
|
virtual void play();
|
2014-09-15 14:33:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
virtual bool is_playing() const;
|
2014-09-15 14:33:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
virtual void set_paused(bool p_paused);
|
|
|
|
virtual bool is_paused() const;
|
2014-09-15 14:33:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
virtual double get_length() const;
|
2014-09-15 14:33:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
virtual double get_playback_position() const;
|
|
|
|
virtual void seek(double p_time);
|
2014-11-12 14:23:23 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
virtual void set_audio_track(int p_idx);
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2022-07-28 22:23:11 +00:00
|
|
|
virtual Ref<Texture2D> get_texture() const;
|
|
|
|
virtual void update(double p_delta);
|
2014-09-15 14:33:30 +00:00
|
|
|
|
2022-07-28 22:23:11 +00: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 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2015-09-26 17:50:42 +00:00
|
|
|
class VideoStream : public Resource {
|
2017-01-03 02:03:46 +00:00
|
|
|
GDCLASS(VideoStream, Resource);
|
2022-07-28 22:23:11 +00:00
|
|
|
OBJ_SAVE_TYPE(VideoStream);
|
|
|
|
|
|
|
|
protected:
|
2023-10-20 15:54:39 +00:00
|
|
|
static void _bind_methods();
|
2022-07-28 22:23:11 +00:00
|
|
|
|
|
|
|
GDVIRTUAL0R(Ref<VideoStreamPlayback>, _instantiate_playback);
|
|
|
|
|
|
|
|
String file;
|
|
|
|
int audio_track = 0;
|
2015-09-26 17:50:42 +00:00
|
|
|
|
|
|
|
public:
|
2022-07-28 22:23:11 +00: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 17:50:42 +00:00
|
|
|
};
|
|
|
|
|
2022-07-23 21:41:51 +00:00
|
|
|
#endif // VIDEO_STREAM_H
|