Esempio n. 1
0
int64
MediaBlockMapReader::ReadFramesAt(void* buffer, int64 start, int64 frameCount)
{
    if (start < 0)
        return 0;

    SeekToFrame(start);
    return ReadFrames(buffer, frameCount);
}
Esempio n. 2
0
int64
MediaBlockMapWriter::WriteFramesAt(void* buffer, int64 start, int64 frameCount)
{
    if (start < 0)
        return 0;

    SeekToFrame(start);
    return WriteFrames(buffer, frameCount);
}
Esempio n. 3
0
void EMWaveFileReader::SeekToTime(int64 p_vToTime)
{
	if(! HasFormat())
		ReadFormatE();

	m_opSem -> Acquire();

	if(m_vIsInitialized)
		SeekToFrame(EMMediaUtility::Instance() -> TimeToFrames(p_vToTime, m_opFormat));
	m_vCurrentPosition = EMMediaUtility::Instance() -> TimeToFrames(p_vToTime, m_opFormat);
	
	m_opSem -> Release();
}
Esempio n. 4
0
int64
MediaBlockMapReader::ReadPreview(void** buf, int64 frameCount, int64 start)
{
    // TODO allow to read only a part of the preview.
    int64 totalFrames = fMap->PreviewFrames();
    float* preview = new float[totalFrames];
    memset(preview, 0, StorageUtils::FramesToSize(totalFrames));
    SeekToFrame(0);
    int64 offset = 0;
    for (int32 i = 0; i < fMap->CountBlocks(); i++) {
        MediaBlock* nextBlock = fMap->BlockAt(i);
        int64 blockFrames = nextBlock->PreviewFrames();
        offset += nextBlock->ReadPreview(preview+offset, blockFrames);
    }

    *buf = preview;

    return offset;
}
Esempio n. 5
0
bool EMBeMediaTimer::IncreaseNowFrame(int64 p_vWithFrames)
{
//	status_t vAcquireResult = acquire_sem(m_vTimeProtectionSemaphore);
//	if(vAcquireResult != B_NO_ERROR)
//		EMDebugger("ERROR! EMBeMediaTimer could not acquire semaphore for timer protection!");
	
/*	if(! m_vIsStarted)
		return false;
*/
	if(p_vWithFrames >= 0)
	{
		m_vNow += p_vWithFrames;

		if(m_vIsLooped || EMMediaEngine::Instance() -> GetMediaProject() -> IsRenderingAudio() || EMMediaEngine::Instance() -> GetMediaProject() -> IsRenderingVideo())
		{
			if(m_vLoopStart != m_vLoopEnd)
			{
				if(m_vNow >= m_vLoopEnd && ! EMMediaEngine::Instance() -> GetMediaProject() -> IsRenderingAudio() && ! EMMediaEngine::Instance() -> GetMediaProject() -> IsRenderingVideo())
				{
					m_vNow = m_vLoopStart;
//					release_sem(m_vTimeProtectionSemaphore);
					SeekToFrame(m_vLoopStart);
					return true;
				}
 				else if(EMMediaEngine::Instance() -> GetMediaProject() -> IsPlaying() && m_vNow >= m_vLoopEnd && 
						(EMMediaEngine::Instance() -> GetMediaProject() -> IsRenderingAudio() || 
						EMMediaEngine::Instance() -> GetMediaProject() -> IsRenderingVideo()))
				{
//					EMMediaEngine::Instance() -> GetCommandRepository() -> ExecuteCommand(COMMAND_STOP);
					return false;
				}
			}
		}
	}
	else
		EMDebugger("ERROR in MediaTimer::IncreaseNowFrame. Cannot increase with negative number of frames!");
//	release_sem(m_vTimeProtectionSemaphore);
	return true;
}
Esempio n. 6
0
/*****************************************************************************************
Old code for frame decompression
*****************************************************************************************/
int CUnMAC::DecompressFrameOld(unsigned char *pOutputData, int32 FrameIndex, int CPULoadBalancingFactor) 
{
    // error check the parameters (too high of a frame index, etc.)
    if (FrameIndex >= m_pAPEDecompress->GetInfo(APE_INFO_TOTAL_FRAMES)) { return ERROR_SUCCESS; }

    // get the number of samples in the frame
    int nBlocks = 0;
    nBlocks = ((FrameIndex + 1) >= m_pAPEDecompress->GetInfo(APE_INFO_TOTAL_FRAMES)) ? m_pAPEDecompress->GetInfo(APE_INFO_FINAL_FRAME_BLOCKS) : m_pAPEDecompress->GetInfo(APE_INFO_BLOCKS_PER_FRAME);
    if (nBlocks == 0)
        return -1; // nothing to do (file must be zero length) (have to return error)

    // take care of seeking and frame alignment
    if (SeekToFrame(FrameIndex) != 0) { return -1; }

    // get the checksum
    unsigned int nSpecialCodes = 0;
    uint32 nStoredCRC = 0;
    
    if (GET_USES_CRC(m_pAPEDecompress) == FALSE)
    {
        nStoredCRC = m_pAPEDecompressCore->GetUnBitArrray()->DecodeValue(DECODE_VALUE_METHOD_UNSIGNED_RICE, 30);
        if (nStoredCRC == 0)
        {
            nSpecialCodes = SPECIAL_FRAME_LEFT_SILENCE | SPECIAL_FRAME_RIGHT_SILENCE;
        }            
    }
    else
    {
        nStoredCRC = m_pAPEDecompressCore->GetUnBitArrray()->DecodeValue(DECODE_VALUE_METHOD_UNSIGNED_INT);
        
        // get any 'special' codes if the file uses them (for silence, FALSE stereo, etc.)
        nSpecialCodes = 0;
        if (GET_USES_SPECIAL_FRAMES(m_pAPEDecompress))
        {
            if (nStoredCRC & 0x80000000) 
            {
                nSpecialCodes = m_pAPEDecompressCore->GetUnBitArrray()->DecodeValue(DECODE_VALUE_METHOD_UNSIGNED_INT);
            }
            nStoredCRC &= 0x7FFFFFFF;
        }
    }

    // the CRC that will be figured during decompression
    uint32 CRC = 0xFFFFFFFF;

    // decompress and convert from (x,y) -> (l,r)
    // sort of int and ugly.... sorry
    if (m_pAPEDecompress->GetInfo(APE_INFO_CHANNELS) == 2) 
    {
        m_pAPEDecompressCore->GenerateDecodedArrays(nBlocks, nSpecialCodes, FrameIndex, CPULoadBalancingFactor);

        WAVEFORMATEX WaveFormatEx; m_pAPEDecompress->GetInfo(APE_INFO_WAVEFORMATEX, (long) &WaveFormatEx);
        m_pPrepare->UnprepareOld(m_pAPEDecompressCore->GetDataX(), m_pAPEDecompressCore->GetDataY(), nBlocks, &WaveFormatEx, 
            pOutputData, (unsigned int *) &CRC, (int *) &nSpecialCodes, m_pAPEDecompress->GetInfo(APE_INFO_FILE_VERSION));
    }
    else if (m_pAPEDecompress->GetInfo(APE_INFO_CHANNELS) == 1) 
    {
        m_pAPEDecompressCore->GenerateDecodedArrays(nBlocks, nSpecialCodes, FrameIndex, CPULoadBalancingFactor);
        
        WAVEFORMATEX WaveFormatEx; m_pAPEDecompress->GetInfo(APE_INFO_WAVEFORMATEX, (long) &WaveFormatEx);
        m_pPrepare->UnprepareOld(m_pAPEDecompressCore->GetDataX(), NULL, nBlocks, &WaveFormatEx, 
            pOutputData, (unsigned int *) &CRC, (int *) &nSpecialCodes, m_pAPEDecompress->GetInfo(APE_INFO_FILE_VERSION));
    }

    if (GET_USES_SPECIAL_FRAMES(m_pAPEDecompress))
    {
        CRC >>= 1;
    }

    // check the CRC
    if (GET_USES_CRC(m_pAPEDecompress) == FALSE)
    {
        uint32 nChecksum = CalculateOldChecksum(m_pAPEDecompressCore->GetDataX(), m_pAPEDecompressCore->GetDataY(), m_pAPEDecompress->GetInfo(APE_INFO_CHANNELS), nBlocks);
        if (nChecksum != nStoredCRC)
            return -1;
    }
    else
    {
        if (CRC != nStoredCRC)
            return -1;
    }

    m_LastDecodedFrameIndex = FrameIndex;
    return nBlocks;    
}