This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Add byte streaming capability for the camera #965
Merged
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
c3f703e
Start of Android side of byte stream passing
bparrishMines f310580
dart side of byte streaming
bparrishMines 87fdb60
Fix android streaming
bparrishMines 673b003
Merge branch 'master' of github.com:flutter/plugins into camera_android
bparrishMines 8d353ad
Add ios byte streaming
bparrishMines 0291a29
Convert buffer to uiimage to pass over
bparrishMines 31f746a
formatting
bparrishMines 5fcfeb2
Stream yuv bytes instead
bparrishMines 040d1ae
Make video format a constant
bparrishMines 16d1d32
Pass back metadata for ios image
bparrishMines 8e88978
Pass back metadata for android image
bparrishMines 67f8304
Dart code now parses camera image buffer
bparrishMines 646283a
YUV image to bgra
bparrishMines 7e99691
Add documentation
bparrishMines 4cbfab9
Only pass available data on Android
bparrishMines aa0e263
Merge branch 'master' of github.com:bparrishMines/plugins into camera…
bparrishMines 9b2ae22
Merge branch 'master' of github.com:flutter/plugins into camera_andro…
bparrishMines 297fe7a
Bump version
bparrishMines bdd9007
Formatting
bparrishMines ccc057b
create imageformat error
bparrishMines 989edf6
Don't return from null
bparrishMines 22ce601
Merge branch 'master' of github.com:bparrishMines/plugins into camera…
bparrishMines b1d7b89
Init buffers in constructor
bparrishMines aa3db0c
Add yuv ios format
bparrishMines 0349ae2
Used presets with defined resolution. Sometimes resolution would come…
bparrishMines 2633c49
Formatting
bparrishMines 6377c64
Move CameraImage classes to separate file
bparrishMines 6660a68
Move camera.dart to src folder
bparrishMines a4d278e
Create camera library
bparrishMines 045dd53
Better name and comments
bparrishMines 01520fe
Change from library camera file
bparrishMines 6155620
bytestream -> imagestream
bparrishMines 5898b4c
Comments and names
bparrishMines 7617bb9
Formatting
bparrishMines f18db98
Added resolution and fps todo
bparrishMines 0bf466a
Unmodify file
bparrishMines a53222b
Empty commit to rerun tests
bparrishMines fe965d1
Remove TODO from documentation
bparrishMines 7c0228f
Merge branch 'master' of github.com:flutter/plugins into camera_andro…
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Move CameraImage classes to separate file
- Loading branch information
commit 6377c641a59cc7b9fccabd1fad57fceb0a408ac6
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // Copyright 2018 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// A single color plane of image data. | ||
| /// | ||
| /// The number and meaning of the planes in an image are determined by the | ||
| /// format of the Image. | ||
| class Plane { | ||
| Plane._fromPlatformData(dynamic data) | ||
| : bytes = data['bytes'], | ||
| bytesPerPixel = data['bytesPerPixel'], | ||
| bytesPerRow = data['bytesPerRow'], | ||
| height = data['height'], | ||
| width = data['width']; | ||
|
|
||
| /// Bytes representing this plane. | ||
| final Uint8List bytes; | ||
|
|
||
| /// The distance between adjacent pixel samples on Android, in bytes. | ||
| /// | ||
| /// Will be `null` on iOS. | ||
| final int bytesPerPixel; | ||
|
|
||
| /// The row stride for this color plane, in bytes. | ||
| final int bytesPerRow; | ||
|
|
||
| /// Height of the pixel buffer on iOS. | ||
| /// | ||
| /// Will be `null` on Android | ||
| final int height; | ||
|
|
||
| /// Width of the pixel buffer on iOS. | ||
| /// | ||
| /// Will be `null` on Android. | ||
| final int width; | ||
| } | ||
|
|
||
| /// Group of image formats that are comparable across Android and iOS platforms. | ||
| enum ImageFormatGroup { | ||
| /// The image format does not fit into any specific group. | ||
| unknown, | ||
|
|
||
| /// Multi-plane YUV 420 format. | ||
| /// | ||
| /// This format is a generic YCbCr format, capable of describing any 4:2:0 | ||
| /// chroma-subsampled planar or semiplanar buffer (but not fully interleaved), | ||
| /// with 8 bits per color sample. | ||
| /// | ||
| /// On Android, this is `android.graphics.ImageFormat.YUV_420_888`. See | ||
| /// https://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888 | ||
| /// | ||
| /// On iOS, this is `kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange`. See | ||
| /// https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers/kcvpixelformattype_420ypcbcr8biplanarvideorange?language=objc | ||
| yuv420, | ||
| } | ||
|
|
||
| /// Describes how pixels are represented in an image. | ||
| class ImageFormat { | ||
| ImageFormat._fromPlatformData(this.raw) : group = _asImageFormatGroup(raw); | ||
|
|
||
| /// Describes the format group the raw image format falls into. | ||
| final ImageFormatGroup group; | ||
|
|
||
| /// Raw version of the format from the Android or iOS platform. | ||
| /// | ||
| /// On Android, this is an `int` from class `android.graphics.ImageFormat`. See | ||
| /// https://developer.android.com/reference/android/graphics/ImageFormat | ||
| /// | ||
| /// On iOS, this is a `FourCharCode` constant from Pixel Format Identifiers. | ||
| /// See https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers?language=objc | ||
| final dynamic raw; | ||
| } | ||
|
|
||
| ImageFormatGroup _asImageFormatGroup(dynamic rawFormat) { | ||
| if (rawFormat == 35 || rawFormat == 875704438) { | ||
| return ImageFormatGroup.yuv420; | ||
| } else { | ||
| return ImageFormatGroup.unknown; | ||
| } | ||
| } | ||
|
|
||
| /// A single complete image buffer from the platform camera. | ||
| /// | ||
| /// This class allows for direct application access to the pixel data of an | ||
| /// Image through one or more [Uint8List]. Each buffer is encapsulated in a | ||
| /// [Plane] that describes the layout of the pixel data in that plane. The | ||
| /// [CameraImage] is not directly usable as a UI resource. | ||
| /// | ||
| /// Although not all image formats are planar on iOS, we treat 1-dimensional | ||
| /// images as single planar images. | ||
| class CameraImage { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add a helper to make it easy to turn this into a https://docs.flutter.io/flutter/painting/ImageProvider-class.html
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation doesn't include a compatible image format with 'ImageProvider'. This impl uses yuv420. I also include in |
||
| CameraImage._fromPlatformData(dynamic data) | ||
| : format = ImageFormat._fromPlatformData(data['format']), | ||
| height = data['height'], | ||
| width = data['width'], | ||
| planes = List<Plane>.unmodifiable(data['planes'] | ||
| .map((dynamic planeData) => Plane._fromPlatformData(planeData))); | ||
|
|
||
| /// Format of the image provided. | ||
| /// | ||
| /// Determines the number of planes needed to represent the image, and | ||
| /// the general layout of the pixel data in each [Uint8List]. | ||
| final ImageFormat format; | ||
|
|
||
| /// Height of the image in pixels. | ||
| /// | ||
| /// For formats where some color channels are subsampled, this is the height | ||
| /// of the largest-resolution plane. | ||
| final int height; | ||
|
|
||
| /// Width of the image in pixels. | ||
| /// | ||
| /// For formats where some color channels are subsampled, this is the width | ||
| /// of the largest-resolution plane. | ||
| final int width; | ||
|
|
||
| /// The pixels planes for this image. | ||
| /// | ||
| /// The number of planes is determined by the format of the image. | ||
| final List<Plane> planes; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.