desc:解析服务端返回的Rtsp推流地址

main
xiaowusky 2 years ago
parent ac769de55d
commit dcdb5cac19

@ -1,6 +1,7 @@
package com.yinuo.safetywatcher.watcher.utils
import com.lztek.toolkit.Lztek
import com.yinuo.library.vlc.PushHelper
import java.math.BigInteger
import java.security.MessageDigest
@ -48,5 +49,6 @@ object LztekUtil {
fun setRtspUrl(str: String?) {
this.rtspUrl = str
rtspUrl?.let { PushHelper.setPushUrl(it) }
}
}

@ -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
}
}

@ -75,7 +75,6 @@ public class RtspSurfaceRender2 implements RtspHelper.RtspCallback {
mVideoBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
RtspHelper.getInstance().createPlayer(mRtspUrl, width, height, RtspSurfaceRender2.this);
renderThread.start();
PushHelper.INSTANCE.configSize(width, height);
}
}

Loading…
Cancel
Save