Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container: Change to an interface #68

Merged
merged 1 commit into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions app/src/main/java/com/chiller3/bcr/format/Container.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import java.nio.ByteBuffer
/**
* Abstract class for writing encoded samples to a container format.
*/
sealed class Container {
interface Container {
/**
* Start the muxer process.
*
* Must be called before [writeSamples].
*/
abstract fun start()
fun start()

/**
* Stop the muxer process.
*
* Must not be called if [start] did not complete successfully.
*/
abstract fun stop()
fun stop()

/**
* Free resources used by the muxer process.
*
* Can be called in any state. If the muxer process is started, it will be stopped.
*/
abstract fun release()
fun release()

/**
* Add a track to the container with the specified format.
Expand All @@ -36,7 +36,7 @@ sealed class Container {
*
* @param mediaFormat Must be the instance returned by [MediaCodec.getOutputFormat]
*/
abstract fun addTrack(mediaFormat: MediaFormat): Int
fun addTrack(mediaFormat: MediaFormat): Int

/**
* Write encoded samples to the output container.
Expand All @@ -45,6 +45,5 @@ sealed class Container {
*
* @param trackIndex Must be an index returned by [addTrack]
*/
abstract fun writeSamples(trackIndex: Int, byteBuffer: ByteBuffer,
bufferInfo: MediaCodec.BufferInfo)
fun writeSamples(trackIndex: Int, byteBuffer: ByteBuffer, bufferInfo: MediaCodec.BufferInfo)
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/chiller3/bcr/format/FlacContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.nio.ByteBuffer
* @param fd Output file descriptor. This class does not take ownership of it and it should not
* be touched outside of this class until [stop] is called and returns.
*/
class FlacContainer(private val fd: FileDescriptor) : Container() {
class FlacContainer(private val fd: FileDescriptor) : Container {
private var isStarted = false
private var lastPresentationTimeUs = -1L
private var track = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.nio.ByteBuffer
class MediaMuxerContainer(
fd: FileDescriptor,
containerFormat: Int,
) : Container() {
) : Container {
private val muxer = MediaMuxer(fd, containerFormat)

override fun start() =
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/chiller3/bcr/format/WaveContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.io.FileDescriptor
import java.nio.ByteBuffer
import java.nio.ByteOrder

class WaveContainer(private val fd: FileDescriptor) : Container() {
class WaveContainer(private val fd: FileDescriptor) : Container {
private var isStarted = false
private var track = -1
private var frameSize = 0
Expand Down