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

/*-----------------------------------------------------------------------------
 * $RCSfile: u_dmx_util.h,v $
 * $Revision: #1 $
 * $Date: 2015/11/10 $
 * $Author: dtvbm11 $
 *
 * Description:
 *         
 *---------------------------------------------------------------------------*/

#ifndef _U_DMX_UTIL_H_
#define _U_DMX_UTIL_H_

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

#include "x_common.h"

/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_DMX_UT DMX Utility
 *
 *  @ingroup groupMW
 *  @brief For load section
 *
 *  %MW Application API would be used by Application, lot of these APIs would
 *   be wrapped from Exported API. Using these APIs, application could change input source, 
 *   change channel, select multi media and so on.
 *
 *  @see groupMW
 *  @{ 
 */
/*----------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/
 
/*------------------------------------------------------------------*/
/*! @struct DMX_UT_SF_INFO_T
 *  @brief  Setion Filter Information, Demux is according to this info to filter some sections
 *  @code
 *  typedef struct _DMX_UT_SF_INFO_T
 *  {
 *      UINT8  ui1_tbl_id_pattern;
 *      UINT8  ui1_tbl_id_mask;

 *      UINT8  ui1_pattern_offset;
 *      UINT8  ui1_pattern_len;

 *      UINT8*  pui1_pos_pattern;
 *      UINT8*  pui1_pos_mask;

 *      UINT8*  pui1_neg_pattern;
 *      UINT8*  pui1_neg_mask;

 *      BOOL  b_check_crc;
 *  }   DMX_UT_SF_INFO_T; 
 *  @endcode
 *  @li@c  ui1_tbl_id_pattern                                  ui1_tbl_id_pattern - table id pattern
 *  @li@c  ui1_tbl_id_mask                                     ui1_tbl_id_mask -table id mask
 *  @li@c  ui1_pattern_offset                                  ui1_pattern_offset - offset where start filter pattern 
 *  @li@c  ui1_pattern_len                                      ui1_pattern_len - len which filter pattern length
 *  @li@c  pui1_pos_pattern                                     pui1_pos_pattern - local array for filter pattern
 *  @li@c  pui1_pos_mask                                        pui1_pos_mask - local mask for filter pattern
 *  @li@c  pui1_neg_pattern                                     pui1_neg_pattern - against pattern for above
 *  @li@c  pui1_neg_mask                                        pui1_neg_mask - against pattern mask
 */
/*------------------------------------------------------------------*/
typedef struct _DMX_UT_SF_INFO_T
{
    UINT8  ui1_tbl_id_pattern;
    UINT8  ui1_tbl_id_mask;

    UINT8  ui1_pattern_offset;
    UINT8  ui1_pattern_len;

    UINT8*  pui1_pos_pattern;
    UINT8*  pui1_pos_mask;

    UINT8*  pui1_neg_pattern;
    UINT8*  pui1_neg_mask;

    BOOL  b_check_crc;
}   DMX_UT_SF_INFO_T;

/* service context states */
/*------------------------------------------------------------------*/
/*! @enum   DMX_UT_COND_T
 *  @brief  section notify condition
 *  @code
 *  typedef enum
 *  {
 *      DMX_UT_COND_DATA_REC = 0,
 *      DMX_UT_COND_DATA_OVERFLOW
 *  } DMX_UT_COND_T;
 *  @endcode
 *  @li@c  DMX_UT_COND_DATA_REC                         DMX_UT_COND_DATA_REC - section data is arrived
 *  @li@c  DMX_UT_COND_DATA_OVERFLOW              DMX_UT_COND_DATA_OVERFLOW - ready use, only init field.
 */
/*------------------------------------------------------------------*/
typedef enum
{
    DMX_UT_COND_DATA_REC = 0,
    DMX_UT_COND_DATA_OVERFLOW
} DMX_UT_COND_T;

/*------------------------------------------------------------------*/
/*! @brief  prototype for section notify
 *  @param  [in]  e_nfy_cond - notify current section arrived condition.
 *  @param  [in]  pv_nfy_tag - tag for notify.
 *  @param  [in]  z_sec_len - section length.
 *  @param  [in]  ui4_nfy_data - section data.
 *  @return TRUE or FALSE
 */
/*------------------------------------------------------------------*/
typedef BOOL (*x_dmx_ut_nfy_fct) (DMX_UT_COND_T e_nfy_cond,
                                  VOID*         pv_src_tag,
                                  UINT32		ui4_dmx_data,
                                  SIZE_T        z_sec_len,
                                  UINT32        ui4_nfy_data);


/*-----------------------------------------------------------------------------
                    functions declarations
 ----------------------------------------------------------------------------*/
#define DMXR_UT_OK                               ((INT32)    0) /**< operate OK */
#define DMXR_UT_FAIL                             ((INT32)   -1) /**< operate Fail */
#define DMXR_UT_NOT_INIT                         ((INT32)   -2) /**< demux utility moduel dont' initialize */
#define DMXR_UT_INV_ARGS                         ((INT32)   -3) /**< input invalid arguments */
#define DMXR_UT_INV_OP                           ((INT32)   -4) /**< current call is invalid */
#define DMXR_UT_INV_HANDLE                       ((INT32)   -5) /**< input handle is invalid */
#define DMXR_UT_NO_RESOURCE                      ((INT32)   -6) /**< demux utility module resource is not enough */
#define DMXR_UT_INTERNAL_ERR                     ((INT32)   -7) /**< demux utility module has a internal error */
#define DMXR_UT_RM_ERR                           ((INT32)   -8) /**< resource manager return a error */

#define DMXR_UT_CLI_ERR                        ((INT32)   -11)  /**< cli command has a error */
#endif /* _U_DMX_UTIL_H_ */

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


