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

📄 audopwave.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    return m_wLastError;
}

HX_RESULT CAudioOutOpenwave::_Imp_GetCurrentTime( ULONG32& ulCurrentTime )
{
    ULONG32 ulTime   = 0;
    INT64  ulBytes  = 0;
    /*
  
	if (RA_AOS_OPEN_PLAYING == m_wState)
	{
		ulTime = GetTickCount();
    
		HX_ASSERT(ulTime >= m_ulLastTick);

		//Not used anywhere but belongs to CHXAudioDevice so we must set it.
		m_ulCurrentTime  += (ulTime - m_ulLastTick);
		m_ulLastTick = ulTime;
	}
	ulCurrentTime = m_ulCurrentTime;
	*/

//// New implementation

    ulBytes = _GetBytesActualyPlayed();

    ulTime = (ULONG32) ((ulBytes * 1000) / m_unBytesPerSec);
    
//    OpDPRINTF("cur %d, new %d\n", m_ulCurrentTime, ulTime);
    //Not used anywhere but belongs to CHXAudioDevice so we must set it.
    m_ulCurrentTime  = ulTime;

    //Set the answer.
    ulCurrentTime = ulTime;

    m_wLastError = HXR_OK;
    return HXR_OK;
}

void CAudioOutOpenwave::DoTimeSyncs()
{
    ReschedPlaybackCheck();
    OnTimeSync();
    return;
}


HX_RESULT CAudioOutOpenwave::ReschedPlaybackCheck()
{
    HX_RESULT retCode = HXR_OK;
    
    if(!m_bCallbackPending)
    {
        HX_ASSERT( m_pCallback );
        if(m_pCallback)
        {
            *m_pPlaybackCountCBTime += (int)(500*m_ulGranularity);
            m_bCallbackPending = TRUE;
            m_PendingCallbackID = m_pScheduler->AbsoluteEnter( m_pCallback,*((HXTimeval*)m_pPlaybackCountCBTime));
        }
        else
        {
            retCode = HXR_OUTOFMEMORY;
        }
    }

    m_wLastError = retCode;
    return m_wLastError;
}

UINT16 CAudioOutOpenwave::_NumberOfBlocksRemainingToPlay(void)
{
    //XXXctd total hack, to make sure there is always data to write
    if (m_pWriteList && !m_bFirstWrite && m_pWriteList->GetCount() > 10)
    {
	   return m_pWriteList->GetCount(); 
    }
    return 0;
}


CAudioOutOpenwave::HXPlaybackCountCB::~HXPlaybackCountCB()
{
}

STDMETHODIMP CAudioOutOpenwave::HXPlaybackCountCB::QueryInterface(	REFIID riid, void** ppvObj )
{
    HX_RESULT retCode = HXR_OK;
    
    if( IsEqualIID(riid, IID_IHXCallback) )
    {
        AddRef();
        *ppvObj = (IHXCallback*)this;
    }
    else if (IsEqualIID(riid, IID_IUnknown))
    {
        AddRef();
        *ppvObj = this;
    }
    else
    {
        *ppvObj = NULL;
        retCode = HXR_NOINTERFACE;
    }

    return retCode;
}

STDMETHODIMP_(ULONG32) CAudioOutOpenwave::HXPlaybackCountCB::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

STDMETHODIMP_(ULONG32) CAudioOutOpenwave::HXPlaybackCountCB::Release()
{
    
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }
    
    delete this;
    return HXR_OK;
}

STDMETHODIMP CAudioOutOpenwave::HXPlaybackCountCB::Func(void)
{
    if (m_pAudioDeviceObject)
    {
        if(!m_timed)
        {
            //m_pAudioDeviceObject->_Imp_Write(NULL);
        }
        else
        {
            m_pAudioDeviceObject->m_bCallbackPending  = FALSE;
            //m_pAudioDeviceObject->_Imp_Write(NULL);
            m_pAudioDeviceObject->DoTimeSyncs();
        }
    }

    return HXR_OK;
}


HX_RESULT CAudioOutOpenwave::_Pause()
{
    return RA_AOE_NOTSUPPORTED;
}

HX_RESULT CAudioOutOpenwave::_Resume()
{
    return RA_AOE_NOTSUPPORTED;
}

BOOL CAudioOutOpenwave::_IsSelectable() const
{
    return TRUE;
}

BOOL CAudioOutOpenwave::_HardwarePauseSupported() const
{
    return FALSE;
}


// Don't protect anything in this method with mutexes. It has 
// already been done from where it is called from. But mostly
// because we aren't using recursive mutexes yet.
ULONG32 CAudioOutOpenwave::_PushBits()
{
    if (!m_bWriteDone)
    {
    	//OpDPRINTF("_PushBits : ERROR Both buffers are writing?\n");
	return 0;
    }
    if (m_pWriteList == NULL || m_pWriteList->GetCount() <= 0)  
    {
    	//OpDPRINTF("_PushBits : ERROR Nothing to write\n");
    	//OpDPRINTF("_PushBits : m_pWriteList(%d) %d\n", m_pWriteList->GetCount(), m_nCurBuf);
	return 0;
    }
    if (m_SndBuf[m_nCurBuf].fState == OP_SNDBUF_STATE_NOWPLAYING ||
    	m_SndBuf[m_nCurBuf].fState == OP_SNDBUF_STATE_QUEUED)
    {
    	//OpDPRINTF("_PushBits : buf playing %d\n", m_nCurBuf);
	return 0;
    }
    //OpDPRINTF("_PushBits : m_pWriteList(%d)\n", m_pWriteList->GetCount());

    IHXBuffer* pBuffer  = NULL;
    UCHAR*      pData    = 0;
    ULONG32     nSize = 0;
    op_sound_buffer* sndbuf;

    sndbuf = &m_SndBuf[m_nCurBuf];
    m_nCurBuf = !m_nCurBuf;
    //m_nCurBuf = (m_nCurBuf + 1) % 10;  // use all ten buffers

    //We are going to try and write. Grab the head and do it.
    pBuffer = (IHXBuffer*)m_pWriteList->RemoveHead();
    pData   = pBuffer->GetBuffer();
    nSize   = pBuffer->GetSize();

    memcpy( (unsigned char*)sndbuf->fSampleBuffer, pData, nSize );
    HX_RELEASE( pBuffer );

    sndbuf->fNSamples = (nSize) / (m_unNumChannels * (m_unBitsPerSample/8));
    m_ulTotalWritten += nSize; //Keep track of how much we have written to the device.
    op_sound_write (m_pSndDev, sndbuf);

    m_bWriteDone = false;

    return nSize;
}

HX_RESULT CAudioOutOpenwave::_Imp_Write( const HXAudioData* pAudioOutHdr )
{
    ULONG32     ulCount  = 0;

    //Schedule callbacks.
    if( m_bInitCallback && pAudioOutHdr )
    {
        m_bInitCallback = FALSE;

        //  Initialize the playback callback time.
        HXTimeval lTime = m_pScheduler->GetCurrentSchedulerTime();
        m_pPlaybackCountCBTime->tv_sec = lTime.tv_sec;
        m_pPlaybackCountCBTime->tv_usec = lTime.tv_usec;

        //  Scheduler playback callback.
        ReschedPlaybackCheck();
    }

    //Blindly add the incoming data to the tail of the writelist.
    if( pAudioOutHdr != NULL)
    {
        IHXBuffer* pTmpBuff = pAudioOutHdr->pData;
        m_pWriteList->AddTail(pTmpBuff);
        pTmpBuff->AddRef();
    }

    //OpDPRINTF("_Imp_Write : m_pWriteList(%d) \n", m_pWriteList->GetCount());

    //Just return if there is nothing to do 
    if( m_pWriteList->GetCount() <= 0 || m_wState==RA_AOS_OPEN_PAUSED )
    {
        return RA_AOE_NOERR;
    }
    m_wState = RA_AOS_OPEN_PLAYING;

    if( m_bFirstWrite )
    {
	if (m_pWriteList->GetCount() >= 10)
	{
        	m_bFirstWrite = FALSE;
		for (int i=0; i<2; i++)
		{
			m_bWriteDone = TRUE;
			ulCount = _PushBits(); // Start the double buffering
		}
	}
    }
    else
    {
    	//ulCount = _PushBits();// causes two competing threads
    }
    
    if ( m_bInitCallback )
    {
        m_bInitCallback = FALSE;
            
        //  Initialize the playback callback time. 
        HXTimeval lTime = m_pScheduler->GetCurrentSchedulerTime();
        m_pPlaybackCountCBTime->tv_sec = lTime.tv_sec;
        m_pPlaybackCountCBTime->tv_usec = lTime.tv_usec;
            
        //  Scheduler playback callback. 
        ReschedPlaybackCheck();
    }

    //make sure the device is kept full.
    //if( m_pWriteList->GetCount()>0 && ulCount>0)
        //_PushBits();

    return m_wLastError;
    
}

//-------------------------------------------------------
// These Device Specific methods must be implemented 
// by the platform specific sub-classes.
//-------------------------------------------------------
INT16 CAudioOutOpenwave::_Imp_GetAudioFd(void)
{
    return 0;
}

//Device specific method to set the audio device characteristics. Sample rate,
//bits-per-sample, etc.
//Method *must* set member vars. m_unSampleRate and m_unNumChannels.
HX_RESULT CAudioOutOpenwave::_SetDeviceConfig( const HXAudioFormat* pFormat )
{
    return RA_AOE_NOERR;
}


//Device specific method to write bytes out to the audiodevice and return a
//count of bytes written. 
HX_RESULT CAudioOutOpenwave::_WriteBytes( UCHAR* buffer, ULONG32 ulBuffLength, LONG32& lCount )
{
    HX_RESULT retCode = RA_AOE_NOERR;
    return retCode;
}

//Device specific methods to open/close the mixer and audio devices.
HX_RESULT CAudioOutOpenwave::_OpenAudio()
{
    HX_RESULT retCode = RA_AOE_NOERR;
    
    m_wLastError = retCode;
    return m_wLastError;
}

HX_RESULT CAudioOutOpenwave::_CloseAudio()
{
    HX_RESULT retCode = RA_AOE_NOERR;
    
    m_wLastError = retCode;
    return m_wLastError;
}

HX_RESULT CAudioOutOpenwave::_OpenMixer()
{
    HX_RESULT retCode = RA_AOE_NOERR;
    m_wLastError = retCode;
    return m_wLastError;
}

HX_RESULT CAudioOutOpenwave::_CloseMixer()
{
    HX_RESULT retCode = RA_AOE_NOERR;

    m_wLastError = retCode;
    return m_wLastError;
}


UINT64 CAudioOutOpenwave::_GetBytesActualyPlayed(void) const
{
    /* Get current playback position in device DMA. */
    return  m_ulTotalWritten;
}




HX_RESULT CAudioOutOpenwave::_CheckSampleRate( ULONG32 ulSampleRate )
{
    ULONG32 ulTmp = ulSampleRate;

    m_wLastError = RA_AOE_NOERR;
    
    return m_wLastError;
}

⌨️ 快捷键说明

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