video_player.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*************************************************************************/
  2. /* video_player.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #ifndef VIDEO_PLAYER_H
  31. #define VIDEO_PLAYER_H
  32. #include "scene/gui/control.h"
  33. #include "scene/resources/video_stream.h"
  34. #include "servers/audio/audio_rb_resampler.h"
  35. #include "servers/audio_server.h"
  36. class VideoPlayer : public Control {
  37. GDCLASS(VideoPlayer, Control);
  38. struct Output {
  39. AudioFrame vol;
  40. int bus_index;
  41. Viewport *viewport; //pointer only used for reference to previous mix
  42. };
  43. Ref<VideoStreamPlayback> playback;
  44. Ref<VideoStream> stream;
  45. int sp_get_channel_count() const;
  46. bool mix(AudioFrame *p_buffer, int p_frames);
  47. RID stream_rid;
  48. Ref<ImageTexture> texture;
  49. Ref<Image> last_frame;
  50. AudioRBResampler resampler;
  51. Vector<AudioFrame> mix_buffer;
  52. int wait_resampler, wait_resampler_limit;
  53. bool paused;
  54. bool autoplay;
  55. float volume;
  56. double last_audio_time;
  57. bool expand;
  58. bool loops;
  59. int buffering_ms;
  60. int audio_track;
  61. int bus_index;
  62. StringName bus;
  63. void _mix_audio();
  64. static int _audio_mix_callback(void *p_udata, const float *p_data, int p_frames);
  65. static void _mix_audios(void *self) { reinterpret_cast<VideoPlayer *>(self)->_mix_audio(); }
  66. protected:
  67. static void _bind_methods();
  68. void _notification(int p_notification);
  69. void _validate_property(PropertyInfo &property) const;
  70. public:
  71. Size2 get_minimum_size() const;
  72. void set_expand(bool p_expand);
  73. bool has_expand() const;
  74. Ref<Texture> get_video_texture();
  75. void set_stream(const Ref<VideoStream> &p_stream);
  76. Ref<VideoStream> get_stream() const;
  77. void play();
  78. void stop();
  79. bool is_playing() const;
  80. void set_paused(bool p_paused);
  81. bool is_paused() const;
  82. void set_volume(float p_vol);
  83. float get_volume() const;
  84. void set_volume_db(float p_db);
  85. float get_volume_db() const;
  86. String get_stream_name() const;
  87. float get_stream_position() const;
  88. void set_stream_position(float p_position);
  89. void set_autoplay(bool p_enable);
  90. bool has_autoplay() const;
  91. void set_audio_track(int p_track);
  92. int get_audio_track() const;
  93. void set_buffering_msec(int p_msec);
  94. int get_buffering_msec() const;
  95. void set_bus(const StringName &p_bus);
  96. StringName get_bus() const;
  97. VideoPlayer();
  98. ~VideoPlayer();
  99. };
  100. #endif // VIDEO_PLAYER_H