Hi Rémi,<div><br></div><div>I felt the need to get the name of the video file, so that's why I used the input. Do you know any alternative for getting that name? Or do you think is best to use a strategy that does not require it? Any thoughts?</div>
<div><br></div><div>My first draft actually did not used the input, it only looked for the string between the last two dots in the file name. So, "video.x.avi" would output "x". The problem with that is the fact that many video files use dots instead of spaces as word separator, so the function might end up detecting something that is not actually the subtitle language. For example, in "cool.video.avi" that naive strategy would yield "video".<br>
<br>If I do need to go through the input, could you point me to some reference part of the code that does the necessary locking and ref counting?</div><div><br></div><div><br></div><div>Thanks<br><br><div class="gmail_quote">
On Sat, Feb 2, 2013 at 3:32 AM, Rémi Denis-Courmont <span dir="ltr"><<a href="mailto:remi@remlab.net" target="_blank">remi@remlab.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le vendredi 1 février 2013 22:46:16, Walter Cacau a écrit :<br>
<div><div class="h5">> A user who has many subtitles for a single video can now distinguish<br>
> between them by the suffix containing language information.<br>
><br>
> So, for example, suppose the user has a video file named "video.mp4".<br>
> If he names a subtitle as "video.en.srt", the English language will<br>
> be detected. Similarly, he can name other subtitles with different<br>
> languages, ex: "video.pt.srt", "video.pt-BR.srt", ...<br>
><br>
> If the subtitle name is equal to the video name (except for the<br>
> file extension), then no language is detected.<br>
><br>
> This change has the positive side effect of making the subtitle menu<br>
> show the detected language instead of only "Track X".<br>
> ---<br>
> modules/demux/subtitle.c | 57<br>
> ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57<br>
> insertions(+)<br>
><br>
> diff --git a/modules/demux/subtitle.c b/modules/demux/subtitle.c<br>
> index aa1c7e6..dd91dbe 100644<br>
> --- a/modules/demux/subtitle.c<br>
> +++ b/modules/demux/subtitle.c<br>
> @@ -35,6 +35,7 @@<br>
> #include <vlc_plugin.h><br>
> #include <vlc_input.h><br>
> #include <vlc_memory.h><br>
> +#include <vlc_url.h><br>
><br>
> #include <ctype.h><br>
><br>
> @@ -223,6 +224,7 @@ static int Demux( demux_t * );<br>
> static int Control( demux_t *, int, va_list );<br>
><br>
> static void Fix( demux_t * );<br>
> +static char * get_language_from_filename( const char *, const char * );<br>
><br>
> /*************************************************************************<br>
</div></div>> **** * Module initializer<br>
<div class="im">> @@ -529,6 +531,19 @@ static int Open ( vlc_object_t *p_this )<br>
> }<br>
> else<br>
> es_format_Init( &fmt, SPU_ES, VLC_CODEC_SUBT );<br>
> +<br>
> + /* Detecting subtitle language using its filename */<br>
> + char * psz_language = get_language_from_filename(<br>
> + p_demux->psz_location,<br>
> + input_GetItem(p_demux->p_input)->psz_uri<br>
> + );<br>
<br>
</div>Please leave the input alone; you don't need it to know your location. AFAIK,<br>
there might not even be an input. Also that code looks like it lacks reference<br>
counting and locking.<br>
<div class="HOEnZb"><div class="h5"><br>
> + if( psz_language )<br>
> + {<br>
> + fmt.psz_language = psz_language;<br>
> + msg_Dbg( p_demux, "detected language %s of subtitle: %s",<br>
> psz_language, + p_demux->psz_location );<br>
> + }<br>
> +<br>
> if( unicode )<br>
> fmt.subs.psz_encoding = strdup( "UTF-8" );<br>
> char *psz_description = var_InheritString( p_demux, "sub-description"<br>
> ); @@ -2079,3 +2094,45 @@ static int ParseSubViewer1( demux_t *p_demux,<br>
> subtitle_t *p_subtitle, int i_idx return VLC_SUCCESS;<br>
> }<br>
><br>
> +static char * get_language_from_filename( const char * psz_sub_location,<br>
> + const char * psz_video_url )<br>
> +{<br>
> + char * psz_ret = NULL;<br>
> + char * psz_video_file = NULL;<br>
> + char * psz_sub_file = NULL;<br>
> + char * psz_tmp;<br>
> + char * psz_sub_suffix;<br>
> + char * ps_language_end;<br>
> +<br>
> + psz_video_file = strrchr( psz_video_url, '/' );<br>
> + if( !psz_video_file ) goto end;<br>
> + psz_video_file++;<br>
> + psz_video_file = decode_URI_duplicate(psz_video_file);<br>
> + if( !psz_video_file ) goto end;<br>
> +<br>
> + psz_sub_file = strrchr( psz_sub_location, '/' );<br>
> + if( !psz_sub_file ) goto end;<br>
> + psz_sub_file++;<br>
> + psz_sub_file = decode_URI_duplicate(psz_sub_file);<br>
> + if( !psz_video_file ) goto end;<br>
> +<br>
> + /* Removing extension, but leaving the dot */<br>
> + psz_tmp = strrchr( psz_video_file, '.' );<br>
> + if( !psz_tmp ) goto end;<br>
> + psz_tmp[1] = '\0';<br>
> +<br>
> + /* Extracting sub file prefix */<br>
> + if( strstr(psz_sub_file, psz_video_file) != psz_sub_file ) goto end;<br>
> + psz_sub_suffix = psz_sub_file + strlen(psz_video_file);<br>
> +<br>
> + ps_language_end = strrchr( psz_sub_suffix, '.' );<br>
> + if( !ps_language_end ) goto end;<br>
> + *ps_language_end = '\0';<br>
> +<br>
> + psz_ret = strdup(psz_sub_suffix);<br>
> +<br>
> +end:<br>
> + FREENULL(psz_video_file);<br>
> + FREENULL(psz_sub_file);<br>
> + return psz_ret;<br>
> +}<br>
<br>
--<br>
</div></div><span class="HOEnZb"><font color="#888888">Rémi Denis-Courmont<br>
<a href="http://www.remlab.net/" target="_blank">http://www.remlab.net/</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Walter Carlos P. Cacau Filho<br>ITA T12 - Engenharia de Computaçăo<div><a href="mailto:waltercacau@gmail.com" target="_blank">waltercacau@gmail.com</a></div>
</div>