Skip to content
Snippets Groups Projects
Commit 7a975c8c authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Choose preset from source resolution

parent 07da9d6e
No related branches found
No related tags found
1 merge request!143Implements #210 Choose definition from source resolution
Pipeline #15924 passed
......@@ -40,9 +40,11 @@ enum struct definition_t : uint8_t {
LD360 = 6,
Any = 7,
HTC_VIVE = 8
HTC_VIVE = 8,
// TODO: Add audio definitions
Invalid
};
/**
......@@ -87,6 +89,8 @@ static const preset_t kPresetLQThreshold = 4;
static const preset_t kPresetHTCVive = -1;
static const preset_t kPresetMinimum = -1;
/**
* Represents the details of each preset codec configuration.
*/
......@@ -125,6 +129,8 @@ preset_t findPreset(definition_t, definition_t);
*/
preset_t findPreset(definition_t);
preset_t findPreset(size_t width, size_t height);
}
}
......
......@@ -41,7 +41,8 @@ static const Resolution resolutions[] = {
854, 480, // SD480
640, 360, // LD360
0, 0, // ANY
1852, 2056 // HTC_VIVE
1852, 2056, // HTC_VIVE
0, 0
};
int ftl::codecs::getWidth(definition_t d) {
......@@ -57,4 +58,32 @@ const CodecPreset &ftl::codecs::getPreset(preset_t p) {
if (p > kPresetWorst) return presets[kPresetWorst];
if (p < kPresetBest) return presets[kPresetBest];
return presets[p];
};
}
preset_t ftl::codecs::findPreset(size_t width, size_t height) {
int min_error = std::numeric_limits<int>::max();
// Find best definition
int best_def = (int)definition_t::Invalid;
for (int i=0; i<(int)definition_t::Invalid; ++i) {
int dw = resolutions[i].width - width;
int dh = resolutions[i].height - height;
int error = dw*dw + dh*dh;
if (error < min_error) {
min_error = error;
best_def = i;
}
}
// Find preset that matches this best definition
for (preset_t i=kPresetMinimum; i<=kPresetWorst; ++i) {
const auto &preset = getPreset(i);
if ((int)preset.colour_res == best_def && (int)preset.depth_res == best_def) {
return i;
}
}
return kPresetWorst;
}
......@@ -189,6 +189,12 @@ void Streamer::add(Source *src) {
group_.addSource(src);
src->addRawCallback([this,s](Source *src, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) {
if (spkt.channel == Channel::Calibration) {
// Calibration changed, so lets re-check the bitrate presets
const auto &params = src->parameters();
s->hq_bitrate = ftl::codecs::findPreset(params.width, params.height);
}
//LOG(INFO) << "RAW CALLBACK";
_transmitPacket(s, spkt, pkt, Quality::Any);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment