Skip to content

Commit a058f4f

Browse files
committed
Switch from NSLog to OSLog
1 parent 14e2e94 commit a058f4f

14 files changed

+182
-127
lines changed

BUILDING.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@ Prerequisites
1111

1212
Products
1313
-------
14-
The "QLVideo" scheme in the Xcode project `QLVideo.xcodeproj` builds the following Products:
14+
The Xcode project `QLVideo.xcodeproj` builds the following Products:
1515

16-
* ffmpeg - The [FFmpeg](http://ffmpeg.org/) libraries. The plugins depend on these.
17-
* QLVideo.app - Launch Services won't read [Uniform Type Identifiers](http://developer.apple.com/library/mac/documentation/General/Conceptual/DevPedia-CocoaCore/UniformTypeIdentifier.html) from plugin bundles, so this dummy app serves to register the UTIs of the media types that the plugins understand. Should be installed in `/Library/Application Support/QLVideo/`.
18-
* Video.mdimporter - Spotlight plugin. Should be installed in `/Library/Spotlight/`.
19-
* Video.qlgenerator - QuickLook plugin. Should be installed in `/Library/QuickLook/`.
20-
21-
The `resetmds` and `resetquicklood` post-installation scripts can be run to inform Launch Services, SpotLight and QuickLook respectively of any changes.
16+
* QuickLook Video.app - App that hosts plugins and registers the
17+
[Uniform Type Identifiers](http://developer.apple.com/library/mac/documentation/General/Conceptual/DevPedia-CocoaCore/UniformTypeIdentifier.html)
18+
of the media types that the plugins understand.
19+
* mdimporter - Spotlight plugin provides metadata.
20+
* qlgenerator - QuickLook plugin provides static previews and, on macOS versions prior to Catalina, thumbnails.
21+
* thumbnailer - QuickLook plugin provides thumbnails on macOS Catalina and later.
22+
* benchmark - Simple executable for benchmarking, not included in the app.
23+
* ffmpeg - The [FFmpeg](http://ffmpeg.org/) libraries. The plugins depend on these. Also builds a standalone version of the `ffprobe` executable for bug reporting.
24+
* aom - Support for the [AV1](https://en.wikipedia.org/wiki/AV1) codec. ffmpeg depends on this.
2225

2326
Debugging
2427
---------
25-
The Spotlight and QuickLook processes cannot be debugged on 10.11 and later due to System Integrity Protection. Copy `mdimport` or `qlmanage` from `/usr/local` to the project directory, and use this copy to debug the plugin.
26-
27-
Packaging
28-
---------
29-
The [Packages](http://s.sudre.free.fr/Software/Packages/about.html) project `QLVideo.pkgproj` packages the above targets into a flat `.pkg` file for distribution. The `.pkg` file includes the post-installation scripts.
28+
All plugins produce output in the system log. Use the filter `subsystem:uk.org.marginal.qlvideo` in the Console app.
29+
* mdimporter - Invoke for debugging with `mdimport -n -d3 <testfile>`
30+
* glgenerator - Invoke for debugging with `qlmanage -p <testfile>`
31+
* thumbnailer - Invoke for debugging with `qlmanage -t -f2 <testfile>`
3032

3133
Notes
3234
-----

QLVideo.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@
346346
ABE72EBC29392EEB005433DF /* ffprobe */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ffprobe; path = universal/bin/ffprobe; sourceTree = BUILT_PRODUCTS_DIR; };
347347
ABE72EC0293A32B5005433DF /* ffmpeg */ = {isa = PBXFileReference; lastKnownFileType = text; name = ffmpeg; path = universal/bin/ffmpeg; sourceTree = BUILT_PRODUCTS_DIR; };
348348
ABE72EC2293D1DC6005433DF /* OldVersionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OldVersionView.swift; sourceTree = "<group>"; };
349+
ABE72ED6294379D1005433DF /* GetMetadataForFile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GetMetadataForFile.h; sourceTree = "<group>"; };
349350
/* End PBXFileReference section */
350351

351352
/* Begin PBXFrameworksBuildPhase section */
@@ -572,6 +573,7 @@
572573
isa = PBXGroup;
573574
children = (
574575
AB9FB57E1965DD7200D39647 /* main.m */,
576+
ABE72ED6294379D1005433DF /* GetMetadataForFile.h */,
575577
AB9FB5801965DD7200D39647 /* GetMetadataForFile.m */,
576578
AB9FB58C1965DF0700D39647 /* Info.plist */,
577579
ABB1A29A1A1C358500EEF82B /* buildschema */,

app/AppDelegate.swift

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import Cocoa
9+
import OSLog
910

1011

1112
// Settings
@@ -39,16 +40,20 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3940
@IBOutlet var oldVersionWindow: NSWindow!
4041

4142
var defaults: UserDefaults?
43+
var logger: OSLog?
4244

4345
lazy var snapshotTimeFormatter: DateComponentsFormatter = {
4446
let formatter = DateComponentsFormatter()
4547
formatter.unitsStyle = .abbreviated
4648
return formatter
4749
}()
48-
// View is loaded but not yet displayed - read settings
4950

51+
// View is loaded but not yet displayed - read settings
5052
func applicationDidFinishLaunching(_ aNotification: Notification) {
5153

54+
logger = OSLog(subsystem: "uk.org.marginal.qlvideo", category: "app")
55+
os_log("applicationDidFinishLaunching", log: logger!, type: .info)
56+
5257
// Remove the searchable Help entry
5358
NSApplication.shared.helpMenu = NSMenu(title: "Unused")
5459

@@ -87,7 +92,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
8792
}
8893

8994
if (defaults == nil) {
90-
NSLog("QLVideo app can't access defaults for application group \(suiteName)")
95+
os_log("Can't access defaults for application group %{public}s", log: logger!, type: .error, suiteName)
9196
} else {
9297
maybeResetCache(version)
9398
maybeResetSpotlight(version)
@@ -151,7 +156,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
151156
}
152157
} catch {
153158
// Can't happen :)
154-
NSLog("QLVideo app couldn't remove old user plugins \(error)")
159+
os_log("Couldn't remove old user plugins: %{public}s", log: logger!, type: .error, String(describing: error))
155160
}
156161

157162
if (fm.fileExists(atPath: "/Library/Application Support/QLVideo") ||
@@ -165,7 +170,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
165170
if (error == nil) {
166171
return true;
167172
} else {
168-
NSLog("QLVideo app couldn't remove old system plugins \(String(describing: error!))")
173+
os_log("Couldn't remove old system plugins: %{public}s", log: logger!, type: .error, String(describing: error!))
174+
169175
}
170176
}
171177
} else {

mdimporter/GetMetadataForFile.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// GetMetadataForFile.h
3+
// QLVideo
4+
//
5+
// Created by Jonathan Harris on 09/12/2022.
6+
//
7+
8+
#ifndef GetMetadataForFile_h
9+
#define GetMetadataForFile_h
10+
11+
#include <os/log.h>
12+
13+
#include "libavformat/avformat.h"
14+
#include "libavutil/log.h"
15+
16+
#ifndef DEBUG
17+
#include <pthread.h>
18+
#include <signal.h>
19+
#endif
20+
21+
#import <Cocoa/Cocoa.h>
22+
23+
extern os_log_t logger;
24+
25+
#endif /* GetMetadataForFile_h */

mdimporter/GetMetadataForFile.m

+16-13
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
//
77
//
88

9-
#import <Cocoa/Cocoa.h>
10-
11-
#include <libavformat/avformat.h>
12-
#include <libavutil/dict.h>
13-
9+
#include "GetMetadataForFile.h"
1410

1511
// Custom attributes
1612
NSString *kFrameRate = @"uk_org_marginal_qlvideo_framerate";
@@ -19,14 +15,19 @@
1915

2016
Boolean die(CFStringRef pathToFile, int err)
2117
{
22-
#ifdef DEBUG
2318
char errbuf[AV_ERROR_MAX_STRING_SIZE];
2419
const char *errbuf_ptr = errbuf;
2520

26-
if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
27-
errbuf_ptr = strerror(AVUNERROR(err));
28-
NSLog(@"Video.mdimporter %@: %s", pathToFile, errbuf_ptr);
29-
#endif
21+
if (!logger)
22+
{}
23+
else if (!av_strerror(err, errbuf, sizeof(errbuf)))
24+
{
25+
os_log_error(logger, "%@: %{public}s", pathToFile, errbuf);
26+
}
27+
else
28+
{
29+
os_log_error(logger, "%@: %{darwin.errno}d", pathToFile, err);
30+
}
3031
return false;
3132
}
3233

@@ -135,6 +136,10 @@ Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attribute
135136
if (!filename || !CFStringGetFileSystemRepresentation(pathToFile, [filename mutableBytes], [filename length]))
136137
return false;
137138

139+
if (!logger)
140+
logger = os_log_create("uk.org.marginal.qlvideo", "mdimporter");
141+
os_log_info(logger, "Import with UTI=%{public}@ for %{public}@", contentTypeUTI, pathToFile);
142+
138143
AVFormatContext *fmt_ctx = NULL;
139144
int err;
140145
if ((err = avformat_open_input(&fmt_ctx, [filename mutableBytes], NULL, NULL)))
@@ -362,10 +367,8 @@ Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attribute
362367
if (![codecs containsObject:nsname])
363368
[codecs addObject:nsname];
364369
}
365-
#ifdef DEBUG
366370
else
367-
NSLog(@"Video.mdimporter %@: unsupported codec with id %d for stream %d", pathToFile, params->codec_id, stream_idx);
368-
#endif
371+
os_log_info(logger, "Unsupported codec with id %d for stream %d in %{public}@", params->codec_id, stream_idx, pathToFile);
369372
}
370373

371374
if ([codecs count])

mdimporter/en.lproj/schema.strings

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* Video frames per second */
1+
/* Finder Info window: Video frames per second */
22
"uk_org_marginal_qlvideo_framerate" = "Frame rate";
33

4-
/* For translations see /System/Library/Frameworks/AVKit.framework/Resources/??.lproj/Localizable.strings */
4+
/* Finder Info window: Subtitle languages */
55
"uk_org_marginal_qlvideo_subtitles" = "Subtitles";

mdimporter/main.m

+10-24
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
//
77
//
88

9-
10-
11-
12-
139
//==============================================================================
1410
//
1511
// DO NO MODIFY THE CONTENT OF THIS FILE
@@ -19,20 +15,23 @@
1915
//
2016
//==============================================================================
2117

18+
#include "GetMetadataForFile.h"
2219

23-
#import <Cocoa/Cocoa.h>
20+
os_log_t logger = NULL;
2421

25-
#include <signal.h>
26-
#include <dlfcn.h>
27-
28-
#include "libavformat/avformat.h"
29-
#include "libavutil/log.h"
22+
#ifndef DEBUG
23+
void segv_handler(int signum)
24+
{
25+
if (logger)
26+
os_log_fault(logger, "Thread exiting on signal %{darwin.signal}d", signum);
27+
pthread_exit(NULL);
28+
}
29+
#endif
3030

3131
// -----------------------------------------------------------------------------
3232
// constants
3333
// -----------------------------------------------------------------------------
3434

35-
3635
#define PLUGIN_ID "3BD30E87-1D12-4322-AFCE-F58CB4B56096"
3736

3837
//
@@ -88,19 +87,6 @@ Boolean GetMetadataForFile(void *thisInterface,
8887
};
8988

9089

91-
void segv_handler(int signum)
92-
{
93-
char *sCrashReporterInfo = dlsym(RTLD_DEFAULT, "__crashreporter_info__");
94-
95-
if (sCrashReporterInfo && *sCrashReporterInfo)
96-
NSLog(@"Video.mdimporter crashed: %s", sCrashReporterInfo);
97-
else
98-
NSLog(@"Video.mdimporter crashed!");
99-
100-
exit(EXIT_FAILURE);
101-
}
102-
103-
10490
// -----------------------------------------------------------------------------
10591
// AllocMetadataImporterPluginType
10692
// -----------------------------------------------------------------------------

qlgenerator/GeneratePreviewForURL.m

+11-25
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
8686

8787
@autoreleasepool
8888
{
89-
#ifdef DEBUG
90-
NSLog(@"QLVideo preview %@ with options %@", [(__bridge NSURL*)url path], options);
91-
#endif
89+
os_log_info(logger, "Preview with options=%{public}@ UTI=%{public}@ for %{public}@", options, contentTypeUTI, [(__bridge NSURL*)url path]);
9290
Snapshotter *snapshotter = nil;
9391

9492
// Prefer any cover art (if present) over a playable preview or static snapshot in Finder and Spotlight views
@@ -102,9 +100,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
102100
if (cover)
103101
{
104102
CGSize coversize = CGSizeMake(CGImageGetWidth(cover), CGImageGetHeight(cover));
105-
#ifdef DEBUG
106-
NSLog(@"QLVideo supplying %dx%d cover art for %@", (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
107-
#endif
103+
os_log_info(logger, "Supplying %dx%d cover art for %{public}@", (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
108104
CGContextRef context = QLPreviewRequestCreateContext(preview, coversize, true, nil);
109105
CGContextDrawImage(context, CGRectMake(0, 0, coversize.width, coversize.height), cover);
110106
QLPreviewRequestFlushContext(preview, context);
@@ -120,10 +116,8 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
120116
if (QLPreviewRequestIsCancelled(preview)) return kQLReturnNoError;
121117
CFBundleRef myBundle = QLPreviewRequestGetGeneratorBundle(preview);
122118
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kSettingsSuiteName];
123-
#ifdef DEBUG
124-
NSLog(@"QLvideo preview defaults=%@", defaults);
125-
NSLog(@"QLvideo preview SnapshoCount=%ld", (long)[defaults integerForKey:kSettingsSnapshotCount]);
126-
#endif
119+
os_log_debug(logger, "QLvideo preview defaults=%@", defaults);
120+
os_log_debug(logger, "QLvideo preview SnapshoCount=%ld", (long)[defaults integerForKey:kSettingsSnapshotCount]);
127121

128122
if (![defaults boolForKey:kSettingsSnapshotAlways])
129123
@autoreleasepool // Reduce peak footprint
@@ -132,9 +126,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
132126

133127
if (player.playable)
134128
{
135-
#ifdef DEBUG
136-
NSLog(@"QLVideo handing off %@ to AVFoundation", [(__bridge NSURL*)url path]);
137-
#endif
129+
os_log_info(logger, "Handing off %{public}@ to AVFoundation", [(__bridge NSURL*)url path]);
138130
NSString *title = [player title];
139131
if (!title)
140132
title = [(__bridge NSURL *)url lastPathComponent];
@@ -173,9 +165,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
173165
if (cover)
174166
{
175167
CGSize coversize = CGSizeMake(CGImageGetWidth(cover), CGImageGetHeight(cover));
176-
#ifdef DEBUG
177-
NSLog(@"QLVideo supplying %dx%d cover art for %@", (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
178-
#endif
168+
os_log_info(logger, "Supplying %dx%d cover art for %{public}@", (int) coversize.width, (int) coversize.height, [(__bridge NSURL*)url path]);
179169
NSDictionary *properties = @{(NSString *) kQLPreviewPropertyDisplayNameKey: theTitle};
180170
CGContextRef context = QLPreviewRequestCreateContext(preview, coversize, true, (__bridge CFDictionaryRef) properties);
181171
CGContextDrawImage(context, CGRectMake(0, 0, coversize.width, coversize.height), cover);
@@ -257,9 +247,7 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
257247
(__bridge NSString *) kQLPreviewPropertyPageElementXPathKey: @"/html/body/div",
258248
(NSString *) kQLPreviewPropertyPDFStyleKey: @(kQLPreviewPDFPagesWithThumbnailsOnLeftStyle),
259249
(NSString *) kQLPreviewPropertyAttachmentsKey: attachments};
260-
#ifdef DEBUG
261-
NSLog(@"QLVideo supplying %lu %dx%d images for %@", [properties[(NSString *) kQLPreviewPropertyAttachmentsKey] count], (int) scaled.width, (int) scaled.height, [(__bridge NSURL*)url path]);
262-
#endif
250+
os_log_info(logger, "Supplying %lu %dx%d images for %{public}@", [properties[(NSString *) kQLPreviewPropertyAttachmentsKey] count], (int) scaled.width, (int) scaled.height, [(__bridge NSURL*)url path]);
263251
QLPreviewRequestSetDataRepresentation(preview, (__bridge CFDataRef) [html dataUsingEncoding:NSUTF8StringEncoding], kUTTypeHTML,
264252
(__bridge CFDictionaryRef) properties);
265253
return kQLReturnNoError; // early exit
@@ -276,7 +264,6 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
276264
if (thePreview)
277265
{
278266
CGSize size = CGSizeMake(CGImageGetWidth(thePreview), CGImageGetHeight(thePreview));
279-
#ifdef DEBUG
280267
# if 0 // Make small image for running with no OpenGL acceleration (e.g. under virtualisation) to avoid QuickLookUIHelper timing out
281268
const int kMaxWidth = 640;
282269
const int kMaxHeight = 480;
@@ -288,19 +275,18 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
288275
else
289276
size = CGSizeMake(round(original.width * kMaxHeight / original.height), kMaxHeight);
290277
# endif
291-
NSLog(@"QLVideo supplying %dx%d image for %@", (int) size.width, (int) size.height, [(__bridge NSURL*)url path]);
292-
#endif
278+
os_log_info(logger, "Supplying %dx%d image for %{public}@", (int) size.width, (int) size.height, [(__bridge NSURL*)url path]);
293279
NSDictionary *properties = @{(NSString *) kQLPreviewPropertyDisplayNameKey: theTitle};
294280
CGContextRef context = QLPreviewRequestCreateContext(preview, size, true, (__bridge CFDictionaryRef) properties);
295281
CGContextDrawImage(context, CGRectMake(0, 0, size.width, size.height), thePreview);
296282
QLPreviewRequestFlushContext(preview, context);
297283
CGContextRelease(context);
298284
CGImageRelease(thePreview);
299285
}
300-
#ifdef DEBUG
301286
else
302-
NSLog(@"QLVideo can't supply anything for %@", [(__bridge NSURL*)url path]);
303-
#endif
287+
{
288+
os_log_error(logger, "Can't supply anything for %@", [(__bridge NSURL*)url path]);
289+
}
304290
}
305291
return kQLReturnNoError;
306292
}

qlgenerator/GenerateThumbnailForURL.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
3939
{
4040
// https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/Quicklook_Programming_Guide/Articles/QLImplementationOverview.html
4141

42+
#ifndef DEBUG // Skip this check to enable debugging with qlmanage -t ...
4243
// On Catalina and later the QLThumbnailGenerator application extension generates thumbnails
4344
if (newQuickLook)
4445
return kQLReturnNoError;
46+
#endif
4547

4648
CGImageRef snapshot = NULL;
4749

4850
@autoreleasepool
4951
{
50-
#ifdef DEBUG
51-
NSLog(@"QLVideo options=%@ size=%dx%d %@", options, (int) maxSize.width, (int) maxSize.height, url);
52-
#endif
52+
os_log_info(logger, "Thumbnail with options=%{public}@ UTI=%{public}@ size=%dx%d for %{public}@", options, contentTypeUTI, (int) maxSize.width, (int) maxSize.height, url);
5353
Snapshotter *snapshotter = [[Snapshotter alloc] initWithURL:url];
5454
if (!snapshotter) return kQLReturnNoError;
5555

qlgenerator/Snapshotter.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import <Cocoa/Cocoa.h>
10+
#include <os/log.h>
1011

1112
#include <libavcodec/avcodec.h>
1213
#include "libavformat/avformat.h"

0 commit comments

Comments
 (0)