changeset 31609:cd81fce1f010

Make the stream language an argument to the stream creation function so that some code can be shared.
author reimar
date Sat, 10 Jul 2010 18:47:59 +0000
parents ad007a37ae4e
children 9e2c61ae171f
files libmpdemux/asfheader.c libmpdemux/aviheader.c libmpdemux/demux_aac.c libmpdemux/demux_audio.c libmpdemux/demux_avs.c libmpdemux/demux_film.c libmpdemux/demux_lavf.c libmpdemux/demux_lmlm4.c libmpdemux/demux_mkv.c libmpdemux/demux_mov.c libmpdemux/demux_mpc.c libmpdemux/demux_mpg.c libmpdemux/demux_nemesi.c libmpdemux/demux_nsv.c libmpdemux/demux_nut.c libmpdemux/demux_ogg.c libmpdemux/demux_pva.c libmpdemux/demux_rawaudio.c libmpdemux/demux_rawdv.c libmpdemux/demux_real.c libmpdemux/demux_realaud.c libmpdemux/demux_roq.c libmpdemux/demux_smjpeg.c libmpdemux/demux_ts.c libmpdemux/demux_ty.c libmpdemux/demux_viv.c libmpdemux/demux_vqf.c libmpdemux/demux_xmms.c libmpdemux/demuxer.c libmpdemux/stheader.h
diffstat 30 files changed, 58 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/asfheader.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/asfheader.c	Sat Jul 10 18:47:59 2010 +0000
@@ -440,7 +440,7 @@
       le2me_ASF_stream_header_t(streamh);
       audio_pos += 64; //16+16+4+4+4+16+4;
       buffer = &hdr[audio_pos];
-      sh_audio=new_sh_audio(demuxer,streamh->stream_no & 0x7F);
+      sh_audio=new_sh_audio(demuxer,streamh->stream_no & 0x7F, NULL);
       sh_audio->needs_parsing = 1;
       mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "asfheader", streamh->stream_no & 0x7F);
       ++audio_streams;
@@ -478,7 +478,7 @@
     if (pos > hdr_len) goto len_err_out;
     switch(ASF_LOAD_GUID_PREFIX(streamh->type)){
       case ASF_GUID_PREFIX_audio_stream: {
-        sh_audio_t* sh_audio=new_sh_audio(demuxer,streamh->stream_no & 0x7F);
+        sh_audio_t* sh_audio=new_sh_audio(demuxer,streamh->stream_no & 0x7F, NULL);
         mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "asfheader", streamh->stream_no & 0x7F);
         ++audio_streams;
         if (!asf_init_audio_stream(demuxer, asf, sh_audio, streamh, &pos, &buffer, hdr, hdr_len))
--- a/libmpdemux/aviheader.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/aviheader.c	Sat Jul 10 18:47:59 2010 +0000
@@ -206,7 +206,7 @@
         sh_video->stream_delay = (float)sh_video->video.dwStart * sh_video->video.dwScale/sh_video->video.dwRate;
       } else
       if(h.fccType==streamtypeAUDIO){
-        sh_audio=new_sh_audio(demuxer,stream_id);
+        sh_audio=new_sh_audio(demuxer,stream_id, NULL);
         mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "aviheader", stream_id);
         memcpy(&sh_audio->audio,&h,sizeof(h));
         sh_audio->stream_delay = (float)sh_audio->audio.dwStart * sh_audio->audio.dwScale/sh_audio->audio.dwRate;
--- a/libmpdemux/demux_aac.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_aac.c	Sat Jul 10 18:47:59 2010 +0000
@@ -127,7 +127,7 @@
 {
 	sh_audio_t *sh;
 
-	sh = new_sh_audio(demuxer, 0);
+	sh = new_sh_audio(demuxer, 0, NULL);
 	sh->ds = demuxer->audio;
 	sh->format = mmioFOURCC('M', 'P', '4', 'A');
 	demuxer->audio->id = 0;
--- a/libmpdemux/demux_audio.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_audio.c	Sat Jul 10 18:47:59 2010 +0000
@@ -326,7 +326,7 @@
   if(!frmt)
     return 0;
 
-  sh_audio = new_sh_audio(demuxer,0);
+  sh_audio = new_sh_audio(demuxer,0, NULL);
 
   switch(frmt) {
   case MP3:
--- a/libmpdemux/demux_avs.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_avs.c	Sat Jul 10 18:47:59 2010 +0000
@@ -324,7 +324,7 @@
       }
     if (audio_samplesize)
     {
-        sh_audio_t *sh_audio = new_sh_audio(demuxer, 0);
+        sh_audio_t *sh_audio = new_sh_audio(demuxer, 0, NULL);
         found = 1;
         mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Clip has audio -> Channels = %d - Freq = %d\n", AVS->video_info->nchannels, AVS->video_info->audio_samples_per_second);
 
--- a/libmpdemux/demux_film.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_film.c	Sat Jul 10 18:47:59 2010 +0000
@@ -321,7 +321,7 @@
         if (audio_channels > 0)
         {
           // create and initialize the audio stream header
-          sh_audio = new_sh_audio(demuxer, 0);
+          sh_audio = new_sh_audio(demuxer, 0, NULL);
           demuxer->audio->id = 0;
           demuxer->audio->sh = sh_audio;
           sh_audio->ds = demuxer->audio;
@@ -353,7 +353,7 @@
         // otherwise, make some assumptions about the audio
 
         // create and initialize the audio stream header
-        sh_audio = new_sh_audio(demuxer, 0);
+        sh_audio = new_sh_audio(demuxer, 0, NULL);
         demuxer->audio->sh = sh_audio;
         sh_audio->ds = demuxer->audio;
 
--- a/libmpdemux/demux_lavf.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_lavf.c	Sat Jul 10 18:47:59 2010 +0000
@@ -271,7 +271,7 @@
         case CODEC_TYPE_AUDIO:{
             WAVEFORMATEX *wf;
             sh_audio_t* sh_audio;
-            sh_audio = new_sh_audio_aid(demuxer, i, priv->audio_streams);
+            sh_audio = new_sh_audio_aid(demuxer, i, priv->audio_streams, lang ? lang->value : NULL);
             if(!sh_audio)
                 break;
             stream_type = "audio";
@@ -329,10 +329,6 @@
             }
             if (title && title->value)
                 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n", priv->audio_streams, title->value);
-            if (lang && lang->value) {
-              sh_audio->lang = strdup(lang->value);
-              mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_LANG=%s\n", priv->audio_streams, sh_audio->lang);
-            }
             if (st->disposition & AV_DISPOSITION_DEFAULT)
               sh_audio->default_track = 1;
             if(mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
@@ -432,7 +428,7 @@
                 type = 'p';
             else
                 break;
-            sh_sub = new_sh_sub_sid(demuxer, i, priv->sub_streams);
+            sh_sub = new_sh_sub_sid(demuxer, i, priv->sub_streams, lang ? lang->value : NULL);
             if(!sh_sub) break;
             stream_type = "subtitle";
             priv->sstreams[priv->sub_streams] = i;
@@ -444,10 +440,6 @@
             }
             if (title && title->value)
                 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_NAME=%s\n", priv->sub_streams, title->value);
-            if (lang && lang->value) {
-              sh_sub->lang = strdup(lang->value);
-              mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", priv->sub_streams, sh_sub->lang);
-            }
             if (st->disposition & AV_DISPOSITION_DEFAULT)
               sh_sub->default_track = 1;
             stream_id = priv->sub_streams++;
--- a/libmpdemux/demux_lmlm4.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_lmlm4.c	Sat Jul 10 18:47:59 2010 +0000
@@ -247,7 +247,7 @@
             return -1; //goto hdr;
         }
 	if(demux->audio->id==-1){
-	    if(!demux->a_streams[id]) new_sh_audio(demux,id);
+	    if(!demux->a_streams[id]) new_sh_audio(demux,id, NULL);
 	    demux->audio->id=id;
 	    demux->audio->sh=demux->a_streams[id];
 	    ((sh_audio_t*)(demux->audio->sh))->format=0x50; // mpeg audio layer 1/2
@@ -320,7 +320,7 @@
     sh_video->bih->biCompression = sh_video->format;
     sh_video->bih->biSizeImage = sh_video->disp_w*sh_video->disp_h;
 
-    sh_audio = new_sh_audio(demuxer, 0);
+    sh_audio = new_sh_audio(demuxer, 0, NULL);
     demuxer->audio->sh = sh_audio;
     sh_audio->ds = demuxer->audio;
 
--- a/libmpdemux/demux_mkv.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_mkv.c	Sat Jul 10 18:47:59 2010 +0000
@@ -1414,8 +1414,6 @@
             if (mkv_d->tracks[i]->name)
                 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n", aid,
                        mkv_d->tracks[i]->name);
-            mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_LANG=%s\n", aid,
-                   mkv_d->tracks[i]->language);
             sprintf(str, "-aid %u, -alang %.5s", aid++,
                     mkv_d->tracks[i]->language);
             break;
@@ -1610,14 +1608,13 @@
                                 int aid)
 {
     mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
-    sh_audio_t *sh_a = new_sh_audio_aid(demuxer, track->tnum, aid);
+    sh_audio_t *sh_a = new_sh_audio_aid(demuxer, track->tnum, aid,
+                                        track->language);
     demux_packet_t *dp;
     if (!sh_a)
         return 1;
     mkv_d->audio_tracks[mkv_d->last_aid] = track->tnum;
 
-    if (track->language && (strcmp(track->language, "und") != 0))
-        sh_a->lang = strdup(track->language);
     sh_a->default_track = track->default_track;
     sh_a->ds = demuxer->audio;
     sh_a->wf = malloc(sizeof(WAVEFORMATEX));
@@ -1898,7 +1895,7 @@
     if (track->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN) {
         int size, m;
         uint8_t *buffer;
-        sh_sub_t *sh = new_sh_sub_sid(demuxer, track->tnum, sid);
+        sh_sub_t *sh = new_sh_sub_sid(demuxer, track->tnum, sid, track->language);
         track->sh_sub = sh;
         sh->type = 't';
         if (track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB)
@@ -1915,8 +1912,6 @@
         sh->extradata = malloc(track->private_size);
         memcpy(sh->extradata, track->private_data, track->private_size);
         sh->extradata_len = track->private_size;
-        if (track->language && (strcmp(track->language, "und") != 0))
-            sh->lang = strdup(track->language);
         sh->default_track = track->default_track;
     } else {
         mp_msg(MSGT_DEMUX, MSGL_ERR,
--- a/libmpdemux/demux_mov.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_mov.c	Sat Jul 10 18:47:59 2010 +0000
@@ -1338,7 +1338,7 @@
 	    mov_build_index(trak,priv->timescale);
 	    switch(trak->type){
 	    case MOV_TRAK_AUDIO: {
-		sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db);
+		sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db, NULL);
 		mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "mov", priv->track_db);
 		gen_sh_audio(sh, trak, priv->timescale);
 		break;
@@ -1353,7 +1353,7 @@
 		if (trak->fourcc == mmioFOURCC('m','p','4','s') ||
 		    trak->fourcc == mmioFOURCC('t','x','3','g') ||
 		    trak->fourcc == mmioFOURCC('t','e','x','t')) {
-			sh_sub_t *sh = new_sh_sub(demuxer, priv->track_db);
+			sh_sub_t *sh = new_sh_sub(demuxer, priv->track_db, NULL);
 			mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_SubtitleID, "mov", priv->track_db);
 			if (trak->fourcc == mmioFOURCC('m','p','4','s'))
 				init_vobsub(sh, trak);
--- a/libmpdemux/demux_mpc.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_mpc.c	Sat Jul 10 18:47:59 2010 +0000
@@ -93,7 +93,7 @@
   sh_audio_t* sh_audio;
   da_priv_t* priv = demuxer->priv;
 
-  sh_audio = new_sh_audio(demuxer,0);
+  sh_audio = new_sh_audio(demuxer,0, NULL);
 
   {
     char *wf = calloc(1, sizeof(WAVEFORMATEX) + HDR_SIZE);
--- a/libmpdemux/demux_mpg.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_mpg.c	Sat Jul 10 18:47:59 2010 +0000
@@ -269,7 +269,7 @@
   if(!demux->a_streams[aid]){
     mpg_demuxer_t *mpg_d=(mpg_demuxer_t*)demux->priv;
     sh_audio_t* sh_a;
-    new_sh_audio(demux,aid);
+    new_sh_audio(demux,aid, NULL);
     sh_a = (sh_audio_t*)demux->a_streams[aid];
     sh_a->needs_parsing = 1;
     switch(aid & 0xE0){  // 1110 0000 b  (high 3 bit: type  low 5: id)
@@ -477,15 +477,13 @@
         aid&=0x1F;
 
         if(!demux->s_streams[aid]){
-            sh_sub_t *sh = new_sh_sub(demux, aid);
+            sh_sub_t *sh = new_sh_sub(demux, aid, NULL);
             if (sh) sh->type = 'v';
             mp_msg(MSGT_DEMUX,MSGL_V,"==> Found subtitle: %d\n",aid);
         }
 
         if(demux->sub->id > -1)
           demux->sub->id &= 0x1F;
-        if(!dvdsub_lang && demux->sub->id == -1)
-          demux->sub->id = aid;
         if(demux->sub->id==aid){
             ds=demux->sub;
         }
--- a/libmpdemux/demux_nemesi.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_nemesi.c	Sat Jul 10 18:47:59 2010 +0000
@@ -222,7 +222,7 @@
 
         if (ptinfo->type == AU) {
             if (ndsd->session[NEMESI_SESSION_AUDIO] == NULL) {
-                sh_audio_t* sh_audio = new_sh_audio(demuxer,0);
+                sh_audio_t* sh_audio = new_sh_audio(demuxer,0, NULL);
                 WAVEFORMATEX* wf;
                 demux_stream_t* d_audio = demuxer->audio;
                 demuxer->audio->id = 0;
--- a/libmpdemux/demux_nsv.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_nsv.c	Sat Jul 10 18:47:59 2010 +0000
@@ -194,7 +194,7 @@
         //   bytes 8-11   audio codec fourcc
         // PCM fourcc needs extra parsing for every audio chunk, yet to implement
         if((demuxer->audio->id != -2) && strncmp(hdr+8,"NONE", 4)){//&&strncmp(hdr+8,"VLB ", 4)){
-            sh_audio = new_sh_audio ( demuxer, 0 );
+            sh_audio = new_sh_audio ( demuxer, 0, NULL );
             demuxer->audio->id = 0;
             demuxer->audio->sh = sh_audio;
             sh_audio->format=mmioFOURCC(hdr[8],hdr[9],hdr[10],hdr[11]);
--- a/libmpdemux/demux_nut.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_nut.c	Sat Jul 10 18:47:59 2010 +0000
@@ -113,7 +113,7 @@
 			WAVEFORMATEX *wf =
 				calloc(sizeof(WAVEFORMATEX) +
 				              s[i].codec_specific_len, 1);
-			sh_audio_t* sh_audio = new_sh_audio(demuxer, i);
+			sh_audio_t* sh_audio = new_sh_audio(demuxer, i, NULL);
 			int j;
 			mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "nut", i);
 
--- a/libmpdemux/demux_ogg.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_ogg.c	Sat Jul 10 18:47:59 2010 +0000
@@ -862,7 +862,7 @@
 
         // Check for Vorbis
         if (pack.bytes >= 7 && !strncmp(&pack.packet[1], "vorbis", 6)) {
-            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio);
+            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);
             sh_a->format = FOURCC_VORBIS;
             ogg_d->subs[ogg_d->num_sub].vorbis = 1;
             ogg_d->subs[ogg_d->num_sub].id     = n_audio;
@@ -871,7 +871,7 @@
                    "[Ogg] stream %d: audio (Vorbis), -aid %d\n",
                    ogg_d->num_sub, n_audio - 1);
         } else if (pack.bytes >= 80 && !strncmp(pack.packet, "Speex", 5)) {
-            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio);
+            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);
             sh_a->wf         = calloc(1, sizeof(WAVEFORMATEX) + pack.bytes);
             sh_a->format     = FOURCC_SPEEX;
             sh_a->samplerate = sh_a->wf->nSamplesPerSec = AV_RL32(&pack.packet[36]);
@@ -938,7 +938,7 @@
             theora_info_clear(&inf);
 #endif /* CONFIG_OGGTHEORA */
         } else if (pack.bytes >= 4 && !strncmp (&pack.packet[0], "fLaC", 4)) {
-            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio);
+            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);
             sh_a->format = mmioFOURCC('f', 'L', 'a', 'C');
             ogg_d->subs[ogg_d->num_sub].id = n_audio;
             n_audio++;
@@ -948,7 +948,7 @@
                    "[Ogg] stream %d: audio (FLAC), -aid %d\n",
                    ogg_d->num_sub, n_audio - 1);
         } else if (pack.bytes >= 51 && !strncmp(&pack.packet[1], "FLAC", 4)) {
-            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio);
+            sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);
             sh_a->format = mmioFOURCC('f', 'L', 'a', 'C');
             ogg_d->subs[ogg_d->num_sub].id = n_audio;
             n_audio++;
@@ -995,7 +995,7 @@
             } else if (AV_RL32(pack.packet + 96) == 0x05589F81) {
                 unsigned int extra_size;
 
-                sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio);
+                sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);
                 extra_size = AV_RL16(pack.packet + 140);
                 sh_a->wf         = calloc(1, sizeof(WAVEFORMATEX) + extra_size);
                 sh_a->format     = sh_a->wf->wFormatTag     = AV_RL16(pack.packet + 124);
@@ -1072,7 +1072,7 @@
                     extra_offset  = 4;
                 }
 
-                sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio);
+                sh_a = new_sh_audio_aid(demuxer, ogg_d->num_sub, n_audio, NULL);
                 sh_a->wf         = calloc(1, sizeof(WAVEFORMATEX) + extra_size);
                 sh_a->format     = sh_a->wf->wFormatTag = strtol(buffer, NULL, 16);
                 sh_a->channels   = sh_a->wf->nChannels  = AV_RL16(&st->sh.audio.channels);
@@ -1105,7 +1105,7 @@
                 ogg_d->subs[ogg_d->num_sub].id         = ogg_d->n_text;
                 if (demuxer->sub->id == ogg_d->n_text)
                     text_id = ogg_d->num_sub;
-                new_sh_sub(demuxer, ogg_d->n_text);
+                new_sh_sub(demuxer, ogg_d->n_text, NULL);
                 ogg_d->n_text++;
                 ogg_d->text_ids = realloc_struct(ogg_d->text_ids, ogg_d->n_text, sizeof(*ogg_d->text_ids));
                 ogg_d->text_ids[ogg_d->n_text - 1] = ogg_d->num_sub;
@@ -1387,7 +1387,7 @@
 
     // Finish setting up the ogg demuxer
     od->priv = ogg_d;
-    sh_audio = new_sh_audio(od, 0);
+    sh_audio = new_sh_audio(od, 0, NULL);
     od->audio->id = 0;
     od->video->id = -2;
     od->audio->sh = sh_audio;
--- a/libmpdemux/demux_pva.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_pva.c	Sat Jul 10 18:47:59 2010 +0000
@@ -133,7 +133,7 @@
 static demuxer_t * demux_open_pva (demuxer_t * demuxer)
 {
 	sh_video_t *sh_video = new_sh_video(demuxer,0);
-        sh_audio_t *sh_audio = new_sh_audio(demuxer,0);
+        sh_audio_t *sh_audio = new_sh_audio(demuxer,0, NULL);
 
 
 	pva_priv_t * priv;
--- a/libmpdemux/demux_rawaudio.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_rawaudio.c	Sat Jul 10 18:47:59 2010 +0000
@@ -50,7 +50,7 @@
   sh_audio_t* sh_audio;
   WAVEFORMATEX* w;
 
-  sh_audio = new_sh_audio(demuxer,0);
+  sh_audio = new_sh_audio(demuxer,0, NULL);
   sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX));
   w->wFormatTag = sh_audio->format = format;
   w->nChannels = sh_audio->channels = channels;
--- a/libmpdemux/demux_rawdv.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_rawdv.c	Sat Jul 10 18:47:59 2010 +0000
@@ -207,7 +207,7 @@
 
    mp_msg(MSGT_DEMUXER,MSGL_V,"demux_open_rawdv() seek to %qu, size: %d, dv_dec->frame_size: %d\n",frames->current_filepos,frames->frame_size, dv_decoder->frame_size);
     if (dv_decoder->audio != NULL && demuxer->audio->id>=-1){
-       sh_audio_t *sh_audio =  new_sh_audio(demuxer, 0);
+       sh_audio_t *sh_audio =  new_sh_audio(demuxer, 0, NULL);
        demuxer->audio->id = 0;
 	    demuxer->audio->sh = sh_audio;
 	    sh_audio->ds = demuxer->audio;
--- a/libmpdemux/demux_real.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_real.c	Sat Jul 10 18:47:59 2010 +0000
@@ -1264,7 +1264,7 @@
 		    mp_msg(MSGT_DEMUX,MSGL_V,"Audio: can't find .ra in codec data\n");
 		} else {
 		    /* audio header */
-		    sh_audio_t *sh = new_sh_audio(demuxer, stream_id);
+		    sh_audio_t *sh = new_sh_audio(demuxer, stream_id, NULL);
 		    char buf[128]; /* for codec name */
 		    int frame_size;
 		    int sub_packet_size;
@@ -1476,7 +1476,7 @@
 #endif
 		}
 	  } else if (strstr(mimet,"X-MP3-draft-00")) {
-		    sh_audio_t *sh = new_sh_audio(demuxer, stream_id);
+		    sh_audio_t *sh = new_sh_audio(demuxer, stream_id, NULL);
     		    mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_AudioID, "real", stream_id);
 
 		    /* Emulate WAVEFORMATEX struct: */
--- a/libmpdemux/demux_realaud.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_realaud.c	Sat Jul 10 18:47:59 2010 +0000
@@ -172,7 +172,7 @@
 	memset(ra_priv, 0, sizeof(ra_priv_t));
 
 	demuxer->priv = ra_priv;
-	sh = new_sh_audio(demuxer, 0);
+	sh = new_sh_audio(demuxer, 0, NULL);
 	demuxer->audio->id = 0;
 	sh->ds=demuxer->audio;
 	demuxer->audio->sh = sh;
--- a/libmpdemux/demux_roq.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_roq.c	Sat Jul 10 18:47:59 2010 +0000
@@ -168,7 +168,7 @@
       if (sh_audio == NULL)
       {
         // make the header first
-        sh_audio = new_sh_audio(demuxer, 0);
+        sh_audio = new_sh_audio(demuxer, 0, NULL);
         // make sure the demuxer knows about the new stream header
         demuxer->audio->id = 0;
         demuxer->audio->sh = sh_audio;
--- a/libmpdemux/demux_smjpeg.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_smjpeg.c	Sat Jul 10 18:47:59 2010 +0000
@@ -149,7 +149,7 @@
 	    sh_video->bih->biSizeImage = sh_video->disp_w*sh_video->disp_h;
 	    break;
 	case mmioFOURCC('_','S','N','D'):
-	    sh_audio = new_sh_audio(demuxer, 0);
+	    sh_audio = new_sh_audio(demuxer, 0, NULL);
 	    demuxer->audio->id = 0;
 	    demuxer->audio->sh = sh_audio;
 	    sh_audio->ds = demuxer->audio;
--- a/libmpdemux/demux_ts.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_ts.c	Sat Jul 10 18:47:59 2010 +0000
@@ -339,10 +339,9 @@
 
 	if((IS_AUDIO(es->type) || IS_AUDIO(es->subtype)) && priv->last_aid+1 < MAX_A_STREAMS)
 	{
-		sh_audio_t *sh = new_sh_audio_aid(demuxer, priv->last_aid, es->pid);
+		sh_audio_t *sh = new_sh_audio_aid(demuxer, priv->last_aid, es->pid, pid_lang_from_pmt(priv, es->pid));
 		if(sh)
 		{
-			const char *lang = pid_lang_from_pmt(priv, es->pid);
 			sh->needs_parsing = 1;
 			sh->format = IS_AUDIO(es->type) ? es->type : es->subtype;
 			sh->ds = demuxer->audio;
@@ -351,8 +350,6 @@
 			priv->ts.streams[es->pid].sh = sh;
 			priv->ts.streams[es->pid].type = TYPE_AUDIO;
 			mp_msg(MSGT_DEMUX, MSGL_V, "\r\nADDED AUDIO PID %d, type: %x stream n. %d\r\n", es->pid, sh->format, priv->last_aid);
-			if (lang && lang[0])
-				mp_msg(MSGT_IDENTIFY, MSGL_V, "ID_AID_%d_LANG=%s\n", es->pid, lang);
 			priv->last_aid++;
 		}
 
--- a/libmpdemux/demux_ty.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_ty.c	Sat Jul 10 18:47:59 2010 +0000
@@ -569,7 +569,7 @@
                }
 
                demux->audio->id = aid;
-               if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid );
+               if( !demux->a_streams[ aid ] ) new_sh_audio( demux, aid, NULL );
                if( demux->audio->id == aid )
                {
                   demux_stream_t *ds = demux->audio;
--- a/libmpdemux/demux_viv.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_viv.c	Sat Jul 10 18:47:59 2010 +0000
@@ -648,7 +648,7 @@
   if(!ds_fill_buffer(demuxer->audio)){
     mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream);
   } else
-{		sh_audio_t* sh=new_sh_audio(demuxer,1);
+{		sh_audio_t* sh=new_sh_audio(demuxer,1, NULL);
 
 		/* Select audio codec */
 		if (priv->audio_codec == 0)
--- a/libmpdemux/demux_vqf.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_vqf.c	Sat Jul 10 18:47:59 2010 +0000
@@ -48,7 +48,7 @@
 
   s = demuxer->stream;
 
-  sh_audio = new_sh_audio(demuxer,0);
+  sh_audio = new_sh_audio(demuxer,0, NULL);
   sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX)+sizeof(headerInfo));
   hi = (headerInfo *)&w[1];
   memset(hi,0,sizeof(headerInfo));
--- a/libmpdemux/demux_xmms.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demux_xmms.c	Sat Jul 10 18:47:59 2010 +0000
@@ -265,7 +265,7 @@
     memset(xmms_audiobuffer,0,XMMS_PACKETSIZE);
 
     xmms_channels=0;
-    sh_audio = new_sh_audio(demuxer,0);
+    sh_audio = new_sh_audio(demuxer,0, NULL);
     sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX));
     w->wFormatTag = sh_audio->format = format;
 
--- a/libmpdemux/demuxer.c	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/demuxer.c	Sat Jul 10 18:47:59 2010 +0000
@@ -254,7 +254,7 @@
     return d;
 }
 
-sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid)
+sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid, const char *lang)
 {
     if (id > MAX_S_STREAMS - 1 || id < 0) {
         mp_msg(MSGT_DEMUXER, MSGL_WARN,
@@ -269,6 +269,10 @@
         demuxer->s_streams[id] = sh;
         sh->sid = sid;
         mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid);
+        if (lang && lang[0] && strcmp(lang, "und")) {
+            sh->lang = strdup(lang);
+            mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, lang);
+        }
     }
     if (sid == dvdsub_id) {
         demuxer->sub->id = id;
@@ -292,7 +296,7 @@
     free(sh);
 }
 
-sh_audio_t *new_sh_audio_aid(demuxer_t *demuxer, int id, int aid)
+sh_audio_t *new_sh_audio_aid(demuxer_t *demuxer, int id, int aid, const char *lang)
 {
     if (id > MAX_A_STREAMS - 1 || id < 0) {
         mp_msg(MSGT_DEMUXER, MSGL_WARN,
@@ -314,6 +318,10 @@
         sh->audio_out_minsize = 8192;   /* default size, maybe not enough for Win32/ACM */
         sh->pts = MP_NOPTS_VALUE;
         mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid);
+        if (lang && lang[0] && strcmp(lang, "und")) {
+            sh->lang = strdup(lang);
+            mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_LANG=%s\n", aid, lang);
+        }
     }
     return demuxer->a_streams[id];
 }
--- a/libmpdemux/stheader.h	Sat Jul 10 18:11:05 2010 +0000
+++ b/libmpdemux/stheader.h	Sat Jul 10 18:47:59 2010 +0000
@@ -131,12 +131,12 @@
 } sh_sub_t;
 
 // demuxer.c:
-#define new_sh_audio(d, i) new_sh_audio_aid(d, i, i)
-sh_audio_t* new_sh_audio_aid(demuxer_t *demuxer,int id,int aid);
+#define new_sh_audio(d, i, l) new_sh_audio_aid(d, i, i, l)
+sh_audio_t* new_sh_audio_aid(demuxer_t *demuxer,int id,int aid, const char *lang);
 #define new_sh_video(d, i) new_sh_video_vid(d, i, i)
 sh_video_t* new_sh_video_vid(demuxer_t *demuxer,int id,int vid);
-#define new_sh_sub(d, i) new_sh_sub_sid(d, i, i)
-sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid);
+#define new_sh_sub(d, i, l) new_sh_sub_sid(d, i, i, l)
+sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid, const char *lang);
 void free_sh_audio(demuxer_t *demuxer, int id);
 void free_sh_video(sh_video_t *sh);