將Device修改成HiSharpDX的資料結構
This commit is contained in:
parent
85218c443f
commit
4e09a449ca
@ -0,0 +1,55 @@
|
||||
package com.ray650128.gstreamer_demo_app.extensions
|
||||
|
||||
import android.util.Log
|
||||
import com.ray650128.gstreamer_demo_app.model.Device
|
||||
|
||||
/**
|
||||
* IpCam 擴充函式-取得完整串流路徑
|
||||
* @param streamPathNum 串流路徑編號
|
||||
* @author Raymond Yang
|
||||
*/
|
||||
fun Device.getStreamPath(streamPathNum: Int): String? {
|
||||
val stringBuilder = getPath(this) ?: return null
|
||||
|
||||
// 加入串流路徑
|
||||
when (streamPathNum) {
|
||||
1 -> if (this.stream1.isNotEmpty()) {
|
||||
if (this.stream1.first() != '/') {
|
||||
stringBuilder.append("/")
|
||||
}
|
||||
stringBuilder.append(this.stream1)
|
||||
}
|
||||
2 -> if (this.stream2.isNotEmpty()) {
|
||||
if (this.stream2.first() != '/') {
|
||||
stringBuilder.append("/")
|
||||
}
|
||||
stringBuilder.append(this.stream2)
|
||||
}
|
||||
else -> return null
|
||||
}
|
||||
Log.d("+++URL", stringBuilder.toString())
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
private fun getPath(ipCam: Device): StringBuilder? {
|
||||
if (ipCam.ip.isEmpty()) return null
|
||||
val stringBuilder = StringBuilder()
|
||||
// 加入 URL schema
|
||||
stringBuilder.append("rtsp://")
|
||||
|
||||
// 加入帳號密碼
|
||||
if (ipCam.account.isNotEmpty()) {
|
||||
if (ipCam.password.isEmpty()) {
|
||||
stringBuilder.append("${ipCam.account}@")
|
||||
} else {
|
||||
stringBuilder.append("${ipCam.account}:${ipCam.password}@")
|
||||
}
|
||||
}
|
||||
|
||||
// 加入 IP 及 port
|
||||
stringBuilder.append(ipCam.ip)
|
||||
if (ipCam.rtspPort.isNotEmpty()) {
|
||||
stringBuilder.append(":${ipCam.rtspPort}")
|
||||
}
|
||||
return stringBuilder
|
||||
}
|
||||
@ -5,7 +5,13 @@ import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class Device(
|
||||
val name: String = "",
|
||||
val rtspUrl: String = "",
|
||||
var ip: String = "",
|
||||
var rtspPort: String = "",
|
||||
val deviceName: String = "",
|
||||
var account: String = "",
|
||||
var password: String = "",
|
||||
var stream1: String = "",
|
||||
var stream2: String = "",
|
||||
//val rtspUrl: String = "",
|
||||
var isPlaying: Boolean = false
|
||||
): Parcelable
|
||||
|
||||
@ -10,44 +10,104 @@ class MainViewModel: ViewModel() {
|
||||
private val uriList: List<Device> by lazy {
|
||||
listOf(
|
||||
Device(
|
||||
name = "192.168.0.73",
|
||||
rtspUrl = "rtsp://admin:hs22601576@@192.168.0.73:554/media/video2"
|
||||
deviceName = "192.168.0.73",
|
||||
ip = "192.168.0.73",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "hs22601576",
|
||||
stream1 = "/media/video1",
|
||||
stream2 = "/media/video2",
|
||||
//rtspUrl = "rtsp://admin:hs22601576@@192.168.0.73:554/media/video2"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.77",
|
||||
rtspUrl = "rtsp://admin:admin@192.168.0.77:554/media/video2"
|
||||
deviceName = "192.168.0.77",
|
||||
ip = "192.168.0.77",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "admin",
|
||||
stream1 = "/media/video1",
|
||||
stream2 = "/media/video2",
|
||||
//rtspUrl = "rtsp://admin:admin@192.168.0.77:554/media/video2"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.79",
|
||||
rtspUrl = "rtsp://admin:1q2w3e4r!@192.168.0.79:554/media/video2"
|
||||
deviceName = "192.168.0.79",
|
||||
ip = "192.168.0.79",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "1q2w3e4r!",
|
||||
stream1 = "/media/video1",
|
||||
stream2 = "/media/video2",
|
||||
//rtspUrl = "rtsp://admin:1q2w3e4r!@192.168.0.79:554/media/video2"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.88",
|
||||
rtspUrl = "rtsp://admin:1q2w3e4r~@211.23.78.226:8588/media/video2"
|
||||
deviceName = "192.168.0.88",
|
||||
ip = "211.23.78.226",
|
||||
rtspPort = "8588",
|
||||
account = "admin",
|
||||
password = "1q2w3e4r~",
|
||||
stream1 = "/media/video1",
|
||||
stream2 = "/media/video2",
|
||||
//rtspUrl = "rtsp://admin:1q2w3e4r~@211.23.78.226:8588/media/video2"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.74",
|
||||
rtspUrl = "rtsp://admin:admin@211.23.78.226:8574/v02"
|
||||
deviceName = "192.168.0.74",
|
||||
ip = "211.23.78.226",
|
||||
rtspPort = "8574",
|
||||
account = "admin",
|
||||
password = "admin",
|
||||
stream1 = "/v01",
|
||||
stream2 = "/v02",
|
||||
//rtspUrl = "rtsp://admin:admin@211.23.78.226:8574/v02"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.75",
|
||||
rtspUrl = "rtsp://admin:admin@211.23.78.226:8575/v02"
|
||||
deviceName = "192.168.0.75",
|
||||
ip = "211.23.78.226",
|
||||
rtspPort = "8575",
|
||||
account = "admin",
|
||||
password = "admin",
|
||||
stream1 = "/v01",
|
||||
stream2 = "/v02",
|
||||
//rtspUrl = "rtsp://admin:admin@211.23.78.226:8575/v02"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.76",
|
||||
rtspUrl = "rtsp://admin:123456@211.23.78.226:8576/profile2"
|
||||
deviceName = "192.168.0.76",
|
||||
ip = "211.23.78.226",
|
||||
rtspPort = "8576",
|
||||
account = "admin",
|
||||
password = "123456",
|
||||
stream1 = "/profile1",
|
||||
stream2 = "/profile2",
|
||||
//rtspUrl = "rtsp://admin:123456@211.23.78.226:8576/profile2"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.82",
|
||||
rtspUrl = "rtsp://admin:123456@192.168.0.82:554/profile2"
|
||||
deviceName = "192.168.0.82",
|
||||
ip = "192.168.0.82",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "123456",
|
||||
stream1 = "/profile1",
|
||||
stream2 = "/profile2",
|
||||
//rtspUrl = "rtsp://admin:123456@192.168.0.82:554/profile2"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.84",
|
||||
rtspUrl = "rtsp://admin:123456@192.168.0.84:554/profile2"
|
||||
deviceName = "192.168.0.84",
|
||||
ip = "192.168.0.84",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "123456",
|
||||
stream1 = "/profile1",
|
||||
stream2 = "/profile2",
|
||||
//rtspUrl = "rtsp://admin:123456@192.168.0.84:554/profile2"
|
||||
),
|
||||
Device(
|
||||
name = "192.168.0.95",
|
||||
rtspUrl = "rtsp://admin:123456@192.168.0.95:554/profile2"
|
||||
deviceName = "192.168.0.95",
|
||||
ip = "192.168.0.95",
|
||||
rtspPort = "554",
|
||||
account = "admin",
|
||||
password = "123456",
|
||||
stream1 = "/profile1",
|
||||
stream2 = "/profile2",
|
||||
//rtspUrl = "rtsp://admin:123456@192.168.0.95:554/profile2"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ import com.hisharp.gstreamer_player.GstCallback
|
||||
import com.hisharp.gstreamer_player.GstLibrary
|
||||
import com.hisharp.gstreamer_player.GstStatus
|
||||
import com.ray650128.gstreamer_demo_app.databinding.ItemVideoViewBinding
|
||||
import com.ray650128.gstreamer_demo_app.extensions.getStreamPath
|
||||
import com.ray650128.gstreamer_demo_app.model.Device
|
||||
|
||||
class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
@ -59,8 +60,6 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
|
||||
private lateinit var gstLibrary: GstLibrary
|
||||
|
||||
private var streamType = MAIN_STREAM
|
||||
|
||||
private val mHandler: MyHandler by lazy {
|
||||
MyHandler(Looper.getMainLooper())
|
||||
}
|
||||
@ -79,7 +78,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
fun setData(device: Device?) {
|
||||
fun setData(device: Device?, streamType: Int = SUB_STREAM) {
|
||||
if (device == null) {
|
||||
view.textDeviceName.isVisible = false
|
||||
isPlaying = false
|
||||
@ -87,11 +86,12 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
return
|
||||
}
|
||||
this.data = device
|
||||
this.tag = device.name
|
||||
view.textDeviceName.text = device.name
|
||||
this.tag = device.deviceName
|
||||
view.textDeviceName.text = device.deviceName
|
||||
view.textDeviceName.isVisible = true
|
||||
gstLibrary.setRtspUrl(this.data?.rtspUrl)
|
||||
Log.d("${TAG}_$tag", "Set device to: $device")
|
||||
val rtspUrl = this.data?.getStreamPath(streamType) ?: return
|
||||
Log.d("${TAG}_$tag", "Set device to: $device, rtspUrl = $rtspUrl")
|
||||
gstLibrary.setRtspUrl(rtspUrl)
|
||||
}
|
||||
|
||||
fun setTextVisible(isVisible: Boolean) {
|
||||
@ -127,9 +127,9 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||
|
||||
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
||||
Log.d("${TAG}_$tag", "Surface changed, format: $format, width: $width, height: $height")
|
||||
if (this::gstLibrary.isInitialized) {
|
||||
/*if (this::gstLibrary.isInitialized) {
|
||||
gstLibrary.setSurfaceHolder(holder)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
override fun surfaceDestroyed(p0: SurfaceHolder) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user