Skip to content

Commit

Permalink
Merge branch 'main' of github.com:flutter/packages into webview_darwi…
Browse files Browse the repository at this point in the history
…n_proxy
  • Loading branch information
bparrishMines committed Jan 17, 2025
2 parents 0c80869 + 205960d commit d501f3c
Show file tree
Hide file tree
Showing 87 changed files with 2,088 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .ci/flutter_master.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4b23b8182888d5d94645d8f97cdcc79800e44a9a
5517cc9b3b3bcf12431b47f495e342a30b738835
2 changes: 1 addition & 1 deletion .ci/flutter_stable.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17025dd88227cd9532c33fa78f5250d548d87e9a
68415ad1d920f6fe5ec284f5c2febf7c4dd5b0b3
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ updates:
test-dependencies:
patterns:
- "androidx.test:*"
- "io.mockk:mockk:*"
- "io.mockk:*"
- "junit:junit"
- "org.mockito:*"
- "org.robolectric:*"
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.10

* Adds API support query for image streaming.

## 0.10.9+17

* Updates annotations lib to 1.9.1.
Expand Down
3 changes: 3 additions & 0 deletions packages/camera/camera_android/lib/src/android_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ class AndroidCamera extends CameraPlatform {
Future<void> resumeVideoRecording(int cameraId) =>
_hostApi.resumeVideoRecording();

@override
bool supportsImageStreaming() => true;

@override
Stream<CameraImageData> onStreamedFrameAvailable(int cameraId,
{CameraImageStreamOptions? options}) {
Expand Down
5 changes: 3 additions & 2 deletions packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22

version: 0.10.9+17
version: 0.10.10

environment:
sdk: ^3.5.0
Expand All @@ -19,7 +19,7 @@ flutter:
dartPluginClass: AndroidCamera

dependencies:
camera_platform_interface: ^2.6.0
camera_platform_interface: ^2.9.0
flutter:
sdk: flutter
flutter_plugin_android_lifecycle: ^2.0.2
Expand All @@ -30,6 +30,7 @@ dev_dependencies:
build_runner: ^2.4.11
flutter_test:
sdk: flutter
leak_tracker_flutter_testing: any
mockito: ^5.4.4
pigeon: ^22.4.1

Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_android/test/android_camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ void main() {
verify(mockCameraApi.resumePreview()).called(1);
});

test('Should report support for image streaming', () async {
expect(camera.supportsImageStreaming(), true);
});

test('Should start streaming', () async {
// Arrange
// Act
Expand Down
13 changes: 13 additions & 0 deletions packages/camera/camera_android/test/flutter_test_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
LeakTesting.enable();
LeakTracking.warnForUnsupportedPlatforms = false;
await testMain();
}
4 changes: 4 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.13

* Adds API support query for image streaming.

## 0.6.12

* Suppresses deprecation and removal warnings for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,9 @@ class AndroidCameraCameraX extends CameraPlatform {
}
}

@override
bool supportsImageStreaming() => true;

/// A new streamed frame is available.
///
/// Listening to this stream will start streaming, and canceling will stop.
Expand Down
5 changes: 3 additions & 2 deletions packages/camera/camera_android_camerax/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android_camerax
description: Android implementation of the camera plugin using the CameraX library.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.6.12
version: 0.6.13

environment:
sdk: ^3.6.0
Expand All @@ -19,7 +19,7 @@ flutter:

dependencies:
async: ^2.5.0
camera_platform_interface: ^2.6.0
camera_platform_interface: ^2.9.0
flutter:
sdk: flutter
meta: ^1.7.0
Expand All @@ -31,6 +31,7 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
leak_tracker_flutter_testing: any
mockito: ^5.4.4
pigeon: ^9.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,11 @@ void main() {
verify(mockCameraControl.setZoomRatio(zoomRatio));
});

test('Should report support for image streaming', () async {
final AndroidCameraCameraX camera = AndroidCameraCameraX();
expect(camera.supportsImageStreaming(), true);
});

test(
'onStreamedFrameAvailable emits CameraImageData when picked up from CameraImageData stream controller',
() async {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
LeakTesting.enable();
LeakTracking.warnForUnsupportedPlatforms = false;
await testMain();
}
8 changes: 8 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.9.18

* Adds API support query for image streaming.

## 0.9.17+7

* Fixes changing global audio session category to be collision free across plugins.

## 0.9.17+6

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,27 @@ - (void)testStartWritingShouldNotBeCalledBetweenSampleCreationAndAppending {
CFRelease(videoSample);
}

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

id writerMock = OCMClassMock([AVAssetWriter class]);
OCMStub([writerMock alloc]).andReturn(writerMock);
OCMStub([writerMock initWithURL:OCMOCK_ANY fileType:OCMOCK_ANY error:[OCMArg setTo:nil]])
.andReturn(writerMock);

[AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];

[cam
startVideoRecordingWithCompletion:^(FlutterError *_Nullable error) {
}
messengerForStreaming:nil];
XCTAssert(
AVAudioSession.sharedInstance.categoryOptions & AVAudioSessionCategoryOptionMixWithOthers,
@"Flag MixWithOthers was removed.");
XCTAssert(AVAudioSession.sharedInstance.category == AVAudioSessionCategoryPlayAndRecord,
@"Category should be PlayAndRecord.");
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ - (void)prepareForVideoRecordingWithCompletion:
(nonnull void (^)(FlutterError *_Nullable))completion {
__weak typeof(self) weakSelf = self;
dispatch_async(self.captureSessionQueue, ^{
[weakSelf.camera setUpCaptureSessionForAudio];
[weakSelf.camera setUpCaptureSessionForAudioIfNeeded];
completion(nil);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ - (instancetype)initWithMediaSettings:(FCPPlatformMediaSettings *)mediaSettings
_videoFormat = kCVPixelFormatType_32BGRA;
_inProgressSavePhotoDelegates = [NSMutableDictionary dictionary];
_fileFormat = FCPPlatformImageFileFormatJpeg;
_videoCaptureSession.automaticallyConfiguresApplicationAudioSession = NO;
_audioCaptureSession.automaticallyConfiguresApplicationAudioSession = NO;

// To limit memory consumption, limit the number of frames pending processing.
// After some testing, 4 was determined to be the best maximum value.
Expand Down Expand Up @@ -725,7 +727,8 @@ - (void)captureOutput:(AVCaptureOutput *)output
if (_isFirstVideoSample) {
[_videoWriter startSessionAtSourceTime:currentSampleTime];
// fix sample times not being numeric when pause/resume happens before first sample buffer
// arrives https://github.com/flutter/flutter/issues/132014
// arrives
// https://github.com/flutter/flutter/issues/132014
_lastVideoSampleTime = currentSampleTime;
_lastAudioSampleTime = currentSampleTime;
_isFirstVideoSample = NO;
Expand Down Expand Up @@ -1283,9 +1286,7 @@ - (BOOL)setupWriterForPath:(NSString *)path {
return NO;
}

if (_mediaSettings.enableAudio && !_isAudioSetup) {
[self setUpCaptureSessionForAudio];
}
[self setUpCaptureSessionForAudioIfNeeded];

_videoWriter = [[AVAssetWriter alloc] initWithURL:outputURL
fileType:AVFileTypeMPEG4
Expand Down Expand Up @@ -1365,9 +1366,42 @@ - (BOOL)setupWriterForPath:(NSString *)path {
return YES;
}

- (void)setUpCaptureSessionForAudio {
// This function, although slightly modified, is also in video_player_avfoundation.
// Both need to do the same thing and run on the same thread (for example main thread).
// Configure application wide audio session manually to prevent overwriting flag
// MixWithOthers by capture session.
// Only change category if it is considered an upgrade which means it can only enable
// ability to play in silent mode or ability to record audio but never disables it,
// that could affect other plugins which depend on this global state. Only change
// category or options if there is change to prevent unnecessary lags and silence.
static void upgradeAudioSessionCategory(AVAudioSessionCategory requestedCategory,
AVAudioSessionCategoryOptions options) {
NSSet *playCategories = [NSSet
setWithObjects:AVAudioSessionCategoryPlayback, AVAudioSessionCategoryPlayAndRecord, nil];
NSSet *recordCategories =
[NSSet setWithObjects:AVAudioSessionCategoryRecord, AVAudioSessionCategoryPlayAndRecord, nil];
NSSet *requiredCategories =
[NSSet setWithObjects:requestedCategory, AVAudioSession.sharedInstance.category, nil];
BOOL requiresPlay = [requiredCategories intersectsSet:playCategories];
BOOL requiresRecord = [requiredCategories intersectsSet:recordCategories];
if (requiresPlay && requiresRecord) {
requestedCategory = AVAudioSessionCategoryPlayAndRecord;
} else if (requiresPlay) {
requestedCategory = AVAudioSessionCategoryPlayback;
} else if (requiresRecord) {
requestedCategory = AVAudioSessionCategoryRecord;
}
options = AVAudioSession.sharedInstance.categoryOptions | options;
if ([requestedCategory isEqualToString:AVAudioSession.sharedInstance.category] &&
options == AVAudioSession.sharedInstance.categoryOptions) {
return;
}
[AVAudioSession.sharedInstance setCategory:requestedCategory withOptions:options error:nil];
}

- (void)setUpCaptureSessionForAudioIfNeeded {
// Don't setup audio twice or we will lose the audio.
if (_isAudioSetup) {
if (!_mediaSettings.enableAudio || _isAudioSetup) {
return;
}

Expand All @@ -1383,6 +1417,20 @@ - (void)setUpCaptureSessionForAudio {
// Setup the audio output.
_audioOutput = [[AVCaptureAudioDataOutput alloc] init];

dispatch_block_t block = ^{
// Set up options implicit to AVAudioSessionCategoryPlayback to avoid conflicts with other
// plugins like video_player.
upgradeAudioSessionCategory(AVAudioSessionCategoryPlayAndRecord,
AVAudioSessionCategoryOptionDefaultToSpeaker |
AVAudioSessionCategoryOptionAllowBluetoothA2DP |
AVAudioSessionCategoryOptionAllowAirPlay);
};
if (!NSThread.isMainThread) {
dispatch_sync(dispatch_get_main_queue(), block);
} else {
block();
}

if ([_audioCaptureSession canAddInput:audioInput]) {
[_audioCaptureSession addInput:audioInput];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)startImageStreamWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger;
- (void)stopImageStream;
- (void)setZoomLevel:(CGFloat)zoom withCompletion:(void (^)(FlutterError *_Nullable))completion;
- (void)setUpCaptureSessionForAudio;
- (void)setUpCaptureSessionForAudioIfNeeded;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ class AVFoundationCamera extends CameraPlatform {
await _hostApi.resumeVideoRecording();
}

@override
bool supportsImageStreaming() => true;

@override
Stream<CameraImageData> onStreamedFrameAvailable(int cameraId,
{CameraImageStreamOptions? options}) {
Expand Down
5 changes: 3 additions & 2 deletions packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_avfoundation
description: iOS implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.17+6
version: 0.9.18

environment:
sdk: ^3.4.0
Expand All @@ -17,7 +17,7 @@ flutter:
dartPluginClass: AVFoundationCamera

dependencies:
camera_platform_interface: ^2.7.0
camera_platform_interface: ^2.9.0
flutter:
sdk: flutter
stream_transform: ^2.0.0
Expand All @@ -27,6 +27,7 @@ dev_dependencies:
build_runner: ^2.4.9
flutter_test:
sdk: flutter
leak_tracker_flutter_testing: any
mockito: ^5.4.4
pigeon: ^22.4.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ void main() {
verify(mockApi.resumePreview());
});

test('Should report support for image streaming', () async {
expect(camera.supportsImageStreaming(), true);
});

test('Should start streaming', () async {
final StreamSubscription<CameraImageData> subscription = camera
.onStreamedFrameAvailable(cameraId)
Expand Down
13 changes: 13 additions & 0 deletions packages/camera/camera_avfoundation/test/flutter_test_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
LeakTesting.enable();
LeakTracking.warnForUnsupportedPlatforms = false;
await testMain();
}
1 change: 1 addition & 0 deletions packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dev_dependencies:
async: ^2.5.0
flutter_test:
sdk: flutter
leak_tracker_flutter_testing: any

topics:
- camera
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
LeakTesting.enable();
LeakTracking.warnForUnsupportedPlatforms = false;
await testMain();
}
1 change: 1 addition & 0 deletions packages/camera/camera_windows/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dev_dependencies:
build_runner: ^2.4.9
flutter_test:
sdk: flutter
leak_tracker_flutter_testing: any
mockito: ^5.4.4
pigeon: ^22.6.0

Expand Down
Loading

0 comments on commit d501f3c

Please sign in to comment.