Dana
6 天以前 597ab1d3451e000597ba3e12749f087f6b45a328
app/src/main/java/com/safeluck/floatwindow/MainActivity.kt
@@ -80,7 +80,11 @@
                        onStartUsbRecord = { startUsbRecord() },
                        onStopUsbRecord = { stopUsbRecord() },
                        onStartUsbPush = { startUsbPush() },
                        onStopUsbPush = { stopUsbPush() }
                        onStopUsbPush = { stopUsbPush() },
                        onStartP2Push = { startP2Push() },
                        onStopP2Push = { stopP2Push() },
                        onStartP2Record = { startP2Record() },
                        onStopP2Record = { stopP2Record() }
                    )
                }
            }
@@ -119,7 +123,12 @@
        }
        
        try {
            mediaAidlInterface?.stopMedia()
            val mediaArgu = MediaArgu().apply {
                isPush = false
                isUsedOutCamera = false // Android 内置摄像头
                usbCameraId = 0 // Android 相机,usbCameraId 为 0
            }
            mediaAidlInterface?.stopMedia(mediaArgu)
            Timber.d("Stopped Android camera record")
        } catch (e: RemoteException) {
            Timber.e(e, "Error stopping Android record")
@@ -136,6 +145,7 @@
            val mediaArgu = MediaArgu().apply {
                isPush = false
                isUsedOutCamera = true // USB 摄像头
                usbCameraId = 1 // P1 USB 摄像头
                codeRate = 0
                frameRate = 0
                m_screen = MediaArgu.ScreenSolution(640, 480) // 默认分辨率
@@ -145,7 +155,7 @@
            
            mediaAidlInterface?.registerCallback(callback)
            mediaAidlInterface?.startMedia(mediaArgu)
            Timber.d("Started USB camera record")
            Timber.d("Started USB camera record (P1)")
        } catch (e: RemoteException) {
            Timber.e(e, "Error starting USB record")
        }
@@ -158,8 +168,13 @@
        }
        
        try {
            mediaAidlInterface?.stopMedia()
            Timber.d("Stopped USB camera record")
            val mediaArgu = MediaArgu().apply {
                isPush = false
                isUsedOutCamera = true // USB 摄像头
                usbCameraId = 1 // P1 USB 摄像头
            }
            mediaAidlInterface?.stopMedia(mediaArgu)
            Timber.d("Stopped USB camera record (P1)")
        } catch (e: RemoteException) {
            Timber.e(e, "Error stopping USB record")
        }
@@ -173,6 +188,7 @@
        
        try {
            val mediaArgu = MediaArgu().apply {
                usbCameraId = 1 // P1 USB 摄像头
                isPush = true
                isUsedOutCamera = true // USB 摄像头
                codeRate = 0
@@ -185,7 +201,7 @@
            
            mediaAidlInterface?.registerCallback(callback)
            mediaAidlInterface?.startMedia(mediaArgu)
            Timber.d("Started USB camera push")
            Timber.d("Started USB camera push (P1)")
        } catch (e: RemoteException) {
            Timber.e(e, "Error starting USB push")
        }
@@ -198,10 +214,106 @@
        }
        
        try {
            mediaAidlInterface?.stopMedia()
            Timber.d("Stopped USB camera push")
            val mediaArgu = MediaArgu().apply {
                usbCameraId = 1 // P1 USB 摄像头
                isPush = true
                isUsedOutCamera = true // USB 摄像头
            }
            mediaAidlInterface?.stopMedia(mediaArgu)
            Timber.d("Stopped USB camera push (P1)")
        } catch (e: RemoteException) {
            Timber.e(e, "Error stopping USB push")
        }
    }
    private fun startP2Push() {
        if (mediaAidlInterface == null) {
            Timber.w("Service not bound, cannot start P2 push")
            return
        }
        try {
            val mediaArgu = MediaArgu().apply {
                usbCameraId = 2 // P2 USB 摄像头
                isPush = true
                isUsedOutCamera = true // USB 摄像头
                codeRate = 0
                frameRate = 0
                m_screen = MediaArgu.ScreenSolution(640, 480) // 默认分辨率
                url = "rtmp://192.168.16.143/live/livestream" // TODO: 需要设置实际的推流地址
                userName = ""
                pwd = ""
            }
            mediaAidlInterface?.registerCallback(callback)
            mediaAidlInterface?.startMedia(mediaArgu)
            Timber.d("Started P2 USB camera push")
        } catch (e: RemoteException) {
            Timber.e(e, "Error starting P2 push")
        }
    }
    private fun stopP2Push() {
        if (mediaAidlInterface == null) {
            Timber.w("Service not bound, cannot stop P2 push")
            return
        }
        try {
            val mediaArgu = MediaArgu().apply {
                usbCameraId = 2 // P2 USB 摄像头
                isPush = true
                isUsedOutCamera = true // USB 摄像头
            }
            mediaAidlInterface?.stopMedia(mediaArgu)
            Timber.d("Stopped P2 USB camera push")
        } catch (e: RemoteException) {
            Timber.e(e, "Error stopping P2 push")
        }
    }
    private fun startP2Record() {
        if (mediaAidlInterface == null) {
            Timber.w("Service not bound, cannot start P2 record")
            return
        }
        try {
            val mediaArgu = MediaArgu().apply {
                isPush = false
                isUsedOutCamera = true // USB 摄像头
                usbCameraId = 2 // P2 USB 摄像头
                codeRate = 0
                frameRate = 0
                m_screen = MediaArgu.ScreenSolution(640, 480) // 默认分辨率
                recordTime = 0
                tfCardFlag = 0 // 内部存储
            }
            mediaAidlInterface?.registerCallback(callback)
            mediaAidlInterface?.startMedia(mediaArgu)
            Timber.d("Started P2 USB camera record")
        } catch (e: RemoteException) {
            Timber.e(e, "Error starting P2 record")
        }
    }
    private fun stopP2Record() {
        if (mediaAidlInterface == null) {
            Timber.w("Service not bound, cannot stop P2 record")
            return
        }
        try {
            val mediaArgu = MediaArgu().apply {
                isPush = false
                isUsedOutCamera = true // USB 摄像头
                usbCameraId = 2 // P2 USB 摄像头
            }
            mediaAidlInterface?.stopMedia(mediaArgu)
            Timber.d("Stopped P2 USB camera record")
        } catch (e: RemoteException) {
            Timber.e(e, "Error stopping P2 record")
        }
    }
    
@@ -240,7 +352,11 @@
    onStartUsbRecord: () -> Unit,
    onStopUsbRecord: () -> Unit,
    onStartUsbPush: () -> Unit,
    onStopUsbPush: () -> Unit
    onStopUsbPush: () -> Unit,
    onStartP2Push: () -> Unit,
    onStopP2Push: () -> Unit,
    onStartP2Record: () -> Unit,
    onStopP2Record: () -> Unit
) {
    Column(
        modifier = Modifier.fillMaxSize()
@@ -339,22 +455,62 @@
            
            Divider(modifier = Modifier.padding(vertical = 8.dp))
            
            // 按钮 7: 开始 USB 推流
            // 按钮 7: 开始 USB 推流 (P1)
            Button(
                onClick = onStartUsbPush,
                modifier = Modifier.fillMaxWidth(),
                enabled = isServiceBound
            ) {
                Text("7. 开始 USB 推流")
                Text("7. 开始 USB 推流 (P1)")
            }
            
            // 按钮 8: 结束 USB 推流
            // 按钮 8: 结束 USB 推流 (P1)
            Button(
                onClick = onStopUsbPush,
                modifier = Modifier.fillMaxWidth(),
                enabled = isServiceBound
            ) {
                Text("8. 结束 USB 推流")
                Text("8. 结束 USB 推流 (P1)")
            }
            Divider(modifier = Modifier.padding(vertical = 8.dp))
            // 按钮 9: 开始 P2 USB 推流
            Button(
                onClick = onStartP2Push,
                modifier = Modifier.fillMaxWidth(),
                enabled = isServiceBound
            ) {
                Text("9. 开始 P2 USB 推流")
            }
            // 按钮 10: 结束 P2 USB 推流
            Button(
                onClick = onStopP2Push,
                modifier = Modifier.fillMaxWidth(),
                enabled = isServiceBound
            ) {
                Text("10. 结束 P2 USB 推流")
            }
            Divider(modifier = Modifier.padding(vertical = 8.dp))
            // 按钮 11: 开始 P2 USB 录像
            Button(
                onClick = onStartP2Record,
                modifier = Modifier.fillMaxWidth(),
                enabled = isServiceBound
            ) {
                Text("11. 开始 P2 USB 录像")
            }
            // 按钮 12: 结束 P2 USB 录像
            Button(
                onClick = onStopP2Record,
                modifier = Modifier.fillMaxWidth(),
                enabled = isServiceBound
            ) {
                Text("12. 结束 P2 USB 录像")
            }
            
            Spacer(modifier = Modifier.height(12.dp))