[Mplayer-dvb] ac3 sound in vdr file not recognized by mplayer and mencoder ?Wed Jan 2 21:17:00 2002

Dieter Bloms dbloms at suse.de
Sat Jan 5 12:19:59 CET 2002


Hi,

On Sat, Jan 05, Dieter Bloms wrote:

> I've made a little patch for play-ac3, so it works with vdr.
> I will send it to you, if I've access to it.

ok, here is the patch:

There problems were:

o play-ac3 exited, if it can't read FRAMES * frame_size at once, now it
  read till it can't read anything and then exited
o sometimes the first frame coming from vdr is not valid. Now play-ac3
  ignore the first sizeof(buffer) bytes
o if I jump through the movie my ac3 decoder becomes confused, so
  play-ac3 now checks for the beginning of the next frame and coninues
  at this place
  
--snip--
diff -Nur play-ac3.orig/play-ac3.c play-ac3/play-ac3.c
--- play-ac3.orig/play-ac3.c	Sun Sep  2 13:02:07 2001
+++ play-ac3/play-ac3.c	Sat Jan  5 11:57:13 2002
@@ -45,6 +45,7 @@
 	unsigned char buffer[4096];
 	struct ac3info ai;
 
+        read (in, buffer, sizeof(buffer)); // some times the first bytes contains no valid data
 	i = read(in, buffer, sizeof(buffer));
 	if (i != sizeof(buffer)) {
 		fprintf(stderr, "Error reading AC3 stream.\n");
@@ -117,15 +118,40 @@
 	}
 	ac3buf = malloc(FRAMES * frame_size);
 	iecbuf = malloc(FRAMES * 6144);
-	bytes_read = read(in, ac3buf, FRAMES * frame_size);
-	while (bytes_read == FRAMES * frame_size) {
-		for (i = 0; i < FRAMES; i++) {
-			ac3_iec958_build_burst(frame_size, data_type, 1, 
-					ac3buf + i * frame_size,
-					iecbuf + i * 6144);
-		}
-		write(fd, iecbuf, FRAMES * 6144);
-		bytes_read = read(in, ac3buf, FRAMES * frame_size);
+        bytes_read = 0;
+        while (1) {
+          while (bytes_read != FRAMES * frame_size) {
+            int bytes;
+            bytes = read(in, &ac3buf[bytes_read], (FRAMES * frame_size) - bytes_read);
+            if (bytes) {
+              bytes_read = bytes_read + bytes;
+            } else {
+              exit (0);
+            }
+            if ((ac3buf[0] == 11) && (ac3buf[1] == 119)) {
+            // we got valid data, so we don't have to correct anything
+            } else {  // we have to correct the stream.
+              // ignore the data till the next frame
+              for (i=0; i < bytes_read; i++) {
+                if ((ac3buf[i] == 11) && (ac3buf[i+1] == 119)) {
+                  int j;
+                  for (j=i; j<(FRAMES * frame_size); j++) {
+                    ac3buf[j-i] = ac3buf[j];
+                  }
+                  bytes_read = bytes_read - i;
+                  break;
+                }
+              }
+            }
+          }
+          // ok, now we have a complete frame, so play it.
+          for (i = 0; i < FRAMES; i++) {
+		ac3_iec958_build_burst(frame_size, data_type, 1, 
+				ac3buf + i * frame_size,
+				iecbuf + i * 6144);
+	  }
+	  write(fd, iecbuf, FRAMES * 6144);
+          bytes_read = 0;
 	}
 	return 0;
 }
--snip--
-- 
Mit freundlichen Gruessen,

	Dieter Bloms (Dieter.Bloms at suse.de)

--------------------------------------------------------------------
SuSE Linux Solutions AG,    Tel:   +49-911-74053653 
Deutschherrnstr. 15-19,     Fax:   +49-911-74053674
90429 Nuernberg,            Email: Dieter.Bloms at suse.de 
Germany                     WWW:   http://www.suse.de
--------------------------------------------------------------------

Key fingerprint = C54E EAD2 784A 5402 C4E4  A58A 414A AEA1 9038 7583
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 246 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dvb/attachments/20020105/c1719aae/attachment.pgp>


More information about the MPlayer-dvb mailing list