video_stream.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**************************************************************************/
  2. /* video_stream.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. #ifndef VIDEO_STREAM_H
  31. #define VIDEO_STREAM_H
  32. #include "scene/resources/texture.h"
  33. class VideoStreamPlayback : public Resource {
  34. GDCLASS(VideoStreamPlayback, Resource);
  35. public:
  36. typedef int (*AudioMixCallback)(void *p_udata, const float *p_data, int p_frames);
  37. protected:
  38. AudioMixCallback mix_callback = nullptr;
  39. void *mix_udata = nullptr;
  40. mutable int _channel_count = 0; // Used only to assist with bounds checking in mix_audio.
  41. static void _bind_methods();
  42. GDVIRTUAL0(_stop);
  43. GDVIRTUAL0(_play);
  44. GDVIRTUAL0RC(bool, _is_playing);
  45. GDVIRTUAL1(_set_paused, bool);
  46. GDVIRTUAL0RC(bool, _is_paused);
  47. GDVIRTUAL0RC(double, _get_length);
  48. GDVIRTUAL0RC(double, _get_playback_position);
  49. GDVIRTUAL1(_seek, double);
  50. GDVIRTUAL1(_set_audio_track, int);
  51. GDVIRTUAL0RC(Ref<Texture2D>, _get_texture);
  52. GDVIRTUAL1_REQUIRED(_update, double);
  53. GDVIRTUAL0RC(int, _get_channels);
  54. GDVIRTUAL0RC(int, _get_mix_rate);
  55. int mix_audio(int num_frames, PackedFloat32Array buffer = {}, int offset = 0);
  56. public:
  57. VideoStreamPlayback();
  58. virtual ~VideoStreamPlayback();
  59. virtual void stop();
  60. virtual void play();
  61. virtual bool is_playing() const;
  62. virtual void set_paused(bool p_paused);
  63. virtual bool is_paused() const;
  64. virtual double get_length() const;
  65. virtual double get_playback_position() const;
  66. virtual void seek(double p_time);
  67. virtual void set_audio_track(int p_idx);
  68. virtual Ref<Texture2D> get_texture() const;
  69. virtual void update(double p_delta);
  70. virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata);
  71. virtual int get_channels() const;
  72. virtual int get_mix_rate() const;
  73. };
  74. class VideoStream : public Resource {
  75. GDCLASS(VideoStream, Resource);
  76. OBJ_SAVE_TYPE(VideoStream);
  77. protected:
  78. static void _bind_methods();
  79. GDVIRTUAL0R(Ref<VideoStreamPlayback>, _instantiate_playback);
  80. String file;
  81. int audio_track = 0;
  82. public:
  83. void set_file(const String &p_file);
  84. String get_file();
  85. virtual void set_audio_track(int p_track);
  86. virtual Ref<VideoStreamPlayback> instantiate_playback();
  87. VideoStream();
  88. ~VideoStream();
  89. };
  90. #endif // VIDEO_STREAM_H