mirror of
https://github.com/mpv-player/mpv
synced 2025-01-01 04:12:25 +00:00
mac/log: rename log functions and cleanup class
This commit is contained in:
parent
ceaabb7b98
commit
ed0587692f
@ -48,7 +48,7 @@ class LibmpvHelper {
|
||||
]
|
||||
|
||||
if (mpv_render_context_create(&mpvRenderContext, mpv, ¶ms) < 0) {
|
||||
log.sendError("Render context init has failed.")
|
||||
log.error("Render context init has failed.")
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ class LibmpvHelper {
|
||||
|
||||
func setRenderUpdateCallback(_ callback: @escaping mpv_render_update_fn, context object: AnyObject) {
|
||||
if mpvRenderContext == nil {
|
||||
log.sendWarning("Init mpv render context first.")
|
||||
log.warning("Init mpv render context first.")
|
||||
} else {
|
||||
mpv_render_context_set_update_callback(mpvRenderContext, callback, TypeHelper.bridge(obj: object))
|
||||
}
|
||||
@ -81,7 +81,7 @@ class LibmpvHelper {
|
||||
|
||||
func setRenderControlCallback(_ callback: @escaping mp_render_cb_control_fn, context object: AnyObject) {
|
||||
if mpvRenderContext == nil {
|
||||
log.sendWarning("Init mpv render context first.")
|
||||
log.warning("Init mpv render context first.")
|
||||
} else {
|
||||
mp_render_context_set_control_callback(mpvRenderContext, callback, TypeHelper.bridge(obj: object))
|
||||
}
|
||||
@ -143,7 +143,7 @@ class LibmpvHelper {
|
||||
func setRenderICCProfile(_ profile: NSColorSpace) {
|
||||
if mpvRenderContext == nil { return }
|
||||
guard var iccData = profile.iccProfileData else {
|
||||
log.sendWarning("Invalid ICC profile data.")
|
||||
log.warning("Invalid ICC profile data.")
|
||||
return
|
||||
}
|
||||
iccData.withUnsafeMutableBytes { (ptr: UnsafeMutableRawBufferPointer) in
|
||||
|
@ -24,24 +24,24 @@ class LogHelper {
|
||||
self.log = log
|
||||
}
|
||||
|
||||
func sendVerbose(_ msg: String) {
|
||||
send(message: msg, type: MSGL_V)
|
||||
func verbose(_ message: String) {
|
||||
send(message: message, type: MSGL_V)
|
||||
}
|
||||
|
||||
func sendInfo(_ msg: String) {
|
||||
send(message: msg, type: MSGL_INFO)
|
||||
func info(_ message: String) {
|
||||
send(message: message, type: MSGL_INFO)
|
||||
}
|
||||
|
||||
func sendWarning(_ msg: String) {
|
||||
send(message: msg, type: MSGL_WARN)
|
||||
func warning(_ message: String) {
|
||||
send(message: message, type: MSGL_WARN)
|
||||
}
|
||||
|
||||
func sendError(_ msg: String) {
|
||||
send(message: msg, type: MSGL_ERR)
|
||||
func error(_ message: String) {
|
||||
send(message: message, type: MSGL_ERR)
|
||||
}
|
||||
|
||||
func send(message msg: String, type t: Int) {
|
||||
let args: [CVarArg] = [ (msg as NSString).utf8String ?? "NO MESSAGE"]
|
||||
mp_msg_va(log, Int32(t), "%s\n", getVaList(args))
|
||||
func send(message: String, type: Int) {
|
||||
let args: [CVarArg] = [(message as NSString).utf8String ?? "NO MESSAGE"]
|
||||
mp_msg_va(log, Int32(type), "%s\n", getVaList(args))
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class PreciseTimer {
|
||||
|
||||
pthread_create(&thread, &threadAttr, entryC, TypeHelper.bridge(obj: self))
|
||||
if thread == nil {
|
||||
common.log.sendWarning("Couldn't create pthread for high precision timer")
|
||||
common.log.warning("Couldn't create pthread for high precision timer")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ class PreciseTimer {
|
||||
|
||||
isHighPrecision = success == KERN_SUCCESS
|
||||
if !isHighPrecision {
|
||||
common.log.sendWarning("Couldn't create a high precision timer")
|
||||
common.log.warning("Couldn't create a high precision timer")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class CocoaCB: Common, EventSubscriber {
|
||||
backendState = .needsInit
|
||||
|
||||
guard let layer = self.layer else {
|
||||
log.sendError("Something went wrong, no GLLayer was initialized")
|
||||
log.error("Something went wrong, no GLLayer was initialized")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ class CocoaCB: Common, EventSubscriber {
|
||||
func updateWindowSize(_ vo: UnsafeMutablePointer<vo>) {
|
||||
guard let targetScreen = getTargetScreen(forFullscreen: false) ?? NSScreen.main else
|
||||
{
|
||||
log.sendWarning("Couldn't update Window size, no Screen available")
|
||||
log.warning("Couldn't update Window size, no Screen available")
|
||||
return
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ class CocoaCB: Common, EventSubscriber {
|
||||
|
||||
override func updateICCProfile() {
|
||||
guard let colorSpace = window?.screen?.colorSpace else {
|
||||
log.sendWarning("Couldn't update ICC Profile, no color space available")
|
||||
log.warning("Couldn't update ICC Profile, no color space available")
|
||||
return
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ class CocoaCB: Common, EventSubscriber {
|
||||
let ccb = unsafeBitCast(ctx, to: CocoaCB.self)
|
||||
|
||||
guard let vo = v, let events = e else {
|
||||
ccb.log.sendWarning("Unexpected nil value in Control Callback")
|
||||
ccb.log.warning("Unexpected nil value in Control Callback")
|
||||
return VO_FALSE
|
||||
}
|
||||
|
||||
|
@ -78,13 +78,13 @@ class Common: NSObject {
|
||||
let (targetScreen, wr) = getInitProperties(vo)
|
||||
|
||||
guard let view = self.view else {
|
||||
log.sendError("Something went wrong, no View was initialized")
|
||||
log.error("Something went wrong, no View was initialized")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
window = Window(contentRect: wr, screen: targetScreen, view: view, common: self)
|
||||
guard let window = self.window else {
|
||||
log.sendError("Something went wrong, no Window was initialized")
|
||||
log.error("Something went wrong, no Window was initialized")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ class Common: NSObject {
|
||||
|
||||
view = View(frame: wr, common: self)
|
||||
guard let view = self.view else {
|
||||
log.sendError("Something went wrong, no View was initialized")
|
||||
log.error("Something went wrong, no View was initialized")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ class Common: NSObject {
|
||||
guard let screen = getTargetScreen(forFullscreen: false) ?? NSScreen.main,
|
||||
let link = self.link else
|
||||
{
|
||||
log.sendWarning("Couldn't start DisplayLink, no OptionHelper, Screen or DisplayLink available")
|
||||
log.warning("Couldn't start DisplayLink, no Screen or DisplayLink available")
|
||||
return
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ class Common: NSObject {
|
||||
|
||||
func updateDisplaylink() {
|
||||
guard let screen = window?.screen, let link = self.link else {
|
||||
log.sendWarning("Couldn't update DisplayLink, no Screen or DisplayLink available")
|
||||
log.warning("Couldn't update DisplayLink, no Screen or DisplayLink available")
|
||||
return
|
||||
}
|
||||
|
||||
@ -214,17 +214,17 @@ class Common: NSObject {
|
||||
}
|
||||
|
||||
if fabs(actualFps - nominalFps) > 0.1 {
|
||||
log.sendVerbose("Falling back to nominal display refresh rate: \(nominalFps)")
|
||||
log.verbose("Falling back to nominal display refresh rate: \(nominalFps)")
|
||||
return nominalFps
|
||||
} else {
|
||||
return actualFps
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.sendWarning("No DisplayLink available")
|
||||
log.warning("No DisplayLink available")
|
||||
}
|
||||
|
||||
log.sendWarning("Falling back to standard display refresh rate: 60Hz")
|
||||
log.warning("Falling back to standard display refresh rate: 60Hz")
|
||||
return 60.0
|
||||
}
|
||||
|
||||
@ -278,13 +278,13 @@ class Common: NSObject {
|
||||
}
|
||||
|
||||
func lightSensorUpdate() {
|
||||
log.sendWarning("lightSensorUpdate not implemented")
|
||||
log.warning("lightSensorUpdate not implemented")
|
||||
}
|
||||
|
||||
func initLightSensor() {
|
||||
let srv = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleLMUController"))
|
||||
if srv == IO_OBJECT_NULL {
|
||||
log.sendVerbose("Can't find an ambient light sensor")
|
||||
log.verbose("Can't find an ambient light sensor")
|
||||
return
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ class Common: NSObject {
|
||||
IOObjectRelease(srv)
|
||||
|
||||
if kr != KERN_SUCCESS {
|
||||
log.sendVerbose("Can't start ambient light sensor connection")
|
||||
log.verbose("Can't start ambient light sensor connection")
|
||||
return
|
||||
}
|
||||
lightSensorCallback(TypeHelper.bridge(obj: self), 0, 0, nil)
|
||||
@ -315,7 +315,7 @@ class Common: NSObject {
|
||||
let displayID = com.window?.screen?.displayID ?? display
|
||||
|
||||
if displayID == display {
|
||||
com.log.sendVerbose("Detected display mode change, updating screen refresh rate")
|
||||
com.log.verbose("Detected display mode change, updating screen refresh rate")
|
||||
com.flagEvents(VO_EVENT_WIN_STATE)
|
||||
}
|
||||
}
|
||||
@ -372,12 +372,12 @@ class Common: NSObject {
|
||||
}
|
||||
|
||||
func updateICCProfile() {
|
||||
log.sendWarning("updateICCProfile not implemented")
|
||||
log.warning("updateICCProfile not implemented")
|
||||
}
|
||||
|
||||
func getScreenBy(id screenID: Int) -> NSScreen? {
|
||||
if screenID >= NSScreen.screens.count {
|
||||
log.sendInfo("Screen ID \(screenID) does not exist, falling back to current device")
|
||||
log.info("Screen ID \(screenID) does not exist, falling back to current device")
|
||||
return nil
|
||||
} else if screenID < 0 {
|
||||
return nil
|
||||
@ -441,7 +441,7 @@ class Common: NSObject {
|
||||
|
||||
func getInitProperties(_ vo: UnsafeMutablePointer<vo>) -> (NSScreen, NSRect) {
|
||||
guard let targetScreen = getTargetScreen(forFullscreen: false) ?? NSScreen.main else {
|
||||
log.sendError("Something went wrong, no Screen was found")
|
||||
log.error("Something went wrong, no Screen was found")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ class Common: NSObject {
|
||||
eventsLock.unlock()
|
||||
|
||||
guard let vo = vo else {
|
||||
log.sendWarning("vo nil in flagEvents")
|
||||
log.warning("vo nil in flagEvents")
|
||||
return
|
||||
}
|
||||
vo_wakeup(vo)
|
||||
@ -580,7 +580,7 @@ class Common: NSObject {
|
||||
case VOCTRL_GET_ICC_PROFILE:
|
||||
let screen = getCurrentScreen()
|
||||
guard var iccData = screen?.colorSpace?.iccProfileData else {
|
||||
log.sendWarning("No Screen available to retrieve ICC profile")
|
||||
log.warning("No Screen available to retrieve ICC profile")
|
||||
return VO_TRUE
|
||||
}
|
||||
|
||||
@ -632,7 +632,7 @@ class Common: NSObject {
|
||||
return VO_TRUE
|
||||
case VOCTRL_GET_DISPLAY_RES:
|
||||
guard let screen = getCurrentScreen() else {
|
||||
log.sendWarning("No Screen available to retrieve frame")
|
||||
log.warning("No Screen available to retrieve frame")
|
||||
return VO_NOTAVAIL
|
||||
}
|
||||
let sizeData = data!.assumingMemoryBound(to: Int32.self)
|
||||
|
@ -260,7 +260,7 @@ class GLLayer: CAOpenGLLayer {
|
||||
}
|
||||
|
||||
guard let pixelFormat = pix, err == kCGLNoError else {
|
||||
ccb.log.sendError("Couldn't create any CGL pixel format")
|
||||
ccb.log.error("Couldn't create any CGL pixel format")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ class GLLayer: CAOpenGLLayer {
|
||||
return attributeLookUp[value.rawValue] ?? String(value.rawValue)
|
||||
})
|
||||
|
||||
ccb.log.sendVerbose("Created CGL pixel format with attributes: " +
|
||||
ccb.log.verbose("Created CGL pixel format with attributes: " +
|
||||
"\(attArray.joined(separator: ", "))")
|
||||
return (pix, glFormat.contains(glFormat10Bit) ? 16 : 8, err)
|
||||
}
|
||||
@ -305,11 +305,11 @@ class GLLayer: CAOpenGLLayer {
|
||||
}
|
||||
|
||||
let errS = String(cString: CGLErrorString(err))
|
||||
ccb.log.sendWarning("Couldn't create a " +
|
||||
ccb.log.warning("Couldn't create a " +
|
||||
"\(software ? "software" : "hardware accelerated") " +
|
||||
"CGL pixel format: \(errS) (\(err.rawValue))")
|
||||
if software == false && ccb.option.mac.cocoa_cb_sw_renderer == -1 {
|
||||
ccb.log.sendWarning("Falling back to software renderer")
|
||||
ccb.log.warning("Falling back to software renderer")
|
||||
}
|
||||
|
||||
return (pix, 8, err)
|
||||
@ -321,7 +321,7 @@ class GLLayer: CAOpenGLLayer {
|
||||
|
||||
guard let cglContext = context, error == kCGLNoError else {
|
||||
let errS = String(cString: CGLErrorString(error))
|
||||
ccb.log.sendError("Couldn't create a CGLContext: " + errS)
|
||||
ccb.log.error("Couldn't create a CGLContext: " + errS)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ class Window: NSWindow, NSWindowDelegate {
|
||||
|
||||
override func setFrame(_ frameRect: NSRect, display flag: Bool) {
|
||||
if frameRect.width < minSize.width || frameRect.height < minSize.height {
|
||||
common.log.sendVerbose("tried to set too small window size: \(frameRect.size)")
|
||||
common.log.verbose("tried to set too small window size: \(frameRect.size)")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class MacCommon: Common {
|
||||
let (_, wr) = getInitProperties(vo)
|
||||
|
||||
guard let layer = self.layer else {
|
||||
log.sendError("Something went wrong, no MetalLayer was initialized")
|
||||
log.error("Something went wrong, no MetalLayer was initialized")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user