|
|
|
@ -1,11 +1,13 @@
|
|
|
|
|
package com.yinuo.library.vlc
|
|
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
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 {
|
|
|
|
@ -14,12 +16,11 @@ object PushHelper {
|
|
|
|
|
|
|
|
|
|
private val mApplicationContext = CommonApplication.getContext()
|
|
|
|
|
|
|
|
|
|
private var mHeight: Int = 0
|
|
|
|
|
private var mWidth: Int = 0
|
|
|
|
|
private var mIp: String? = null
|
|
|
|
|
private var mPort: String? = null
|
|
|
|
|
private var mId: String? = null
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
setPushUrl("")
|
|
|
|
|
}
|
|
|
|
|
private var mInitialized = false
|
|
|
|
|
|
|
|
|
|
var callback = InitCallback { code ->
|
|
|
|
|
var msg = ""
|
|
|
|
@ -44,24 +45,40 @@ object PushHelper {
|
|
|
|
|
LogUtils.v("PushHelper. InitCallback $msg")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun configSize(width: Int, height: Int) {
|
|
|
|
|
this.mWidth = width
|
|
|
|
|
this.mHeight = height
|
|
|
|
|
fun setPushUrl(url: String) {
|
|
|
|
|
val mUri = Uri.parse(url)
|
|
|
|
|
mIp = mUri.host
|
|
|
|
|
mPort = mUri.port.toString()
|
|
|
|
|
mId = mUri.path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun setPushUrl(url: String) {
|
|
|
|
|
initHelper("192.168.5.16", "554", "123")
|
|
|
|
|
fun startStream() {
|
|
|
|
|
stop()
|
|
|
|
|
initHelper()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun stop() {
|
|
|
|
|
mPusher.stop()
|
|
|
|
|
mInitialized = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun pushData(h264: ByteArray, length: Int, timeStamp: Long) {
|
|
|
|
|
if (mIp.isNullOrEmpty() || mPort.isNullOrEmpty() || mId.isNullOrEmpty()) {
|
|
|
|
|
LogUtils.e("PushHelper error, please setPushUrl before!!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (!mInitialized) {
|
|
|
|
|
LogUtils.e("PushHelper error, please init first!!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
mPusher.push(h264, 0, length, timeStamp, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun initHelper(ip: String, port: String, id: String) {
|
|
|
|
|
private fun initHelper() {
|
|
|
|
|
if (mIp.isNullOrEmpty() || mPort.isNullOrEmpty() || mId.isNullOrEmpty()) {
|
|
|
|
|
LogUtils.e("PushHelper error, please setPushUrl first!!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
mPusher.initPush(mApplicationContext, callback)
|
|
|
|
|
mPusher.setMediaInfo(
|
|
|
|
|
Pusher.Codec.EASY_SDK_VIDEO_CODEC_H264,
|
|
|
|
@ -71,6 +88,7 @@ object PushHelper {
|
|
|
|
|
8000,
|
|
|
|
|
16
|
|
|
|
|
)
|
|
|
|
|
mPusher.start(ip, port, String.format("%s.sdp", id), Pusher.TransType.EASY_RTP_OVER_TCP)
|
|
|
|
|
mPusher.start(mIp, mPort, mId, Pusher.TransType.EASY_RTP_OVER_TCP)
|
|
|
|
|
mInitialized = true
|
|
|
|
|
}
|
|
|
|
|
}
|