peer_connection.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <vector>
  3. #include <string>
  4. #include <functional>
  5. #include <future>
  6. #include <mutex>
  7. #include "api.h"
  8. #include "../common/comm.h"
  9. class SocketClient;
  10. class CIOBuffer;
  11. class CPeerConnection
  12. {
  13. public:
  14. CPeerConnection(ChannelType type, SocketClient* d);
  15. virtual ~CPeerConnection();
  16. void Initialize(int32_t peer,int32_t index,int32_t MinPort,int32_t MaxPort);
  17. static void ConnectionCallBack(void* UserData);
  18. static void LocalSdpReadytoSendCallback(void* user_data,int32_t peer,int32_t view, const char* type, const char* sdp_data);
  19. static void IceCandidateReadytoSendCallback(void* user_data,int32_t peer,int32_t view, const char* sdp, int32_t sdp_mline_index, const char* sdp_mid);
  20. static void MessageCallback(void * user_data,const void * data,const int32_t size);
  21. void AddLocalArgb32VideoFrameReady(PeerConnectionARGBVideoFrameCallback fn, void* user_data);
  22. void AddLocalAudioTrack();
  23. void RemoveLocalAudioTrack();
  24. void AddRemoteArgb32VideoFrameReady(PeerConnectionARGBVideoFrameCallback fn, void* user_data);
  25. void AddDataChannel(bool ordered, bool reliable);
  26. void RemoveDataChannel();
  27. void SetRemoteDescription(const char* type, std::string sdp);
  28. bool CreateAnswer();
  29. bool CreateOffer();
  30. void AddIceCandidate(const char* sdp, int32_t sdp_mline_index, const char* sdp_mid);
  31. void Close();
  32. void SetGsml(int64_t time,int64_t StartRecord,int64_t DeviceId);
  33. bool bReadyChannel;
  34. #ifdef WEBRTC_LINUX
  35. //void AddLocalVideoTrack(RenderPosition type,int32_t fps);
  36. void AddLocalVideoTrack(RenderPosition type,int32_t index,int32_t GSML);
  37. // void AddLocalVideoTrack(int32_t index,const std::string& label,const std::string &videourl,int32_t width,int32_t height);
  38. void SwitchCapture(bool front);
  39. void * GetCurrentCtx();
  40. void SetOtherCtx(void * data);
  41. #else
  42. void SetDataReady();
  43. bool IsDataReady();
  44. #endif
  45. void SendData(CIOBuffer& pBuffer);
  46. private:
  47. void OnConnect();
  48. void OnPeerMessage(const void * data,const int32_t size);
  49. void OnLocalSdpReadytoSend(int32_t peer,int32_t view,const char* type, const char* sdp);
  50. void OnIceCandidateReadytoSend(int32_t peer,int32_t view,const char* sdp, int32_t sdp_mline_index, const char* sdp_mid);
  51. private:
  52. PeerConnectionHandle _nativeHandle;
  53. SocketClient* _client;
  54. ChannelType _type;
  55. // bool bDataChannel;
  56. bool bConnected;
  57. static std::mutex _lock;
  58. };