Skip to content

Commit

Permalink
update to 9.7.6 (3721)
Browse files Browse the repository at this point in the history
  • Loading branch information
xaxtix committed Aug 5, 2023
1 parent 6c1e8c1 commit 0bcf4fe
Show file tree
Hide file tree
Showing 62 changed files with 1,589 additions and 662 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,25 @@ public boolean updateQueuedPeriods(
newPeriodInfo.copyWithRequestedContentPositionUs(
oldPeriodInfo.requestedContentPositionUs);

if (!areDurationsCompatible(oldPeriodInfo.durationUs, newPeriodInfo.durationUs)) {
// The period duration changed. Remove all subsequent periods and check whether we read
// beyond the new duration.
periodHolder.updateClipping();
long newDurationInRendererTime =
newPeriodInfo.durationUs == C.TIME_UNSET
? Long.MAX_VALUE
: periodHolder.toRendererTime(newPeriodInfo.durationUs);
boolean isReadingAndReadBeyondNewDuration =
periodHolder == reading
&& !periodHolder.info.isFollowedByTransitionToSameStream
&& (maxRendererReadPositionUs == C.TIME_END_OF_SOURCE
|| maxRendererReadPositionUs >= newDurationInRendererTime);
boolean readingPeriodRemoved = removeAfter(periodHolder);
return !readingPeriodRemoved && !isReadingAndReadBeyondNewDuration;
}
//@xaxtix
//comment cause lead to infinit seek loop in end of video

// if (!areDurationsCompatible(oldPeriodInfo.durationUs, newPeriodInfo.durationUs)) {
// // The period duration changed. Remove all subsequent periods and check whether we read
// // beyond the new duration.
// periodHolder.updateClipping();
// long newDurationInRendererTime =
// newPeriodInfo.durationUs == C.TIME_UNSET
// ? Long.MAX_VALUE
// : periodHolder.toRendererTime(newPeriodInfo.durationUs);
// boolean isReadingAndReadBeyondNewDuration =
// periodHolder == reading
// && !periodHolder.info.isFollowedByTransitionToSameStream
// && (maxRendererReadPositionUs == C.TIME_END_OF_SOURCE
// || maxRendererReadPositionUs >= newDurationInRendererTime);
// boolean readingPeriodRemoved = removeAfter(periodHolder);
// return !readingPeriodRemoved && !isReadingAndReadBeyondNewDuration;
// }

previousPeriodHolder = periodHolder;
periodHolder = periodHolder.getNext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ public void experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled(boole
@Override
public MediaCodecAdapter createAdapter(MediaCodecAdapter.Configuration configuration)
throws IOException {
// if (Util.SDK_INT >= 23
// && (asynchronousMode == MODE_ENABLED
// || (asynchronousMode == MODE_DEFAULT && Util.SDK_INT >= 31))) {
// int trackType = MimeTypes.getTrackType(configuration.format.sampleMimeType);
// Log.i(
// TAG,
// "Creating an asynchronous MediaCodec adapter for track type "
// + Util.getTrackTypeString(trackType));
// AsynchronousMediaCodecAdapter.Factory factory =
// new AsynchronousMediaCodecAdapter.Factory(
// trackType, enableSynchronizeCodecInteractionsWithQueueing);
// return factory.createAdapter(configuration);
// }
if (Util.SDK_INT >= 23
&& (asynchronousMode == MODE_ENABLED
|| (asynchronousMode == MODE_DEFAULT && Util.SDK_INT >= 31))) {
int trackType = MimeTypes.getTrackType(configuration.format.sampleMimeType);
Log.i(
TAG,
"Creating an asynchronous MediaCodec adapter for track type "
+ Util.getTrackTypeString(trackType));
AsynchronousMediaCodecAdapter.Factory factory =
new AsynchronousMediaCodecAdapter.Factory(
trackType, enableSynchronizeCodecInteractionsWithQueueing);
return factory.createAdapter(configuration);
}
return new SynchronousMediaCodecAdapter.Factory().createAdapter(configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.IDN;
Expand Down Expand Up @@ -247,9 +248,6 @@ public class AndroidUtilities {
private static int adjustOwnerClassGuid = 0;
private static int altFocusableClassGuid = 0;

private static Paint roundPaint;
private static RectF bitmapRect;

public static final RectF rectTmp = new RectF();
public static final Rect rectTmp2 = new Rect();

Expand Down Expand Up @@ -513,9 +511,17 @@ public static void recycleBitmaps(List<Bitmap> bitmapToRecycle) {
return;
}
if (bitmapToRecycle != null && !bitmapToRecycle.isEmpty()) {
ArrayList<WeakReference<Bitmap>> bitmapsToRecycleRef = new ArrayList<>();
for (int i = 0; i < bitmapToRecycle.size(); i++) {
Bitmap bitmap = bitmapToRecycle.get(i);
if (bitmap != null && !bitmap.isRecycled()) {
bitmapsToRecycleRef.add(new WeakReference<>(bitmap));
}
}
AndroidUtilities.runOnUIThread(() -> Utilities.globalQueue.postRunnable(() -> {
for (int i = 0; i < bitmapToRecycle.size(); i++) {
Bitmap bitmap = bitmapToRecycle.get(i);
for (int i = 0; i < bitmapsToRecycleRef.size(); i++) {
Bitmap bitmap = bitmapsToRecycleRef.get(i).get();
bitmapsToRecycleRef.get(i).clear();
if (bitmap != null && !bitmap.isRecycled()) {
try {
bitmap.recycle();
Expand Down Expand Up @@ -3202,10 +3208,10 @@ public static File generateVideoPath(boolean secretChat) {
}

public static String formatFileSize(long size) {
return formatFileSize(size, false);
return formatFileSize(size, false, false);
}

public static String formatFileSize(long size, boolean removeZero) {
public static String formatFileSize(long size, boolean removeZero, boolean makeShort) {
if (size == 0) {
return String.format("%d KB", 0);
} else if (size < 1024) {
Expand All @@ -3228,6 +3234,8 @@ public static String formatFileSize(long size, boolean removeZero) {
float value = (int) (size / 1024L / 1024L) / 1000.0f;
if (removeZero && (value - (int) value) * 10 == 0) {
return String.format("%d GB", (int) value);
} else if (makeShort) {
return String.format("%.1f GB", value);
} else {
return String.format("%.2f GB", value);
}
Expand Down Expand Up @@ -5370,10 +5378,12 @@ public static ByteBuffer cloneByteBuffer(ByteBuffer original) {
System.gc();
clone = ByteBuffer.allocate(original.capacity());
}
int position = original.position();
original.rewind();
clone.put(original);
original.rewind();
clone.flip();
clone.position(position);
return clone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class BuildVars {
public static boolean USE_CLOUD_STRINGS = true;
public static boolean CHECK_UPDATES = true;
public static boolean NO_SCOPED_STORAGE = Build.VERSION.SDK_INT <= 29;
public static int BUILD_VERSION = 3712;
public static String BUILD_VERSION_STRING = "9.7.4";
public static int BUILD_VERSION = 3721;
public static String BUILD_VERSION_STRING = "9.7.6";
public static int APP_ID = 4;
public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.telegram.messenger;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;

public class ChatMessageSharedResources {

public Context context;
public Drawable chat_msgAvatarLiveLocationDrawable;
public Drawable chat_redLocationIcon;

public ChatMessageSharedResources(Context context) {
this.context = context;
}

public Drawable getRedLocationIcon() {
if (chat_redLocationIcon == null) {
Resources resources = context.getResources();
chat_redLocationIcon = resources.getDrawable(R.drawable.map_pin).mutate();
}
return chat_redLocationIcon;
}

public Drawable getAvatarLiveLocation() {
if (chat_msgAvatarLiveLocationDrawable == null) {
Resources resources = context.getResources();
chat_msgAvatarLiveLocationDrawable = resources.getDrawable(R.drawable.livepin).mutate();
}
return chat_msgAvatarLiveLocationDrawable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DispatchQueue extends Thread {
private long lastTaskTime;
private static int indexPointer = 0;
public final int index = indexPointer++;
private int priority = THREAD_PRIORITY_DEFAULT;
private int threadPriority = THREAD_PRIORITY_DEFAULT;

public DispatchQueue(final String threadName) {
this(threadName, true);
Expand All @@ -39,7 +39,7 @@ public DispatchQueue(final String threadName, boolean start) {
}

public DispatchQueue(final String threadName, boolean start, int priority) {
this.priority = priority;
this.threadPriority = priority;
setName(threadName);
if (start) {
start();
Expand Down Expand Up @@ -126,8 +126,8 @@ public void run() {
return true;
});
syncLatch.countDown();
if (priority != THREAD_PRIORITY_DEFAULT) {
Process.setThreadPriority(priority);
if (threadPriority != THREAD_PRIORITY_DEFAULT) {
Process.setThreadPriority(threadPriority);
}
Looper.loop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,12 @@ protected long[] getDownloadedLengthFromOffset(final long offset, final long len
final CountDownLatch countDownLatch = new CountDownLatch(1);
final long[] result = new long[2];
Utilities.stageQueue.postRunnable(() -> {
result[0] = getDownloadedLengthFromOffsetInternal(notLoadedBytesRanges, offset, length);
try {
result[0] = getDownloadedLengthFromOffsetInternal(notLoadedBytesRanges, offset, length);
} catch (Throwable e) {
FileLog.e(e);
result[0] = 0;
}
if (state == stateFinished) {
result[1] = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private static void checkGson() {
privateFields.add("networkType");
privateFields.add("disableFree");
privateFields.add("mContext");
privateFields.add("priority");

//exclude file loading
excludeRequests = new HashSet<>();
Expand All @@ -183,7 +184,7 @@ public boolean shouldSkipField(FieldAttributes f) {

@Override
public boolean shouldSkipClass(Class<?> clazz) {
return clazz.isInstance(AnimatedFileDrawable.class) || clazz.isInstance(ColorStateList.class) || clazz.isInstance(Context.class);
return clazz.isInstance(DispatchQueue.class) || clazz.isInstance(AnimatedFileDrawable.class) || clazz.isInstance(ColorStateList.class) || clazz.isInstance(Context.class);
}
};
gson = new GsonBuilder().addSerializationExclusionStrategy(strategy).registerTypeAdapterFactory(RuntimeClassNameTypeAdapterFactory.of(TLObject.class, "type_", strategy)).create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static int getStreamPrioriy(TLRPC.Document document) {
@Override
public long open(DataSpec dataSpec) throws IOException {
uri = dataSpec.uri;
transferInitializing(dataSpec);
currentAccount = Utilities.parseInt(uri.getQueryParameter("account"));
parentObject = FileLoader.getInstance(currentAccount).getParentObject(Utilities.parseInt(uri.getQueryParameter("rid")));
document = new TLRPC.TL_document();
Expand Down Expand Up @@ -124,6 +125,7 @@ public int read(byte[] buffer, int offset, int readLength) throws IOException {
return C.RESULT_END_OF_INPUT;
} else {
int availableLength = 0;
int bytesRead;
try {
if (bytesRemaining < readLength) {
readLength = (int) bytesRemaining;
Expand Down Expand Up @@ -165,14 +167,16 @@ public int read(byte[] buffer, int offset, int readLength) throws IOException {
if (!opened) {
return 0;
}
file.readFully(buffer, offset, availableLength);
currentOffset += availableLength;
bytesRemaining -= availableLength;
bytesTransferred(availableLength);
bytesRead = file.read(buffer, offset, availableLength);
if (bytesRead > 0) {
currentOffset += bytesRead;
bytesRemaining -= bytesRead;
bytesTransferred(bytesRead);
}
} catch (Exception e) {
throw new IOException(e);
}
return availableLength;
return bytesRead;
}
}

Expand Down
37 changes: 26 additions & 11 deletions TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.telegram.ui.Components.MotionBackgroundDrawable;
import org.telegram.ui.Components.Point;
import org.telegram.ui.Components.RLottieDrawable;
import org.telegram.ui.Components.Reactions.HwEmojis;
import org.telegram.ui.Components.SlotsDrawable;
import org.telegram.ui.Components.ThemePreviewDrawable;

Expand Down Expand Up @@ -103,6 +102,8 @@
*/
public class ImageLoader {

private static final boolean DEBUG_MODE = false;

private HashMap<String, Integer> bitmapUseCounts = new HashMap<>();
private LruCache<BitmapDrawable> smallImagesMemCache;
private LruCache<BitmapDrawable> memCache;
Expand Down Expand Up @@ -1822,7 +1823,9 @@ public static Bitmap getStrippedPhotoBitmap(byte[] photoBytes, String filter) {
data[164] = photoBytes[1];
data[166] = photoBytes[2];

Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, len);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = SharedConfig.deviceIsHigh() ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, len, options);
if (bitmap != null && !TextUtils.isEmpty(filter) && filter.contains("b")) {
Utilities.blurBitmap(bitmap, 3, 1, bitmap.getWidth(), bitmap.getHeight(), bitmap.getRowBytes());
}
Expand Down Expand Up @@ -2060,15 +2063,15 @@ public ImageLoader() {
} else {
maxSize = 15;
}
int cacheSize = Math.min(maxSize, memoryClass / 7) * 1024 * 1024;
int cacheSize = DEBUG_MODE ? 1 : Math.min(maxSize, memoryClass / 7) * 1024 * 1024;

int commonCacheSize = (int) (cacheSize * 0.8f);
int smallImagesCacheSize = (int) (cacheSize * 0.2f);
int commonCacheSize = DEBUG_MODE ? 1 : (int) (cacheSize * 0.8f);
int smallImagesCacheSize = DEBUG_MODE ? 1 : (int) (cacheSize * 0.2f);

memCache = new LruCache<BitmapDrawable>(commonCacheSize) {
@Override
protected int sizeOf(String key, BitmapDrawable value) {
return value.getBitmap().getByteCount();
return sizeOfBitmapDrawable(value);
}

@Override
Expand All @@ -2090,7 +2093,7 @@ protected void entryRemoved(boolean evicted, String key, final BitmapDrawable ol
smallImagesMemCache = new LruCache<BitmapDrawable>(smallImagesCacheSize) {
@Override
protected int sizeOf(String key, BitmapDrawable value) {
return value.getBitmap().getByteCount();
return sizeOfBitmapDrawable(value);
}

@Override
Expand All @@ -2109,18 +2112,18 @@ protected void entryRemoved(boolean evicted, String key, final BitmapDrawable ol
}
}
};
wallpaperMemCache = new LruCache<BitmapDrawable>(cacheSize / 4) {
wallpaperMemCache = new LruCache<BitmapDrawable>(DEBUG_MODE ? 1 : cacheSize / 4) {
@Override
protected int sizeOf(String key, BitmapDrawable value) {
return value.getBitmap().getByteCount();
return sizeOfBitmapDrawable(value);
}
};

lottieMemCache = new LruCache<BitmapDrawable>(512 * 512 * 2 * 4 * 5) {
lottieMemCache = new LruCache<BitmapDrawable>(DEBUG_MODE ? 1 : 512 * 512 * 2 * 4 * 5) {

@Override
protected int sizeOf(String key, BitmapDrawable value) {
return value.getIntrinsicWidth() * value.getIntrinsicHeight() * 4 * 2;
return sizeOfBitmapDrawable(value);
}

@Override
Expand Down Expand Up @@ -2327,6 +2330,18 @@ public void onReceive(Context arg0, Intent intent) {
checkMediaPaths();
}

private int sizeOfBitmapDrawable(BitmapDrawable value) {
if (value instanceof AnimatedFileDrawable) {
AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) value;
int maxSize = animatedFileDrawable.getRenderingHeight() * animatedFileDrawable.getRenderingWidth() * 4 * 3;
maxSize = Math.max(animatedFileDrawable.getIntrinsicHeight() * value.getIntrinsicWidth() * 4 * 3, maxSize);
return maxSize;
} if (value instanceof RLottieDrawable) {
return value.getIntrinsicWidth() * value.getIntrinsicHeight() * 4 * 2;
}
return value.getBitmap().getByteCount();
}

public void checkMediaPaths() {
checkMediaPaths(null);
}
Expand Down
Loading

0 comments on commit 0bcf4fe

Please sign in to comment.