/* 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.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 * $RCSfile: x_mm_sbtl_engine.h,v $
 * $Revision: #1 $
 * $Date: 2015/05/29 $
 * $Author: brianpc.huang $
 * $CCRevision: $
 * $SWAuthor: $
 * $MD5HEX: $
 *
 * Description: 
 *         This header file contains Subtitle Stream handler specific 
 *         events.
 *---------------------------------------------------------------------------*/

#ifndef _X_MM_SBTL_ENGINE_H_
#define _X_MM_SBTL_ENGINE_H_


/*-----------------------------------------------------------------------------
                    include files
-----------------------------------------------------------------------------*/
#ifndef __KERNEL__
#include "x_mm_common.h"
#include "u_mm_sbtl_engine.h"
#include "u_sm_cc_hdlr.h"
#else /*__KERNEL__*/

#include "x_mm_common.h"
#include "u_mm_sbtl_engine.h"
#include "u_sm_cc_hdlr.h"
#endif /*__KERNEL__*/

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

/*------------------------------------------------------------------*/
/*! @struct SBTL_CFG_T
 *  @brief This struct defines the subtitle config information
 *  @code
 *  typedef struct _SBTL_CFG_T
 *  {
 *      MM_SBTL_TYPE_T                 e_sbtl_type;
 *      MM_SBTL_DIVX_TYPE_T            e_divx_sbtl_type;
 *      BOOL                        b_divx_hd;
 *      UINT8                       ui1_ovs_top;
 *      UINT8                       ui1_ovs_bottom;
 *      UINT8                       ui1_ovs_left;
 *      UINT8                       ui1_ovs_right;
 *      GL_RECT_T                   t_rect_display;
 *      GL_RECT_T                   t_rect_video;
 *      GL_SIZE_T                   t_video_resolution;
 *      SCDB_SUBTITLE_DIVX_T        t_subtitle_avi;
 *      STREAM_ID_T                 t_stream_id;
 *      UINT16                      ui2_menu_item;
 *      UINT64                      ui8_codec_private_len;
 *      UINT8                       aui1_codec_private[MM_MAX_MKV_CODEC_PRIVATE_LENGTH];
 *      UINT8                       ui1_encoding_count;
 *      SBTL_MKV_CONTENT_ENCODING_T at_content_encoding[MM_MAX_MKV_CONTENT_ENCODING_COUNT];
 *      GL_RECT_T                   t_rect_osd;
 *      BOOL                        b_rect_osd;
 *      WGL_INSET_T                 t_inset;
 *      GL_POINT_T                  t_pos_adjust;
 *      WGL_COLOR_INFO_T            t_fg_color_info;
 *      WGL_COLOR_INFO_T            t_bg_color_info;
 *      WGL_FONT_INFO_T             t_font_info;
 *      UINT8                       ui1_text_alignment;
 *      INT32                       i4_speed;
 *      INT32                       i4_pts_offset;
 *      UINT32                      ui4_video_scale; 
 *      UINT32                      ui4_video_rate; 
 *      UINT32                      ui4_stream_id;
 *      HANDLE_T                    h_connection;
 *      HANDLE_T                    h_source;
 *      HANDLE_T                    h_gl_plane;
 *      HANDLE_T                    h_video;
 *      SBTL_DISPLAY_INFO_CMD_T     t_display_info;
 *      CHAR                        s_prefered_lang_list[MM_SBTL_PREFERED_LANG_LIST_LEN];
 *      MEDIA_FEEDER_T*             pt_feeder[MM_SBTL_FEEDER_MAX];
 *  } SBTL_CFG_T;
 *  @endcode
 *  @li@c  e_sbtl_type                                       -Subtitle type 
 *  @li@c  e_divx_sbtl_type                                  -Divx subtitle type
 *  @li@c  b_divx_hd                                         -Divx subtitle is hd or not
 *  @li@c  ui1_ovs_top                                       -The top of overscan
 *  @li@c  ui1_ovs_bottom                                    -The bottom of overscan
 *  @li@c  ui1_ovs_left                                      -The left of overscan
 *  @li@c  ui1_ovs_right                                     -The right of overscan
 *  @li@c  t_rect_display                                    -The subtitle display rectang
 *  @li@c  t_rect_video                                      -The video retang
 *  @li@c  t_video_resolution                                -The video reolution
 *  @li@c  t_subtitle_avi                                    -The subtitle avi information
 *  @li@c  t_stream_id                                       -The stream id
 *  @li@c  ui2_menu_item                                     -The menu item for menu divx subtitle
 *  @li@c  ui8_codec_private_len                             -The private codec length
 *  @li@c  aui1_codec_private[MM_MAX_MKV_CODEC_PRIVATE_LENGTH]    -The private codec information
 *  @li@c  ui1_encoding_count                                -Encoding count
 *  @li@c  at_content_encoding[MM_MAX_MKV_CONTENT_ENCODING_COUNT]    -The encoding content information
 *  @li@c  t_rect_osd                                        -The osd rectang
 *  @li@c  b_rect_osd                                        -True: the osd rectang is valid;otherwise:not valid
 *  @li@c  t_inset                                           -The inset rectang
 *  @li@c  t_pos_adjust                                      -The subtitle adjust position
 *  @li@c  t_fg_color_info                                   -The foreground color information
 *  @li@c  t_bg_color_info                                   -The background color informaiton
 *  @li@c  t_font_info                                       -The font information
 *  @li@c  ui1_text_alignment                                -The subtitle alignment type
 *  @li@c  i4_speed                                          -The subtitle display speed information
 *  @li@c  i4_pts_offset                                     -The pts offset value
 *  @li@c  ui4_video_scale                                   -The video scale value
 *  @li@c  ui4_video_rate                                    -The video rate value
 *  @li@c  ui4_stream_id                                     -The stream id
 *  @li@c  h_connection                                      -The connection handle
 *  @li@c  h_source                                          -The source handle
 *  @li@c  h_gl_plane                                        -The plane handle
 *  @li@c  h_video                                           -The video handle
 *  @li@c  t_display_info                                    -The display information
 *  @li@c  s_prefered_lang_list[MM_SBTL_PREFERED_LANG_LIST_LEN]    -Prefered language list  information
 *  @li@c  pt_feeder[MM_SBTL_FEEDER_MAX]                     -The subtitle feeder information
 */
/*------------------------------------------------------------------*/
typedef struct _SBTL_CFG_T
{
    MM_SBTL_TYPE_T                 e_sbtl_type;
    MM_SBTL_DIVX_TYPE_T            e_divx_sbtl_type;
    MM_SBTL_ENCODING_T             e_encoding;
    UINT32                         ui4_cmd_mask;

    /*for divx subtitle only*/
    BOOL                        b_divx_hd;
    
    /*overscan*/
    UINT8                       ui1_ovs_top;
    UINT8                       ui1_ovs_bottom;
    UINT8                       ui1_ovs_left;
    UINT8                       ui1_ovs_right;
    GL_RECT_T                   t_rect_display;
    GL_RECT_T                   t_rect_video;
    GL_SIZE_T                   t_video_resolution;
    SCDB_SUBTITLE_DIVX_T        t_subtitle_avi;
    SCDB_SUBTITLE_PS_T          t_subtitle_ps;
    
    SCDB_SUBTITLE_MP4_T         t_subtitle_mp4;
    STREAM_ID_T                 t_stream_id;
    /*for divx menu subtitle only*/
    UINT16                      ui2_menu_item;

    /*for MKV subtitle only*/
    UINT64                      ui8_codec_private_len;
    UINT8                       aui1_codec_private[MM_MAX_MKV_CODEC_PRIVATE_LENGTH];
    UINT8                       ui1_encoding_count;
    SBTL_MKV_CONTENT_ENCODING_T at_content_encoding[MM_MAX_MKV_CONTENT_ENCODING_COUNT];
    
    /*common*/
    GL_RECT_T                   t_rect_osd;
    BOOL                        b_rect_osd;
    WGL_INSET_T                 t_inset;
    GL_POINT_T                  t_pos_adjust;
    WGL_COLOR_INFO_T            t_fg_color_info;
    WGL_COLOR_INFO_T            t_bg_color_info;
    WGL_COLOR_INFO_T            t_font_bg_color;
    WGL_COLOR_INFO_T            t_edge_color_info;
    UINT32                      ui4_edge_width;
    WGL_FONT_INFO_T             t_font_info;
    UINT8                       ui1_text_alignment;
    MM_SBTL_DISP_PAGE_T         t_disp_page;
    MM_SBTL_TM_OFST_INF         t_time_ofst;
    BOOL                        b_hide;

    /*common*/
    INT32                       i4_speed;
    INT32                       i4_pts_offset;
    UINT32                      ui4_video_scale; 
    UINT32                      ui4_video_rate; 
    BOOL                        b_has_strm_id;  /*1:the ui4_stream_id has been setted;0:not setted*/
    UINT32                      ui4_stream_id;
    
    HANDLE_T                    h_connection;
    HANDLE_T                    h_source;
    HANDLE_T                    h_gl_plane;
    HANDLE_T                    h_video;

    SBTL_DISPLAY_INFO_CMD_T     t_display_info;

    SBTL_LYRIC_INFO_T           t_lyric;

    x_mm_sbtl_pts_cb            pf_pts_cb;
    VOID*                       pv_pts_cb_tag;

    CHAR                        s_prefered_lang_list[MM_SBTL_PREFERED_LANG_LIST_LEN];
    MEDIA_FEEDER_T*             pt_feeder[MM_SBTL_FEEDER_MAX];
    BOOL                        b_is_http_file;
    CHAR                        s_dest_grp_name[RM_NAME_LEN + 1];
	/*for xml_ipcc subtitle only*/
    BOOL                        b_is_xml_m4t;
    SM_CCH_DTVCC_ATTRIBS_INFO_T t_sbtl_cc_info;
	SBTL_DUMMY_FNCTBL_T         t_dummy_func;
    HANDLE_T                    h_pm;
    SBTL_BUFFER_FILE_INFO_T     t_first_info;
    UINT32                      ui4_tlv_dmx_id;
    UINT32                      ui4_tlv_frm_idx;
    x_mm_sbtl_data_cb           pf_data_cb;
    VOID*                       pv_data_tag;
    BOOL                        b_ext_stc;
    PTS_T                       ui8_ext_stc;
    UINT32                      ui4_ext_record_time;//ms unit
    SBTL_PTS_WITH_JIFFIES_T     t_pts_jiffes;
    UINT8                       ui1_stc_flag;
} SBTL_CFG_T;



extern INT32 x_sbtl_engine_init(VOID);

extern INT32 x_sbtl_engine_open( SBTL_CFG_T*            pt_cfg,
                                 BOOL                   b_auto_play,
                                 sbtl_state_notify_fct  pf_state_nfy,
                                 VOID*                  pv_sm_nfy_tag,
                                 VOID**                 ppv_engine);

extern INT32 x_sbtl_engine_close( VOID*                 pv_engine);

extern INT32 x_sbtl_engine_set(VOID*                    pt_engine,
                               MM_EVN_TYPE_T            e_event,
                               VOID*                    pv_set_info,
                               SIZE_T                   z_set_info_len);

extern INT32 x_sbtl_engine_get(VOID*                    pv_engine,
                               MM_EVN_TYPE_T            e_event,
                               VOID*                    pv_get_info,
                               SIZE_T                   z_get_info_len);
#endif /* _X_MM_SBTL_ENGINE_H_ */
