changeset 21600:ca8327c8d1fb

added dvdnav_aid_from_lang() to support -alang
author nicodvb
date Thu, 14 Dec 2006 22:11:43 +0000
parents fe48c337a269
children 9bfe006bef97
files stream/stream_dvdnav.c stream/stream_dvdnav.h
diffstat 2 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/stream/stream_dvdnav.c	Thu Dec 14 18:14:57 2006 +0000
+++ b/stream/stream_dvdnav.c	Thu Dec 14 22:11:43 2006 +0000
@@ -473,6 +473,50 @@
 }
 
 /**
+ * \brief dvdnav_aid_from_lang() returns the audio id corresponding to the language code 'lang'
+ * \param stream: - stream pointer
+ * \param lang: 2-characters language code[s], eventually separated by spaces of commas
+ * \return -1 on error, current subtitle id if successful
+ */
+int dvdnav_aid_from_lang(stream_t *stream, unsigned char *language) {
+  dvdnav_priv_t * priv=(dvdnav_priv_t*)stream->priv;
+  int k;
+  uint8_t format, lg;
+  uint16_t lang, lcode;;
+
+#ifdef DVDNAV_FORMAT_AC3
+  //this macro is defined only in libdvdnav-cvs
+  while(language && strlen(language)>=2) {
+    lcode = (language[0] << 8) | (language[1]);
+    for(k=0; k<32; k++) {
+      lg = dvdnav_get_audio_logical_stream(priv->dvdnav, k);
+      if(lg == 0xff) continue;
+      lang = dvdnav_audio_stream_to_lang(priv->dvdnav, lg);
+      if(lang != 0xFFFF && lang == lcode) {
+        format = dvdnav_audio_stream_format(priv->dvdnav, lg);
+        switch(format) {
+          case DVDNAV_FORMAT_AC3:
+            return k+128;
+          case DVDNAV_FORMAT_DTS:
+            return k+136;
+          case DVDNAV_FORMAT_LPCM:
+            return k+160;
+          case DVDNAV_FORMAT_MPEGAUDIO:
+            return k;
+          default:
+            return -1;
+        }
+      }
+    }
+    language += 2;
+    while(language[0]==',' || language[0]==' ') ++language;
+  }
+#endif
+  return -1;
+}
+
+
+/**
  * \brief dvdnav_sid_from_lang() returns the subtitle id corresponding to the language code 'lang'
  * \param stream: - stream pointer
  * \param lang: 2-characters language code[s], eventually separated by spaces of commas
--- a/stream/stream_dvdnav.h	Thu Dec 14 18:14:57 2006 +0000
+++ b/stream/stream_dvdnav.h	Thu Dec 14 22:11:43 2006 +0000
@@ -30,6 +30,7 @@
 
 
 int dvdnav_number_of_subs(stream_t *stream);
+int dvdnav_aid_from_lang(stream_t *stream, unsigned char *language);
 int dvdnav_sid_from_lang(stream_t *stream, unsigned char *language);
 int dvdnav_lang_from_sid(stream_t *stream, int sid, unsigned char *buf);
 int mp_dvdnav_handle_input(stream_t *stream, int cmd, int *button);