diff --git a/packages/camera/camera_aurora/lib/camera_data.dart b/packages/camera/camera_aurora/lib/camera_data.dart new file mode 100644 index 0000000..39367d8 --- /dev/null +++ b/packages/camera/camera_aurora/lib/camera_data.dart @@ -0,0 +1,155 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause +import 'dart:async'; +import 'dart:convert'; + +import 'package:camera_platform_interface/camera_platform_interface.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +import 'camera_aurora_method_channel.dart'; +import 'camera_aurora_platform_interface.dart'; + +class CameraAurora extends CameraPlatform { + /// Registers this class as the default instance of [CameraPlatform]. + static void registerWith() { + CameraPlatform.instance = CameraAurora(); + } + + // The stream for vending frames to platform interface clients. + StreamController? _frameStreamController; + + /// Completes with a list of available cameras. + /// + /// This method returns an empty list when no cameras are available. + @override + Future> availableCameras() => + CameraAuroraPlatform.instance.availableCameras(); + + /// Creates an uninitialized camera instance and returns the cameraId. + @override + Future createCamera( + CameraDescription cameraDescription, + ResolutionPreset? resolutionPreset, { + bool enableAudio = false, + }) { + EventChannel(CameraAuroraEvents.cameraAuroraStreamedFrame.name) + .receiveBroadcastStream() + .listen((event) { + debugPrint(event); + }); + return CameraAuroraPlatform.instance.createCamera(cameraDescription.name); + } + + /// Initializes the camera on the device. + /// + /// [imageFormatGroup] is used to specify the image formatting used. + /// On Android this defaults to ImageFormat.YUV_420_888 and applies only to the imageStream. + /// On iOS this defaults to kCVPixelFormatType_32BGRA. + /// On Web this parameter is currently not supported. + @override + Future initializeCamera( + int cameraId, { + ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown, + }) async { + // init + } + + /// Releases the resources of this camera. + @override + Future dispose(int cameraId) { + return CameraAuroraPlatform.instance.dispose(cameraId); + } + + /// Captures an image and returns the file where it was saved. + @override + Future takePicture(int cameraId) => + CameraAuroraPlatform.instance.takePicture(cameraId); + + /// Starts a video recording. + /// + /// The length of the recording can be limited by specifying the [maxVideoDuration]. + /// By default no maximum duration is specified, + /// meaning the recording will continue until manually stopped. + /// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent] + /// through the [onVideoRecordedEvent] stream when the set duration is reached. + /// + /// This method is deprecated in favour of [startVideoCapturing]. + @override + Future startVideoRecording(int cameraId, + {Duration? maxVideoDuration}) => + CameraAuroraPlatform.instance.startVideoRecording(cameraId); + + /// Stops the video recording and returns the file where it was saved. + @override + Future stopVideoRecording(int cameraId) => + CameraAuroraPlatform.instance.stopVideoRecording(cameraId); + + /// Pause video recording. + @override + Future pauseVideoRecording(int cameraId) => + CameraAuroraPlatform.instance.pauseVideoRecording(cameraId); + + /// Resume video recording after pausing. + @override + Future resumeVideoRecording(int cameraId) => + CameraAuroraPlatform.instance.resumeVideoRecording(cameraId); + + /// The ui orientation changed. + /// + /// Implementations for this: + /// - Should support all 4 orientations. + @override + Stream onDeviceOrientationChanged() async* { + yield const DeviceOrientationChangedEvent(DeviceOrientation.portraitUp); + } + + /// The camera has been initialized. + @override + Stream onCameraInitialized(int cameraId) async* { + yield CameraInitializedEvent( + cameraId, + // previewWidth + 400, + // previewHeight + 400, + // exposureMode + ExposureMode.auto, + // exposurePointSupported + true, + // focusMode + FocusMode.auto, + // focusPointSupported + true, + ); + } + + @override + Stream onStreamedFrameAvailable( + int cameraId, { + CameraImageStreamOptions? options, + }) { + _frameStreamController = StreamController( + onListen: () => + CameraAuroraPlatform.instance.streamedFrame(cameraId).listen((data) { + _frameStreamController!.add(data); + }), + onPause: () => {}, + onResume: () => {}, + onCancel: () => {}, + ); + return _frameStreamController!.stream; + } + + /// Returns a widget showing a live camera preview. + @override + Widget buildPreview(int cameraId) { + return Center( + child: Text( + 'Camera: $cameraId', + style: + const TextStyle(fontWeight: FontWeight.bold, color: Colors.white), + ), + ); + } +} diff --git a/packages/camera/camera_aurora/lib/camera_viewfinder.dart b/packages/camera/camera_aurora/lib/camera_viewfinder.dart new file mode 100644 index 0000000..39367d8 --- /dev/null +++ b/packages/camera/camera_aurora/lib/camera_viewfinder.dart @@ -0,0 +1,155 @@ +// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC +// SPDX-License-Identifier: BSD-3-Clause +import 'dart:async'; +import 'dart:convert'; + +import 'package:camera_platform_interface/camera_platform_interface.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +import 'camera_aurora_method_channel.dart'; +import 'camera_aurora_platform_interface.dart'; + +class CameraAurora extends CameraPlatform { + /// Registers this class as the default instance of [CameraPlatform]. + static void registerWith() { + CameraPlatform.instance = CameraAurora(); + } + + // The stream for vending frames to platform interface clients. + StreamController? _frameStreamController; + + /// Completes with a list of available cameras. + /// + /// This method returns an empty list when no cameras are available. + @override + Future> availableCameras() => + CameraAuroraPlatform.instance.availableCameras(); + + /// Creates an uninitialized camera instance and returns the cameraId. + @override + Future createCamera( + CameraDescription cameraDescription, + ResolutionPreset? resolutionPreset, { + bool enableAudio = false, + }) { + EventChannel(CameraAuroraEvents.cameraAuroraStreamedFrame.name) + .receiveBroadcastStream() + .listen((event) { + debugPrint(event); + }); + return CameraAuroraPlatform.instance.createCamera(cameraDescription.name); + } + + /// Initializes the camera on the device. + /// + /// [imageFormatGroup] is used to specify the image formatting used. + /// On Android this defaults to ImageFormat.YUV_420_888 and applies only to the imageStream. + /// On iOS this defaults to kCVPixelFormatType_32BGRA. + /// On Web this parameter is currently not supported. + @override + Future initializeCamera( + int cameraId, { + ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown, + }) async { + // init + } + + /// Releases the resources of this camera. + @override + Future dispose(int cameraId) { + return CameraAuroraPlatform.instance.dispose(cameraId); + } + + /// Captures an image and returns the file where it was saved. + @override + Future takePicture(int cameraId) => + CameraAuroraPlatform.instance.takePicture(cameraId); + + /// Starts a video recording. + /// + /// The length of the recording can be limited by specifying the [maxVideoDuration]. + /// By default no maximum duration is specified, + /// meaning the recording will continue until manually stopped. + /// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent] + /// through the [onVideoRecordedEvent] stream when the set duration is reached. + /// + /// This method is deprecated in favour of [startVideoCapturing]. + @override + Future startVideoRecording(int cameraId, + {Duration? maxVideoDuration}) => + CameraAuroraPlatform.instance.startVideoRecording(cameraId); + + /// Stops the video recording and returns the file where it was saved. + @override + Future stopVideoRecording(int cameraId) => + CameraAuroraPlatform.instance.stopVideoRecording(cameraId); + + /// Pause video recording. + @override + Future pauseVideoRecording(int cameraId) => + CameraAuroraPlatform.instance.pauseVideoRecording(cameraId); + + /// Resume video recording after pausing. + @override + Future resumeVideoRecording(int cameraId) => + CameraAuroraPlatform.instance.resumeVideoRecording(cameraId); + + /// The ui orientation changed. + /// + /// Implementations for this: + /// - Should support all 4 orientations. + @override + Stream onDeviceOrientationChanged() async* { + yield const DeviceOrientationChangedEvent(DeviceOrientation.portraitUp); + } + + /// The camera has been initialized. + @override + Stream onCameraInitialized(int cameraId) async* { + yield CameraInitializedEvent( + cameraId, + // previewWidth + 400, + // previewHeight + 400, + // exposureMode + ExposureMode.auto, + // exposurePointSupported + true, + // focusMode + FocusMode.auto, + // focusPointSupported + true, + ); + } + + @override + Stream onStreamedFrameAvailable( + int cameraId, { + CameraImageStreamOptions? options, + }) { + _frameStreamController = StreamController( + onListen: () => + CameraAuroraPlatform.instance.streamedFrame(cameraId).listen((data) { + _frameStreamController!.add(data); + }), + onPause: () => {}, + onResume: () => {}, + onCancel: () => {}, + ); + return _frameStreamController!.stream; + } + + /// Returns a widget showing a live camera preview. + @override + Widget buildPreview(int cameraId) { + return Center( + child: Text( + 'Camera: $cameraId', + style: + const TextStyle(fontWeight: FontWeight.bold, color: Colors.white), + ), + ); + } +}