video_stream_webm.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**************************************************************************/
  2. /* video_stream_webm.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_WEBM_H
  31. #define VIDEO_STREAM_WEBM_H
  32. #include "core/io/resource_loader.h"
  33. #include "scene/resources/video_stream.h"
  34. class WebMFrame;
  35. class WebMDemuxer;
  36. class VPXDecoder;
  37. class OpusVorbisDecoder;
  38. class VideoStreamPlaybackWebm : public VideoStreamPlayback {
  39. GDCLASS(VideoStreamPlaybackWebm, VideoStreamPlayback);
  40. String file_name;
  41. int audio_track;
  42. WebMDemuxer *webm;
  43. VPXDecoder *video;
  44. OpusVorbisDecoder *audio;
  45. WebMFrame **video_frames, *audio_frame;
  46. int video_frames_pos, video_frames_capacity;
  47. int num_decoded_samples, samples_offset;
  48. AudioMixCallback mix_callback;
  49. void *mix_udata;
  50. bool playing, paused;
  51. double delay_compensation;
  52. double time, video_frame_delay, video_pos;
  53. PoolVector<uint8_t> frame_data;
  54. Ref<ImageTexture> texture;
  55. float *pcm;
  56. public:
  57. VideoStreamPlaybackWebm();
  58. ~VideoStreamPlaybackWebm();
  59. bool open_file(const String &p_file);
  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 void set_loop(bool p_enable);
  66. virtual bool has_loop() const;
  67. virtual float get_length() const;
  68. virtual float get_playback_position() const;
  69. virtual void seek(float p_time);
  70. virtual void set_audio_track(int p_idx);
  71. virtual Ref<Texture> get_texture() const;
  72. virtual void update(float p_delta);
  73. virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata);
  74. virtual int get_channels() const;
  75. virtual int get_mix_rate() const;
  76. private:
  77. inline bool has_enough_video_frames() const;
  78. bool should_process(WebMFrame &video_frame);
  79. void delete_pointers();
  80. };
  81. /**/
  82. class VideoStreamWebm : public VideoStream {
  83. GDCLASS(VideoStreamWebm, VideoStream);
  84. String file;
  85. int audio_track;
  86. protected:
  87. static void _bind_methods();
  88. public:
  89. VideoStreamWebm();
  90. virtual Ref<VideoStreamPlayback> instance_playback();
  91. virtual void set_file(const String &p_file);
  92. String get_file();
  93. virtual void set_audio_track(int p_track);
  94. };
  95. class ResourceFormatLoaderWebm : public ResourceFormatLoader {
  96. public:
  97. virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_no_subresource_cache = false);
  98. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  99. virtual bool handles_type(const String &p_type) const;
  100. virtual String get_resource_type(const String &p_path) const;
  101. };
  102. #endif // VIDEO_STREAM_WEBM_H