CarplayLink.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef CARPLAYLINK_H
  2. #define CARPLAYLINK_H
  3. #ifdef __cplusplus
  4. #include "IUserLinkPlayer.h"
  5. #include "carplayWrapper.h"
  6. #include "carplayVideoWrapper.h"
  7. #include "carplayAudioWrapper.h"
  8. #include <list>
  9. #include <mutex>
  10. #define PLAYLOAD 640
  11. #define AECLEN 160
  12. #ifdef USE_CARPLAY
  13. class BufferQueue;
  14. class CarplayWrapper;
  15. class CarplayAudioCtx;
  16. class ICarplayVideoCallbacksImpl : public ICarplayVideoCallbacks
  17. {
  18. public:
  19. ICarplayVideoCallbacksImpl(CarplayLink* handle) : mHandle(handle) {}
  20. int carplayVideoStartCB();
  21. void carplayVideoStopCB();
  22. int carplayVideoDataProcCB(const char *buf, int len);
  23. private:
  24. // long mInterfaceFrame;
  25. CarplayLink* mHandle;
  26. };
  27. class ICarplayAudioCallbacksImpl : public ICarplayAudioCallbacks
  28. {
  29. public:
  30. ICarplayAudioCallbacksImpl(CarplayLink* handle) : mHandle(handle) {}
  31. void carplayAudioStartCB(int handle, AudioStreamType type, int rate, int bits, int channels);
  32. void carplayAudioStopCB(int handle, AudioStreamType type);
  33. private:
  34. CarplayLink* mHandle;
  35. Mutex mLock;
  36. std::list<CarplayAudioCtx*> mAudioHandlList;
  37. };
  38. #endif
  39. class CarplayLink : public IUserLinkPlayer
  40. {
  41. public:
  42. CarplayLink();
  43. virtual ~CarplayLink();
  44. #ifdef USE_CARPLAY
  45. protected:
  46. virtual bool init(LinkMode linkMode);
  47. virtual bool release();
  48. virtual bool start();
  49. virtual bool stop();
  50. virtual bool start_mirror();
  51. virtual bool stop_mirror();
  52. virtual bool set_background();
  53. virtual bool set_foreground();
  54. virtual bool get_audio_focus();
  55. virtual bool release_audio_focus();
  56. virtual void set_inserted(bool inserted, PhoneType phoneType);
  57. virtual void send_screen_size(int width, int height);
  58. virtual void record_audio_callback(unsigned char *data, int len);
  59. virtual void send_car_bluetooth(const string& name, const string& address, const string& pin);
  60. virtual void send_phone_bluetooth(const string& address);
  61. virtual void send_car_wifi(WifiInfo& info);
  62. virtual void send_touch(int x, int y, TouchCode touchCode);
  63. virtual void send_multi_touch(int x1, int y1, TouchCode touchCode1, int x2, int y2, TouchCode touchCode2){}
  64. virtual bool send_key(KeyCode keyCode);
  65. virtual bool send_wheel(WheelCode wheel, bool foucs);
  66. virtual bool send_night_mode(bool night);
  67. virtual bool send_right_hand_driver(bool right);
  68. virtual bool open_page(AppPage appPage);
  69. virtual void request_status(RequestAppStatus requestAppStatus, void *reserved = nullptr);
  70. virtual void send_license(const string& license){}
  71. virtual void send_input_text(const string& text) {}
  72. virtual void send_input_selection(const int start, const int stop){}
  73. virtual void send_input_action(const int acionId, const int keyCode){}
  74. virtual void send_bluetooth_cmd(const string& cmd ){}
  75. virtual void send_broadcast(bool enable){}
  76. virtual void send_delay_record(int millisecond){}
  77. virtual void send_wifi_state_changed(WifiStateAction action, WifiState state, const string& phoneIp, const string& carIp){}
  78. protected:
  79. LinkConfig getLinkConfig() const {return mLinkConfig;}
  80. CarplayConfig getCarPlayConfig() const {return mCarplayConfig;}
  81. PhoneType getPhoneType() const {return mPhoneType;}
  82. bool sendPlayData(int handle, char type, const char* buf, int len, int frames, long long time_stamp);
  83. bool receiveRecordData(int handle, int frames);
  84. void AudioRecordVoiceDenoisePorcess(char *buf, int len);
  85. void setLocalTime(long long local);
  86. friend class CarplayAudioPlayCtx;
  87. friend class CarplayAudioRecordCtx;
  88. friend class ICarplayVideoCallbacksImpl;
  89. friend class ICarplayAudioCallbacksImpl;
  90. friend class CarplayLinkCbsImpl;
  91. std::mutex mMutex;
  92. CarplayWrapper* mHandle;
  93. ICarplayCallbacks* mCbs;
  94. ICarplayVideoCallbacks* mVideoCbs;
  95. ICarplayAudioCallbacks* mAudioCbs;
  96. PhoneType mPhoneType;
  97. long long mLocalTime;
  98. LinkMode mLinkMode;
  99. bool mDefaultWifi;
  100. bool mDdefaultPhonebtMac;
  101. void* mAecHandle;
  102. void* mDenoiseHandle;
  103. BufferQueue* mAecQueue;
  104. AudioStreamType mAudioStreamType;
  105. int mRecHandle;
  106. int mRecFrames;
  107. int mRecPos;
  108. char mRecBuf[PLAYLOAD];
  109. long mInterfaceFrame;
  110. #endif
  111. };
  112. #endif
  113. #endif // CARPLAYLINK_H