| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/resources/texture.h" |
| 34 |
|
| 35 |
class VideoStreamPlayback : public Resource { |
| 36 |
GDCLASS(VideoStreamPlayback, Resource); |
| 37 |
|
| 38 |
public: |
| 39 |
typedef int (*AudioMixCallback)(void *p_udata, const float *p_data, int p_frames); |
| 40 |
|
| 41 |
protected: |
| 42 |
AudioMixCallback mix_callback = nullptr; |
| 43 |
void *mix_udata = nullptr; |
| 44 |
mutable int _channel_count = 0; |
| 45 |
|
| 46 |
static void _bind_methods(); |
| 47 |
GDVIRTUAL0(_stop); |
| 48 |
GDVIRTUAL0(_play); |
| 49 |
GDVIRTUAL0RC(bool, _is_playing); |
| 50 |
GDVIRTUAL1(_set_paused, bool); |
| 51 |
GDVIRTUAL0RC(bool, _is_paused); |
| 52 |
GDVIRTUAL0RC(double, _get_length); |
| 53 |
GDVIRTUAL0RC(double, _get_playback_position); |
| 54 |
GDVIRTUAL1(_seek, double); |
| 55 |
GDVIRTUAL1(_set_audio_track, int); |
| 56 |
GDVIRTUAL0RC(Ref<Texture2D>, _get_texture); |
| 57 |
GDVIRTUAL1_REQUIRED(_update, double); |
| 58 |
GDVIRTUAL0RC(int, _get_channels); |
| 59 |
GDVIRTUAL0RC(int, _get_mix_rate); |
| 60 |
|
| 61 |
int mix_audio(int num_frames, PackedFloat32Array buffer = {}, int offset = 0); |
| 62 |
|
| 63 |
public: |
| 64 |
VideoStreamPlayback(); |
| 65 |
virtual ~VideoStreamPlayback(); |
| 66 |
|
| 67 |
virtual void stop(); |
| 68 |
virtual void play(); |
| 69 |
|
| 70 |
virtual bool is_playing() const; |
| 71 |
|
| 72 |
virtual void set_paused(bool p_paused); |
| 73 |
virtual bool is_paused() const; |
| 74 |
|
| 75 |
virtual double get_length() const; |
| 76 |
|
| 77 |
virtual double get_playback_position() const; |
| 78 |
virtual void seek(double p_time); |
| 79 |
|
| 80 |
virtual void set_audio_track(int p_idx); |
| 81 |
|
| 82 |
virtual Ref<Texture2D> get_texture() const; |
| 83 |
virtual void update(double p_delta); |
| 84 |
|
| 85 |
virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata); |
| 86 |
virtual int get_channels() const; |
| 87 |
virtual int get_mix_rate() const; |
| 88 |
}; |
| 89 |
|
| 90 |
class VideoStream : public Resource { |
| 91 |
GDCLASS(VideoStream, Resource); |
| 92 |
OBJ_SAVE_TYPE(VideoStream); |
| 93 |
|
| 94 |
protected: |
| 95 |
static void _bind_methods(); |
| 96 |
|
| 97 |
GDVIRTUAL0R_REQUIRED(Ref<VideoStreamPlayback>, _instantiate_playback); |
| 98 |
|
| 99 |
String file; |
| 100 |
int audio_track = 0; |
| 101 |
|
| 102 |
public: |
| 103 |
void set_file(const String &p_file); |
| 104 |
String get_file(); |
| 105 |
|
| 106 |
virtual void set_audio_track(int p_track); |
| 107 |
virtual Ref<VideoStreamPlayback> instantiate_playback(); |
| 108 |
|
| 109 |
VideoStream(); |
| 110 |
~VideoStream(); |
| 111 |
}; |