Skip to content

Commit 5f0d67e

Browse files
author
Daniel Neto
committed
Add user-specific resolution handling and logging for encoding
1 parent 68b59cf commit 5f0d67e

File tree

3 files changed

+152
-11
lines changed

3 files changed

+152
-11
lines changed

objects/Format.php

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,65 @@ public static function getAvailableResolutionsInfo()
557557
return $resolutions;
558558
}
559559

560+
/**
561+
* Get available resolutions info with user group restrictions applied
562+
* Shows only the resolutions that will actually be encoded for the current user
563+
* @return array Array of resolution info considering user restrictions
564+
*/
565+
public static function getAvailableResolutionsInfoForUser()
566+
{
567+
$resolutions = [];
568+
$availableResolutions = Format::getAvailableResolutions();
569+
570+
// Get the final resolutions that will be used for encoding (with user restrictions)
571+
$finalResolutions = self::getSelectedResolutionsWithUserRestrictions();
572+
573+
foreach ($availableResolutions as $key => $resolution) {
574+
// Check if this resolution will actually be encoded for the current user
575+
$resolutionWillBeEncoded = (array_search($resolution, $finalResolutions, true) !== false);
576+
577+
if (!$resolutionWillBeEncoded) {
578+
continue; // Skip resolutions that won't be encoded
579+
}
580+
581+
$label = "<span class='label label-";
582+
583+
// Different color based on user permissions
584+
require_once __DIR__ . '/Login.php';
585+
$userAllowedResolutions = Login::getAllowedResolutions();
586+
587+
if (empty($userAllowedResolutions) || in_array($resolution, $userAllowedResolutions)) {
588+
$label .= "success"; // Green for allowed resolutions
589+
} else {
590+
$label .= "default"; // Gray for encoder-only resolutions
591+
}
592+
593+
$label .= "'>{$resolution}p ";
594+
595+
// Add quality indicators
596+
if ($resolution == 720) {
597+
$label .= '<span class="label label-danger">HD</span>';
598+
} elseif ($resolution == 1080) {
599+
$label .= '<span class="label label-danger">FHD</span>';
600+
} elseif ($resolution == 1440) {
601+
$label .= '<span class="label label-danger">FHD+</span>';
602+
} elseif ($resolution == 2160) {
603+
$label .= '<span class="label label-danger">4K</span>';
604+
}
605+
$label .= " </span>";
606+
607+
$resolutions[] = array(
608+
'resolutionChecked' => 'checked', // All returned resolutions will be encoded
609+
'label' => $label,
610+
'resolution' => $resolution,
611+
);
612+
}
613+
614+
_error_log("Format::getAvailableResolutionsInfoForUser - Final resolutions for display: " . json_encode(array_column($resolutions, 'resolution')));
615+
616+
return $resolutions;
617+
}
618+
560619
public static function sanitizeResolutions($resolutions)
561620
{
562621
if (is_array($resolutions)) {
@@ -609,6 +668,58 @@ private static function getSelectedResolutions()
609668
return $result;
610669
}
611670

671+
/**
672+
* Get final resolutions to encode based on user restrictions and encoder settings
673+
* @param array|null $userAllowedResolutions Resolutions from login response
674+
* @param array $encoderEnabledResolutions Resolutions enabled in encoder
675+
* @return array Final resolutions to use
676+
*/
677+
private static function getFinalResolutions($userAllowedResolutions, $encoderEnabledResolutions) {
678+
// Se não há restrições do usuário, usar as do encoder
679+
if (empty($userAllowedResolutions) || !is_array($userAllowedResolutions)) {
680+
_error_log("Format::getFinalResolutions - No user restrictions, using encoder resolutions: " . json_encode($encoderEnabledResolutions));
681+
return $encoderEnabledResolutions;
682+
}
683+
684+
// Calcular intersecção (apenas as que estão em ambos)
685+
$finalResolutions = array_intersect($userAllowedResolutions, $encoderEnabledResolutions);
686+
687+
// Se não há nenhuma resolução em comum, usar as do encoder (fallback)
688+
if (empty($finalResolutions)) {
689+
_error_log("Format::getFinalResolutions - No intersection, fallback to encoder resolutions. User: " . json_encode($userAllowedResolutions) . " Encoder: " . json_encode($encoderEnabledResolutions));
690+
return $encoderEnabledResolutions;
691+
}
692+
693+
// Remover duplicatas e ordenar
694+
$finalResolutions = array_unique($finalResolutions);
695+
sort($finalResolutions);
696+
697+
_error_log("Format::getFinalResolutions - Final resolutions after filtering. User: " . json_encode($userAllowedResolutions) . " Encoder: " . json_encode($encoderEnabledResolutions) . " Final: " . json_encode($finalResolutions));
698+
699+
return $finalResolutions;
700+
}
701+
702+
/**
703+
* Get selected resolutions with user group restrictions applied
704+
* @return array Final resolutions to use for encoding
705+
*/
706+
private static function getSelectedResolutionsWithUserRestrictions()
707+
{
708+
// Get encoder configured resolutions
709+
$encoderResolutions = self::getSelectedResolutions();
710+
711+
// Get user allowed resolutions from login session
712+
require_once __DIR__ . '/Login.php';
713+
$userAllowedResolutions = Login::getAllowedResolutions();
714+
715+
// Apply user restrictions
716+
$finalResolutions = self::getFinalResolutions($userAllowedResolutions, $encoderResolutions);
717+
718+
_error_log("Format::getSelectedResolutionsWithUserRestrictions - User allowed: " . json_encode($userAllowedResolutions) . " Encoder enabled: " . json_encode($encoderResolutions) . " Final: " . json_encode($finalResolutions));
719+
720+
return $finalResolutions;
721+
}
722+
612723
static function loadEncoderConfiguration()
613724
{
614725
$availableConfiguration = self::getAvailableConfigurations();
@@ -618,7 +729,8 @@ static function loadEncoderConfiguration()
618729
$audioBitrate = [];
619730
$videoFramerate = [];
620731

621-
$selectedResolutions = self::getSelectedResolutions();
732+
// Use the new method that applies user group restrictions
733+
$selectedResolutions = self::getSelectedResolutionsWithUserRestrictions();
622734

623735
sort($selectedResolutions);
624736

@@ -631,6 +743,13 @@ static function loadEncoderConfiguration()
631743
array_push($videoFramerate, $availableConfiguration["videoFramerate"][$key]);
632744
}
633745

746+
_error_log("Format::loadEncoderConfiguration - Final encoder config: " . json_encode(array(
747+
"resolutions" => $resolutions,
748+
"bandwidth" => $bandwidth,
749+
"audioBitrate" => $audioBitrate,
750+
"videoFramerate" => $videoFramerate
751+
)));
752+
634753
return array(
635754
"resolutions" => $resolutions,
636755
"bandwidth" => $bandwidth,

objects/Login.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ private static function modifyUrl($url) {
1313
if (strpos($url, '/live?p=') !== false) {
1414
$parsedUrl = parse_url($url);
1515
$path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
16-
16+
1717
// Remove everything after the last '/' before '/live?p='
1818
$path = substr($path, 0, strrpos($path, '/live?p='));
19-
19+
2020
return $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $path . '/';
2121
}
2222
return $url;
@@ -246,6 +246,23 @@ static function getStreamerId() {
246246
return intval($_SESSION['login']->streamers_id);
247247
}
248248

249+
/**
250+
* Get allowed resolutions for the logged user from login session
251+
* @return array|null Array of allowed resolutions or null if not set
252+
*/
253+
static function getAllowedResolutions() {
254+
if (!static::isLogged()) {
255+
return null;
256+
}
257+
258+
// Check if allowedResolutions exists in session
259+
if (!empty($_SESSION['login']->allowedResolutions) && is_array($_SESSION['login']->allowedResolutions)) {
260+
return $_SESSION['login']->allowedResolutions;
261+
}
262+
263+
return null;
264+
}
265+
249266
}
250267

251-
}
268+
}

view/index_shareVideos.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
?>
6363
<div class="form-group">
6464
<div style="display: flex;">
65-
<?php
65+
<?php
6666
echo getCategoriesSelect('download_categories_id');
6767
?>
6868
</div>
@@ -113,7 +113,7 @@
113113
?>
114114
<div class="form-group">
115115
<div style="display: flex;">
116-
<?php
116+
<?php
117117
echo getCategoriesSelect('bulk_categories_id');
118118
?>
119119
</div>
@@ -131,13 +131,18 @@
131131
<div class="panel-footer">
132132
<div class="availableResolutionsLabels">
133133
<?php
134-
$resolutionsInfo = Format::getAvailableResolutionsInfo();
134+
// Show resolutions that will actually be encoded for this user
135+
$resolutionsInfo = Format::getAvailableResolutionsInfoForUser();
135136

136-
foreach ($resolutionsInfo as $value) {
137-
if (empty($value['resolutionChecked'])) {
138-
continue;
137+
if (!empty($resolutionsInfo)) {
138+
foreach ($resolutionsInfo as $value) {
139+
if (empty($value['resolutionChecked'])) {
140+
continue;
141+
}
142+
echo $value['label'] . ' ';
139143
}
140-
echo $value['label'];
144+
} else {
145+
echo '<small class="text-warning">' . __('No resolutions available for encoding') . '</small>';
141146
}
142147
?>
143148
</div>

0 commit comments

Comments
 (0)