• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2012 Fluendo S.A. <support@fluendo.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <gst/gst.h>
25 #include <SLES/OpenSLES.h>
26 
27 #include "opensles.h"
28 #include "openslessink.h"
29 #include "openslessrc.h"
30 
31 static GMutex engine_mutex;
32 static SLObjectItf engine_object = NULL;
33 static gint engine_object_refcount = 0;
34 
35 SLObjectItf
gst_opensles_get_engine(void)36 gst_opensles_get_engine (void)
37 {
38   g_mutex_lock (&engine_mutex);
39   if (!engine_object) {
40     SLresult result;
41     result = slCreateEngine (&engine_object, 0, NULL, 0, NULL, NULL);
42     if (result != SL_RESULT_SUCCESS) {
43       GST_ERROR ("slCreateEngine failed(0x%08x)", (guint32) result);
44       engine_object = NULL;
45     }
46 
47     result = (*engine_object)->Realize (engine_object, SL_BOOLEAN_FALSE);
48     if (result != SL_RESULT_SUCCESS) {
49       GST_ERROR ("engine.Realize failed(0x%08x)", (guint32) result);
50       (*engine_object)->Destroy (engine_object);
51       engine_object = NULL;
52     }
53   }
54 
55   if (engine_object) {
56     engine_object_refcount++;
57   }
58   g_mutex_unlock (&engine_mutex);
59 
60   return engine_object;
61 }
62 
63 void
gst_opensles_release_engine(SLObjectItf engine_object_parameter)64 gst_opensles_release_engine (SLObjectItf engine_object_parameter)
65 {
66   g_mutex_lock (&engine_mutex);
67   g_assert (engine_object == engine_object_parameter);
68 
69   if (engine_object) {
70     engine_object_refcount--;
71 
72     if (engine_object_refcount == 0) {
73       (*engine_object)->Destroy (engine_object);
74       engine_object = NULL;
75     }
76   }
77   g_mutex_unlock (&engine_mutex);
78 }
79 
80 static gboolean
plugin_init(GstPlugin * plugin)81 plugin_init (GstPlugin * plugin)
82 {
83   g_mutex_init (&engine_mutex);
84 
85   if (!gst_element_register (plugin, "openslessink", GST_RANK_PRIMARY,
86           GST_TYPE_OPENSLES_SINK)) {
87     return FALSE;
88   }
89   if (!gst_element_register (plugin, "openslessrc", GST_RANK_PRIMARY,
90           GST_TYPE_OPENSLES_SRC)) {
91     return FALSE;
92   }
93 
94   return TRUE;
95 }
96 
97 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
98     GST_VERSION_MINOR,
99     opensles,
100     "OpenSL ES support for GStreamer",
101     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
102