From 2b51baa1981fb445b938e64bdce539e58fe70264 Mon Sep 17 00:00:00 2001
From: Runt <qingingrunt2010@qq.com>
Date: Sat, 26 Jul 2025 13:17:14 +0000
Subject: [PATCH] 小窗缩放, 相机转小窗显示 小窗旋转,相机画面旋转 关闭按钮优化

---
 LiveProject/activity/stream/LiveViewModel.swift |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/LiveProject/activity/stream/LiveViewModel.swift b/LiveProject/activity/stream/LiveViewModel.swift
index bfc3671..bb31219 100644
--- a/LiveProject/activity/stream/LiveViewModel.swift
+++ b/LiveProject/activity/stream/LiveViewModel.swift
@@ -10,15 +10,15 @@
 class LiveViewModel: ObservableObject {
     @Published var pixelBuffer: CVPixelBuffer?
     
-    let encoder = H264Encoder(width: 1080, height: 1920, fps: 30, bitrate: 1_000_000)
+    //let encoder = H264Encoder(width: 1080, height: 1920, fps: 30, bitrate: 1_000_000)
     var frameIndex: Int64 = 0
-    let encodeQueue = DispatchQueue(label: "encoder.queue")
+    //let encodeQueue = DispatchQueue(label: "encoder.queue")
 
     lazy var camera = CameraCapture()
     var timestamp = Int(Date().timeIntervalSince1970 * 1000)
     
-    func newWindowAction(device:DeviceInfo,completion: @escaping (Bool) -> Void = {b in}){
-        switch device.type{
+    func newWindowAction(minidata:MiniWindowData,completion: @escaping (Bool) -> Void = {b in}){
+        switch minidata.streamType{
         case StreamType.CAMERA:
             requestCameraPermission(mediaType: .video){ staus in
                 if(staus){
@@ -33,15 +33,18 @@
                             print("Invalid pixel buffer size: \(width)x\(height)")
                             return
                         }
-                        
+                        if(minidata.size.width != CGFloat(width) || minidata.size.height != CGFloat(height)){
+                            minidata.size = CGSize(width:width,height:height);
+                        }
                         self.frameIndex += 1
                         let ts =  Int(Date().timeIntervalSince1970 * 1000)
 
                         self.timestamp = ts;
                         let cmTime = CMTimeMake(value: Int64(CACurrentMediaTime() * 1000), timescale: 1000);
-                        self.encoder.encode(pixelBuffer: buffer, pts: cmTime)
+                        //self.encoder.encode(pixelBuffer: buffer, pts: cmTime)
                         DispatchQueue.main.async {
-                            self.pixelBuffer = buffer;
+                            minidata.pixelBuffer = buffer;
+                            
                         }
                         //print("画面更新")
                     }
@@ -49,12 +52,12 @@
                         self.camera.start()
                     }
                     print("启动相机")
-                    self.encoder.onEncoded = { (data: Data, ctime: CMTime, isKey: Bool) in
+                    /*self.encoder.onEncoded = { (data: Data, ctime: CMTime, isKey: Bool) in
                         let timestamp2 = Int(Date().timeIntervalSince1970 * 1000)
                         print("编码时间2 \(timestamp2 - self.timestamp)")
                         print("Encoded NALU size: \(data.count), key frame: \(isKey)")
 
-                    }
+                    }*/
                 }else{
                     
                 }
@@ -67,10 +70,11 @@
         }
     }
     
-    func closeWindowAction(device:DeviceInfo){
-        switch device.type{
+    func closeWindowAction(miniData:MiniWindowData){
+        switch miniData.streamType{
         case StreamType.CAMERA:
             print("关闭相机")
+            camera.stop();
             break;
         default:
             break;

--
Gitblit v1.9.1