forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[camera] CameraPlatform.createCameraWithSettings (flutter#3615)
## Platform interface of federated plugin This is the `platform-interface` part of `camera` PR flutter#3586. ## App-facing change Previously, CameraController was unable to setup fps and bitrates, allowing only resolution settings like this: ```dart controller = CameraController(_cameras[0], ResolutionPreset.max); ``` This PR gives additional functionality to set `fps` and `bitrates` via `withSettings`: ```dart controller = CameraController.withSettings( _cameras[0], mediaSettings: const MediaSettings( resolutionPreset: ResolutionPreset.low, fps: 15, videoBitrate: 200000, audioBitrate: 32000, enableAudio: true, ), ); ``` ## Android, iOS, etc. All platforms must implement `CameraPlatform.createCameraWithSettings` in addition to `CameraPlatform.createCamera`, providing platform specific code for `fps` and `bitrate' platform: ```dart Future<int> createCamera( CameraDescription cameraDescription, CameraDescription cameraDescription, ResolutionPreset? resolutionPreset, { ResolutionPreset? resolutionPreset, { bool enableAudio = false, bool enableAudio = false, }) { }) => throw UnimplementedError('createCamera() is not implemented.'); createCameraWithSettings( cameraDescription, MediaSettings( resolutionPreset: resolutionPreset, enableAudio: enableAudio, ), ); /// Creates an uninitialized camera instance and returns the cameraId. Future<int> createCameraWithSettings( CameraDescription cameraDescription, MediaSettings? mediaSettings, ) { throw UnimplementedError('createCameraWithSettings() is not implemented.'); } } ```
- Loading branch information
Showing
10 changed files
with
471 additions
and
20 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
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
77 changes: 77 additions & 0 deletions
77
packages/camera/camera_platform_interface/lib/src/types/media_settings.dart
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,77 @@ | ||
// 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. | ||
|
||
// ignore_for_file: avoid_equals_and_hash_code_on_mutable_classes | ||
|
||
import 'resolution_preset.dart'; | ||
|
||
/// Recording media settings. | ||
/// | ||
/// Used in [CameraPlatform.createCameraWithSettings]. | ||
/// Allows to tune recorded video parameters, such as resolution, frame rate, bitrate. | ||
/// If [fps], [videoBitrate] or [audioBitrate] are passed, they must be greater than zero. | ||
class MediaSettings { | ||
/// Creates a [MediaSettings]. | ||
const MediaSettings({ | ||
this.resolutionPreset, | ||
this.fps, | ||
this.videoBitrate, | ||
this.audioBitrate, | ||
this.enableAudio = false, | ||
}) : assert(fps == null || fps > 0, 'fps must be null or greater than zero'), | ||
assert(videoBitrate == null || videoBitrate > 0, | ||
'videoBitrate must be null or greater than zero'), | ||
assert(audioBitrate == null || audioBitrate > 0, | ||
'audioBitrate must be null or greater than zero'); | ||
|
||
/// [ResolutionPreset] affect the quality of video recording and image capture. | ||
final ResolutionPreset? resolutionPreset; | ||
|
||
/// Rate at which frames should be captured by the camera in frames per second. | ||
final int? fps; | ||
|
||
/// The video encoding bit rate for recording. | ||
final int? videoBitrate; | ||
|
||
/// The audio encoding bit rate for recording. | ||
final int? audioBitrate; | ||
|
||
/// Controls audio presence in recorded video. | ||
final bool enableAudio; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (identical(other, this)) { | ||
return true; | ||
} | ||
if (other.runtimeType != runtimeType) { | ||
return false; | ||
} | ||
return other is MediaSettings && | ||
resolutionPreset == other.resolutionPreset && | ||
fps == other.fps && | ||
videoBitrate == other.videoBitrate && | ||
audioBitrate == other.audioBitrate && | ||
enableAudio == other.enableAudio; | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash( | ||
resolutionPreset, | ||
fps, | ||
videoBitrate, | ||
audioBitrate, | ||
enableAudio, | ||
); | ||
|
||
@override | ||
String toString() { | ||
return 'MediaSettings{' | ||
'resolutionPreset: $resolutionPreset, ' | ||
'fps: $fps, ' | ||
'videoBitrate: $videoBitrate, ' | ||
'audioBitrate: $audioBitrate, ' | ||
'enableAudio: $enableAudio}'; | ||
} | ||
} |
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
Oops, something went wrong.