Example #1
0
bool Chain::parse (const ssi_char_t *filepath) {

	release ();

	if (filepath == 0 || filepath[0] == '\0') {
		ssi_wrn ("file is empty");
		return false;
	}

	FilePath fp (filepath);
	ssi_char_t *filepath_with_ext = 0;
	if (strcmp (fp.getExtension (), SSI_FILE_TYPE_CHAIN) != 0) {
		filepath_with_ext = ssi_strcat (filepath, SSI_FILE_TYPE_CHAIN);
	} else {
		filepath_with_ext = ssi_strcpy (filepath);
	}

	if (!ssi_exists (filepath_with_ext)) {
		ssi_wrn ("file not found '%s", filepath_with_ext);
		return false;
	}

	ssi_msg (SSI_LOG_LEVEL_BASIC, "load '%s'", filepath_with_ext);

	TiXmlDocument doc;
	if (!doc.LoadFile (filepath_with_ext)) {
		ssi_wrn ("failed loading chain from file '%s'", filepath_with_ext);
		delete[] filepath_with_ext;
		return false;
	}

	TiXmlElement *body = doc.FirstChildElement();	
	if (!body || strcmp (body->Value (), "chain") != 0) {
		ssi_wrn ("tag <chain> missing");
		delete[] filepath_with_ext;
		return false;	
	}

	TiXmlElement *filter = body->FirstChildElement ("filter");
	if (filter) {
		if (!parseFilter (filter)) {
			ssi_wrn ("failed parsing <filter> tag");
			return false;
		}
	}

	TiXmlElement *feature = body->FirstChildElement ("feature");
	if (feature) {
		if (!parseFeature (feature)) {
			ssi_wrn ("failed parsing <feature> tag");
			return false;
		}
	}

	_parsed = feature || filter;
	if (!_parsed) {
		ssi_wrn ("parsing failed because no feature/filter were loaded");
	}

	return _parsed;
}
Example #2
0
int main (int argc, char **argv) {

#ifdef USE_SSI_LEAK_DETECTOR
	{
#endif

	char info[1024];
	ssi_sprint (info, "\n%s\n\nbuild version: %s\n\n", SSI_COPYRIGHT, SSI_VERSION);

	//**** READ COMMAND LINE ****//

	CmdArgParser cmd;
	cmd.info (info);

	ssi_char_t *dllpath = 0;	
	ssi_char_t *apipath = 0;	
	ssi_char_t *outdir = 0;
	ssi_char_t *reg = 0; 
	bool index;

	cmd.addText("\nArguments:");
	cmd.addSCmdArg("dllpath", &dllpath, "input path to dll");	

	cmd.addText ("\nOptions:");
	cmd.addSCmdOption ("-dir", &outdir, "", "output directory []");
	cmd.addBCmdOption ("-index", &index, false, "create index [false]");
	cmd.addSCmdOption ("-reg", &reg, "", "register additional dll's (if several separate by semicolon)");
	
	if (cmd.read (argc, argv)) {		

		ssi_char_t string[SSI_MAX_CHAR];

		FilePath fp (dllpath);
		ssi_char_t *dllpath_with_ext = 0;
		if (strcmp (fp.getExtension (), ".dll") != 0) {
			dllpath_with_ext = ssi_strcat (dllpath, ".dll");
		} else {
			dllpath_with_ext = ssi_strcpy (dllpath);
		}

		if (Factory::RegisterDLL (dllpath_with_ext)) {	

			// register additional dlls
			if (reg) {
				APIGenerator::SaveCurrentComponentList ();
				ssi_size_t n_reg = ssi_split_string_count (reg, ';');
				ssi_char_t **regs = new ssi_char_t *[n_reg];
				ssi_split_string (n_reg, regs, reg, ';');
				for (ssi_size_t i = 0; i < n_reg; i++) {
					Factory::RegisterDLL (regs[i]);
					delete[] regs[i];
				}
				delete[] regs;
			}

			if (outdir[0] == '\0') {
				ssi_sprint (string, "%s", fp.getPath ());
			} else {
				ssi_sprint (string, "%s\\%s", outdir, fp.getName ());
			}

			APIGenerator::CreateAPI (string);
			APIGenerator::ResetCurrentComponentList ();
			Factory::Clear ();
		}

		if (index) {
			if (outdir[0] == '\0') {
				APIGenerator::CreateAPIIndex (fp.getDir ());
			} else {
				APIGenerator::CreateAPIIndex (outdir);
			}
		}

		delete[] dllpath_with_ext;
	}

	delete[] dllpath;	
	delete[] apipath;	
	delete[] outdir;

#ifdef USE_SSI_LEAK_DETECTOR
	}
	_CrtDumpMemoryLeaks();
#endif

	return 0;
}
Example #3
0
bool FileSamplesOut::open (ISamples &data,
	const ssi_char_t *path,
	File::TYPE type, 
	File::VERSION version) {

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "open files '%s'", path);	

	_version = version;

	if (_version < File::V2) {
		ssi_wrn ("version < V2 not supported");
		return false;
	}

	if (_file_info || _file_data) {
		ssi_wrn ("samples already open");
		return false;
	}

	_n_users = data.getUserSize ();
	_users = new ssi_char_t *[_n_users];
	_n_per_user = new ssi_size_t[_n_users];
	for (ssi_size_t i = 0; i < _n_users; i++) {
		_users[i] = ssi_strcpy (data.getUserName (i));
		_n_per_user[i] = 0;
	}
	_n_classes = data.getClassSize ();
	_classes = new ssi_char_t *[_n_classes];
	_n_per_class = new ssi_size_t[_n_classes];
	for (ssi_size_t i = 0; i < _n_classes; i++) {
		_classes[i] = ssi_strcpy (data.getClassName (i));
		_n_per_class[i] = 0;
	}
	
	_n_streams = data.getStreamSize ();
	_streams = new ssi_stream_t[_n_streams];
	for (ssi_size_t i = 0; i < _n_streams; i++) {
		ssi_stream_t s = data.getStream (i);
		ssi_stream_init (_streams[i], 0, s.dim, s.byte, s.type, s.sr, 0);
	}

	_has_missing_data = false;

	if (path == 0 || path[0] == '\0') {
		_console = true;
	}

	if (_console) {
		
		_file_data = File::CreateAndOpen (type, File::WRITE, "");
		if (!_file_data) {
			ssi_wrn ("could not open console");
			return false;
		}

	} else {

		FilePath fp (path);
		ssi_char_t *path_info = 0;
		if (strcmp (fp.getExtension (), SSI_FILE_TYPE_SAMPLES) != 0) {
			path_info = ssi_strcat (path, SSI_FILE_TYPE_SAMPLES);
		} else {
			path_info = ssi_strcpy (path);
		}	
		_path = ssi_strcpy (path_info);

		_file_info = File::CreateAndOpen (File::ASCII, File::WRITE, path_info);
		if (!_file_info) {
			ssi_wrn ("could not open info file '%s'", path_info);
			return false;
		}

		ssi_sprint (_string, "<?xml version=\"1.0\" ?>\n<samples ssi-v=\"%d\">", version);
		_file_info->writeLine (_string);
	
		ssi_char_t *path_data = ssi_strcat (path_info, "~");			
		_file_data = File::CreateAndOpen (type, File::WRITE, path_data);
		if (!_file_data) {
			ssi_wrn ("could not open data file '%s'", path_data);
			return false;
		}

		if (_version == File::V3) {

			_file_streams = new FileStreamOut[_n_streams];
			ssi_char_t string[SSI_MAX_CHAR];
			for (ssi_size_t i = 0; i < _n_streams; i++) {
				ssi_sprint (string, "%s.#%u", path_info, i);
				_file_streams[i].open (_streams[i], string, type);				
			}

		}

		delete[] path_info;
		delete[] path_data;

	}

	return true;
};
Example #4
0
bool FileStreamIn::open (ssi_stream_t &data,
	const ssi_char_t *path,
	ssi_size_t &n_meta,
	void **meta) {

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "open stream file '%s'", path);	

	if (_file_info || _file_data) {
		ssi_wrn ("stream already open");
		return false;
	}

	if (path == 0 || path[0] == '\0') {
		ssi_wrn ("'%s' is not a valid path", path);
		return false;
	}

	FilePath fp (path);
	ssi_char_t *path_info = 0;
	if (strcmp (fp.getExtension (), SSI_FILE_TYPE_STREAM) != 0) {
		path_info = ssi_strcat (path, SSI_FILE_TYPE_STREAM);
	} else {
		path_info = ssi_strcpy (path);
	}	
	_path = ssi_strcpy (path_info);

	_file_info = File::CreateAndOpen (File::ASCII, File::READ, path_info);
	if (!_file_info) {
		ssi_wrn ("could not open info file '%s'", path_info);
		return false;
	}

	TiXmlDocument doc;
	if (!doc.LoadFile (_file_info->getFile ())) {
		ssi_wrn ("failed loading stream from file '%s'", path_info);
		return false;
	}

	TiXmlElement *body = doc.FirstChildElement();	
	if (!body || strcmp (body->Value (), "stream") != 0) {
		ssi_wrn ("tag <stream> missing");
		return false;	
	}

	int v = 0;
	if (body->QueryIntAttribute ("ssi-v", &v) != TIXML_SUCCESS) {
		ssi_wrn ("attribute <ssi-v> in tag <stream> missing");
		return false;	
	}
	_version = ssi_cast (File::VERSION, v);

	if (_version < File::V2) {
		ssi_wrn ("version < V2 not supported");
		return false;
	}
	
	TiXmlElement *element = body->FirstChildElement ("info");
	if (!element || strcmp (element->Value (), "info") != 0) {
		ssi_wrn ("tag <info> missing");
		return false;
	}

	ssi_time_t sample_rate = 0;
	if (element->QueryDoubleAttribute ("sr", &sample_rate) != TIXML_SUCCESS) {
		ssi_wrn ("attribute <sr> missing in tag <info>");
		return false;
	}

	int sample_dimension = 0;
	if (element->QueryIntAttribute ("dim", &sample_dimension) != TIXML_SUCCESS) {
		ssi_wrn ("attribute <dim> missing in tag <info>");
		return false;
	}

	int sample_byte = 0;
	if (element->QueryIntAttribute ("byte", &sample_byte) != TIXML_SUCCESS) {
		ssi_wrn ("attribute <byte> missing in tag <info>");
		return false;
	}

	const char *type = element->Attribute ("type");
	if (!type) {
		ssi_wrn ("attribute <type> missing in tag <info>");
		return false;
	}
	ssi_type_t sample_type;
	if (!ssi_name2type (type, sample_type)) {
		ssi_wrn ("could not parse type from '%s'", type);
		return false;
	}

	const char *ftype_name = element->Attribute ("ftype");
	if (!ftype_name) {
		ssi_wrn ("attribute <ftype> missing in tag <info>");
		return false;
	}
	File::TYPE ftype;
	if (strcmp (ftype_name, File::TYPE_NAMES[0]) == 0) {
		ftype = File::BINARY;
	} else if (strcmp (ftype_name, File::TYPE_NAMES[1]) == 0) {
		ftype = File::ASCII;
	} else {
		ssi_wrn ("attribute <ftype> has invalid value '%s' in tag <info>", ftype_name);
		return false;
	}

	*meta = 0;
	n_meta = 0;

	element = body->FirstChildElement ("meta");
	if (element && strcmp (element->Value (), "meta") == 0) {

		switch (sample_type) {
			case SSI_IMAGE: {
				n_meta = sizeof (ssi_video_params_t);
				ssi_video_params_t *params = new ssi_video_params_t ();
				*meta = params;
				if (element->QueryIntAttribute ("width", &params->widthInPixels) != TIXML_SUCCESS) {
					ssi_wrn ("attribute <width> missing in tag <meta>");
					return false;
				}
				if (element->QueryIntAttribute ("height", &params->heightInPixels) != TIXML_SUCCESS) {
					ssi_wrn ("attribute <height> missing in tag <meta>");
					return false;
				}
				if (element->QueryIntAttribute ("depth", &params->depthInBitsPerChannel) != TIXML_SUCCESS) {
					ssi_wrn ("attribute <depth> missing in tag <meta>");
					return false;
				}
				if (element->QueryIntAttribute ("channels", &params->numOfChannels) != TIXML_SUCCESS) {
					ssi_wrn ("attribute <channels> missing in tag <meta>");
					return false;
				}
				int flip = 0;
				if (element->QueryIntAttribute ("channels", &flip) != TIXML_SUCCESS) {
					ssi_wrn ("attribute <flip> missing in tag <meta>");
				}
				params->flipImage = flip != 0;
		
				break;
			}
			default:
				ssi_wrn ("type '%s' doesn't support meta information", SSI_TYPE_NAMES[sample_type]);
				break;
		}
	}

	ssi_char_t *path_data = ssi_strcat (path_info, "~");			
	_file_data = File::CreateAndOpen (ftype, File::READ, path_data);
	if (!_file_data) {
		ssi_wrn ("could not open data file '%s'", path_data);
		return false;
	}

	ssi_stream_init (data, 0, sample_dimension, sample_byte, sample_type, sample_rate, 0);
	ssi_stream_init (_stream, 0, sample_dimension, sample_byte, sample_type, sample_rate, 0);

	// count chunks
	_n_chunks = 0;	
	_next_chunk = 0;
	element = body->FirstChildElement ("chunk");
	if (element) {
		do {
			_n_chunks++;
			element = element->NextSiblingElement ("chunk");
		} while (element);
	}

	// read in chunks
	_n_samples = 0;
	_samples = new ssi_size_t[_n_chunks];
	_time = new ssi_time_t[_n_chunks];
	_bytes = new ssi_size_t[_n_chunks];	
	element = body->FirstChildElement ("chunk");
	ssi_size_t n = 0;
	if (element) {
		do {
			ssi_time_t time = 0;
			if (element->QueryDoubleAttribute ("from", &time) != TIXML_SUCCESS) {
				ssi_wrn ("attribute <time> missing in tag <chunk>");
				return false;
			}
			_time[n] = time;
			int bytes = 0;
			if (element->QueryIntAttribute ("byte", &bytes) != TIXML_SUCCESS) {
				ssi_wrn ("attribute <bytes> missing in tag <chunk>");
				return false;
			}
			_bytes[n] = ssi_cast (ssi_size_t, bytes);
			int samples = 0;
			if (element->QueryIntAttribute ("num", &samples) != TIXML_SUCCESS) {
				ssi_wrn ("attribute <time> missing in tag <chunk>");
				return false;
			}
			_n_samples += ssi_cast (ssi_size_t, samples);
			_samples[n++] = ssi_cast (ssi_size_t, samples);
			element = element->NextSiblingElement ("chunk");
		} while (element);
	}

	delete[] path_info;
	delete[] path_data;

	return true;
};