Nagram/TMessagesProj/jni/voip/tgcalls/group/GroupInstanceImpl.h

197 lines
5.2 KiB
C
Raw Normal View History

2020-12-23 07:48:30 +00:00
#ifndef TGCALLS_GROUP_INSTANCE_IMPL_H
#define TGCALLS_GROUP_INSTANCE_IMPL_H
#include <functional>
#include <vector>
#include <string>
#include <memory>
#include <map>
#include "../Instance.h"
2021-03-19 10:25:58 +00:00
#include "../StaticThreads.h"
2021-06-25 00:43:10 +00:00
#include "GroupJoinPayload.h"
2021-03-19 10:25:58 +00:00
2020-12-23 07:48:30 +00:00
namespace webrtc {
class AudioDeviceModule;
class TaskQueueFactory;
2021-06-25 00:43:10 +00:00
class VideoTrackSourceInterface;
2020-12-23 07:48:30 +00:00
}
2021-03-19 10:25:58 +00:00
namespace rtc {
template <class T>
class scoped_refptr;
}
2020-12-23 07:48:30 +00:00
namespace tgcalls {
class LogSinkImpl;
class GroupInstanceManager;
2021-03-19 10:25:58 +00:00
struct AudioFrame;
2020-12-23 07:48:30 +00:00
struct GroupConfig {
2021-03-19 10:25:58 +00:00
bool need_log{true};
2020-12-23 07:48:30 +00:00
FilePath logPath;
};
struct GroupLevelValue {
float level = 0.;
bool voice = false;
2021-06-25 00:43:10 +00:00
bool isMuted = false;
2020-12-23 07:48:30 +00:00
};
struct GroupLevelUpdate {
uint32_t ssrc = 0;
GroupLevelValue value;
};
struct GroupLevelsUpdate {
std::vector<GroupLevelUpdate> updates;
};
2021-03-19 10:25:58 +00:00
class BroadcastPartTask {
public:
virtual ~BroadcastPartTask() = default;
virtual void cancel() = 0;
};
struct BroadcastPart {
enum class Status {
Success,
NotReady,
ResyncNeeded
};
int64_t timestampMilliseconds = 0;
double responseTimestamp = 0;
Status status = Status::NotReady;
std::vector<uint8_t> oggData;
};
enum class GroupConnectionMode {
GroupConnectionModeNone,
GroupConnectionModeRtc,
GroupConnectionModeBroadcast
};
struct GroupNetworkState {
bool isConnected = false;
bool isTransitioningFromBroadcastToRtc = false;
};
2021-06-25 00:43:10 +00:00
enum class VideoContentType {
None,
Screencast,
Generic
2020-12-23 07:48:30 +00:00
};
2021-06-25 00:43:10 +00:00
enum class VideoCodecName {
VP8,
VP9
2020-12-23 07:48:30 +00:00
};
2021-06-25 00:43:10 +00:00
class RequestMediaChannelDescriptionTask {
public:
virtual ~RequestMediaChannelDescriptionTask() = default;
2021-03-19 10:25:58 +00:00
2021-06-25 00:43:10 +00:00
virtual void cancel() = 0;
2021-03-19 10:25:58 +00:00
};
2021-06-25 00:43:10 +00:00
struct MediaChannelDescription {
enum class Type {
Audio,
Video
};
2021-03-19 10:25:58 +00:00
2021-06-25 00:43:10 +00:00
Type type = Type::Audio;
uint32_t audioSsrc = 0;
std::string videoInformation;
};
2020-12-23 07:48:30 +00:00
2021-06-25 00:43:10 +00:00
struct MediaSsrcGroup {
std::string semantics;
std::vector<uint32_t> ssrcs;
2021-03-19 10:25:58 +00:00
};
2021-06-25 00:43:10 +00:00
struct VideoChannelDescription {
enum class Quality {
Thumbnail,
Medium,
Full
};
2021-03-19 10:25:58 +00:00
uint32_t audioSsrc = 0;
2021-06-25 00:43:10 +00:00
std::string endpointId;
std::vector<MediaSsrcGroup> ssrcGroups;
Quality minQuality = Quality::Thumbnail;
Quality maxQuality = Quality::Thumbnail;
2020-12-23 07:48:30 +00:00
};
2021-06-25 00:43:10 +00:00
struct GroupInstanceDescriptor {
std::shared_ptr<Threads> threads;
GroupConfig config;
std::function<void(GroupNetworkState)> networkStateUpdated;
std::function<void(GroupLevelsUpdate const &)> audioLevelsUpdated;
std::function<void(uint32_t, const AudioFrame &)> onAudioFrame;
std::string initialInputDeviceId;
std::string initialOutputDeviceId;
bool useDummyChannel{true};
bool disableIncomingChannels{false};
std::function<rtc::scoped_refptr<webrtc::AudioDeviceModule>(webrtc::TaskQueueFactory*)> createAudioDeviceModule;
std::shared_ptr<VideoCaptureInterface> videoCapture; // deprecated
std::function<webrtc::VideoTrackSourceInterface*()> getVideoSource;
std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, std::function<void(BroadcastPart &&)>)> requestBroadcastPart;
int outgoingAudioBitrateKbit{32};
bool disableOutgoingAudioProcessing{false};
VideoContentType videoContentType{VideoContentType::None};
bool initialEnableNoiseSuppression{false};
std::vector<VideoCodecName> videoCodecPreferences;
std::function<std::shared_ptr<RequestMediaChannelDescriptionTask>(std::vector<uint32_t> const &, std::function<void(std::vector<MediaChannelDescription> &&)>)> requestMediaChannelDescriptions;
int minOutgoingVideoBitrateKbit{100};
2020-12-23 07:48:30 +00:00
2021-06-25 00:43:10 +00:00
std::shared_ptr<PlatformContext> platformContext;
2020-12-23 07:48:30 +00:00
};
template <typename T>
class ThreadLocalObject;
2021-03-19 10:25:58 +00:00
class GroupInstanceInterface {
protected:
GroupInstanceInterface() = default;
2020-12-23 07:48:30 +00:00
public:
2021-03-19 10:25:58 +00:00
virtual ~GroupInstanceInterface() = default;
virtual void stop() = 0;
virtual void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) = 0;
2021-06-25 00:43:10 +00:00
virtual void emitJoinPayload(std::function<void(GroupJoinPayload const &)> completion) = 0;
virtual void setJoinResponsePayload(std::string const &payload) = 0;
2021-03-19 10:25:58 +00:00
virtual void removeSsrcs(std::vector<uint32_t> ssrcs) = 0;
2021-06-25 00:43:10 +00:00
virtual void removeIncomingVideoSource(uint32_t ssrc) = 0;
2020-12-23 07:48:30 +00:00
2021-03-19 10:25:58 +00:00
virtual void setIsMuted(bool isMuted) = 0;
2021-06-25 00:43:10 +00:00
virtual void setIsNoiseSuppressionEnabled(bool isNoiseSuppressionEnabled) = 0;
virtual void setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture) = 0;
virtual void setVideoSource(std::function<webrtc::VideoTrackSourceInterface*()> getVideoSource) = 0;
2021-03-19 10:25:58 +00:00
virtual void setAudioOutputDevice(std::string id) = 0;
virtual void setAudioInputDevice(std::string id) = 0;
2020-12-23 07:48:30 +00:00
2021-06-25 00:43:10 +00:00
virtual void addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0;
2020-12-23 07:48:30 +00:00
2021-03-19 10:25:58 +00:00
virtual void setVolume(uint32_t ssrc, double volume) = 0;
2021-06-25 00:43:10 +00:00
virtual void setRequestedVideoChannels(std::vector<VideoChannelDescription> &&requestedVideoChannels) = 0;
2020-12-23 07:48:30 +00:00
struct AudioDevice {
enum class Type {Input, Output};
std::string name;
std::string guid;
};
2021-04-09 13:17:32 +00:00
static std::vector<GroupInstanceInterface::AudioDevice> getAudioDevices(AudioDevice::Type type);
2020-12-23 07:48:30 +00:00
};
} // namespace tgcalls
#endif