audio_session-mmf.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 641 行 · 第 1/2 页

CPP
641
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: audio_session-mmf.cpp,v 1.1.2.2 2004/07/09 02:01:33 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

#if defined (HELIX_CONFIG_CALYPSO_AUDIO_PREF)
#include <calypso/audiopreference.h>
#endif

#include "hxcom.h"
#include "hxslist.h"
#include "hxausvc.h"
#include "hxbuffer.h"
#include "audio_session-mmf.h"
#include "hxtick.h"
#include <e32std.h>

static const TInt KClientPriority = 69;
#if defined(HELIX_CONFIG_CALYPSO_AUDIO_PREF)
static const TMdaPriorityPreference KPriorityPref = (TMdaPriorityPreference)KAudioPrefComposer; 
#else
static const TMdaPriorityPreference KPriorityPref = (TMdaPriorityPreference)80; //EMdaPriorityPreferenceTime;
#endif // SERIES60_PLAYER

const INT32 WriteBufferDepth = 10; // Number of buffers we allow in the queue before blocking the caller



static TInt FlagToNumber(TMMFSampleRate flag)
{
    switch( flag )
    {
    case EMMFSampleRate8000Hz:
        return 8000;
    case EMMFSampleRate11025Hz:
        return 11025;
    case EMMFSampleRate16000Hz:
        return 16000;
    case EMMFSampleRate22050Hz:
        return 22050;
    case EMMFSampleRate32000Hz:
        return 32000;
    case EMMFSampleRate44100Hz:
        return 44100;
    case EMMFSampleRate48000Hz:
        return 48000;
    default:
        return 0;
        break;
    }
    return 0;
}

static TMMFSampleRate NumberToFlag(TInt num)
{
    switch(num)
    {
    case 8000:
        return  EMMFSampleRate8000Hz;
    case 11025:
        return  EMMFSampleRate11025Hz;
    case 16000:
        return  EMMFSampleRate16000Hz;
    case 22050:
        return  EMMFSampleRate22050Hz;
    case 32000:
        return  EMMFSampleRate32000Hz;
    case 44100:
        return  EMMFSampleRate44100Hz;
    case 48000:
        return  EMMFSampleRate48000Hz;
    default:
        HX_ASSERT(NULL=="Invalid sample rate flag");
        break;
    }
    return EMMFSampleRate16000Hz;
}

HXSymbianAudioSession::HXSymbianAudioSession(RThread& client,
                                             HXSymbianAudioServer* pServer)
    : CSession(client),
      m_pServer(pServer),
      m_wantsNotify(false),
      m_reason(KErrNone),
      m_open(false),
      m_bPaused(FALSE),
      m_pStream(NULL),
      m_pData(NULL),
      m_bBufferNeedsFilling(false),
      m_bPlayInited(FALSE),
      m_uSampleRate(0),
      m_ulPauseTime(0),
      m_ulStartTime(0),
      m_nLastSampleCount(0),
      m_nUnderflowSampleCount(0)
{
    // add the session to the server
    m_pServer->AddSession();
    memset(&m_Settings, 0, sizeof( m_Settings) );
}

//
// HXSymbianAudioSession::dtor
//
HXSymbianAudioSession::~HXSymbianAudioSession()
{
    DoCleanup();
}


//
// HXSymbianAudioSession::NewL
//
// creates a new session
//
HXSymbianAudioSession* HXSymbianAudioSession::NewL(RThread& client,
                                                   HXSymbianAudioServer* pServer)
{
    HXSymbianAudioSession* pSession =
        new (ELeave) HXSymbianAudioSession(client, pServer);
    
    return pSession;
}

//
// HXSymbianAudioSession::ServiceL
//
// services a client message
//
void HXSymbianAudioSession::ServiceL(const RMessage& mesg)
{
    switch (mesg.Function()) 
    {
    case HXSymbianAudioServer::EAS_Init:
        Init();
        break;
    case HXSymbianAudioServer::EAS_Play:
        Play();
        break;
    case HXSymbianAudioServer::EAS_Pause:
        Pause();
        break;
    case HXSymbianAudioServer::EAS_Write:
        Write();
        break;
    case HXSymbianAudioServer::EAS_CancelWrite:
        mesg.Complete(KErrNone);
        break;
    case HXSymbianAudioServer::EAS_GetTime:
        GetTime();
        break;
    case HXSymbianAudioServer::EAS_GetBlocksBuffered:
        GetBlocksBuffered();
        break;
    case HXSymbianAudioServer::EAS_SetVolume:
        SetVolume();
        break;
    case HXSymbianAudioServer::EAS_GetVolume:
        GetVolume();
        break;
    case HXSymbianAudioServer::EAS_GetMaxVolume:
        GetMaxVolume();
        break;
    case HXSymbianAudioServer::EAS_GetMinVolume:
        GetMinVolume();
        break;
    case HXSymbianAudioServer::EAS_Stop:
        Stop();
        break;
    case HXSymbianAudioServer::EAS_RequestDeviceTakenNotification:
        RequestDeviceTakenNotification();
        break;
    case HXSymbianAudioServer::EAS_CancelDeviceTakenNotification:
        CancelDeviceTakenNotification();
        break;
    default:
        mesg.Complete(KErrNotSupported);
        break;
    }
}

//
// HXSymbianAudioSession::Init
//
// 1. Matches input sample rate to output sample rate
//    by building a sample rate converter, if necessary.
// 2. Opens and initializes the audio device.
//
void HXSymbianAudioSession::Init()
{
    TInt err = KErrNone;

    // translate the audio props to flags needed by interface
    m_Settings.iRate     = NumberToFlag(Message().Int0());
    m_Settings.iChannels = Message().Int1();
    m_Settings.iEncoding = EMMFSoundEncoding16BitPCM; //We always do 16bit.
    m_uSampleRate        = Message().Int0();
    
    if (m_open)
    {
        TRAP(err, (m_pStream->CMMFDevSound::SetConfigL(m_Settings)));
        Message().Complete(err);
    }
    else 
    {
        TRAP(err, (m_pStream = CMMFDevSound::NewL()));
        if(KErrNone == err)
        {
            m_InitMessage = Message();
            TRAP(err, (m_pStream->InitializeL(*this, EMMFStatePlaying)));
        }
        if( KErrNone != err )
        {
            Message().Complete(err);
        }
    }

    m_bPlayInited = FALSE;
}

void HXSymbianAudioSession::DoCleanup()
{
    while(!m_bufferList.IsEmpty())
    {
        IHXBuffer* pBuf = (IHXBuffer*)m_bufferList.RemoveHead();
        HX_RELEASE(pBuf);
    }

    if (m_wantsNotify)
    {
        m_notifyRequest.Complete(KErrCancel);
        m_wantsNotify = false;
    }

    if (m_pStream)
    {
        m_pStream->Stop();
        delete m_pStream;
        m_pStream = 0;
        m_open = false;
        m_pData= NULL;
    }

    // remove session from server
    if( m_pServer)
    {
        m_pServer->DelSession();
        m_pServer = 0;
    }
}

//
// HXSymbianAudioSession::Play
//
void HXSymbianAudioSession::Play()
{
    TInt err = KErrNone;
    m_reason = KErrNone;

    m_ulStartTime = HX_GET_TICKCOUNT();

    if( m_pData )
    {
        m_pStream->PlayData();
    }

    if(!m_bPlayInited)
    {
        //Set priority.
        TMMFPrioritySettings prioritySettings;
        prioritySettings.iPref     = KPriorityPref;
        prioritySettings.iPriority = KClientPriority;
        
        m_pStream->SetPrioritySettings(prioritySettings);
        TRAP(err, m_pStream->PlayInitL());
        m_bPlayInited = TRUE;
    }

⌨️ 快捷键说明

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