OpenTera WebRTC API (C++) 1.2.6
StreamPeerConnectionHandler.h
1 #ifndef OPENTERA_WEBRTC_NATIVE_CLIENT_HANDLERS_STREAM_PEER_CONNECTION_HANDLER_H
2 #define OPENTERA_WEBRTC_NATIVE_CLIENT_HANDLERS_STREAM_PEER_CONNECTION_HANDLER_H
3 
4 #include <OpenteraWebrtcNativeClient/Handlers/PeerConnectionHandler.h>
5 #include <OpenteraWebrtcNativeClient/Sinks/VideoSink.h>
6 #include <OpenteraWebrtcNativeClient/Sinks/EncodedVideoSink.h>
7 #include <OpenteraWebrtcNativeClient/Sinks/AudioSink.h>
8 
9 #include <set>
10 
11 namespace opentera
12 {
13  using VideoFrameReceivedCallback = std::function<void(const Client&, const cv::Mat&, uint64_t)>;
14  using EncodedVideoFrameReceivedCallback = std::function<void(
15  const Client& client,
16  const uint8_t* data,
17  size_t dataSize,
18  VideoCodecType codecType,
19  bool isKeyFrame,
20  uint32_t width,
21  uint32_t height,
22  uint64_t timestampUs)>;
23  using AudioFrameReceivedCallback = std::function<void(
24  const Client& client,
25  const void* audioData,
26  int bitsPerSample,
27  int sampleRate,
28  size_t numberOfChannels,
29  size_t numberOfFrames)>;
30 
32  {
33  bool m_offerToReceiveVideo;
34  bool m_offerToReceiveAudio;
35 
36  rtc::scoped_refptr<webrtc::VideoTrackInterface> m_videoTrack;
37  rtc::scoped_refptr<webrtc::AudioTrackInterface> m_audioTrack;
38 
39  std::function<void(const Client&)> m_onAddRemoteStream;
40  std::function<void(const Client&)> m_onRemoveRemoteStream;
41 
42  std::unique_ptr<VideoSink> m_videoSink;
43  std::unique_ptr<EncodedVideoSink> m_encodedVideoSink;
44  std::unique_ptr<AudioSink> m_audioSink;
45 
46  std::set<rtc::scoped_refptr<webrtc::MediaStreamTrackInterface>> m_tracks;
47 
48  public:
50  std::string id,
51  Client peerClient,
52  bool isCaller,
53  bool hasOnMixedAudioFrameReceivedCallback,
54  SignalingClient& m_signalingClient,
55  std::function<void(const std::string&)> onError,
56  std::function<void(const Client&)> onClientConnected,
57  std::function<void(const Client&)> onClientDisconnected,
58  std::function<void(const Client&)> onClientConnectionFailed,
59  rtc::scoped_refptr<webrtc::VideoTrackInterface> videoTrack,
60  rtc::scoped_refptr<webrtc::AudioTrackInterface> audioTrack,
61  std::function<void(const Client&)> onAddRemoteStream,
62  std::function<void(const Client&)> onRemoveRemoteStream,
63  const VideoFrameReceivedCallback& onVideoFrameReceived,
64  const EncodedVideoFrameReceivedCallback& onEncodedVideoFrameReceived,
65  const AudioFrameReceivedCallback& onAudioFrameReceived);
66 
67  ~StreamPeerConnectionHandler() override;
68 
69  void setPeerConnection(const rtc::scoped_refptr<webrtc::PeerConnectionInterface>& peerConnection) override;
70 
71  void setAllLocalAudioTracksEnabled(bool enabled);
72  void setAllRemoteAudioTracksEnabled(bool enabled);
73  void setAllVideoTracksEnabled(bool enabled);
74 
75  // Observer methods
76  void OnTrack(rtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) override;
77  void OnRemoveTrack(rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) override;
78 
79  protected:
80  void createAnswer() override;
81 
82  private:
83  void addTransceiver(
84  cricket::MediaType type,
85  rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track,
86  bool offerToReceive);
87  void updateTransceiver(
88  cricket::MediaType type,
89  rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> track,
90  bool offerToReceive);
91 
92  void setAllLocalTracksEnabled(const char* kind, bool enabled);
93  void setAllRemoteTracksEnabled(const char* kind, bool enabled);
94  };
95 }
96 
97 #endif
Represents a peer client.
Definition: Client.h:14
Definition: PeerConnectionHandler.h:36
Definition: SignalingClient.h:16
Definition: StreamPeerConnectionHandler.h:32