Diffstat (limited to 'core/multimedia/opieplayer/libmad/decoder.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/decoder.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/libmad/decoder.c b/core/multimedia/opieplayer/libmad/decoder.c index b2b6cbb..d039bfb 100644 --- a/core/multimedia/opieplayer/libmad/decoder.c +++ b/core/multimedia/opieplayer/libmad/decoder.c | |||
@@ -1,27 +1,27 @@ | |||
1 | /* | 1 | /* |
2 | * libmad - MPEG audio decoder library | 2 | * libmad - MPEG audio decoder library |
3 | * Copyright (C) 2000-2001 Robert Leslie | 3 | * Copyright (C) 2000-2004 Underbit Technologies, Inc. |
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 |
7 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. | 8 | * (at your option) any later version. |
9 | * | 9 | * |
10 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | * | 18 | * |
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 | # endif | 24 | # endif |
25 | 25 | ||
26 | # include "libmad_global.h" | 26 | # include "libmad_global.h" |
27 | 27 | ||
@@ -31,48 +31,52 @@ | |||
31 | 31 | ||
32 | # ifdef HAVE_SYS_WAIT_H | 32 | # ifdef HAVE_SYS_WAIT_H |
33 | # include <sys/wait.h> | 33 | # include <sys/wait.h> |
34 | # endif | 34 | # endif |
35 | 35 | ||
36 | # ifdef HAVE_UNISTD_H | 36 | # ifdef HAVE_UNISTD_H |
37 | # include <unistd.h> | 37 | # include <unistd.h> |
38 | # endif | 38 | # endif |
39 | 39 | ||
40 | # ifdef HAVE_FCNTL_H | 40 | # ifdef HAVE_FCNTL_H |
41 | # include <fcntl.h> | 41 | # include <fcntl.h> |
42 | # endif | 42 | # endif |
43 | 43 | ||
44 | # include <stdlib.h> | 44 | # include <stdlib.h> |
45 | 45 | ||
46 | # ifdef HAVE_ERRNO_H | 46 | # ifdef HAVE_ERRNO_H |
47 | # include <errno.h> | 47 | # include <errno.h> |
48 | # endif | 48 | # endif |
49 | 49 | ||
50 | # include "stream.h" | 50 | # include "stream.h" |
51 | # include "frame.h" | 51 | # include "frame.h" |
52 | # include "synth.h" | 52 | # include "synth.h" |
53 | # include "decoder.h" | 53 | # include "decoder.h" |
54 | 54 | ||
55 | /* | ||
56 | * NAME:decoder->init() | ||
57 | * DESCRIPTION:initialize a decoder object with callback routines | ||
58 | */ | ||
55 | void mad_decoder_init(struct mad_decoder *decoder, void *data, | 59 | void mad_decoder_init(struct mad_decoder *decoder, void *data, |
56 | enum mad_flow (*input_func)(void *, | 60 | enum mad_flow (*input_func)(void *, |
57 | struct mad_stream *), | 61 | struct mad_stream *), |
58 | enum mad_flow (*header_func)(void *, | 62 | enum mad_flow (*header_func)(void *, |
59 | struct mad_header const *), | 63 | struct mad_header const *), |
60 | enum mad_flow (*filter_func)(void *, | 64 | enum mad_flow (*filter_func)(void *, |
61 | struct mad_stream const *, | 65 | struct mad_stream const *, |
62 | struct mad_frame *), | 66 | struct mad_frame *), |
63 | enum mad_flow (*output_func)(void *, | 67 | enum mad_flow (*output_func)(void *, |
64 | struct mad_header const *, | 68 | struct mad_header const *, |
65 | struct mad_pcm *), | 69 | struct mad_pcm *), |
66 | enum mad_flow (*error_func)(void *, | 70 | enum mad_flow (*error_func)(void *, |
67 | struct mad_stream *, | 71 | struct mad_stream *, |
68 | struct mad_frame *), | 72 | struct mad_frame *), |
69 | enum mad_flow (*message_func)(void *, | 73 | enum mad_flow (*message_func)(void *, |
70 | void *, unsigned int *)) | 74 | void *, unsigned int *)) |
71 | { | 75 | { |
72 | decoder->mode = -1; | 76 | decoder->mode = -1; |
73 | 77 | ||
74 | decoder->options = 0; | 78 | decoder->options = 0; |
75 | 79 | ||
76 | decoder->async.pid = 0; | 80 | decoder->async.pid = 0; |
77 | decoder->async.in = -1; | 81 | decoder->async.in = -1; |
78 | decoder->async.out = -1; | 82 | decoder->async.out = -1; |
@@ -501,70 +505,78 @@ int run_async(struct mad_decoder *decoder) | |||
501 | close(ptoc[0]); | 505 | close(ptoc[0]); |
502 | close(ctop[1]); | 506 | close(ctop[1]); |
503 | 507 | ||
504 | decoder->async.in = ctop[0]; | 508 | decoder->async.in = ctop[0]; |
505 | decoder->async.out = ptoc[1]; | 509 | decoder->async.out = ptoc[1]; |
506 | 510 | ||
507 | return 0; | 511 | return 0; |
508 | } | 512 | } |
509 | 513 | ||
510 | /* child */ | 514 | /* child */ |
511 | 515 | ||
512 | close(ptoc[1]); | 516 | close(ptoc[1]); |
513 | close(ctop[0]); | 517 | close(ctop[0]); |
514 | 518 | ||
515 | decoder->async.in = ptoc[0]; | 519 | decoder->async.in = ptoc[0]; |
516 | decoder->async.out = ctop[1]; | 520 | decoder->async.out = ctop[1]; |
517 | 521 | ||
518 | _exit(run_sync(decoder)); | 522 | _exit(run_sync(decoder)); |
519 | 523 | ||
520 | /* not reached */ | 524 | /* not reached */ |
521 | return -1; | 525 | return -1; |
522 | } | 526 | } |
523 | # endif | 527 | # endif |
524 | 528 | ||
529 | /* | ||
530 | * NAME:decoder->run() | ||
531 | * DESCRIPTION:run the decoder thread either synchronously or asynchronously | ||
532 | */ | ||
525 | int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) | 533 | int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) |
526 | { | 534 | { |
527 | int result; | 535 | int result; |
528 | int (*run)(struct mad_decoder *) = 0; | 536 | int (*run)(struct mad_decoder *) = 0; |
529 | 537 | ||
530 | switch (decoder->mode = mode) { | 538 | switch (decoder->mode = mode) { |
531 | case MAD_DECODER_MODE_SYNC: | 539 | case MAD_DECODER_MODE_SYNC: |
532 | run = run_sync; | 540 | run = run_sync; |
533 | break; | 541 | break; |
534 | 542 | ||
535 | case MAD_DECODER_MODE_ASYNC: | 543 | case MAD_DECODER_MODE_ASYNC: |
536 | # if defined(USE_ASYNC) | 544 | # if defined(USE_ASYNC) |
537 | run = run_async; | 545 | run = run_async; |
538 | # endif | 546 | # endif |
539 | break; | 547 | break; |
540 | } | 548 | } |
541 | 549 | ||
542 | if (run == 0) | 550 | if (run == 0) |
543 | return -1; | 551 | return -1; |
544 | 552 | ||
545 | decoder->sync = malloc(sizeof(*decoder->sync)); | 553 | decoder->sync = malloc(sizeof(*decoder->sync)); |
546 | if (decoder->sync == 0) | 554 | if (decoder->sync == 0) |
547 | return -1; | 555 | return -1; |
548 | 556 | ||
549 | result = run(decoder); | 557 | result = run(decoder); |
550 | 558 | ||
551 | free(decoder->sync); | 559 | free(decoder->sync); |
552 | decoder->sync = 0; | 560 | decoder->sync = 0; |
553 | 561 | ||
554 | return result; | 562 | return result; |
555 | } | 563 | } |
556 | 564 | ||
565 | /* | ||
566 | * NAME:decoder->message() | ||
567 | * DESCRIPTION:send a message to and receive a reply from the decoder process | ||
568 | */ | ||
557 | int mad_decoder_message(struct mad_decoder *decoder, | 569 | int mad_decoder_message(struct mad_decoder *decoder, |
558 | void *message, unsigned int *len) | 570 | void *message, unsigned int *len) |
559 | { | 571 | { |
560 | # if defined(USE_ASYNC) | 572 | # if defined(USE_ASYNC) |
561 | if (decoder->mode != MAD_DECODER_MODE_ASYNC || | 573 | if (decoder->mode != MAD_DECODER_MODE_ASYNC || |
562 | send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE || | 574 | send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE || |
563 | receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE) | 575 | receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE) |
564 | return -1; | 576 | return -1; |
565 | 577 | ||
566 | return 0; | 578 | return 0; |
567 | # else | 579 | # else |
568 | return -1; | 580 | return -1; |
569 | # endif | 581 | # endif |
570 | } | 582 | } |