comparison OrthancServer/OrthancRestApi/OrthancRestArchive.cpp @ 3913:6ddad3e0b569 transcoding

transcoding ZIP archive and media
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 May 2020 19:15:28 +0200
parents 2a170a8f1faf
children
comparison
equal deleted inserted replaced
3912:7610af1532c3 3913:6ddad3e0b569
44 44
45 namespace Orthanc 45 namespace Orthanc
46 { 46 {
47 static const char* const KEY_RESOURCES = "Resources"; 47 static const char* const KEY_RESOURCES = "Resources";
48 static const char* const KEY_EXTENDED = "Extended"; 48 static const char* const KEY_EXTENDED = "Extended";
49 static const char* const KEY_TRANSCODE = "Transcode";
49 50
50 static void AddResourcesOfInterestFromArray(ArchiveJob& job, 51 static void AddResourcesOfInterestFromArray(ArchiveJob& job,
51 const Json::Value& resources) 52 const Json::Value& resources)
52 { 53 {
53 if (resources.type() != Json::arrayValue) 54 if (resources.type() != Json::arrayValue)
96 throw OrthancException(ErrorCode_BadFileFormat); 97 throw OrthancException(ErrorCode_BadFileFormat);
97 } 98 }
98 } 99 }
99 100
100 101
101 static void GetJobParameters(bool& synchronous, /* out */ 102 static DicomTransferSyntax GetTransferSyntax(const std::string& value)
102 bool& extended, /* out */ 103 {
103 int& priority, /* out */ 104 DicomTransferSyntax syntax;
104 const Json::Value& body, /* in */ 105 if (LookupTransferSyntax(syntax, value))
105 const bool defaultExtended /* in */) 106 {
107 return syntax;
108 }
109 else
110 {
111 throw OrthancException(ErrorCode_ParameterOutOfRange,
112 "Unknown transfer syntax: " + value);
113 }
114 }
115
116
117 static void GetJobParameters(bool& synchronous, /* out */
118 bool& extended, /* out */
119 bool& transcode, /* out */
120 DicomTransferSyntax& syntax, /* out */
121 int& priority, /* out */
122 const Json::Value& body, /* in */
123 const bool defaultExtended /* in */)
106 { 124 {
107 synchronous = OrthancRestApi::IsSynchronousJobRequest 125 synchronous = OrthancRestApi::IsSynchronousJobRequest
108 (true /* synchronous by default */, body); 126 (true /* synchronous by default */, body);
109 127
110 priority = OrthancRestApi::GetJobRequestPriority(body); 128 priority = OrthancRestApi::GetJobRequestPriority(body);
115 extended = SerializationToolbox::ReadBoolean(body, KEY_EXTENDED); 133 extended = SerializationToolbox::ReadBoolean(body, KEY_EXTENDED);
116 } 134 }
117 else 135 else
118 { 136 {
119 extended = defaultExtended; 137 extended = defaultExtended;
138 }
139
140 if (body.type() == Json::objectValue &&
141 body.isMember(KEY_TRANSCODE))
142 {
143 transcode = true;
144 syntax = GetTransferSyntax(SerializationToolbox::ReadString(body, KEY_TRANSCODE));
145 }
146 else
147 {
148 transcode = false;
120 } 149 }
121 } 150 }
122 151
123 152
124 static void SubmitJob(RestApiOutput& output, 153 static void SubmitJob(RestApiOutput& output,
173 ServerContext& context = OrthancRestApi::GetContext(call); 202 ServerContext& context = OrthancRestApi::GetContext(call);
174 203
175 Json::Value body; 204 Json::Value body;
176 if (call.ParseJsonRequest(body)) 205 if (call.ParseJsonRequest(body))
177 { 206 {
178 bool synchronous, extended; 207 bool synchronous, extended, transcode;
208 DicomTransferSyntax transferSyntax;
179 int priority; 209 int priority;
180 GetJobParameters(synchronous, extended, priority, body, DEFAULT_IS_EXTENDED); 210 GetJobParameters(synchronous, extended, transcode, transferSyntax,
211 priority, body, DEFAULT_IS_EXTENDED);
181 212
182 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); 213 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
183 AddResourcesOfInterest(*job, body); 214 AddResourcesOfInterest(*job, body);
215
216 if (transcode)
217 {
218 job->SetTranscode(transferSyntax);
219 }
220
184 SubmitJob(call.GetOutput(), context, job, priority, synchronous, "Archive.zip"); 221 SubmitJob(call.GetOutput(), context, job, priority, synchronous, "Archive.zip");
185 } 222 }
186 else 223 else
187 { 224 {
188 throw OrthancException(ErrorCode_BadFileFormat, 225 throw OrthancException(ErrorCode_BadFileFormat,
206 } 243 }
207 else 244 else
208 { 245 {
209 extended = false; 246 extended = false;
210 } 247 }
211 248
212 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); 249 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
213 job->AddResource(id); 250 job->AddResource(id);
251
252 static const char* const TRANSCODE = "transcode";
253 if (call.HasArgument(TRANSCODE))
254 {
255 job->SetTranscode(GetTransferSyntax(call.GetArgument(TRANSCODE, "")));
256 }
214 257
215 SubmitJob(call.GetOutput(), context, job, 0 /* priority */, 258 SubmitJob(call.GetOutput(), context, job, 0 /* priority */,
216 true /* synchronous */, id + ".zip"); 259 true /* synchronous */, id + ".zip");
217 } 260 }
218 261
226 std::string id = call.GetUriComponent("id", ""); 269 std::string id = call.GetUriComponent("id", "");
227 270
228 Json::Value body; 271 Json::Value body;
229 if (call.ParseJsonRequest(body)) 272 if (call.ParseJsonRequest(body))
230 { 273 {
231 bool synchronous, extended; 274 bool synchronous, extended, transcode;
275 DicomTransferSyntax transferSyntax;
232 int priority; 276 int priority;
233 GetJobParameters(synchronous, extended, priority, body, DEFAULT_IS_EXTENDED); 277 GetJobParameters(synchronous, extended, transcode, transferSyntax,
278 priority, body, DEFAULT_IS_EXTENDED);
234 279
235 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); 280 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended));
236 job->AddResource(id); 281 job->AddResource(id);
282
283 if (transcode)
284 {
285 job->SetTranscode(transferSyntax);
286 }
287
237 SubmitJob(call.GetOutput(), context, job, priority, synchronous, id + ".zip"); 288 SubmitJob(call.GetOutput(), context, job, priority, synchronous, id + ".zip");
238 } 289 }
239 else 290 else
240 { 291 {
241 throw OrthancException(ErrorCode_BadFileFormat); 292 throw OrthancException(ErrorCode_BadFileFormat);