/* 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.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file u_psi_eng.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This header file contains PSI engine specific definitions, which
 *         are exported.
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_PSI_H_
#define _U_PSI_H_    /**<        */


/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/

#include "u_handle_grp.h"
#include "u_common.h"

/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_TBL_MNGR_PSI_ENG  MPEG2 PSI Engine
 *
 *  @ingroup groupMW_TBL_MNGR
 *  @brief Load and get MPEG2 program information for Application
 *
 *  %MW Application API would be used by Application, lot of these APIs would
 *   be wrapped from Exported API. Using these APIs, application could load or get
 *   the detail information of MPEG2 program information table.
 *   
 *  @see groupMW_TBL_MNGR
 *  @{ 
 */
/*----------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/

/* Default PSI engine name. */
#define PSI_DEFAULT_NAME  "psi_engine"    /**< Default name of PSI engine       */


/* PSI engine handle types. */
#define TMT_PSI_PAT  (TMT_PSI + ((HANDLE_TYPE_T)  0))    /**< Handle type for PAT */
#define TMT_PSI_PMT  (TMT_PSI + ((HANDLE_TYPE_T)  1))    /**< Handle type for PMT */
#define TMT_PSI_CAT  (TMT_PSI + ((HANDLE_TYPE_T)  2))    /**< Handle type for CAT */
#define TMT_PSI_TSDT (TMT_PSI + ((HANDLE_TYPE_T)  3))    /**< Handle type TSDT table */

#define TMT_PSI_PAT_MON  (TMT_PSI + ((HANDLE_TYPE_T)  4))    /**< Handle type for monitor PAT       */


/* PSI engine get operations. */
#define PSI_GET_TYPE_SVC_ENTRY     (TM_GET_TYPE_LAST_ENTRY + ((TM_GET_TYPE_T) 0))    /**< get information, reference to PSI_PID_SVC_ID_INFO_T */
#define PSI_GET_TYPE_PCR_PID       (TM_GET_TYPE_LAST_ENTRY + ((TM_GET_TYPE_T) 1))    /**< get information, reference to MPEG_2_PID_T */
#define PSI_GET_TYPE_STREAM_ENTRY  (TM_GET_TYPE_LAST_ENTRY + ((TM_GET_TYPE_T) 2))    /**< get information, reference to PSI_STREAM_INFO_T */
#define PSI_GET_TYPE_PAT_ENTRY     (TM_GET_TYPE_LAST_ENTRY + ((TM_GET_TYPE_T) 3))    /**< get information, reference to PSI_PID_SVC_ID_INFO_T */

/* PSI engine load types. */
#define PSI_LOAD_TYPE_SVC_ID       (TM_LOAD_TYPE_LAST_ENTRY + ((TM_LOAD_TYPE_T) 0))    /**< Load type for service id */
#define PSI_LOAD_TYPE_PID_SVC_ID  ((TM_LOAD_TYPE_LAST_ENTRY + ((TM_LOAD_TYPE_T) 1)) | TM_LOAD_TYPE_SINGLE_SRC)    /**< Load type for PID, service id  */
#define PSI_LOAD_TYPE_RAW_SECT     (TM_LOAD_TYPE_LAST_ENTRY + ((TM_LOAD_TYPE_T) 2))    /**< Load type for service id */

/* PSI engine set operations. */
#define PSI_SET_TYPE_PCR_PID       (TM_SET_TYPE_LAST_ENTRY + ((TM_SET_TYPE_T) 0))    /**< Set type for PCR PID  */
#define PSI_SET_TYPE_STREAM_DESCR  (TM_SET_TYPE_LAST_ENTRY + ((TM_SET_TYPE_T) 1))    /**< Set type for stream description */

/* Holds a TS id and version value. */
/*------------------------------------------------------------------*/
/*! @struct PSI_TS_VER_INFO_T
 *  @brief This structure contains all information of a table's TS ID and version value.
 *  @code
 *  typedef struct _PSI_TS_VER_INFO_T
 *  {
 *      UINT16  ui2_ts_id;
 *      UINT8   ui1_version;
 *  }   PSI_TS_VER_INFO_T;
 *  @endcode
 *  @li@c  ui2_ts_id         - This field contains the table's TS ID value
 *  @li@c  ui1_version     - This field contains the table's version value
 */
/*------------------------------------------------------------------*/
typedef struct _PSI_TS_VER_INFO_T
{
    UINT16  ui2_ts_id;

    UINT8   ui1_version;
}   PSI_TS_VER_INFO_T;

/* Holds a PID and SVC id value. */
/*------------------------------------------------------------------*/
/*! @struct PSI_PID_SVC_ID_INFO_T
 *  @brief This structure contains information of PAT table's loop entry
 *  @code
 *  typedef struct _PSI_PID_SVC_ID_INFO_T
 *  {
 *      MPEG_2_PID_T  t_pid;
 *      UINT16  ui2_svc_id;
 *  }   PSI_PID_SVC_ID_INFO_T;
 *  @endcode
 *  @li@c  t_pid             - This field contains the table's PID value
 *  @li@c  ui2_svc_id     - This field contains the table's service ID value
 */
/*------------------------------------------------------------------*/
#pragma pack(4)

typedef struct _PSI_PID_SVC_ID_INFO_T
{
    MPEG_2_PID_T  t_pid;

    UINT16  ui2_svc_id;
}   PSI_PID_SVC_ID_INFO_T;

#pragma pack()

/* Holds a stream type and PID value. */
/*------------------------------------------------------------------*/
/*! @struct PSI_STREAM_INFO_T
 *  @brief This structure contains all information of a PMT table's stream loop entry
 *  @code
 *  typedef struct _PSI_STREAM_INFO_T
 *  {
 *      MPEG_2_PID_T  t_pid;
 *      UINT8  ui1_stream_type;
 *  }   PSI_STREAM_INFO_T;
 *  @endcode
 *  @li@c  t_pid                     - This field contains the PID value of a PMT table's stream loop entry
 *  @li@c  ui1_stream_type    - This field contains the stream type value of a PMT table's stream
 *                                           loop entry
 */
/*------------------------------------------------------------------*/
#pragma pack(4)

typedef struct _PSI_STREAM_INFO_T
{
    MPEG_2_PID_T  t_pid;

    UINT8  ui1_stream_type;
}   PSI_STREAM_INFO_T;

#pragma pack()

/*------------------------------------------------------------------*/
/*! @struct PSI_RAW_SECT_INFO_T
 *  @brief This structure contains information of PAT table's loop entry
 *  @code
 *  typedef struct _PSI_PID_SVC_ID_INFO_T
 *  {
 *      MPEG_2_PID_T  t_pid;
 *      UINT16  ui2_svc_id;
 *  }   PSI_PID_SVC_ID_INFO_T;
 *  @endcode
 *  @li@c  t_pid             - This field contains the table's PID value
 *  @li@c  ui2_svc_id     - This field contains the table's service ID value
 */
/*------------------------------------------------------------------*/
typedef struct _PSI_RAW_SECT_INFO_T
{
    MPEG_2_PID_T  t_pid;
    UINT16  ui2_svc_id;
    VOID*   pv_raw_sect;
    SIZE_T  z_sect_len;
}   PSI_RAW_SECT_INFO_T;

/* PSI engine configuration structure. */
/*------------------------------------------------------------------*/
/*! @struct PSI_CONFIG_T
 *  @brief This structure contains all information for the configuration of the PSI engine
 *  @code
 *  typedef struct _PSI_CONFIG_T
 *  {
 *      UINT8  ui1_num_pat_filters;
 *      UINT8  ui1_num_pmt_filters;
 *      UINT8  ui1_num_cat_filters;
 *      UINT8  ui1_num_tsdt_filters;
 *      SIZE_T  z_pat_buff_size;
 *      SIZE_T  z_pmt_buff_size;
 *      SIZE_T  z_cat_buff_size;
 *      SIZE_T  z_tsdt_buff_size;
 *      UINT16  ui2_num_pat_tbl_objs;
 *      UINT16  ui2_num_pmt_tbl_objs;
 *      UINT16  ui2_num_cat_tbl_objs;
 *      UINT16  ui2_num_tsdt_tbl_objs;
 *      UINT16  ui2_num_mon_pat_tbl_objs;
 *  }   PSI_CONFIG_T;
 *  @endcode
 *  @li@c  ui1_num_pat_filters               -Contains the number of PAT filters the PSI 
 *                                                         engine shall maintain. The value of this field 
 *                                                         must always be greater than '0'
 *  @li@c  ui1_num_pmt_filters              -Contains the number of PMT filters the PSI 
 *                                                         engine shall maintain. The value of this field 
 *                                                         must always be greater than '0'
 *  @li@c  ui1_num_cat_filters               - Contains the number of CAT filters 
 *                                                          the PSI engine shall maintain. The value of 
 *                                                          this field must always be greater than '0'
 *  @li@c  ui1_num_tsdt_filters              - Contains the number of TSDT filters the PSI 
 *                                                          engine shall maintain. The value of this field 
 *                                                          must always be greater than '0'
 *  @li@c  z_pat_buff_size                     - Contains the demux filter buffer size per PAT
 *                                                           filter in number of Bytes. The value of this field
 *                                                          must always be greater than '0'
 *  @li@c  z_pmt_buff_size                    - Contains the demux filter buffer size per PMT
 *                                                           filter in number of Bytes. The value of this field 
 *                                                           must always be greater than '0'
 *  @li@c  z_cat_buff_size                     - Contains the demux filter buffer size per CAT
 *                                                           filter in number of Bytes. The value of this field
 *                                                           must always be greater than '0'
 *  @li@c  z_tsdt_buff_size                    - Contains the demux filter buffer size per TSDT 
 *                                                          filter in number of Bytes. The value of this field
 *                                                          must always be greater than '0'
 *  @li@c  ui2_num_pat_tbl_objs           - Contains the number of PAT table objects
 *  @li@c  ui2_num_pmt_tbl_objs          - Contains the number of PMT table objects
 *  @li@c  ui2_num_cat_tbl_objs           - Contains the number of CAT table objects
 *  @li@c  ui2_num_tsdt_tbl_objs          - Contains the number of TSDT table objects
 *  @li@c  ui2_num_mon_pat_tbl_objs   - Contains the number of PAT monitor  table objects
 */
/*------------------------------------------------------------------*/
typedef struct _PSI_CONFIG_T
{
    UINT8  ui1_num_pat_filters;
    UINT8  ui1_num_pmt_filters;
    UINT8  ui1_num_cat_filters;
    UINT8  ui1_num_tsdt_filters;

    SIZE_T  z_pat_buff_size;
    SIZE_T  z_pmt_buff_size;
    SIZE_T  z_cat_buff_size;
    SIZE_T  z_tsdt_buff_size;

    UINT16  ui2_num_pat_tbl_objs;
    UINT16  ui2_num_pmt_tbl_objs;
    UINT16  ui2_num_cat_tbl_objs;
    UINT16  ui2_num_tsdt_tbl_objs;

    UINT16  ui2_num_mon_pat_tbl_objs;
}   PSI_CONFIG_T;

#endif /* _U_PSI_H_ */

/*----------------------------------------------------------------------------*/
/*! @} */                                  /* end of groupMW_TBL_MNGR_PSI_ENG */
/*----------------------------------------------------------------------------*/
