Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 3931:e6606d3ec892 transcoding
new configuration option: BuiltinDecoderTranscoderOrder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 May 2020 09:22:31 +0200 |
parents | b99acc213937 |
children | 54dbebbcc032 |
comparison
equal
deleted
inserted
replaced
3930:b99acc213937 | 3931:e6606d3ec892 |
---|---|
266 limitFindResults_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0); | 266 limitFindResults_ = lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0); |
267 | 267 |
268 // New configuration option in Orthanc 1.6.0 | 268 // New configuration option in Orthanc 1.6.0 |
269 storageCommitmentReports_.reset(new StorageCommitmentReports(lock.GetConfiguration().GetUnsignedIntegerParameter("StorageCommitmentReportsSize", 100))); | 269 storageCommitmentReports_.reset(new StorageCommitmentReports(lock.GetConfiguration().GetUnsignedIntegerParameter("StorageCommitmentReportsSize", 100))); |
270 | 270 |
271 // New option in Orthanc 1.7.0 | 271 // New options in Orthanc 1.7.0 |
272 transcodeDicomProtocol_ = lock.GetConfiguration().GetBooleanParameter("TranscodeDicomProtocol", true); | 272 transcodeDicomProtocol_ = lock.GetConfiguration().GetBooleanParameter("TranscodeDicomProtocol", true); |
273 builtinDecoderTranscoderOrder_ = StringToBuiltinDecoderTranscoderOrder(lock.GetConfiguration().GetStringParameter("BuiltinDecoderTranscoderOrder", "After")); | |
273 } | 274 } |
274 | 275 |
275 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); | 276 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); |
276 | 277 |
277 listeners_.push_back(ServerListener(luaListener_, "Lua")); | 278 listeners_.push_back(ServerListener(luaListener_, "Lua")); |
1173 | 1174 |
1174 | 1175 |
1175 ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& publicId, | 1176 ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& publicId, |
1176 unsigned int frameIndex) | 1177 unsigned int frameIndex) |
1177 { | 1178 { |
1178 // TODO => Reorder given the global parameter | 1179 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before) |
1180 { | |
1181 // Use Orthanc's built-in decoder, using the cache to speed-up | |
1182 // things on multi-frame images | |
1183 ServerContext::DicomCacheLocker locker(*this, publicId); | |
1184 std::unique_ptr<ImageAccessor> decoded( | |
1185 DicomImageDecoder::Decode(locker.GetDicom(), frameIndex)); | |
1186 if (decoded.get() != NULL) | |
1187 { | |
1188 return decoded.release(); | |
1189 } | |
1190 } | |
1179 | 1191 |
1180 #if ORTHANC_ENABLE_PLUGINS == 1 | 1192 #if ORTHANC_ENABLE_PLUGINS == 1 |
1181 if (HasPlugins() && | 1193 if (HasPlugins() && |
1182 GetPlugins().HasCustomImageDecoder()) | 1194 GetPlugins().HasCustomImageDecoder()) |
1183 { | 1195 { |
1184 // TODO: Store the raw buffer in the DicomCacheLocker | 1196 // TODO: Store the raw buffer in the DicomCacheLocker |
1185 std::string dicomContent; | 1197 std::string dicomContent; |
1186 ReadDicom(dicomContent, publicId); | 1198 ReadDicom(dicomContent, publicId); |
1187 | |
1188 std::unique_ptr<ImageAccessor> decoded( | 1199 std::unique_ptr<ImageAccessor> decoded( |
1189 GetPlugins().Decode(dicomContent.c_str(), dicomContent.size(), frameIndex)); | 1200 GetPlugins().Decode(dicomContent.c_str(), dicomContent.size(), frameIndex)); |
1190 if (decoded.get() != NULL) | 1201 if (decoded.get() != NULL) |
1191 { | 1202 { |
1192 return decoded.release(); | 1203 return decoded.release(); |
1193 } | 1204 } |
1194 else | 1205 else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1195 { | 1206 { |
1196 LOG(INFO) << "The installed image decoding plugins cannot handle an image, " | 1207 LOG(INFO) << "The installed image decoding plugins cannot handle an image, " |
1197 << "fallback to the built-in DCMTK decoder"; | 1208 << "fallback to the built-in DCMTK decoder"; |
1198 } | 1209 } |
1199 } | 1210 } |
1200 #endif | 1211 #endif |
1201 | 1212 |
1202 { | 1213 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1203 // Use Orthanc's built-in decoder, using the cache to speed-up | 1214 { |
1204 // things on multi-frame images | |
1205 ServerContext::DicomCacheLocker locker(*this, publicId); | 1215 ServerContext::DicomCacheLocker locker(*this, publicId); |
1206 return DicomImageDecoder::Decode(locker.GetDicom(), frameIndex); | 1216 return DicomImageDecoder::Decode(locker.GetDicom(), frameIndex); |
1207 } | 1217 } |
1218 else | |
1219 { | |
1220 return NULL; // Built-in decoder is disabled | |
1221 } | |
1208 } | 1222 } |
1209 | 1223 |
1210 | 1224 |
1211 ImageAccessor* ServerContext::DecodeDicomFrame(const DicomInstanceToStore& dicom, | 1225 ImageAccessor* ServerContext::DecodeDicomFrame(const DicomInstanceToStore& dicom, |
1212 unsigned int frameIndex) | 1226 unsigned int frameIndex) |
1213 { | 1227 { |
1214 // TODO => Reorder given the global parameter | 1228 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before) |
1229 { | |
1230 std::unique_ptr<ImageAccessor> decoded( | |
1231 DicomImageDecoder::Decode(dicom.GetParsedDicomFile(), frameIndex)); | |
1232 if (decoded.get() != NULL) | |
1233 { | |
1234 return decoded.release(); | |
1235 } | |
1236 } | |
1215 | 1237 |
1216 #if ORTHANC_ENABLE_PLUGINS == 1 | 1238 #if ORTHANC_ENABLE_PLUGINS == 1 |
1217 if (HasPlugins() && | 1239 if (HasPlugins() && |
1218 GetPlugins().HasCustomImageDecoder()) | 1240 GetPlugins().HasCustomImageDecoder()) |
1219 { | 1241 { |
1221 GetPlugins().Decode(dicom.GetBufferData(), dicom.GetBufferSize(), frameIndex)); | 1243 GetPlugins().Decode(dicom.GetBufferData(), dicom.GetBufferSize(), frameIndex)); |
1222 if (decoded.get() != NULL) | 1244 if (decoded.get() != NULL) |
1223 { | 1245 { |
1224 return decoded.release(); | 1246 return decoded.release(); |
1225 } | 1247 } |
1226 else | 1248 else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1227 { | 1249 { |
1228 LOG(INFO) << "The installed image decoding plugins cannot handle an image, " | 1250 LOG(INFO) << "The installed image decoding plugins cannot handle an image, " |
1229 << "fallback to the built-in DCMTK decoder"; | 1251 << "fallback to the built-in DCMTK decoder"; |
1230 } | 1252 } |
1231 } | 1253 } |
1232 #endif | 1254 #endif |
1233 | 1255 |
1234 return DicomImageDecoder::Decode(dicom.GetParsedDicomFile(), frameIndex); | 1256 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1257 { | |
1258 return DicomImageDecoder::Decode(dicom.GetParsedDicomFile(), frameIndex); | |
1259 } | |
1260 else | |
1261 { | |
1262 return NULL; | |
1263 } | |
1235 } | 1264 } |
1236 | 1265 |
1237 | 1266 |
1238 void ServerContext::StoreWithTranscoding(std::string& sopClassUid, | 1267 void ServerContext::StoreWithTranscoding(std::string& sopClassUid, |
1239 std::string& sopInstanceUid, | 1268 std::string& sopInstanceUid, |
1263 bool& hasSopInstanceUidChanged /* out */, | 1292 bool& hasSopInstanceUidChanged /* out */, |
1264 DcmFileFormat& dicom /* in, possibly modified */, | 1293 DcmFileFormat& dicom /* in, possibly modified */, |
1265 DicomTransferSyntax targetSyntax, | 1294 DicomTransferSyntax targetSyntax, |
1266 bool allowNewSopInstanceUid) | 1295 bool allowNewSopInstanceUid) |
1267 { | 1296 { |
1297 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before) | |
1298 { | |
1299 if (dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom, | |
1300 targetSyntax, allowNewSopInstanceUid)) | |
1301 { | |
1302 return true; | |
1303 } | |
1304 } | |
1305 | |
1268 #if ORTHANC_ENABLE_PLUGINS == 1 | 1306 #if ORTHANC_ENABLE_PLUGINS == 1 |
1269 if (HasPlugins()) | 1307 if (HasPlugins() && |
1308 GetPlugins().HasCustomTranscoder()) | |
1270 { | 1309 { |
1271 if (GetPlugins().TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom, | 1310 if (GetPlugins().TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom, |
1272 targetSyntax, allowNewSopInstanceUid)) | 1311 targetSyntax, allowNewSopInstanceUid)) |
1273 { | 1312 { |
1274 return true; | 1313 return true; |
1275 } | 1314 } |
1276 else | 1315 else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1277 { | 1316 { |
1278 LOG(INFO) << "The installed transcoding plugins cannot handle an image, " | 1317 LOG(INFO) << "The installed transcoding plugins cannot handle an image, " |
1279 << "fallback to the built-in DCMTK transcoder"; | 1318 << "fallback to the built-in DCMTK transcoder"; |
1280 } | 1319 } |
1281 } | 1320 } |
1282 #endif | 1321 #endif |
1283 | 1322 |
1284 return dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom, | 1323 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1285 targetSyntax, allowNewSopInstanceUid); | 1324 { |
1325 return dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom, | |
1326 targetSyntax, allowNewSopInstanceUid); | |
1327 } | |
1328 else | |
1329 { | |
1330 return false; | |
1331 } | |
1286 } | 1332 } |
1287 | 1333 |
1288 | 1334 |
1289 IDicomTranscoder::TranscodedDicom* | 1335 IDicomTranscoder::TranscodedDicom* |
1290 ServerContext::TranscodeToParsed(DcmFileFormat& dicom, | 1336 ServerContext::TranscodeToParsed(DcmFileFormat& dicom, |
1291 const void* buffer, | 1337 const void* buffer, |
1292 size_t size, | 1338 size_t size, |
1293 const std::set<DicomTransferSyntax>& allowedSyntaxes, | 1339 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
1294 bool allowNewSopInstanceUid) | 1340 bool allowNewSopInstanceUid) |
1295 { | 1341 { |
1342 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before) | |
1343 { | |
1344 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded( | |
1345 dcmtkTranscoder_->TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, | |
1346 allowNewSopInstanceUid)); | |
1347 if (transcoded.get() != NULL) | |
1348 { | |
1349 return transcoded.release(); | |
1350 } | |
1351 } | |
1352 | |
1296 #if ORTHANC_ENABLE_PLUGINS == 1 | 1353 #if ORTHANC_ENABLE_PLUGINS == 1 |
1297 if (HasPlugins()) | 1354 if (HasPlugins() && |
1355 GetPlugins().HasCustomTranscoder()) | |
1298 { | 1356 { |
1299 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded( | 1357 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded( |
1300 GetPlugins().TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid)); | 1358 GetPlugins().TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid)); |
1301 | 1359 |
1302 if (transcoded.get() != NULL) | 1360 if (transcoded.get() != NULL) |
1303 { | 1361 { |
1304 return transcoded.release(); | 1362 return transcoded.release(); |
1305 } | 1363 } |
1306 else | 1364 else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1307 { | 1365 { |
1308 LOG(INFO) << "The installed transcoding plugins cannot handle an image, " | 1366 LOG(INFO) << "The installed transcoding plugins cannot handle an image, " |
1309 << "fallback to the built-in DCMTK transcoder"; | 1367 << "fallback to the built-in DCMTK transcoder"; |
1310 } | 1368 } |
1311 } | 1369 } |
1312 #endif | 1370 #endif |
1313 | 1371 |
1314 return dcmtkTranscoder_->TranscodeToParsed( | 1372 if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) |
1315 dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid); | 1373 { |
1374 return dcmtkTranscoder_->TranscodeToParsed( | |
1375 dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid); | |
1376 } | |
1377 else | |
1378 { | |
1379 return NULL; | |
1380 } | |
1316 } | 1381 } |
1317 } | 1382 } |