chxavsettingsdata.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 509 行

CPP
509
字号
/************************************************************************
 * chxavsettingsdata.cpp
 * ---------------------
 *
 * Synopsis:
 * Data values associated with settings lists.
 *
 * Target:
 * Symbian OS
 *
 *
 * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
 *
 ************************************************************************/

// Symbian includes...
#include <akntextsettingpage.h>

// Includes from this project...
#include "chxavmisc.h"
#include "chxavsettingslist.h"
#include "chxavsettingsview.h"
#include "chxavconfignames.h"
#include "chxavfileutil.h"
#include "hxapihelp.h"
#include "hxsym_debug.h"
#include "chxavaccesspointsettingsitem.h"
#include "realplayer.hrh"
#include "chxavstringutils.h"


namespace
{

const TUint MS_PER_SEC = 1000;
const TUint BYTES_PER_KB = 1024;

const TInt k_minUdpPortLimit = 6970;
const TInt k_maxUdpPortLimit = 32000;//KMaxTUint16;

static const TInt g_bwVals[] = 
{
    9050,
    13400,
    18100,
    26800,
    27150,
    40200
};

static const TInt g_clipIntroVals[] =
{
    0, 5, 10, 20, 30, 45, 60
};

// ensure that 'lower <= val <= upper' is true for val
template< typename T>
inline
void ConstrainWithinBounds(T lower, T& val, T upper)
{
    HX_ASSERT(lower <= upper);
    val = min(upper, max(lower, val));
}

inline
TInt ConvertBwToIndex(TInt val)
{
    return CHXAvUtil::GetThresholdIndex(val, g_bwVals, ARRAY_COUNT(g_bwVals));
}

inline
TInt ConvertClipIntroTimeToIndex(TInt val)
{
    return CHXAvUtil::GetThresholdIndex(val, g_clipIntroVals, ARRAY_COUNT(g_clipIntroVals));
}

void EnableZeroLength(CAknSettingItem* pItem)
{
    TInt flags = pItem->SettingPageFlags();
    pItem->SetSettingPageFlags( flags | CAknTextSettingPage::EZeroLengthAllowed);
}


} // locals


CHXAvSettingsData::CHXAvSettingsData(IHXCommonClassFactory* pFactory, IHXPreferences* pPrefs)
{
    HX_ASSERT(pPrefs);
    HX_ASSERT(pFactory);
    m_prefs = pPrefs;
    m_factory = pFactory;
}


/*
 * UpdatePrefInt
 * -------------
 * Return if has value has changed or if id is not already found.
 *
 */
bool 
CHXAvSettingsData::UpdatePrefInt(const CHXString& id, TInt newVal)
{
    HX_ASSERT(m_prefs);
   
    INT32 oldVal;
    // only write if value is new or is different from what is there
    bool bFound = prefs::LookupINT32(m_prefs, id, oldVal);
    if (!bFound || (oldVal != newVal))
    {
        prefs::Write(m_factory, m_prefs, id, newVal);
        return true;
    }

    return false;
}


void CHXAvSettingsData::SetTextValue(const CHXString& id, TDes& buffer)
{
    CHXString strValue = prefs::GetString(m_prefs, id);
    CHXAvStringUtils::StringToDes(strValue, buffer);
}


/*
 * UpdatePrefString
 * ----------------
 * Return if has value has changed or if id is not already found.
 *
 */
bool 
CHXAvSettingsData::UpdatePrefString(const CHXString& id, const TDes& newVal)
{
    CHXString strNew;
    CHXAvStringUtils::DesToString(newVal, strNew);
    return UpdatePrefString(id, strNew); 
}
bool 
CHXAvSettingsData::UpdatePrefString(const CHXString& id, const CHXString& strNew)
{
    HX_ASSERT(m_prefs);
    CHXString strOld;
    bool bFound = prefs::LookupString(m_prefs, id, strOld);
    
    // only write if value is new or is different from what is there
    if (!bFound || (strOld != strNew) )
    {
        prefs::Write(m_factory, m_prefs, id, strNew);  
        return true;
    }

    return false;
}




////////////////////////////////////////////////////
//
void CHXAvSettingsDataVideo::InitValuesFromPreferencesL()
{
/*
    There is a Quality preference used in the RV, MPEG4, and RA renderers.

    Here is the meaning for RV renderer:
    quality >= 4 - FRU and Post Filter
    quality >= 3 - Deblocking of B-Frames
    quality >= 2 - Full decoding of B-frames
    quality >= 1 - Decode B-Frames.


    Here is the meaning for MPEG 4 renderer:
    quality >= 2 - Postfilter
    FRU and B-Frames appear to always be off
*/
    m_bAutoScaleVideo = prefs::GetBool(m_prefs, CHXAV_AutoScale, m_bAutoScaleVideo);
    m_bPostFilterOn = prefs::GetBool(m_prefs, CHXAV_EnablePostFilter, m_bPostFilterOn);
}

void CHXAvSettingsDataVideo::UpdatePreferencesL()
{
    UpdatePrefInt(CHXAV_AutoScale, m_bAutoScaleVideo);
    UpdatePrefInt(CHXAV_EnablePostFilter, m_bPostFilterOn);
}

CAknSettingItem* CHXAvSettingsDataVideo::CreateSettingItemL(TInt id)
{
    CAknSettingItem* pItem = 0;

    switch(id)
    {

    case ESetPostFilter:
	pItem = new (ELeave) CAknBinaryPopupSettingItem(id, m_bPostFilterOn);
	break;
    case ESetAutoScaleVideo:
	pItem = new (ELeave) CAknBinaryPopupSettingItem(id, m_bAutoScaleVideo);
	break;
    default:
        HX_ASSERT(false);
    };

    return pItem;
}



////////////////////////////////////////////////////
//
void CHXAvSettingsDataPlayback::InitValuesFromPreferencesL()
{
    HX_ASSERT(m_prefs);

    m_bLoopMode = prefs::GetBool(m_prefs, CHXAV_LoopMode, m_bLoopMode);
    m_bShuffleMode = prefs::GetBool(m_prefs, CHXAV_ShuffleMode, m_bShuffleMode);
    TInt secsClipIntro = prefs::GetINT32(m_prefs, CHXAV_ClipIntroSecs);
    m_idxClipIntro = ConvertClipIntroTimeToIndex(secsClipIntro);
}
void CHXAvSettingsDataPlayback::UpdatePreferencesL()
{
    UpdatePrefInt(CHXAV_LoopMode, m_bLoopMode);
    UpdatePrefInt(CHXAV_ShuffleMode, m_bShuffleMode);
    HX_ASSERT(m_idxClipIntro < ARRAY_COUNT(g_clipIntroVals));
    UpdatePrefInt(CHXAV_ClipIntroSecs, g_clipIntroVals[m_idxClipIntro]);
}

CAknSettingItem* CHXAvSettingsDataPlayback::CreateSettingItemL(TInt id)
{
    CAknSettingItem* pItem = 0;

    switch(id)
    {

    case ESetLoopMode:
	pItem = new (ELeave) CAknBinaryPopupSettingItem(id, m_bLoopMode);
	break;
    case ESetShuffleMode:
        pItem = new (ELeave) CAknBinaryPopupSettingItem(id, m_bShuffleMode);
        break;
    case ESetClipIntroSecs:
        pItem = new (ELeave) CAknEnumeratedTextPopupSettingItem(id, m_idxClipIntro);
        break;
    default:
        HX_ASSERT(false);
    };

    return pItem;
}

namespace
{
////////////////////////////////////////////////////
// port preference strings is in form "low-high[,low-high]" (we only allow one range however)
void ParsePortRange(const CHXString& strPorts, TInt& minPort, TInt& maxPort)
{
    minPort = k_minUdpPortLimit;
    maxPort = k_maxUdpPortLimit;

    minPort = atoi(strPorts);
    TInt idxDash = strPorts.Find("-");
    HX_ASSERT(idxDash != -1);
    if(-1 != idxDash)
    {
        CHXString strHigh = strPorts.Mid(idxDash + 1);
        maxPort = atoi(strHigh);
    }
}
} // ns anon
////////////////////////////////////////////////////
//

void CHXAvSettingsDataNetwork::InitValuesFromPreferencesL()
{

    //m_bUseManualBW = prefs::GetBool(m_prefs, CHXAV_ManualBandwidth, m_bUseManualBW);
    
    //XXXLCM
    /*Bandwidth - Typical bitrate you are able to sustain
MaxBandwidth - The highest bitrate that you want the player to try
               to upshift to.
               */
    TInt maxDeliveryBW = 0;
    maxDeliveryBW = prefs::GetINT32(m_prefs, CHXAV_MaxBandwidth, maxDeliveryBW);
    m_idxNetworkBW = ConvertBwToIndex(maxDeliveryBW);

    m_connectTimeOut = prefs::GetINT32(m_prefs, CHXAV_ConnTimeout, m_connectTimeOut);
    ConstrainWithinBounds(10, m_connectTimeOut, 120);

    m_serverTimeOut = prefs::GetINT32(m_prefs, CHXAV_ServerTimeout, m_serverTimeOut);
    ConstrainWithinBounds(10, m_serverTimeOut, 120);

    // ports
    CHXString strPorts = prefs::GetString(m_prefs, CHXAV_UDPPort);
    ParsePortRange(strPorts, m_minUdpPort, m_maxUdpPort);
    ConstrainWithinBounds(k_minUdpPortLimit, m_minUdpPort, k_maxUdpPortLimit);
    ConstrainWithinBounds(m_minUdpPort, m_maxUdpPort, k_maxUdpPortLimit);


    // If the int value of the access point is 0, we use the string value....
    m_idAccessPoint = prefs::GetINT32(m_prefs, CHXAV_AccessPoint, 0);
    if (m_idAccessPoint == 0)
    {
	CHXString strValue = prefs::GetString(m_prefs, CHXAV_AccessPointStr);
	
	// If the string value is not empty, convert it to integer using the accesspointdb...
	if (!strValue.IsEmpty())
	{
            CHXAvAccessPointDB* pDb = new (ELeave) CHXAvAccessPointDB;
            AUTO_PUSH_POP_DEL(pDb);
            pDb->ConstructL();

	    m_idAccessPoint = pDb->GetIapIDFromNameL(strValue);
	}
    }

}


void CHXAvSettingsDataNetwork::UpdatePreferencesL()
{
    //UpdatePrefInt(CHXAV_ManualBandwidth, m_bUseManualBW);
    
    // special case: prevent unwanted overwrite
    if(m_bMaxDelivBWEdited) 
    {
        HX_ASSERT(m_idxNetworkBW < ARRAY_COUNT(g_bwVals));
        UpdatePrefInt(CHXAV_MaxBandwidth, g_bwVals[m_idxNetworkBW]);

        // XXXLCM set 'bandwidth' and max delivery bw the same
        UpdatePrefInt(CHXAV_Bandwidth, g_bwVals[m_idxNetworkBW]);
    }
    UpdatePrefInt(CHXAV_ConnTimeout, m_connectTimeOut);
    UpdatePrefInt(CHXAV_ServerTimeout, m_serverTimeOut);
    // use 'server timeout' value specified by user to set (similar) 
    // udp timeout as well. 
    // Note: The UDPTimeout units are milliseconds instead of seconds
    UpdatePrefInt(CHXAV_UDPTimeout, m_serverTimeOut * 1000);
    UpdatePrefInt(CHXAV_AccessPoint, m_idAccessPoint);
    

    // ports (contrain to valid values)
    ConstrainWithinBounds(k_minUdpPortLimit, m_minUdpPort, k_maxUdpPortLimit);
    ConstrainWithinBounds(m_minUdpPort, m_maxUdpPort, k_maxUdpPortLimit);
        
    HX_ASSERT(m_maxUdpPort >= m_minUdpPort);
    UpdatePrefInt(CHXAV_UseUDPPort, true);
    CHXString strPort;
    strPort.Format("%lu-%lu", m_minUdpPort, m_maxUdpPort);
    UpdatePrefString(CHXAV_UDPPort, strPort);

}
CAknSettingItem* CHXAvSettingsDataNetwork::CreateSettingItemL(TInt id)
{
    CAknSettingItem* pItem = 0;

    switch(id)
    {
    case ESetDefaultAccessPoint:
        pItem = new (ELeave) CHXAvAccessPointSettingsItem(id, m_idAccessPoint);
        break;
    case ESetUseManualBW:
        HX_ASSERT(false);
	//pItem = new (ELeave) CAknBinaryPopupSettingItem(id, m_bUseManualBW);
	break;
    case ESetNetworkBandwidth:
        pItem = new (ELeave) CAknEnumeratedTextPopupSettingItem(id, m_idxNetworkBW);
        break;
    case ESetConnectTimeOut:
	pItem = new (ELeave) CAknSliderSettingItem(id, m_connectTimeOut);
	break;
    case ESetServerTimeOut:
	pItem = new (ELeave) CAknSliderSettingItem(id, m_serverTimeOut);
	break;
    case ESetMinUdpPort:
	pItem = new (ELeave) CAknIntegerEdwinSettingItem(id, m_minUdpPort);
	break;
    case ESetMaxUdpPort:
	pItem = new (ELeave) CAknIntegerEdwinSettingItem(id, m_maxUdpPort);
	break;
    default:
        HX_ASSERT(false);
    };

    return pItem;
}
void CHXAvSettingsDataNetwork::EditItemL(CAknSettingItem* pItem)
{
    //
    // special case to handle fact that debug tab 
    // also allows you to edit the same value
    //
    if( pItem->Identifier() == ESetNetworkBandwidth)
    {
        m_bMaxDelivBWEdited = true;
    }
}

////////////////////////////////////////////////////
//
void CHXAvSettingsDataProxy::InitValuesFromPreferencesL()
{
    m_bUseProxy = prefs::GetBool(m_prefs, CHXAV_UseProxy, m_bUseProxy);
    m_proxyPort = prefs::GetINT32(m_prefs, CHXAV_ProxyPort, m_proxyPort);
 
    m_spProxy = new (ELeave) TFileName;
    SetTextValue(CHXAV_Proxy, *m_spProxy);
}
void CHXAvSettingsDataProxy::UpdatePreferencesL()
{
    UpdatePrefInt(CHXAV_UseProxy, m_bUseProxy);
    UpdatePrefInt(CHXAV_ProxyPort, m_proxyPort);
    UpdatePrefString(CHXAV_Proxy, *m_spProxy);
}
CAknSettingItem* CHXAvSettingsDataProxy::CreateSettingItemL(TInt id)
{
    CAknSettingItem* pItem = 0;

    switch(id)
    {
    case ESetProxyHost:
	pItem = new (ELeave) CAknTextSettingItem(id, *m_spProxy);
        EnableZeroLength(pItem);
	break;
    case ESetProxyPort:
	pItem = new (ELeave) CAknIntegerEdwinSettingItem(id, m_proxyPort);
	break;
    case ESetUseProxyHost:
	pItem = new (ELeave) CAknBinaryPopupSettingItem(id, m_bUseProxy);
	break;
    default:
        HX_ASSERT(false);
    };

    return pItem;
}

#if defined(HELIX_FEATURE_DPRINTF)

#include "chxavcheckboxlistsettingitem.h"

////////////////////////////////////////////////////
//
void CHXAvSettingsDataDebug::InitValuesFromPreferencesL()
{
    //
    // debug settings
    //
    m_debugMask = prefs::GetUINT32(m_prefs, CHXAV_DebugMask, 0);
  
    m_spLogSink = new (ELeave) TFileName;
    SetTextValue(CHXAV_LogSink, *m_spLogSink);
}
void CHXAvSettingsDataDebug::UpdatePreferencesL()
{
    DPRINTF(SYMP_INFO, ("CHXAvSettingsDataDebug::UpdatePreferencesL()\n"));

    // logsink can be filename, disabled ("" or "none"), or "console"
    _LIT(KSinkNone, "none");
    _LIT(KSinkConsole, "console");

    if( 0 == m_spLogSink->CompareF(KSinkNone) )
    {
        // set "none" to ""
        m_spLogSink->Zero();
    }

    if( (m_spLogSink->Length() > 0) && (0 != m_spLogSink->CompareF(KSinkConsole)) )
    {
        TInt idxDrive = CHXAvFile::GetDriveIndex(*m_spLogSink);
        if(-1 == idxDrive)
        {
            // make relative to c: drive so file is easy to find
            m_spLogSink = CHXAvFile::AllocFileNameL(_L("c:\\"), *m_spLogSink);
        }
    }

    UpdatePrefInt(CHXAV_DebugMask, m_debugMask);
    UpdatePrefString(CHXAV_LogSink, *m_spLogSink);

    dbg::SetupDebug(m_prefs);
    DPRINTF(SYMP_INFO, ("CHXAvSettingsDataDebug::UpdatePreferencesL(): updated log sink and mask\n"));
}

CAknSettingItem* CHXAvSettingsDataDebug::CreateSettingItemL(TInt id)
{
    CAknSettingItem* pItem = 0;

    switch(id)
    {

    case ESetDebugMask:
        pItem = new (ELeave) CHXAvCheckBoxListSettingItem(id, m_debugMask );
        break;
    case ESetLogSink:
	pItem = new (ELeave) CAknTextSettingItem(id, *m_spLogSink);
        EnableZeroLength(pItem);
	break;
    default:
        HX_ASSERT(false);
    };

    return pItem;
}
#endif


⌨️ 快捷键说明

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