]> git.sesse.net Git - vlc/blobdiff - modules/access/bluray.c
bluray: add an option to select player region code
[vlc] / modules / access / bluray.c
index da9e31452f29e2446726a6c7bab316406e1af462..2da09aa972dd707705269318593cb70d16ea1757 100644 (file)
@@ -46,7 +46,7 @@
 #include <vlc_atomic.h>
 #include <vlc_dialog.h>                     /* BD+/AACS warnings */
 #include <vlc_vout.h>                       /* vout_PutSubpicture / subpicture_t */
-#include <vlc_url.h>                       /* vlc_path2uri */
+#include <vlc_url.h>                        /* vlc_path2uri */
 
 #include <libbluray/bluray.h>
 #include <libbluray/keys.h>
  * Module descriptor
  *****************************************************************************/
 
-#define BD_MENU_TEXT        N_( "Bluray menus" )
-#define BD_MENU_LONGTEXT    N_( "Use bluray menus. If disabled, "\
+#define BD_MENU_TEXT        N_( "Blu-ray menus" )
+#define BD_MENU_LONGTEXT    N_( "Use Blu-ray menus. If disabled, "\
                                 "the movie will start directly" )
+#define BD_REGION_TEXT      N_( "Region code" )
+#define BD_REGION_LONGTEXT  N_( "Blu-Ray player region code. "\
+                                "Some discs can be played only with a correct region code.")
+
+static const char *const ppsz_region_code[] = {
+    "A", "B", "C" };
+static const char *const ppsz_region_code_text[] = {
+    "Region A", "Region B", "Region C" };
+
+#define REGION_DEFAULT   1   /* Index to region list. Actual region code is (1<<REGION_DEFAULT) */
 
 /* Callbacks */
 static int  blurayOpen ( vlc_object_t * );
 static void blurayClose( vlc_object_t * );
 
 vlc_module_begin ()
-    set_shortname( N_("BluRay") )
-    set_description( N_("Blu-Ray Disc support (libbluray)") )
+    set_shortname( N_("Blu-ray") )
+    set_description( N_("Blu-ray Disc support (libbluray)") )
 
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_ACCESS )
     set_capability( "access_demux", 200)
     add_bool( "bluray-menu", false, BD_MENU_TEXT, BD_MENU_LONGTEXT, false )
+    add_string( "bluray-region", ppsz_region_code[REGION_DEFAULT], BD_REGION_TEXT, BD_REGION_LONGTEXT, false)
+        change_string_list( ppsz_region_code, ppsz_region_code_text )
 
     add_shortcut( "bluray", "file" )
 
@@ -247,7 +259,7 @@ static int blurayOpen( vlc_object_t *object )
 
     /* Is it a bluray? */
     if (!disc_info->bluray_detected) {
-        error_msg = "Path doesn't appear to be a bluray";
+        error_msg = "Path doesn't appear to be a Blu-ray";
         goto error;
     }
 
@@ -260,7 +272,7 @@ static int blurayOpen( vlc_object_t *object )
     /* AACS */
     if (disc_info->aacs_detected) {
         if (!disc_info->libaacs_detected) {
-            error_msg = _("This Blu-Ray Disc needs a library for AACS decoding, "
+            error_msg = _("This Blu-ray Disc needs a library for AACS decoding, "
                       "and your system does not have it.");
             goto error;
         }
@@ -269,7 +281,7 @@ static int blurayOpen( vlc_object_t *object )
             if (disc_info->aacs_error_code) {
                 switch (disc_info->aacs_error_code) {
                     case BD_AACS_CORRUPTED_DISC:
-                        error_msg = _("BluRay Disc is corrupted.");
+                        error_msg = _("Blu-ray Disc is corrupted.");
                         break;
                     case BD_AACS_NO_CONFIG:
                         error_msg = _("Missing AACS configuration file!");
@@ -300,7 +312,7 @@ static int blurayOpen( vlc_object_t *object )
     /* BD+ */
     if (disc_info->bdplus_detected) {
         if (!disc_info->libbdplus_detected) {
-            error_msg = _("This Blu-Ray Disc needs a library for BD+ decoding, "
+            error_msg = _("This Blu-ray Disc needs a library for BD+ decoding, "
                       "and your system does not have it.");
             goto error;
         }
@@ -311,6 +323,12 @@ static int blurayOpen( vlc_object_t *object )
         }
     }
 
+    /* set player region code */
+    char *psz_region = var_InheritString(p_demux, "bluray-region");
+    unsigned int region = psz_region ? (psz_region[0] - 'A') : REGION_DEFAULT;
+    free(psz_region);
+    bd_set_player_setting(p_sys->bluray, BLURAY_PLAYER_SETTING_REGION_CODE, 1<<region);
+
     /* Get titles and chapters */
     p_sys->p_meta = bd_get_meta(p_sys->bluray);
     if (!p_sys->p_meta)
@@ -367,7 +385,7 @@ static int blurayOpen( vlc_object_t *object )
 
 error:
     if (error_msg)
-        dialog_Fatal(p_demux, _("Blu-Ray error"), "%s", error_msg);
+        dialog_Fatal(p_demux, _("Blu-ray error"), "%s", error_msg);
     blurayClose(object);
     return VLC_EGENERIC;
 }
@@ -605,7 +623,10 @@ static void subpictureUpdaterUpdate(subpicture_t *p_subpic,
 
     subpicture_region_t *p_src = p_overlay->p_regions;
     if (!p_src)
+    {
+        vlc_mutex_unlock(&p_overlay->lock);
         return;
+    }
 
     subpicture_region_t **p_dst = &(p_subpic->p_region);
     while (p_src != NULL) {
@@ -651,6 +672,15 @@ static int onMouseEvent(vlc_object_t *p_vout, const char *psz_var, vlc_value_t o
     return VLC_SUCCESS;
 }
 
+static int sendKeyEvent(demux_sys_t *p_sys, unsigned int key)
+{
+    mtime_t now = mdate();
+    if (bd_user_input(p_sys->bluray, now, key) < 0) {
+        return VLC_EGENERIC;
+    }
+    return VLC_SUCCESS;
+}
+
 /*****************************************************************************
  * libbluray overlay handling:
  *****************************************************************************/
@@ -1121,6 +1151,17 @@ static int blurayControl(demux_t *p_demux, int query, va_list args)
             return VLC_SUCCESS;
         }
 
+        case DEMUX_NAV_ACTIVATE:
+            return sendKeyEvent(p_sys, BD_VK_ENTER);
+        case DEMUX_NAV_UP:
+            return sendKeyEvent(p_sys, BD_VK_UP);
+        case DEMUX_NAV_DOWN:
+            return sendKeyEvent(p_sys, BD_VK_DOWN);
+        case DEMUX_NAV_LEFT:
+            return sendKeyEvent(p_sys, BD_VK_LEFT);
+        case DEMUX_NAV_RIGHT:
+            return sendKeyEvent(p_sys, BD_VK_RIGHT);
+
         case DEMUX_CAN_RECORD:
         case DEMUX_GET_FPS:
         case DEMUX_SET_GROUP: