summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libcamera/internal/yaml_emitter.h98
-rw-r--r--src/libcamera/pipeline_handler.cpp57
-rw-r--r--src/libcamera/yaml_emitter.cpp176
3 files changed, 273 insertions, 58 deletions
diff --git a/include/libcamera/internal/yaml_emitter.h b/include/libcamera/internal/yaml_emitter.h
index f8df5265..14ea8241 100644
--- a/include/libcamera/internal/yaml_emitter.h
+++ b/include/libcamera/internal/yaml_emitter.h
@@ -9,7 +9,9 @@
#include <map>
#include <memory>
+#include <stack>
#include <string>
+#include <string_view>
#include <libcamera/base/class.h>
#include <libcamera/base/file.h>
@@ -21,15 +23,105 @@ namespace libcamera {
class File;
class YamlEvent;
+class YamlEmitter;
+class YamlDict;
+class YamlList;
+
+class YamlOutput
+{
+protected:
+ enum class YamlType {
+ Root,
+ Scalar,
+ Dict,
+ List,
+ };
+
+public:
+ virtual ~YamlOutput() {}
+ virtual void close() {}
+
+ std::unique_ptr<YamlDict> dict();
+ std::unique_ptr<YamlList> list();
+
+ YamlType type() { return type_; }
+
+protected:
+ YamlOutput(YamlEmitter *emitter, YamlType type)
+ : emitter_(emitter), type_(type)
+ {
+ }
+
+ int emitScalar(std::string_view scalar);
+ int emitMappingStart();
+ int emitMappingEnd();
+ int emitSequenceStart();
+ int emitSequenceEnd();
+
+ YamlEmitter *emitter_;
+ YamlType type_;
+};
+
+class YamlRoot : public YamlOutput
+{
+public:
+ ~YamlRoot() {}
+
+ std::unique_ptr<YamlList> list();
+ std::unique_ptr<YamlDict> dict();
+ void scalar(std::string_view scalar);
+
+private:
+ friend class YamlEmitter;
+
+ YamlRoot(YamlEmitter *emitter)
+ : YamlOutput(emitter, YamlType::Root)
+ {
+ emitterRoot_ = std::unique_ptr<YamlEmitter>(emitter);
+ }
+
+ std::unique_ptr<YamlEmitter> emitterRoot_;
+};
+
+class YamlList : public YamlOutput
+{
+public:
+ ~YamlList();
+
+ std::unique_ptr<YamlList> list();
+ std::unique_ptr<YamlDict> dict();
+ void scalar(std::string_view scalar);
+
+private:
+ friend class YamlOutput;
+
+ YamlList(YamlEmitter *emitter);
+};
+
+
+class YamlDict : public YamlOutput
+{
+public:
+ ~YamlDict();
+
+ void scalar(std::string_view key, std::string_view value);
+ std::unique_ptr<YamlList> list(std::string_view key);
+ std::unique_ptr<YamlDict> dict(std::string_view key);
+
+private:
+ friend class YamlOutput;
+
+ YamlDict(YamlEmitter *emitter);
+};
+
class YamlEmitter final
{
public:
~YamlEmitter();
- static std::unique_ptr<YamlEmitter> create(std::string &path);
+ static std::unique_ptr<YamlRoot> root(std::string &path);
- int emit(std::map<std::string, std::string>);
- int emit(const std::string &scalar);
+ int emit(YamlEvent *event);
private:
LIBCAMERA_DISABLE_COPY(YamlEmitter);
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index 5fd55edb..7e1c4f3f 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -788,40 +788,51 @@ void PipelineHandler::disconnect()
* \return The CameraManager for this pipeline handler
*/
-void PipelineHandler::dumpConfiguration(const std::set<const Stream *> &streams,
- const Orientation &orientation)
+void PipelineHandler::dumpConfiguration([[maybe_unused]] const std::set<const Stream *> &streams,
+ [[maybe_unused]] const Orientation &orientation)
{
std::string path("/tmp/yaml_emitter.yaml");
- auto emitter = YamlEmitter::create(path);
- std::map<std::string, std::string> map = { { "cane", "gatto" }, };
- emitter->emit(map);
+ auto root = YamlEmitter::root(path);
- if (!dumpCaptureScript_)
- return;
-
- std::stringstream ss;
- ss << "configuration:" << std::endl;
- ss << " orientation: " << orientation << std::endl;
+ auto rootDict = root->dict();
+ auto config = rootDict->dict("configuration");
+ config->scalar("orientation", "front");
- /* TODO Dump Sensor configuration */
+ auto yamlStreams = config->list("streams");
- ss << " streams:" << std::endl;
for (const auto &stream : streams) {
const StreamConfiguration &streamConfig = stream->configuration();
- ss << " - pixelFormat: " << streamConfig.pixelFormat << std::endl;
- ss << " size: " << streamConfig.size << std::endl;
- ss << " stride: " << streamConfig.stride << std::endl;
- ss << " frameSize: " << streamConfig.frameSize << std::endl;
- ss << " bufferCount: " << streamConfig.bufferCount << std::endl;
+ auto yamlStream = yamlStreams->dict();
+
+ yamlStream->scalar("pixelformat", "YUYV");
+ yamlStream->scalar("size", "1920x1080");
+
if (streamConfig.colorSpace)
- ss << " colorSpace: " << streamConfig.colorSpace->toString() << std::endl;
+ LOG(Error);
}
- dumpCaptureScript_->write(ss.str().c_str(), ss.str().size());
+#if 0
+ auto yamlStreams = std::unique_ptr<YamlList>(config->list("streams"));
- std::string str = "frames:\n";
- dumpCaptureScript_->write(str.c_str(), str.size());
- dumpCaptureScript_->flush();
+ /* TODO Dump Sensor configuration */
+
+ for (const auto &stream : streams) {
+ const StreamConfiguration &streamConfig = stream->configuration();
+ auto yamlStream = std::unique_ptr<YamlDict>(yamlStreams->dict(""));
+
+ yamlStream->append("pixelformat", "YUYV");
+ yamlStream->append("size", "1920x1080");
+
+ //ss << " - pixelFormat: " << streamConfig.pixelFormat << std::endl;
+ //ss << " size: " << streamConfig.size << std::endl;
+ //ss << " stride: " << streamConfig.stride << std::endl;
+ //ss << " frameSize: " << streamConfig.frameSize << std::endl;
+ //ss << " bufferCount: " << streamConfig.bufferCount << std::endl;
+ if (streamConfig.colorSpace)
+ LOG(Error);
+ // ss << " colorSpace: " << streamConfig.colorSpace->toString() << std::endl;
+ }
+#endif
}
void PipelineHandler::dumpRequest(Request *request, DumpMode mode)
diff --git a/src/libcamera/yaml_emitter.cpp b/src/libcamera/yaml_emitter.cpp
index 5683d1d4..0da0fe68 100644
--- a/src/libcamera/yaml_emitter.cpp
+++ b/src/libcamera/yaml_emitter.cpp
@@ -68,6 +68,141 @@ std::unique_ptr<YamlEvent> YamlEvent::create()
return std::unique_ptr<YamlEvent>(new YamlEvent(), Deleter());
}
+std::unique_ptr<YamlDict> YamlOutput::dict()
+{
+ return std::unique_ptr<YamlDict>(new YamlDict(emitter_));
+}
+
+std::unique_ptr<YamlList> YamlOutput::list()
+{
+ return std::unique_ptr<YamlList>(new YamlList(emitter_));
+}
+
+int YamlOutput::emitScalar(std::string_view scalar)
+{
+ LOG(Error) << "SCALAR: " << scalar;
+
+ std::unique_ptr<YamlEvent> event = YamlEvent::create();
+
+ const unsigned char *value = reinterpret_cast<const unsigned char *>
+ (scalar.data());
+ yaml_scalar_event_initialize(event->event(), NULL, NULL, value,
+ scalar.length(), true, false,
+ YAML_PLAIN_SCALAR_STYLE);
+ return emitter_->emit(event.get());
+}
+
+int YamlOutput::emitMappingStart()
+{
+ LOG(Error) << "MAP START";
+ std::unique_ptr<YamlEvent> event = YamlEvent::create();
+ yaml_mapping_start_event_initialize(event->event(), NULL, NULL,
+ true, YAML_BLOCK_MAPPING_STYLE);
+ return emitter_->emit(event.get());
+}
+
+int YamlOutput::emitMappingEnd()
+{
+ LOG(Error) << "MAP END";
+ std::unique_ptr<YamlEvent> event = YamlEvent::create();
+ yaml_mapping_end_event_initialize(event->event());
+ return emitter_->emit(event.get());
+}
+
+int YamlOutput::emitSequenceStart()
+{
+ LOG(Error) << "LIST START";
+ std::unique_ptr<YamlEvent> event = YamlEvent::create();
+ yaml_sequence_start_event_initialize(event->event(), NULL, NULL, true,
+ YAML_BLOCK_SEQUENCE_STYLE);
+ return emitter_->emit(event.get());
+}
+
+int YamlOutput::emitSequenceEnd()
+{
+ LOG(Error) << "LIST END";
+ std::unique_ptr<YamlEvent> event = YamlEvent::create();
+ yaml_sequence_end_event_initialize(event->event());
+ return emitter_->emit(event.get());
+}
+
+std::unique_ptr<YamlDict> YamlRoot::dict()
+{
+ emitMappingStart();
+
+ return YamlOutput::dict();
+}
+
+std::unique_ptr<YamlList> YamlRoot::list()
+{
+ emitSequenceStart();
+
+ return YamlOutput::list();
+
+}
+
+YamlList::YamlList(YamlEmitter *emitter)
+ : YamlOutput(emitter, YamlType::List)
+{
+}
+
+YamlList::~YamlList()
+{
+ emitSequenceEnd();
+}
+
+void YamlList::scalar(std::string_view scalar)
+{
+ emitScalar(scalar);
+}
+
+std::unique_ptr<YamlList> YamlList::list()
+{
+ emitSequenceStart();
+
+ return YamlOutput::list();
+}
+
+std::unique_ptr<YamlDict> YamlList::dict()
+{
+ emitMappingStart();
+
+ return YamlOutput::dict();
+}
+
+YamlDict::YamlDict(YamlEmitter *emitter)
+ : YamlOutput(emitter, YamlType::Dict)
+{
+}
+
+YamlDict::~YamlDict()
+{
+ LOG(Error) << "~Dict";
+ emitMappingEnd();
+}
+
+void YamlDict::scalar(std::string_view key, std::string_view value)
+{
+ emitScalar(key);
+ emitScalar(value);
+}
+
+std::unique_ptr<YamlList> YamlDict::list(std::string_view key)
+{
+ emitScalar(key);
+ emitSequenceStart();
+
+ return YamlOutput::list();
+}
+
+std::unique_ptr<YamlDict> YamlDict::dict(std::string_view key)
+{
+ emitScalar(key);
+ emitMappingStart();
+
+ return YamlOutput::dict();
+}
+
YamlEmitter::Emitter::~Emitter()
{
yaml_emitter_delete(&emitter_);
@@ -118,9 +253,11 @@ YamlEmitter::~YamlEmitter()
{
std::unique_ptr<YamlEvent> event = YamlEvent::create();
+ LOG(Error) << "DOC END";
yaml_document_end_event_initialize(event->event(), 0);
emitter_.emit(event.get());
+ LOG(Error) << "STREAM END";
yaml_stream_end_event_initialize(event->event());
emitter_.emit(event.get());
}
@@ -131,15 +268,17 @@ void YamlEmitter::init()
std::unique_ptr<YamlEvent> event = YamlEvent::create();
+ LOG(Error) << "STREAM START";
yaml_stream_start_event_initialize(event->event(), YAML_UTF8_ENCODING);
emitter_.emit(event.get());
+ LOG(Error) << "DOC START";
yaml_document_start_event_initialize(event->event(), NULL, NULL,
NULL, 0);
emitter_.emit(event.get());
}
-std::unique_ptr<YamlEmitter> YamlEmitter::create(std::string &path)
+std::unique_ptr<YamlRoot> YamlEmitter::root(std::string &path)
{
YamlEmitter *emitter = new YamlEmitter();
@@ -148,40 +287,13 @@ std::unique_ptr<YamlEmitter> YamlEmitter::create(std::string &path)
emitter->init();
- return std::unique_ptr<YamlEmitter>(emitter);
+ YamlRoot *root = new YamlRoot(emitter);
+ return std::unique_ptr<YamlRoot>(root);
}
-int YamlEmitter::emit(std::map<std::string, std::string> map)
+int YamlEmitter::emit(YamlEvent *event)
{
- std::unique_ptr<YamlEvent> event = YamlEvent::create();
-
- auto iter = map.begin();
-
- yaml_mapping_start_event_initialize(event->event(), NULL, NULL,
- true, YAML_BLOCK_MAPPING_STYLE);
- emitter_.emit(event.get());
-
- emit(iter->first);
- emit(iter->second);
-
- yaml_mapping_end_event_initialize(event->event());
- emitter_.emit(event.get());
-
- return 0;
-}
-
-int YamlEmitter::emit(const std::string &scalar)
-{
- const unsigned char *value = reinterpret_cast<const unsigned char *>
- (scalar.c_str());
- std::unique_ptr<YamlEvent> event = YamlEvent::create();
-
- yaml_scalar_event_initialize(event->event(), NULL, NULL, value,
- scalar.length(), true, false,
- YAML_PLAIN_SCALAR_STYLE);
- emitter_.emit(event.get());
-
- return 0;
+ return emitter_.emit(event);
}
} /* namespace libcamera */