Well, I took some more time looking around the VLC source and then changed a little bit the code which uses the input to do reference counting and locking (actually I am relying on the access functions for doing the latter). Bellow is the modified version.<div>
<div><br></div><div><div><div><div>---</div><div> modules/demux/subtitle.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++</div><div> 1 file changed, 68 insertions(+)</div><div><br></div><div>diff --git a/modules/demux/subtitle.c b/modules/demux/subtitle.c</div>
<div>index aa1c7e6..464f4e8 100644</div><div>--- a/modules/demux/subtitle.c</div><div>+++ b/modules/demux/subtitle.c</div><div>@@ -35,6 +35,7 @@</div><div> #include <vlc_plugin.h></div><div> #include <vlc_input.h></div>
<div> #include <vlc_memory.h></div><div>+#include <vlc_url.h></div><div> </div><div> #include <ctype.h></div><div> </div><div>@@ -223,6 +224,7 @@ static int Demux( demux_t * );</div><div> static int Control( demux_t *, int, va_list );</div>
<div> </div><div> static void Fix( demux_t * );</div><div>+static char * get_language_from_filename( const char *, const char * );</div><div> </div><div> /*****************************************************************************</div>
<div>  * Module initializer</div><div>@@ -529,6 +531,30 @@ static int Open ( vlc_object_t *p_this )</div><div>     }</div><div>     else</div><div>         es_format_Init( &fmt, SPU_ES, VLC_CODEC_SUBT );</div><div>+</div>
<div>+    /* Detecting subtitle language using its filename */</div><div>+    {</div><div>+        input_thread_t * p_input = demux_GetParentInput(p_demux);</div><div>+        char * psz_video_url = input_item_GetURI(input_GetItem(p_input));</div>
<div>+        vlc_object_release(p_input);</div><div>+</div><div>+        if ( psz_video_url )</div><div>+        {</div><div>+            char * psz_language = get_language_from_filename(</div><div>+                p_demux->psz_location,</div>
<div>+                psz_video_url</div><div>+</div><div>+            );</div><div>+            if( psz_language )</div><div>+            {</div><div>+                fmt.psz_language = psz_language;</div><div>+                msg_Dbg( p_demux, "detected language %s of subtitle: %s",</div>
<div>+                         psz_language, p_demux->psz_location );</div><div>+            }</div><div>+            free(psz_video_url);</div><div>+        }</div><div>+    }</div><div>+</div><div>     if( unicode )</div>
<div>         fmt.subs.psz_encoding = strdup( "UTF-8" );</div><div>     char *psz_description = var_InheritString( p_demux, "sub-description" );</div><div>@@ -2079,3 +2105,45 @@ static int ParseSubViewer1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx</div>
<div>     return VLC_SUCCESS;</div><div> }</div><div> </div><div>+static char * get_language_from_filename( const char * psz_sub_location,</div><div>+                                          const char * psz_video_url )</div>
<div>+{</div><div>+    char * psz_ret = NULL;</div><div>+    char * psz_video_file = NULL;</div><div>+    char * psz_sub_file = NULL;</div><div>+    char * psz_tmp;</div><div>+    char * psz_sub_suffix;</div><div>+    char * ps_language_end;</div>
<div>+</div><div>+    psz_video_file = strrchr( psz_video_url, '/' );</div><div>+    if( !psz_video_file ) goto end;</div><div>+    psz_video_file++;</div><div>+    psz_video_file = decode_URI_duplicate(psz_video_file);</div>
<div>+    if( !psz_video_file ) goto end;</div><div>+</div><div>+    psz_sub_file = strrchr( psz_sub_location, '/' );</div><div>+    if( !psz_sub_file ) goto end;</div><div>+    psz_sub_file++;</div><div>+    psz_sub_file = decode_URI_duplicate(psz_sub_file);</div>
<div>+    if( !psz_video_file ) goto end;</div><div>+</div><div>+    /* Removing extension, but leaving the dot */</div><div>+    psz_tmp = strrchr( psz_video_file, '.' );</div><div>+    if( !psz_tmp ) goto end;</div>
<div>+    psz_tmp[1] = '\0';</div><div>+</div><div>+    /* Extracting sub file prefix */</div><div>+    if( strstr(psz_sub_file, psz_video_file) != psz_sub_file ) goto end;</div><div>+    psz_sub_suffix = psz_sub_file + strlen(psz_video_file);</div>
<div>+</div><div>+    ps_language_end = strrchr( psz_sub_suffix, '.' );</div><div>+    if( !ps_language_end ) goto end;</div><div>+    *ps_language_end = '\0';</div><div>+</div><div>+    psz_ret = strdup(psz_sub_suffix);</div>
<div>+</div><div>+end:</div><div>+    FREENULL(psz_video_file);</div><div>+    FREENULL(psz_sub_file);</div><div>+    return psz_ret;</div><div>+}</div><div>-- </div></div></div></div><div><br></div>
</div>