Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Split CameraEvents into separate streams
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanbeusekom committed Nov 12, 2020
1 parent 96b40fc commit 69f573b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 132 deletions.
Expand Up @@ -2,5 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/events/camera_event.dart';
export 'src/platform_interface/camera_platform.dart';
export 'src/types/types.dart';
@@ -0,0 +1,62 @@
import 'dart:ui';

/// Generic Event coming from the native side of Camera.
///
/// All [CameraEvent]s contain the `cameraId` that originated the event. This
/// should never be `null`.
///
/// This class is used as a base class for all the events that might be
/// triggered from a Camera, but it is never used directly as an event type.
///
/// Do NOT instantiate new events like `CameraEvent(cameraId)` directly,
/// use a specific class instead:
///
/// Do `class NewEvent extend CameraEvent` when creating your own events.
/// See below for examples: `CameraClosingEvent`, `CameraErrorEvent`...
/// These events are more semantic and more pleasant to use than raw generics.
/// They can be (and in fact, are) filtered by the `instanceof`-operator.
abstract class CameraEvent {
/// The ID of the Camera this event is associated to.
final int cameraId;

/// Build a Camera Event, that relates a `cameraId`.
///
/// The `cameraId` is the ID of the camera that triggered the event.
CameraEvent(this.cameraId);
}

/// An event fired when the resolution preset of the camera has changed.
class ResolutionChangedEvent extends CameraEvent {
/// The capture size in pixels.
final Size captureSize;

/// The size of the preview in pixels.
final Size previewSize;

/// Build a ResolutionChanged event triggered from the camera represented by
/// `cameraId`.
///
/// The `captureSize` represents the size of the resulting image in pixels.
/// The `previewSize` represents the size of the generated preview in pixels.
ResolutionChangedEvent(int cameraId, this.captureSize, this.previewSize)
: super(cameraId);
}

/// An event fired when the camera is going to close.
class CameraClosingEvent extends CameraEvent {
/// Build a CameraClosing event triggered from the camera represented by
/// `cameraId`.
CameraClosingEvent(int cameraId) : super(cameraId);
}

/// An event fired when an error occured while operating the camera.
class CameraErrorEvent extends CameraEvent {
/// Description of the error.
final String description;

/// Build a CameraError event triggered from the camera represented by
/// `cameraId`.
///
/// The `description` represents the error occured on the camera.
CameraErrorEvent(int cameraId, this.description) : super(cameraId);
}
Expand Up @@ -4,6 +4,7 @@

import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart';

Expand Down Expand Up @@ -41,7 +42,7 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('availableCameras() is not implemented.');
}

/// Initializes the camera on the device and returns its textureId.
/// Initializes the camera on the device and returns its cameraId.
Future<int> initializeCamera(
CameraDescription cameraDescription, {
ResolutionPreset resolutionPreset,
Expand All @@ -50,13 +51,23 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('initializeCamera() is not implemented.');
}

/// Returns a Stream of [CameraEvent]s.
Stream<CameraEvent> cameraEventsFor(int textureId) {
throw UnimplementedError('videoEventsFor() has not been implemented.');
/// The camera's resolution has changed
Stream<ResolutionChangedEvent> onResolutionChanged(int cameraId) {
throw UnimplementedError('onResolutionChanged() is not implemented.');
}

/// The camera started to close.
Stream<CameraClosingEvent> onCameraClosing(int cameraId) {
throw UnimplementedError('onCameraClosing() is not implemented.');
}

/// The camera experienced an error.
Stream<CameraErrorEvent> onCameraError(int cameraId) {
throw UnimplementedError('onCameraError() is not implemented.');
}

/// Captures an image and saves it to [path].
Future<void> takePicture(int textureId, String path) {
Future<void> takePicture(int cameraId, String path) {
throw UnimplementedError('takePicture() is not implemented.');
}

Expand All @@ -73,43 +84,32 @@ abstract class CameraPlatform extends PlatformInterface {
/// The file is written on the flight as the video is being recorded.
/// If a file already exists at the provided path an error will be thrown.
/// The file can be read as soon as [stopVideoRecording] returns.
Future<void> startVideoRecording(int textureId, String path) {
Future<void> startVideoRecording(int cameraId, String path) {
throw UnimplementedError('startVideoRecording() is not implemented.');
}

/// Stop the video recording.
Future<void> stopVideoRecording(int textureId) {
Future<void> stopVideoRecording(int cameraId) {
throw UnimplementedError('stopVideoRecording() is not implemented.');
}

/// Pause video recording.
Future<void> pauseVideoRecording(int textureId) {
Future<void> pauseVideoRecording(int cameraId) {
throw UnimplementedError('pauseVideoRecording() is not implemented.');
}

/// Resume video recording after pausing.
Future<void> resumeVideoRecording(int textureId) {
Future<void> resumeVideoRecording(int cameraId) {
throw UnimplementedError('resumeVideoRecording() is not implemented.');
}

/// Start streaming images from platform camera.
///
/// When running continuously with [CameraPreview] widget, this function runs
/// best with [ResolutionPreset.low]. Running on [ResolutionPreset.high] can
/// have significant frame rate drops for [CameraPreview] on lower end
/// devices.
// TODO(bmparr): Add settings for resolution and fps.
Future<void> startImageStream(ImageAvailableHandler onAvailable) {
throw UnimplementedError('startImageStream() is not implemented.');
}

/// Stop streaming images from platform camera.
Future<void> stopImageStream() {
throw UnimplementedError('stopImageStream() is not implemented.');
/// Returns a widget showing a live camera preview.
Widget buildView(int cameraId) {
throw UnimplementedError('buildView() has not been implemented.');
}

/// Releases the resources of this camera.
Future<void> dispose(int textureId) {
Future<void> dispose(int cameraId) {
throw UnimplementedError('dispose() is not implemented.');
}
}

This file was deleted.

This file was deleted.

Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'callbacks.dart';
export 'camera_description.dart';
export 'camera_event.dart';
export 'camera_image.dart';
export 'resolution_preset.dart';

0 comments on commit 69f573b

Please sign in to comment.