mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Temp
This commit is contained in:
@@ -26,8 +26,7 @@ static rtc::Thread *makeMediaThread() {
|
||||
return value.get();
|
||||
}
|
||||
|
||||
|
||||
static rtc::Thread *getMediaThread() {
|
||||
rtc::Thread *Manager::getMediaThread() {
|
||||
static rtc::Thread *value = makeMediaThread();
|
||||
return value;
|
||||
}
|
||||
@@ -38,6 +37,7 @@ Manager::Manager(
|
||||
bool enableP2P,
|
||||
std::vector<TgVoipRtcServer> const &rtcServers,
|
||||
bool isVideo,
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> videoCapture,
|
||||
std::function<void (const TgVoipState &)> stateUpdated,
|
||||
std::function<void (bool)> videoStateUpdated,
|
||||
std::function<void (bool)> remoteVideoIsActiveUpdated,
|
||||
@@ -48,6 +48,7 @@ _encryptionKey(encryptionKey),
|
||||
_enableP2P(enableP2P),
|
||||
_rtcServers(rtcServers),
|
||||
_startWithVideo(isVideo),
|
||||
_videoCapture(videoCapture),
|
||||
_stateUpdated(stateUpdated),
|
||||
_videoStateUpdated(videoStateUpdated),
|
||||
_remoteVideoIsActiveUpdated(remoteVideoIsActiveUpdated),
|
||||
@@ -111,11 +112,12 @@ void Manager::start() {
|
||||
);
|
||||
}));
|
||||
bool isOutgoing = _encryptionKey.isOutgoing;
|
||||
_mediaManager.reset(new ThreadLocalObject<MediaManager>(getMediaThread(), [isOutgoing, thread = _thread, startWithVideo = _startWithVideo, weakThis]() {
|
||||
_mediaManager.reset(new ThreadLocalObject<MediaManager>(getMediaThread(), [isOutgoing, thread = _thread, startWithVideo = _startWithVideo, videoCapture = _videoCapture, weakThis]() {
|
||||
return new MediaManager(
|
||||
getMediaThread(),
|
||||
isOutgoing,
|
||||
startWithVideo,
|
||||
videoCapture,
|
||||
[thread, weakThis](const rtc::CopyOnWriteBuffer &packet) {
|
||||
thread->PostTask(RTC_FROM_HERE, [weakThis, packet]() {
|
||||
auto strongThis = weakThis.lock();
|
||||
|
||||
@@ -12,12 +12,15 @@ namespace TGVOIP_NAMESPACE {
|
||||
|
||||
class Manager : public std::enable_shared_from_this<Manager> {
|
||||
public:
|
||||
static rtc::Thread *getMediaThread();
|
||||
|
||||
Manager(
|
||||
rtc::Thread *thread,
|
||||
TgVoipEncryptionKey encryptionKey,
|
||||
bool enableP2P,
|
||||
std::vector<TgVoipRtcServer> const &rtcServers,
|
||||
bool isVideo,
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> videoCapture,
|
||||
std::function<void (const TgVoipState &)> stateUpdated,
|
||||
std::function<void (bool)> videoStateUpdated,
|
||||
std::function<void (bool)> remoteVideoIsActiveUpdated,
|
||||
@@ -40,6 +43,7 @@ private:
|
||||
bool _enableP2P;
|
||||
std::vector<TgVoipRtcServer> _rtcServers;
|
||||
bool _startWithVideo;
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> _videoCapture;
|
||||
std::function<void (const TgVoipState &)> _stateUpdated;
|
||||
std::function<void (bool)> _videoStateUpdated;
|
||||
std::function<void (bool)> _remoteVideoIsActiveUpdated;
|
||||
|
||||
@@ -164,7 +164,7 @@ static rtc::Thread *makeWorkerThread() {
|
||||
}
|
||||
|
||||
|
||||
static rtc::Thread *getWorkerThread() {
|
||||
static rtc::Thread *MediaManager::getWorkerThread() {
|
||||
static rtc::Thread *value = makeWorkerThread();
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -54,10 +54,13 @@ private:
|
||||
friend class MediaManager::NetworkInterfaceImpl;
|
||||
|
||||
public:
|
||||
static rtc::Thread *getWorkerThread();
|
||||
|
||||
MediaManager(
|
||||
rtc::Thread *thread,
|
||||
bool isOutgoing,
|
||||
bool startWithVideo,
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> videoCapture,
|
||||
std::function<void (const rtc::CopyOnWriteBuffer &)> packetEmitted,
|
||||
std::function<void (bool)> localVideoCaptureActiveUpdated
|
||||
);
|
||||
@@ -99,8 +102,7 @@ private:
|
||||
std::unique_ptr<cricket::VoiceMediaChannel> _audioChannel;
|
||||
std::unique_ptr<cricket::VideoMediaChannel> _videoChannel;
|
||||
std::unique_ptr<webrtc::VideoBitrateAllocatorFactory> _videoBitrateAllocatorFactory;
|
||||
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _nativeVideoSource;
|
||||
std::unique_ptr<VideoCapturerInterface> _videoCapturer;
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> _videoCapture;
|
||||
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _currentIncomingVideoSink;
|
||||
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _currentOutgoingVideoSink;
|
||||
|
||||
|
||||
@@ -129,6 +129,16 @@ struct TgVoipAudioDataCallbacks {
|
||||
std::function<void(int16_t*, size_t)> preprocessed;
|
||||
};
|
||||
|
||||
class TgVoipVideoCaptureInterface {
|
||||
protected:
|
||||
TgVoipVideoCaptureInterface() = default;
|
||||
public:
|
||||
static std::shared_ptr<TgVoipVideoCaptureInterface> makeInstance();
|
||||
|
||||
virtual ~TgVoipVideoCaptureInterface();
|
||||
virtual void setVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0;
|
||||
};
|
||||
|
||||
class TgVoip {
|
||||
protected:
|
||||
TgVoip() = default;
|
||||
@@ -147,6 +157,7 @@ public:
|
||||
TgVoipNetworkType initialNetworkType,
|
||||
TgVoipEncryptionKey const &encryptionKey,
|
||||
bool isVideo,
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> videoCapture,
|
||||
std::function<void(TgVoipState)> stateUpdated,
|
||||
std::function<void(bool)> videoStateUpdated,
|
||||
std::function<void(bool)> remoteVideoIsActiveUpdated,
|
||||
|
||||
@@ -5,10 +5,19 @@
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
#include "Manager.h"
|
||||
#include "MediaManager.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <iostream>
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
#include "CodecsApple.h"
|
||||
|
||||
#else
|
||||
#error "Unsupported platform"
|
||||
#endif
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
@@ -143,6 +152,7 @@ public:
|
||||
TgVoipConfig const &config,
|
||||
TgVoipEncryptionKey const &encryptionKey,
|
||||
bool isVideo,
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> videoCapture,
|
||||
TgVoipNetworkType initialNetworkType,
|
||||
std::function<void(TgVoipState)> stateUpdated,
|
||||
std::function<void(bool)> videoStateUpdated,
|
||||
@@ -160,13 +170,14 @@ public:
|
||||
|
||||
bool enableP2P = config.enableP2P;
|
||||
|
||||
_manager.reset(new ThreadLocalObject<Manager>(getManagerThread(), [encryptionKey = encryptionKey, enableP2P = enableP2P, isVideo, stateUpdated, videoStateUpdated, remoteVideoIsActiveUpdated, signalingDataEmitted, rtcServers](){
|
||||
_manager.reset(new ThreadLocalObject<Manager>(getManagerThread(), [encryptionKey = encryptionKey, enableP2P = enableP2P, isVideo, stateUpdated, videoStateUpdated, remoteVideoIsActiveUpdated, signalingDataEmitted, rtcServers, videoCapture](){
|
||||
return new Manager(
|
||||
getManagerThread(),
|
||||
encryptionKey,
|
||||
enableP2P,
|
||||
rtcServers,
|
||||
isVideo,
|
||||
videoCapture,
|
||||
[stateUpdated](const TgVoipState &state) {
|
||||
stateUpdated(state);
|
||||
},
|
||||
@@ -388,6 +399,7 @@ TgVoip *TgVoip::makeInstance(
|
||||
TgVoipNetworkType initialNetworkType,
|
||||
TgVoipEncryptionKey const &encryptionKey,
|
||||
bool isVideo,
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface> videoCapture,
|
||||
std::function<void(TgVoipState)> stateUpdated,
|
||||
std::function<void(bool)> videoStateUpdated,
|
||||
std::function<void(bool)> remoteVideoIsActiveUpdated,
|
||||
@@ -401,6 +413,7 @@ TgVoip *TgVoip::makeInstance(
|
||||
config,
|
||||
encryptionKey,
|
||||
isVideo,
|
||||
videoCapture,
|
||||
initialNetworkType,
|
||||
stateUpdated,
|
||||
videoStateUpdated,
|
||||
@@ -411,6 +424,78 @@ TgVoip *TgVoip::makeInstance(
|
||||
|
||||
TgVoip::~TgVoip() = default;
|
||||
|
||||
class TgVoipVideoCaptureInterfaceObject {
|
||||
public:
|
||||
TgVoipVideoCaptureInterfaceObject() {
|
||||
_videoSource = makeVideoSource(Manager::getMediaThread(), MediaManager::getWorkerThread());
|
||||
//this should outlive the capturer
|
||||
_videoCapturer = makeVideoCapturer(_videoSource, true, [this](bool isActive) {
|
||||
if (this->_isActiveUpdated) {
|
||||
this->_isActiveUpdated(isActive);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
~TgVoipVideoCaptureInterfaceObject() {
|
||||
if (_currentSink != nullptr) {
|
||||
_videoSource->RemoveSink(_currentSink.get());
|
||||
}
|
||||
}
|
||||
|
||||
void setVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
|
||||
if (_currentSink != nullptr) {
|
||||
_videoSource->RemoveSink(_currentSink.get());
|
||||
}
|
||||
_currentSink = sink;
|
||||
if (_currentSink != nullptr) {
|
||||
_videoSource->AddOrUpdateSink(_currentSink.get(), rtc::VideoSinkWants());
|
||||
}
|
||||
}
|
||||
|
||||
void setIsActiveUpdated(std::function<void (bool)> isActiveUpdated) {
|
||||
_isActiveUpdated = isActiveUpdated;
|
||||
}
|
||||
|
||||
public:
|
||||
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> _videoSource;
|
||||
std::unique_ptr<VideoCapturerInterface> _videoCapturer;
|
||||
|
||||
private:
|
||||
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _currentSink;
|
||||
std::function<void (bool)> _isActiveUpdated;
|
||||
};
|
||||
|
||||
class TgVoipVideoCaptureInterfaceImpl : public TgVoipVideoCaptureInterface {
|
||||
public:
|
||||
TgVoipVideoCaptureInterfaceImpl() {
|
||||
_impl.reset(new ThreadLocalObject<TgVoipVideoCaptureInterfaceObject>(
|
||||
Manager::getMediaThread(),
|
||||
[]() {
|
||||
return new TgVoipVideoCaptureInterfaceObject();
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
virtual ~TgVoipVideoCaptureInterfaceImpl() {
|
||||
|
||||
}
|
||||
|
||||
virtual void setVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
|
||||
_impl->perform([sink](TgVoipVideoCaptureInterfaceObject *impl) {
|
||||
impl->setVideoOutput(sink);
|
||||
});
|
||||
}
|
||||
|
||||
public:
|
||||
std::unique_ptr<ThreadLocalObject<TgVoipVideoCaptureInterfaceObject>> _impl;
|
||||
};
|
||||
|
||||
std::shared_ptr<TgVoipVideoCaptureInterface>TgVoipVideoCaptureInterface::makeInstance() {
|
||||
return std::shared_ptr<TgVoipVideoCaptureInterface>(new TgVoipVideoCaptureInterfaceImpl());
|
||||
}
|
||||
|
||||
TgVoipVideoCaptureInterface::~TgVoipVideoCaptureInterface() = default;
|
||||
|
||||
#ifdef TGVOIP_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user