Read info about source from source/flow_def
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -72,4 +73,55 @@ inline std::string make_audio_flow_def(
|
||||
}.dump();
|
||||
}
|
||||
|
||||
// Actual video format as written into the MXL flow_def.json by a source node.
|
||||
// Sink nodes use this to read width/height/fps from MXL instead of trusting config values.
|
||||
struct VideoFlowInfo {
|
||||
int width = 1920;
|
||||
int height = 1080;
|
||||
int fps_num = 25;
|
||||
int fps_den = 1;
|
||||
};
|
||||
|
||||
inline VideoFlowInfo read_video_flow_info(const std::string& domain, const std::string& flow_id) {
|
||||
VideoFlowInfo info;
|
||||
const std::string path = domain + "/" + flow_id + ".mxl-flow/flow_def.json";
|
||||
std::ifstream f(path);
|
||||
if (!f.is_open()) return info;
|
||||
const auto j = nlohmann::json::parse(f, nullptr, /*allow_exceptions=*/false);
|
||||
if (j.is_discarded()) return info;
|
||||
info.width = j.value("frame_width", 1920);
|
||||
info.height = j.value("frame_height", 1080);
|
||||
if (j.contains("grain_rate")) {
|
||||
info.fps_num = j["grain_rate"].value("numerator", 25);
|
||||
info.fps_den = j["grain_rate"].value("denominator", 1);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
// Actual audio format as written into the MXL flow_def.json by a source node.
|
||||
struct AudioFlowInfo {
|
||||
int sample_rate = 48000;
|
||||
int channels = 2;
|
||||
int samples_per_grain = 1920; // sample_rate * grain_rate_den / grain_rate_num
|
||||
};
|
||||
|
||||
inline AudioFlowInfo read_audio_flow_info(const std::string& domain, const std::string& flow_id) {
|
||||
AudioFlowInfo info;
|
||||
const std::string path = domain + "/" + flow_id + ".mxl-flow/flow_def.json";
|
||||
std::ifstream f(path);
|
||||
if (!f.is_open()) return info;
|
||||
const auto j = nlohmann::json::parse(f, nullptr, /*allow_exceptions=*/false);
|
||||
if (j.is_discarded()) return info;
|
||||
if (j.contains("sample_rate"))
|
||||
info.sample_rate = j["sample_rate"].value("numerator", 48000);
|
||||
info.channels = j.value("channel_count", 2);
|
||||
if (j.contains("grain_rate") && info.sample_rate > 0) {
|
||||
const int gr_num = j["grain_rate"].value("numerator", 25);
|
||||
const int gr_den = j["grain_rate"].value("denominator", 1);
|
||||
if (gr_num > 0)
|
||||
info.samples_per_grain = info.sample_rate * gr_den / gr_num;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
} // namespace dmf
|
||||
|
||||
Reference in New Issue
Block a user