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

📄 pe_consumer_bdrom.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************
******************************************************************************
**                                                                          **
**  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_bdrom.cpp
 *
 * $Revision: 1.25 $ 
 *
 * PE Consumer BDROM 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_bdrom.h"
#include "utility.h"

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

extern BOOLEAN              fMainStarted;

/* BDROM Specific Defines */
#define AU_SIZE 6144



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

    m_pg_dec    = NULL;
    m_ig_dec    = NULL;
    m_st_dec    = NULL;

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

    return (status);
}

/**
 * cPEConsumer_BDROM::Reset
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_BDROM::Reset(void)
{
    PE_STATUS status;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::Reset()\n"));

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

    /* @todo Examine what decode/channel stops need to be called and if teardown
     * of dataProc for this BDROM consumer and its information should be done. */

    if ( (IS_PECONSUMER_STATE_RUNNING(m_ConsumerState) == TRUE) && (m_fStop == FALSE) )
    {
        PEINPUTMESSAGE* pMessage = NULL;

        /* tell the consumer data task it should stop */
        m_fStop  = TRUE;
        m_fAbort = TRUE;

        /* kick the dataProc so it won't wait */
        pMessage = (PEINPUTMESSAGE*)m_InputStream->GetMsg((ULONG)OS_NO_WAIT);
        if (pMessage != NULL)
        {
            m_InputStream->Write((PVOID)pMessage, OS_NO_WAIT);
        }

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

        /* if we have the PG decoder then stop it */
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::Reset() - PGStop (%d)\n", m_ConsumerInput));
        if (m_pg_dec != NULL)
        {
            PGStop(m_pg_dec);
            m_pg_pid = -1;
        }

        /* if we have the IG decoder then stop it */
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::Reset() - IGStop (%d)\n", m_ConsumerInput));
        if (m_ig_dec != NULL)
        {
            IGStop(m_ig_dec);
            m_ig_pid = -1;
        }

        /* if we have the ST decoder then stop it */
        DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::Reset() - STStop (%d)\n", m_ConsumerInput));
        if (m_st_dec != NULL)
        {
            TextSTStop(m_st_dec);
        }

        m_fAbort = FALSE;
    }

    /* use the base clase to terminate the consumer task */
    status = cPEConsumer::Reset();

    m_pg_dec = NULL;
    m_ig_dec = NULL;
    m_st_dec = NULL;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::Reset() done\n"));

    return (status);

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

/**
 * Assigns the PID for the video stream. If idle (not being used to demux) then become active.
 * Only valid if the stream type for the PEConsumer is the STREAM_MAIN.
 *
 * @param LONG lPID
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_BDROM::DemuxAddVideoTS(LONG lPID, PE_ISTREAMCTRL_VIDEO_TYPE VideoType, Decoder* pDecoder)
{
    VDVD_ERROR  error  = VDVD_SUCCESS;
    PE_STATUS   status = PE_SUCCESS;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::DemuxAddVideoTS() - PID=%x\n", lPID));

    /* validate state
     * NOTE: We don't support dynamic video PID configuration. You should stop the consumer if you
     * want to change video PIDs */
    if ( (m_ConsumerState == PE_CONSUMER_STATE_UNREALIZED) || (IS_PECONSUMER_STATE_RUNNING(m_ConsumerState) == TRUE) )
    {
        status = PE_INVALID_STATE;
    }

    /* validate input */
    if (pDecoder == NULL)
    {
        status = PE_NULL_POINTER;
    }

    /* @todo Substream PIP video selection to be incorporated later */
    if (INPUT_MAIN != m_ConsumerInput)
    {
        status = PE_FAILURE;
    }

    if (status == PE_SUCCESS)
    {
        DECODE_VIDEO_PARAMETERS dvpVideoParams;

        /* Store main video decode handle */
        m_videoDecode[0] = pDecoder;

        /* configure video params */
        dvpVideoParams.pid          = lPID;                   /* Video PID, if Transport Stream */
        dvpVideoParams.stream_id    = 0;                      /* Video Stream ID, if Program Stream */
        dvpVideoParams.substream_id = 0;                      /* Video Sub stream ID; optional for PS */
        dvpVideoParams.extstream_id = 0;                      /* Video Stream ID Extension; optional */
        dvpVideoParams.stc_offset   = 0;


        if (VideoType == VIDEO_TYPE_MPEG2)
        {
            DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::DemuxAddVideoTS() - VIDEO_CODEC_MPEG2\n"));
        }
        else if (VideoType == VIDEO_TYPE_AVC)
        {
            DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::DemuxAddVideoTS() - VIDEO_CODEC_H264\n"));
        }
        else if (VideoType == VIDEO_TYPE_VC1)
        {
            DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::DemuxAddVideoTS() - VIDEO_CODEC_VC1\n"));
        }

        /* add demux to decoder */
        error = m_videoDecode[0]->SelectVideoStream(&dvpVideoParams);
        if (VDVD_IS_ERROR(error))
        {
            m_videoDecode[0] = NULL;
            status           = PE_FAILURE;
        }
    }

    return (status);

} /* end cPEConsumer_BDROM::DemuxAddVideoTS() */

/**
 * Assigns the PID for the audio stream. If idle (not being used to demux) then become active.
 * Only valid for a PEConsumer with the following stream types:
 * STREAM_MAIN, STREAM_BDROM_APP_TYPE_4, STREAM_BDROM_APP_TYPE_7.
 *
 * @param LONG lPID
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_BDROM::DemuxAddAudioTS(LONG lPID, PE_ISTREAMCTRL_AUDIO_TYPE AudioType, PE_ISTREAMCTRL_AUDIO_ATTRIBUTES *pAttributes, Decoder* pDecoder)
{
    VDVD_ERROR  error  = VDVD_SUCCESS;
    PE_STATUS   status = PE_SUCCESS;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::DemuxAddAudioTS() - PID=%x\n", lPID));

    /* validate state */
    if (m_ConsumerState == PE_CONSUMER_STATE_UNREALIZED)
    {
        status = PE_INVALID_STATE;
    }

    /* validate input */
    if (pDecoder == NULL)
    {
        status = PE_NULL_POINTER;
    }

    if (status == PE_SUCCESS)
    {
        DECODE_AUDIO_PARAMETERS dapAudioParams;

        /* Store main audio decode handle */
        m_audioDecode[0] = pDecoder;

        /* set stream id's */
        dapAudioParams.pid            = lPID;
        dapAudioParams.stream_id      = 0;
        dapAudioParams.substream_id   = 0;
        dapAudioParams.extstream_id   = 0;
        dapAudioParams.format         = AudioType;
        dapAudioParams.stc_offset     = 0;
        dapAudioParams.downmix_enable = false;
        if (pAttributes != NULL)
        {
            /* config sampling freq and num channels */
            switch (pAttributes->sampling_frequency)
            {
                case AUDIO_SAMPLING_FREQUENCY_44_1_KHz:
                    dapAudioParams.sample_rate = 44100;
                    break;

                default:
                case AUDIO_SAMPLING_FREQUENCY_INVALID:
                case AUDIO_SAMPLING_FREQUENCY_48_KHz:
                    dapAudioParams.sample_rate = 48000;
                    break;

                case AUDIO_SAMPLING_FREQUENCY_96_KHz:
                    dapAudioParams.sample_rate = 96000;
                    break;

                case AUDIO_SAMPLING_FREQUENCY_192_KHz:
                    dapAudioParams.sample_rate = 192000;
                    break;
            }

            switch(pAttributes->n_channels)
            {
                case AUDIO_MONO:
                    dapAudioParams.num_channels = 1;
                    break;

                case AUDIO_DUAL_MONO:
                case AUDIO_STEREO:
                    dapAudioParams.num_channels = 2;
                    break;

                case AUDIO_3_CHANNELS:
                    dapAudioParams.num_channels = 3;
                    break;

                case AUDIO_4_CHANNELS:
                    dapAudioParams.num_channels = 4;
                    break;

                case AUDIO_5_CHANNELS:
                    dapAudioParams.num_channels = 5;
                    break;

                case AUDIO_6_CHANNELS:
                    dapAudioParams.num_channels = 6;
                    break;

                case AUDIO_7_CHANNELS:
                    dapAudioParams.num_channels = 7;
                    break;

                case AUDIO_8_CHANNELS:
                    dapAudioParams.num_channels = 8;
                    break;

                case AUDIO_MULTI_CHANNEL:            /* Blu-Ray audio_presentation_type 6  */
                case AUDIO_STEREO_PLUS_MULTI_EXT:    /* Blu-Ray audio_presentation_type 12 */
                case AUDIO_CHANNELS_INVALID:
                    dapAudioParams.num_channels = 0;
                    break;
            }
        }
        else
        {
            /* the audio attributes were NULL */
            dapAudioParams.sample_rate = 48000;
            dapAudioParams.num_channels = 0;
        }

        // if need to check if already running before changing streams use
        // if (IS_PECONSUMER_STATE_RUNNING(m_ConsumerState) == TRUE)

        error = m_audioDecode[0]->SelectAudioStream(&dapAudioParams);
        if (VDVD_IS_ERROR(error))
        {
            m_audioDecode[0] = NULL;
            status             = PE_FAILURE;
        }
    }

    return (status);

} /* end cPEConsumer_BDROM::DemuxAddAudioTS() */

/**
 * Assigns the PID for the Secondary Audio Stream.
 * If idle (not being used to demux) then become active.
 *
 * @param lPID      - audio PID
 * @param AudioType - audio format
 * @param pDecoder  - decode handle to use for audio
 *
 * @return PE_STATUS
 */
PE_STATUS cPEConsumer_BDROM::DemuxAddSecondaryAudioTS(LONG lPID, PE_ISTREAMCTRL_AUDIO_TYPE AudioType, PE_ISTREAMCTRL_AUDIO_ATTRIBUTES *pAttributes, Decoder* pDecoder)
{
    VDVD_ERROR  error = VDVD_SUCCESS;
    PE_STATUS   status = PE_SUCCESS;

    DBGPRINT(DBG_ON(DBG_TRACE), ("cPEConsumer_BDROM::DemuxAddSecondaryAudioTS() - PID=%x\n", lPID));

    /* validate state */
    if (m_ConsumerState == PE_CONSUMER_STATE_UNREALIZED)
    {
        status = PE_INVALID_STATE;
    }

    /* validate input */
    if (pDecoder == NULL)
    {
        status = PE_NULL_POINTER;
    }

    if (status == PE_SUCCESS)
    {
        DECODE_AUDIO_PARAMETERS dapAudioParams;

        /* Store main audio decode handle */
        m_audioDecode[1] = pDecoder;

        /* set stream id's */
        dapAudioParams.pid            = lPID;
        dapAudioParams.stream_id      = 0;
        dapAudioParams.substream_id   = 0;
        dapAudioParams.extstream_id   = 0;
        dapAudioParams.format         = AudioType;
        dapAudioParams.downmix_enable = false;

        if (pAttributes != NULL)
        {
            /* config sampling freq and num channels */
            switch (pAttributes->sampling_frequency)
            {
                case AUDIO_SAMPLING_FREQUENCY_44_1_KHz:
                    dapAudioParams.sample_rate = 44100;
                    break;

                default:
                case AUDIO_SAMPLING_FREQUENCY_INVALID:
                case AUDIO_SAMPLING_FREQUENCY_48_KHz:
                    dapAudioParams.sample_rate = 48000;

⌨️ 快捷键说明

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