Mercurial > hg > orthanc
changeset 6812:d689c2f52405 streaming
created TranscodingCallable
line wrap: on
line diff
--- a/OrthancFramework/Resources/CMake/OrthancFrameworkConfiguration.cmake Tue May 19 15:14:48 2026 +0200 +++ b/OrthancFramework/Resources/CMake/OrthancFrameworkConfiguration.cmake Tue May 19 16:55:23 2026 +0200 @@ -681,6 +681,7 @@ if (ENABLE_DCMTK) list(APPEND ORTHANC_CORE_SOURCES_INTERNAL ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DataSource/DicomDataSource.cpp + ${CMAKE_CURRENT_LIST_DIR}/../../Sources/DicomParsing/TranscodingCallable.cpp ) endif()
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.cpp Tue May 19 16:55:23 2026 +0200 @@ -286,7 +286,14 @@ } - ParsedDicomFile& DicomDataSource::Dicom::Lock::GetContent() const + ParsedDicomFile* DicomDataSource::Dicom::Clone() + { + Lock lock(*this); + return lock.GetContent().Clone(true); + } + + + const ParsedDicomFile& DicomDataSource::Dicom::Lock::GetContent() const { return dynamic_cast<const Value&>(*that_.value_).GetContent(); }
--- a/OrthancFramework/Sources/DataSource/DicomDataSource.h Tue May 19 15:14:48 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DicomDataSource.h Tue May 19 16:55:23 2026 +0200 @@ -72,6 +72,8 @@ public: explicit Dicom(const boost::shared_ptr<IDynamicObject>& value); + ParsedDicomFile* Clone(); + /** * Access to the DICOM value must be protected by a mutex, as it * could be shared by multiple threads if caching is enabled in @@ -90,7 +92,7 @@ { } - ParsedDicomFile& GetContent() const; + const ParsedDicomFile& GetContent() const; bool HasRawBuffer() const;
--- a/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h Tue May 19 15:14:48 2026 +0200 +++ b/OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h Tue May 19 16:55:23 2026 +0200 @@ -24,8 +24,13 @@ #pragma once +#if ORTHANC_ENABLE_DCMTK != 1 +# error The macro ORTHANC_ENABLE_DCMTK must be set to 1 +#endif + #include "../Compatibility.h" #include "../Enumerations.h" +#include "../IDynamicObject.h" #include <boost/noncopyable.hpp> #include <set> @@ -43,7 +48,7 @@ class ORTHANC_PUBLIC IDicomTranscoder : public boost::noncopyable { public: - class ORTHANC_PUBLIC DicomImage : public boost::noncopyable + class ORTHANC_PUBLIC DicomImage : public IDynamicObject { private: std::unique_ptr<DcmFileFormat> parsed_;
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Tue May 19 16:55:23 2026 +0200 @@ -6081,7 +6081,7 @@ { PImpl::ServerContextReference lock(*pimpl_); - success = lock.GetContext().GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew); + success = lock.GetContext().GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew); } if (success)
--- a/OrthancServer/Sources/OrthancGetRequestHandler.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/OrthancGetRequestHandler.cpp Tue May 19 16:55:23 2026 +0200 @@ -331,7 +331,7 @@ std::set<DicomTransferSyntax> ts; ts.insert(selectedSyntax); - if (context_.GetTranscoder().Transcode(transcoded, source, ts, TranscodingSopInstanceUidMode_AllowNew)) + if (context_.GetTranscoder()->Transcode(transcoded, source, ts, TranscodingSopInstanceUidMode_AllowNew)) { // Transcoding has succeeded DcmDataset *stDetailTmp = NULL;
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue May 19 16:55:23 2026 +0200 @@ -25,6 +25,7 @@ #include "OrthancRestApi.h" #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" +#include "../../../OrthancFramework/Sources/DicomParsing/TranscodingCallable.h" #include "../../../OrthancFramework/Sources/Logging.h" #include "../../../OrthancFramework/Sources/SerializationToolbox.h" #include "../DicomInstanceToStore.h" @@ -37,6 +38,7 @@ #include <boost/lexical_cast.hpp> #include <boost/algorithm/string/predicate.hpp> + #define INFO_SUBSEQUENCES \ "Starting with Orthanc 1.9.4, paths to subsequences can be provided using the "\ "same syntax as the `dcmodify` command-line tool (wildcards are supported as well)." @@ -217,33 +219,24 @@ std::unique_ptr<ParsedDicomFile> modified; { - ServerContext::DicomCacheLocker locker(context, id); - modified.reset(locker.GetDicom().Clone(true)); + std::unique_ptr<DicomDataSource::Dicom> dicom(context.ReadParsedDicom(id, false)); + modified.reset(dicom->Clone()); } modification.Apply(modified); if (transcode) { - IDicomTranscoder::DicomImage source; - source.AcquireParsed(*modified); // "modified" is invalid below this point - - IDicomTranscoder::DicomImage transcoded; + std::unique_ptr<TranscodingCallable> callable(new TranscodingCallable); + callable->AcquireParsed(*modified); // "modified" is invalid below this point + callable->AddTransferSyntax(targetSyntax); + callable->SetLossyQuality(lossyQuality); - std::set<DicomTransferSyntax> s; - s.insert(targetSyntax); - - if (context.GetTranscoder().Transcode(transcoded, source, s, TranscodingSopInstanceUidMode_AllowNew, lossyQuality)) - { - call.GetOutput().AnswerBuffer(transcoded.GetBufferData(), - transcoded.GetBufferSize(), MimeType_Dicom); - } - else - { - throw OrthancException(ErrorCode_InternalError, - "Cannot transcode to transfer syntax: " + - std::string(GetTransferSyntaxUid(targetSyntax))); - } + std::unique_ptr<Future> future(context.SubmitTranscodingRequest(callable.release())); + + std::unique_ptr<IDicomTranscoder::DicomImage> transcoded(dynamic_cast<IDicomTranscoder::DicomImage*>(future->ReleaseResult())); + call.GetOutput().AnswerBuffer(transcoded->GetBufferData(), + transcoded->GetBufferSize(), MimeType_Dicom); } else {
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp Tue May 19 16:55:23 2026 +0200 @@ -432,7 +432,7 @@ std::set<DicomTransferSyntax> allowedSyntaxes; allowedSyntaxes.insert(GetTransferSyntax(call.GetArgument(GET_TRANSCODE, ""))); - if (context.GetTranscoder().Transcode(targetImage, sourceImage, allowedSyntaxes, TranscodingSopInstanceUidMode_AllowNew, lossyQuality)) + if (context.GetTranscoder()->Transcode(targetImage, sourceImage, allowedSyntaxes, TranscodingSopInstanceUidMode_AllowNew, lossyQuality)) { call.GetOutput().SetContentFilename(filename.c_str()); call.GetOutput().AnswerBuffer(targetImage.GetBufferData(), targetImage.GetBufferSize(), MimeType_Dicom);
--- a/OrthancServer/Sources/ServerContext.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Tue May 19 16:55:23 2026 +0200 @@ -31,6 +31,7 @@ #include "../../OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h" #include "../../OrthancFramework/Sources/DicomParsing/DicomModification.h" #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" +#include "../../OrthancFramework/Sources/DicomParsing/TranscodingCallable.h" #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h" #include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h" #include "../../OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h" @@ -571,6 +572,12 @@ dicomReader_.reset(new DataSourceReader(pool.release(), new DicomDataSource(storageAreaReader_))); dicomReader_->CreateCache(100 * 1024 * 1024); // 100 MB - TODO-Streaming - Parameter } + + { + transcodingThreadPool_.reset(new ThreadPool); + transcodingThreadPool_->SetCountThreads(4); // TODO-Streaming - Parameter + transcodingThreadPool_->Start(); + } } catch (OrthancException&) { @@ -1081,7 +1088,7 @@ IDicomTranscoder::DicomImage transcoded; - if (GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew /* allow new SOP instance UID */)) + if (GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew /* allow new SOP instance UID */)) { std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); @@ -1931,7 +1938,7 @@ { DicomDataSource::Dicom::Lock lock(*dicom); - decoded.reset(GetTranscoder().DecodeFrame(lock.GetContent(), lock.GetRawBufferData(), lock.GetRawBufferSize(), frameIndex)); + decoded.reset(GetTranscoder()->DecodeFrame(lock.GetContent(), lock.GetRawBufferData(), lock.GetRawBufferSize(), frameIndex)); } if (decoded.get() == NULL) @@ -1953,10 +1960,10 @@ ImageAccessor* ServerContext::DecodeDicomFrame(const DicomInstanceToStore& dicom, unsigned int frameIndex) { - return GetTranscoder().DecodeFrame(dicom.GetParsedDicomFile(), - dicom.GetBufferData(), - dicom.GetBufferSize(), - frameIndex); + return GetTranscoder()->DecodeFrame(dicom.GetParsedDicomFile(), + dicom.GetBufferData(), + dicom.GetBufferSize(), + frameIndex); } @@ -1966,7 +1973,7 @@ unsigned int frameIndex) { std::unique_ptr<ParsedDicomFile> instance(new ParsedDicomFile(dicom, size)); - return GetTranscoder().DecodeFrame(*instance, dicom, size, frameIndex); + return GetTranscoder()->DecodeFrame(*instance, dicom, size, frameIndex); } @@ -2042,7 +2049,7 @@ std::set<DicomTransferSyntax> syntaxes; syntaxes.insert(targetSyntax); - if (GetTranscoder().Transcode(targetDicom, sourceDicom, syntaxes, TranscodingSopInstanceUidMode_AllowNew)) + if (GetTranscoder()->Transcode(targetDicom, sourceDicom, syntaxes, TranscodingSopInstanceUidMode_AllowNew)) { cacheAccessor.AddTranscodedInstance(attachmentId, targetSyntax, reinterpret_cast<const char*>(targetDicom.GetBufferData()), targetDicom.GetBufferSize()); target = std::string(reinterpret_cast<const char*>(targetDicom.GetBufferData()), targetDicom.GetBufferSize()); @@ -2263,11 +2270,11 @@ } - ServerTranscoder& ServerContext::GetTranscoder() const + const boost::shared_ptr<ServerTranscoder>& ServerContext::GetTranscoder() const { if (transcoder_.get() != NULL) { - return *transcoder_; + return transcoder_; } else { @@ -2284,7 +2291,20 @@ } else { - transcoder_.reset(NULL); + transcoder_.reset(); } } + + + Future* ServerContext::SubmitTranscodingRequest(TranscodingCallable* callable) + { + if (callable == NULL) + { + throw OrthancException(ErrorCode_NullPointer); + } + + callable->SetTranscoder(transcoder_); + + return transcodingThreadPool_->Submit(callable); + } }
--- a/OrthancServer/Sources/ServerContext.h Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.h Tue May 19 16:55:23 2026 +0200 @@ -47,6 +47,8 @@ class OrthancPlugins; class SharedArchive; class StorageCommitmentReports; + class ThreadPool; + class TranscodingCallable; /** @@ -248,7 +250,7 @@ std::unique_ptr<StorageCommitmentReports> storageCommitmentReports_; - std::unique_ptr<ServerTranscoder> transcoder_; + boost::shared_ptr<ServerTranscoder> transcoder_; bool transcodeDicomProtocol_; bool isIngestTranscoding_; DicomTransferSyntax ingestTransferSyntax_; @@ -291,6 +293,7 @@ bool checkMD5_; boost::shared_ptr<DataSourceReader> storageAreaReader_; std::unique_ptr<DataSourceReader> dicomReader_; + boost::shared_ptr<ThreadPool> transcodingThreadPool_; public: class DicomCacheLocker : public boost::noncopyable @@ -623,7 +626,7 @@ void SetTranscoder(ServerTranscoder* transcoder /* takes ownership */); - ServerTranscoder& GetTranscoder() const; + const boost::shared_ptr<ServerTranscoder>& GetTranscoder() const; // TODO-Streaming : REMOVE void ResetTranscoder(); @@ -641,5 +644,7 @@ { return *dicomReader_; } + + Future* SubmitTranscodingRequest(TranscodingCallable* callable); }; }
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp Tue May 19 16:55:23 2026 +0200 @@ -72,7 +72,7 @@ IDicomTranscoder::DicomImage source, transcoded; source.SetExternalBuffer(dicom); - if (context_.GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew)) + if (context_.GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew)) { body.assign(reinterpret_cast<const char*>(transcoded.GetBufferData()), transcoded.GetBufferSize());
--- a/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp Tue May 19 16:55:23 2026 +0200 @@ -262,7 +262,7 @@ source.AcquireParsed(*modified); // "modified" is invalid below this point IDicomTranscoder::DicomImage transcoded; - if (GetContext().GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew)) + if (GetContext().GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew)) { modified.reset(transcoded.ReleaseAsParsedDicomFile());
--- a/OrthancServer/Sources/ServerJobs/ThreadedInstancesLoader.cpp Tue May 19 15:14:48 2026 +0200 +++ b/OrthancServer/Sources/ServerJobs/ThreadedInstancesLoader.cpp Tue May 19 16:55:23 2026 +0200 @@ -267,7 +267,7 @@ IDicomTranscoder::DicomImage source, transcoded; source.SetExternalBuffer(sourceBuffer); - if (context_.GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew, lossyQuality_)) + if (context_.GetTranscoder()->Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew, lossyQuality_)) { transcodedBuffer.assign(reinterpret_cast<const char*>(transcoded.GetBufferData()), transcoded.GetBufferSize()); return true;
