Skip to content

Commit

Permalink
update to 9.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
xaxtix authored and immat0x1 committed Feb 26, 2023
1 parent 317a24e commit 7008f96
Show file tree
Hide file tree
Showing 22 changed files with 261 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class WrappedDtlsSrtpTransport : public webrtc::DtlsSrtpTransport {
return webrtc::DtlsSrtpTransport::SendRtpPacket(packet, options, flags);
}

void ProcessRtpPacket(webrtc::RtpPacketReceived const &packet, bool isUnresolved) {
void ProcessRtpPacket(webrtc::RtpPacketReceived const &packet, bool isUnresolved) override {
_processRtpPacket(packet, isUnresolved);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ std::unique_ptr<webrtc::VideoEncoderFactory> AndroidInterface::makeVideoEncoderF
webrtc::ScopedJavaLocalRef<jclass> factory_class = webrtc::GetClass(env, "org/webrtc/DefaultVideoEncoderFactory");
jmethodID factory_constructor = env->GetMethodID(factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;ZZ)V");
webrtc::ScopedJavaLocalRef<jobject> factory_object(env, env->NewObject(factory_class.obj(), factory_constructor, eglContext, false, true));

return webrtc::JavaToNativeVideoEncoderFactory(env, factory_object.obj());
}

Expand Down
5 changes: 5 additions & 0 deletions TMessagesProj/jni/voip/tgcalls/v2/InstanceV2Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ class InstanceV2ImplInternal : public std::enable_shared_from_this<InstanceV2Imp
"WebRTC-DataChannel-Dcsctp/Enabled/"
"WebRTC-Audio-MinimizeResamplingOnMobile/Enabled/"
"WebRTC-Audio-iOS-Holding/Enabled/"
"WebRTC-IceFieldTrials/skip_relay_to_non_relay_connections:true/"
);
}

Expand Down Expand Up @@ -2146,7 +2147,11 @@ InstanceV2Impl::InstanceV2Impl(Descriptor &&descriptor) {
if (descriptor.config.logPath.data.size() != 0) {
_logSink = std::make_unique<LogSinkImpl>(descriptor.config.logPath);
}
#ifdef DEBUG
rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE);
#else
rtc::LogMessage::LogToDebug(rtc::LS_INFO);
#endif
rtc::LogMessage::SetLogToStderr(false);
if (_logSink) {
rtc::LogMessage::AddLogToStream(_logSink.get(), rtc::LS_INFO);
Expand Down
64 changes: 59 additions & 5 deletions TMessagesProj/jni/voip/tgcalls/v2/ReflectorPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,17 @@ cricket::Connection* ReflectorPort::CreateConnection(const cricket::Candidate& r
if (!SupportsProtocol(remote_candidate.protocol())) {
return nullptr;
}
if (remote_candidate.address().port() != serverId_) {

auto remoteHostname = remote_candidate.address().hostname();
if (remoteHostname.empty()) {
return nullptr;
}
std::ostringstream ipFormat;
ipFormat << "reflector-" << (uint32_t)serverId_ << "-";
if (!absl::StartsWith(remoteHostname, ipFormat.str()) || !absl::EndsWith(remoteHostname, ".reflector")) {
return nullptr;
}
if (remote_candidate.address().port() != server_address_.address.port()) {
return nullptr;
}

Expand Down Expand Up @@ -424,9 +434,44 @@ int ReflectorPort::SendTo(const void* data,
const rtc::PacketOptions& options,
bool payload) {
rtc::CopyOnWriteBuffer targetPeerTag;
uint32_t ipAddress = addr.ip();

auto syntheticHostname = addr.hostname();

uint32_t resolvedPeerTag = 0;
auto resolvedPeerTagIt = resolved_peer_tags_by_hostname_.find(syntheticHostname);
if (resolvedPeerTagIt != resolved_peer_tags_by_hostname_.end()) {
resolvedPeerTag = resolvedPeerTagIt->second;
} else {
std::ostringstream prefixFormat;
prefixFormat << "reflector-" << (uint32_t)serverId_ << "-";
std::string suffixFormat = ".reflector";
if (!absl::StartsWith(syntheticHostname, prefixFormat.str()) || !absl::EndsWith(syntheticHostname, suffixFormat)) {
RTC_LOG(LS_ERROR) << ToString()
<< ": Discarding SendTo request with destination "
<< addr.ToString();

return -1;
}

auto startPosition = prefixFormat.str().size();
auto tagString = syntheticHostname.substr(startPosition, syntheticHostname.size() - suffixFormat.size() - startPosition);

std::stringstream tagStringStream(tagString);
tagStringStream >> resolvedPeerTag;

if (resolvedPeerTag == 0) {
RTC_LOG(LS_ERROR) << ToString()
<< ": Discarding SendTo request with destination "
<< addr.ToString() << " (could not parse peer tag)";

return -1;
}

resolved_peer_tags_by_hostname_.insert(std::make_pair(syntheticHostname, resolvedPeerTag));
}

targetPeerTag.AppendData(peer_tag_.data(), peer_tag_.size() - 4);
targetPeerTag.AppendData((uint8_t *)&ipAddress, 4);
targetPeerTag.AppendData((uint8_t *)&resolvedPeerTag, 4);

rtc::ByteBufferWriter bufferWriter;
bufferWriter.WriteBytes((const char *)targetPeerTag.data(), targetPeerTag.size());
Expand Down Expand Up @@ -505,7 +550,13 @@ bool ReflectorPort::HandleIncomingPacket(rtc::AsyncPacketSocket* socket,
if (state_ != STATE_READY) {
state_ = STATE_READY;

rtc::SocketAddress candidateAddress(randomTag_, serverId_);
RTC_LOG(LS_INFO)
<< ToString()
<< ": REFLECTOR " << server_address_.address.ToString() << " is now ready";

std::ostringstream ipFormat;
ipFormat << "reflector-" << (uint32_t)serverId_ << "-" << randomTag_ << ".reflector";
rtc::SocketAddress candidateAddress(ipFormat.str(), server_address_.address.port());

// For relayed candidate, Base is the candidate itself.
AddAddress(candidateAddress, // Candidate address.
Expand Down Expand Up @@ -545,7 +596,10 @@ bool ReflectorPort::HandleIncomingPacket(rtc::AsyncPacketSocket* socket,
<< ToString()
<< ": Received data packet with invalid size tag";
} else {
rtc::SocketAddress candidateAddress(senderTag, serverId_);
std::ostringstream ipFormat;
ipFormat << "reflector-" << (uint32_t)serverId_ << "-" << senderTag << ".reflector";
rtc::SocketAddress candidateAddress(ipFormat.str(), server_address_.address.port());
candidateAddress.SetResolvedIP(server_address_.address.ipaddr());

DispatchPacket(data + 16 + 4 + 4, dataSize, candidateAddress, cricket::ProtocolType::PROTO_UDP, packet_time_us);
}
Expand Down
2 changes: 2 additions & 0 deletions TMessagesProj/jni/voip/tgcalls/v2/ReflectorPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class ReflectorPort : public cricket::Port {
cricket::ProtocolAddress server_address_;
uint8_t serverId_ = 0;

std::map<std::string, uint32_t> resolved_peer_tags_by_hostname_;

cricket::RelayCredentials credentials_;
AttemptedServerSet attempted_server_addresses_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.telegram.messenger;

import org.telegram.messenger.utils.ImmutableByteArrayOutputStream;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.NativeByteBuffer;
import org.telegram.tgnet.TLObject;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class FileLoadOperation {
long streamOffset;

public static volatile DispatchQueue filesQueue = new DispatchQueue("writeFileQueue");
public static ImmutableByteArrayOutputStream filesQueueByteBuffer;
private boolean forceSmallChunk;

public void setStream(FileLoadOperationStream stream, boolean streamPriority, long streamOffset) {
Expand Down Expand Up @@ -524,18 +526,28 @@ private void addPart(ArrayList<Range> ranges, long start, long end, boolean save
filesQueue.postRunnable(() -> {
long time = System.currentTimeMillis();
try {
if (filePartsStream == null) {
return;
}
int countFinal = rangesFinal.size();
int bufferSize = 4 + 8 * 2 * countFinal;
if (filesQueueByteBuffer == null) {
filesQueueByteBuffer = new ImmutableByteArrayOutputStream(bufferSize);
} else {
filesQueueByteBuffer.reset();
}
filesQueueByteBuffer.writeInt(countFinal);
for (int a = 0; a < countFinal; a++) {
Range rangeFinal = rangesFinal.get(a);
filesQueueByteBuffer.writeLong(rangeFinal.start);
filesQueueByteBuffer.writeLong(rangeFinal.end);
}
synchronized (FileLoadOperation.this) {
if (filePartsStream == null) {
return;
}
filePartsStream.seek(0);
int countFinal = rangesFinal.size();
filePartsStream.writeInt(countFinal);
for (int a = 0; a < countFinal; a++) {
Range rangeFinal = rangesFinal.get(a);
filePartsStream.writeLong(rangeFinal.start);
filePartsStream.writeLong(rangeFinal.end);
}
filePartsStream.write(filesQueueByteBuffer.buf, 0, bufferSize);
}
} catch (Exception e) {
if (AndroidUtilities.isENOSPC(e)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ private void startUploadRequest() {
started = true;
if (stream == null) {
File cacheFile = new File(uploadingFilePath);
if (AndroidUtilities.isInternalUri(Uri.fromFile(cacheFile))) {
throw new FileLog.IgnoreSentException("trying to upload internal file");
}
// if (AndroidUtilities.isInternalUri(Uri.fromFile(cacheFile))) {
// throw new FileLog.IgnoreSentException("trying to upload internal file");
// }
stream = new RandomAccessFile(cacheFile, "r");
boolean isInternalFile = false;
try {
Expand Down
21 changes: 18 additions & 3 deletions TMessagesProj/src/main/java/org/telegram/messenger/LiteMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ public class LiteMode {
public static final int FLAG_AUTOPLAY_VIDEOS = 1024;
public static final int FLAG_AUTOPLAY_GIFS = 2048;

public static final int ENABLED = (
FLAGS_ANIMATED_STICKERS |
FLAGS_ANIMATED_EMOJI |
FLAGS_CHAT |
FLAG_CALLS_ANIMATIONS
);

public static final int PRESET_LOW = 0;
public static final int PRESET_MEDIUM = (
FLAG_ANIMATED_STICKERS_CHAT |
FLAG_ANIMATED_EMOJI_CHAT |
FLAG_CHAT_FORUM_TWOCOLUMN |
FLAGS_ANIMATED_STICKERS |
FLAGS_ANIMATED_EMOJI |
FLAGS_CHAT |
FLAG_CALLS_ANIMATIONS |
FLAG_AUTOPLAY_VIDEOS |
FLAG_AUTOPLAY_GIFS
Expand Down Expand Up @@ -111,6 +118,14 @@ public static void loadPreference() {

final SharedPreferences preferences = MessagesController.getGlobalMainSettings();
if (!preferences.contains("lite_mode")) {
if (preferences.contains("light_mode")) {
boolean prevLiteModeEnabled = (preferences.getInt("light_mode", SharedConfig.getDevicePerformanceClass() == SharedConfig.PERFORMANCE_CLASS_LOW ? 1 : 0) & 1) > 0;
if (prevLiteModeEnabled) {
defaultValue = PRESET_LOW;
} else {
defaultValue = PRESET_HIGH;
}
}
// migrate settings
if (preferences.contains("loopStickers")) {
boolean loopStickers = preferences.getBoolean("loopStickers", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3646,8 +3646,6 @@ public boolean delete() {
AndroidUtilities.runOnUIThread(() -> {
recordStartRunnable = null;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.recordStartError, guid);
NotificationCenter.getInstance(recordingCurrentAccount).postNotificationName(NotificationCenter.audioDidSent, recordingGuid, null, null);

});
return;
}
Expand All @@ -3656,7 +3654,6 @@ public boolean delete() {
AndroidUtilities.runOnUIThread(() -> {
recordStartRunnable = null;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.recordStarted, guid, true);
NotificationCenter.getInstance(recordingCurrentAccount).postNotificationName(NotificationCenter.audioDidSent, recordingGuid, null, null);
});
}, paused ? 500 : 50);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,7 @@ public MessageObject(int accountNum, TLRPC.TL_channelAdminLogEvent event, ArrayL
messageOwner.peer_id.channel_id = chat.id;
messageOwner.unread = false;
MediaController mediaController = MediaController.getInstance();
isOutOwnerCached = null;

if (message instanceof TLRPC.TL_messageEmpty) {
message = null;
Expand Down Expand Up @@ -5565,7 +5566,7 @@ public boolean isOut() {
return messageOwner.out;
}

Boolean isOutOwnerCached;
public Boolean isOutOwnerCached;
public boolean isOutOwner() {
if (preview) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ public static void toggleArchiveHidden() {
}

public static void toggleAutoplayVideo() {
LiteMode.toggleFlag(LiteMode.FLAG_AUTOPLAY_VIDEOS, !isAutoplayVideo());
LiteMode.toggleFlag(LiteMode.FLAG_AUTOPLAY_VIDEOS);
}

public static boolean isSecretMapPreviewSet() {
Expand Down
Loading

0 comments on commit 7008f96

Please sign in to comment.