Skip to content

Commit

Permalink
refactor(core): use 2 different interfaces for audio and video source…
Browse files Browse the repository at this point in the history
… in case there areboth audio and video sources
  • Loading branch information
ThibaultBee committed Jan 14, 2025
1 parent c96327d commit 650f7be
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2021 Thibault B.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.thibaultbee.streampack.core.elements.sources.audio

import io.github.thibaultbee.streampack.core.elements.data.Frame
import java.nio.ByteBuffer

interface IAudioFrameSource {

/**
* Gets an audio frame from the source.
*
* @param buffer buffer where to write data. Must be set as buffer of returned Frame
* @return frame with correct infos (at least buffer, mime type and pts)
*/
fun getAudioFrame(buffer: ByteBuffer): Frame
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ package io.github.thibaultbee.streampack.core.elements.sources.audio
import io.github.thibaultbee.streampack.core.elements.interfaces.Configurable
import io.github.thibaultbee.streampack.core.elements.interfaces.Releasable
import io.github.thibaultbee.streampack.core.elements.interfaces.Streamable
import io.github.thibaultbee.streampack.core.elements.sources.IFrameSource

interface IAudioSourceInternal : IAudioSource, IFrameSource, Streamable,
interface IAudioSourceInternal : IAudioSource, IAudioFrameSource, Streamable,
Configurable<AudioSourceConfig>, Releasable

interface IAudioSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ sealed class AudioRecordSource : IAudioSourceInternal, IAudioRecordSource {
return timestamp
}

override fun getFrame(buffer: ByteBuffer): Frame {
override fun getAudioFrame(buffer: ByteBuffer): Frame {
val audioRecord = requireNotNull(audioRecord)
val length = audioRecord.read(buffer, buffer.remaining())
if (length >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.thibaultbee.streampack.core.elements.sources
package io.github.thibaultbee.streampack.core.elements.sources.video

import io.github.thibaultbee.streampack.core.elements.data.Frame
import java.nio.ByteBuffer

interface IFrameSource {
interface IVideoFrameSource {

/**
* Generate a frame from capture device
* Gets a video frame from a source.
* @param buffer buffer where to write data. Must be set as buffer of returned Frame
* @return frame with correct infos (at least buffer, mime type and pts)
*/
fun getFrame(buffer: ByteBuffer): Frame
fun getVideoFrame(buffer: ByteBuffer): Frame
}
18 changes: 11 additions & 7 deletions docs/StreamerElements.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ interface ISurfaceSource {
+ outputSurface: Surface?
}
interface IFrameSource {
+ getFrame(buffer: ByteBuffer): Frame
interface IVideoFrameSource {
+ getVideoFrame(buffer: ByteBuffer): Frame
}
interface IVideoSource {
Expand All @@ -105,11 +105,15 @@ interface IVideoSource {
class CameraSource {
}
CameraSource <|.. ISurfaceSource
CameraSource <|.. IVideoFrameSource
CameraSource <|.. IVideoSource
interface IAudioFrameSource {
+ getAudioFrame(buffer: ByteBuffer): Frame
}
interface IAudioSource
IAudioSource <|.. IFrameSource
IAudioSource <|.. IAudioFrameSource
class MicrophoneSource {
}
Expand All @@ -118,11 +122,11 @@ MicrophoneSource <|.. IAudioSource
@enduml
-->

To create a new audio source, implements a `IAudioSource`. It inherits from `IFrameSource`.
To create a new audio source, implements a `IAudioSource`. It inherits from `IAudioFrameSource`.

To create a new video source, implements a `IVideoSource` and `IFrameSource`
To create a new video source, implements a `IVideoSource` and `IVideoFrameSource`
or `ISurfaceSource`. Always prefer to use a video source as a `Surface` source if it is possible.
`IFrameSource` has missing features and is not be stable.
`IVideoFrameSource` has missing features and is not be stable.

### Encoders

Expand Down

0 comments on commit 650f7be

Please sign in to comment.