2021-08-18 07:29:27 +00:00
|
|
|
package c.a.q.m0;
|
2021-08-09 22:50:52 +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;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
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-01 07:19:03 +00:00
|
|
|
import d0.z.d.m;
|
2021-08-09 22:50:52 +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;
|
|
|
|
import rx.functions.Action1;
|
|
|
|
/* compiled from: ScreenCapturer.kt */
|
|
|
|
public final class b extends ScreenCapturerAndroid {
|
|
|
|
public static final a i = new a(null);
|
2021-11-05 21:05:33 +00:00
|
|
|
public final RunnableC0036b j = new RunnableC0036b();
|
2021-08-09 22:50:52 +00:00
|
|
|
public NativeCapturerObserver k;
|
|
|
|
public SurfaceTextureHelper l;
|
|
|
|
public Context m;
|
|
|
|
public final SoundshareAudioSource n = new SoundshareAudioSource();
|
|
|
|
public int o;
|
|
|
|
public int p;
|
|
|
|
public Long q;
|
2021-11-01 07:19:03 +00:00
|
|
|
public final Rect r = new Rect();
|
2021-08-09 22:50:52 +00:00
|
|
|
|
2021-11-01 07:19:03 +00:00
|
|
|
/* renamed from: s reason: collision with root package name */
|
2021-11-29 08:39:39 +00:00
|
|
|
public final Rect f217s = new Rect();
|
2021-08-09 22:50:52 +00:00
|
|
|
public final Point t = new Point();
|
|
|
|
public int u;
|
|
|
|
public Subscription v;
|
2021-11-01 07:19:03 +00:00
|
|
|
public final Logger w;
|
2021-08-09 22:50:52 +00:00
|
|
|
|
|
|
|
/* renamed from: x reason: collision with root package name */
|
2021-11-29 08:39:39 +00:00
|
|
|
public final ThumbnailEmitter f218x;
|
2021-08-09 22:50:52 +00:00
|
|
|
|
|
|
|
/* compiled from: ScreenCapturer.kt */
|
|
|
|
public static final class a {
|
|
|
|
public a(DefaultConstructorMarker defaultConstructorMarker) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compiled from: ScreenCapturer.kt */
|
2021-08-18 07:29:27 +00:00
|
|
|
/* renamed from: c.a.q.m0.b$b reason: collision with other inner class name */
|
2021-11-05 21:05:33 +00:00
|
|
|
public final class RunnableC0036b implements Runnable {
|
|
|
|
public RunnableC0036b() {
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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");
|
2021-11-01 07:19:03 +00:00
|
|
|
this.w = logger;
|
2021-11-29 08:39:39 +00:00
|
|
|
this.f218x = thumbnailEmitter;
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2021-10-22 07:30:30 +00:00
|
|
|
Observable<Long> d02 = Observable.d0(((long) this.p) / 1000000, TimeUnit.MILLISECONDS);
|
2021-08-09 22:50:52 +00:00
|
|
|
SurfaceTextureHelper surfaceTextureHelper = this.l;
|
|
|
|
if (surfaceTextureHelper == null) {
|
|
|
|
m.throwUninitializedPropertyAccessException("surfaceTextureHelper");
|
|
|
|
}
|
|
|
|
Handler handler = surfaceTextureHelper.getHandler();
|
|
|
|
m.checkNotNullExpressionValue(handler, "surfaceTextureHelper.handler");
|
|
|
|
Looper looper = handler.getLooper();
|
2021-11-01 07:19:03 +00:00
|
|
|
AtomicReference<j0.j.b.a> atomicReference = j0.j.b.a.a;
|
2021-08-09 22:50:52 +00:00
|
|
|
Objects.requireNonNull(looper, "looper == null");
|
2021-11-01 07:19:03 +00:00
|
|
|
this.v = d02.X(new j0.j.b.b(looper)).W(new c(this), d.i);
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid, org.webrtc.VideoCapturer
|
|
|
|
public synchronized void changeCaptureFormat(int i2, int i3, int i4) {
|
2021-11-01 07:19:03 +00:00
|
|
|
a(this.r, Math.max(i2, i3));
|
2021-08-09 22:50:52 +00:00
|
|
|
d(i4);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // org.webrtc.ScreenCapturerAndroid
|
|
|
|
public void createVirtualDisplay() {
|
|
|
|
try {
|
|
|
|
super.createVirtualDisplay();
|
|
|
|
} catch (Throwable th) {
|
2021-11-01 07:19:03 +00:00
|
|
|
Logger.e$default(this.w, "ScreenCapturer", "error in createVirtualDisplay", th, null, 8, null);
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2021-11-29 08:39:39 +00:00
|
|
|
ThumbnailEmitter thumbnailEmitter = this.f218x;
|
2021-08-09 22:50:52 +00:00
|
|
|
if (thumbnailEmitter != null) {
|
|
|
|
synchronized (thumbnailEmitter) {
|
|
|
|
thumbnailEmitter.d.release();
|
2021-12-04 21:42:05 +00:00
|
|
|
thumbnailEmitter.f2219c.release();
|
2021-08-09 22:50:52 +00:00
|
|
|
JniCommon.nativeFreeByteBuffer(thumbnailEmitter.b);
|
|
|
|
thumbnailEmitter.a = RecyclerView.FOREVER_NS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2021-11-29 08:39:39 +00:00
|
|
|
Rect rect = this.f217s;
|
2021-08-09 22:50:52 +00:00
|
|
|
Context context = this.m;
|
|
|
|
if (context == null) {
|
|
|
|
m.throwUninitializedPropertyAccessException("context");
|
|
|
|
}
|
|
|
|
rect.set(DisplayUtils.getScreenSize(context));
|
2021-11-29 08:39:39 +00:00
|
|
|
if (!m.areEqual(this.f217s, this.r)) {
|
|
|
|
this.r.set(this.f217s);
|
|
|
|
a(this.f217s, this.u);
|
2021-08-09 22:50:52 +00:00
|
|
|
}
|
|
|
|
this.q = Long.valueOf(videoFrame.getTimestampNs());
|
2021-11-29 08:39:39 +00:00
|
|
|
ThumbnailEmitter thumbnailEmitter = this.f218x;
|
2021-08-09 22:50:52 +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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|