From 597ab1d3451e000597ba3e12749f087f6b45a328 Mon Sep 17 00:00:00 2001
From: Dana <Dana_Lee1016@126.com>
Date: 星期四, 29 一月 2026 13:14:49 +0800
Subject: [PATCH] 1.p2摄像头 跨进程服务,未测试

---
 app/src/main/java/com/safeluck/floatwindow/MainActivity.kt |  182 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 169 insertions(+), 13 deletions(-)

diff --git a/app/src/main/java/com/safeluck/floatwindow/MainActivity.kt b/app/src/main/java/com/safeluck/floatwindow/MainActivity.kt
index 437b645..76a24d5 100644
--- a/app/src/main/java/com/safeluck/floatwindow/MainActivity.kt
+++ b/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 鐩告満锛寀sbCameraId 涓� 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))

--
Gitblit v1.8.0