@@ -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 ,
0 commit comments