summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/decoder.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/decoder.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/decoder.c60
1 files changed, 38 insertions, 22 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 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
@@ -20,19 +20,14 @@
20 */ 20 */
21 21
22# ifdef HAVE_CONFIG_H 22# ifdef HAVE_CONFIG_H
23# include "libmad_config.h" 23# include "libmad_config.h"
24# else
25# ifndef WEXITSTATUS
26# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
27# endif
28# ifndef WIFEXITED
29# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
30# endif
31# endif 24# endif
32 25
33# include "libmad_global.h" 26# include "libmad_global.h"
34 27
35# include <sys/types.h> 28# ifdef HAVE_SYS_TYPES_H
29# include <sys/types.h>
30# endif
36 31
37# ifdef HAVE_SYS_WAIT_H 32# ifdef HAVE_SYS_WAIT_H
38# include <sys/wait.h> 33# include <sys/wait.h>
@@ -42,9 +37,15 @@
42# include <unistd.h> 37# include <unistd.h>
43# endif 38# endif
44 39
45# include <fcntl.h> 40# ifdef HAVE_FCNTL_H
41# include <fcntl.h>
42# endif
43
46# include <stdlib.h> 44# include <stdlib.h>
47# include <errno.h> 45
46# ifdef HAVE_ERRNO_H
47# include <errno.h>
48# endif
48 49
49# include "stream.h" 50# include "stream.h"
50# include "frame.h" 51# include "frame.h"
@@ -52,14 +53,18 @@
52# include "decoder.h" 53# include "decoder.h"
53 54
54void mad_decoder_init(struct mad_decoder *decoder, void *data, 55void mad_decoder_init(struct mad_decoder *decoder, void *data,
55 enum mad_flow (*input_func)(void *, struct mad_stream *), 56 enum mad_flow (*input_func)(void *,
57 struct mad_stream *),
56 enum mad_flow (*header_func)(void *, 58 enum mad_flow (*header_func)(void *,
57 struct mad_header const *), 59 struct mad_header const *),
58 enum mad_flow (*filter_func)(void *, struct mad_frame *), 60 enum mad_flow (*filter_func)(void *,
61 struct mad_stream const *,
62 struct mad_frame *),
59 enum mad_flow (*output_func)(void *, 63 enum mad_flow (*output_func)(void *,
60 struct mad_header const *, 64 struct mad_header const *,
61 struct mad_pcm *), 65 struct mad_pcm *),
62 enum mad_flow (*error_func)(void *, struct mad_stream *, 66 enum mad_flow (*error_func)(void *,
67 struct mad_stream *,
63 struct mad_frame *), 68 struct mad_frame *),
64 enum mad_flow (*message_func)(void *, 69 enum mad_flow (*message_func)(void *,
65 void *, unsigned int *)) 70 void *, unsigned int *))
@@ -86,15 +91,15 @@ void mad_decoder_init(struct mad_decoder *decoder, void *data,
86 91
87int mad_decoder_finish(struct mad_decoder *decoder) 92int mad_decoder_finish(struct mad_decoder *decoder)
88{ 93{
94# if defined(USE_ASYNC)
89 if (decoder->mode == MAD_DECODER_MODE_ASYNC && decoder->async.pid) { 95 if (decoder->mode == MAD_DECODER_MODE_ASYNC && decoder->async.pid) {
90 pid_t pid; 96 pid_t pid;
91 int status; 97 int status;
92 98
93 close(decoder->async.in); 99 close(decoder->async.in);
94 100
95 do { 101 do
96 pid = waitpid(decoder->async.pid, &status, 0); 102 pid = waitpid(decoder->async.pid, &status, 0);
97 }
98 while (pid == -1 && errno == EINTR); 103 while (pid == -1 && errno == EINTR);
99 104
100 decoder->mode = -1; 105 decoder->mode = -1;
@@ -110,10 +115,12 @@ int mad_decoder_finish(struct mad_decoder *decoder)
110 115
111 return (!WIFEXITED(status) || WEXITSTATUS(status)) ? -1 : 0; 116 return (!WIFEXITED(status) || WEXITSTATUS(status)) ? -1 : 0;
112 } 117 }
118# endif
113 119
114 return 0; 120 return 0;
115} 121}
116 122
123# if defined(USE_ASYNC)
117static 124static
118enum mad_flow send_io(int fd, void const *data, size_t len) 125enum mad_flow send_io(int fd, void const *data, size_t len)
119{ 126{
@@ -121,9 +128,8 @@ enum mad_flow send_io(int fd, void const *data, size_t len)
121 ssize_t count; 128 ssize_t count;
122 129
123 while (len) { 130 while (len) {
124 do { 131 do
125 count = write(fd, ptr, len); 132 count = write(fd, ptr, len);
126 }
127 while (count == -1 && errno == EINTR); 133 while (count == -1 && errno == EINTR);
128 134
129 if (count == -1) 135 if (count == -1)
@@ -143,9 +149,8 @@ enum mad_flow receive_io(int fd, void *buffer, size_t len)
143 ssize_t count; 149 ssize_t count;
144 150
145 while (len) { 151 while (len) {
146 do { 152 do
147 count = read(fd, ptr, len); 153 count = read(fd, ptr, len);
148 }
149 while (count == -1 && errno == EINTR); 154 while (count == -1 && errno == EINTR);
150 155
151 if (count == -1) 156 if (count == -1)
@@ -281,6 +286,7 @@ enum mad_flow check_message(struct mad_decoder *decoder)
281 286
282 return result; 287 return result;
283} 288}
289# endif
284 290
285static 291static
286enum mad_flow error_default(void *data, struct mad_stream *stream, 292enum mad_flow error_default(void *data, struct mad_stream *stream,
@@ -348,6 +354,7 @@ int run_sync(struct mad_decoder *decoder)
348 } 354 }
349 355
350 while (1) { 356 while (1) {
357# if defined(USE_ASYNC)
351 if (decoder->mode == MAD_DECODER_MODE_ASYNC) { 358 if (decoder->mode == MAD_DECODER_MODE_ASYNC) {
352 switch (check_message(decoder)) { 359 switch (check_message(decoder)) {
353 case MAD_FLOW_IGNORE: 360 case MAD_FLOW_IGNORE:
@@ -359,6 +366,7 @@ int run_sync(struct mad_decoder *decoder)
359 goto done; 366 goto done;
360 } 367 }
361 } 368 }
369# endif
362 370
363 if (decoder->header_func) { 371 if (decoder->header_func) {
364 if (mad_header_decode(&frame->header, stream) == -1) { 372 if (mad_header_decode(&frame->header, stream) == -1) {
@@ -409,7 +417,7 @@ int run_sync(struct mad_decoder *decoder)
409 bad_last_frame = 0; 417 bad_last_frame = 0;
410 418
411 if (decoder->filter_func) { 419 if (decoder->filter_func) {
412 switch (decoder->filter_func(decoder->cb_data, frame)) { 420 switch (decoder->filter_func(decoder->cb_data, stream, frame)) {
413 case MAD_FLOW_STOP: 421 case MAD_FLOW_STOP:
414 goto done; 422 goto done;
415 case MAD_FLOW_BREAK: 423 case MAD_FLOW_BREAK:
@@ -450,6 +458,7 @@ int run_sync(struct mad_decoder *decoder)
450 return result; 458 return result;
451} 459}
452 460
461# if defined(USE_ASYNC)
453static 462static
454int run_async(struct mad_decoder *decoder) 463int run_async(struct mad_decoder *decoder)
455{ 464{
@@ -511,6 +520,7 @@ int run_async(struct mad_decoder *decoder)
511 /* not reached */ 520 /* not reached */
512 return -1; 521 return -1;
513} 522}
523# endif
514 524
515int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) 525int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
516{ 526{
@@ -523,7 +533,9 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
523 break; 533 break;
524 534
525 case MAD_DECODER_MODE_ASYNC: 535 case MAD_DECODER_MODE_ASYNC:
536# if defined(USE_ASYNC)
526 run = run_async; 537 run = run_async;
538# endif
527 break; 539 break;
528 } 540 }
529 541
@@ -545,10 +557,14 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
545int mad_decoder_message(struct mad_decoder *decoder, 557int mad_decoder_message(struct mad_decoder *decoder,
546 void *message, unsigned int *len) 558 void *message, unsigned int *len)
547{ 559{
560# if defined(USE_ASYNC)
548 if (decoder->mode != MAD_DECODER_MODE_ASYNC || 561 if (decoder->mode != MAD_DECODER_MODE_ASYNC ||
549 send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE || 562 send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE ||
550 receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE) 563 receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE)
551 return -1; 564 return -1;
552 565
553 return 0; 566 return 0;
567# else
568 return -1;
569# endif
554} 570}