• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Control Interface - local header file
3  *  Copyright (c) 2000 by Jaroslav Kysela <perex@perex.cz>
4  *
5  *
6  *   This library is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU Lesser General Public License as
8  *   published by the Free Software Foundation; either version 2.1 of
9  *   the License, or (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #include "local.h"
23 #include <sound/tlv.h>
24 
25 typedef struct _snd_ctl_ops {
26 	int (*close)(snd_ctl_t *handle);
27 	int (*nonblock)(snd_ctl_t *handle, int nonblock);
28 	int (*async)(snd_ctl_t *handle, int sig, pid_t pid);
29 	int (*subscribe_events)(snd_ctl_t *handle, int subscribe);
30 	int (*card_info)(snd_ctl_t *handle, snd_ctl_card_info_t *info);
31 	int (*element_list)(snd_ctl_t *handle, snd_ctl_elem_list_t *list);
32 	int (*element_info)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
33 	int (*element_add)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
34 	int (*element_replace)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
35 	int (*element_remove)(snd_ctl_t *handle, snd_ctl_elem_id_t *id);
36 	int (*element_read)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
37 	int (*element_write)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
38 	int (*element_lock)(snd_ctl_t *handle, snd_ctl_elem_id_t *lock);
39 	int (*element_unlock)(snd_ctl_t *handle, snd_ctl_elem_id_t *unlock);
40 	int (*element_tlv)(snd_ctl_t *handle, int op_flag, unsigned int numid,
41 			   unsigned int *tlv, unsigned int tlv_size);
42 	int (*hwdep_next_device)(snd_ctl_t *handle, int *device);
43 	int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info);
44 	int (*pcm_next_device)(snd_ctl_t *handle, int *device);
45 	int (*pcm_info)(snd_ctl_t *handle, snd_pcm_info_t * info);
46 	int (*pcm_prefer_subdevice)(snd_ctl_t *handle, int subdev);
47 	int (*rawmidi_next_device)(snd_ctl_t *handle, int *device);
48 	int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info);
49 	int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev);
50 	int (*ump_next_device)(snd_ctl_t *handle, int *device);
51 	int (*ump_endpoint_info)(snd_ctl_t *handle, snd_ump_endpoint_info_t *info);
52 	int (*ump_block_info)(snd_ctl_t *handle, snd_ump_block_info_t *info);
53 	int (*set_power_state)(snd_ctl_t *handle, unsigned int state);
54 	int (*get_power_state)(snd_ctl_t *handle, unsigned int *state);
55 	int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event);
56 	int (*poll_descriptors_count)(snd_ctl_t *handle);
57 	int (*poll_descriptors)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int space);
58 	int (*poll_revents)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
59 } snd_ctl_ops_t;
60 
61 
62 struct _snd_ctl {
63 	void *open_func;
64 	char *name;
65 	snd_ctl_type_t type;
66 	const snd_ctl_ops_t *ops;
67 	void *private_data;
68 	int mode;
69 	int nonblock;
70 	int poll_fd;
71 	struct list_head async_handlers;
72 };
73 
74 struct _snd_hctl_elem {
75 	snd_ctl_elem_id_t id; 		/* must be always on top */
76 	struct list_head list;		/* links for list of all helems */
77 	int compare_weight;		/* compare weight (reversed) */
78 	/* event callback */
79 	snd_hctl_elem_callback_t callback;
80 	void *callback_private;
81 	/* links */
82 	snd_hctl_t *hctl;		/* associated handle */
83 };
84 
85 struct _snd_hctl {
86 	snd_ctl_t *ctl;
87 	struct list_head elems;		/* list of all controls */
88 	unsigned int alloc;
89 	unsigned int count;
90 	snd_hctl_elem_t **pelems;
91 	snd_hctl_compare_t compare;
92 	snd_hctl_callback_t callback;
93 	void *callback_private;
94 };
95 
96 
97 /* make local functions really local */
98 #define snd_ctl_new	snd1_ctl_new
99 
100 int snd_ctl_new(snd_ctl_t **ctlp, snd_ctl_type_t type, const char *name, int mode);
101 int _snd_ctl_poll_descriptor(snd_ctl_t *ctl);
102 #define _snd_ctl_async_descriptor _snd_ctl_poll_descriptor
103 int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode);
104 int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *sockname, const char *sname, int mode);
105 int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid);
106 
107 #define CTLINABORT(x) ((x)->nonblock == 2)
108 
109 #ifdef INTERNAL
110 int INTERNAL(snd_ctl_elem_info_get_dimensions)(const snd_ctl_elem_info_t *obj);
111 int INTERNAL(snd_ctl_elem_info_get_dimension)(const snd_ctl_elem_info_t *obj, unsigned int idx);
112 #endif /* INTERNAL */
113 
114 int _snd_ctl_open_named_child(snd_ctl_t **pctl, const char *name,
115 			      snd_config_t *root, snd_config_t *conf,
116 			      int mode, snd_config_t *parent_conf);
117 static inline int
_snd_ctl_open_child(snd_ctl_t ** pctl,snd_config_t * root,snd_config_t * conf,int mode,snd_config_t * parent_conf)118 _snd_ctl_open_child(snd_ctl_t **pctl, snd_config_t *root,
119 		    snd_config_t *conf, int mode, snd_config_t *parent_conf)
120 {
121 	return _snd_ctl_open_named_child(pctl, NULL, root, conf, mode, parent_conf);
122 }
123 
124 int __snd_ctl_add_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
125 			   unsigned int element_count,
126 			   unsigned int member_count);
127 
128 int __snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst,
129 				  const char *str,
130 				  const char **ret_ptr);
131 
132 static inline int
__snd_pcm_info_eld_fixup_check(snd_pcm_info_t * info)133 __snd_pcm_info_eld_fixup_check(snd_pcm_info_t *info)
134 {
135 	return info->stream == SND_PCM_STREAM_PLAYBACK &&
136 	       strncmp((char *)info->name, "HDMI ", 5) == 0;
137 }
138 
139 int __snd_pcm_info_eld_fixup(snd_pcm_info_t *info);
140