/* 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_sm_sess_rcrd.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This header file contains Stream Manager's record session handler exported 
 *         definitions.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @addtogroup groupMW_STRM_MNGR_SESS_RCRD_HDLR
 *  @{ 
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_SM_SESS_RCRD_H_
#define _U_SM_SESS_RCRD_H_


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


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

/* set/get types *************************************************************/
#define SM_GRP_SESS_RCRD                (( SM_GRP_LAST_ENTRY + 16 ) << SM_CODE_BITS)    /**<record session handler cmd group   */


/* get types *****************************************************************/
#define SM_SESS_RCRD_GET_TYPE_IGNORE            ((SM_GET_TYPE_T)(SM_GRP_SESS_RCRD | 0))    /**<not to handle        */
#define SM_SESS_RCRD_GET_TYPE_PVR_BUFFER_INFO   ((SM_GET_TYPE_T)(SM_GRP_SESS_RCRD | 1))    /**< get PVR ring buffer   info     */
#define SM_SESS_RCRD_GET_TYPE_PVR_BUFFER_STATUS ((SM_GET_TYPE_T)(SM_GRP_SESS_RCRD | 2))    /**< get PVR ring buffer status         */
#define SM_SESS_RCRD_GET_TYPE_RING_BUFFER_STATUS ((SM_GET_TYPE_T)(SM_GRP_SESS_RCRD | 3))    /**< get PVR ring buffer status         */


/* set types *****************************************************************/
#define SM_SESS_RCRD_SET_TYPE_IGNORE            ((SM_SET_TYPE_T)(SM_GRP_SESS_RCRD | 0))    /**< not to handle         */
#define SM_SESS_RCRD_SET_TYPE_ENCRYPTION        ((SM_SET_TYPE_T)(SM_GRP_SESS_RCRD | 1))    /**< set encryption to recorded es       */

/* event types *****************************************************************/
/* APP events . */
#define SM_EVN_SESS_RCRD_GRP_APP              SM_MAKE_EVN_GRP(SM_EVN_GRP_SESS_RCRD, 0)    /**< record session handler  event group        */
   
#define SM_EVN_SESS_RCRD_APP_OPEN_REQ         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 0)    /**<record session open request         */
#define SM_EVN_SESS_RCRD_APP_PLAY_REQ         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 1)    /**<record session play request         */
#define SM_EVN_SESS_RCRD_APP_STOP_REQ         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 2)    /**<record session stop request         */
#define SM_EVN_SESS_RCRD_APP_CLOSE_REQ        SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 3)    /**<record session close request        */
#define SM_EVN_SESS_RCRD_ALL_OPENED           SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 4)    /**<record session opened request         */
#define SM_EVN_SESS_RCRD_ALL_PLAYED           SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 5)    /**<record session played request         */
#define SM_EVN_SESS_RCRD_ALL_STOPPED          SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 6)    /**<record session stopped request         */
#define SM_EVN_SESS_RCRD_ALL_CLOSED           SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 7)    /**<record session closed request         */
#define SM_EVN_SESS_RCRD_COMP_ERR             SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 8)    /**<record session component error event     */
#define SM_EVN_SESS_RCRD_SCDB_CLOSED          SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 9)    /**< scdb closed event       */
#define SM_EVN_SESS_RCRD_SCDB_UPDATE          SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 10)    /**<scdb update event       */
#define SM_EVN_SESS_RCRD_PVR_CTRL_OVERFLOW    SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 11)    /**<PVR ring buffer overflow  event        */
#define SM_EVN_SESS_RCRD_PVR_CTRL_FLUSHED     SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 12)    /**< PVR ring buffer flushed  event           */

#define SM_EVN_SESS_RCRD_INTERNAL_ERR         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 13)    /**< record session internal error event        */

/*need notify to AP so define here*/
#define SM_EVN_SESS_RCRD_PVR_CTRL_OPENED      SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 14)    /**<PVR ring buffer opened event        */

/*#define SM_EVN_SESS_RCRD_PVR_PMT_UPDATED      SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 15)*/
#define SM_EVN_SESS_RCRD_REACH_BOUND          SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 15)    /**<TS file reach bound        */
#define SM_EVN_SESS_RCRD_STRG_FULL            SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 16)    /**<TS file is  full                  */
#define SM_EVN_SESS_RCRD_BUF_FULL            SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 17)    /**<Tshift buf is  full                  */
#define SM_EVN_SESS_RCRD_REACH_TIME_BOUND          SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_APP, 18)    /**<TS file reach time bound        */



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

/* SM_SESS_RCRD_CFG_T.ui1_frame_mask */
#define SM_SESS_RCRD_FRAME_TYPE_MASK_I       MAKE_BIT_MASK_8(0)    /**< I frame       */
#define SM_SESS_RCRD_FRAME_TYPE_MASK_P       MAKE_BIT_MASK_8(1)    /**< P frame       */
#define SM_SESS_RCRD_FRAME_TYPE_MASK_B       MAKE_BIT_MASK_8(2)    /**< B frame       */

/*------------------------------------------------------------------*/
/*! @enum SM_SESS_RCRD_PVR_OVERFLOW_OPT_T
 *  @brief Defines record behaviour when PVR buffer is overflow
 *  @code
 *  typedef enum _SM_SESS_RCRD_PVR_OVERFLOW_OPT_T
 *  {
 *      SM_SESS_RCRD_OVERFLOW_OPT_CONTINUOUS_TICK = 0,
 *      SM_SESS_RCRD_OVERFLOW_OPT_SKIP_TICK,
 *      SM_SESS_RCRD_OVERFLOW_OPT_LAST_ENTRY
 *  }SM_SESS_RCRD_PVR_OVERFLOW_OPT_T;
 *  @endcode
 *  @li@c  SM_SESS_RCRD_OVERFLOW_OPT_CONTINUOUS_TICK          -continue tick 
 *  @li@c  SM_SESS_RCRD_OVERFLOW_OPT_SKIP_TICK                       -ignore tick which is not continuous
 *  @li@c  SM_SESS_RCRD_OVERFLOW_OPT_LAST_ENTRY                   -bound mark
 */
/*------------------------------------------------------------------*/
typedef enum _SM_SESS_RCRD_PVR_OVERFLOW_OPT_T
{
    SM_SESS_RCRD_OVERFLOW_OPT_CONTINUOUS_TICK = 0,
    SM_SESS_RCRD_OVERFLOW_OPT_SKIP_TICK,
    
    SM_SESS_RCRD_OVERFLOW_OPT_LAST_ENTRY
}SM_SESS_RCRD_PVR_OVERFLOW_OPT_T;

/* record config (x_sm_open_sess (pv_sess_data)) */
/*------------------------------------------------------------------*/
/*! @struct SM_SESS_RCRD_CFG_T
 *  @brief Descript record related information such as PVR alignment. 
 *  This should be set when start to record
 *  @code
 *  typedef struct _SM_SESS_RCRD_CFG_T
 *  {
 *      UINT32                            ui4_flags;      
 *      CHAR*                             s_name_rec_util;
 *      UINT8                             ui1_frame_mask;
 *      UINT32                            ui4_ms_tick_period;
 *      UINT32                            ui4_pvr_buf_align;
 *      SM_SESS_RCRD_PVR_OVERFLOW_OPT_T   e_pvr_overflow_opt;
 *  } SM_SESS_RCRD_CFG_T;
 *  @endcode
 *  @li@c  ui4_flags                                               -indicate which fieldare valid
 *  @li@c  s_name_rec_util                                   -record utility name
 *  @li@c  ui1_frame_mask                                   -frame mask
 *  @li@c  ui4_ms_tick_period                               -tick period to notify tick data
 *  @li@c  ui4_pvr_buf_align                                  -PVR ring buffer alignement
 *  @li@c  e_pvr_overflow_opt                              -how to handle PVR ring buffer overflow event
 */
/*------------------------------------------------------------------*/
typedef struct _SM_SESS_RCRD_CFG_T
{
    UINT32                            ui4_flags;      /* reserved, should be 0 */
    CHAR*                             s_name_rec_util;
    UINT8                             ui1_frame_mask;
    UINT32                            ui4_ms_tick_period;
    UINT32                            ui4_pvr_buf_align;
    SM_SESS_RCRD_PVR_OVERFLOW_OPT_T   e_pvr_overflow_opt;
    BOOL                              b_free_ca_mode;
} SM_SESS_RCRD_CFG_T;

#endif  /* _U_SM_SESS_RCRD_H_ */
/*----------------------------------------------------------------------------*/
/*! @} */                                             /* end of groupMW_STRM_MNGR_SESS_RCRD_HDLR */

