Mercurial > hg > orthanc
changeset 6846:8d118becf246 streaming
using DicomDataSource::MultipleReader in OrthancGetRequestHandler
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 22 May 2026 10:57:51 +0200 |
| parents | 4444d7994ba5 |
| children | 96731e8733c2 |
| files | OrthancFramework/Sources/DataSource/DicomDataSource.cpp OrthancFramework/Sources/DataSource/DicomDataSource.h OrthancServer/Sources/OrthancGetRequestHandler.cpp OrthancServer/Sources/OrthancGetRequestHandler.h OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h |
| diffstat | 6 files changed, 125 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Fri May 22 10:25:30 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Fri May 22 10:57:51 2026 +0200 @@ -199,7 +199,7 @@ } - const ParsedDicomFile& DicomDataSource::Dicom::Lock::GetContent() const + ParsedDicomFile& DicomDataSource::Dicom::Lock::GetContent() const { return dynamic_cast<const Value&>(*that_.value_).GetContent(); } @@ -232,4 +232,69 @@ boost::shared_ptr<IDynamicObject> value = reader.ReadSingle(id.release()); return new Dicom(value); } + + + class DicomDataSource::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) + { + if (request_.get() == NULL) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + request_->Enqueue(new WholeIdentifier(attachment)); + } + } + + Dicom* Dequeue() + { + if (answer_.get() == NULL) + { + assert(request_.get() != NULL); + answer_ = reader_->Submit(request_.release()); + } + + std::unique_ptr<DataSourceAnswer::Item> item(answer_->Dequeue()); + return new Dicom(item->GetValue()); + } + }; + + + DicomDataSource::MultipleReader::MultipleReader(const boost::shared_ptr<DataSourceReader>& reader) : + pimpl_(new PImpl(reader)) + { + } + + + DicomDataSource::MultipleReader::~MultipleReader() + { + assert(pimpl_ != NULL); + delete pimpl_; + } + + + void DicomDataSource::MultipleReader::Enqueue(const FileInfo& attachment) + { + pimpl_->Enqueue(attachment); + } + + + DicomDataSource::Dicom* DicomDataSource::MultipleReader::Dequeue() + { + return pimpl_->Dequeue(); + } }
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.h Fri May 22 10:25:30 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.h Fri May 22 10:57:51 2026 +0200 @@ -92,7 +92,7 @@ { } - const ParsedDicomFile& GetContent() const; + ParsedDicomFile& GetContent() const; }; }; @@ -102,5 +102,21 @@ static Dicom* ReadUntilPixelData(DataSourceReader& reader, const FileInfo& attachment, uint64_t pixelDataOffset); + + class MultipleReader : public boost::noncopyable + { + private: + class PImpl; + PImpl* pimpl_; + + public: + MultipleReader(const boost::shared_ptr<DataSourceReader>& reader); + + ~MultipleReader(); + + void Enqueue(const FileInfo& item); + + Dicom* Dequeue(); + }; }; }
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp Fri May 22 10:25:30 2026 +0200 +++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp Fri May 22 10:57:51 2026 +0200 @@ -70,32 +70,35 @@ throw OrthancException(ErrorCode_BadSequenceOfCalls); } - std::unique_ptr<StorageAreaDataSource::MultipleReader::Item> item(instancesLoader_->Dequeue()); - - std::unique_ptr<DcmFileFormat> parsed( - FromDcmtkBridge::LoadFromMemoryBuffer(item->GetData(), item->GetSize())); + { + std::unique_ptr<DicomDataSource::Dicom> item(instancesLoader_->Dequeue()); - if (parsed.get() == NULL || - parsed->getDataset() == NULL) - { - throw OrthancException(ErrorCode_InternalError); - } + if (item == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } - DcmDataset& dataset = *parsed->getDataset(); + DicomDataSource::Dicom::Lock lock(*item); + + if (lock.GetContent().GetDcmtkObject().getDataset() == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } - OFString a, b; - if (!dataset.findAndGetOFString(DCM_SOPClassUID, a).good() || - !dataset.findAndGetOFString(DCM_SOPInstanceUID, b).good()) - { - throw OrthancException(ErrorCode_NoSopClassOrInstance, - "Unable to determine the SOP class/instance for C-STORE with AET " + - originatorAet_); + OFString a, b; + if (!lock.GetContent().GetDcmtkObject().getDataset()->findAndGetOFString(DCM_SOPClassUID, a).good() || + !lock.GetContent().GetDcmtkObject().getDataset()->findAndGetOFString(DCM_SOPInstanceUID, b).good()) + { + throw OrthancException(ErrorCode_NoSopClassOrInstance, + "Unable to determine the SOP class/instance for C-STORE with AET " + + originatorAet_); + } + + std::string sopClassUid(a.c_str()); + std::string sopInstanceUid(b.c_str()); + + return PerformGetSubOp(assoc, sopClassUid, sopInstanceUid, lock.GetContent().GetDcmtkObject()); } - - std::string sopClassUid(a.c_str()); - std::string sopInstanceUid(b.c_str()); - - return PerformGetSubOp(assoc, sopClassUid, sopInstanceUid, parsed.release()); } @@ -225,13 +228,10 @@ bool OrthancGetRequestHandler::PerformGetSubOp(T_ASC_Association* assoc, const std::string& sopClassUid, const std::string& sopInstanceUid, - DcmFileFormat* dicomRaw) + DcmFileFormat& dicom) { - assert(dicomRaw != NULL); - std::unique_ptr<DcmFileFormat> dicom(dicomRaw); - DicomTransferSyntax sourceSyntax; - if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, *dicom)) + if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom)) { failedCount_++; AddFailedUIDInstance(sopInstanceUid); @@ -308,7 +308,7 @@ // No transcoding is required DcmDataset *stDetailTmp = NULL; cond = DIMSE_storeUser( - assoc, presId, &req, NULL /* imageFileName */, dicom->getDataset(), + assoc, presId, &req, NULL /* imageFileName */, dicom.getDataset(), ProgressCallback, NULL /* callbackData */, (timeout_ > 0 ? DIMSE_NONBLOCKING : DIMSE_BLOCKING), static_cast<int>(timeout_), &rsp, &stDetailTmp, &cancelParameters); @@ -318,7 +318,7 @@ { // Transcoding to the selected uncompressed transfer syntax IDicomTranscoder::DicomImage source, transcoded; - source.AcquireParsed(dicom.release()); + source.AcquireParsed(new DcmFileFormat(dicom)); // TODO-Streaming : Trancode upfront std::set<DicomTransferSyntax> ts; ts.insert(selectedSyntax); @@ -567,7 +567,7 @@ } } - instancesLoader_.reset(context_.CreateMultipleStorageAreaReader()); + instancesLoader_.reset(context_.CreateMultipleDicomReader()); std::vector<FileInfo> filesInfo; @@ -584,7 +584,7 @@ for (size_t i = 0; i < instancesIds_.size(); ++i) { - instancesLoader_->Enqueue(filesInfo[i], true /* uncompress */); + instancesLoader_->Enqueue(filesInfo[i]); } failedUIDs_.clear();
--- a/OrthancServer/Sources/OrthancGetRequestHandler.h Fri May 22 10:25:30 2026 +0200 +++ b/OrthancServer/Sources/OrthancGetRequestHandler.h Fri May 22 10:57:51 2026 +0200 @@ -23,7 +23,7 @@ #pragma once #include "../../OrthancFramework/Sources/Compatibility.h" // For ORTHANC_OVERRIDE -#include "../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h" +#include "../../OrthancFramework/Sources/DataSource/DicomDataSource.h" #include "../../OrthancFramework/Sources/DicomNetworking/IGetRequestHandler.h" #include "../../OrthancFramework/Sources/DicomNetworking/RemoteModalityParameters.h" @@ -45,7 +45,7 @@ std::vector<std::string> instancesIds_; size_t position_; std::string originatorAet_; - std::unique_ptr<StorageAreaDataSource::MultipleReader> instancesLoader_; // TODO-Streaming : Should be DICOM + std::unique_ptr<DicomDataSource::MultipleReader> instancesLoader_; unsigned int completedCount_; unsigned int warningCount_; @@ -63,7 +63,7 @@ bool PerformGetSubOp(T_ASC_Association *assoc, const std::string& sopClassUid, const std::string& sopInstanceUid, - DcmFileFormat* datasetRaw); + DcmFileFormat& dicom); void AddFailedUIDInstance(const std::string& sopInstance);
--- a/OrthancServer/Sources/ServerContext.cpp Fri May 22 10:25:30 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Fri May 22 10:57:51 2026 +0200 @@ -2142,4 +2142,10 @@ { return new StorageAreaDataSource::MultipleReader(storageAreaReader_); } + + + DicomDataSource::MultipleReader* ServerContext::CreateMultipleDicomReader() const + { + return new DicomDataSource::MultipleReader(dicomReader_); + } }
--- a/OrthancServer/Sources/ServerContext.h Fri May 22 10:25:30 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.h Fri May 22 10:57:51 2026 +0200 @@ -591,5 +591,7 @@ Future* SubmitTranscodingRequest(TranscodingCallable* callable); StorageAreaDataSource::MultipleReader* CreateMultipleStorageAreaReader() const; + + DicomDataSource::MultipleReader* CreateMultipleDicomReader() const; }; }
