| 
									
										
										
										
											2016-06-18 14:46:12 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  video_stream_theora.cpp                                              */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2016-06-18 14:46:12 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-01-01 11:16:22 +01:00
										 |  |  | /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2016-06-18 14:46:12 +02:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "video_stream_theora.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-13 19:40:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/os/os.h"
 | 
					
						
							|  |  |  | #include "core/project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2017-04-28 19:28:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "thirdparty/misc/yuv2rgb.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int VideoStreamPlaybackTheora::buffer_data() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	char *buffer = ogg_sync_buffer(&oy, 4096); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int read; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	do { | 
					
						
							|  |  |  | 		thread_sem->post(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		read = MIN(ring_buffer.data_left(), 4096); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 		if (read) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			ring_buffer.read((uint8_t *)buffer, read); | 
					
						
							|  |  |  | 			ogg_sync_wrote(&oy, read); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			OS::get_singleton()->delay_usec(100); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} while (read == 0); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return read; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int bytes = file->get_buffer((uint8_t *)buffer, 4096); | 
					
						
							|  |  |  | 	ogg_sync_wrote(&oy, bytes); | 
					
						
							|  |  |  | 	return (bytes); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int VideoStreamPlaybackTheora::queue_page(ogg_page *page) { | 
					
						
							|  |  |  | 	if (theora_p) { | 
					
						
							|  |  |  | 		ogg_stream_pagein(&to, page); | 
					
						
							|  |  |  | 		if (to.e_o_s) | 
					
						
							|  |  |  | 			theora_eos = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (vorbis_p) { | 
					
						
							|  |  |  | 		ogg_stream_pagein(&vo, page); | 
					
						
							|  |  |  | 		if (vo.e_o_s) | 
					
						
							|  |  |  | 			vorbis_eos = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void VideoStreamPlaybackTheora::video_write(void) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	th_ycbcr_buffer yuv; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	th_decode_ycbcr_out(td, yuv); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int pitch = 4; | 
					
						
							|  |  |  | 	frame_data.resize(size.x * size.y * pitch); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 		PoolVector<uint8_t>::Write w = frame_data.write(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		char *dst = (char *)w.ptr(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 19:04:21 +02:00
										 |  |  | 		//uv_offset=(ti.pic_x/2)+(yuv[1].stride)*(ti.pic_y/2);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		if (px_fmt == TH_PF_444) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 21:19:33 +00:00
										 |  |  | 			yuv444_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		} else if (px_fmt == TH_PF_422) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 21:19:33 +00:00
										 |  |  | 			yuv422_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		} else if (px_fmt == TH_PF_420) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 21:19:33 +00:00
										 |  |  | 			yuv420_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 16:33:42 -03:00
										 |  |  | 		format = Image::FORMAT_RGBA8; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-17 07:36:47 -03:00
										 |  |  | 	Ref<Image> img = memnew(Image(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data)); //zero copy image creation
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	texture->set_data(img); //zero copy send to visual server
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	frames_pending = 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | void VideoStreamPlaybackTheora::clear() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 09:46:25 -03:00
										 |  |  | 	if (!file) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (vorbis_p) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ogg_stream_clear(&vo); | 
					
						
							|  |  |  | 		if (vorbis_p >= 3) { | 
					
						
							|  |  |  | 			vorbis_block_clear(&vb); | 
					
						
							|  |  |  | 			vorbis_dsp_clear(&vd); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		vorbis_comment_clear(&vc); | 
					
						
							|  |  |  | 		vorbis_info_clear(&vi); | 
					
						
							|  |  |  | 		vorbis_p = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (theora_p) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ogg_stream_clear(&to); | 
					
						
							|  |  |  | 		th_decode_free(td); | 
					
						
							|  |  |  | 		th_comment_clear(&tc); | 
					
						
							|  |  |  | 		th_info_clear(&ti); | 
					
						
							|  |  |  | 		theora_p = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ogg_sync_clear(&oy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	thread_exit = true; | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 	thread_sem->post(); //just in case
 | 
					
						
							|  |  |  | 	Thread::wait_to_finish(thread); | 
					
						
							|  |  |  | 	memdelete(thread); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	thread = NULL; | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 	ring_buffer.clear(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	theora_p = 0; | 
					
						
							|  |  |  | 	vorbis_p = 0; | 
					
						
							|  |  |  | 	videobuf_ready = 0; | 
					
						
							|  |  |  | 	frames_pending = 0; | 
					
						
							|  |  |  | 	videobuf_time = 0; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	theora_eos = false; | 
					
						
							|  |  |  | 	vorbis_eos = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 09:46:25 -03:00
										 |  |  | 	if (file) { | 
					
						
							|  |  |  | 		memdelete(file); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	file = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	playing = false; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void VideoStreamPlaybackTheora::set_file(const String &p_file) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 	ERR_FAIL_COND(playing); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	ogg_packet op; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	th_setup_info *ts = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	file_name = p_file; | 
					
						
							|  |  |  | 	if (file) { | 
					
						
							|  |  |  | 		memdelete(file); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	file = FileAccess::open(p_file, FileAccess::READ); | 
					
						
							| 
									
										
										
										
											2019-09-25 10:28:50 +02:00
										 |  |  | 	ERR_FAIL_COND_MSG(!file, "Cannot open file '" + p_file + "'."); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	thread_exit = false; | 
					
						
							|  |  |  | 	thread_eof = false; | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 	//pre-fill buffer
 | 
					
						
							|  |  |  | 	int to_read = ring_buffer.space_left(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int read = file->get_buffer(read_buffer.ptr(), to_read); | 
					
						
							|  |  |  | 	ring_buffer.write(read_buffer.ptr(), read); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	thread = Thread::create(_streaming_thread, this); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ogg_sync_init(&oy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* init supporting Vorbis structures needed in header parsing */ | 
					
						
							|  |  |  | 	vorbis_info_init(&vi); | 
					
						
							|  |  |  | 	vorbis_comment_init(&vc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* init supporting Theora structures needed in header parsing */ | 
					
						
							|  |  |  | 	th_comment_init(&tc); | 
					
						
							|  |  |  | 	th_info_init(&ti); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	theora_eos = false; | 
					
						
							|  |  |  | 	vorbis_eos = false; | 
					
						
							| 
									
										
										
										
											2016-01-23 17:58:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	/* Ogg file open; parse the headers */ | 
					
						
							|  |  |  | 	/* Only interested in Vorbis/Theora streams */ | 
					
						
							|  |  |  | 	int stateflag = 0; | 
					
						
							| 
									
										
										
										
											2015-10-13 01:17:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int audio_track_skip = audio_track; | 
					
						
							| 
									
										
										
										
											2015-11-17 09:46:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	while (!stateflag) { | 
					
						
							|  |  |  | 		int ret = buffer_data(); | 
					
						
							|  |  |  | 		if (ret == 0) break; | 
					
						
							|  |  |  | 		while (ogg_sync_pageout(&oy, &og) > 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			ogg_stream_state test; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* is this a mandated initial header? If not, stop parsing */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (!ogg_page_bos(&og)) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				/* don't leak the page; get it into the appropriate stream */ | 
					
						
							|  |  |  | 				queue_page(&og); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				stateflag = 1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			ogg_stream_init(&test, ogg_page_serialno(&og)); | 
					
						
							|  |  |  | 			ogg_stream_pagein(&test, &og); | 
					
						
							|  |  |  | 			ogg_stream_packetout(&test, &op); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* identify the codec: try theora */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (!theora_p && th_decode_headerin(&ti, &tc, &ts, &op) >= 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				/* it is theora */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				copymem(&to, &test, sizeof(test)); | 
					
						
							|  |  |  | 				theora_p = 1; | 
					
						
							|  |  |  | 			} else if (!vorbis_p && vorbis_synthesis_headerin(&vi, &vc, &op) >= 0) { | 
					
						
							| 
									
										
										
										
											2015-11-16 08:44:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				/* it is vorbis */ | 
					
						
							| 
									
										
										
										
											2015-11-17 09:46:08 -03:00
										 |  |  | 				if (audio_track_skip) { | 
					
						
							|  |  |  | 					vorbis_info_clear(&vi); | 
					
						
							|  |  |  | 					vorbis_comment_clear(&vc); | 
					
						
							|  |  |  | 					ogg_stream_clear(&test); | 
					
						
							|  |  |  | 					vorbis_info_init(&vi); | 
					
						
							|  |  |  | 					vorbis_comment_init(&vc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					audio_track_skip--; | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					copymem(&vo, &test, sizeof(test)); | 
					
						
							|  |  |  | 					vorbis_p = 1; | 
					
						
							| 
									
										
										
										
											2015-11-17 09:46:08 -03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				/* whatever it is, we don't care about it */ | 
					
						
							|  |  |  | 				ogg_stream_clear(&test); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* fall through to non-bos page parsing */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* we're expecting more header packets. */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	while ((theora_p && theora_p < 3) || (vorbis_p && vorbis_p < 3)) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* look for further theora headers */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		while (theora_p && (theora_p < 3) && (ret = ogg_stream_packetout(&to, &op))) { | 
					
						
							|  |  |  | 			if (ret < 0) { | 
					
						
							| 
									
										
										
										
											2018-04-02 16:47:06 -04:00
										 |  |  | 				fprintf(stderr, "Error parsing Theora stream headers; corrupt stream?\n"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				clear(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (!th_decode_headerin(&ti, &tc, &ts, &op)) { | 
					
						
							| 
									
										
										
										
											2018-04-02 16:47:06 -04:00
										 |  |  | 				fprintf(stderr, "Error parsing Theora stream headers; corrupt stream?\n"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				clear(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			theora_p++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* look for more vorbis header packets */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		while (vorbis_p && (vorbis_p < 3) && (ret = ogg_stream_packetout(&vo, &op))) { | 
					
						
							|  |  |  | 			if (ret < 0) { | 
					
						
							|  |  |  | 				fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?\n"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				clear(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			ret = vorbis_synthesis_headerin(&vi, &vc, &op); | 
					
						
							|  |  |  | 			if (ret) { | 
					
						
							|  |  |  | 				fprintf(stderr, "Error parsing Vorbis stream headers; corrupt stream?\n"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				clear(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			vorbis_p++; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (vorbis_p == 3) break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* The header pages/packets will arrive before anything else we
 | 
					
						
							|  |  |  | 		care about, or the stream is not obeying spec */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (ogg_sync_pageout(&oy, &og) > 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			queue_page(&og); /* demux into the appropriate stream */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2019-02-12 21:10:08 +01:00
										 |  |  | 			int ret2 = buffer_data(); /* someone needs more data */ | 
					
						
							|  |  |  | 			if (ret2 == 0) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				fprintf(stderr, "End of file while searching for codec headers.\n"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				clear(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* and now we have it all.  initialize decoders */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (theora_p) { | 
					
						
							|  |  |  | 		td = th_decode_alloc(&ti, ts); | 
					
						
							|  |  |  | 		px_fmt = ti.pixel_fmt; | 
					
						
							|  |  |  | 		switch (ti.pixel_fmt) { | 
					
						
							| 
									
										
										
										
											2018-04-02 16:47:06 -04:00
										 |  |  | 			case TH_PF_420: | 
					
						
							|  |  |  | 				//printf(" 4:2:0 video\n");
 | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case TH_PF_422: | 
					
						
							|  |  |  | 				//printf(" 4:2:2 video\n");
 | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case TH_PF_444: | 
					
						
							|  |  |  | 				//printf(" 4:4:4 video\n");
 | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			case TH_PF_RSVD: | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				printf(" video\n  (UNKNOWN Chroma sampling!)\n"); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		th_decode_ctl(td, TH_DECCTL_GET_PPLEVEL_MAX, &pp_level_max, | 
					
						
							|  |  |  | 				sizeof(pp_level_max)); | 
					
						
							|  |  |  | 		pp_level = 0; | 
					
						
							|  |  |  | 		th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, sizeof(pp_level)); | 
					
						
							|  |  |  | 		pp_inc = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		int w; | 
					
						
							|  |  |  | 		int h; | 
					
						
							| 
									
										
										
										
											2018-09-26 16:35:32 +02:00
										 |  |  | 		w = ((ti.pic_x + ti.frame_width + 1) & ~1) - (ti.pic_x & ~1); | 
					
						
							|  |  |  | 		h = ((ti.pic_y + ti.frame_height + 1) & ~1) - (ti.pic_y & ~1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		size.x = w; | 
					
						
							|  |  |  | 		size.y = h; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		texture->create(w, h, Image::FORMAT_RGBA8, Texture::FLAG_FILTER | Texture::FLAG_VIDEO_SURFACE); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		/* tear down the partial theora setup */ | 
					
						
							|  |  |  | 		th_info_clear(&ti); | 
					
						
							|  |  |  | 		th_comment_clear(&tc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	th_setup_free(ts); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (vorbis_p) { | 
					
						
							|  |  |  | 		vorbis_synthesis_init(&vd, &vi); | 
					
						
							|  |  |  | 		vorbis_block_init(&vd, &vb); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		//_setup(vi.channels, vi.rate);
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		/* tear down the partial vorbis setup */ | 
					
						
							|  |  |  | 		vorbis_info_clear(&vi); | 
					
						
							|  |  |  | 		vorbis_comment_clear(&vc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	playing = false; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	buffering = true; | 
					
						
							|  |  |  | 	time = 0; | 
					
						
							|  |  |  | 	audio_frames_wrote = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | float VideoStreamPlaybackTheora::get_time() const { | 
					
						
							| 
									
										
										
										
											2020-02-07 21:01:03 +01:00
										 |  |  | 	// FIXME: AudioServer output latency was fixed in af9bb0e, previously it used to
 | 
					
						
							|  |  |  | 	// systematically return 0. Now that it gives a proper latency, it broke this
 | 
					
						
							|  |  |  | 	// code where the delay compensation likely never really worked.
 | 
					
						
							|  |  |  | 	return time - /* AudioServer::get_singleton()->get_output_latency() - */ delay_compensation; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-24 01:35:47 +01:00
										 |  |  | Ref<Texture> VideoStreamPlaybackTheora::get_texture() const { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return texture; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VideoStreamPlaybackTheora::update(float p_delta) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 01:59:55 -03:00
										 |  |  | 	if (!file) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-15 23:39:36 -03:00
										 |  |  | 	if (!playing || paused) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		//printf("not playing\n");
 | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							|  |  |  | 	thread_sem->post(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	time += p_delta; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (videobuf_time > get_time()) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		return; //no new frames need to be produced
 | 
					
						
							| 
									
										
										
										
											2015-11-25 00:28:03 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	bool frame_done = false; | 
					
						
							|  |  |  | 	bool audio_done = !vorbis_p; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-23 17:58:17 -03:00
										 |  |  | 	while (!frame_done || (!audio_done && !vorbis_eos)) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		//a frame needs to be produced
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		ogg_packet op; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		bool no_theora = false; | 
					
						
							| 
									
										
										
										
											2017-09-14 15:45:02 -05:00
										 |  |  | 		bool buffer_full = false; | 
					
						
							| 
									
										
										
										
											2015-12-15 09:17:32 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 15:45:02 -05:00
										 |  |  | 		while (vorbis_p && !audio_done && !buffer_full) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			int ret; | 
					
						
							|  |  |  | 			float **pcm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* if there's pending, decoded audio, grab it */ | 
					
						
							| 
									
										
										
										
											2017-09-06 23:50:18 +02:00
										 |  |  | 			ret = vorbis_synthesis_pcmout(&vd, &pcm); | 
					
						
							|  |  |  | 			if (ret > 0) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				const int AUXBUF_LEN = 4096; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 				int to_read = ret; | 
					
						
							| 
									
										
										
										
											2017-09-14 15:45:02 -05:00
										 |  |  | 				float aux_buffer[AUXBUF_LEN]; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				while (to_read) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					int m = MIN(AUXBUF_LEN / vi.channels, to_read); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					int count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					for (int j = 0; j < m; j++) { | 
					
						
							|  |  |  | 						for (int i = 0; i < vi.channels; i++) { | 
					
						
							| 
									
										
										
										
											2017-09-14 15:45:02 -05:00
										 |  |  | 							aux_buffer[count++] = pcm[i][j]; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (mix_callback) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						int mixed = mix_callback(mix_udata, aux_buffer, m); | 
					
						
							|  |  |  | 						to_read -= mixed; | 
					
						
							|  |  |  | 						if (mixed != m) { //could mix no more
 | 
					
						
							|  |  |  | 							buffer_full = true; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 							break; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						to_read -= m; //just pretend we sent the audio
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 11:24:41 +02:00
										 |  |  | 				vorbis_synthesis_read(&vd, ret - to_read); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				audio_frames_wrote += ret - to_read; | 
					
						
							| 
									
										
										
										
											2015-11-03 09:30:28 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* no pending audio; is there a pending packet to decode? */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (ogg_stream_packetout(&vo, &op) > 0) { | 
					
						
							|  |  |  | 					if (vorbis_synthesis(&vb, &op) == 0) { /* test for success! */ | 
					
						
							|  |  |  | 						vorbis_synthesis_blockin(&vd, &vb); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				} else { /* we need more data; break out to suck in another page */ | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			audio_done = videobuf_time < (audio_frames_wrote / float(vi.rate)); | 
					
						
							| 
									
										
										
										
											2015-11-03 09:30:28 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			if (buffer_full) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		while (theora_p && !frame_done) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			/* theora is one in, one out... */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (ogg_stream_packetout(&to, &op) > 0) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (false && pp_inc) { | 
					
						
							|  |  |  | 					pp_level += pp_inc; | 
					
						
							|  |  |  | 					th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, | 
					
						
							|  |  |  | 							sizeof(pp_level)); | 
					
						
							|  |  |  | 					pp_inc = 0; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				/*HACK: This should be set after a seek or a gap, but we might not have
 | 
					
						
							|  |  |  | 				a granulepos for the first packet (we only have them for the last | 
					
						
							|  |  |  | 				packet on a page), so we just set it as often as we get it. | 
					
						
							|  |  |  | 				To do this right, we should back-track from the last packet on the | 
					
						
							|  |  |  | 				page and compute the correct granulepos for the first packet after | 
					
						
							|  |  |  | 				a seek or a gap.*/ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (op.granulepos >= 0) { | 
					
						
							|  |  |  | 					th_decode_ctl(td, TH_DECCTL_SET_GRANPOS, &op.granulepos, | 
					
						
							|  |  |  | 							sizeof(op.granulepos)); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				ogg_int64_t videobuf_granulepos; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (th_decode_packetin(td, &op, &videobuf_granulepos) == 0) { | 
					
						
							|  |  |  | 					videobuf_time = th_granule_time(td, videobuf_granulepos); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					//printf("frame time %f, play time %f, ready %i\n", (float)videobuf_time, get_time(), videobuf_ready);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					/* is it already too old to be useful?  This is only actually
 | 
					
						
							|  |  |  | 					 useful cosmetically after a SIGSTOP.  Note that we have to | 
					
						
							|  |  |  | 					 decode the frame even if we don't show it (for now) due to | 
					
						
							|  |  |  | 					 keyframing.  Soon enough libtheora will be able to deal | 
					
						
							|  |  |  | 					 with non-keyframe seeks.  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (videobuf_time >= get_time()) { | 
					
						
							|  |  |  | 						frame_done = true; | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 						/*If we are too slow, reduce the pp level.*/ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 						pp_inc = pp_level > 0 ? -1 : 0; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 00:28:03 -03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				no_theora = true; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2015-11-25 00:28:03 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-01-23 17:58:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (file && thread_eof && no_theora && theora_eos && ring_buffer.data_left() == 0) { | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2016-01-23 17:58:17 -03:00
										 |  |  | 		if (file && /*!videobuf_ready && */ no_theora && theora_eos) { | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-04-02 16:47:06 -04:00
										 |  |  | 			//printf("video done, stopping\n");
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			stop(); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2015-11-03 09:30:28 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (!frame_done || !audio_done) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			//what's the point of waiting for audio to grab a page?
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			buffer_data(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			while (ogg_sync_pageout(&oy, &og) > 0) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 				queue_page(&og); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-27 21:07:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		/* If playback has begun, top audio buffer off immediately. */ | 
					
						
							|  |  |  | 		//if(stateflag) audio_write_nonblocking();
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		/* are we at or past time for this video frame? */ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (videobuf_ready && videobuf_time <= get_time()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 			//video_write();
 | 
					
						
							|  |  |  | 			//videobuf_ready=0;
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			//printf("frame at %f not ready (time %f), ready %i\n", (float)videobuf_time, get_time(), videobuf_ready);
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		float tdiff = videobuf_time - get_time(); | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		/*If we have lots of extra time, increase the post-processing level.*/ | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (tdiff > ti.fps_denominator * 0.25 / ti.fps_numerator) { | 
					
						
							|  |  |  | 			pp_inc = pp_level < pp_level_max ? 1 : 0; | 
					
						
							|  |  |  | 		} else if (tdiff < ti.fps_denominator * 0.05 / ti.fps_numerator) { | 
					
						
							|  |  |  | 			pp_inc = pp_level > 0 ? -1 : 0; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 	video_write(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | void VideoStreamPlaybackTheora::play() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!playing) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		time = 0; | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		stop(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	playing = true; | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | 	delay_compensation = ProjectSettings::get_singleton()->get("audio/video_delay_compensation_ms"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	delay_compensation /= 1000.0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | void VideoStreamPlaybackTheora::stop() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 	if (playing) { | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 		clear(); | 
					
						
							|  |  |  | 		set_file(file_name); //reset
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	playing = false; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	time = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | bool VideoStreamPlaybackTheora::is_playing() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return playing; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | void VideoStreamPlaybackTheora::set_paused(bool p_paused) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	paused = p_paused; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 15:45:02 -05:00
										 |  |  | bool VideoStreamPlaybackTheora::is_paused() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-15 23:39:36 -03:00
										 |  |  | 	return paused; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void VideoStreamPlaybackTheora::set_loop(bool p_enable){ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | bool VideoStreamPlaybackTheora::has_loop() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | float VideoStreamPlaybackTheora::get_length() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | String VideoStreamPlaybackTheora::get_stream_name() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | int VideoStreamPlaybackTheora::get_loop_count() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 00:31:36 -03:00
										 |  |  | float VideoStreamPlaybackTheora::get_playback_position() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return get_time(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 00:31:36 -03:00
										 |  |  | void VideoStreamPlaybackTheora::seek(float p_time){ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// no
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void VideoStreamPlaybackTheora::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mix_callback = p_callback; | 
					
						
							|  |  |  | 	mix_udata = p_userdata; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int VideoStreamPlaybackTheora::get_channels() const { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return vi.channels; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VideoStreamPlaybackTheora::set_audio_track(int p_idx) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	audio_track = p_idx; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | int VideoStreamPlaybackTheora::get_mix_rate() const { | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return vi.rate; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VideoStreamPlaybackTheora::_streaming_thread(void *ud) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	VideoStreamPlaybackTheora *vs = (VideoStreamPlaybackTheora *)ud; | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	while (!vs->thread_exit) { | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		//just fill back the buffer
 | 
					
						
							|  |  |  | 		if (!vs->thread_eof) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			int to_read = vs->ring_buffer.space_left(); | 
					
						
							|  |  |  | 			if (to_read) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				int read = vs->file->get_buffer(vs->read_buffer.ptr(), to_read); | 
					
						
							|  |  |  | 				vs->ring_buffer.write(vs->read_buffer.ptr(), read); | 
					
						
							|  |  |  | 				vs->thread_eof = vs->file->eof_reached(); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		vs->thread_sem->wait(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	file = NULL; | 
					
						
							|  |  |  | 	theora_p = 0; | 
					
						
							|  |  |  | 	vorbis_p = 0; | 
					
						
							|  |  |  | 	videobuf_ready = 0; | 
					
						
							|  |  |  | 	playing = false; | 
					
						
							|  |  |  | 	frames_pending = 0; | 
					
						
							|  |  |  | 	videobuf_time = 0; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	paused = false; | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	buffering = false; | 
					
						
							|  |  |  | 	texture = Ref<ImageTexture>(memnew(ImageTexture)); | 
					
						
							|  |  |  | 	mix_callback = NULL; | 
					
						
							|  |  |  | 	mix_udata = NULL; | 
					
						
							|  |  |  | 	audio_track = 0; | 
					
						
							|  |  |  | 	delay_compensation = 0; | 
					
						
							|  |  |  | 	audio_frames_wrote = 0; | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int rb_power = nearest_shift(RB_SIZE_KB * 1024); | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 	ring_buffer.resize(rb_power); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	read_buffer.resize(RB_SIZE_KB * 1024); | 
					
						
							|  |  |  | 	thread_sem = Semaphore::create(); | 
					
						
							|  |  |  | 	thread = NULL; | 
					
						
							|  |  |  | 	thread_exit = false; | 
					
						
							|  |  |  | 	thread_eof = false; | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-26 14:50:42 -03:00
										 |  |  | VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-05 23:16:41 -03:00
										 |  |  | #ifdef THEORA_USE_THREAD_STREAMING
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memdelete(thread_sem); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (file) | 
					
						
							|  |  |  | 		memdelete(file); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 15:45:02 -05:00
										 |  |  | void VideoStreamTheora::_bind_methods() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 15:45:02 -05:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamTheora::set_file); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamTheora::get_file); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-12 00:35:12 +02:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::STRING, "file", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_file", "get_file"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-03 19:22:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FileAccess *f = FileAccess::open(p_path, FileAccess::READ); | 
					
						
							|  |  |  | 	if (!f) { | 
					
						
							|  |  |  | 		if (r_error) { | 
					
						
							|  |  |  | 			*r_error = ERR_CANT_OPEN; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return RES(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VideoStreamTheora *stream = memnew(VideoStreamTheora); | 
					
						
							|  |  |  | 	stream->set_file(p_path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<VideoStreamTheora> ogv_stream = Ref<VideoStreamTheora>(stream); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (r_error) { | 
					
						
							|  |  |  | 		*r_error = OK; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 09:49:13 +01:00
										 |  |  | 	f->close(); | 
					
						
							|  |  |  | 	memdelete(f); | 
					
						
							| 
									
										
										
										
											2018-07-03 19:22:35 +02:00
										 |  |  | 	return ogv_stream; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ResourceFormatLoaderTheora::get_recognized_extensions(List<String> *p_extensions) const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p_extensions->push_back("ogv"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ResourceFormatLoaderTheora::handles_type(const String &p_type) const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ClassDB::is_parent_class(p_type, "VideoStream"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String ResourceFormatLoaderTheora::get_resource_type(const String &p_path) const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String el = p_path.get_extension().to_lower(); | 
					
						
							|  |  |  | 	if (el == "ogv") | 
					
						
							|  |  |  | 		return "VideoStreamTheora"; | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } |