1/**************************************************************************/
2/* video_stream_player.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef VIDEO_STREAM_PLAYER_H
32#define VIDEO_STREAM_PLAYER_H
33
34#include "scene/gui/control.h"
35#include "scene/resources/video_stream.h"
36#include "servers/audio/audio_rb_resampler.h"
37#include "servers/audio_server.h"
38
39class ImageTexture;
40
41class VideoStreamPlayer : public Control {
42 GDCLASS(VideoStreamPlayer, Control);
43
44 struct Output {
45 AudioFrame vol;
46 int bus_index = 0;
47 Viewport *viewport = nullptr; //pointer only used for reference to previous mix
48 };
49 Ref<VideoStreamPlayback> playback;
50 Ref<VideoStream> stream;
51
52 int sp_get_channel_count() const;
53 bool mix(AudioFrame *p_buffer, int p_frames);
54
55 RID stream_rid;
56
57 Ref<ImageTexture> texture;
58
59 AudioRBResampler resampler;
60 Vector<AudioFrame> mix_buffer;
61 int wait_resampler = 0;
62 int wait_resampler_limit = 2;
63
64 bool paused = false;
65 bool paused_from_tree = false;
66 bool autoplay = false;
67 float volume = 1.0;
68 double last_audio_time = 0.0;
69 bool expand = false;
70 bool loop = false;
71 int buffering_ms = 500;
72 int audio_track = 0;
73 int bus_index = 0;
74
75 StringName bus;
76
77 void _mix_audio();
78 static int _audio_mix_callback(void *p_udata, const float *p_data, int p_frames);
79 static void _mix_audios(void *p_self);
80
81protected:
82 static void _bind_methods();
83 void _notification(int p_notification);
84 void _validate_property(PropertyInfo &p_property) const;
85
86public:
87 Size2 get_minimum_size() const override;
88 void set_expand(bool p_expand);
89 bool has_expand() const;
90
91 Ref<Texture2D> get_video_texture() const;
92
93 void set_stream(const Ref<VideoStream> &p_stream);
94 Ref<VideoStream> get_stream() const;
95
96 void play();
97 void stop();
98 bool is_playing() const;
99
100 void set_loop(bool p_loop);
101 bool has_loop() const;
102
103 void set_paused(bool p_paused);
104 bool is_paused() const;
105
106 void set_volume(float p_vol);
107 float get_volume() const;
108
109 void set_volume_db(float p_db);
110 float get_volume_db() const;
111
112 String get_stream_name() const;
113 double get_stream_length() const;
114 double get_stream_position() const;
115 void set_stream_position(double p_position);
116
117 void set_autoplay(bool p_enable);
118 bool has_autoplay() const;
119
120 void set_audio_track(int p_track);
121 int get_audio_track() const;
122
123 void set_buffering_msec(int p_msec);
124 int get_buffering_msec() const;
125
126 void set_bus(const StringName &p_bus);
127 StringName get_bus() const;
128
129 VideoStreamPlayer();
130 ~VideoStreamPlayer();
131};
132
133#endif // VIDEO_STREAM_PLAYER_H
134