📄 oggpluginadaptor.cpp
字号:
iVolume = aVol;
if (iPlayer)
{
TInt max = iPlayer->MaxVolume();
TReal relative = ((TReal) aVol)/KMaxVolume;
TInt vol = (TInt) (relative*max);
iPlayer->SetVolume(vol);
}
}
void COggPluginAdaptor::SetPosition(TInt64 aPos)
{
TRACEF(COggLog::VA(_L("COggPluginAdaptor::SetPosition %i"), aPos ));
if (iPlayer)
{
// Do not change the position if it is bigger than the lenght of the tune,
// it would otherwise wrap the tune to the beginning.
if (aPos*1000 < iPlayer->Duration().Int64() )
{
iPlayer->Stop(); // Must pause before changing position. Some MMF Plugins panics otherwise.
iPlayer->SetPosition(aPos * 1000);
iPlayer->PlayL();
}
}
}
TInt64 COggPluginAdaptor::Position()
{
TTimeIntervalMicroSeconds aPos(0);
if (iState == EPaused)
aPos = iLastPosition;
else if (iPlayer)
{
aPos = iPlayer->Position();
}
if (aPos != TTimeIntervalMicroSeconds(0))
iLastPosition = aPos;
return(aPos.Int64()/1000); // Dividing by 1000, to get millisecs from microsecs
}
TInt64 COggPluginAdaptor::Time()
{
if (iPlayer)
return (iPlayer->Duration().Int64()/1000);
return(0);
}
TInt COggPluginAdaptor::Volume()
{
// Not Implemented yet
return 0;
}
const TInt32* COggPluginAdaptor::GetFrequencyBins()
{
if (iPluginControllerUID.iUid != KOggTremorUidControllerImplementation)
return iFreqBins;
TMMFGetFreqsParams pckg;
pckg.iFreqBins = iFreqBins;
TMMFGetFreqsConfig freqConfig(pckg); // Pack the config.
TPckg <TInt32 [16]> dataFrom(iFreqBins);
TMMFMessageDestination msg(iPluginControllerUID, KMMFObjectHandleController);
TPckgBuf<TMMFMessageDestination> packedMsg(msg); // Pack the destination
TInt err = iPlayer->PlayControllerCustomCommandSync(packedMsg,
EOggPlayControllerCCGetFrequencies, freqConfig, KNullDesC8, dataFrom);
if (err != KErrNone)
{
TRACEF(COggLog::VA(_L("COggPluginAdaptor::GetFrequencyBins %i"), err));
}
return iFreqBins;
}
void COggPluginAdaptor::SetVolumeGain(TGainType aGain)
{
TMMFSetVolumeGainParams pckg;
pckg.iGain = (TInt) aGain;
TMMFSetVolumeGainConfig gainConfig(pckg); // Pack the config.
TInt dummy;
TPckg <TInt> dataFrom(dummy);
TMMFMessageDestination msg(iPluginControllerUID, KMMFObjectHandleController);
TPckgBuf<TMMFMessageDestination> packedMsg(msg); // Pack the destination
TInt err = KErrNone;
iGain = aGain;
if (iPlayer && (iPluginControllerUID.iUid == KOggTremorUidControllerImplementation))
err = iPlayer->PlayControllerCustomCommandSync(packedMsg, EOggPlayControllerCCSetVolumeGain, gainConfig, KNullDesC8, dataFrom);
if (err != KErrNone)
{
TRACEF(COggLog::VA(_L("COggPluginAdaptor::SetVolumeGain %i"), err));
}
}
void COggPluginAdaptor::GetAudioProperties()
{
if (iPluginControllerUID.iUid != KOggTremorUidControllerImplementation)
return;
TInt audioData[4];
TPckg<TInt [4]> dataFrom(audioData);
TMMFMessageDestination msg(iPluginControllerUID, KMMFObjectHandleController);
TPckgBuf<TMMFMessageDestination> packedMsg(msg); // Pack the destination
TInt err = iPlayer->PlayControllerCustomCommandSync(packedMsg,
EOggPlayControllerCCGetAudioProperties, KNullDesC8, KNullDesC8, dataFrom);
if (err == KErrNone)
{
iRate = audioData[0];
iChannels = audioData[1];
iBitRate = audioData[2];
iFileSize = audioData[3];
}
else
{
TRACEF(COggLog::VA(_L("COggPluginAdaptor::GetAudioProperties %i"), err));
}
}
void COggPluginAdaptor::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
{
TRACEF(COggLog::VA(_L("MoscoStateChange :%d %d %d "), aPreviousState, aCurrentState, aErrorCode));
#ifdef MMF_AVAILABLE
if (iWait.IsStarted())
{
// We should be in wait state only when opening a file.
// From not opened to opened
TRACEF(COggLog::VA(_L("MoscoStateChange : InitComplete %d"), aErrorCode ));
iError = aErrorCode;
if (iError == KErrNone)
{
if (iPluginControllerUID.iUid == KOggTremorUidControllerImplementation)
{
// Wait until the controller has opened the audio output stream
TMMFMessageDestination msg(iPluginControllerUID, KMMFObjectHandleController);
TPckgBuf<TMMFMessageDestination> packedMsg(msg); // Pack the destination
iError = iPlayer->PlayControllerCustomCommandSync(packedMsg, EOggPlayControllerStreamWait, KNullDesC8, KNullDesC8);
}
}
iWait.AsyncStop(); // Gives back the control to the waiting OpenL()
}
#else
if ((aPreviousState == CMdaAudioClipUtility::ENotReady)
&& (aCurrentState == CMdaAudioClipUtility::EOpen))
{
// From not opened to opened
TRACEF(COggLog::VA(_L("MoscoStateChange : InitComplete %d"), aErrorCode ));
iError = aErrorCode;
}
#endif
if (aCurrentState == CMdaAudioClipUtility::EPlaying)
{
if (aErrorCode == KErrNone)
{
// Update the audio properties (get the file size)
GetAudioProperties();
}
else
{
// From opened to Playing
// The sound device was stolen by somebody else. (A SMS arrival notice, for example).
iInterrupted = ETrue;
iObserver->NotifyPlayInterrupted();
}
}
if ((aPreviousState == CMdaAudioClipUtility::EPlaying)
&& (aCurrentState == CMdaAudioClipUtility::EOpen))
{
// From Playing to stopped playing
TRACEF(COggLog::VA(_L("MoscoStateChange : PlayComplete %d"), aErrorCode ));
switch (aErrorCode)
{
case KErrDied :
// The sound device was stolen by somebody else. (A SMS arrival notice, for example).
iInterrupted = ETrue;
iObserver->NotifyPlayInterrupted();
break;
case KErrUnderflow:
iState = EStopped;
break;
default:
iObserver->NotifyPlayComplete();
break;
}
}
}
void COggPluginAdaptor::ConstructL()
{
iPluginSupportedList.ConstructL();
// iPluginInfos will be updated, if required plugin has been found
SearchPluginsL(_L("ogg"), ETrue);
SearchPluginsL(_L("mp3"), ETrue);
SearchPluginsL(_L("aac"), ETrue);
SearchPluginsL(_L("mp4"), ETrue);
SearchPluginsL(_L("m4a"), ETrue);
#if defined(SERIES60V3)
SearchPluginsL(_L("wma"), ETrue);
#endif
SearchPluginsL(_L("mid"), EFalse); // Disabled by default
SearchPluginsL(_L("amr"), EFalse); // Disabled by default
}
CPluginSupportedList & COggPluginAdaptor::GetPluginListL()
{
return iPluginSupportedList;
}
#ifdef MMF_AVAILABLE
// Interface using the MMF
COggPluginAdaptor::~COggPluginAdaptor()
{
delete iPlayer;
}
void COggPluginAdaptor::ConstructAPlayerL(const TDesC & /*anExtension*/)
{
// Stupid, but true, we must delete the player when loading a new file
// Otherwise, will panic with -15 on some HW
delete iPlayer;
iPlayer = NULL;
iState = EClosed;
iPlayer = CMdaAudioRecorderUtility::NewL(*this);
}
void COggPluginAdaptor::SearchPluginsL(const TDesC &anExtension, TBool isEnabled)
{
iPluginSupportedList.AddExtension(anExtension); // Add this extension to the selected list
CMMFControllerPluginSelectionParameters * cSelect = CMMFControllerPluginSelectionParameters::NewLC();
CMMFFormatSelectionParameters * fSelect = CMMFFormatSelectionParameters::NewLC();
fSelect->SetMatchToFileNameL(anExtension);
cSelect->SetRequiredPlayFormatSupportL(*fSelect);
RMMFControllerImplInfoArray controllers;
CleanupResetAndDestroyPushL(controllers);
cSelect->ListImplementationsL(controllers);
TInt nbFound = 0;
for (TInt ii=0; ii< controllers.Count(); ii++)
{
// Found at least one controller !
const RMMFFormatImplInfoArray& formatArray = controllers[ii]->PlayFormats();
TBuf8 <10> anEx8;
anEx8.Copy(anExtension); // Convert the 16 bit descriptor to 8 bits
TInt found = EFalse;
TInt i;
for (i=0; i<formatArray.Count(); i++)
{
const CDesC8Array &extensions = formatArray[i]->SupportedFileExtensions();
for (TInt j=0; j<extensions.Count(); j++)
{
if (extensions[j].FindF(anEx8) != KErrNotFound)
{
found = ETrue;
break;
}
}
if (found)
break;
}
__ASSERT_ALWAYS ( found, User::Panic(_L("Extension not found"), 999) );
TRACEF(COggLog::VA(_L(".%S Plugin Found:%S %S %i %x"), &anExtension,
&formatArray[i]->DisplayName(),
&formatArray[i]->Supplier(),
formatArray[i]->Version(),
controllers[ii]->Uid()
));
nbFound++;
iPluginSupportedList.AddPluginL(anExtension,
*formatArray[i],
controllers[ii]->Uid() );
if (isEnabled)
{
// This will be overruled by the .ini file, if the file exist.
iPluginSupportedList.SelectPluginL(anExtension,controllers[ii]->Uid() );
}
}
CleanupStack::PopAndDestroy(3); /* cSelect, fSelect, controllers */
}
#else
// Interface when MMF is not available
COggPluginAdaptor::~COggPluginAdaptor()
{
delete (iOggPlayer);
delete (iMp3Player);
// Finished with the DLLs
//
iOggLibrary.Close();
iMp3Library.Close();
iPluginInfos->ResetAndDestroy();
delete (iPluginInfos);
}
void COggPluginAdaptor::SearchPluginsL(const TDesC &anExtension)
{
CPluginInfo* info = NULL;
const TUid KOggPlayDecoderLibraryUid={0x101FD21D};
if (anExtension == _L("ogg"))
{
if (iOggPlayer == NULL)
{
TUidType uidType(KDynamicLibraryUid,KOggPlayDecoderLibraryUid);
TBool found = (iOggLibrary.Load(_L("OGGPLUGINDECODERPREMMF.DLL"), uidType) == KErrNone) ;
if (found)
{
// Function at ordinal 1 creates new C
TLibraryFunction entry=iOggLibrary.Lookup(1);
// Call the function to create new CMessenger
iOggPlayer = (CPseudoMMFController*) entry();
iOggPlayer->SetObserver(*this);
info = CPluginInfo::NewL(
anExtension,
_L("OGG tremor decoder"),
_L("OggPlay Team"),
1);
}
}
}
if (anExtension == _L("mp3"))
{
if (iMp3Player == NULL)
{
TUidType uidType(KDynamicLibraryUid,KOggPlayDecoderLibraryUid);
TBool found = (iMp3Library.Load(_L("MADPLUGINDECODERPREMMF.DLL"), uidType) == KErrNone) ;
if (found)
{
// Function at ordinal 1 creates new C
TLibraryFunction entry=iMp3Library.Lookup(1);
// Call the function to create new CMessenger
iMp3Player = (CPseudoMMFController*) entry();
iMp3Player->SetObserver(*this);
info = CPluginInfo::NewL(
anExtension,
_L("MP3 Mad decoder"),
_L("?"),
1);
}
}
}
if (info)
iPluginInfos->AppendL(info);
}
void COggPluginAdaptor::ConstructAPlayerL(const TDesC &anExtension)
{
// Load the plugin.
TParsePtrC p( anExtension);
TPtrC pp (p.Ext().Mid(1)); // Remove the . in front of the extension
if ( pp.CompareF( _L("ogg") ) == 0 )
{
// an Ogg File
iPlayer = iOggPlayer;
}
if ( pp.CompareF( _L("mp3") ) == 0 )
{
// an Ogg File
iPlayer = iMp3Player;
}
__ASSERT_ALWAYS(iPlayer, User::Panic(_L("Couldn't construct a Player"), 999) );
}
#endif
#endif /* PLUGIN_SYSTEM */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -