1 /*************************************************************************/ 2 /* video_stream_webm.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 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 31 #ifndef VIDEO_STREAM_WEBM_H 32 #define VIDEO_STREAM_WEBM_H 33 34 #include "core/io/resource_loader.h" 35 #include "scene/resources/video_stream.h" 36 37 class WebMFrame; 38 class WebMDemuxer; 39 class VPXDecoder; 40 class OpusVorbisDecoder; 41 42 class VideoStreamPlaybackWebm : public VideoStreamPlayback { 43 44 GDCLASS(VideoStreamPlaybackWebm, VideoStreamPlayback); 45 46 String file_name; 47 int audio_track; 48 49 WebMDemuxer *webm; 50 VPXDecoder *video; 51 OpusVorbisDecoder *audio; 52 53 WebMFrame **video_frames, *audio_frame; 54 int video_frames_pos, video_frames_capacity; 55 56 int num_decoded_samples, samples_offset; 57 AudioMixCallback mix_callback; 58 void *mix_udata; 59 60 bool playing, paused; 61 double delay_compensation; 62 double time, video_frame_delay, video_pos; 63 64 PoolVector<uint8_t> frame_data; 65 Ref<ImageTexture> texture; 66 67 float *pcm; 68 69 public: 70 VideoStreamPlaybackWebm(); 71 ~VideoStreamPlaybackWebm(); 72 73 bool open_file(const String &p_file); 74 75 virtual void stop(); 76 virtual void play(); 77 78 virtual bool is_playing() const; 79 80 virtual void set_paused(bool p_paused); 81 virtual bool is_paused() const; 82 83 virtual void set_loop(bool p_enable); 84 virtual bool has_loop() const; 85 86 virtual float get_length() const; 87 88 virtual float get_playback_position() const; 89 virtual void seek(float p_time); 90 91 virtual void set_audio_track(int p_idx); 92 93 virtual Ref<Texture> get_texture() const; 94 virtual void update(float p_delta); 95 96 virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata); 97 virtual int get_channels() const; 98 virtual int get_mix_rate() const; 99 100 private: 101 inline bool has_enough_video_frames() const; 102 bool should_process(WebMFrame &video_frame); 103 104 void delete_pointers(); 105 }; 106 107 /**/ 108 109 class VideoStreamWebm : public VideoStream { 110 111 GDCLASS(VideoStreamWebm, VideoStream); 112 113 String file; 114 int audio_track; 115 116 protected: 117 static void _bind_methods(); 118 119 public: 120 VideoStreamWebm(); 121 122 virtual Ref<VideoStreamPlayback> instance_playback(); 123 124 virtual void set_file(const String &p_file); 125 String get_file(); 126 virtual void set_audio_track(int p_track); 127 }; 128 129 class ResourceFormatLoaderWebm : public ResourceFormatLoader { 130 public: 131 virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); 132 virtual void get_recognized_extensions(List<String> *p_extensions) const; 133 virtual bool handles_type(const String &p_type) const; 134 virtual String get_resource_type(const String &p_path) const; 135 }; 136 137 #endif // VIDEO_STREAM_WEBM_H 138