Skip to content

Commit

Permalink
refactor(core): refactor how the encoder are handled. Avoid to recrea…
Browse files Browse the repository at this point in the history
…te a new `MediaCodec` when `stopStream` and `startStream` are called.
  • Loading branch information
ThibaultBee committed Apr 3, 2024
1 parent 82c64cd commit 904a2c6
Show file tree
Hide file tree
Showing 28 changed files with 1,149 additions and 859 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package io.github.thibaultbee.streampack.data

import android.media.MediaFormat
import io.github.thibaultbee.streampack.internal.encoders.MediaCodecHelper
import io.github.thibaultbee.streampack.internal.encoders.mediacodec.MediaCodecHelper
import io.github.thibaultbee.streampack.streamers.bases.BaseStreamer

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import android.media.MediaFormat
import android.media.MediaFormat.KEY_PRIORITY
import android.os.Build
import android.util.Size
import io.github.thibaultbee.streampack.internal.encoders.MediaCodecHelper
import io.github.thibaultbee.streampack.internal.encoders.mediacodec.MediaCodecHelper
import io.github.thibaultbee.streampack.internal.utils.av.video.DynamicRangeProfile
import io.github.thibaultbee.streampack.internal.utils.extensions.isDevicePortrait
import io.github.thibaultbee.streampack.internal.utils.extensions.isVideo
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,125 @@
*/
package io.github.thibaultbee.streampack.internal.encoders

import io.github.thibaultbee.streampack.internal.interfaces.Configurable
import android.view.Surface
import io.github.thibaultbee.streampack.internal.data.Frame
import io.github.thibaultbee.streampack.internal.interfaces.Releaseable
import io.github.thibaultbee.streampack.internal.interfaces.Streamable
import io.github.thibaultbee.streampack.internal.interfaces.SuspendStreamable
import java.nio.ByteBuffer
import java.util.concurrent.Executor


interface IEncoderParameters {
val mimeType: String
val startBitrate: Int
var bitrate: Int
}

interface IEncoder : SuspendStreamable, Releaseable {
interface IEncoderListener {
/**
* Calls when an encoder has an error.
*/
fun onError(e: Exception) {}

/**
* Calls when an encoder has generated an output frame.
* @param frame Output frame with correct parameters and buffers
*/
fun onOutputFrame(frame: Frame) {}
}

/**
* The encoder mime type
* @see List of audio/video mime type on <a href="https://developer.android.com/reference/android/media/MediaFormat">Android developer guide</a>
*/
val mimeType: String

interface IEncoder<T> : Streamable, Configurable<T>, Releaseable {
/**
* Input and output of an async encoder
* The bitrate at which the encoder will start (ie the one in the configuration)
*/
val encoderListener: IEncoderListener
val startBitrate: Int

/**
* Get encoder mime type
* @return a string corresponding to a media mime type
* @see List of audio/video mime type on <a href="https://developer.android.com/reference/android/media/MediaFormat">Android developer guide</a>
* Gets/sets encoder bitrate.
*
* The setter is only applicable for video encoders. On audio encoders, it will throw an exception.
*/
var bitrate: Int

/**
* The encoder info like the supported resolutions, bitrates, etc.
*/
val info: IEncoderInfo

interface IEncoderInfo {
/**
* The encoder name
*/
val name: String
}

/**
* The encoder input.
* @see IEncoderInput
*/
val input: IEncoderInput

interface IEncoderInput

/**
* The [Surface] input
*/
interface ISurfaceInput : IEncoderInput {
/**
* The surface update listener
*/
var listener: OnSurfaceUpdateListener

interface OnSurfaceUpdateListener {
fun onSurfaceUpdated(surface: Surface) {}
}
}

/**
* The [ByteBuffer] input
*/
interface IByteBufferInput : IEncoderInput {
/**
* The buffer available listener
*/
var listener: OnFrameRequestedListener

interface OnFrameRequestedListener {
/**
* Calls when a buffer is available for encoding.
*
* @param buffer the buffer where to write the frame
*/
fun onFrameRequested(buffer: ByteBuffer): Frame
}
}

/**
* Force the encoder to generate a key frame.
*/
fun requestKeyFrame()

/**
* Set the encoder listener
*
* @param listener the listener
* @param listenerExecutor the executor where the listener will be called
*/
fun setListener(listener: IEncoderListener, listenerExecutor: Executor)

/**
* Reset the encoder
*/
fun reset()

/**
* Configure the encoder
*/
val mimeType: String?
}
fun configure()
}

This file was deleted.

Loading

0 comments on commit 904a2c6

Please sign in to comment.