3 * Copyright (C) 2012 Fluendo S.A. <support@fluendo.com>
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.
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.
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.
22 #ifndef __GST_CORE_AUDIO_H__
23 #define __GST_CORE_AUDIO_H__
30 #include <gst/audio/audio-channels.h>
32 #include <CoreAudio/CoreAudioTypes.h>
33 #define AudioDeviceID gint
34 #define kAudioDeviceUnknown 0
36 #include <CoreAudio/CoreAudio.h>
37 #include <AudioToolbox/AudioToolbox.h>
38 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
39 #include <CoreServices/CoreServices.h>
40 #define AudioComponentFindNext FindNextComponent
41 #define AudioComponentInstanceNew OpenAComponent
42 #define AudioComponentInstanceDispose CloseComponent
43 #define AudioComponent Component
44 #define AudioComponentDescription ComponentDescription
47 #include <AudioUnit/AudioUnit.h>
48 #include "gstosxaudioelement.h"
53 #define GST_TYPE_CORE_AUDIO \
54 (gst_core_audio_get_type())
55 #define GST_CORE_AUDIO(obj) \
56 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CORE_AUDIO,GstCoreAudio))
57 #define GST_CORE_AUDIO_CLASS(klass) \
58 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CORE_AUDIO,GstCoreAudioClass))
59 #define GST_CORE_AUDIO_GET_CLASS(obj) \
60 (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_CORE_AUDIO,GstCoreAudioClass))
61 #define GST_IS_CORE_AUDIO(obj) \
62 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CORE_AUDIO))
63 #define GST_IS_CORE_AUDIO_CLASS(klass) \
64 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CORE_AUDIO))
66 /* TODO: Consider raising to 64 */
67 #define GST_OSX_AUDIO_MAX_CHANNEL (9)
69 #define CORE_AUDIO_FORMAT_IS_SPDIF(f) ((f).mFormat.mFormatID == 'IAC3' || (f).mFormat.mFormatID == 'iac3' || (f).mFormat.mFormatID == kAudioFormat60958AC3 || (f).mFormat.mFormatID == kAudioFormatAC3)
71 #define CORE_AUDIO_FORMAT "FormatID: %" GST_FOURCC_FORMAT " rate: %f flags: 0x%x BytesPerPacket: %u FramesPerPacket: %u BytesPerFrame: %u ChannelsPerFrame: %u BitsPerChannel: %u"
72 #define CORE_AUDIO_FORMAT_ARGS(f) GST_FOURCC_ARGS((unsigned int)(f).mFormatID),(f).mSampleRate,(unsigned int)(f).mFormatFlags,(unsigned int)(f).mBytesPerPacket,(unsigned int)(f).mFramesPerPacket,(unsigned int)(f).mBytesPerFrame,(unsigned int)(f).mChannelsPerFrame,(unsigned int)(f).mBitsPerChannel
74 #define CORE_AUDIO_INNER_SCOPE(core_audio) ((core_audio)->is_src ? kAudioUnitScope_Output : kAudioUnitScope_Input)
75 #define CORE_AUDIO_OUTER_SCOPE(core_audio) ((core_audio)->is_src ? kAudioUnitScope_Input : kAudioUnitScope_Output)
76 #define CORE_AUDIO_ELEMENT(core_audio) ((core_audio)->is_src ? 1 : 0)
78 typedef struct _GstCoreAudio GstCoreAudio;
79 typedef struct _GstCoreAudioClass GstCoreAudioClass;
86 GstOsxAudioElementInterface *element;
89 gboolean is_passthrough;
90 AudioDeviceID device_id;
91 gboolean cached_caps_valid; /* thread-safe flag */
94 gboolean io_proc_active;
95 gboolean io_proc_needs_deactivation;
99 UInt32 recBufferSize; /* AudioUnitRender clobbers mDataByteSize */
100 AudioBufferList *recBufferList;
105 gboolean disabled_mixing;
106 AudioStreamID stream_id;
107 gboolean revert_format;
108 AudioStreamBasicDescription original_format, stream_format;
109 AudioDeviceIOProcID procID;
113 struct _GstCoreAudioClass
115 GObjectClass parent_class;
118 GType gst_core_audio_get_type (void);
120 void gst_core_audio_init_debug (void);
122 GstCoreAudio * gst_core_audio_new (GstObject *osxbuf);
124 gboolean gst_core_audio_open (GstCoreAudio *core_audio);
126 gboolean gst_core_audio_close (GstCoreAudio *core_audio);
128 gboolean gst_core_audio_initialize (GstCoreAudio *core_audio,
129 AudioStreamBasicDescription format,
131 gboolean is_passthrough);
133 void gst_core_audio_uninitialize (GstCoreAudio *core_audio);
135 gboolean gst_core_audio_start_processing (GstCoreAudio *core_audio);
137 gboolean gst_core_audio_pause_processing (GstCoreAudio *core_audio);
139 gboolean gst_core_audio_stop_processing (GstCoreAudio *core_audio);
141 gboolean gst_core_audio_get_samples_and_latency (GstCoreAudio * core_audio,
146 void gst_core_audio_set_volume (GstCoreAudio *core_audio,
149 gboolean gst_core_audio_audio_device_is_spdif_avail (AudioDeviceID device_id);
152 gboolean gst_core_audio_select_device (GstCoreAudio * core_audio);
155 gst_core_audio_probe_caps (GstCoreAudio * core_audio, GstCaps * in_caps);
158 gst_core_audio_get_channel_layout (GstCoreAudio * core_audio, gboolean outer);
160 gboolean gst_core_audio_parse_channel_layout (AudioChannelLayout * layout,
161 guint * channels, guint64 * channel_mask, GstAudioChannelPosition * pos);
162 GstCaps * gst_core_audio_asbd_to_caps (AudioStreamBasicDescription * asbd,
163 AudioChannelLayout * layout);
167 #endif /* __GST_CORE_AUDIO_H__ */