Skip to content

Commit

Permalink
Update VideoCodec.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Mar 24, 2024
1 parent 1e272ed commit 9a94be5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 5 additions & 11 deletions haishinkit/src/main/java/com/haishinkit/codec/VideoCodec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class VideoCodec(applicationContext: Context) : Codec() {
throw IllegalArgumentException("Unsupported mime type for ${newValue.mime}.")
}
codec?.outputMimeType = newValue.mime
codec?.profile = newValue.profile
codec?.level = newValue.level
codec?.profileLevel = newValue
}

/**
Expand Down Expand Up @@ -130,12 +129,7 @@ class VideoCodec(applicationContext: Context) : Codec() {
/**
* Specifies the profile for a video output.
*/
var profile = DEFAULT_PROFILE_LEVEL.profile

/**
* Specifies the profile-level for a video outout.
*/
var level = DEFAULT_PROFILE_LEVEL.level
var profileLevel: VideoCodecProfileLevel = VideoCodecProfileLevel.H264_BASELINE_3_2

/**
* The pixel transform instance.
Expand Down Expand Up @@ -174,11 +168,11 @@ class VideoCodec(applicationContext: Context) : Codec() {
setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1)
setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFrameInterval)
setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat)
setInteger(MediaFormat.KEY_PROFILE, profile)
setInteger(MediaFormat.KEY_PROFILE, profileLevel.profile)
if (Build.VERSION_CODES.M <= Build.VERSION.SDK_INT) {
setInteger(MediaFormat.KEY_LEVEL, level)
setInteger(MediaFormat.KEY_LEVEL, profileLevel.level)
} else {
setInteger("level", level)
setInteger("level", profileLevel.level)
}
} else {
if (Build.VERSION_CODES.R <= Build.VERSION.SDK_INT) {
Expand Down
14 changes: 13 additions & 1 deletion haishinkit/src/main/java/com/haishinkit/rtmp/RtmpStream.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.haishinkit.rtmp

import android.content.Context
import android.media.MediaFormat
import android.util.Log
import com.haishinkit.codec.Codec
import com.haishinkit.event.Event
Expand Down Expand Up @@ -415,7 +416,18 @@ class RtmpStream(context: Context, internal var connection: RtmpConnection) :
metadata["width"] = videoCodec.width
metadata["height"] = videoCodec.height
metadata["framerate"] = videoCodec.frameRate
metadata["videocodecid"] = RtmpMuxer.FLV_VIDEO_CODEC_AVC.toInt()
when (videoCodec.profileLevel.mime) {
MediaFormat.MIMETYPE_VIDEO_HEVC ->
metadata["videocodecid"] = RtmpMuxer.FLV_VIDEO_FOUR_CC_HEVC

MediaFormat.MIMETYPE_VIDEO_AVC -> {
metadata["videocodecid"] = RtmpMuxer.FLV_VIDEO_CODEC_AVC.toInt()
}

else -> {
Log.w(TAG, "not set a videocodecid for ${videoCodec.profileLevel.mime}")
}
}
metadata["videodatarate"] = videoCodec.bitRate / 1000
}
audioSource?.let {
Expand Down

0 comments on commit 9a94be5

Please sign in to comment.