218 {
219
220
221
222 auto jsonValue = picojson::value{};
223 auto const err =
parseJson(jsonValue, in_flowDef);
224 if (!err.empty())
225 {
226 throw std::invalid_argument{"Invalid JSON flow definition. " + err};
227 }
228
229
230 if (!jsonValue.is<picojson::object>())
231 {
232 throw std::invalid_argument{"Expected a JSON Object"};
233 }
234 _root = jsonValue.get<picojson::object>();
235
236 auto id = uuids::uuid::from_string(fetchAs<std::string>(
_root,
"id"));
237 if (!id.has_value())
238 {
239 throw std::invalid_argument{"Invalid flow 'id'."};
240 }
241
243
244
245 _format = translateFlowFormat(fetchAs<std::string>(
_root,
"format"));
246
247
249 {
250 _grainRate = extractRational(fetchAs<picojson::object>(
_root,
"grain_rate"));
251 }
253 {
254 _grainRate = extractRational(fetchAs<picojson::object>(
_root,
"sample_rate"));
255 }
256 else
257 {
258 throw std::domain_error{"Unsupported flow format."};
259 }
260
261
263 {
265 }
266
267
268 auto const label = fetchAs<std::string>(
_root,
"label");
269 if (label.empty())
270 {
271 throw std::domain_error{"Empty flow label."};
272 }
273
274
275 if (!validateGroupHint(
_root))
276 {
277 throw std::domain_error{"Invalid or missing group hint tag."};
278 }
279
280
281
283 {
284 auto const width = fetchInteger<std::size_t>(
_root,
"frame_width");
285 auto const height = fetchInteger<std::size_t>(
_root,
"frame_height");
286
287 if ((width < 2) || (width > MAX_WIDTH) || (height < 1) || (height > MAX_HEIGHT))
288 {
289 auto msg = fmt::format("Invalid video dimensions: {}x{}. range is 2x1 to {}x{}", width, height, MAX_WIDTH, MAX_HEIGHT);
290 throw std::invalid_argument{std::move(msg)};
291 }
292
293 auto interlaceMode = std::string{};
294 if (
auto const it =
_root.find(
"interlace_mode"); it !=
_root.end())
295 {
296 interlaceMode = it->second.get<std::string>();
297 }
298 else
299 {
300
301
302 interlaceMode = "progressive";
303 }
304
305 constexpr auto validValues = std::array{"progressive", "interlaced_tff", "interlaced_bff"};
306 auto const match = std::ranges::any_of(validValues, [&](auto v) noexcept { return interlaceMode == v; });
307 if (!match)
308 {
309 auto msg = fmt::format("Invalid interlace_mode: {}", interlaceMode);
310 throw std::invalid_argument{std::move(msg)};
311 }
312
313 if ((interlaceMode == "interlaced_tff") || (interlaceMode == "interlaced_bff"))
314 {
315
317 {
318 auto msg = std::string{"Invalid grain_rate for interlaced video. Expected 30000/1001 or 25/1."};
319 throw std::invalid_argument{std::move(msg)};
320 }
321
322
325 }
326 }
327 }
std::string parseJson(picojson::value &out, std::string_view text, JsonLimits const &limits={})
struct mxlRational_t mxlRational