tsrc/consoleplayer/player/src/openmax_al/openmaxplayerutility.cpp
changeset 37 36c0918edf90
parent 35 b0f0be18af85
--- a/tsrc/consoleplayer/player/src/openmax_al/openmaxplayerutility.cpp	Fri Sep 17 08:31:33 2010 +0300
+++ b/tsrc/consoleplayer/player/src/openmax_al/openmaxplayerutility.cpp	Mon Oct 04 00:36:08 2010 +0300
@@ -1,5 +1,23 @@
+/*
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ * Source file for the main class of the ConsolePlayer test app.
+ *
+ */
+
 #include <string.h>
-#include <stdlib.h> 
+#include <stdlib.h>
 #include "openmaxplayerutility.h"
 
 #define FILE_EXTN "file:///"
@@ -13,7 +31,7 @@
     COpenMaxPlayerUtility* pSelf = (COpenMaxPlayerUtility*)pContext;
     if(event & XA_PLAYEVENT_HEADMOVING)
     {
-        strcpy(callback_string, "XA_PLAYEVENT_HEADMOVING");    
+        strcpy(callback_string, "XA_PLAYEVENT_HEADMOVING");
     }
     else if(event & XA_PLAYEVENT_HEADATEND)
     {
@@ -23,15 +41,15 @@
     }
     else if(event & XA_PLAYEVENT_HEADATMARKER)
     {
-        strcpy(callback_string, "XA_PLAYEVENT_HEADATMARKER");    
+        strcpy(callback_string, "XA_PLAYEVENT_HEADATMARKER");
     }
     else if(event & XA_PLAYEVENT_HEADATNEWPOS)
     {
-        strcpy(callback_string, "XA_PLAYEVENT_HEADATNEWPOS");    
+        strcpy(callback_string, "XA_PLAYEVENT_HEADATNEWPOS");
     }
     else if(event & XA_PLAYEVENT_HEADSTALLED)
     {
-        strcpy(callback_string, "XA_PLAYEVENT_HEADSTALLED");    
+        strcpy(callback_string, "XA_PLAYEVENT_HEADSTALLED");
     }
     //LOGFILE (callback_string);
 }
@@ -45,10 +63,10 @@
 {
     /* Destroy the player */
     DestroyPlayer ();
-    
+
     /* Destroy Output Mix object */
     (*m_outputMix)->Destroy(m_outputMix);
-    
+
     /* Shutdown OpenMAX AL */
     (*m_engine)->Destroy(m_engine);
 }
@@ -66,15 +84,15 @@
     };
 
     /* Create OpenMAX AL */
-   res = xaCreateEngine(&m_engine, 1, EngineOption, 0, NULL, NULL); 
+   res = xaCreateEngine(&m_engine, 1, EngineOption, 0, NULL, NULL);
    CheckErr(res, "xaCreateEngine");
 
     /* Realizing the XA Engine in synchronous mode. */
-   res = (*m_engine)->Realize(m_engine, XA_BOOLEAN_FALSE); 
+   res = (*m_engine)->Realize(m_engine, XA_BOOLEAN_FALSE);
    CheckErr(res, "Realize(engine)");
 
     /* Get the XA Engine Interface which is implicit */
-   res = (*m_engine)->GetInterface(m_engine, XA_IID_ENGINE, (void**) &m_EngineItf); 
+   res = (*m_engine)->GetInterface(m_engine, XA_IID_ENGINE, (void**) &m_EngineItf);
    CheckErr(res, "GetInterface(engine)");
 
     /* Initialize arrays required[] and iidArray[] */
@@ -91,20 +109,20 @@
     m_iidArray[1] = XA_IID_EQUALIZER;
 
     /* Create Output Mix object to be used by player */
-    res = (*m_EngineItf)->CreateOutputMix(m_EngineItf, &m_outputMix, 2, m_iidArray, m_required); 
+    res = (*m_EngineItf)->CreateOutputMix(m_EngineItf, &m_outputMix, 2, m_iidArray, m_required);
     CheckErr(res, "CreateOutputMix");
 
     /* Realizing the Output Mix object in synchronous mode. */
-    res = (*m_outputMix)->Realize(m_outputMix, XA_BOOLEAN_FALSE); 
+    res = (*m_outputMix)->Realize(m_outputMix, XA_BOOLEAN_FALSE);
     CheckErr(res, "Realize(outputMix)");
 
     /* Get volume and equalizer interfaces */
-    res = (*m_outputMix)->GetInterface(m_outputMix, XA_IID_VOLUME, (void**) &m_volumeItf); 
+    res = (*m_outputMix)->GetInterface(m_outputMix, XA_IID_VOLUME, (void**) &m_volumeItf);
     CheckErr(res, "GetInterface(volume)");
-    res = (*m_outputMix)->GetInterface(m_outputMix, XA_IID_EQUALIZER, (void**) &m_equalizerItf); 
+    res = (*m_outputMix)->GetInterface(m_outputMix, XA_IID_EQUALIZER, (void**) &m_equalizerItf);
     CheckErr(res, "GetInterface(equalizer)");
 
-    // Setup the audio sink structure 
+    // Setup the audio sink structure
     m_locator_outputmix.locatorType = XA_DATALOCATOR_OUTPUTMIX;
     m_locator_outputmix.outputMix = m_outputMix;
     m_audioSink.pLocator = (void*) &m_locator_outputmix;
@@ -116,14 +134,14 @@
     m_required[1] = XA_BOOLEAN_FALSE;
     m_iidArray[1] = XA_IID_NULL;
 
-    // Setup the video sink structure 
-    // Set nativeWindowHandle and nativeDisplayHandle to platform specific values 
+    // Setup the video sink structure
+    // Set nativeWindowHandle and nativeDisplayHandle to platform specific values
     XANativeHandle nativeWindowHandle = NULL;
     XANativeHandle nativeDisplayHandle = NULL;
-    
+
     m_locator_displayregion.locatorType = XA_DATALOCATOR_NATIVEDISPLAY;
     m_locator_displayregion.hDisplay = nativeDisplayHandle;
-    m_locator_displayregion.hWindow = nativeWindowHandle; 
+    m_locator_displayregion.hWindow = nativeWindowHandle;
     m_videoSink.pLocator = (void*) &m_locator_displayregion;
     m_videoSink.pFormat = NULL;
 
@@ -133,8 +151,8 @@
     res = (*m_volumeItf)->GetMaxVolumeLevel (m_volumeItf, &maxVol);
     CheckErr(res, "GetMaxVolumeLevel");
 
-    // before Play, set volume 
-    res = (*m_volumeItf)->SetVolumeLevel(m_volumeItf, minVol); 
+    // before Play, set volume
+    res = (*m_volumeItf)->SetVolumeLevel(m_volumeItf, minVol);
     CheckErr(res, "SetVolumeLevel");
 }
 
@@ -145,14 +163,14 @@
     /* Stop the music */
     res = (*m_playItf)->GetPlayState(m_playItf, &playState);
     CheckErr(res, "GetPlayState");
-    
+
     if ( playState != XA_PLAYSTATE_STOPPED )
         {
-        res = (*m_playItf)->SetPlayState(m_playItf, XA_PLAYSTATE_STOPPED); 
+        res = (*m_playItf)->SetPlayState(m_playItf, XA_PLAYSTATE_STOPPED);
         CheckErr(res, "SetPlayState(stopped)");
         }
-    
-    // Destroy the player caused app to crash 
+
+    // Destroy the player caused app to crash
 //    (*player)->Destroy(player);
     }
 
@@ -169,15 +187,15 @@
     XAmilliHertz maxFreq;
     int band;
     XAresult res;
-    res = (*m_equalizerItf)->GetNumberOfBands(m_equalizerItf, &numBands); 
+    res = (*m_equalizerItf)->GetNumberOfBands(m_equalizerItf, &numBands);
     CheckErr(res, "GetNumberOfBands(equalizerItf)");
-    res = (*m_equalizerItf)->GetBandLevelRange(m_equalizerItf, &minLevel, &maxLevel); 
+    res = (*m_equalizerItf)->GetBandLevelRange(m_equalizerItf, &minLevel, &maxLevel);
     CheckErr(res, "GetBandLevelRange(equalizerItf)");
     for (band = 0; band<numBands; band++)
     {
-        res = (*m_equalizerItf)->GetBandFreqRange(m_equalizerItf, (XAint16) band, &minFreq, &maxFreq); 
+        res = (*m_equalizerItf)->GetBandFreqRange(m_equalizerItf, (XAint16) band, &minFreq, &maxFreq);
         CheckErr(res, "GetBandFreqRange(equalizerItf)");
-        res = (*m_equalizerItf)->GetBandLevel(m_equalizerItf, (XAint16)band, &bandLevel); 
+        res = (*m_equalizerItf)->GetBandLevel(m_equalizerItf, (XAint16)band, &bandLevel);
         CheckErr(res, "GetBandLevel(equalizerItf)");
  //       drawEQBand(minFreq, maxFreq, bandLevel);
     }
@@ -220,7 +238,7 @@
 void COpenMaxPlayerUtility::SetVolume(TInt aVolume)
     {
     m_nVolume = aVolume;
-    XAresult res = (*m_volumeItf)->SetVolumeLevel(m_volumeItf, (XAmillibel)m_nVolume); 
+    XAresult res = (*m_volumeItf)->SetVolumeLevel(m_volumeItf, (XAmillibel)m_nVolume);
     CheckErr(res, "SetVolumeL");
     }
 
@@ -230,36 +248,36 @@
 
 void COpenMaxPlayerUtility::SetPosition(const TTimeIntervalMicroSeconds& /*aPosition*/)
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::SetRotation(const RWindow& /*aWindow*/, TVideoRotation /*aRotation*/)
     {
-    
+
     }
 
-void COpenMaxPlayerUtility::SetScaleFactor(const RWindow& /*aWindow*/, TReal32 /*aWidthPercentage*/, 
+void COpenMaxPlayerUtility::SetScaleFactor(const RWindow& /*aWindow*/, TReal32 /*aWidthPercentage*/,
         TReal32 /*aHeightPercentage*/)
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::SetAutoScale(const RWindow& /*aWindow*/, TAutoScaleType /*aScaleType*/)
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::StepFrame(TInt /*aStep*/)
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::OpenFile(const TDesC& aFileName, TUid /*aControllerUid*/)
     {
     const TUint16 *pFile = aFileName.Ptr();
     TInt len = aFileName.Length();
-    
-    if (pFile) 
+
+    if (pFile)
         {
         strcpy((char*)m_sourceName, FILE_EXTN);
         len = wcstombs((char*)&m_sourceName[FILE_EXTN_LEN], (const wchar_t *)pFile, len);
@@ -268,7 +286,7 @@
         uri.URI = (XAchar*) m_sourceName;
         m_mime.formatType = XA_DATAFORMAT_MIME;
         m_mime.mimeType = (XAchar *) "audio/ra";
-        
+
 		//Do we need this here?
         PlaySource (uri);
         }
@@ -276,30 +294,30 @@
 
 void COpenMaxPlayerUtility::OpenUrl(const TDesC& /*aUrl*/)
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::Prepare()
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::Close()
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::Pause()
     {
     XAresult res;
-    res = (*m_playItf)->SetPlayState(m_playItf, XA_PLAYSTATE_PAUSED); 
+    res = (*m_playItf)->SetPlayState(m_playItf, XA_PLAYSTATE_PAUSED);
     CheckErr(res, "SetPlayState(paused)");
     }
 
 void COpenMaxPlayerUtility::Play()
     {
     XAresult res;
-    res = (*m_playItf)->SetPlayState(m_playItf, XA_PLAYSTATE_PLAYING); 
+    res = (*m_playItf)->SetPlayState(m_playItf, XA_PLAYSTATE_PLAYING);
     CheckErr(res, "SetPlayState(playing)");
     }
 
@@ -317,12 +335,12 @@
 
 void COpenMaxPlayerUtility::SetWindowClipRect(const RWindow& /*aWindow*/, const TRect& /*aWindowClipRect*/)
     {
-    
+
     }
 
 void COpenMaxPlayerUtility::SetVideoExtent(const RWindow& /*aWindow*/, const TRect& /*aVideoExtent*/)
     {
-    
+
     }
 
 /* Checks for error. If any errors exit the application! */
@@ -343,10 +361,10 @@
     XAmillibel maxLevel;
     XAresult res;
 
-    res = (*m_equalizerItf)->GetNumberOfBands(m_equalizerItf, &numBands); 
+    res = (*m_equalizerItf)->GetNumberOfBands(m_equalizerItf, &numBands);
     CheckErr(res, "GetNumberOfBands");
 
-    res = (*m_equalizerItf)->GetBandLevelRange(m_equalizerItf, &minLevel, &maxLevel); 
+    res = (*m_equalizerItf)->GetBandLevelRange(m_equalizerItf, &minLevel, &maxLevel);
     CheckErr(res, "GetBandLevelRange");
     if (band >= numBands)
     {
@@ -354,7 +372,7 @@
         exit(0);
     }
 
-    res = (*m_equalizerItf)->GetBandLevel(m_equalizerItf, band, &bandLevel); 
+    res = (*m_equalizerItf)->GetBandLevel(m_equalizerItf, band, &bandLevel);
     CheckErr(res, "GetBandLevel");
 
     if (increase==XA_BOOLEAN_TRUE)
@@ -364,7 +382,7 @@
         bandLevel = bandLevel + 100;
         if(bandLevel < maxLevel)
         {
-            res = (*m_equalizerItf)->SetBandLevel(m_equalizerItf, band, bandLevel); 
+            res = (*m_equalizerItf)->SetBandLevel(m_equalizerItf, band, bandLevel);
             CheckErr(res);
             DrawEQDisplay();
         }
@@ -376,7 +394,7 @@
         bandLevel = bandLevel - 100;
         if( bandLevel > minLevel )
         {
-            res = (*m_equalizerItf)->SetBandLevel(m_equalizerItf, band, bandLevel); 
+            res = (*m_equalizerItf)->SetBandLevel(m_equalizerItf, band, bandLevel);
             CheckErr(res);
             DrawEQDisplay();
         }
@@ -390,38 +408,38 @@
 
     // Create the music player //
     XAresult res;
-    res = (*m_EngineItf)->CreateMediaPlayer ( m_EngineItf, &player, &m_dataSource, NULL, &m_audioSink, 
-            &m_videoSink, NULL, NULL, 1, m_iidArray, m_required); 
+    res = (*m_EngineItf)->CreateMediaPlayer ( m_EngineItf, &player, &m_dataSource, NULL, &m_audioSink,
+            &m_videoSink, NULL, NULL, 1, m_iidArray, m_required);
     CheckErr(res, "CreateMediaPlayer");
-    
-    // Realizing the player in synchronous mode. 
-    res = (*player)->Realize(player, XA_BOOLEAN_FALSE); 
+
+    // Realizing the player in synchronous mode.
+    res = (*player)->Realize(player, XA_BOOLEAN_FALSE);
     CheckErr(res, "Realize(player)");
 
-    // Get the play interface 
-    res = (*player)->GetInterface(player, XA_IID_PLAY, (void**) &m_playItf); 
+    // Get the play interface
+    res = (*player)->GetInterface(player, XA_IID_PLAY, (void**) &m_playItf);
     CheckErr(res, "GetInterface(player)");
 
 /*    XADynamicSourceItf sourceItf;
-    res = (*player)->GetInterface(player, XA_IID_DYNAMICSOURCE, (void**) &sourceItf); 
+    res = (*player)->GetInterface(player, XA_IID_DYNAMICSOURCE, (void**) &sourceItf);
     CheckErr(res, "GetDynamicSource");
 
     res = (*sourceItf)->SetSource (sourceItf, &m_dataSource);
     CheckErr(res, "SetSource");
 */
-    // before Play, set volume 
-    res = (*m_volumeItf)->SetVolumeLevel(m_volumeItf, m_nVolume); 
+    // before Play, set volume
+    res = (*m_volumeItf)->SetVolumeLevel(m_volumeItf, m_nVolume);
     CheckErr(res, "SetVolumeLevel");
 
     XAmillisecond playDuration = 0;
-    res = (*m_playItf)->GetDuration(m_playItf, &playDuration); 
+    res = (*m_playItf)->GetDuration(m_playItf, &playDuration);
     bool b = CheckErr(res, "GetDuration");
     //if ( b && (playDuration != XA_DURATION_UNKNOWN) )
         //SetDurationL ((playDuration/1000));
 
-    res = (*m_playItf)->SetCallbackEventsMask(m_playItf, XA_PLAYEVENT_HEADATEND | XA_PLAYEVENT_HEADMOVING); 
+    res = (*m_playItf)->SetCallbackEventsMask(m_playItf, XA_PLAYEVENT_HEADATEND | XA_PLAYEVENT_HEADMOVING);
     CheckErr(res, "SetCallbackEventsMask");
-    
+
     res = (*m_playItf)->RegisterCallback(m_playItf, PlayCallbackFun, this);
     CheckErr(res, "RegisterCallback");
 	//Do we need this here?
@@ -442,7 +460,7 @@
 
 void COpenMaxPlayerUtility::MuteChanged(bool bChecked)
     {
-    XAresult res = (*m_volumeItf)->SetMute(m_volumeItf, (XAboolean)bChecked); 
+    XAresult res = (*m_volumeItf)->SetMute(m_volumeItf, (XAboolean)bChecked);
     CheckErr(res, "MuteChanged");
     }