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

#ifndef _C_DLNA_DMR_H_
#define _C_DLNA_DMR_H_
#include "u_common.h"

#define DMRR_OK                (1 << 0)
#define DMRR_NOT_STARTED       (1 << 1)
#define DMRR_FAILED            (1 << 2)

typedef enum {
    DLNA_DMR_SPEED_FR_64X   =   -6400000,   ///< Fast Rewind 64X [Reserved]
    DLNA_DMR_SPEED_FR_32X   =   -3200000,   ///< Fast Rewind 32X [Reserved] 
    DLNA_DMR_SPEED_FR_16X   =   -1600000,   ///< Fast Rewind 16X [Reserved]
    DLNA_DMR_SPEED_FR_8X    =   -800000,    ///< Fast Rewind 8X
    DLNA_DMR_SPEED_FR_4X    =   -400000,    ///< Fast Rewind 4X
    DLNA_DMR_SPEED_FR_2X    =   -200000,    ///< Fast Rewind 2X
    DLNA_DMR_SPEED_ZERO     =   0,          ///< paused [Reserved]
    DLNA_DMR_SPEED_1X       =   100000,     ///< normal play
    DLNA_DMR_SPEED_FF_2X    =   200000,     ///< Fast Forward 2X
    DLNA_DMR_SPEED_FF_4X    =   400000,     ///< Fast Forward 4X
    DLNA_DMR_SPEED_FF_8X    =   800000,     ///< Fast Forward 8X
    DLNA_DMR_SPEED_FF_16X   =   1600000,    ///< Fast Forward 16X [Reserved]
    DLNA_DMR_SPEED_FF_32X   =   3200000,    ///< Fast Forward 32X [Reserved]
    DLNA_DMR_SPEED_FF_64X   =   6400000,    ///< Fast Forward 64X [Reserved]
    DLNA_DMR_SPEED_SF_1_2X    =  200,    ///< Slow Forward 1/2X
    DLNA_DMR_SPEED_SF_1_4X    =  400,    ///< Slow Forward 1/4X
    DLNA_DMR_SPEED_SF_1_8X    =  800,    ///< Slow Forward 1/8X [Reserved]
    DLNA_DMR_SPEED_SF_1_16X   =  1600,   ///< Slow Forward 1/16X [Reserved]
    DLNA_DMR_SPEED_SF_1_32X   =  3200,   ///< Slow Forward 1/32X [Reserved]
    DLNA_DMR_SPEED_SR_1_2X    =  -200,   ///< Slow Rewind 1/2X
    DLNA_DMR_SPEED_SR_1_4X    =  -400,   ///< Slow Rewind 1/4X
    DLNA_DMR_SPEED_SR_1_8X    =  -800,   ///< Slow Rewind 1/8X [Reserved]
    DLNA_DMR_SPEED_SR_1_16X   =  -1600,  ///< Slow Rewind 1/16X [Reserved]
    DLNA_DMR_SPEED_SR_1_32X   =  -3200  ///< Slow Rewind 1/32X [Reserved]
} E_DMR_PLAYER_PLAYSPEED;

/*add by chenkun for get the media info and player status*/
typedef enum
{
	PLAYER_MEDIATYPE_ERROR = 0,/*no this situation*/
	PLAYER_MEDIATYPE_PHOTO,
	PLAYER_MEDIATYPE_AUDIO,
	PLAYER_MEDIATYPE_VIDEO,
	PLAYER_MEDIATYPE_UNKNOWN,
	PLAYER_MEDIATYPE_IGNORE
}E_PLAYER_MEDIA_TYPE;


// typedef VOID (*c_dmr_player_start_fct)(const CHAR * ps_file_name);
typedef VOID (*c_dmr_player_start_fct)(E_DMR_PLAYER_PLAYSPEED tPlayspeed);
typedef VOID (*c_dmr_player_stop_fct)(VOID);
typedef VOID (*c_dmr_player_pause_fct)(VOID);
/*add by chenkun for resume player*/
typedef VOID (*c_dmr_player_resume_fct)(E_DMR_PLAYER_PLAYSPEED tPlayspeed);
/* Render Access Control */
typedef BOOL (*c_dmr_player_is_dmc_allowed_fct)(CHAR* ps_name, CHAR* ps_mac);
/* volume control */
typedef VOID (*c_dmr_player_get_volume_fct)(UINT8* pui1_volume);/* 0-100 0:mute 100:max */
typedef INT8 (*c_dmr_player_set_volume_fct)(UINT8 ui1_volume);/*return 0:OK -1:failed */
typedef VOID (*c_dmr_player_get_mute_fct)(BOOL* pb_mute);/* 1:mute 0:unmute */
typedef INT8 (*c_dmr_player_set_mute_fct)(BOOL b_mute);/*return 0:OK -1:failed */
/* progress information */
/* eg: current position 25th second. media duration 120seconds */
typedef VOID (*c_dmr_player_get_progress_fct)(UINT64* pi8_position, UINT64* pi8_duration);
/* seek */
typedef VOID (*c_dmr_player_seek_fct)(UINT64 pi8_target);/* eg:10th second */
typedef INT8 (*c_dmr_player_fast_forward_fct)(VOID);
typedef INT8 (*c_dmr_player_fast_rewind_fct)(VOID);
/* check AP status */
typedef BOOL (*c_dmr_player_is_status_available_fct)(E_PLAYER_MEDIA_TYPE mediatype);


typedef struct
{
    c_dmr_player_start_fct     pf_play; // start or resume determined by ps_file_name pushed,
                                        // if ps_file_name is different with the former one, means start new media.
                                        // else if ps_file_name is same as the former one, means resume if possible.
    c_dmr_player_stop_fct      pf_stop;
    c_dmr_player_pause_fct     pf_pause;
	/*add by chenkun for resume player*/
	c_dmr_player_resume_fct    pf_resume;
    /* resume use play to replace. */

    /* Render Access Control */
    c_dmr_player_is_dmc_allowed_fct pf_is_dmc_allowed;

    /* volume control */
    c_dmr_player_get_volume_fct pf_get_volume;
    c_dmr_player_set_volume_fct pf_set_volume;
    c_dmr_player_get_mute_fct pf_get_mute;
    c_dmr_player_set_mute_fct pf_set_mute;
    /* progress */
    c_dmr_player_get_progress_fct pf_get_progress;
    /* seek */
    c_dmr_player_seek_fct pf_seek;
    c_dmr_player_fast_forward_fct pf_fast_forward;
    c_dmr_player_fast_rewind_fct pf_fast_rewind;

    /* check AP status */
    c_dmr_player_is_status_available_fct pf_is_status_ok;

}DMR_PLAYER_T;

typedef enum
{
	PLAYER_NFYCODE_FILE_NOT_SUPPORT = 0,
	PLAYER_NFYCODE_NONE_AV,
	PLAYER_NFYCODE_AUDIO_ONLY,
	PLAYER_NFYCODE_VIDEO_ONLY,
	PLAYER_NFYCODE_AV_BOTH,
	PLAYER_NFYCODE_AUDIO_PLAYED,
	PLAYER_NFYCODE_VIDEO_PLAYED,
	PLAYER_NFYCODE_AUDIO_NOT_SUPPORT,
	PLAYER_NFYCODE_VIDEO_NOT_SUPPORT,
	PLAYER_NFYCODE_HD_NOT_SUPPORT,
	PLAYER_NFYCODE_DRM_NOT_SUPPORT,
	PLAYER_NFYCODE_RESOLUTION_NOT_SUPPORT,
	PLAYER_NFYCODE_FRAMERATE_NOT_SUPPORT,
	PLAYER_NFYCODE_NO_CONTENT,
	PLAYER_NFYCODE_STOPPED,
	PLAYER_NFYCODE_PHOTO_PLAYED,
	PLAYER_NFYCODE_END_OF_MEDIA,
	PLAYER_NFYCODE_PLAYER_EXIT,
    PLAYER_NFYCODE_PAUSE,
    PLAYER_NFYCODE_PLAYER_SEEK_DONE,
    PLAYER_NFYCODE_PLAYER_SEEK_ERROR,
	PLAYER_NFYCODE_IGNORE
}E_PLAYER_NFY_CODE;
#if 0
typedef enum
{
    /* Player Control */
    DLNA_DMR_PLAYER_START = 0,
    DLNA_DMR_PLAYER_STOP,
    DLNA_DMR_PLAYER_PAUSE,
    DLNA_DMR_PLAYER_RESUME,
    DLNA_DMR_PLAYER_SEEK,

    /* Render Info */
    DLNA_DMR_PLAYER_GET_VOL = 10,
    DLNA_DMR_PLAYER_SET_VOL,
    DLNA_DMR_PLAYER_GET_MUTE,
    DLNA_DMR_PLAYER_SET_MUTE,
    DLNA_DMR_PLAYER_GET_PROGRESS,

    /* Extension Info */
    DLNA_DMR_PLAYER_EXT_CHKDMC = 50,
    DLNA_DMR_PLAYER_EXT_CHKSTATE
}E_DMR_PLAYER_CMD;

typedef enum
{
    E_DMR_PLAYER_PLAYSPEED tPlayspeed;
    UINT64 i8_time;
    UINT8 i1_volume;
    BOOL b_mute;
    BOOL *pb_ret;
    
    struct {
        UINT64 *i8_position;
        UINT64 *i8_duration;
    }tProgress;

    struct {
        CHAR *ps_name;
        CHAR *ps_mac;
        BOOL *pb_ret;
    }tCHKDMC;
}E_DMR_PLAYER_PARAM;

typedef UINT32 (*dmr_player_callback)(E_DMR_PLAYER_PARAM *pParam);

#endif

INT32 c_dmr_start(VOID);
INT32 c_dmr_stop(VOID);
INT32 c_dmr_current_file(CHAR ** ps_file_name);
INT32 c_dmr_register_player(DMR_PLAYER_T * pt_player);
INT32 c_dmr_submit_player_status(E_PLAYER_MEDIA_TYPE mediatype, E_PLAYER_NFY_CODE nfycode);
INT32 c_dmr_submit_player_vol(UINT8 i1_vol);
INT32 c_dmr_submit_player_mute(BOOL b_mute);


/* ps_dmr_name minmum size is 64 bytes*/
INT32 c_dmr_get_dmr_name(CHAR ** ps_dmr_name);
/* ps_dmr_name maxmum size is 64 bytes*/
INT32 c_dmr_set_dmr_name(CHAR * ps_dmr_name);

INT32 c_dmr_update_interface(CHAR* ps_name);

#endif /* _U_DMR_API_H_ */
