2021-12-21 23:37:30 +00:00
|
|
|
package b.a.q.m0;
|
2021-07-13 20:48:29 +00:00
|
|
|
|
2021-07-20 22:20:08 +00:00
|
|
|
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;
|
2021-08-09 22:50:01 +00:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2021-07-20 22:20:08 +00:00
|
|
|
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;
|
2021-11-08 18:25:28 +00:00
|
|
|
import d0.z.d.m;
|
2021-07-20 22:20:08 +00:00
|
|
|
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;
|
2021-07-13 20:48:29 +00:00
|
|
|
import rx.functions.Action1;
|
2021-07-20 22:20:08 +00:00
|
|
|
/* compiled from: ScreenCapturer.kt */
|
|
|
|
public final class b extends ScreenCapturerAndroid {
|
2021-12-17 22:03:14 +00:00
|
|
|
public static final a j = new a(null);
|
2021-12-21 23:37:30 +00:00
|
|
|
public final RunnableC0034b k = new RunnableC0034b();
|
2021-12-17 22:03:14 +00:00
|
|
|
public NativeCapturerObserver l;
|
|
|
|
public SurfaceTextureHelper m;
|
|
|
|
public Context n;
|
|
|
|
public final SoundshareAudioSource o = new SoundshareAudioSource();
|
2021-07-20 22:20:08 +00:00
|
|
|
public int p;
|
2021-12-17 22:03:14 +00:00
|
|
|
public int q;
|
|
|
|
public Long r;
|
2021-07-13 20:48:29 +00:00
|
|
|
|
2021-11-08 18:25:28 +00:00
|
|
|
/* renamed from: s reason: collision with root package name */
|
2021-12-21 23:37:30 +00:00
|
|
|
public final Rect f262s = new Rect();
|
2021-12-17 22:03:14 +00:00
|
|
|
public final Rect t = new Rect();
|
|
|
|
public final Point u = new Point();
|
|
|
|
public int v;
|
|
|
|
public Subscription w;
|
2021-07-20 22:20:08 +00:00
|
|
|
|
|
|
|
/* renamed from: x reason: collision with root package name */
|
2021-12-21 23:37:30 +00:00
|
|
|
public final Logger f263x;
|
2021-12-17 22:03:14 +00:00
|
|
|
|
|
|
|
/* renamed from: y reason: collision with root package name */
|
2021-12-21 23:37:30 +00:00
|
|
|
public final ThumbnailEmitter f264y;
|
2021-07-20 22:20:08 +00:00
|
|
|
|
|
|
|
/* compiled from: ScreenCapturer.kt */
|
|
|
|
public static final class a {
|
|
|
|
public a(DefaultConstructorMarker defaultConstructorMarker) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compiled from: ScreenCapturer.kt */
|
2021-12-21 23:37:30 +00:00
|
|
|
/* renamed from: b.a.q.m0.b$b reason: collision with other inner class name */
|
|
|
|
public final class RunnableC0034b implements Runnable {
|
|
|
|
public RunnableC0034b() {
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.lang.Runnable
|
|
|
|
public void run() {
|
|
|
|
b bVar = b.this;
|
2021-12-17 22:03:14 +00:00
|
|
|
if (bVar.p > 0) {
|
|
|
|
Long l = bVar.r;
|
2021-07-20 22:20:08 +00:00
|
|
|
if (l != null) {
|
|
|
|
long rtcTimeNanos = TimestampAligner.getRtcTimeNanos() - l.longValue();
|
|
|
|
b bVar2 = b.this;
|
2021-12-17 22:03:14 +00:00
|
|
|
if (rtcTimeNanos > ((long) bVar2.q)) {
|
|
|
|
NativeCapturerObserver nativeCapturerObserver = bVar2.l;
|
2021-07-20 22:20:08 +00:00
|
|
|
if (nativeCapturerObserver == null) {
|
|
|
|
m.throwUninitializedPropertyAccessException("nativeObserver");
|
|
|
|
}
|
|
|
|
nativeCapturerObserver.repeatLastFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.this.c();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compiled from: ScreenCapturer.kt */
|
|
|
|
public static final class c<T> implements Action1<Long> {
|
2021-12-17 22:03:14 +00:00
|
|
|
public final /* synthetic */ b j;
|
2021-07-20 22:20:08 +00:00
|
|
|
|
|
|
|
public c(b bVar) {
|
2021-12-17 22:03:14 +00:00
|
|
|
this.j = bVar;
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
|
|
@Override // rx.functions.Action1
|
|
|
|
public void call(Long l) {
|
2021-12-17 22:03:14 +00:00
|
|
|
this.j.k.run();
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compiled from: ScreenCapturer.kt */
|
|
|
|
public static final class d<T> implements Action1<Throwable> {
|
2021-12-17 22:03:14 +00:00
|
|
|
public static final d j = new d();
|
2021-07-20 22:20:08 +00:00
|
|
|
|
|
|
|
/* 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");
|
2021-12-21 23:37:30 +00:00
|
|
|
this.f263x = logger;
|
|
|
|
this.f264y = thumbnailEmitter;
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 22:03:14 +00:00
|
|
|
public final synchronized void a(Rect rect, int i) {
|
2021-07-20 22:20:08 +00:00
|
|
|
m.checkNotNullParameter(rect, "measuredSize");
|
|
|
|
int max = Math.max(rect.width(), rect.height());
|
|
|
|
if (max > 0) {
|
2021-12-17 22:03:14 +00:00
|
|
|
float f = ((float) i) / ((float) max);
|
|
|
|
this.u.set((int) (((float) rect.width()) * f), (int) (((float) rect.height()) * f));
|
|
|
|
Point point = this.u;
|
|
|
|
int i2 = point.x;
|
|
|
|
int i3 = i2 % 16;
|
|
|
|
if (i3 >= 8) {
|
|
|
|
i2 += 16;
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
int i4 = i2 - i3;
|
|
|
|
int i5 = point.y;
|
|
|
|
int i6 = i5 % 16;
|
|
|
|
if (i6 >= 8) {
|
|
|
|
i5 += 16;
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
point.set(i4, i5 - i6);
|
|
|
|
Point point2 = this.u;
|
|
|
|
super.changeCaptureFormat(point2.x, point2.y, this.p);
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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() {
|
2021-12-17 22:03:14 +00:00
|
|
|
if (this.p > 0) {
|
|
|
|
Subscription subscription = this.w;
|
2021-07-20 22:20:08 +00:00
|
|
|
if (subscription != null) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
Observable<Long> d02 = Observable.d0(((long) this.q) / 1000000, TimeUnit.MILLISECONDS);
|
|
|
|
SurfaceTextureHelper surfaceTextureHelper = this.m;
|
2021-07-20 22:20:08 +00:00
|
|
|
if (surfaceTextureHelper == null) {
|
|
|
|
m.throwUninitializedPropertyAccessException("surfaceTextureHelper");
|
|
|
|
}
|
|
|
|
Handler handler = surfaceTextureHelper.getHandler();
|
|
|
|
m.checkNotNullExpressionValue(handler, "surfaceTextureHelper.handler");
|
|
|
|
Looper looper = handler.getLooper();
|
2021-11-08 18:25:28 +00:00
|
|
|
AtomicReference<j0.j.b.a> atomicReference = j0.j.b.a.a;
|
2021-07-20 22:20:08 +00:00
|
|
|
Objects.requireNonNull(looper, "looper == null");
|
2021-12-17 22:03:14 +00:00
|
|
|
this.w = d02.X(new j0.j.b.b(looper)).W(new c(this), d.j);
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
|
2021-12-17 22:03:14 +00:00
|
|
|
public synchronized void changeCaptureFormat(int i, int i2, int i3) {
|
2021-12-21 23:37:30 +00:00
|
|
|
a(this.f262s, Math.max(i, i2));
|
2021-12-17 22:03:14 +00:00
|
|
|
d(i3);
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid
|
|
|
|
public void createVirtualDisplay() {
|
|
|
|
try {
|
|
|
|
super.createVirtualDisplay();
|
|
|
|
} catch (Throwable th) {
|
2021-12-21 23:37:30 +00:00
|
|
|
Logger.e$default(this.f263x, "ScreenCapturer", "error in createVirtualDisplay", th, null, 8, null);
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 22:03:14 +00:00
|
|
|
public final void d(int i) {
|
|
|
|
if (i <= 0) {
|
2021-07-20 22:20:08 +00:00
|
|
|
this.p = 0;
|
2021-12-17 22:03:14 +00:00
|
|
|
this.q = 0;
|
2021-07-20 22:20:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
this.p = i;
|
|
|
|
this.q = 1000000000 / Math.max(10, i / 2);
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
|
|
|
|
public void dispose() {
|
|
|
|
stopCapture();
|
2021-12-21 23:37:30 +00:00
|
|
|
ThumbnailEmitter thumbnailEmitter = this.f264y;
|
2021-07-20 22:20:08 +00:00
|
|
|
if (thumbnailEmitter != null) {
|
|
|
|
synchronized (thumbnailEmitter) {
|
|
|
|
thumbnailEmitter.d.release();
|
2021-12-21 23:37:30 +00:00
|
|
|
thumbnailEmitter.c.release();
|
2022-01-11 22:19:46 +00:00
|
|
|
JniCommon.nativeFreeByteBuffer(thumbnailEmitter.f2759b);
|
2021-08-09 22:50:01 +00:00
|
|
|
thumbnailEmitter.a = RecyclerView.FOREVER_NS;
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
this.o.release();
|
2021-07-20 22:20:08 +00:00
|
|
|
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");
|
2021-12-17 22:03:14 +00:00
|
|
|
this.m = surfaceTextureHelper;
|
|
|
|
this.n = context;
|
|
|
|
this.l = (NativeCapturerObserver) capturerObserver;
|
2021-07-20 22:20:08 +00:00
|
|
|
super.initialize(surfaceTextureHelper, context, capturerObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoSink
|
|
|
|
public void onFrame(VideoFrame videoFrame) {
|
2021-12-17 22:03:14 +00:00
|
|
|
Rect rect = this.t;
|
|
|
|
Context context = this.n;
|
2021-07-20 22:20:08 +00:00
|
|
|
if (context == null) {
|
|
|
|
m.throwUninitializedPropertyAccessException("context");
|
|
|
|
}
|
|
|
|
rect.set(DisplayUtils.getScreenSize(context));
|
2021-12-21 23:37:30 +00:00
|
|
|
if (!m.areEqual(this.t, this.f262s)) {
|
|
|
|
this.f262s.set(this.t);
|
2021-12-17 22:03:14 +00:00
|
|
|
a(this.t, this.v);
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
2021-12-17 22:03:14 +00:00
|
|
|
this.r = Long.valueOf(videoFrame.getTimestampNs());
|
2021-12-21 23:37:30 +00:00
|
|
|
ThumbnailEmitter thumbnailEmitter = this.f264y;
|
2021-07-20 22:20:08 +00:00
|
|
|
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) {
|
2021-12-17 22:03:14 +00:00
|
|
|
long j2 = (long) 1000;
|
|
|
|
if (timestampNs > thumbnailEmitter.i * j2 * j2) {
|
2021-07-20 22:20:08 +00:00
|
|
|
thumbnailEmitter.a = videoFrame.getTimestampNs();
|
|
|
|
thumbnailEmitter.l.invoke(thumbnailEmitter.a(videoFrame));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onFrame(videoFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
|
2021-12-17 22:03:14 +00:00
|
|
|
public synchronized void startCapture(int i, int i2, int i3) {
|
2021-12-21 23:37:30 +00:00
|
|
|
AudioRecord b2;
|
2021-12-17 22:03:14 +00:00
|
|
|
super.startCapture(i, i2, i3);
|
|
|
|
this.v = Math.max(i, i2);
|
|
|
|
d(i3);
|
2021-12-21 23:37:30 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 29 && (b2 = b()) != null) {
|
|
|
|
this.o.startRecording(b2);
|
2021-07-20 22:20:08 +00:00
|
|
|
}
|
|
|
|
c();
|
2021-07-13 20:48:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 22:20:08 +00:00
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
|
|
|
|
public synchronized void stopCapture() {
|
|
|
|
super.stopCapture();
|
2021-12-17 22:03:14 +00:00
|
|
|
this.o.stopRecording();
|
|
|
|
this.p = 0;
|
|
|
|
this.r = null;
|
2021-07-13 20:48:29 +00:00
|
|
|
}
|
|
|
|
}
|