2006-04-28 14:55:20 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
2009-01-02 20:39:34 +00:00
|
|
|
* Copyright (C) 2005,2006 Zaheer Abbas Merali <zaheerabbas at merali dot org>
|
|
|
|
* Copyright (C) 2008 Pioneers of the Inevitable <songbird@songbirdnest.com>
|
|
|
|
*
|
2006-04-28 14:55:20 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2004-05-20 19:45:13 +00:00
|
|
|
*
|
2006-04-28 14:55:20 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
|
|
|
* which case the following provisions apply instead of the ones
|
|
|
|
* mentioned above:
|
2004-05-20 19:45:13 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2004-05-20 19:45:13 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
/**
|
2009-01-29 08:10:08 +00:00
|
|
|
* SECTION:element-osxaudiosrc
|
|
|
|
*
|
|
|
|
* This element captures raw audio samples using the CoreAudio api.
|
2006-04-28 14:55:20 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
2009-01-29 08:10:08 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 osxaudiosrc ! wavenc ! filesink location=audio.wav
|
2009-01-29 08:10:08 +00:00
|
|
|
* ]|
|
2006-04-28 14:55:20 +00:00
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2004-05-20 19:45:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-04-28 14:55:20 +00:00
|
|
|
# include <config.h>
|
2004-05-20 19:45:13 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include "gstosxaudiosrc.h"
|
|
|
|
#include "gstosxaudioelement.h"
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (osx_audiosrc_debug);
|
|
|
|
#define GST_CAT_DEFAULT osx_audiosrc_debug
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
/* Filter signals and args */
|
2004-05-20 19:45:13 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_DEVICE
|
|
|
|
};
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
2004-05-20 19:45:13 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2016-04-30 13:15:13 +00:00
|
|
|
GST_STATIC_CAPS (GST_OSX_AUDIO_SRC_CAPS)
|
2004-05-20 19:45:13 +00:00
|
|
|
);
|
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
static void gst_osx_audio_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_osx_audio_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2014-11-28 16:53:17 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_osx_audio_src_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
|
2013-03-30 13:49:34 +00:00
|
|
|
static GstCaps *gst_osx_audio_src_get_caps (GstBaseSrc * src, GstCaps * filter);
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2013-03-30 13:49:34 +00:00
|
|
|
static GstAudioRingBuffer *gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc
|
|
|
|
* src);
|
2006-04-28 14:55:20 +00:00
|
|
|
static void gst_osx_audio_src_osxelement_init (gpointer g_iface,
|
|
|
|
gpointer iface_data);
|
2013-03-30 13:49:34 +00:00
|
|
|
static OSStatus gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf,
|
2009-01-02 20:39:34 +00:00
|
|
|
AudioUnitRenderActionFlags * ioActionFlags,
|
|
|
|
const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber,
|
|
|
|
UInt32 inNumberFrames, AudioBufferList * bufferList);
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
static void
|
2009-01-02 20:39:34 +00:00
|
|
|
gst_osx_audio_src_do_init (GType type)
|
2004-05-20 19:45:13 +00:00
|
|
|
{
|
2006-04-28 14:55:20 +00:00
|
|
|
static const GInterfaceInfo osxelement_info = {
|
|
|
|
gst_osx_audio_src_osxelement_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (osx_audiosrc_debug, "osxaudiosrc", 0,
|
|
|
|
"OSX Audio Src");
|
|
|
|
g_type_add_interface_static (type, GST_OSX_AUDIO_ELEMENT_TYPE,
|
|
|
|
&osxelement_info);
|
2004-05-20 19:45:13 +00:00
|
|
|
}
|
|
|
|
|
2014-11-28 16:53:17 +00:00
|
|
|
#define gst_osx_audio_src_parent_class parent_class
|
2013-03-30 13:49:34 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstOsxAudioSrc, gst_osx_audio_src,
|
2013-04-09 16:21:49 +00:00
|
|
|
GST_TYPE_AUDIO_BASE_SRC, gst_osx_audio_src_do_init (g_define_type_id));
|
2006-04-28 14:55:20 +00:00
|
|
|
|
2004-05-20 19:45:13 +00:00
|
|
|
static void
|
2006-04-28 14:55:20 +00:00
|
|
|
gst_osx_audio_src_class_init (GstOsxAudioSrcClass * klass)
|
2004-05-20 19:45:13 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2009-01-02 20:39:34 +00:00
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
2013-03-30 13:49:34 +00:00
|
|
|
GstAudioBaseSrcClass *gstaudiobasesrc_class;
|
2004-05-20 19:45:13 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2009-01-02 20:39:34 +00:00
|
|
|
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
2013-03-30 13:49:34 +00:00
|
|
|
gstaudiobasesrc_class = (GstAudioBaseSrcClass *) klass;
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2010-06-06 15:57:03 +00:00
|
|
|
gobject_class->set_property = gst_osx_audio_src_set_property;
|
|
|
|
gobject_class->get_property = gst_osx_audio_src_get_property;
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2014-11-28 16:53:17 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_osx_audio_src_change_state);
|
|
|
|
|
2009-01-02 20:39:34 +00:00
|
|
|
gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_osx_audio_src_get_caps);
|
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_DEVICE,
|
2007-10-23 08:38:50 +00:00
|
|
|
g_param_spec_int ("device", "Device ID", "Device ID of input device",
|
2010-10-13 14:21:23 +00:00
|
|
|
0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2006-04-28 14:55:20 +00:00
|
|
|
|
2013-03-30 13:49:34 +00:00
|
|
|
gstaudiobasesrc_class->create_ringbuffer =
|
2006-04-28 14:55:20 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_osx_audio_src_create_ringbuffer);
|
2013-03-30 13:49:34 +00:00
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &src_factory);
|
2013-03-30 13:49:34 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "Audio Source (OSX)",
|
|
|
|
"Source/Audio",
|
|
|
|
"Input from a sound card in OS X",
|
|
|
|
"Zaheer Abbas Merali <zaheerabbas at merali dot org>");
|
2004-05-20 19:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-03-30 13:49:34 +00:00
|
|
|
gst_osx_audio_src_init (GstOsxAudioSrc * src)
|
2004-05-20 19:45:13 +00:00
|
|
|
{
|
2006-04-28 14:55:20 +00:00
|
|
|
gst_base_src_set_live (GST_BASE_SRC (src), TRUE);
|
2008-08-26 21:13:08 +00:00
|
|
|
|
|
|
|
src->device_id = kAudioDeviceUnknown;
|
2004-05-20 19:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-04-28 14:55:20 +00:00
|
|
|
gst_osx_audio_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2004-05-20 19:45:13 +00:00
|
|
|
{
|
2006-04-28 14:55:20 +00:00
|
|
|
GstOsxAudioSrc *src = GST_OSX_AUDIO_SRC (object);
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
2008-08-26 21:13:08 +00:00
|
|
|
src->device_id = g_value_get_int (value);
|
2006-04-28 14:55:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2004-05-20 19:45:13 +00:00
|
|
|
}
|
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
static void
|
|
|
|
gst_osx_audio_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2004-05-20 19:45:13 +00:00
|
|
|
{
|
2006-04-28 14:55:20 +00:00
|
|
|
GstOsxAudioSrc *src = GST_OSX_AUDIO_SRC (object);
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DEVICE:
|
2008-08-26 21:13:08 +00:00
|
|
|
g_value_set_int (value, src->device_id);
|
2006-04-28 14:55:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2014-11-28 16:53:17 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_osx_audio_src_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstOsxAudioSrc *osxsrc = GST_OSX_AUDIO_SRC (element);
|
|
|
|
GstOsxAudioRingBuffer *ringbuffer;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (transition) {
|
2014-12-22 09:23:01 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2014-11-28 16:53:17 +00:00
|
|
|
/* The device is open now, so fix our device_id if it changed */
|
|
|
|
ringbuffer =
|
|
|
|
GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SRC (osxsrc)->ringbuffer);
|
2014-12-22 09:23:01 +00:00
|
|
|
if (ringbuffer->core_audio->device_id != osxsrc->device_id) {
|
|
|
|
osxsrc->device_id = ringbuffer->core_audio->device_id;
|
|
|
|
g_object_notify (G_OBJECT (osxsrc), "device");
|
|
|
|
}
|
2014-11-28 16:53:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-02 20:39:34 +00:00
|
|
|
static GstCaps *
|
2013-03-30 13:49:34 +00:00
|
|
|
gst_osx_audio_src_get_caps (GstBaseSrc * src, GstCaps * filter)
|
2009-01-02 20:39:34 +00:00
|
|
|
{
|
|
|
|
GstOsxAudioSrc *osxsrc;
|
2014-11-28 17:02:36 +00:00
|
|
|
GstAudioRingBuffer *buf;
|
2015-03-09 21:34:06 +00:00
|
|
|
GstOsxAudioRingBuffer *osxbuf;
|
|
|
|
GstCaps *caps, *filtered_caps;
|
2009-01-02 20:39:34 +00:00
|
|
|
|
|
|
|
osxsrc = GST_OSX_AUDIO_SRC (src);
|
2014-12-08 17:08:22 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (osxsrc);
|
2014-11-28 17:02:36 +00:00
|
|
|
buf = GST_AUDIO_BASE_SRC (src)->ringbuffer;
|
2014-12-08 17:08:22 +00:00
|
|
|
if (buf)
|
|
|
|
gst_object_ref (buf);
|
|
|
|
GST_OBJECT_UNLOCK (osxsrc);
|
2014-11-28 17:02:36 +00:00
|
|
|
|
2015-03-09 21:34:06 +00:00
|
|
|
if (!buf) {
|
|
|
|
GST_DEBUG_OBJECT (src, "no ring buffer, using template caps");
|
|
|
|
return GST_BASE_SRC_CLASS (parent_class)->get_caps (src, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
|
2014-12-01 14:11:35 +00:00
|
|
|
|
2015-03-09 21:34:06 +00:00
|
|
|
/* protect against cached_caps going away */
|
|
|
|
GST_OBJECT_LOCK (buf);
|
2009-01-02 20:39:34 +00:00
|
|
|
|
2015-03-21 18:34:25 +00:00
|
|
|
if (osxbuf->core_audio->cached_caps_valid) {
|
2015-03-09 21:34:06 +00:00
|
|
|
GST_LOG_OBJECT (src, "Returning cached caps");
|
|
|
|
caps = gst_caps_ref (osxbuf->core_audio->cached_caps);
|
|
|
|
} else if (buf->open) {
|
|
|
|
GstCaps *template_caps;
|
|
|
|
|
|
|
|
/* Get template caps */
|
|
|
|
template_caps =
|
|
|
|
gst_pad_get_pad_template_caps (GST_AUDIO_BASE_SRC_PAD (osxsrc));
|
2009-01-02 20:39:34 +00:00
|
|
|
|
2015-03-09 21:34:06 +00:00
|
|
|
/* Device is open, let's probe its caps */
|
|
|
|
caps = gst_core_audio_probe_caps (osxbuf->core_audio, template_caps);
|
|
|
|
gst_caps_replace (&osxbuf->core_audio->cached_caps, caps);
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2015-03-09 21:34:06 +00:00
|
|
|
gst_caps_unref (template_caps);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (src, "ring buffer not open, using template caps");
|
|
|
|
caps = GST_BASE_SRC_CLASS (parent_class)->get_caps (src, NULL);
|
2009-08-09 12:58:07 +00:00
|
|
|
}
|
2009-01-02 20:39:34 +00:00
|
|
|
|
2015-03-09 21:34:06 +00:00
|
|
|
GST_OBJECT_UNLOCK (buf);
|
|
|
|
|
|
|
|
gst_object_unref (buf);
|
|
|
|
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!filter)
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
/* Take care of filtered caps */
|
|
|
|
filtered_caps =
|
|
|
|
gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
return filtered_caps;
|
2009-01-02 20:39:34 +00:00
|
|
|
}
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2013-03-30 13:49:34 +00:00
|
|
|
static GstAudioRingBuffer *
|
|
|
|
gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc * src)
|
2006-04-28 14:55:20 +00:00
|
|
|
{
|
|
|
|
GstOsxAudioSrc *osxsrc;
|
2013-03-30 13:49:34 +00:00
|
|
|
GstOsxAudioRingBuffer *ringbuffer;
|
2006-04-28 14:55:20 +00:00
|
|
|
|
|
|
|
osxsrc = GST_OSX_AUDIO_SRC (src);
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2014-11-28 09:04:34 +00:00
|
|
|
GST_DEBUG_OBJECT (osxsrc, "Creating ringbuffer");
|
2013-03-30 13:49:34 +00:00
|
|
|
ringbuffer = g_object_new (GST_TYPE_OSX_AUDIO_RING_BUFFER, NULL);
|
2014-11-28 09:04:34 +00:00
|
|
|
GST_DEBUG_OBJECT (osxsrc, "osx src 0x%p element 0x%p ioproc 0x%p", osxsrc,
|
2008-08-26 21:13:08 +00:00
|
|
|
GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsrc),
|
|
|
|
(void *) gst_osx_audio_src_io_proc);
|
|
|
|
|
2013-03-05 20:17:52 +00:00
|
|
|
ringbuffer->core_audio->element =
|
|
|
|
GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsrc);
|
|
|
|
ringbuffer->core_audio->is_src = TRUE;
|
2008-08-26 21:13:08 +00:00
|
|
|
|
2014-12-22 09:23:01 +00:00
|
|
|
/* By default the coreaudio instance created by the ringbuffer
|
|
|
|
* has device_id==kAudioDeviceUnknown. The user might have
|
|
|
|
* selected a different one here
|
|
|
|
*/
|
|
|
|
if (ringbuffer->core_audio->device_id != osxsrc->device_id)
|
2014-11-28 16:53:17 +00:00
|
|
|
ringbuffer->core_audio->device_id = osxsrc->device_id;
|
|
|
|
|
2013-03-30 13:49:34 +00:00
|
|
|
return GST_AUDIO_RING_BUFFER (ringbuffer);
|
2006-04-28 14:55:20 +00:00
|
|
|
}
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2009-01-02 20:39:34 +00:00
|
|
|
static OSStatus
|
2013-03-30 13:49:34 +00:00
|
|
|
gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf,
|
2009-01-02 20:39:34 +00:00
|
|
|
AudioUnitRenderActionFlags * ioActionFlags,
|
|
|
|
const AudioTimeStamp * inTimeStamp,
|
|
|
|
UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList)
|
2006-04-28 14:55:20 +00:00
|
|
|
{
|
2009-01-02 20:39:34 +00:00
|
|
|
OSStatus status;
|
2006-04-28 14:55:20 +00:00
|
|
|
guint8 *writeptr;
|
|
|
|
gint writeseg;
|
|
|
|
gint len;
|
2009-01-02 20:39:34 +00:00
|
|
|
gint remaining;
|
2015-02-24 03:57:24 +00:00
|
|
|
UInt32 n;
|
2009-01-02 20:39:34 +00:00
|
|
|
gint offset = 0;
|
|
|
|
|
2015-02-24 03:57:24 +00:00
|
|
|
/* Previous invoke of AudioUnitRender changed mDataByteSize into
|
|
|
|
* number of bytes actually read. Reset the members. */
|
|
|
|
for (n = 0; n < buf->core_audio->recBufferList->mNumberBuffers; ++n) {
|
|
|
|
buf->core_audio->recBufferList->mBuffers[n].mDataByteSize =
|
|
|
|
buf->core_audio->recBufferSize;
|
|
|
|
}
|
|
|
|
|
2013-03-05 20:17:52 +00:00
|
|
|
status = AudioUnitRender (buf->core_audio->audiounit, ioActionFlags,
|
|
|
|
inTimeStamp, inBusNumber, inNumberFrames, buf->core_audio->recBufferList);
|
2009-01-02 20:39:34 +00:00
|
|
|
|
|
|
|
if (status) {
|
|
|
|
GST_WARNING_OBJECT (buf, "AudioUnitRender returned %d", (int) status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-02-24 03:57:24 +00:00
|
|
|
/* TODO: To support non-interleaved audio, go over all mBuffers,
|
|
|
|
* not just the first one. */
|
|
|
|
|
2013-03-05 20:17:52 +00:00
|
|
|
remaining = buf->core_audio->recBufferList->mBuffers[0].mDataByteSize;
|
close #333784 unref the result of gst_pad_get_parent() by: Christophe Fergeau.
Original commit message from CVS:
* ext/cairo/gsttextoverlay.c: (gst_text_overlay_setcaps):
* ext/esd/esdmon.c: (gst_esdmon_get):
* ext/flac/gstflactag.c: (gst_flac_tag_chain):
* ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_sink_setcaps),
(gst_gdk_pixbuf_sink_getcaps):
* ext/jpeg/gstjpegenc.c: (gst_jpegenc_getcaps),
(gst_jpegenc_setcaps):
* ext/jpeg/gstsmokedec.c: (gst_smokedec_chain):
* ext/jpeg/gstsmokeenc.c: (gst_smokeenc_getcaps),
(gst_smokeenc_setcaps):
* ext/libmng/gstmngdec.c: (gst_mngdec_sinklink),
(gst_mngdec_src_getcaps):
* ext/libmng/gstmngenc.c: (gst_mngenc_sinklink),
(gst_mngenc_chain):
* ext/libpng/gstpngenc.c: (gst_pngenc_setcaps):
* ext/mikmod/gstmikmod.c: (gst_mikmod_srclink):
* ext/speex/gstspeexdec.c: (speex_dec_convert),
(speex_dec_src_event), (speex_dec_chain):
* gst/avi/gstavimux.c: (gst_avimux_vidsinkconnect),
(gst_avimux_audsinkconnect), (gst_avimux_handle_event):
* gst/debug/negotiation.c: (gst_negotiation_getcaps),
(gst_negotiation_pad_link), (gst_negotiation_chain):
* gst/flx/gstflxdec.c: (gst_flxdec_src_query_handler),
(gst_flxdec_chain):
* gst/interleave/deinterleave.c: (deinterleave_sink_link),
(deinterleave_chain):
* gst/law/mulaw-encode.c: (mulawenc_setcaps):
* gst/median/gstmedian.c: (gst_median_link):
* gst/monoscope/gstmonoscope.c: (gst_monoscope_srcconnect),
(gst_monoscope_chain):
* gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_sinkconnect):
* gst/wavenc/gstwavenc.c: (gst_wavenc_sink_setcaps):
* sys/osxaudio/gstosxaudiosink.c: (gst_osxaudiosink_chain):
* sys/osxaudio/gstosxaudiosrc.c: (gst_osxaudiosrc_get):
close #333784 unref the result of gst_pad_get_parent()
by: Christophe Fergeau.
2006-03-13 15:49:08 +00:00
|
|
|
|
2009-01-02 20:39:34 +00:00
|
|
|
while (remaining) {
|
2013-03-30 13:49:34 +00:00
|
|
|
if (!gst_audio_ring_buffer_prepare_read (GST_AUDIO_RING_BUFFER (buf),
|
2009-01-02 20:39:34 +00:00
|
|
|
&writeseg, &writeptr, &len))
|
|
|
|
return 0;
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2009-01-02 20:39:34 +00:00
|
|
|
len -= buf->segoffset;
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2009-01-02 20:39:34 +00:00
|
|
|
if (len > remaining)
|
|
|
|
len = remaining;
|
|
|
|
|
|
|
|
memcpy (writeptr + buf->segoffset,
|
2013-03-05 20:17:52 +00:00
|
|
|
(char *) buf->core_audio->recBufferList->mBuffers[0].mData + offset,
|
|
|
|
len);
|
2009-01-02 20:39:34 +00:00
|
|
|
|
|
|
|
buf->segoffset += len;
|
|
|
|
offset += len;
|
|
|
|
remaining -= len;
|
|
|
|
|
2013-03-30 13:49:34 +00:00
|
|
|
if ((gint) buf->segoffset == GST_AUDIO_RING_BUFFER (buf)->spec.segsize) {
|
2009-01-02 20:39:34 +00:00
|
|
|
/* we wrote one segment */
|
2013-03-30 13:49:34 +00:00
|
|
|
gst_audio_ring_buffer_advance (GST_AUDIO_RING_BUFFER (buf), 1);
|
2009-01-02 20:39:34 +00:00
|
|
|
|
|
|
|
buf->segoffset = 0;
|
|
|
|
}
|
2004-05-20 19:45:13 +00:00
|
|
|
}
|
2006-04-28 14:55:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2006-04-28 14:55:20 +00:00
|
|
|
static void
|
|
|
|
gst_osx_audio_src_osxelement_init (gpointer g_iface, gpointer iface_data)
|
|
|
|
{
|
|
|
|
GstOsxAudioElementInterface *iface = (GstOsxAudioElementInterface *) g_iface;
|
2004-05-20 19:45:13 +00:00
|
|
|
|
2009-01-02 20:39:34 +00:00
|
|
|
iface->io_proc = (AURenderCallback) gst_osx_audio_src_io_proc;
|
2004-05-20 19:45:13 +00:00
|
|
|
}
|