diff --git a/app/src/main/java/com/pedro/streamer/file/FromFileActivity.kt b/app/src/main/java/com/pedro/streamer/file/FromFileActivity.kt index 371b0a8a5..e1c7a7d4c 100644 --- a/app/src/main/java/com/pedro/streamer/file/FromFileActivity.kt +++ b/app/src/main/java/com/pedro/streamer/file/FromFileActivity.kt @@ -33,6 +33,7 @@ import androidx.appcompat.app.AppCompatActivity import com.pedro.common.ConnectChecker import com.pedro.encoder.input.decoder.AudioDecoderInterface import com.pedro.encoder.input.decoder.VideoDecoderInterface +import com.pedro.extrasources.extractor.Media3Extractor import com.pedro.library.base.recording.RecordController import com.pedro.library.generic.GenericFromFile import com.pedro.library.view.OpenGlView @@ -105,6 +106,8 @@ class FromFileActivity : AppCompatActivity(), ConnectChecker, openGlView = findViewById(R.id.surfaceView) genericFromFile = GenericFromFile(openGlView, this, this, this) genericFromFile.setLoopMode(true) + genericFromFile.setAudioExtractor(Media3Extractor(this)) + genericFromFile.setVideoExtractor(Media3Extractor(this)) bStream.setOnClickListener { if (genericFromFile.isStreaming) { diff --git a/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java b/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java index c8d78cce5..9b10944b2 100644 --- a/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java +++ b/encoder/src/main/java/com/pedro/encoder/input/decoder/BaseDecoder.java @@ -21,14 +21,14 @@ import android.media.MediaFormat; import android.net.Uri; import android.os.Build; -import android.os.Handler; -import android.os.HandlerThread; import android.util.Log; import android.view.Surface; import java.io.FileDescriptor; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; public abstract class BaseDecoder { @@ -38,7 +38,7 @@ public abstract class BaseDecoder { protected MediaCodec codec; protected volatile boolean running = false; protected MediaFormat mediaFormat; - private HandlerThread handlerThread; + private ExecutorService executor; protected String mime = ""; protected boolean loopMode = false; private volatile long startTs = 0; @@ -71,11 +71,9 @@ public boolean initExtractor(Context context, Uri uri) throws IOException { public void start() { Log.i(TAG, "start decoder"); running = true; - handlerThread = new HandlerThread(TAG); - handlerThread.start(); - Handler handler = new Handler(handlerThread.getLooper()); codec.start(); - handler.post(() -> { + executor = Executors.newSingleThreadExecutor(); + executor.execute(() -> { try { decode(); } catch (IllegalStateException e) { @@ -122,24 +120,14 @@ protected void stopDecoder() { protected void stopDecoder(boolean clearTs) { running = false; if (clearTs) startTs = 0; - if (handlerThread != null) { - if (handlerThread.getLooper() != null) { - if (handlerThread.getLooper().getThread() != null) { - handlerThread.getLooper().getThread().interrupt(); - } - handlerThread.getLooper().quit(); - } - handlerThread.quit(); + if (executor != null) { + executor.shutdownNow(); + executor = null; if (codec != null) { try { codec.flush(); } catch (IllegalStateException ignored) { } } - //wait for thread to die for 500ms. - try { - handlerThread.getLooper().getThread().join(500); - } catch (Exception ignored) { } - handlerThread = null; } try { codec.stop(); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5f88cb104..519fa4035 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,7 +20,7 @@ junit = "4.13.2" mockito = "5.4.0" ktor = "3.0.0" uvcandroid = "1.0.7" -media3 = "1.4.1" +media3 = "1.5.0-beta01" [libraries] androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "annotation" }