Skip to content

Commit

Permalink
Update to 7.6.1 (2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Apr 9, 2021
1 parent ca13bc9 commit 7ba9838
Show file tree
Hide file tree
Showing 86 changed files with 2,794 additions and 939 deletions.
4 changes: 2 additions & 2 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 288,7 @@ android {
}
}

defaultConfig.versionCode = 2264
defaultConfig.versionCode = 2274

applicationVariants.all { variant ->
variant.outputs.all { output ->
Expand All @@ -307,7 307,7 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionName "7.6.0"
versionName "7.6.1"

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

Expand Down
9 changes: 6 additions & 3 deletions TMessagesProj/jni/voip/tgcalls/AudioDeviceHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 49,13 @@ void SetAudioInputDeviceById(webrtc::AudioDeviceModule *adm, const std::string &
RTC_LOG(LS_ERROR) << "setAudioInputDevice(" << id << "): Could not get recording devices count: " << count << ".";
return finish();
}
for (auto i = 0; i != count; i) {

int16_t order = !id.empty() && id[0] == '#' ? static_cast<int16_t>(std::stoi(id.substr(1))) : -1;
for (auto i = 0; i != count; i) {
char name[webrtc::kAdmMaxDeviceNameSize 1] = { 0 };
char guid[webrtc::kAdmMaxGuidSize 1] = { 0 };
adm->RecordingDeviceName(i, name, guid);
if (!SkipDefaultDevice(name) && id == guid) {
if ((!SkipDefaultDevice(name) && id == guid) || order == i) {
const auto result = adm->SetRecordingDevice(i);
if (result != 0) {
RTC_LOG(LS_ERROR) << "setAudioInputDevice(" << id << ") name '" << std::string(name) << "' failed: " << result << ".";
Expand Down Expand Up @@ -95,11 97,12 @@ void SetAudioOutputDeviceById(webrtc::AudioDeviceModule *adm, const std::string
RTC_LOG(LS_ERROR) << "setAudioOutputDevice(" << id << "): Could not get playout devices count: " << count << ".";
return finish();
}
int16_t order = !id.empty() && id[0] == '#' ? static_cast<int16_t>(std::stoi(id.substr(1))) : -1;
for (auto i = 0; i != count; i) {
char name[webrtc::kAdmMaxDeviceNameSize 1] = { 0 };
char guid[webrtc::kAdmMaxGuidSize 1] = { 0 };
adm->PlayoutDeviceName(i, name, guid);
if (!SkipDefaultDevice(name) && id == guid) {
if ((!SkipDefaultDevice(name) && id == guid) || order == i) {
const auto result = adm->SetPlayoutDevice(i);
if (result != 0) {
RTC_LOG(LS_ERROR) << "setAudioOutputDevice(" << id << ") name '" << std::string(name) << "' failed: " << result << ".";
Expand Down
66 changes: 37 additions & 29 deletions TMessagesProj/jni/voip/tgcalls/FakeAudioDeviceModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,8 @@
#include "rtc_base/time_utils.h"

#include <thread>
#include <mutex>
#include <condition_variable>

namespace tgcalls {
class FakeAudioDeviceModuleImpl : public webrtc::webrtc_impl::AudioDeviceModuleDefault<webrtc::AudioDeviceModule> {
Expand All @@ -19,7 21,20 @@ class FakeAudioDeviceModuleImpl : public webrtc::webrtc_impl::AudioDeviceModuleD

FakeAudioDeviceModuleImpl(webrtc::TaskQueueFactory*, FakeAudioDeviceModule::Options options,
std::shared_ptr<FakeAudioDeviceModule::Renderer> renderer)
: num_channels_{options.num_channels}, samples_per_sec_{options.samples_per_sec}, renderer_(std::move(renderer)) {
: num_channels_{options.num_channels}, samples_per_sec_{options.samples_per_sec}, scheduler_(options.scheduler_), renderer_(std::move(renderer)) {
if (!scheduler_) {
scheduler_ = [](auto f) {
std::thread([f = std::move(f)]() {
while (true) {
double wait = f();
if (wait < 0) {
return;
}
std::this_thread::sleep_for(std::chrono::microseconds (static_cast<int64_t>(wait * 1000000)));
}
}).detach();
};
}
RTC_CHECK(num_channels_ == 1 || num_channels_ == 2);
auto good_sample_rate = [](size_t sr) {
return sr == 8000 || sr == 16000 || sr == 32000 || sr == 44100 || sr == 48000;
Expand Down Expand Up @@ -65,38 80,34 @@ class FakeAudioDeviceModuleImpl : public webrtc::webrtc_impl::AudioDeviceModuleD
}

int32_t RegisterAudioCallback(webrtc::AudioTransport* callback) override {
webrtc::MutexLock lock(&lock_);
std::unique_lock<std::mutex> lock(mutex_);
audio_callback_ = callback;
return 0;
}

int32_t StartPlayout() override {
webrtc::MutexLock lock(&lock_);
std::unique_lock<std::mutex> lock(mutex_);
RTC_CHECK(renderer_);
if (rendering_) {
return 0;
}
need_rendering_ = true;
rendering_ = true;
renderThread_ = std::make_unique<rtc::PlatformThread>(
RenderThreadFunction, this, "webrtc_fake_audio_module_capture_thread", rtc::kRealtimePriority);
renderThread_->Start();

scheduler_([this]{
return Render() / 1000000.0;
});
return 0;
}

int32_t StopPlayout() override {
if (!rendering_) {
return 0;
}
decltype(renderThread_) thread;

{
webrtc::MutexLock lock(&lock_);
thread = std::move(renderThread_);
rendering_ = false;
}
need_rendering_ = false;
std::unique_lock<std::mutex> lock(mutex_);
cond_.wait(lock, [this]{ return !rendering_; });

thread->Stop();
return 0;
}

Expand All @@ -105,22 116,15 @@ class FakeAudioDeviceModuleImpl : public webrtc::webrtc_impl::AudioDeviceModuleD
}

private:
static void RenderThreadFunction(void* pThis) {
auto* device = static_cast<FakeAudioDeviceModuleImpl*>(pThis);
while (true) {
int wait_for_us = device->Render();
if (wait_for_us < 0) {
break;
}
std::this_thread::sleep_for(std::chrono::microseconds(wait_for_us));
}
}

int32_t Render() {
webrtc::MutexLock lock(&lock_);
if (!rendering_) {
std::unique_lock<std::mutex> lock(mutex_);
if (!need_rendering_) {
rendering_ = false;
cond_.notify_all();
return -1;
}

size_t samples_out = 0;
int64_t elapsed_time_ms = -1;
int64_t ntp_time_ms = -1;
Expand Down Expand Up @@ -157,13 161,17 @@ class FakeAudioDeviceModuleImpl : public webrtc::webrtc_impl::AudioDeviceModuleD
const uint32_t samples_per_sec_;
size_t samples_per_frame_{0};

mutable webrtc::Mutex lock_;
std::function<void(FakeAudioDeviceModule::Task)> scheduler_;

mutable std::mutex mutex_;
std::atomic<bool> need_rendering_{false};
std::atomic<bool> rendering_{false};
std::condition_variable cond_;
std::unique_ptr<rtc::PlatformThread> renderThread_;

webrtc::AudioTransport* audio_callback_{nullptr};
const std::shared_ptr<FakeAudioDeviceModule::Renderer> renderer_ RTC_GUARDED_BY(lock_);
std::vector<int16_t> playout_buffer_ RTC_GUARDED_BY(lock_);
const std::shared_ptr<FakeAudioDeviceModule::Renderer> renderer_;
std::vector<int16_t> playout_buffer_;
};

std::function<rtc::scoped_refptr<webrtc::AudioDeviceModule>(webrtc::TaskQueueFactory*)> FakeAudioDeviceModule::Creator(
Expand Down
2 changes: 2 additions & 0 deletions TMessagesProj/jni/voip/tgcalls/FakeAudioDeviceModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 32,11 @@ class FakeAudioDeviceModule {
return 10000;
}
};
using Task = std::function<double()>;
struct Options {
uint32_t samples_per_sec{48000};
uint32_t num_channels{2};
std::function<void(Task)> scheduler_;
};
static std::function<rtc::scoped_refptr<webrtc::AudioDeviceModule>(webrtc::TaskQueueFactory *)> Creator(
std::shared_ptr<Renderer> renderer, Options options);
Expand Down
12 changes: 4 additions & 8 deletions TMessagesProj/jni/voip/tgcalls/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 19,14 @@ struct PeerIceParameters {
std::string ufrag;
std::string pwd;

PeerIceParameters() {
}
PeerIceParameters() = default;
PeerIceParameters(const PeerIceParameters &other) = default;

PeerIceParameters(std::string ufrag_, std::string pwd_) :
ufrag(ufrag_),
pwd(pwd_) {
}

PeerIceParameters(const PeerIceParameters &other) :
ufrag(other.ufrag),
pwd(other.pwd) {
}

};

struct CandidatesListMessage {
Expand Down
6 changes: 6 additions & 0 deletions TMessagesProj/jni/voip/tgcalls/StaticThreads.cpp
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
#include "StaticThreads.h"

#include "rtc_base/thread.h"
#include "call/call.h"

#include <mutex>
#include <algorithm>
Expand Down Expand Up @@ -63,6 64,7 @@ class ThreadsImpl : public Threads {
media_ = create("tgc-media" suffix);
worker_ = create("tgc-work" suffix);
process_ = create("tgc-process" suffix);
shared_module_thread_ = webrtc::SharedModuleThread::Create(webrtc::ProcessThread::Create("tgc-module"), nullptr);
}

rtc::Thread *getNetworkThread() override {
Expand All @@ -77,12 79,16 @@ class ThreadsImpl : public Threads {
rtc::Thread *getProcessThread() override {
return process_.get();
}
rtc::scoped_refptr<webrtc::SharedModuleThread> getSharedModuleThread() override {
return shared_module_thread_;
}

private:
Thread network_;
Thread media_;
Thread worker_;
Thread process_;
rtc::scoped_refptr<webrtc::SharedModuleThread> shared_module_thread_;

static Thread create(const std::string &name) {
return init(std::unique_ptr<rtc::Thread>(rtc::Thread::Create()), name);
Expand Down
7 changes: 7 additions & 0 deletions TMessagesProj/jni/voip/tgcalls/StaticThreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,11 @@

namespace rtc {
class Thread;
template <class T>
class scoped_refptr;
}
namespace webrtc {
class SharedModuleThread;
}

namespace tgcalls {
Expand All @@ -16,6 21,7 @@ class Threads {
virtual rtc::Thread *getMediaThread() = 0;
virtual rtc::Thread *getWorkerThread() = 0;
virtual rtc::Thread *getProcessThread() = 0;
virtual rtc::scoped_refptr<webrtc::SharedModuleThread> getSharedModuleThread() = 0;

// it is not possible to decrease pool size
static void setPoolSize(size_t size);
Expand All @@ -27,6 33,7 @@ rtc::Thread *getNetworkThread();
rtc::Thread *getMediaThread();
rtc::Thread *getWorkerThread();
rtc::Thread *getProcessThread();
rtc::scoped_refptr<webrtc::SharedModuleThread> getSharedMoudleThread();
std::shared_ptr<Threads> &getThreads();
}

Expand Down
Loading

0 comments on commit 7ba9838

Please sign in to comment.