Skip to content

Commit

Permalink
feat(rtmp): add support for enhanced RTMP for HEVC
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Oct 21, 2023
1 parent 4aca32c commit ebad206
Show file tree
Hide file tree
Showing 19 changed files with 727 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import io.github.thibaultbee.streampack.internal.data.PacketType
import io.github.thibaultbee.streampack.internal.interfaces.IOrientationProvider
import io.github.thibaultbee.streampack.internal.muxers.IMuxer
import io.github.thibaultbee.streampack.internal.muxers.IMuxerListener
import io.github.thibaultbee.streampack.internal.muxers.flv.packet.FlvHeader
import io.github.thibaultbee.streampack.internal.muxers.flv.packet.FlvTagFactory
import io.github.thibaultbee.streampack.internal.muxers.flv.packet.OnMetadata
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.AVTagsFactory
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.FlvHeader
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.OnMetadata
import io.github.thibaultbee.streampack.internal.utils.TimeUtils
import io.github.thibaultbee.streampack.internal.utils.extensions.isAudio
import io.github.thibaultbee.streampack.internal.utils.extensions.isVideo
Expand Down Expand Up @@ -73,7 +73,7 @@ class FlvMuxer(
}

frame.pts -= startUpTime!!
val flvTags = FlvTagFactory(frame, true, streams[streamPid]).build()
val flvTags = AVTagsFactory(frame, streams[streamPid]).build()
flvTags.forEach {
listener?.onOutputFrame(
Packet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import android.media.MediaFormat
import io.github.thibaultbee.streampack.internal.muxers.IAudioMuxerHelper
import io.github.thibaultbee.streampack.internal.muxers.IMuxerHelper
import io.github.thibaultbee.streampack.internal.muxers.IVideoMuxerHelper
import io.github.thibaultbee.streampack.internal.muxers.flv.packet.CodecID
import io.github.thibaultbee.streampack.internal.muxers.flv.packet.SoundFormat
import io.github.thibaultbee.streampack.internal.muxers.flv.packet.SoundRate
import io.github.thibaultbee.streampack.internal.muxers.flv.packet.SoundSize
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.video.CodecID
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.SoundFormat
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.SoundRate
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.SoundSize

class FlvMuxerHelper : IMuxerHelper {
override val video = VideoFlvMuxerHelper()
Expand All @@ -35,18 +35,21 @@ class VideoFlvMuxerHelper : IVideoMuxerHelper {
*/
override val supportedEncoders: List<String>
get() {
return CodecID.values().mapNotNull {
val extendedSupportedCodec = listOf(
MediaFormat.MIMETYPE_VIDEO_HEVC
)
val supportedCodecList = CodecID.values().mapNotNull {
try {
it.toMimeType()
} catch (e: Exception) {
null
}
}.filter {
listOf(
MediaFormat.MIMETYPE_VIDEO_AVC,
MediaFormat.MIMETYPE_VIDEO_HEVC
MediaFormat.MIMETYPE_VIDEO_AVC
).contains(it)
}
return supportedCodecList + extendedSupportedCodec
}
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2022 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.internal.muxers.flv.tags

import android.media.MediaFormat
import io.github.thibaultbee.streampack.data.AudioConfig
import io.github.thibaultbee.streampack.data.Config
import io.github.thibaultbee.streampack.data.VideoConfig
import io.github.thibaultbee.streampack.internal.data.Frame
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.video.PacketType
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.video.VideoTagFactory
import java.io.IOException

class AVTagsFactory(
private val frame: Frame,
private val config: Config
) {
fun build(): List<FlvTag> {
return if (frame.isVideo) {
createVideoTags(frame, config as VideoConfig)
} else if (frame.isAudio) {
createAudioTags(frame, config as AudioConfig)
} else {
throw IOException("Frame is neither video nor audio: ${frame.mimeType}")
}
}

private fun createAudioTags(
frame: Frame,
config: AudioConfig
): List<FlvTag> {
return listOf(
AudioTag(
frame.pts,
frame.extra!![0],
if (config.mimeType == MediaFormat.MIMETYPE_AUDIO_AAC) {
AACPacketType.SEQUENCE_HEADER
} else {
null
},
config
),
AudioTag(
frame.pts,
frame.buffer,
if (config.mimeType == MediaFormat.MIMETYPE_AUDIO_AAC) {
AACPacketType.RAW
} else {
null
},
config
)
)
}

private fun createVideoTags(
frame: Frame,
config: VideoConfig
): List<FlvTag> {
val videoTags = mutableListOf<FlvTag>()

if (frame.isKeyFrame) {
videoTags.add(
VideoTagFactory(
frame.pts,
frame.extra!!,
true,
PacketType.SEQUENCE_START,
config.mimeType
).build()
)
}

videoTags.add(
VideoTagFactory(
frame.pts,
frame.buffer,
frame.isKeyFrame,
PacketType.CODED_FRAMES_X, // For extended codec onlu.
config.mimeType
).build()
)

return videoTags
}
}
Loading

0 comments on commit ebad206

Please sign in to comment.