chiark / gitweb /
plugins/tracklength-gstreamer.c: Rewrite to use `GstDiscoverer'.
[disorder] / server / decode.h
1 /*
2  * This file is part of DisOrder
3  * Copyright (C) 2007-2010 Richard Kettlewell
4  *
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
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 /** @file server/decode.h
19  * @brief General-purpose decoder for use by speaker process
20  */
21 #ifndef DECODE_H
22 #define DECODE_H
23
24 #include "disorder-server.h"
25 #include "hreader.h"
26 #include "speaker-protocol.h"
27
28 #define INPUT_BUFFER_SIZE 1048576
29   
30 /** @brief Output file */
31 extern FILE *outputfp;
32
33 /** @brief Input filename */
34 extern const char *path;
35
36 /** @brief Input buffer */
37 extern char input_buffer[INPUT_BUFFER_SIZE];
38
39 /** @brief Number of bytes read into buffer */
40 extern int input_count;
41
42 /** @brief Write an 8-bit word */
43 static inline void output_8(int n) {
44   if(putc(n, outputfp) < 0)
45     disorder_fatal(errno, "decoding %s: output error", path);
46 }
47
48 /** @brief Write a 16-bit word in bigendian format */
49 static inline void output_16(uint16_t n) {
50   if(putc(n >> 8, outputfp) < 0
51      || putc(n, outputfp) < 0)
52     disorder_fatal(errno, "decoding %s: output error", path);
53 }
54
55 /** @brief Write a 24-bit word in bigendian format */
56 static inline void output_24(uint32_t n) {
57   if(putc(n >> 16, outputfp) < 0
58      || putc(n >> 8, outputfp) < 0
59      || putc(n, outputfp) < 0)
60     disorder_fatal(errno, "decoding %s: output error", path);
61 }
62
63 /** @brief Write a 32-bit word in bigendian format */
64 static inline void output_32(uint32_t n) {
65   if(putc(n >> 24, outputfp) < 0
66      || putc(n >> 16, outputfp) < 0
67      || putc(n >> 8, outputfp) < 0
68      || putc(n, outputfp) < 0)
69     disorder_fatal(errno, "decoding %s: output error", path);
70 }
71
72 void output_header(int rate,
73                    int channels,
74                    int bits,
75                    int nbytes,
76                    int endian);
77
78 void decode_mp3(void);
79 void decode_ogg(void);
80 void decode_wav(void);
81 void decode_flac(void);
82
83 #endif /* DECODE_H */
84
85 /*
86 Local Variables:
87 c-basic-offset:2
88 comment-column:40
89 fill-column:79
90 indent-tabs-mode:nil
91 End:
92 */