carlifeplayer.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #ifndef CARLIFEPLAYER_H
  2. #define CARLIFEPLAYER_H
  3. typedef enum
  4. {
  5. CARPLAY = 0x00,
  6. CARLIFE= 0x01,
  7. ANDROID_MIRROR = 0x02,
  8. ANDROID_CARLIFE = 0x03,
  9. IOS_CARLIFE = 0x04,
  10. AUTO = 0x05,
  11. ECLINK = 0x06,
  12. CARPLAY_WIRELESS = 0x07,
  13. CARLIFE_WIRELESS = 0x08,
  14. }Link_TYPE;
  15. #include "carlife.h"
  16. //#include <QFileSystemWatcher>
  17. //#include <QTimer>
  18. #include "timer.h"
  19. //#include "ArkDbus.h"
  20. class UsbManager;
  21. class CarLife;
  22. #define CARPLAY_PATH "/tmp/carplay"
  23. #define CARLIFE_PATH "/tmp/carlife"
  24. typedef std::function<void (int, int, unsigned char*, int, void*)> FUNCVIDEOINFO;
  25. typedef std::function<void (bool, int, int,void*)> FUNCVIDEOSTART;
  26. typedef std::function<void(bool, int,int,int,int,void*)> FUNCAUDIOSTART;
  27. typedef std::function<void(int, unsigned char*, int,void*)> FUNCAUDIOINFO;
  28. typedef std::function<void(int,void*)> FUNCSTATUS;
  29. typedef std::function<void(string,void*)> FUNCPHONENUMBER;
  30. class CarlifePlayer
  31. {
  32. public:
  33. explicit CarlifePlayer();
  34. virtual ~CarlifePlayer();
  35. bool Initialize();
  36. void UnInitialize();
  37. bool SetPlayForeground(bool bForeground);//前后台切换
  38. bool SetPlayMute(bool bMute);
  39. void SetLinkType(int type);
  40. int StartLink(Timer* pTimer = NULL);
  41. //主动退出解码库
  42. bool ExitLink();
  43. //失败的处理
  44. bool HandleFailed(int error);
  45. //退出进程
  46. bool ExitProcess();
  47. //切源后重新解码库
  48. bool RestartLink();
  49. bool Authentication();
  50. void InitCarlife();
  51. void VideoChangeRate(int fps);
  52. void VideoPause();
  53. void VideoStart();
  54. void VideoDisplay(bool bDisplay);
  55. void Touch(int x, int y, int screenwidth, int screenheight, ScreenAction act);
  56. void Key(int key);
  57. // void SetWireless(QString str);
  58. void SetVideoStartCallback(FUNCVIDEOSTART funcVideoStart, void* parameter);
  59. void SetVideoInfoCallback(bool bControlVideo, FUNCVIDEOINFO funcVideoInfo, void* parameter);
  60. void SetAudioStartCallback(FUNCAUDIOSTART funcAudioStart, void* parameter);
  61. void SetAudioInfoCallback(FUNCAUDIOINFO funcAudioInfo, void* parameter);
  62. void SetLinkstatusCallback(FUNCSTATUS funcStatus, void* parameter);
  63. void SetCmdPhoneNumberCallback(FUNCPHONENUMBER funcPhoneNumber, void *parameter);
  64. void SetCmdMediaInfoCallback(void (*callback)(string, string, string, void*), void *parameter);
  65. void SetInsertPath(char *pBuffer);
  66. void setMicAudioData(unsigned char *data, int length);
  67. //是否准备好可以连接
  68. bool GetReadyLink() const {
  69. return m_bConnectable;
  70. }
  71. bool GetInserted() const {
  72. return m_bInserted;
  73. }
  74. bool GetConnected() const {
  75. return m_bConnected;
  76. }
  77. //主要是设置carlife拔出没有状态给出
  78. void SetInserted(bool bInsert);
  79. //检测手机端拔出状态
  80. bool GetRemoved();
  81. //获取用户设置的手机类型
  82. PhoneOS GetUserPhoneOS() const {
  83. return m_PhoneOS;
  84. }
  85. //获取插入手机的类型
  86. PhoneOS GetPhoneOS() const {
  87. return m_nPassive;
  88. }
  89. //用户主动去设置
  90. void SetUserPhoneOS(PhoneOS os);
  91. bool IsCarplayLinked();
  92. //车机端的蓝牙信息
  93. void SetCarBTInfo(int status);
  94. //作为盒子端从车机获取屏幕大小
  95. void GetCarScreenSize(int screenwidth, int screenheight);
  96. void SendCarBluetooth(const string& name, const string& address, const string& pin);
  97. //
  98. void SetBTHFPInComming(char *pPhoneNumber);
  99. void SetBTHFPActive();
  100. void SetBTHFPInActive();
  101. void SetBTHFPOutGoing();
  102. void SetEapLink(bool bEapLink);
  103. void SetAoaLink(bool bAoaLink);
  104. void SetidVendor(int idVendor);
  105. void SetIPAddress(char *pAddress);
  106. void SetTrustMode(bool bTrust);
  107. void SetOpenCarlife(bool bOpen);
  108. void SetInvokedExit(bool Invoked){
  109. m_bInvokedExit = Invoked;
  110. }
  111. char *GetIPAddress() const {return m_pAddress;}
  112. protected:
  113. //苹果手机切换device时,拔出是无法知道苹果手机时候还连着的.carplay并不知道的,所以创建/tmp/carlife文件来发给carplay
  114. //carplay点击的时候来判断时候可以进入carplay
  115. void Exited();
  116. void Linked();
  117. private:
  118. static void usb_callback_func(int online, int type, int vid,void* parameter);
  119. static void socket_disconnect_callback_func(void* parameter);
  120. static void mic_disconnect_callback_func(void* parameter);
  121. static void cmd_status_callback_func(int status, void* parameter);
  122. static void music_status_callback_func(int status, void* parameter);
  123. static void cmd_phonenumber_callback_func(string phonenumber, void* parameter);
  124. static void cmd_mediainfo_callback_func(string song, string artist, string album, void* parameter);
  125. static void vido_callback_func(int ready , int width, int height, void* parameter);
  126. static void video_info_callback_func(int width, int height, unsigned char* data, int length, void*parameter);
  127. static void audio_info_callback_func(int type, unsigned char* data, int length, void*parameter);
  128. static void audio_start_callback_func(bool start, int type, int rate, int bit, int channel, void*parameter);
  129. private:
  130. bool m_bExitProcess;
  131. UsbManager *m_pUsbManger;
  132. CarLife *m_pCarlife;
  133. //被动插入的手机类型
  134. PhoneOS m_nPassive;
  135. //主动发起的手机类型
  136. PhoneOS m_PhoneOS;
  137. //已检测到的
  138. bool m_bInserted;
  139. //初始化完成可以连接的
  140. bool m_bConnectable;
  141. //连接上的状态
  142. bool m_bConnected;
  143. int m_idVendor;
  144. //检测手机端拔出状态
  145. //手机端在启动过程中会切一次OTG,会有一个断开再连接的过程,所以必须检测socket断开和usb未检测到才是拔出状态
  146. bool m_bRemoved;
  147. void* m_parameter;
  148. //命令状态
  149. FUNCSTATUS mFuncStatus;
  150. FUNCPHONENUMBER mFuncPhoneNumber;
  151. void (*m_cmd_mediainfo_callback)(string, string, string ,void*);
  152. FUNCVIDEOSTART mFuncVideoStart;
  153. FUNCVIDEOINFO mFuncVideoInfo;
  154. FUNCAUDIOSTART mFuncAudioStart;
  155. FUNCAUDIOINFO mFuncAudioInfo;
  156. bool m_bCarBack;
  157. bool m_bControlVideo;
  158. sem_t m_SemInit;
  159. sem_t m_SemRelease;
  160. bool m_changeOTG;
  161. char *m_pAddress;
  162. bool m_bTrustMode;
  163. bool m_bOpenCarlife;
  164. bool m_bEapLink;
  165. bool m_bAoaLink;
  166. bool m_bMusicPlayState;
  167. bool m_bExited;
  168. Timer* m_OTGTimer;
  169. Timer* m_InvokedExitTimer;
  170. bool m_bInvokedExit;
  171. bool m_bClickAPKAndStart;
  172. };
  173. #endif // CARLIFEPLAYER_H