//
|
// LiveViewModel.swift
|
// LiveProject
|
//
|
// Created by 倪路朋 on 6/27/25.
|
//
|
import UIKit
|
import AVFoundation
|
|
class LiveViewModel{
|
|
lazy var camera = CameraCapture()
|
lazy var renderer = MetalRenderer()
|
|
func newWindowAction(device:DeviceInfo,completion: @escaping (Bool) -> Void = {b in}){
|
switch device.type{
|
case StreamType.CAMERA:
|
requestCameraPermission(mediaType: .video){ staus in
|
if(staus){
|
self.camera.onFrame = { buffer in
|
self.renderer.updateFrame(pixelBuffer: buffer)
|
print("画面更新")
|
}
|
self.camera.start()
|
print("启动相机")
|
}else{
|
|
}
|
completion(staus)
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
|
|
func requestCameraPermission(mediaType: AVMediaType,completion: @escaping (Bool) -> Void) {
|
let status = AVCaptureDevice.authorizationStatus(for: mediaType)
|
switch status {
|
case .authorized:
|
completion(true)
|
case .notDetermined:
|
AVCaptureDevice.requestAccess(for: .video) { granted in
|
DispatchQueue.main.async {
|
completion(granted)
|
}
|
}
|
default:
|
// denied / restricted
|
completion(false)
|
}
|
}
|
}
|