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

📄 pe_consumer_cdda.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  Copyright (c) 2006 Videon Central, Inc.                                 **
**  All rights reserved.                                                    **
**                                                                          **
**  The computer program contained herein contains proprietary information  **
**  which is the property of Videon Central, Inc.  The program may be used  **
**  and/or copied only with the written permission of Videon Central, Inc.  **
**  or in accordance with the terms and conditions stipulated in the        **
**  agreement/contract under which the programs have been supplied.         **
**                                                                          **
******************************************************************************
*****************************************************************************/
/**
 * @file pe_consumer_cdda.cpp
 *
 * $Revision: 1.18 $ 
 *
 * PE Consumer CDDA Derived Class Definition
 * The PE Consumer moves data from an input stream to a decoder or demux.
 *
 */

#include <stdlib.h>
#include "decoder.h"
#include "vdvd_types.h"
#include "osapi.h"
#include "dbgprint.h"
#include "pe_app.h"
#include "pe_consumer.h"
#include "pe_consumer_cdda.h"
#include "utility.h"

#define DEBUG_PE_CONSUMER_CDDA  DBG_ERROR
#define DBG_ON(x)               (DEBUG_PE_CONSUMER_CDDA >= x)

#define CDDA_FASTFORWARD_ATTENUATION (6 * 100) /* 6dB in 100ths */

/**
 * cPEConsumer_CDDA::Configure
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_CDDA::Configure(PE_CONSUMER_CONFIG_INFO *pConfigInfo)
{
    PE_STATUS status;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Configure()\n"));

    /* base class does work required by all consumers */
    status = cPEConsumer::Configure(pConfigInfo);

    return (status);
}


/**
 * cPEConsumer_CDDA::Reset
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_CDDA::Reset(void)
{
    VDVD_ERROR  error  = VDVD_SUCCESS;
    PE_STATUS   status = PE_SUCCESS;

    /* clear prefill since we are going to stop state */
    m_fPrefill = FALSE;
    m_fSuspend = FALSE;

    if ( (IS_PECONSUMER_STATE_RUNNING(m_ConsumerState) == TRUE) && (m_fStop == FALSE) )
    {
        /* tell the consumer data task it should stop */
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Reset() - tell data to stop\n"));
        m_fStop = TRUE;
        m_fAbort = TRUE;

        /* wait for transition to stopped state */
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Reset() - wait for transition to stopped state\n"));
        while (m_fStop == TRUE)
        {
            OS_TaskYield();
        }

        /* stop PCM playback */
        if (m_audioDecode[0] != NULL)
        {
            error = m_audioDecode[0]->Stop(FALSE);
        }

        /* SDK: wait until all outstanding payloads are released */
        m_fAbort = FALSE;
        /* This means that we will tell the SPDIF layer to toggle the copy bit */
        /* get the current spdif settings */
        /* If the copy bit is set, copy is prohibited, if the emphasis bit is set, pre-emphasis is on */
        m_bPrevCopy = CDDA_COPY_UNITIALIZED;
    }

    /* signal the cdda consumer tasks to terminate */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Reset() - signal the cdda consumer tasks\n"));
    m_fKillDataProc  = TRUE;

    /* wait until the cdda consumer tasks have terminated */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Reset() - wait until tasks have terminated\n"));

    /* use the base clase to terminate the main consumer task */
    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Reset() - base clase terminate\n"));
    status = cPEConsumer::Reset();

    return (status);

} /* end cPEConsumer_CDDA::Reset() */





/**
 * If active start consuming and presenting AV data.  Wakes up dataProc.
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_CDDA::Run(void)
{
    VDVD_ERROR              error               = VDVD_SUCCESS;
    PE_STATUS               status              = PE_SUCCESS;
    DECODER_SETTINGS_TYPE   decoderSettings;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Run\n"));

    memset(&m_pcm_settings,0,sizeof(m_pcm_settings));

    m_pcm_settings.bits_per_sample   = 16;
    m_pcm_settings.sample_rate       = 44100;
    m_pcm_settings.channels          = 2;
    m_pcm_settings.spdif_output_only = false;

    if (IS_PECONSUMER_STATE_RUNNING(m_ConsumerState) == FALSE)
    {
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Run - start PCM decoding\n"));

        decoderSettings.streamType = DECODER_STREAM_TYPE_PCM;
        decoderSettings.pcm        = m_pcm_settings;

        error = m_audioDecode[0]->Setup(&decoderSettings);
        if (VDVD_IS_ERROR(error))
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("cPEConsumer_CDDA::Run - pcm decoder setup FAILED!\n"));
        }
    }

    /* update state info */
    m_fPrefill      = FALSE;
    m_fSuspend      = FALSE;
    m_fStillOn      = FALSE;
    m_ConsumerState = PE_CONSUMER_STATE_RUN;

    m_bPrevCopy = CDDA_COPY_UNITIALIZED;

    return (status);

} /* end cPEConsumer_CDDA::Run() */


/**
 * If active start consuming and presenting AV data.
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_CDDA::Stop(BOOLEAN fHoldPicture)
{
    VDVD_ERROR   error = VDVD_SUCCESS;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Stop()\n"));

    /* clear prefill since we are going to stop state */
    m_fPrefill = FALSE;
    m_fSuspend = FALSE;

    if ( (IS_PECONSUMER_STATE_RUNNING(m_ConsumerState) == TRUE) && (m_fStop == FALSE) )
    {
        /* tell the consumer data task it should stop */
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Stop() - tell data to stop\n"));
        m_fStop = TRUE;
        m_fAbort = TRUE;

        /* wait for transition to stopped state */
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Stop() - wait for transition to stopped state\n"));
        while (m_fStop == TRUE)
        {
            OS_TaskYield();
        }

        if (m_audioDecode[0] != NULL)
        {
            error = m_audioDecode[0]->Stop(FALSE);
        }

        /* SDK: wait until all outstanding payloads are released */
        m_fAbort = FALSE;
        /* This means that we will tell the SPDIF layer to toggle the copy bit */
        /* get the current spdif settings */
        /* If the copy bit is set, copy is prohibited, if the emphasis bit is set, pre-emphasis is on */
        m_bPrevCopy = CDDA_COPY_UNITIALIZED;
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_CDDA::Stop() - done\n"));

    return (PE_SUCCESS);

} /* end cPEConsumer_CDDA::Stop() */


/**
 * Flush the decoder and all related streams.
 * Returns to the RUN state once completed.
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_CDDA::Flush()
{
    DBGPRINT(DBG_ON(DBG_TRACE), (("cPEConsumer_CDDA::Flush\n" )));
    return (PE_SUCCESS);

} /* end cPEConsumer_CDDA::Flush() */


/**
 * SetRate overrides the base class consumer.
 *
 * @param PE_ISTREAMCTRL_PLAYRATE *pPlayRate
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_CDDA::SetRate(PE_ISTREAMCTRL_PLAYRATE *pPlayRate)
{
    VDVD_ERROR   error = VDVD_SUCCESS;

    /* verify input */
    if (pPlayRate == NULL)
    {
        return (PE_NULL_POINTER);
    }

    if (INPUT_MAIN == m_ConsumerInput)
    {

        /* If we're going from pause to play, resume the pcm playback */
        if ((PLAY_RATE_PAUSE == m_playrate.rate) &&
            (PLAY_RATE_PAUSE != pPlayRate->rate)) 
        {
            error = m_audioDecode[0]->Resume();
        }
        /* If we're going from play to pause, pause the pcm playback */
        else if ((PLAY_RATE_PAUSE != m_playrate.rate) &&
            (PLAY_RATE_PAUSE == pPlayRate->rate)) {
            error = m_audioDecode[0]->Pause();
        }

        /* if we're going from pause/step/normal into fast forward */
        /* drop the volume by 6dB */
        if ((PLAY_RATE_NORMAL >= m_playrate.rate &&
                  PLAY_RATE_NORMAL < pPlayRate->rate)) {
            uint32 left;
            uint32 right;
            // SDK ToDo: get volume
            left = 0;
            right = 0;

            left += (6 * 100);
            right += (6 * 100);
            // SDK ToDo: set volume
        }
        /* else if we're going from fast forward to pause/step/normal */
        /* set the volume back to normal (increase the volume by 6dB )*/
        else if ((PLAY_RATE_NORMAL < m_playrate.rate &&
                  PLAY_RATE_NORMAL >= pPlayRate->rate)) {
            uint32 left;
            uint32 right;
            // SDK ToDo: get volume
            left = 0;
            right = 0;

            left -= (6 * 100);
            right -= (6 * 100);
            // SDK ToDo: set volume
        }

        /* update playrate */
        m_playrate = *pPlayRate;

⌨️ 快捷键说明

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