gnome-shell-3.6.3.1/src/gvc/gvc-mixer-event-role.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found gvc/gvc-mixer-event-role.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  2  *
  3  * Copyright (C) 2008 William Jon McCann
  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 2 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, write to the Free Software
 17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 18  *
 19  */
 20 
 21 #include "config.h"
 22 
 23 #include <stdlib.h>
 24 #include <stdio.h>
 25 #include <unistd.h>
 26 
 27 #include <glib.h>
 28 #include <glib/gi18n-lib.h>
 29 
 30 #include <pulse/pulseaudio.h>
 31 #include <pulse/ext-stream-restore.h>
 32 
 33 #include "gvc-mixer-event-role.h"
 34 #include "gvc-mixer-stream-private.h"
 35 #include "gvc-channel-map-private.h"
 36 
 37 #define GVC_MIXER_EVENT_ROLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_MIXER_EVENT_ROLE, GvcMixerEventRolePrivate))
 38 
 39 struct GvcMixerEventRolePrivate
 40 {
 41         char          *device;
 42 };
 43 
 44 enum
 45 {
 46         PROP_0,
 47         PROP_DEVICE
 48 };
 49 
 50 static void     gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass);
 51 static void     gvc_mixer_event_role_init       (GvcMixerEventRole      *mixer_event_role);
 52 static void     gvc_mixer_event_role_finalize   (GObject            *object);
 53 
 54 G_DEFINE_TYPE (GvcMixerEventRole, gvc_mixer_event_role, GVC_TYPE_MIXER_STREAM)
 55 
 56 static gboolean
 57 update_settings (GvcMixerEventRole *role,
 58                  gboolean           is_muted,
 59                  gpointer          *op)
 60 {
 61         pa_operation              *o;
 62         const GvcChannelMap       *map;
 63         pa_context                *context;
 64         pa_ext_stream_restore_info info;
 65 
 66         map = gvc_mixer_stream_get_channel_map (GVC_MIXER_STREAM(role));
 67 
 68         info.volume = *gvc_channel_map_get_cvolume(map);
 69         info.name = "sink-input-by-media-role:event";
 70         info.channel_map = *gvc_channel_map_get_pa_channel_map(map);
 71         info.device = role->priv->device;
 72         info.mute = is_muted;
 73 
 74         context = gvc_mixer_stream_get_pa_context (GVC_MIXER_STREAM (role));
 75 
 76         o = pa_ext_stream_restore_write (context,
 77                                          PA_UPDATE_REPLACE,
 78                                          &info,
 79                                          1,
 80                                          TRUE,
 81                                          NULL,
 82                                          NULL);
 83 
 84         if (o == NULL) {
 85                 g_warning ("pa_ext_stream_restore_write() failed");
 86                 return FALSE;
 87         }
 88 
 89         if (op != NULL)
 90                 *op = o;
 91 
 92         return TRUE;
 93 }
 94 
 95 static gboolean
 96 gvc_mixer_event_role_push_volume (GvcMixerStream *stream, gpointer *op)
 97 {
 98         return update_settings (GVC_MIXER_EVENT_ROLE (stream),
 99                                 gvc_mixer_stream_get_is_muted (stream), op);
100 }
101 
102 static gboolean
103 gvc_mixer_event_role_change_is_muted (GvcMixerStream *stream,
104                                       gboolean        is_muted)
105 {
106         return update_settings (GVC_MIXER_EVENT_ROLE (stream),
107                                 is_muted, NULL);
108 }
109 
110 static gboolean
111 gvc_mixer_event_role_set_device (GvcMixerEventRole *role,
112                                  const char        *device)
113 {
114         g_return_val_if_fail (GVC_IS_MIXER_EVENT_ROLE (role), FALSE);
115 
116         g_free (role->priv->device);
117         role->priv->device = g_strdup (device);
118         g_object_notify (G_OBJECT (role), "device");
119 
120         return TRUE;
121 }
122 
123 static void
124 gvc_mixer_event_role_set_property (GObject       *object,
125                                    guint          prop_id,
126                                    const GValue  *value,
127                                    GParamSpec    *pspec)
128 {
129         GvcMixerEventRole *self = GVC_MIXER_EVENT_ROLE (object);
130 
131         switch (prop_id) {
132         case PROP_DEVICE:
133                 gvc_mixer_event_role_set_device (self, g_value_get_string (value));
134                 break;
135         default:
136                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137                 break;
138         }
139 }
140 
141 static void
142 gvc_mixer_event_role_get_property (GObject     *object,
143                                    guint        prop_id,
144                                    GValue      *value,
145                                    GParamSpec  *pspec)
146 {
147         GvcMixerEventRole *self = GVC_MIXER_EVENT_ROLE (object);
148 
149         switch (prop_id) {
150         case PROP_DEVICE:
151                 g_value_set_string (value, self->priv->device);
152                 break;
153         default:
154                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
155                 break;
156         }
157 }
158 
159 static void
160 gvc_mixer_event_role_class_init (GvcMixerEventRoleClass *klass)
161 {
162         GObjectClass        *object_class = G_OBJECT_CLASS (klass);
163         GvcMixerStreamClass *stream_class = GVC_MIXER_STREAM_CLASS (klass);
164 
165         object_class->finalize = gvc_mixer_event_role_finalize;
166         object_class->set_property = gvc_mixer_event_role_set_property;
167         object_class->get_property = gvc_mixer_event_role_get_property;
168 
169         stream_class->push_volume = gvc_mixer_event_role_push_volume;
170         stream_class->change_is_muted = gvc_mixer_event_role_change_is_muted;
171 
172         g_object_class_install_property (object_class,
173                                          PROP_DEVICE,
174                                          g_param_spec_string ("device",
175                                                               "Device",
176                                                               "Device",
177                                                               NULL,
178                                                               G_PARAM_READWRITE|G_PARAM_CONSTRUCT));
179 
180         g_type_class_add_private (klass, sizeof (GvcMixerEventRolePrivate));
181 }
182 
183 static void
184 gvc_mixer_event_role_init (GvcMixerEventRole *event_role)
185 {
186         event_role->priv = GVC_MIXER_EVENT_ROLE_GET_PRIVATE (event_role);
187 
188 }
189 
190 static void
191 gvc_mixer_event_role_finalize (GObject *object)
192 {
193         GvcMixerEventRole *mixer_event_role;
194 
195         g_return_if_fail (object != NULL);
196         g_return_if_fail (GVC_IS_MIXER_EVENT_ROLE (object));
197 
198         mixer_event_role = GVC_MIXER_EVENT_ROLE (object);
199 
200         g_return_if_fail (mixer_event_role->priv != NULL);
201 
202         g_free (mixer_event_role->priv->device);
203 
204         G_OBJECT_CLASS (gvc_mixer_event_role_parent_class)->finalize (object);
205 }
206 
207 /**
208  * gvc_mixer_event_role_new: (skip)
209  * @context:
210  * @device:
211  * @channel_map:
212  *
213  * Returns:
214  */
215 GvcMixerStream *
216 gvc_mixer_event_role_new (pa_context *context,
217                           const char *device,
218                           GvcChannelMap *channel_map)
219 {
220         GObject *object;
221 
222         object = g_object_new (GVC_TYPE_MIXER_EVENT_ROLE,
223                                "pa-context", context,
224                                "index", 0,
225                                "device", device,
226                                "channel-map", channel_map,
227                                NULL);
228 
229         return GVC_MIXER_STREAM (object);
230 }