Mercurial > hg > orthanc
changeset 6845:4444d7994ba5 streaming
using data sources in OrthancGetRequestHandler
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 22 May 2026 10:25:30 +0200 |
| parents | dbebcd49317c |
| children | 8d118becf246 |
| files | OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp OrthancFramework/Sources/DataSource/StorageAreaDataSource.h OrthancServer/Sources/OrthancGetRequestHandler.cpp OrthancServer/Sources/OrthancGetRequestHandler.h OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h |
| diffstat | 6 files changed, 165 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Fri May 22 09:34:01 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.cpp Fri May 22 10:25:30 2026 +0200 @@ -154,6 +154,18 @@ } } + const IPostProcessing& GetPostProcessing() const + { + if (postProcessing_.get() == NULL) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + return *postProcessing_; + } + } + boost::shared_ptr<IDynamicObject> ApplyPostProcessing(const boost::shared_ptr<IDynamicObject>& value) const { if (value.get() == NULL) @@ -194,6 +206,11 @@ } } + const FileInfo& GetAttachment() const + { + return attachment_; + } + virtual boost::shared_ptr<IDynamicObject> Apply(const boost::shared_ptr<IDynamicObject>& obj) const ORTHANC_OVERRIDE { if (obj.get() == NULL) @@ -424,4 +441,92 @@ } } } + + + class StorageAreaDataSource::MultipleReader::PImpl : public boost::noncopyable + { + private: + boost::shared_ptr<DataSourceReader> reader_; + std::unique_ptr<DataSourceRequest> request_; + boost::shared_ptr<DataSourceAnswer> answer_; + + public: + PImpl(const boost::shared_ptr<DataSourceReader>& reader) : + reader_(reader), + request_(new DataSourceRequest) + { + } + + void Enqueue(const FileInfo& attachment, + bool uncompress) + { + if (request_.get() == NULL) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + std::unique_ptr<Identifier> id(new Identifier(attachment.GetUuid(), + attachment.GetContentType(), + 0, attachment.GetCompressedSize(), + attachment.GetCustomData())); + id->SetPostProcessing(new AttachmentPostProcessing(attachment, uncompress)); + + request_->Enqueue(id.release()); + } + } + + Item* Dequeue() + { + if (answer_.get() == NULL) + { + assert(request_.get() != NULL); + answer_ = reader_->Submit(request_.release()); + } + + std::unique_ptr<DataSourceAnswer::Item> item(answer_->Dequeue()); + + std::unique_ptr<StorageAreaDataSource::Range> range(new Range(item->GetValue())); + + const Identifier& id = dynamic_cast<const Identifier&>(item->GetId()); + range.reset(range->ApplyPostProcessing(id)); + + const AttachmentPostProcessing& postProcessing = dynamic_cast<const AttachmentPostProcessing&>(id.GetPostProcessing()); + return new Item(range.release(), postProcessing.GetAttachment()); + } + }; + + + StorageAreaDataSource::MultipleReader::Item::Item(Range* range, + const FileInfo& attachment) : + range_(range), + attachment_(attachment) + { + } + + + StorageAreaDataSource::MultipleReader::MultipleReader(const boost::shared_ptr<DataSourceReader>& reader) : + pimpl_(new PImpl(reader)) + { + } + + + StorageAreaDataSource::MultipleReader::~MultipleReader() + { + assert(pimpl_ != NULL); + delete pimpl_; + } + + + void StorageAreaDataSource::MultipleReader::Enqueue(const FileInfo& attachment, + bool uncompress) + { + pimpl_->Enqueue(attachment, uncompress); + } + + + StorageAreaDataSource::MultipleReader::Item* StorageAreaDataSource::MultipleReader::Dequeue() + { + return pimpl_->Dequeue(); + } }
--- a/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Fri May 22 09:34:01 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/StorageAreaDataSource.h Fri May 22 10:25:30 2026 +0200 @@ -105,5 +105,48 @@ const FileInfo& attachment, const StorageRange& range, bool uncompress); + + class MultipleReader : public boost::noncopyable + { + private: + class PImpl; + PImpl* pimpl_; + + public: + class Item : public boost::noncopyable + { + private: + std::unique_ptr<Range> range_; + FileInfo attachment_; + + public: + Item(Range* range, + const FileInfo& attachment); + + const void* GetData() const + { + return range_->GetData(); + } + + size_t GetSize() const + { + return range_->GetSize(); + } + + const FileInfo& GetAttachment() const + { + return attachment_; + } + }; + + MultipleReader(const boost::shared_ptr<DataSourceReader>& reader); + + ~MultipleReader(); + + void Enqueue(const FileInfo& item, + bool uncompress); + + Item* Dequeue(); + }; }; }
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp Fri May 22 09:34:01 2026 +0200 +++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp Fri May 22 10:25:30 2026 +0200 @@ -30,7 +30,6 @@ #include "OrthancConfiguration.h" #include "ServerContext.h" #include "ServerJobs/DicomModalityStoreJob.h" -#include "ServerJobs/ThreadedInstancesLoader.h" #include "ServerTranscoder.h" #include <dcmtk/dcmdata/dcdeftag.h> @@ -71,18 +70,10 @@ throw OrthancException(ErrorCode_BadSequenceOfCalls); } - const std::string& id = instancesIds_[position_++]; - - std::string dicom; - instancesLoader_->WaitDicomInstance(dicom, id); - - if (dicom.empty()) - { - throw OrthancException(ErrorCode_BadFileFormat); - } + std::unique_ptr<StorageAreaDataSource::MultipleReader::Item> item(instancesLoader_->Dequeue()); std::unique_ptr<DcmFileFormat> parsed( - FromDcmtkBridge::LoadFromMemoryBuffer(dicom.c_str(), dicom.size())); + FromDcmtkBridge::LoadFromMemoryBuffer(item->GetData(), item->GetSize())); if (parsed.get() == NULL || parsed->getDataset() == NULL) @@ -551,7 +542,6 @@ localAet_ = context_.GetDefaultLocalApplicationEntityTitle(); position_ = 0; originatorAet_ = originatorAet; - unsigned int loaderThreads = 1; { OrthancConfiguration::ReaderLock lock; @@ -575,11 +565,10 @@ throw OrthancException(ErrorCode_InexistentItem, "C-GET: Rejecting SCU request from unknown modality with AET: " + originatorAet); } - - loaderThreads = lock.GetConfiguration().GetLoaderThreads(); } - instancesLoader_.reset(new ThreadedInstancesLoader(context_, loaderThreads, false, DicomTransferSyntax_BigEndianExplicit /* dummy unused value */, 0, "CGET")); + instancesLoader_.reset(context_.CreateMultipleStorageAreaReader()); + std::vector<FileInfo> filesInfo; for (std::list<std::string>::const_iterator @@ -591,9 +580,11 @@ context_.GetOrderedChildInstances(instancesIds_, filesInfo, *resourceId, level); } + // TODO-Streaming : Should instances be ordered? + for (size_t i = 0; i < instancesIds_.size(); ++i) { - instancesLoader_->PreloadDicomInstance(instancesIds_[i], filesInfo[i]); + instancesLoader_->Enqueue(filesInfo[i], true /* uncompress */); } failedUIDs_.clear();
--- a/OrthancServer/Sources/OrthancGetRequestHandler.h Fri May 22 09:34:01 2026 +0200 +++ b/OrthancServer/Sources/OrthancGetRequestHandler.h Fri May 22 10:25:30 2026 +0200 @@ -23,6 +23,7 @@ #pragma once #include "../../OrthancFramework/Sources/Compatibility.h" // For ORTHANC_OVERRIDE +#include "../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h" #include "../../OrthancFramework/Sources/DicomNetworking/IGetRequestHandler.h" #include "../../OrthancFramework/Sources/DicomNetworking/RemoteModalityParameters.h" @@ -35,7 +36,6 @@ namespace Orthanc { class ServerContext; - class ThreadedInstancesLoader; class OrthancGetRequestHandler : public IGetRequestHandler { @@ -45,7 +45,7 @@ std::vector<std::string> instancesIds_; size_t position_; std::string originatorAet_; - std::unique_ptr<ThreadedInstancesLoader> instancesLoader_; + std::unique_ptr<StorageAreaDataSource::MultipleReader> instancesLoader_; // TODO-Streaming : Should be DICOM unsigned int completedCount_; unsigned int warningCount_;
--- a/OrthancServer/Sources/ServerContext.cpp Fri May 22 09:34:01 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Fri May 22 10:25:30 2026 +0200 @@ -2136,4 +2136,10 @@ return transcoderThreadPool_->Submit(callable); } + + + StorageAreaDataSource::MultipleReader* ServerContext::CreateMultipleStorageAreaReader() const + { + return new StorageAreaDataSource::MultipleReader(storageAreaReader_); + } }
--- a/OrthancServer/Sources/ServerContext.h Fri May 22 09:34:01 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.h Fri May 22 10:25:30 2026 +0200 @@ -589,5 +589,7 @@ const boost::shared_ptr<ServerTranscoder>& GetTranscoder() const; Future* SubmitTranscodingRequest(TranscodingCallable* callable); + + StorageAreaDataSource::MultipleReader* CreateMultipleStorageAreaReader() const; }; }
