Exemple #1
0
const BWDB::dbrow *BWDB::get_prepared_row()
{
    _clear_row();
    rowp = new(row);
    int colcount = sqlite3_column_count(stmt);
    if (sqlite3_step(stmt) == SQLITE_ROW)
    {
        for (int i = 0; i < colcount; ++i)
        {
            const char *colname = (const char *) sqlite3_column_name(stmt, i);
            const char *colval = (const char *) sqlite3_column_text(stmt, i);
            if (colname && colval)
            {
                rowp->insert({colname, colval});
            }
        }
        return rowp;
    } else
    {
        _finalize();
        return nullptr;
    }

}
Exemple #2
0
PoiseuilleFlowSystem::~PoiseuilleFlowSystem(){
	_finalize();
	numParticles = 0;
}
  void IndexWriter::_IndexWriter(const bool create){
  //Func - Initialises the instances
  //Pre  - create indicates if the indexWriter must create a new index located at path or just open it
  //Post -

	similarity = CL_NS(search)::Similarity::getDefault();

	useCompoundFile = true;
	if ( directory->getDirectoryType() == RAMDirectory::DirectoryType() )
	    useCompoundFile = false;

	//Create a ramDirectory
	ramDirectory = _CLNEW TransactionalRAMDirectory;

	CND_CONDITION(ramDirectory != NULL,"ramDirectory is NULL");

	//Initialize the writeLock to
	writeLock  = NULL;
	
	//initialise the settings...
	maxFieldLength = DEFAULT_MAX_FIELD_LENGTH;
	mergeFactor = DEFAULT_MERGE_FACTOR;
	maxMergeDocs = DEFAULT_MAX_MERGE_DOCS;
	writeLockTimeout = WRITE_LOCK_TIMEOUT;
	commitLockTimeout = COMMIT_LOCK_TIMEOUT;
	minMergeDocs = DEFAULT_MAX_BUFFERED_DOCS;
	termIndexInterval = DEFAULT_TERM_INDEX_INTERVAL;

	//Create a new lock using the name "write.lock"
	LuceneLock* newLock = directory->makeLock(IndexWriter::WRITE_LOCK_NAME);

	//Condition check to see if newLock has been allocated properly
	CND_CONDITION(newLock != NULL, "No memory could be allocated for LuceneLock newLock");

	//Try to obtain a write lock
	if (!newLock->obtain(writeLockTimeout)){
		//Write lock could not be obtained so delete it
		_CLDELETE(newLock);
		//Reset the instance
		_finalize();
		//throw an exception because no writelock could be created or obtained
		_CLTHROWA(CL_ERR_IO, "Index locked for write or no write access." );
	}

	//The Write Lock has been obtained so save it for later use
	this->writeLock = newLock;

	//Create a new lock using the name "commit.lock"
	LuceneLock* lock = directory->makeLock(IndexWriter::COMMIT_LOCK_NAME);

	//Condition check to see if lock has been allocated properly
	CND_CONDITION(lock != NULL, "No memory could be allocated for LuceneLock lock");

	LockWith2 with ( lock,commitLockTimeout,this, NULL, create );
	{
            // CPIXASYNC SCOPED_LOCK_MUTEX(directory->THIS_LOCK) // in- & inter-process sync
            SCOPED_LOCK_CRUCIAL_MUTEX(directory->Directory_THIS_LOCK) // in- & inter-process sync
		with.run();
	}

	//Release the commit lock
	_CLDELETE(lock);

   isOpen = true;
  }
BodySystemCPU::~BodySystemCPU()
{
    _finalize();
    m_numBodies = 0;
}
CFishListCtrl::~CFishListCtrl()
{
    _finalize();
}
Exemple #6
0
int _tmain(int argc, _TCHAR* argv[])
{
	int nChannelCount;
	int nSampleRate;
	int nBitrate=128000;
	int nBitsPerSample=16;
	int nChannelMode=2; //0-Multichannel, 1-Mono, 2-Stereo, 3-IS, 4-PS, 5-DC
	int bMPEG4AAC=9;    // Let the encoder choice: with enc_aacplus.dll 1.24 was 4 but with 1.26 was MPEG2
	int mp4mode = 0;
	int bNoPS = 0;
	int bRawPCM = 0;
	int bSpeech = 0;
	int bPNS = 0;
	int nType=1;        //0- he, 1 - lc, 2 - he-high, 3-PS
	DWORD dwBytesRead;
	_TCHAR szTempDir[MAX_PATH];
	char szTempName[MAX_PATH];
	char lpPathBuffer[BUFSIZE];

	_TCHAR * strOutputFileName = NULL;
	_TCHAR * strInputFileName = NULL;
	FILE*  hInput=NULL;
	FILE*  hOutput=NULL;
	wavHeader wav;

	_tsetlocale(LC_ALL, _T(""));

	if(argc<2)
	{
		showUsage(argv[0]);
		return ERROR_INSUFFICIENT_ARGS;
	}

	strInputFileName	= argv[1];
	strOutputFileName	= argv[2];

	// let's parse command line
	for(int i=3;i<argc;++i)
	{
		if(0==_tcscmp(_T("--rawpcm"), argv[i]))
		{
			nSampleRate=_tstoi(argv[++i]);
			nChannelCount=_tstoi(argv[++i]);
			nBitsPerSample=_tstoi(argv[++i]);
			bRawPCM=1;
			continue;
		}

		if(0==_tcscmp(_T("--mono"), argv[i]))
		{
			nChannelMode=1;
			continue;
		}
		if(0==_tcscmp(_T("--ps"), argv[i]))
		{
			bNoPS=1;
			nType=0;
			//nChannelMode=4; assigned only if bitrate <=56000
			continue;
		}
		if(0==_tcscmp(_T("--is"), argv[i]))
		{
			nChannelMode=3;
			continue;
		}
		if(0==_tcscmp(_T("--dc"), argv[i]))
		{
			nChannelMode=5;
			continue;
		}
		if(0==_tcscmp(_T("--he"), argv[i]))
		{
			nType=0;
			continue;
		}
		if(0==_tcscmp(_T("--lc"), argv[i]))
		{
			nType=1;
			continue;
		}
		if(0==_tcscmp(_T("--high"), argv[i]))
		{
			nType=2;
			continue;
		}
		if(0==_tcscmp(_T("--br"), argv[i]))
		{
			nBitrate=_tstoi(argv[++i]);
			continue;
		}
		if(0==_tcscmp(_T("--mpeg2aac"), argv[i]))
		{
			bMPEG4AAC=0;
			continue;
		}
		if(0==_tcscmp(_T("--mpeg4aac"), argv[i]))
		{
			bMPEG4AAC=1;
			continue;
		}
		if(0==_tcscmp(_T("--speech"), argv[i]))
		{
			bSpeech=1;
			continue;
		}
		if(0==_tcscmp(_T("--pns"), argv[i]))
		{
			bPNS=1;
			continue;
		}
	}

	showLogo();

	int bStdIn = 0==_tcscmp(_T("-"), strInputFileName)?1:0;
	// let's open WAV file
	if(bStdIn)
	{
		#ifdef WIN32
		setmode(fileno(stdin), O_BINARY);
		#endif
		hInput = stdin;
	}
	else
	{
		hInput = _tfopen(strInputFileName,_T("rb"));
	}

	if(!hInput)
	{
		printf("Can't open input file!\n");
		return ERROR_CANNOT_OPEN_INFILE;
	};

	if(0==bRawPCM)
	{
		// let's read WAV HEADER
		memset(&wav, 0, sizeof(wav));
		if(fread(&wav, 1, sizeof(wav), hInput)!=sizeof(wav))
		{
			// Can't read wav header
			fclose(hInput);
			printf("Input file must be WAV PCM!\n");
			return ERROR_CANNOT_LOAD_DECODER;
		}

		if(	wav.chunkid!=0x46464952
			|| wav.rifftype!=0x45564157
			|| wav.fmt!=0x20746D66
			|| wav.fmtsize!=0x00000010
			|| wav.bps!=16
			|| (wav.srate!=32000 && wav.srate!=44100 && wav.srate!=48000 )
			|| wav.ccode!=0x0001)
		{
			// unsupported or invalid wav format
			fclose(hInput);
			printf("Invalid or unsuppored WAV file format (must be 16 bit PCM)\n");
			return ERROR_INCOMPATABLE_DECODER;
		}

		nBitsPerSample	= wav.bps;
		nChannelCount	= wav.nch;
		nSampleRate	= wav.srate;
	}

	int bitrates[3][6] =
	{
		{
		 //he - mono,	 stereo,			6ch
		8000, 64000,	16000, 128000,	96000, 213335
		},
		{
		 //lc - mono,	 stereo,			6ch
		8000, 160000,	16000, 320000,	160000, 320000
		},
		{
		 //hi - mono,	 stereo,			6ch
		64000, 160000,	96000, 256000,	8000, 256000
		}
	};

	int maxBitrate=0;
	int minBitrate=0;

	switch(nChannelCount)
	{
		case 1:
			minBitrate = bitrates[nType][0];
			maxBitrate = bitrates[nType][1];
			break;
		case 2:
			minBitrate = bitrates[nType][2];
			maxBitrate = bitrates[nType][3];
			break;
		default:
			minBitrate = bitrates[nType][4];
			maxBitrate = bitrates[nType][5];
			break;
	}

	const _TCHAR* channelModes[] = {_T("Multichannel"), _T("Mono"), _T("Stereo"), _T("Independant Stereo"), _T("Parametric Stereo"), _T("Dual Channels")};
	const _TCHAR* codecName[] = {_T("HE-AAC"),_T("LC-AAC"),_T("HE-AAC High"),_T("HE-AAC+PS")};
	const _TCHAR* BooleanResult[] = {_T("No"), _T("Yes")};

	nBitrate		= min(max(minBitrate, nBitrate), maxBitrate);

	nChannelMode	= 1==nChannelCount ? 1:((2==nChannelCount) ? ( (nBitrate<=56000 && 0==nType && 1==bNoPS) ? 4:nChannelMode):0);

	if (4==nChannelMode)// only for printf
		nType=3;

	// just to be sure that we have the correct mode
	_TCHAR *ext = PathFindExtension(strOutputFileName);
	if(ext) {
		if(!_tcsicmp(ext,_T(".m4a")) || !_tcsicmp(ext,_T(".mp4"))) mp4mode = 1;
	}

	// let's write used config:
	_tprintf(_T("\nInput file: %s\nOutput file: %s\nSampleRate: %d\nChannelCount: %d\nBitsPerSample: %d\nBitrate: %d\nChannelMode: %s\nEngine: %s\nTune For Speech: %s\nPNS: %s\nMP4 Output: %s\n"),
		strInputFileName, strOutputFileName, nSampleRate, nChannelCount,nBitsPerSample , nBitrate, channelModes[nChannelMode], codecName[nType], BooleanResult[bSpeech?1:0], BooleanResult[bPNS?1:0], BooleanResult[mp4mode?1:0]);
	fflush(stdout);

	if (4==nChannelMode) //back
		nType=0;

	//create temp file name
#ifdef UNICODE
	_TCHAR tempFileW[MAX_PATH];
#endif
	GetTempPath(
		MAX_PATH,   // length of the buffer
        szTempDir);      // buffer for path
#ifdef UNICODE
	GetTempFileName(szTempDir, // directory for temp files
        NULL,                    // temp file name prefix
        0,                        // create unique name
        tempFileW);              // buffer for name
	wcstombs_s(NULL,szTempName,MAX_PATH,tempFileW,(MAX_PATH)*sizeof(_TCHAR));
#else
	GetTempFileName(szTempDir, // directory for temp files
        NULL,                    // temp file name prefix
        0,                        // create unique name
        szTempName);              // buffer for name
#endif

	AudioCoder * encoder=NULL;
	AudioCoder *(*finishAudio3)(_TCHAR *fn, AudioCoder *c)=NULL;
	void (*prepareToFinish)(_TCHAR *filename, AudioCoder *coder)=NULL;
	AudioCoder* (*createAudio3)(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile)=NULL;
	HMODULE encplug = LoadLibrary(_T("enc_aacplus.dll"));
	if(NULL == encplug)
	{
		fclose(hInput);
		printf("Can't find enc_aacplus.dll!\n");
		return ERROR_CANNOT_LOAD_ENCODER;
	}
	*(void **)&createAudio3 = (void *)GetProcAddress(encplug, "CreateAudio3");
	if( NULL == createAudio3)
	{
		FreeLibrary(encplug);
		fclose(hInput);
		printf("Can't find CreateAudio3 in enc_aacplus.dll!\n");
		return ERROR_CANNOT_LOAD_DECODER;
	}
#ifdef UNICODE
	*(void **)&finishAudio3=(void *)GetProcAddress(encplug,"FinishAudio3W");
	*(void **)&prepareToFinish=(void *)GetProcAddress(encplug,"PrepareToFinishW");
#else
	*(void **)&finishAudio3=(void *)GetProcAddress(encplug,"FinishAudio3");
	*(void **)&prepareToFinish=(void *)GetProcAddress(encplug,"PrepareToFinish");
#endif

	{
		//const char* codecSection[] = {"audio_aacplus","audio_aac","audio_aacplushigh"};
		FILE * tmp = fopen(szTempName,"wt");
		fprintf(tmp, "[audio%s_aac%s]\nsamplerate=%u\nchannelmode=%u\nbitrate=%u\nv2enable=1\nbitstream=%i\nsignallingmode=0\nspeech=%i\npns=%i\n",
			      mp4mode?"_mp4":"",1==nType?"":2==nType?"plushigh":"plus", nSampleRate, nChannelMode, nBitrate, bMPEG4AAC?5:0, bSpeech?1:0, bPNS?1:0);
		fclose(tmp);

		unsigned int outt = 0;
		if (1==nType)
			outt = mp4mode ? mmioFOURCC('M','4','A',' ') : mmioFOURCC('A','A','C','r');
		else if (2==nType)
			outt = mp4mode ? mmioFOURCC('M','4','A','H') : mmioFOURCC('A','A','C','H');
		else
			outt = mp4mode ? mmioFOURCC('M','4','A','+') : mmioFOURCC('A','A','C','P');
		encoder=createAudio3(nChannelCount,nSampleRate, nBitsPerSample ,mmioFOURCC('P','C','M',' '),&outt,szTempName);
		DeleteFileA(szTempName);
	}


	if(NULL==encoder)
	{
		FreeLibrary(encplug);
		fclose(hInput);
		printf("Can't create encoder!\n");
		return ERROR_CANNOT_OPEN_ENCODER;
	}

	hOutput = _tfopen(strOutputFileName, _T("wb"));

	if (!hOutput)
        {
		delete encoder;
		FreeLibrary(encplug);
		fclose(hInput);
		printf("Can't create output file!\n");
	        return ERROR_CANNOT_OPEN_OUTFILE;
        }

	// encode
	printf("Encoding...");
	int toRead = (2*nChannelCount*2*1024);
	toRead = (sizeof(lpPathBuffer)/toRead)*toRead;
	while(0!=(dwBytesRead = fread(lpPathBuffer, 1, toRead, hInput)))
        {
		_encode(hOutput, encoder, dwBytesRead, lpPathBuffer, bMPEG4AAC);
        }
	printf("\rFinalizing...");

	// finalize encoding
	if(prepareToFinish) prepareToFinish(strOutputFileName,encoder);
	_finalize(hOutput, encoder, lpPathBuffer, bMPEG4AAC);
	fclose(hOutput);
	if (finishAudio3) finishAudio3(strOutputFileName,encoder);
	fclose(hInput);
	delete encoder;
	FreeLibrary(encplug);

	if(mp4mode) {
		struct __stat64 statbuf;
		if(!_tstat64(strOutputFileName,&statbuf)) {
			if(!_tfopen_s(&hOutput,strOutputFileName,_T("r+b"))) {
				optimizeAtoms(hOutput,statbuf.st_size);
			}
			if(hOutput) fclose(hOutput);
		}
	}

	// shut down
	printf("\rDone           \n");
	return TRANSCODE_FINISHED_OK;
}
Exemple #7
0
 void operator()(T& t, T0 t0, T1 t1, T2 t2)
 {
   _finalize(t);
 }
Exemple #8
0
BodySystemGPU<T>::~BodySystemGPU()
{
    _finalize();
    m_numBodies = 0;
}
Exemple #9
0
 void operator()(T& t)
 {
   _finalize(t);
 }
Exemple #10
0
 R operator()(T& t, T0 t0, T1 t1, T2 t2)
 {
   _finalize(t);
   return t.get_aspect().template get<N>()(t, t0, t1, t2);
 }
Exemple #11
0
 R operator()(T& t, T0 t0)
 {
   _finalize(t);
   return t.get_aspect().template get<N>()(t, t0);
 }
Exemple #12
0
FluidSystem::~FluidSystem()
{
    _finalize();
    m_numParticles = 0;
}
Exemple #13
0
int main(int argc, char* argv[]) {
  int retvalue = 0, rlret;
  char *dataFileName, *dir, buf[1024];
  
  signal(SIGSEGV, _handleSignal);
  signal(SIGINT, _handleSignal);
  signal(SIGTERM, _handleSignal);
  signal(SIGFPE, _handleSignal);
  signal(SIGPROF, _handleSignal);

  //sprintf(dataFileName, "%s.dat", argv[0]);

  rlret = readlink("/proc/self/exe", buf, 1023);
  if (rlret != -1) {
    buf[rlret] = 0;
    dir = dirname(buf);
  } else {
    dir = getcwd(NULL, 0);
  }
  /*fprintf(stderr, "Writing datafile in %s.\n", dir);*/
  dataFileName = (char*)"datafile.dat";
  datfname = malloc(strlen(dir) + strlen(dataFileName) + 2);
  sprintf(datfname, "%s/%s", dir, dataFileName);
  //fprintf(stderr, "%s\n", datfname);
  //exit(0);
  

  #ifdef THREADED
    #ifdef DEBUG
      fprintf(stderr, "Threaded mode enabled.\n");
    #endif
  #endif

  #ifdef DEBUG
    fprintf(stderr, "program start\n");
  #endif

  #ifdef THREAD_SAFE
    pthread_mutex_init(&libMutex, NULL);
  #endif

  _registerAll();

  if(!_instrumentationInfo) {
    _initInstrumentationInfo(0);
  }

  _initialReadDataFile();

  _startTiming();

  /* call original main function */
  #ifdef THREADED
    {
      struct strMainArgs mainArgs;
      struct strTimerArgs timerArgs;
      pthread_t t_program, t_runtimer;
      /* TODO: threaded?? 
         issue: stack space for thread */
      /*mainArgs.ret = 0;
      mainArgs.argc = argc;
      mainArgs.argv = argv;
      if(pthread_create(&t_program, NULL, programThread, (void*)&mainArgs)) {
        fprintf(stderr, "Error creating program thread.\n");
        abort();
      }*/
      _running = 1;
      timerArgs.msInterval = 1;
      timerArgs.timerFunction = &_handleInvariantTimerUpdate;
      if(pthread_create(&t_timer, NULL, timerThread, (void*)&timerArgs)) {
        fprintf(stderr, "Error creating timer thread.\n");
        abort();
      }
      if(pthread_create(&t_runtimer, NULL, runTimerThread, NULL)) {
        fprintf(stderr, "Error creating run-timer thread.\n");
        abort();
      }

      /* non-threaded main call */
      retvalue = _main_original(argc, argv);

      /*pthread_join(t_program, NULL);*/
      _running = 0;

      _instrumentationInfo->passFail[_instrumentationInfo->run] = 1;
      _instrumentationInfo->run++;

      /*pthread_join(t_timer, NULL);*/
      pthread_join(t_runtimer, NULL);
      /*retvalue = mainArgs.ret;*/
    }
  #else
    retvalue = _main_original(argc, argv);
    
    _instrumentationInfo->passFail[_instrumentationInfo->run] = 1;
    _instrumentationInfo->run++;
  #endif

  #ifdef THREAD_SAFE
    pthread_mutex_lock(&libMutex);
  #endif

  _stopTiming();

  #ifdef DEBUG
    fprintf(stderr, "program returned with value %d\n", retvalue);
    _fprintTiming(stderr);
  #endif

  _finalize();

  _exitHandled = 1;

  #ifdef THREAD_SAFE
    pthread_mutex_unlock(&libMutex);
  #endif

  return 0;
}
Exemple #14
0
static int finalize_one_thread (void *item,void *arg)
{
   _finalize ((ft_thread_t)item);
   return REMOVE;
}
ParticleSystem::~ParticleSystem()
{
    _finalize();
    m_numParticles = 0;
}
Exemple #16
0
 void operator()(T& t, T0 t0)
 {
   _finalize(t);
 }
btGpu3DGridBroadphase::~btGpu3DGridBroadphase()
{
	//btSimpleBroadphase will free memory of btSortedOverlappingPairCache, because m_ownsPairCache
	assert(m_bInitialized);
	_finalize();
}
 PrivateMemorySegment::~PrivateMemorySegment()
 {
     _finalize();
 }