cc96dbbbf31793426ac5f5334be15d06f6d0576e
[paraslash.git] / afs.h
1 /*
2 * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
17 */
18
19 /** \file afs.h functions and structures for audio format handling (para_server) */
20
21 /** \cond */
22 #ifdef HAVE_OGGVORBIS
23 #define OV_AUDIO_FORMAT " ogg"
24 #define OV_AUDIO_FORMAT_ARRAY , "ogg"
25 #else
26 #define OV_AUDIO_FORMAT ""
27 #define OV_AUDIO_FORMAT_ARRAY
28 #endif
29
30 #ifdef HAVE_FAAD
31 #define AAC_AUDIO_FORMAT " aac"
32 #define AAC_AUDIO_FORMAT_ARRAY , "aac"
33 #else
34 #define AAC_AUDIO_FORMAT ""
35 #define AAC_AUDIO_FORMAT_ARRAY
36 #endif
37
38 #define SUPPORTED_AUDIO_FORMATS "mp3" OV_AUDIO_FORMAT AAC_AUDIO_FORMAT
39 #define SUPPORTED_AUDIO_FORMATS_ARRAY "mp3" OV_AUDIO_FORMAT_ARRAY \
40 AAC_AUDIO_FORMAT_ARRAY, NULL
41
42 /* status flags */
43 #define AFS_NOMORE 1
44 #define AFS_NEXT 2
45 #define AFS_REPOS 4
46 #define AFS_PLAYING 8
47 #define DBT_CHANGE 16
48 /** \endcond */
49
50 /**
51 * structure for audio format handling
52 *
53 * There's exactly one such struct for each supported audio format. Initially,
54 * only \a name and \a init are defined. During the startup process,
55 * para_server calls the \a init function of each audio format handler which is
56 * expected to fill in all the other function pointers.
57 */
58 struct audio_format {
59 /**
60 *
61 *
62 * name of the audio format
63 */
64 const char *name;
65 /**
66 *
67 *
68 * pointer to the audio format handler's init function
69 *
70 * Must initialize all function pointers and is assumed to succeed.
71 */
72 void (*init)(void*);
73 /**
74 *
75 *
76 * period of time between sending data chunks
77 */
78 struct timeval chunk_tv; /* length of one chunk of data */
79 /**
80 *
81 *
82 * end of file timeout - do not load new audio file until this time
83 *
84 */
85 struct timeval eof_tv; /* timeout on eof */
86 /**
87 *
88 *
89 * Pointer to the optional get-header function.
90 *
91 * This is called from a sender in case a new client connects in the middle of
92 * the stream. The audio format handler may set this to NULL to indicate that
93 * this audio format does not need any special header treatment. If non-NULL,
94 * the function it points to must return a pointer to a buffer holding the
95 * current audio file header, together with the header length.
96 */
97 char *(*get_header_info)(int *header_len);
98 /**
99 *
100 *
101 * check if this audio format handler can handle the file
102 *
103 * This is a pointer to a function returning whether a given file is valid for
104 * this audio format. A negative return value indicates that this audio format
105 * handler did not recognize the given file. On success, the function is
106 * expected to return a positive value and to fill in \arg info_str, \arg
107 * chunks and \arg seconds appropriately.
108 */
109 int (*get_file_info)(FILE *audio_file, char *info_str,
110 long unsigned *chunks, int *seconds);
111 /**
112 *
113 *
114 * cleanup function of this audio format handler
115 *
116 * This close function should deallocate any resources
117 * associated with the current audio file. In particular, it is responsible
118 * for closing the file handle. It is assumed to succeed.
119 */
120 void (*close_audio_file)(void);
121 /**
122 *
123 *
124 * jump to another position in the current audio file
125 *
126 * This is called if a client issued the ff or jmp command with \a request
127 * being the number of the next chunk that should be sent out. Must return a
128 * positive value on success and a negative value on errors.
129 */
130 int (*reposition_stream)(long unsigned request);
131 /**
132 *
133 *
134 * function responsible for reading one data chunk.
135 *
136 * \a read_chunk() must return a pointer to the next chunk of data that should
137 * be sent out, or \p NULL on errors or if the end of the file was encountered.
138 *
139 * If it returns non-NULL, \a len must contain the length of the returned
140 * buffer (which may be zero if nothing has to be sent for some reason).
141 * Otherwise, \a len is used to distinguish between the eof and the error case:
142 * It must be zero in the eof case, or negative if an error occcured.
143 */
144 char * (*read_chunk)(long unsigned chunk_num, ssize_t *len);
145 };
146
147 void afs_init(void);
148 void afs_send_chunk(void);
149 struct timeval *afs_preselect(void);
150 const char *audio_format_name(int);
151 unsigned int afs_playing(void);
152 unsigned int afs_next(void);
153 unsigned int afs_repos(void);
154 unsigned int afs_paused(void);
155