12 #include <unordered_map>
15 #include "AgoraBase.h"
16 #include "NGIAgoraVideoTrack.h"
17 #include "call/rtp_config.h"
19 #include "rtc_connection_i.h"
20 #include "track_stat_i.h"
21 #include "video_config_i.h"
22 #include "common_defines.h"
23 #include "video_node_i.h"
31 CONFIG_PRIORITY_DEBUG = 0,
33 CONFIG_PRIORITY_DEVICE,
37 CONFIG_PRIORITY_HIGH_FROM_SERVER,
43 CONFIG_PRIORITY_NORMAL_FROM_SERVER,
45 CONFIG_PRIORITY_INTERNAL,
49 template <
typename Observer>
55 bool add(std::shared_ptr<Observer> obs) {
60 std::lock_guard<std::mutex> _(obs_mutex_);
61 observer_map_[obs.get()] = obs;
66 std::lock_guard<std::mutex> _(obs_mutex_);
67 return observer_map_.size();
71 bool remove(Observer* obs) {
76 std::lock_guard<std::mutex> _(obs_mutex_);
77 if (observer_map_.find(obs) == observer_map_.end()) {
81 observer_map_.erase(obs);
85 void notify(std::function<
void (std::shared_ptr<Observer>)>&& notify) {
86 std::vector<std::shared_ptr<Observer>> obs_copy;
89 std::lock_guard<std::mutex> _(obs_mutex_);
91 for (
auto it = observer_map_.begin(); it != observer_map_.end();) {
92 auto obs_shared = it->second.lock();
94 it = observer_map_.erase(it);
98 obs_copy.push_back(obs_shared);
103 for (
auto obs : obs_copy) {
109 std::mutex obs_mutex_;
110 std::unordered_map<Observer*, std::weak_ptr<Observer>> observer_map_;
117 class VideoNodeRtpSink;
118 class VideoNodeRtpSource;
119 class VideoTrackConfigurator;
121 enum class InternalVideoSourceType : unsigned {
128 CustomEncodedImageSource = 5,
129 CustomPacketSource = 6,
131 TranscodedSource = 8,
137 virtual void onLocalVideoStateChanged(
int id,
138 LOCAL_VIDEO_STREAM_STATE state,
139 LOCAL_VIDEO_STREAM_ERROR errorCode,
142 virtual void onRemoteVideoStateChanged(uid_t uid,
143 REMOTE_VIDEO_STATE state,
144 REMOTE_VIDEO_STATE_REASON reason,
147 virtual void onFirstVideoFrameRendered(uid_t uid,
int width,
int height,
int timestamp_ms) {}
149 virtual void onFirstVideoFrameDecoded(uid_t uid,
int width,
int height,
int timestamp_ms) {}
151 virtual void onSourceVideoSizeChanged(uid_t uid,
152 int width,
int height,
153 int rotation,
int timestamp_ms) {}
154 virtual void onSendSideDelay(
int id,
int send_delay) {}
155 virtual void onRecvSideDelay(uid_t uid,
int recv_delay) {}
156 virtual void onRecvSideFps(uid_t uid,
int fps) {}
157 virtual void onSetVideoEncoderConfiguration(
int width,
int height,
int fps,
int framerate) {}
162 enum DetachReason { MANUAL, TRACK_DESTROY, NETWORK_DESTROY };
166 std::vector<int> fec_protection_factor;
167 std::vector<std::vector<int>> fec_ratioLevel;
168 std::vector<int> fec_rttThreshold;
173 bool QuickAdaptNetwork;
175 int MinHoldtimeAutoResizeZoomin;
176 int MinHoldtimeAutoResizeZoomout;
184 VideoNodeRtpSink* network;
185 WeakPipelineBuilder builder;
186 uint64_t stats_space;
187 CongestionControlType cc_type;
188 bool enable_two_bytes_extension;
189 webrtc::FecConfig fec_config;
192 std::string enable_hw_encoder;
193 std::string hw_encoder_provider;
200 int32_t dmfec_minimum_level;
204 VideoNodeRtpSink* network;
211 virtual bool hasPublished() = 0;
213 virtual int SetVideoConfigEx(
const VideoConfigurationEx& configEx, utils::ConfigPriority priority = utils::CONFIG_PRIORITY_USER) = 0;
215 virtual int GetConfigExs(std::vector<VideoConfigurationEx>& configs) = 0;
217 virtual int setUserId(uid_t uid) { user_id_ = uid;
return 0; }
219 virtual uid_t getUserId() {
return user_id_; }
221 virtual int getObserverSize() {
return track_observers_.size(); }
223 virtual int GetActiveStreamsCount() = 0;
225 virtual int prepareNodes() = 0;
227 virtual bool attach(
const AttachInfo& info) = 0;
228 virtual bool detach(
const DetachInfo& info) = 0;
230 virtual bool registerTrackObserver(std::shared_ptr<IVideoTrackObserver> observer) {
233 virtual bool unregisterTrackObserver(IVideoTrackObserver* observer) {
237 virtual int32_t Width()
const = 0;
238 virtual int32_t Height()
const = 0;
239 virtual bool Enabled()
const = 0;
241 virtual int addVideoWatermark(
const char* watermarkUrl,
const WatermarkOptions& options) {
return -ERR_NOT_SUPPORTED; };
242 virtual int clearVideoWatermarks() {
return -ERR_NOT_SUPPORTED; }
244 virtual VideoTrackConfigurator* GetVideoTrackConfigurator() {
248 virtual InternalVideoSourceType getInternalVideoSourceType() {
return InternalVideoSourceType::None; }
250 int TrackId()
const {
return id_; }
253 static void resetIdGenerator();
257 utils::WeakObservers<IVideoTrackObserver> track_observers_;
261 static std::atomic<int> id_generator_;
265 uint64_t firstDecodingTimeTickMs = 0;
266 uint64_t firstVideoFrameRendered = 0;
267 bool isHardwareCodec =
false;
272 enum DetachReason { MANUAL, TRACK_DESTROY, NETWORK_DESTROY };
273 using RemoteVideoEvents = StateEvents<REMOTE_VIDEO_STATE, REMOTE_VIDEO_STATE_REASON>;
276 VideoNodeRtpSource* source;
277 VideoNodeRtpSink* rtcp_sender;
278 WeakPipelineBuilder builder;
279 bool recv_media_packet =
false;
280 uint64_t stats_space = 0;
284 VideoNodeRtpSource* source;
285 VideoNodeRtpSink* rtcp_sender;
293 virtual uint32_t getRemoteSsrc() = 0;
295 virtual bool attach(
const AttachInfo& info, REMOTE_VIDEO_STATE_REASON reason) = 0;
296 virtual bool detach(
const DetachInfo& info, REMOTE_VIDEO_STATE_REASON reason) = 0;
300 virtual bool registerTrackObserver(std::shared_ptr<IVideoTrackObserver> observer) {
303 virtual bool unregisterTrackObserver(IVideoTrackObserver* observer) {
308 utils::WeakObservers<IVideoTrackObserver> track_observers_;