comparison OrthancServer/Sources/ServerContext.cpp @ 4384:7e0d015ad109

new configuration options IngestTranscodingOfUncompressed and IngestTranscodingOfCompressed
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Dec 2020 11:13:00 +0100
parents b002f9abe802
children 3af1d763763a
comparison
equal deleted inserted replaced
4383:e49cf50b54c8 4384:7e0d015ad109
72 * locking. 72 * locking.
73 **/ 73 **/
74 74
75 namespace Orthanc 75 namespace Orthanc
76 { 76 {
77 static bool IsUncompressedTransferSyntax(DicomTransferSyntax transferSyntax)
78 {
79 return (transferSyntax == DicomTransferSyntax_LittleEndianImplicit ||
80 transferSyntax == DicomTransferSyntax_LittleEndianExplicit ||
81 transferSyntax == DicomTransferSyntax_BigEndianExplicit);
82 }
83
84
85 static bool IsTranscodableTransferSyntax(DicomTransferSyntax transferSyntax)
86 {
87 return (
88 // Do not try to transcode DICOM videos (new in Orthanc 1.8.2)
89 transferSyntax != DicomTransferSyntax_MPEG2MainProfileAtMainLevel &&
90 transferSyntax != DicomTransferSyntax_MPEG2MainProfileAtHighLevel &&
91 transferSyntax != DicomTransferSyntax_MPEG4HighProfileLevel4_1 &&
92 transferSyntax != DicomTransferSyntax_MPEG4BDcompatibleHighProfileLevel4_1 &&
93 transferSyntax != DicomTransferSyntax_MPEG4HighProfileLevel4_2_For2DVideo &&
94 transferSyntax != DicomTransferSyntax_MPEG4HighProfileLevel4_2_For3DVideo &&
95 transferSyntax != DicomTransferSyntax_MPEG4StereoHighProfileLevel4_2 &&
96 transferSyntax != DicomTransferSyntax_HEVCMainProfileLevel5_1 &&
97 transferSyntax != DicomTransferSyntax_HEVCMain10ProfileLevel5_1 &&
98
99 // Do not try to transcode special transfer syntaxes
100 transferSyntax != DicomTransferSyntax_RFC2557MimeEncapsulation &&
101 transferSyntax != DicomTransferSyntax_XML);
102 }
103
104
77 void ServerContext::ChangeThread(ServerContext* that, 105 void ServerContext::ChangeThread(ServerContext* that,
78 unsigned int sleepDelay) 106 unsigned int sleepDelay)
79 { 107 {
80 while (!that->done_) 108 while (!that->done_)
81 { 109 {
268 isHttpServerSecure_(true), 296 isHttpServerSecure_(true),
269 isExecuteLuaEnabled_(false), 297 isExecuteLuaEnabled_(false),
270 overwriteInstances_(false), 298 overwriteInstances_(false),
271 dcmtkTranscoder_(new DcmtkTranscoder), 299 dcmtkTranscoder_(new DcmtkTranscoder),
272 isIngestTranscoding_(false), 300 isIngestTranscoding_(false),
301 ingestTranscodingOfUncompressed_(true),
302 ingestTranscodingOfCompressed_(true),
273 deidentifyLogs_(false) 303 deidentifyLogs_(false)
274 { 304 {
275 try 305 try
276 { 306 {
277 unsigned int lossyQuality; 307 unsigned int lossyQuality;
307 if (LookupTransferSyntax(ingestTransferSyntax_, s)) 337 if (LookupTransferSyntax(ingestTransferSyntax_, s))
308 { 338 {
309 isIngestTranscoding_ = true; 339 isIngestTranscoding_ = true;
310 LOG(WARNING) << "Incoming DICOM instances will automatically be transcoded to " 340 LOG(WARNING) << "Incoming DICOM instances will automatically be transcoded to "
311 << "transfer syntax: " << GetTransferSyntaxUid(ingestTransferSyntax_); 341 << "transfer syntax: " << GetTransferSyntaxUid(ingestTransferSyntax_);
342
343 ingestTranscodingOfUncompressed_ = lock.GetConfiguration().GetBooleanParameter("IngestTranscodingOfUncompressed", true);
344 ingestTranscodingOfCompressed_ = lock.GetConfiguration().GetBooleanParameter("IngestTranscodingOfCompressed", true);
345
346 LOG(WARNING) << " Ingest transcoding will "
347 << (ingestTranscodingOfUncompressed_ ? "be applied" : "*not* be applied")
348 << " to uncompressed transfer syntaxes (Little Endian Implicit/Explicit, Big Endian Explicit)";
349
350 LOG(WARNING) << " Ingest transcoding will "
351 << (ingestTranscodingOfCompressed_ ? "be applied" : "*not* be applied")
352 << " to compressed transfer syntaxes";
312 } 353 }
313 else 354 else
314 { 355 {
315 throw OrthancException(ErrorCode_ParameterOutOfRange, 356 throw OrthancException(ErrorCode_ParameterOutOfRange,
316 "Unknown transfer syntax for ingest transcoding: " + s); 357 "Unknown transfer syntax for ingest transcoding: " + s);
589 // No automated transcoding. This was the only path in Orthanc <= 1.6.1. 630 // No automated transcoding. This was the only path in Orthanc <= 1.6.1.
590 return StoreAfterTranscoding(resultPublicId, dicom, mode); 631 return StoreAfterTranscoding(resultPublicId, dicom, mode);
591 } 632 }
592 else 633 else
593 { 634 {
594 // Automated transcoding of incoming DICOM files 635 // Automated transcoding of incoming DICOM instance
636
637 bool transcode = false;
595 638
596 DicomTransferSyntax sourceSyntax; 639 DicomTransferSyntax sourceSyntax;
597 if (!FromDcmtkBridge::LookupOrthancTransferSyntax( 640 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(
598 sourceSyntax, dicom.GetParsedDicomFile().GetDcmtkObject()) || 641 sourceSyntax, dicom.GetParsedDicomFile().GetDcmtkObject()) ||
599 sourceSyntax == ingestTransferSyntax_) 642 sourceSyntax == ingestTransferSyntax_)
600 { 643 {
644 // Don't transcode if the incoming DICOM is already in the proper transfer syntax
645 transcode = false;
646 }
647 else if (!IsTranscodableTransferSyntax(sourceSyntax))
648 {
649 // Don't try to transcode video files, this is useless (new in
650 // Orthanc 1.8.2). This could be accepted in the future if
651 // video transcoding gets implemented.
652 transcode = false;
653 }
654 else if (IsUncompressedTransferSyntax(sourceSyntax))
655 {
656 // This is an uncompressed transfer syntax (new in Orthanc 1.8.2)
657 transcode = ingestTranscodingOfUncompressed_;
658 }
659 else
660 {
661 // This is an compressed transfer syntax (new in Orthanc 1.8.2)
662 transcode = ingestTranscodingOfCompressed_;
663 }
664
665 if (!transcode)
666 {
601 // No transcoding 667 // No transcoding
602 return StoreAfterTranscoding(resultPublicId, dicom, mode); 668 return StoreAfterTranscoding(resultPublicId, dicom, mode);
603 } 669 }
604 else 670 else
605 { 671 {
672 // Trancoding
606 std::set<DicomTransferSyntax> syntaxes; 673 std::set<DicomTransferSyntax> syntaxes;
607 syntaxes.insert(ingestTransferSyntax_); 674 syntaxes.insert(ingestTransferSyntax_);
608 675
609 IDicomTranscoder::DicomImage source; 676 IDicomTranscoder::DicomImage source;
610 source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize()); 677 source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize());
611 678
612 IDicomTranscoder::DicomImage transcoded; 679 IDicomTranscoder::DicomImage transcoded;
613 if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) 680 if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */))
614 { 681 {
615 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); 682 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile());
616 683