• 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 /**
21  * SECTION:element-openslessrc
22  * @title: openslessrc
23  * @see_also: openslessink
24  *
25  * This element reads data from default audio input using the OpenSL ES API in Android OS.
26  *
27  * ## Example pipelines
28  * |[
29  * gst-launch-1.0 -v openslessrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=recorded.ogg
30  * ]| Record from default audio input and encode to Ogg/Vorbis.
31  *
32  */
33 
34 #ifdef HAVE_CONFIG_H
35 #  include <config.h>
36 #endif
37 
38 #include "opensles.h"
39 #include "openslessrc.h"
40 
41 GST_DEBUG_CATEGORY_STATIC (opensles_src_debug);
42 #define GST_CAT_DEFAULT opensles_src_debug
43 
44 /* *INDENT-OFF* */
45 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
46     GST_PAD_SRC,
47     GST_PAD_ALWAYS,
48     GST_STATIC_CAPS ("audio/x-raw, "
49         "format = (string) " GST_AUDIO_NE (S16) ", "
50         "rate = (int) 16000, "
51         "channels = (int) 1, "
52         "layout = (string) interleaved")
53     );
54 /* *INDENT-ON* */
55 
56 #define _do_init \
57   GST_DEBUG_CATEGORY_INIT (opensles_src_debug, "openslessrc", 0, \
58       "OpenSLES Source");
59 #define parent_class gst_opensles_src_parent_class
60 G_DEFINE_TYPE_WITH_CODE (GstOpenSLESSrc, gst_opensles_src,
61     GST_TYPE_AUDIO_BASE_SRC, _do_init);
62 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (openslessrc, "openslessrc",
63     GST_RANK_PRIMARY, GST_TYPE_OPENSLES_SRC, opensles_element_init (plugin));
64 
65 enum
66 {
67   PROP_0,
68   PROP_PRESET,
69 };
70 
71 #define DEFAULT_PRESET GST_OPENSLES_RECORDING_PRESET_NONE
72 
73 
74 static void
gst_opensles_src_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)75 gst_opensles_src_set_property (GObject * object, guint prop_id,
76     const GValue * value, GParamSpec * pspec)
77 {
78   GstOpenSLESSrc *src = GST_OPENSLES_SRC (object);
79 
80   switch (prop_id) {
81     case PROP_PRESET:
82       src->preset = g_value_get_enum (value);
83       break;
84     default:
85       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
86       break;
87   }
88 }
89 
90 static void
gst_opensles_src_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)91 gst_opensles_src_get_property (GObject * object, guint prop_id,
92     GValue * value, GParamSpec * pspec)
93 {
94   GstOpenSLESSrc *src = GST_OPENSLES_SRC (object);
95 
96   switch (prop_id) {
97     case PROP_PRESET:
98       g_value_set_enum (value, src->preset);
99       break;
100     default:
101       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
102       break;
103   }
104 }
105 
106 static GstAudioRingBuffer *
gst_opensles_src_create_ringbuffer(GstAudioBaseSrc * base)107 gst_opensles_src_create_ringbuffer (GstAudioBaseSrc * base)
108 {
109   GstAudioRingBuffer *rb;
110 
111   rb = gst_opensles_ringbuffer_new (RB_MODE_SRC);
112   GST_OPENSLES_RING_BUFFER (rb)->preset = GST_OPENSLES_SRC (base)->preset;
113 
114   return rb;
115 }
116 
117 static void
gst_opensles_src_class_init(GstOpenSLESSrcClass * klass)118 gst_opensles_src_class_init (GstOpenSLESSrcClass * klass)
119 {
120   GObjectClass *gobject_class;
121   GstElementClass *gstelement_class;
122   GstAudioBaseSrcClass *gstaudiobasesrc_class;
123 
124   gobject_class = (GObjectClass *) klass;
125   gstelement_class = (GstElementClass *) klass;
126   gstaudiobasesrc_class = (GstAudioBaseSrcClass *) klass;
127 
128   gobject_class->set_property = gst_opensles_src_set_property;
129   gobject_class->get_property = gst_opensles_src_get_property;
130 
131   g_object_class_install_property (gobject_class, PROP_PRESET,
132       g_param_spec_enum ("preset", "Preset", "Recording preset to use",
133           GST_TYPE_OPENSLES_RECORDING_PRESET, DEFAULT_PRESET,
134           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
135 
136   gst_element_class_add_static_pad_template (gstelement_class, &src_factory);
137 
138   gst_element_class_set_static_metadata (gstelement_class, "OpenSL ES Src",
139       "Source/Audio",
140       "Input sound using the OpenSL ES APIs",
141       "Josep Torra <support@fluendo.com>");
142 
143   gstaudiobasesrc_class->create_ringbuffer =
144       GST_DEBUG_FUNCPTR (gst_opensles_src_create_ringbuffer);
145 }
146 
147 static void
gst_opensles_src_init(GstOpenSLESSrc * src)148 gst_opensles_src_init (GstOpenSLESSrc * src)
149 {
150   src->preset = DEFAULT_PRESET;
151 }
152