mirror of
https://github.com/toyota-connected/ivi-homescreen-plugins.git
synced 2026-06-21 07:19:32 -07:00
format the code
Signed-off-by: Bill Chen <bill.chen@woven-planet.global>
This commit is contained in:
@@ -24,18 +24,18 @@ CameraManager::~CameraManager() {
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<uint32_t, std::string>& CameraManager::getAvailableCameras() const {
|
||||
const std::map<uint32_t, std::string>& CameraManager::getAvailableCameras()
|
||||
const {
|
||||
return camera_nodes_;
|
||||
}
|
||||
|
||||
// Callback function for detecting cameras
|
||||
void CameraManager::on_global(void* data,
|
||||
uint32_t id,
|
||||
uint32_t permissions,
|
||||
const char* type,
|
||||
uint32_t version,
|
||||
const struct spa_dict* props) {
|
||||
|
||||
uint32_t id,
|
||||
uint32_t permissions,
|
||||
const char* type,
|
||||
uint32_t version,
|
||||
const struct spa_dict* props) {
|
||||
if (!data) {
|
||||
std::cerr << "[Error] on_global received null data\n";
|
||||
return;
|
||||
@@ -44,30 +44,30 @@ void CameraManager::on_global(void* data,
|
||||
if (!props)
|
||||
return;
|
||||
const char* media_class = spa_dict_lookup(props, "media.class");
|
||||
if (!media_class || std::string(media_class) != "Video/Source") return;
|
||||
if (!media_class || std::string(media_class) != "Video/Source")
|
||||
return;
|
||||
|
||||
const char *node_name = spa_dict_lookup(props, "node.description");
|
||||
const char* node_name = spa_dict_lookup(props, "node.description");
|
||||
std::string name = node_name ? node_name : "Unknown";
|
||||
|
||||
auto *self = static_cast<CameraManager *>(data);
|
||||
auto* self = static_cast<CameraManager*>(data);
|
||||
self->camera_nodes_[id] = name;
|
||||
std::cout << "[+] Camera added: " << name << " (id: " << id << ")\n";
|
||||
|
||||
}
|
||||
void CameraManager::on_global_remove(void *data, uint32_t id) {
|
||||
void CameraManager::on_global_remove(void* data, uint32_t id) {
|
||||
if (!data) {
|
||||
std::cerr << "[Error] on_global_remove received null data\n";
|
||||
return;
|
||||
}
|
||||
auto *self = static_cast<CameraManager *>(data);
|
||||
auto* self = static_cast<CameraManager*>(data);
|
||||
auto it = self->camera_nodes_.find(id);
|
||||
if (it != self->camera_nodes_.end()) {
|
||||
std::cout << "[-] Camera removed: " << it->second << " (id: " << id << ")\n";
|
||||
std::cout << "[-] Camera removed: " << it->second << " (id: " << id
|
||||
<< ")\n";
|
||||
self->camera_nodes_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CameraManager::initialize() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
@@ -119,11 +119,12 @@ bool CameraManager::initialize() {
|
||||
}
|
||||
pw_registry_ = pw_core_get_registry(pw_core_, PW_VERSION_REGISTRY, 0);
|
||||
static pw_registry_events registry_events = {
|
||||
PW_VERSION_REGISTRY_EVENTS,
|
||||
.global = on_global,
|
||||
.global_remove = on_global_remove,
|
||||
};
|
||||
pw_registry_add_listener(pw_registry_, new spa_hook{}, ®istry_events, this);
|
||||
PW_VERSION_REGISTRY_EVENTS,
|
||||
.global = on_global,
|
||||
.global_remove = on_global_remove,
|
||||
};
|
||||
pw_registry_add_listener(pw_registry_, new spa_hook{}, ®istry_events,
|
||||
this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
//
|
||||
// Created by tcna on 3/24/25.
|
||||
//
|
||||
#include "CameraStream.h"
|
||||
#include <GLES2/gl2.h>
|
||||
#include <cstdio>
|
||||
#include <jpeglib.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <string/string_tools.h>
|
||||
#include <time/time_tools.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "tools/command.h"
|
||||
#include "CameraStream.h"
|
||||
#include "CameraManager.h"
|
||||
#include "tools/command.h"
|
||||
static constexpr char kPictureCaptureExtension[] = "jpeg";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -407,7 +407,8 @@ void CameraStream::OnStreamStateChanged(void* data,
|
||||
const char* error) {
|
||||
std::fprintf(stderr,
|
||||
"[CameraStream] stream state changed from %s to %s (%s)\n",
|
||||
StreamStateToString(old_state), StreamStateToString(new_state), (error ? error : "no error"));
|
||||
StreamStateToString(old_state), StreamStateToString(new_state),
|
||||
(error ? error : "no error"));
|
||||
}
|
||||
|
||||
void CameraStream::OnStreamProcess(void* data) {
|
||||
@@ -418,7 +419,7 @@ void CameraStream::OnStreamProcess(void* data) {
|
||||
}
|
||||
|
||||
void CameraStream::PauseStream() {
|
||||
if(!pw_stream_)
|
||||
if (!pw_stream_)
|
||||
return;
|
||||
|
||||
auto& mgr = CameraManager::instance();
|
||||
@@ -434,14 +435,12 @@ void CameraStream::PauseStream() {
|
||||
}
|
||||
|
||||
pw_thread_loop_lock(loop);
|
||||
{
|
||||
pw_stream_set_active(pw_stream_, false);
|
||||
}
|
||||
{ pw_stream_set_active(pw_stream_, false); }
|
||||
pw_thread_loop_unlock(loop);
|
||||
}
|
||||
|
||||
void CameraStream::ResumeStream() {
|
||||
if(!pw_stream_)
|
||||
if (!pw_stream_)
|
||||
return;
|
||||
|
||||
auto& mgr = CameraManager::instance();
|
||||
@@ -457,9 +456,7 @@ void CameraStream::ResumeStream() {
|
||||
}
|
||||
|
||||
pw_thread_loop_lock(loop);
|
||||
{
|
||||
pw_stream_set_active(pw_stream_, true);
|
||||
}
|
||||
{ pw_stream_set_active(pw_stream_, true); }
|
||||
pw_thread_loop_unlock(loop);
|
||||
}
|
||||
std::optional<std::string> CameraStream::GetFilePathForPicture() {
|
||||
@@ -472,19 +469,17 @@ std::optional<std::string> CameraStream::GetFilePathForPicture() {
|
||||
std::filesystem::path path(
|
||||
plugin_common::StringTools::trim(picture_path, "\n"));
|
||||
|
||||
path /= "PhotoCapture_" + plugin_common::TimeTools::GetCurrentTimeString() + "." +
|
||||
kPictureCaptureExtension;
|
||||
path /= "PhotoCapture_" + plugin_common::TimeTools::GetCurrentTimeString() +
|
||||
"." + kPictureCaptureExtension;
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string CameraStream::takePicture() {
|
||||
auto filename = GetFilePathForPicture();
|
||||
std::cout << "[CameraStream::takePicture()]: Running in thread ID: "<<std::this_thread::get_id()<<std::endl;
|
||||
save_image_to_jpeg(filename.value(),
|
||||
decoded_buffer_.get(), width_, height_, 3, 90);
|
||||
std::cout << "[CameraStream::takePicture()]: Running in thread ID: "
|
||||
<< std::this_thread::get_id() << std::endl;
|
||||
save_image_to_jpeg(filename.value(), decoded_buffer_.get(), width_, height_,
|
||||
3, 90);
|
||||
|
||||
return filename.value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#include <flutter/plugin_registrar_homescreen.h>
|
||||
#include <flutter/texture_registrar.h>
|
||||
#include <pipewire/pipewire.h> // forward-decl is risky; better to include full
|
||||
#include <spa/param/video/format-utils.h>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <flutter/plugin_registrar_homescreen.h>
|
||||
#include <flutter/texture_registrar.h>
|
||||
#include <pipewire/pipewire.h> // forward-decl is risky; better to include full
|
||||
#include <spa/param/video/format-utils.h>
|
||||
|
||||
/**
|
||||
* CameraStream manages a single PipeWire MJPEG camera stream and its Flutter
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <flutter/plugin_registrar_homescreen.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -31,9 +30,9 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "plugins/common/common.h"
|
||||
#include "camera_plugin.h"
|
||||
#include "CameraManager.h"
|
||||
#include "camera_plugin.h"
|
||||
#include "plugins/common/common.h"
|
||||
|
||||
extern "C" {
|
||||
#include <pipewire/pipewire.h>
|
||||
@@ -84,10 +83,10 @@ namespace camera_plugin {
|
||||
// TODO static constexpr char kResolutionPresetValueUltraHigh[] = "ultraHigh";
|
||||
// TODO static constexpr char kResolutionPresetValueMax[] = "max";
|
||||
|
||||
//static std::unique_ptr<libcamera::CameraManager> g_camera_manager;
|
||||
// static std::vector<std::shared_ptr<CameraContext>> g_cameras;
|
||||
// static std::unordered_map<unsigned int, std::shared_ptr<CameraSession>>
|
||||
// g_camera_sessions;
|
||||
// static std::unique_ptr<libcamera::CameraManager> g_camera_manager;
|
||||
// static std::vector<std::shared_ptr<CameraContext>> g_cameras;
|
||||
// static std::unordered_map<unsigned int, std::shared_ptr<CameraSession>>
|
||||
// g_camera_sessions;
|
||||
|
||||
// static
|
||||
void CameraPlugin::RegisterWithRegistrar(
|
||||
@@ -100,8 +99,7 @@ void CameraPlugin::RegisterWithRegistrar(
|
||||
|
||||
CameraPlugin::CameraPlugin(flutter::PluginRegistrarDesktop* plugin_registrar,
|
||||
flutter::BinaryMessenger* messenger)
|
||||
: registrar_(plugin_registrar),
|
||||
messenger_(messenger) {
|
||||
: registrar_(plugin_registrar), messenger_(messenger) {
|
||||
if (!CameraManager::instance().initialize()) {
|
||||
std::cerr << "Failed to initialize PipeWire manager!\n";
|
||||
}
|
||||
@@ -146,10 +144,10 @@ std::string CameraPlugin::get_camera_lens_facing(
|
||||
}
|
||||
*/
|
||||
ErrorOr<flutter::EncodableList> CameraPlugin::GetAvailableCameras() {
|
||||
flutter::EncodableList list;
|
||||
flutter::EncodableList list;
|
||||
auto& mgr = CameraManager::instance();
|
||||
auto cameras = mgr.getAvailableCameras();
|
||||
for(const auto& [id, name] : cameras) {
|
||||
for (const auto& [id, name] : cameras) {
|
||||
std::cout << "Detected camera: " << name << " (ID: " << id << ")\n";
|
||||
list.emplace_back(flutter::EncodableValue(std::move(std::to_string(id))));
|
||||
}
|
||||
@@ -342,29 +340,11 @@ std::optional<FlutterError> CameraPlugin::Dispose(const int64_t camera_id) {
|
||||
void CameraPlugin::TakePicture(
|
||||
const int64_t camera_id,
|
||||
const std::function<void(ErrorOr<std::string> reply)> result) {
|
||||
|
||||
SPDLOG_DEBUG("[camera_plugin] Take Picture: {}", camera_id);
|
||||
auto camera_stream = TextureId_CameraStream[camera_id];
|
||||
|
||||
//std::string str = "Take Picture ";
|
||||
// std::string str = "Take Picture ";
|
||||
result(camera_stream->takePicture());
|
||||
|
||||
//result(camera->takePicture());
|
||||
// const auto camera =
|
||||
// g_camera_sessions[static_cast<unsigned long>(camera_id - 1)];
|
||||
// const auto camera = g_camera_sessions[camera_id];
|
||||
// camera->pausePreview();
|
||||
/*
|
||||
SPDLOG_DEBUG("[camera_plugin] pause the camera: {}");
|
||||
|
||||
libcamera::StreamRole stream_roles = { libcamera::StreamRole::StillCapture
|
||||
};
|
||||
//std::unique_ptr<libcamera::CameraConfiguration> config =
|
||||
//camera->generateConfiguration(stream_roles);
|
||||
//camera->
|
||||
camera->resumePreview();
|
||||
*/
|
||||
// result(camera->takePicture());
|
||||
}
|
||||
|
||||
void CameraPlugin::StartVideoRecording(
|
||||
@@ -392,7 +372,6 @@ void CameraPlugin::StopVideoRecording(
|
||||
void CameraPlugin::PausePreview(
|
||||
const int64_t camera_id,
|
||||
const std::function<void(std::optional<FlutterError> reply)> result) {
|
||||
|
||||
SPDLOG_DEBUG("[camera_plugin] PausePreview");
|
||||
auto camera_stream = TextureId_CameraStream[camera_id];
|
||||
camera_stream->PauseStream();
|
||||
@@ -406,5 +385,5 @@ void CameraPlugin::ResumePreview(
|
||||
auto camera_stream = TextureId_CameraStream[camera_id];
|
||||
camera_stream->ResumeStream();
|
||||
result({});
|
||||
}
|
||||
}
|
||||
} // namespace camera_plugin
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
#include <pipewire/properties.h>
|
||||
#include <spa/param/param.h>
|
||||
#include <spa/param/video/format-utils.h>
|
||||
#include "plugins/common/common.h"
|
||||
#include "CameraStream.h"
|
||||
#include "event_channel.h"
|
||||
#include "messages.g.h"
|
||||
#include "CameraStream.h"
|
||||
#include "plugins/common/common.h"
|
||||
|
||||
namespace camera_plugin {
|
||||
|
||||
@@ -103,7 +103,7 @@ class CameraPlugin final : public flutter::Plugin, public CameraApi {
|
||||
pw_stream_state old_state,
|
||||
pw_stream_state new_state,
|
||||
const char* error);
|
||||
//void start_camera_stream(const std::string& nodeID);
|
||||
// void start_camera_stream(const std::string& nodeID);
|
||||
void handle_stream();
|
||||
|
||||
struct preview {
|
||||
|
||||
Reference in New Issue
Block a user