[libbluray-devel] Update selected audio and subtitle stream PSRs when not using menus.

hpi1 git at videolan.org
Fri Apr 8 15:49:36 CEST 2011


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Mar 21 13:34:48 2011 +0200| [eed8bfbf251140089dc632706141b9f39ecefa5f] | committer: hpi1

Update selected audio and subtitle stream PSRs when not using menus.
Selection is based on language setting PSRs and clip STN.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=eed8bfbf251140089dc632706141b9f39ecefa5f
---

 src/libbluray/bluray.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 93b954f..c33ed67 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -209,6 +209,74 @@ static int _queue_event(BLURAY *bd, BD_EVENT ev)
 }
 
 /*
+ * PSR utils
+ */
+
+static void _update_stream_psr_by_lang(BD_REGISTERS *regs,
+                                       uint32_t psr_lang, uint32_t psr_stream,
+                                       uint32_t enable_flag, uint32_t undefined_val,
+                                       MPLS_STREAM *streams, unsigned num_streams)
+{
+    uint32_t psr_val;
+    int      stream_idx = -1;
+    unsigned ii;
+
+    /* get preferred language */
+    psr_val = bd_psr_read(regs, psr_lang);
+    if (psr_val == 0xffffff) {
+        /* language setting not initialized */
+        return;
+    }
+
+    /* find stream */
+
+    for (ii = 0; ii < num_streams; ii++) {
+        if (psr_val == str_to_uint32((const char *)streams[ii].lang, 3)) {
+            stream_idx = ii;
+            break;
+        }
+    }
+
+    if (stream_idx < 0) {
+        /* requested language not found */
+        stream_idx = undefined_val - 1;
+        enable_flag = 0;
+    }
+
+    /* update PSR */
+
+    BD_DEBUG(DBG_BLURAY, "Selected stream %d (language %s)\n", ii, streams[ii].lang);
+
+    bd_psr_lock(regs);
+
+    psr_val = bd_psr_read(regs, psr_stream) & 0xffff0000;
+    psr_val |= (stream_idx + 1) | enable_flag;
+    bd_psr_write(regs, psr_stream, psr_val);
+
+    bd_psr_unlock(regs);
+}
+
+static void _update_clip_psrs(BLURAY *bd, NAV_CLIP *clip)
+{
+    bd_psr_write(bd->regs, PSR_PLAYITEM, clip->ref);
+    bd_psr_write(bd->regs, PSR_TIME,     clip->in_time);
+
+    /* Update selected audio and subtitle stream PSRs when not using menus.
+     * Selection is based on language setting PSRs and clip STN.
+     */
+    if (bd->title_type == title_undef) {
+        MPLS_STN *stn = &clip->title->pl->play_item[clip->ref].stn;
+
+        _update_stream_psr_by_lang(bd->regs,
+                                   PSR_AUDIO_LANG, PSR_PRIMARY_AUDIO_ID, 0, 0xff,
+                                   stn->audio, stn->num_audio);
+        _update_stream_psr_by_lang(bd->regs,
+                                   PSR_PG_AND_SUB_LANG, PSR_PG_STREAM, 0x80000000, 0xfff,
+                                   stn->pg, stn->num_pg);
+    }
+}
+
+/*
  * clip access (BD_STREAM)
  */
 
@@ -251,8 +319,7 @@ static int _open_m2ts(BLURAY *bd, BD_STREAM *st)
             }
 
             if (st == &bd->st0) {
-                bd_psr_write(bd->regs, PSR_PLAYITEM, st->clip->ref);
-                bd_psr_write(bd->regs, PSR_TIME,     st->clip->in_time);
+                _update_clip_psrs(bd, st->clip);
             }
 
             return 1;



More information about the libbluray-devel mailing list