Diffstat (limited to 'core/multimedia/opieplayer/libmad/decoder.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/decoder.c | 60 |
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,6 +1,6 @@ | |||
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 |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
@@ -19,21 +19,16 @@ | |||
19 | * $Id$ | 19 | * $Id$ |
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> |
39 | # endif | 34 | # endif |
@@ -41,26 +36,36 @@ | |||
41 | # ifdef HAVE_UNISTD_H | 36 | # ifdef HAVE_UNISTD_H |
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" |
51 | # include "synth.h" | 52 | # include "synth.h" |
52 | # include "decoder.h" | 53 | # include "decoder.h" |
53 | 54 | ||
54 | void mad_decoder_init(struct mad_decoder *decoder, void *data, | 55 | void 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 *)) |
66 | { | 71 | { |
@@ -85,17 +90,17 @@ void mad_decoder_init(struct mad_decoder *decoder, void *data, | |||
85 | } | 90 | } |
86 | 91 | ||
87 | int mad_decoder_finish(struct mad_decoder *decoder) | 92 | int 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; |
101 | 106 | ||
@@ -109,22 +114,23 @@ int mad_decoder_finish(struct mad_decoder *decoder) | |||
109 | return -1; | 114 | return -1; |
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) | ||
117 | static | 124 | static |
118 | enum mad_flow send_io(int fd, void const *data, size_t len) | 125 | enum mad_flow send_io(int fd, void const *data, size_t len) |
119 | { | 126 | { |
120 | char const *ptr = data; | 127 | char const *ptr = data; |
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) |
130 | return MAD_FLOW_BREAK; | 136 | return MAD_FLOW_BREAK; |
@@ -142,11 +148,10 @@ enum mad_flow receive_io(int fd, void *buffer, size_t len) | |||
142 | char *ptr = buffer; | 148 | char *ptr = buffer; |
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) |
152 | return (errno == EAGAIN) ? MAD_FLOW_IGNORE : MAD_FLOW_BREAK; | 157 | return (errno == EAGAIN) ? MAD_FLOW_IGNORE : MAD_FLOW_BREAK; |
@@ -280,8 +285,9 @@ enum mad_flow check_message(struct mad_decoder *decoder) | |||
280 | free(message); | 285 | free(message); |
281 | 286 | ||
282 | return result; | 287 | return result; |
283 | } | 288 | } |
289 | # endif | ||
284 | 290 | ||
285 | static | 291 | static |
286 | enum mad_flow error_default(void *data, struct mad_stream *stream, | 292 | enum mad_flow error_default(void *data, struct mad_stream *stream, |
287 | struct mad_frame *frame) | 293 | struct mad_frame *frame) |
@@ -347,8 +353,9 @@ int run_sync(struct mad_decoder *decoder) | |||
347 | break; | 353 | break; |
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: |
354 | case MAD_FLOW_CONTINUE: | 361 | case MAD_FLOW_CONTINUE: |
@@ -358,8 +365,9 @@ int run_sync(struct mad_decoder *decoder) | |||
358 | case MAD_FLOW_STOP: | 365 | case MAD_FLOW_STOP: |
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) { |
365 | if (!MAD_RECOVERABLE(stream->error)) | 373 | if (!MAD_RECOVERABLE(stream->error)) |
@@ -408,9 +416,9 @@ int run_sync(struct mad_decoder *decoder) | |||
408 | else | 416 | else |
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: |
416 | goto fail; | 424 | goto fail; |
@@ -449,8 +457,9 @@ int run_sync(struct mad_decoder *decoder) | |||
449 | 457 | ||
450 | return result; | 458 | return result; |
451 | } | 459 | } |
452 | 460 | ||
461 | # if defined(USE_ASYNC) | ||
453 | static | 462 | static |
454 | int run_async(struct mad_decoder *decoder) | 463 | int run_async(struct mad_decoder *decoder) |
455 | { | 464 | { |
456 | pid_t pid; | 465 | pid_t pid; |
@@ -510,8 +519,9 @@ int run_async(struct mad_decoder *decoder) | |||
510 | 519 | ||
511 | /* not reached */ | 520 | /* not reached */ |
512 | return -1; | 521 | return -1; |
513 | } | 522 | } |
523 | # endif | ||
514 | 524 | ||
515 | int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) | 525 | int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) |
516 | { | 526 | { |
517 | int result; | 527 | int result; |
@@ -522,9 +532,11 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) | |||
522 | run = run_sync; | 532 | run = run_sync; |
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 | ||
530 | if (run == 0) | 542 | if (run == 0) |
@@ -544,11 +556,15 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) | |||
544 | 556 | ||
545 | int mad_decoder_message(struct mad_decoder *decoder, | 557 | int 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 | } |