-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split isolate payload into
FramePayload
, LogPayload
, and `Details…
…Payload` (#9) * Documented everything * Added lint explanation to deprecated_member_use * Upgraded package:typed_isolate
- Loading branch information
1 parent
628315d
commit 8c23dcc
Showing
9 changed files
with
154 additions
and
144 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
import "dart:ffi"; | ||
|
||
import "package:burt_network/burt_network.dart"; | ||
import "package:burt_network/logging.dart"; | ||
import "package:opencv_ffi/opencv_ffi.dart"; | ||
|
||
/// A payload containing some data to report back to the parent isolate. | ||
/// | ||
/// Instead of having nullable fields on this class, we subclass it and provide | ||
/// only the relevant fields for each subclass. That way, for example, you cannot | ||
/// accidentally send a frame without a [CameraDetails]. | ||
sealed class IsolatePayload { const IsolatePayload(); } | ||
|
||
/// A payload representing the status of the given camera. | ||
class DetailsPayload extends IsolatePayload { | ||
/// The details being sent. | ||
final CameraDetails details; | ||
/// A const constructor. | ||
const DetailsPayload(this.details); | ||
} | ||
|
||
/// A container for a pointer to a native buffer that can be sent across isolates. | ||
/// | ||
/// Sending a buffer across isolates would mean that data is copied, which is not ideal for | ||
/// buffers containing an entire JPG image, from multiple isolates, multiple frames per second. | ||
/// Since we cannot yet send FFI pointers across isolates, we have to send its raw address | ||
/// instead. | ||
class FrameData { | ||
/// The [CameraDetails] for this frame. | ||
/// Since we cannot yet send FFI pointers across isolates, we have to send its raw address. | ||
class FramePayload extends IsolatePayload { | ||
/// The details of the camera this frame came from. | ||
final CameraDetails details; | ||
/// The address of the FFI pointer containing the image. | ||
final int? address; | ||
/// The amount of bytes to read past [address]. | ||
final int? length; | ||
/// The address in FFI memory this frame starts at. | ||
final int address; | ||
/// The length of this frame in bytes. | ||
final int length; | ||
|
||
/// A const constructor. | ||
const FramePayload({required this.details, required this.address, required this.length}); | ||
|
||
/// The underlying data held at [address]. | ||
/// | ||
/// This cannot be a normal field as [Pointer]s cannot be sent across isolates, and this should | ||
/// not be a getter because the underlying memory needs to be freed and cannot be used again. | ||
OpenCVImage getFrame() => OpenCVImage(pointer: Pointer.fromAddress(address), length: length); | ||
} | ||
|
||
/// Creates a [FrameData] containing an actual frame. | ||
FrameData({required this.details, required this.address, required this.length}); | ||
/// Creates a [FrameData] that only has [CameraDetails]. | ||
FrameData.details(this.details) : address = null, length = null; | ||
/// A class to send log messages across isolates. The parent isolate is responsible for logging. | ||
class LogPayload extends IsolatePayload { | ||
/// The level to log this message. | ||
final LogLevel level; | ||
/// The message to log. | ||
final String message; | ||
/// A const constructor. | ||
const LogPayload({required this.level, required this.message}); | ||
} |
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.