shithub: riscv

Download patch

ref: 79172e71e6be93d7902f9dd58ae5beb527cf52a6
parent: 251c3cd70ab1b8a574832cfbe306490ba5055010
author: cinap_lenrek <[email protected]>
date: Thu Nov 17 17:26:53 EST 2011

games/mp3dec: dont give up too soon on stream errors

--- a/sys/src/games/mp3dec/main.c
+++ b/sys/src/games/mp3dec/main.c
@@ -9,6 +9,7 @@
 char *name;
 vlong offset;
 int rate = 44100;
+int debug = 0;
 
 char *outfile;
 int vfd; /* /dev/volume */
@@ -149,12 +150,17 @@
 static enum mad_flow
 error(void *data, struct mad_stream *stream, struct mad_frame *frame)
 {
-	if(stream->error == MAD_ERROR_LOSTSYNC)
-		return MAD_FLOW_CONTINUE;
-	sysfatal("%s:#%lld: %s",
-		name, offset-(stream->bufend-stream->next_frame),
-		mad_stream_errorstr(stream));
-	return 0;
+	if(stream->error == MAD_ERROR_LOSTSYNC){
+		if(memcmp(stream->this_frame, "TAG", 3)==0){
+			mad_stream_skip(stream, 128);
+			return MAD_FLOW_CONTINUE;
+		}
+	}
+	if(debug)
+		fprint(2, "%s:#%lld: %s\n",
+			name, offset-(stream->bufend-stream->next_frame),
+			mad_stream_errorstr(stream));
+	return MAD_FLOW_CONTINUE;
 }
 
 void
@@ -171,7 +177,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: mp3dec [-o outfile] [file...]\n");
+	fprint(2, "usage: mp3dec [ -d ] [ -o outfile ] [ file ... ]\n");
 	exits("usage");
 }
 
@@ -184,6 +190,9 @@
 	ARGBEGIN{
 	case 'o':
 		outfile = EARGF(usage());
+		break;
+	case 'd':
+		debug++;
 		break;
 	default:
 		usage();