將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
|
@Parcelize
|
||||||
data class Device(
|
data class Device(
|
||||||
val name: String = "",
|
var ip: String = "",
|
||||||
val rtspUrl: 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
|
var isPlaying: Boolean = false
|
||||||
): Parcelable
|
): Parcelable
|
||||||
|
|||||||
@ -10,44 +10,104 @@ class MainViewModel: ViewModel() {
|
|||||||
private val uriList: List<Device> by lazy {
|
private val uriList: List<Device> by lazy {
|
||||||
listOf(
|
listOf(
|
||||||
Device(
|
Device(
|
||||||
name = "192.168.0.73",
|
deviceName = "192.168.0.73",
|
||||||
rtspUrl = "rtsp://admin:hs22601576@@192.168.0.73:554/media/video2"
|
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(
|
Device(
|
||||||
name = "192.168.0.77",
|
deviceName = "192.168.0.77",
|
||||||
rtspUrl = "rtsp://admin:admin@192.168.0.77:554/media/video2"
|
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(
|
Device(
|
||||||
name = "192.168.0.79",
|
deviceName = "192.168.0.79",
|
||||||
rtspUrl = "rtsp://admin:1q2w3e4r!@192.168.0.79:554/media/video2"
|
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(
|
Device(
|
||||||
name = "192.168.0.88",
|
deviceName = "192.168.0.88",
|
||||||
rtspUrl = "rtsp://admin:1q2w3e4r~@211.23.78.226:8588/media/video2"
|
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(
|
Device(
|
||||||
name = "192.168.0.74",
|
deviceName = "192.168.0.74",
|
||||||
rtspUrl = "rtsp://admin:admin@211.23.78.226:8574/v02"
|
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(
|
Device(
|
||||||
name = "192.168.0.75",
|
deviceName = "192.168.0.75",
|
||||||
rtspUrl = "rtsp://admin:admin@211.23.78.226:8575/v02"
|
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(
|
Device(
|
||||||
name = "192.168.0.76",
|
deviceName = "192.168.0.76",
|
||||||
rtspUrl = "rtsp://admin:123456@211.23.78.226:8576/profile2"
|
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(
|
Device(
|
||||||
name = "192.168.0.82",
|
deviceName = "192.168.0.82",
|
||||||
rtspUrl = "rtsp://admin:123456@192.168.0.82:554/profile2"
|
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(
|
Device(
|
||||||
name = "192.168.0.84",
|
deviceName = "192.168.0.84",
|
||||||
rtspUrl = "rtsp://admin:123456@192.168.0.84:554/profile2"
|
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(
|
Device(
|
||||||
name = "192.168.0.95",
|
deviceName = "192.168.0.95",
|
||||||
rtspUrl = "rtsp://admin:123456@192.168.0.95:554/profile2"
|
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.GstLibrary
|
||||||
import com.hisharp.gstreamer_player.GstStatus
|
import com.hisharp.gstreamer_player.GstStatus
|
||||||
import com.ray650128.gstreamer_demo_app.databinding.ItemVideoViewBinding
|
import com.ray650128.gstreamer_demo_app.databinding.ItemVideoViewBinding
|
||||||
|
import com.ray650128.gstreamer_demo_app.extensions.getStreamPath
|
||||||
import com.ray650128.gstreamer_demo_app.model.Device
|
import com.ray650128.gstreamer_demo_app.model.Device
|
||||||
|
|
||||||
class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
||||||
@ -59,8 +60,6 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
|
|
||||||
private lateinit var gstLibrary: GstLibrary
|
private lateinit var gstLibrary: GstLibrary
|
||||||
|
|
||||||
private var streamType = MAIN_STREAM
|
|
||||||
|
|
||||||
private val mHandler: MyHandler by lazy {
|
private val mHandler: MyHandler by lazy {
|
||||||
MyHandler(Looper.getMainLooper())
|
MyHandler(Looper.getMainLooper())
|
||||||
}
|
}
|
||||||
@ -79,7 +78,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setData(device: Device?) {
|
fun setData(device: Device?, streamType: Int = SUB_STREAM) {
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
view.textDeviceName.isVisible = false
|
view.textDeviceName.isVisible = false
|
||||||
isPlaying = false
|
isPlaying = false
|
||||||
@ -87,11 +86,12 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.data = device
|
this.data = device
|
||||||
this.tag = device.name
|
this.tag = device.deviceName
|
||||||
view.textDeviceName.text = device.name
|
view.textDeviceName.text = device.deviceName
|
||||||
view.textDeviceName.isVisible = true
|
view.textDeviceName.isVisible = true
|
||||||
gstLibrary.setRtspUrl(this.data?.rtspUrl)
|
val rtspUrl = this.data?.getStreamPath(streamType) ?: return
|
||||||
Log.d("${TAG}_$tag", "Set device to: $device")
|
Log.d("${TAG}_$tag", "Set device to: $device, rtspUrl = $rtspUrl")
|
||||||
|
gstLibrary.setRtspUrl(rtspUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTextVisible(isVisible: Boolean) {
|
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) {
|
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
||||||
Log.d("${TAG}_$tag", "Surface changed, format: $format, width: $width, height: $height")
|
Log.d("${TAG}_$tag", "Surface changed, format: $format, width: $width, height: $height")
|
||||||
if (this::gstLibrary.isInitialized) {
|
/*if (this::gstLibrary.isInitialized) {
|
||||||
gstLibrary.setSurfaceHolder(holder)
|
gstLibrary.setSurfaceHolder(holder)
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun surfaceDestroyed(p0: SurfaceHolder) {
|
override fun surfaceDestroyed(p0: SurfaceHolder) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user