Changeset 236ca7aea13a438f92c245565208c9bb6ff9e11c
- Timestamp:
- 08/02/05 18:00:18 (4 years ago)
- git-parent:
- Files:
-
- modules/access/dvdnav.c (modified) (6 diffs)
- src/input/es_out.c (modified) (14 diffs)
- src/input/var.c (modified) (1 diff)
- src/libvlc.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/access/dvdnav.c
rd5eacbe r236ca7a 46 46 #include "iso_lang.h" 47 47 48 /* FIXME we should find a better way than including that */ 49 #include "../../src/misc/iso-639_def.h" 50 51 48 52 #include <dvdnav/dvdnav.h> 49 53 … … 65 69 "Allows you to start the DVD directly in the main menu. This "\ 66 70 "will try to skip all the useless warnings introductions." ) 71 72 #define LANGUAGE_DEFAULT ("en") 67 73 68 74 static int Open ( vlc_object_t * ); … … 146 152 static int ProbeDVD( demux_t *, char * ); 147 153 154 static char *DemuxGetLanguageCode( demux_t *p_demux, char *psz_var ); 155 148 156 /***************************************************************************** 149 157 * DemuxOpen: … … 156 164 int i_angle; 157 165 char *psz_name; 166 char *psz_code; 158 167 vlc_value_t val; 159 168 … … 234 243 } 235 244 236 if( dvdnav_menu_language_select (p_sys->dvdnav,"en") != DVDNAV_STATUS_OK || 237 dvdnav_audio_language_select(p_sys->dvdnav,"en") != DVDNAV_STATUS_OK || 238 dvdnav_spu_language_select (p_sys->dvdnav,"en") != DVDNAV_STATUS_OK ) 239 { 240 msg_Warn( p_demux, "something failed while setting en language (%s)", 245 /* Set menu language ("en") 246 * XXX: maybe it would be better to set it like audio/spu or to create a --menu-language option */ 247 if( dvdnav_menu_language_select( p_sys->dvdnav,LANGUAGE_DEFAULT ) != DVDNAV_STATUS_OK ) 248 { 249 msg_Warn( p_demux, "something failed while setting menu '%s' language (%s)", 250 LANGUAGE_DEFAULT, 241 251 dvdnav_err_to_string( p_sys->dvdnav ) ); 242 252 } 253 254 /* Set audio language */ 255 psz_code = DemuxGetLanguageCode( p_demux, "audio-language" ); 256 if( dvdnav_audio_language_select(p_sys->dvdnav, psz_code ) != DVDNAV_STATUS_OK ) 257 { 258 msg_Warn( p_demux, "something failed while setting audio '%s' language (%s)", 259 psz_code, 260 dvdnav_err_to_string( p_sys->dvdnav ) ); 261 /* We try to fall back to 'en' */ 262 if( strcmp( psz_code, LANGUAGE_DEFAULT ) ) 263 dvdnav_audio_language_select(p_sys->dvdnav, LANGUAGE_DEFAULT ); 264 } 265 free( psz_code ); 266 267 /* Set spu language */ 268 psz_code = DemuxGetLanguageCode( p_demux, "spu-language" ); 269 if( dvdnav_spu_language_select( p_sys->dvdnav,psz_code ) != DVDNAV_STATUS_OK ) 270 { 271 msg_Warn( p_demux, "something failed while setting spu '%s' language (%s)", 272 psz_code, 273 dvdnav_err_to_string( p_sys->dvdnav ) ); 274 /* We try to fall back to 'en' */ 275 if( strcmp( psz_code, LANGUAGE_DEFAULT ) ) 276 dvdnav_spu_language_select(p_sys->dvdnav, LANGUAGE_DEFAULT ); 277 } 278 free( psz_code ); 243 279 244 280 DemuxTitles( p_demux ); … … 733 769 } 734 770 771 /* Get a 2 char code 772 * FIXME: partiallyy duplicated from src/input/es_out.c 773 */ 774 static char *DemuxGetLanguageCode( demux_t *p_demux, char *psz_var ) 775 { 776 const iso639_lang_t *pl; 777 char *psz_lang; 778 char *p; 779 780 psz_lang = var_CreateGetString( p_demux, psz_var ); 781 /* XXX: we will use only the first value (and ignore other ones in case of a list) */ 782 if( ( p = strchr( psz_lang, "," ) ) ) 783 *p = '\0'; 784 785 for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ ) 786 { 787 if( !strcasecmp( pl->psz_eng_name, psz_lang ) || 788 !strcasecmp( pl->psz_native_name, psz_lang ) || 789 !strcasecmp( pl->psz_iso639_1, psz_lang ) || 790 !strcasecmp( pl->psz_iso639_2T, psz_lang ) || 791 !strcasecmp( pl->psz_iso639_2B, psz_lang ) ) 792 break; 793 } 794 795 free( psz_lang ); 796 797 if( pl->psz_iso639_1 != NULL ) 798 return strdup( pl->psz_iso639_1 ); 799 800 return strdup(LANGUAGE_DEFAULT); 801 } 802 735 803 static void DemuxTitles( demux_t *p_demux ) 736 804 { src/input/es_out.c
r47cc1b2 r236ca7a 1 2 1 /***************************************************************************** 3 2 * es_out.c: Es Out handler for input. … … 36 35 #include "vlc_playlist.h" 37 36 #include "iso_lang.h" 37 /* FIXME we should find a better way than including that */ 38 #include "../misc/iso-639_def.h" 38 39 39 40 /***************************************************************************** … … 65 66 es_format_t fmt; 66 67 char *psz_language; 68 char *psz_language_code; 67 69 decoder_t *p_dec; 68 70 }; … … 95 97 int i_audio_last; 96 98 int i_sub_last; 99 char **ppsz_audio_language; 100 char **ppsz_sub_language; 97 101 98 102 /* current main es */ … … 117 121 static void EsUnselect( es_out_t *out, es_out_id_t *es, vlc_bool_t b_update ); 118 122 static char *LanguageGetName( const char *psz_code ); 123 static char *LanguageGetCode( const char *psz_lang ); 124 static char **LanguageSplit( const char *psz_langs ); 125 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang ); 119 126 120 127 /***************************************************************************** … … 126 133 es_out_sys_t *p_sys = malloc( sizeof( es_out_sys_t ) ); 127 134 vlc_value_t val; 135 int i; 128 136 129 137 out->pf_add = EsOutAdd; … … 151 159 p_sys->i_sub = 0; 152 160 161 /* */ 153 162 var_Get( p_input, "audio-channel", &val ); 154 163 p_sys->i_audio_last = val.i_int; … … 157 166 p_sys->i_sub_last = val.i_int; 158 167 168 var_Get( p_input, "audio-language", &val ); 169 p_sys->ppsz_audio_language = LanguageSplit(val.psz_string); 170 if( p_sys->ppsz_audio_language ) 171 { 172 for( i = 0; p_sys->ppsz_audio_language[i]; i++ ) 173 msg_Dbg( p_input, "Select audio in language[%d] %s", 174 i, p_sys->ppsz_audio_language[i] ); 175 } 176 177 var_Get( p_input, "spu-language", &val ); 178 p_sys->ppsz_sub_language = LanguageSplit(val.psz_string); 179 if( p_sys->ppsz_sub_language ) 180 { 181 for( i = 0; p_sys->ppsz_sub_language[i]; i++ ) 182 msg_Dbg( p_input, "Select subtitle in language[%d] %s", 183 i, p_sys->ppsz_sub_language[i] ); 184 } 185 186 /* */ 159 187 p_sys->p_es_audio = NULL; 160 188 p_sys->p_es_video = NULL; … … 183 211 if( p_sys->es[i]->psz_language ) 184 212 free( p_sys->es[i]->psz_language ); 213 if( p_sys->es[i]->psz_language_code ) 214 free( p_sys->es[i]->psz_language_code ); 185 215 es_format_Clean( &p_sys->es[i]->fmt ); 186 216 187 217 free( p_sys->es[i] ); 188 218 } 219 if( p_sys->ppsz_audio_language ) 220 { 221 for( i = 0; p_sys->ppsz_audio_language[i]; i++ ) 222 free( p_sys->ppsz_audio_language[i] ); 223 free( p_sys->ppsz_audio_language ); 224 } 225 if( p_sys->ppsz_sub_language ) 226 { 227 for( i = 0; p_sys->ppsz_sub_language[i]; i++ ) 228 free( p_sys->ppsz_sub_language[i] ); 229 free( p_sys->ppsz_sub_language ); 230 } 231 189 232 if( p_sys->es ) 190 233 free( p_sys->es ); … … 306 349 { 307 350 if( es->psz_language && *es->psz_language ) 308 {309 text.psz_string = malloc( strlen( es->fmt.psz_description) + strlen( es->psz_language ) + 10 );310 sprintf( text.psz_string, "%s - [%s]", es->fmt.psz_description, es->psz_language );311 }312 else text.psz_string = strdup( es->fmt.psz_description );351 { 352 text.psz_string = malloc( strlen( es->fmt.psz_description) + strlen( es->psz_language ) + 10 ); 353 sprintf( text.psz_string, "%s - [%s]", es->fmt.psz_description, es->psz_language ); 354 } 355 else text.psz_string = strdup( es->fmt.psz_description ); 313 356 } 314 357 else … … 494 537 } 495 538 es->psz_language = LanguageGetName( fmt->psz_language ); /* remember so we only need to do it once */ 539 es->psz_language_code = LanguageGetCode( fmt->psz_language ); 496 540 es->p_dec = NULL; 497 541 … … 668 712 if( i_cat == AUDIO_ES ) 669 713 { 714 int idx1 = LanguageArrayIndex( p_sys->ppsz_audio_language, 715 es->psz_language_code ); 716 670 717 if( p_sys->p_es_audio && 671 718 p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority ) 672 719 { 673 return; 674 } 675 i_wanted = p_sys->i_audio_last >= 0 ? 676 p_sys->i_audio_last : es->i_channel; 720 int idx2 = LanguageArrayIndex( p_sys->ppsz_audio_language, 721 p_sys->p_es_audio->psz_language_code ); 722 723 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) ) 724 return; 725 i_wanted = es->i_channel; 726 } 727 else 728 { 729 /* Select audio if (no audio selected yet) 730 * - no audio-language 731 * - no audio code for the ES 732 * - audio code in the requested list */ 733 if( idx1 >= 0 || 734 !strcmp( es->psz_language_code, "??" ) || 735 !p_sys->ppsz_audio_language ) 736 i_wanted = es->i_channel; 737 } 738 739 if( p_sys->i_audio_last >= 0 ) 740 i_wanted = p_sys->i_audio_last; 677 741 } 678 742 else if( i_cat == SPU_ES ) 679 743 { 744 int idx1 = LanguageArrayIndex( p_sys->ppsz_sub_language, 745 es->psz_language_code ); 746 680 747 if( p_sys->p_es_sub && 681 p_sys->p_es_sub->fmt.i_priority >= 682 es->fmt.i_priority ) 683 { 684 return; 685 } 686 i_wanted = p_sys->i_sub_last; 748 p_sys->p_es_sub->fmt.i_priority >= es->fmt.i_priority ) 749 { 750 int idx2 = LanguageArrayIndex( p_sys->ppsz_sub_language, 751 p_sys->p_es_sub->psz_language_code ); 752 753 msg_Dbg( p_sys->p_input, "idx1=%d(%s) idx2=%d(%s)", 754 idx1, es->psz_language_code, idx2, 755 p_sys->p_es_sub->psz_language_code ); 756 757 if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) ) 758 return; 759 /* We found a SPU that matches our language request */ 760 i_wanted = es->i_channel; 761 } 762 else if( idx1 >= 0 ) 763 { 764 msg_Dbg( p_sys->p_input, "idx1=%d(%s)", 765 idx1, es->psz_language_code ); 766 767 i_wanted = es->i_channel; 768 } 769 if( p_sys->i_sub_last >= 0 ) 770 i_wanted = p_sys->i_sub_last; 687 771 } 688 772 else if( i_cat == VIDEO_ES ) … … 833 917 if( es->psz_language ) 834 918 free( es->psz_language ); 919 if( es->psz_language_code ) 920 free( es->psz_language_code ); 835 921 836 922 es_format_Clean( &es->fmt ); … … 1133 1219 } 1134 1220 1221 /* Get a 2 char code */ 1222 static char *LanguageGetCode( const char *psz_lang ) 1223 { 1224 const iso639_lang_t *pl; 1225 1226 if( psz_lang == NULL || *psz_lang == '\0' ) 1227 return strdup("??"); 1228 1229 for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ ) 1230 { 1231 if( !strcasecmp( pl->psz_eng_name, psz_lang ) || 1232 !strcasecmp( pl->psz_native_name, psz_lang ) || 1233 !strcasecmp( pl->psz_iso639_1, psz_lang ) || 1234 !strcasecmp( pl->psz_iso639_2T, psz_lang ) || 1235 !strcasecmp( pl->psz_iso639_2B, psz_lang ) ) 1236 break; 1237 } 1238 1239 if( pl->psz_iso639_1 != NULL ) 1240 return strdup( pl->psz_iso639_1 ); 1241 1242 return strdup("??"); 1243 } 1244 1245 static char **LanguageSplit( const char *psz_langs ) 1246 { 1247 char *psz_dup; 1248 char *psz_parser; 1249 char **ppsz = NULL; 1250 int i_psz = 0; 1251 1252 if( psz_langs == NULL ) 1253 return NULL; 1254 1255 psz_parser = psz_dup = strdup(psz_langs); 1256 1257 while( psz_parser && *psz_parser ) 1258 { 1259 char *psz; 1260 char *psz_code; 1261 1262 psz = strchr(psz_parser, ',' ); 1263 if( psz ) 1264 { 1265 *psz++ = '\0'; 1266 } 1267 1268 psz_code = LanguageGetCode( psz_parser ); 1269 if( strcmp( psz_code, "??" ) ) 1270 { 1271 TAB_APPEND( i_psz, ppsz, psz_code ); 1272 } 1273 1274 psz_parser = psz; 1275 } 1276 1277 if( i_psz ) 1278 { 1279 TAB_APPEND( i_psz, ppsz, NULL ); 1280 } 1281 1282 return ppsz; 1283 } 1284 1285 static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang ) 1286 { 1287 int i; 1288 1289 if( !ppsz_langs || !psz_lang ) 1290 return -1; 1291 1292 for( i = 0; ppsz_langs[i]; i++ ) 1293 if( !strcasecmp( ppsz_langs[i], psz_lang ) ) 1294 return i; 1295 1296 return -1; 1297 } 1298 1135 1299 /**************************************************************************** 1136 1300 * EsOutAddInfo: src/input/var.c
r534a812 r236ca7a 401 401 var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT ); 402 402 403 var_Create( p_input, "audio-language", VLC_VAR_STRING|VLC_VAR_DOINHERIT ); 404 var_Create( p_input, "spu-language", VLC_VAR_STRING|VLC_VAR_DOINHERIT ); 405 403 406 var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT ); 404 407 var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL | src/libvlc.h
r44d19ee r236ca7a 328 328 329 329 #define INPUT_SUB_TEXT N_("Choose subtitles track") 330 #define INPUT_CHAN_LANG_TEXT N_("Choose audio language") 331 #define INPUT_CHAN_LANG_LONGTEXT N_( \ 332 "Give the language of the audio channel you want to use " \ 333 "(comma separted, two or tree letter country code).") 334 #define INPUT_SUB_LANG_TEXT N_("Choose subtitle track") 335 #define INPUT_SUB_LANG_LONGTEXT N_( \ 336 "Give the language of the subtitle channel you want to use " \ 337 "(comma separted, two or tree letter country code).") 338 339 330 340 #define INPUT_SUB_LONGTEXT N_( \ 331 341 "Give the stream number of the subtitle channel you want to use " \ … … 980 990 add_integer( "spu-channel", -1, NULL, 981 991 INPUT_SUB_TEXT, INPUT_SUB_LONGTEXT, VLC_FALSE ); 992 add_string( "audio-language", "", NULL, 993 INPUT_CHAN_LANG_TEXT, INPUT_CHAN_LANG_LONGTEXT, VLC_FALSE ); 994 add_string( "spu-language", "", NULL, 995 INPUT_SUB_LANG_TEXT, INPUT_SUB_LANG_LONGTEXT, VLC_FALSE ); 996 982 997 983 998 set_section( N_( "Playback control" ) , NULL);
