# HG changeset patch # User Sebastien Jodogne # Date 1606247673 -3600 # Node ID 84fe7089ccaacf077cb637a7d1339ebbc4c61dcd # Parent f2e8b3ac1dcd1249806af9876fbfd24aafb7c479 switch to server-side transcoding on failed decoding (for jpeg2k) diff -r f2e8b3ac1dcd -r 84fe7089ccaa Applications/StoneWebViewer/WebApplication/index.html --- a/Applications/StoneWebViewer/WebApplication/index.html Tue Nov 24 18:08:07 2020 +0100 +++ b/Applications/StoneWebViewer/WebApplication/index.html Tue Nov 24 20:54:33 2020 +0100 @@ -368,6 +368,7 @@ diff -r f2e8b3ac1dcd -r 84fe7089ccaa Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp --- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Tue Nov 24 18:08:07 2020 +0100 +++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Tue Nov 24 20:54:33 2020 +0100 @@ -1247,23 +1247,26 @@ private: std::string sopInstanceUid_; unsigned int frameNumber_; + int priority_; bool isPrefetch_; public: SetFullDicomFrame(boost::shared_ptr viewport, const std::string& sopInstanceUid, unsigned int frameNumber, + int priority, bool isPrefetch) : ICommand(viewport), sopInstanceUid_(sopInstanceUid), frameNumber_(frameNumber), + priority_(priority), isPrefetch_(isPrefetch) { } virtual void Handle(const OrthancStone::ParseDicomSuccessMessage& message) const ORTHANC_OVERRIDE { - Apply(GetViewport(), message.GetDicom(), sopInstanceUid_, frameNumber_); + Apply(GetViewport(), message.GetDicom(), sopInstanceUid_, frameNumber_, priority_, isPrefetch_); if (isPrefetch_) { @@ -1274,7 +1277,9 @@ static void Apply(ViewerViewport& viewport, const Orthanc::ParsedDicomFile& dicom, const std::string& sopInstanceUid, - unsigned int frameNumber) + unsigned int frameNumber, + int priority, + bool isPrefetch) { Orthanc::DicomMap tags; dicom.ExtractDicomSummary(tags, ORTHANC_STONE_MAX_TAG_LENGTH); @@ -1285,8 +1290,27 @@ // Safety check throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } + + std::unique_ptr frame; - std::unique_ptr frame(dicom.DecodeFrame(frameNumber)); + try + { + frame.reset(dicom.DecodeFrame(frameNumber)); + } + catch (Orthanc::OrthancException& e) + { + if (e.GetErrorCode() == Orthanc::ErrorCode_NotImplemented) + { + viewport.serverSideTranscoding_ = true; + LOG(INFO) << "Switching to server-side transcoding"; + viewport.ScheduleLoadFullDicomFrame(sopInstanceUid, frameNumber, priority, isPrefetch); + return; + } + else + { + throw; + } + } if (frame.get() == NULL) { @@ -1375,6 +1399,7 @@ bool fitNextContent_; bool isCtrlDown_; std::list prefetchQueue_; + bool serverSideTranscoding_; bool hasFocusOnInstance_; @@ -1630,6 +1655,23 @@ } } + void ScheduleLoadFullDicomFrame(const std::string& sopInstanceUid, + unsigned int frameNumber, + int priority, + bool isPrefetch) + { + if (frames_.get() != NULL) + { + std::unique_ptr lock(context_.Lock()); + lock->Schedule( + GetSharedObserver(), priority, OrthancStone::ParseDicomFromWadoCommand::Create( + source_, frames_->GetStudyInstanceUid(), frames_->GetSeriesInstanceUid(), + sopInstanceUid, serverSideTranscoding_, + Orthanc::DicomTransferSyntax_LittleEndianExplicit, + new SetFullDicomFrame(GetSharedObserver(), sopInstanceUid, frameNumber, priority, isPrefetch))); + } + } + void ScheduleLoadFullDicomFrame(size_t cursorIndex, int priority, bool isPrefetch) @@ -1638,16 +1680,7 @@ { std::string sopInstanceUid = frames_->GetInstanceOfFrame(cursorIndex).GetSopInstanceUid(); unsigned int frameNumber = frames_->GetFrameNumberInInstance(cursorIndex); - - { - std::unique_ptr lock(context_.Lock()); - lock->Schedule( - GetSharedObserver(), priority, OrthancStone::ParseDicomFromWadoCommand::Create( - source_, frames_->GetStudyInstanceUid(), frames_->GetSeriesInstanceUid(), - sopInstanceUid, false /* transcoding (TODO) */, - Orthanc::DicomTransferSyntax_LittleEndianExplicit /* TODO */, - new SetFullDicomFrame(GetSharedObserver(), sopInstanceUid, frameNumber, isPrefetch))); - } + ScheduleLoadFullDicomFrame(sopInstanceUid, frameNumber, priority, isPrefetch); } } @@ -1676,7 +1709,8 @@ { try { - SetFullDicomFrame::Apply(*this, accessor->GetDicom(), instance.GetSopInstanceUid(), frameNumber); + SetFullDicomFrame::Apply(*this, accessor->GetDicom(), instance.GetSopInstanceUid(), + frameNumber, priority, isPrefetch); return; } catch (Orthanc::OrthancException&) @@ -1884,6 +1918,7 @@ fitNextContent_ = true; cineRate_ = DEFAULT_CINE_RATE; inverted_ = false; + serverSideTranscoding_ = false; frames_.reset(frames); cursor_.reset(new SeriesCursor(frames_->GetFramesCount()));