/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: xhui.xie $
 * $Date: 2016/02/19 $
 * $RCSfile: swdmx_if.h,v $
 * $Revision: #6 $
 *
 *---------------------------------------------------------------------------*/

/** @file swdmx_if.h
 *  Public interface of software program stream demux driver
 */


#ifndef SWDMX_IF_H
#define SWDMX_IF_H

#ifndef SWDMX_DBG_USB
//#define SWDMX_DBG_USB
#endif

#ifndef SWDMX_DBG_SEMIHOST
//#define SWDMX_DBG_SEMIHOST
#endif

//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------

/*lint -save -e961 */
#include "x_common.h"
#include "x_typedef.h"
#include "x_timer.h"
#include "x_assert.h"
#include "x_os.h"
#include "x_bim.h"
#include "x_clksrc.h"
#include "x_hal_5381.h"
#include "x_hal_926.h"

//#define DEFINE_IS_LOG   SWDMX_IsLog
//#include "x_debug.h"
/*lint -restore */

#include "drv_common.h"
#include "dmx_if.h"
#include "mpv_if.h"
#include "mpv_drvif.h"
#include "vdp_if.h"
#include "vdp_drvif.h"
#include "pmx_if.h"
#include "aud_if.h"
#include "feeder_if.h"


//-----------------------------------------------------------------------------
// Configurations
//-----------------------------------------------------------------------------

#define SWDMX_DRV_OK                   ((INT32) 0)
#define SWDMX_DRV_SET_FAILED         ((INT32) -262)
#define SWDMX_DRV_INV_GET_INFO       ((INT32) -258)
#define SWDMX_DRV_INV_SET_INFO       ((INT32) -259) /**<the set operation is invalid or cannot be processed*/

// It is better to sync this with PLAYMGR_MAX_VID_TRACK
#define SWDMX_MAX_VID_TRACK    0x00000008
#define SWDMX_MAX_AUD_TRACK    0x00000010
#define SWDMX_MAX_SUB_TRACK    0x00000008
#define SWDMX_MAX_PCR_TRACK    0x00000001
#define SWDMX_MAX_PROGRAM      0x00000060

// SWDMX_STREAM_INFO
#define SWDMX_STREAM_INFO_MASK_NONE             0x00000000
#define SWDMX_STREAM_INFO_MASK_TRACK            0x00000001
#define SWDMX_STREAM_INFO_MASK_RESOLUTION       0x00000002

#define SWDMX_VID_PID_INDEX                     0x00000000
#define SWDMX_AUD_PID_INDEX                     0x00000001

#define SWDMX_MAX_HDR_SIZE 8
#define SWDMX_MVC_HDR_SIZE 8

//-----------------------------------------------------------------------------
// Constant definitions
//-----------------------------------------------------------------------------
#define SWDMX_PROGRAM_SOURCE 0x00
#define SWDMX_AUDIO_ONLY_SOURCE 0x01

#define SWDMX_PRIMARY_SOURCE 0x00
#define SWDMX_SECONDARY_SOURCE 0x01
#define SWDMX_THIRD_SOURCE 0x02
#define SWDMX_4th_SOURCE 0x03
#define SWDMX_5th_SOURCE 0x04
#if defined(CC_SKYPE_FINE_INSTANCE)
#define SWDMX_SOURCE_MAX 0x05
#elif defined(CC_FBM_FOUR_INST_SUPPORT)
#define SWDMX_SOURCE_MAX 0x04
#elif defined(CC_FBM_TWO_FBP)
#define SWDMX_SOURCE_MAX 0x02
#else
#define SWDMX_SOURCE_MAX 0x01
#endif
#define SWDMX_UNKNOWN_SOURCE 0xFF

//#define CC_SWDMX_RENDER_PTS
#define CC_SWDMX_RENDER_POSITION
//#define CC_SWDMX_RENDER_POSITION_TEST
#define UNDERFLOW_CHECK_USE_TIME_LIMIT
#define SWDMX_YOUVIEW_FAST_START

#ifdef SWDMX_YOUVIEW_FAST_START
#define SWDMX_YOUVIEW_FAST_START_STORE_KEY
#endif /* SWDMX_YOUVIEW_FAST_START */
#define DRV_APPLY_SWDMX_DESCRAMBLER
//-----------------------------------------------------------------------------
// Type definitions
//-----------------------------------------------------------------------------

/** the notify conditions.
  This structure match to the one in mw. Can't change it's sequence.
*/
typedef enum
{
    SWDMX_COND_ERROR = -1,
    SWDMX_COND_CTRL_DONE,
    SWDMX_COND_SUBTITLE
}   SWDMX_COND_T;

typedef enum
{
   SWDMX_PLAY_MODE_NORMAL,
   SWDMX_PLAY_MODE_IFRAME
}SWDMX_PLAY_MODE_T;

/**This notification function is called by the video decoder in response to some events.
*/
typedef void (*PFN_SWDMX_NFY_FCT) (
    void*               pvNfyTag,
    SWDMX_COND_T        eNfyCond,
    UINT32              u4Data1,
    UINT32              u4Data2
);

/**This structure contains a video decoders notify function and tag.
*/
typedef struct
{
    void*  pvTag;
    PFN_SWDMX_NFY_FCT  pfSwdmxNfy;
}SWDMX_NFY_INFO_T;



/** file format.
*/
typedef enum
{
    SWDMX_FMT_UNKNOWN,
    SWDMX_FMT_AVI,
    SWDMX_FMT_MPEG1_DAT,
    SWDMX_FMT_MPEG2_PS,
    SWDMX_FMT_MPEG2_TS,         // 188 ts
    SWDMX_FMT_MPEG2_TS_192,     // 192 ts, time case
    SWDMX_FMT_MPEG2_TS_ZERO_192,// 4 byte 192 ts
    SWDMX_FMT_MPEG2_TS_ENCRYPT_192,
    SWDMX_FMT_MPEG2_TS_130,             // RVU  130 support
    SWDMX_FMT_MPEG2_TS_134,             // RVU  134 support
    SWDMX_FMT_MPEG2_TS_204,     //188+16 (FEC data)
    SWDMX_FMT_MPEG2_TS_206,     //192+14(PCP header)
    SWDMX_FMT_MPEG2_TS_TIME_SHIFT,// time shift 192 ts
    SWDMX_FMT_VC1_ES,
    SWDMX_FMT_MPEG2_VIDEO_ES,
    SWDMX_FMT_MPEG4_VIDEO_ES,
    SWDMX_FMT_H264_VIDEO_ES,
    SWDMX_FMT_H265_VIDEO_ES,
    SWDMX_FMT_AVS_VIDEO_ES,
    SWDMX_FMT_DV_VIDEO_ES,
    SWDMX_FMT_RAW_AUDIO_ES, // last one for ES, should not change this order.
    SWDMX_FMT_MP3_AUDIO_ES,
    SWDMX_FMT_VC1_WMV,
    SWDMX_FMT_WMA_AUDIO_ES,
    SWDMX_FMT_MP4,
    SWDMX_FMT_M4A,
    SWDMX_FMT_MKV,
    SWDMX_FMT_RM,
    SWDMX_FMT_FLV,
    SWDMX_FMT_CMPB,            // private container for CMPB
    SWDMX_FMT_ES_WITH_PTS,
    SWDMX_FMT_OGM,
    SWDMX_FMT_OGG_AUDIO_ES,
    SWDMX_FMT_APE_AUDIO_ES,
    SWDMX_FMT_TS_OUT
}   ENUM_SWDMX_FMT_T;


typedef enum
{
    eSWDMX_STRM_TYPE_UNKNOWN,
    eSWDMX_STRM_TYPE_VID,
    eSWDMX_STRM_TYPE_VID2,
    eSWDMX_STRM_TYPE_AUD,
    eSWDMX_STRM_TYPE_AUD2,
    eSWDMX_STRM_TYPE_AUD3, // 0831
    eSWDMX_STRM_TYPE_SUBTITLE,
    eSWDMX_STRM_TYPE_PCR,
    eSWDMX_STRM_TYPE_MAX
} ENUM_SWDMX_STRM_TYPE_T;


/**The video codec format*/
typedef enum{
    ENUM_SWDMX_VDEC_UNKNOWN,
    ENUM_SWDMX_VDEC_MPEG1_MPEG2,
    ENUM_SWDMX_VDEC_DX311,
    ENUM_SWDMX_VDEC_MPEG4,
    ENUM_SWDMX_VDEC_H264,
    ENUM_SWDMX_VDEC_MVC,
    ENUM_SWDMX_VDEC_VC1,
    ENUM_SWDMX_VDEC_WMV7,
    ENUM_SWDMX_VDEC_WMV8,
    ENUM_SWDMX_VDEC_WMV9,
    ENUM_SWDMX_VDEC_MJPEG,
    ENUM_SWDMX_VDEC_RV,
    ENUM_SWDMX_VDEC_H263,
    ENUM_SWDMX_VDEC_VP6,
    ENUM_SWDMX_VDEC_VP8,
    ENUM_SWDMX_VDEC_RAW_NV12,
    ENUM_SWDMX_VDEC_AVS,
    ENUM_SWDMX_VDEC_MULTITRACK,
    ENUM_SWDMX_VDEC_H265,
    ENUM_SWDMX_VDEC_VP9,
    ENUM_SWDMX_VDEC_DV_H264,
    ENUM_SWDMX_VDEC_DV_H265,
    ENUM_SWDMX_VDEC_MAX
}ENUM_SWDMX_VDEC_T;


/**Audio decoder format.*/
typedef enum{
    ENUM_SWDMX_ADEC_UNKNOWN = 0,
    ENUM_SWDMX_ADEC_MPEG,
    ENUM_SWDMX_ADEC_AC3,
    ENUM_SWDMX_ADEC_PCM,
    ENUM_SWDMX_ADEC_MP3,
    ENUM_SWDMX_ADEC_AAC,
    ENUM_SWDMX_ADEC_DTS,
    ENUM_SWDMX_ADEC_WMA,
    ENUM_SWDMX_ADEC_RA,
    ENUM_SWDMX_ADEC_HDCD,
    ENUM_SWDMX_ADEC_MLP,
    ENUM_SWDMX_ADEC_MTS,
    ENUM_SWDMX_ADEC_A2,
    ENUM_SWDMX_ADEC_PAL,
    ENUM_SWDMX_ADEC_FMFM,
    ENUM_SWDMX_ADEC_NICAM,
    ENUM_SWDMX_ADEC_TTXAAC,
    ENUM_SWDMX_ADEC_DETECTOR,
    ENUM_SWDMX_ADEC_VORBIS,
    ENUM_SWDMX_ADEC_MINER
}ENUM_SWDMX_ADEC_T;


/**Subpic format.*/
typedef enum{
    ENUM_SWDMX_SUBPIC_UNKNOWN = 0,
    ENUM_SWDMX_SUBPIC_MAX
}ENUM_SWDMX_SUBPIC_T;

typedef enum
{
    eSWDMX_STATE_STOP,          // stop
    eSWDMX_STATE_PAUSE,         // pause
    eSWDMX_STATE_PLAY,          // play
    eSWDMX_STATE_CMPB_FLUSH,
    eSWDMX_STATE_MAX
} ENUM_SWDMX_PLAY_STATE_T;

typedef enum
{
    eSWDMX_BUF_MODE_DEFAULT,
    eSWDMX_BUF_MODE_TIME,
    eSWDMX_BUF_MODE_BYTE,
    eSWDMX_BUF_MODE_MAX
}ENUM_SWDMX_BUFFER_TYPE_T;
typedef enum
{
    eSWDMX_TYPE_BYTE_SEEK = 0,
    eSWDMX_TYPE_TIME_SEEK
}ENUM_SWDMX_SEEK_TYPE_T;

typedef enum _SWDMX_SET_DECODER_TYPE
{
    eSWDMX_SET_VIDSEQHEADER,
    eSWDMX_SET_VIDEOTYPE,
    eSWDMX_SET_SUBVIDEOTYPE,
    eSWDMX_SET_VIDEO2TYPE,
    eSWDMX_SET_AUDIOTYPE,
    eSWDMX_SET_AUDIO2TYPE,   // 0831, support second audio
    eSWDMX_SET_AUDIO3TYPE,   // 0831
    eSWDMX_SET_SYSTEMINFO,
    eSWDMX_ENABLE_STREAM,
    eSWDMX_DISABLE_STREAM,
    eSWDMX_SET_RANGECALLBACK,
    eSWDMX_SET_RANGECALLBACKEX,
    eSWDMX_SET_CHK_PSI_BUF_SIZE, // should be eSWDMX_CHK_PSI_BUF_SIZE
    eSWDMX_TOTAL_DURATION,
    eSWDMX_SET_FEEDER_TEST_FUNCTION,
    eSWDMX_SET_SUBTITLECALLBACK,
    eSWDMX_GET_CURRENT_POSITION,
    eSWDMX_GET_FILE_OFFSET,
    eSWDMX_GET_IS_TRICK, // should be eSWDMX_GET_IS_TRICKABLE
    eSWDMX_CONTAINER_TYPE,
    eSWDMX_GET_INTERNAL_INFO,
    eSWDMX_SET_REC_BUF_RANGE,
    eSWDMX_PRINT_REC_BUF_STATUS,
    eSWDMX_PRINT_INTERNAL_STATUS,
    eSWDMX_SET_MONITOF_LBA,
    eSWDMX_GET_CURRENT_TICK,
    eSWDMX_GET_CURRENT_LBA,
    eSWDMX_SET_NETFLIX_STREAM_ID,
    eSWDMX_SET_NETFLIX_EOS,
    eSWDMX_GET_CURRENT_TIME,
    eSWDMX_PID_INDEX_START,
    eSWDMX_SET_TPT_VIDSEQHEADER,    //for divx plus
    eSWDMX_SET_AOUT_ENABLE,
    eSWDMX_SET_EOS,
    eSWDMX_SET_VIDEO_DECRYPT,
    eSWDMX_SET_AUDIO_DECRYPT,
    eSWDMX_SET_AUDIO2_DECRYPT,
    eSWDMX_SET_AUDIO3_DECRYPT, // 0831
    eSWDMX_SET_VID_PID_IDX,
    eSWDMX_SET_AUD_PID_IDX,
    eSWDMX_SET_PCR_PID_IDX,
    eSWDMX_GET_STC_OFFSET,
    eSWDMX_SET_VDEC_ID,  // maybe we will have vdp id
    eSWDMX_SET_VDEC2_ID,  // maybe we will have vdp id
    eSWDMX_SET_ADEC_ID,
    eSWDMX_SET_ADEC2_ID, // 0831
    eSWDMX_SET_ADEC3_ID, // 0831
    eSWDMX_SET_STC_ID,
    eSWDMX_SET_B2R_ID,
    eSWDMX_SET_DMX_ID,
    eSWDMX_SET_SRC_TYPE,
    eSWDMX_GET_INTERNAL_BUF,
    eSWDMX_SET_PLAYBACK_THRESHOLD,
    eSWDMX_GET_PLAYBACK_THRESHOLD,
    eSWDMX_GET_TIME_TO_BYTES_INFO,
    eSWDMX_SET_VID_SCRAMBLE_NFY,
    eSWDMX_SET_AUD_SCRAMBLE_NFY,
    eSWDMX_SET_SYSTEM_B,
    eSWDMX_GET_AUDIO_ACTIVE_PIDX,
    eSWDMX_GET_VIDEO_PIDX,  // get current active video pidx
    eSWDMX_GET_AUDIO_PIDX,  // get current active audio pidx
#if 1//def CC_MMP_BAD_INTERLEAVED_FILE_SUPPORT
    eSWDMX_SET_BAD_INTERLEAVED_INFO,
    eSWDMX_GET_BAD_INTERLEAVED_INFO,
#endif
    eSWDMX_SET_HDMVC_INFO,
    eSWDMX_GET_HDMVC_INFO,
#if 1//def SWDMX_DBG_USB
    eSWDMX_SET_DBGINFO,
    eSWDMX_GET_DBGINFO,
#endif // SWDMX_DBG_USB
    eSWDMX_GET_MM_SRC_TYPE,
    eSWDMX_SET_VID_CHG_CALLBACK,
    eSWDMX_SET_AUD_CHG_CALLBACK,
    eSWDMX_TYPE_VID_PID_CHG_DONE,
    eSWDMX_TYPE_AUD_PID_CHG_DONE,
    eSWDMX_TYPE_VID_CODEC_CHG_DONE,
    eSWDMX_TYPE_AUD_CODEC_CHG_DONE,
    eSWDMX_SET_FLUSHFEEDER,
    eSWDMX_GET_AUDIO_PTS_INFO,
    eSWDMX_GET_VIDEO_PTS_INFO,
    eSWDMX_TYPE_GNRC_ALL_STREAM_INFO,
    eSWDMX_SET_AD_PLAY_WITH_LASTMEMORY,
    eSWDMX_TYPE_GET_AUD_STREAM_INFO,
    eSWDMX_TYPE_SET_HDCP_KEY,
    eSWDMX_SET_DURATION,
    eSWDMX_SET_FILE_SZ_UPDATE,
    eSWDMX_SET_FILE_PUSH_CHANGE_AUDIO,
    eSWDMX_SET_TYPE_PCP_LEN,      //ts 206 PCB header
    eSWDMX_SET_TYPE_PCM_SAMPLE_SIZE,
#ifdef UNDERFLOW_CHECK_USE_TIME_LIMIT
    eSWDMX_SET_TYPE_UNDERFLOW_TIMELIMIT,
    eSWDMX_SET_TYPE_BUFREADY_TIMELIMIT,
    eSWDMX_GET_TYPE_UNDERFLOW_TIME2SIZE_INFO,
#endif /* UNDERFLOW_CHECK_USE_TIME_LIMIT */
#ifdef SWDMX_YOUVIEW_FAST_START
    eSWDMX_SET_TYPE_FAST_START_TIMELIMIT,
    eSWDMX_SET_TYPE_PLAYBACK_TIMELIMIT,
    eSWDMX_SET_TYPE_DATA_SPEED_VALID_DURATION,
    eSWDMX_SET_TYPE_EN_EARLY_SEND_AUD_PES,
    eSWDMX_SET_TYPE_LAST_MEM_USE_DMX_VCB_POS,
#endif /* SWDMX_YOUVIEW_FAST_START */
    eSWDMX_SET_TYPE_STEP_DONE,
    eSWDMX_GET_TYPE_GET_AUD_READY,
    eSWDMX_SET_MAX
}SWDMX_SET_DECODER_TYPE;

typedef enum
{
    eSWDMX_GET_UOP_TYPE_SEEK = 1,
    eSWDMX_GET_UOP_TYPE_TRICK
}SWDMX_GET_UOP_TYPE;

/// Scrambling state
typedef enum
{
    SWDMX_SCRAMBLE_STATE_CLEAR=0,           ///< Clear data
    SWDMX_SCRAMBLE_STATE_SCRAMBLED,       ///< Scrambled data
    SWDMX_SCRAMBLE_STATE_UNKNOWN          ///< Unknown data
} SWDMX_SCRAMBLE_STATE_T;


typedef struct SWDMX_STREAM_INFO
{
    // SWDMX_STREAM_INFO_MASK_TRACK
    UINT16 u2VideoNum;
    UINT16 u2AudioNum;
    UINT16 u2SubpicNum;
    UINT16 u2PcrNum;

    UINT16 au2VideoId[SWDMX_MAX_VID_TRACK];
    UINT16 au2SubVideoId[SWDMX_MAX_VID_TRACK];
    UINT16 au2AudioId[SWDMX_MAX_AUD_TRACK];
    UINT16 au2AudioSubId[SWDMX_MAX_AUD_TRACK];
    UINT16 au2SubpicId[SWDMX_MAX_SUB_TRACK];
    UINT16 au2PcrId[SWDMX_MAX_PCR_TRACK];

    UINT32 u4FirstPts;
    UINT32 u4TotalTime;

    UINT8 aau1VideoHdr[SWDMX_MAX_VID_TRACK][SWDMX_MAX_HDR_SIZE];

    ENUM_SWDMX_VDEC_T aeVideo[SWDMX_MAX_VID_TRACK];
    ENUM_SWDMX_VDEC_T aeSubVideo[SWDMX_MAX_VID_TRACK];
    ENUM_SWDMX_ADEC_T aeAudio[SWDMX_MAX_AUD_TRACK];
    ENUM_SWDMX_SUBPIC_T aeSubpic[SWDMX_MAX_SUB_TRACK]; // TS no caption
    //ENUM_SWDMX_SUBPIC_T aePcrpic[SWDMX_MAX_PCR_TRACK];

    // SWDMX_STREAM_INFO_MASK_RESOLUTION
    UINT32 u4Width[SWDMX_MAX_VID_TRACK];
    UINT32 u4Height[SWDMX_MAX_VID_TRACK];
} SWDMX_STREAM_INFO_T;


typedef struct SWDMX_PROGRAM_INFO
{
    // output
    UINT32 u4InfoMask;
    UINT32 u4PgmNum;
    SWDMX_STREAM_INFO_T rPgm[SWDMX_MAX_PROGRAM];
} SWDMX_PROGRAM_INFO_T;


typedef struct SWDMX_RANGE_INFO
{
    UINT32 u4CurRangeID;
    UINT64 u8CurRangePTS;
    UINT32 u4QRangeID;
    UINT64 u8QRangePTS;
}SWDMX_RANGE_INFO_T;

typedef struct SWDMX_READ_INFO
{
    UCHAR*  pucDest;
    UINT8   u1SerialNumber;
    UINT32  u4FrameAddr;
    UINT32  u4CopyLen;
}SWDMX_READ_INFO_T;

typedef enum
{
    ENUM_SWDMX_AUDIO_NOTIFY_DECODE_DONE,
    ENUM_SWDMX_AUDIO_NOTIFY_NO_DATA,
    ENUM_SWDMX_AUDIO_NOTIFY_RESUME_DONE,
    ENUM_SWDMX_AUDIO_NOTIFY_MAX
}ENUM_SWDMX_AUDIO_NOTIFY_TYPE_T;


typedef struct
{
    UINT8 u1FlavorID;
    UINT8 u1ChanNum;
    UINT32 u4SamplePerFrame;
    UINT32 u4CookSampRate;
    UINT16 u2FrameSzInBytes;
    UINT16 u2RegnNum;
    UINT16 u2StartRegn;
    UINT16 u2CplQBits;
    UINT16 u2CookBlockPerSB;
    UINT16 u2CookBlockSz;
    UINT16 u2CookFramePerBlock;
    UINT16 u2CookFramePerSB;
    UINT16 u2CookSBSz;
} COOK_INFO_T;

typedef enum
{
    eSWDMX_ST_UNKNOWN = -1,  /* Must be set to '-1' else I loose an entry in the bit mask. */
    eSWDMX_ST_AUDIO,
    eSWDMX_ST_VIDEO,
    eSWDMX_ST_CLOSED_CAPTION,
    eSWDMX_ST_ISDB_CAPTION,
    eSWDMX_ST_ISDB_TEXT,
    eSWDMX_ST_TELETEXT,
    eSWDMX_ST_SUBTITLE,
    eSWDMX_ST_DATA,
    eSWDMX_ST_BYPASS,
    eSWDMX_ST_MM_SUBTITLE,
    eSWDMX_ST_RCRD_STRM,
    eSWDMX_ST_GINGA_STOP_AUDIO,
    eSWDMX_ST_GINGA_STOP_VIDEO
}SWDMX_STREAM_TYPE_T;

typedef  UINT8  SWDMX_VID_ENC_T;    /**< Video Encoding type. */
typedef  UINT8  SWDMX_AUD_ENC_T;    /**< Audio Encoding type. */

typedef struct
{
    UINT32             ui4_aud_strm_id;       ///< PID
    UINT32             ui4_vid_strm_id;       ///< PID
    SWDMX_VID_ENC_T        e_vid_enc;
    SWDMX_AUD_ENC_T        e_aud_enc;
} SWDMX_BUF_AGT_CTRL_IBC_PARAM_STRM_INFO_T;

typedef struct
{
    UINT64    ui8_bandwidth;
    BOOL      b_bandwidth_chg;

}SWDMX_IBC_DASH_SET_INFO_T ;

typedef struct
{
    // For WFD no audio data but audio enabled case, invalidate
    // this flag to notify B2R not to ref AUD PTS to do A-V sync.
    BOOL      fgAudioValid;

    UINT32    u4Pts;
    INT32     i4DeltaPts;
    HAL_TIME_T  rDeltaTime;
}SWDMX_PTS_INFO_T ;

#ifdef SWDMX_DBG_USB
#define MM_DBG_MODE_LOGCRC              0X00000000
#define MM_DBG_MODE_SAVECRC            0X00000001
#define MM_DBG_MODE_AUTOCHECK        0X00000002
#define MM_DBG_MODE_SAVEDATA          0X00000003
#define MM_DBG_MODE_SAVEBLOCK         0X00000004
#define MM_DBG_MODE_MAX                   0X00000005

// return int(0, 1, 2, 3)
#define MM_DBG_MODE_VALUE( mode_now, mode_look )                \
(((mode_now) >> ((mode_look)*2)) & 0X03 )

// return BOOL(TRUE: source 1 on    FALSE: source 1 off)
#define MM_DBG_SOURCE1_ON( mode_now, mode_look )                \
(1 == ((((mode_now) >> ((mode_look)*2)) & 0X03 ) % 2) )

// return BOOL(TRUE: source 2 on    FALSE: source 2 off)
#define MM_DBG_SOURCE2_ON( mode_now, mode_look )                \
(1 == ((((mode_now) >> ((mode_look)*2)) & 0X03 ) / 2) )

typedef struct
{
    UINT32              u4Mode;

    HANDLE_T          hFileSaveCrc;
    HANDLE_T          hFileGetCrc;
    HANDLE_T          hFileSaveData;
    HANDLE_T          hFileSaveCrc1;
    HANDLE_T          hFileGetCrc1;
    HANDLE_T          hFileSaveData1;
}MM_DBG_INFO_T;
#endif // SWDMX_DBG_USB

//-----------------------------------------------------------------------------
// Macro definitions
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Prototype  of inter-file functions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Prototype  of public functions
//-----------------------------------------------------------------------------

EXTERN VOID SWDMX_Init(VOID);

EXTERN BOOL SWDMX_GetStreamInfo(UINT8 u1SrcId,
        ENUM_SWDMX_FMT_T eType,
        UINT32 u4InfoMask,
        UINT64 u8FileSize,
        SWDMX_PROGRAM_INFO_T* prPInfo);

EXTERN BOOL SWDMX_SetInfo(UINT8 u1SrcId, UINT8 u1Type,UINT32 u4Para1,UINT32 u4Para2,UINT32 u4Para3);

EXTERN BOOL SWDMX_GetInfo(UINT8 u1SrcId, UINT8 u1Type,UINT32* pu4Para1,UINT32* pu4Para2,UINT32* pu4Para3);

EXTERN BOOL SWDMX_SetSpeed(UINT8 u1SrcId, INT32 i4Speed);

EXTERN BOOL SWDMX_SeekTime(UINT8 u1SrcId, UINT64 u8SeekTime, UINT64* pu8FilePos);

EXTERN BOOL SWDMX_SeekPos(UINT8 u1SrcId, UINT64 u8SeekPos, UINT64 u8SeekPosI);

EXTERN BOOL SWDMX_SeekOffset(UINT8 u1SrcId, VOID *prPosition);

EXTERN BOOL SWDMX_SeekPercent(UINT8 u1SrcId, UINT32 u4SeekPercent, UINT64* pu8FilePos);

EXTERN BOOL SWDMX_RenderFromPos(UINT8 u1SrcId, VOID *prPosition);

EXTERN BOOL SWDMX_SetContainerType(UINT8 u1SrcId, ENUM_SWDMX_FMT_T eContainerType);
EXTERN BOOL SWDMX_FilterLog(UINT8 u1SrcId, BOOL fgAdd, UINT32 u4LogFilter);
EXTERN BOOL SWDMX_Play(UINT8 u1SrcId);

EXTERN BOOL SWDMX_Pause(UINT8 u1SrcId);

EXTERN BOOL SWDMX_PlayOneFrm(UINT8 u1SrcId);
EXTERN BOOL SWDMX_Stop(UINT8 u1SrcId);

EXTERN BOOL SWDMX_WaitForPause(UINT8 u1SrcId, UINT32 u4WaitTime);

EXTERN BOOL SWDMX_Flush(UINT8 u1SrcId);

EXTERN BOOL SWDMX_SetStrmID(UINT8 u1SrcId, UINT32 u4StrmID, UINT32 u4StrmSubID, ENUM_SWDMX_STRM_TYPE_T eStrmType);

EXTERN BOOL SWDMX_AddRange(UINT8 u1SrcId, VOID* pvRangeInfo, UINT32 u4TagID);
EXTERN BOOL SWDMX_CodecChgDone(UINT8 u1SrcId,UINT8 u1Type,VOID* pvCodecChg);
EXTERN BOOL SWDMX_PidChgDone(UINT8 u1SrcId,UINT8 u1Type,VOID* pvPidChg);
EXTERN BOOL SWDMX_RegPidChgCallback(UINT8 u1SrcId,UINT8 u1Type,VOID* pvRegPidChgCb);
EXTERN BOOL SWDMX_DelRange(UINT8 u1SrcId, VOID* pvRangeInfo, UINT32 u4TagID, BOOL fgDelAllRange);

EXTERN ENUM_SWDMX_PLAY_STATE_T SWDMX_QueryStatus(UINT8 u1SrcId);

EXTERN BOOL SWDMX_SetRangeCb(UINT8 u1SrcId, VOID* pfnCbFunc);

EXTERN BOOL SWDMX_SetRangeCbEx(UINT8 u1SrcId, VOID* pfnCbFunc);

EXTERN VOID SWDMX_QueryRangeInfo(UINT8 u1SrcId, SWDMX_RANGE_INFO_T* prRangeInfo);

EXTERN INT32 SWDMX_SetDmxNfy(UINT8 u1SrcId, const SWDMX_NFY_INFO_T* prSwdmxNfyInfo);

EXTERN BOOL SWDMX_ReadBuffer(UINT8 u1SrcId, ENUM_SWDMX_STRM_TYPE_T eStrmType, SWDMX_READ_INFO_T *prReadInfo);

EXTERN BOOL SWDMX_ReleaseBuffer(UINT8 u1SrcId, ENUM_SWDMX_STRM_TYPE_T eStrmType, SWDMX_READ_INFO_T *prReadInfo);

EXTERN BOOL SWDMX_AudioNotify(UINT8 u1SrcId, ENUM_SWDMX_AUDIO_NOTIFY_TYPE_T eAudioNotifyType);

EXTERN BOOL SWDMX_PcrCallBack(UINT32 u4PcrBase);

EXTERN BOOL SWDMX_SetPlayMode(UINT8 u1SrcId, SWDMX_PLAY_MODE_T ePlayMode);
#ifdef CC_SWDMX_RENDER_PTS
EXTERN VOID SWDMX_SetRenderPts(UINT8 u1SrcId, UINT32 u4RenderPts);
#endif

#ifdef CC_SWDMX_RENDER_POSITION_TEST
EXTERN VOID SWDMX_GetRenderPosition(VOID *prRenderPos);
EXTERN VOID SWDMX_SetRenderPosition(VOID *prRenderPos);
#endif

EXTERN BOOL SWDMX_SetFlushFeederInfo(UINT8 u1SrcId, UINT8 u1Type,VOID* pvMMFlushInfo,UINT32 u4Para2,UINT32 u4Para3);

EXTERN BOOL SWDMX_LockValidSrc(UINT8 u1SrcId);
EXTERN void SWDMX_UnlockSrc(UINT8 u1SrcId);
EXTERN UINT32 SWDMX_QueryDataSize(VOID);

EXTERN BOOL SWDMX_SetGnrcStreamInfo(UINT8 u1SrcId, UINT32 u4Para1);
EXTERN BOOL SWDMX_EnableHdcpKey(UINT8 u1SrcId,UINT8 u1Type);
EXTERN BOOL SWDMX_SetAdPlayWithLastMemory(UINT8 u1SrcId);

#if defined(DRV_APPLY_SWDMX_DESCRAMBLER)
EXTERN BOOL SWDMX_EnableCIPlusDesc(UINT8 u1SrcId, UINT32 u4EnCiPlus);
EXTERN BOOL SWDMX_SetDescrambler(UINT8 u1SrcId,  VOID* prDescInfoRaw);
#endif

#endif  // SWDMX_IF_H

