• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2012 Fluendo S.A. <support@fluendo.com>
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 #ifdef HAVE_IOS
32   #include <CoreAudio/CoreAudioTypes.h>
33   #define AudioDeviceID gint
34   #define kAudioDeviceUnknown 0
35 #else
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
45   #endif
46 #endif
47 #include <AudioUnit/AudioUnit.h>
48 #include "gstosxaudioelement.h"
49 
50 
51 G_BEGIN_DECLS
52 
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))
65 
66 #define GST_OSX_AUDIO_MAX_CHANNEL (64)
67 
68 #define CORE_AUDIO_FORMAT_IS_SPDIF(f) ((f).mFormat.mFormatID == 'IAC3' || (f).mFormat.mFormatID == 'iac3' || (f).mFormat.mFormatID == kAudioFormat60958AC3 || (f).mFormat.mFormatID == kAudioFormatAC3)
69 
70 #define CORE_AUDIO_FORMAT "FormatID: %" GST_FOURCC_FORMAT " rate: %f flags: 0x%x BytesPerPacket: %u FramesPerPacket: %u BytesPerFrame: %u ChannelsPerFrame: %u BitsPerChannel: %u"
71 #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
72 
73 #define CORE_AUDIO_INNER_SCOPE(core_audio) ((core_audio)->is_src ? kAudioUnitScope_Output : kAudioUnitScope_Input)
74 #define CORE_AUDIO_OUTER_SCOPE(core_audio) ((core_audio)->is_src ? kAudioUnitScope_Input : kAudioUnitScope_Output)
75 #define CORE_AUDIO_ELEMENT(core_audio) ((core_audio)->is_src ? 1 : 0)
76 
77 typedef struct _GstCoreAudio GstCoreAudio;
78 typedef struct _GstCoreAudioClass GstCoreAudioClass;
79 
80 struct _GstCoreAudio
81 {
82   GObject object;
83 
84   GstObject *osxbuf;
85   GstOsxAudioElementInterface *element;
86 
87   gboolean is_src;
88   gboolean is_passthrough;
89   AudioDeviceID device_id;
90   gboolean cached_caps_valid; /* thread-safe flag */
91   GstCaps *cached_caps;
92   gint stream_idx;
93   gboolean io_proc_active;
94   gboolean io_proc_needs_deactivation;
95 
96   /* For LPCM in/out */
97   AudioUnit audiounit;
98   UInt32 recBufferSize; /* AudioUnitRender clobbers mDataByteSize */
99   AudioBufferList *recBufferList;
100 
101 #ifndef HAVE_IOS
102   /* For SPDIF out */
103   pid_t hog_pid;
104   gboolean disabled_mixing;
105   AudioStreamID stream_id;
106   gboolean revert_format;
107   AudioStreamBasicDescription original_format, stream_format;
108   AudioDeviceIOProcID procID;
109 #endif
110 };
111 
112 struct _GstCoreAudioClass
113 {
114   GObjectClass parent_class;
115 };
116 
117 GType gst_core_audio_get_type                                (void);
118 
119 void gst_core_audio_init_debug (void);
120 
121 GstCoreAudio * gst_core_audio_new                            (GstObject *osxbuf);
122 
123 gboolean gst_core_audio_open                                 (GstCoreAudio *core_audio);
124 
125 gboolean gst_core_audio_close                                (GstCoreAudio *core_audio);
126 
127 gboolean gst_core_audio_initialize                           (GstCoreAudio *core_audio,
128                                                               AudioStreamBasicDescription format,
129                                                               GstCaps *caps,
130                                                               gboolean is_passthrough);
131 
132 void gst_core_audio_uninitialize                             (GstCoreAudio *core_audio);
133 
134 gboolean gst_core_audio_start_processing                     (GstCoreAudio *core_audio);
135 
136 gboolean gst_core_audio_pause_processing                     (GstCoreAudio *core_audio);
137 
138 gboolean gst_core_audio_stop_processing                      (GstCoreAudio *core_audio);
139 
140 gboolean gst_core_audio_get_samples_and_latency              (GstCoreAudio * core_audio,
141                                                               gdouble rate,
142                                                               guint *samples,
143                                                               gdouble *latency);
144 
145 void  gst_core_audio_set_volume                              (GstCoreAudio *core_audio,
146                                                               gfloat volume);
147 
148 gboolean gst_core_audio_audio_device_is_spdif_avail          (AudioDeviceID device_id);
149 
150 
151 gboolean gst_core_audio_select_device                        (GstCoreAudio * core_audio);
152 
153 GstCaps *
154 gst_core_audio_probe_caps (GstCoreAudio * core_audio, GstCaps * in_caps);
155 
156 AudioChannelLayout *
157 gst_core_audio_get_channel_layout (GstCoreAudio * core_audio, gboolean outer);
158 
159 gboolean gst_core_audio_parse_channel_layout (AudioChannelLayout * layout,
160     guint * channels, guint64 * channel_mask, GstAudioChannelPosition * pos);
161 GstCaps * gst_core_audio_asbd_to_caps (AudioStreamBasicDescription * asbd,
162     AudioChannelLayout * layout);
163 
164 G_END_DECLS
165 
166 #endif /* __GST_CORE_AUDIO_H__ */
167