peer_connection.h 2.1 KB

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