changeset 6823:80073731929d streaming

using data sources to decode frames
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 May 2026 18:30:27 +0200
parents 5eac7f32c814
children b9ecf4edf9c5
files OrthancFramework/Sources/DataSource/DataSourceReader.cpp OrthancFramework/Sources/DataSource/DataSourceReader.h OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h OrthancServer/Sources/ServerTranscoder.cpp OrthancServer/Sources/ServerTranscoder.h OrthancServer/Sources/main.cpp OrthancServer/UnitTestsSources/ServerConfigTests.cpp OrthancServer/UnitTestsSources/ServerIndexTests.cpp OrthancServer/UnitTestsSources/ServerJobsTests.cpp
diffstat 10 files changed, 274 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceReader.cpp	Wed May 20 18:30:27 2026 +0200
@@ -156,13 +156,13 @@
   };
 
 
-  DataSourceReader::DataSourceReader(IExecutorService* executor /* takes ownership */,
+  DataSourceReader::DataSourceReader(const boost::shared_ptr<IExecutorService>& executor /* takes ownership */,
                                      IDataSource* source /* takes ownership */) :
     executor_(executor),
     source_(source),
     budget_(new Internals::DataSourceMemoryBudget(0))
   {
-    if (executor == NULL ||
+    if (executor.get() == NULL ||
         source == NULL)
     {
       throw OrthancException(ErrorCode_NullPointer);
--- a/OrthancFramework/Sources/DataSource/DataSourceReader.h	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancFramework/Sources/DataSource/DataSourceReader.h	Wed May 20 18:30:27 2026 +0200
@@ -46,22 +46,17 @@
   private:
     class DataSourceRunnable;
 
-    std::unique_ptr<IExecutorService>                     executor_;
+    boost::shared_ptr<IExecutorService>                   executor_;
     std::unique_ptr<IDataSource>                          source_;
     boost::shared_ptr<SharedObjectCache>                  cache_;
     boost::shared_ptr<Internals::DataSourceMemoryBudget>  budget_;
 
   public:
-    DataSourceReader(IExecutorService* executor /* takes ownership */,
+    DataSourceReader(const boost::shared_ptr<IExecutorService>& executor,
                      IDataSource* source /* takes ownership */);
 
     ~DataSourceReader();
 
-    IDataSource& GetSource() const
-    {
-      return *source_;
-    }
-
     void CreateCache(size_t capacity);
 
     void SetMaximumMemory(uint64_t maximumMemory);
--- a/OrthancServer/Sources/ServerContext.cpp	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Wed May 20 18:30:27 2026 +0200
@@ -26,6 +26,7 @@
 
 #include "../../OrthancFramework/Sources/Cache/SharedArchive.h"
 #include "../../OrthancFramework/Sources/DataSource/StorageAreaDataSource.h"
+#include "../../OrthancFramework/Sources/DataSource/TranscoderDataSource.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomElement.h"
 #include "../../OrthancFramework/Sources/DicomFormat/DicomStreamReader.h"
 #include "../../OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h"
@@ -379,6 +380,7 @@
 
   ServerContext::ServerContext(IDatabaseWrapper& database,
                                IPluginStorageArea& area,
+                               ServerTranscoder* transcoder /* takes ownership */,
                                bool unitTesting,
                                size_t maxCompletedJobs,
                                bool readOnly) :
@@ -402,6 +404,8 @@
     isExecuteLuaEnabled_(false),
     isRestApiWriteToFileSystemEnabled_(false),
     overwriteInstances_(OverwriteInstancesMode_Never),
+    transcoder_(transcoder),
+    transcodeDicomProtocol_(true),
     isIngestTranscoding_(false),
     ingestTranscodingOfUncompressed_(true),
     ingestTranscodingOfCompressed_(true),
@@ -558,29 +562,34 @@
 
       // For streaming
       {
-        std::unique_ptr<ThreadPool> pool(new ThreadPool);
+        boost::shared_ptr<ThreadPool> pool(new ThreadPool);
         pool->SetCountThreads(4);  // TODO-Streaming - Parameter
         pool->SetDequeueTimeout(100);
         pool->Start();
 
-        storageAreaReader_.reset(new DataSourceReader(pool.release(), new StorageAreaDataSource(area_)));
+        storageAreaReader_.reset(new DataSourceReader(pool, new StorageAreaDataSource(area_)));
         storageAreaReader_->CreateCache(DICOM_CACHE_SIZE); // TODO-Streaming - Parameter
       }
 
       {
-        std::unique_ptr<ThreadPool> pool(new ThreadPool);
+        boost::shared_ptr<ThreadPool> pool(new ThreadPool);
         pool->SetCountThreads(2);  // TODO-Streaming - Parameter
         pool->SetDequeueTimeout(100);
         pool->Start();
 
-        dicomReader_.reset(new DataSourceReader(pool.release(), new DicomDataSource(storageAreaReader_)));
+        dicomReader_.reset(new DataSourceReader(pool, new DicomDataSource(storageAreaReader_)));
         dicomReader_->CreateCache(100 * 1024 * 1024); // 100 MB - TODO-Streaming - Parameter
       }
 
+      if (transcoder_.get() != NULL)
       {
-        transcodingThreadPool_.reset(new ThreadPool);
-        transcodingThreadPool_->SetCountThreads(4);  // TODO-Streaming - Parameter
-        transcodingThreadPool_->Start();
+        transcoderThreadPool_.reset(new ThreadPool);
+        transcoderThreadPool_->SetCountThreads(2);  // TODO-Streaming - Parameter
+        transcoderThreadPool_->SetDequeueTimeout(100);
+        transcoderThreadPool_->Start();
+
+        transcoderReader_.reset(new DataSourceReader(transcoderThreadPool_, new TranscoderDataSource(transcoder_, storageAreaReader_)));
+        transcoderReader_->CreateCache(100 * 1024 * 1024); // 100 MB - TODO-Streaming - Parameter
       }
     }
     catch (OrthancException&)
@@ -1840,26 +1849,32 @@
   }
 
 
-  ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& publicId,
+  ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& instancePublicId,
                                                  unsigned int frameIndex)
   {
-    std::unique_ptr<DicomDataSource::Dicom> dicom(ReadParsedDicom(publicId, true /* raw buffer is necessary for transcoding */));
+    FileInfo attachment;
+    int64_t revision;
+
+    if (!index_.LookupAttachment(attachment, revision, ResourceType_Instance, instancePublicId, FileContentType_Dicom))
+    {
+      throw OrthancException(ErrorCode_InternalError,
+                             "Unable to read attachment " + EnumerationToString(FileContentType_Dicom) +
+                             " of instance " + instancePublicId);
+    }
 
     std::unique_ptr<ImageAccessor> decoded;
 
-    {
-      DicomDataSource::Dicom::Lock lock(*dicom);
-      decoded.reset(GetTranscoder()->DecodeFrame(lock.GetContent(), lock.GetRawBufferData(), lock.GetRawBufferSize(), frameIndex));
-    }
+    decoded.reset(GetTranscoder()->DecodeFrame(dicomReader_, storageAreaReader_, transcoderReader_, attachment, frameIndex, checkMD5_));
 
     if (decoded.get() == NULL)
     {
       OrthancConfiguration::ReaderLock configLock;
       if (configLock.GetConfiguration().IsWarningEnabled(Warnings_003_DecoderFailure))
       {
-        LOG(WARNING) << "W003: Unable to decode frame " << frameIndex << " from instance " << publicId;
+        LOG(WARNING) << "W003: Unable to decode frame " << frameIndex << " from instance " << instancePublicId;
       }
-      return NULL;
+
+      throw OrthancException(ErrorCode_NotImplemented);
     }
     else
     {
@@ -2131,25 +2146,6 @@
   }
 
 
-  void ServerContext::SetTranscoder(ServerTranscoder* transcoder)
-  {
-    std::unique_ptr<ServerTranscoder> protection(transcoder);
-
-    if (transcoder == NULL)
-    {
-      throw OrthancException(ErrorCode_NullPointer);
-    }
-    else if (transcoder_.get() != NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      transcoder_.reset(protection.release());
-    }
-  }
-
-
   const boost::shared_ptr<ServerTranscoder>& ServerContext::GetTranscoder() const
   {
     if (transcoder_.get() != NULL)
@@ -2158,20 +2154,7 @@
     }
     else
     {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-  }
-
-
-  void ServerContext::ResetTranscoder()
-  {
-    if (transcoder_.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      transcoder_.reset();
+      throw OrthancException(ErrorCode_BadSequenceOfCalls, "No transcoder is available");
     }
   }
 
@@ -2185,6 +2168,6 @@
 
     callable->SetTranscoder(transcoder_);
 
-    return transcodingThreadPool_->Submit(callable);
+    return transcoderThreadPool_->Submit(callable);
   }
 }
--- a/OrthancServer/Sources/ServerContext.h	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.h	Wed May 20 18:30:27 2026 +0200
@@ -288,12 +288,14 @@
     // For streaming
     bool                                 checkMD5_;
     boost::shared_ptr<DataSourceReader>  storageAreaReader_;
-    std::unique_ptr<DataSourceReader>    dicomReader_;
-    boost::shared_ptr<ThreadPool>        transcodingThreadPool_;
+    boost::shared_ptr<DataSourceReader>  dicomReader_;
+    boost::shared_ptr<ThreadPool>        transcoderThreadPool_;
+    boost::shared_ptr<DataSourceReader>  transcoderReader_;
 
   public:
     ServerContext(IDatabaseWrapper& database,
                   IPluginStorageArea& area,
+                  ServerTranscoder* transcoder /* takes ownership */,
                   bool unitTesting,
                   size_t maxCompletedJobs,
                   bool readOnly);
@@ -542,9 +544,11 @@
     ImageAccessor* DecodeDicomFrame(const std::string& publicId,
                                     unsigned int frameIndex);
 
+    // TODO-Streaming : To remove (or adapt)
     ImageAccessor* DecodeDicomFrame(const DicomInstanceToStore& dicom,
                                     unsigned int frameIndex);
 
+    // TODO-Streaming : To remove
     ImageAccessor* DecodeDicomFrame(const void* dicom,
                                     size_t size,
                                     unsigned int frameIndex);
@@ -588,23 +592,19 @@
 
     void PublishCacheMetrics();
 
-    void SetTranscoder(ServerTranscoder* transcoder /* takes ownership */);
-
     const boost::shared_ptr<ServerTranscoder>& GetTranscoder() const;  // TODO-Streaming : REMOVE
 
-    void ResetTranscoder();
-
     bool IsCheckMD5() const
     {
       return checkMD5_;
     }
 
-    DataSourceReader& GetStorageAreaReader() const
+    DataSourceReader& GetStorageAreaReader() const  // TODO-Streaming : REMOVE?
     {
       return *storageAreaReader_;
     }
 
-    DataSourceReader& GetDicomReader() const
+    DataSourceReader& GetDicomReader() const  // TODO-Streaming : REMOVE?
     {
       return *dicomReader_;
     }
--- a/OrthancServer/Sources/ServerTranscoder.cpp	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/Sources/ServerTranscoder.cpp	Wed May 20 18:30:27 2026 +0200
@@ -48,8 +48,8 @@
     {
       WorkingSource_Unknown,
       WorkingSource_Builtin,
-      WorkingSource_Plugins,
-      WorkingSource_Transcoding
+      WorkingSource_PluginsDecoder,
+      WorkingSource_PluginsTranscoder
     };
   }
 
@@ -136,6 +136,28 @@
 #endif
 
 
+  bool ServerTranscoder::HasPluginsDecoder() const
+  {
+#if ORTHANC_ENABLE_PLUGINS == 1
+    return (plugins_ != NULL &&
+            plugins_->HasCustomImageDecoder());
+#else
+    return false;
+#endif
+  }
+
+
+  bool ServerTranscoder::HasPluginsTranscoder() const
+  {
+#if ORTHANC_ENABLE_PLUGINS == 1
+    return (plugins_ != NULL &&
+            plugins_->HasCustomTranscoder());
+#else
+    return false;
+#endif
+  }
+
+
   ImageAccessor* ServerTranscoder::DecodeFrameBuiltin(const ParsedDicomFile& dicom,
                                                       unsigned int frameIndex)
   {
@@ -153,13 +175,12 @@
   }
 
 
-  ImageAccessor* ServerTranscoder::DecodeFrameUsingPlugins(const void* buffer,
-                                                           size_t size,
-                                                           unsigned int frameIndex)
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsDecoder(const void* buffer,
+                                                                  size_t size,
+                                                                  unsigned int frameIndex)
   {
 #if ORTHANC_ENABLE_PLUGINS == 1
-    if (plugins_ != NULL &&
-        plugins_->HasCustomImageDecoder())
+    if (HasPluginsDecoder())
     {
       try
       {
@@ -175,13 +196,12 @@
   }
 
 
-  ImageAccessor* ServerTranscoder::DecodeFrameUsingTranscoding(const void* buffer,
-                                                               size_t size,
-                                                               unsigned int frameIndex)
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsTranscoder(const void* buffer,
+                                                                     size_t size,
+                                                                     unsigned int frameIndex)
   {
 #if ORTHANC_ENABLE_PLUGINS == 1
-    if (plugins_ != NULL &&
-        plugins_->HasCustomTranscoder())
+    if (HasPluginsTranscoder())
     {
       DicomImage transcoded;
       DicomImage source;
@@ -208,6 +228,60 @@
   }
 
 
+  ImageAccessor* ServerTranscoder::DecodeFrameBuiltin(const boost::shared_ptr<DataSourceReader>& dicomReader,
+                                                      const FileInfo& attachment,
+                                                      unsigned int frameIndex,
+                                                      bool checkMD5)
+  {
+    std::unique_ptr<DicomDataSource::Dicom> dicom(
+      DicomDataSource::ReadWhole(*dicomReader, attachment, false, checkMD5));
+
+    DicomDataSource::Dicom::Lock lock(*dicom);
+
+    return DecodeFrameBuiltin(lock.GetContent(), frameIndex);
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsDecoder(const boost::shared_ptr<DataSourceReader>& storageAreaReader,
+                                                                  const FileInfo& attachment,
+                                                                  unsigned int frameIndex,
+                                                                  bool checkMD5)
+  {
+    if (!HasPluginsDecoder())
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      std::unique_ptr<StorageAreaDataSource::Range> range(
+        StorageAreaDataSource::ReadAttachment(*storageAreaReader, attachment, true /* uncompress */, checkMD5));
+
+      return DecodeFrameUsingPluginsDecoder(range->GetData(), range->GetSize(), frameIndex);
+    }
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrameUsingPluginsTranscoder(const boost::shared_ptr<DataSourceReader>& transcoderReader,
+                                                                     const FileInfo& attachment,
+                                                                     unsigned int frameIndex,
+                                                                     bool checkMD5)
+  {
+    if (!HasPluginsDecoder())
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else
+    {
+      std::unique_ptr<TranscoderDataSource::Transcoded> transcoded(
+        TranscoderDataSource::Transcode(*transcoderReader, attachment, DicomTransferSyntax_LittleEndianExplicit, checkMD5));
+
+      TranscoderDataSource::Transcoded::Lock lock(*transcoded);
+
+      return DecodeFrameBuiltin(lock.GetDicom(), frameIndex);
+    }
+  }
+
+
   ImageAccessor* ServerTranscoder::DecodeFrame(const ParsedDicomFile& dicom,
                                                const void* buffer,
                                                size_t size,
@@ -224,7 +298,7 @@
       }
     }
 
-    decoded.reset(DecodeFrameUsingPlugins(buffer, size, frameIndex));
+    decoded.reset(DecodeFrameUsingPluginsDecoder(buffer, size, frameIndex));
     if (decoded.get() != NULL)
     {
       return decoded.release();
@@ -239,12 +313,101 @@
       }
     }
 
-    decoded.reset(DecodeFrameUsingTranscoding(buffer, size, frameIndex));
+    decoded.reset(DecodeFrameUsingPluginsTranscoder(buffer, size, frameIndex));
+    if (decoded.get() != NULL)
+    {
+      return decoded.release();
+    }
+
+    return NULL;
+  }
+
+
+  ImageAccessor* ServerTranscoder::DecodeFrame(const boost::shared_ptr<DataSourceReader>& dicomReader,        // For built-in decoding
+                                               const boost::shared_ptr<DataSourceReader>& storageAreaReader,  // For plugin-based decoding
+                                               const boost::shared_ptr<DataSourceReader>& transcoderReader,   // For transcoding-based decoding
+                                               const FileInfo& attachment,
+                                               unsigned int frameIndex,
+                                               bool checkMD5)
+  {
+    // Step 1: Try with the last decoder that successfully handled this DICOM attachment
+
+    const WorkingSource source = pimpl_->LookupWorkingSource(attachment.GetUuid());
+
+    std::unique_ptr<ImageAccessor> decoded;
+
+    switch (source)
+    {
+      case WorkingSource_Unknown:
+        break;
+
+      case WorkingSource_Builtin:
+        decoded.reset(DecodeFrameBuiltin(dicomReader, attachment, frameIndex, checkMD5));
+        break;
+
+      case WorkingSource_PluginsDecoder:
+        decoded.reset(DecodeFrameUsingPluginsDecoder(storageAreaReader, attachment, frameIndex, checkMD5));
+        break;
+
+      case WorkingSource_PluginsTranscoder:
+        decoded.reset(DecodeFrameUsingPluginsTranscoder(transcoderReader, attachment, frameIndex, checkMD5));
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+
     if (decoded.get() != NULL)
     {
       return decoded.release();
     }
 
+    // Step 2: If this attachment is unknown, try the available decoders
+
+    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before)
+    {
+      decoded.reset(DecodeFrameBuiltin(dicomReader, attachment, frameIndex, checkMD5));
+
+      if (decoded.get() != NULL)
+      {
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_Builtin);
+        return decoded.release();
+      }
+    }
+
+    if (HasPluginsDecoder())
+    {
+      decoded.reset(DecodeFrameUsingPluginsDecoder(storageAreaReader, attachment, frameIndex, checkMD5));
+
+      if (decoded.get() != NULL)
+      {
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_PluginsDecoder);
+        return decoded.release();
+      }
+    }
+
+    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
+    {
+      decoded.reset(DecodeFrameBuiltin(dicomReader, attachment, frameIndex, checkMD5));
+
+      if (decoded.get() != NULL)
+      {
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_Builtin);
+        return decoded.release();
+      }
+    }
+
+    if (HasPluginsTranscoder())
+    {
+      decoded.reset(DecodeFrameUsingPluginsTranscoder(transcoderReader, attachment, frameIndex, checkMD5));
+
+      if (decoded.get() != NULL)
+      {
+        pimpl_->SetWorkingSource(attachment.GetUuid(), WorkingSource_PluginsTranscoder);
+        return decoded.release();
+      }
+    }
+
     return NULL;
   }
 
--- a/OrthancServer/Sources/ServerTranscoder.h	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/Sources/ServerTranscoder.h	Wed May 20 18:30:27 2026 +0200
@@ -24,6 +24,7 @@
 #pragma once
 
 #include "../../OrthancFramework/Sources/DicomParsing/IDicomTranscoder.h"
+#include "../../OrthancFramework/Sources/FileStorage/FileInfo.h"
 #include "../../OrthancFramework/Sources/Images/ImageAccessor.h"
 #include "ServerEnumerations.h"
 
@@ -32,6 +33,8 @@
 
 namespace Orthanc
 {
+  class DataSourceReader;
+
 #if ORTHANC_ENABLE_PLUGINS == 1
   class OrthancPlugins;
 #endif
@@ -52,13 +55,29 @@
     ImageAccessor* DecodeFrameBuiltin(const ParsedDicomFile& dicom,
                                       unsigned int frameIndex);
 
-    ImageAccessor* DecodeFrameUsingPlugins(const void* buffer,  // buffer that is the source of the ParsedDicomFile
-                                           size_t size,
-                                           unsigned int frameIndex);
+    ImageAccessor* DecodeFrameUsingPluginsDecoder(const void* buffer,
+                                                  size_t size,
+                                                  unsigned int frameIndex);
+
+    // TODO-Streaming : remove
+    ImageAccessor* DecodeFrameUsingPluginsTranscoder(const void* buffer,
+                                                     size_t size,
+                                                     unsigned int frameIndex);
 
-    ImageAccessor* DecodeFrameUsingTranscoding(const void* buffer,  // buffer that is the source of the ParsedDicomFile
-                                               size_t size,
-                                               unsigned int frameIndex);
+    ImageAccessor* DecodeFrameBuiltin(const boost::shared_ptr<DataSourceReader>& dicomReader,
+                                      const FileInfo& attachment,
+                                      unsigned int frameIndex,
+                                      bool checkMD5);
+
+    ImageAccessor* DecodeFrameUsingPluginsDecoder(const boost::shared_ptr<DataSourceReader>& storageAreaReader,
+                                                  const FileInfo& attachment,
+                                                  unsigned int frameIndex,
+                                                  bool checkMD5);
+
+    ImageAccessor* DecodeFrameUsingPluginsTranscoder(const boost::shared_ptr<DataSourceReader>& transcoderReader,
+                                                     const FileInfo& attachment,
+                                                     unsigned int frameIndex,
+                                                     bool checkMD5);
 
   public:
     ServerTranscoder(unsigned int maxConcurrentDcmtkTranscoder);
@@ -67,11 +86,22 @@
     void SetPlugins(OrthancPlugins& plugins);
 #endif
 
+    bool HasPluginsDecoder() const;
+
+    bool HasPluginsTranscoder() const;
+
     ImageAccessor* DecodeFrame(const ParsedDicomFile& dicom,
                                const void* buffer,  // buffer that is the source of the ParsedDicomFile
                                size_t size,
                                unsigned int frameIndex);  // TODO-Streaming : Remove this flavor
 
+    ImageAccessor* DecodeFrame(const boost::shared_ptr<DataSourceReader>& dicomReader,        // For built-in decoding
+                               const boost::shared_ptr<DataSourceReader>& storageAreaReader,  // For plugin-based decoding
+                               const boost::shared_ptr<DataSourceReader>& transcoderReader,   // For transcoding-based decoding
+                               const FileInfo& attachment,
+                               unsigned int frameIndex,
+                               bool checkMD5);
+
     // This method can be used even if the global option
     // "TranscodeDicomProtocol" is set to "false"
     virtual bool Transcode(DicomImage& target,
--- a/OrthancServer/Sources/main.cpp	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/Sources/main.cpp	Wed May 20 18:30:27 2026 +0200
@@ -1609,19 +1609,14 @@
         lock.GetConfiguration().SetServerIndex(context.GetIndex());
       }
 
-      std::unique_ptr<ServerTranscoder> transcoder(new ServerTranscoder(maxDcmtkConcurrentTranscoders));
-
 #if ORTHANC_ENABLE_PLUGINS == 1
       if (plugins_ != NULL)
       {
         plugins_->SetServerContext(context_);
         context_.SetPlugins(*plugins_);
         context_.GetIndex().SetMaxDatabaseRetries(plugins_->GetMaxDatabaseRetries());
-        transcoder->SetPlugins(*plugins_);
       }
 #endif
-
-      context.SetTranscoder(transcoder.release());
     }
 
     ~ServerContextConfigurator()
@@ -1638,8 +1633,6 @@
         context_.ResetPlugins();
       }
 #endif
-
-      context_.ResetTranscoder();
     }
   };
 }
@@ -1710,8 +1703,14 @@
     DicomAssociationParameters::SetDefaultRemoteCertificateRequired(
       lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_REMOTE_CERTIFICATE_REQUIRED, true));
   }
+
+  std::unique_ptr<ServerTranscoder> transcoder(new ServerTranscoder(maxDcmtkConcurrentTranscoders));
+
+#if ORTHANC_ENABLE_PLUGINS == 1
+  transcoder->SetPlugins(*plugins);
+#endif
   
-  ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs, readOnly);
+  ServerContext context(database, storageArea, transcoder.release(), false /* not running unit tests */, maxCompletedJobs, readOnly);
 
   {
     OrthancConfiguration::ReaderLock lock;
@@ -2181,7 +2180,8 @@
           SQLiteDatabaseWrapper inMemoryDatabase;
           inMemoryDatabase.Open();
           PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea);
-          ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
+          ServerContext context(inMemoryDatabase, inMemoryStorage, NULL /* no transcoder */,
+                                true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
           OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
           restApi.GenerateOpenApiDocumentation(openapi);
           context.Stop();
@@ -2232,7 +2232,8 @@
           SQLiteDatabaseWrapper inMemoryDatabase;
           inMemoryDatabase.Open();
           PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea);
-          ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
+          ServerContext context(inMemoryDatabase, inMemoryStorage, NULL /* no transcoder */,
+                                true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
           OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
           restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html");
           context.Stop();
--- a/OrthancServer/UnitTestsSources/ServerConfigTests.cpp	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/ServerConfigTests.cpp	Wed May 20 18:30:27 2026 +0200
@@ -39,7 +39,7 @@
   PluginStorageAreaAdapter storage(new MemoryStorageArea);
   SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
   db.Open();
-  ServerContext context(db, storage, true /* running unit tests */, 10, false);
+  ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false);
 
   { // default config -> all SOP Classes should be accepted
     std::set<std::string> s;
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Wed May 20 18:30:27 2026 +0200
@@ -730,7 +730,7 @@
   PluginStorageAreaAdapter storage(new FilesystemStorage(path));
   SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
   db.Open();
-  ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+  ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
   context.SetupJobsEngine(true, false);
 
   ServerIndex& index = context.GetIndex();
@@ -812,7 +812,7 @@
   PluginStorageAreaAdapter storage(new FilesystemStorage(path));
   SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
   db.Open();
-  ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+  ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
   context.SetupJobsEngine(true, false);
   ServerIndex& index = context.GetIndex();
 
@@ -935,7 +935,7 @@
     PluginStorageAreaAdapter storage(new MemoryStorageArea);
     SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
     db.Open();
-    ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+    ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
     context.SetupJobsEngine(true, false);
     context.SetCompressionEnabled(true);
 
@@ -1106,7 +1106,7 @@
     PluginStorageAreaAdapter storage(new MemoryStorageArea);
     SQLiteDatabaseWrapper db;   // The SQLite DB is in memory
     db.Open();
-    ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */);
+    ServerContext context(db, storage, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */);
     context.SetupJobsEngine(true, false);
     context.SetCompressionEnabled(compression);
 
--- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Wed May 20 08:16:23 2026 +0200
+++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Wed May 20 18:30:27 2026 +0200
@@ -566,7 +566,7 @@
       storage_(new MemoryStorageArea)
     {
       db_.Open();
-      context_.reset(new ServerContext(db_, storage_, true /* running unit tests */, 10, false /* readonly */));
+      context_.reset(new ServerContext(db_, storage_, NULL /* no transcoder */, true /* running unit tests */, 10, false /* readonly */));
       context_->SetupJobsEngine(true, false);
     }