StreamManager refactoring
[platform/core/ml/aitt.git] / modules / webrtc / WebRtcEventHandler.h
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <functional>
20
21 #include "WebRtcState.h"
22
23 namespace AittWebRTCNamespace {
24
25 class WebRtcEventHandler {
26   public:
27     // TODO Add error and state callbacks
28     void SetOnStateChangedCb(std::function<void(WebRtcState::Stream)> on_state_changed_cb)
29     {
30         on_state_changed_cb_ = on_state_changed_cb;
31     };
32     void CallOnStateChangedCb(WebRtcState::Stream state) const
33     {
34         if (on_state_changed_cb_)
35             on_state_changed_cb_(state);
36     };
37     void UnsetOnStateChangedCb(void) { on_state_changed_cb_ = nullptr; };
38
39     void SetOnSignalingStateNotifyCb(
40           std::function<void(WebRtcState::Signaling)> on_signaling_state_notify_cb)
41     {
42         on_signaling_state_notify_cb_ = on_signaling_state_notify_cb;
43     };
44     void CallOnSignalingStateNotifyCb(WebRtcState::Signaling state) const
45     {
46         if (on_signaling_state_notify_cb_)
47             on_signaling_state_notify_cb_(state);
48     };
49     void UnsetOnSignalingStateNotifyCb(void) { on_signaling_state_notify_cb_ = nullptr; };
50
51     void SetOnIceCandidateCb(std::function<void(std::string)> on_ice_candidate_cb)
52     {
53         on_ice_candidate_cb_ = on_ice_candidate_cb;
54     };
55     void CallOnIceCandidateCb(std::string candidate) const
56     {
57         if (on_ice_candidate_cb_)
58             on_ice_candidate_cb_(candidate);
59     };
60     void UnsetOnIceCandidateCb(void) { on_ice_candidate_cb_ = nullptr; };
61
62     void SetOnIceGatheringStateNotifyCb(
63           std::function<void(WebRtcState::IceGathering)> on_ice_gathering_state_notify_cb)
64     {
65         on_ice_gathering_state_notify_cb_ = on_ice_gathering_state_notify_cb;
66     };
67     void CallOnIceGatheringStateNotifyCb(WebRtcState::IceGathering state) const
68     {
69         if (on_ice_gathering_state_notify_cb_)
70             on_ice_gathering_state_notify_cb_(state);
71     };
72     void UnsetOnIceGatheringStateNotifyeCb(void) { on_ice_gathering_state_notify_cb_ = nullptr; };
73
74     void SetOnIceConnectionStateNotifyCb(
75           std::function<void(WebRtcState::IceConnection)> on_ice_connection_state_notify_cb)
76     {
77         on_ice_connection_state_notify_cb_ = on_ice_connection_state_notify_cb;
78     };
79     void CallOnIceConnectionStateNotifyCb(WebRtcState::IceConnection state) const
80     {
81         if (on_ice_connection_state_notify_cb_)
82             on_ice_connection_state_notify_cb_(state);
83     };
84     void UnsetOnIceConnectionStateNotifyeCb(void) { on_ice_connection_state_notify_cb_ = nullptr; };
85
86     void SetOnEncodedFrameCb(std::function<void(void)> on_encoded_frame_cb)
87     {
88         on_encoded_frame_cb_ = on_encoded_frame_cb;
89     };
90     void CallOnEncodedFrameCb(void) const
91     {
92         if (on_encoded_frame_cb_)
93             on_encoded_frame_cb_();
94     };
95     void UnsetEncodedFrameCb(void) { on_encoded_frame_cb_ = nullptr; };
96
97     void SetOnTrakAddedCb(std::function<void(unsigned int id)> on_track_added_cb)
98     {
99         on_track_added_cb_ = on_track_added_cb;
100     };
101     void CallOnTrakAddedCb(unsigned int id) const
102     {
103         if (on_track_added_cb_)
104             on_track_added_cb_(id);
105     };
106     void UnsetTrackAddedCb(void) { on_track_added_cb_ = nullptr; };
107
108   private:
109     std::function<void(void)> on_negotiation_needed_cb_;
110     std::function<void(WebRtcState::Stream)> on_state_changed_cb_;
111     std::function<void(WebRtcState::Signaling)> on_signaling_state_notify_cb_;
112     std::function<void(std::string)> on_ice_candidate_cb_;
113     std::function<void(WebRtcState::IceGathering)> on_ice_gathering_state_notify_cb_;
114     std::function<void(WebRtcState::IceConnection)> on_ice_connection_state_notify_cb_;
115     std::function<void(void)> on_encoded_frame_cb_;
116     std::function<void(unsigned int id)> on_track_added_cb_;
117 };
118
119 }  // namespace AittWebRTCNamespace