Skip to content

Commit

Permalink
update to 11.5.3 (5511)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaraush committed Dec 6, 2024
1 parent fb2e545 commit 9dcd88b
Show file tree
Hide file tree
Showing 177 changed files with 12,830 additions and 2,547 deletions.
40 changes: 38 additions & 2 deletions TMessagesProj/jni/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Stories_recorder_FfmpegAudioWaveform
int skip = 4;
int barWidth = (int) round((double) duration_in_seconds * sampleRate / count / (1 + skip)); // Assuming you have 'duration' and 'count' defined somewhere

int channels = codecContext->channels;

short peak = 0;
int currentCount = 0;
int index = 0;
Expand All @@ -937,9 +939,43 @@ JNIEXPORT void JNICALL Java_org_telegram_ui_Stories_recorder_FfmpegAudioWaveform
break;
}

int16_t* samples = (int16_t*) frame->data[0];
const int is_planar = av_sample_fmt_is_planar(codecContext->sample_fmt);
const int sample_size = av_get_bytes_per_sample(codecContext->sample_fmt);
for (int i = 0; i < frame->nb_samples; i++) {
short value = samples[i]; // Read the 16-bit PCM sample
int sum = 0;
for (int channel = 0; channel < channels; channel++) {
uint8_t *data;
if (is_planar) {
data = frame->data[channel] + i * sample_size;
} else {
data = frame->data[0] + (i * channels + channel) * sample_size;
}
short sample_value = 0;
switch (codecContext->sample_fmt) {
case AV_SAMPLE_FMT_S16:
case AV_SAMPLE_FMT_S16P:
// Signed 16-bit PCM
sample_value = *(int16_t *)data;
break;

case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
// 32-bit float, scale to 16-bit PCM range
sample_value = (short)(*(float *)data * 32767.0f);
break;

case AV_SAMPLE_FMT_U8:
case AV_SAMPLE_FMT_U8P:
// Unsigned 8-bit PCM, scale to 16-bit PCM range
sample_value = (*(uint8_t *)data - 128) * 256;
break;

default:
break;
}
sum += sample_value;
}
short value = sum / channels;

if (currentCount >= barWidth) {
waveformChunkData[index - chunkIndex] = peak;
Expand Down
7 changes: 4 additions & 3 deletions TMessagesProj/jni/gifvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int open_codec_context(int *stream_idx, AVCodecContext **dec_ctx, AVFormatContex

dec = avcodec_find_decoder(st->codecpar->codec_id);
if (!dec) {
LOGE("failed to find %s codec", av_get_media_type_string(type));
LOGE("failed to find %d codec", st->codecpar->codec_id);
return AVERROR(EINVAL);
}

Expand Down Expand Up @@ -857,7 +857,7 @@ extern "C" JNIEXPORT int JNICALL Java_org_telegram_ui_Components_AnimatedFileDra
}

extern "C" JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_AnimatedFileDrawable_getVideoFrame(JNIEnv *env, jclass clazz, jlong ptr, jobject bitmap, jintArray data, jint stride, jboolean preview, jfloat start_time, jfloat end_time, jboolean loop) {
if (ptr == NULL || bitmap == nullptr) {
if (ptr == NULL) {
return 0;
}
//int64_t time = ConnectionsManager::getInstance(0).getCurrentTimeMonotonicMillis();
Expand Down Expand Up @@ -946,10 +946,11 @@ extern "C" JNIEXPORT jint JNICALL Java_org_telegram_ui_Components_AnimatedFileDr
}
if (got_frame) {
//LOGD("decoded frame with w = %d, h = %d, format = %d", info->frame->width, info->frame->height, info->frame->format);
if (info->frame->format == AV_PIX_FMT_YUV420P || info->frame->format == AV_PIX_FMT_BGRA || info->frame->format == AV_PIX_FMT_YUVJ420P || info->frame->format == AV_PIX_FMT_YUV444P || info->frame->format == AV_PIX_FMT_YUVA420P) {
if (bitmap != nullptr && (info->frame->format == AV_PIX_FMT_YUV420P || info->frame->format == AV_PIX_FMT_BGRA || info->frame->format == AV_PIX_FMT_YUVJ420P || info->frame->format == AV_PIX_FMT_YUV444P || info->frame->format == AV_PIX_FMT_YUVA420P)) {
writeFrameToBitmap(env, info, data, bitmap, stride);
}
info->has_decoded_frames = true;
push_time(env, info, data);
av_frame_unref(info->frame);
return 1;
}
Expand Down
Binary file modified TMessagesProj/src/main/assets/models/coin_stars.binobj
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.Context;
import android.media.MediaCodec;
import android.media.PlaybackParams;
import android.opengl.EGLContext;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.IntDef;
Expand Down Expand Up @@ -286,13 +287,15 @@ public DefaultRenderersFactory setAllowedVideoJoiningTimeMs(long allowedVideoJoi
@Override
public Renderer[] createRenderers(
Handler eventHandler,
EGLContext parentContext,
VideoRendererEventListener videoRendererEventListener,
AudioRendererEventListener audioRendererEventListener,
TextOutput textRendererOutput,
MetadataOutput metadataRendererOutput) {
ArrayList<Renderer> renderersList = new ArrayList<>();
buildVideoRenderers(
context,
parentContext,
extensionRendererMode,
mediaCodecSelector,
enableDecoderFallback,
Expand Down Expand Up @@ -348,6 +351,7 @@ public Renderer[] createRenderers(
*/
protected void buildVideoRenderers(
Context context,
EGLContext parentContext,
@ExtensionRendererMode int extensionRendererMode,
MediaCodecSelector mediaCodecSelector,
boolean enableDecoderFallback,
Expand All @@ -358,6 +362,7 @@ protected void buildVideoRenderers(
MediaCodecVideoRenderer videoRenderer =
new MediaCodecVideoRenderer(
context,
parentContext,
getCodecAdapterFactory(),
mediaCodecSelector,
allowedVideoJoiningTimeMs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.media.AudioDeviceInfo;
import android.media.AudioTrack;
import android.media.MediaCodec;
import android.opengl.EGLContext;
import android.os.Looper;
import android.os.Process;
import android.view.Surface;
Expand Down Expand Up @@ -452,6 +453,7 @@ default void onExperimentalOffloadedPlayback(boolean offloadedPlayback) {}
final class Builder {

/* package */ final Context context;
public EGLContext eglContext;

/* package */ Clock clock;
/* package */ long foregroundModeTimeoutMs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public ExoPlayerImpl(ExoPlayer.Builder builder, @Nullable Player wrappingPlayer)
.get()
.createRenderers(
eventHandler,
builder.eglContext,
componentListener,
componentListener,
componentListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2;

import android.opengl.EGLContext;
import android.os.Handler;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.metadata.MetadataOutput;
Expand All @@ -36,6 +37,7 @@ public interface RenderersFactory {
*/
Renderer[] createRenderers(
Handler eventHandler,
EGLContext parentContext,
VideoRendererEventListener videoRendererEventListener,
AudioRendererEventListener audioRendererEventListener,
TextOutput textRendererOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.media.MediaCodec;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.opengl.EGLContext;
import android.os.Handler;
import androidx.annotation.CallSuper;
import androidx.annotation.DoNotInline;
Expand Down Expand Up @@ -418,7 +419,9 @@ protected MediaCodecAdapter.Configuration getMediaCodecConfiguration(
MediaCodecInfo codecInfo,
Format format,
@Nullable MediaCrypto crypto,
float codecOperatingRate) {
float codecOperatingRate,
EGLContext parentContext
) {
codecMaxInputSize = getCodecMaxInputSize(codecInfo, format, getStreamFormats());
codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
MediaFormat mediaFormat =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.media.MediaCryptoException;
import android.media.MediaFormat;
import android.media.metrics.LogSessionId;
import android.opengl.EGLContext;
import android.os.Bundle;
import android.os.SystemClock;
import androidx.annotation.CallSuper;
Expand Down Expand Up @@ -75,6 +76,8 @@
import com.google.android.exoplayer2.util.TimedValueQueue;
import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.MediaCodecVideoRenderer;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -487,7 +490,8 @@ protected abstract MediaCodecAdapter.Configuration getMediaCodecConfiguration(
MediaCodecInfo codecInfo,
Format format,
@Nullable MediaCrypto crypto,
float codecOperatingRate);
float codecOperatingRate,
EGLContext context);

protected final void maybeInitCodecOrBypass() throws ExoPlaybackException {
if (codec != null || bypassEnabled || inputFormat == null) {
Expand Down Expand Up @@ -1099,7 +1103,7 @@ private void initCodec(MediaCodecInfo codecInfo, MediaCrypto crypto) throws Exce
}
codecInitializingTimestamp = SystemClock.elapsedRealtime();
MediaCodecAdapter.Configuration configuration =
getMediaCodecConfiguration(codecInfo, inputFormat, crypto, codecOperatingRate);
getMediaCodecConfiguration(codecInfo, inputFormat, crypto, codecOperatingRate, this instanceof MediaCodecVideoRenderer ? ((MediaCodecVideoRenderer) this).eglContext : null);
if (Util.SDK_INT >= 31) {
Api31.setLogSessionIdToMediaCodecFormat(configuration, getPlayerId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public static RendererCapabilities[] getRendererCapabilities(RenderersFactory re
Renderer[] renderers =
renderersFactory.createRenderers(
Util.createHandlerForCurrentOrMainLooper(),
null,
new VideoRendererEventListener() {},
new AudioRendererEventListener() {},
(cues) -> {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public static synchronized DefaultBandwidthMeter getSingletonInstance(Context co
private @C.NetworkType int networkType;
private long totalElapsedTimeMs;
private long totalBytesTransferred;
private long bitrateEstimate;
private volatile long bitrateEstimate;
private long lastReportedBitrateEstimate;

private boolean networkTypeOverrideSet;
Expand Down Expand Up @@ -420,7 +420,7 @@ public synchronized void onTransferEnd(DataSource source, DataSpec dataSpec, boo
streamCount--;
}

public void onTransfer(long bytes, long duration) {
public synchronized void onTransfer(long bytes, long duration) {
long nowMs = clock.elapsedRealtime();
int sampleElapsedTimeMs = (int) (nowMs - sampleStartTimeMs);
totalElapsedTimeMs += sampleElapsedTimeMs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public interface TextureImageListener {
/**
* @param handler The {@link Handler} that will be used to call {@link
* SurfaceTexture#updateTexImage()} to update images on the {@link SurfaceTexture}. Note that
* {@link #init(int)} has to be called on the same looper thread as the {@link Handler}'s
* {@link #init(int, EGLContext)} has to be called on the same looper thread as the {@link Handler}'s
* looper.
*/
public EGLSurfaceTexture(Handler handler) {
Expand All @@ -100,7 +100,7 @@ public EGLSurfaceTexture(Handler handler) {
/**
* @param handler The {@link Handler} that will be used to call {@link
* SurfaceTexture#updateTexImage()} to update images on the {@link SurfaceTexture}. Note that
* {@link #init(int)} has to be called on the same looper thread as the looper of the {@link
* {@link #init(int, EGLContext)} has to be called on the same looper thread as the looper of the {@link
* Handler}.
* @param callback The {@link TextureImageListener} to be called when the texture image on {@link
* SurfaceTexture} has been updated. This callback will be called on the same handler thread
Expand All @@ -117,10 +117,10 @@ public EGLSurfaceTexture(Handler handler, @Nullable TextureImageListener callbac
*
* @param secureMode The {@link SecureMode} to be used for EGL surface.
*/
public void init(@SecureMode int secureMode) throws GlUtil.GlException {
public void init(@SecureMode int secureMode, EGLContext parentContext) throws GlUtil.GlException {
display = getDefaultDisplay();
EGLConfig config = chooseEGLConfig(display);
context = createEGLContext(display, config, secureMode);
context = createEGLContext(display, config, secureMode, parentContext);
surface = createEGLSurface(display, config, context, secureMode);
generateTextureIds(textureIdHolder);
texture = new SurfaceTexture(textureIdHolder[0]);
Expand Down Expand Up @@ -164,7 +164,7 @@ public void release() {
}

/**
* Returns the wrapped {@link SurfaceTexture}. This can only be called after {@link #init(int)}.
* Returns the wrapped {@link SurfaceTexture}. This can only be called after {@link #init(int, EGLContext)}.
*/
public SurfaceTexture getSurfaceTexture() {
return Assertions.checkNotNull(texture);
Expand Down Expand Up @@ -232,7 +232,7 @@ private static EGLConfig chooseEGLConfig(EGLDisplay display) throws GlUtil.GlExc
}

private static EGLContext createEGLContext(
EGLDisplay display, EGLConfig config, @SecureMode int secureMode) throws GlUtil.GlException {
EGLDisplay display, EGLConfig config, @SecureMode int secureMode, EGLContext eglContext) throws GlUtil.GlException {
int[] glAttributes;
if (secureMode == SECURE_MODE_NONE) {
glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};
Expand All @@ -248,7 +248,7 @@ private static EGLContext createEGLContext(
}
EGLContext context =
EGL14.eglCreateContext(
display, config, android.opengl.EGL14.EGL_NO_CONTEXT, glAttributes, 0);
display, config, eglContext == null ? android.opengl.EGL14.EGL_NO_CONTEXT : eglContext, glAttributes, 0);
GlUtil.checkGlException(context != null, "eglCreateContext failed");
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.opengl.EGLContext;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
Expand Down Expand Up @@ -123,6 +124,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
private static boolean deviceNeedsSetOutputSurfaceWorkaround;

private final Context context;
public EGLContext eglContext;
private final VideoFrameReleaseHelper frameReleaseHelper;
private final EventDispatcher eventDispatcher;
private final long allowedJoiningTimeMs;
Expand Down Expand Up @@ -207,6 +209,7 @@ public MediaCodecVideoRenderer(
int maxDroppedFramesToNotify) {
this(
context,
null,
MediaCodecAdapter.Factory.DEFAULT,
mediaCodecSelector,
allowedJoiningTimeMs,
Expand Down Expand Up @@ -241,6 +244,7 @@ public MediaCodecVideoRenderer(
int maxDroppedFramesToNotify) {
this(
context,
null,
MediaCodecAdapter.Factory.DEFAULT,
mediaCodecSelector,
allowedJoiningTimeMs,
Expand Down Expand Up @@ -269,6 +273,7 @@ public MediaCodecVideoRenderer(
*/
public MediaCodecVideoRenderer(
Context context,
EGLContext parentContext,
MediaCodecAdapter.Factory codecAdapterFactory,
MediaCodecSelector mediaCodecSelector,
long allowedJoiningTimeMs,
Expand All @@ -279,6 +284,7 @@ public MediaCodecVideoRenderer(

this(
context,
parentContext,
codecAdapterFactory,
mediaCodecSelector,
allowedJoiningTimeMs,
Expand Down Expand Up @@ -312,6 +318,7 @@ public MediaCodecVideoRenderer(
*/
public MediaCodecVideoRenderer(
Context context,
EGLContext parentContext,
MediaCodecAdapter.Factory codecAdapterFactory,
MediaCodecSelector mediaCodecSelector,
long allowedJoiningTimeMs,
Expand All @@ -329,6 +336,7 @@ public MediaCodecVideoRenderer(
this.allowedJoiningTimeMs = allowedJoiningTimeMs;
this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
this.context = context.getApplicationContext();
this.eglContext = parentContext;
frameReleaseHelper = new VideoFrameReleaseHelper(this.context);
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
deviceNeedsNoPostProcessWorkaround = deviceNeedsNoPostProcessWorkaround();
Expand Down Expand Up @@ -674,7 +682,7 @@ private void setOutput(@Nullable Object output) throws ExoPlaybackException {
} else {
MediaCodecInfo codecInfo = getCodecInfo();
if (codecInfo != null && shouldUsePlaceholderSurface(codecInfo)) {
placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure);
placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure, eglContext);
surface = placeholderSurface;
}
}
Expand Down Expand Up @@ -739,8 +747,10 @@ protected MediaCodecAdapter.Configuration getMediaCodecConfiguration(
MediaCodecInfo codecInfo,
Format format,
@Nullable MediaCrypto crypto,
float codecOperatingRate) {
if (placeholderSurface != null && placeholderSurface.secure != codecInfo.secure) {
float codecOperatingRate,
EGLContext parentContext
) {
if (placeholderSurface != null && (placeholderSurface.secure != codecInfo.secure || placeholderSurface.parentContext != parentContext)) {
// We can't re-use the current DummySurface instance with the new decoder.
releasePlaceholderSurface();
}
Expand All @@ -759,7 +769,7 @@ protected MediaCodecAdapter.Configuration getMediaCodecConfiguration(
throw new IllegalStateException();
}
if (placeholderSurface == null) {
placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure);
placeholderSurface = PlaceholderSurface.newInstanceV17(context, codecInfo.secure, parentContext);
}
surface = placeholderSurface;
}
Expand Down
Loading

1 comment on commit 9dcd88b

@nubesurrealista
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comply with your obligations, release the source code. Releasing updates without releasing the source code is considered conduct that violates the license.

Please sign in to comment.