コード例 #1
0
				Object::Action Object::SetProfile(Sample *sample)
				{
					if (sample && Tracker.IsValid() && DescIndex != UINT_ERROR &&
						Utility::GetStreamCountFromDesc(&Profile.inputs))
					{
						if (TrackerConfig.empty())
						{
							String folder, file;

							auto vars = App::Vars::GetForCurrentThread();
							if (!vars->GetRecordsCount()) if (Utility::Failed(vars->Read())) return;

							if (vars->HasRecord(_NenaVideo_DFusion_DefCfgFolderRec))
								folder = vars->GetRecord<String>(_NenaVideo_DFusion_DefCfgFolderRec);
							if (vars->HasRecord(_NenaVideo_DFusion_DefCfgFileRec))
								file = vars->GetRecord<String>(_NenaVideo_DFusion_DefCfgFileRec);

							TrackerConfig = folder + file;
						}

						UINT32 streamsRequired = Utility::GetStreamCountFromDesc(Profile.inputs);
						if (streamsRequired != sample->StreamCount)
						{
							Check() = PXC_STATUS_HANDLE_INVALID;
							return;
						}

						PXCCapture::VideoStream::ProfileInfo streamProfile;
						sample->VideoStreams[0]->QueryProfile(&streamProfile);
						Profile.width = streamProfile.imageInfo.width;
						Profile.height = streamProfile.imageInfo.height;

						Check() = Tracker->SetProfile(TrackerConfig.c_str(), &Profile);
					}
					else Check() = PXC_STATUS_HANDLE_INVALID;
				}
コード例 #2
0
//---------------------------------------------------------------------------
void Table::Compact(int *progress) {
	// ok so we're gonna be cheating a bit, instead of figuring out how to safely modify all those
	// nifty indexes that cross reference themselves and blablabla, we're just gonna duplicate the
	// whole table from scratch, overwrite ourselves, and reopen the table. duh.

	// crate a temporary table in windows temp dir
	char temp_table[MAX_PATH+12];
	char temp_index[MAX_PATH+12];
	char old_table[MAX_PATH+12];
	char old_index[MAX_PATH+12];
	DWORD pid=GetCurrentProcessId();

	sprintf(temp_table, "%s.new%08X", Name,pid);
	sprintf(temp_index, "%s.new%08X", IdxName,pid);
	sprintf(old_table, "%s.old%08X", Name,pid);
	sprintf(old_index, "%s.old%08X", IdxName,pid);

	// delete them, in case we crashed while packing

	DeleteFile(temp_table);
	DeleteFile(temp_index);
	DeleteFile(old_table);
	DeleteFile(old_index);

	// create a brand new db and a brand new table
	Table *ctable = db->OpenTable(temp_table, temp_index, NDE_OPEN_ALWAYS, Cached);

	// make a list to keep track of subtables
	LinkedList sublist;

	// duplicate the columns
	Record *record = GetColumns();
	LinkedList *collist = NULL;
	if (record != NULL) 
	{
		collist = record->GetFields();
		if (collist != NULL) 
			collist->WalkList(Compact_ColumnWalk, 0, (void *)ctable, (void *)&sublist);
	}
	ctable->PostColumns();

	// duplicate the indexes
	LinkedList *indlist = GetIndexes();
	if (indlist != NULL) 
		indlist->WalkList(Compact_IndexWalk, 0, (void *)ctable, 0);

	// duplicate the data
	int reccount = GetRecordsCount();
	int ndrop = 0;

	int count = 0;
	First();
	size_t data_size = 65536;
	unsigned char *data = (unsigned char *)malloc(65536);

	while (1) {
		int lasterr = NumErrors();
		GetDefaultScanner()->GetRecordById(count, FALSE);
		count++;

		if (Eof() || count > reccount) break;

		if (NumErrors() > lasterr) 
			continue;

		Index *idx = GetDefaultScanner()->GetIndex();
		int pos = idx->Get(GetDefaultScanner()->GetRecordId());

		if (pos == 0) ndrop++;
		SetDlgInfo(reccount, GetRecordId(), ndrop);
		if (pos == 0) continue;

		int pr = (int)((float)GetRecordId()/(float)reccount*100.0f);
		if (progress != NULL) *progress = pr;
		int gotstuff = 0;

		if (collist != NULL) {
			ColumnField *colfield = static_cast<ColumnField *>(collist->GetHead());
			while (colfield != NULL) {
				unsigned char fieldid = colfield->GetFieldId();
				//char *fieldname = colfield->GetFieldName();
				Field *mfield = this->GetFieldById(fieldid);
				//Field *mfield = GetFieldByName(fieldname);
				if (mfield != NULL) {
					if (!gotstuff) {
						ctable->New();
						gotstuff = 1;
					}
					Field *cfield = ctable->NewFieldById(fieldid, mfield->GetPerm());
					//Field *cfield = ctable->NewFieldByName(fieldname, mfield->GetPerm());
					size_t len = mfield->GetDataSize();
					if (len > data_size)
					{
						data_size = len;
						data = (unsigned char *)realloc(data, data_size);
					}
					mfield->WriteTypedData(data, len);
					cfield->ReadTypedData(data, len);
				}
				colfield = static_cast<ColumnField *>(colfield->GetNext());
			}
		}
		if (gotstuff) ctable->Post(); else ndrop++;
	}
	free(data);

	SetDlgInfo(reccount, GetRecordId(), ndrop);

	// done creating temp table
	db->CloseTable(ctable);

	// close this table
	Close();
	Reset();

	if (MoveFile(Name,old_table))
	{
		if (MoveFile(IdxName,old_index))
		{
			if (!MoveFile(temp_table,Name) || !MoveFile(temp_index,IdxName))
			{
				// failed, try to copy back
				DeleteFile(Name);
				DeleteFile(IdxName);
				MoveFile(old_table,Name); // restore old file
				MoveFile(old_index,IdxName); // restore old file
			}
		}
		else
		{
			MoveFile(old_table,Name); // restore old file
		}
	}

	// clean up our temp files
	DeleteFile(temp_table);
	DeleteFile(temp_index);
	DeleteFile(old_table);
	DeleteFile(old_index);

	while (sublist.GetNElements() > 0) {
		StringField *subfile = static_cast<StringField *>(sublist.GetHead());
		DeleteFile(subfile->GetString());
		sublist.RemoveEntry(subfile);
	}

	if (progress != NULL) *progress = 100;

	// reopen our table
	Init();
	Open();
}