My version of ChooseBestResolution
#1
i have been using and testing this version of choosebestresolution for a while now and it works ok for me. this version doesn't use the 'autoswitch widescreen' option but chooses the best resolution according to the video aspect ratio and the bios settings (read this topic). i think the 'upsample to gui res' should also be removed (just remove the test at the begining of the function).
i hope this can be of some use.
comments ? suggestions ?

Quote:void cxboxrenderer::choosebestresolution(float fps)
{
 // this function implements the following rules :
 //
 // bios settings     ||display resolution
 // ws|480p|720p/1080i||4:3 videos     |16:6 videos
 // ------------------||------------------------------
 // - | x  |    x     || 480p 4:3      | 720p
 // - | x  |    -     || 480p 4:3      | 480p 4:3
 // - | -  |    x     || 720p          | 720p
 // - | -  |    -     || ntsc/pal 4:3  |ntsc/pal 4:3
 // x | x  |    x     || 720p          | 720p
 // x | x  |    -     || 480p 4:3      | 480p 16:9
 // x | -  |    x     || 720p          | 720p
 // x | -  |    -     || ntsc/pal 4:3  |ntsc/pal 16:9

 bool busingpal = g_videoconfig.haspal();    // current video standard:pal or ntsc
 bool bcandowidescreen = g_videoconfig.haswidescreen(); // can widescreen be enabled?
 bool bwidescreenmode = false;

 // if we use gui resolution then do nothing (should be removed ?)
 if (g_guisettings.getbool("videoplayer.useguiresolution"))
 {
   m_iresolution = g_graphicscontext.getvideoresolution();
   return;
 }

 // work out if the framerate suits pal50 or pal60
 bool bpal60 = false;
 if (busingpal && g_guisettings.getint("myvideos.framerateconversions") == frame_rate_use_pal60 && g_videoconfig.haspal60())
 {
   // yes we're in pal
   // yes pal60 is allowed
   // yes dashboard pal60 settings is enabled
   // calculate the framerate difference from a divisor of 120fps and 100fps
   // (twice 60fps and 50fps to allow for 2:3 ivtc pulldown)
   float fframedifference60 = abs(120.0f / fps - floor(120.0f / fps + 0.5f));
   float fframedifference50 = abs(100.0f / fps - floor(100.0f / fps + 0.5f));
   // make a decision based on the framerate difference
   if (fframedifference60 < fframedifference50)
     bpal60 = true;
 }

 // work out if framesize suits 4:3 or 16:9
 // uses the frame aspect ratio of 8/(3*sqrt(3)) (=1.53960) which is the optimal point
 // where the percentage of black bars to screen area in 4:3 and 16:9 is equal
 if (bcandowidescreen && m_fsourceframeratio > 8.0f / (3.0f*sqrt(3.0f)))
   bwidescreenmode = true;

 // we are allowed to switch video resolutions, so we must
 // now decide which is the best resolution for the video we have
 if (busingpal)  // pal resolutions
 {

   // currently does not allow hdtv solutions, as it is my belief
   // that the xbox hardware only allows hdtv resolutions for ntsc systems.
   // this may need revising as more knowledge is obtained.
   if (bpal60)
   {
     if (bwidescreenmode)
       m_iresolution = pal60_16x9;
     else
       m_iresolution = pal60_4x3;
   }
   else    // pal50
   {
     if (bwidescreenmode)
       m_iresolution = pal_16x9;
     else
       m_iresolution = pal_4x3;
   }
 }
 else      // ntsc resolutions
 {
   if (bcandowidescreen)
   { // the tv set has a wide screen (16:9)
     // so we always choose the best hd widescreen resolution no matter what
     // the video aspect ratio is
     // if the tv has no hd support widescreen mode is chossen according to video ar

     if (g_videoconfig.has1080i())     // widescreen tv with 1080i res
       m_iresolution = hdtv_1080i;
     else if (g_videoconfig.has720p()) // widescreen tv with 720p res
       m_iresolution = hdtv_720p;
     else if (g_videoconfig.has480p()) // widescreen tv with 480p
     {
       if (bwidescreenmode) // choose widescreen mode according to video ar
         m_iresolution = hdtv_480p_16x9;
       else
         m_iresolution = hdtv_480p_4x3;
     }
     else if (bwidescreenmode)         // standard 16:9 tv set with no hd
       m_iresolution = ntsc_16x9;
     else
       m_iresolution = ntsc_4x3;
   }
   else
   { // the tv set has a 4:3 aspect ratio
     // so 4:3 video sources will best fit the screen with 4:3 resolution
     // we choose 16:9 resolution only for 16:9 video sources

     if (m_fsourceframeratio >= 16.0f / 9.0f)
     {
       // the video fits best into widescreen modes so they are
       // the first choices
       if (g_videoconfig.has1080i())
         m_iresolution = hdtv_1080i;
       else if (g_videoconfig.has720p())
         m_iresolution = hdtv_720p;
       else if (g_videoconfig.has480p())
         m_iresolution = hdtv_480p_4x3;
       else
         m_iresolution = ntsc_4x3;
     }
     else
     {
       // the video fits best into 4:3 modes so 480p
       // is the first choice
       if (g_videoconfig.has480p())
         m_iresolution = hdtv_480p_4x3;
       else if (g_videoconfig.has1080i())
         m_iresolution = hdtv_1080i;
       else if (g_videoconfig.has720p())
         m_iresolution = hdtv_720p;
       else
         m_iresolution = ntsc_4x3;
     }
   }
 }
Reply
#2
a couple of comments:

1. don't use 16/9 as your test for "widescreen" in the case of non-widescreen tv's - use the optimal value of 8/(3*sqrt(3)) - i'd use this a const float with the actual value so we don't need the sqrt (not that this function gets called much, but still...)

2. i'm not sure if 1080i should be prioritized over 720p. the reason is in hardware overlays mode, we only use 1920x540 - ie decreased vertical resolution than 720p mode, which i believe is easier to pick up than the decrease in horizontal resolution when going to 720p.

3. i agree the upsample to gui resolution option should be removed, but i'd prefer it to be replaced with a single setting incorporating the widescreen setting as well:

* if on a non-hd system (ie no 720p or 1080i) then you can have: 4x3, 16x9, auto as options (auto choosing the "best" option based on source aspect ratio etc.)
* if on a hd system, then you can choose: 480p (both options), 720p, 1080i, auto (where auto chooses the "best" option based on frame size and aspect ratio.)
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
thx for your comments.

1. i disagree. i think that for non widescreen tv 16/9 should be used instead of 8/(3*sqrt(3)). if you switch to 16:9 mode on a 4:3 tv for a video that has an aspect ratio less than 16/9 the picture will look smaller on the screen. if you stay in 4:3 mode you'll get black bars on top and bottom only. if you switch to 16:9 mode you'll get black bars on top and bottom but also on the left and right of the screen. i am wrong ?

2. i don't really know... but don't you think that users with 1080i devices will want 1080i no matter what ? most people don't really care about small details like video scaling problems... they bought 1080i they want 1080i Smile

3. i agree. an option like 'display resolution :' should be available where the user could choose between auto and all other available resolutions.
Reply
#4
1. yes, you are wrong - the 16x9 modes don't care about what size the tv frame is, so will only produce black bars left and right (who's area is less than those that would be top and bottom on a 4x3 set). in fact, it doesn't actually matter - the widescreen flag is superfluous in this case as the hd modes are always widescreen, so they either shouldn't be an option here, or our bcandowidescreen should include this fact.

2. possibly - it is at least consistent with the "auto" setting in the gui resolution, so we should probably keep it the same.

3. Smile i'll work on it when i get a chance - if you get time, please do up a patch.

cheers,
jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#5
markeen,

Quote:most people don't really care about small details like video scaling problems... they bought 1080i they want 1080i

a false assumption is the mother of all fuckups.

sollie.



Image
Reply
#6
1. i'm having a hard time explaining myself in english so let me try to use a drawing. here is what is happening with my 4:3 projector which supports 16:9 modes like 720p and 1080i. i know i shouldn't use 720p and 1080i with a 800x600 resolution (which i don't anymore) but the point is that it is a possible configuration.
so what is happening when i want to display a 1.56 ar video ? if the 8/(3*sqrt(3)) switch value is used xbmc will switch to 16:9 mode which will take only a portion of the 4:3 display and then xbmc will fit the video into a portion of the 16:9 mode. the result is a significantly smaller picture than if xbmc had tried to fit it into a 4:3 mode.

Image

sorry if if i am a little insistant about this matter but it's what is happening with my system. i don't want to be right at all costs i just want to completly understand the problem. and i am a slow learner...

3. sorry i didn't mean to say that you should do it. i am interested so i'll look into it but it'll probably take you less than an hour to do when it'll take about the same time for me just to understand the relations between the skin and the settings classes... slow learner again.
Reply
#7
ok so i finally took the time to implement the 'display resolution' spin control where the user can choose between auto and all other available resolutions. i also removed the 'upsample to gui res' and 'widescreen switching' options. ex: auto/1080i 16:9/720p 16:9/480p 16:9/480p 4:3/ntsc 16:9/ntsc 4:3
i didn't change the auto algorithm for now.
the modification impacts the following files :
string.xml
guisettings.cpp
guiwindowsettingscategory.cpp
xboxrenderer.cpp

is there a dev out there willing to try this mod and maybe incorporate it ?
Reply
#8
please post it on sourceforge. whole files is preferable to diffs as things tend to change fairly fast.

i'll take a look at it sometime this week.

btw: your situation is very much unique - you are using a 4:3 "set" that can handle 720p modes but does not use the whole frame for these. i'd say this is probably less than 0.01% of all display devices. perhaps i'll add the setting to switch between 16:9 and 4:3 to the advanced settings section (not in the gui, xml only) so that you can set this manually.

cheers,
jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#9
(jmarshall @ feb. 12 2006,21:40 Wrote:your situation is very much unique - you are using a 4:3 "set" that can handle 720p modes but does not use the whole frame for these. i'd say this is probably less than 0.01% of all display devices.
jmarshall is correct, the 720p term assumes a widescreen aspect ratio of 16:9. only a few very tv models that where early adaptors of 720p (and did not follow the standard!Wink are 4:3, and the same goes for 1080i.

this has been discussed before on a couple of occations:
http://www.xboxmediaplayer.de/cgi-bin....2;t=543
http://www.xboxmediaplayer.de/cgi-bin....;t=2371

(jmarshall @ mar. 24 2004,20:58 Wrote:720p and 1080i should only be used for 16x9 screenmodes, as this is what they are.  they each have a pixel ratio of 1:1 (ie square pixels) and due to the number of pixels, they have a frame aspect ratio of 16:9.

unfortunately, due to the fact that they were introduced at a time when many tv manufacturers hadn't yet fully switched to widescreen formats, there were a generation of 4:3 televisions which came with 1080i in 4:3, with usually the option to compress the image into a 16:9 frame size (leaving bars top + bottom).

just because you can display a 4x3 image with a 720p or 1080i source, doesn't mean you should.

certainly there should be nothing encoded in 720p/1080i that should be displayed in anything other than a 16x9 framesize.

if you want to achieve 4x3 display ratio in xbmc, you can alter the pixel ratio using the calibration tool to achieve a pixel ratio of 0.75 which should do the trick.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#10
my mod can be found here but it is currently broken (as is the 'resolution' setting) due to the modification in the text spincontrol. see my post here
edit : i also mailed my mod to deanrparry at his request.
edit2 : ok not broken anymore... i don't know what happened (sleep needed maybe)

concerning my 'unique' tv set :
i agree with most of what has been said here but i think there is still a misunderstanding here. my 4:3 projector follows the standard by the book. it doesn't try to do 720p 4:3. it does 'real' 720p as my little drawing describes. when it is in 720p mode it is unable to display anything in the upper and lower 'black' bars. actually those bars are not even part of the projected picture. nothing is projected into thoese black bars not even black pixels.
i think that most 4:3 tv don't support wide hd modes (720p/1080i) and there i agree that only a small percentage of users have such devices. but how do you suppose xbmc should handle such devices ? my solution is to switch to these modes only for 16/9 videos (but only for 4:3 devices which supports wide hd modes). i don't see how this could be in conflict with other configurations. can you give me an example where my solution doesn't work ?



Reply
#11
i updated the patch cleaning up the code a little bit. and merged with the todays cvs (20-02-2006).
any feedback ?
Reply
#12
link doesn't work.

try uploading to www.xboxmediaplayer.it/upload.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#13
sorry for the bad link. the correct one is this.
i also uploaded it to www.xboxmediaplayer.it/upload
Reply

Logout Mark Read Team Forum Stats Members Help
My version of ChooseBestResolution0