gst: don't use volatile to mean atomic
[platform/upstream/gstreamer.git] / sys / opensles / openslescommon.c
1 /* GStreamer
2  * Copyright (C) 2015 Centricular Ltd.,
3  *                    Arun Raghavan <mail@arunraghavan.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "openslescommon.h"
22
23 #ifndef SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION
24 /* This was added in Android API level 14 */
25 #define SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION ((SLuint32) 0x00000004)
26 #endif
27
28 GType
29 gst_opensles_recording_preset_get_type (void)
30 {
31   static const GEnumValue values[] = {
32     {GST_OPENSLES_RECORDING_PRESET_NONE,
33         "GST_OPENSLES_RECORDING_PRESET_NONE", "none"},
34     {GST_OPENSLES_RECORDING_PRESET_GENERIC,
35         "GST_OPENSLES_RECORDING_PRESET_GENERIC", "generic"},
36     {GST_OPENSLES_RECORDING_PRESET_CAMCORDER,
37         "GST_OPENSLES_RECORDING_PRESET_CAMCORDER", "camcorder"},
38     {GST_OPENSLES_RECORDING_PRESET_VOICE_RECOGNITION,
39         "GST_OPENSLES_RECORDING_PRESET_VOICE_RECOGNITION", "voice-recognition"},
40     {GST_OPENSLES_RECORDING_PRESET_VOICE_COMMUNICATION,
41           "GST_OPENSLES_RECORDING_PRESET_VOICE_COMMUNICATION",
42         "voice-communication"},
43     {0, NULL, NULL}
44   };
45   static GType id = 0;
46
47   if (g_once_init_enter ((gsize *) & id)) {
48     GType _id;
49
50     _id = g_enum_register_static ("GstOpenSLESRecordingPreset", values);
51
52     g_once_init_leave ((gsize *) & id, _id);
53   }
54
55   return id;
56 }
57
58 SLint32
59 gst_to_opensles_recording_preset (GstOpenSLESRecordingPreset preset)
60 {
61   switch (preset) {
62     case GST_OPENSLES_RECORDING_PRESET_NONE:
63       return SL_ANDROID_RECORDING_PRESET_NONE;
64
65     case GST_OPENSLES_RECORDING_PRESET_GENERIC:
66       return SL_ANDROID_RECORDING_PRESET_GENERIC;
67
68     case GST_OPENSLES_RECORDING_PRESET_CAMCORDER:
69       return SL_ANDROID_RECORDING_PRESET_CAMCORDER;
70
71     case GST_OPENSLES_RECORDING_PRESET_VOICE_RECOGNITION:
72       return SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
73
74     case GST_OPENSLES_RECORDING_PRESET_VOICE_COMMUNICATION:
75       return SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION;
76
77     default:
78       GST_ERROR ("Unsupported preset: %d", (int) preset);
79       return SL_ANDROID_RECORDING_PRESET_NONE;
80   }
81 }
82
83 GType
84 gst_opensles_stream_type_get_type (void)
85 {
86   static const GEnumValue values[] = {
87     {GST_OPENSLES_STREAM_TYPE_VOICE,
88         "GST_OPENSLES_STREAM_TYPE_VOICE", "voice"},
89     {GST_OPENSLES_STREAM_TYPE_SYSTEM,
90         "GST_OPENSLES_STREAM_TYPE_SYSTEM", "system"},
91     {GST_OPENSLES_STREAM_TYPE_RING,
92         "GST_OPENSLES_STREAM_TYPE_RING", "ring"},
93     {GST_OPENSLES_STREAM_TYPE_MEDIA,
94         "GST_OPENSLES_STREAM_TYPE_MEDIA", "media"},
95     {GST_OPENSLES_STREAM_TYPE_ALARM,
96         "GST_OPENSLES_STREAM_TYPE_ALARM", "alarm"},
97     {GST_OPENSLES_STREAM_TYPE_NOTIFICATION,
98         "GST_OPENSLES_STREAM_TYPE_NOTIFICATION", "notification"},
99     {GST_OPENSLES_STREAM_TYPE_NONE,
100         "GST_OPENSLES_STREAM_TYPE_NONE", "none"},
101     {0, NULL, NULL}
102   };
103   static GType id = 0;
104
105   if (g_once_init_enter ((gsize *) & id)) {
106     GType _id;
107
108     _id = g_enum_register_static ("GstOpenSLESStreamType", values);
109
110     g_once_init_leave ((gsize *) & id, _id);
111   }
112
113   return id;
114 }
115
116
117 SLint32
118 gst_to_opensles_stream_type (GstOpenSLESStreamType stream_type)
119 {
120   switch (stream_type) {
121     case GST_OPENSLES_STREAM_TYPE_VOICE:
122       return SL_ANDROID_STREAM_VOICE;
123
124     case GST_OPENSLES_STREAM_TYPE_SYSTEM:
125       return SL_ANDROID_STREAM_SYSTEM;
126
127     case GST_OPENSLES_STREAM_TYPE_RING:
128       return SL_ANDROID_STREAM_RING;
129
130     case GST_OPENSLES_STREAM_TYPE_MEDIA:
131       return SL_ANDROID_STREAM_MEDIA;
132
133     case GST_OPENSLES_STREAM_TYPE_ALARM:
134       return SL_ANDROID_STREAM_ALARM;
135
136     case GST_OPENSLES_STREAM_TYPE_NOTIFICATION:
137       return SL_ANDROID_STREAM_NOTIFICATION;
138
139     default:
140       GST_ERROR ("Unsupported stream type: %d", (int) stream_type);
141       return SL_ANDROID_STREAM_MEDIA;
142   }
143 }