Skip to content

Commit 6a7328f

Browse files
ref: Use average color for redact masking (#3877)
Use the text color or the average color of the image as the redaction mask. Co-authored-by: Philipp Hofmann <[email protected]>
1 parent c379c5e commit 6a7328f

18 files changed

+658
-204
lines changed

Samples/iOS-Swift/iOS-Swift/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2525
options.debug = true
2626

2727
if #available(iOS 16.0, *) {
28-
options.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: 0, errorSampleRate: 1, redactAllText: true, redactAllImages: true)
28+
options.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1, redactAllText: true, redactAllImages: true)
2929
}
3030

3131
if #available(iOS 15.0, *) {

Sentry.xcodeproj/project.pbxproj

Lines changed: 28 additions & 8 deletions
Large diffs are not rendered by default.

Sources/Sentry/SentryCoreGraphicsHelper.m

Lines changed: 0 additions & 18 deletions
This file was deleted.

Sources/Sentry/SentrySessionReplay.m

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ @implementation SentrySessionReplay {
3535
NSDate *_sessionStart;
3636
NSMutableArray<UIImage *> *imageCollection;
3737
SentryReplayOptions *_replayOptions;
38-
SentryOnDemandReplay *_replayMaker;
38+
id<SentryReplayVideoMaker> _replayMaker;
3939
SentryDisplayLinkWrapper *_displayLink;
4040
SentryCurrentDateProvider *_dateProvider;
4141
id<SentryRandom> _sentryRandom;
@@ -48,7 +48,7 @@ @implementation SentrySessionReplay {
4848
- (instancetype)initWithSettings:(SentryReplayOptions *)replayOptions
4949
replayFolderPath:(NSURL *)folderPath
5050
screenshotProvider:(id<SentryViewScreenshotProvider>)screenshotProvider
51-
replayMaker:(id<SentryReplayMaker>)replayMaker
51+
replayMaker:(id<SentryReplayVideoMaker>)replayMaker
5252
dateProvider:(SentryCurrentDateProvider *)dateProvider
5353
random:(id<SentryRandom>)random
5454
displayLinkWrapper:(SentryDisplayLinkWrapper *)displayLinkWrapper;
@@ -242,6 +242,7 @@ - (void)createAndCapture:(NSURL *)videoUrl
242242
duration:(NSTimeInterval)duration
243243
startedAt:(NSDate *)start
244244
{
245+
__weak SentrySessionReplay *weakSelf = self;
245246
[_replayMaker
246247
createVideoWithDuration:duration
247248
beginning:start
@@ -251,17 +252,22 @@ - (void)createAndCapture:(NSURL *)videoUrl
251252
if (error != nil) {
252253
SENTRY_LOG_ERROR(@"Could not create replay video - %@", error);
253254
} else {
254-
[self captureSegment:self->_currentSegmentId++
255-
video:videoInfo
256-
replayId:self->_sessionReplayId
257-
replayType:kSentryReplayTypeSession];
258-
259-
[self->_replayMaker releaseFramesUntil:videoInfo.end];
260-
self->_videoSegmentStart = nil;
255+
[weakSelf newSegmentAvailable:videoInfo];
261256
}
262257
}];
263258
}
264259

260+
- (void)newSegmentAvailable:(SentryVideoInfo *)videoInfo
261+
{
262+
[self captureSegment:self->_currentSegmentId++
263+
video:videoInfo
264+
replayId:self->_sessionReplayId
265+
replayType:kSentryReplayTypeSession];
266+
267+
[_replayMaker releaseFramesUntil:videoInfo.end];
268+
_videoSegmentStart = nil;
269+
}
270+
265271
- (void)captureSegment:(NSInteger)segment
266272
video:(SentryVideoInfo *)videoInfo
267273
replayId:(SentryId *)replayid
@@ -306,11 +312,16 @@ - (void)takeScreenshot
306312
_processingScreenshot = YES;
307313
}
308314

309-
UIImage *screenshot = [_screenshotProvider imageWithView:_rootView options:_replayOptions];
315+
__weak SentrySessionReplay *weakSelf = self;
316+
[_screenshotProvider imageWithView:_rootView
317+
options:_replayOptions
318+
onComplete:^(UIImage *screenshot) { [weakSelf newImage:screenshot]; }];
319+
}
310320

321+
- (void)newImage:(UIImage *)image
322+
{
311323
_processingScreenshot = NO;
312-
313-
[self->_replayMaker addFrameAsyncWithImage:screenshot];
324+
[_replayMaker addFrameAsyncWithImage:image];
314325
}
315326

316327
@end

Sources/Sentry/SentrySessionReplayIntegration.m

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@
2828
- (void)newSceneActivate;
2929
@end
3030

31-
API_AVAILABLE(ios(16.0), tvos(16.0))
32-
@interface
33-
SentryViewPhotographer (SentryViewScreenshotProvider) <SentryViewScreenshotProvider>
34-
@end
35-
36-
API_AVAILABLE(ios(16.0), tvos(16.0))
37-
@interface
38-
SentryOnDemandReplay (SentryReplayMaker) <SentryReplayMaker>
39-
40-
@end
41-
4231
@implementation SentrySessionReplayIntegration {
4332
BOOL _startedAsFullSession;
4433
SentryReplayOptions *_replayOptions;

Sources/Sentry/include/SentryCoreGraphicsHelper.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

Sources/Sentry/include/SentryPrivate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111

1212
// Headers that also import SentryDefines should be at the end of this list
1313
// otherwise it wont compile
14-
#import "SentryCoreGraphicsHelper.h"

Sources/Sentry/include/SentrySessionReplay.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,19 @@
1313

1414
@protocol SentryRandom;
1515
@protocol SentryRedactOptions;
16+
@protocol SentryViewScreenshotProvider;
17+
@protocol SentryReplayVideoMaker;
1618

1719
NS_ASSUME_NONNULL_BEGIN
1820

19-
@protocol SentryReplayMaker <NSObject>
20-
21-
- (void)addFrameAsyncWithImage:(UIImage *)image;
22-
- (void)releaseFramesUntil:(NSDate *)date;
23-
- (BOOL)createVideoWithDuration:(NSTimeInterval)duration
24-
beginning:(NSDate *)beginning
25-
outputFileURL:(NSURL *)outputFileURL
26-
error:(NSError *_Nullable *_Nullable)error
27-
completion:
28-
(void (^)(SentryVideoInfo *_Nullable, NSError *_Nullable))completion;
29-
30-
@end
31-
32-
@protocol SentryViewScreenshotProvider <NSObject>
33-
- (UIImage *)imageWithView:(UIView *)view options:(id<SentryRedactOptions>)options;
34-
@end
35-
36-
API_AVAILABLE(ios(16.0), tvos(16.0))
3721
@interface SentrySessionReplay : NSObject
3822

3923
@property (nonatomic, strong, readonly) SentryId *sessionReplayId;
4024

4125
- (instancetype)initWithSettings:(SentryReplayOptions *)replayOptions
4226
replayFolderPath:(NSURL *)folderPath
4327
screenshotProvider:(id<SentryViewScreenshotProvider>)photographer
44-
replayMaker:(id<SentryReplayMaker>)replayMaker
28+
replayMaker:(id<SentryReplayVideoMaker>)replayMaker
4529
dateProvider:(SentryCurrentDateProvider *)dateProvider
4630
random:(id<SentryRandom>)random
4731
displayLinkWrapper:(SentryDisplayLinkWrapper *)displayLinkWrapper;

Sources/Swift/Integrations/SessionReplay/SentryOnDemandReplay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum SentryOnDemandReplayError: Error {
2222
}
2323

2424
@objcMembers
25-
class SentryOnDemandReplay: NSObject {
25+
class SentryOnDemandReplay: NSObject, SentryReplayVideoMaker {
2626
private let _outputPath: String
2727
private var _currentPixelBuffer: SentryPixelBuffer?
2828
private var _totalFrames = 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#if canImport(UIKit)
2+
import Foundation
3+
import UIKit
4+
5+
@objc
6+
protocol SentryReplayVideoMaker: NSObjectProtocol {
7+
func addFrameAsync(image: UIImage)
8+
func releaseFramesUntil(_ date: Date)
9+
func createVideoWith(duration: TimeInterval, beginning: Date, outputFileURL: URL, completion: @escaping (SentryVideoInfo?, Error?) -> Void) throws
10+
}
11+
#endif

0 commit comments

Comments
 (0)