carplayWrapper.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef __CARPLAY_INTERFACE_H
  2. #define __CARPLAY_INTERFACE_H
  3. #ifdef __cplusplus
  4. #include <string>
  5. #include <stdint.h>
  6. #include "carplayVideoWrapper.h"
  7. #include "carplayAudioWrapper.h"
  8. typedef int CarplayEntity;
  9. #define CarplayEntity_NotApplicable 0
  10. #define CarplayEntity_Controller 1
  11. #define CarplayEntity_Accessory 2
  12. typedef int CarplayTransferType;
  13. #define CarplayTransferType_NotApplicable 0
  14. #define CarplayTransferType_Take 1 // Transfer ownership permanently.
  15. #define CarplayTransferType_Untake 2 // Release permanent ownership.
  16. #define CarplayTransferType_Borrow 3 // Transfer ownership temporarily.
  17. #define CarplayTransferType_Unborrow 4 // Release temporary ownership.
  18. typedef int CarplayTransferPriority;
  19. #define CarplayTransferPriority_NotApplicable 0
  20. #define CarplayTransferPriority_NiceToHave 100 // Transfer succeeds only if constraint is <= Anytime.
  21. #define CarplayTransferPriority_UserInitiated 500 // Transfer succeeds only if constraint is <= UserInitiated.
  22. typedef int CarplayConstraint;
  23. #define CarplayConstraint_NotApplicable 0
  24. #define CarplayConstraint_Anytime 100 // Resource may be taken/borrowed at any time.
  25. #define CarplayConstraint_UserInitiated 500 // Resource may be taken/borrowed if user initiated.
  26. #define CarplayConstraint_Never 1000 // Resource may never be taken/borrowed.
  27. typedef int CarplayTriState;
  28. #define CarplayTriState_NotApplicable 0
  29. #define CarplayTriState_False -1
  30. #define CarplayTriState_True 1
  31. typedef int CarplaySpeechMode;
  32. #define CarplaySpeechMode_NotApplicable 0
  33. #define CarplaySpeechMode_None -1 // No speech-related states are active.
  34. #define CarplaySpeechMode_Speaking 1 // Device is speaking to the user.
  35. #define CarplaySpeechMode_Recognizing 2 // Device is recording audio to recognize speech from the user.
  36. typedef struct
  37. {
  38. CarplayEntity entity;
  39. CarplaySpeechMode mode;
  40. } CarPlaySpeechState;
  41. typedef struct
  42. {
  43. CarplayEntity screen; // Owner of the screen.
  44. CarplayEntity mainAudio; // Owner of main audio.
  45. CarplayEntity phoneCall; // Owner of phone call.
  46. CarPlaySpeechState speech; // Owner of speech and its mode.
  47. CarplayEntity turnByTurn; // Owner of navigation.
  48. } CarPlayModeState;
  49. typedef enum
  50. {
  51. UsbHost = 0,
  52. UsbDevice
  53. } UsbMode;
  54. class CarplayWrapper;
  55. class ICarplayCallbacks
  56. {
  57. public:
  58. virtual void iap2LinkStatus(int status) = 0;
  59. virtual int iap2WriteData(char *buf, int len) = 0;
  60. virtual void carplaySessionStart() = 0;
  61. virtual void carplaySessionStop() = 0;
  62. virtual int switchUsbModeCB(UsbMode mode) = 0;
  63. virtual void appleTimeUpdateCB(long long time, int zone_offset) = 0;
  64. virtual void appleLanguageUpdateCB(const char *lang) = 0;
  65. virtual void NotifyDeviceNameCB(const char *name, int name_len) = 0;
  66. /* *
  67. * @brief 退出的通知
  68. * */
  69. virtual void carplayExitCB() = 0;
  70. /* *
  71. * @brief 点击返回本地界面的按钮通知
  72. * */
  73. virtual void returnNativeUICB() = 0;
  74. /* *
  75. * @brief carplay模式改变的通知
  76. * */
  77. virtual void modesChangeCB(CarPlayModeState *modes) = 0;
  78. /* *
  79. * @brief carplay禁止蓝牙
  80. * */
  81. virtual void disableBluetoothCB() = 0;
  82. /* *
  83. * @brief 压低其他音频流音量
  84. * */
  85. virtual void caplayDuckAudioCB(double inDurationSecs, double inVolume) = 0;
  86. /* *
  87. * @brief 还原其他音频流音量
  88. * */
  89. virtual void caplayUnduckAudioCB(double inDurationSecs) = 0;
  90. };
  91. class ICarplayVideoCallbacks;
  92. class ICarplayAudioCallbacks;
  93. class ICarplayCallbacks;
  94. class Mutex;
  95. class CarplayWrapper
  96. {
  97. public:
  98. CarplayWrapper();
  99. bool init();
  100. void registerCallbacks(ICarplayCallbacks *pcbs);
  101. void registerVideoCallbacks(ICarplayVideoCallbacks *pcbs);
  102. void registerAudioCallbacks(ICarplayAudioCallbacks *pcbs);
  103. int32_t CarplayStart();
  104. void CarplayStop();
  105. void CarplaySetIntParameter(const std::string& key, const int32_t& value);
  106. void CarplaySetStringParameter(const std::string& key, const std::string& value);
  107. int CarplayGetIntValue(const std::string& key);
  108. std::string CarplayGetStringValue(const std::string& key);
  109. void CarplaySendMediaKey(const int32_t& button, const bool& pressed);
  110. void CarplaySendTelephoneKey(const int32_t& button, const bool& pressed);
  111. void CarplaysendSiriButton(const bool& pressed);
  112. void CarplaySendSingleTouchPoint(const uint16_t& x, const uint16_t& y, const bool& pressed);
  113. void CarplaySendKnob(const uint8_t& selectButton, const uint8_t& homeButton, const uint8_t& backButton, const double& x, const double& y, const uint8_t& wheelPositionRelative);
  114. void CarplayForceKeyFrame();
  115. void CarplayRequestUI(const std::string& url);
  116. void CarplayChangeModes(const int32_t& ScreenType, const int32_t& ScreenPriority, const int32_t& ScreenTake, const int32_t& ScreenBorrow, const int32_t& AudioType, const int32_t& AudioPriority, const int32_t& AudioTake, const int32_t& AudioBorrow, const int32_t& Phone, const int32_t& Speech, const int32_t& TurnByTurn);
  117. void CarplaySendNightMode(bool inNightMode);
  118. /* *
  119. * @brief 获取carplay送过来的音频数据,然后送到声卡播放
  120. * @param handle 该路音频流操作句柄
  121. * @param buffer 数据缓存
  122. * @param len 数据缓存大小
  123. * @param frames 音频数据帧大小 frames = len / (bits / 8 * channels)
  124. * @timestamp timestamp 播放时间戳
  125. * */
  126. void AudioPlayStream(int handle, void *buffer, int len, int frames, unsigned long long timestamp);
  127. /* *
  128. * @brief 从声卡获取录音数据,然后发给carplay
  129. * @param handle 该路音频流操作句柄
  130. * @param buffer 数据缓存
  131. * @param len 数据缓存大小
  132. * @param frames 音频数据帧大小 frames = len / (bits / 8 * channels)
  133. * @timestamp timestamp 播放时间戳
  134. * */
  135. void AudioRecordStream(int handle, void *buffer, int len, int frames, unsigned long long timestamp);
  136. void stopTimer();
  137. friend class CarplayCallbacksPriv;
  138. protected:
  139. static void* CarplayStartProc(void *ctx);
  140. static void* CarplayStopProc(void *ctx);
  141. static void timeoutExpiredProc(void *ctx);
  142. private:
  143. Mutex* mLock;
  144. void* mTimeout;
  145. bool mStart;
  146. ICarplayCallbacks *mCbs;
  147. ICarplayVideoCallbacks *mVideoCbs;
  148. ICarplayAudioCallbacks *mAudioCbs;
  149. };
  150. #endif
  151. #endif//__DEMO_ECHO_SERVER_H