Browse Source

[camera] Add pixel buffer

camera
Vitaliy Zarubin 1 year ago
parent
commit
ff482f15f3
  1. 155
      packages/camera/camera_aurora/lib/camera_data.dart
  2. 155
      packages/camera/camera_aurora/lib/camera_viewfinder.dart

155
packages/camera/camera_aurora/lib/camera_data.dart

@ -0,0 +1,155 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// 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<CameraImageData>? _frameStreamController;
/// Completes with a list of available cameras.
///
/// This method returns an empty list when no cameras are available.
@override
Future<List<CameraDescription>> availableCameras() =>
CameraAuroraPlatform.instance.availableCameras();
/// Creates an uninitialized camera instance and returns the cameraId.
@override
Future<int> 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<void> initializeCamera(
int cameraId, {
ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown,
}) async {
// init
}
/// Releases the resources of this camera.
@override
Future<void> dispose(int cameraId) {
return CameraAuroraPlatform.instance.dispose(cameraId);
}
/// Captures an image and returns the file where it was saved.
@override
Future<XFile> 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<void> startVideoRecording(int cameraId,
{Duration? maxVideoDuration}) =>
CameraAuroraPlatform.instance.startVideoRecording(cameraId);
/// Stops the video recording and returns the file where it was saved.
@override
Future<XFile> stopVideoRecording(int cameraId) =>
CameraAuroraPlatform.instance.stopVideoRecording(cameraId);
/// Pause video recording.
@override
Future<void> pauseVideoRecording(int cameraId) =>
CameraAuroraPlatform.instance.pauseVideoRecording(cameraId);
/// Resume video recording after pausing.
@override
Future<void> resumeVideoRecording(int cameraId) =>
CameraAuroraPlatform.instance.resumeVideoRecording(cameraId);
/// The ui orientation changed.
///
/// Implementations for this:
/// - Should support all 4 orientations.
@override
Stream<DeviceOrientationChangedEvent> onDeviceOrientationChanged() async* {
yield const DeviceOrientationChangedEvent(DeviceOrientation.portraitUp);
}
/// The camera has been initialized.
@override
Stream<CameraInitializedEvent> onCameraInitialized(int cameraId) async* {
yield CameraInitializedEvent(
cameraId,
// previewWidth
400,
// previewHeight
400,
// exposureMode
ExposureMode.auto,
// exposurePointSupported
true,
// focusMode
FocusMode.auto,
// focusPointSupported
true,
);
}
@override
Stream<CameraImageData> onStreamedFrameAvailable(
int cameraId, {
CameraImageStreamOptions? options,
}) {
_frameStreamController = StreamController<CameraImageData>(
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),
),
);
}
}

155
packages/camera/camera_aurora/lib/camera_viewfinder.dart

@ -0,0 +1,155 @@
// SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
// 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<CameraImageData>? _frameStreamController;
/// Completes with a list of available cameras.
///
/// This method returns an empty list when no cameras are available.
@override
Future<List<CameraDescription>> availableCameras() =>
CameraAuroraPlatform.instance.availableCameras();
/// Creates an uninitialized camera instance and returns the cameraId.
@override
Future<int> 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<void> initializeCamera(
int cameraId, {
ImageFormatGroup imageFormatGroup = ImageFormatGroup.unknown,
}) async {
// init
}
/// Releases the resources of this camera.
@override
Future<void> dispose(int cameraId) {
return CameraAuroraPlatform.instance.dispose(cameraId);
}
/// Captures an image and returns the file where it was saved.
@override
Future<XFile> 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<void> startVideoRecording(int cameraId,
{Duration? maxVideoDuration}) =>
CameraAuroraPlatform.instance.startVideoRecording(cameraId);
/// Stops the video recording and returns the file where it was saved.
@override
Future<XFile> stopVideoRecording(int cameraId) =>
CameraAuroraPlatform.instance.stopVideoRecording(cameraId);
/// Pause video recording.
@override
Future<void> pauseVideoRecording(int cameraId) =>
CameraAuroraPlatform.instance.pauseVideoRecording(cameraId);
/// Resume video recording after pausing.
@override
Future<void> resumeVideoRecording(int cameraId) =>
CameraAuroraPlatform.instance.resumeVideoRecording(cameraId);
/// The ui orientation changed.
///
/// Implementations for this:
/// - Should support all 4 orientations.
@override
Stream<DeviceOrientationChangedEvent> onDeviceOrientationChanged() async* {
yield const DeviceOrientationChangedEvent(DeviceOrientation.portraitUp);
}
/// The camera has been initialized.
@override
Stream<CameraInitializedEvent> onCameraInitialized(int cameraId) async* {
yield CameraInitializedEvent(
cameraId,
// previewWidth
400,
// previewHeight
400,
// exposureMode
ExposureMode.auto,
// exposurePointSupported
true,
// focusMode
FocusMode.auto,
// focusPointSupported
true,
);
}
@override
Stream<CameraImageData> onStreamedFrameAvailable(
int cameraId, {
CameraImageStreamOptions? options,
}) {
_frameStreamController = StreamController<CameraImageData>(
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),
),
);
}
}
Loading…
Cancel
Save