coreaudio: disable resampling when latency is too high
[vlc.git] / modules / audio_output / coreaudio_common.h
blob21cdcb6518e696a82a8fc414011ab23adbdc57ec
1 /*****************************************************************************
2 * coreaudio_common.h: Common AudioUnit code for iOS and macOS
3 *****************************************************************************
4 * Copyright (C) 2005 - 2017 VLC authors and VideoLAN
6 * Authors: Derk-Jan Hartman <hartman at videolan dot org>
7 * Felix Paul Kühne <fkuehne at videolan dot org>
8 * David Fuhrmann <david dot fuhrmann at googlemail dot com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # import "config.h"
27 #endif
29 #import <vlc_common.h>
30 #import <stdatomic.h>
31 #import <vlc_aout.h>
32 #import <vlc_threads.h>
34 #import <AudioUnit/AudioUnit.h>
35 #import <AudioToolbox/AudioToolbox.h>
36 #import "TPCircularBuffer.h"
38 #define STREAM_FORMAT_MSG(pre, sfm) \
39 pre "[%f][%4.4s][%u][%u][%u][%u][%u][%u]", \
40 sfm.mSampleRate, (char *)&sfm.mFormatID, \
41 (unsigned int)sfm.mFormatFlags, (unsigned int)sfm.mBytesPerPacket, \
42 (unsigned int)sfm.mFramesPerPacket, (unsigned int)sfm.mBytesPerFrame, \
43 (unsigned int)sfm.mChannelsPerFrame, (unsigned int)sfm.mBitsPerChannel
45 #define ca_LogErr(fmt) msg_Err(p_aout, fmt ", OSStatus: %d", (int) err)
46 #define ca_LogWarn(fmt) msg_Warn(p_aout, fmt ", OSStatus: %d", (int) err)
48 struct aout_sys_common
50 /* The following is owned by common.c (initialized from ca_Init, cleaned
51 * from ca_Clean) */
53 /* circular buffer to swap the audio data */
54 TPCircularBuffer circular_buffer;
55 atomic_uint i_underrun_size;
56 atomic_bool b_paused;
57 atomic_bool b_do_flush;
58 atomic_bool b_highlatency;
59 vlc_sem_t flush_sem;
60 vlc_mutex_t lock;
61 int i_rate;
62 unsigned int i_bytes_per_frame;
63 unsigned int i_frame_length;
64 uint8_t chans_to_reorder;
65 uint8_t chan_table[AOUT_CHAN_MAX];
66 /* ca_TimeGet extra latency, in micro-seconds */
67 mtime_t i_dev_latency_us;
70 void ca_Open(audio_output_t *p_aout);
72 void ca_Close(audio_output_t *p_aout);
74 void ca_Render(audio_output_t *p_aout, uint32_t i_nb_samples, uint8_t *p_output,
75 size_t i_requested);
77 int ca_TimeGet(audio_output_t *p_aout, mtime_t *delay);
79 void ca_Flush(audio_output_t *p_aout, bool wait);
81 void ca_Pause(audio_output_t * p_aout, bool pause, mtime_t date);
83 void ca_Play(audio_output_t * p_aout, block_t * p_block);
85 int ca_Initialize(audio_output_t *p_aout, const audio_sample_format_t *fmt,
86 mtime_t i_dev_latency_us);
88 void ca_Uninitialize(audio_output_t *p_aout);
90 void ca_SetAliveState(audio_output_t *p_aout, bool alive);
92 AudioUnit au_NewOutputInstance(audio_output_t *p_aout, OSType comp_sub_type);
94 int au_Initialize(audio_output_t *p_aout, AudioUnit au,
95 audio_sample_format_t *fmt,
96 const AudioChannelLayout *outlayout, mtime_t i_dev_latency_us,
97 bool *warn_configuration);
99 void au_Uninitialize(audio_output_t *p_aout, AudioUnit au);