/* 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 x_sm_sess_rcrd.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/11/10 $
 *  $Author: dtvbm11 $
 *  
 *  @par Description:
 *         This header file contains Stream Manager's record session exported  
 *         definitions.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_STRM_MNGR_SESS_RCRD_HDLR Record Session Handler
 *
 *  @ingroup groupMW_STRM_MNGR
 *  @brief Provides record session external functions for TV timeshift or simple
 *   PVR Application
 *
 *  %MW Application API would be used by TV Application, lot of these APIs would
 *   be wrapped from Exported API
 *
 *  @see groupMW_STRM_MNGR
 *  @{ 
 */
/*----------------------------------------------------------------------------*/
#ifndef _X_SM_SESS_RCRD_H_
#define _X_SM_SESS_RCRD_H_

/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/
#include "u_sm_sess_rcrd.h"
#include "u_sm_event.h"


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

#define SM_SESS_RCRD_UTIL_NAME_LEN       SYS_NAME_LEN

/*Event main subgroups: APP, PVR Ctrl, PM Record Utilty*/
/*The first sub group 0 is for APP which defined in u_sm_rcrd_hdlr.h */
#define SM_EVN_SESS_RCRD_GRP_PVR   SM_MAKE_EVN_GRP(SM_EVN_GRP_SESS_RCRD, 1)
#define SM_EVN_SESS_RCRD_GRP_PM    SM_MAKE_EVN_GRP(SM_EVN_GRP_SESS_RCRD, 2)
#define SM_EVN_SESS_RCRD_GRP_RUTI  SM_MAKE_EVN_GRP(SM_EVN_GRP_SESS_RCRD, 3)
#define SM_EVN_SESS_RCRD_GRP_STRM  SM_MAKE_EVN_GRP(SM_EVN_GRP_SESS_RCRD, 4)


/*PVR events state machine: 
    |--------------------------
    |        -OVERFLOW--      |
    |       ^    |     |      |
    |       |    |     V      V
 OPENED->PLAYED<->STOPPED->CLOSED
    |      |     |    |       ^
    |      V     V    V       |
    |----->    Error   ------->
    Note: 1)Herein Overflow means PVR Ctrl has been disabled in driver so should transfer 
            to stop and if all data has been written down then restart session again .All 
            are automatical.
          2)Played means enable PVR ctrl,Stopped means disable enable
          3)Opened means PVR Ctrl default is disable
*/
#define SM_EVN_SESS_RCRD_PVR_OPENED         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PVR, 0)
#define SM_EVN_SESS_RCRD_PVR_PLAYED         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PVR, 1)
#define SM_EVN_SESS_RCRD_PVR_STOPPED        SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PVR, 2)
#define SM_EVN_SESS_RCRD_PVR_CLOSED         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PVR, 3)
#define SM_EVN_SESS_RCRD_PVR_OVERFLOW       SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PVR, 4)
#define SM_EVN_SESS_RCRD_PVR_FLUSHED        SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PVR, 5)
#define SM_EVN_SESS_RCRD_PVR_ERR            SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PVR, 6)

/*PM events state machine:
    |------------------------|
    |                        V
 OPENED->PLAYED<->STOPPED->CLOSED
    |      |         |       ^
    |      V         V       |
    |----->   Error   ------->
    Note: State is acording to PM APIs
*/
#define SM_EVN_SESS_RCRD_PM_COND_OPENED     SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PM, 0)
#define SM_EVN_SESS_RCRD_PM_COND_PLAYED     SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PM, 1)
#define SM_EVN_SESS_RCRD_PM_COND_STOPPED    SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PM, 2)
#define SM_EVN_SESS_RCRD_PM_COND_CLOSED     SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PM, 3)
#define SM_EVN_SESS_RCRD_PM_COND_ERR        SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_PM, 4)


/*Record utility  events state machine: 
    |---------CLOSED------------------------------|
    |       ^             ^                ^      |
    |      |   ---------------------------|       |  
    |      |    |        |                |       |
    |      |    V        |                |       |
 OPENED->TRANSITION<->READY_>PLAYED<->STOPPED     |
    |      |           |         |        |       |
    |      V           V         V        V       |
    |----->   Error   ------->---------------------
  Note: 1)Herein played means record utility is writing data so in this status can not
          be stoppted immediately
        2)stopped means record utility is ready,When opened its default is ready
*/
#define SM_EVN_SESS_RCRD_RUTI_OPENED      SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 0)
#define SM_EVN_SESS_RCRD_RUTI_READY       SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 1)
#define SM_EVN_SESS_RCRD_RUTI_TRANSITION  SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 2)
#define SM_EVN_SESS_RCRD_RUTI_PLAYED      SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 3)
#define SM_EVN_SESS_RCRD_RUTI_STOPPED     SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 4)
#define SM_EVN_SESS_RCRD_RUTI_CLOSED      SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 5)
#define SM_EVN_SESS_RCRD_RUTI_REACH_BOUND SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 6)
#define SM_EVN_SESS_RCRD_RUTI_STRG_FULL   SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 7)
#define SM_EVN_SESS_RCRD_RUTI_ERR         SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 8)
#define SM_EVN_SESS_RCRD_RUTI_REACH_TIME_BOUND   SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 9)
#define SM_EVN_SESS_RCRD_RUTI_BUF_FULL   SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_RUTI, 10)




/*Stream events:
  Note: 1)This state is same to stream handler
        2)If a stream is requested to open then add or if requested to close then del
        3)All_XXX means they are in same state
*/
#define SM_EVN_SESS_RCRD_STRM_ADD           SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 0)
#define SM_EVN_SESS_RCRD_STRM_DEL           SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 1)
#define SM_EVN_SESS_RCRD_STRM_OPENED        SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 2)
#define SM_EVN_SESS_RCRD_STRM_PLAYED        SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 3)
#define SM_EVN_SESS_RCRD_STRM_CLOSED        SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 4)
#define SM_EVN_SESS_RCRD_STRM_ALL_OPENED    SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 5)
#define SM_EVN_SESS_RCRD_STRM_ALL_PLAYED    SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 6)
#define SM_EVN_SESS_RCRD_STRM_ALL_CLOSED    SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 7)
#define SM_EVN_SESS_RCRD_STRM_ERR           SM_MAKE_EVN(SM_EVN_SESS_RCRD_GRP_STRM, 8)


/*-----------------------------------------------------------------------------
                    Functions declarations
-----------------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/*! @brief
 *  @param [in]
 *  @param [out]
 *  @note
 *  @see
 *  @return
 *  @retval      -
 */
/*------------------------------------------------------------------*/
extern INT32 x_sm_sess_rcrd_init(VOID);


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


