Exemple #1
0
//------------SRC_MANAGER--------------------
void SrcManager::captureCallBack(CAPTURE_HANDLE handle, unsigned char *data, unsigned int height, unsigned int width)
{
	for(set<CaptureDevice*>::iterator it = _active_capture_devices[handle].begin(); it != _active_capture_devices[handle].end(); ++it)
	{
		ISource *source = dynamic_cast<ISource*>(reinterpret_cast<CaptureDevice*>(*it));
		Image *img = Image::initImage(data, width, height);
		source->broadcastFrame(img);
	}
}
void CStreamSource::releasePhysicalSource()
{
	if (hasPhysicalSource())
	{
		CAudioMixerUser *mixer = CAudioMixerUser::instance();
		ISource *pSource = getPhysicalSource();
		nlassert(pSource != NULL);

		// free the track
		pSource->stop();
		pSource->setStreaming(false);
		mixer->freeTrack(m_Track);
		m_Track = NULL;
	}
}
Exemple #3
0
void CSimpleSource::releasePhysicalSource()
{
	if (hasPhysicalSource())
	{
		CAudioMixerUser *mixer = CAudioMixerUser::instance();
		ISource *pSource = getPhysicalSource();
		nlassert(pSource != NULL);

		// free the track
		pSource->stop();
		pSource->setStaticBuffer(NULL);
		mixer->freeTrack(_Track);
		_Track = NULL;
	}
}
Exemple #4
0
void PipedReader::inputThreadProc()
{
    try {
        ISource *src = source();
        uint32_t bpf = src->getSampleFormat().mBytesPerFrame;
        std::vector<uint8_t> buffer(NSAMPLES * bpf);
        uint8_t *bp = &buffer[0];
        HANDLE ph = m_writePipe.get();
        size_t n;
        DWORD nb;
        while ((n = src->readSamples(bp, NSAMPLES)) > 0
               && WriteFile(ph, bp, n * bpf, &nb, 0))
            ;
    } catch (...) {}
    m_writePipe.reset(); // close
}
Exemple #5
0
void Service::slotFind(const QString &sourceId, const QString &key, PCursor *ppCursor)
{
    // 获得当前的InputMethod
    InputMethod *pInputMethod = _pEnvironment->pCurrentInputMethod;
    if (!pInputMethod)
    {
        throw Exception("slotFind:当前输入法为空。");
    }
    ISource *pSource = pInputMethod->getSource(sourceId);
    if (!pSource)
    {
        throw SourceNotFoundException(QString("slotFind:没有找到ID为%1的数据源。").arg(sourceId));
    }
    ICursor *pICursor = pSource->query(key);
    if (!pICursor)
    {
        throw Exception(QString("slotFind:数据源%1查找%2未返回游标。").arg(pSource->idAndName()).arg(key));
    }
    *ppCursor = QSharedPointer< ICursor >(pICursor); 
}
OMX_ERRORTYPE TestTranscode::Execute(CodecConfigType *pConfig,
        DynamicConfigType *pDynamicConfig, OMX_S32 nTestNum) {

    (void)pDynamicConfig; (void)nTestNum;
    OMX_ERRORTYPE result = OMX_ErrorNone;
    OMX_U32 i;

    m_pCrypto = new Crypto();
    m_pBufferManager = new BufferManager();

    if (!m_pCrypto || !m_pBufferManager) {
        return OMX_ErrorInsufficientResources;
    }

    m_pSources.push_back(new DecoderFileSource(m_pCrypto));
    m_pSources.push_back(new Decoder(pConfig));
    m_pSources.push_back(new NativeWindow(
                pConfig->bRotateDisplay, pConfig->nOutputColorFormat));
    m_pSources.push_back(new Encoder(pConfig));
    m_pSources.push_back(new EncoderFileSink(m_pCrypto));

    if (pConfig->bSecureSession) {
        result = m_pCrypto->Init();
        FAILED1(result, "Crypto Init failed");
    }

    for (i = 0; i < m_pSources.size(); i++) {

        if (!m_pSources[i]) {
            return OMX_ErrorInsufficientResources;
        }

        ISource *prev = (i == 0 ? NULL : m_pSources[i-1]);
        ISource *next = (i == m_pSources.size() - 1 ? NULL : m_pSources[i+1]);
        VTEST_MSG_HIGH("Linking %s: %s ==> %s ==> %s",
                m_pSources[i]->Name(), (prev != NULL ? prev->Name() : "NONE"),
                m_pSources[i]->Name(), (next != NULL ? next->Name() : "NONE"));
        result = m_pSources[i]->Configure(pConfig, m_pBufferManager, prev, next);
        FAILED1(result, "Could not configure %s", m_pSources[i]->Name());
    }

    for (i = 0; i < (m_pSources.size() - 1); i++) {
        result = m_pBufferManager->SetupBufferPool(m_pSources[i], m_pSources[i+1]);
        if (result != OMX_ErrorNone) {
            VTEST_MSG_ERROR("Buffer pool alloc failed between %s %s",
                    m_pSources[i]->Name(), m_pSources[i+1]->Name());
            break;
        }
    }

    if (result != OMX_ErrorNone) {
        while (i > 0) {
            m_pBufferManager->FreeBuffers(m_pSources[i-1], PORT_INDEX_OUT);
            i--;
        }
        return result;
    }

    OMX_S32 executionResult = 0;

    /*start/stop the last node so that we can transcode all frames*/
    executionResult = m_pSources[m_pSources.size() - 1]->Start();

    executionResult |= m_pSources[m_pSources.size() - 1]->Finish();

    executionResult |= m_pSources[m_pSources.size() - 1]->Stop();
    result = (OMX_ERRORTYPE)executionResult;

    for (i = 0; i < (m_pSources.size() - 1); i++) {
        m_pBufferManager->FreeBuffers(m_pSources[i], PORT_INDEX_OUT);
    }

    if (pConfig->bSecureSession) {
        m_pCrypto->Terminate();
    }

    return result;
}
Exemple #7
0
int Test11B_FB_Demod()
{
	printf ( "Demodulate 11b with Fine Brick!\n" );


	ISource * ssrc = CreateDemodGraph ();

//	int bCnt = LoadSoraDumpFile ( "c:\\11b-1M-1.dmp", (COMPLEX16*)InputBuf, IN_BUF_SIZE );
//	int bCnt = LoadSoraDumpFile ( "d:\\noise.dmp", (COMPLEX16*)InputBuf, IN_BUF_SIZE );
	int bCnt = LoadSoraDumpFile ( "d:\\test.dmp", (COMPLEX16*)InputBuf, IN_BUF_SIZE );


	printf ( "Load sample %d\n", bCnt );



	ULONGLONG ts1 = SoraGetCPUTimestamp ( &tsinfo );
	for ( int i=0; i<100; i++) {
		
		InitFBDemodContext ((COMPLEX16*)InputBuf, (bCnt)*sizeof(COMPLEX16), OutputBuf, OUT_BUF_SIZE);

		ssrc->Reset ();
		if ( BB11bDemodCtx.CF_Error::error_code() == E_ERROR_SUCCESS ) {
			FB_11B_DemodBuffer (ssrc);
		} else {
			printf ( "Reset error!\n" );
		}
	}	
	ULONGLONG ts2 = SoraGetCPUTimestamp ( &tsinfo );
	
	ulong& err = BB11bDemodCtx.CF_Error::error_code();
	if (  err == E_ERROR_FRAME_OK ) {	
		printf ( "one good frame find!\n" );
	} else {
		printf ( "error code: %08x \n", err );
	}


	printf("Signal data rate:	 %dk\n",BB11bDemodCtx.CF_11bRxVector::data_rate_kbps() ); 
	printf("Bytes decoded: %d\n",   	BB11bDemodCtx.CF_11bRxVector::frame_length() );
    printf("Time cost average:   %.3fus \n", SoraTimeElapsed (ts2-ts1, &tsinfo) * 1.0 / 1000 / 100 );

/*
	if ( pArgs->pcOutFileName != NULL ) {
		FILE* pOut = NULL;
#pragma warning (push)
#pragma warning (disable:4996)
		pOut = fopen(pArgs->pcOutFileName, "w+b");
#pragma warning (pop)
		if (!pOut)
		{
			printf("Cannot create output file.\n");
			return -1;
		}

		fwrite(	OutputBuf, 
				fb11bDemodCtx.CF_MPDU_Info::frame_len(), 
				1, pOut);
		fclose(pOut);
	}
*/
	IReferenceCounting::Release (ssrc);

	return 0;
}
Exemple #8
0
Lexer::Lexer(DiagBuilder &diag, ISource &source)
    : diag(diag), source(source), stringNext(false)
{
  ch = source.Current();
  pk = source.Lookahead();
}
void CStreamSource::play()
{
	nlassert(!_Playing);
	bool play = false;
	CAudioMixerUser *mixer = CAudioMixerUser::instance();
	
	{
		CAutoMutex<CMutex> autoMutex(m_BufferMutex);
		
		//if ((mixer->getListenPosVector() - _Position).sqrnorm() > m_StreamSound->getMaxDistance() * m_StreamSound->getMaxDistance())
		if ((_RelativeMode ? getPos().sqrnorm() : (mixer->getListenPosVector() - getPos()).sqrnorm()) > m_StreamSound->getMaxDistance() * m_StreamSound->getMaxDistance())
		{
			// Source is too far to play
			if (_Spawn)
			{
				if (_SpawnEndCb != NULL)
					_SpawnEndCb(this, _CbUserParam);
				delete this;
			}
			// nldebug("CStreamSource %p : play FAILED !", (CAudioMixerUser::IMixerEvent*)this);
			return;
		}
		
		CAudioMixerUser *mixer = CAudioMixerUser::instance();

		if (!hasPhysicalSource())
			initPhysicalSource();

		if (hasPhysicalSource())
		{
			ISource *pSource = getPhysicalSource();
			nlassert(pSource != NULL);
			
			for (uint i = 0; i < m_NextBuffer; ++i)
				pSource->submitStreamingBuffer(m_Buffers[i]);
			
			// pSource->setPos( _Position, false);
			pSource->setPos(getVirtualPos(), false);
			if (!m_Buffers[0]->isStereo())
			{
				pSource->setMinMaxDistances(m_StreamSound->getMinDistance(), m_StreamSound->getMaxDistance(), false);
				setDirection(_Direction); // because there is a workaround inside
				pSource->setVelocity(_Velocity);
			}
			pSource->setGain(_Gain);
			pSource->setSourceRelativeMode(_RelativeMode);
			// pSource->setLooping(_Looping);
			pSource->setPitch(_Pitch);
			pSource->setAlpha(m_Alpha);
			
			// and play the sound
			play = pSource->play();
			// nldebug("CStreamSource %p : REAL play done", (CAudioMixerUser::IMixerEvent*)this);
		}
		else
		{
			if (_Priority == HighestPri)
			{
				// This sound is not discardable, add it in waiting playlist
				mixer->addSourceWaitingForPlay(this);
				return;
			}
			else
			{
				// No source available, kill.
				if (_Spawn)
				{
					if (_SpawnEndCb != NULL)
						_SpawnEndCb(this, _CbUserParam);					
					delete this;
				}
				return;
			}
		}
		
		if (play)
			CSourceCommon::play();
	}

	nlassert(play);
}
Exemple #10
0
/// Play
void CSimpleSource::play()
{
	// nldebug("CSimpleSource %p : play", this);

	CAudioMixerUser *mixer = CAudioMixerUser::instance();

	// -- Some test to check if we can play the source

	// Check if sample buffer is available and if the sound source is not too far
	if (_SimpleSound->getBuffer() == 0
		|| !_SimpleSound->getBuffer()->isBufferLoaded()
		//|| (mixer->getListenPosVector() - _Position).sqrnorm() > _SimpleSound->getMaxDistance() * _SimpleSound->getMaxDistance())
		|| (_RelativeMode ? getPos().sqrnorm() : (mixer->getListenPosVector() - getPos()).sqrnorm()) > _SimpleSound->getMaxDistance() * _SimpleSound->getMaxDistance())
	{
		// The sample buffer is not available, don't play (we don't know the length)
		_WaitingForPlay = false;
		if (_Spawn)
		{
			if (_SpawnEndCb != 0)
				_SpawnEndCb(this, _CbUserParam);
			
			delete this;
		}
		// nldebug("CSimpleSource %p : play FAILED !", (CAudioMixerUser::IMixerEvent*)this);
		return;
	}

	// -- Here we can play the source, either in a real track or as a muted source.

	// Try to obtain a track
	if (!hasPhysicalSource())
		initPhysicalSource();

	if (hasPhysicalSource())
	{
		ISource *pSource = getPhysicalSource();
		nlassert(pSource != NULL);

		// ok, we have a track to realy play, fill the data into the track
		pSource->setStaticBuffer(_SimpleSound->getBuffer());
		
		// pSource->setPos( _Position, false);
		pSource->setPos(getVirtualPos(), false);
		if (!_SimpleSound->getBuffer()->isStereo())
		{
			pSource->setMinMaxDistances(_SimpleSound->getMinDistance(), _SimpleSound->getMaxDistance(), false);
			setDirection(_Direction); // because there is a workaround inside
			pSource->setVelocity(_Velocity);
		}
		pSource->setGain(getFinalGain());
		pSource->setSourceRelativeMode(_RelativeMode);
		pSource->setLooping(_Looping);
		pSource->setPitch(_Pitch);
		pSource->setAlpha(_Alpha);
		
		// and play the sound
		bool play = pSource->play();		

#ifdef NL_DEBUG
		nlassert(play);
#else
		if (!play)
			nlwarning("Failed to play physical sound source. This is a serious error");
#endif

		// nldebug("CSimpleSource %p : REAL play done", (CAudioMixerUser::IMixerEvent*)this);
	}
	else
	{
		if (_Priority == HighestPri)
		{
			// This sound is not discardable, add it in waiting playlist
			mixer->addSourceWaitingForPlay(this);
			_WaitingForPlay = true;
			return;
		}
		// there is no available track, just do a 'muted' play
		mixer->addEvent(this, CTime::getLocalTime() + _SimpleSound->getDuration());
		_PlayMuted = true;
		mixer->incPlayingSourceMuted();
		// nldebug("CSimpleSource %p : MUTED play done", (CAudioMixerUser::IMixerEvent*)this);
	}

	CSourceCommon::play();
	_WaitingForPlay = false;
}