Skip to content

Commit

Permalink
Revert "Clean Up PR"
Browse files Browse the repository at this point in the history
This reverts commit b725be7.
  • Loading branch information
brustolin committed Feb 21, 2024
1 parent 32227b1 commit a99524d
Show file tree
Hide file tree
Showing 9 changed files with 768 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,14 @@
D8370B6C273DF20F00F66E2D /* SentryNSURLSessionTaskSearch.h in Headers */ = {isa = PBXBuildFile; fileRef = D8370B6B273DF20F00F66E2D /* SentryNSURLSessionTaskSearch.h */; };
D83D07812B7E5EFA00CC9674 /* SentryReplaySettings.h in Headers */ = {isa = PBXBuildFile; fileRef = D83D07802B7E5EFA00CC9674 /* SentryReplaySettings.h */; };
D83D07832B7E5F2100CC9674 /* SentryReplaySettings.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D07822B7E5F2100CC9674 /* SentryReplaySettings.m */; };
D83D07862B7E65DC00CC9674 /* SentryViewPhotographer.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D07852B7E65DC00CC9674 /* SentryViewPhotographer.m */; };
D83D07882B7E65F000CC9674 /* SentryViewPhotographer.h in Headers */ = {isa = PBXBuildFile; fileRef = D83D07872B7E65F000CC9674 /* SentryViewPhotographer.h */; };
D83D078A2B7E691400CC9674 /* SentryOnDemandReplay.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D07892B7E691400CC9674 /* SentryOnDemandReplay.m */; };
D83D078C2B7E692300CC9674 /* SentryOnDemandReplay.h in Headers */ = {isa = PBXBuildFile; fileRef = D83D078B2B7E692300CC9674 /* SentryOnDemandReplay.h */; };
D83D078E2B7E712F00CC9674 /* SentrySessionReplay.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D078D2B7E712F00CC9674 /* SentrySessionReplay.m */; };
D83D07902B7E713A00CC9674 /* SentrySessionReplayIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D078F2B7E713A00CC9674 /* SentrySessionReplayIntegration.m */; };
D83D07922B7E714B00CC9674 /* SentrySessionReplay.h in Headers */ = {isa = PBXBuildFile; fileRef = D83D07912B7E714B00CC9674 /* SentrySessionReplay.h */; };
D83D07942B7E715700CC9674 /* SentrySessionReplayIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = D83D07932B7E715700CC9674 /* SentrySessionReplayIntegration.h */; };
D83D079B2B7F9D1C00CC9674 /* SentryMsgPackSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = D83D07992B7F9D1C00CC9674 /* SentryMsgPackSerializer.h */; };
D83D079C2B7F9D1C00CC9674 /* SentryMsgPackSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = D83D079A2B7F9D1C00CC9674 /* SentryMsgPackSerializer.m */; };
D84541182A2DC2CD00E2B11C /* SentryBinaryImageCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84541172A2DC2CD00E2B11C /* SentryBinaryImageCacheTests.swift */; };
Expand Down Expand Up @@ -1768,6 +1776,14 @@
D83D07802B7E5EFA00CC9674 /* SentryReplaySettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryReplaySettings.h; path = Public/SentryReplaySettings.h; sourceTree = "<group>"; };
D83D07822B7E5F2100CC9674 /* SentryReplaySettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryReplaySettings.m; sourceTree = "<group>"; };
D83D07842B7E634F00CC9674 /* SentryReplaySettings+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryReplaySettings+Private.h"; path = "include/HybridPublic/SentryReplaySettings+Private.h"; sourceTree = "<group>"; };
D83D07852B7E65DC00CC9674 /* SentryViewPhotographer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryViewPhotographer.m; sourceTree = "<group>"; };
D83D07872B7E65F000CC9674 /* SentryViewPhotographer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryViewPhotographer.h; path = include/SentryViewPhotographer.h; sourceTree = "<group>"; };
D83D07892B7E691400CC9674 /* SentryOnDemandReplay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryOnDemandReplay.m; sourceTree = "<group>"; };
D83D078B2B7E692300CC9674 /* SentryOnDemandReplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryOnDemandReplay.h; path = include/SentryOnDemandReplay.h; sourceTree = "<group>"; };
D83D078D2B7E712F00CC9674 /* SentrySessionReplay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentrySessionReplay.m; sourceTree = "<group>"; };
D83D078F2B7E713A00CC9674 /* SentrySessionReplayIntegration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentrySessionReplayIntegration.m; sourceTree = "<group>"; };
D83D07912B7E714B00CC9674 /* SentrySessionReplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySessionReplay.h; path = include/SentrySessionReplay.h; sourceTree = "<group>"; };
D83D07932B7E715700CC9674 /* SentrySessionReplayIntegration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySessionReplayIntegration.h; path = include/SentrySessionReplayIntegration.h; sourceTree = "<group>"; };
D83D07992B7F9D1C00CC9674 /* SentryMsgPackSerializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMsgPackSerializer.h; path = include/SentryMsgPackSerializer.h; sourceTree = "<group>"; };
D83D079A2B7F9D1C00CC9674 /* SentryMsgPackSerializer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMsgPackSerializer.m; sourceTree = "<group>"; };
D84541172A2DC2CD00E2B11C /* SentryBinaryImageCacheTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBinaryImageCacheTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3415,9 +3431,19 @@
D80694CC2B7E0A3E00B820E6 /* SentryReplayType.m */,
D88D6C1B2B7B5A8800C8C633 /* SentryReplayRecording.h */,
D88D6C1C2B7B5A8800C8C633 /* SentryReplayRecording.m */,
D88D6C1F2B7BA25400C8C633 /* SentryReplayEnvelopeItemHeader.h */,
D88D6C202B7BA25400C8C633 /* SentryReplayEnvelopeItemHeader.m */,
D83D07802B7E5EFA00CC9674 /* SentryReplaySettings.h */,
D83D07842B7E634F00CC9674 /* SentryReplaySettings+Private.h */,
D83D07822B7E5F2100CC9674 /* SentryReplaySettings.m */,
D83D07872B7E65F000CC9674 /* SentryViewPhotographer.h */,
D83D07852B7E65DC00CC9674 /* SentryViewPhotographer.m */,
D83D078B2B7E692300CC9674 /* SentryOnDemandReplay.h */,
D83D07892B7E691400CC9674 /* SentryOnDemandReplay.m */,
D83D07912B7E714B00CC9674 /* SentrySessionReplay.h */,
D83D078D2B7E712F00CC9674 /* SentrySessionReplay.m */,
D83D07932B7E715700CC9674 /* SentrySessionReplayIntegration.h */,
D83D078F2B7E713A00CC9674 /* SentrySessionReplayIntegration.m */,
);
name = SessionReplay;
sourceTree = "<group>";
Expand Down Expand Up @@ -3639,6 +3665,7 @@
03F84D2A27DD416B008FE43F /* SentryProfilingLogging.hpp in Headers */,
63FE714D20DA4C1100CDBAE8 /* SentryCrashJSONCodec.h in Headers */,
7BAF3DD4243DD40F008A5414 /* SentryTransportFactory.h in Headers */,
D83D078C2B7E692300CC9674 /* SentryOnDemandReplay.h in Headers */,
63FE717F20DA4C1100CDBAE8 /* SentryCrashReportFields.h in Headers */,
7BE912AB272162AF00E49E62 /* SentryNoOpSpan.h in Headers */,
63FE70D120DA4C1000CDBAE8 /* SentryCrashMonitorContext.h in Headers */,
Expand Down Expand Up @@ -3711,6 +3738,7 @@
63FE712320DA4C1000CDBAE8 /* SentryCrashID.h in Headers */,
D88D6C1D2B7B5A8800C8C633 /* SentryReplayRecording.h in Headers */,
7DC27EC523997EB7006998B5 /* SentryAutoBreadcrumbTrackingIntegration.h in Headers */,
D83D07942B7E715700CC9674 /* SentrySessionReplayIntegration.h in Headers */,
63FE707F20DA4C1000CDBAE8 /* SentryCrashVarArgs.h in Headers */,
03F84D2627DD414C008FE43F /* SentryThreadMetadataCache.hpp in Headers */,
7BC9A20228F41350001E7C4C /* SentryMeasurementUnit.h in Headers */,
Expand Down Expand Up @@ -3834,6 +3862,7 @@
6344DDB01EC308E400D9160D /* SentryCrashInstallationReporter.h in Headers */,
8E25C95725F836EE00DC215B /* SentryRandom.h in Headers */,
7B5CAF7527F5A67C00ED0DB6 /* SentryNSURLRequestBuilder.h in Headers */,
D83D07882B7E65F000CC9674 /* SentryViewPhotographer.h in Headers */,
63FE70ED20DA4C1000CDBAE8 /* SentryCrashMonitor_NSException.h in Headers */,
7BA61CB4247BC3EB00C130A8 /* SentryCrashBinaryImageProvider.h in Headers */,
63FE713D20DA4C1100CDBAE8 /* SentryCrashLogger.h in Headers */,
Expand Down Expand Up @@ -3861,6 +3890,7 @@
6334314120AD9AE40077E581 /* SentryMechanism.h in Headers */,
03F84D2827DD414C008FE43F /* SentryCPU.h in Headers */,
0A80E435291017D500095219 /* SentryWatchdogTerminationScopeObserver.h in Headers */,
D83D07922B7E714B00CC9674 /* SentrySessionReplay.h in Headers */,
7B610D642512399600B0B5D9 /* SentryHub+Private.h in Headers */,
D8F6A24B2885515C00320515 /* SentryPredicateDescriptor.h in Headers */,
639FCF9C1EBC7F9500778193 /* SentryThread.h in Headers */,
Expand Down Expand Up @@ -4182,6 +4212,7 @@
7B8713B426415BAA006D6004 /* SentryAppStartTracker.m in Sources */,
7BDB03BB2513652900BAE198 /* SentryDispatchQueueWrapper.m in Sources */,
7B6C5EDE264E8DF00010D138 /* SentryFramesTracker.m in Sources */,
D83D07902B7E713A00CC9674 /* SentrySessionReplayIntegration.m in Sources */,
D84F833E2A1CC401005828E0 /* SentrySwiftAsyncIntegration.m in Sources */,
7B6438AB26A70F24000D0F65 /* UIViewController+Sentry.m in Sources */,
63AA76A31EB9CBAA00D153DE /* SentryDsn.m in Sources */,
Expand Down Expand Up @@ -4241,6 +4272,7 @@
15360CED2433A15500112302 /* SentryInstallation.m in Sources */,
7B98D7E825FB7BCD00C5A389 /* SentryAppState.m in Sources */,
D8370B6A273DF1E900F66E2D /* SentryNSURLSessionTaskSearch.m in Sources */,
D83D078E2B7E712F00CC9674 /* SentrySessionReplay.m in Sources */,
7B30B67E26527894006B2752 /* SentryDisplayLinkWrapper.m in Sources */,
63FE711D20DA4C1000CDBAE8 /* SentryCrashCPU_arm64.c in Sources */,
844EDC77294144DB00C86F34 /* SentrySystemWrapper.mm in Sources */,
Expand Down Expand Up @@ -4309,6 +4341,7 @@
7B6D1261265F784000C9BE4B /* PrivateSentrySDKOnly.mm in Sources */,
63BE85711ECEC6DE00DC44F5 /* NSDate+SentryExtras.m in Sources */,
7BD4BD4927EB2A5D0071F4FF /* SentryDiscardedEvent.m in Sources */,
D83D07862B7E65DC00CC9674 /* SentryViewPhotographer.m in Sources */,
03F84D3827DD4191008FE43F /* SentryBacktrace.cpp in Sources */,
63FE712720DA4C1000CDBAE8 /* SentryCrashThread.c in Sources */,
7B127B0F27CF6F4700A71ED2 /* SentryANRTrackingIntegration.m in Sources */,
Expand Down Expand Up @@ -4404,6 +4437,7 @@
63FE710520DA4C1000CDBAE8 /* SentryCrashLogger.c in Sources */,
0A2D8D5B289815C0008720F6 /* SentryBaseIntegration.m in Sources */,
639FCF991EBC7B9700778193 /* SentryEvent.m in Sources */,
D83D078A2B7E691400CC9674 /* SentryOnDemandReplay.m in Sources */,
632F43521F581D5400A18A36 /* SentryCrashExceptionApplication.m in Sources */,
620379DD2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m in Sources */,
7B77BE3727EC8460003C9020 /* SentryDiscardReasonMapper.m in Sources */,
Expand Down
234 changes: 234 additions & 0 deletions Sources/Sentry/SentryOnDemandReplay.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
#import "SentryOnDemandReplay.h"

#if SENTRY_HAS_UIKIT
# import "SentryLog.h"
# import <AVFoundation/AVFoundation.h>
# import <UIKit/UIKit.h>
@interface SentryReplayFrame : NSObject

@property (nonatomic, strong) NSString *imagePath;
@property (nonatomic, strong) NSDate *time;

- (instancetype)initWithPath:(NSString *)path time:(NSDate *)time;

@end

@implementation SentryReplayFrame
- (instancetype)initWithPath:(NSString *)path time:(NSDate *)time
{
if (self = [super init]) {
self.imagePath = path;
self.time = time;

Check warning on line 21 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L20-L21

Added lines #L20 - L21 were not covered by tests
}
return self;
}

Check warning on line 24 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L23-L24

Added lines #L23 - L24 were not covered by tests

@end

@implementation SentryOnDemandReplay {
NSString *_outputPath;
NSDate *_startTime;
NSMutableArray<SentryReplayFrame *> *_frames;
CGSize _videoSize;
dispatch_queue_t _onDemandDispatchQueue;
}

- (instancetype)initWithOutputPath:(NSString *)outputPath
{
if (self = [super init]) {
_outputPath = outputPath;
_startTime = [[NSDate alloc] init];
_frames = [NSMutableArray array];

Check warning on line 41 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L39-L41

Added lines #L39 - L41 were not covered by tests
//_videoSize = CGSizeMake(300, 651);
_videoSize = CGSizeMake(200, 434);
_bitRate = 20000;
_cacheMaxSize = NSUIntegerMax;
_onDemandDispatchQueue = dispatch_queue_create("io.sentry.sessionreplay.ondemand", NULL);
}
return self;
}

Check warning on line 49 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L43-L49

Added lines #L43 - L49 were not covered by tests

- (void)addFrame:(UIImage *)image
{
dispatch_async(_onDemandDispatchQueue, ^{
NSData *data = UIImagePNGRepresentation([self resizeImage:image withMaxWidth:300]);
NSDate *date = [[NSDate alloc] init];
NSTimeInterval interval = [date timeIntervalSinceDate:self->_startTime];
NSString *imagePath = [self->_outputPath
stringByAppendingPathComponent:[NSString stringWithFormat:@"%lf.png", interval]];

Check warning on line 58 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L54-L58

Added lines #L54 - L58 were not covered by tests

[data writeToFile:imagePath atomically:YES];

Check warning on line 60 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L60

Added line #L60 was not covered by tests

SentryReplayFrame *frame = [[SentryReplayFrame alloc] initWithPath:imagePath time:date];
[self->_frames addObject:frame];

Check warning on line 63 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L62-L63

Added lines #L62 - L63 were not covered by tests

while (self->_frames.count > self->_cacheMaxSize) {
[self removeOldestFrame];

Check warning on line 66 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L66

Added line #L66 was not covered by tests
}
});
}

Check warning on line 69 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L68-L69

Added lines #L68 - L69 were not covered by tests

- (UIImage *)resizeImage:(UIImage *)originalImage withMaxWidth:(CGFloat)maxWidth
{
CGSize originalSize = originalImage.size;
CGFloat aspectRatio = originalSize.width / originalSize.height;

Check warning on line 74 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L73-L74

Added lines #L73 - L74 were not covered by tests

CGFloat newWidth = MIN(originalSize.width, maxWidth);
CGFloat newHeight = newWidth / aspectRatio;

Check warning on line 77 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L76-L77

Added lines #L76 - L77 were not covered by tests

CGSize newSize = CGSizeMake(newWidth, newHeight);

Check warning on line 79 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L79

Added line #L79 was not covered by tests

UIGraphicsBeginImageContextWithOptions(newSize, NO, 1);
[originalImage drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Check warning on line 84 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L81-L84

Added lines #L81 - L84 were not covered by tests

return resizedImage;
}

Check warning on line 87 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L86-L87

Added lines #L86 - L87 were not covered by tests

- (void)releaseFramesUntil:(NSDate *)date
{
dispatch_async(_onDemandDispatchQueue, ^{
while (self->_frames.count > 0 &&
[self->_frames.firstObject.time compare:date] != NSOrderedDescending) {
[self removeOldestFrame];

Check warning on line 94 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L94

Added line #L94 was not covered by tests
}
});
}

Check warning on line 97 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L96-L97

Added lines #L96 - L97 were not covered by tests

- (void)removeOldestFrame
{
NSError *error;

Check warning on line 101 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L101

Added line #L101 was not covered by tests
if (![NSFileManager.defaultManager removeItemAtPath:_frames.firstObject.imagePath
error:&error]) {
SENTRY_LOG_DEBUG(
@"Could not delete replay frame at: %@. %@", _frames.firstObject.imagePath, error);
}
[_frames removeObjectAtIndex:0];
}

Check warning on line 108 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L105-L108

Added lines #L105 - L108 were not covered by tests

- (void)createVideoOf:(NSTimeInterval)duration
from:(NSDate *)beginning
outputFileURL:(NSURL *)outputFileURL
completion:(void (^)(BOOL success, NSError *error))completion
{
// Set up AVAssetWriter with appropriate settings
AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:outputFileURL
fileType:AVFileTypeQuickTimeMovie
error:nil];

Check warning on line 118 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L116-L118

Added lines #L116 - L118 were not covered by tests

NSDictionary *videoSettings = @{
AVVideoCodecKey : AVVideoCodecTypeH264,
AVVideoWidthKey : @(_videoSize.width),
AVVideoHeightKey : @(_videoSize.height),
AVVideoCompressionPropertiesKey : @ {
AVVideoAverageBitRateKey : @(_bitRate),
AVVideoProfileLevelKey : AVVideoProfileLevelH264BaselineAutoLevel,
},
};

Check warning on line 128 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L120-L128

Added lines #L120 - L128 were not covered by tests

AVAssetWriterInput *videoWriterInput =
[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videoSettings];
NSDictionary *bufferAttributes = @{
(id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32ARGB),
};

Check warning on line 135 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L130-L135

Added lines #L130 - L135 were not covered by tests

AVAssetWriterInputPixelBufferAdaptor *pixelBufferAdaptor = [AVAssetWriterInputPixelBufferAdaptor
assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput
sourcePixelBufferAttributes:bufferAttributes];

Check warning on line 139 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L137-L139

Added lines #L137 - L139 were not covered by tests

[videoWriter addInput:videoWriterInput];

Check warning on line 141 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L141

Added line #L141 was not covered by tests

// Start writing video
[videoWriter startWriting];
[videoWriter startSessionAtSourceTime:kCMTimeZero];

Check warning on line 145 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L144-L145

Added lines #L144 - L145 were not covered by tests

NSDate *end = [beginning dateByAddingTimeInterval:duration];
__block NSInteger frameCount = 0;
NSMutableArray<NSString *> *frames = [NSMutableArray array];

Check warning on line 149 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L147-L149

Added lines #L147 - L149 were not covered by tests
for (SentryReplayFrame *frame in self->_frames) {
if ([frame.time compare:beginning] == NSOrderedAscending) {
continue;
;
} else if ([frame.time compare:end] == NSOrderedDescending) {
break;

Check warning on line 155 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L155

Added line #L155 was not covered by tests
}
[frames addObject:frame.imagePath];
}

[videoWriterInput
requestMediaDataWhenReadyOnQueue:_onDemandDispatchQueue

Check warning on line 161 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L160-L161

Added lines #L160 - L161 were not covered by tests
usingBlock:^{
UIImage *image =
[UIImage imageWithContentsOfFile:frames[frameCount]];

Check warning on line 164 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L163-L164

Added lines #L163 - L164 were not covered by tests
if (image) {
CMTime presentTime = CMTimeMake(frameCount++, 1);

Check warning on line 166 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L166

Added line #L166 was not covered by tests

if (![self appendPixelBufferForImage:image
pixelBufferAdaptor:pixelBufferAdaptor

Check warning on line 169 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L169

Added line #L169 was not covered by tests
presentationTime:presentTime]) {
if (completion) {
completion(NO, videoWriter.error);

Check warning on line 172 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L172

Added line #L172 was not covered by tests
}
}
}

Check warning on line 175 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L174-L175

Added lines #L174 - L175 were not covered by tests

if (frameCount >= frames.count) {
[videoWriterInput markAsFinished];

Check warning on line 178 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L178

Added line #L178 was not covered by tests
[videoWriter finishWritingWithCompletionHandler:^{
if (completion) {
completion(videoWriter.status
== AVAssetWriterStatusCompleted,
videoWriter.error);

Check warning on line 183 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L181-L183

Added lines #L181 - L183 were not covered by tests
}
}];
}
}];
}

Check warning on line 188 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L185-L188

Added lines #L185 - L188 were not covered by tests

- (BOOL)appendPixelBufferForImage:(UIImage *)image
pixelBufferAdaptor:(AVAssetWriterInputPixelBufferAdaptor *)pixelBufferAdaptor
presentationTime:(CMTime)presentationTime
{
CVReturn status = kCVReturnSuccess;

Check warning on line 194 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L194

Added line #L194 was not covered by tests

CVPixelBufferRef pixelBuffer = NULL;
status = CVPixelBufferCreate(kCFAllocatorDefault, (size_t)image.size.width,
(size_t)image.size.height, kCVPixelFormatType_32ARGB, NULL, &pixelBuffer);

Check warning on line 198 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L196-L198

Added lines #L196 - L198 were not covered by tests

if (status != kCVReturnSuccess) {
return NO;

Check warning on line 201 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L201

Added line #L201 was not covered by tests
}

CVPixelBufferLockBaseAddress(pixelBuffer, 0);
void *pixelData = CVPixelBufferGetBaseAddress(pixelBuffer);

Check warning on line 205 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L205

Added line #L205 was not covered by tests

CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixelData, (size_t)image.size.width,
(size_t)image.size.height, 8, CVPixelBufferGetBytesPerRow(pixelBuffer), rgbColorSpace,
(CGBitmapInfo)kCGImageAlphaNoneSkipFirst);

Check warning on line 210 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L207-L210

Added lines #L207 - L210 were not covered by tests

CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

Check warning on line 213 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L212-L213

Added lines #L212 - L213 were not covered by tests

UIGraphicsPushContext(context);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
UIGraphicsPopContext();

Check warning on line 217 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L215-L217

Added lines #L215 - L217 were not covered by tests

CGColorSpaceRelease(rgbColorSpace);
CGContextRelease(context);

Check warning on line 220 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L219-L220

Added lines #L219 - L220 were not covered by tests

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

Check warning on line 222 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L222

Added line #L222 was not covered by tests

// Append the pixel buffer with the current image to the video
BOOL success = [pixelBufferAdaptor appendPixelBuffer:pixelBuffer
withPresentationTime:presentationTime];

Check warning on line 226 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L225-L226

Added lines #L225 - L226 were not covered by tests

CVPixelBufferRelease(pixelBuffer);

Check warning on line 228 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L228

Added line #L228 was not covered by tests

return success;
}

Check warning on line 231 in Sources/Sentry/SentryOnDemandReplay.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryOnDemandReplay.m#L230-L231

Added lines #L230 - L231 were not covered by tests

@end
#endif // SENTRY_HAS_UIKIT
Loading

0 comments on commit a99524d

Please sign in to comment.