indexing description: "[ Singleton factory that creates objects of type EM_VIDEO_DECODER. Use EM_SHARED_VIDEO_DECODER_FACTORY to access this singleton. ]" date: "$Date$" revision: "$Revision$" class EM_VIDEO_DECODER_FACTORY inherit EM_VIDEO_DECODER_CONSTANTS export {NONE} all end EM_SHARED_ERROR_HANDLER export {NONE} all end KL_SHARED_FILE_SYSTEM export {NONE} all end create {EM_SHARED_VIDEO_DECODER_FACTORY} default_create feature -- Access last_video_decoder: EM_VIDEO_DECODER -- Last video decoder created feature -- Video decoder creation create_video_decoder_from_file (a_filename: STRING) is -- Create video decoder and initialize it using the data -- from the file named `a_filename'. Make resulting video decoder -- available via `last_video_decoder'. If the video could not be -- loaded or the video decoder could not be created raise -- an exception. require a_filename_not_void: a_filename /= Void local tmp_file: KL_BINARY_INPUT_FILE tmp_video_decoder: EM_VIDEO_DECODER do last_video_decoder := Void create tmp_file.make (a_filename) tmp_file.open_read if tmp_file.is_open_read then tmp_video_decoder := get_type (tmp_file) if tmp_video_decoder /= Void and then tmp_video_decoder.is_valid_file (tmp_file) then tmp_video_decoder.load_from_file (tmp_file) if tmp_video_decoder.is_loaded then last_video_decoder := tmp_video_decoder end end end if last_video_decoder = Void then if tmp_video_decoder /= Void then Error_handler.raise_error (Error_handler.em_error_create_video_decoder_from_file_not_valid, [file_system.absolute_pathname (a_filename), tmp_video_decoder.type]) elseif file_system.file_exists (a_filename) then Error_handler.raise_error (Error_handler.em_error_create_video_decoder_from_file, [file_system.absolute_pathname (a_filename)]) else Error_handler.raise_error (Error_handler.em_error_create_video_decoder_from_file_does_not_exist, [file_system.absolute_pathname (a_filename)]) end end ensure loaded_if_created: last_video_decoder /= Void implies last_video_decoder.is_loaded end feature {NONE} -- Implementation get_type (file: KL_BINARY_INPUT_FILE): EM_VIDEO_DECODER is -- checks type of file and creates the apropiate video decoder require file_exist: file /= Void file_open_read: file.is_open_read do file.read_string (em_smjpeg_magic.count) if file.last_string.is_equal (em_smjpeg_magic) then create {EM_SMJPEG_DECODER}Result.make end if Result /= Void and then not Result.accept_file (file) then Result := Void end end end