1 /*
2  * Copyright 2008-2013 Various Authors
3  * Copyright 2004-2005 Timo Hirvonen
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * 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 
19 #ifndef CMUS_IP_H
20 #define CMUS_IP_H
21 
22 #include "keyval.h"
23 #include "sf.h"
24 #include "channelmap.h"
25 
26 #ifndef __GNUC__
27 #include <fcntl.h>
28 #include <unistd.h>
29 #endif
30 
31 #define IP_ABI_VERSION 1
32 
33 enum {
34 	/* no error */
35 	IP_ERROR_SUCCESS,
36 	/* system error (error code in errno) */
37 	IP_ERROR_ERRNO,
38 	/* file type not recognized */
39 	IP_ERROR_UNRECOGNIZED_FILE_TYPE,
40 	/* file type recognized, but not supported */
41 	IP_ERROR_UNSUPPORTED_FILE_TYPE,
42 	/* function not supported (usually seek) */
43 	IP_ERROR_FUNCTION_NOT_SUPPORTED,
44 	/* input plugin detected corrupted file */
45 	IP_ERROR_FILE_FORMAT,
46 	/* malformed uri */
47 	IP_ERROR_INVALID_URI,
48 	/* sample format not supported */
49 	IP_ERROR_SAMPLE_FORMAT,
50 	/* wrong disc inserted */
51 	IP_ERROR_WRONG_DISC,
52 	/* could not read disc */
53 	IP_ERROR_NO_DISC,
54 	/* error parsing response line / headers */
55 	IP_ERROR_HTTP_RESPONSE,
56 	/* usually 404 */
57 	IP_ERROR_HTTP_STATUS,
58 	/* too many redirections */
59 	IP_ERROR_HTTP_REDIRECT_LIMIT,
60 	/* plugin does not have this option */
61 	IP_ERROR_NOT_OPTION,
62 	/*  */
63 	IP_ERROR_INTERNAL
64 };
65 
66 struct input_plugin_data {
67 	/* filled by ip-layer */
68 	char *filename;
69 	int fd;
70 
71 	unsigned int remote : 1;
72 	unsigned int metadata_changed : 1;
73 
74 	/* shoutcast */
75 	int counter;
76 	int metaint;
77 	char *metadata;
78 	char *icy_name;
79 	char *icy_genre;
80 	char *icy_url;
81 
82 	/* filled by plugin */
83 	sample_format_t sf;
84 	channel_position_t channel_map[CHANNELS_MAX];
85 	void *private;
86 };
87 
88 struct input_plugin_ops {
89 	int (*open)(struct input_plugin_data *ip_data);
90 	int (*close)(struct input_plugin_data *ip_data);
91 	int (*read)(struct input_plugin_data *ip_data, char *buffer, int count);
92 	int (*seek)(struct input_plugin_data *ip_data, double offset);
93 	int (*read_comments)(struct input_plugin_data *ip_data,
94 			struct keyval **comments);
95 	int (*duration)(struct input_plugin_data *ip_data);
96 	long (*bitrate)(struct input_plugin_data *ip_data);
97 	long (*bitrate_current)(struct input_plugin_data *ip_data);
98 	char *(*codec)(struct input_plugin_data *ip_data);
99 	char *(*codec_profile)(struct input_plugin_data *ip_data);
100 };
101 
102 struct input_plugin_opt {
103 	const char *name;
104 	int (*set)(const char *val);
105 	int (*get)(char **val);
106 };
107 
108 /* symbols exported by plugin */
109 extern const struct input_plugin_ops ip_ops;
110 extern const int ip_priority;
111 extern const char * const ip_extensions[];
112 extern const char * const ip_mime_types[];
113 extern const struct input_plugin_opt ip_options[];
114 extern const unsigned ip_abi_version;
115 
116 #endif
117