diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/pipeline_handler.cpp | 57 | ||||
-rw-r--r-- | src/libcamera/yaml_emitter.cpp | 176 |
2 files changed, 178 insertions, 55 deletions
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 */ |