/* 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_rec_util.h,v $
 * $Revision: #1 $
 * $Date: 2015/05/29 $
 * $Author: brianpc.huang $
 * $CCRevision: /main/DTV_X_HQ_int/5 $
 * $SWAuthor: Clear Case Administrator $
 * $MD5HEX: e5a2644d77eac094a5d2aa1496612a57 $
 *
 * Description:
 *         This contains Record Utility exported macros, definitons,
 *         and structures.
 *---------------------------------------------------------------------------*/

#ifndef _X_REC_UTIL_H_
#define _X_REC_UTIL_H_

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

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
-----------------------------------------------------------------------------*/


/*-----------------------------------------------------------------------------
                        structures
-----------------------------------------------------------------------------*/

/* parameter for PVR buffer allocation */
typedef struct _REC_UTIL_PBA_PARAM_T
{
    VOID*                       pv_rec_purpose;
    BRDCST_TYPE_T               e_brdcst_type;
    BRDCST_MEDIUM_T             e_brdcst_medium;
    UINT32                      ui4_mem_align;
    SIZE_T                      z_size;

} REC_UTIL_PBA_PARAM_T;

/* allocated PVR buffer info */
typedef struct _REC_UTIL_PBA_BUF_INFO_T
{
    UINT32          ui4_buf_id;
    VOID*           pv_buf;
    SIZE_T          z_size;
    UINT32          ui4_buf_offset;

} REC_UTIL_PBA_BUF_INFO_T;

/* bitrate map items */
typedef struct _REC_UTIL_BITRATE_MAP_ITEM_T
{
    BRDCST_TYPE_T       e_brdcst_type;
    BRDCST_MEDIUM_T     e_brdcst_medium;
    UINT32              ui4_byte_per_second;

} REC_UTIL_BITRATE_MAP_ITEM_T;
/*-----------------------------------------------------------------------------
 * Name: (*rec_util_pvr_buf_query_avail_fct)
 *
 * Description: This callback querys available PVR buffer size.
 *
 * Inputs:  pv_tag       Contains the tag from REC_UTIL_SYS_CONFIG_T.pv_tag_pvr_buf_cb
 *          pt_param     Contains parameters for buffer allocation
 *
 * Outputs: pz_max_size  Contains available PVR buffer size.
 *
 * Returns: TRUE         Success to query this info;
 *          FALSE        Fail to query this info.
 ----------------------------------------------------------------------------*/
typedef BOOL (*rec_util_pvr_buf_query_avail_fct) (
    VOID*                           pv_tag,
    const REC_UTIL_PBA_PARAM_T*     pt_param,
    SIZE_T*                         pz_max_size );

/*-----------------------------------------------------------------------------
 * Name: (*rec_util_pvr_buf_alloc_fct)
 *
 * Description: This callback requests to allocate a PVR buffer.
 *
 * Inputs:  pv_tag       Contains the tag from REC_UTIL_SYS_CONFIG_T.pv_tag_pvr_buf_cb
 *          pt_param     Contains parameters for buffer allocation
 *
 * Outputs: pt_buf_info  Contains allocated buffer info.
 *
 * Returns: TRUE         Success to allocate buffer.
 *          FALSE        Fail to allocate buffer.
 ----------------------------------------------------------------------------*/
typedef BOOL (*rec_util_pvr_buf_alloc_fct) (
    VOID*                           pv_tag,
    const REC_UTIL_PBA_PARAM_T*     pt_param,
    REC_UTIL_PBA_BUF_INFO_T*        pt_buf_info);

/*-----------------------------------------------------------------------------
 * Name: (*rec_util_pvr_buf_free_fct)
 *
 * Description: This callback requests to allocate a PVR buffer.
 *
 * Inputs:  pv_tag       Contains the tag from REC_UTIL_SYS_CONFIG_T.pv_tag_pvr_buf_cb
 *          pt_buf_info  Contains allocated buffer info.
 *
 * Outputs: -
 *
 * Returns: TRUE         Success to free buffer.
 *          FALSE        Fail to free buffer.
 ----------------------------------------------------------------------------*/
typedef BOOL (*rec_util_pvr_buf_free_fct) (
    VOID*                           pv_tag,
    const REC_UTIL_PBA_BUF_INFO_T*  pt_buf_info);

/* PVR Buffer function table */
typedef struct _REC_UTIL_PVR_BUF_FCT_TBL_T
{
    rec_util_pvr_buf_query_avail_fct  pf_query_avail_pvr_buf; /* pvr buffer query available size callback */
    rec_util_pvr_buf_alloc_fct        pf_alloc_pvr_buf;       /* pvr buffer allocation callback */
    rec_util_pvr_buf_free_fct         pf_free_pvr_buf;        /* pvr buffer free callback */

} REC_UTIL_PVR_BUF_FCT_TBL_T;

/* system init config for record util */
typedef struct _REC_UTIL_SYS_CONFIG_T
{
    UINT32                       ui4_strct_ver;          /* structure version, should be 1 */
    UINT32                       ui4_flags;              /* reserved, should be 0 */
    UINT32                       ui4_write_fail_rate;    /* tolerant write fail rate */
    UINT16                       ui2_bitrate_map_items;  /* num of items in bitrate map array */
    REC_UTIL_BITRATE_MAP_ITEM_T* at_bitrate_map;         /* bitrate map array */
    UINT32                       ui4_pvr_buf_depth;      /* pvr buffer depth in milliseconds */
    VOID*                        pv_tag_pvr_buf_cb;      /* pvr buffer callback tag */
    REC_UTIL_PVR_BUF_FCT_TBL_T   t_fct_tbl_pvr_buf;      /* pvr buffer function table */

} REC_UTIL_SYS_CONFIG_T;


/*-----------------------------------------------------------------------------
                    Functions declarations
-----------------------------------------------------------------------------*/

/*extern INT32 x_rec_util_init(VOID);*/

extern INT32 x_rec_util_init(
    const REC_UTIL_SYS_CONFIG_T*    pt_sys_cfg);



#endif /*end of _X_REC_UTIL_H_ */


