author | harlekin <harlekin> | 2002-04-19 16:08:55 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-04-19 16:08:55 (UTC) |
commit | 7ea4abeb652e6787e57a938e1ca028d25fd249ce (patch) (unidiff) | |
tree | ee08f2d9d6aaa8adb1c5f07f4124da8a61eb8cd5 /core/multimedia/opieplayer/libmad/decoder.c | |
parent | caa7ced77b9014526607f9f65c58aabe7e0ba631 (diff) | |
download | opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.zip opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.gz opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.bz2 |
new libmad version, less cpu usage
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,4 +1,4 @@ | |||
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 | * |
@@ -21,17 +21,12 @@ | |||
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 |
@@ -43,7 +38,13 @@ | |||
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" |
@@ -53,12 +54,16 @@ | |||
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 *, |
@@ -87,4 +92,5 @@ void mad_decoder_init(struct mad_decoder *decoder, void *data, | |||
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; |
@@ -93,7 +99,6 @@ int mad_decoder_finish(struct mad_decoder *decoder) | |||
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 | ||
@@ -111,8 +116,10 @@ int mad_decoder_finish(struct mad_decoder *decoder) | |||
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) |
@@ -122,7 +129,6 @@ enum mad_flow send_io(int fd, void const *data, size_t len) | |||
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 | ||
@@ -144,7 +150,6 @@ enum mad_flow receive_io(int fd, void *buffer, size_t len) | |||
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 | ||
@@ -282,4 +287,5 @@ enum mad_flow check_message(struct mad_decoder *decoder) | |||
282 | return result; | 287 | return result; |
283 | } | 288 | } |
289 | # endif | ||
284 | 290 | ||
285 | static | 291 | static |
@@ -349,4 +355,5 @@ int run_sync(struct mad_decoder *decoder) | |||
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)) { |
@@ -360,4 +367,5 @@ int run_sync(struct mad_decoder *decoder) | |||
360 | } | 367 | } |
361 | } | 368 | } |
369 | # endif | ||
362 | 370 | ||
363 | if (decoder->header_func) { | 371 | if (decoder->header_func) { |
@@ -410,5 +418,5 @@ int run_sync(struct mad_decoder *decoder) | |||
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; |
@@ -451,4 +459,5 @@ int run_sync(struct mad_decoder *decoder) | |||
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) |
@@ -512,4 +521,5 @@ int run_async(struct mad_decoder *decoder) | |||
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) |
@@ -524,5 +534,7 @@ int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) | |||
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 | } |
@@ -546,4 +558,5 @@ 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 || |
@@ -552,3 +565,6 @@ int mad_decoder_message(struct mad_decoder *decoder, | |||
552 | 565 | ||
553 | return 0; | 566 | return 0; |
567 | # else | ||
568 | return -1; | ||
569 | # endif | ||
554 | } | 570 | } |