Commit Diff


commit - 335fa83ad847d6b5b891ec166625907be664ab5d
commit + 0da0ad464c14fc59e00a2d2d904ebc97bedb212e
blob - 1a34556b307eb012bf5cadbee3d8df60cee84f9e
blob + 78c5bb881644a08add919005340ea647ae29cc5c
--- amused.h
+++ amused.h
@@ -139,9 +139,9 @@ int	player_setup(int, int, int);
 int	play(const void *, size_t);
 int	player(int, int);
 
-void	play_oggvorbis(int fd);
-void	play_mp3(int fd);
-void	play_flac(int fd);
-void	play_opus(int fd);
+int	play_oggvorbis(int fd);
+int	play_mp3(int fd);
+int	play_flac(int fd);
+int	play_opus(int fd);
 
 #endif
blob - b9a9de3865bb7121b65bec0d4948cfeb2718c719
blob + d7578b3004797929eaa1b28898da85dbcb02ff25
--- player_123.c
+++ player_123.c
@@ -48,13 +48,13 @@ setup(mpg123_handle *mh)
 	return 1;
 }
 
-void
+int
 play_mp3(int fd)
 {
 	static char	 buf[4096];
 	size_t		 len;
 	mpg123_handle	*mh;
-	int		 err;
+	int		 err, ret = -1;
 
 	if ((mh = mpg123_new(NULL, NULL)) == NULL)
 		fatal("mpg123_new");
@@ -62,7 +62,7 @@ play_mp3(int fd)
 	if (mpg123_open_fd(mh, fd) != MPG123_OK) {
 		log_warnx("mpg123_open_fd failed");
 		close(fd);
-		return;
+		return -1;
 	}
 
 	if (!setup(mh))
@@ -72,14 +72,17 @@ play_mp3(int fd)
 		err = mpg123_read(mh, buf, sizeof(buf), &len);
 		switch (err) {
 		case MPG123_DONE:
+			ret = 0;
 			goto done;
 		case MPG123_NEW_FORMAT:
 			if (!setup(mh))
 				goto done;
 			break;
 		case MPG123_OK:
-			if (!play(buf, len))
+			if (!play(buf, len)) {
+				ret = 1;
 				goto done;
+			}
 			break;
 		default:
 			log_warnx("error %d decoding mp3", err);
@@ -90,4 +93,5 @@ play_mp3(int fd)
 done:
 	mpg123_delete(mh);
 	close(fd);
+	return ret;
 }
blob - d171938609638723f73d1757610b5525e1bac771
blob + 2f3959fc942ba93b806bc733638a3d78771d5bf0
--- player_flac.c
+++ player_flac.c
@@ -84,7 +84,7 @@ errcb(const FLAC__StreamDecoder *decoder, FLAC__Stream
 	log_warnx("flac error: %s", FLAC__StreamDecoderErrorStatusString[status]);
 }
 
-void
+int
 play_flac(int fd)
 {
 	FILE *f;
@@ -110,12 +110,16 @@ play_flac(int fd)
 
 	ok = FLAC__stream_decoder_process_until_end_of_stream(decoder);
 	s = FLAC__stream_decoder_get_state(decoder);
+
+	FLAC__stream_decoder_delete(decoder);
+	fclose(f);
+
 	if (!ok && s != FLAC__STREAM_DECODER_ABORTED) {
 		state = FLAC__StreamDecoderStateString[s];
 		log_warnx("decoding failed; state: %s", state);
+		return 1;
 	}
-
-	FLAC__stream_decoder_delete(decoder);
-
-	fclose(f);
+	if (!ok)
+		return -1;
+	return 0;
 }
blob - 422719ff4dcf87d8d37fc17d9d204ae0e6844aef
blob + cb40650d64725a03be62ba9d78d10644e0191df6
--- player_oggvorbis.c
+++ player_oggvorbis.c
@@ -39,20 +39,21 @@
 #define nitems(x) (sizeof(x)/sizeof(x[0]))
 #endif
 
-void
+int
 play_oggvorbis(int fd)
 {
 	static uint8_t pcmout[4096];
 	FILE *f;
 	OggVorbis_File vf;
 	vorbis_info *vi;
-	int current_section, eof = 0;
+	int current_section, eof = 0, ret = 0;
 
 	if ((f = fdopen(fd, "r")) == NULL)
 		err(1, "fdopen");
 
 	if (ov_open_callbacks(f, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) {
 		log_warnx("input is not an Ogg bitstream");
+		ret = -1;
 		goto end;
 	}
 
@@ -74,8 +75,10 @@ play_oggvorbis(int fd)
 			eof = 1;
 		else if (ret > 0) {
 			/* TODO: deal with sample rate changes */
-			if (!play(pcmout, ret))
+			if (!play(pcmout, ret)) {
+				ret = 1;
 				break;
+			}
 		}
 	}
 
@@ -83,4 +86,5 @@ play_oggvorbis(int fd)
 
 end:
 	fclose(f);
+	return ret;
 }
blob - f91abdad8581280a7db2492fa93372cda909c4c3
blob + fc479e99d9b48e2c24f1772e0d57a4866987ef99
--- player_opus.c
+++ player_opus.c
@@ -38,36 +38,37 @@
 #define nitems(x) (sizeof(x)/sizeof(x[0]))
 #endif
 
-void
+int
 play_opus(int fd)
 {
 	static uint16_t pcm[BUFSIZ];
 	static uint8_t out[BUFSIZ * 2];
 	OggOpusFile *of;
 	void *f;
-	int ret;
+	int r, ret = 0;
 	OpusFileCallbacks cb = {NULL, NULL, NULL, NULL};
 	int i, li, prev_li = -1;
 
 	if ((f = op_fdopen(&cb, fd, "r")) == NULL)
 		err(1, "fdopen");
 
-	of = op_open_callbacks(f, &cb, NULL, 0, &ret);
+	of = op_open_callbacks(f, &cb, NULL, 0, &r);
 	if (of == NULL) {
 		close(fd);
-		return;
+		return -1;
 	}
 
 	for (;;) {
 		/* NB: will downmix multichannels files into two channels */
-		ret = op_read_stereo(of, pcm, nitems(pcm));
-		if (ret == OP_HOLE) /* corrupt file segment? */
+		r = op_read_stereo(of, pcm, nitems(pcm));
+		if (r == OP_HOLE) /* corrupt file segment? */
 			continue;
-		if (ret < 0) {
+		if (r < 0) {
 			log_warnx("error %d decoding file", ret);
+			ret = -1;
 			break;
 		}
-		if (ret == 0)
+		if (r == 0)
 			break; /* eof */
 
 		li = op_current_link(of);
@@ -75,7 +76,6 @@ play_opus(int fd)
 			const OpusHead *head;
 
 			prev_li = li;
-
 			head = op_head(of, li);
 			if (head->input_sample_rate &&
 			    player_setup(16, head->input_sample_rate, 2) == -1)
@@ -87,9 +87,12 @@ play_opus(int fd)
 			out[2*i+1] = (pcm[i] >> 8) & 0xFF;
 		}
 
-		if (!play(out, 4*ret))
+		if (!play(out, 4*ret)) {
+			ret = 1;
 			break;
+		}
 	}
 
 	op_free(of);
+	return ret;
 }