--- upnphttp.c.orig	2011-03-18 22:01:18.000000000 +0100
+++ upnphttp.c	2011-03-18 23:17:51.000000000 +0100
@@ -1083,6 +1083,58 @@
 	}
 }
 
+/*** aid-patch for minidlna_1.0.18, (c) by Bernhard Oemer, licence GPLv2 ***/
+
+void maskaid(int len,unsigned char *buf,int aid) {
+  unsigned char *p=buf,*pend=buf+len,*q,*r;
+  for(p=buf;p<pend-3;p++) {
+    if(p[0] || p[1] || p[2]!=0x01 || p[3]<0xbd || p[3]>=0xf0) continue;
+    unsigned char *pnext= p<pend-5 ? p+6+((p[4]<<8)|p[5]) : pend;
+    if(pnext>pend) pnext=pend;
+    if((p[3]&0xe0)==0xc0 && p[3]!=0xc0+aid || 
+       p[3]==0xbd && p<pend-8 && (p[6]&0xc0)==0x80 && (q=p+9+p[8])<pend && q[0]>=0x80 && q[0]!=aid) {
+      p[3]=0xbe;                        /* change SID to 0xBE (padding stream) */
+      for(r=p+6;r<pnext;r++) *r=0xff;   /* blank stream with 1s */
+    }
+    p=pnext-1;
+  }
+}
+
+
+void
+send_file_aid(struct upnphttp * h, int sendfd, off_t offset, off_t end_offset, int aid)
+{
+        off_t ret;
+        off_t start_offset = (offset & ~0x7ff);
+	unsigned char buf[2048];
+        ret = lseek(sendfd, start_offset, SEEK_SET);
+	if( ret == -1 )
+	{
+		DPRINTF(E_DEBUG, L_HTTP, "seek error :: error no. %d [%s]\n", errno, strerror(errno));
+		return;
+	}
+        while( offset < end_offset )
+        {
+        	ret = read(sendfd, buf, 2048);
+		if( ret != 2048 )
+		{
+			DPRINTF(E_DEBUG, L_HTTP, "block read error :: error no. %d [%s]\n", errno, strerror(errno));
+			return;
+		}
+                maskaid(2048, buf, aid);
+                size_t n = 2048 - (offset & 0x7ff);
+                if( n > end_offset-offset ) n = end_offset-offset;
+                unsigned char *sbuf = buf + (offset & 0x7ff);
+                offset = (offset & ~0x7ff) + 2048;
+                ret = write(h->socket, sbuf, n);
+		if( ret != n )
+		{
+			DPRINTF(E_DEBUG, L_HTTP, "block send error :: error no. %d [%s]\n", errno, strerror(errno));
+			return;
+		}
+        }
+}
+
 void
 SendResp_icon(struct upnphttp * h, char * icon)
 {
@@ -1791,7 +1843,21 @@
 
 	if( (send_data(h, header, strlen(header), MSG_MORE) == 0) && (h->req_command != EHead) && (sendfh > 0) )
 	{
-		send_file(h, sendfh, offset, h->req_RangeEnd);
+        	/**** check if path contains an audio-id marker (e.g. "@128." for aid 128) ****/ 
+                
+		char *pc = rindex(last_file.path,'@');
+                int aid = -1;
+                
+                if(pc && pc[1]>='0' && pc[1]<='9' && ( ends_with(last_file.path, ".mpg") || ends_with(last_file.path, ".mpeg") || ends_with(last_file.path, ".vob") ) )
+                {
+                	aid = strtol(pc+1, &pc, 10);
+                        errno = 0;
+                        if(*pc!=0 && *pc!='/' && pc!='.' || aid<=0 || aid>255 ) aid = -1;
+                }
+		if( aid>=0 ) 
+                	send_file_aid(h, sendfh, offset, h->req_RangeEnd, aid);
+                else
+                	send_file(h, sendfh, offset, h->req_RangeEnd);	
 	}
 	close(sendfh);
 
