discord-jadx/app/src/main/java/c/a/r/k0/b.java

289 lines
11 KiB
Java

package c.a.r.k0;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.graphics.Rect;
import android.media.AudioFormat;
import android.media.AudioPlaybackCaptureConfiguration;
import android.media.AudioRecord;
import android.media.projection.MediaProjection;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.RequiresApi;
import co.discord.media_engine.NativeCapturerObserver;
import co.discord.media_engine.SoundshareAudioSource;
import com.discord.rtcconnection.mediaengine.ThumbnailEmitter;
import com.discord.utilities.display.DisplayUtils;
import com.discord.utilities.logging.Logger;
import d0.z.d.m;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import kotlin.jvm.internal.DefaultConstructorMarker;
import org.webrtc.CapturerObserver;
import org.webrtc.JniCommon;
import org.webrtc.ScreenCapturerAndroid;
import org.webrtc.SurfaceTextureHelper;
import org.webrtc.TimestampAligner;
import org.webrtc.VideoFrame;
import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;
/* compiled from: ScreenCapturer.kt */
public final class b extends ScreenCapturerAndroid {
public static final a i = new a(null);
public final RunnableC0035b j = new RunnableC0035b();
public NativeCapturerObserver k;
public SurfaceTextureHelper l;
public Context m;
public final SoundshareAudioSource n = new SoundshareAudioSource();
public int o;
public int p;
public Long q;
public final Rect r = new Rect();
/* renamed from: s reason: collision with root package name */
public final Rect f209s = new Rect();
public final Point t = new Point();
public int u;
public Subscription v;
public final Logger w;
/* renamed from: x reason: collision with root package name */
public final ThumbnailEmitter f210x;
/* compiled from: ScreenCapturer.kt */
public static final class a {
public a(DefaultConstructorMarker defaultConstructorMarker) {
}
}
/* compiled from: ScreenCapturer.kt */
/* renamed from: c.a.r.k0.b$b reason: collision with other inner class name */
public final class RunnableC0035b implements Runnable {
public RunnableC0035b() {
}
@Override // java.lang.Runnable
public void run() {
b bVar = b.this;
if (bVar.o > 0) {
Long l = bVar.q;
if (l != null) {
long rtcTimeNanos = TimestampAligner.getRtcTimeNanos() - l.longValue();
b bVar2 = b.this;
if (rtcTimeNanos > ((long) bVar2.p)) {
NativeCapturerObserver nativeCapturerObserver = bVar2.k;
if (nativeCapturerObserver == null) {
m.throwUninitializedPropertyAccessException("nativeObserver");
}
nativeCapturerObserver.repeatLastFrame();
}
}
b.this.c();
}
}
}
/* compiled from: ScreenCapturer.kt */
public static final class c<T> implements Action1<Long> {
public final /* synthetic */ b i;
public c(b bVar) {
this.i = bVar;
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // rx.functions.Action1
public void call(Long l) {
this.i.j.run();
}
}
/* compiled from: ScreenCapturer.kt */
public static final class d<T> implements Action1<Throwable> {
public static final d i = new d();
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // rx.functions.Action1
public void call(Throwable th) {
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public b(Intent intent, MediaProjection.Callback callback, Logger logger, ThumbnailEmitter thumbnailEmitter) {
super(intent, callback);
m.checkNotNullParameter(intent, "mediaProjectionPermissionResultData");
m.checkNotNullParameter(callback, "mediaProjectionCallback");
m.checkNotNullParameter(logger, "logger");
this.w = logger;
this.f210x = thumbnailEmitter;
}
public final synchronized void a(Rect rect, int i2) {
m.checkNotNullParameter(rect, "measuredSize");
int max = Math.max(rect.width(), rect.height());
if (max > 0) {
float f = ((float) i2) / ((float) max);
this.t.set((int) (((float) rect.width()) * f), (int) (((float) rect.height()) * f));
Point point = this.t;
int i3 = point.x;
int i4 = i3 % 16;
if (i4 >= 8) {
i3 += 16;
}
int i5 = i3 - i4;
int i6 = point.y;
int i7 = i6 % 16;
if (i7 >= 8) {
i6 += 16;
}
point.set(i5, i6 - i7);
Point point2 = this.t;
super.changeCaptureFormat(point2.x, point2.y, this.o);
}
}
@RequiresApi(29)
public final AudioRecord b() {
MediaProjection mediaProjection = this.mediaProjection;
if (mediaProjection == null) {
return null;
}
AudioPlaybackCaptureConfiguration build = new AudioPlaybackCaptureConfiguration.Builder(mediaProjection).addMatchingUsage(1).addMatchingUsage(14).addMatchingUsage(0).build();
m.checkNotNullExpressionValue(build, "AudioPlaybackCaptureConf…KNOWN)\n .build()");
try {
return new AudioRecord.Builder().setAudioFormat(new AudioFormat.Builder().setEncoding(2).setSampleRate(44100).setChannelMask(16).build()).setAudioPlaybackCaptureConfig(build).build();
} catch (SecurityException unused) {
Log.w(b.class.getName(), "Failed to record audio");
return null;
}
}
public final void c() {
if (this.o > 0) {
Subscription subscription = this.v;
if (subscription != null) {
subscription.unsubscribe();
}
Observable<Long> d02 = Observable.d0(((long) this.p) / 1000000, TimeUnit.MILLISECONDS);
SurfaceTextureHelper surfaceTextureHelper = this.l;
if (surfaceTextureHelper == null) {
m.throwUninitializedPropertyAccessException("surfaceTextureHelper");
}
Handler handler = surfaceTextureHelper.getHandler();
m.checkNotNullExpressionValue(handler, "surfaceTextureHelper.handler");
Looper looper = handler.getLooper();
AtomicReference<j0.j.b.a> atomicReference = j0.j.b.a.a;
Objects.requireNonNull(looper, "looper == null");
this.v = d02.X(new j0.j.b.b(looper)).W(new c(this), d.i);
}
}
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
public synchronized void changeCaptureFormat(int i2, int i3, int i4) {
a(this.r, Math.max(i2, i3));
d(i4);
}
@Override // org.webrtc.ScreenCapturerAndroid
public void createVirtualDisplay() {
try {
super.createVirtualDisplay();
} catch (Throwable th) {
Logger.e$default(this.w, "ScreenCapturer", "error in createVirtualDisplay", th, null, 8, null);
}
}
public final void d(int i2) {
if (i2 <= 0) {
this.o = 0;
this.p = 0;
return;
}
this.o = i2;
this.p = 1000000000 / Math.max(10, i2 / 2);
}
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
public void dispose() {
stopCapture();
ThumbnailEmitter thumbnailEmitter = this.f210x;
if (thumbnailEmitter != null) {
synchronized (thumbnailEmitter) {
thumbnailEmitter.d.release();
thumbnailEmitter.f2099c.release();
JniCommon.nativeFreeByteBuffer(thumbnailEmitter.b);
thumbnailEmitter.a = Long.MAX_VALUE;
}
}
this.n.release();
super.dispose();
}
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
public synchronized void initialize(SurfaceTextureHelper surfaceTextureHelper, Context context, CapturerObserver capturerObserver) {
m.checkNotNullParameter(surfaceTextureHelper, "surfaceTextureHelper");
m.checkNotNullParameter(context, "applicationContext");
m.checkNotNullParameter(capturerObserver, "capturerObserver");
this.l = surfaceTextureHelper;
this.m = context;
this.k = (NativeCapturerObserver) capturerObserver;
super.initialize(surfaceTextureHelper, context, capturerObserver);
}
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoSink
public void onFrame(VideoFrame videoFrame) {
Rect rect = this.f209s;
Context context = this.m;
if (context == null) {
m.throwUninitializedPropertyAccessException("context");
}
rect.set(DisplayUtils.getScreenSize(context));
if (!m.areEqual(this.f209s, this.r)) {
this.r.set(this.f209s);
a(this.f209s, this.u);
}
this.q = Long.valueOf(videoFrame.getTimestampNs());
ThumbnailEmitter thumbnailEmitter = this.f210x;
if (thumbnailEmitter != null) {
synchronized (thumbnailEmitter) {
m.checkNotNullParameter(videoFrame, "frame");
long currentTimeMillis = thumbnailEmitter.k.currentTimeMillis() - thumbnailEmitter.e;
long timestampNs = videoFrame.getTimestampNs() - thumbnailEmitter.a;
if (currentTimeMillis > thumbnailEmitter.j) {
long j = (long) 1000;
if (timestampNs > thumbnailEmitter.i * j * j) {
thumbnailEmitter.a = videoFrame.getTimestampNs();
thumbnailEmitter.l.invoke(thumbnailEmitter.a(videoFrame));
}
}
}
}
super.onFrame(videoFrame);
}
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
public synchronized void startCapture(int i2, int i3, int i4) {
AudioRecord b;
super.startCapture(i2, i3, i4);
this.u = Math.max(i2, i3);
d(i4);
if (Build.VERSION.SDK_INT >= 29 && (b = b()) != null) {
this.n.startRecording(b);
}
c();
}
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
public synchronized void stopCapture() {
super.stopCapture();
this.n.stopRecording();
this.o = 0;
this.q = null;
}
}