This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[camera] Fixed a crash when streaming on iOS (#4520)
- Loading branch information
Showing
9 changed files
with
159 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/camera/camera/example/ios/RunnerTests/StreamingTest.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
@import camera; | ||
@import camera.Test; | ||
@import XCTest; | ||
@import AVFoundation; | ||
#import <OCMock/OCMock.h> | ||
#import "CameraTestUtils.h" | ||
|
||
@interface StreamingTests : XCTestCase | ||
@property(readonly, nonatomic) FLTCam *camera; | ||
@property(readonly, nonatomic) CMSampleBufferRef sampleBuffer; | ||
@end | ||
|
||
@implementation StreamingTests | ||
|
||
- (void)setUp { | ||
dispatch_queue_t captureSessionQueue = dispatch_queue_create("testing", NULL); | ||
_camera = FLTCreateCamWithCaptureSessionQueue(captureSessionQueue); | ||
_sampleBuffer = FLTCreateTestSampleBuffer(); | ||
} | ||
|
||
- (void)tearDown { | ||
CFRelease(_sampleBuffer); | ||
} | ||
|
||
- (void)testExceedMaxStreamingPendingFramesCount { | ||
XCTestExpectation *streamingExpectation = [self | ||
expectationWithDescription:@"Must not call handler over maxStreamingPendingFramesCount"]; | ||
|
||
id handlerMock = OCMClassMock([FLTImageStreamHandler class]); | ||
OCMStub([handlerMock eventSink]).andReturn(^(id event) { | ||
[streamingExpectation fulfill]; | ||
}); | ||
|
||
id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); | ||
[_camera startImageStreamWithMessenger:messenger imageStreamHandler:handlerMock]; | ||
|
||
XCTKVOExpectation *expectation = [[XCTKVOExpectation alloc] initWithKeyPath:@"isStreamingImages" | ||
object:_camera | ||
expectedValue:@YES]; | ||
XCTWaiterResult result = [XCTWaiter waitForExpectations:@[ expectation ] timeout:1]; | ||
XCTAssertEqual(result, XCTWaiterResultCompleted); | ||
|
||
streamingExpectation.expectedFulfillmentCount = 4; | ||
for (int i = 0; i < 10; i++) { | ||
[_camera captureOutput:nil didOutputSampleBuffer:self.sampleBuffer fromConnection:nil]; | ||
} | ||
|
||
[self waitForExpectationsWithTimeout:1.0 handler:nil]; | ||
} | ||
|
||
- (void)testReceivedImageStreamData { | ||
XCTestExpectation *streamingExpectation = | ||
[self expectationWithDescription: | ||
@"Must be able to call the handler again when receivedImageStreamData is called"]; | ||
|
||
id handlerMock = OCMClassMock([FLTImageStreamHandler class]); | ||
OCMStub([handlerMock eventSink]).andReturn(^(id event) { | ||
[streamingExpectation fulfill]; | ||
}); | ||
|
||
id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); | ||
[_camera startImageStreamWithMessenger:messenger imageStreamHandler:handlerMock]; | ||
|
||
XCTKVOExpectation *expectation = [[XCTKVOExpectation alloc] initWithKeyPath:@"isStreamingImages" | ||
object:_camera | ||
expectedValue:@YES]; | ||
XCTWaiterResult result = [XCTWaiter waitForExpectations:@[ expectation ] timeout:1]; | ||
XCTAssertEqual(result, XCTWaiterResultCompleted); | ||
|
||
streamingExpectation.expectedFulfillmentCount = 5; | ||
for (int i = 0; i < 10; i++) { | ||
[_camera captureOutput:nil didOutputSampleBuffer:self.sampleBuffer fromConnection:nil]; | ||
} | ||
|
||
[_camera receivedImageStreamData]; | ||
[_camera captureOutput:nil didOutputSampleBuffer:self.sampleBuffer fromConnection:nil]; | ||
|
||
[self waitForExpectationsWithTimeout:1.0 handler:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters