/*===========================================================================

FILE: OEMBrewAVCompetition.h

SERVICES: for resolve the competition between ICamera instance,ISound instance,IMedia instance,
		  IMediaUtil instance

DESCRIPTION
   		provide the judgement,resource clear function when competition between objects happened

PUBLIC CLASSES:  Not Applicable
 
INITIALIZATION AND SEQUENCING REQUIREMENTS:  Not Applicable

            Copyright 2005 -  NEUSOFT  Incorporated.
            All Rights Reserved.
            NEUSOFT Proprietary/GTDR
===================================================================================================*/
/*===================================================================================================

                    			 INCLUDE FILES FOR MODULE

===================================================================================================*/
#ifndef ___BREW_AV_COMPETITION_MODULE___
#define ___BREW_AV_COMPETITION_MODULE___



#include "AEE.h"
#include "OEMHeap.h"

// [PTX804_BREWAV] Zhou Jianwei added BUGLIST 618  2005/05/02 
#include "AEESound.h"

#ifdef WIN32
#include "../msctrl/Task/winrexqueue.h"
#else
#include "queue.h"
#endif


//---------------------------------------------------------------------------------------------------//
//      						Macros defination								     							  //
//---------------------------------------------------------------------------------------------------//

/* Reqire List defination Begin */
#define REQ_OBJECT_RELEASE										0xFFFFFFFF
#define GROUP_NUM												4

/*Common Group definition Begin */
#define REQ_COMMON_GROUP										0x00000000
#define COMMON_GROUP_ACTION_NUM								22
#define REQ_CAMERA_CREATE										(REQ_COMMON_GROUP + 0x00000001)
#define REQ_CAMERA_CAPTURE									(REQ_COMMON_GROUP + 0x00000002)
#define REQ_ISHELL_BEEP											(REQ_COMMON_GROUP + 0x00000004)
#define REQ_ISHELL_BEEP_STOP									(REQ_COMMON_GROUP + 0x00000008)
#define REQ_SOUND_CREATE										(REQ_COMMON_GROUP + 0x00000010)
#define REQ_SOUND_STOP										(REQ_COMMON_GROUP + 0x00000020)
#define REQ_SOUND_PLAY											(REQ_COMMON_GROUP + 0x00000040)
#define REQ_MEDIA_UTIL_CREATE									(REQ_COMMON_GROUP + 0x00000080)
#define REQ_MEIDA_UTIL_ENCODE									(REQ_COMMON_GROUP + 0x00000100)
#define REQ_MEIDA_UTIL_ENCODE_STOP							(REQ_COMMON_GROUP + 0x00000200)
/* [PTX805_BREWAV] Zhoujw added  [S] */
#define REQ_VOC_CREATE											(REQ_COMMON_GROUP + 0x00000400)
#define REQ_VOC_PLAY											(REQ_COMMON_GROUP + 0x00000800)
#define REQ_VOC_STOP											(REQ_COMMON_GROUP + 0x00001000)
/* [PTX805_BREWAV] Zhoujw added  [E] */

// [PTX804_BREWAV] CuiXinyu added 2005/10/10 [S]
#define REQ_DSR_CREATE				                                                 (REQ_COMMON_GROUP + 0x00002000)
#define REQ_DSR_PLAY				                                                 (REQ_COMMON_GROUP + 0x00004000)
#define REQ_DSR_STOP				                                                 (REQ_COMMON_GROUP + 0x00008000)
#define REQ_GL_CREATE											(REQ_COMMON_GROUP + 0x00010000)
#define REQ_GL_PLAY												(REQ_COMMON_GROUP + 0x00020000)
#define REQ_GL_STOP												(REQ_COMMON_GROUP + 0x00040000)
#define REQ_EGL_CREATE											(REQ_COMMON_GROUP + 0x00080000)
#define REQ_EGL_PLAY											(REQ_COMMON_GROUP + 0x00100000)
#define REQ_EGL_STOP											(REQ_COMMON_GROUP + 0x00200000)
//CuiXinyu [PTX804 BREWAV] [E]

/*Common Group definition End */

/*MPEG4 Group definition Begin */
#define REQ_MPEG4_GROUP										0x40000000
#define MPEG4_GROUP_ACTION_NUM								10
#define REQ_MEDIA_MPEG4_CREATE								(REQ_MPEG4_GROUP + 0x00000001)
#define REQ_MEDIA_MPEG4_VIDEO_SETMMD							(REQ_MPEG4_GROUP + 0x00000002)
#define REQ_MEDIA_MPEG4_VIDEO_AUDIO_SETMMD					(REQ_MPEG4_GROUP + 0x00000004)
#define REQ_MEDIA_MPEG4_AUDIO_SETMMD							(REQ_MPEG4_GROUP + 0x00000008)
#define REQ_MEDIA_MPEG4_VIDEO_PLAY							(REQ_MPEG4_GROUP + 0x00000010)
#define REQ_MEDIA_MPEG4_VIDEO_AUDIO_PLAY						(REQ_MPEG4_GROUP + 0x00000020)
#define REQ_MEDIA_MPEG4_AUDIO_PLAY							(REQ_MPEG4_GROUP + 0x00000040)
#define REQ_MEDIA_MPEG4_VIDEO_STOP							(REQ_MPEG4_GROUP + 0x00000080)
#define REQ_MEDIA_MPEG4_VIDEO_AUDIO_STOP						(REQ_MPEG4_GROUP + 0x00000100)
#define REQ_MEDIA_MPEG4_AUDIO_STOP							(REQ_MPEG4_GROUP + 0x00000200)
/*MPEG4 Group definition End */

/* QCP Group defination Begin */
#define REQ_MEDIA_QCP_GROUP									0x80000000
#define QCP_GROUP_ACTION_NUM									5
#define REQ_MEDIA_QCP_CREATE									(REQ_MEDIA_QCP_GROUP + 0x00000001)
#define REQ_MEDIA_QCP_SETMMD									(REQ_MEDIA_QCP_GROUP + 0x00000002)
#define REQ_MEDIA_QCP_PLAY										(REQ_MEDIA_QCP_GROUP + 0x00000004)
#define REQ_MEDIA_QCP_RECORD									(REQ_MEDIA_QCP_GROUP + 0x00000008)
#define REQ_MEDIA_QCP_STOP										(REQ_MEDIA_QCP_GROUP + 0x00000010)
/* QCP Group defination End */
 

/*MA7 Group definition Begin */
#define REQ_MA7_GROUP											0xC0000000
#define MA7_GROUP_ACTION_NUM									23
#define REQ_MA7_MMF_CREATE									(REQ_MA7_GROUP + 0x00000001)
#define REQ_MA7_MIDI_CREATE									(REQ_MA7_GROUP + 0x00000002)
#define REQ_MA7_MIDIOUTMSG_CREATE							(REQ_MA7_GROUP + 0x00000004)
#define REQ_MA7_ADPCM_CREATE									(REQ_MA7_GROUP + 0x00000008)
#define REQ_MA7_PHR_CREATE										(REQ_MA7_GROUP + 0x00000010)
#define REQ_MA7_HVS_CREATE										(REQ_MA7_GROUP + 0x00000020)

#define REQ_MA7_MMF_SETMMD									(REQ_MA7_GROUP + 0x00000040)
#define REQ_MA7_MIDI_SETMMD									(REQ_MA7_GROUP + 0x00000080)
#define REQ_MA7_ADPCM_SETMMD									(REQ_MA7_GROUP + 0x00000100)
#define REQ_MA7_PHR_SETMMD									(REQ_MA7_GROUP + 0x00000200)
#define REQ_MA7_HVS_SETMMD									(REQ_MA7_GROUP + 0x00000400)

#define REQ_MA7_MMF_PLAY										(REQ_MA7_GROUP + 0x00000800)
#define REQ_MA7_MIDI_PLAY										(REQ_MA7_GROUP + 0x00001000)
#define REQ_MA7_MIDIOUTMSG_PLAY								(REQ_MA7_GROUP + 0x00002000)
#define REQ_MA7_ADPCM_PLAY									(REQ_MA7_GROUP + 0x00004000)
#define REQ_MA7_PHR_PLAY										(REQ_MA7_GROUP + 0x00008000)
#define REQ_MA7_HVS_PLAY										(REQ_MA7_GROUP + 0x00010000)

#define REQ_MA7_MMF_STOP										(REQ_MA7_GROUP + 0x00020000)
#define REQ_MA7_MIDI_STOP										(REQ_MA7_GROUP + 0x00040000)
#define REQ_MA7_MIDIOUTMSG_STOP								(REQ_MA7_GROUP + 0x00080000)
#define REQ_MA7_ADPCM_STOP									(REQ_MA7_GROUP + 0x00100000)
#define REQ_MA7_PHR_STOP										(REQ_MA7_GROUP + 0x00200000)
#define REQ_MA7_HVS_STOP										(REQ_MA7_GROUP + 0x00400000)
/*MA7 Group definition End */

/* Reqire List defination End */

/* Utility:														*/
/* when current requirement is denied,competition module will return 	*
 * these error code to client(such as IMedia,ICamera etc.),from the error	*
 * code,the client could know why the requirement has been denied		*/
 
/* Error Code definition Begin */
#define		BREW_AV_COM_ERROR_BASE									0x00000000
#define 		BREW_AV_COM_SUCCESS										BREW_AV_COM_ERROR_BASE
#define		BREW_AV_COM_CAMERA_WORKING								(BREW_AV_COM_ERROR_BASE + 1)
#define		BREW_AV_COM_SHELL_BEEPING								(BREW_AV_COM_ERROR_BASE + 2)
#define		BREW_AV_COM_SOUND_CREATED								(BREW_AV_COM_ERROR_BASE + 3)
#define		BREW_AV_COM_QCP_CREATED								(BREW_AV_COM_ERROR_BASE + 4)
#define		BREW_AV_COM_MMF_CREATED								(BREW_AV_COM_ERROR_BASE + 5)
#define		BREW_AV_COM_PHR_CREATED									(BREW_AV_COM_ERROR_BASE + 6)
#define		BREW_AV_COM_MPEG4_CREATED								(BREW_AV_COM_ERROR_BASE + 7)
#define		BREW_AV_COM_HVS_CREATED									(BREW_AV_COM_ERROR_BASE + 8)
#define		BREW_AV_COM_MIDI_CREATED								(BREW_AV_COM_ERROR_BASE + 9)
#define		BREW_AV_COM_ADPCM_CREATED								(BREW_AV_COM_ERROR_BASE + 10)
#define		BREW_AV_COM_MIDIOUTMSG_CREATED						(BREW_AV_COM_ERROR_BASE + 11)
#define		BREW_AV_COM_SAF_CREATED									(BREW_AV_COM_ERROR_BASE + 12)
#define		BREW_AV_COM_STM_CREATED									(BREW_AV_COM_ERROR_BASE + 13)
#define		BREW_AV_COM_MAPI_EXTENSION_CREATED					(BREW_AV_COM_ERROR_BASE + 14)
#define		BREW_AV_COM_QCP_IDLE										(BREW_AV_COM_ERROR_BASE + 15)
#define		BREW_AV_COM_MMF_IDLE										(BREW_AV_COM_ERROR_BASE + 16)
#define		BREW_AV_COM_PHR_IDLE										(BREW_AV_COM_ERROR_BASE + 17)
#define		BREW_AV_COM_MPEG4_VIDEO_IDLE							(BREW_AV_COM_ERROR_BASE + 18)
#define		BREW_AV_COM_MPEG4_VIDEO_AUDIO_IDLE						(BREW_AV_COM_ERROR_BASE + 19)
#define		BREW_AV_COM_MPEG4_AUDIO_IDLE							(BREW_AV_COM_ERROR_BASE + 20)
#define		BREW_AV_COM_HVS_IDLE										(BREW_AV_COM_ERROR_BASE + 21)
#define		BREW_AV_COM_MIDI_IDLE										(BREW_AV_COM_ERROR_BASE + 22)
#define		BREW_AV_COM_ADPCM_IDLE									(BREW_AV_COM_ERROR_BASE + 23)
#define		BREW_AV_COM_SAF_IDLE										(BREW_AV_COM_ERROR_BASE + 24)
#define		BREW_AV_COM_STM_IDLE										(BREW_AV_COM_ERROR_BASE + 25)
#define		BREW_AV_COM_MAPI_EXTENSION_IDLE							(BREW_AV_COM_ERROR_BASE + 26)
#define		BREW_AV_COM_UTIL_CREATED								(BREW_AV_COM_ERROR_BASE + 27)
#define		BREW_AV_COM_UTIL_ENCODING								(BREW_AV_COM_ERROR_BASE + 28)
#define		BREW_AV_COM_SOUND_PLAYING								(BREW_AV_COM_ERROR_BASE + 29)
#define		BREW_AV_COM_QCP_PLAYING									(BREW_AV_COM_ERROR_BASE + 30)
#define		BREW_AV_COM_MMF_PLAYING									(BREW_AV_COM_ERROR_BASE + 31)
#define		BREW_AV_COM_PHR_PLAYING									(BREW_AV_COM_ERROR_BASE + 32)
#define		BREW_AV_COM_MPEG4_VIDEO_PLAYING						(BREW_AV_COM_ERROR_BASE + 33)
#define		BREW_AV_COM_MPEG4_VIDEO_AUDIO_PLAYING					(BREW_AV_COM_ERROR_BASE + 34)
#define		BREW_AV_COM_MPEG4_AUDIO_PLAYING						(BREW_AV_COM_ERROR_BASE + 35)
#define		BREW_AV_COM_HVS_PLAYING									(BREW_AV_COM_ERROR_BASE + 36)
#define		BREW_AV_COM_MIDI_PLAYING									(BREW_AV_COM_ERROR_BASE + 37)
#define		BREW_AV_COM_ADPCM_PLAYING								(BREW_AV_COM_ERROR_BASE + 38)
#define		BREW_AV_COM_MIDIOUTMSG_PLAYING							(BREW_AV_COM_ERROR_BASE + 39)
#define		BREW_AV_COM_SAF_PLAYING									(BREW_AV_COM_ERROR_BASE + 40)
#define		BREW_AV_COM_STM_PLAYING									(BREW_AV_COM_ERROR_BASE + 41)
#define		BREW_AV_COM_MAPI_EXTENSION_PLAYING						(BREW_AV_COM_ERROR_BASE + 42)
#define		BREW_AV_COM_BADPARM										(BREW_AV_COM_ERROR_BASE + 43)
#define		BREW_AV_COM_OBJECT_NOT_FOUND							(BREW_AV_COM_ERROR_BASE + 44)
#define		BREW_AV_COM_OBJECT_TOO_MUCH							(BREW_AV_COM_ERROR_BASE + 45)
#define		BREW_AV_COM_FAILED										(BREW_AV_COM_ERROR_BASE + 46)

/* [PTX805_BREWAV] Zhoujw added  [S] */
#define		BREW_AV_COM_VOC_CREATED								(BREW_AV_COM_ERROR_BASE + 47)
#define		BREW_AV_COM_VOC_PLAYING								(BREW_AV_COM_ERROR_BASE + 48)
/* [PTX805_BREWAV] Zhoujw added  [S] */

// [PTX804_BREWAV] CuiXinyu added 2005/10/10 [S]
#define		BREW_AV_COM_DSR_CREATED		                                   (BREW_AV_COM_ERROR_BASE + 49)
#define		BREW_AV_COM_DSR_PLAYING		                                   (BREW_AV_COM_ERROR_BASE + 50)
#define		BREW_AV_COM_GL_CREATED							(BREW_AV_COM_ERROR_BASE + 51)
#define		BREW_AV_COM_GL_PLAYING							(BREW_AV_COM_ERROR_BASE + 52)
#define		BREW_AV_COM_EGL_CREATED							(BREW_AV_COM_ERROR_BASE + 53)
#define		BREW_AV_COM_EGL_PLAYING							(BREW_AV_COM_ERROR_BASE + 54)
//CuiXinyu [PTX804 BREWAV] [E]

/* Error Code definition End */


/* status List defination Begin */
enum e_status
{
	STATUS_IDLE,
	STATUS_CAMERA_WORKING, 
	STATUS_SHELL_BEEPING,
	STATUS_MEDIA_UTIL_CREATE,
	STATUS_MEDIA_UTIL_ENCODING,
	STATUS_SOUND_IDLE,
	STATUS_SOUND_PLAYING,
	STATUS_MEDIA_QCP_CREATE,
	STATUS_MEDIA_QCP_IDLE,
	STATUS_MEDIA_QCP_PLAYING,
	STATUS_MEDIA_QCP_RECORDING,
	STATUS_MEDIA_MPEG4_CREATE,
	STATUS_MEDIA_MPEG4_VIDEO_IDLE,
	STATUS_MEDIA_MPEG4_VIDEO_PLAYING,
	STATUS_MEDIA_MPEG4_VIDEO_AUDIO_IDLE,
	STATUS_MEDIA_MPEG4_VIDEO_AUDIO_PLAYING,
	STATUS_MEDIA_MPEG4_AUDIO_IDLE,
	STATUS_MEDIA_MPEG4_AUDIO_PLAYING,
	STATUS_MEDIA_MMF_CREATE,
	STATUS_MEDIA_MMF_IDLE,
	STATUS_MEDIA_MMF_PLAYING,
	STATUS_MEDIA_PHR_CREATE,
	STATUS_MEDIA_PHR_IDLE,
	STATUS_MEDIA_PHR_PLAYING,
	STATUS_MEDIA_HVS_CREATE,
	STATUS_MEDIA_HVS_IDLE,
	STATUS_MEDIA_HVS_PLAYING,
	STATUS_MEDIA_MIDI_CREATE,
	STATUS_MEDIA_MIDI_IDLE,
	STATUS_MEDIA_MIDI_PLAYING,
	STATUS_MEDIA_MIDIOUTMSG_CREATE,
	STATUS_MEDIA_MIDIOUTMSG_PLAYING,
	STATUS_MEDIA_ADPCM_CREATE,
	STATUS_MEDIA_ADPCM_IDLE,
	STATUS_MEDIA_ADPCM_PLAYING,	
/* [PTX805_BREWAV] Zhoujw added  [S] */
	STATUS_VOC_IDLE,
	STATUS_VOC_PLAYING,
/* [PTX805_BREWAV] Zhoujw added  [E] */	
// [PTX804_BREWAV] CuiXinyu added 2005/10/10 [S]
	STATUS_DSR_IDLE,
	STATUS_DSR_PLAYING,	
	STATUS_GL_IDLE,
	STATUS_GL_PLAYING,
	STATUS_EGL_IDLE,
	STATUS_EGL_PLAYING,
//CuiXinyu [PTX804 BREWAV] [E]

	STATUS_MAX
};
/* status List defination End */

/* Scribe:																	*
 *	client will call ApiBrewAVCom_Req to check if the instance could be created,				*
 *	the function 's paramter include this pointer,when competition happened,competition		*
 * 	module will check if the pointer is NULL ,if not, call it.								*
 * Utility:																		*
 *	this funtion is definated to resolve the competition described at specification,such as:	*
 *	When Media serials instance is created,this function will force the sound object to stop 	*
 *	play(by now , there is only one utility like this)									*/
typedef enum e_status e_status;
//------------------------------------------------------------------------------------------//
//      								Type declarations											//
//------------------------------------------------------------------------------------------//

typedef struct brew_av_com_parm_struct brew_av_com_parm;

/* Competition Act Function definition Begin */
typedef long ( * BrewAV_Competition_Action )(void  * pObjct , void * parm1);
/* Competition Act Function definition End */

/* Scribe:																	*
 *	when instance is create, this function will regist to competition module if this object		*
 *	could set/get volume(just like IMedia,ISound).									*
 * Utility:																		*
 *	at PTX804,the volume is maitained at competition module.so, competition module give 	*
 *	the volume get/set function to client.when set function is called by client,competition 	*
 *	module will call every function that the client regist to competition module to set volume	*/

/* Volume set Function defination Begin */
typedef long ( * BrewAV_SetVolume )(void  * pObjct , long parm1 , long parm2);
/* Volume set Function defination End */

/* Scribe:																	*
 *	when competition module receive a action requirement,at first it will check if this action	*
 *	could be accepted,if yes,the competition will find the status change function from status	*
 *	change list,and call it.														*
 * Utility:																		*
 *	1.add a item to object list(only at the time of create a instance reqirement received) 	*
 *	2.change status														 	*
 *	3.delete a item from object list(only at the time of release requirement received)		*
 *	4.call the competition function(when competition happened)							*/
 
/* Status change Function definition Begin */



/* [PTX804_BREWAV] Zhou Jianwei added BUGLIST 618  2005/05/02 [S] */
/* SoundInfo set Function defination Begin */

typedef long ( * BrewAV_SetSoundInfo )(void  * pObjct , AEESoundInfo * parm);

/* SoundInfo set Function defination End */
/* [PTX804_BREWAV] Zhou Jianwei added BUGLIST 618  2005/05/02 [E] */

typedef long( *BrewAV_Object_Status_Change)(brew_av_com_parm * parm , e_status status);
/* Status change Function definition End */


//status change list's item defination
typedef struct brew_av_object_status_chg_struct
{
	long								status;		//after accept this action,the status that the object will change to
	BrewAV_Object_Status_Change		ChgFunc;	//if necessary,do something in this function
} brew_av_object_status_chg;



//ApiBrewAVCom_ActionReq's parameter defination,client will fill this structure and call it
struct brew_av_com_parm_struct
{
	void 						* pObject;
	AEECLSID					clsID;
	long							action;
	void *						pUser;	//for OEMSound,other object can ignore it 
	BrewAV_Competition_Action	ComAction;
	BrewAV_SetVolume			VolumeSetting;
	
/* [PTX804_BREWAV] Zhou Jianwei added BUGLIST 618  2005/05/02 [S] */
	BrewAV_SetSoundInfo                SoundInfoSetting;
/* [PTX804_BREWAV] Zhou Jianwei added BUGLIST 618  2005/05/02 [E] */

};


//------------------------------------------------------------------------------------------//
//      								extern function declarations									//
//------------------------------------------------------------------------------------------//

/* extern function defination Begin */
extern long ApiBrewAVCom_Initialize();

extern long ApiBrewAVCom_ActionReq(brew_av_com_parm * parm);

extern short ApiBrewAVCom_CountInstanceNum(AEECLSID clsID);

extern long ApiBrewAVCom_SetVolume(void * pObject , short wVolume , boolean mute);

extern long ApiBrewAVCom_GetVolume();

extern long ApiBrewAVCom_Suspend();

/* [PTX804_BREWAV] Zhou Jianwei added BUGLIST 618  2005/05/02 [S] */

extern long ApiBrewAVCom_SetSoundInfo(void * pObject ,AEESoundInfo *parm );

extern long  ApiBrewAVCom_GetSoundInfo(AEESoundInfo *parm );

/* [PTX804_BREWAV] Zhou Jianwei added BUGLIST 618  2005/05/02 [E] */

//PTX808 Add -S-
//ForTRK33
extern long ApiBrewCom_GetObjCurrentStatus( void *pObject,  e_status *pObjStatus);
//PTX808 Add -E-
/* extern function defination End */

#endif
