Skip to content

Commit

Permalink
Merge remote-tracking branch 'telegram/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Aug 11, 2023
2 parents 535d405 + 0bcf4fe commit 1d357ca
Show file tree
Hide file tree
Showing 1,012 changed files with 97,923 additions and 18,036 deletions.
8 changes: 4 additions & 4 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 = "9.5.8"
def verCode = 1128
def verName = "9.7.6"
def verCode = 1130


def officialVer = "9.5.8"
def officialCode = 3252
def officialVer = "9.7.6"
def officialCode = 3721

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

Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ target_include_directories(breakpad PUBLIC
#voip
include(${CMAKE_HOME_DIRECTORY}/voip/CMakeLists.txt)

set(NATIVE_LIB "tmessages.44")
set(NATIVE_LIB "tmessages.45")

#tmessages
add_library(${NATIVE_LIB} SHARED
Expand Down
41 changes: 25 additions & 16 deletions TMessagesProj/jni/TgNetWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ void cancelRequest(JNIEnv *env, jclass c, jint instanceNum, jint token, jboolean
return ConnectionsManager::getInstance(instanceNum).cancelRequest(token, notifyServer);
}

void failNotRunningRequest(JNIEnv *env, jclass c, jint instanceNum, jint token) {
return ConnectionsManager::getInstance(instanceNum).failNotRunningRequest(token);
}

void cleanUp(JNIEnv *env, jclass c, jint instanceNum, jboolean resetKeys) {
return ConnectionsManager::getInstance(instanceNum).cleanUp(resetKeys, -1);
}
Expand Down Expand Up @@ -230,7 +234,7 @@ void resumeNetwork(JNIEnv *env, jclass c, jint instanceNum, jboolean partial) {
}

void updateDcSettings(JNIEnv *env, jclass c, jint instanceNum) {
ConnectionsManager::getInstance(instanceNum).updateDcSettings(0, false);
ConnectionsManager::getInstance(instanceNum).updateDcSettings(0, false, false);
}

void setIpStrategy(JNIEnv *env, jclass c, jint instanceNum, jbyte value) {
Expand Down Expand Up @@ -405,6 +409,10 @@ onHostNameResolved(JNIEnv *env, jclass c, jstring host, jlong address, jstring i
socket->onHostNameResolved(h, i, ipv6);
}

void discardConnection(JNIEnv *env, jclass c, jint instanceNum, jint datacenerId, jint connectionType) {
ConnectionsManager::getInstance(instanceNum).reconnect(datacenerId, connectionType);
}

void setLangCode(JNIEnv *env, jclass c, jint instanceNum, jstring langCode) {
const char *langCodeStr = env->GetStringUTFChars(langCode, 0);

Expand Down Expand Up @@ -530,21 +538,22 @@ static JNINativeMethod ConnectionsManagerMethods[] = {
{"native_getConnectionState", "(I)I", (void *) getConnectionState},
{"native_setUserId", "(IJ)V", (void *) setUserId},
{"native_init", "(IIIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IJZZII)V", (void *) init},
{"native_setLangCode", "(ILjava/lang/String;)V", (void *) setLangCode},
{"native_setRegId", "(ILjava/lang/String;)V", (void *) setRegId},
{"native_setSystemLangCode", "(ILjava/lang/String;)V", (void *) setSystemLangCode},
{"native_switchBackend", "(IZ)V", (void *) switchBackend},
{"native_pauseNetwork", "(I)V", (void *) pauseNetwork},
{"native_resumeNetwork", "(IZ)V", (void *) resumeNetwork},
{"native_updateDcSettings", "(I)V", (void *) updateDcSettings},
{"native_setIpStrategy", "(IB)V", (void *) setIpStrategy},
{"native_setNetworkAvailable", "(IZIZ)V", (void *) setNetworkAvailable},
{"native_setPushConnectionEnabled", "(IZ)V", (void *) setPushConnectionEnabled},
{"native_setJava", "(Z)V", (void *) setJava},
{"native_setJava", "(I)V", (void *) setJava1},
{"native_applyDnsConfig", "(IJLjava/lang/String;I)V", (void *) applyDnsConfig},
{"native_checkProxy", "(ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/telegram/tgnet/RequestTimeDelegate;)J", (void *) checkProxy},
{"native_onHostNameResolved", "(Ljava/lang/String;JLjava/lang/String;Z)V", (void *) onHostNameResolved}
{"native_setLangCode", "(ILjava/lang/String;)V", (void *) setLangCode},
{"native_setRegId", "(ILjava/lang/String;)V", (void *) setRegId},
{"native_setSystemLangCode", "(ILjava/lang/String;)V", (void *) setSystemLangCode},
{"native_switchBackend", "(IZ)V", (void *) switchBackend},
{"native_pauseNetwork", "(I)V", (void *) pauseNetwork},
{"native_resumeNetwork", "(IZ)V", (void *) resumeNetwork},
{"native_updateDcSettings", "(I)V", (void *) updateDcSettings},
{"native_setIpStrategy", "(IB)V", (void *) setIpStrategy},
{"native_setNetworkAvailable", "(IZIZ)V", (void *) setNetworkAvailable},
{"native_setPushConnectionEnabled", "(IZ)V", (void *) setPushConnectionEnabled},
{"native_setJava", "(Z)V", (void *) setJava},
{"native_applyDnsConfig", "(IJLjava/lang/String;I)V", (void *) applyDnsConfig},
{"native_checkProxy", "(ILjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/telegram/tgnet/RequestTimeDelegate;)J", (void *) checkProxy},
{"native_onHostNameResolved", "(Ljava/lang/String;JLjava/lang/String;Z)V", (void *) onHostNameResolved},
{"native_discardConnection", "(III)V", (void *) discardConnection},
{"native_failNotRunningRequest", "(II)V", (void *) failNotRunningRequest},
};

inline int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Expand Down
1 change: 0 additions & 1 deletion TMessagesProj/jni/ffmpeg
Submodule ffmpeg deleted from 4bc4ca
69 changes: 67 additions & 2 deletions TMessagesProj/jni/gifvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static const std::string av_make_error_str(int errnum) {
jclass jclass_AnimatedFileDrawableStream;
jmethodID jclass_AnimatedFileDrawableStream_read;
jmethodID jclass_AnimatedFileDrawableStream_cancel;
jmethodID jclass_AnimatedFileDrawableStream_isCanceled;
jmethodID jclass_AnimatedFileDrawableStream_isFinishedLoadingFile;
jmethodID jclass_AnimatedFileDrawableStream_getFinishedFilePath;

Expand Down Expand Up @@ -792,7 +793,7 @@ int readCallback(void *opaque, uint8_t *buf, int buf_size) {
javaVm->DetachCurrentThread();
}
if (buf_size == 0) {
return AVERROR_EOF;
return AVERROR_EXIT;
}
int ret = (int) read(info->fd, buf, (size_t) buf_size);
if (ret <= 0) {
Expand Down Expand Up @@ -1035,6 +1036,26 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_telegram_ui_Components_AnimatedFileD
dataArr[2] = 0;
}
dataArr[4] = (int32_t) (info->fmt_ctx->duration * 1000 / AV_TIME_BASE);
int video_stream_index = -1;
double fps = 30.0;
for (int i = 0; i < info->fmt_ctx->nb_streams; i++) {
if (info->fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
video_stream_index = i;
break;
}
}
if (video_stream_index != -1) {
AVStream* video_stream = info->fmt_ctx->streams[video_stream_index];
if (video_stream->avg_frame_rate.den && video_stream->avg_frame_rate.num) {
fps = av_q2d(video_stream->avg_frame_rate);
} else if(video_stream->r_frame_rate.den && video_stream->r_frame_rate.num) {
fps = av_q2d(video_stream->r_frame_rate);
} else {
int ticks = video_stream->codec->ticks_per_frame;
fps = 1.0 / (ticks * av_q2d(video_stream->time_base));
}
}
dataArr[5] = (int32_t) fps;
//(int32_t) (1000 * info->video_stream->duration * av_q2d(info->video_stream->time_base));
env->ReleaseIntArrayElements(data, dataArr, 0);
}
Expand Down Expand Up @@ -1102,7 +1123,7 @@ extern "C" JNIEXPORT void JNICALL Java_org_telegram_ui_Components_AnimatedFileDr
return;
}
int got_frame = 0;
int32_t tries = 1000;
int32_t tries = 100;
while (tries > 0) {
if (info->pkt.size == 0) {
ret = av_read_frame(info->fmt_ctx, &info->pkt);
Expand Down Expand Up @@ -1235,6 +1256,26 @@ extern "C" JNIEXPORT int JNICALL Java_org_telegram_ui_Components_AnimatedFileDra
int32_t tries = 1000;
bool readNextPacket = true;
while (tries > 0) {
if (info->stream != nullptr) {
JNIEnv *jniEnv = nullptr;
JavaVMAttachArgs jvmArgs;
jvmArgs.version = JNI_VERSION_1_6;

bool attached;
if (JNI_EDETACHED == javaVm->GetEnv((void **) &jniEnv, JNI_VERSION_1_6)) {
javaVm->AttachCurrentThread(&jniEnv, &jvmArgs);
attached = true;
} else {
attached = false;
}
jboolean canceled = jniEnv->CallBooleanMethod(info->stream, jclass_AnimatedFileDrawableStream_isCanceled);
if (attached) {
javaVm->DetachCurrentThread();
}
if (canceled) {
return 0;
}
}
if (info->pkt.size == 0 && readNextPacket) {
ret = av_read_frame(info->fmt_ctx, &info->pkt);
if (ret >= 0) {
Expand Down Expand Up @@ -1309,6 +1350,26 @@ extern "C" JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_AnimatedFileDr
int32_t triesCount = preview ? 50 : 6;
//info->has_decoded_frames = false;
while (!info->stopped && triesCount != 0) {
if (info->stream != nullptr) {
JNIEnv *jniEnv = nullptr;
JavaVMAttachArgs jvmArgs;
jvmArgs.version = JNI_VERSION_1_6;

bool attached;
if (JNI_EDETACHED == javaVm->GetEnv((void **) &jniEnv, JNI_VERSION_1_6)) {
javaVm->AttachCurrentThread(&jniEnv, &jvmArgs);
attached = true;
} else {
attached = false;
}
jboolean canceled = jniEnv->CallBooleanMethod(info->stream, jclass_AnimatedFileDrawableStream_isCanceled);
if (attached) {
javaVm->DetachCurrentThread();
}
if (canceled) {
return 0;
}
}
if (info->pkt.size == 0) {
ret = av_read_frame(info->fmt_ctx, &info->pkt);
if (ret >= 0) {
Expand Down Expand Up @@ -1400,6 +1461,10 @@ extern "C" jint videoOnJNILoad(JavaVM *vm, JNIEnv *env) {
if (jclass_AnimatedFileDrawableStream_isFinishedLoadingFile == 0) {
return JNI_FALSE;
}
jclass_AnimatedFileDrawableStream_isCanceled = env->GetMethodID(jclass_AnimatedFileDrawableStream, "isCanceled", "()Z");
if (jclass_AnimatedFileDrawableStream_isCanceled == 0) {
return JNI_FALSE;
}
jclass_AnimatedFileDrawableStream_getFinishedFilePath = env->GetMethodID(jclass_AnimatedFileDrawableStream, "getFinishedFilePath", "()Ljava/lang/String;");
if (jclass_AnimatedFileDrawableStream_getFinishedFilePath == 0) {
return JNI_FALSE;
Expand Down
25 changes: 25 additions & 0 deletions TMessagesProj/jni/lottie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_create(JNIEnv *e
return (jlong) (intptr_t) info;
}

JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_getFramesCount(JNIEnv *env, jclass clazz, jstring src, jstring json) {
auto info = new LottieInfo();
char const *srcString = env->GetStringUTFChars(src, nullptr);
info->path = srcString;
if (json != nullptr) {
char const *jsonString = env->GetStringUTFChars(json, nullptr);
if (jsonString) {
info->animation = rlottie::Animation::loadFromData(jsonString, info->path, nullptr, FitzModifier::None);
env->ReleaseStringUTFChars(json, jsonString);
}
} else {
info->animation = rlottie::Animation::loadFromFile(info->path, nullptr, FitzModifier::None);
}
if (srcString) {
env->ReleaseStringUTFChars(src, srcString);
}
if (info->animation == nullptr) {
delete info;
return 0;
}
long frameCount = info->animation->totalFrame();
delete info;
return (jlong) frameCount;
}

JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_createWithJson(JNIEnv *env, jclass clazz, jstring json, jstring name, jintArray data, jintArray colorReplacement) {
std::map<int32_t, int32_t> *colors = nullptr;
if (colorReplacement != nullptr) {
Expand Down
4 changes: 4 additions & 0 deletions TMessagesProj/jni/tgnet/ApiScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,15 @@ void TL_user::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &er
usernames.push_back(std::unique_ptr<TL_username>(object));
}
}
if ((flags2 & 32) != 0) {
stories_max_id = stream->readInt32(&error);
}
}

void TL_user::serializeToStream(NativeByteBuffer *stream) {
stream->writeInt32(constructor);
stream->writeInt32(flags);
stream->writeInt32(flags2);
stream->writeInt64(id);
if ((flags & 1) != 0) {
stream->writeInt64(access_hash);
Expand Down
3 changes: 2 additions & 1 deletion TMessagesProj/jni/tgnet/ApiScheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class User : public TLObject {
std::string bot_inline_placeholder;
std::string lang_code;
std::vector<std::unique_ptr<TL_username>> usernames;
int32_t stories_max_id;

static User *TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error);
};
Expand All @@ -351,7 +352,7 @@ class TL_userEmpty : public User {
class TL_user : public User {

public:
static const uint32_t constructor = 0x8f97c628;
static const uint32_t constructor = 0xabb5f120;

void readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error);
void serializeToStream(NativeByteBuffer *stream);
Expand Down
Loading

0 comments on commit 1d357ca

Please sign in to comment.