@@ -281,6 +281,42 @@ static void stream_camera(struct camera_portal_source *camera_source)
281281 obs_pipewire_connect_stream (connection -> obs_pw , camera_source -> source , device -> id , & connect_info );
282282}
283283
284+ static double gcd (uint32_t m , uint32_t n )
285+ {
286+ if (n == 0 )
287+ return m ;
288+
289+ return gcd (n , m % n );
290+ }
291+
292+ static struct dstr aspect_ratio_from_spa_rectangle (struct spa_rectangle rect )
293+ {
294+ struct dstr str = {};
295+ double divisor = gcd (rect .width , rect .height );
296+
297+ if (divisor <= 50 ) {
298+ if (rect .width > rect .height ) {
299+ double x = (double )rect .width / (double )rect .height ;
300+ dstr_printf (& str , "%.2f:1" , x );
301+ } else {
302+ double y = (double )rect .height / (double )rect .width ;
303+ dstr_printf (& str , "1:%.2f" , y );
304+ }
305+ } else {
306+ uint32_t x = rect .width / (uint32_t )divisor ;
307+ uint32_t y = rect .height / (uint32_t )divisor ;
308+
309+ if (x == 8 && y == 5 ) {
310+ x = 16 ;
311+ y = 10 ;
312+ }
313+
314+ dstr_printf (& str , "%u:%u" , x , y );
315+ }
316+
317+ return str ;
318+ }
319+
284320static void camera_format_list (struct camera_device * dev , obs_property_t * prop )
285321{
286322 struct param * p ;
@@ -291,6 +327,7 @@ static void camera_format_list(struct camera_device *dev, obs_property_t *prop)
291327 spa_list_for_each (p , & dev -> param_list , link )
292328 {
293329 struct dstr str = {};
330+ struct dstr aspect_ratio ;
294331 uint32_t media_type , media_subtype ;
295332 uint32_t format = 0 ;
296333 const char * format_name ;
@@ -372,7 +409,15 @@ static void camera_format_list(struct camera_device *dev, obs_property_t *prop)
372409 continue ;
373410 }
374411
375- dstr_printf (& str , "%ux%u - " , resolution .width , resolution .height );
412+ dstr_printf (& str , "%ux%u" , resolution .width , resolution .height );
413+
414+ aspect_ratio = aspect_ratio_from_spa_rectangle (resolution );
415+ if (aspect_ratio .len != 0 ) {
416+ dstr_catf (& str , " (%s)" , aspect_ratio .array );
417+ dstr_free (& aspect_ratio );
418+ }
419+
420+ dstr_cat (& str , " - " );
376421
377422 for (int i = framerates -> len - 1 ; i >= 0 ; i -- ) {
378423 const struct spa_fraction * framerate = & g_array_index (framerates , struct spa_fraction , i );
0 commit comments