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

main
xiaowusky 2 years ago
parent ac769de55d
commit dcdb5cac19

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

@ -1,11 +1,13 @@
package com.yinuo.library.vlc package com.yinuo.library.vlc
import android.net.Uri
import com.common.commonlib.CommonApplication import com.common.commonlib.CommonApplication
import com.yinuo.library.vlc.utils.LogUtils import com.yinuo.library.vlc.utils.LogUtils
import org.easydarwin.push.EasyPusher import org.easydarwin.push.EasyPusher
import org.easydarwin.push.InitCallback import org.easydarwin.push.InitCallback
import org.easydarwin.push.Pusher import org.easydarwin.push.Pusher
object PushHelper { object PushHelper {
private val mPusher: EasyPusher by lazy { private val mPusher: EasyPusher by lazy {
@ -14,12 +16,11 @@ object PushHelper {
private val mApplicationContext = CommonApplication.getContext() private val mApplicationContext = CommonApplication.getContext()
private var mHeight: Int = 0 private var mIp: String? = null
private var mWidth: Int = 0 private var mPort: String? = null
private var mId: String? = null
init { private var mInitialized = false
setPushUrl("")
}
var callback = InitCallback { code -> var callback = InitCallback { code ->
var msg = "" var msg = ""
@ -44,24 +45,40 @@ object PushHelper {
LogUtils.v("PushHelper. InitCallback $msg") LogUtils.v("PushHelper. InitCallback $msg")
} }
fun configSize(width: Int, height: Int) { fun setPushUrl(url: String) {
this.mWidth = width val mUri = Uri.parse(url)
this.mHeight = height mIp = mUri.host
mPort = mUri.port.toString()
mId = mUri.path
} }
fun setPushUrl(url: String) { fun startStream() {
initHelper("192.168.5.16", "554", "123") stop()
initHelper()
} }
fun stop() { fun stop() {
mPusher.stop() mPusher.stop()
mInitialized = false
} }
fun pushData(h264: ByteArray, length: Int, timeStamp: Long) { 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) 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.initPush(mApplicationContext, callback)
mPusher.setMediaInfo( mPusher.setMediaInfo(
Pusher.Codec.EASY_SDK_VIDEO_CODEC_H264, Pusher.Codec.EASY_SDK_VIDEO_CODEC_H264,
@ -71,6 +88,7 @@ object PushHelper {
8000, 8000,
16 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); mVideoBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
RtspHelper.getInstance().createPlayer(mRtspUrl, width, height, RtspSurfaceRender2.this); RtspHelper.getInstance().createPlayer(mRtspUrl, width, height, RtspSurfaceRender2.this);
renderThread.start(); renderThread.start();
PushHelper.INSTANCE.configSize(width, height);
} }
} }

Loading…
Cancel
Save