peer_connection.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. bool bReadyChannel;
  33. #ifdef WEBRTC_LINUX
  34. void AddLocalVideoTrack(RenderPosition type,int32_t fps);
  35. // void AddLocalVideoTrack(int32_t index,const std::string& label,const std::string &videourl,int32_t width,int32_t height);
  36. void SwitchCapture(bool front);
  37. void * GetCurrentCtx();
  38. void SetOtherCtx(void * data);
  39. #else
  40. void SetDataReady();
  41. bool IsDataReady();
  42. #endif
  43. void SendData(CIOBuffer& pBuffer);
  44. private:
  45. void OnConnect();
  46. void OnPeerMessage(const void * data,const int32_t size);
  47. void OnLocalSdpReadytoSend(int32_t peer,int32_t view,const char* type, const char* sdp);
  48. void OnIceCandidateReadytoSend(int32_t peer,int32_t view,const char* sdp, int32_t sdp_mline_index, const char* sdp_mid);
  49. private:
  50. PeerConnectionHandle _nativeHandle;
  51. SocketClient* _client;
  52. ChannelType _type;
  53. // bool bDataChannel;
  54. bool bConnected;
  55. static std::mutex _lock;
  56. };