You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB
Kotlin

package com.yinuo.library.vlc
import com.common.commonlib.CommonApplication
import com.yinuo.library.vlc.utils.LogUtils
import org.easydarwin.push.EasyPusher
import org.easydarwin.push.InitCallback
import org.easydarwin.push.Pusher
object PushHelper {
private val mPusher: EasyPusher by lazy {
EasyPusher()
}
private val mApplicationContext = CommonApplication.getContext()
private var mHeight: Int = 0
private var mWidth: Int = 0
init {
setPushUrl("")
}
var callback = InitCallback { code ->
var msg = ""
when (code) {
EasyPusher.OnInitPusherCallback.CODE.EASY_ACTIVATE_INVALID_KEY -> msg = "无效Key"
EasyPusher.OnInitPusherCallback.CODE.EASY_ACTIVATE_SUCCESS -> msg = "未开始"
EasyPusher.OnInitPusherCallback.CODE.EASY_PUSH_STATE_CONNECTING -> msg = "连接中"
EasyPusher.OnInitPusherCallback.CODE.EASY_PUSH_STATE_CONNECTED -> msg = "连接成功"
EasyPusher.OnInitPusherCallback.CODE.EASY_PUSH_STATE_CONNECT_FAILED -> msg = "连接失败"
EasyPusher.OnInitPusherCallback.CODE.EASY_PUSH_STATE_CONNECT_ABORT -> msg =
"连接异常中断"
EasyPusher.OnInitPusherCallback.CODE.EASY_PUSH_STATE_PUSHING -> msg = "推流中"
EasyPusher.OnInitPusherCallback.CODE.EASY_PUSH_STATE_DISCONNECTED -> msg = "断开连接"
EasyPusher.OnInitPusherCallback.CODE.EASY_ACTIVATE_PLATFORM_ERR -> msg = "平台不匹配"
EasyPusher.OnInitPusherCallback.CODE.EASY_ACTIVATE_COMPANY_ID_LEN_ERR -> msg =
"授权使用商不匹配"
EasyPusher.OnInitPusherCallback.CODE.EASY_ACTIVATE_PROCESS_NAME_LEN_ERR -> msg =
"进程名称长度不匹配"
}
LogUtils.v("PushHelper. InitCallback $msg")
}
fun configSize(width: Int, height: Int) {
this.mWidth = width
this.mHeight = height
}
fun setPushUrl(url: String) {
initHelper("192.168.5.16", "554", "123")
}
fun stop() {
mPusher.stop()
}
fun pushData(h264: ByteArray, length: Int, timeStamp: Long) {
mPusher.push(h264, 0, length, timeStamp, 1)
}
private fun initHelper(ip: String, port: String, id: String) {
mPusher.initPush(mApplicationContext, callback)
mPusher.setMediaInfo(
Pusher.Codec.EASY_SDK_VIDEO_CODEC_H264,
24,
Pusher.Codec.EASY_SDK_AUDIO_CODEC_AAC,
1,
8000,
16
)
mPusher.start(ip, port, String.format("%s.sdp", id), Pusher.TransType.EASY_RTP_OVER_TCP)
}
@JvmField
var mPpsSps = ByteArray(0)
@JvmField
var h264 = ByteArray(1920 * 1080)
}