Skip to content

Commit

Permalink
Update to 3.10.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Aug 20, 2021
1 parent ab221da commit e445788
Show file tree
Hide file tree
Showing 133 changed files with 7,849 additions and 2,177 deletions.
6 changes: 3 additions & 3 deletions TMessagesProj/build.gradle
Expand Up @@ -25,7 +25,7 @@ dependencies {
compileOnly 'org.checkerframework:checker-qual:2.5.2'
compileOnly 'org.checkerframework:checker-compat-qual:2.5.0'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
implementation 'com.google.firebase:firebase-config:21.0.0'
implementation 'com.google.firebase:firebase-config:21.0.1'
implementation 'com.google.firebase:firebase-datatransport:18.0.1'
implementation 'com.google.firebase:firebase-appindexing:20.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
Expand Down Expand Up @@ -299,7 +299,7 @@ android {
}
}

defaultConfig.versionCode = 2390
defaultConfig.versionCode = 2397

applicationVariants.all { variant ->
variant.outputs.all { output ->
Expand All @@ -318,7 +318,7 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionName "7.9.3"
versionName "7.10.0"

vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']

Expand Down
4 changes: 3 additions & 1 deletion TMessagesProj/jni/voip/CMakeLists.txt
Expand Up @@ -918,7 +918,9 @@ add_library(tgcalls STATIC
voip/tgcalls/group/GroupNetworkManager.cpp
voip/tgcalls/group/GroupInstanceCustomImpl.cpp
voip/tgcalls/group/GroupJoinPayloadInternal.cpp
voip/tgcalls/group/StreamingPart.cpp
voip/tgcalls/group/AudioStreamingPart.cpp
voip/tgcalls/group/VideoStreamingPart.cpp
voip/tgcalls/group/StreamingMediaContext.cpp
voip/tgcalls/third-party/json11.cpp

voip/webrtc/rtc_base/async_invoker.cc
Expand Down
69 changes: 53 additions & 16 deletions TMessagesProj/jni/voip/org_telegram_messenger_voip_Instance.cpp
Expand Up @@ -76,10 +76,12 @@ class BroadcastPartTaskJava : public BroadcastPartTask {
public:
BroadcastPartTaskJava(std::shared_ptr<PlatformContext> platformContext,
std::function<void(BroadcastPart &&)> callback,
int64_t timestamp) :
int64_t timestamp, int32_t videoChannel, VideoChannelDescription::Quality quality) :
_platformContext(std::move(platformContext)),
_callback(std::move(callback)),
_timestamp(timestamp) {
_timestamp(timestamp),
_videoChannel(videoChannel),
_quality(quality) {
}

void call(int64_t ts, int64_t responseTs, BroadcastPart::Status status, uint8_t *data, int32_t len) {
Expand All @@ -91,22 +93,37 @@ class BroadcastPartTaskJava : public BroadcastPartTask {
part.responseTimestamp = responseTs / 1000.0;
part.status = status;
if (data != nullptr) {
part.oggData = std::vector<uint8_t>(data, data + len);
part.data = std::vector<uint8_t>(data, data + len);
}
_callback(std::move<>(part));
}

bool isValidTaskFor(int64_t timestamp, int32_t videoChannel, VideoChannelDescription::Quality quality) {
return _timestamp == timestamp && _videoChannel == videoChannel && _quality == quality;
}

private:
void cancel() override {
tgvoip::jni::DoWithJNI([&](JNIEnv *env) {
jobject globalRef = ((AndroidContext *) _platformContext.get())->getJavaInstance();
env->CallVoidMethod(globalRef, env->GetMethodID(NativeInstanceClass, "onCancelRequestBroadcastPart", "(J)V"), _timestamp);
auto context = (AndroidContext *) _platformContext.get();
jobject globalRef = context->getJavaInstance();
env->CallVoidMethod(globalRef, env->GetMethodID(NativeInstanceClass, "onCancelRequestBroadcastPart", "(JII)V"), _timestamp, _videoChannel, (jint) _quality);
if (_videoChannel != 0) {
for (auto videoTaskIter = context->videoStreamTasks.begin(); videoTaskIter != context->videoStreamTasks.end(); videoTaskIter++) {
if (((BroadcastPartTaskJava *) videoTaskIter->get())->isValidTaskFor(_timestamp, _videoChannel, _quality)) {
context->videoStreamTasks.erase(videoTaskIter);
break;
}
}
}
});
}

std::shared_ptr<PlatformContext> _platformContext;
std::function<void(BroadcastPart &&)> _callback;
int64_t _timestamp;
int32_t _videoChannel;
VideoChannelDescription::Quality _quality;
};

class JavaObject {
Expand Down Expand Up @@ -399,12 +416,21 @@ JNIEXPORT jlong JNICALL Java_org_telegram_messenger_voip_NativeInstance_makeGrou
.platformContext = platformContext
};
if (!screencast) {
descriptor.requestBroadcastPart = [](std::shared_ptr<PlatformContext> platformContext, int64_t timestamp, int64_t duration, std::function<void(BroadcastPart &&)> callback) -> std::shared_ptr<BroadcastPartTask> {
std::shared_ptr<BroadcastPartTask> task = std::make_shared<BroadcastPartTaskJava>(platformContext, callback, timestamp);
((AndroidContext *) platformContext.get())->streamTask = task;
descriptor.requestAudioBroadcastPart = [](std::shared_ptr<PlatformContext> platformContext, int64_t timestamp, int64_t duration, std::function<void(BroadcastPart &&)> callback) -> std::shared_ptr<BroadcastPartTask> {
std::shared_ptr<BroadcastPartTask> task = std::make_shared<BroadcastPartTaskJava>(platformContext, callback, timestamp, 0, VideoChannelDescription::Quality::Full);
((AndroidContext *) platformContext.get())->audioStreamTask = task;
tgvoip::jni::DoWithJNI([platformContext, timestamp, duration, task](JNIEnv *env) {
jobject globalRef = ((AndroidContext *) platformContext.get())->getJavaInstance();
env->CallVoidMethod(globalRef, env->GetMethodID(NativeInstanceClass, "onRequestBroadcastPart", "(JJ)V"), timestamp, duration);
env->CallVoidMethod(globalRef, env->GetMethodID(NativeInstanceClass, "onRequestBroadcastPart", "(JJII)V"), timestamp, duration, 0, 0);
});
return task;
};
descriptor.requestVideoBroadcastPart = [](std::shared_ptr<PlatformContext> platformContext, int64_t timestamp, int64_t duration, int32_t video_channel, VideoChannelDescription::Quality quality, std::function<void(BroadcastPart &&)> callback) -> std::shared_ptr<BroadcastPartTask> {
std::shared_ptr<BroadcastPartTask> task = std::make_shared<BroadcastPartTaskJava>(platformContext, callback, timestamp, video_channel, quality);
((AndroidContext *) platformContext.get())->videoStreamTasks.push_back(task);
tgvoip::jni::DoWithJNI([platformContext, timestamp, duration, task, video_channel, quality](JNIEnv *env) {
jobject globalRef = ((AndroidContext *) platformContext.get())->getJavaInstance();
env->CallVoidMethod(globalRef, env->GetMethodID(NativeInstanceClass, "onRequestBroadcastPart", "(JJII)V"), timestamp, duration, video_channel, (jint) quality);
});
return task;
};
Expand Down Expand Up @@ -812,20 +838,31 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_stopGroup
delete instance;
}

JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_onStreamPartAvailable(JNIEnv *env, jobject obj, jlong ts, jobject byteBuffer, jint size, jlong responseTs) {
JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_onStreamPartAvailable(JNIEnv *env, jobject obj, jlong ts, jobject byteBuffer, jint size, jlong responseTs, jint videoChannel, jint quality) {
InstanceHolder *instance = getInstanceHolder(env, obj);
if (instance->groupNativeInstance == nullptr) {
return;
}
auto context = (AndroidContext *) instance->_platformContext.get();
std::shared_ptr<BroadcastPartTask> streamTask = context->streamTask;
auto task = (BroadcastPartTaskJava *) streamTask.get();
std::shared_ptr<BroadcastPartTask> task;
if (videoChannel != 0) {
auto q = (VideoChannelDescription::Quality) quality;
for (auto videoTaskIter = context->videoStreamTasks.begin(); videoTaskIter != context->videoStreamTasks.end(); videoTaskIter++) {
if (((BroadcastPartTaskJava *) videoTaskIter->get())->isValidTaskFor(ts, videoChannel, q)) {
task = *videoTaskIter;
context->videoStreamTasks.erase(videoTaskIter);
break;
}
}
} else {
task = context->audioStreamTask;
}
if (task != nullptr) {
if (byteBuffer != nullptr) {
auto buf = (uint8_t *) env->GetDirectBufferAddress(byteBuffer);
task->call(ts, responseTs, BroadcastPart::Status::Success, buf, size);
((BroadcastPartTaskJava *) task.get())->call(ts, responseTs, BroadcastPart::Status::Success, buf, size);
} else {
task->call(ts, responseTs, size == 0 ? BroadcastPart::Status::NotReady : BroadcastPart::Status::ResyncNeeded, nullptr, 0);
((BroadcastPartTaskJava *) task.get())->call(ts, responseTs, size == 0 ? BroadcastPart::Status::NotReady : BroadcastPart::Status::ResyncNeeded, nullptr, 0);
}
}
}
Expand Down Expand Up @@ -886,7 +923,7 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_destroyVi

JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_switchCameraCapturer(JNIEnv *env, jclass clazz, jlong videoCapturer, jboolean front) {
auto capturer = reinterpret_cast<VideoCaptureInterface *>(videoCapturer);
capturer->switchToDevice(front ? "front" : "back");
capturer->switchToDevice(front ? "front" : "back", false);
}

JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_setVideoStateCapturer(JNIEnv *env, jclass clazz, jlong videoCapturer, jint videoState) {
Expand All @@ -899,7 +936,7 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_switchCam
if (instance->_videoCapture == nullptr) {
return;
}
instance->_videoCapture->switchToDevice(front ? "front" : "back");
instance->_videoCapture->switchToDevice(front ? "front" : "back", false);
}

JNIEXPORT jboolean JNICALL Java_org_telegram_messenger_voip_NativeInstance_hasVideoCapturer(JNIEnv *env, jobject obj) {
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/jni/voip/tgcalls/Instance.h
Expand Up @@ -204,6 +204,7 @@ class Instance {

virtual void receiveSignalingData(const std::vector<uint8_t> &data) = 0;
virtual void setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture) = 0;
virtual void sendVideoDeviceUpdated() = 0;
virtual void setRequestedVideoAspect(float aspect) = 0;

virtual void stop(std::function<void(FinalState)> completion) = 0;
Expand Down
6 changes: 6 additions & 0 deletions TMessagesProj/jni/voip/tgcalls/InstanceImpl.cpp
Expand Up @@ -58,6 +58,12 @@ void InstanceImpl::setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoC
});
}

void InstanceImpl::sendVideoDeviceUpdated() {
_manager->perform(RTC_FROM_HERE, [](Manager *manager) {
manager->sendVideoDeviceUpdated();
});
}

void InstanceImpl::setRequestedVideoAspect(float aspect) {
_manager->perform(RTC_FROM_HERE, [aspect](Manager *manager) {
manager->setRequestedVideoAspect(aspect);
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/jni/voip/tgcalls/InstanceImpl.h
Expand Up @@ -21,6 +21,7 @@ class InstanceImpl final : public Instance {

void receiveSignalingData(const std::vector<uint8_t> &data) override;
void setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture) override;
void sendVideoDeviceUpdated() override;
void setRequestedVideoAspect(float aspect) override;
void setNetworkType(NetworkType networkType) override;
void setMuteMicrophone(bool muteMicrophone) override;
Expand Down
6 changes: 6 additions & 0 deletions TMessagesProj/jni/voip/tgcalls/Manager.cpp
Expand Up @@ -316,6 +316,12 @@ void Manager::setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCaptur
});
}

void Manager::sendVideoDeviceUpdated() {
_mediaManager->perform(RTC_FROM_HERE, [](MediaManager *mediaManager) {
mediaManager->sendVideoDeviceUpdated();
});
}

void Manager::setRequestedVideoAspect(float aspect) {
_mediaManager->perform(RTC_FROM_HERE, [aspect](MediaManager *mediaManager) {
mediaManager->setRequestedVideoAspect(aspect);
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/jni/voip/tgcalls/Manager.h
Expand Up @@ -29,6 +29,7 @@ class Manager final : public std::enable_shared_from_this<Manager> {
void start();
void receiveSignalingData(const std::vector<uint8_t> &data);
void setVideoCapture(std::shared_ptr<VideoCaptureInterface> videoCapture);
void sendVideoDeviceUpdated();
void setRequestedVideoAspect(float aspect);
void setMuteOutgoingAudio(bool mute);
void setIncomingVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
Expand Down
35 changes: 24 additions & 11 deletions TMessagesProj/jni/voip/tgcalls/MediaManager.cpp
Expand Up @@ -641,17 +641,18 @@ void MediaManager::setSendVideo(std::shared_ptr<VideoCaptureInterface> videoCapt
_videoCapture = videoCapture;
if (_videoCapture) {
_videoCapture->setPreferredAspectRatio(_preferredAspectRatio);
_isScreenCapture = _videoCapture->isScreenCapture();

const auto thread = _thread;
const auto weak = std::weak_ptr<MediaManager>(shared_from_this());
GetVideoCaptureAssumingSameThread(_videoCapture.get())->setStateUpdated([=](VideoState state) {
thread->PostTask(RTC_FROM_HERE, [=] {
if (const auto strong = weak.lock()) {
strong->setOutgoingVideoState(state);
}
});
});

const auto thread = _thread;
const auto weak = std::weak_ptr<MediaManager>(shared_from_this());
const auto object = GetVideoCaptureAssumingSameThread(_videoCapture.get());
_isScreenCapture = object->isScreenCapture();
object->setStateUpdated([=](VideoState state) {
thread->PostTask(RTC_FROM_HERE, [=] {
if (const auto strong = weak.lock()) {
strong->setOutgoingVideoState(state);
}
});
});
setOutgoingVideoState(VideoState::Active);
} else {
_isScreenCapture = false;
Expand Down Expand Up @@ -681,6 +682,18 @@ void MediaManager::setSendVideo(std::shared_ptr<VideoCaptureInterface> videoCapt
checkIsReceivingVideoChanged(wasReceiving);
}

void MediaManager::sendVideoDeviceUpdated() {
if (!computeIsSendingVideo()) {
return;
}
const auto wasScreenCapture = _isScreenCapture;
const auto object = GetVideoCaptureAssumingSameThread(_videoCapture.get());
_isScreenCapture = object->isScreenCapture();
if (_isScreenCapture != wasScreenCapture) {
adjustBitratePreferences(true);
}
}

void MediaManager::setRequestedVideoAspect(float aspect) {
if (_localPreferredVideoAspectRatio != aspect) {
_localPreferredVideoAspectRatio = aspect;
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/jni/voip/tgcalls/MediaManager.h
Expand Up @@ -58,6 +58,7 @@ class MediaManager : public sigslot::has_slots<>, public std::enable_shared_from
void setIsConnected(bool isConnected);
void notifyPacketSent(const rtc::SentPacket &sentPacket);
void setSendVideo(std::shared_ptr<VideoCaptureInterface> videoCapture);
void sendVideoDeviceUpdated();
void setRequestedVideoAspect(float aspect);
void setMuteOutgoingAudio(bool mute);
void setIncomingVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
Expand Down
3 changes: 1 addition & 2 deletions TMessagesProj/jni/voip/tgcalls/VideoCaptureInterface.h
Expand Up @@ -39,8 +39,7 @@ class VideoCaptureInterface {

virtual ~VideoCaptureInterface();

virtual bool isScreenCapture() = 0;
virtual void switchToDevice(std::string deviceId) = 0;
virtual void switchToDevice(std::string deviceId, bool isScreenCapture) = 0;
virtual void setState(VideoState state) = 0;
virtual void setPreferredAspectRatio(float aspectRatio) = 0;
virtual void setOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0;
Expand Down
35 changes: 18 additions & 17 deletions TMessagesProj/jni/voip/tgcalls/VideoCaptureInterfaceImpl.cpp
Expand Up @@ -9,11 +9,11 @@

namespace tgcalls {

VideoCaptureInterfaceObject::VideoCaptureInterfaceObject(std::string deviceId, std::shared_ptr<PlatformContext> platformContext, Threads &threads)
: _videoSource(PlatformInterface::SharedInstance()->makeVideoSource(threads.getMediaThread(), threads.getWorkerThread(), deviceId == "screen")) {
VideoCaptureInterfaceObject::VideoCaptureInterfaceObject(std::string deviceId, bool isScreenCapture, std::shared_ptr<PlatformContext> platformContext, Threads &threads)
: _videoSource(PlatformInterface::SharedInstance()->makeVideoSource(threads.getMediaThread(), threads.getWorkerThread(), isScreenCapture)) {
_platformContext = platformContext;
switchToDevice(deviceId);

switchToDevice(deviceId, isScreenCapture);
}

VideoCaptureInterfaceObject::~VideoCaptureInterfaceObject() {
Expand All @@ -34,13 +34,18 @@ int VideoCaptureInterfaceObject::getRotation() {
}
}

void VideoCaptureInterfaceObject::switchToDevice(std::string deviceId) {
if (_videoCapturer && _currentUncroppedSink != nullptr) {
bool VideoCaptureInterfaceObject::isScreenCapture() {
return _isScreenCapture;
}

void VideoCaptureInterfaceObject::switchToDevice(std::string deviceId, bool isScreenCapture) {
if (_videoCapturer) {
_videoCapturer->setUncroppedOutput(nullptr);
}
_isScreenCapture = isScreenCapture;
if (_videoSource) {
//this should outlive the capturer
_videoCapturer = NULL;
_videoCapturer = nullptr;
_videoCapturer = PlatformInterface::SharedInstance()->makeVideoCapturer(_videoSource, deviceId, [this](VideoState state) {
if (this->_stateUpdated) {
this->_stateUpdated(state);
Expand Down Expand Up @@ -164,23 +169,19 @@ void VideoCaptureInterfaceObject::setRotationUpdated(std::function<void(int)> ro

VideoCaptureInterfaceImpl::VideoCaptureInterfaceImpl(std::string deviceId, bool isScreenCapture, std::shared_ptr<PlatformContext> platformContext, std::shared_ptr<Threads> threads) :
_platformContext(platformContext),
_impl(threads->getMediaThread(), [deviceId, platformContext, threads]() {
return new VideoCaptureInterfaceObject(deviceId, platformContext, *threads);
}), _isScreenCapture(isScreenCapture) {
_impl(threads->getMediaThread(), [deviceId, isScreenCapture, platformContext, threads]() {
return new VideoCaptureInterfaceObject(deviceId, isScreenCapture, platformContext, *threads);
}) {
}

VideoCaptureInterfaceImpl::~VideoCaptureInterfaceImpl() = default;

void VideoCaptureInterfaceImpl::switchToDevice(std::string deviceId) {
_impl.perform(RTC_FROM_HERE, [deviceId](VideoCaptureInterfaceObject *impl) {
impl->switchToDevice(deviceId);
void VideoCaptureInterfaceImpl::switchToDevice(std::string deviceId, bool isScreenCapture) {
_impl.perform(RTC_FROM_HERE, [deviceId, isScreenCapture](VideoCaptureInterfaceObject *impl) {
impl->switchToDevice(deviceId, isScreenCapture);
});
}

bool VideoCaptureInterfaceImpl::isScreenCapture() {
return _isScreenCapture;
}

void VideoCaptureInterfaceImpl::withNativeImplementation(std::function<void(void *)> completion) {
_impl.perform(RTC_FROM_HERE, [completion](VideoCaptureInterfaceObject *impl) {
impl->withNativeImplementation(completion);
Expand Down

1 comment on commit e445788

@AlexandrKozlovskiy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DrKLO Why do you not pay attention in pr #1640? In this pr i fixed several accessibility bugs?

Please sign in to comment.