/* 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 c_sm.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This header file contains Stream Manager specific definitions,
 *         which are exported to applications.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_STRM_MNGR Stream Manager
 *
 *  @ingroup groupMW
 *  @brief Provides stream manager external function for TV Application
 *
 *
 *  @see groupMW
 *  @{ 
 */
/*----------------------------------------------------------------------------*/


#ifndef _C_SM_H_
#define _C_SM_H_    /**<        */


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

#include "u_sm.h"

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


/*-----------------------------------------------------------------------------
                    functions declarations
-----------------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/*! @brief           This function is used to open a session of Stream Manager.
 *  @param [in]    h_connection     The connection handle created by connection  Manager.
 *  @param [in]    ps_sess_name     References to the name of session handler.
 *  @param [in]    pv_sess_data     References to the data used by the session handler.
 *  @param [in]    z_sess_data_size Contains the size of data used by session handler.
 *  @param [in]    i4_speed         Coantins the default play speed of this session.
 *  @param [in]    pf_sess_nfy      References to the session event callback funtion,which should be implement by the caller.
 *  @param [in]    pv_sess_nfy_tag  References to a caller specifiec tag, which will be pass into the pf_sess_nfy callback function.
 *  @param [out]  ph_sess          References to the session handle created by this function .
 *  @note
 *  @see
 *  @return    Return the error code
 *  @retval      -SMR_OK                       Success.
 *  @retval      -SMR_INV_HANDLE               The h_connection is invalid.
 *  @retval      -SMR_INV_ARG                  The ph_sess, pv_sess_date, z_sess_data_size, ps_sess_name or  pf_sess_nfy is invalid.
 *  @retval      -SMR_SESS_ALREADY_EXIST       The session correlsponding to the connection is already opened.
 *  @retval      -SMR_HDLR_NOT_REGISTERED_YET  The ps_sess_name references to no  session handler.
 *  @retval      -SMR_INTERNAL_ERROR           A serious internal error.
 *  @retval      -SMR_INSUFFICIENT_MEMORY      Not enough memory resource.
 *  @retval      -SMR_NOT_INIT                 The Stream Manager is not initialized yet.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_open_sess( HANDLE_T              h_connection,
                             const CHAR*           ps_sess_name,
                             const CHAR*           ps_dest_grp_name,
                             VOID*                 pv_sess_data,
                             SIZE_T                z_sess_data_size,
                             INT32                 i4_speed,
                             x_sess_nfy_fct        pf_sess_nfy,
                             VOID*                 pv_sess_nfy_tag,
                             HANDLE_T*             ph_sess );

/*------------------------------------------------------------------*/
/*! @brief  This function is used to close a session of Stream Manager.
 *  @param [in] h_sess References to handle of the session.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_close_sess( HANDLE_T             h_sess );

/*------------------------------------------------------------------*/
/*! @brief   This function is used to play a session of Stream Manager.
 *  @param [in]  h_sess   References to handle of the session.
 *  @param [in]  i4_speed References to speed fo the play.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_play_sess( HANDLE_T              h_sess,
                             INT32                 i4_speed );

/*------------------------------------------------------------------*/
/*! @brief     This function is used to stop a  Stream .
 *  @param [in]   h_sess References to handle of the session.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_stop_sess( HANDLE_T              h_sess );

/*------------------------------------------------------------------*/
/*! @brief      This function is used to open a stream in a specific session.
 *  @param [in]   h_sess          References to the session.
 *  @param [in]   pt_strm_comp_id References to the component ID aquired from SCDB.
 *  @param [in]   pt_cmd          References to the command sets to initialize the stream.
 *  @param [in]    pf_strm_nfy     References to a stream event callback function, which is implemented by the caller.
 *  @param [in]  pv_strm_nfy_tag References to a tag to be pass to the stream event  callback function.
 *  @param [in]  b_auto_play     Indicate if the stream sould play automatically.
 *  @param [out] ph_stream       References to the stream handle created by Stream  Manager. 
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 *  @retval      -SMR_NOT_SUPPORT     There is no stream handler that support this type of stream.
 *  @retval      - SMR_INV_ARG         The argument ph_stream, pf_strm_nfy, or pt_strm_comp_id is invalid.
 */
/*------------------------------------------------------------------*/

extern INT32 c_sm_open_stream( HANDLE_T                 h_sess,
                               const STREAM_COMP_ID_T*  pt_strm_comp_id,
                               const SM_COMMAND_T*      pt_cmd_sets,
                               x_stream_nfy_fct         pf_strm_nfy,
                               VOID*                    pv_strm_nfy_tag,
                               BOOL                     b_auto_play,
                               HANDLE_T*                ph_stream ); /* OUT */


/*------------------------------------------------------------------*/
/*! @brief  This function is used to close a stream of Stream Manager.
 *  @param [in]  h_stream References to the handle of the stream.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/

extern INT32 c_sm_close_stream( HANDLE_T           h_stream );

/*------------------------------------------------------------------*/
/*! @brief  This function is used to play a stream of Stream Manager
 *  @param [in] h_stream References to the handle of the stream.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_play_stream( HANDLE_T            h_stream );

/*------------------------------------------------------------------*/
/*! @brief   This function is used to stop a stream of Stream Manager
 *  @param [in]  h_stream References to the handle of the stream.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_stop_stream( HANDLE_T            h_stream );

/*------------------------------------------------------------------*/
/*! @brief  This function is used to set the attribuites of a stream or a session.
 *  @param [in]  h_sm_handle       References to handle of a session or stream.
 *  @param [in]  e_set_type        References to the type of attributes to set.
 *  @param [in]  pv_set_info       References to the data information of the set type.
 *  @param [in]  ui4_set_info_size Contains the size of data information of the set type.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_set( HANDLE_T            h_sm_handle,
                       SM_SET_TYPE_T       e_set_type,
                       VOID*               pv_set_info,
                       SIZE_T              z_set_info_size );

/*------------------------------------------------------------------*/
/*! @brief  This function is used to get the attribuites of a stream or a session.
 *  @param [in]  h_sm_handle        References to handle of a session or stream.
 *  @param [in]  e_get_type         References to the type of attributes to get.
 *  @param [in]   pv_get_info        References to the data information of the get   type.
 *  @param [in]   pui4_get_info_size References to the size of data information of the get type.
 *  @note
 *  @see
 *  @return
 *  @retval      -SMR_OK              Success.
 *  @retval      -SMR_INTERNAL_ERROR  A serious internal error.
 *  @retval      -SMR_INV_HANDLE      The h_sess is invalid.
 */
/*------------------------------------------------------------------*/
extern INT32 c_sm_get( HANDLE_T            h_sm_handle,
                       SM_GET_TYPE_T       e_get_type,
                       VOID*               pv_get_info,          /* IN/OUT */
                       SIZE_T*             pz_get_info_size );   /* IN/OUT */


#endif /* _C_SM_H_ */
/*----------------------------------------------------------------------------*/
/*! @} */                                              /* end of groupMW_STRM_MNGR */
/*----------------------------------------------------------------------------*/

