#bluray: improve menuless playlist selection

From c11f3fcb34a8b7af864f4e2addcf28b0e7851605 Mon Sep 17 00:00:00 2001
From: Francois Cartegnie <fcartegnie@free.fr>
Date: Tue, 5 Feb 2019 14:40:07 +0100
Subject: [PATCH] improve main playlist guess

---
 src/libbluray/bdnav/navigation.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index f72d253..e48461a 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -71,6 +71,25 @@ _pl_chapter_count(MPLS_PL *pl)
     return chapters;
 }
 
+static uint32_t
+_pl_streams_score(MPLS_PL *pl)
+{
+    MPLS_PI *pi;
+    uint32_t i_num_audio = 0;
+    uint32_t i_num_pg = 0;
+
+    for (int ii = 0; ii < pl->list_count; ii++) {
+        pi = &pl->play_item[ii];
+        if(pi->stn.num_audio > i_num_audio)
+            i_num_audio= pi->stn.num_audio;
+
+        if(pi->stn.num_pg > i_num_pg)
+            i_num_pg = pi->stn.num_pg;
+    }
+
+    return i_num_audio * 2 + i_num_pg;
+}
+
 /*
  * Check if two playlists are the same
  */
@@ -353,7 +372,10 @@ static int _pl_guess_main_title(MPLS_PL *p1, MPLS_PL *p2,
         return -1;
     }
 
-    return 0;
+    /* prefer playlist with higher number of tracks */
+    int sc1 = _pl_streams_score(p1);
+    int sc2 = _pl_streams_score(p2);
+    return sc2 - sc1;
 }
 
 /*
-- 
2.20.1

