Skip to content

Commit

Permalink
Merge remote-tracking branch 'official/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jan 1, 2024
2 parents f9f9c14 + a746a07 commit 3a48b5b
Show file tree
Hide file tree
Showing 363 changed files with 26,939 additions and 4,102 deletions.
20 changes: 15 additions & 5 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import cn.hutool.core.util.RuntimeUtil
apply plugin: "com.android.application"
apply plugin: "kotlin-android"

def verName = "10.3.2"
def verCode = 1151
def verName = "10.5.0"
def verCode = 1152


def officialVer = "10.3.2"
def officialCode = 4145
def officialVer = "10.5.0"
def officialCode = 4228

def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")

Expand Down Expand Up @@ -113,7 +113,7 @@ android {
appHash = properties.getProperty("TELEGRAM_APP_HASH") ?: System.getenv("TELEGRAM_APP_HASH") ?: appHash
}


buildConfigField "String", "BUILD_VERSION_STRING", "\"" + verName + "\""
buildConfigField "String", "OFFICIAL_VERSION", "\"" + officialVer + "\""
buildConfigField "int", "OFFICIAL_VERSION_CODE", officialCode + ""
buildConfigField "int", "APP_ID", appId
Expand Down Expand Up @@ -348,6 +348,16 @@ dependencies {
implementation "com.jakewharton:process-phoenix:2.1.2"
implementation 'com.google.guava:guava:31.1-android'

implementation 'com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1'
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
}
}

compileOnly 'org.yaml:snakeyaml:1.29'
fullImplementation 'org.yaml:snakeyaml:1.29'

Expand Down
8 changes: 8 additions & 0 deletions TMessagesProj/jni/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ std::vector<std::pair<float, float>> gatherPositions(std::vector<std::pair<float
}

thread_local static float *pixelCache = nullptr;
thread_local static int pixelCacheSize = 0;

JNIEXPORT void Java_org_telegram_messenger_Utilities_generateGradient(JNIEnv *env, jclass clazz, jobject bitmap, jboolean unpin, jint phase, jfloat progress, jint width, jint height, jint stride, jintArray colors) {
if (!bitmap) {
Expand Down Expand Up @@ -1224,6 +1225,13 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_generateGradient(JNIEnv *en

auto colorsArray = (uint8_t *) env->GetIntArrayElements(colors, nullptr);
float *newPixelCache = nullptr;

if (width * height != pixelCacheSize && pixelCache != nullptr) {
delete[] pixelCache;
pixelCache = nullptr;
}
pixelCacheSize = width * height;

if (pixelCache == nullptr) {
newPixelCache = new float[width * height * 2];
}
Expand Down
30 changes: 10 additions & 20 deletions TMessagesProj/jni/tgnet/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {

buffer->rewind();

NativeByteBuffer *reuseLater = nullptr;
while (buffer->hasRemaining()) {
if (!hasSomeDataSinceLastConnect) {
currentDatacenter->storeCurrentAddressAndPortNum();
Expand Down Expand Up @@ -154,14 +155,11 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {
if ((fByte & (1 << 7)) != 0) {
buffer->position(mark);
if (buffer->remaining() < 4) {
NativeByteBuffer *reuseLater = restOfTheData;
reuseLater = restOfTheData;
restOfTheData = BuffersStorage::getInstance().getFreeBuffer(16384);
restOfTheData->writeBytes(buffer);
restOfTheData->limit(restOfTheData->position());
lastPacketLength = 0;
if (reuseLater != nullptr) {
reuseLater->reuse();
}
break;
}
int32_t ackId = buffer->readBigInt32(nullptr) & (~(1 << 31));
Expand All @@ -175,14 +173,11 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {
buffer->position(mark);
if (buffer->remaining() < 4) {
if (restOfTheData == nullptr || (restOfTheData != nullptr && restOfTheData->position() != 0)) {
NativeByteBuffer *reuseLater = restOfTheData;
reuseLater = restOfTheData;
restOfTheData = BuffersStorage::getInstance().getFreeBuffer(16384);
restOfTheData->writeBytes(buffer);
restOfTheData->limit(restOfTheData->position());
lastPacketLength = 0;
if (reuseLater != nullptr) {
reuseLater->reuse();
}
} else {
restOfTheData->position(restOfTheData->limit());
}
Expand All @@ -195,14 +190,11 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {
} else {
if (buffer->remaining() < 4) {
if (restOfTheData == nullptr || (restOfTheData != nullptr && restOfTheData->position() != 0)) {
NativeByteBuffer *reuseLater = restOfTheData;
reuseLater = restOfTheData;
restOfTheData = BuffersStorage::getInstance().getFreeBuffer(16384);
restOfTheData->writeBytes(buffer);
restOfTheData->limit(restOfTheData->position());
lastPacketLength = 0;
if (reuseLater != nullptr) {
reuseLater->reuse();
}
} else {
restOfTheData->position(restOfTheData->limit());
}
Expand All @@ -223,7 +215,7 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {
if (currentProtocolType != ProtocolTypeDD && currentProtocolType != ProtocolTypeTLS && currentPacketLength % 4 != 0 || currentPacketLength > 2 * 1024 * 1024) {
if (LOGS_ENABLED) DEBUG_D("connection(%p, account%u, dc%u, type %d) received invalid packet length", this, currentDatacenter->instanceNum, currentDatacenter->getDatacenterId(), connectionType);
reconnect();
return;
break;
}

if (currentPacketLength < buffer->remaining()) {
Expand All @@ -233,8 +225,6 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {
} else {
if (LOGS_ENABLED) DEBUG_D("connection(%p, account%u, dc%u, type %d) received packet size less(%u) then message size(%u)", this, currentDatacenter->instanceNum, currentDatacenter->getDatacenterId(), connectionType, buffer->remaining(), currentPacketLength);

NativeByteBuffer *reuseLater = nullptr;

if (restOfTheData != nullptr && restOfTheData->capacity() < len) {
reuseLater = restOfTheData;
restOfTheData = nullptr;
Expand All @@ -248,10 +238,7 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {
restOfTheData->limit(len);
}
lastPacketLength = len;
if (reuseLater != nullptr) {
reuseLater->reuse();
}
return;
break;
}

uint32_t old = buffer->limit();
Expand All @@ -262,7 +249,7 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {

if (restOfTheData != nullptr) {
if ((lastPacketLength != 0 && restOfTheData->position() == lastPacketLength) || (lastPacketLength == 0 && !restOfTheData->hasRemaining())) {
restOfTheData->reuse();
reuseLater = restOfTheData;
restOfTheData = nullptr;
} else {
restOfTheData->compact();
Expand All @@ -276,6 +263,9 @@ void Connection::onReceivedData(NativeByteBuffer *buffer) {
parseLaterBuffer = nullptr;
}
}
if (reuseLater != nullptr) {
reuseLater->reuse();
}
}

void Connection::connect() {
Expand Down
63 changes: 58 additions & 5 deletions TMessagesProj/jni/voip/tgcalls/v2/InstanceV2Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,54 @@ class OutgoingAudioChannel : public sigslot::has_slots<> {
bool _isMuted = true;
};

namespace {
class AudioSinkImpl: public webrtc::AudioSinkInterface {
public:
AudioSinkImpl(std::function<void(float, float)> update) :
_update(update) {
}

virtual ~AudioSinkImpl() {
}

virtual void OnData(const Data& audio) override {
if (_update && audio.channels == 1) {
const int16_t *samples = (const int16_t *)audio.data;
int numberOfSamplesInFrame = (int)audio.samples_per_channel;

int16_t currentPeak = 0;
for (int i = 0; i < numberOfSamplesInFrame; i++) {
int16_t sample = samples[i];
if (sample < 0) {
sample = -sample;
}
if (_peak < sample) {
_peak = sample;
}
if (currentPeak < sample) {
currentPeak = sample;
}
_peakCount += 1;
}

if (_peakCount >= 4400) {
float level = ((float)(_peak)) / 8000.0f;
_peak = 0;
_peakCount = 0;
_update(0, level);
}
}
}

private:
std::function<void(float, float)> _update;

int _peakCount = 0;
uint16_t _peak = 0;
};

}

class IncomingV2AudioChannel : public sigslot::has_slots<> {
public:
IncomingV2AudioChannel(
Expand All @@ -261,6 +309,7 @@ class IncomingV2AudioChannel : public sigslot::has_slots<> {
webrtc::RtpTransport *rtpTransport,
rtc::UniqueRandomIdGenerator *randomIdGenerator,
signaling::MediaContent const &mediaContent,
std::function<void(float, float)> &&onAudioLevelUpdated,
std::shared_ptr<Threads> threads) :
_threads(threads),
_ssrc(mediaContent.ssrc),
Expand All @@ -278,9 +327,7 @@ class IncomingV2AudioChannel : public sigslot::has_slots<> {
_threads->getNetworkThread()->BlockingCall([&]() {
_audioChannel->SetRtpTransport(rtpTransport);
});




std::vector<cricket::AudioCodec> codecs;
for (const auto &payloadType : mediaContent.payloadTypes) {
cricket::AudioCodec codec(payloadType.id, payloadType.name, payloadType.clockrate, 0, payloadType.channels);
Expand Down Expand Up @@ -317,11 +364,14 @@ class IncomingV2AudioChannel : public sigslot::has_slots<> {
streamParams.set_stream_ids({ streamId });
incomingAudioDescription->AddStream(streamParams);

threads->getWorkerThread()->BlockingCall([&]() {
threads->getWorkerThread()->BlockingCall([this, &outgoingAudioDescription, &incomingAudioDescription, onAudioLevelUpdated = std::move(onAudioLevelUpdated), ssrc = mediaContent.ssrc]() {
_audioChannel->SetPayloadTypeDemuxingEnabled(false);
std::string errorDesc;
_audioChannel->SetLocalContent(outgoingAudioDescription.get(), webrtc::SdpType::kOffer, errorDesc);
_audioChannel->SetRemoteContent(incomingAudioDescription.get(), webrtc::SdpType::kAnswer, errorDesc);

std::unique_ptr<AudioSinkImpl> audioLevelSink(new AudioSinkImpl(std::move(onAudioLevelUpdated)));
_audioChannel->media_channel()->SetRawAudioSink(ssrc, std::move(audioLevelSink));
});

outgoingAudioDescription.reset();
Expand Down Expand Up @@ -1101,7 +1151,7 @@ class InstanceV2ImplInternal : public std::enable_shared_from_this<InstanceV2Imp

mediaDeps.adm = _audioDeviceModule;

webrtc:: AudioProcessingBuilder builder;
webrtc::AudioProcessingBuilder builder;
mediaDeps.audio_processing = builder.Create();

_availableVideoFormats = mediaDeps.video_encoder_factory->GetSupportedFormats();
Expand Down Expand Up @@ -1468,6 +1518,9 @@ class InstanceV2ImplInternal : public std::enable_shared_from_this<InstanceV2Imp
_rtpTransport,
_uniqueRandomIdGenerator.get(),
content,
[audioLevelUpdated = _audioLevelUpdated](float myLvl, float level) {
audioLevelUpdated(myLvl, level);
},
_threads
));
}
Expand Down
9 changes: 7 additions & 2 deletions TMessagesProj/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

<uses-sdk tools:overrideLibrary="com.google.mlkit.vision.segmentation.subject"/>

<queries>
<package android:name="com.google.android.apps.maps"/>
<intent>
Expand Down Expand Up @@ -348,6 +350,9 @@
</intent-filter>
<meta-data android:name="android.service.chooser.chooser_target_service" android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="subject_segment" />
</activity>
<activity-alias
android:name="org.telegram.ui.CallsActivity"
Expand Down Expand Up @@ -667,8 +672,8 @@

<!--<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" />-->

<!--<meta-data android:name="com.google.android.gms.car.notification.SmallIcon" android:resource="@drawable/ic_player" />-->
<!--<meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" />-->
<!-- <meta-data android:name="com.google.android.gms.car.notification.SmallIcon" android:resource="@drawable/ic_player" />-->
<!-- <meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" />-->

<!--<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="face,barcode" />-->

Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/src/main/assets/darkblue.attheme
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ chat_searchPanelText=-8796932
chat_inContactIcon=-1
code_comment=-2130706433
chat_outCodeBackground=857487708
chat_inCodeBackground=856033549
chat_inCodeBackground=-1
code_keyword=-27776
code_constant=-27776
code_function=-27776
Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/src/main/assets/night.attheme
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ chat_searchPanelText=-10767620
chat_inContactIcon=-1
code_comment=-2130706433
chat_outCodeBackground=859062986
chat_inCodeBackground=855638016
chat_inCodeBackground=-1
code_keyword=-27776
code_constant=-27776
code_function=-27776
Expand Down
Loading

0 comments on commit 3a48b5b

Please sign in to comment.