[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:
@@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
|
||||
#include "method_channel/method_channel_camera.h"
|
||||
|
||||
#include <flutter/standard_method_codec.h>
|
||||
|
||||
namespace {
|
||||
constexpr char kChannelName[] = "flutter.io/cameraPlugin/camera";
|
||||
constexpr char kChannelMethodInitialized[] = "initialized";
|
||||
}; // namespace
|
||||
|
||||
MethodChannelCamera::MethodChannelCamera(flutter::PluginRegistrar* registrar,
|
||||
int64_t camera_id) {
|
||||
std::string channel_name = kChannelName + std::to_string(camera_id);
|
||||
channel_ = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), channel_name.c_str(),
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
}
|
||||
|
||||
void MethodChannelCamera::SendInitializedEvent(
|
||||
CameraInitializedEvent& message) {
|
||||
auto value = std::make_unique<flutter::EncodableValue>(message.ToMap());
|
||||
Send(kChannelMethodInitialized, std::move(value));
|
||||
}
|
||||
|
||||
void MethodChannelCamera::Send(
|
||||
const std::string& method,
|
||||
std::unique_ptr<flutter::EncodableValue>&& arguments) {
|
||||
channel_->InvokeMethod(method, std::move(arguments));
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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_CAMERA_METHOD_CHANNEL_METHOD_CHANNEL_CAMERA_H_
|
||||
#define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_METHOD_CHANNEL_METHOD_CHANNEL_CAMERA_H_
|
||||
|
||||
#include <flutter/encodable_value.h>
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/plugin_registrar.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "events/camera_initialized_event.h"
|
||||
|
||||
enum class CameraEventType {
|
||||
kError,
|
||||
kCameraClosing,
|
||||
kInitialized,
|
||||
};
|
||||
|
||||
class MethodChannelCamera {
|
||||
public:
|
||||
MethodChannelCamera(flutter::PluginRegistrar* registrar, int64_t camera_id);
|
||||
~MethodChannelCamera() = default;
|
||||
|
||||
void SendInitializedEvent(CameraInitializedEvent& message);
|
||||
|
||||
private:
|
||||
void Send(const std::string& method,
|
||||
std::unique_ptr<flutter::EncodableValue>&& arguments);
|
||||
|
||||
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
|
||||
};
|
||||
|
||||
#endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_METHOD_CHANNEL_METHOD_CHANNEL_CAMERA_H_
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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.
|
||||
|
||||
#include "method_channel/method_channel_device.h"
|
||||
|
||||
#include <flutter/standard_method_codec.h>
|
||||
|
||||
namespace {
|
||||
constexpr char kChannelName[] = "flutter.io/cameraPlugin/device";
|
||||
constexpr char kChannelMethodInitialized[] = "initialized";
|
||||
|
||||
constexpr char kOrientation[] = "orientation";
|
||||
}; // namespace
|
||||
|
||||
MethodChannelDevice::MethodChannelDevice(flutter::PluginRegistrar* registrar) {
|
||||
channel_ = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
||||
registrar->messenger(), kChannelName,
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
}
|
||||
|
||||
void MethodChannelDevice::SendDeviceOrientationChangeEvent(
|
||||
const DeviceOrientation& orientation) {
|
||||
flutter::EncodableMap mp;
|
||||
mp[flutter::EncodableValue(kOrientation)] =
|
||||
flutter::EncodableValue(SerializeDeviceOrientation(orientation));
|
||||
auto value = std::make_unique<flutter::EncodableValue>(mp);
|
||||
|
||||
Send(kChannelMethodInitialized, std::move(value));
|
||||
}
|
||||
|
||||
void MethodChannelDevice::Send(
|
||||
const std::string& method,
|
||||
std::unique_ptr<flutter::EncodableValue>&& arguments) {
|
||||
channel_->InvokeMethod(method, std::move(arguments));
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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_CAMERA_METHOD_CHANNEL_METHOD_CHANNEL_DEVICE_H_
|
||||
#define PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_METHOD_CHANNEL_METHOD_CHANNEL_DEVICE_H_
|
||||
|
||||
#include <flutter/encodable_value.h>
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/plugin_registrar.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "types/orientation.h"
|
||||
|
||||
class MethodChannelDevice {
|
||||
public:
|
||||
MethodChannelDevice(flutter::PluginRegistrar* registrar);
|
||||
~MethodChannelDevice() = default;
|
||||
|
||||
void SendDeviceOrientationChangeEvent(const DeviceOrientation& orientation);
|
||||
|
||||
private:
|
||||
void Send(const std::string& method,
|
||||
std::unique_ptr<flutter::EncodableValue>&& arguments);
|
||||
|
||||
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
|
||||
};
|
||||
|
||||
#endif // PACKAGES_CAMERA_CAMERA_ELINUX_CAMERA_METHOD_CHANNEL_METHOD_CHANNEL_DEVICE_H_
|
||||
Reference in New Issue
Block a user