⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oggplaycontroller.cpp

📁 OggPlay for Symbian 是symbian上的一个媒体播放程序的源码。它支持ogg,wav等等多媒体格式。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        iDecoder->Clear();
		iFile->Close();

		delete iFile;
		iFile = NULL;

		iState= EStateNotOpened;
        User::Leave(KOggPlayPluginErrOpeningFile);
    }
        
    // Parse tag information and put it in the provided buffers.
    iDecoder->ParseTags(iTitle, iArtist, iAlbum, iGenre, iTrackNumber);

	// Save the audio properties
	iRate = iDecoder->Rate();
	iChannels = iDecoder->Channels();
	iBitRate = iDecoder->Bitrate();

    // Change the title, to let know the client that we have a random ringing tone
    if (iRandomRingingTone)
    {
        iTitle = KRandomRingingToneTitle;
    }

    TRACEF(COggLog::VA(_L("Tags: %S %S %S %S"), &iTitle, &iArtist, &iAlbum, &iGenre ));
    if (!aOpenForInfo)
		{
        iFileLength = iDecoder->TimeTotal() * 1000;
		iFileSize = iDecoder->FileSize();
		}
} 

void COggPlayController::MapdSetVolumeRampL(const TTimeIntervalMicroSeconds& aRampDuration)
{
    PRINT("COggPlayController::MapdSetVolumeRampL");
    if (!iAudioOutput) User::Leave(KErrNotReady);

	iAudioOutput->SoundDevice().SetVolumeRamp(aRampDuration);
}

void COggPlayController::MapdSetBalanceL(TInt aBalance)
{
    PRINT("COggPlayController::MapdSetBalanceL");
    if (!iAudioOutput) User::Leave(KErrNotReady);

    if (aBalance < KMMFBalanceMaxLeft)
		aBalance = KMMFBalanceMaxLeft;

	if (aBalance > KMMFBalanceMaxRight)
		aBalance = KMMFBalanceMaxRight;
	
	TInt balanceRange = KMMFBalanceMaxRight-KMMFBalanceMaxLeft;
	TInt leftBalance = (100*(KMMFBalanceMaxRight - aBalance))/balanceRange;
    iAudioOutput->SoundDevice().SetPlayBalanceL(leftBalance, 100-leftBalance);
}

void COggPlayController::MapdGetBalanceL(TInt& aBalance)
{
    PRINT("COggPlayController::MapdGetBalanceL");
    if (!iAudioOutput) User::Leave(KErrNotReady);

	// Initialise values to KMMFBalanceCenter
	TInt leftBalance = 50;
	TInt rightBalance = 50;

	// Read the balance from devsound
    iAudioOutput->SoundDevice().GetPlayBalanceL(leftBalance, rightBalance);

	// Calculate the balance, assuming that leftBalance+rightBalance = 100
	TInt balanceRange = KMMFBalanceMaxRight-KMMFBalanceMaxLeft;
	aBalance = KMMFBalanceMaxLeft + (balanceRange*rightBalance)/100;
}

void COggPlayController::MapdSetVolumeL(TInt aVolume)
{
    TRACEF(COggLog::VA(_L("COggPlayController::SetVolumeL %i"), aVolume ));
    if (!iAudioOutput) User::Leave(KErrNotReady);
    
    TInt maxVolume = iAudioOutput->SoundDevice().MaxVolume();
	if( ( aVolume < 0 ) || ( aVolume > maxVolume ))
	    User::Leave(KErrArgument);
    
    iAudioOutput->SoundDevice().SetVolume(aVolume);
}

void COggPlayController::MapdGetMaxVolumeL(TInt& aMaxVolume)
{
    PRINT("COggPlayController::MapdGetMaxVolumeL");
    if (!iAudioOutput) User::Leave(KErrNotReady);
    
    aMaxVolume = iAudioOutput->SoundDevice().MaxVolume();
}

void COggPlayController::MapdGetVolumeL(TInt& aVolume)
{
    PRINT("COggPlayController::MapdGetVolumeL");
    if (!iAudioOutput) User::Leave(KErrNotReady);
    
	aVolume = iAudioOutput->SoundDevice().Volume();
}

void COggPlayController::MapcSetPlaybackWindowL(const TTimeIntervalMicroSeconds& /*aStart*/,
                            const TTimeIntervalMicroSeconds& /*aEnd*/)
{
    PRINT("COggPlayController::MapcSetPlaybackWindowL");

    // No implementation
    User::Leave(KErrNotSupported);
}

void COggPlayController::MapcDeletePlaybackWindowL()
{   
    PRINT("COggPlayController::MapcDeletePlaybackWindowL");
 
    // No implementation
    User::Leave(KErrNotSupported);
}

void COggPlayController::MapcGetLoadingProgressL(TInt& /*aPercentageComplete*/)
{    
    PRINT("COggPlayController::MapcGetLoadingProgressL");
 
    // No implementation
    User::Leave(KErrNotSupported);
}

TInt COggPlayController::GetNewSamples(TDes8 &aBuffer, TBool aRequestFrequencyBins) 
{
    if (iState != EStatePlaying)
        return 0;

	if (aRequestFrequencyBins && !iRequestingFrequencyBins)
	{
		// Make a request for frequency data
		iDecoder->GetFrequencyBins(iFreqArray[iLastFreqArrayIdx].iFreqCoefs, KNumberOfFreqBins);

		// Mark that we have issued the request
		iRequestingFrequencyBins = ETrue;
	}

	TInt len = aBuffer.Length();
    TInt ret=iDecoder->Read(aBuffer, len);
    if (ret >0)
    {
        aBuffer.SetLength(len + ret);

		if (iRequestingFrequencyBins)
		{
			// Determine the status of the request
			TInt requestingFrequencyBins = iDecoder->RequestingFrequencyBins();
			if (!requestingFrequencyBins)
			{
				iLastFreqArrayIdx++;
				if (iLastFreqArrayIdx >= KFreqArrayLength)
					iLastFreqArrayIdx = 0;

				// The frequency request has completed
				iFreqArray[iLastFreqArrayIdx].iTime = iOggSource->iTotalBufferBytes;
				iRequestingFrequencyBins = EFalse;
			}
		}
	}

	if (ret == 0)
    {
        iState = EStateOpen;
        return KErrCompletion;
    }

	return ret;
}

void  COggPlayController::GetFrequenciesL(TMMFMessage& aMessage )
{
   	// Get the size of the init data and create a buffer to hold it
    TInt desLength = aMessage.SizeOfData1FromClient();
    HBufC8* buf = HBufC8::NewLC(desLength);
    TPtr8 ptr = buf->Des();
    aMessage.ReadData1FromClientL(ptr);
    
    TMMFGetFreqsParams params;
    TPckgC<TMMFGetFreqsParams> config(params);
    config.Set(*buf);
    params = config();

	TInt64 positionBytes = 2*iUsedChannels*iAudioOutput->SoundDevice().SamplesPlayed();
	TInt idx = iLastFreqArrayIdx;
	for (TInt i=0; i<KFreqArrayLength; i++)
    {
		if (iFreqArray[idx].iTime <= positionBytes)
			break;
      
		idx--;
		if (idx < 0)
			idx = KFreqArrayLength-1;
    }

	TPckg<TInt32[16]> binsPckg(iFreqArray[idx].iFreqCoefs);
    aMessage.WriteDataToClient(binsPckg);

    CleanupStack::PopAndDestroy(buf);
}

void  COggPlayController::SetVolumeGainL(TMMFMessage& aMessage)
{
   	// Get the size of the init data and create a buffer to hold it
    TInt desLength = aMessage.SizeOfData1FromClient();
    HBufC8* buf = HBufC8::NewLC(desLength);
    TPtr8 ptr = buf->Des();
    aMessage.ReadData1FromClientL(ptr);
    
    TMMFSetVolumeGainParams params;
    TPckgC<TMMFSetVolumeGainParams> config(params);
    config.Set(*buf);
    params = config();
    
	iOggSource->SetVolumeGain((TGainType) params.iGain);
    CleanupStack::PopAndDestroy(buf);//buf
}

void COggPlayController::MaoscOpenComplete(TInt aError)
{
	if (iStreamState == EStreamStateRequested)
	{
		iStreamMessage->Complete(aError);

		delete iStreamMessage;
		iStreamMessage = NULL;
	}

	iStreamState = EStreamOpened;
	iStreamError = aError;

	if (iPlayRequestPending && (iStreamError == KErrNone))
	{
		// Start playing now (ignore error)
		TRAPD(err, 	{ SetAudioCapsL(iDecoder->Rate(), iDecoder->Channels()); PlayNowL(); });
	}

	iPlayRequestPending = EFalse;
}

void COggPlayController::MaoscBufferCopied(TInt /* aError */, const TDesC8& /* aBuffer */)
{
}

void COggPlayController::MaoscPlayComplete(TInt /* aError */)
{
}

// COggSource
COggSource::COggSource(MOggSampleRateFillBuffer &aSampleRateFillBuffer)
: MDataSource(TUid::Uid(KOggTremorUidPlayFormatImplementation)), iSampleRateFillBuffer(aSampleRateFillBuffer), iGain(ENoGain)
{
}

COggSource::~COggSource()
{
    delete iOggSampleRateConverter;
}

void COggSource::ConstructL(TInt aBufferSize, TInt aInputRate, TInt aOutputRate, TInt aInputChannel, TInt aOutputChannel)
{
    // We use the Sample Rate converter only for the buffer filling and the gain settings,
    // sample rate conversion is done by MMF.
    PRINT("COggSource::ConstructL()");
    iOggSampleRateConverter = new(ELeave) COggSampleRateConverter;
    
    iOggSampleRateConverter->Init(&iSampleRateFillBuffer, aBufferSize, aBufferSize-1024,
	aInputRate,  aOutputRate, aInputChannel, aOutputChannel);

	iOggSampleRateConverter->SetVolumeGain(iGain);
    PRINT("COggSource::ConstructL() Out");
}

void COggSource::SetVolumeGain(TGainType aGain)
{
	iGain = aGain;
	if (iOggSampleRateConverter)
		iOggSampleRateConverter->SetVolumeGain(aGain);
}

void COggSource::SetSink(MDataSink* aSink)
    {
    iSink=aSink;
    }

void COggSource::ConstructSourceL(  const TDesC8& /*aInitData*/ )
    {
    }

CMMFBuffer* COggSource::CreateSourceBufferL(TMediaId /*aMediaId*/, TBool &aReference)
    {
    aReference = EFalse;
    return NULL;
    }

TBool COggSource::CanCreateSourceBuffer()
    {
    return EFalse;
    }

TFourCC COggSource::SourceDataTypeCode(TMediaId aMediaId)
    {
    if (aMediaId.iMediaType==KUidMediaTypeAudio)
        {
		// only support 1st stream for now
        return 1;
        }
    else
		return 0;
    }

void COggSource::FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer,TMediaId aMediaId)
    {   
    if ((aMediaId.iMediaType==KUidMediaTypeAudio)&&(aBuffer->Type()==KUidMmfDescriptorBuffer))
    {
        //BufferEmptiedL(aBuffer);
        CMMFDataBuffer* db = static_cast<CMMFDataBuffer*>(aBuffer);
        if (iOggSampleRateConverter->FillBuffer(db->Data()) == KErrCompletion)
        {
            PRINT("COggSource::FillBufferL LastBuffer");
            db->SetLastBuffer(ETrue);
        }
		iTotalBufferBytes += db->Data().Length();

		SetSink(aConsumer);
        aConsumer->BufferFilledL(db);
    }
    else
		User::Leave(KErrNotSupported);
    }


void COggSource::BufferEmptiedL(CMMFBuffer* aBuffer)
{
    if ( (aBuffer->Type()==KUidMmfDescriptorBuffer) || (aBuffer->Type()==KUidMmfTransferBuffer) || (aBuffer->Type()==KUidMmfPtrBuffer))
    {    
        CMMFDataBuffer* db = static_cast<CMMFDataBuffer*>(aBuffer);
        if (iOggSampleRateConverter->FillBuffer(db->Data()) == KErrCompletion)
        {
            PRINT("COggSource::BufferEmptiedL Last Buffer");
            db->SetLastBuffer(ETrue);
        }

		iTotalBufferBytes += db->Data().Length();
        iSink->EmptyBufferL(db, this, TMediaId(KUidMediaTypeAudio));
    }
    else
		User::Leave(KErrNotSupported);
}


// CFakeFormatDecode
CFakeFormatDecode* CFakeFormatDecode::NewL(TFourCC aFourCC, TUint aChannels, TUint aSampleRate, TUint aBitRate)
	{
	CFakeFormatDecode* self = new(ELeave) CFakeFormatDecode;
	self->iFourCC = aFourCC;
	self->iChannels = aChannels;
	self->iSampleRate = aSampleRate;
	self->iBitRate = aBitRate;
	return self;
	}

CFakeFormatDecode::CFakeFormatDecode()
	{
	}
    
CFakeFormatDecode::~CFakeFormatDecode()
	{
	}
    
TUint CFakeFormatDecode::Streams(TUid /*aMediaType*/) const
	{
	User::Panic(KFakeFormatDecodePanic, 1);
	return 0;
	}
		
TTimeIntervalMicroSeconds CFakeFormatDecode::FrameTimeInterval(TMediaId /*aMediaType*/) const
	{
	User::Panic(KFakeFormatDecodePanic, 2);
	return TTimeIntervalMicroSeconds(0);
	}
	
TTimeIntervalMicroSeconds CFakeFormatDecode::Duration(TMediaId /*aMediaType*/) const
	{
	User::Panic(KFakeFormatDecodePanic, 3);
	return TTimeIntervalMicroSeconds(0);
	}
		
void CFakeFormatDecode::FillBufferL(CMMFBuffer* /*aBuffer*/, MDataSink* /*aConsumer*/, TMediaId /*aMediaId*/)
	{
	User::Panic(KFakeFormatDecodePanic, 4);
	}
	
CMMFBuffer* CFakeFormatDecode::CreateSourceBufferL(TMediaId /*aMediaId*/, TBool& /*aReference*/)
	{
	User::Panic(KFakeFormatDecodePanic, 4);
	return NULL;
	}
	
TFourCC CFakeFormatDecode::SourceDataTypeCode(TMediaId /*aMediaId*/)
	{
	return iFourCC;
	}
	
TUint CFakeFormatDecode::NumChannels()
	{
	return iChannels;
	}
	
TUint CFakeFormatDecode::SampleRate()
	{
	return iSampleRate;
	}
		
TUint CFakeFormatDecode::BitRate()
	{
	return iBitRate;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -