/* 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_sbtl_hdlr.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This header file contains Subtitle Stream handler specific 
 *         definitions, which are exported to applications.
 */
/*----------------------------------------------------------------------------*/

#ifndef _U_SM_SBTL_HDLR_H_
#define _U_SM_SBTL_HDLR_H_

/*----------------------------------------------------------------------------*/
/*! @defgroup groupMW_STRM_MNGR_SBTL_HDLR DVB Subtitle Handler
  *  @ingroup groupMW_STRM_MNGR
  *  @brief Provides external function TV Application
  *  %MW Application API would be used by TV Application, lot of these APIs would
  *   be wrapped from Exported API
  *  @see groupMW_STRM_MNGR_SBTL_HDLR
  *  @{ 
  */
/*----------------------------------------------------------------------------*/

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

#include "u_common.h"
#include "u_sys_name.h"
#include "u_handle.h"
#include "u_sm.h"

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


/* command sets *************************************************************/
/* primary commands */
/* argument is h_obj contains the handle of the video stream */
#define SM_SBTL_CMD_CODE_SET_VS_HANDLE                        \
      ((SM_CMD_CODE_T)(SM_CMD_CODE_PRIMARY_BIT_FLAG | 0))    /**< set video handle information */

/* argument is h_obj contains the handle of the OSD driver component */
#define SM_SBTL_CMD_CODE_SET_OSD_HANDLE                       \
      ((SM_CMD_CODE_T)(SM_CMD_CODE_PRIMARY_BIT_FLAG | 1))    /**< set OSD canvas handle */
      
/* argument is h_obj contains the handle of the subtitle SCART canvas */
#define SM_SBTL_CMD_CODE_SET_SCART_CANVAS_HANDLE                       \
      ((SM_CMD_CODE_T)(SM_CMD_CODE_PRIMARY_BIT_FLAG | 2))    /**< set SCART canvas handle */

/* argument is b_boolean contains the flag that set the state invisble of main canvas when open subtitle stream */
#define SM_SBTL_CMD_CODE_SET_OPEN_MAIN_INVISIBLE_FLAG                       \
      ((SM_CMD_CODE_T)(SM_CMD_CODE_PRIMARY_BIT_FLAG | 3))    /**< set the invisible flag of main canvas when open subtitle stream */
      
/* set/get type groups *******************************************************/
#define SM_GRP_SBTLH                      (( SM_GRP_LAST_ENTRY + 12 ) << SM_CODE_BITS)    /**< get/set command group id */

/* set types *****************************************************************/
#define SM_SBTLH_SET_TYPE_IGNORE          ((SM_SET_TYPE_T)(SM_GRP_SBTLH | 0))    /**< setting type is IGNORE */

#define SM_SBTLH_SET_TYPE_VISIBLE         ((SM_SET_TYPE_T)(SM_GRP_SBTLH | 1))    /**< setting type is VISIBLE */
#define SM_SBTLH_SET_TYPE_INVISIBLE       ((SM_SET_TYPE_T)(SM_GRP_SBTLH | 2))    /**< setting type is INVISIBLE */
#define SM_SBTLH_SET_TYPE_SPEED           ((SM_SET_TYPE_T)(SM_GRP_SBTLH | 3))    /**< setting type is SPEED */

/* get types *****************************************************************/
#define SM_SBTLH_GET_TYPE_IGNORE          ((SM_GET_TYPE_T)(SM_GRP_SBTLH | 0))    /**< getting type is IGNORE */


/*------------------------------------------------------------------*/
/*! @struct SM_SBTLH_STREAM_INFO
 *  @brief  This structure contains the configuration data for APP playing subtitle stream
 *  @code
 *  typedef struct _SM_SBTLH_STREAM_INFO
 *  {
 *      HANDLE_T            h_scart_plane;
 *      BOOL                   b_open_main_invisible;
 *  }   SM_SBTLH_STREAM_INFO;
 *  @endcode
 *  @li@c  h_scart_plane                                     - Destination plane of bypass subtitle
 *  @li@c  b_open_main_invisible                         - Main plane's invisible flag when open subtitle
 */
/*------------------------------------------------------------------*/
typedef struct _SM_SBTLH_STREAM_INFO
{
    HANDLE_T            h_scart_plane;
    BOOL                b_open_main_invisible;
}   SM_SBTLH_STREAM_INFO;


/* Init configuration Structure  */
/*------------------------------------------------------------------*/
/*! @struct SM_SBTLH_CONFIG_T
 *  @brief  This structure contains the configuration data for subtitle stream handler
 *  @code
 *  typedef struct _SM_SBTLH_CONFIG_T
 *  {
 *      HANDLE_T            h_partition;            
 *      THREAD_DESCR_T      t_thrd_descr;           
 *      UINT8               ui1_max_service_cnt;    
 *      UINT8               ui1_color_depth;        
 *      UINT32              ui4_page_width;         
 *      UINT32              ui4_page_height;        
 *      UINT8               ui1_wgl_order;          
 *  } SM_SBTLH_CONFIG_T;
 *  @endcode
 *  @li@c  h_partition                                       - Partition of subtitle stream handler
 *  @li@c  t_thrd_descr                                      - Subtitle handler thread information
 *  @li@c  ui1_max_service_cnt                               - The maximum number of subtitle stream service
 *  @li@c  ui1_color_depth                                   - The maximum color depth of subtitle page
 *  @li@c  ui4_page_width                                    - The page width of subtitle. The spec value is 720, but it may vary by different country
 *  @li@c  ui4_page_height                                   - The page height of subtitle. The spec value is 567, but it may vary by different country
 *  @li@c  ui1_wgl_order                                     - Subtitle widget app order
 */
/*------------------------------------------------------------------*/
typedef struct _SM_SBTLH_CONFIG_T
{
    HANDLE_T            h_partition;            /* Partition of subtitle stream handler */
    THREAD_DESCR_T      t_thrd_descr;           /* Subtitle handler thread */
    UINT8               ui1_max_service_cnt;    /* Number of maximum concurrent subtitle service */
    UINT8               ui1_color_depth;        /* Subtitle decoder depth */   
    UINT32              ui4_page_width;         /* Width of default canvas */
    UINT32              ui4_page_height;        /* Height of default canvas */
    UINT8               ui1_wgl_order;          /* Subtitle widget app order */
} SM_SBTLH_CONFIG_T;

/*------------------------------------------------------------------*/
/*! @struct SM_SBTLH_RENDER_INFO_T
 *  @brief  This structure contains the render information for ROM render engine and text render engine.
 *  @code
 *  typedef struct _SM_SBTLH_RENDER_INFO_T
 *  {
 *      UINT16 ui2_obj_x_pos;
 *      UINT16 ui2_obj_y_pos;
 *      UINT8  ui1_obj_fg_color;        
 *      UINT8  ui1_obj_bg_color;        
 *      UINT8  ui1_rgn_depth;
 *      UINT16 ui2_rgn_width;
 *      UINT16 ui2_rgn_height;
 *      UINT8* pui1_rgn;
 *      UINT16 ui2_obj_width;       
 *      UINT16 ui2_obj_height;      
 *  } SM_SBTLH_RENDER_INFO_T;
 *  @endcode
 *  @li@c  ui2_obj_x_pos                                     - The horizontal position of the top left pixel of the object
 *  @li@c  ui2_obj_y_pos                                     - The vertical position of the top left pixel of the object
 *  @li@c  ui1_obj_fg_color                                  - The entry in the applied CLUT that has been selected as the foreground colour of the characters
 *  @li@c  ui1_obj_bg_color                                  - The entry in the applied CLUT that has been selected as the background colour of the characters
 *  @li@c  ui1_rgn_depth                                     - The pixel depth of the region. 0x01 means 2 bit; 0x02 means 4 bit; 0x03 means 8bit
 *  @li@c  ui2_rgn_width                                     - The horizontal length of the region
 *  @li@c  ui2_rgn_height                                    - The vertical length of the region
 *  @li@c  pui1_rgn                                          - Pointer points to the byte buffer of the region. It's a byte-aligned buffer for each horizontal line pixels
 *  @li@c  ui2_obj_width                                     - The horizontal length of the object. It's an output field
 *  @li@c  ui2_obj_height                                    - The vertical length of the object. It's an output field
 */
/*------------------------------------------------------------------*/
typedef struct _SM_SBTLH_RENDER_INFO_T
{
    UINT16 ui2_obj_x_pos;
    UINT16 ui2_obj_y_pos;
    UINT8  ui1_obj_fg_color;        /* Only used as a text object */
    UINT8  ui1_obj_bg_color;        /* Only used as a text object */
    UINT8  ui1_rgn_depth;
    UINT16 ui2_rgn_width;
    UINT16 ui2_rgn_height;
    UINT8* pui1_rgn;
    
    UINT16 ui2_obj_width;       /* Output */
    UINT16 ui2_obj_height;      /* Output */
} SM_SBTLH_RENDER_INFO_T;

/*-----------------------------------------------------------------------------
                    functions declarations
-----------------------------------------------------------------------------*/

#endif /* _U_SM_SBTL_HDLR_H_ */

/*----------------------------------------------------------------------------*/
/*! @} */                                /* end of groupMW_STRM_MNGR_SBTL_HDLR */
/*----------------------------------------------------------------------------*/


