/* 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: x_dmx_util.h,v $
 * $Revision: #1 $
 * $Date: 2015/11/10 $
 * $Author: dtvbm11 $
 *
 * Description:
 *         
 *---------------------------------------------------------------------------*/

#ifndef _X_DMX_UTIL_H_
#define _X_DMX_UTIL_H_

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

#include "x_common.h"
#include "u_dmx_util.h"

/*----------------------------------------------------------------------------*/
/*! @addtogroup groupMW_DMX_UT
 *  @{ 
 */
/*----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
 * structure, constants, macro definitions
 *---------------------------------------------------------------------------*/
 

/*-----------------------------------------------------------------------------
                    functions declarations
 ----------------------------------------------------------------------------*/

/*------------------------------------------------------------------*/
/*! @brief  This API init dmx util module
 *  @param  [in]  pv_data - Contains initial data.
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_init(VOID* pv_data);

/*------------------------------------------------------------------*/
/*! @brief  This API alloc a pid filter
 *  @param  [in]  t_pid - stream or table identify 
 *  @param  [in]  z_buf_size - for this pid cache size
 *  @param  [out]  ph_pidf_ctrl - a handle for pid filter control
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_pid_filter_alloc(
            MPEG_2_PID_T        t_pid,
            SIZE_T              z_buf_size,
            HANDLE_T*           ph_pidf_ctrl);

/*------------------------------------------------------------------*/
/*! @brief  This API allow client set a new callback function
 *  @param  [in]  h_pidf_ctrl - pid filter handle 
 *  @param  [in]  pf_dmx_ut_nfy - client impletement this callback function
 *  @param  [out]  ui4_nfy_data - this is a tag
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_ARGS - pf_dmx_ut_nfy is NULL
 *  @retval DMXR_UT_INV_HANDLE - h_pidf_ctrl is NULL
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_pid_filter_set_nfy(
            HANDLE_T            h_pidf_ctrl,
            x_dmx_ut_nfy_fct    pf_dmx_ut_nfy,
            UINT32              ui4_nfy_data);


/*------------------------------------------------------------------*/
/*! @brief  This API free a pid filter handle
 *  @param  [in]  h_pidf_ctrl - pid filter handle 
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_HANDLE - h_pidf_ctrl invalid
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_pid_filter_free(HANDLE_T h_pidf_ctrl);

/*------------------------------------------------------------------*/
/*! @brief  This API alloc a section filter
 *  @param  [in]  h_pidf_ctrl - pid filter handle 
 *  @param  [out]  ph_secf_ctrl - a handle for section filter control
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_HANDLE - h_pidf_ctrl invalid
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_sec_filter_alloc(
            HANDLE_T           h_pidf_ctrl,
            HANDLE_T*          ph_secf_ctrl);

/*------------------------------------------------------------------*/
/*! @brief  This API config a section filter for add table id information
 *  @param  [in]  h_secf_ctrl - section filter handle 
 *  @param  [out]  pt_sf_info - config detail struction info
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_HANDLE - h_secf_ctrl invalid
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_sec_filter_set(
            HANDLE_T            h_secf_ctrl,
            DMX_UT_SF_INFO_T*   pt_sf_info);

/*------------------------------------------------------------------*/
/*! @brief  This API control a section filter to active or inactive
 *  @param  [in]  h_secf_ctrl - section filter handle 
 *  @param  [out]  b_enable - open filter or disable. 
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_HANDLE - h_secf_ctrl invalid
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_sec_filter_ctrl(
            HANDLE_T    h_secf_ctrl,
            BOOL        b_enable);

/*------------------------------------------------------------------*/
/*! @brief  This API free a section filter handle
 *  @param  [in]  h_secf_ctrl - section filter handle 
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_HANDLE - h_secf_ctrl invalid
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_sec_filter_free(HANDLE_T h_secf_ctrl);

/*------------------------------------------------------------------*/
/*! @brief  This API copy section data when dmx utility notify to client
 *  @param  [in]  h_pidf_ctrl - pid filter handle 
 *  @param  [in]  pv_src_tag - a tag from dmx utility notify parament
 *  @param  [in]  z_skip_len - skip some section data 
 *  @param  [in]  z_copy_len - the length for copy 
 *  @param  [in]  pui1_buf - section header
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_ARGS - pui1_buf is NULL
 *  @retval DMXR_UT_INV_HANDLE - h_pidf_ctrl is NULL
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_sec_data_read(HANDLE_T   h_pidf_ctrl,
                                    VOID*      pv_src_tag,
                                    UINT32     ui4_dmx_data,
                                    SIZE_T     z_skip_len,
                                    SIZE_T     z_copy_len,
                                    UINT8*     pui1_buf);

/*------------------------------------------------------------------*/
/*! @brief  This API was call after copy section completely.
 *  @param  [in]  h_pidf_ctrl - pid filter handle 
 *  @param  [in]  pv_src_tag - a tag from dmx utility notify parament
 *  @param  [in]  z_sec_size - release size. take small value between Notify section length and Max buffer length.
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_HANDLE - h_pidf_ctrl is NULL
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/ 
extern INT32 x_dmx_ut_sec_data_release(HANDLE_T   h_pidf_ctrl,
                                       VOID*      pv_src_tag,
                                       UINT32     ui4_dmx_data,
                                       SIZE_T     z_sec_size);

/*------------------------------------------------------------------*/
/*! @brief  This API was reset demux driver data of all relation PID fitler
 *  @param  [in]  h_pidf_ctrl - pid filter handle 
 *  @return return the error code
 *  @retval DMXR_UT_NOT_INIT - dmx util module not init
 *  @retval DMXR_UT_INV_HANDLE - h_pidf_ctrl is NULL
 *  @retval DMXR_UT_OK - Routine successful.
 */
/*------------------------------------------------------------------*/                                  
extern INT32 x_dmx_ut_sec_buf_flush(HANDLE_T   h_pidf_ctrl);

extern UINT16 dmx_ut_get_dbg_level(VOID);

extern VOID dmx_ut_set_dbg_level(UINT16 ui2_db_level);

#endif /* _X_DMX_UTIL_H_ */

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


