Diffstat (limited to 'core/multimedia/opieplayer/libmad/decoder.c') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/decoder.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/core/multimedia/opieplayer/libmad/decoder.c b/core/multimedia/opieplayer/libmad/decoder.c index dcf7cf3..b2b6cbb 100644 --- a/core/multimedia/opieplayer/libmad/decoder.c +++ b/core/multimedia/opieplayer/libmad/decoder.c @@ -1,5 +1,5 @@ /* - * mad - MPEG audio decoder + * libmad - MPEG audio decoder library * Copyright (C) 2000-2001 Robert Leslie * * This program is free software; you can redistribute it and/or modify @@ -21,18 +21,13 @@ # ifdef HAVE_CONFIG_H # include "libmad_config.h" -# else -# ifndef WEXITSTATUS -# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) -# endif -# ifndef WIFEXITED -# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) -# endif # endif # include "libmad_global.h" +# ifdef HAVE_SYS_TYPES_H # include <sys/types.h> +# endif # ifdef HAVE_SYS_WAIT_H # include <sys/wait.h> @@ -42,9 +37,15 @@ # include <unistd.h> # endif +# ifdef HAVE_FCNTL_H # include <fcntl.h> +# endif + # include <stdlib.h> + +# ifdef HAVE_ERRNO_H # include <errno.h> +# endif # include "stream.h" # include "frame.h" @@ -52,14 +53,18 @@ # include "decoder.h" void mad_decoder_init(struct mad_decoder *decoder, void *data, - enum mad_flow (*input_func)(void *, struct mad_stream *), + enum mad_flow (*input_func)(void *, + struct mad_stream *), enum mad_flow (*header_func)(void *, struct mad_header const *), - enum mad_flow (*filter_func)(void *, struct mad_frame *), + enum mad_flow (*filter_func)(void *, + struct mad_stream const *, + struct mad_frame *), enum mad_flow (*output_func)(void *, struct mad_header const *, struct mad_pcm *), - enum mad_flow (*error_func)(void *, struct mad_stream *, + enum mad_flow (*error_func)(void *, + struct mad_stream *, struct mad_frame *), enum mad_flow (*message_func)(void *, void *, unsigned int *)) @@ -86,15 +91,15 @@ void mad_decoder_init(struct mad_decoder *decoder, void *data, int mad_decoder_finish(struct mad_decoder *decoder) { +# if defined(USE_ASYNC) if (decoder->mode == MAD_DECODER_MODE_ASYNC && decoder->async.pid) { pid_t pid; int status; close(decoder->async.in); - do { + do pid = waitpid(decoder->async.pid, &status, 0); - } while (pid == -1 && errno == EINTR); decoder->mode = -1; @@ -110,10 +115,12 @@ int mad_decoder_finish(struct mad_decoder *decoder) return (!WIFEXITED(status) || WEXITSTATUS(status)) ? -1 : 0; } +# endif return 0; } +# if defined(USE_ASYNC) static enum mad_flow send_io(int fd, void const *data, size_t len) { @@ -121,9 +128,8 @@ enum mad_flow send_io(int fd, void const *data, size_t len) ssize_t count; while (len) { - do { + do count = write(fd, ptr, len); - } while (count == -1 && errno == EINTR); if (count == -1) @@ -143,9 +149,8 @@ enum mad_flow receive_io(int fd, void *buffer, size_t len) ssize_t count; while (len) { - do { + do count = read(fd, ptr, len); - } while (count == -1 && errno == EINTR); if (count == -1) @@ -281,6 +286,7 @@ enum mad_flow check_message(struct mad_decoder *decoder) return result; } +# endif static enum mad_flow error_default(void *data, struct mad_stream *stream, @@ -348,6 +354,7 @@ int run_sync(struct mad_decoder *decoder) } while (1) { +# if defined(USE_ASYNC) if (decoder->mode == MAD_DECODER_MODE_ASYNC) { switch (check_message(decoder)) { case MAD_FLOW_IGNORE: @@ -359,6 +366,7 @@ int run_sync(struct mad_decoder *decoder) goto done; } } +# endif if (decoder->header_func) { if (mad_header_decode(&frame->header, stream) == -1) { @@ -409,7 +417,7 @@ int run_sync(struct mad_decoder *decoder) bad_last_frame = 0; if (decoder->filter_func) { - switch (decoder->filter_func(decoder->cb_data, frame)) { + switch (decoder->filter_func(decoder->cb_data, stream, frame)) { case MAD_FLOW_STOP: goto done; case MAD_FLOW_BREAK: @@ -450,6 +458,7 @@ int run_sync(struct mad_decoder *decoder) return result; } +# if defined(USE_ASYNC) static int run_async(struct mad_decoder *decoder) { @@ -511,6 +520,7 @@ int run_async(struct mad_decoder *decoder) /* not reached */ return -1; } +# endif int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) { @@ -523,7 +533,9 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) break; case MAD_DECODER_MODE_ASYNC: +# if defined(USE_ASYNC) run = run_async; +# endif break; } @@ -545,10 +557,14 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) int mad_decoder_message(struct mad_decoder *decoder, void *message, unsigned int *len) { +# if defined(USE_ASYNC) if (decoder->mode != MAD_DECODER_MODE_ASYNC || send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE || receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE) return -1; return 0; +# else + return -1; +# endif } |