[camera][draft] Add camera plugin (#29)

Added the first draft version, but there are still a lot of unimplemented features.
This commit is contained in:
Hidenori Matsubayashi
2021-08-16 16:43:28 +09:00
committed by GitHub
parent 4c37b98e79
commit 999fdad59c
45 changed files with 3874 additions and 0 deletions
@@ -0,0 +1,79 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_AVAILABLE_CAMERAS_MESSAGE_H_
#define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_AVAILABLE_CAMERAS_MESSAGE_H_
#include <flutter/binary_messenger.h>
#include <flutter/encodable_value.h>
#include <string>
#include <variant>
class AvailableCamerasMessage {
public:
AvailableCamerasMessage() = default;
~AvailableCamerasMessage() = default;
// Prevent copying.
AvailableCamerasMessage(AvailableCamerasMessage const&) = default;
AvailableCamerasMessage& operator=(AvailableCamerasMessage const&) = default;
void SetName(const std::string& name) { name_ = name; }
std::string GetName() const { return name_; }
void SetSensorOrientation(const int& sensor_orientation) {
sensor_orientation_ = sensor_orientation;
}
int GetSensorOrientation() const { return sensor_orientation_; }
void SetLensFacing(const std::string& lens_facing) {
lens_facing_ = lens_facing;
}
std::string GetLensFacing() const { return lens_facing_; }
flutter::EncodableValue ToMap() {
flutter::EncodableMap map = {
{flutter::EncodableValue("name"), flutter::EncodableValue(name_)},
{flutter::EncodableValue("sensorOrientation"),
flutter::EncodableValue(sensor_orientation_)},
{flutter::EncodableValue("lensFacing"),
flutter::EncodableValue(lens_facing_)}};
return flutter::EncodableValue(map);
}
static AvailableCamerasMessage FromMap(const flutter::EncodableValue& value) {
AvailableCamerasMessage message;
if (std::holds_alternative<flutter::EncodableMap>(value)) {
auto map = std::get<flutter::EncodableMap>(value);
flutter::EncodableValue& name = map[flutter::EncodableValue("name")];
if (std::holds_alternative<std::string>(name)) {
message.SetName(std::get<std::string>(name));
}
flutter::EncodableValue& sensor_orientation =
map[flutter::EncodableValue("sensorOrientation")];
if (std::holds_alternative<int>(sensor_orientation)) {
message.SetSensorOrientation(std::get<int>(sensor_orientation));
}
flutter::EncodableValue& lens_facing =
map[flutter::EncodableValue("lensFacing")];
if (std::holds_alternative<std::string>(lens_facing)) {
message.SetLensFacing(std::get<std::string>(lens_facing));
}
}
return message;
}
private:
std::string name_;
int sensor_orientation_;
std::string lens_facing_;
};
#endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_AVAILABLE_CAMERAS_MESSAGE_H_
@@ -0,0 +1,13 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_MESSAGES_H_
#define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_MESSAGES_H_
#include "available_cameras_message.h"
#include "orientation_message.h"
#include "texture_message.h"
#include "zoom_level_message.h"
#endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_MESSAGES_H_
@@ -0,0 +1,57 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ORIENTATION_MESSAGE_H_
#define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ORIENTATION_MESSAGE_H_
#include <flutter/binary_messenger.h>
#include <flutter/encodable_value.h>
#include <string>
#include <variant>
#include "types/orientation.h"
class OrientationMessage {
public:
OrientationMessage() = default;
~OrientationMessage() = default;
// Prevent copying.
OrientationMessage(OrientationMessage const&) = default;
OrientationMessage& operator=(OrientationMessage const&) = default;
void SetOrientation(DeviceOrientation orientation) {
orientation_ = orientation;
}
DeviceOrientation GetOrientation() const { return orientation_; }
flutter::EncodableValue ToMap() {
flutter::EncodableMap map = {
{flutter::EncodableValue("orientation"),
flutter::EncodableValue(SerializeDeviceOrientation(orientation_))}};
return flutter::EncodableValue(map);
}
static OrientationMessage FromMap(const flutter::EncodableValue& value) {
OrientationMessage message;
if (std::holds_alternative<flutter::EncodableMap>(value)) {
auto map = std::get<flutter::EncodableMap>(value);
flutter::EncodableValue& orientation =
map[flutter::EncodableValue("orientation")];
if (std::holds_alternative<std::string>(orientation)) {
message.SetOrientation(
DeserializeDeviceOrientation(std::get<std::string>(orientation)));
}
}
return message;
}
private:
DeviceOrientation orientation_;
};
#endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ORIENTATION_MESSAGE_H_
@@ -0,0 +1,50 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_
#define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_
#include <flutter/binary_messenger.h>
#include <flutter/encodable_value.h>
class TextureMessage {
public:
TextureMessage() = default;
~TextureMessage() = default;
// Prevent copying.
TextureMessage(TextureMessage const&) = default;
TextureMessage& operator=(TextureMessage const&) = default;
void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; }
int64_t GetTextureId() const { return texture_id_; }
flutter::EncodableValue ToMap() {
flutter::EncodableMap map = {{flutter::EncodableValue("textureId"),
flutter::EncodableValue(texture_id_)}};
return flutter::EncodableValue(map);
}
static TextureMessage FromMap(const flutter::EncodableValue& value) {
TextureMessage message;
if (std::holds_alternative<flutter::EncodableMap>(value)) {
auto map = std::get<flutter::EncodableMap>(value);
flutter::EncodableValue& texture_id =
map[flutter::EncodableValue("textureId")];
if (std::holds_alternative<int32_t>(texture_id) ||
std::holds_alternative<int64_t>(texture_id)) {
message.SetTextureId(texture_id.LongValue());
}
}
return message;
}
private:
int64_t texture_id_ = 0;
};
#endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_
@@ -0,0 +1,49 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ZOOM_LEVEL_MESSAGE_H_
#define PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ZOOM_LEVEL_MESSAGE_H_
#include <flutter/binary_messenger.h>
#include <flutter/encodable_value.h>
#include <variant>
class ZoomLevelMessage {
public:
ZoomLevelMessage() = default;
~ZoomLevelMessage() = default;
// Prevent copying.
ZoomLevelMessage(ZoomLevelMessage const&) = default;
ZoomLevelMessage& operator=(ZoomLevelMessage const&) = default;
void SetZoom(double zoom) { zoom_ = zoom; }
double GetZoom() const { return zoom_; }
flutter::EncodableValue ToMap() {
flutter::EncodableMap map = {
{flutter::EncodableValue("zoom"), flutter::EncodableValue(zoom_)}};
return flutter::EncodableValue(map);
}
static ZoomLevelMessage FromMap(const flutter::EncodableValue& value) {
ZoomLevelMessage message;
if (std::holds_alternative<flutter::EncodableMap>(value)) {
auto map = std::get<flutter::EncodableMap>(value);
flutter::EncodableValue& zoom = map[flutter::EncodableValue("zoom")];
if (std::holds_alternative<double>(zoom)) {
message.SetZoom(std::get<double>(zoom));
}
}
return message;
}
private:
double zoom_;
};
#endif // PACKAGES_CAMERA_CAMERA_ELINUX_MESSAGES_ZOOM_LEVEL_MESSAGE_H_