Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix formatting
  • Loading branch information
mchudy committed Feb 13, 2025
commit f9214f2837e071dce0a0c6c2d26b346b6629ca77
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ - (void)setMaxFrameDuration:(CMTime)duration onDevice:(AVCaptureDevice *)capture
return [[MockAssetWriterInput alloc] init];
}

- (void)addInput:(NSObject<FLTAssetWriterInput> *)writerInput toAssetWriter:(NSObject<FLTAssetWriter> *)writer {
- (void)addInput:(NSObject<FLTAssetWriterInput> *)writerInput
toAssetWriter:(NSObject<FLTAssetWriter> *)writer {
}

- (NSDictionary<NSString *, id> *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
configuration.videoCaptureSession = videoSessionMock;
configuration.audioCaptureSession = audioSessionMock;
configuration.orientation = UIDeviceOrientationPortrait;
configuration.assetWriterFactory = ^NSObject<FLTAssetWriter> *(
NSURL *url, AVFileType fileType, NSError **error) {
configuration.assetWriterFactory =
^NSObject<FLTAssetWriter> *(NSURL *url, AVFileType fileType, NSError **error) {
return [[MockAssetWriter alloc] init];
};
configuration.inputPixelBufferAdaptorFactory = ^NSObject<FLTAssetWriterInputPixelBufferAdaptor> *(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ @interface FLTCamSampleBufferTests : XCTestCase

@implementation FLTCamSampleBufferTests

- (FLTCam *)createCameraWithAssetWriter:(MockAssetWriter *)assetWriter adaptor:(MockAssetWriterInputPixelBufferAdaptor *)adaptor input:(MockAssetWriterInput *)input {
- (FLTCam *)createCameraWithAssetWriter:(MockAssetWriter *)assetWriter
adaptor:(MockAssetWriterInputPixelBufferAdaptor *)adaptor
input:(MockAssetWriterInput *)input {
FLTCamConfiguration *configuration = FLTCreateTestCameraConfiguration();
configuration.mediaSettings =
[FCPPlatformMediaSettings makeWithResolutionPreset:FCPPlatformResolutionPresetMedium
Expand All @@ -82,13 +84,14 @@ - (FLTCam *)createCameraWithAssetWriter:(MockAssetWriter *)assetWriter adaptor:(

configuration.assetWriterFactory =
^NSObject<FLTAssetWriter> *_Nonnull(NSURL *url, AVFileType fileType, NSError **error) {
return assetWriter;
return assetWriter;
};
configuration.inputPixelBufferAdaptorFactory = ^id<FLTAssetWriterInputPixelBufferAdaptor> _Nonnull(
NSObject<FLTAssetWriterInput> *input, NSDictionary<NSString *, id> *settings) {
return adaptor;
configuration.inputPixelBufferAdaptorFactory =
^id<FLTAssetWriterInputPixelBufferAdaptor> _Nonnull(NSObject<FLTAssetWriterInput> *input,
NSDictionary<NSString *, id> *settings) {
return adaptor;
};

return FLTCreateCamWithConfiguration(configuration);
}

Expand Down Expand Up @@ -139,19 +142,22 @@ - (void)testDidOutputSampleBuffer_mustNotChangeSampleBufferRetainCountAfterPause

- (void)testDidOutputSampleBufferIgnoreAudioSamplesBeforeVideoSamples {
MockAssetWriter *writerMock = [[MockAssetWriter alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock = [[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock =
[[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInput *inputMock = [[MockAssetWriterInput alloc] init];
MockCaptureConnection *connectionMock = [[MockCaptureConnection alloc] init];

__block AVAssetWriterStatus status = AVAssetWriterStatusUnknown;
writerMock.startWritingStub = ^{
status = AVAssetWriterStatusWriting;
};
writerMock.statusStub = ^AVAssetWriterStatus{
writerMock.statusStub = ^AVAssetWriterStatus {
return status;
};

FLTCam *camera = [self createCameraWithAssetWriter:writerMock adaptor:adaptorMock input:inputMock];
FLTCam *camera = [self createCameraWithAssetWriter:writerMock
adaptor:adaptorMock
input:inputMock];
CMSampleBufferRef videoSample = FLTCreateTestSampleBuffer();
CMSampleBufferRef audioSample = FLTCreateTestAudioSampleBuffer();

Expand Down Expand Up @@ -189,22 +195,25 @@ - (void)testDidOutputSampleBufferIgnoreAudioSamplesBeforeVideoSamples {

- (void)testDidOutputSampleBufferSampleTimesMustBeNumericAfterPauseResume {
MockAssetWriter *writerMock = [[MockAssetWriter alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock = [[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock =
[[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInput *inputMock = [[MockAssetWriterInput alloc] init];
MockCaptureConnection *connectionMock = [[MockCaptureConnection alloc] init];

FLTCam *camera = [self createCameraWithAssetWriter:writerMock adaptor:adaptorMock input:inputMock];

FLTCam *camera = [self createCameraWithAssetWriter:writerMock
adaptor:adaptorMock
input:inputMock];
CMSampleBufferRef videoSample = FLTCreateTestSampleBuffer();
CMSampleBufferRef audioSample = FLTCreateTestAudioSampleBuffer();

__block AVAssetWriterStatus status = AVAssetWriterStatusUnknown;
writerMock.startWritingStub = ^{
status = AVAssetWriterStatusWriting;
};
writerMock.statusStub = ^AVAssetWriterStatus{
writerMock.statusStub = ^AVAssetWriterStatus {
return status;
};

__block BOOL videoAppended = NO;
adaptorMock.appendPixelBufferStub = ^BOOL(CVPixelBufferRef buffer, CMTime time) {
XCTAssert(CMTIME_IS_NUMERIC(time));
Expand Down Expand Up @@ -245,11 +254,14 @@ - (void)testDidOutputSampleBufferSampleTimesMustBeNumericAfterPauseResume {

- (void)testDidOutputSampleBufferMustNotAppendSampleWhenReadyForMoreMediaDataIsNo {
MockAssetWriter *writerMock = [[MockAssetWriter alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock = [[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock =
[[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInput *inputMock = [[MockAssetWriterInput alloc] init];
MockCaptureConnection *connectionMock = [[MockCaptureConnection alloc] init];
FLTCam *camera = [self createCameraWithAssetWriter:writerMock adaptor:adaptorMock input:inputMock];

FLTCam *camera = [self createCameraWithAssetWriter:writerMock
adaptor:adaptorMock
input:inputMock];

CMSampleBufferRef videoSample = FLTCreateTestSampleBuffer();

__block BOOL sampleAppended = NO;
Expand Down Expand Up @@ -282,15 +294,18 @@ - (void)testDidOutputSampleBufferMustNotAppendSampleWhenReadyForMoreMediaDataIsN

- (void)testStopVideoRecordingWithCompletionMustCallCompletion {
MockAssetWriter *writerMock = [[MockAssetWriter alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock = [[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock =
[[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInput *inputMock = [[MockAssetWriterInput alloc] init];
FLTCam *camera = [self createCameraWithAssetWriter:writerMock adaptor:adaptorMock input:inputMock];

FLTCam *camera = [self createCameraWithAssetWriter:writerMock
adaptor:adaptorMock
input:inputMock];

__block AVAssetWriterStatus status = AVAssetWriterStatusUnknown;
writerMock.startWritingStub = ^{
status = AVAssetWriterStatusWriting;
};
writerMock.statusStub = ^AVAssetWriterStatus{
writerMock.statusStub = ^AVAssetWriterStatus {
return status;
};
writerMock.finishWritingStub = ^(void (^param)(void)) {
Expand All @@ -316,11 +331,14 @@ - (void)testStopVideoRecordingWithCompletionMustCallCompletion {

- (void)testStartWritingShouldNotBeCalledBetweenSampleCreationAndAppending {
MockAssetWriter *writerMock = [[MockAssetWriter alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock = [[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInputPixelBufferAdaptor *adaptorMock =
[[MockAssetWriterInputPixelBufferAdaptor alloc] init];
MockAssetWriterInput *inputMock = [[MockAssetWriterInput alloc] init];
MockCaptureConnection *connectionMock = [[MockCaptureConnection alloc] init];
FLTCam *camera = [self createCameraWithAssetWriter:writerMock adaptor:adaptorMock input:inputMock];

FLTCam *camera = [self createCameraWithAssetWriter:writerMock
adaptor:adaptorMock
input:inputMock];

CMSampleBufferRef videoSample = FLTCreateTestSampleBuffer();

__block BOOL startWritingCalled = NO;
Expand Down Expand Up @@ -358,7 +376,7 @@ - (void)testStartWritingShouldNotBeCalledBetweenSampleCreationAndAppending {

- (void)testStartVideoRecordingWithCompletionShouldNotDisableMixWithOthers {
FLTCam *cam = FLTCreateCamWithCaptureSessionQueue(dispatch_queue_create("testing", NULL));

[AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ @interface FLTCam () <AVCaptureVideoDataOutputSampleBufferDelegate,
@property(strong, nonatomic) NSObject<FLTAssetWriter> *videoWriter;
@property(strong, nonatomic) NSObject<FLTAssetWriterInput> *videoWriterInput;
@property(strong, nonatomic) NSObject<FLTAssetWriterInput> *audioWriterInput;
@property(strong, nonatomic) NSObject<FLTAssetWriterInputPixelBufferAdaptor> *assetWriterPixelBufferAdaptor;
@property(strong, nonatomic)
NSObject<FLTAssetWriterInputPixelBufferAdaptor> *assetWriterPixelBufferAdaptor;
@property(strong, nonatomic) AVCaptureVideoDataOutput *videoOutput;
@property(strong, nonatomic) AVCaptureAudioDataOutput *audioOutput;
@property(strong, nonatomic) NSString *videoRecordingPath;
Expand Down Expand Up @@ -1259,7 +1260,7 @@ - (BOOL)setupWriterForPath:(NSString *)path {
[self setUpCaptureSessionForAudioIfNeeded];

_videoWriter = _assetWriterFactory(outputURL, AVFileTypeMPEG4, &error);

NSParameterAssert(_videoWriter);
if (error) {
[self reportErrorMessage:error.description];
Expand Down Expand Up @@ -1287,9 +1288,8 @@ - (BOOL)setupWriterForPath:(NSString *)path {
_videoWriterInput =
[_mediaSettingsAVWrapper assetWriterVideoInputWithOutputSettings:videoSettings];

_videoAdaptor = _inputPixelBufferAdaptorFactory(_videoWriterInput, @{
(NSString *)kCVPixelBufferPixelFormatTypeKey : @(_videoFormat)
});
_videoAdaptor = _inputPixelBufferAdaptorFactory(
_videoWriterInput, @{(NSString *)kCVPixelBufferPixelFormatTypeKey : @(_videoFormat)});

NSParameterAssert(_videoWriterInput);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ - (instancetype)initWithMediaSettings:(FCPPlatformMediaSettings *)mediaSettings
return CMVideoFormatDescriptionGetDimensions(format.formatDescription);
};
_captureDeviceInputFactory = captureDeviceInputFactory;
_assetWriterFactory = ^id<FLTAssetWriter> (NSURL *url, AVFileType fileType, NSError **error) {
_assetWriterFactory = ^id<FLTAssetWriter>(NSURL *url, AVFileType fileType, NSError **error) {
return [[FLTDefaultAssetWriter alloc] initWithURL:url fileType:fileType error:error];
};
_inputPixelBufferAdaptorFactory = ^NSObject<FLTAssetWriterInputPixelBufferAdaptor> *(NSObject<FLTAssetWriterInput> *assetWriterInput,
NSDictionary<NSString *, id> *sourcePixelBufferAttributes) {
return [[FLTDefaultAssetWriterInputPixelBufferAdaptor alloc]
initWithAdaptor:[[AVAssetWriterInputPixelBufferAdaptor alloc]
initWithAssetWriterInput:assetWriterInput.input
sourcePixelBufferAttributes:sourcePixelBufferAttributes]];
};
_inputPixelBufferAdaptorFactory = ^NSObject<FLTAssetWriterInputPixelBufferAdaptor> *(
NSObject<FLTAssetWriterInput> *assetWriterInput,
NSDictionary<NSString *, id> *sourcePixelBufferAttributes) {
return [[FLTDefaultAssetWriterInputPixelBufferAdaptor alloc]
initWithAdaptor:[[AVAssetWriterInputPixelBufferAdaptor alloc]
initWithAssetWriterInput:assetWriterInput.input
sourcePixelBufferAttributes:sourcePixelBufferAttributes]];
};
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "./include/camera_avfoundation/FLTAssetWriter.h"
#import "./include/camera_avfoundation/FLTCamMediaSettingsAVWrapper.h"
#import "./include/camera_avfoundation/FLTAssetWriter.h"
#import "./include/camera_avfoundation/FLTCaptureDevice.h"
#import "./include/camera_avfoundation/FLTCaptureSession.h"

Expand Down Expand Up @@ -37,8 +37,8 @@ - (void)setMaxFrameDuration:(CMTime)duration onDevice:(NSObject<FLTCaptureDevice
- (NSObject<FLTAssetWriterInput> *)assetWriterAudioInputWithOutputSettings:
(nullable NSDictionary<NSString *, id> *)outputSettings {
return [[FLTDefaultAssetWriterInput alloc]
initWithInput:[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio
outputSettings:outputSettings]];
initWithInput:[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio
outputSettings:outputSettings]];
}

- (NSObject<FLTAssetWriterInput> *)assetWriterVideoInputWithOutputSettings:
Expand All @@ -48,7 +48,8 @@ - (void)setMaxFrameDuration:(CMTime)duration onDevice:(NSObject<FLTCaptureDevice
outputSettings:outputSettings]];
}

- (void)addInput:(NSObject<FLTAssetWriterInput> *)writerInput toAssetWriter:(NSObject<FLTAssetWriter> *)writer {
- (void)addInput:(NSObject<FLTAssetWriterInput> *)writerInput
toAssetWriter:(NSObject<FLTAssetWriter> *)writer {
[writer addInput:writerInput.input];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ NS_ASSUME_NONNULL_BEGIN

/// A default implementation of `FLTAssetWriterInputPixelBufferAdaptor` which forwards calls to the
/// underlying `AVAssetWriterInputPixelBufferAdaptor`.
@interface FLTDefaultAssetWriterInputPixelBufferAdaptor : NSObject <FLTAssetWriterInputPixelBufferAdaptor>
@interface FLTDefaultAssetWriterInputPixelBufferAdaptor
: NSObject <FLTAssetWriterInputPixelBufferAdaptor>

/// Creates a wrapper around the `adaptor` which will forward calls to it.
- (instancetype)initWithAdaptor:(AVAssetWriterInputPixelBufferAdaptor *)adaptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef NSObject<FLTCaptureDevice> *_Nonnull (^CaptureDeviceFactory)(void);
typedef NSObject<FLTCaptureSession> *_Nonnull (^CaptureSessionFactory)(void);

typedef NSObject<FLTAssetWriter> *_Nonnull (^AssetWriterFactory)(NSURL *, AVFileType,
NSError *_Nullable *_Nullable);
NSError *_Nullable *_Nullable);

typedef NSObject<FLTAssetWriterInputPixelBufferAdaptor> *_Nonnull (^InputPixelBufferAdaptorFactory)(
NSObject<FLTAssetWriterInput> *, NSDictionary<NSString *, id> *_Nullable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ NS_ASSUME_NONNULL_BEGIN
* @param writerInput The `AVAssetWriterInput` object to be added.
* @param writer The `AVAssetWriter` object.
*/
- (void)addInput:(NSObject<FLTAssetWriterInput> *)writerInput toAssetWriter:(NSObject<FLTAssetWriter> *)writer;
- (void)addInput:(NSObject<FLTAssetWriterInput> *)writerInput
toAssetWriter:(NSObject<FLTAssetWriter> *)writer;

/**
* @method recommendedVideoSettingsForAssetWriterWithFileType:forOutput:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/// Exposed for unit tests.
- (void)captureOutput:(AVCaptureOutput *)output
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(NSObject<FLTCaptureConnection> *)connection;
fromConnection:(NSObject<FLTCaptureConnection> *)connection;

/// Start streaming images.
- (void)startImageStreamWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ NS_ASSUME_NONNULL_BEGIN
/// `AVCaptureConnection` in tests.
@protocol FLTCaptureConnection <NSObject>

/// Underlying `AVCaptureConnection` instance. All methods and properties are passed through to this.
/// Underlying `AVCaptureConnection` instance. All methods and properties are passed through to
/// this.
@property(nonatomic, readonly) AVCaptureConnection *connection;

@property(nonatomic) BOOL videoMirrored;
Expand Down