| 1 |
/* |
| 2 |
* GStreamer |
| 3 |
* Copyright (C) 2012 Fluendo S.A. <[email protected]> |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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. |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef __GST_CORE_AUDIO_H__ |
| 23 |
#define __GST_CORE_AUDIO_H__ |
| 24 |
|
| 25 |
#ifdef HAVE_CONFIG_H |
| 26 |
# include <config.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <gst/gst.h> |
| 30 |
#include <gst/audio/audio-channels.h> |
| 31 |
#include <TargetConditionals.h> |
| 32 |
#if TARGET_OS_OSX |
| 33 |
#include <CoreAudio/CoreAudio.h> |
| 34 |
#include <AudioToolbox/AudioToolbox.h> |
| 35 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 |
| 36 |
#include <CoreServices/CoreServices.h> |
| 37 |
#define AudioComponentFindNext FindNextComponent |
| 38 |
#define AudioComponentInstanceNew OpenAComponent |
| 39 |
#define AudioComponentInstanceDispose CloseComponent |
| 40 |
#define AudioComponent Component |
| 41 |
#define AudioComponentDescription ComponentDescription |
| 42 |
#endif |
| 43 |
#else |
| 44 |
#include <CoreAudio/CoreAudioTypes.h> |
| 45 |
#define AudioDeviceID gint |
| 46 |
#define kAudioDeviceUnknown 0 |
| 47 |
#endif |
| 48 |
#include <AudioUnit/AudioUnit.h> |
| 49 |
#include <mach/mach_time.h> |
| 50 |
#include "gstosxaudioelement.h" |
| 51 |
|
| 52 |
|
| 53 |
G_BEGIN_DECLS |
| 54 |
|
| 55 |
#define GST_TYPE_CORE_AUDIO \ |
| 56 |
(gst_core_audio_get_type()) |
| 57 |
#define GST_CORE_AUDIO(obj) \ |
| 58 |
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CORE_AUDIO,GstCoreAudio)) |
| 59 |
#define GST_CORE_AUDIO_CLASS(klass) \ |
| 60 |
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CORE_AUDIO,GstCoreAudioClass)) |
| 61 |
#define GST_CORE_AUDIO_GET_CLASS(obj) \ |
| 62 |
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_CORE_AUDIO,GstCoreAudioClass)) |
| 63 |
#define GST_IS_CORE_AUDIO(obj) \ |
| 64 |
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CORE_AUDIO)) |
| 65 |
#define GST_IS_CORE_AUDIO_CLASS(klass) \ |
| 66 |
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CORE_AUDIO)) |
| 67 |
|
| 68 |
#define GST_OSX_AUDIO_MAX_CHANNEL (64) |
| 69 |
|
| 70 |
#define CORE_AUDIO_FORMAT_IS_SPDIF(f) ((f).mFormat.mFormatID == 'IAC3' || (f).mFormat.mFormatID == 'iac3' || (f).mFormat.mFormatID == kAudioFormat60958AC3 || (f).mFormat.mFormatID == kAudioFormatAC3) |
| 71 |
|
| 72 |
#define CORE_AUDIO_FORMAT "FormatID: %" GST_FOURCC_FORMAT " rate: %f flags: 0x%x BytesPerPacket: %u FramesPerPacket: %u BytesPerFrame: %u ChannelsPerFrame: %u BitsPerChannel: %u" |
| 73 |
#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 |
|
| 75 |
#define CORE_AUDIO_INNER_SCOPE(core_audio) ((core_audio)->is_src ? kAudioUnitScope_Output : kAudioUnitScope_Input) |
| 76 |
#define CORE_AUDIO_OUTER_SCOPE(core_audio) ((core_audio)->is_src ? kAudioUnitScope_Input : kAudioUnitScope_Output) |
| 77 |
#define CORE_AUDIO_ELEMENT(core_audio) ((core_audio)->is_src ? 1 : 0) |
| 78 |
|
| 79 |
typedef struct _GstCoreAudio GstCoreAudio; |
| 80 |
typedef struct _GstCoreAudioClass GstCoreAudioClass; |
| 81 |
|
| 82 |
#define CORE_AUDIO_TIMING_LOCK(core_audio) (g_mutex_lock(&(core_audio->timing_lock))) |
| 83 |
#define CORE_AUDIO_TIMING_UNLOCK(core_audio) (g_mutex_unlock(&(core_audio->timing_lock))) |
| 84 |
|
| 85 |
struct _GstCoreAudio |
| 86 |
{ |
| 87 |
GObject object; |
| 88 |
|
| 89 |
GstObject *osxbuf; |
| 90 |
GstOsxAudioElementInterface *element; |
| 91 |
|
| 92 |
gboolean is_src; |
| 93 |
gboolean is_passthrough; |
| 94 |
AudioDeviceID device_id; |
| 95 |
char *unique_id; |
| 96 |
gboolean is_default; |
| 97 |
gboolean cached_caps_valid; /* thread-safe flag */ |
| 98 |
GstCaps *cached_caps; |
| 99 |
gint stream_idx; |
| 100 |
gboolean io_proc_active; |
| 101 |
gboolean io_proc_dropping; |
| 102 |
|
| 103 |
/* For LPCM in/out */ |
| 104 |
AudioUnit audiounit; |
| 105 |
UInt32 recBufferSize; /* AudioUnitRender clobbers mDataByteSize */ |
| 106 |
AudioBufferList *recBufferList; |
| 107 |
|
| 108 |
#if TARGET_OS_OSX |
| 109 |
/* For SPDIF out */ |
| 110 |
pid_t hog_pid; |
| 111 |
gboolean disabled_mixing; |
| 112 |
AudioStreamID stream_id; |
| 113 |
gboolean revert_format; |
| 114 |
AudioStreamBasicDescription original_format, stream_format; |
| 115 |
AudioDeviceIOProcID procID; |
| 116 |
#endif |
| 117 |
|
| 118 |
mach_timebase_info_data_t timebase; |
| 119 |
GMutex timing_lock; |
| 120 |
uint64_t anchor_hosttime_ns; |
| 121 |
uint32_t anchor_pend_samples; |
| 122 |
float rate_scalar; |
| 123 |
|
| 124 |
#if !TARGET_OS_OSX |
| 125 |
gdouble first_sample_time; |
| 126 |
gboolean configure_session; |
| 127 |
#endif |
| 128 |
}; |
| 129 |
|
| 130 |
struct _GstCoreAudioClass |
| 131 |
{ |
| 132 |
GObjectClass parent_class; |
| 133 |
}; |
| 134 |
|
| 135 |
GType gst_core_audio_get_type (void); |
| 136 |
|
| 137 |
void gst_core_audio_init_debug (void); |
| 138 |
|
| 139 |
gboolean gst_core_audio_open (GstCoreAudio *core_audio); |
| 140 |
|
| 141 |
gboolean gst_core_audio_close (GstCoreAudio *core_audio); |
| 142 |
|
| 143 |
gboolean gst_core_audio_initialize (GstCoreAudio *core_audio, |
| 144 |
AudioStreamBasicDescription format, |
| 145 |
GstCaps *caps, |
| 146 |
guint32 frames_per_packet, |
| 147 |
gboolean is_passthrough); |
| 148 |
|
| 149 |
void gst_core_audio_uninitialize (GstCoreAudio *core_audio); |
| 150 |
|
| 151 |
gboolean gst_core_audio_start_processing (GstCoreAudio *core_audio); |
| 152 |
|
| 153 |
gboolean gst_core_audio_pause_processing (GstCoreAudio *core_audio); |
| 154 |
|
| 155 |
gboolean gst_core_audio_stop_processing (GstCoreAudio *core_audio); |
| 156 |
|
| 157 |
gboolean gst_core_audio_get_samples_and_latency (GstCoreAudio * core_audio, |
| 158 |
gdouble rate, |
| 159 |
guint *samples, |
| 160 |
gdouble *latency); |
| 161 |
|
| 162 |
void gst_core_audio_update_timing (GstCoreAudio * core_audio, |
| 163 |
const AudioTimeStamp * inTimeStamp, |
| 164 |
unsigned int inNumberFrames); |
| 165 |
|
| 166 |
void gst_core_audio_set_volume (GstCoreAudio *core_audio, |
| 167 |
gfloat volume); |
| 168 |
|
| 169 |
gboolean gst_core_audio_audio_device_is_spdif_avail (AudioDeviceID device_id); |
| 170 |
|
| 171 |
|
| 172 |
gboolean gst_core_audio_select_device (GstCoreAudio * core_audio); |
| 173 |
|
| 174 |
GstCaps * |
| 175 |
gst_core_audio_probe_caps (GstCoreAudio * core_audio, GstCaps * in_caps); |
| 176 |
|
| 177 |
AudioChannelLayout * |
| 178 |
gst_core_audio_get_channel_layout (GstCoreAudio * core_audio, gboolean outer); |
| 179 |
|
| 180 |
gboolean gst_core_audio_parse_channel_layout (AudioChannelLayout * layout, |
| 181 |
AudioDeviceID device_id, guint * channels, guint64 * channel_mask, GstAudioChannelPosition * pos); |
| 182 |
GstCaps * gst_core_audio_asbd_to_caps (AudioStreamBasicDescription * asbd, AudioDeviceID device_id, |
| 183 |
AudioChannelLayout * layout); |
| 184 |
|
| 185 |
G_END_DECLS |
| 186 |
|
| 187 |
#endif /* __GST_CORE_AUDIO_H__ */ |