Skip to content

Commit

Permalink
Merge pull request #68 from chenxiaolong/interface
Browse files Browse the repository at this point in the history
Container: Change to an interface
  • Loading branch information
chenxiaolong authored Jun 4, 2022
2 parents 4db53d6 + bdfc740 commit 091bd5b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
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

0 comments on commit 091bd5b

Please sign in to comment.