Skip to content

Commit

Permalink
refactor(*): rename RtmpConnection and SrtConnection to RtmpConnectio…
Browse files Browse the repository at this point in the history
…nDescriptor and SrtConnectionDescriptor
  • Loading branch information
ThibaultBee committed Dec 26, 2023
1 parent 78e34bd commit 247e142
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.content.Context
import android.os.Build
import androidx.annotation.RequiresPermission
import io.github.thibaultbee.streampack.app.configuration.Configuration
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnection
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnectionDescriptor
import io.github.thibaultbee.streampack.ext.srt.streamers.interfaces.ISrtLiveStreamer
import io.github.thibaultbee.streampack.listeners.OnConnectionListener
import io.github.thibaultbee.streampack.listeners.OnErrorListener
Expand Down Expand Up @@ -96,7 +96,7 @@ class StreamerManager(
suspend fun startStream() {
if (streamer?.getLiveStreamer() != null) {
getSrtLiveStreamer()?.let {
val connection = SrtConnection(
val connection = SrtConnectionDescriptor(
configuration.endpoint.srt.ip,
configuration.endpoint.srt.port,
configuration.endpoint.srt.streamID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import io.github.thibaultbee.streampack.data.AudioConfig
import io.github.thibaultbee.streampack.data.BitrateRegulatorConfig
import io.github.thibaultbee.streampack.data.VideoConfig
import io.github.thibaultbee.streampack.ext.rtmp.services.ScreenRecorderRtmpLiveService
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnection
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnectionDescriptor
import io.github.thibaultbee.streampack.ext.srt.services.ScreenRecorderSrtLiveService
import io.github.thibaultbee.streampack.ext.srt.streamers.interfaces.ISrtLiveStreamer
import io.github.thibaultbee.streampack.internal.encoders.MediaCodecHelper
Expand Down Expand Up @@ -215,7 +215,7 @@ class MainActivity : AppCompatActivity() {

runBlocking {
streamer.getStreamer<ISrtLiveStreamer>()?.let {
val connection = SrtConnection(
val connection = SrtConnectionDescriptor(
configuration.endpoint.srt.ip,
configuration.endpoint.srt.port,
configuration.endpoint.srt.streamID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Test

class RtmpConnectionTest {
class RtmpConnectionDescriptorTest {
@Test
fun fromUrl() {
val url = "rtmp://broadcast.host.com:1234/app/streamKey"
val connection = RtmpConnection.fromUrl(url)
val connection = RtmpConnectionDescriptor.fromUrl(url)
assertEquals("rtmp", connection.scheme)
assertEquals("broadcast.host.com", connection.host)
assertEquals(1234, connection.port)
Expand All @@ -34,7 +34,7 @@ class RtmpConnectionTest {
@Test
fun fromRtmpsUrl() {
val url = "rtmps://broadcast.host.com:1234/app/streamKey"
val connection = RtmpConnection.fromUrl(url)
val connection = RtmpConnectionDescriptor.fromUrl(url)
assertEquals("rtmps", connection.scheme)
assertEquals("broadcast.host.com", connection.host)
assertEquals(1234, connection.port)
Expand All @@ -45,7 +45,7 @@ class RtmpConnectionTest {
@Test
fun fromUrlWithDefaultPort() {
val url = "rtmp://broadcast.host.com/app/streamKey"
val connection = RtmpConnection.fromUrl(url)
val connection = RtmpConnectionDescriptor.fromUrl(url)
assertEquals("rtmp", connection.scheme)
assertEquals("broadcast.host.com", connection.host)
assertEquals(1935, connection.port)
Expand All @@ -56,7 +56,7 @@ class RtmpConnectionTest {
@Test
fun fromRtmpsUrlWithDefaultPort() {
val url = "rtmps://broadcast.host.com/app/streamKey"
val connection = RtmpConnection.fromUrl(url)
val connection = RtmpConnectionDescriptor.fromUrl(url)
assertEquals("rtmps", connection.scheme)
assertEquals("broadcast.host.com", connection.host)
assertEquals(443, connection.port)
Expand All @@ -68,7 +68,7 @@ class RtmpConnectionTest {
fun fromUrlWithBadScheme() {
val url = "rtp://broadcast.host.com:1234/app/streamKey"
try {
RtmpConnection.fromUrl(url)
RtmpConnectionDescriptor.fromUrl(url)
Assert.fail("Should throw an exception")
} catch (_: Exception) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import java.security.InvalidParameterException
* @param app the application name
* @param streamKey the stream key
*/
data class RtmpConnection(
data class RtmpConnectionDescriptor(
val scheme: String, val host: String, val port: Int, val app: String, val streamKey: String
) {
val uri = Uri.Builder()
Expand Down Expand Up @@ -67,7 +67,7 @@ data class RtmpConnection(
* @param url the server url (syntax: rtmp://host:port/app/streamKey)
* @return RTMP connection
*/
fun fromUrl(url: String): RtmpConnection {
fun fromUrl(url: String): RtmpConnectionDescriptor {
val uri = Uri.parse(url)

val scheme =
Expand All @@ -90,7 +90,7 @@ data class RtmpConnection(
val app = uri.pathSegments.minus(uri.lastPathSegment).joinToString("/")
val streamKey = uri.lastPathSegment
?: throw InvalidParameterException("Invalid streamKey ${uri.lastPathSegment}")
return RtmpConnection(scheme, host, port, app, streamKey)
return RtmpConnectionDescriptor(scheme, host, port, app, streamKey)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.github.thibaultbee.streampack.ext.rtmp.internal.endpoints

import io.github.thibaultbee.streampack.ext.rtmp.data.RtmpConnection
import io.github.thibaultbee.streampack.ext.rtmp.data.RtmpConnectionDescriptor
import io.github.thibaultbee.streampack.internal.data.Packet
import io.github.thibaultbee.streampack.internal.endpoints.ILiveEndpoint
import io.github.thibaultbee.streampack.listeners.OnConnectionListener
Expand Down Expand Up @@ -50,7 +50,7 @@ class RtmpProducer(
}

override suspend fun connect(url: String) {
RtmpConnection.fromUrl(url) // URL validation
RtmpConnectionDescriptor.fromUrl(url) // URL validation

withContext(coroutineDispatcher) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Test

class SrtConnectionTest {
class SrtConnectionDescriptorTest {
@Test
fun fromUrl() {
val url = "srt://broadcast.host.com:1234"
val connection = SrtConnection.fromUrl(url)
val connection = SrtConnectionDescriptor.fromUrl(url)
assertEquals("broadcast.host.com", connection.host)
assertEquals(1234, connection.port)
}

@Test
fun fromIp() {
val url = "srt://192.168.1.12:1234"
val connection = SrtConnection.fromUrl(url)
val connection = SrtConnectionDescriptor.fromUrl(url)
assertEquals("192.168.1.12", connection.host)
assertEquals(1234, connection.port)
}

@Test
fun fromUrlWithParameters() {
val url = "srt://host.com:1234?streamid=streamId&passphrase=passPhrase"
val connection = SrtConnection.fromUrl(url)
val connection = SrtConnectionDescriptor.fromUrl(url)
assertEquals("host.com", connection.host)
assertEquals(1234, connection.port)
assertEquals("streamId", connection.streamId)
Expand All @@ -50,7 +50,7 @@ class SrtConnectionTest {
fun fromUrlWithBadScheme() {
val url = "srtp://broadcast.host.com:1234"
try {
SrtConnection.fromUrl(url)
SrtConnectionDescriptor.fromUrl(url)
fail("Should throw an exception")
} catch (_: Exception) {
}
Expand All @@ -60,7 +60,7 @@ class SrtConnectionTest {
fun fromUrlWithUnknownParam() {
val url = "srt://host.com:1234?streamid=streamId&passphrase=passPhrase&unknown=unknown"
try {
SrtConnection.fromUrl(url)
SrtConnectionDescriptor.fromUrl(url)
} catch (e: Exception) {
assertEquals("Failed to parse URL $url: unknown parameter(s): unknown", e.message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.security.InvalidParameterException
* @param latency SRT latency in ms
* @param connectionTimeout SRT connection timeout in ms
*/
data class SrtConnection(
data class SrtConnectionDescriptor(
val host: String,
val port: Int,
val streamId: String? = null,
Expand Down Expand Up @@ -71,7 +71,7 @@ data class SrtConnection(
* @param url server url (syntax: srt://host:port?streamid=streamId&passphrase=passPhrase)
* @return SRT connection
*/
fun fromUrl(url: String): SrtConnection {
fun fromUrl(url: String): SrtConnectionDescriptor {
val uri = Uri.parse(url)
if (uri.scheme != SRT_SCHEME) {
throw InvalidParameterException("URL $url is not an srt URL")
Expand All @@ -92,7 +92,7 @@ data class SrtConnection(
throw InvalidParameterException("Failed to parse URL $url: unknown parameter(s): $unknownParameters")
}

return SrtConnection(
return SrtConnectionDescriptor(
host,
port,
streamId,
Expand All @@ -115,7 +115,7 @@ data class SrtConnection(
url: String,
streamId: String? = null,
passPhrase: String? = null
): SrtConnection {
): SrtConnectionDescriptor {
val uri = Uri.parse(url)
if (uri.scheme != SRT_SCHEME) {
throw InvalidParameterException("URL $url is not an srt URL")
Expand All @@ -124,7 +124,7 @@ data class SrtConnection(
?: throw InvalidParameterException("Failed to parse URL $url: unknown host")
val port = uri.port

return SrtConnection(host, port, streamId, passPhrase)
return SrtConnectionDescriptor(host, port, streamId, passPhrase)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import io.github.thibaultbee.srtdroid.listeners.SocketListener
import io.github.thibaultbee.srtdroid.models.MsgCtrl
import io.github.thibaultbee.srtdroid.models.Socket
import io.github.thibaultbee.srtdroid.models.Stats
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnection
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnectionDescriptor
import io.github.thibaultbee.streampack.internal.data.Packet
import io.github.thibaultbee.streampack.internal.data.SrtPacket
import io.github.thibaultbee.streampack.internal.endpoints.ILiveEndpoint
Expand Down Expand Up @@ -88,9 +88,9 @@ class SrtProducer(
this.bitrate = config.toLong()
}

override suspend fun connect(url: String) = connect(SrtConnection.fromUrl(url))
override suspend fun connect(url: String) = connect(SrtConnectionDescriptor.fromUrl(url))

suspend fun connect(connection: SrtConnection) {
suspend fun connect(connection: SrtConnectionDescriptor) {
withContext(coroutineDispatcher) {
try {
socket.listener = object : SocketListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package io.github.thibaultbee.streampack.ext.srt.streamers

import android.content.Context
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnection
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnectionDescriptor
import io.github.thibaultbee.streampack.ext.srt.internal.endpoints.SrtProducer
import io.github.thibaultbee.streampack.ext.srt.streamers.interfaces.ISrtLiveStreamer
import io.github.thibaultbee.streampack.internal.muxers.ts.TSMuxer
Expand Down Expand Up @@ -114,7 +114,7 @@ class AudioOnlySrtLiveStreamer(
replaceWith = ReplaceWith("connect(SrtConnection)")
)
override suspend fun connect(ip: String, port: Int) {
val connection = SrtConnection(ip, port)
val connection = SrtConnectionDescriptor(ip, port)
srtProducer.connect(connection)
}

Expand All @@ -125,7 +125,7 @@ class AudioOnlySrtLiveStreamer(
* @param connection the SRT connection
* @throws Exception if connection has failed or configuration has failed
*/
override suspend fun connect(connection: SrtConnection) {
override suspend fun connect(connection: SrtConnectionDescriptor) {
srtProducer.connect(connection)
}

Expand All @@ -143,7 +143,7 @@ class AudioOnlySrtLiveStreamer(
replaceWith = ReplaceWith("startStream(SrtConnection)")
)
override suspend fun startStream(ip: String, port: Int) {
val connection = SrtConnection(ip, port)
val connection = SrtConnectionDescriptor(ip, port)
startStream(connection)
}

Expand All @@ -155,7 +155,7 @@ class AudioOnlySrtLiveStreamer(
* @param connection the SRT connection
* @throws Exception if connection has failed or configuration has failed or [startStream] has failed too.
*/
override suspend fun startStream(connection: SrtConnection) {
override suspend fun startStream(connection: SrtConnectionDescriptor) {
connect(connection)
startStream()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package io.github.thibaultbee.streampack.ext.srt.streamers

import android.content.Context
import io.github.thibaultbee.streampack.data.BitrateRegulatorConfig
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnection
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnectionDescriptor
import io.github.thibaultbee.streampack.ext.srt.internal.endpoints.SrtProducer
import io.github.thibaultbee.streampack.ext.srt.regulator.srt.SrtBitrateRegulator
import io.github.thibaultbee.streampack.ext.srt.streamers.interfaces.ISrtLiveStreamer
Expand Down Expand Up @@ -146,7 +146,7 @@ class CameraSrtLiveStreamer(
replaceWith = ReplaceWith("connect(SrtConnection)")
)
override suspend fun connect(ip: String, port: Int) {
val connection = SrtConnection(ip, port)
val connection = SrtConnectionDescriptor(ip, port)
srtProducer.connect(connection)
}

Expand All @@ -157,7 +157,7 @@ class CameraSrtLiveStreamer(
* @param connection the SRT connection
* @throws Exception if connection has failed or configuration has failed
*/
override suspend fun connect(connection: SrtConnection) {
override suspend fun connect(connection: SrtConnectionDescriptor) {
srtProducer.connect(connection)
}

Expand Down Expand Up @@ -195,7 +195,7 @@ class CameraSrtLiveStreamer(
replaceWith = ReplaceWith("startStream(SrtConnection)")
)
override suspend fun startStream(ip: String, port: Int) {
val connection = SrtConnection(ip, port)
val connection = SrtConnectionDescriptor(ip, port)
startStream(connection)
}

Expand All @@ -207,7 +207,7 @@ class CameraSrtLiveStreamer(
* @param connection the SRT connection
* @throws Exception if connection has failed or configuration has failed or [startStream] has failed too.
*/
override suspend fun startStream(connection: SrtConnection) {
override suspend fun startStream(connection: SrtConnectionDescriptor) {
connect(connection)
startStream()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.github.thibaultbee.streampack.ext.srt.streamers
import android.app.Service
import android.content.Context
import io.github.thibaultbee.streampack.data.BitrateRegulatorConfig
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnection
import io.github.thibaultbee.streampack.ext.srt.data.SrtConnectionDescriptor
import io.github.thibaultbee.streampack.ext.srt.internal.endpoints.SrtProducer
import io.github.thibaultbee.streampack.ext.srt.regulator.srt.SrtBitrateRegulator
import io.github.thibaultbee.streampack.ext.srt.services.ScreenRecorderSrtLiveService
Expand Down Expand Up @@ -152,7 +152,7 @@ class ScreenRecorderSrtLiveStreamer(
replaceWith = ReplaceWith("connect(SrtConnection)")
)
override suspend fun connect(ip: String, port: Int) {
val connection = SrtConnection(ip, port)
val connection = SrtConnectionDescriptor(ip, port)
srtProducer.connect(connection)
}

Expand All @@ -163,7 +163,7 @@ class ScreenRecorderSrtLiveStreamer(
* @param connection the SRT connection
* @throws Exception if connection has failed or configuration has failed
*/
override suspend fun connect(connection: SrtConnection) {
override suspend fun connect(connection: SrtConnectionDescriptor) {
srtProducer.connect(connection)
}

Expand Down Expand Up @@ -201,7 +201,7 @@ class ScreenRecorderSrtLiveStreamer(
replaceWith = ReplaceWith("startStream(SrtConnection)")
)
override suspend fun startStream(ip: String, port: Int) {
val connection = SrtConnection(ip, port)
val connection = SrtConnectionDescriptor(ip, port)
startStream(connection)
}

Expand All @@ -213,7 +213,7 @@ class ScreenRecorderSrtLiveStreamer(
* @param connection the SRT connection
* @throws Exception if connection has failed or configuration has failed or [startStream] has failed too.
*/
override suspend fun startStream(connection: SrtConnection) {
override suspend fun startStream(connection: SrtConnectionDescriptor) {
connect(connection)
startStream()
}
Expand Down
Loading

0 comments on commit 247e142

Please sign in to comment.