Skip to content

Commit 842e054

Browse files
committed
fu rtmp
1 parent 22b7c80 commit 842e054

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ A RTMP client and server (soon) library for Kotlin Multiplatform.
66

77
Features:
88

9-
- [x] RTMP publish client
10-
- [ ] RTMP play client
11-
- [ ] RTMP play2 client
12-
- [ ] RTMP server
9+
- [x] RTMP client
10+
- [x] RTMP server
1311
- [ ] Statistics
12+
- [x] Support for legacy RTMP
13+
- [x] Support for enhanced RTMP v2: AV1, HEVC, VP8, VP9
1414

1515
Supported protocols:
1616

@@ -43,7 +43,7 @@ Then prepare your live by sending these messages to the server:
4343
```kotlin
4444
client.connect()
4545
client.createStream()
46-
client.publish(Command.Publish.Type.LIVE)
46+
client.publish(StreamPublishType.LIVE)
4747
```
4848

4949
If you already have FLV data, write your video/audio data:

rtmp/src/commonMain/kotlin/io/github/thibaultbee/krtmp/rtmp/messages/command/ConnectObject.kt

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ enum class ObjectEncoding(val value: Int) {
4949
* @param videoFunction The supported (by the client) video functions
5050
* @param pageUrl The URL of the web page in which the media was embedded
5151
* @param objectEncoding The AMF encoding version
52+
* @param audioTrackIdInfoMap The audio track ID information map (enhanced RTMP v2)
53+
* @param videoFourCcInfoMap The video FourCC information map (enhanced RTMP v2)
54+
* @param capsEx The extended capabilities of the client (enhanced RTMP v2)
5255
*/
5356
class ConnectObjectBuilder(
5457
var app: String,
@@ -61,7 +64,10 @@ class ConnectObjectBuilder(
6164
var videoCodecs: List<VideoMediaType>? = DEFAULT_VIDEO_CODECS,
6265
var videoFunction: List<ConnectObject.VideoFunction> = DEFAULT_VIDEO_FUNCTION,
6366
var pageUrl: String? = null,
64-
var objectEncoding: ObjectEncoding = ObjectEncoding.AMF0
67+
var objectEncoding: ObjectEncoding = ObjectEncoding.AMF0,
68+
var audioTrackIdInfoMap: Map<AudioMediaType, List<ConnectObject.FourCCInfo>>? = null,
69+
var videoFourCcInfoMap: Map<VideoMediaType, List<ConnectObject.FourCCInfo>>? = null,
70+
var capsEx: List<ConnectObject.CapsEx>? = null,
6571
) {
6672
fun build() = ConnectObject(
6773
app,
@@ -87,7 +93,22 @@ class ConnectObjectBuilder(
8793
acc or vFunction.value
8894
}.toDouble(),
8995
pageUrl,
90-
objectEncoding.value.toDouble()
96+
objectEncoding.value.toDouble(),
97+
audioTrackIdInfoMap?.entries?.filter { it.key.fourCCs != null }?.associate {
98+
it.key.fourCCs!!.value.toString() to
99+
it.value.fold(0) { acc, fourCCInfo ->
100+
acc or fourCCInfo.value
101+
}.toDouble()
102+
},
103+
videoFourCcInfoMap?.entries?.filter { it.key.fourCCs != null }?.associate {
104+
it.key.fourCCs!!.value.toString() to
105+
it.value.fold(0) { acc, fourCCInfo ->
106+
acc or fourCCInfo.value
107+
}.toDouble()
108+
},
109+
capsEx?.fold(0) { acc, capEx ->
110+
acc or capEx.value
111+
}?.toDouble()
91112
)
92113
}
93114

@@ -101,9 +122,12 @@ class ConnectObjectBuilder(
101122
* @param fpad True if proxy is used
102123
* @param audioCodecs The supported (by the client) audio codecs
103124
* @param videoCodecs The supported (by the client) video codecs
104-
* @param fourCcList The supported (by the client) video codecs (extended RTMP)
125+
* @param fourCcList The supported (by the client) video codecs (enhanced RTMP v1)
105126
* @param pageUrl The URL of the web page in which the media was embedded
106127
* @param objectEncoding The AMF encoding version
128+
* @param audioTrackIdInfoMap The audio track ID information map (enhanced RTMP v2)
129+
* @param videoTrackIdInfoMap The video track ID information map (enhanced RTMP v2)
130+
* @param capsEx The extended capabilities of the client (enhanced RTMP v2)
107131
*/
108132
@Serializable
109133
class ConnectObject
@@ -119,7 +143,10 @@ internal constructor(
119143
val fourCcList: List<String>?,
120144
val videoFunction: Double = 0.0,
121145
val pageUrl: String?,
122-
val objectEncoding: Double = ObjectEncoding.AMF0.value.toDouble()
146+
val objectEncoding: Double = ObjectEncoding.AMF0.value.toDouble(),
147+
val audioTrackIdInfoMap: Map<String, Double>? = null,
148+
val videoTrackIdInfoMap: Map<String, Double>? = null,
149+
val capsEx: Double? = null
123150
) {
124151
override fun toString(): String {
125152
return "ConnectObject(app='$app', flashVer='$flashVer', tcUrl='$tcUrl', swfUrl=$swfUrl, fpad=$fpad, capabilities=$capabilities, audioCodecs=$audioCodecs, videoCodecs=$videoCodecs, fourCcList=$fourCcList, videoFunction=$videoFunction, pageUrl=$pageUrl, objectEncoding=$objectEncoding)"
@@ -136,7 +163,7 @@ internal constructor(
136163
VideoMediaType.SORENSON_H263, VideoMediaType.AVC
137164
)
138165
}
139-
166+
140167
enum class AudioCodec(val value: Int, val mediaType: AudioMediaType?) {
141168
NONE(0x0001, null),
142169
ADPCM(0x0002, AudioMediaType.ADPCM),
@@ -214,4 +241,17 @@ internal constructor(
214241
CLIENT_PACKET_TYPE_METADATA(0x4),
215242
CLIENT_LARGE_SCALE_TILE(0x8),
216243
}
244+
245+
enum class CapsEx(val value: Int) {
246+
RECONNECT(0x01),
247+
MULTITRACK(0x02),
248+
MODEX(0x04),
249+
TIMESTAMP_NANO_OFFSET(0x08),
250+
}
251+
252+
enum class FourCCInfo(val value: Int) {
253+
CAN_DECODE(0x01),
254+
CAN_ENCODE(0x02),
255+
CAN_FORWARD(0x04),
256+
}
217257
}

samples/rtmpclient-cli/src/main/kotlin/Main.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,10 @@ class RTMPClientCli : SuspendingCliktCommand() {
5959

6060
val header = parser.decodeFlvHeader()
6161
echo("Parsed FLV header: $header")
62-
63-
/*
62+
6463
parser.decodeAllRaw { tag ->
6564
echo("Sending: $tag")
6665
client.write(tag)
67-
}*/
68-
parser.decodeAll { tag ->
69-
echo("Sending: $tag")
70-
client.write(tag)
7166
}
7267
} catch (t: Throwable) {
7368
echo("Error reading FLV file: ${t.message}")

0 commit comments

Comments
 (0)