diff --git a/ffcodecs/src/main/java/io/github/anilbeesetti/nextlib/ffcodecs/NextRenderersFactory.java b/ffcodecs/src/main/java/io/github/anilbeesetti/nextlib/ffcodecs/NextRenderersFactory.java deleted file mode 100644 index 0f55acd..0000000 --- a/ffcodecs/src/main/java/io/github/anilbeesetti/nextlib/ffcodecs/NextRenderersFactory.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.github.anilbeesetti.nextlib.ffcodecs; - -import android.content.Context; -import android.os.Handler; - -import androidx.media3.common.util.Log; -import androidx.media3.common.util.UnstableApi; -import androidx.media3.exoplayer.DefaultRenderersFactory; -import androidx.media3.exoplayer.Renderer; -import androidx.media3.exoplayer.audio.AudioRendererEventListener; -import androidx.media3.exoplayer.audio.AudioSink; -import androidx.media3.exoplayer.mediacodec.MediaCodecSelector; -import androidx.media3.exoplayer.video.VideoRendererEventListener; - -import java.util.ArrayList; - -@UnstableApi -public class NextRenderersFactory extends DefaultRenderersFactory { - - /** - * @param context A {@link Context}. - */ - public NextRenderersFactory(Context context) { - super(context); - } - - private static final String TAG = "NextRenderersFactory"; - - @Override - protected void buildAudioRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, AudioSink audioSink, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList out) { - super.buildAudioRenderers(context, extensionRendererMode, mediaCodecSelector, enableDecoderFallback, audioSink, eventHandler, eventListener, out); - - if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) return; - - int extensionRendererIndex = out.size(); - if (extensionRendererMode == EXTENSION_RENDERER_MODE_PREFER) { - extensionRendererIndex--; - } - - try { - Renderer renderer = new FfmpegAudioRenderer(eventHandler, eventListener, audioSink); - out.add(extensionRendererIndex++, renderer); - Log.i(TAG, "Loaded FfmpegAudioRenderer."); - } catch (Exception e) { - // The extension is present, but instantiation failed. - throw new RuntimeException("Error instantiating FFmpeg extension", e); - } - } - - @Override - protected void buildVideoRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, Handler eventHandler, VideoRendererEventListener eventListener, long allowedVideoJoiningTimeMs, ArrayList out) { - super.buildVideoRenderers(context, extensionRendererMode, mediaCodecSelector, enableDecoderFallback, eventHandler, eventListener, allowedVideoJoiningTimeMs, out); - - if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) return; - - int extensionRendererIndex = out.size(); - if (extensionRendererMode == EXTENSION_RENDERER_MODE_PREFER) { - extensionRendererIndex--; - } - - try { - Renderer renderer = new FfmpegVideoRenderer(allowedVideoJoiningTimeMs, eventHandler, eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY); - out.add(extensionRendererIndex++, renderer); - Log.i(TAG, "Loaded FfmpegVideoRenderer."); - } catch (Exception e) { - // The extension is present, but instantiation failed. - throw new RuntimeException("Error instantiating FFmpeg extension", e); - } - } -} diff --git a/ffcodecs/src/main/java/io/github/anilbeesetti/nextlib/ffcodecs/NextRenderersFactory.kt b/ffcodecs/src/main/java/io/github/anilbeesetti/nextlib/ffcodecs/NextRenderersFactory.kt new file mode 100644 index 0000000..f09f762 --- /dev/null +++ b/ffcodecs/src/main/java/io/github/anilbeesetti/nextlib/ffcodecs/NextRenderersFactory.kt @@ -0,0 +1,93 @@ +package io.github.anilbeesetti.nextlib.ffcodecs + +import android.content.Context +import android.os.Handler +import androidx.media3.common.util.Log +import androidx.media3.exoplayer.DefaultRenderersFactory +import androidx.media3.exoplayer.Renderer +import androidx.media3.exoplayer.audio.AudioRendererEventListener +import androidx.media3.exoplayer.audio.AudioSink +import androidx.media3.exoplayer.mediacodec.MediaCodecSelector +import androidx.media3.exoplayer.video.VideoRendererEventListener + +class NextRenderersFactory(context: Context) : DefaultRenderersFactory(context) { + override fun buildAudioRenderers( + context: Context, + extensionRendererMode: Int, + mediaCodecSelector: MediaCodecSelector, + enableDecoderFallback: Boolean, + audioSink: AudioSink, + eventHandler: Handler, + eventListener: AudioRendererEventListener, + out: ArrayList + ) { + super.buildAudioRenderers( + context, + extensionRendererMode, + mediaCodecSelector, + enableDecoderFallback, + audioSink, + eventHandler, + eventListener, + out + ) + + if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) return + + var extensionRendererIndex = out.size + if (extensionRendererMode == EXTENSION_RENDERER_MODE_PREFER) { + extensionRendererIndex-- + } + + try { + val renderer = FfmpegAudioRenderer(eventHandler, eventListener, audioSink) + out.add(extensionRendererIndex++, renderer) + Log.i(TAG, "Loaded FfmpegAudioRenderer.") + } catch (e: Exception) { + // The extension is present, but instantiation failed. + throw RuntimeException("Error instantiating Ffmpeg extension", e) + } + } + + override fun buildVideoRenderers( + context: Context, + extensionRendererMode: Int, + mediaCodecSelector: MediaCodecSelector, + enableDecoderFallback: Boolean, + eventHandler: Handler, + eventListener: VideoRendererEventListener, + allowedVideoJoiningTimeMs: Long, + out: ArrayList + ) { + super.buildVideoRenderers( + context, + extensionRendererMode, + mediaCodecSelector, + enableDecoderFallback, + eventHandler, + eventListener, + allowedVideoJoiningTimeMs, + out + ) + + if (extensionRendererMode == EXTENSION_RENDERER_MODE_OFF) return + + var extensionRendererIndex = out.size + if (extensionRendererMode == EXTENSION_RENDERER_MODE_PREFER) { + extensionRendererIndex-- + } + + try { + val renderer = FfmpegVideoRenderer(allowedVideoJoiningTimeMs, eventHandler, eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY) + out.add(extensionRendererIndex++, renderer) + Log.i(TAG, "Loaded FfmpegVideoRenderer.") + } catch (e: java.lang.Exception) { + // The extension is present, but instantiation failed. + throw java.lang.RuntimeException("Error instantiating Ffmpeg extension", e) + } + } + + companion object { + const val TAG = "NextRenderersFactory" + } +} \ No newline at end of file