osxaudio: port to v.1.0

This commit is contained in:
ted-n 2013-03-30 22:49:34 +09:00 committed by Sebastian Dröge
parent 24bb263d54
commit b217b6fdfb
10 changed files with 280 additions and 286 deletions

View File

@ -1,6 +1,6 @@
plugin_LTLIBRARIES = libgstosxaudio.la plugin_LTLIBRARIES = libgstosxaudio.la
libgstosxaudio_la_SOURCES = gstosxringbuffer.c \ libgstosxaudio_la_SOURCES = gstosxaudioringbuffer.c \
gstosxaudioelement.c \ gstosxaudioelement.c \
gstosxaudiosink.c \ gstosxaudiosink.c \
gstosxaudiosrc.c \ gstosxaudiosrc.c \
@ -11,7 +11,6 @@ libgstosxaudio_la_SOURCES = gstosxringbuffer.c \
libgstosxaudio_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) \ libgstosxaudio_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) \
-Wno-deprecated-declarations -Wno-deprecated-declarations
libgstosxaudio_la_LIBADD = \ libgstosxaudio_la_LIBADD = \
-lgstinterfaces-@GST_API_VERSION@ \
-lgstaudio-@GST_API_VERSION@ \ -lgstaudio-@GST_API_VERSION@ \
$(GST_PLUGINS_BASE_LIBS) \ $(GST_PLUGINS_BASE_LIBS) \
$(GST_BASE_LIBS) \ $(GST_BASE_LIBS) \
@ -27,7 +26,7 @@ libgstosxaudio_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS) --tag=CC
noinst_HEADERS = gstosxaudiosink.h \ noinst_HEADERS = gstosxaudiosink.h \
gstosxaudioelement.h \ gstosxaudioelement.h \
gstosxringbuffer.h \ gstosxaudioringbuffer.h \
gstosxaudiosrc.h \ gstosxaudiosrc.h \
gstosxcoreaudiocommon.h \ gstosxcoreaudiocommon.h \
gstosxcoreaudio.h \ gstosxcoreaudio.h \

View File

@ -47,6 +47,7 @@
*/ */
#include "gstosxaudioelement.h" #include "gstosxaudioelement.h"
#include <gst/gst.h>
static void static void
gst_osx_audio_element_interface_init (GstOsxAudioElementInterface * iface); gst_osx_audio_element_interface_init (GstOsxAudioElementInterface * iface);

View File

@ -48,8 +48,8 @@
#endif #endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/multichannel.h> #include <gst/audio/audio-channels.h>
#include "gstosxringbuffer.h" #include "gstosxaudioringbuffer.h"
#include "gstosxaudiosink.h" #include "gstosxaudiosink.h"
#include "gstosxaudiosrc.h" #include "gstosxaudiosrc.h"
@ -60,84 +60,79 @@ GST_DEBUG_CATEGORY_STATIC (osx_audio_debug);
#include "gstosxcoreaudio.h" #include "gstosxcoreaudio.h"
static void gst_osx_ring_buffer_dispose (GObject * object); static void gst_osx_audio_ring_buffer_dispose (GObject * object);
static void gst_osx_ring_buffer_finalize (GObject * object); static void gst_osx_audio_ring_buffer_finalize (GObject * object);
static gboolean gst_osx_ring_buffer_open_device (GstRingBuffer * buf); static gboolean gst_osx_audio_ring_buffer_open_device (GstAudioRingBuffer *
static gboolean gst_osx_ring_buffer_close_device (GstRingBuffer * buf); buf);
static gboolean gst_osx_audio_ring_buffer_close_device (GstAudioRingBuffer *
buf);
static gboolean gst_osx_ring_buffer_acquire (GstRingBuffer * buf, static gboolean gst_osx_audio_ring_buffer_acquire (GstAudioRingBuffer * buf,
GstRingBufferSpec * spec); GstAudioRingBufferSpec * spec);
static gboolean gst_osx_ring_buffer_release (GstRingBuffer * buf); static gboolean gst_osx_audio_ring_buffer_release (GstAudioRingBuffer * buf);
static gboolean gst_osx_ring_buffer_start (GstRingBuffer * buf); static gboolean gst_osx_audio_ring_buffer_start (GstAudioRingBuffer * buf);
static gboolean gst_osx_ring_buffer_pause (GstRingBuffer * buf); static gboolean gst_osx_audio_ring_buffer_pause (GstAudioRingBuffer * buf);
static gboolean gst_osx_ring_buffer_stop (GstRingBuffer * buf); static gboolean gst_osx_audio_ring_buffer_stop (GstAudioRingBuffer * buf);
static guint gst_osx_ring_buffer_delay (GstRingBuffer * buf); static guint gst_osx_audio_ring_buffer_delay (GstAudioRingBuffer * buf);
static GstRingBufferClass *ring_parent_class = NULL; static GstAudioRingBufferClass *ring_parent_class = NULL;
#define gst_osx_audio_ring_buffer_do_init \
GST_DEBUG_CATEGORY_INIT (osx_audio_debug, "osxaudio", 0, "OSX Audio Elements");
G_DEFINE_TYPE_WITH_CODE (GstOsxAudioRingBuffer, gst_osx_audio_ring_buffer,
GST_TYPE_AUDIO_RING_BUFFER, gst_osx_audio_ring_buffer_do_init);
static void static void
gst_osx_ring_buffer_do_init (GType type) gst_osx_audio_ring_buffer_class_init (GstOsxAudioRingBufferClass * klass)
{
GST_DEBUG_CATEGORY_INIT (osx_audio_debug, "osxaudio", 0,
"OSX Audio Elements");
}
GST_BOILERPLATE_FULL (GstOsxRingBuffer, gst_osx_ring_buffer,
GstRingBuffer, GST_TYPE_RING_BUFFER, gst_osx_ring_buffer_do_init);
static void
gst_osx_ring_buffer_base_init (gpointer g_class)
{
/* Nothing to do right now */
}
static void
gst_osx_ring_buffer_class_init (GstOsxRingBufferClass * klass)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstObjectClass *gstobject_class; GstObjectClass *gstobject_class;
GstRingBufferClass *gstringbuffer_class; GstAudioRingBufferClass *gstringbuffer_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
gstobject_class = (GstObjectClass *) klass; gstobject_class = (GstObjectClass *) klass;
gstringbuffer_class = (GstRingBufferClass *) klass; gstringbuffer_class = (GstAudioRingBufferClass *) klass;
ring_parent_class = g_type_class_peek_parent (klass); ring_parent_class = g_type_class_peek_parent (klass);
gobject_class->dispose = gst_osx_ring_buffer_dispose; gobject_class->dispose = gst_osx_audio_ring_buffer_dispose;
gobject_class->finalize = gst_osx_ring_buffer_finalize; gobject_class->finalize = gst_osx_audio_ring_buffer_finalize;
gstringbuffer_class->open_device = gstringbuffer_class->open_device =
GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_open_device); GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_open_device);
gstringbuffer_class->close_device = gstringbuffer_class->close_device =
GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_close_device); GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_close_device);
gstringbuffer_class->acquire = gstringbuffer_class->acquire =
GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_acquire); GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_acquire);
gstringbuffer_class->release = gstringbuffer_class->release =
GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_release); GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_release);
gstringbuffer_class->start = GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_start); gstringbuffer_class->start =
gstringbuffer_class->pause = GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_pause); GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_start);
gstringbuffer_class->resume = GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_start); gstringbuffer_class->pause =
gstringbuffer_class->stop = GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_stop); GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_pause);
gstringbuffer_class->resume =
GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_start);
gstringbuffer_class->stop =
GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_stop);
gstringbuffer_class->delay =
GST_DEBUG_FUNCPTR (gst_osx_audio_ring_buffer_delay);
gstringbuffer_class->delay = GST_DEBUG_FUNCPTR (gst_osx_ring_buffer_delay); GST_DEBUG ("osx audio ring buffer class init");
GST_DEBUG ("osx ring buffer class init");
} }
static void static void
gst_osx_ring_buffer_init (GstOsxRingBuffer * ringbuffer, gst_osx_audio_ring_buffer_init (GstOsxAudioRingBuffer * ringbuffer)
GstOsxRingBufferClass * g_class)
{ {
ringbuffer->core_audio = gst_core_audio_new (GST_OBJECT (ringbuffer)); ringbuffer->core_audio = gst_core_audio_new (GST_OBJECT (ringbuffer));
} }
static void static void
gst_osx_ring_buffer_dispose (GObject * object) gst_osx_audio_ring_buffer_dispose (GObject * object)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
osxbuf = GST_OSX_RING_BUFFER (object); osxbuf = GST_OSX_AUDIO_RING_BUFFER (object);
if (osxbuf->core_audio) { if (osxbuf->core_audio) {
g_object_unref (osxbuf->core_audio); g_object_unref (osxbuf->core_audio);
@ -147,42 +142,43 @@ gst_osx_ring_buffer_dispose (GObject * object)
} }
static void static void
gst_osx_ring_buffer_finalize (GObject * object) gst_osx_audio_ring_buffer_finalize (GObject * object)
{ {
G_OBJECT_CLASS (ring_parent_class)->finalize (object); G_OBJECT_CLASS (ring_parent_class)->finalize (object);
} }
static gboolean static gboolean
gst_osx_ring_buffer_open_device (GstRingBuffer * buf) gst_osx_audio_ring_buffer_open_device (GstAudioRingBuffer * buf)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
osxbuf = GST_OSX_RING_BUFFER (buf); osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
return gst_core_audio_open (osxbuf->core_audio); return gst_core_audio_open (osxbuf->core_audio);
} }
static gboolean static gboolean
gst_osx_ring_buffer_close_device (GstRingBuffer * buf) gst_osx_audio_ring_buffer_close_device (GstAudioRingBuffer * buf)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
osxbuf = GST_OSX_RING_BUFFER (buf); osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
return gst_core_audio_close (osxbuf->core_audio); return gst_core_audio_close (osxbuf->core_audio);
} }
static gboolean static gboolean
gst_osx_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec) gst_osx_audio_ring_buffer_acquire (GstAudioRingBuffer * buf,
GstAudioRingBufferSpec * spec)
{ {
gboolean ret = FALSE, is_passthrough = FALSE; gboolean ret = FALSE, is_passthrough = FALSE;
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
AudioStreamBasicDescription format; AudioStreamBasicDescription format;
osxbuf = GST_OSX_RING_BUFFER (buf); osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
if (RINGBUFFER_IS_SPDIF (spec->type)) { if (RINGBUFFER_IS_SPDIF (spec->type)) {
format.mFormatID = kAudioFormat60958AC3; format.mFormatID = kAudioFormat60958AC3;
format.mSampleRate = (double) spec->rate; format.mSampleRate = (double) spec->info.rate;
format.mChannelsPerFrame = 2; format.mChannelsPerFrame = 2;
format.mFormatFlags = kAudioFormatFlagIsSignedInteger | format.mFormatFlags = kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonMixable; kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonMixable;
@ -198,32 +194,32 @@ gst_osx_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
int width, depth; int width, depth;
/* Fill out the audio description we're going to be using */ /* Fill out the audio description we're going to be using */
format.mFormatID = kAudioFormatLinearPCM; format.mFormatID = kAudioFormatLinearPCM;
format.mSampleRate = (double) spec->rate; format.mSampleRate = (double) spec->info.rate;
format.mChannelsPerFrame = spec->channels; format.mChannelsPerFrame = spec->info.channels;
if (spec->type == GST_BUFTYPE_FLOAT) { if (spec->type == GST_AUDIO_FORMAT_F32) {
format.mFormatFlags = kAudioFormatFlagsNativeFloatPacked; format.mFormatFlags = kAudioFormatFlagsNativeFloatPacked;
width = depth = spec->width; width = depth = spec->info.finfo->width;
} else { } else {
format.mFormatFlags = kAudioFormatFlagIsSignedInteger; format.mFormatFlags = kAudioFormatFlagIsSignedInteger;
width = spec->width; width = spec->info.finfo->width;
depth = spec->depth; depth = spec->info.finfo->depth;
if (width == depth) { if (width == depth) {
format.mFormatFlags |= kAudioFormatFlagIsPacked; format.mFormatFlags |= kAudioFormatFlagIsPacked;
} else { } else {
format.mFormatFlags |= kAudioFormatFlagIsAlignedHigh; format.mFormatFlags |= kAudioFormatFlagIsAlignedHigh;
} }
if (spec->bigend) { if (spec->info.finfo->endianness == G_BIG_ENDIAN) {
format.mFormatFlags |= kAudioFormatFlagIsBigEndian; format.mFormatFlags |= kAudioFormatFlagIsBigEndian;
} }
} }
format.mBytesPerFrame = spec->channels * (width >> 3); format.mBytesPerFrame = spec->info.channels * (width >> 3);
format.mBitsPerChannel = depth; format.mBitsPerChannel = depth;
format.mBytesPerPacket = spec->channels * (width >> 3); format.mBytesPerPacket = spec->info.channels * (width >> 3);
format.mFramesPerPacket = 1; format.mFramesPerPacket = 1;
format.mReserved = 0; format.mReserved = 0;
spec->segsize = spec->segsize =
(spec->latency_time * spec->rate / G_USEC_PER_SEC) * (spec->latency_time * spec->info.rate / G_USEC_PER_SEC) *
spec->bytes_per_sample; spec->info.bpf;
spec->segtotal = spec->buffer_time / spec->latency_time; spec->segtotal = spec->buffer_time / spec->latency_time;
is_passthrough = FALSE; is_passthrough = FALSE;
} }
@ -231,15 +227,16 @@ gst_osx_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
GST_DEBUG_OBJECT (osxbuf, "Format: " CORE_AUDIO_FORMAT, GST_DEBUG_OBJECT (osxbuf, "Format: " CORE_AUDIO_FORMAT,
CORE_AUDIO_FORMAT_ARGS (format)); CORE_AUDIO_FORMAT_ARGS (format));
buf->data = gst_buffer_new_and_alloc (spec->segtotal * spec->segsize); buf->size = spec->segtotal * spec->segsize;
memset (GST_BUFFER_DATA (buf->data), 0, GST_BUFFER_SIZE (buf->data)); buf->memory = g_malloc0 (buf->size);
ret = gst_core_audio_initialize (osxbuf->core_audio, format, spec->caps, ret = gst_core_audio_initialize (osxbuf->core_audio, format, spec->caps,
is_passthrough); is_passthrough);
if (!ret) { if (!ret) {
gst_buffer_unref (buf->data); g_free (buf->memory);
buf->data = NULL; buf->memory = NULL;
buf->size = 0;
} }
osxbuf->segoffset = 0; osxbuf->segoffset = 0;
@ -248,45 +245,46 @@ gst_osx_ring_buffer_acquire (GstRingBuffer * buf, GstRingBufferSpec * spec)
} }
static gboolean static gboolean
gst_osx_ring_buffer_release (GstRingBuffer * buf) gst_osx_audio_ring_buffer_release (GstAudioRingBuffer * buf)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
osxbuf = GST_OSX_RING_BUFFER (buf); osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
gst_core_audio_unitialize (osxbuf->core_audio); gst_core_audio_unitialize (osxbuf->core_audio);
gst_buffer_unref (buf->data); g_free (buf->memory);
buf->data = NULL; buf->memory = NULL;
buf->size = 0;
return TRUE; return TRUE;
} }
static gboolean static gboolean
gst_osx_ring_buffer_start (GstRingBuffer * buf) gst_osx_audio_ring_buffer_start (GstAudioRingBuffer * buf)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
osxbuf = GST_OSX_RING_BUFFER (buf); osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
return gst_core_audio_start_processing (osxbuf->core_audio); return gst_core_audio_start_processing (osxbuf->core_audio);
} }
static gboolean static gboolean
gst_osx_ring_buffer_pause (GstRingBuffer * buf) gst_osx_audio_ring_buffer_pause (GstAudioRingBuffer * buf)
{ {
GstOsxRingBuffer *osxbuf = GST_OSX_RING_BUFFER (buf); GstOsxAudioRingBuffer *osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
return gst_core_audio_pause_processing (osxbuf->core_audio); return gst_core_audio_pause_processing (osxbuf->core_audio);
} }
static gboolean static gboolean
gst_osx_ring_buffer_stop (GstRingBuffer * buf) gst_osx_audio_ring_buffer_stop (GstAudioRingBuffer * buf)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
osxbuf = GST_OSX_RING_BUFFER (buf); osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
gst_core_audio_stop_processing (osxbuf->core_audio); gst_core_audio_stop_processing (osxbuf->core_audio);
@ -294,16 +292,16 @@ gst_osx_ring_buffer_stop (GstRingBuffer * buf)
} }
static guint static guint
gst_osx_ring_buffer_delay (GstRingBuffer * buf) gst_osx_audio_ring_buffer_delay (GstAudioRingBuffer * buf)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
double latency; double latency;
guint samples; guint samples;
osxbuf = GST_OSX_RING_BUFFER (buf); osxbuf = GST_OSX_AUDIO_RING_BUFFER (buf);
if (!gst_core_audio_get_samples_and_latency (osxbuf->core_audio, if (!gst_core_audio_get_samples_and_latency (osxbuf->core_audio,
GST_RING_BUFFER (buf)->spec.rate, &samples, &latency)) { GST_AUDIO_RING_BUFFER (buf)->spec.info.rate, &samples, &latency)) {
return 0; return 0;
} }
GST_DEBUG_OBJECT (buf, "Got latency: %f seconds -> %d samples", GST_DEBUG_OBJECT (buf, "Got latency: %f seconds -> %d samples",

View File

@ -50,33 +50,33 @@
#endif #endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/gstringbuffer.h> #include <gst/audio/gstaudioringbuffer.h>
#include <gstosxcoreaudio.h> #include <gstosxcoreaudio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_OSX_RING_BUFFER \ #define GST_TYPE_OSX_AUDIO_RING_BUFFER \
(gst_osx_ring_buffer_get_type()) (gst_osx_audio_ring_buffer_get_type())
#define GST_OSX_RING_BUFFER(obj) \ #define GST_OSX_AUDIO_RING_BUFFER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OSX_RING_BUFFER,GstOsxRingBuffer)) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OSX_AUDIO_RING_BUFFER,GstOsxAudioRingBuffer))
#define GST_OSX_RING_BUFFER_CLASS(klass) \ #define GST_OSX_AUDIO_RING_BUFFER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OSX_RING_BUFFER,GstOsxRingBufferClass)) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OSX_AUDIO_RING_BUFFER,GstOsxAudioRingBufferClass))
#define GST_OSX_RING_BUFFER_GET_CLASS(obj) \ #define GST_OSX_AUDIO_RING_BUFFER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_OSX_RING_BUFFER,GstOsxRingBufferClass)) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_OSX_AUDIO_RING_BUFFER,GstOsxAudioRingBufferClass))
#define GST_IS_OSX_RING_BUFFER(obj) \ #define GST_IS_OSX_AUDIO_RING_BUFFER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OSX_RING_BUFFER)) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OSX_AUDIO_RING_BUFFER))
#define GST_IS_OSX_RING_BUFFER_CLASS(klass) \ #define GST_IS_OSX_AUDIO_RING_BUFFER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OSX_RING_BUFFER)) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OSX_AUDIO_RING_BUFFER))
#define RINGBUFFER_IS_SPDIF(t) ((t) == GST_BUFTYPE_AC3 || (t) == GST_BUFTYPE_DTS) #define RINGBUFFER_IS_SPDIF(t) ((t) == GST_AUDIO_RING_BUFFER_FORMAT_TYPE_AC3 || (t) == GST_AUDIO_RING_BUFFER_FORMAT_TYPE_DTS)
typedef struct _GstOsxRingBuffer GstOsxRingBuffer; typedef struct _GstOsxAudioRingBuffer GstOsxAudioRingBuffer;
typedef struct _GstOsxRingBufferClass GstOsxRingBufferClass; typedef struct _GstOsxAudioRingBufferClass GstOsxAudioRingBufferClass;
struct _GstOsxRingBuffer struct _GstOsxAudioRingBuffer
{ {
GstRingBuffer object; GstAudioRingBuffer object;
GstCoreAudio *core_audio; GstCoreAudio *core_audio;
@ -84,14 +84,14 @@ struct _GstOsxRingBuffer
guint segoffset; guint segoffset;
}; };
struct _GstOsxRingBufferClass struct _GstOsxAudioRingBufferClass
{ {
GstRingBufferClass parent_class; GstAudioRingBufferClass parent_class;
}; };
GType gst_osx_ring_buffer_get_type (void); GType gst_osx_audio_ring_buffer_get_type (void);
G_END_DECLS G_END_DECLS
#endif /* __GST_OSX_RING_BUFFER_H__ */ #endif /* __GST_OSX_AUDIO_RING_BUFFER_H__ */

View File

@ -67,7 +67,7 @@
#endif #endif
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/multichannel.h> #include <gst/audio/audio-channels.h>
#include <gst/audio/gstaudioiec61937.h> #include <gst/audio/gstaudioiec61937.h>
#include "gstosxaudiosink.h" #include "gstosxaudiosink.h"
@ -94,43 +94,20 @@ enum
#define DEFAULT_VOLUME 1.0 #define DEFAULT_VOLUME 1.0
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
# define FORMATS "{ S32LE, S24LE, S16LE, U8 }"
#else
# define FORMATS "{ S32BE, S24BE, S16BE, U8 }"
#endif
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK, GST_PAD_SINK,
GST_PAD_ALWAYS, GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-raw-float, " GST_STATIC_CAPS ("audio/x-raw, "
"endianness = (int) {" G_STRINGIFY (G_BYTE_ORDER) " }, " "format = (string) " FORMATS ", "
"signed = (boolean) { TRUE }, " "layout = (string) interleaved, "
"width = (int) 32, "
"depth = (int) 32, "
"rate = (int) [1, MAX], " "rate = (int) [1, MAX], "
"channels = (int) [1, 9];" "channels = (int) [1, 9];"
"audio/x-raw-int, "
"endianness = (int) {" G_STRINGIFY (G_BYTE_ORDER) " }, "
"signed = (boolean) { TRUE }, "
"width = (int) 32, "
"depth = (int) 32, "
"rate = (int) [1, MAX], "
"channels = (int) [1, 9];"
"audio/x-raw-int, "
"endianness = (int) {" G_STRINGIFY (G_BYTE_ORDER) " }, "
"signed = (boolean) { TRUE }, "
"width = (int) 24, "
"depth = (int) 24, "
"rate = (int) [1, MAX], "
"channels = (int) [1, 9];"
"audio/x-raw-int, "
"endianness = (int) {" G_STRINGIFY (G_BYTE_ORDER) " }, "
"signed = (boolean) { TRUE }, "
"width = (int) 16, "
"depth = (int) 16, "
"rate = (int) [1, MAX], "
"channels = (int) [1, 9];"
"audio/x-raw-int, "
"endianness = (int) {" G_STRINGIFY (G_BYTE_ORDER) " }, "
"signed = (boolean) { TRUE }, "
"width = (int) 8, "
"depth = (int) 8, "
"rate = (int) [1, MAX], " "channels = (int) [1, MAX];"
"audio/x-ac3, framed = (boolean) true;" "audio/x-ac3, framed = (boolean) true;"
"audio/x-dts, framed = (boolean) true") "audio/x-dts, framed = (boolean) true")
); );
@ -140,20 +117,24 @@ static void gst_osx_audio_sink_set_property (GObject * object, guint prop_id,
static void gst_osx_audio_sink_get_property (GObject * object, guint prop_id, static void gst_osx_audio_sink_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static gboolean gst_osx_audio_sink_stop (GstBaseSink * base); static gboolean gst_osx_audio_sink_query (GstBaseSink * base, GstQuery * query);
static GstCaps *gst_osx_audio_sink_getcaps (GstBaseSink * base);
static gboolean gst_osx_audio_sink_acceptcaps (GstPad * pad, GstCaps * caps);
static GstBuffer *gst_osx_audio_sink_sink_payload (GstBaseAudioSink * sink, static gboolean gst_osx_audio_sink_stop (GstBaseSink * base);
static GstCaps *gst_osx_audio_sink_getcaps (GstBaseSink * base,
GstCaps * filter);
static gboolean gst_osx_audio_sink_acceptcaps (GstOsxAudioSink * sink,
GstCaps * caps);
static GstBuffer *gst_osx_audio_sink_sink_payload (GstAudioBaseSink * sink,
GstBuffer * buf); GstBuffer * buf);
static GstRingBuffer *gst_osx_audio_sink_create_ringbuffer (GstBaseAudioSink * static GstAudioRingBuffer
sink); * gst_osx_audio_sink_create_ringbuffer (GstAudioBaseSink * sink);
static void gst_osx_audio_sink_osxelement_init (gpointer g_iface, static void gst_osx_audio_sink_osxelement_init (gpointer g_iface,
gpointer iface_data); gpointer iface_data);
static gboolean gst_osx_audio_sink_select_device (GstOsxAudioSink * osxsink); static gboolean gst_osx_audio_sink_select_device (GstOsxAudioSink * osxsink);
static void gst_osx_audio_sink_set_volume (GstOsxAudioSink * sink); static void gst_osx_audio_sink_set_volume (GstOsxAudioSink * sink);
static OSStatus gst_osx_audio_sink_io_proc (GstOsxRingBuffer * buf, static OSStatus gst_osx_audio_sink_io_proc (GstOsxAudioRingBuffer * buf,
AudioUnitRenderActionFlags * ioActionFlags, AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp, const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList); UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList);
@ -175,22 +156,10 @@ gst_osx_audio_sink_do_init (GType type)
&osxelement_info); &osxelement_info);
} }
GST_BOILERPLATE_FULL (GstOsxAudioSink, gst_osx_audio_sink, GstBaseAudioSink, #define gst_osx_audio_sink_parent_class parent_class
GST_TYPE_BASE_AUDIO_SINK, gst_osx_audio_sink_do_init); G_DEFINE_TYPE_WITH_CODE (GstOsxAudioSink, gst_osx_audio_sink,
GST_TYPE_AUDIO_BASE_SINK,
static void gst_osx_audio_sink_do_init (GST_TYPE_AUDIO_BASE_SINK));
gst_osx_audio_sink_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
gst_element_class_set_static_metadata (element_class, "Audio Sink (OSX)",
"Sink/Audio",
"Output to a sound card in OS X",
"Zaheer Abbas Merali <zaheerabbas at merali dot org>");
}
static void static void
gst_osx_audio_sink_class_init (GstOsxAudioSinkClass * klass) gst_osx_audio_sink_class_init (GstOsxAudioSinkClass * klass)
@ -198,12 +167,12 @@ gst_osx_audio_sink_class_init (GstOsxAudioSinkClass * klass)
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
GstBaseSinkClass *gstbasesink_class; GstBaseSinkClass *gstbasesink_class;
GstBaseAudioSinkClass *gstbaseaudiosink_class; GstAudioBaseSinkClass *gstaudiobasesink_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
gstbasesink_class = (GstBaseSinkClass *) klass; gstbasesink_class = (GstBaseSinkClass *) klass;
gstbaseaudiosink_class = (GstBaseAudioSinkClass *) klass; gstaudiobasesink_class = (GstAudioBaseSinkClass *) klass;
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
@ -216,6 +185,8 @@ gst_osx_audio_sink_class_init (GstOsxAudioSinkClass * klass)
0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
#endif #endif
gstbasesink_class->query = GST_DEBUG_FUNCPTR (gst_osx_audio_sink_query);
g_object_class_install_property (gobject_class, ARG_VOLUME, g_object_class_install_property (gobject_class, ARG_VOLUME,
g_param_spec_double ("volume", "Volume", "Volume of this stream", g_param_spec_double ("volume", "Volume", "Volume of this stream",
0, 1.0, 1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); 0, 1.0, 1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
@ -223,14 +194,22 @@ gst_osx_audio_sink_class_init (GstOsxAudioSinkClass * klass)
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_osx_audio_sink_getcaps); gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_osx_audio_sink_getcaps);
gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_osx_audio_sink_stop); gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_osx_audio_sink_stop);
gstbaseaudiosink_class->create_ringbuffer = gstaudiobasesink_class->create_ringbuffer =
GST_DEBUG_FUNCPTR (gst_osx_audio_sink_create_ringbuffer); GST_DEBUG_FUNCPTR (gst_osx_audio_sink_create_ringbuffer);
gstbaseaudiosink_class->payload = gstaudiobasesink_class->payload =
GST_DEBUG_FUNCPTR (gst_osx_audio_sink_sink_payload); GST_DEBUG_FUNCPTR (gst_osx_audio_sink_sink_payload);
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sink_factory));
gst_element_class_set_static_metadata (gstelement_class, "Audio Sink (OSX)",
"Sink/Audio",
"Output to a sound card in OS X",
"Zaheer Abbas Merali <zaheerabbas at merali dot org>");
} }
static void static void
gst_osx_audio_sink_init (GstOsxAudioSink * sink, GstOsxAudioSinkClass * gclass) gst_osx_audio_sink_init (GstOsxAudioSink * sink)
{ {
GST_DEBUG ("Initialising object"); GST_DEBUG ("Initialising object");
@ -238,9 +217,6 @@ gst_osx_audio_sink_init (GstOsxAudioSink * sink, GstOsxAudioSinkClass * gclass)
sink->cached_caps = NULL; sink->cached_caps = NULL;
sink->volume = DEFAULT_VOLUME; sink->volume = DEFAULT_VOLUME;
gst_pad_set_acceptcaps_function (GST_BASE_SINK (sink)->sinkpad,
GST_DEBUG_FUNCPTR (gst_osx_audio_sink_acceptcaps));
} }
static void static void
@ -285,6 +261,30 @@ gst_osx_audio_sink_get_property (GObject * object, guint prop_id,
} }
} }
static gboolean
gst_osx_audio_sink_query (GstBaseSink * base, GstQuery * query)
{
GstOsxAudioSink *sink = GST_OSX_AUDIO_SINK (base);
gboolean ret = FALSE;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_ACCEPT_CAPS:
{
GstCaps *caps = NULL;
gst_query_parse_accept_caps (query, &caps);
ret = gst_osx_audio_sink_acceptcaps (sink, caps);
gst_query_set_accept_caps_result (query, ret);
ret = TRUE;
break;
}
default:
ret = GST_BASE_SINK_CLASS (parent_class)->query (base, query);
break;
}
return ret;
}
static gboolean static gboolean
gst_osx_audio_sink_stop (GstBaseSink * base) gst_osx_audio_sink_stop (GstBaseSink * base)
{ {
@ -299,7 +299,7 @@ gst_osx_audio_sink_stop (GstBaseSink * base)
} }
static GstCaps * static GstCaps *
gst_osx_audio_sink_getcaps (GstBaseSink * base) gst_osx_audio_sink_getcaps (GstBaseSink * base, GstCaps * filter)
{ {
GstOsxAudioSink *sink = GST_OSX_AUDIO_SINK (base); GstOsxAudioSink *sink = GST_OSX_AUDIO_SINK (base);
gchar *caps_string = NULL; gchar *caps_string = NULL;
@ -316,23 +316,22 @@ gst_osx_audio_sink_getcaps (GstBaseSink * base)
} }
static gboolean static gboolean
gst_osx_audio_sink_acceptcaps (GstPad * pad, GstCaps * caps) gst_osx_audio_sink_acceptcaps (GstOsxAudioSink * sink, GstCaps * caps)
{ {
GstOsxAudioSink *sink = GST_OSX_AUDIO_SINK (gst_pad_get_parent_element (pad)); GstOsxAudioRingBuffer *osxbuf = NULL;
GstOsxRingBuffer *osxbuf;
GstCaps *pad_caps; GstCaps *pad_caps;
GstStructure *st; GstStructure *st;
gboolean ret = FALSE; gboolean ret = FALSE;
GstRingBufferSpec spec = { 0 }; GstAudioRingBufferSpec spec = { 0 };
gchar *caps_string = NULL; gchar *caps_string = NULL;
osxbuf = GST_OSX_RING_BUFFER (GST_BASE_AUDIO_SINK (sink)->ringbuffer); osxbuf = GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SINK (sink)->ringbuffer);
caps_string = gst_caps_to_string (caps); caps_string = gst_caps_to_string (caps);
GST_DEBUG_OBJECT (sink, "acceptcaps called with %s", caps_string); GST_DEBUG_OBJECT (sink, "acceptcaps called with %s", caps_string);
g_free (caps_string); g_free (caps_string);
pad_caps = gst_pad_get_caps (pad); pad_caps = gst_pad_query_caps (GST_BASE_SINK_PAD (sink), caps);
if (pad_caps) { if (pad_caps) {
gboolean cret = gst_caps_can_intersect (pad_caps, caps); gboolean cret = gst_caps_can_intersect (pad_caps, caps);
gst_caps_unref (pad_caps); gst_caps_unref (pad_caps);
@ -349,12 +348,12 @@ gst_osx_audio_sink_acceptcaps (GstPad * pad, GstCaps * caps)
/* parse helper expects this set, so avoid nasty warning /* parse helper expects this set, so avoid nasty warning
* will be set properly later on anyway */ * will be set properly later on anyway */
spec.latency_time = GST_SECOND; spec.latency_time = GST_SECOND;
if (!gst_ring_buffer_parse_caps (&spec, caps)) if (!gst_audio_ring_buffer_parse_caps (&spec, caps))
goto done; goto done;
/* Make sure input is framed and can be payloaded */ /* Make sure input is framed and can be payloaded */
switch (spec.type) { switch (spec.type) {
case GST_BUFTYPE_AC3: case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_AC3:
{ {
gboolean framed = FALSE; gboolean framed = FALSE;
@ -365,7 +364,7 @@ gst_osx_audio_sink_acceptcaps (GstPad * pad, GstCaps * caps)
goto done; goto done;
break; break;
} }
case GST_BUFTYPE_DTS: case GST_AUDIO_RING_BUFFER_FORMAT_TYPE_DTS:
{ {
gboolean parsed = FALSE; gboolean parsed = FALSE;
@ -382,12 +381,11 @@ gst_osx_audio_sink_acceptcaps (GstPad * pad, GstCaps * caps)
ret = TRUE; ret = TRUE;
done: done:
gst_object_unref (sink);
return ret; return ret;
} }
static GstBuffer * static GstBuffer *
gst_osx_audio_sink_sink_payload (GstBaseAudioSink * sink, GstBuffer * buf) gst_osx_audio_sink_sink_payload (GstAudioBaseSink * sink, GstBuffer * buf)
{ {
GstOsxAudioSink *osxsink; GstOsxAudioSink *osxsink;
@ -396,36 +394,42 @@ gst_osx_audio_sink_sink_payload (GstBaseAudioSink * sink, GstBuffer * buf)
if (RINGBUFFER_IS_SPDIF (sink->ringbuffer->spec.type)) { if (RINGBUFFER_IS_SPDIF (sink->ringbuffer->spec.type)) {
gint framesize = gst_audio_iec61937_frame_size (&sink->ringbuffer->spec); gint framesize = gst_audio_iec61937_frame_size (&sink->ringbuffer->spec);
GstBuffer *out; GstBuffer *out;
GstMapInfo inmap, outmap;
gboolean res;
if (framesize <= 0) if (framesize <= 0)
return NULL; return NULL;
out = gst_buffer_new_and_alloc (framesize); out = gst_buffer_new_and_alloc (framesize);
gst_buffer_map (buf, &inmap, GST_MAP_READ);
gst_buffer_map (out, &outmap, GST_MAP_WRITE);
/* FIXME: the endianness needs to be queried and then set */ /* FIXME: the endianness needs to be queried and then set */
if (!gst_audio_iec61937_payload (GST_BUFFER_DATA (buf), res = gst_audio_iec61937_payload (inmap.data, inmap.size,
GST_BUFFER_SIZE (buf), GST_BUFFER_DATA (out), outmap.data, outmap.size, &sink->ringbuffer->spec, G_BIG_ENDIAN);
GST_BUFFER_SIZE (out), &sink->ringbuffer->spec, G_BYTE_ORDER)) {
gst_buffer_unmap (buf, &inmap);
gst_buffer_unmap (out, &outmap);
if (!res) {
gst_buffer_unref (out); gst_buffer_unref (out);
return NULL; return NULL;
} }
gst_buffer_copy_metadata (out, buf, GST_BUFFER_COPY_ALL); gst_buffer_copy_into (out, buf, GST_BUFFER_COPY_METADATA, 0, -1);
/* Fix endianness */
swab ((gchar *) GST_BUFFER_DATA (buf),
(gchar *) GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
return out; return out;
} else { } else {
return gst_buffer_ref (buf); return gst_buffer_ref (buf);
} }
} }
static GstRingBuffer * static GstAudioRingBuffer *
gst_osx_audio_sink_create_ringbuffer (GstBaseAudioSink * sink) gst_osx_audio_sink_create_ringbuffer (GstAudioBaseSink * sink)
{ {
GstOsxAudioSink *osxsink; GstOsxAudioSink *osxsink;
GstOsxRingBuffer *ringbuffer; GstOsxAudioRingBuffer *ringbuffer;
osxsink = GST_OSX_AUDIO_SINK (sink); osxsink = GST_OSX_AUDIO_SINK (sink);
@ -435,7 +439,7 @@ gst_osx_audio_sink_create_ringbuffer (GstBaseAudioSink * sink)
} }
GST_DEBUG_OBJECT (sink, "Creating ringbuffer"); GST_DEBUG_OBJECT (sink, "Creating ringbuffer");
ringbuffer = g_object_new (GST_TYPE_OSX_RING_BUFFER, NULL); ringbuffer = g_object_new (GST_TYPE_OSX_AUDIO_RING_BUFFER, NULL);
GST_DEBUG_OBJECT (sink, "osx sink %p element %p ioproc %p", osxsink, GST_DEBUG_OBJECT (sink, "osx sink %p element %p ioproc %p", osxsink,
GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsink), GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsink),
(void *) gst_osx_audio_sink_io_proc); (void *) gst_osx_audio_sink_io_proc);
@ -447,7 +451,7 @@ gst_osx_audio_sink_create_ringbuffer (GstBaseAudioSink * sink)
ringbuffer->core_audio->device_id = osxsink->device_id; ringbuffer->core_audio->device_id = osxsink->device_id;
ringbuffer->core_audio->is_src = FALSE; ringbuffer->core_audio->is_src = FALSE;
return GST_RING_BUFFER (ringbuffer); return GST_AUDIO_RING_BUFFER (ringbuffer);
} }
/* HALOutput AudioUnit will request fairly arbitrarily-sized chunks /* HALOutput AudioUnit will request fairly arbitrarily-sized chunks
@ -455,7 +459,7 @@ gst_osx_audio_sink_create_ringbuffer (GstBaseAudioSink * sink)
* the current ringbuffer segment we are, and only advance the segment * the current ringbuffer segment we are, and only advance the segment
* once we've read the whole thing */ * once we've read the whole thing */
static OSStatus static OSStatus
gst_osx_audio_sink_io_proc (GstOsxRingBuffer * buf, gst_osx_audio_sink_io_proc (GstOsxAudioRingBuffer * buf,
AudioUnitRenderActionFlags * ioActionFlags, AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp, const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList) UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList)
@ -468,7 +472,7 @@ gst_osx_audio_sink_io_proc (GstOsxRingBuffer * buf,
gint offset = 0; gint offset = 0;
while (remaining) { while (remaining) {
if (!gst_ring_buffer_prepare_read (GST_RING_BUFFER (buf), if (!gst_audio_ring_buffer_prepare_read (GST_AUDIO_RING_BUFFER (buf),
&readseg, &readptr, &len)) &readseg, &readptr, &len))
return 0; return 0;
@ -484,12 +488,12 @@ gst_osx_audio_sink_io_proc (GstOsxRingBuffer * buf,
offset += len; offset += len;
remaining -= len; remaining -= len;
if ((gint) buf->segoffset == GST_RING_BUFFER (buf)->spec.segsize) { if ((gint) buf->segoffset == GST_AUDIO_RING_BUFFER (buf)->spec.segsize) {
/* clear written samples */ /* clear written samples */
gst_ring_buffer_clear (GST_RING_BUFFER (buf), readseg); gst_audio_ring_buffer_clear (GST_AUDIO_RING_BUFFER (buf), readseg);
/* we wrote one segment */ /* we wrote one segment */
gst_ring_buffer_advance (GST_RING_BUFFER (buf), 1); gst_audio_ring_buffer_advance (GST_AUDIO_RING_BUFFER (buf), 1);
buf->segoffset = 0; buf->segoffset = 0;
} }
@ -508,9 +512,9 @@ gst_osx_audio_sink_osxelement_init (gpointer g_iface, gpointer iface_data)
static void static void
gst_osx_audio_sink_set_volume (GstOsxAudioSink * sink) gst_osx_audio_sink_set_volume (GstOsxAudioSink * sink)
{ {
GstOsxRingBuffer *osxbuf; GstOsxAudioRingBuffer *osxbuf;
osxbuf = GST_OSX_RING_BUFFER (GST_BASE_AUDIO_SINK (sink)->ringbuffer); osxbuf = GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SINK (sink)->ringbuffer);
if (!osxbuf) if (!osxbuf)
return; return;
@ -527,17 +531,7 @@ gst_osx_audio_sink_allowed_caps (GstOsxAudioSink * osxsink)
GstPadTemplate *pad_template; GstPadTemplate *pad_template;
GstCaps *caps, *in_caps; GstCaps *caps, *in_caps;
GstAudioChannelPosition pos[9] = { guint64 channel_mask = 0;
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID,
GST_AUDIO_CHANNEL_POSITION_INVALID
};
/* First collect info about the HW capabilites and preferences */ /* First collect info about the HW capabilites and preferences */
spdif_allowed = spdif_allowed =
@ -561,31 +555,31 @@ gst_osx_audio_sink_allowed_caps (GstOsxAudioSink * osxsink)
for (i = 0; i < max_channels; i++) { for (i = 0; i < max_channels; i++) {
switch (layout->mChannelDescriptions[i].mChannelLabel) { switch (layout->mChannelDescriptions[i].mChannelLabel) {
case kAudioChannelLabel_Left: case kAudioChannelLabel_Left:
pos[i] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_LEFT);
break; break;
case kAudioChannelLabel_Right: case kAudioChannelLabel_Right:
pos[i] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_RIGHT);
break; break;
case kAudioChannelLabel_Center: case kAudioChannelLabel_Center:
pos[i] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (FRONT_CENTER);
break; break;
case kAudioChannelLabel_LFEScreen: case kAudioChannelLabel_LFEScreen:
pos[i] = GST_AUDIO_CHANNEL_POSITION_LFE; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (LFE1);
break; break;
case kAudioChannelLabel_LeftSurround: case kAudioChannelLabel_LeftSurround:
pos[i] = GST_AUDIO_CHANNEL_POSITION_REAR_LEFT; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (REAR_LEFT);
break; break;
case kAudioChannelLabel_RightSurround: case kAudioChannelLabel_RightSurround:
pos[i] = GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (REAR_RIGHT);
break; break;
case kAudioChannelLabel_RearSurroundLeft: case kAudioChannelLabel_RearSurroundLeft:
pos[i] = GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (SIDE_LEFT);
break; break;
case kAudioChannelLabel_RearSurroundRight: case kAudioChannelLabel_RearSurroundRight:
pos[i] = GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (SIDE_RIGHT);
break; break;
case kAudioChannelLabel_CenterSurround: case kAudioChannelLabel_CenterSurround:
pos[i] = GST_AUDIO_CHANNEL_POSITION_REAR_CENTER; channel_mask |= GST_AUDIO_CHANNEL_POSITION_MASK (REAR_CENTER);
break; break;
default: default:
GST_WARNING_OBJECT (osxsink, "unrecognized channel: %d", GST_WARNING_OBJECT (osxsink, "unrecognized channel: %d",
@ -619,12 +613,12 @@ gst_osx_audio_sink_allowed_caps (GstOsxAudioSink * osxsink)
if (max_channels > 2 && use_positions) { if (max_channels > 2 && use_positions) {
out_s = gst_structure_copy (in_s); out_s = gst_structure_copy (in_s);
gst_structure_remove_field (out_s, "channels"); gst_structure_remove_field (out_s, "channels");
gst_structure_set (out_s, "channels", G_TYPE_INT, max_channels, NULL); gst_structure_set (out_s, "channels", G_TYPE_INT, max_channels,
gst_audio_set_channel_positions (out_s, pos); "channel-mask", GST_TYPE_BITMASK, channel_mask, NULL);
gst_caps_append_structure (caps, out_s); gst_caps_append_structure (caps, out_s);
} }
out_s = gst_structure_copy (in_s); out_s = gst_structure_copy (in_s);
gst_structure_remove_field (out_s, "channels"); gst_structure_remove_fields (out_s, "channels", "channel-mask", NULL);
gst_structure_set (out_s, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL); gst_structure_set (out_s, "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
gst_caps_append_structure (caps, out_s); gst_caps_append_structure (caps, out_s);
} }

View File

@ -51,8 +51,8 @@
#define __GST_OSXAUDIOSINK_H__ #define __GST_OSXAUDIOSINK_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/gstbaseaudiosink.h> #include <gst/audio/gstaudiobasesink.h>
#include "gstosxringbuffer.h" #include "gstosxaudioringbuffer.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -68,7 +68,7 @@ typedef struct _GstOsxAudioSinkClass GstOsxAudioSinkClass;
struct _GstOsxAudioSink struct _GstOsxAudioSink
{ {
GstBaseAudioSink sink; GstAudioBaseSink sink;
AudioDeviceID device_id; AudioDeviceID device_id;
@ -79,7 +79,7 @@ struct _GstOsxAudioSink
struct _GstOsxAudioSinkClass struct _GstOsxAudioSinkClass
{ {
GstBaseAudioSinkClass parent_class; GstAudioBaseSinkClass parent_class;
}; };
GType gst_osx_audio_sink_get_type (void); GType gst_osx_audio_sink_get_type (void);

View File

@ -95,13 +95,13 @@ static void gst_osx_audio_src_set_property (GObject * object, guint prop_id,
static void gst_osx_audio_src_get_property (GObject * object, guint prop_id, static void gst_osx_audio_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static GstCaps *gst_osx_audio_src_get_caps (GstBaseSrc * src); static GstCaps *gst_osx_audio_src_get_caps (GstBaseSrc * src, GstCaps * filter);
static GstRingBuffer *gst_osx_audio_src_create_ringbuffer (GstBaseAudioSrc * static GstAudioRingBuffer *gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc
src); * src);
static void gst_osx_audio_src_osxelement_init (gpointer g_iface, static void gst_osx_audio_src_osxelement_init (gpointer g_iface,
gpointer iface_data); gpointer iface_data);
static OSStatus gst_osx_audio_src_io_proc (GstOsxRingBuffer * buf, static OSStatus gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf,
AudioUnitRenderActionFlags * ioActionFlags, AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber, const AudioTimeStamp * inTimeStamp, UInt32 inBusNumber,
UInt32 inNumberFrames, AudioBufferList * bufferList); UInt32 inNumberFrames, AudioBufferList * bufferList);
@ -123,22 +123,9 @@ gst_osx_audio_src_do_init (GType type)
&osxelement_info); &osxelement_info);
} }
GST_BOILERPLATE_FULL (GstOsxAudioSrc, gst_osx_audio_src, GstBaseAudioSrc, G_DEFINE_TYPE_WITH_CODE (GstOsxAudioSrc, gst_osx_audio_src,
GST_TYPE_BASE_AUDIO_SRC, gst_osx_audio_src_do_init); GST_TYPE_AUDIO_BASE_SRC,
gst_osx_audio_src_do_init (GST_TYPE_AUDIO_BASE_SRC));
static void
gst_osx_audio_src_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_factory));
gst_element_class_set_static_metadata (element_class, "Audio Source (OSX)",
"Source/Audio",
"Input from a sound card in OS X",
"Zaheer Abbas Merali <zaheerabbas at merali dot org>");
}
static void static void
gst_osx_audio_src_class_init (GstOsxAudioSrcClass * klass) gst_osx_audio_src_class_init (GstOsxAudioSrcClass * klass)
@ -146,14 +133,12 @@ gst_osx_audio_src_class_init (GstOsxAudioSrcClass * klass)
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
GstBaseSrcClass *gstbasesrc_class; GstBaseSrcClass *gstbasesrc_class;
GstBaseAudioSrcClass *gstbaseaudiosrc_class; GstAudioBaseSrcClass *gstaudiobasesrc_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
gstbasesrc_class = (GstBaseSrcClass *) klass; gstbasesrc_class = (GstBaseSrcClass *) klass;
gstbaseaudiosrc_class = (GstBaseAudioSrcClass *) klass; gstaudiobasesrc_class = (GstAudioBaseSrcClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_class->set_property = gst_osx_audio_src_set_property; gobject_class->set_property = gst_osx_audio_src_set_property;
gobject_class->get_property = gst_osx_audio_src_get_property; gobject_class->get_property = gst_osx_audio_src_get_property;
@ -164,12 +149,20 @@ gst_osx_audio_src_class_init (GstOsxAudioSrcClass * klass)
g_param_spec_int ("device", "Device ID", "Device ID of input device", g_param_spec_int ("device", "Device ID", "Device ID of input device",
0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gstbaseaudiosrc_class->create_ringbuffer = gstaudiobasesrc_class->create_ringbuffer =
GST_DEBUG_FUNCPTR (gst_osx_audio_src_create_ringbuffer); GST_DEBUG_FUNCPTR (gst_osx_audio_src_create_ringbuffer);
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&src_factory));
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>");
} }
static void static void
gst_osx_audio_src_init (GstOsxAudioSrc * src, GstOsxAudioSrcClass * gclass) gst_osx_audio_src_init (GstOsxAudioSrc * src)
{ {
gst_base_src_set_live (GST_BASE_SRC (src), TRUE); gst_base_src_set_live (GST_BASE_SRC (src), TRUE);
@ -210,7 +203,7 @@ gst_osx_audio_src_get_property (GObject * object, guint prop_id,
} }
static GstCaps * static GstCaps *
gst_osx_audio_src_get_caps (GstBaseSrc * src) gst_osx_audio_src_get_caps (GstBaseSrc * src, GstCaps * filter)
{ {
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
GstOsxAudioSrc *osxsrc; GstOsxAudioSrc *osxsrc;
@ -248,18 +241,18 @@ gst_osx_audio_src_get_caps (GstBaseSrc * src)
return caps; return caps;
} }
static GstRingBuffer * static GstAudioRingBuffer *
gst_osx_audio_src_create_ringbuffer (GstBaseAudioSrc * src) gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc * src)
{ {
GstOsxAudioSrc *osxsrc; GstOsxAudioSrc *osxsrc;
GstOsxRingBuffer *ringbuffer; GstOsxAudioRingBuffer *ringbuffer;
osxsrc = GST_OSX_AUDIO_SRC (src); osxsrc = GST_OSX_AUDIO_SRC (src);
gst_osx_audio_src_select_device (osxsrc); gst_osx_audio_src_select_device (osxsrc);
GST_DEBUG ("Creating ringbuffer"); GST_DEBUG ("Creating ringbuffer");
ringbuffer = g_object_new (GST_TYPE_OSX_RING_BUFFER, NULL); ringbuffer = g_object_new (GST_TYPE_OSX_AUDIO_RING_BUFFER, NULL);
GST_DEBUG ("osx src 0x%p element 0x%p ioproc 0x%p", osxsrc, GST_DEBUG ("osx src 0x%p element 0x%p ioproc 0x%p", osxsrc,
GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsrc), GST_OSX_AUDIO_ELEMENT_GET_INTERFACE (osxsrc),
(void *) gst_osx_audio_src_io_proc); (void *) gst_osx_audio_src_io_proc);
@ -269,11 +262,11 @@ gst_osx_audio_src_create_ringbuffer (GstBaseAudioSrc * src)
ringbuffer->core_audio->is_src = TRUE; ringbuffer->core_audio->is_src = TRUE;
ringbuffer->core_audio->device_id = osxsrc->device_id; ringbuffer->core_audio->device_id = osxsrc->device_id;
return GST_RING_BUFFER (ringbuffer); return GST_AUDIO_RING_BUFFER (ringbuffer);
} }
static OSStatus static OSStatus
gst_osx_audio_src_io_proc (GstOsxRingBuffer * buf, gst_osx_audio_src_io_proc (GstOsxAudioRingBuffer * buf,
AudioUnitRenderActionFlags * ioActionFlags, AudioUnitRenderActionFlags * ioActionFlags,
const AudioTimeStamp * inTimeStamp, const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList) UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * bufferList)
@ -296,7 +289,7 @@ gst_osx_audio_src_io_proc (GstOsxRingBuffer * buf,
remaining = buf->core_audio->recBufferList->mBuffers[0].mDataByteSize; remaining = buf->core_audio->recBufferList->mBuffers[0].mDataByteSize;
while (remaining) { while (remaining) {
if (!gst_ring_buffer_prepare_read (GST_RING_BUFFER (buf), if (!gst_audio_ring_buffer_prepare_read (GST_AUDIO_RING_BUFFER (buf),
&writeseg, &writeptr, &len)) &writeseg, &writeptr, &len))
return 0; return 0;
@ -313,9 +306,9 @@ gst_osx_audio_src_io_proc (GstOsxRingBuffer * buf,
offset += len; offset += len;
remaining -= len; remaining -= len;
if ((gint) buf->segoffset == GST_RING_BUFFER (buf)->spec.segsize) { if ((gint) buf->segoffset == GST_AUDIO_RING_BUFFER (buf)->spec.segsize) {
/* we wrote one segment */ /* we wrote one segment */
gst_ring_buffer_advance (GST_RING_BUFFER (buf), 1); gst_audio_ring_buffer_advance (GST_AUDIO_RING_BUFFER (buf), 1);
buf->segoffset = 0; buf->segoffset = 0;
} }

View File

@ -45,8 +45,8 @@
#define __GST_OSXAUDIOSRC_H__ #define __GST_OSXAUDIOSRC_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/gstbaseaudiosrc.h> #include <gst/audio/gstaudiobasesrc.h>
#include "gstosxringbuffer.h" #include "gstosxaudioringbuffer.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -62,7 +62,7 @@ typedef struct _GstOsxAudioSrcClass GstOsxAudioSrcClass;
struct _GstOsxAudioSrc struct _GstOsxAudioSrc
{ {
GstBaseAudioSrc src; GstAudioBaseSrc src;
AudioDeviceID device_id; AudioDeviceID device_id;
@ -72,7 +72,7 @@ struct _GstOsxAudioSrc
struct _GstOsxAudioSrcClass struct _GstOsxAudioSrcClass
{ {
GstBaseAudioSrcClass parent_class; GstAudioBaseSrcClass parent_class;
}; };
GType gst_osx_audio_src_get_type (void); GType gst_osx_audio_src_get_type (void);

View File

@ -222,7 +222,8 @@ gst_core_audio_set_channels_layout (GstCoreAudio * core_audio,
int layoutSize, element, i; int layoutSize, element, i;
AudioUnitScope scope; AudioUnitScope scope;
GstStructure *structure; GstStructure *structure;
GstAudioChannelPosition *positions; GstAudioChannelPosition *positions = NULL;
guint64 channel_mask;
/* Describe channels */ /* Describe channels */
layoutSize = sizeof (AudioChannelLayout) + layoutSize = sizeof (AudioChannelLayout) +
@ -230,7 +231,11 @@ gst_core_audio_set_channels_layout (GstCoreAudio * core_audio,
layout = g_malloc (layoutSize); layout = g_malloc (layoutSize);
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
positions = gst_audio_get_channel_positions (structure); if (gst_structure_get (structure, "channel-mask", GST_TYPE_BITMASK,
&channel_mask, NULL)) {
positions = g_new (GstAudioChannelPosition, channels);
gst_audio_channel_positions_from_mask (channels, channel_mask, positions);
}
layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions; layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
layout->mChannelBitmap = 0; /* Not used */ layout->mChannelBitmap = 0; /* Not used */
@ -377,7 +382,7 @@ gst_audio_channel_position_to_coreaudio_channel_label (GstAudioChannelPosition
switch (position) { switch (position) {
case GST_AUDIO_CHANNEL_POSITION_NONE: case GST_AUDIO_CHANNEL_POSITION_NONE:
return kAudioChannelLabel_Discrete_0 | channel; return kAudioChannelLabel_Discrete_0 | channel;
case GST_AUDIO_CHANNEL_POSITION_FRONT_MONO: case GST_AUDIO_CHANNEL_POSITION_MONO:
return kAudioChannelLabel_Mono; return kAudioChannelLabel_Mono;
case GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT: case GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT:
return kAudioChannelLabel_Left; return kAudioChannelLabel_Left;
@ -389,7 +394,7 @@ gst_audio_channel_position_to_coreaudio_channel_label (GstAudioChannelPosition
return kAudioChannelLabel_LeftSurround; return kAudioChannelLabel_LeftSurround;
case GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT: case GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT:
return kAudioChannelLabel_RightSurround; return kAudioChannelLabel_RightSurround;
case GST_AUDIO_CHANNEL_POSITION_LFE: case GST_AUDIO_CHANNEL_POSITION_LFE1:
return kAudioChannelLabel_LFEScreen; return kAudioChannelLabel_LFEScreen;
case GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER: case GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER:
return kAudioChannelLabel_Center; return kAudioChannelLabel_Center;

View File

@ -22,7 +22,11 @@
*/ */
#include "gstosxcoreaudio.h" #include "gstosxcoreaudio.h"
<<<<<<<
#include <gst/audio/multichannel.h> #include <gst/audio/multichannel.h>
=======
#include <gst/audio/audio-channels.h>
>>>>>>>
typedef struct typedef struct
{ {