aud.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:14k
源码类别:

DVD

开发平台:

C/C++

  1. /*****************************************************************************
  2. File name: aud.c
  3. Description: Audio setup and starting
  4. COPYRIGHT (C) 2004 STMicroelectronics
  5. *****************************************************************************/
  6. /* Includes --------------------------------------------------------------- */
  7. #include <string.h>
  8. #include "stlite.h"
  9. #include "stdevice.h"
  10. #include "stsys.h"
  11. #include "sttbx.h"
  12. #include "section.h"   /* memory partitions */
  13. #include "errors.h"
  14. #include "evt.h"
  15. #include "avmem.h"
  16. #include "clkrv.h"
  17. #include "aud.h"
  18. #include "stpti_hal.h"
  19. #include "avslot.h"
  20. /* Private Types ------------------------------------------------------ */
  21. /* Private Constants -------------------------------------------------- */
  22. /* Private Variables -------------------------------------------------- */
  23. /* Private Macros ----------------------------------------------------- */
  24. #define AUDIO_DEFAULT_PTI_INSTANCE  0
  25. /* Private Function prototypes ---------------------------------------- */
  26. /* Global Variables --------------------------------------------------- */
  27. STAUD_Handle_t  AUD_Handle;
  28. ST_DeviceName_t AUD_DeviceName="AUDIO";
  29. /* Functions ---------------------------------------------------------- */
  30. /* Functions ---------------------------------------------------------- */
  31. /* INTERFACE OBJECT: WRAPPER FCT TO LINK PTI AND VIDEO */
  32. /*-------------------------------------------------------------------------
  33.  * Function: AUD_GetPESBuffWritePtr
  34.  * Decription: Gets the PES Buffer Write Pointer from PTI
  35.  * Input   : PTI Buffer Handle
  36.  * Output  :
  37.  * Return  : Error code and the Audio Input Buffer Address
  38.  * ----------------------------------------------------------------------*/
  39. static ST_ErrorCode_t AUD_GetPESBuffWritePtr(void * const Handle_p, void ** const Address_p)
  40. {
  41.     ST_ErrorCode_t Err;
  42.     /* just cast the handle */
  43.     Err = STPTI_BufferGetWritePointer((STPTI_Buffer_t)Handle_p,Address_p);
  44.     return(Err);
  45. }
  46. /*-------------------------------------------------------------------------
  47.  * Function: AUD_SetPESBuffReadPtrFct
  48.  * Decription: Sets the PTI Read Pointer.
  49.  * Input   : PTI Buffer Handle and the Audio Buffer Address
  50.  * Output  :
  51.  * Return  : Error code
  52.  * ----------------------------------------------------------------------*/
  53. static ST_ErrorCode_t AUD_SetPESBuffReadPtrFct(void * const Handle_p, void * const Address_p)
  54. {
  55.     ST_ErrorCode_t Err;
  56.     /* just cast the handle */
  57.     Err = STPTI_BufferSetReadPointer((STPTI_Buffer_t)Handle_p,Address_p);
  58.     if ( Err != ST_NO_ERROR )
  59.     {
  60.         STTBX_Print(( "PTI_BufferSetReadPointer()Failed %sn", KB_ErrorGetText(Err)));
  61.     }
  62.     return(Err);
  63. }
  64. /*-------------------------------------------------------------------------
  65. * Function : AUD_Setup
  66. *            Initialise Audio
  67. * Input    : service mode
  68. * Output   :
  69. * Return   : Error Code
  70. * ----------------------------------------------------------------------*/
  71. ST_ErrorCode_t AUD_Setup(KB_ServiceMode SERVICE_Mode)
  72. {
  73.     ST_ErrorCode_t           ST_ErrorCode;
  74.     STAUD_InitParams_t       STAUD_InitParams;
  75.     STAUD_OpenParams_t       STAUD_OpenParams;
  76.     STAUD_BroadcastProfile_t STAUD_BroadcastProfile;
  77.     ST_ErrorCode = KB_ServiceAUDInitPara(SERVICE_Mode, &STAUD_InitParams, &STAUD_BroadcastProfile);
  78.     if (ST_ErrorCode != ST_NO_ERROR)
  79.     {
  80.         return( ST_ErrorCode );
  81.     }
  82.     STAUD_InitParams.DeviceType                   = AUD_DEVICE_TYPE ;
  83.     STAUD_InitParams.InterfaceType                = AUD_INTERFACE_TYPE;
  84.     STAUD_InitParams.CDInterfaceType              = AUD_CD_INTERFACE_TYPE;
  85.     STAUD_InitParams.CD2InterfaceType             = AUD_CD2_INTERFACE_TYPE;
  86.     STAUD_InitParams.CD1BufferAddress_p           = NULL;
  87.     STAUD_InitParams.CD1BufferSize                = 0;
  88.     STAUD_InitParams.CD2BufferAddress_p           = NULL;
  89.     STAUD_InitParams.CD2BufferSize                = 0;
  90.     STAUD_InitParams.InternalPLL                  = TRUE;
  91.     STAUD_InitParams.DACClockToFsRatio            = AUD_CLOCKRATIO;
  92.     STAUD_InitParams.PCMOutParams.InvertWordClock = AUD_PCMPARAM_INVWORD;
  93.     STAUD_InitParams.PCMOutParams.Format          = AUD_PCMPARAM_FORMAT;
  94.     STAUD_InitParams.PCMOutParams.InvertBitClock  = FALSE;
  95.     STAUD_InitParams.PCMOutParams.Precision       = AUD_DAC_DATA_PRECISION;
  96.     STAUD_InitParams.PCMOutParams.Alignment       = AUD_DAC_DATA_ALIGNMENT;
  97.     STAUD_InitParams.PCMOutParams.MSBFirst        = FALSE;
  98.     STAUD_InitParams.MaxOpen                      = 1;
  99.     STAUD_InitParams.CPUPartition_p               = SystemPartition;
  100.     STAUD_InitParams.AVMEMPartition               = g_KBAvmemPartitionHandle[0];
  101.     STAUD_InitParams.InterruptNumber              = AUDIO_INTERRUPT;
  102.     STAUD_InitParams.InterruptLevel               = AUDIO_INTERRUPT_LEVEL;
  103.     STAUD_InitParams.CD1InterruptNumber           = AUD_CD1_INTERRUPT_NUMBER;
  104.     STAUD_InitParams.PCMInterruptNumber           = AUD_PCM_INTERRUPT_NUMBER;
  105.     STAUD_InitParams.CD1InterruptLevel            = AUDIO_INTERRUPT_LEVEL;
  106.     STAUD_InitParams.PCMInterruptLevel            = AUDIO_INTERRUPT_LEVEL;
  107.     /* Configure interface to AUDIO registers */
  108.     STAUD_InitParams.InterfaceParams.EMIParams.BaseAddress_p = (void *)AUDIO_BASE_ADDRESS;
  109.     STAUD_InitParams.InterfaceParams.EMIParams.RegisterWordWidth = AUD_REGISTER_WORD_WIDTH;
  110.     /* Configure interface to ADSC registers */
  111.     STAUD_InitParams.CDInterfaceParams.EMIParams.BaseAddress_p = (void *)AUD_CD_INTERFACE_BASE_ADDRESS;
  112.     STAUD_InitParams.CDInterfaceParams.EMIParams.RegisterWordWidth = AUD_REGISTER_WORD_WIDTH;
  113.     STAUD_InitParams.CD2InterfaceParams.EMIParams.BaseAddress_p = (void *)AUD_CD2_INTERFACE_BASE_ADDRESS;
  114.     STAUD_InitParams.CD2InterfaceParams.EMIParams.RegisterWordWidth = AUD_REGISTER_WORD_WIDTH;
  115.     STAUD_InitParams.ClockGeneratorBaseAddress_p  = (void *)CKG_BASE_ADDRESS;
  116.     STAUD_InitParams.PCM1QueueSize = AUD_PCM1_QUEUE_SIZE;
  117.     /* For AC3 Support */
  118.     #ifdef AC3_DECODE
  119.         STAUD_InitParams.SPDIFMode = AC3_OVER_SPDIF;
  120.     #else
  121.         STAUD_InitParams.SPDIFMode = PCM_OVER_SPDIF;
  122.     #endif
  123.     STAUD_InitParams.PCMMode = PCM_ON;
  124.     strcpy(STAUD_InitParams.EvtHandlerName,    "EVT" );
  125.     strcpy(STAUD_InitParams.ClockRecoveryName, g_KBCLKRVDeviceName        );
  126.     STTBX_Print(("AUD_Setup(%s)=", AUD_DeviceName ));
  127.     ST_ErrorCode = STAUD_Init(AUD_DeviceName, &STAUD_InitParams);
  128.     if (ST_ErrorCode != ST_NO_ERROR)
  129.     {
  130.         STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  131.         return( ST_ErrorCode );
  132.     }
  133.     STTBX_Print(("%sn", STAUD_GetRevision() ));
  134.     STAUD_OpenParams.SyncDelay = 0;
  135.     STTBX_Print(("AUD_Open="));
  136.     ST_ErrorCode = STAUD_Open(AUD_DeviceName,&STAUD_OpenParams, &AUD_Handle);
  137.     STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  138.     if (ST_ErrorCode != ST_NO_ERROR)
  139.         return( ST_ErrorCode );
  140.     ST_ErrorCode = STAUD_DRSetBroadcastProfile(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, STAUD_BroadcastProfile);
  141.     if (ST_ErrorCode != ST_NO_ERROR)
  142.     {
  143.         STTBX_Print(("AUD_DRSetBroadcastProfile=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  144.         return( ST_ErrorCode );
  145.     }
  146. #if 0
  147.     STAUD_SpeakerEnable.Left          = TRUE;
  148.     STAUD_SpeakerEnable.Right         = TRUE;
  149.     STAUD_SpeakerEnable.LeftSurround  = AUD_SPKR_LEFTSURROUND;
  150.     STAUD_SpeakerEnable.RightSurround = AUD_SPKR_RIGHTSURROUND;
  151.     STAUD_SpeakerEnable.Center        = AUD_SPKR_CENTER;
  152.     STAUD_SpeakerEnable.Subwoofer     = AUD_SPKR_SUBWOOFER;
  153.     ST_ErrorCode = STAUD_OPSetSpeakerEnable(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, &STAUD_SpeakerEnable);
  154.     if (ST_ErrorCode != ST_NO_ERROR)
  155.     {
  156.         STTBX_Print(("AUD_OPSetSpeakerEnable=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  157.     }
  158. #endif
  159. #if 0 //TMTM comment off
  160.     /* Link corresponding Audio and PTI */
  161.     STTBX_Print(("AUD_Link(%d)=", AUDIO_DEFAULT_PTI_INSTANCE));
  162.     ST_ErrorCode = AUD_Link( AUDIO_DEFAULT_PTI_INSTANCE );
  163.     STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode)));
  164. #else
  165.     /* Link corresponding Audio and PTI */
  166.     STTBX_Print(("AUD_Link(%d)=", AUDIO_DEFAULT_PTI_INSTANCE));
  167.     ST_ErrorCode = PTI_LinkAudio( AUDIO_DEFAULT_PTI_INSTANCE );
  168.     STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode)));
  169. #endif
  170.     return( ST_ErrorCode );
  171. }
  172. /*-------------------------------------------------------------------------
  173.  * Function : AUD_Link
  174.  *            Link the correspoding PTI to Video
  175.  * Input    :
  176.  * Output   :
  177.  * Return   : ErrorCode
  178.  * ----------------------------------------------------------------------*/
  179. ST_ErrorCode_t PTI_LinkAudio (U32 PTIInst)
  180. {
  181.     ST_ErrorCode_t          ST_ErrorCode;
  182.     STAUD_BufferParams_t    BufferParams;
  183. #ifdef AC3_DECODE
  184.     ST_ErrorCode = STAUD_IPGetInputBufferParamsCompressed(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, &BufferParams);
  185.     if (ST_ErrorCode != ST_NO_ERROR)
  186.     {
  187.         STTBX_Print (("AUD_GetDataInputBufferParams=%sn",KB_ErrorGetText(ST_ErrorCode)));
  188.         return(ST_ErrorCode);
  189.     }
  190. #else
  191.         ST_ErrorCode = STAUD_IPGetInputBufferParams(AUD_Handle, STAUD_OBJECT_DECODER_COMPRESSED1, &BufferParams);
  192.     if (ST_ErrorCode != ST_NO_ERROR)
  193.     {
  194.         STTBX_Print (("AUD_GetDataInputBufferParams=%sn",KB_ErrorGetText(ST_ErrorCode)));
  195.         return(ST_ErrorCode);
  196.     }
  197. #endif
  198.     ST_ErrorCode = STPTI_BufferAllocateManual(  g_KB_PTIHandleMultiple[PTIInst],
  199.                                                 BufferParams.BufferBaseAddr_p, BufferParams.BufferSize,
  200.                                                 1, &PTI_AudioBufferHandle);
  201.     if (ST_ErrorCode != ST_NO_ERROR)
  202.     {
  203.         STTBX_Print (("PTI_BufferAllocateManual=%sn",KB_ErrorGetText(ST_ErrorCode)));
  204.         return(ST_ErrorCode);
  205.     }
  206.     /* No cd-fifo: Initialise the link between pti and audio */
  207.     ST_ErrorCode = STPTI_SlotLinkToBuffer(PTI_SlotHandle_Multiple[PTIInst][SLOTAUD], PTI_AudioBufferHandle);
  208.     if (ST_ErrorCode != ST_NO_ERROR)
  209.     {
  210.         STTBX_Print (("PTI_SlotLinkToBuffer=%sn",KB_ErrorGetText(ST_ErrorCode)));
  211.         return(ST_ErrorCode);
  212.     }
  213.     ST_ErrorCode = STPTI_BufferSetOverflowControl(PTI_AudioBufferHandle, TRUE);
  214.     if (ST_ErrorCode != ST_NO_ERROR)
  215.     {
  216.         STTBX_Print (("PTI_BufferSetOverflowControl=%sn",KB_ErrorGetText(ST_ErrorCode)));
  217.         return(ST_ErrorCode);
  218.     }
  219. #ifdef AC3_DECODE
  220.     ST_ErrorCode = STAUD_IPSetDataInputInterfaceCompressed(AUD_Handle,
  221.                                                  STAUD_OBJECT_DECODER_COMPRESSED1,
  222.                                                  AUD_GetPESBuffWritePtr,
  223.                                                  AUD_SetPESBuffReadPtrFct,
  224.                                                  (void *)PTI_AudioBufferHandle);
  225.     if (ST_ErrorCode != ST_NO_ERROR)
  226.     {
  227.         STTBX_Print (("AUD_SetDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
  228.         return(ST_ErrorCode);
  229.     }
  230. #else
  231.     ST_ErrorCode = STAUD_IPSetDataInputInterface(AUD_Handle,
  232.                                                  STAUD_OBJECT_DECODER_COMPRESSED1,
  233.                                                  AUD_GetPESBuffWritePtr,
  234.                                                  AUD_SetPESBuffReadPtrFct,
  235.                                                  (void *)PTI_AudioBufferHandle);
  236.     if (ST_ErrorCode != ST_NO_ERROR)
  237.     {
  238.         STTBX_Print (("AUD_SetDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
  239.         return(ST_ErrorCode);
  240.     }
  241. #endif
  242.     return (ST_ErrorCode);
  243. }
  244. /*-------------------------------------------------------------------------
  245.  * Function : AUD_Unlink
  246.  *            Unlink the correspoding PTI to Video
  247.  * Input    :
  248.  * Output   :
  249.  * Return   : ErrorCode
  250.  * ----------------------------------------------------------------------*/
  251. ST_ErrorCode_t PTI_UnlinkAudio(U32 PTIInst)
  252. {
  253.     ST_ErrorCode_t ST_ErrorCode;
  254. #if 0
  255.     ST_ErrorCode = STAUD_DeleteDataInputInterface(AUD_Handle);
  256.     if (ST_ErrorCode != ST_NO_ERROR)
  257.     {
  258.         STTBX_Print (("AUD_DeleteDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
  259.         return(ST_ErrorCode);
  260.     }
  261. #endif
  262.     ST_ErrorCode = STPTI_BufferFlush(PTI_AudioBufferHandle);
  263.     if (ST_ErrorCode != ST_NO_ERROR)
  264.     {
  265.         STTBX_Print (("PTI_BufferFlush=%sn",KB_ErrorGetText(ST_ErrorCode)));
  266.         return(ST_ErrorCode);
  267.     }
  268.     ST_ErrorCode = STPTI_SlotUnLink(PTI_SlotHandle_Multiple[PTIInst][SLOTAUD]);
  269.     if (ST_ErrorCode != ST_NO_ERROR)
  270.     {
  271.         STTBX_Print (("PTI_SlotUnLink=%sn",KB_ErrorGetText(ST_ErrorCode)));
  272.         return(ST_ErrorCode);
  273.     }
  274.     ST_ErrorCode = STPTI_BufferDeallocate(PTI_AudioBufferHandle);
  275.     if (ST_ErrorCode != ST_NO_ERROR)
  276.     {
  277.         STTBX_Print (("PTI_BufferDeallocate=%sn",KB_ErrorGetText(ST_ErrorCode)));
  278.         return(ST_ErrorCode);
  279.     }
  280.     return (ST_ErrorCode);
  281. }
  282. /*-------------------------------------------------------------------------
  283. * Function : AUD_Start
  284. *            Start Decoding Audio
  285. * Input    :
  286. * Output   :
  287. * Return   : ErrorCode
  288. * ----------------------------------------------------------------------*/
  289. ST_ErrorCode_t AUD_Start(STAUD_StartParams_t *STAUD_StartParams_p)
  290. {
  291.     ST_ErrorCode_t ST_ErrorCode;
  292.     ST_ErrorCode = STAUD_Start(AUD_Handle, STAUD_StartParams_p);
  293.     STTBX_Print(("STAUD_Start(%d,%d,%d,%02.2x)=%s",
  294.                 STAUD_StartParams_p->StreamContent,     STAUD_StartParams_p->StreamType,
  295.                 STAUD_StartParams_p->SamplingFrequency, STAUD_StartParams_p->StreamID,
  296.                 KB_ErrorGetText(ST_ErrorCode) ));
  297.     return ( ST_ErrorCode );
  298. }
  299. //TMTM added
  300. ST_ErrorCode_t AUD_Term(void)
  301. {
  302. ST_ErrorCode_t ST_ErrorCode;
  303. STAUD_TermParams_t TermParams;
  304.     /*ST_ErrorCode = STAUD_Close(AUD_Handle);
  305. if (ST_ErrorCode != ST_NO_ERROR)
  306. {
  307. STTBX_Print(("STAUD_Close()=%s", KB_ErrorGetText(ST_ErrorCode) ));
  308. }*/
  309. TermParams.ForceTerminate = TRUE;
  310. ST_ErrorCode = STAUD_Term(AUD_DeviceName, &TermParams);
  311. if (ST_ErrorCode != ST_NO_ERROR)
  312. {
  313. STTBX_Print(("STAUD_Term()=%s", KB_ErrorGetText(ST_ErrorCode) ));
  314. }
  315. return ( ST_ErrorCode );
  316. }
  317. /* EOF --------------------------------------------------------------------- */