Skip to content

Commit

Permalink
[camera_windows] Support camera on windows desktop platform (flutter#…
Browse files Browse the repository at this point in the history
…4641)

This PR adds a Windows Desktop implementation of [camera plugin](https://pub.dev/packages/camera) using Media Foundation and CaptureEngine interface.

The implementation supports multiple cameras, video preview, and capturing photos and videos. Works with camera plugin and [camera example](https://pub.dev/packages/camera/example).

The current implementation uses FlutterDesktopPixelBuffer, but could be switched to use shared textures or Platform views after those are supported.

Unit tests are partially done; for the CaptureControllerImpl class all falilure code paths are not yet covered.

Still missing some features, like exposure and focus controls. These can be done later with interfaces IAMCameraControl and IAMVideoProcAmp,

Resolves flutter#41709: [camera] Add Windows support
  • Loading branch information
jokerttu committed Feb 3, 2022
1 parent dbbd21f commit bf01875
Show file tree
Hide file tree
Showing 63 changed files with 9,891 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/camera/camera_windows/.gitignore
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
10 changes: 10 additions & 0 deletions packages/camera/camera_windows/.metadata
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
channel: stable

project_type: plugin
8 changes: 8 additions & 0 deletions packages/camera/camera_windows/AUTHORS
@@ -0,0 +1,8 @@
# Below is a list of people and organizations that have contributed
# to the Flutter project. Names should be added to the list like so:
#
# Name/Organization <email address>

Google Inc.
Joonas Kerttula <joonas.kerttula@codemate.com>
Codemate Ltd.
3 changes: 3 additions & 0 deletions packages/camera/camera_windows/CHANGELOG.md
@@ -0,0 +1,3 @@
## 0.1.0

* Initial release
25 changes: 25 additions & 0 deletions packages/camera/camera_windows/LICENSE
@@ -0,0 +1,25 @@
Copyright 2013 The Flutter Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 changes: 66 additions & 0 deletions packages/camera/camera_windows/README.md
@@ -0,0 +1,66 @@
# Camera Windows Plugin

The Windows implementation of [`camera`][camera].

*Note*: This plugin is under development.
See [missing implementations and limitations](#missing-features-on-the-windows-platform).

## Usage

### Depend on the package

This package is not an [endorsed][endorsed-federated-plugin]
implementation of the [`camera`][camera] plugin, so you'll need to
[add it explicitly][install].

## Missing features on the Windows platform

### Device orientation

Device orientation detection
is not yet implemented: [issue #97540][device-orientation-issue].

### Pause and Resume video recording

Pausing and resuming the video recording
is not supported due to Windows API limitations.

### Exposure mode, point and offset

Support for explosure mode and offset
is not yet implemented: [issue #97537][camera-control-issue].

Exposure points are not supported due to
limitations of the Windows API.

### Focus mode and point

Support for explosure mode and offset
is not yet implemented: [issue #97537][camera-control-issue].

### Flash mode

Support for flash mode is not yet implemented: [issue #97537][camera-control-issue].

Focus points are not supported due to
current limitations of the Windows API.

### Streaming of frames

Support for image streaming is not yet implemented: [issue #97542][image-streams-issue].

## Error handling

Camera errors can be listened using the platform's `onCameraError` method.

Listening to errors is important, and in certain situations,
disposing of the camera is the only way to reset the situation.

<!-- Links -->

[camera]: https://pub.dev/packages/camera
[endorsed-federated-plugin]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin
[install]: https://pub.dev/packages/camera_windows/install
[camera-control-issue]: https://github.com/flutter/flutter/issues/97537
[device-orientation-issue]: https://github.com/flutter/flutter/issues/97540
[image-streams-issue]: https://github.com/flutter/flutter/issues/97542
46 changes: 46 additions & 0 deletions packages/camera/camera_windows/example/.gitignore
@@ -0,0 +1,46 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
10 changes: 10 additions & 0 deletions packages/camera/camera_windows/example/.metadata
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
channel: stable

project_type: app
3 changes: 3 additions & 0 deletions packages/camera/camera_windows/example/README.md
@@ -0,0 +1,3 @@
# camera_windows_example

Demonstrates how to use the camera_windows plugin.
@@ -0,0 +1,100 @@
// 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:async/async.dart';
import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

// Note that these integration tests do not currently cover
// most features and code paths, as they can only be tested if
// one or more cameras are available in the test environment.
// Native unit tests with better coverage are available at
// the native part of the plugin implementation.

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('initializeCamera', () {
testWidgets('throws exception if camera is not created',
(WidgetTester _) async {
final CameraPlatform camera = CameraPlatform.instance;

expect(() async => await camera.initializeCamera(1234),
throwsA(isA<CameraException>()));
});
});

group('takePicture', () {
testWidgets('throws exception if camera is not created',
(WidgetTester _) async {
final CameraPlatform camera = CameraPlatform.instance;

expect(() async => await camera.takePicture(1234),
throwsA(isA<PlatformException>()));
});
});

group('startVideoRecording', () {
testWidgets('throws exception if camera is not created',
(WidgetTester _) async {
final CameraPlatform camera = CameraPlatform.instance;

expect(() async => await camera.startVideoRecording(1234),
throwsA(isA<PlatformException>()));
});
});

group('stopVideoRecording', () {
testWidgets('throws exception if camera is not created',
(WidgetTester _) async {
final CameraPlatform camera = CameraPlatform.instance;

expect(() async => await camera.stopVideoRecording(1234),
throwsA(isA<PlatformException>()));
});
});

group('pausePreview', () {
testWidgets('throws exception if camera is not created',
(WidgetTester _) async {
final CameraPlatform camera = CameraPlatform.instance;

expect(() async => await camera.pausePreview(1234),
throwsA(isA<PlatformException>()));
});
});

group('resumePreview', () {
testWidgets('throws exception if camera is not created',
(WidgetTester _) async {
final CameraPlatform camera = CameraPlatform.instance;

expect(() async => await camera.resumePreview(1234),
throwsA(isA<PlatformException>()));
});
});

group('onDeviceOrientationChanged', () {
testWidgets('emits the initial DeviceOrientationChangedEvent',
(WidgetTester _) async {
final Stream<DeviceOrientationChangedEvent> eventStream =
CameraPlatform.instance.onDeviceOrientationChanged();

final StreamQueue<DeviceOrientationChangedEvent> streamQueue =
StreamQueue<DeviceOrientationChangedEvent>(eventStream);

expect(
await streamQueue.next,
equals(
const DeviceOrientationChangedEvent(
DeviceOrientation.landscapeRight,
),
),
);
});
});
}

0 comments on commit bf01875

Please sign in to comment.