/* 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_rec_hdlr.h
 *  $RCSfile: $
 *  $Revision: #3 $
 *  $Date: 2015/07/31 $
 *  $Author: lin.li $
 *
 *  @par Description:
 *         This header file contains Record Handler specific definitions.
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_REC_HDLR_H_
#define _U_REC_HDLR_H_

/*----------------------------------------------------------------------------*/
/*! @defgroup   groupMW_SVCTX_REC_HDLR Record Handler
 *  @ingroup    groupMW_SVCTX
 *  @brief      Provides external definitions for record handler.
 *  @see        groupMW_SVCTX
 *  @{
 */
/*----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/
#include "u_svctx.h"
#include "u_fm_mfw.h"
#include "u_ci.h"

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

#define SRC_TYPE_RECORD              ((SRC_TYPE_T) 16)        /**< Defines the source type for REC_HDLR */

/* return value */
#define SVCTXR_REC_MSG_LAST_ENTRY    (SVCTXR_MSG_LAST_ENTRY   + ((INT32) 32)) /**< Defines the last entry of message type return value */

#define SVCTXR_REC_INTERNAL_ERROR    (SVCTXR_ERROR_LAST_ENTRY - ((INT32)  1)) /**< Defines the return value that indicates internal error */
#define SVCTXR_REC_FILE_NOT_FOUND    (SVCTXR_ERROR_LAST_ENTRY - ((INT32)  2)) /**< Defines the return value that indicates the file is not found. */
#define SVCTXR_REC_INV_META_KEY_TYPE (SVCTXR_ERROR_LAST_ENTRY - ((INT32)  3)) /**< Defines the return value that indicates the metadata key type is invalid. */
#define SVCTXR_REC_BUFF_TOO_SMALL    (SVCTXR_ERROR_LAST_ENTRY - ((INT32)  4)) /**< Defines the return value that indicates the buffer prepared by caller is too small. */
#define SVCTXR_REC_INFO_NOT_FOUND    (SVCTXR_ERROR_LAST_ENTRY - ((INT32)  5)) /**< Defines the return value that indicates the requested info is not found. */
#define SVCTXR_REC_EXTNL_MODULE_FAIL (SVCTXR_ERROR_LAST_ENTRY - ((INT32)  6)) /**< Defines the return value that indicates some operation of external module is fail. */

#define SVCTXR_REC_ERR_LAST_ENTRY    (SVCTXR_ERROR_LAST_ENTRY - ((INT32) 32)) /**< Defines the last entry of error type return value */

#define SVCTX_GRP_REC                (5<<SVCTX_TYPE_CODE_BITS)                /**< Defines the set/get type group for REC_HDLR */

/* set commands */
#define SVCTX_REC_SET_TYPE_IGNORE          ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 0))     /**< (Ignore) */
#define SVCTX_REC_SET_TYPE_START_REC       ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 1))     /**< Defines the set type to start record, pv_set_info: (SVCTX_REC_CONFIG_T *) */
#define SVCTX_REC_SET_TYPE_STOP_REC        ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 2))     /**< Defines the set type to stop record, pv_set_info: NULL */
#define SVCTX_REC_SET_TYPE_PAUSE_REC       ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 3))     /**< Defines the set type to pause record, pv_set_info: NULL */
#define SVCTX_REC_SET_TYPE_RESUME_REC      ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 4))     /**< Defines the set type to resume record, pv_set_info: NULL */
#define SVCTX_REC_SET_TYPE_ES_LIST         ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 5))     /**< Defines the set type to set ES list, pv_set_info: (SVCTX_REC_ES_LIST_T *) */
#define SVCTX_REC_SET_TYPE_DEL_REC_DATA    ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 6))     /**< Defines the sst type to delete a specified set of record data, pv_set_info: (SVCTX_REC_DEL_DATA_T *) */
#define SVCTX_REC_SET_TYPE_META_DB_OPEN    ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 7))     /**< Defines the command to open metadata database, pv_set_info: (SVCTX_REC_META_DB_OPEN_T *) */
#define SVCTX_REC_SET_TYPE_META_DB_CLOSE   ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 8))     /**< Defines the command to close metadata database, pv_set_info: (SVCTX_REC_META_DB_CLOSE_T *) */
#define SVCTX_REC_SET_TYPE_META_DB_STORE   ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 9))     /**< Defines the command to store metadata database, pv_set_info: (SVCTX_REC_META_DB_STORE_T *) */
#define SVCTX_REC_SET_TYPE_META_INFO       ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 10))    /**< Defines the command to set an entry of metadata database. Note that the modification will not be physically stored into file before SVCTX_REC_SET_TYPE_META_DB_STORE or SVCTX_REC_SET_TYPE_META_DB_CLOSE is called, pv_set_info: (SVCTX_REC_SET_META_INFO_T *) */
#define SVCTX_REC_SET_TYPE_CRET_REC_FILE   ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 11))    /**< Defines the set type create rec file:pv_set_info:SVCTX_REC_FILE_INFO_T*/
#define SVCTX_REC_SET_TYPE_INPUT_LOCK      ((SVCTX_SET_TYPE_T) (SVCTX_GRP_REC | 12))    /**< Defines the set type input lock, pv_set_info:SVCTX_REC_FILE_INFO_T*/

/* get commands */
#define SVCTX_REC_GET_TYPE_IGNORE                 ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 0))    /**< (Ignore) */
#define SVCTX_REC_GET_TYPE_TICK_PERIOD            ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 1))    /**< Defines the get type for tick period, pv_get_info: (UINT32 *) */
#define SVCTX_REC_GET_TYPE_CAPABILITY             ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 2))    /**< Defines the get type for capability, pv_get_info: (SVCTX_REC_CAP_INFO_T *) */
#define SVCTX_REC_GET_TYPE_SYS_RES_INFO           ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 3))    /**< Defines the get type for system resource info, pv_get_info: (SVCTX_REC_SYS_RES_INFO_T *) */
#define SVCTX_REC_GET_TYPE_STATUS                 ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 4))    /**< Defines the get type for current record status, pv_get_info: (SVCTX_REC_STATUS_T *) */
#define SVCTX_REC_GET_TYPE_ESL_AUTH_STATUS        ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 5))    /**< Defines the get type for authentication status of each ES, pv_get_info: (SVCTX_REC_ESL_AUTH_STATUS_T *) */
#define SVCTX_REC_GET_TYPE_FILE_SIZE              ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 6))    /**< Defines the get type for capacity consume of device pv_get_info:UINT64 consumed data size*/
#define SVCTX_REC_GET_TYPE_META_INFO              ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 7))    /**< Defines the command to get the data of a specified entry in metadata database, pv_get_info: (SVCTX_REC_GET_META_INFO_T *) */
#define SVCTX_REC_GET_TYPE_META_INFO_LEN          ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 8))    /**< Defines the command to get the length of a specified entry in metadata database, pv_get_info: (SVCTX_REC_GET_META_INFO_LEN_T *) */
#define SVCTX_REC_GET_CI_PIN_CAPABILITY           ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 9))    /**< Defines the command to get the length of a specified entry in metadata database, pv_get_info: (SVCTX_REC_GET_META_INFO_LEN_T *) */
#define SVCTX_REC_GET_CI_PVR_RENTION_TIME         ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 10))   /**< Defines the command to get the CI plus rention time*/
#define SVCTX_REC_GET_TYPE_SVL_INFO               ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 11))   /**/
#define SVCTX_REC_GET_REC_FILE_ATTR               ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 12))   /**< Defines the get type for record file attribute,such as size, pv_get_info: (SVCTX_GET_REC_FILE_ATTR_T *) */
#define SVCTX_REC_GET_TYPE_META_INFO_COUNT        ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 13))
#define SVCTX_REC_GET_TYPE_META_INFO_EX           ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 14))   /**< Defines the command to get the data of a specified entry in metadata database, pv_get_info: (SVCTX_REC_GET_META_INFO_T *) */
#define SVCTX_REC_GET_TYPE_META_INFO_LEN_EX       ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 15))   /**< Defines the command to get the length of a specified entry in metadata database, pv_get_info: (SVCTX_REC_GET_META_INFO_LEN_T *) */
#define SVCTX_REC_GET_TYPE_REC_STATUS             ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 16))   /*Defines the command to get the record status , true : in recording, false : not is recording , but already connect cm*/
#define SVCTX_REC_GET_TUNER_SERIAL_NO             ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 17))   /**< Defines the get type for tunner serial ID under dual tuner condition, pv_get_info: (UINT32 *) */
#define SVCTX_REC_GET_TYPE_RECORD_START_TIME      ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 18)) /**< Defines the get type for record start time, pv_get_info: (TIME_T *) */
#define SVCTX_REC_GET_TYPE_RECORD_START_UTC_TIME  ((SVCTX_GET_TYPE_T) (SVCTX_GRP_REC | 19)) /**< Defines the get type for record start utc time, pv_get_info: (TIME_T *) */


/* metadata key type */
typedef UINT32 SVCTX_REC_META_KEY_TYPE_T;

/* metadata key types */
#define SVCTX_REC_META_KEY_TYPE_UNKNOWN             ((SVCTX_REC_META_KEY_TYPE_T) 0)     /**< (Unknown) */
#define SVCTX_REC_META_KEY_TYPE_CH_ID               ((SVCTX_REC_META_KEY_TYPE_T) 1)     /**< Defines the metadata key type for channel ID. Data type: (UINT32) */
#define SVCTX_REC_META_KEY_TYPE_CH_NAME             ((SVCTX_REC_META_KEY_TYPE_T) 2)     /**< Defines the metadata key type for channel name. Data type: (CHAR *) */
#define SVCTX_REC_META_KEY_TYPE_FST_EVN_TITLE       ((SVCTX_REC_META_KEY_TYPE_T) 3)     /**< Defines the metadata key type for the title of the first covered event. Data type: (CHAR *) */
#define SVCTX_REC_META_KEY_TYPE_START_TIME          ((SVCTX_REC_META_KEY_TYPE_T) 4)     /**< Defines the metadata key type for record start date & time in UTC time frame. Data type: (TIME_T) */
#define SVCTX_REC_META_KEY_TYPE_DURATION            ((SVCTX_REC_META_KEY_TYPE_T) 5)     /**< Defines the metadata key type for recorded duration in seconds. Note that the entry of this key type is available only when the recording session is stopped. Data type: (UINT32) */
#define SVCTX_REC_META_KEY_TYPE_EXPIRE_TIME         ((SVCTX_REC_META_KEY_TYPE_T) 6)     /**< Defines the metadata key type for the scheduled expiration date & time (in UTC time frame) for the sake of copy protection. Data type: (TIME_T) */
#define SVCTX_REC_META_KEY_TYPE_CIPLUS_PIN          ((SVCTX_REC_META_KEY_TYPE_T) 7)     /**< Defines the metadata key type for the CICAM parent rating. Data type: (PIN_INFO) */
#define SVCTX_REC_META_KEY_TYPE_CIPLUS_LICENSE      ((SVCTX_REC_META_KEY_TYPE_T) 8)     /**< Defines the metadata key type for the CICAM LICENSE. Data type: (CHAR*) */
#define SVCTX_REC_META_KEY_TYPE_CIPLUS_URI          ((SVCTX_REC_META_KEY_TYPE_T) 9)     /**< Defines the metadata key type for the CICAM URI. Data type: (URI_INFO) */
#define SVCTX_REC_META_KEY_TYPE_LOCK_CHANNEL_MASK   ((SVCTX_REC_META_KEY_TYPE_T) 10)    /**< Defines the metadata key type for the locked channel. Data type: (UINT32) */
#define SVCTX_REC_META_KEY_TYPE_CATEGORY            ((SVCTX_REC_META_KEY_TYPE_T) 11)    /**< Defines the metadata key type for the locked channel. Data type: (UINT32) */
#define SVCTX_REC_META_KEY_TYPE_EVENT_DETAIL        ((SVCTX_REC_META_KEY_TYPE_T) 12)    /**< Defines the metadata key type for event detail.  */
#define SVCTX_REC_META_KEY_TYPE_START_UTC_TIME      ((SVCTX_REC_META_KEY_TYPE_T) 13)    /**< Defines the metadata key type for record start date & time in UTC time frame. Data type: (TIME_T) */
#define SVCTX_REC_META_KEY_TYPE_HDD_KEY             ((SVCTX_REC_META_KEY_TYPE_T) 14)    /**< Defines the metadata key type for hdd key. Data type: (MM_CRYPT_INFO_T) */
#define SVCTX_REC_META_KEY_TYPE_INPUT_LOCK          ((SVCTX_REC_META_KEY_TYPE_T) 15)    /**< Defines the metadata key type for the input lock. Data type: (BOOL) */
#define SVCTX_REC_META_KEY_TYPE_CI_PVR_RENTION_TIME ((SVCTX_REC_META_KEY_TYPE_T) 16)    /**< Defines the metadata key type for grouping infoCI plus rention time. */
#define SVCTX_REC_META_KEY_TYPE_18_PLUS             ((SVCTX_REC_META_KEY_TYPE_T) 17)    /**< Defines the metadata key type for DVBS&&M7 operator&& 18+. */
#define SVCTX_REC_META_KEY_TYPE_GROUPING_INFO       ((SVCTX_REC_META_KEY_TYPE_T) 18)    /**< Defines the metadata key type for grouping info. */
#define SVCTX_REC_META_KEY_TYPE_EXCEED_IGNORE_CI    ((SVCTX_REC_META_KEY_TYPE_T) 19)    /**< Defines the metadata key type for check prantel exceed ignore cam condition. */
#define SVCTX_REC_META_KEY_TYPE_FIRST_RATING_RANGE  ((SVCTX_REC_META_KEY_TYPE_T) 20)    /**< Defines the metadata key type for first rating range. */
#define SVCTX_REC_META_KEY_TYPE_MULT_RATING_SHOW    ((SVCTX_REC_META_KEY_TYPE_T) 21)    /**< Defines the metadata key type for first rating range. */
#define SVCTX_REC_META_KEY_TYPE_FILE_ENCRYPT_KEY    ((SVCTX_REC_META_KEY_TYPE_T) 22)    /**< Defines the metadata key type for PVR file encrypt key. */

#define SVCTX_REC_META_KEY_TYPE_LAST_ENTRY          ((SVCTX_REC_META_KEY_TYPE_T) 30)    /**< (Ignore) */

#define SVCTX_REC_META_KEY_TYPE_CUST_DFN            ((SVCTX_REC_META_KEY_TYPE_T) 0x00800000)    /**< Defines the start code for customer-defined key types. */

#define SVCTX_REC_CIPLUS_PIN_CODE_LEN               ((UINT8)9)
#define SVCTX_REC_CIPLUS_EVENT_TTL_EEPROM_LEN       ((UINT8)52)


/* notification function */
/*------------------------------------------------------------------*/
/*! @brief This notify function is called by the REC_HDLR to make a
 *         notification during recording.
 *
 *  @param [in] h_svctx_rec - Contains the handle of the record svctx.
 *  @param [in] pv_nfy_tag  - Contains the tag provided by client.
 *  @param [in] e_code      - Contains the notification code.
 *  @param [in] ui4_data    - Contains the data along with the notification code.
 *  @note  This callback should return as soon as possible.
 *  @see
 *  @return  Returns the boolean flag according to the definition of the notification code (e_code).
 *  @retval  TRUE  - The meaning relates to the notification code (e_code).
 *  @retval  FALSE - The meaning relates to the notification code (e_code).
 */
/*------------------------------------------------------------------*/
typedef BOOL (*x_svctx_rec_nfy_fct) (HANDLE_T               h_svctx_rec,
                                     VOID*                  pv_nfy_tag,
                                     SVCTX_NTFY_CODE_T      e_code,
                                     UINT32                 ui4_data);

/* record condition */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_COND_T
 *  @brief  Specifies the record condition.
 *  @code
 *  typedef enum _SVCTX_REC_COND_T
 *  {
 *    SVCTX_REC_COND_STOPPED,
 *    SVCTX_REC_COND_STARTED,
 *    SVCTX_REC_COND_PAUSED,
 *    SVCTX_REC_COND_ERROR
 *  }  SVCTX_REC_COND_T;
 *  @endcode
 *  @li@c SVCTX_REC_COND_STOPPED - Specifies STOPPED state
 *  @li@c SVCTX_REC_COND_STARTED - Specifies STARTED state
 *  @li@c SVCTX_REC_COND_PAUSED  - Specifies PAUSED state
 *  @li@c SVCTX_REC_COND_ERROR   - Specifies ERROR state
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_COND_T
{
    SVCTX_REC_COND_STOPPED,
    SVCTX_REC_COND_STARTED,
    SVCTX_REC_COND_PAUSED,
    SVCTX_REC_COND_ERROR
} SVCTX_REC_COND_T;

/* record source type */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_SRC_TYPE_T
 *  @brief  Specifies the record source type.
 *  @code
 *  typedef enum _SVCTX_REC_SRC_TYPE_T
 *  {
 *      SVCTX_REC_SRC_TYPE_TV,
 *      SVCTX_REC_SRC_TYPE_AVC
 *  } SVCTX_REC_SRC_TYPE_T;
 *  @endcode
 *  @li@c SVCTX_REC_SRC_TYPE_TV  - Specifies the TV source.
 *  @li@c SVCTX_REC_SRC_TYPE_AVC - Specifies the AVC source
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_SRC_TYPE_T
{
    SVCTX_REC_SRC_TYPE_TV,
    SVCTX_REC_SRC_TYPE_AVC
} SVCTX_REC_SRC_TYPE_T;

/* record profile type */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_PROFILE_T
 *  @brief  Specifies the record profile type.
 *  @code
 *  typedef enum _SVCTX_REC_PROFILE_T
 *  {
 *      SVCTX_REC_PROFILE_SIMPLE = 0,
 *      SVCTX_REC_PROFILE_ADVANCED
 *  } SVCTX_REC_PROFILE_T;
 *  @endcode
 *  @li@c SVCTX_REC_PROFILE_SIMPLE   - Specifies the simple profile.
 *  @li@c SVCTX_REC_PROFILE_ADVANCED - Specifies the advanced profile.
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_PROFILE_T
{
    SVCTX_REC_PROFILE_SIMPLE = 0,
    SVCTX_REC_PROFILE_ADVANCED
} SVCTX_REC_PROFILE_T;

/* record buffer type */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_BUF_MODE_T
 *  @brief  Specifies the record buffer mode.
 *  @code
 *  typedef enum _SVCTX_REC_BUF_MODE_T
 *  {
 *      SVCTX_REC_BUF_MODE_PLAIN,
 *      SVCTX_REC_BUF_MODE_RING
 *  } SVCTX_REC_BUF_MODE_T;
 *  @endcode
 *  @li@c SVCTX_REC_BUF_MODE_PLAIN - Specifies the plain buffer mode
 *  @li@c SVCTX_REC_BUF_MODE_RING  - Specifies the ring buffer mode
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_BUF_MODE_T
{
    SVCTX_REC_BUF_MODE_PLAIN,
    SVCTX_REC_BUF_MODE_RING
} SVCTX_REC_BUF_MODE_T;

/* record buffer bound type */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_BOUND_TYPE_T
 *  @brief  Specifies the record bound type.
 *  @code
 *  typedef enum _SVCTX_REC_BOUND_TYPE_T
 *  {
 *      SVCTX_REC_BOUND_TYPE_TIME,
 *      SVCTX_REC_BOUND_TYPE_SPACE
 *  } SVCTX_REC_BOUND_TYPE_T;
 *  @endcode
 *  @li@c SVCTX_REC_BOUND_TYPE_TIME  - Specifies the time bound type.
 *  @li@c SVCTX_REC_BOUND_TYPE_SPACE - Sepcifies the space bound type.
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_BOUND_TYPE_T
{
    SVCTX_REC_BOUND_TYPE_TIME,
    SVCTX_REC_BOUND_TYPE_SPACE
} SVCTX_REC_BOUND_TYPE_T;

/* record stop option */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_STOP_OPT_T
 *  @brief  Specifies the action when stop recording.
 *  @code
 *  typedef enum _SVCTX_REC_STOP_OPT_T
 *  {
 *      SVCTX_REC_STOP_OPT_NO_CARE,
 *      SVCTX_REC_STOP_OPT_FINALIZE
 *  } SVCTX_REC_STOP_OPT_T;
 *  @endcode
 *  @li@c SVCTX_REC_STOP_OPT_NO_CARE  - No action when stop recording.
 *  @li@c SVCTX_REC_STOP_OPT_FINALIZE - Finalize the recorded file when stop recording.
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_STOP_OPT_T
{
    SVCTX_REC_STOP_OPT_NO_CARE,
    SVCTX_REC_STOP_OPT_FINALIZE
} SVCTX_REC_STOP_OPT_T;

/* continuous option */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_CONT_OPT_T
 *  @brief  Specifies the continuous option.
 *  @code
 *  typedef enum _SVCTX_REC_CONT_OPT_T
 *  {
 *      SVCTX_REC_CONT_OPT_NORMAL,
 *      SVCTX_REC_CONT_OPT_CONT
 *  } SVCTX_REC_CONT_OPT_T;
 *  @endcode
 *  @li@c SVCTX_REC_CONT_OPT_NORMAL - Specifies the normal option
 *  @li@c SVCTX_REC_CONT_OPT_CONT   - Specifies the continuous option
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_CONT_OPT_T
{
    SVCTX_REC_CONT_OPT_NORMAL,
    SVCTX_REC_CONT_OPT_CONT
} SVCTX_REC_CONT_OPT_T;

/* options for no data handling */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_NO_DATA_OPT_T
 *  @brief  Specifies the option for no-data tick handling.
 *  @code
 *  typedef enum _SVCTX_REC_NO_DATA_OPT_T
 *  {
 *      SVCTX_REC_NO_DATA_OPT_KEEP_REC,
 *      SVCTX_REC_NO_DATA_OPT_SKIP_REC
 *  } SVCTX_REC_NO_DATA_OPT_T;
 *  @endcode
 *  @li@c SVCTX_REC_NO_DATA_OPT_KEEP_REC - Specifies the option to keep the no-data tick.
 *  @li@c SVCTX_REC_NO_DATA_OPT_SKIP_REC - Specifies the option to skip the no-data tick.
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_NO_DATA_OPT_T
{
    SVCTX_REC_NO_DATA_OPT_KEEP_REC,
    SVCTX_REC_NO_DATA_OPT_SKIP_REC
} SVCTX_REC_NO_DATA_OPT_T;

/* recording authorization status */
/*------------------------------------------------------------------*/
/*! @enum   SVCTX_REC_AUTH_STATUS_T
 *  @brief  Defines the recording authentication status.
 *  @code
 *  typedef enum _SVCTX_REC_AUTH_STATUS_T
 *  {
 *      SVCTX_REC_AUTH_STATUS_UNKNOWN,
 *      SVCTX_REC_AUTH_STATUS_AUTHORIZED,
 *      SVCTX_REC_AUTH_STATUS_UNAUTHORIZED
 *  } SVCTX_REC_AUTH_STATUS_T;
 *  @endcode
 *  @li@c SVCTX_REC_AUTH_STATUS_UNKNOWN      - Specifies the unknown status.
 *  @li@c SVCTX_REC_AUTH_STATUS_AUTHORIZED   - Specifies the stream is authorized to record.
 *  @li@c SVCTX_REC_AUTH_STATUS_UNAUTHORIZED - Specifies the stream is unauthorized to record.
 */
/*------------------------------------------------------------------*/
typedef enum _SVCTX_REC_AUTH_STATUS_T
{
    SVCTX_REC_AUTH_STATUS_UNKNOWN,
    SVCTX_REC_AUTH_STATUS_AUTHORIZED,
    SVCTX_REC_AUTH_STATUS_UNAUTHORIZED,
    SVCTX_REC_AUTH_STATUS_SCRAMBLE
} SVCTX_REC_AUTH_STATUS_T;

/*-----------------------------------------------------------------------------
                    structures
 ----------------------------------------------------------------------------*/
/* special constant of SVCTX_REC_ES_LIST_T.ui2_idx_prim_video */
#define SVCTX_REC_ES_LIST_IDX_NULL          ((UINT16) 0xFFFF)   /**< Defines the NULL ES-index, could be used
                                                                     in SVCTX_REC_ES_LIST_T.ui2_idx_prim_video, for example */

/* elementary stream info */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_ES_INFO_T
 *  @brief  Defines the information of the ES to be recorded.
 *  @code
 *  typedef struct _SVCTX_REC_ES_INFO_T
 *  {
 *      MPEG_2_PID_T        t_pid;
 *      UINT32              ui4_type_mask;
 *  } SVCTX_REC_ES_INFO_T;
 *  @endcode
 *  @li@c t_pid         - Contains the pid of the ES.
 *  @li@c ui4_type_mask - Specifies the stream types the ES belongs to.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_ES_INFO_T
{
    MPEG_2_PID_T        t_pid;               /* pid */
    UINT32              ui4_type_mask;       /* mask for stream types (ST_MASK_*) */
} SVCTX_REC_ES_INFO_T;

/* elementary stream list to be recorded (SVCTX_REC_SET_ES_LIST) */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_ES_LIST_T
 *  @brief  Contains the ES list.
 *  @code
 *  typedef struct _SVCTX_REC_ES_LIST_T
 *  {
 *      UINT32               ui4_strct_ver;
 *      UINT16               ui2_es_num;
 *      SVCTX_REC_ES_INFO_T* at_es_info;
 *      UINT16               ui2_idx_prim_video;
 *  } SVCTX_REC_ES_LIST_T ;
 *  @endcode
 *  @li@c ui4_strct_ver      - Specifies the structure version, should be 1
 *  @li@c ui2_es_num         - Specifies the number of ES to record
 *  @li@c at_es_info         - Specifies the information array of all ES to be record.
 *  @li@c ui2_idx_prim_video - Specifies the index of primary video ES, specify SVCTX_REC_ES_LIST_IDX_NULL if no video ES
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_ES_LIST_T
{
    UINT32               ui4_strct_ver;       /* structure version, should be 1 */
    UINT16               ui2_es_num;          /* number of ES to record */
    SVCTX_REC_ES_INFO_T* at_es_info;          /* list of ES to record */
    UINT16               ui2_idx_prim_video;  /* index of primary video ES,
                                                 specify SVCTX_REC_ES_LIST_IDX_NULL if no video ES */
} SVCTX_REC_ES_LIST_T ;

/* parameter of SVCTX_REC_SET_TYPE_DEL_REC_DATA */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_DEL_DATA_T
 *  @brief  Contains the pv_set_info of the set type SVCTX_REC_SET_TYPE_DEL_REC_DATA
 *  @code
 *  typedef struct _SVCTX_REC_DEL_DATA_T
 *  {
 *      UINT32               ui4_strct_ver;
 *      CHAR*                s_head_file;
 *  } SVCTX_REC_DEL_DATA_T;
 *  @endcode
 *  @li@c ui4_strct_ver - Specifies the struct version
 *  @li@c s_head_file   - Specifies the head file of the record data to be deleted.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_DEL_DATA_T
{
    UINT32               ui4_strct_ver;     /* structure version, should be 1 */
    CHAR*                s_head_file;       /* path of the head file */
} SVCTX_REC_DEL_DATA_T;

/* permanent attributes of record service context */

/* For record source flag */
#define SVCTX_SVC_RECORD_SRC_TYPE_DTV           MAKE_BIT_MASK_32(0)
#define SVCTX_SVC_RECORD_SRC_TYPE_ATV           MAKE_BIT_MASK_32(1)
#define SVCTX_SVC_RECORD_SRC_TYPE_CVBS          MAKE_BIT_MASK_32(2)

/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_ATTR_T
 *  @brief  Contains the attribute for creating a Record SVCTX object.
 *  @code
 *  typedef struct _SVCTX_REC_ATTR_T
 *  {
 *      UINT32                  ui4_strct_ver;
 *      UINT32                  ui4_flags;
 *      HANDLE_T                h_svctx_lead;
 *      SVCTX_REC_SRC_TYPE_T    e_rec_src_type;
 *      INT8                    i1_prio_diff;
 *  } SVCTX_REC_ATTR_T;
 *  @endcode
 *  @li@c ui4_strct_ver  - Specifies the structure version, should be 1
 *  @li@c ui4_flags      - Reserved, should be 0
 *                                 if version is 1(For DTV Record): reserved, should be 0.
 *                                 If Version is 2(For No-DTV Record, ATV, CVBS  etc.):record source type mask
 *                                     Bit 0: For record DTV
 *                                     Bit 1: For record ATV
 *                                     Bit 2: For record CVBS
 *  @li@c h_svctx_lead   - Specifies the svctx to be followed
 *  @li@c e_rec_src_type - Specifies the record source type
 *  @li@c i1_prio_diff   - Specifies the pipe priority diff with the SVCTX controlling the sink display group
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_ATTR_T
{
    UINT32                  ui4_strct_ver;   /* structure version, should be 1 */
    UINT32                  ui4_flags;       /* reserved, should be 0 */
    HANDLE_T                h_svctx_lead;    /* svctx to be followed */
    SVCTX_REC_SRC_TYPE_T    e_rec_src_type;  /* record source type */
    INT8                    i1_prio_diff;    /* pipe priority diff with the SVCTX controlling the sink display group */
    UINT32                  ui4_rec_no;
} SVCTX_REC_ATTR_T;

/* SVCTX_REC_BOUND_TYPE_TIME bound info (SVCTX_REC_CONFIG_T.pv_bound_info) */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_TIME_BOUND_INFO_T
 *  @brief  Contains the information for time-bound mode.
 *  @code
 *  typedef struct _SVCTX_REC_TIME_BOUND_INFO_T
 *  {
 *      UINT32                  ui4_strct_ver;
 *      UINT32                  ui4_flags;
 *      UINT32                  ui4_ticks;
 *      UINT64                  ui8_tsb_cap;
 *  } SVCTX_REC_TIME_BOUND_INFO_T;
 *  @endcode
 *  @li@c ui4_strct_ver - Specifies the structure version, should be 1
 *  @li@c ui4_flags     - Reserved, should be 0
 *  @li@c ui4_ticks     - Specifies the time bound in ticks
 *  @li@c ui8_tsb_cap   - Specifies the ts buffer capacity in bytes (must be multiple of ui4_sec_size)
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_TIME_BOUND_INFO_T
{
    UINT32                  ui4_strct_ver;   /* structure version, should be 1 */
    UINT32                  ui4_flags;       /* reserved, should be 0 */
    UINT32                  ui4_ticks;       /* the time bound in ticks */
    UINT64                  ui8_tsb_cap;     /* ts buffer capacity in bytes (must be multiple of ui4_sec_size) */
} SVCTX_REC_TIME_BOUND_INFO_T;

/* SVCTX_REC_BOUND_TYPE_SPACE bound size */
#define SVCTX_REC_SPACE_BOUND_UNLIMIT        ((UINT64) 0)  /**< Defines the constant used in SVCTX_REC_SPACE_BOUND_INFO_T.ui8_size */

/* time limit of space bound */
#define SVCTX_REC_SPACE_BOUND_TIME_UNLIMIT   ((UINT32) 0)  /**< Defines the constant used in SVCTX_REC_SPACE_BOUND_INFO_T.ui4_tick_cap */

/* SVCTX_REC_BOUND_TYPE_SPACE bound info (SVCTX_REC_CONFIG_T.pv_bound_info) */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_SPACE_BOUND_INFO_T
 *  @brief  Contains the information for space-bound mode.
 *  @code
 *  typedef struct _SVCTX_REC_SPACE_BOUND_INFO_T
 *  {
 *      UINT32                  ui4_strct_ver;
 *      UINT32                  ui4_flags;
 *      UINT64                  ui8_size;
 *      UINT32                  ui4_tick_cap;
 *  } SVCTX_REC_SPACE_BOUND_INFO_T;
 *  @endcode
 *  @li@c ui4_strct_ver - Specifies the structure version, should be 1
 *  @li@c ui4_flags     - Reserved, should be 0
 *  @li@c ui8_size      - Specifies the space bound in bytes
 *  @li@c ui4_tick_cap  - Specifies the time capacity in ticks
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_SPACE_BOUND_INFO_T
{
    UINT32                  ui4_strct_ver;   /* structure version, should be 1 */
    UINT32                  ui4_flags;       /* reserved, should be 0 */
    UINT64                  ui8_size;        /* the space bound in bytes */
    UINT32                  ui4_tick_cap;    /* time capacity in ticks */
} SVCTX_REC_SPACE_BOUND_INFO_T;

/* storage description */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_STRG_DESC_T
 *  @brief  Contains the storage information.
 *  @code
 *  typedef struct _SVCTX_REC_STRG_DESC_T
 *  {
 *      UINT32       ui4_strct_ver;
 *      CHAR*        s_strg_path;
 *      UINT64       ui8_tsb_offset;
 *      UINT32       ui4_mem_align;
 *      UINT32       ui4_sec_size;
 *      UINT32       ui4_min_access_sec_ns;
 *      UINT32       ui4_max_access_sec_ns;
 *      UINT32       ui4_best_access_sec_ns;
 *  } SVCTX_REC_STRG_DESC_T;
 *  @endcode
 *  @li@c ui4_strct_ver          - Specifies the structure version, should be 1
 *  @li@c s_strg_path            - Specifies the storage path for TS Buffer.
 *  @li@c ui8_tsb_offset         - Specifies offset for TS Buffer from begin of storage in bytes (must be multiple of ui4_sec_size)
 *  @li@c ui4_mem_align          - Specifies memory alignment of device
 *  @li@c ui4_sec_size           - Specifies sector size in bytes
 *  @li@c ui4_min_access_sec_ns  - Specifies minimal access size (in sector number) of device
 *  @li@c ui4_max_access_sec_ns  - Specifies maximal access size (in sector number) of device
 *  @li@c ui4_best_access_sec_ns - Specifies best access size (in sector nunber) suggested by device
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_STRG_DESC_T
{
    UINT32       ui4_strct_ver;           /* structure version, should be 1 */

    CHAR*        s_strg_path;             /* storage path for TS Buffer */
    UINT64       ui8_tsb_offset;          /* offset for TS Buffer from begin of storage in bytes (must be multiple of ui4_sec_size) */

    UINT32       ui4_mem_align;           /* memory alignment of device */
    UINT32       ui4_sec_size;            /* sector size in bytes */
    UINT32       ui4_min_access_sec_ns;   /* minimal access size (in sector number) of device */
    UINT32       ui4_max_access_sec_ns;   /* maximal access size (in sector number) of device */
    UINT32       ui4_best_access_sec_ns;  /* best access size (in sector nunber) suggested by device */

} SVCTX_REC_STRG_DESC_T;

/* normal recording info (SVCTX_REC_CONFIG_T.pv_cont_info) for SVCTX_REC_CONT_OPT_NORMAL */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_CONT_INFO_NORMAL_T
 *  @brief  Contains the normal recording info (SVCTX_REC_CONFIG_T.pv_cont_info) for SVCTX_REC_CONT_OPT_NORMAL
 *  @code
 *  typedef struct _SVCTX_REC_CONT_INFO_NORMAL_T
 *  {
 *      UINT32                  ui4_strct_ver;
 *      UINT32                  ui4_flags;
 *  } SVCTX_REC_CONT_INFO_NORMAL_T;
 *  @endcode
 *  @li@c ui4_strct_ver   - Specifies structure version, should be 1
 *  @li@c ui4_flags       - Reserved, should be 0
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_CONT_INFO_NORMAL_T
{
    UINT32                  ui4_strct_ver;      /* structure version, should be 1 */
    UINT32                  ui4_flags;          /* reserved */
} SVCTX_REC_CONT_INFO_NORMAL_T;

/* continued recording info (SVCTX_REC_CONFIG_T.pv_cont_info) for SVCTX_REC_CONT_OPT_CONT */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_CONT_INFO_CONT_T
 *  @brief  Contains the continued recording info (SVCTX_REC_CONFIG_T.pv_cont_info) for SVCTX_REC_CONT_OPT_CONT
 *  @code
 *  typedef struct _SVCTX_REC_CONT_INFO_CONT_T
 *  {
 *      UINT32                   ui4_strct_ver;
 *      UINT32                   ui4_flags;
 *      CHAR*                    s_strg_path;
 *      UINT64                   ui8_strg_offset;
 *  } SVCTX_REC_CONT_INFO_CONT_T;
 *  @endcode
 *  @li@c ui4_strct_ver   - Specifies structure version, should be 1.
 *  @li@c ui4_flags       - Reserved, should be 0.
 *  @li@c s_strg_path     - Specifies the path for previously stored metadata.
 *  @li@c ui8_strg_offset - Specifies the offset for store location.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_CONT_INFO_CONT_T
{
    UINT32                   ui4_strct_ver;      /* structure version, should be 1 */
    UINT32                   ui4_flags;          /* reserved, should be 0 */
    CHAR*                    s_strg_path;        /* path for previously stored metadata */
    UINT64                   ui8_strg_offset;    /* offset for store location */
} SVCTX_REC_CONT_INFO_CONT_T;

/* record config */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_CONFIG_T
 *  @brief  Contains the record configuration.
 *  @code
 *  typedef struct _SVCTX_REC_CONFIG_T
 *  {
 *      UINT32                      ui4_strct_ver;
 *      UINT32                      ui4_flags;
 *      x_svctx_rec_nfy_fct         pf_rec_nfy;
 *      VOID*                       pv_nfy_tag;
 *      HANDLE_T                    h_svctx_nfy;
 *      VOID*                       pv_rec_purpose;
 *      UINT32                      ui4_ms_tick_period;
 *      SVCTX_REC_PROFILE_T         e_profile;
 *      SVCTX_REC_BUF_MODE_T        e_buf_mode;
 *      SVCTX_REC_BOUND_TYPE_T      e_bound_type;
 *      VOID*                       pv_bound_info;
 *      CHAR*                       s_db_name;
 *      SVCTX_REC_STRG_DESC_T       t_strg_desc;
 *      SVCTX_REC_STOP_OPT_T        e_stop_opt;
 *      SVCTX_REC_CONT_OPT_T        e_cont_opt;
 *      VOID*                       pv_cont_info;
 *      SVCTX_REC_NO_DATA_OPT_T     e_no_data_opt;
 *      ISO_639_LANG_T              s_lang;
 *  } SVCTX_REC_CONFIG_T;
 *  @endcode
 *  @li@c ui4_strct_ver      - Specifies structure version, should be 1.
 *  @li@c ui4_flags          - Reserved, should be 0.
 *  @li@c pf_rec_nfy         - Specifies the record notification function.
 *  @li@c pv_nfy_tag         - Specifies the tag for pf_rec_nfy.
 *  @li@c h_svctx_nfy        - Specifies the the listener of record notification.
 *  @li@c pv_rec_purpose     - Specifies the record purpose.
 *  @li@c ui4_ms_tick_period - Specifies the tick period in ms.
 *  @li@c e_profile          - Specifies the record profile.
 *  @li@c e_buf_mode         - Specifies the buffer operation mode.
 *  @li@c e_bound_type       - Specifies the record bound type.
 *  @li@c pv_bound_info      - Specifies the record bound info.
 *  @li@c s_db_name          - Specifies the record DB name.
 *  @li@c t_strg_desc        - Specifies the storage description.
 *  @li@c e_stop_opt         - Specifies the action option when stop recording.
 *  @li@c e_cont_opt         - Specifies the options for continuous recording.
 *  @li@c pv_cont_info       - Specifies the continuous recording info.
 *  @li@c e_no_data_opt      - Specifies the options for handling no-data case.
 *  @li@c s_lang             - Specifies the system language for recording.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_CONFIG_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    UINT32                      ui4_flags;          /* reserved, should be 0 */
    x_svctx_rec_nfy_fct         pf_rec_nfy;         /* record notify */
    VOID*                       pv_nfy_tag;         /* record notify tag */
    HANDLE_T                    h_svctx_nfy;        /* the listener of record notify */
    VOID*                       pv_rec_purpose;     /* record purpose */
    UINT32                      ui4_ms_tick_period; /* tick period in ms */
    SVCTX_REC_PROFILE_T         e_profile;          /* record profile */
    SVCTX_REC_BUF_MODE_T        e_buf_mode;         /* buffer operation mode */
    SVCTX_REC_BOUND_TYPE_T      e_bound_type;       /* record bound type */
    VOID*                       pv_bound_info;      /* record bound info */
    CHAR*                       s_db_name;          /* record database name */
    SVCTX_REC_STRG_DESC_T       t_strg_desc;        /* storage description */
    SVCTX_REC_STOP_OPT_T        e_stop_opt;         /* options for stop recording */
    SVCTX_REC_CONT_OPT_T        e_cont_opt;         /* options for continuous recording */
    VOID*                       pv_cont_info;       /* continued recording info */
    SVCTX_REC_NO_DATA_OPT_T     e_no_data_opt;      /* options for handling no-data case */
    ISO_639_LANG_T              s_lang;             /* system language for recording */
    CHAR                        ac_pin_code[SVCTX_REC_CIPLUS_PIN_CODE_LEN];       /*save the pin code for cam*/
    BOOL                        b_bgm_pvr;
    UINT8                       ui1_data;           /*reserve data,None zero if need*/
    CHAR*                       ps_dev_name;
    BOOL                        b_fat32_file_sys;
    BOOL                        b_use_ttl_from_ap;
    CHAR                        sv_event_ttl[SVCTX_REC_CIPLUS_EVENT_TTL_EEPROM_LEN];       /*save event id from Ap set*/
    UINT16                      ui2_event_id;
    BOOL                        b_is_input_block;
    BOOL                        b_m7_operator;
    BOOL                        b_check_excd_ignore_ci_cond;
    BOOL                        b_multi_rating_show;
} SVCTX_REC_CONFIG_T;

/* record capability (SVCTX_REC_GET_TYPE_CAPABILITY) */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_CAP_INFO_T
 *  @brief  Contains the information about record capability.
 *  @code
 *  typedef struct _SVCTX_REC_CAP_INFO_T
 *  {
 *      BOOL        b_recordable;
 *  } SVCTX_REC_CAP_INFO_T;
 *  @endcode
 *  @li@c b_recordable - Specifies if recordable or not.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_CAP_INFO_T
{
    BOOL        b_recordable;               /* capability to record this service */

} SVCTX_REC_CAP_INFO_T;

/* system resource information (SVCTX_REC_GET_TYPE_SYS_RES_INFO) */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_SYS_RES_INFO_T
 *  @brief  Contains the information abount system resources.
 *  @code
 *  typedef struct _SVCTX_REC_SYS_RES_INFO_T
 *  {
 *      UINT16      ui2_max_es_num;
 *  } SVCTX_REC_SYS_RES_INFO_T;
 *  @endcode
 *  @li@c ui2_max_es_num - Specifies the maximum number of ES that can be concurrently recorded.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_SYS_RES_INFO_T
{
    UINT16      ui2_max_es_num;             /* max concurrent recording es number */

} SVCTX_REC_SYS_RES_INFO_T;

/* recording status (SVCTX_REC_GET_TYPE_STATUS) */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_STATUS_T
 *  @brief  Contains the current recording status.
 *  @code
 *  typedef struct _SVCTX_REC_STATUS_T
 *  {
 *      SVCTX_REC_COND_T  e_rec_cond;
 *      UINT64            ui8_avail;
 *      UINT64            ui8_fullness;
 *      UINT32            ui4_time_bound;
 *      UINT32            ui4_rec_start;
 *      UINT32            ui4_rec_end;
 *  } SVCTX_REC_STATUS_T;
 *  @endcode
 *  @li@c e_rec_cond     - Specifies the recording condition.
 *  @li@c ui8_avail      - Specifies the available space to record in bytes.
 *  @li@c ui8_fullness   - Specifies the recorded data size in bytes.
 *  @li@c ui4_time_bound - Specifies the recording time bound in ticks, 0 if SPACE bound.
 *  @li@c ui4_rec_start  - Specifies the recorded range start in tick.
 *  @li@c ui4_rec_end    - Specifies the recorded range end in tick.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_STATUS_T
{
    SVCTX_REC_COND_T  e_rec_cond;           /* recording condition */
    UINT64            ui8_avail;            /* available space to record in bytes */
    UINT64            ui8_fullness;         /* recorded data size in bytes */
    UINT32            ui4_time_bound;       /* recording time bound in ticks, 0 if SPACE bound */
    UINT32            ui4_rec_start;        /* recorded range start in tick */
    UINT32            ui4_rec_end;          /* recorded range end in tick */
} SVCTX_REC_STATUS_T;

/* authorization info of an es */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_ES_AUTH_INFO_T
 *  @brief  Contains the authentication info of an ES.
 *  @code
 *  typedef struct _SVCTX_REC_ES_AUTH_INFO_T
 *  {
 *      SVCTX_REC_ES_INFO_T         t_info;
 *      SVCTX_REC_AUTH_STATUS_T     e_auth_st;
 *  } SVCTX_REC_ES_AUTH_INFO_T;
 *  @endcode
 *  @li@c t_info    - Contains the ES info.
 *  @li@c e_auth_st - Contains the authentication status.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_ES_AUTH_INFO_T
{
    SVCTX_REC_ES_INFO_T         t_info;     /* es info */
    SVCTX_REC_AUTH_STATUS_T     e_auth_st;  /* recording authorization status */
} SVCTX_REC_ES_AUTH_INFO_T;

/* authorization status of es list (SVCTX_REC_GET_TYPE_ESL_AUTH_STATUS) */
/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_ESL_AUTH_STATUS_T
 *  @brief  Contains the authentication status of all ES.
 *  @code
 *  typedef struct _SVCTX_REC_ESL_AUTH_STATUS_T
 *  {
 *      UINT16                      ui2_es_num_cap;
 *      SVCTX_REC_ES_AUTH_INFO_T*   at_es_auth_info;
 *      UINT16                      ui2_es_num_ret;
 *  } SVCTX_REC_ESL_AUTH_STATUS_T;
 *  @endcode
 *  @li@c ui2_es_num_cap  - (in) Contains the capacity of the array at_es_auth_info.
 *  @li@c at_es_auth_info - (in/out) Contains the authentication info of all ES.
 *  @li@c ui2_es_num_ret  - (out) Contains the returned number of ES authentication info entry.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_ESL_AUTH_STATUS_T
{
    UINT16                      ui2_es_num_cap;     /* IN, capacity of at_es_auth_info */
    SVCTX_REC_ES_AUTH_INFO_T*   at_es_auth_info;    /* IN/OUT, authorization info for es */
    UINT16                      ui2_es_num_ret;     /* OUT, actual es number */
} SVCTX_REC_ESL_AUTH_STATUS_T;

/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_META_DB_OPEN_T
 *  @brief  Defines the parameter structure used in pv_set_info when e_set_type is SVCTX_REC_SET_TYPE_META_DB_OPEN.
 *  @code
 *  typedef struct _SVCTX_REC_META_DB_OPEN_T
 *  {
 *      UINT32                      ui4_strct_ver;
 *      CHAR*                       s_head_file;
 *      HANDLE_T                    h_meta_db;
 *  } SVCTX_REC_META_DB_OPEN_T;
 *  @endcode
 *
 *  @li@c ui4_strct_ver  - (in)  Specifies the structure version, should be 1
 *  @li@c s_head_file    - (in)  Specifies the full path of the PVR head file.
 *  @li@c h_meta_db      - (out) Returns the handle of the opened metadata database.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_META_DB_OPEN_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    CHAR*                       s_head_file;        /* in */
    HANDLE_T                    h_meta_db;          /* out */
} SVCTX_REC_META_DB_OPEN_T;

/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_META_DB_CLOSE_T
 *  @brief  Defines the parameter structure used in pv_set_info when e_set_type is SVCTX_REC_SET_TYPE_META_DB_CLOSE.
 *  @code
 *  typedef struct _SVCTX_REC_META_DB_CLOSE_T
 *  {
 *      UINT32                      ui4_strct_ver;
 *      HANDLE_T                    h_meta_db;
 *  } SVCTX_REC_META_DB_CLOSE_T;
 *  @endcode
 *
 *  @li@c ui4_strct_ver  - (in) Specifies the structure version, should be 1
 *  @li@c h_meta_db      - (in) Specifies the handle of the metadata database.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_META_DB_CLOSE_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
} SVCTX_REC_META_DB_CLOSE_T;

/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_META_DB_STORE_T
 *  @brief  Defines the parameter structure used in pv_set_info when e_set_type is SVCTX_REC_SET_TYPE_META_DB_STORE.
 *  @code
 *  typedef struct _SVCTX_REC_META_DB_STORE_T
 *  {
 *      UINT32                      ui4_strct_ver;
 *      HANDLE_T                    h_meta_db;
 *  } SVCTX_REC_META_DB_STORE_T;
 *  @endcode
 *
 *  @li@c ui4_strct_ver  - (in) Specifies the structure version, should be 1
 *  @li@c h_meta_db      - (in) Specifies the handle of the metadata database.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_META_DB_STORE_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
} SVCTX_REC_META_DB_STORE_T;

/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_SET_META_INFO_T
 *  @brief  Defines the parameter structure used in pv_set_info when e_set_type is SVCTX_REC_SET_TYPE_META_INFO.
 *  @code
 *  typedef struct _SVCTX_REC_SET_META_INFO_T
 *  {
 *      UINT32                      ui4_strct_ver;
 *      HANDLE_T                    h_meta_db;
 *      SVCTX_REC_META_KEY_TYPE_T   e_key_type;
 *      VOID*                       pv_data;
 *      SIZE_T                      z_data_len;
 *  } SVCTX_REC_SET_META_INFO_T;
 *  @endcode
 *
 *  @li@c ui4_strct_ver  - (in) Specifies the structure version, should be 1
 *  @li@c h_meta_db      - (in) Specifies the handle of the metadata database.
 *  @li@c e_key_type     - (in) Specifies the customer-defined key type. Note that the key type here must be a customer-defined key type.
 *  @li@c pv_data        - (in) Contains the data to be set. Specify NULL if z_data_len = 0.
 *  @li@c z_data_len     - (in) Specifies the length of the data to be set. If 0, pv_data can be NULL.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_SET_META_INFO_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
    SVCTX_REC_META_KEY_TYPE_T   e_key_type;         /* in */
    VOID*                       pv_data;            /* in */
    SIZE_T                      z_data_len;         /* in */
} SVCTX_REC_SET_META_INFO_T;

/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_GET_META_INFO_LEN_T
 *  @brief  Defines the parameter structure used in pv_set_info when e_set_type is SVCTX_REC_GET_TYPE_META_INFO_LEN.
 *  @code
 *  typedef struct _SVCTX_REC_GET_META_INFO_LEN_T
 *  {
 *      UINT32                      ui4_strct_ver;
 *      HANDLE_T                    h_meta_db;
 *      SVCTX_REC_META_KEY_TYPE_T   e_key_type;
 *      SIZE_T                      z_data_len;
 *  } SVCTX_REC_GET_META_INFO_LEN_T;
 *  @endcode
 *
 *  @li@c ui4_strct_ver  - (in)  Specifies the structure version, should be 1
 *  @li@c h_meta_db      - (in)  Specifies the handle of the metadata database.
 *  @li@c e_key_type     - (in)  Specifies the key type.
 *  @li@c z_data_len     - (out) Returns the data length of the specified key type.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_GET_META_INFO_LEN_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
    SVCTX_REC_META_KEY_TYPE_T   e_key_type;         /* in */
    UINT32                      z_data_len;         /* out */
} SVCTX_REC_GET_META_INFO_LEN_T;

typedef struct _SVCTX_REC_GET_META_INFO_LEN_T_EX
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
    SVCTX_REC_META_KEY_TYPE_T   e_key_type;         /* in */
    UINT32                      z_data_len;         /* out */
    UINT16                      ui2_meta_idx;
} SVCTX_REC_GET_META_INFO_LEN_T_EX;


typedef struct _SVCTX_REC_GET_META_INFO_COUNT_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
    SVCTX_REC_META_KEY_TYPE_T   e_key_type;         /* in */
    UINT16                      z_data_count;         /* out */
} SVCTX_REC_GET_META_INFO_COUNT_T;

typedef struct _REC_UTIL_EVENT_DETAIL_INFO_T
{
    TIME_T                      t_start_time;
    TIME_T                      t_duration;
    UINT32                      ui4_short_event_len;
    UINT32                      ui4_extend_event_len;
}REC_UTIL_EVENT_DETAIL_INFO_T;

/*----------------------------------------------------------------------------*/
/*! @struct SVCTX_REC_GET_META_INFO_T
 *  @brief  Defines the parameter structure used in pv_set_info when e_set_type is SVCTX_REC_GET_TYPE_META_INFO.
 *  @code
 *  typedef struct _SVCTX_REC_GET_META_INFO_T
 *  {
 *      UINT32                      ui4_strct_ver;
 *      HANDLE_T                    h_meta_db;
 *      SVCTX_REC_META_KEY_TYPE_T   e_key_type;
 *      VOID*                       pv_buf;
 *      SIZE_T                      z_buf_len;
 *      SIZE_T                      z_data_len;
 *  } SVCTX_REC_GET_META_INFO_T;
 *  @endcode
 *
 *  @li@c ui4_strct_ver  - (in)  Specifies the structure version, should be 1
 *  @li@c h_meta_db      - (in)  Specifies the handle of the metadata database.
 *  @li@c e_key_type     - (in)  Specifies the key type.
 *  @li@c pv_buf         - (in/out) Spcifies the buffer address to receive the data.
 *  @li@c z_buf_len      - (in)  Specifies the capacity of the buffer.
 *  @li@c z_data_len     - (out) Specifies the received data length.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SVCTX_REC_GET_META_INFO_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
    SVCTX_REC_META_KEY_TYPE_T   e_key_type;         /* in */
    VOID*                       pv_buf;             /* in/out */
    SIZE_T                      z_buf_len;          /* in */
    SIZE_T                      z_data_len;         /* out */
} SVCTX_REC_GET_META_INFO_T;

typedef struct _SVCTX_REC_GET_META_INFO_T_EX
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
    SVCTX_REC_META_KEY_TYPE_T   e_key_type;         /* in */
    VOID*                       pv_buf;             /* in/out */
    SIZE_T                      z_buf_len;          /* in */
    SIZE_T                      z_data_len;         /* out */
    UINT16                      ui2_meta_idx;    /* in */
} SVCTX_REC_GET_META_INFO_T_EX;

/* record info, SRC_DESC_T's pv_details when e_type = SRC_TYPE_RECORD */
/*----------------------------------------------------------------------------*/
/*! @struct SRC_REC_INFO_T
 *  @brief  Contains the record info. It's SRC_DESC_T's pv_details when e_type = SRC_TYPE_RECORD
 *  @code
 *  typedef struct _SRC_REC_INFO_T
 *  {
 *      SRC_TYPE_T        e_src_rec;
 *      VOID*             pv_detail;
 *  } SRC_REC_INFO_T;
 *  @endcode
 *  @li@c e_src_rec - Specifies the source type of target content to record
 *  @li@c pv_detail - Specifies the detail information corresponding to e_src_rec.
 */
/*----------------------------------------------------------------------------*/
typedef struct _SRC_REC_INFO_T
{
    SRC_TYPE_T        e_src_rec;            /* record source */
    VOID*             pv_detail;            /* detail info */
} SRC_REC_INFO_T;
/*---------------------------------------------------------
   ps_rec_dir  :
           The path of the directory to gengrate the wrapper files.

   ps_meta_file:
           s_meta_file is valid only when e_meta_policy equals to FM_MFW_VF_META_POLICY_VISIBLE_META_FILE
           s_meta_file is file name only, should not contain any path.

   ps_pattern_file:
           s_fn_pattern is used for generate the name of the files in the wrapper.
           s_fn_pattern should like "xxxxxx%xdxxx"(for example, "Timeshift_PRG1_%03d.ts"), otherwise the result is unknown.
           s_fn_pattern is file name only, should not contain any path.

    ui2_path_size  :Path name size.
    ui8_file_size    :File size to limit.
    ui4_data        : Reserve.
    --------------------------------------------------------*/
typedef struct _REC_FILE_INFO_T
{
    CHAR*                   ps_rec_dir;
    CHAR*                   ps_meta_file;
    CHAR*                   ps_pattern_file;
    x_fm_mfw_async_fct      pf_nfy;
    VOID*                   pv_tag;
    UINT64                  ui8_file_size;
    UINT32                  ui4_data;
}SVCTX_REC_FILE_INFO_T;
/*-------------------------------------------------------------------

----------------------------------------------------------------*/
typedef struct _REC_FILE_ATTR_T
{
    UINT64      ui8_size;
    UINT32      ui4_blk_size;
    UINT64      ui8_blk_cnt;
    TIME_T      ui8_create_time;
    TIME_T      ui8_access_time;
    TIME_T      ui8_modify_time;

    UINT32      ui4_start_lba;
    BOOL        b_copy_protected;

}SVCTX_GET_REC_FILE_ATTR_T;

typedef struct _SVCTX_REC_STATUS_INFO_T
{
    BOOL        b_is_recording;            /* recording or not*/
    UINT16      ui2_svc_lst_id;            /*service list identify*/
    UINT16      ui2_svl_rec_id;            /*svl record identify*/
    UINT32      ui4_rec_hdlr_no;           /*rec handler No*/
} SVCTX_REC_STATUS_INFO_T;

typedef enum
{
    REC_UTIL_CIPLUS_TYPE_UNKNOWN = 100,/**reserve type for ap,defined in u_rec_hdlr.h*/
    REC_UTIL_CIPLUS_TYPE_CICAM,   /***CICAM info:UINT16(camID):*/
    REC_UTIL_CIPLUS_TYPE_PIN,     /***PIN info:TIME_T + UINT16 + CI_PIN_PLAYBACK_T*/
    REC_UTIL_CIPLUS_TYPE_LICENSE, /***LICENSE info:TIME_T + UINT16 + CI_LICENSE_Playback_T + LICENSE*/
    REC_UTIL_CIPLUS_TYPE_CP,      /***CP info:TIME_T + UINT16 + UINT32(rention limit)*/
    REC_UTIL_RATING_INFO,         /***store the rating info */
    REC_UTIL_GUIDANDCE_INFO,
    REC_UTIL_CIPLUS_TYPE_CCI,
    REC_UTIL_ENCRYPT_SEED,
    REC_UTIL_CIPLUS_TYPE_TRICK,
    REC_UTIL_CIPLUS_TYPE_LAST
}REC_UTIL_CIPLUS_INFO_TYPE_T;

typedef struct _REC_UTIL_CIPLUS_INFO_T
{
    TIME_T  t_time;
    UINT16  ui2_millisec;
    BOOL    b_ca_sys_id_match;
    UINT8   ui1_cap_rating;
    UINT64  ui8_pos;              // timeshift is lba
    BOOL    b_ci_trick_disable;   /* if true, do not allow do trick*/
    BOOL    b_ci_trick_played_once;
    UINT32  ui4_tick_time;
    union
    {
        CI_PIN_PLAYBACK_T          t_pin_pb;
        CI_LICENSE_Playback_T      t_license_pb;
        CP_INFO_LIST_T             t_cp_info;
        UINT32                     ui4_rention_time;
    }u;

}REC_UTIL_CIPLUS_INFO_T;

#pragma pack(4)
typedef struct _SVCTX_REC_GET_META_INFO_EX_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    HANDLE_T                    h_meta_db;          /* in */
    SVCTX_REC_META_KEY_TYPE_T   e_key_type;         /* in */
    UNION_POINTER_T             pv_buf;             /* in/out */
    UINT32                      z_buf_len;          /* in */
    UINT32                      z_data_len;         /* out */
} SVCTX_REC_GET_META_INFO_EX_T;

typedef struct _SVCTX_REC_STRG_DESC_EX_T
{
    UINT32           ui4_strct_ver;           /* structure version, should be 1 */
    
    UNION_POINTER_T  s_strg_path;             /* storage path for TS Buffer */
    UINT64           ui8_tsb_offset;          /* offset for TS Buffer from begin of storage in bytes (must be multiple of ui4_sec_size) */
    
    UINT32           ui4_mem_align;           /* memory alignment of device */
    UINT32           ui4_sec_size;            /* sector size in bytes */
    UINT32           ui4_min_access_sec_ns;   /* minimal access size (in sector number) of device */
    UINT32           ui4_max_access_sec_ns;   /* maximal access size (in sector number) of device */
    UINT32           ui4_best_access_sec_ns;  /* best access size (in sector nunber) suggested by device */
    
} SVCTX_REC_STRG_DESC_EX_T;

typedef struct _SVCTX_REC_CONFIG_EX_T
{
    UINT32                      ui4_strct_ver;      /* structure version, should be 1 */
    UINT32                      ui4_flags;          /* reserved, should be 0 */
    UNION_POINTER_T             pf_rec_nfy;         /* record notify */
    UNION_POINTER_T             pv_nfy_tag;         /* record notify tag */
    HANDLE_T                    h_svctx_nfy;        /* the listener of record notify */
    UNION_POINTER_T             pv_rec_purpose;     /* record purpose */
    UINT32                      ui4_ms_tick_period; /* tick period in ms */
    SVCTX_REC_PROFILE_T         e_profile;          /* record profile */
    SVCTX_REC_BUF_MODE_T        e_buf_mode;         /* buffer operation mode */
    SVCTX_REC_BOUND_TYPE_T      e_bound_type;       /* record bound type */
    UNION_POINTER_T             pv_bound_info;      /* record bound info */
    UNION_POINTER_T             s_db_name;          /* record database name */
    SVCTX_REC_STRG_DESC_EX_T    t_strg_desc;        /* storage description */
    SVCTX_REC_STOP_OPT_T        e_stop_opt;         /* options for stop recording */
    SVCTX_REC_CONT_OPT_T        e_cont_opt;         /* options for continuous recording */
    UNION_POINTER_T             pv_cont_info;       /* continued recording info */
    SVCTX_REC_NO_DATA_OPT_T     e_no_data_opt;      /* options for handling no-data case */
    UNION_POINTER_T             s_lang;             /* system language for recording */
    CHAR                        ac_pin_code[SVCTX_REC_CIPLUS_PIN_CODE_LEN];       /*save the pin code for cam*/
    BOOL                        b_bgm_pvr;
    UINT8                       ui1_data;           /*reserve data,None zero if need*/
    UNION_POINTER_T             ps_dev_name;
    BOOL                        b_fat32_file_sys;
	CHAR                        sv_event_ttl[SVCTX_REC_CIPLUS_EVENT_TTL_EEPROM_LEN];       /*save event id from Ap set*/
    UINT16                      ui2_event_id;
    BOOL                        b_is_input_block;
} SVCTX_REC_CONFIG_EX_T;
#pragma pack()
/*-----------------------------------------------------------------------------
                    functions declarations
 ----------------------------------------------------------------------------*/


#endif  /* _U_REC_HDLR_H_ */
