carplayWrapper.h 6.2 KB

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