video_stream.h 4.3 KB

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