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

📄 mp3_demux.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************/
/************************************************************************/
/**                                                                    **/
/** Copyright (c) 2002 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
 *    mp3_demux.cpp
 *
 * MP3 Transport Demux source file.
 *
 * @author
 *    John P. Morgan
 *
 * @remark
 *    None
 *
 * CVS Log Information:
 *    $Log: mp3_demux.cpp,v $
 *    Revision 1.11  2007/01/11 19:48:06  jared
 *    Synchronization of MAIN branch (PKG148) with HD DVD branch (PKG148)
 *
 *    Revision 1.9.274.2  2007/01/05 22:31:19  jared
 *    Synchronzation of HD DVD branch (PKG128) with MAIN branch (PKG148).
 *
 *
 *    Revision 1.10  2007/01/05 02:05:12  rbehe
 *    use task delays instead of task yields
 *
 *    Revision 1.9  2005/05/31 14:46:28  ccoble
 *    When flushing a stream queue, use the api
 *    to remove a stream rather than receive one.
 *
 *    Revision 1.8  2005/04/14 21:33:30  rbehe
 *    new directory layout
 *
 *    Revision 1.7  2005/03/30 20:27:14  rbehe
 *    pvPack removed from message.
 *
 *    Revision 1.6  2005/03/28 20:26:46  eric
 *    added dmalloc support
 *
 *    Revision 1.5  2005/03/28 20:10:50  eric
 *    merged in changes from cStream_update branch
 *
 *    Revision 1.4.2.1  2005/03/21 23:23:20  eric
 *    cStream debug update branch check-in
 *
 *    Revision 1.4  2005/03/16 22:49:26  eric
 *    cleanup
 *
 *    Revision 1.3  2003/09/17 13:52:16  rbehe
 *    Use DbgPrint instead of printf
 *
 *    Revision 1.2  2003/09/16 15:27:36  rbehe
 *    Fixed compile warnings and added cvs log info.
 *
 */
#include <string.h>
#include "vdvd_types.h"
#include "osapi.h"
#include "utility.h"
#include "msg_app.h"
#include "cDemux.h"
#include "mp3_demux.h"
#include "mp3struct.h"
#include "dbgprint.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/** MP3 Demux Debug Defines                                            **/
/**                                                                    **/
/************************************************************************/
/************************************************************************/
#define MP3_DEMUX_DEBUG_ON   0

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/** MP3 Demux Private Variables                                        **/
/**                                                                    **/
/************************************************************************/
/************************************************************************/
static MP3DEMUXINFO tDemuxInfo;
static ULONG        ulMP3DemuxErrorCnt = 0;
static ULONG        ulMP3FrameCount    = 0;

// MP3 lookup table
//  dimension 0 => MPEG version, 0=version 1.0, 1=version 2.0
//  dimension 1 => layer (0=layer 1, 1=layer 2, 2=layer 3)
//  dimension 2 => bitrate index 0-15
const ULONG ulMP3Tabsel_123[2][3][16] = 
{
    // MPEG 1.0
    { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
      {0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384,},
      {0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320,} },

    // MPEG 2.0
    { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
      {0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160,},
      {0,  8, 16, 24, 32, 40, 48,  56,  64,  80,  96, 112, 128, 144, 160,} }
};

const ULONG ulMP3Freqs[9] = 
{ 
    44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000 
};

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/** MP3 Demux Forward Function Declarations                            **/
/**                                                                    **/
/************************************************************************/
/************************************************************************/

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/** MP3 Demux Input Function                                           **/
/**                                                                    **/
/************************************************************************/
/************************************************************************/

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/** MP3 Demux Output Function                                          **/
/**                                                                    **/
/************************************************************************/
/************************************************************************/

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/************************************************************************/
/************************************************************************/
static void MP3_DemuxInit( MP3DEMUXINFO *pDemuxInfo )
{

 /* Demux State */
  pDemuxInfo->ulDemuxState = MP3_HEADER;

 /* Local configuration information */
  pDemuxInfo->tConfigInfo.iOutputPinCount = 0;
  pDemuxInfo->tConfigInfo.tInputPin       = NULL;

#if 0
  for( int i = 0; i < OUTPUT_STREAM_MAX_COUNT; i++ )
  {
    pDemuxInfo->tConfigInfo.tOutputPin[i].wPID         = INVALID_PID;
    pDemuxInfo->tConfigInfo.tOutputPin[i].pDestStream  = NULL;
    pDemuxInfo->tConfigInfo.tOutputPin[i].fSendPayload = FALSE;
  }
#endif

} /* end MP3_DemuxInit() */

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/************************************************************************/
/************************************************************************/
static void MP3_DemuxUpdate( MP3DEMUXINFO *pDemuxInfo )
{
    DbgPrint(("MP3_DemuxUpdate: begin %d\n", pDemuxInfo->pDynamicConfigInfo->iOutputPinCount));

    pDemuxInfo->tConfigInfo.iOutputPinCount = pDemuxInfo->pDynamicConfigInfo->iOutputPinCount;
    pDemuxInfo->tConfigInfo.tInputPin       = pDemuxInfo->pDynamicConfigInfo->tInputPin;

    pDemuxInfo->tOutputPin.pDestStream = NULL;
    for (int i=0; i<pDemuxInfo->pDynamicConfigInfo->iOutputPinCount; i++)
    {
        DbgPrint(("MP3_DemuxUpdate: StreamType = %d\n", pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].tStreamType));

        if (pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].tStreamType == AUDIO)
        {
            DbgPrint(("MP3_DemuxUpdate: found audio output pin\n"));
            pDemuxInfo->tOutputPin.bPesID       = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].bPesID;
            pDemuxInfo->tOutputPin.bSubID       = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].bSubID;
            pDemuxInfo->tOutputPin.wPID         = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].wPID;
            pDemuxInfo->tOutputPin.fSendPayload = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].fSendPayload;
            pDemuxInfo->tOutputPin.tTimeType    = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].tTimeType;
            pDemuxInfo->tOutputPin.tStreamType  = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].tStreamType;
            pDemuxInfo->tOutputPin.pDestStream  = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].pDestStream;
            break;
        }
    }

} /* end MP3_DemuxUpdate() */

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/**              procedure MP3_GetValidPacket()                        **/
/**                                                                    **/
/** PURPOSE: To get a payload buffer from the input stream.            **/
/**                                                                    **/
/************************************************************************/
/************************************************************************/
BOOLEAN MP3_GetValidPacket( MP3DEMUXINFO *configInfo, ULONG ulLine )
{

    BOOLEAN           fRet = MP3_FAILURE;
    DEMUXIOSTREAM     *pInputPin  = NULL;
    DEMUXINPUTMESSAGE *pInMessage = NULL;

    pInputPin = configInfo->tConfigInfo.tInputPin;

    if( pInputPin != NULL )
    {

        /* Delete the old payload */
        if( configInfo->ulInputSize == 0 )
        {
            if( configInfo->messInput != NULL )
            {  
		        delete (DEMUXPAYLOAD *)configInfo->messInput->payload;
                configInfo->messInput->payload = NULL;
                pInputPin->ReleaseMsg( configInfo->messInput );
                configInfo->messInput = NULL;
            }
        }
    
        /* Get a new message with more data */
        pInMessage = (DEMUXINPUTMESSAGE *)pInputPin->Read( OS_WAIT_FOREVER );
        if( pInMessage != NULL )
        {
            configInfo->messInput   = (DEMUXINPUTMESSAGE *)pInMessage;
            configInfo->pbInputData = (BYTE *)KSEG0( (configInfo->messInput->payload->get_rd_ptr()) );
            configInfo->ulInputSize = configInfo->messInput->payload->get_size();
            fRet = MP3_SUCCESS;
        }
    }

    return( fRet );

} /* end MP3_GetValidPacket() */

/************************************************************************/
/************************************************************************/
/**                                                                    **/
/************************************************************************/
/************************************************************************/
BOOLEAN MP3_GetHeader( MP3DEMUXINFO *configInfo )
{

  BYTE    *pbData;
  ULONG   ulSize;
  BOOLEAN fPrintDebug = FALSE;
  BOOLEAN fRet;

  fRet = MP3_FAILURE;

 //Stay here until a valid MP3 has been found
  while( fRet == MP3_FAILURE )
  {
   //Get the current header
    if( configInfo->ulInputSize < 4 )
    {
      pbData = (BYTE *)&configInfo->tMP3Header;
      ulSize = configInfo->ulInputSize;

     //Save the current data set
      memcpy( pbData, configInfo->pbInputData, ulSize );

     //Get a new payload
      configInfo->ulInputSize = 0; //Force the deletion of the old payload
      MP3_GetValidPacket( configInfo, __LINE__ );

      pbData += ulSize;
      ulSize  = 4 - ulSize;
      memcpy( pbData, configInfo->pbInputData, ulSize );

    }
    else
    {
      ulSize = 4;
      memcpy( (BYTE *)&configInfo->tMP3Header, configInfo->pbInputData, ulSize );
    }

   //Verify the current header
    if( (configInfo->tMP3Header.ulSyncVal == 0x0fff       ) &&
        (configInfo->tMP3Header.ulID      ==      1       ) &&
        (configInfo->tMP3Header.ulLayer   == MP3_LAYER_III) &&
        (configInfo->tMP3Header.ulBitRate != 0x00         ) &&
        (configInfo->tMP3Header.ulBitRate != 0x0f         ) )
    {

      configInfo->pbInputData += ulSize;
      configInfo->ulInputSize -= ulSize;

      fRet = MP3_SUCCESS;
    }
    else
    {
      if( fPrintDebug == FALSE )
      {
        DbgPrint(("MP3_GetHeader:Header out of sync %d\n", (int)ulMP3FrameCount));
        fPrintDebug = TRUE;
      }

⌨️ 快捷键说明

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