2020-12-23 08:48:30 +01: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 11:25:58 +01:00
|
|
|
#include "../StaticThreads.h"
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
namespace webrtc {
|
|
|
|
class AudioDeviceModule;
|
|
|
|
class TaskQueueFactory;
|
|
|
|
}
|
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
namespace rtc {
|
|
|
|
template <class T>
|
|
|
|
class scoped_refptr;
|
|
|
|
}
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
namespace tgcalls {
|
|
|
|
|
|
|
|
class LogSinkImpl;
|
|
|
|
class GroupInstanceManager;
|
2021-03-19 11:25:58 +01:00
|
|
|
struct AudioFrame;
|
2020-12-23 08:48:30 +01:00
|
|
|
|
|
|
|
struct GroupConfig {
|
2021-03-19 11:25:58 +01:00
|
|
|
bool need_log{true};
|
2020-12-23 08:48:30 +01:00
|
|
|
FilePath logPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupLevelValue {
|
|
|
|
float level = 0.;
|
|
|
|
bool voice = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupLevelUpdate {
|
|
|
|
uint32_t ssrc = 0;
|
|
|
|
GroupLevelValue value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupLevelsUpdate {
|
|
|
|
std::vector<GroupLevelUpdate> updates;
|
|
|
|
};
|
|
|
|
|
2021-03-19 11:25:58 +01: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;
|
|
|
|
};
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
struct GroupInstanceDescriptor {
|
2021-03-19 11:25:58 +01:00
|
|
|
std::shared_ptr<Threads> threads;
|
2020-12-23 08:48:30 +01:00
|
|
|
GroupConfig config;
|
2021-03-19 11:25:58 +01:00
|
|
|
std::function<void(GroupNetworkState)> networkStateUpdated;
|
2020-12-23 08:48:30 +01:00
|
|
|
std::function<void(GroupLevelsUpdate const &)> audioLevelsUpdated;
|
2021-03-19 11:25:58 +01:00
|
|
|
std::function<void(uint32_t, const AudioFrame &)> onAudioFrame;
|
2020-12-23 08:48:30 +01:00
|
|
|
std::string initialInputDeviceId;
|
|
|
|
std::string initialOutputDeviceId;
|
2021-04-09 15:17:32 +02:00
|
|
|
bool useDummyChannel{true};
|
|
|
|
bool disableIncomingChannels{false};
|
2021-03-19 11:25:58 +01:00
|
|
|
std::function<rtc::scoped_refptr<webrtc::AudioDeviceModule>(webrtc::TaskQueueFactory*)> createAudioDeviceModule;
|
|
|
|
std::shared_ptr<VideoCaptureInterface> videoCapture;
|
|
|
|
std::function<void(std::vector<uint32_t> const &)> incomingVideoSourcesUpdated;
|
|
|
|
std::function<void(std::vector<uint32_t> const &)> participantDescriptionsRequired;
|
|
|
|
std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, std::function<void(BroadcastPart &&)>)> requestBroadcastPart;
|
2020-12-23 08:48:30 +01:00
|
|
|
std::shared_ptr<PlatformContext> platformContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupJoinPayloadFingerprint {
|
|
|
|
std::string hash;
|
|
|
|
std::string setup;
|
|
|
|
std::string fingerprint;
|
|
|
|
};
|
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
struct GroupJoinPayloadVideoSourceGroup {
|
|
|
|
std::vector<uint32_t> ssrcs;
|
|
|
|
std::string semantics;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupJoinPayloadVideoPayloadFeedbackType {
|
|
|
|
std::string type;
|
|
|
|
std::string subtype;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupJoinPayloadVideoPayloadType {
|
|
|
|
uint32_t id = 0;
|
|
|
|
std::string name;
|
|
|
|
uint32_t clockrate = 0;
|
|
|
|
uint32_t channels = 0;
|
|
|
|
std::vector<GroupJoinPayloadVideoPayloadFeedbackType> feedbackTypes;
|
|
|
|
std::vector<std::pair<std::string, std::string>> parameters;
|
|
|
|
};
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
struct GroupJoinPayload {
|
|
|
|
std::string ufrag;
|
|
|
|
std::string pwd;
|
|
|
|
std::vector<GroupJoinPayloadFingerprint> fingerprints;
|
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
std::vector<GroupJoinPayloadVideoPayloadType> videoPayloadTypes;
|
|
|
|
std::vector<std::pair<uint32_t, std::string>> videoExtensionMap;
|
2020-12-23 08:48:30 +01:00
|
|
|
uint32_t ssrc = 0;
|
2021-03-19 11:25:58 +01:00
|
|
|
std::vector<GroupJoinPayloadVideoSourceGroup> videoSourceGroups;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupParticipantDescription {
|
|
|
|
std::string endpointId;
|
|
|
|
uint32_t audioSsrc = 0;
|
|
|
|
std::vector<GroupJoinPayloadVideoPayloadType> videoPayloadTypes;
|
|
|
|
std::vector<std::pair<uint32_t, std::string>> videoExtensionMap;
|
|
|
|
std::vector<GroupJoinPayloadVideoSourceGroup> videoSourceGroups;
|
|
|
|
bool isRemoved = false;
|
2020-12-23 08:48:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupJoinResponseCandidate {
|
|
|
|
std::string port;
|
|
|
|
std::string protocol;
|
|
|
|
std::string network;
|
|
|
|
std::string generation;
|
|
|
|
std::string id;
|
|
|
|
std::string component;
|
|
|
|
std::string foundation;
|
|
|
|
std::string priority;
|
|
|
|
std::string ip;
|
|
|
|
std::string type;
|
|
|
|
|
|
|
|
std::string tcpType;
|
|
|
|
std::string relAddr;
|
|
|
|
std::string relPort;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupJoinResponsePayload {
|
|
|
|
std::string ufrag;
|
|
|
|
std::string pwd;
|
|
|
|
std::vector<GroupJoinPayloadFingerprint> fingerprints;
|
|
|
|
std::vector<GroupJoinResponseCandidate> candidates;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class ThreadLocalObject;
|
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
class GroupInstanceInterface {
|
|
|
|
protected:
|
|
|
|
GroupInstanceInterface() = default;
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
public:
|
2021-03-19 11:25:58 +01:00
|
|
|
virtual ~GroupInstanceInterface() = default;
|
|
|
|
|
|
|
|
virtual void stop() = 0;
|
|
|
|
|
|
|
|
virtual void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) = 0;
|
|
|
|
|
|
|
|
virtual void emitJoinPayload(std::function<void(GroupJoinPayload)> completion) = 0;
|
|
|
|
virtual void setJoinResponsePayload(GroupJoinResponsePayload payload, std::vector<tgcalls::GroupParticipantDescription> &&participants) = 0;
|
|
|
|
virtual void addParticipants(std::vector<GroupParticipantDescription> &&participants) = 0;
|
|
|
|
virtual void removeSsrcs(std::vector<uint32_t> ssrcs) = 0;
|
2020-12-23 08:48:30 +01:00
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
virtual void setIsMuted(bool isMuted) = 0;
|
|
|
|
virtual void setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture, std::function<void(GroupJoinPayload)> completion) = 0;
|
|
|
|
virtual void setAudioOutputDevice(std::string id) = 0;
|
|
|
|
virtual void setAudioInputDevice(std::string id) = 0;
|
2020-12-23 08:48:30 +01:00
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
virtual void addIncomingVideoOutput(uint32_t ssrc, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0;
|
2020-12-23 08:48:30 +01:00
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
virtual void setVolume(uint32_t ssrc, double volume) = 0;
|
|
|
|
virtual void setFullSizeVideoSsrc(uint32_t ssrc) = 0;
|
2020-12-23 08:48:30 +01:00
|
|
|
|
|
|
|
struct AudioDevice {
|
|
|
|
enum class Type {Input, Output};
|
|
|
|
std::string name;
|
|
|
|
std::string guid;
|
|
|
|
};
|
2021-04-09 15:17:32 +02:00
|
|
|
static std::vector<GroupInstanceInterface::AudioDevice> getAudioDevices(AudioDevice::Type type);
|
2020-12-23 08:48:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace tgcalls
|
|
|
|
|
|
|
|
#endif
|