1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* libmm-glib -- Access modem status & information from glib applications
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2017 Red Hat, Inc.
*/
#include <string.h>
#include "mm-errors-types.h"
#include "mm-call-audio-format.h"
/**
* SECTION: mm-call-audio-format
* @title: MMCallAudioFormat
* @short_description: Helper object to handle voice call audio formats.
*
* The #MMCallAudioFormat is an object handling the voice call audio format
* which describes how to send/receive voice call audio from the host.
*
* This object is retrieved with either mm_call_get_audio_format() or
* mm_call_peek_audio_format().
*/
G_DEFINE_TYPE (MMCallAudioFormat, mm_call_audio_format, G_TYPE_OBJECT)
#define PROPERTY_ENCODING "encoding"
#define PROPERTY_RESOLUTION "resolution"
#define PROPERTY_RATE "rate"
struct _MMCallAudioFormatPrivate {
gchar *encoding;
gchar *resolution;
guint rate;
};
/*****************************************************************************/
/**
* mm_call_audio_format_get_encoding:
* @self: a #MMCallAudioFormat.
*
* Gets the encoding of the audio format. For example, "pcm" for PCM-encoded
* audio.
*
* Returns: a string with the encoding, or #NULL if unknown. Do not free the
* returned value, it is owned by @self.
*
* Since: 1.10
*/
const gchar *
mm_call_audio_format_get_encoding (MMCallAudioFormat *self)
{
g_return_val_if_fail (MM_IS_CALL_AUDIO_FORMAT (self), NULL);
return self->priv->encoding;
}
/**
* mm_call_audio_format_set_encoding: (skip)
*/
void
mm_call_audio_format_set_encoding (MMCallAudioFormat *self,
const gchar *encoding)
{
g_return_if_fail (MM_IS_CALL_AUDIO_FORMAT (self));
g_free (self->priv->encoding);
self->priv->encoding = g_strdup (encoding);
}
/*****************************************************************************/
/**
* mm_call_audio_format_get_resolution:
* @self: a #MMCallAudioFormat.
*
* Gets the resolution of the audio format. For example, "s16le" for signed
* 16-bit little-endian audio sampling resolution.
*
* Returns: a string with the resolution, or #NULL if unknown. Do not free the
* returned value, it is owned by @self.
*
* Since: 1.10
*/
const gchar *
mm_call_audio_format_get_resolution (MMCallAudioFormat *self)
{
g_return_val_if_fail (MM_IS_CALL_AUDIO_FORMAT (self), NULL);
return self->priv->resolution;
}
/**
* mm_call_audio_format_set_resolution: (skip)
*/
void
mm_call_audio_format_set_resolution (MMCallAudioFormat *self,
const gchar *resolution)
{
g_return_if_fail (MM_IS_CALL_AUDIO_FORMAT (self));
g_free (self->priv->resolution);
self->priv->resolution = g_strdup (resolution);
}
/*****************************************************************************/
/**
* mm_call_audio_format_get_rate:
* @self: a #MMCallAudioFormat.
*
* Gets the sampling rate of the audio format. For example, 8000 for an 8000hz
* sampling rate.
*
* Returns: the sampling rate, or 0 if unknown.
*
* Since: 1.10
*/
guint
mm_call_audio_format_get_rate (MMCallAudioFormat *self)
{
g_return_val_if_fail (MM_IS_CALL_AUDIO_FORMAT (self), 0);
return self->priv->rate;
}
/**
* mm_call_audio_format_set_rate: (skip)
*/
void
mm_call_audio_format_set_rate (MMCallAudioFormat *self,
guint rate)
{
g_return_if_fail (MM_IS_CALL_AUDIO_FORMAT (self));
self->priv->rate = rate;
}
/*****************************************************************************/
/**
* mm_call_audio_format_get_dictionary: (skip)
*/
GVariant *
mm_call_audio_format_get_dictionary (MMCallAudioFormat *self)
{
GVariantBuilder builder;
/* We do allow NULL */
if (!self)
return NULL;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
if (self->priv->encoding)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_ENCODING,
g_variant_new_string (self->priv->encoding));
if (self->priv->resolution)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_RESOLUTION,
g_variant_new_string (self->priv->resolution));
if (self->priv->rate)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_RATE,
g_variant_new_uint32 (self->priv->rate));
return g_variant_builder_end (&builder);
}
/*****************************************************************************/
/**
* mm_call_audio_format_new_from_dictionary: (skip)
*/
MMCallAudioFormat *
mm_call_audio_format_new_from_dictionary (GVariant *dictionary,
GError **error)
{
GVariantIter iter;
gchar *key;
GVariant *value;
MMCallAudioFormat *self;
self = mm_call_audio_format_new ();
if (!dictionary)
return self;
if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{sv}"))) {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Cannot create call audio format from dictionary: "
"invalid variant type received");
g_object_unref (self);
return NULL;
}
g_variant_iter_init (&iter, dictionary);
while (g_variant_iter_next (&iter, "{sv}", &key, &value)) {
if (g_str_equal (key, PROPERTY_ENCODING))
mm_call_audio_format_set_encoding (
self,
g_variant_get_string (value, NULL));
else if (g_str_equal (key, PROPERTY_RESOLUTION))
mm_call_audio_format_set_resolution (
self,
g_variant_get_string (value, NULL));
else if (g_str_equal (key, PROPERTY_RATE))
mm_call_audio_format_set_rate (
self,
g_variant_get_uint32 (value));
g_free (key);
g_variant_unref (value);
}
return self;
}
/*****************************************************************************/
/**
* mm_call_audio_format_new: (skip)
*/
MMCallAudioFormat *
mm_call_audio_format_new (void)
{
return (MM_CALL_AUDIO_FORMAT (
g_object_new (MM_TYPE_CALL_AUDIO_FORMAT, NULL)));
}
static void
mm_call_audio_format_init (MMCallAudioFormat *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
MM_TYPE_CALL_AUDIO_FORMAT,
MMCallAudioFormatPrivate);
}
static void
finalize (GObject *object)
{
MMCallAudioFormat *self = MM_CALL_AUDIO_FORMAT (object);
g_free (self->priv->encoding);
g_free (self->priv->resolution);
G_OBJECT_CLASS (mm_call_audio_format_parent_class)->finalize (object);
}
static void
mm_call_audio_format_class_init (MMCallAudioFormatClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (MMCallAudioFormatPrivate));
object_class->finalize = finalize;
}
|