diff options
58 files changed, 1990 insertions, 329 deletions
diff --git a/man/pulse-daemon.conf.5.xml.in b/man/pulse-daemon.conf.5.xml.in index 82c2b8e5..e6b1e190 100644 --- a/man/pulse-daemon.conf.5.xml.in +++ b/man/pulse-daemon.conf.5.xml.in @@ -133,11 +133,11 @@ USA. </option> <option> - <p><opt>cpu-limit=</opt> If disabled d not install the CPU load + <p><opt>cpu-limit=</opt> If disabled do not install the CPU load limiter, even on platforms where it is supported. This option is useful when debugging/profiling PulseAudio to disable disturbing SIGXCPU signals. Takes a boolean argument, defaults to - <opt>yes</opt>. The <opt>--no-cpu-limit</opt> command line + <opt>no</opt>. The <opt>--no-cpu-limit</opt> command line argument takes precedence.</p> </option> diff --git a/pulseaudio.vapi b/pulseaudio.vapi new file mode 100644 index 00000000..cf0e82e0 --- /dev/null +++ b/pulseaudio.vapi @@ -0,0 +1,1463 @@ +/*** + This file is part of PulseAudio. + + Copyright 2009 Lennart Poettering + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +using GLib; +using Posix; + +[CCode (cheader_filename="pulse/pulseaudio.h")] +namespace Pulse { + + [CCode (cname="pa_get_library_version")] + public unowned string get_library_version(); + + [CCode (cname="PA_API_VERSION")] + public const int API_VERSION; + + [CCode (cname="PA_PROTOCOL_VERSION")] + public const int PROTOCOL_VERSION; + + [CCode (cname="PA_MAJOR")] + public const int MAJOR; + + [CCode (cname="PA_MINOR")] + public const int MINOR; + + [CCode (cname="PA_MICRO")] + public const int MICRO; + + [CCode (cname="PA_CHECK_VERSION")] + public bool CHECK_VERSION(int major, int minor, int micro); + + [CCode (cname="INVALID_INDEX")] + public const uint32 INVALID_INDEX; + + [CCode (cname="pa_free_cb_t")] + public delegate void FreeCb(void *p); + + [CCode (cname="pa_sample_format_t", cprefix="PA_SAMPLE_")] + public enum SampleFormat { + U8, + ALAW, + ULAW, + S16LE, + S16BE, + FLOAT32LE, + FLOAT32BE, + S32LE, + S32BE, + S24LE, + S24BE, + S24_32LE, + S24_32BE, + MAX, + S16NE, + S16RE, + FLOAT32NE, + FLOAT32RE, + S32NE, + S32RE, + S24NE, + S24RE, + S24_32NE, + S24_32RE; + + [CCode (cname="pa_sample_size_of_format")] + public size_t size(); + + [CCode (cname="pa_sample_format_to_string")] + public unowned string? to_string(); + + [CCode (cname="pa_sample_format_is_le")] + public int is_le(); + + [CCode (cname="pa_sample_format_is_be")] + public int is_be(); + + [CCode (cname="pa_sample_format_is_ne")] + public int is_ne(); + + [CCode (cname="pa_sample_format_is_re")] + public int is_re(); + + [CCode (cname="pa_parse_sample_format")] + public static SampleFormat parse(string b); + } + + [CCode (cname="pa_usec_t")] + public struct usec : uint64 { + } + + [CCode (cname="pa_sample_spec")] + public struct SampleSpec { + public SampleFormat format; + public uint32 rate; + public uint8 channels; + + [CCode (cname="PA_SAMPLE_SPEC_SNPRINT_MAX")] + public static const size_t SNPRINT_MAX; + + [CCode (cname="pa_bytes_per_second")] + public size_t bytes_per_second(); + + [CCode (cname="pa_frame_size")] + public size_t frame_size(); + + [CCode (cname="pa_sample_size")] + public size_t sample_size(); + + [CCode (cname="pa_bytes_to_usec", instance_pos=1.1)] + public usec bytes_to_usec(size_t size); + + [CCode (cname="pa_usec_to_bytes", instance_pos=1.1)] + public size_t usec_to_bytes(usec u); + + [CCode (cname="pa_sample_spec_init")] + public unowned SampleSpec? init(); + + [CCode (cname="pa_sample_spec_valid")] + public bool valid(); + + [CCode (cname="pa_sample_spec_equal")] + public bool equal(SampleSpec other); + + [CCode (cname="pa_sample_spec_snprint", instance_pos=3.1)] + public unowned string snprint(char[] buf); + + public string sprint() { + var buffer = new char[SNPRINT_MAX]; + this.snprint(buffer); + return (string) buffer; + } + + public string to_string() { + return sprint(); + } + + [CCode (cname="pa_sample_spec_init")] + SampleSpec(); + } + + // [CCode (cname="PA_BYTES_SNPRINT_MAX")] + [CCode (cname="PA_SAMPLE_SPEC_SNPRINT_MAX")] + public const size_t BYTES_SNPRINT_MAX; + + [CCode (cname="pa_bytes_snprint")] + public unowned string bytes_snprint(char[] buf, uint bytes); + + public string bytes_sprint(uint bytes) { + var buffer = new char[BYTES_SNPRINT_MAX]; + bytes_snprint(buffer, bytes); + return (string) buffer; + } + + [CCode (cname="pa_volume_t")] + public struct Volume : uint32 { + + [CCode (cname="PA_SW_VOLUME_SNPRINT_DB_MAX")] + public static const size_t SW_SNPRINT_DB_MAX; + + [CCode (cname="PA_VOLUME_SNPRINT_MAX")] + public static const size_t SNPRINT_MAX; + + [CCode (cname="PA_VOLUME_MAX")] + public static const Volume MAX; + + [CCode (cname="PA_VOLUME_NORM")] + public static const Volume NORM; + + [CCode (cname="PA_VOLUME_MUTED")] + public static const Volume MUTED; + + // [CCode (cname="PA_VOLUME_INVALID")] + [CCode (cname="PA_VOLUME_MAX")] + public static const Volume INVALID; + + [CCode (cname="pa_volume_snprint", instance_pos = 3.1)] + public unowned string snprint(char[] s); + + public string sprint() { + var buffer = new char[SNPRINT_MAX]; + this.snprint(buffer); + return (string) buffer; + } + + public string to_string() { + return sprint(); + } + + [CCode (cname="pa_sw_volume_snprint_dB", instance_pos = 3.1)] + public unowned string sw_snprint_dB(char[] s); + + public string sw_sprint_dB() { + var buffer = new char[SW_SNPRINT_DB_MAX]; + this.sw_snprint_dB(buffer); + return (string) buffer; + } + + [CCode (cname="pa_sw_volume_multiply")] + public Volume sw_multiply(Volume other); + + [CCode (cname="pa_sw_volume_divide")] + public Volume sw_divide(Volume other); + + [CCode (cname="pa_sw_volume_from_dB")] + public static Volume sw_from_dB(double f); + + [CCode (cname="pa_sw_volume_to_dB")] + public double sw_to_dB(); + + [CCode (cname="pa_sw_volume_from_linear")] + public static Volume sw_from_linear(double f); + + [CCode (cname="pa_sw_volume_to_linear")] + public double sw_to_linear(); + } + + [CCode (cname="PA_DECIBEL_MININFTY")] + public const double DECIBEL_MININFTY; + + [CCode (cname="PA_CHANNELS_MAX")] + public const int CHANNELS_MAX; + + [CCode (cname="PA_CHANNELS_MAX")] + public const int RATE_MAX; + + [CCode (cname="pa_cvolume")] + public struct CVolume { + public uint8 channels; + public Volume values[]; + + [CCode (cname="PA_SW_CVOLUME_SNPRINT_DB_MAX")] + public static const size_t SW_SNPRINT_DB_MAX; + + [CCode (cname="PA_CVOLUME_SNPRINT_MAX")] + public static const size_t SNPRINT_MAX; + + [CCode (cname="pa_cvolume_equal")] + public bool equal(CVolume other); + + [CCode (cname="pa_cvolume_init")] + public unowned CVolume? init(); + + [CCode (cname="pa_cvolume_reset")] + public unowned CVolume? reset(uint8 channels); + + [CCode (cname="pa_cvolume_mute")] + public unowned CVolume? mute(uint8 channels); + + [CCode (cname="pa_cvolume_snprint", instance_pos = 3.1)] + public unowned string snprint(char[] s); + + public string sprint() { + var buffer = new char[SNPRINT_MAX]; + this.snprint(buffer); + return (string) buffer; + } + + public string to_string() { + return sprint(); + } + + [CCode (cname="pa_sw_cvolume_snprint_dB", instance_pos = 3.1)] + public unowned string sw_snprint_dB(char [] s); + + public string sw_sprint_dB() { + var buffer = new char[SW_SNPRINT_DB_MAX]; + this.sw_snprint_dB(buffer); + return (string) buffer; + } + + [CCode (cname="pa_cvolume_init")] + public CVolume(); + + [CCode (cname="pa_cvolume_avg")] + public Volume avg(); + + [CCode (cname="pa_cvolume_max")] + public Volume max(); + + [CCode (cname="pa_cvolume_min")] + public Volume min(); + + [CCode (cname="pa_cvolume_avg_mask")] + public Volume avg_mask(ChannelMap map, ChannelPositionMask mask); + + [CCode (cname="pa_cvolume_max_mask")] + public Volume max_mask(ChannelMap map, ChannelPositionMask mask); + + [CCode (cname="pa_cvolume_min_mask")] + public Volume min_mask(ChannelMap map, ChannelPositionMask mask); + + [CCode (cname="pa_cvolume_valid")] + public bool valid(); + + [CCode (cname="pa_cvolume_channels_equal_to")] + public bool channels_equal_to(Volume other); + + [CCode (cname="pa_cvolume_is_muted")] + public bool is_muted(); + + [CCode (cname="pa_cvolume_is_norm")] + public bool is_norm(); + + [CCode (cname="pa_sw_cvolume_multiply")] + public unowned CVolume? multiply(CVolume other); + + [CCode (cname="pa_sw_cvolume_divide")] + public unowned CVolume? divide(CVolume other); + + [CCode (cname="pa_sw_cvolume_multiply_scalar")] + public unowned CVolume? multiply_scalar(Volume other); + + [CCode (cname="pa_sw_cvolume_divide_scalar")] + public unowned CVolume? divide_scalar(Volume other); + + [CCode (cname="pa_cvolume_remap")] + public unowned CVolume? remap(ChannelMap from, ChannelMap to); + + [CCode (cname="pa_cvolume_compatible")] + public bool compatible(SampleSpec ss); + + [CCode (cname="pa_cvolume_compatible_with_channel_map")] + public bool compatible_with_channel_map(ChannelMap cm); + + [CCode (cname="pa_cvolume_get_balance")] + public float get_balance(ChannelMap map); + + [CCode (cname="pa_cvolume_set_balance")] + public unowned CVolume? set_balance(ChannelMap map, float b); + + [CCode (cname="pa_cvolume_get_fade")] + public float get_fade(ChannelMap map); + + [CCode (cname="pa_cvolume_set_fade")] + public unowned CVolume? set_fade(ChannelMap map, float f); + + [CCode (cname="pa_cvolume_scale")] + public unowned CVolume? scale(Volume max); + + [CCode (cname="pa_cvolume_scale_mask")] + public unowned CVolume? scale_mask(Volume max, ChannelMap map, ChannelPositionMask mask); + + [CCode (cname="pa_cvolume_set_position")] + public unowned CVolume? set_position(ChannelMap map, ChannelPosition p, Volume v); + + [CCode (cname="pa_cvolume_get_position")] + public Volume get_position(ChannelMap map, ChannelPosition p); + + [CCode (cname="pa_cvolume_merge")] + public unowned CVolume? merge(CVolume other); + + [CCode (cname="pa_cvolume_inc")] + public unowned CVolume? inc(Volume plus = 1); + + [CCode (cname="pa_cvolume_dec")] + public unowned CVolume? dec(Volume minus = 1); + } + + [CCode (cname="pa_channel_map")] + public struct ChannelMap { + public uint8 channels; + public ChannelPosition map[]; + + [CCode (cname="PA_CHANNEL_MAP_SNPRINT_MAX")] + public static const size_t SNPRINT_MAX; + + [CCode (cname="pa_channel_map_init")] + public ChannelMap(); + + [CCode (cname="pa_channel_map_init")] + public unowned ChannelMap? init(); + + [CCode (cname="pa_channel_map_init_mono")] + public unowned ChannelMap? init_mono(); + + [CCode (cname="pa_channel_map_init_stereo")] + public unowned ChannelMap? init_stereo(); + + [CCode (cname="pa_channel_map_init_auto")] + public unowned ChannelMap? init_auto(uint8 channels, ChannelMapDef def = ChannelMapDef.DEFAULT); + + [CCode (cname="pa_channel_map_init_extend")] + public unowned ChannelMap? init_extend(uint8 channels, ChannelMapDef def = ChannelMapDef.DEFAULT); + + [CCode (cname="pa_channel_map_snprint", instance_pos = 3.1)] + public unowned string snprint(char[] s); + + public string sprint() { + var buffer = new char[SNPRINT_MAX]; + this.snprint(buffer); + return (string) buffer; + } + + public string to_string() { + return sprint(); + } + + [CCode (cname="pa_channel_map_parse")] + public unowned ChannelMap? parse(string s); + + [CCode (cname="pa_channel_map_equal")] + public bool equal(ChannelMap other); + + [CCode (cname="pa_channel_map_superset")] + public bool superset(ChannelMap other); + + [CCode (cname="pa_channel_map_valid")] + public bool valid(); + + [CCode (cname="pa_channel_map_compatible")] + public bool compatible(SampleSpec ss); + + [CCode (cname="pa_channel_map_can_balance")] + public bool can_balance(); + + [CCode (cname="pa_channel_map_can_fade")] + public bool can_fade(); + + [CCode (cname="pa_channel_map_to_name")] + public unowned string? to_name(); + + [CCode (cname="pa_channel_map_to_pretty_name")] + public unowned string? to_pretty_name(); + + [CCode (cname="pa_channel_map_has_position")] + public bool has_position(ChannelPosition p); + + [CCode (cname="pa_channel_map_mask")] + public ChannelPositionMask mask(); + } + + [CCode (cname="pa_channel_position_mask_t")] + public struct ChannelPositionMask : uint64 { + } + + [CCode (cname="pa_channel_position_t", cprefix="PA_CHANNEL_POSITION_")] + public enum ChannelPosition { + INVALID, + MONO, + FRONT_LEFT, + FRONT_RIGHT, + FRONT_CENTER, + REAR_CENTER, + REAR_LEFT, + REAR_RIGHT, + LFE, + FRONT_LEFT_OF_CENTER, + FRONT_RIGHT_OF_CENTER, + SIDE_LEFT, + SIDE_RIGHT, + TOP_CENTER, + AUX0, + AUX1, + AUX2, + AUX3, + AUX4, + AUX5, + AUX6, + AUX7, + AUX8, + AUX9, + AUX10, + AUX11, + AUX12, + AUX13, + AUX14, + AUX15, + AUX16, + AUX17, + AUX18, + AUX19, + AUX20, + AUX21, + AUX22, + AUX23, + AUX24, + AUX25, + AUX26, + AUX27, + AUX28, + AUX29, + AUX30, + AUX31, + MAX; + + [CCode (cname="PA_CHANNEL_POSITION_MASK")] + public ChannelPositionMask mask(); + + [CCode (cname="pa_channel_position_to_string")] + public unowned string? to_string(); + + [CCode (cname="pa_channel_position_to_pretty_string")] + public unowned string? to_pretty_string(); + + [CCode (cname="pa_channel_position_from_string")] + public static ChannelPosition from_string(string s); + } + + [CCode (cname="pa_channel_map_def_t", cprefix="PA_CHANNEL_MAP_")] + public enum ChannelMapDef { + AIFF, + WAVEEX, + AUX, + DEFAULT, + + [CCode (cname="PA_CHANNEL_MAP_DEF_MAX")] + MAX + } + + [Compact] + [CCode (cname="pa_proplist", cprefix="pa_proplist_", free_function="pa_proplist_free")] + public class Proplist { + + [CCode (cname="PA_PROP_MEDIA_NAME")] + public static const string PROP_MEDIA_NAME; + [CCode (cname="PA_PROP_MEDIA_TITLE")] + public static const string PROP_MEDIA_TITLE; + [CCode (cname="PA_PROP_MEDIA_ARTIST")] + public static const string PROP_MEDIA_ARTIST; + [CCode (cname="PA_PROP_MEDIA_COPYRIGHT")] + public static const string PROP_MEDIA_COPYRIGHT; + [CCode (cname="PA_PROP_MEDIA_SOFTWARE")] + public static const string PROP_MEDIA_SOFTWARE; + [CCode (cname="PA_PROP_MEDIA_LANGUAGE")] + public static const string PROP_MEDIA_LANGUAGE; + [CCode (cname="PA_PROP_MEDIA_FILENAME")] + public static const string PROP_MEDIA_FILENAME; + [CCode (cname="PA_PROP_MEDIA_ICON_NAME")] + public static const string PROP_MEDIA_ICON_NAME; + [CCode (cname="PA_PROP_MEDIA_ROLE")] + public static const string PROP_MEDIA_ROLE; + [CCode (cname="PA_PROP_EVENT_ID")] + public static const string PROP_EVENT_ID; + [CCode (cname="PA_PROP_EVENT_DESCRIPTION")] + public static const string PROP_EVENT_DESCRIPTION; + [CCode (cname="PA_PROP_EVENT_MOUSE_X")] + public static const string PROP_EVENT_MOUSE_X; + [CCode (cname="PA_PROP_EVENT_MOUSE_Y")] + public static const string PROP_EVENT_MOUSE_Y; + [CCode (cname="PA_PROP_EVENT_MOUSE_HPOS")] + public static const string PROP_EVENT_MOUSE_HPOS; + [CCode (cname="PA_PROP_EVENT_MOUSE_VPOS")] + public static const string PROP_EVENT_MOUSE_VPOS; + [CCode (cname="PA_PROP_EVENT_MOUSE_BUTTON")] + public static const string PROP_EVENT_MOUSE_BUTTON; + [CCode (cname="PA_PROP_WINDOW_NAME")] + public static const string PROP_WINDOW_NAME; + [CCode (cname="PA_PROP_WINDOW_ID")] + public static const string PROP_WINDOW_ID; + [CCode (cname="PA_PROP_WINDOW_ICON_NAME")] + public static const string PROP_WINDOW_ICON_NAME; + [CCode (cname="PA_PROP_WINDOW_X11_DISPLAY")] + public static const string PROP_WINDOW_X11_DISPLAY; + [CCode (cname="PA_PROP_WINDOW_X11_SCREEN")] + public static const string PROP_WINDOW_X11_SCREEN; + [CCode (cname="PA_PROP_WINDOW_X11_MONITOR")] + public static const string PROP_WINDOW_X11_MONITOR; + [CCode (cname="PA_PROP_WINDOW_X11_XID")] + public static const string PROP_WINDOW_X11_XID; + [CCode (cname="PA_PROP_APPLICATION_NAME")] + public static const string PROP_APPLICATION_NAME; + [CCode (cname="PA_PROP_APPLICATION_ID")] + public static const string PROP_APPLICATION_ID; + [CCode (cname="PA_PROP_APPLICATION_VERSION")] + public static const string PROP_APPLICATION_VERSION; + [CCode (cname="PA_PROP_APPLICATION_ICON_NAME")] + public static const string PROP_APPLICATION_ICON_NAME; + [CCode (cname="PA_PROP_APPLICATION_LANGUAGE")] + public static const string PROP_APPLICATION_LANGUAGE; + [CCode (cname="PA_PROP_APPLICATION_PROCESS_ID")] + public static const string PROP_APPLICATION_PROCESS_ID; + [CCode (cname="PA_PROP_APPLICATION_PROCESS_BINARY")] + public static const string PROP_APPLICATION_PROCESS_BINARY; + [CCode (cname="PA_PROP_APPLICATION_PROCESS_USER")] + public static const string PROP_APPLICATION_PROCESS_USER; + [CCode (cname="PA_PROP_APPLICATION_PROCESS_HOST")] + public static const string PROP_APPLICATION_PROCESS_HOST; + [CCode (cname="PA_PROP_APPLICATION_PROCESS_MACHINE_ID")] + public static const string PROP_APPLICATION_PROCESS_MACHINE_ID; + [CCode (cname="PA_PROP_APPLICATION_PROCESS_SESSION_ID")] + public static const string PROP_APPLICATION_PROCESS_SESSION_ID; + [CCode (cname="PA_PROP_DEVICE_STRING")] + public static const string PROP_DEVICE_STRING; + [CCode (cname="PA_PROP_DEVICE_API")] + public static const string PROP_DEVICE_API; + [CCode (cname="PA_PROP_DEVICE_DESCRIPTION")] + public static const string PROP_DEVICE_DESCRIPTION; + [CCode (cname="PA_PROP_DEVICE_BUS_PATH")] + public static const string PROP_DEVICE_BUS_PATH; + [CCode (cname="PA_PROP_DEVICE_SERIAL")] + public static const string PROP_DEVICE_SERIAL; + [CCode (cname="PA_PROP_DEVICE_VENDOR_ID")] + public static const string PROP_DEVICE_VENDOR_ID; + [CCode (cname="PA_PROP_DEVICE_VENDOR_NAME")] + public static const string PROP_DEVICE_VENDOR_NAME; + [CCode (cname="PA_PROP_DEVICE_PRODUCT_ID")] + public static const string PROP_DEVICE_PRODUCT_ID; + [CCode (cname="PA_PROP_DEVICE_PRODUCT_NAME")] + public static const string PROP_DEVICE_PRODUCT_NAME; + [CCode (cname="PA_PROP_DEVICE_CLASS")] + public static const string PROP_DEVICE_CLASS; + [CCode (cname="PA_PROP_DEVICE_FORM_FACTOR")] + public static const string PROP_DEVICE_FORM_FACTOR; + [CCode (cname="PA_PROP_DEVICE_BUS")] + public static const string PROP_DEVICE_BUS; + [CCode (cname="PA_PROP_DEVICE_ICON_NAME")] + public static const string PROP_DEVICE_ICON_NAME; + [CCode (cname="PA_PROP_DEVICE_ACCESS_MODE")] + public static const string PROP_DEVICE_ACCESS_MODE; + [CCode (cname="PA_PROP_DEVICE_MASTER_DEVICE")] + public static const string PROP_DEVICE_MASTER_DEVICE; + [CCode (cname="PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE")] + public static const string PROP_DEVICE_BUFFERING_BUFFER_SIZE; + [CCode (cname="PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE")] + public static const string PROP_DEVICE_BUFFERING_FRAGMENT_SIZE; + [CCode (cname="PA_PROP_DEVICE_PROFILE_NAME")] + public static const string PROP_DEVICE_PROFILE_NAME; + [CCode (cname="PA_PROP_DEVICE_INTENDED_ROLES")] + public static const string PROP_DEVICE_INTENDED_ROLES; + [CCode (cname="PA_PROP_DEVICE_PROFILE_DESCRIPTION")] + public static const string PROP_DEVICE_PROFILE_DESCRIPTION; + [CCode (cname="PA_PROP_MODULE_AUTHOR")] + public static const string PROP_MODULE_AUTHOR; + [CCode (cname="PA_PROP_MODULE_DESCRIPTION")] + public static const string PROP_MODULE_DESCRIPTION; + [CCode (cname="PA_PROP_MODULE_USAGE")] + public static const string PROP_MODULE_USAGE; + [CCode (cname="PA_PROP_MODULE_VERSION")] + public static const string PROP_MODULE_VERSION; + + [CCode (cname="pa_proplist_new")] + public Proplist(); + + public int sets(string key, string value); + public int setp(string pair); + + [PrintfFormat] + public int setf(string key, string format, ...); + + public int set(string key, void* data, size_t size); + + public unowned string? gets(string key); + + public int get(string key, out void* data, out size_t size); + + public void update(UpdateMode mode, Proplist other); + + public void unset(string key); + + [CCode (array_length = false)] + public void unset_many(string[] key); + + public unowned string? iterate(ref void* state); + + public string to_string(); + + public string to_string_sep(string sep); + + public static Proplist? from_string(string s); + + public int contains(string key); + + public void clear(); + + public Proplist copy(); + + public uint size(); + + public bool is_empty(); + } + + [CCode (cname="pa_update_mode_t", cprefix="PA_UPDATE_")] + public enum UpdateMode { + SET, + MERGE, + REPLACE + } + + [CCode (cname="PA_OK")] + public const int OK; + + [CCode (cname="int", cprefix="PA_ERR_")] + public enum Error { + ACCESS, + COMMAND, + INVALID, + EXIST, + NOENTITY, + CONNECTIONREFUSED, + PROTOCOL, + TIMEOUT, + AUTHKEY, + INTERNAL, + CONNECTIONTERMINATED, + KILLED, + INVALIDSERVER, + MODINITFAILED, + BADSTATE, + NODATA, + VERSION, + TOOLARGE, + NOTSUPPORTED, + UNKNOWN, + NOEXTENSION, + OBSOLETE, + NOTIMPLEMENTED, + FORKED, + IO, + MAX + } + + [CCode (cname="pa_strerror")] + public unowned string? strerror(Error e); + + public delegate void VoidFunc(); + + [CCode (cname="pa_spawn_api")] + public struct SpawnApi { + VoidFunc? prefork; + VoidFunc? postfork; + VoidFunc? atfork; + } + + [CCode (cname="pa_io_event_flags_t", cprefix="PA_IO_EVENT_")] + public enum IoEventFlags { + NULL, + INPUT, + OUTPUT, + HANGUP, + ERROR + } + + [CCode (cname="pa_io_event")] + public struct IoEvent { + } + + [CCode (cname="pa_time_event")] + public struct TimeEvent { + } + + [CCode (cname="pa_defer_event")] + public struct DeferEvent { + } + + [CCode (cname="pa_signal_event", cprefix="pa_signal_", free_function="pa_signal_free")] + public struct SignalEvent { + + [CCode (cname="pa_signal_new")] + public SignalEvent(int sig, MainLoopApi.SignalEventCb cb); + + public void set_destroy(MainLoopApi.SignalEventDestroyCb cb); + } + + [Compact] + [CCode (cname="pa_mainloop_api")] + public class MainLoopApi { + public void* userdata; + + /* Callbacks for the consumer to implement*/ + public delegate void IoEventCb(IoEvent e, int fd, IoEventFlags flags); + public delegate void IoEventDestroyCb(IoEvent e); + + public delegate void TimeEventCb(TimeEvent e, ref timeval t); + public delegate void TimeEventDestroyCb(TimeEvent e); + + public delegate void DeferEventCb(DeferEvent e); + public delegate void DeferEventDestroyCb(DeferEvent e); + + public delegate void SignalEventCb(SignalEvent e); + public delegate void SignalEventDestroyCb(SignalEvent e); + + /* Callbacks for the provider to implement */ + public delegate IoEvent IoNewCb(int fd, IoEventFlags flags, IoEventCb cb); + public delegate void IoEnableCb(IoEvent e, IoEventFlags flags); + public delegate void IoFreeCb(IoEvent e); + public delegate void IoSetDestroyCb(IoEvent e, IoEventDestroyCb? cb); + + public delegate TimeEvent TimeNewCb(ref timeval? t, TimeEventCb cb); + public delegate void TimeRestartCb(TimeEvent e, ref timeval? t); + public delegate void TimeFreeCb(TimeEvent e); + public delegate void TimeSetDestroyCb(TimeEvent e, TimeEventDestroyCb? cb); + + public delegate DeferEvent DeferNewCb(DeferEventCb cb); + public delegate void DeferEnableCb(DeferEvent e, bool b); + public delegate void DeferFreeCb(DeferEvent e); + public delegate void DeferSetDestroyCb(DeferEvent e, DeferEventDestroyCb? cb); + + public delegate void QuitCb(int retval); + + public delegate void OnceCb(); + + public IoNewCb io_new; + public IoEnableCb io_enable; + public IoFreeCb io_free; + public IoSetDestroyCb io_set_destroy; + + public TimeNewCb time_new; + public TimeRestartCb time_restart; + public TimeFreeCb time_free; + public TimeSetDestroyCb time_set_destroy; + + public DeferNewCb defer_new; + public DeferEnableCb defer_enable; + public DeferFreeCb defer_free; + public DeferSetDestroyCb defer_set_destroy; + + public QuitCb quit; + + [CCode (cname="pa_mainloop_api_once")] + public void once(OnceCb cb); + } + + [CCode (cname="pa_signal_init")] + public void signal_init(MainLoopApi api); + + [CCode (cname="pa_signal_done")] + public void signal_done(); + + [CCode (cname="pa_poll_func")] + public delegate int PollFunc(pollfd[] ufds); + + [Compact] + [CCode (cname="pa_mainloop", cprefix="pa_mainloop_", free_function="pa_mainloop_free")] + public class MainLoop { + + [CCode (cname="pa_mainloop_new")] + public MainLoop(); + + public int prepare(int timeout = -1); + public int poll(); + public int dispatch(); + public int get_retval(); + public int iterate(bool block = true, out int retval = null); + public int run(out int retval = null); + public unowned MainLoopApi get_api(); + public void quit(int r); + public void wakeup(); + public void set_poll_func(PollFunc poll_func); + } + + [Compact] + [CCode (cname="pa_threaded_mainloop", cprefix="pa_threaded_mainloop_", free_function="pa_threaded_mainloop_free")] + public class ThreadedMainLoop { + + [CCode (cname="pa_threaded_mainloop_new")] + public ThreadedMainLoop(); + + public int start(); + public void stop(); + public void lock(); + public void unlock(); + public void wait(); + public void signal(bool WaitForAccept = false); + public void accept(); + public int get_retval(); + public unowned MainLoopApi get_api(); + public bool in_thread(); + } + + [Compact] + [CCode (cname="pa_glib_mainloop", cprefix="pa_glib_mainloop_", free_function="pa_glib_mainloop_free")] + public class GLibMainLoop { + + [CCode (cname="pa_glib_mainloop_new")] + public GLibMainLoop(); + + public unowned MainLoopApi get_api(); + } + + [Compact] + [CCode (cname="pa_operation", cprefix="pa_operation_", unref_function="pa_operation_unref", ref_function="pa_operation_ref")] + public class Operation { + + [CCode (cname="pa_operation_state_t", cprefix="PA_OPERATION_")] + public enum State { + RUNNING, + DONE, + CANCELED + } + + public void cancel(); + public State get_state(); + } + + [Compact] + [CCode (cname="pa_context", cprefix="pa_context_", unref_function="pa_context_unref", ref_function="pa_context_ref")] + public class Context { + + [CCode (cname="pa_context_flags_t", cprefix="PA_CONTEXT_")] + public enum Flags { + NOAUTOSPAWN, + NOFAIL + } + + [CCode (cname="pa_context_state_t", cprefix="PA_CONTEXT_")] + public enum State { + UNCONNECTED, + CONNECTING, + AUTHORIZING, + SETTING_NAME, + READ, + FAILED, + TERMINATED; + + bool IS_GOOD(); + } + + [CCode (cname="pa_subscription_mask_t", cprefix="PA_SUBSCRIPTION_MASK_")] + public enum SubscriptionMask { + NULL, + SINK, + SOURCE, + SINK_INPUT, + SOURCE_OUTPUT, + MODULE, + CLIENT, + SAMPLE_CACHE, + SERVER, + CARD, + ALL; + + [CCode (cname="pa_subscription_match_flags")] + bool match_flags(SubscriptionEventType t); + } + + [CCode (cname="pa_subscription_event_type_t", cprefix="PA_SUBSCRIPTION_EVENT_")] + public enum SubscriptionEventType { + SINK, + SOURCE, + SINK_INPUT, + SOURCE_OUTPUT, + MODULE, + CLIENT, + SAMPLE_CACHE, + SERVER, + CARD, + FACILITY_MASK, + NEW, + CHANGE, + REMOVE, + TYPE_MASK + } + + public delegate void NotifyCb(); + public delegate void SuccessCb(int success); + public delegate void EventCb(string name, Proplist? proplist); + public delegate void SubscribeCb(SubscriptionEventType t, uint32 idx); + public delegate void SinkInfoCb(SinkInfo? i, int eol); + public delegate void SourceInfoCb(SourceInfo? i, int eol); + public delegate void CardInfoCb(CardInfo? i, int eol); + public delegate void SinkInputInfoCb(SinkInputInfo? i, int eol); + public delegate void SourceOutputInfoCb(SourceOutputInfo? i, int eol); + public delegate void ServerInfoCb(ServerInfo? i); + public delegate void StatInfoCb(ServerInfo? i); + public delegate void ModuleInfoCb(ModuleInfo? i, int eol); + public delegate void ClientInfoCb(ClientInfo? i, int eol); + public delegate void SampleInfoCb(SampleInfo? i, int eol); + public delegate void IndexCb(uint32 idx); + + [CCode (cname="pa_context_new_with_proplist")] + public Context(MainLoopApi api, string? name, Proplist? proplist = null); + + public void set_state_callback(NotifyCb? cb = null); + public void set_event_callback(EventCb? cb = null); + public void set_subscribe_callback(SubscribeCb? cb = null); + + public Error errno(); + + public int is_pending(); + public State get_state(); + public int is_local(); + public unowned string? get_server(); + public uint32 get_protocol_version(); + public uint32 get_server_protocol_version(); + public uint32 get_index(); + + public int connect(string? server = null, Flags flags = 0, SpawnApi? api = null); + public void disconnect(); + + public Operation? drain(NotifyCb? cb = null); + public Operation? exit_daemon(SuccessCb? cb = null); + public Operation? set_default_sink(string name, SuccessCb? cb = null); + public Operation? set_default_source(string name, SuccessCb? cb = null); + public Operation? set_name(string name, SuccessCb? cb = null); + + [CCode (array_length = false)] + public Operation? proplist_remove(string[] keys, SuccessCb? cb = null); + public Operation? proplist_update(UpdateMode mode, Proplist pl, SuccessCb? cb = null); + + public Operation? subscribe(SubscriptionMask mask, SuccessCb? cb = null); + + public Operation? get_sink_info_by_name(string name, SinkInfoCb cb); + public Operation? get_sink_info_by_index(uint32 idx, SinkInfoCb cb); + public Operation? get_sink_info_list(SinkInfoCb cb); + + public Operation? set_sink_volume_by_name(string name, CVolume volume, SuccessCb? cb = null); + public Operation? set_sink_volume_by_index(uint32 idx, CVolume volume, SuccessCb? cb = null); + public Operation? set_sink_mute_by_name(string name, bool mute, SuccessCb? cb = null); + public Operation? set_sink_mute_by_index(uint32 idx, bool mute, SuccessCb? cb = null); + + public Operation? suspend_sink_by_name(string name, bool suspend, SuccessCb? cb = null); + public Operation? suspend_sink_by_index(uint32 idx, bool suspend, SuccessCb? cb = null); + + public Operation? set_sink_port_by_name(string name, string port, SuccessCb? cb = null); + public Operation? set_sink_port_by_index(string idx, string port, SuccessCb? cb = null); + + public Operation? get_source_info_by_name(string name, SourceInfoCb cb); + public Operation? get_source_info_by_index(uint32 idx, SourceInfoCb cb); + public Operation? get_source_info_list(SourceInfoCb cb); + + public Operation? set_source_volume_by_name(string name, CVolume volume, SuccessCb? cb = null); + public Operation? set_source_volume_by_index(uint32 idx, CVolume volume, SuccessCb? cb = null); + public Operation? set_source_mute_by_name(string name, bool mute, SuccessCb? cb = null); + public Operation? set_source_mute_by_index(uint32 idx, bool mute, SuccessCb? cb = null); + + public Operation? suspend_source_by_name(string name, bool suspend, SuccessCb? cb = null); + public Operation? suspend_source_by_index(uint32 idx, bool suspend, SuccessCb? cb = null); + + public Operation? set_source_port_by_name(string name, string port, SuccessCb? cb = null); + public Operation? set_source_port_by_index(string idx, string port, SuccessCb? cb = null); + + public Operation? get_server_info(ServerInfoCb cb); + + public Operation? get_module_info(uint32 idx, ModuleInfoCb cb); + public Operation? get_module_info_list(ModuleInfoCb cb); + + public Operation? load_module(string name, string? argument, IndexCb? cb = null); + public Operation? unload_module(uint32 idx, SuccessCb? cb = null); + + public Operation? get_client_info(uint32 idx, ClientInfoCb cb); + public Operation? get_client_info_list(ClientInfoCb cb); + + public Operation? kill_client(uint32 idx, SuccessCb? cb = null); + + public Operation? get_card_info_by_name(string name, CardInfoCb cb); + public Operation? get_card_info_by_index(uint32 idx, CardInfoCb cb); + public Operation? get_card_info_list(CardInfoCb cb); + + public Operation? set_card_profile_by_index(uint32 idx, string profile, SuccessCb? cb = null); + public Operation? set_card_profile_by_name(string name, string profile, SuccessCb? cb = null); + + public Operation? get_sink_input_info(uint32 idx, SinkInputInfoCb cb); + public Operation? get_sink_input_info_list(SinkInputInfoCb cb); + + public Operation? move_sink_input_by_index(uint32 idx, uint32 sink_idx, SuccessCb? cb = null); + public Operation? move_sink_input_by_name(uint32 idx, string sink_name, SuccessCb? cb = null); + + public Operation? set_sink_input_volume(uint32 idx, CVolume volume, SuccessCb? cb = null); + public Operation? set_sink_input_mute(uint32 idx, bool mute, SuccessCb? cb = null); + + public Operation? kill_sink_input(uint32 idx, SuccessCb? cb = null); + + public Operation? get_source_output_info(uint32 idx, SourceOutputInfoCb cb); + public Operation? get_source_output_info_list(SourceOutputInfoCb cb); + + public Operation? move_source_output_by_index(uint32 idx, uint32 source_idx, SuccessCb? cb = null); + public Operation? move_source_output_by_name(uint32 idx, string source_name, SuccessCb? cb = null); + + public Operation? kill_source_output(uint32 idx, SuccessCb? cb = null); + + public Operation? stat(StatInfoCb cb); + + public Operation? get_sample_info_by_name(string name, SampleInfoCb cb); + public Operation? get_sample_info_by_index(uint32 idx, SampleInfoCb cb); + public Operation? get_sample_info_list(SampleInfoCb cb); + + public Operation? remove_sample(string name, SuccessCb? cb = null); + + public Operation? play_sample(string name, string? device = null, Volume volume = Volume.INVALID, SuccessCb? cb = null); + public Operation? play_sample_with_proplist(string name, string? device = null, Volume volume = Volume.INVALID, Proplist? p = null, IndexCb? cb = null); + } + + [Compact] + [CCode (cname="pa_stream", cprefix="pa_stream_", unref_function="pa_stream_unref", ref_function="pa_stream_ref")] + public class Stream { + + [CCode (cname="pa_stream_flags_t", cprefix="PA_STREAM_")] + public enum Flags { + START_CORKED, + INTERPOLATE_TIMING, + NOT_MONOTONIC, + AUTO_TIMING_UPDATE, + NO_REMAP_CHANNELS, + NO_REMIX_CHANNELS, + FIX_FORMAT, + FIX_RATE, + FIX_CHANNELS, + DONT_MOVE, + VARIABLE_RATE, + PEAK_DETECT, + START_MUTED, + ADJUST_LATENCY, + EARLY_REQUESTS, + DONT_INHIBIT_AUTO_SUSPEND, + START_UNMUTED, + FAIL_ON_SUSPEND + } + + [CCode (cname="pa_stream_state_t", cprefix="PA_STREAM_")] + public enum State { + UNCONNECTED, + CREATING, + READY, + FAILED, + TERMINATED; + + bool IS_GOOD(); + } + + [CCode (cname="pa_stream_direction_t", cprefix="PA_STREAM_")] + public enum Direction { + NODIRECTION, + PLAYBACK, + RECORD, + UPLOAD + } + + [CCode (cname="pa_seek_mode_t", cprefix="PA_SEEK_")] + public enum SeekMode { + RELATIVE, + ABSOLUTE, + RELATIVE_ON_READ, + RELATIVE_END + } + + [CCode (cname="pa_buffer_attr")] + public struct BufferAttr { + uint32 maxlength; + uint32 tlength; + uint32 prebuf; + uint32 minreq; + uint32 fragsize; + } + + [CCode (cname="pa_timing_info")] + public struct TimingInfo { + timeval timestamp; + int synchronized_clocks; + usec sink_usec; + usec source_usec; + usec transport_usec; + int playing; + int write_index_corrupt; + int64 write_index; + int read_index_corrupt; + int64 read_index; + usec configured_sink_usec; + usec configured_source_usec; + int64 since_underrun; + } + + [CCode (cname="PA_STREAM_EVENT_REQUEST_CORK")] + public const string EVENT_REQUEST_CORK; + + [CCode (cname="PA_STREAM_EVENT_REQUEST_UNCORK")] + public const string EVENT_REQUEST_UNCORK; + + public delegate void SuccessCb(int success); + public delegate void RequestCb(size_t nbytes); + public delegate void NotifyCb(); + public delegate void EventCb(string name, Proplist proplist); + + [CCode (cname="pa_stream_new_with_proplist")] + public Stream(Context c, string name, SampleSpec ss, ChannelMap map = null, Proplist proplist = null); + + public State get_state(); + public Context get_context(); + public uint32 get_index(); + public uint32 get_device_index(); + public unowned string? get_device_name(); + public int is_suspended(); + public int is_corked(); + + public int connect_playback(string dev, BufferAttr a = null, Flags flags = 0, Volume volume = null, Stream sync_stream = null); + public int connect_record(string dev, BufferAttr a = null, Flags flags = 0); + public int connect_upload(size_t length); + public int disconnect(); + public int finish_upload(); + + public int begin_write(out void* data, out size_t nbytes); + public int cancel_write(); + public int write(void *data, size_t bytes, FreeCb free_cb = null, int64 offset = 0, SeekMode mode = SeekMode.RELATIVE); + public int peek(out void *data, out size_t nbytes); + public int drop(); + public size_t writable_size(); + public size_t readable_size(); + + public void set_state_callback(NotifyCb cb = null); + public void set_write_callback(RequestCb cb = null); + public void set_read_callback(RequestCb cb = null); + public void set_overflow_callback(NotifyCb cb = null); + public void set_underflow_callback(NotifyCb cb = null); + public void set_started_callback(NotifyCb cb = null); + public void set_latency_update_callback(NotifyCb cb = null); + public void set_moved_callback(NotifyCb cb = null); + public void set_suspended_callback(NotifyCb cb = null); + public void set_event_callback(EventCb cb = null); + public void set_buffer_attr_callback(NotifyCb cb = null); + + public Operation? drain(SuccessCb cb = null); + public Operation? update_timing_info(SuccessCb cb = null); + + public Operation? cork(bool b, SuccessCb cb = null); + public Operation? flush(SuccessCb cb = null); + public Operation? prebuf(SuccessCb cb = null); + public Operation? trigger(SuccessCb cb = null); + + public Operation? set_name(string name, SuccessCb cb = null); + public Operation? set_buffer_attr(BufferAttr attr, SuccessCb cb = null); + public Operation? update_sample_rate(uint32 rate, SuccessCb cb = null); + + [CCode (array_length = false)] + public Operation? proplist_remove(string[] keys, SuccessCb cb = null); + public Operation? proplist_update(UpdateMode mode, Proplist pl, SuccessCb cb = null); + + public unowned TimingInfo? get_timing_info(); + public int get_time(out usec u); + public int get_latency(out usec u, out bool negative = null); + + public unowned SampleSpec? get_sample_spec(); + public unowned ChannelMap? get_channel_map(); + public unowned BufferAttr? get_buffer_attr(); + + public int set_monitor_stream(uint32 sink_input); + public uint32 get_monitor_stream(); + } + + [CCode (cname="pa_sink_port_info")] + public struct SinkPortInfo { + string name; + string description; + uint32 priority; + } + + [CCode (cname="pa_sink_info")] + public struct SinkInfo { + string name; + uint32 index; + string description; + SampleSpec sample_spec; + ChannelMap channel_map; + uint32 owner_module; + CVolume volume; + int mute; + uint32 monitor_source; + string monitor_source_name; + usec latency; + string driver; + SinkFlags flags; + Proplist proplist; + usec configured_latency; + Volume base_volume; + SinkState state; + uint32 n_volume_steps; + uint32 card; + uint32 n_ports; + SinkPortInfo*[] ports; + SinkPortInfo* active_port; + } + + [CCode (cname="pa_source_port_info")] + public struct SourcePortInfo { + string name; + string description; + uint32 priority; + } + + [CCode (cname="pa_source_info")] + public struct SourceInfo { + string name; + uint32 index; + string description; + SampleSpec sample_spec; + ChannelMap channel_map; + uint32 owner_module; + CVolume volume; + int mute; + uint32 monitor_of_sink; + string monitor_of_sink_name; + usec latency; + string driver; + SourceFlags flags; + Proplist proplist; + usec configured_latency; + Volume base_volume; + SourceState state; + uint32 n_volume_steps; + uint32 card; + uint32 n_ports; + SourcePortInfo*[] ports; + SourcePortInfo* active_port; + } + + [CCode (cname="pa_server_info")] + public struct ServerInfo { + string user_name; + string host_name; + string server_version; + string server_name; + SampleSpec sample_spec; + string default_sink_name; + string default_source_name; + ChannelMap channel_map; + } + + [CCode (cname="pa_module_info")] + public struct ModuleInfo { + uint32 index; + string name; + string argument; + uint32 n_used; + Proplist proplist; + } + + [CCode (cname="pa_client_info")] + public struct ClientInfo { + uint32 index; + string name; + uint32 owner_module; + string driver; + Proplist proplist; + } + + [CCode (cname="pa_card_profile_info")] + public struct CardProfileInfo { + string name; + string description; + uint32 n_sinks; + uint32 n_sources; + uint32 priority; + } + + [CCode (cname="pa_card_info")] + public struct CardInfo { + uint32 index; + string name; + uint32 owner_module; + string driver; + uint32 n_profiles; + CardProfileInfo profiles[]; + CardProfileInfo *active_profile; + Proplist proplist; + } + + [CCode (cname="pa_sink_input_info")] + public struct SinkInputInfo { + uint32 index; + string name; + uint32 owner_module; + uint32 client; + uint32 sink; + SampleSpec sample_spec; + ChannelMap channel_map; + CVolume volume; + uint32 buffer_usec; + uint32 sink_usec; + string resample_method; + string driver; + int mute; + Proplist proplist; + } + + [CCode (cname="pa_source_output_info")] + public struct SourceOutputInfo { + uint32 index; + string name; + uint32 owner_module; + uint32 client; + uint32 source; + SampleSpec sample_spec; + ChannelMap channel_map; + uint32 buffer_usec; + uint32 sink_usec; + string resample_method; + string driver; + Proplist proplist; + } + + [CCode (cname="pa_stat_info")] + public struct StatInfo { + uint32 memblock_total; + uint32 memblock_total_size; + uint32 memblock_allocated; + uint32 memblock_allocated_size; + uint32 scache_size; + } + + [CCode (cname="pa_sample_info")] + public struct SampleInfo { + uint32 index; + string name; + CVolume volume; + SampleSpec sample_spec; + ChannelMap channel_map; + usec duration; + uint32 bytes; + bool lazy; + string filename; + Proplist proplist; + } + + [CCode (cname="pa_sink_flags_t", cprefix="PA_SINK_")] + public enum SinkFlags { + HW_VOLUME_CTRL, + LATENCY, + HARDWARE, + NETWORK, + HW_MUTE_CTRL, + DECIBEL_VOLUME, + FLAT_VOLUME, + DYNAMIC_LATENCY + } + + [CCode (cname="pa_source_flags_t", cprefix="PA_SOURCE_")] + public enum SourceFlags { + HW_VOLUME_CTRL, + LATENCY, + HARDWARE, + NETWORK, + HW_MUTE_CTRL, + DECIBEL_VOLUME, + DYNAMIC_LATENCY + } + + [CCode (cname="pa_sink_state_t", cprefix="PA_SINK_")] + public enum SinkState { + INVALID_STATE, + RUNNING, + IDLE, + SUSPENDED; + + [CCode (cname="PA_SINK_IS_OPENED")] + public bool IS_OPENED(); + } + + [CCode (cname="pa_source_state_t", cprefix="PA_SOURCE_")] + public enum SourceState { + INVALID_STATE, + RUNNING, + IDLE, + SUSPENDED; + + [CCode (cname="PA_SOURCE_IS_OPENED")] + public bool IS_OPENED(); + } +} diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index ec1ec5ce..6e7926f8 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -83,7 +83,7 @@ static const pa_daemon_conf default_conf = { .config_file = NULL, .use_pid_file = TRUE, .system_instance = FALSE, - .no_cpu_limit = FALSE, + .no_cpu_limit = TRUE, .disable_shm = FALSE, .lock_memory = FALSE, .default_n_fragments = 4, diff --git a/src/daemon/daemon.conf.in b/src/daemon/daemon.conf.in index d8b58d8a..db2059e1 100644 --- a/src/daemon/daemon.conf.in +++ b/src/daemon/daemon.conf.in @@ -28,7 +28,7 @@ ; enable-shm = yes ; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB ; lock-memory = no -; cpu-limit = yes +; cpu-limit = no ; high-priority = yes ; nice-level = -11 diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c index 61c92cd0..685169b9 100644 --- a/src/modules/alsa/alsa-mixer.c +++ b/src/modules/alsa/alsa-mixer.c @@ -2889,7 +2889,7 @@ static void profile_set_add_auto_pair( else name = pa_sprintf_malloc("input:%s", n->name); - if ((p = pa_hashmap_get(ps->profiles, name))) { + if (pa_hashmap_get(ps->profiles, name)) { pa_xfree(name); return; } @@ -3145,7 +3145,13 @@ fail: return NULL; } -void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss) { +void pa_alsa_profile_set_probe( + pa_alsa_profile_set *ps, + const char *dev_id, + const pa_sample_spec *ss, + unsigned default_n_fragments, + unsigned default_fragment_size_msec) { + void *state; pa_alsa_profile *p, *last = NULL; pa_alsa_mapping *m; @@ -3160,6 +3166,7 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons PA_HASHMAP_FOREACH(p, ps->profiles, state) { pa_sample_spec try_ss; pa_channel_map try_map; + snd_pcm_uframes_t try_period_size, try_buffer_size; uint32_t idx; /* Is this already marked that it is supported? (i.e. from the config file) */ @@ -3213,13 +3220,18 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons try_ss = *ss; try_ss.channels = try_map.channels; + try_period_size = + pa_usec_to_bytes(default_fragment_size_msec * PA_USEC_PER_MSEC, &try_ss) / + pa_frame_size(&try_ss); + try_buffer_size = default_n_fragments * try_period_size; + if (!(m ->output_pcm = pa_alsa_open_by_template( m->device_strings, dev_id, NULL, &try_ss, &try_map, SND_PCM_STREAM_PLAYBACK, - NULL, NULL, 0, NULL, NULL, + &try_period_size, &try_buffer_size, 0, NULL, NULL, TRUE))) { p->supported = FALSE; break; @@ -3237,13 +3249,18 @@ void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, cons try_ss = *ss; try_ss.channels = try_map.channels; + try_period_size = + pa_usec_to_bytes(default_fragment_size_msec*PA_USEC_PER_MSEC, &try_ss) / + pa_frame_size(&try_ss); + try_buffer_size = default_n_fragments * try_period_size; + if (!(m ->input_pcm = pa_alsa_open_by_template( m->device_strings, dev_id, NULL, &try_ss, &try_map, SND_PCM_STREAM_CAPTURE, - NULL, NULL, 0, NULL, NULL, + &try_period_size, &try_buffer_size, 0, NULL, NULL, TRUE))) { p->supported = FALSE; break; diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h index 76788183..a0d4fcbe 100644 --- a/src/modules/alsa/alsa-mixer.h +++ b/src/modules/alsa/alsa-mixer.h @@ -269,7 +269,7 @@ void pa_alsa_mapping_dump(pa_alsa_mapping *m); void pa_alsa_profile_dump(pa_alsa_profile *p); pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, const pa_channel_map *bonus); -void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss); +void pa_alsa_profile_set_probe(pa_alsa_profile_set *ps, const char *dev_id, const pa_sample_spec *ss, unsigned default_n_fragments, unsigned default_fragment_size_msec); void pa_alsa_profile_set_free(pa_alsa_profile_set *s); void pa_alsa_profile_set_dump(pa_alsa_profile_set *s); diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index 195bdf6e..76cbe46f 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -116,7 +116,6 @@ struct userdata { pa_usec_t watermark_dec_not_before; - unsigned nfragments; pa_memchunk memchunk; char *device_name; /* name of the PCM device */ @@ -656,6 +655,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle snd_pcm_sframes_t n; size_t n_bytes; int r; + pa_bool_t after_avail = TRUE; if (PA_UNLIKELY((n = pa_alsa_safe_avail(u->pcm_handle, u->hwbuf_size, &u->sink->sample_spec)) < 0)) { @@ -710,7 +710,6 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle for (;;) { snd_pcm_sframes_t frames; void *p; - pa_bool_t after_avail = TRUE; /* pa_log_debug("%lu frames to write", (unsigned long) frames); */ @@ -943,8 +942,7 @@ static int unsuspend(struct userdata *u) { pa_sample_spec ss; int err; pa_bool_t b, d; - unsigned nfrags; - snd_pcm_uframes_t period_size; + snd_pcm_uframes_t period_size, buffer_size; pa_assert(u); pa_assert(!u->pcm_handle); @@ -952,7 +950,7 @@ static int unsuspend(struct userdata *u) { pa_log_info("Trying resume..."); if ((err = snd_pcm_open(&u->pcm_handle, u->device_name, SND_PCM_STREAM_PLAYBACK, - /*SND_PCM_NONBLOCK|*/ + SND_PCM_NONBLOCK| SND_PCM_NO_AUTO_RESAMPLE| SND_PCM_NO_AUTO_CHANNELS| SND_PCM_NO_AUTO_FORMAT)) < 0) { @@ -961,12 +959,12 @@ static int unsuspend(struct userdata *u) { } ss = u->sink->sample_spec; - nfrags = u->nfragments; period_size = u->fragment_size / u->frame_size; + buffer_size = u->hwbuf_size / u->frame_size; b = u->use_mmap; d = u->use_tsched; - if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &nfrags, &period_size, u->hwbuf_size / u->frame_size, &b, &d, TRUE)) < 0) { + if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &period_size, &buffer_size, 0, &b, &d, TRUE)) < 0) { pa_log("Failed to set hardware parameters: %s", pa_alsa_strerror(err)); goto fail; } @@ -981,10 +979,11 @@ static int unsuspend(struct userdata *u) { goto fail; } - if (nfrags != u->nfragments || period_size*u->frame_size != u->fragment_size) { - pa_log_warn("Resume failed, couldn't restore original fragment settings. (Old: %lu*%lu, New %lu*%lu)", - (unsigned long) u->nfragments, (unsigned long) u->fragment_size, - (unsigned long) nfrags, period_size * u->frame_size); + if (period_size*u->frame_size != u->fragment_size || + buffer_size*u->frame_size != u->hwbuf_size) { + pa_log_warn("Resume failed, couldn't restore original fragment settings. (Old: %lu/%lu, New %lu/%lu)", + (unsigned long) u->hwbuf_size, (unsigned long) u->fragment_size, + (unsigned long) (buffer_size*u->fragment_size), (unsigned long) (period_size*u->frame_size)); goto fail; } @@ -1638,8 +1637,8 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca const char *dev_id = NULL; pa_sample_spec ss, requested_ss; pa_channel_map map; - uint32_t nfrags, hwbuf_size, frag_size, tsched_size, tsched_watermark; - snd_pcm_uframes_t period_frames, tsched_frames; + uint32_t nfrags, frag_size, buffer_size, tsched_size, tsched_watermark; + snd_pcm_uframes_t period_frames, buffer_frames, tsched_frames; size_t frame_size; pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, ignore_dB = FALSE; pa_sink_new_data data; @@ -1673,8 +1672,10 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca goto fail; } - hwbuf_size = frag_size * nfrags; + buffer_size = nfrags * frag_size; + period_frames = frag_size/frame_size; + buffer_frames = buffer_size/frame_size; tsched_frames = tsched_size/frame_size; if (pa_modargs_get_value_boolean(ma, "mmap", &use_mmap) < 0) { @@ -1741,7 +1742,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca &u->device_name, &ss, &map, SND_PCM_STREAM_PLAYBACK, - &nfrags, &period_frames, tsched_frames, + &period_frames, &buffer_frames, tsched_frames, &b, &d, mapping))) goto fail; @@ -1756,7 +1757,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca &u->device_name, &ss, &map, SND_PCM_STREAM_PLAYBACK, - &nfrags, &period_frames, tsched_frames, + &period_frames, &buffer_frames, tsched_frames, &b, &d, profile_set, &mapping))) goto fail; @@ -1768,7 +1769,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca &u->device_name, &ss, &map, SND_PCM_STREAM_PLAYBACK, - &nfrags, &period_frames, tsched_frames, + &period_frames, &buffer_frames, tsched_frames, &b, &d, FALSE))) goto fail; } @@ -1794,11 +1795,6 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca u->use_tsched = use_tsched = FALSE; } - if (use_tsched && !pa_alsa_pcm_is_hw(u->pcm_handle)) { - pa_log_info("Device is not a hardware device, disabling timer-based scheduling."); - u->use_tsched = use_tsched = FALSE; - } - if (u->use_mmap) pa_log_info("Successfully enabled mmap() mode."); @@ -1820,7 +1816,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name); - pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (period_frames * frame_size * nfrags)); + pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (buffer_frames * frame_size)); pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (period_frames * frame_size)); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_ACCESS_MODE, u->use_tsched ? "mmap+timer" : (u->use_mmap ? "mmap" : "serial")); @@ -1861,13 +1857,15 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca pa_sink_set_rtpoll(u->sink, u->rtpoll); u->frame_size = frame_size; - u->fragment_size = frag_size = (uint32_t) (period_frames * frame_size); - u->nfragments = nfrags; - u->hwbuf_size = u->fragment_size * nfrags; + u->fragment_size = frag_size = (size_t) (period_frames * frame_size); + u->hwbuf_size = buffer_size = (size_t) (buffer_frames * frame_size); pa_cvolume_mute(&u->hardware_volume, u->sink->sample_spec.channels); - pa_log_info("Using %u fragments of size %lu bytes, buffer time is %0.2fms", - nfrags, (long unsigned) u->fragment_size, + pa_log_info("Using %0.1f fragments of size %lu bytes (%0.2fms), buffer size is %lu bytes (%0.2fms)", + (double) u->hwbuf_size / (double) u->fragment_size, + (long unsigned) u->fragment_size, + (double) pa_bytes_to_usec(u->fragment_size, &ss) / PA_USEC_PER_MSEC, + (long unsigned) u->hwbuf_size, (double) pa_bytes_to_usec(u->hwbuf_size, &ss) / PA_USEC_PER_MSEC); pa_sink_set_max_request(u->sink, u->hwbuf_size); diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index f42d3542..88f2d8ae 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -111,8 +111,6 @@ struct userdata { pa_usec_t watermark_dec_not_before; - unsigned nfragments; - char *device_name; char *control_device; @@ -891,8 +889,7 @@ static int unsuspend(struct userdata *u) { pa_sample_spec ss; int err; pa_bool_t b, d; - unsigned nfrags; - snd_pcm_uframes_t period_size; + snd_pcm_uframes_t period_size, buffer_size; pa_assert(u); pa_assert(!u->pcm_handle); @@ -900,7 +897,7 @@ static int unsuspend(struct userdata *u) { pa_log_info("Trying resume..."); if ((err = snd_pcm_open(&u->pcm_handle, u->device_name, SND_PCM_STREAM_CAPTURE, - /*SND_PCM_NONBLOCK|*/ + SND_PCM_NONBLOCK| SND_PCM_NO_AUTO_RESAMPLE| SND_PCM_NO_AUTO_CHANNELS| SND_PCM_NO_AUTO_FORMAT)) < 0) { @@ -909,12 +906,12 @@ static int unsuspend(struct userdata *u) { } ss = u->source->sample_spec; - nfrags = u->nfragments; period_size = u->fragment_size / u->frame_size; + buffer_size = u->hwbuf_size / u->frame_size; b = u->use_mmap; d = u->use_tsched; - if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &nfrags, &period_size, u->hwbuf_size / u->frame_size, &b, &d, TRUE)) < 0) { + if ((err = pa_alsa_set_hw_params(u->pcm_handle, &ss, &period_size, &buffer_size, 0, &b, &d, TRUE)) < 0) { pa_log("Failed to set hardware parameters: %s", pa_alsa_strerror(err)); goto fail; } @@ -929,10 +926,11 @@ static int unsuspend(struct userdata *u) { goto fail; } - if (nfrags != u->nfragments || period_size*u->frame_size != u->fragment_size) { - pa_log_warn("Resume failed, couldn't restore original fragment settings. (Old: %lu*%lu, New %lu*%lu)", - (unsigned long) u->nfragments, (unsigned long) u->fragment_size, - (unsigned long) nfrags, period_size * u->frame_size); + if (period_size*u->frame_size != u->fragment_size || + buffer_size*u->frame_size != u->hwbuf_size) { + pa_log_warn("Resume failed, couldn't restore original fragment settings. (Old: %lu/%lu, New %lu/%lu)", + (unsigned long) u->hwbuf_size, (unsigned long) u->fragment_size, + (unsigned long) (buffer_size*u->fragment_size), (unsigned long) (period_size*u->frame_size)); goto fail; } @@ -1483,8 +1481,8 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p const char *dev_id = NULL; pa_sample_spec ss, requested_ss; pa_channel_map map; - uint32_t nfrags, hwbuf_size, frag_size, tsched_size, tsched_watermark; - snd_pcm_uframes_t period_frames, tsched_frames; + uint32_t nfrags, frag_size, buffer_size, tsched_size, tsched_watermark; + snd_pcm_uframes_t period_frames, buffer_frames, tsched_frames; size_t frame_size; pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, ignore_dB = FALSE; pa_source_new_data data; @@ -1518,8 +1516,10 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p goto fail; } - hwbuf_size = frag_size * nfrags; + buffer_size = nfrags * frag_size; + period_frames = frag_size/frame_size; + buffer_frames = buffer_size/frame_size; tsched_frames = tsched_size/frame_size; if (pa_modargs_get_value_boolean(ma, "mmap", &use_mmap) < 0) { @@ -1585,7 +1585,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p &u->device_name, &ss, &map, SND_PCM_STREAM_CAPTURE, - &nfrags, &period_frames, tsched_frames, + &period_frames, &buffer_frames, tsched_frames, &b, &d, mapping))) goto fail; @@ -1599,7 +1599,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p &u->device_name, &ss, &map, SND_PCM_STREAM_CAPTURE, - &nfrags, &period_frames, tsched_frames, + &period_frames, &buffer_frames, tsched_frames, &b, &d, profile_set, &mapping))) goto fail; @@ -1610,7 +1610,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p &u->device_name, &ss, &map, SND_PCM_STREAM_CAPTURE, - &nfrags, &period_frames, tsched_frames, + &period_frames, &buffer_frames, tsched_frames, &b, &d, FALSE))) goto fail; } @@ -1636,11 +1636,6 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p u->use_tsched = use_tsched = FALSE; } - if (use_tsched && !pa_alsa_pcm_is_hw(u->pcm_handle)) { - pa_log_info("Device is not a hardware device, disabling timer-based scheduling."); - u->use_tsched = use_tsched = FALSE; - } - if (u->use_mmap) pa_log_info("Successfully enabled mmap() mode."); @@ -1662,7 +1657,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name); - pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (period_frames * frame_size * nfrags)); + pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_BUFFER_SIZE, "%lu", (unsigned long) (buffer_frames * frame_size)); pa_proplist_setf(data.proplist, PA_PROP_DEVICE_BUFFERING_FRAGMENT_SIZE, "%lu", (unsigned long) (period_frames * frame_size)); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_ACCESS_MODE, u->use_tsched ? "mmap+timer" : (u->use_mmap ? "mmap" : "serial")); @@ -1703,13 +1698,15 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p pa_source_set_rtpoll(u->source, u->rtpoll); u->frame_size = frame_size; - u->fragment_size = frag_size = (uint32_t) (period_frames * frame_size); - u->nfragments = nfrags; - u->hwbuf_size = u->fragment_size * nfrags; + u->fragment_size = frag_size = (size_t) (period_frames * frame_size); + u->hwbuf_size = buffer_size = (size_t) (buffer_frames * frame_size); pa_cvolume_mute(&u->hardware_volume, u->source->sample_spec.channels); - pa_log_info("Using %u fragments of size %lu bytes, buffer time is %0.2fms", - nfrags, (long unsigned) u->fragment_size, + pa_log_info("Using %0.1f fragments of size %lu bytes (%0.2fms), buffer size is %lu bytes (%0.2fms)", + (double) u->hwbuf_size / (double) u->fragment_size, + (long unsigned) u->fragment_size, + (double) pa_bytes_to_usec(u->fragment_size, &ss) / PA_USEC_PER_MSEC, + (long unsigned) u->hwbuf_size, (double) pa_bytes_to_usec(u->hwbuf_size, &ss) / PA_USEC_PER_MSEC); if (u->use_tsched) { diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c index a47a8958..f934285a 100644 --- a/src/modules/alsa/alsa-util.c +++ b/src/modules/alsa/alsa-util.c @@ -93,6 +93,7 @@ static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, pa_s int ret; pa_assert(pcm_handle); + pa_assert(hwparams); pa_assert(f); if ((ret = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[*f])) >= 0) @@ -148,33 +149,71 @@ try_auto: return -1; } +static int set_period_size(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, snd_pcm_uframes_t size) { + snd_pcm_uframes_t s; + int d, ret; + + pa_assert(pcm_handle); + pa_assert(hwparams); + + s = size; + d = 0; + if (snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &s, &d) < 0) { + s = size; + d = -1; + if (snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &s, &d) < 0) { + s = size; + d = 1; + if ((ret = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &s, &d)) < 0) { + pa_log_info("snd_pcm_hw_params_set_period_size_near() failed: %s", pa_alsa_strerror(ret)); + return ret; + } + } + } + + return 0; +} + +static int set_buffer_size(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, snd_pcm_uframes_t size) { + int ret; + + pa_assert(pcm_handle); + pa_assert(hwparams); + + if ((ret = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &size)) < 0) { + pa_log_info("snd_pcm_hw_params_set_buffer_size_near() failed: %s", pa_alsa_strerror(ret)); + return ret; + } + + return 0; +} + /* Set the hardware parameters of the given ALSA device. Returns the - * selected fragment settings in *period and *period_size */ + * selected fragment settings in *buffer_size and *period_size. If tsched mode can be enabled */ int pa_alsa_set_hw_params( snd_pcm_t *pcm_handle, pa_sample_spec *ss, - uint32_t *periods, snd_pcm_uframes_t *period_size, + snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, pa_bool_t *use_tsched, pa_bool_t require_exact_channel_number) { int ret = -1; + snd_pcm_hw_params_t *hwparams, *hwparams_copy; + int dir; snd_pcm_uframes_t _period_size = period_size ? *period_size : 0; - unsigned int _periods = periods ? *periods : 0; - unsigned int r = ss->rate; - unsigned int c = ss->channels; - pa_sample_format_t f = ss->format; - snd_pcm_hw_params_t *hwparams; + snd_pcm_uframes_t _buffer_size = buffer_size ? *buffer_size : 0; pa_bool_t _use_mmap = use_mmap && *use_mmap; pa_bool_t _use_tsched = use_tsched && *use_tsched; - int dir; + pa_sample_spec _ss = *ss; pa_assert(pcm_handle); pa_assert(ss); snd_pcm_hw_params_alloca(&hwparams); + snd_pcm_hw_params_alloca(&hwparams_copy); if ((ret = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) { pa_log_debug("snd_pcm_hw_params_any() failed: %s", pa_alsa_strerror(ret)); @@ -208,114 +247,143 @@ int pa_alsa_set_hw_params( if (!_use_mmap) _use_tsched = FALSE; - if ((ret = set_format(pcm_handle, hwparams, &f)) < 0) + if (!pa_alsa_pcm_is_hw(pcm_handle)) + _use_tsched = FALSE; + + if ((ret = set_format(pcm_handle, hwparams, &_ss.format)) < 0) goto finish; - if ((ret = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &r, NULL)) < 0) { + if ((ret = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &_ss.rate, NULL)) < 0) { pa_log_debug("snd_pcm_hw_params_set_rate_near() failed: %s", pa_alsa_strerror(ret)); goto finish; } if (require_exact_channel_number) { - if ((ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, c)) < 0) { - pa_log_debug("snd_pcm_hw_params_set_channels(%u) failed: %s", c, pa_alsa_strerror(ret)); + if ((ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, _ss.channels)) < 0) { + pa_log_debug("snd_pcm_hw_params_set_channels(%u) failed: %s", _ss.channels, pa_alsa_strerror(ret)); goto finish; } } else { + unsigned int c = _ss.channels; + if ((ret = snd_pcm_hw_params_set_channels_near(pcm_handle, hwparams, &c)) < 0) { - pa_log_debug("snd_pcm_hw_params_set_channels_near(%u) failed: %s", c, pa_alsa_strerror(ret)); + pa_log_debug("snd_pcm_hw_params_set_channels_near(%u) failed: %s", _ss.channels, pa_alsa_strerror(ret)); goto finish; } - } - if ((ret = snd_pcm_hw_params_set_periods_integer(pcm_handle, hwparams)) < 0) { - pa_log_debug("snd_pcm_hw_params_set_periods_integer() failed: %s", pa_alsa_strerror(ret)); - goto finish; + _ss.channels = c; } - if (_period_size > 0 && tsched_size > 0 && _periods > 0) { - snd_pcm_uframes_t buffer_size; - unsigned int p; + if (_use_tsched && tsched_size > 0) { + _buffer_size = pa_convert_size(tsched_size, ss, &_ss); + _period_size = _buffer_size; + } else { + _period_size = pa_convert_size(_period_size, ss, &_ss); + _buffer_size = pa_convert_size(_buffer_size, ss, &_ss); + } - /* Adjust the buffer sizes, if we didn't get the rate we were asking for */ - _period_size = (snd_pcm_uframes_t) (((uint64_t) _period_size * r) / ss->rate); - tsched_size = (snd_pcm_uframes_t) (((uint64_t) tsched_size * r) / ss->rate); + if (_buffer_size > 0 || _period_size > 0) { + snd_pcm_uframes_t max_frames = 0; - if (_use_tsched) { - buffer_size = 0; + if ((ret = snd_pcm_hw_params_get_buffer_size_max(hwparams, &max_frames)) < 0) + pa_log_warn("snd_pcm_hw_params_get_buffer_size_max() failed: %s", pa_alsa_strerror(ret)); + else + pa_log_debug("Maximum hw buffer size is %lu ms", (long unsigned) max_frames * PA_MSEC_PER_SEC / _ss.rate); - if ((ret = snd_pcm_hw_params_get_buffer_size_max(hwparams, &buffer_size)) < 0) - pa_log_warn("snd_pcm_hw_params_get_buffer_size_max() failed: %s", pa_alsa_strerror(ret)); - else - pa_log_debug("Maximum hw buffer size is %u ms", (unsigned) buffer_size * 1000 / r); + /* Some ALSA drivers really don't like if we set the buffer + * size first and the number of periods second. (which would + * make a lot more sense to me) So, try a few combinations + * before we give up. */ + + if (_buffer_size > 0 && _period_size > 0) { + snd_pcm_hw_params_copy(hwparams_copy, hwparams); + + /* First try: set buffer size first, followed by period size */ + if (set_buffer_size(pcm_handle, hwparams_copy, _buffer_size) >= 0 && + set_period_size(pcm_handle, hwparams_copy, _period_size) >= 0 && + snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) { + pa_log_debug("Set buffer size first, period size second."); + goto success; + } - _period_size = tsched_size; - _periods = 1; + /* Second try: set period size first, followed by buffer size */ + if (set_period_size(pcm_handle, hwparams_copy, _period_size) >= 0 && + set_buffer_size(pcm_handle, hwparams_copy, _buffer_size) >= 0 && + snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) { + pa_log_debug("Set period size first, buffer size second."); + goto success; + } } - /* Some ALSA drivers really don't like if we set the buffer - * size first and the number of periods second. (which would - * make a lot more sense to me) So, follow this rule and - * adjust the periods first and the buffer size second */ - - /* First we pass 0 as direction to get exactly what we - * asked for. That this is necessary is presumably a bug - * in ALSA. All in all this is mostly a hint to ALSA, so - * we don't care if this fails. */ - - p = _periods; - dir = 0; - if (snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &p, &dir) < 0) { - p = _periods; - dir = 1; - if (snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &p, &dir) < 0) { - p = _periods; - dir = -1; - if ((ret = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &p, &dir)) < 0) - pa_log_info("snd_pcm_hw_params_set_periods_near() failed: %s", pa_alsa_strerror(ret)); + if (_buffer_size > 0) { + snd_pcm_hw_params_copy(hwparams_copy, hwparams); + + /* Third try: set only buffer size */ + if (set_buffer_size(pcm_handle, hwparams_copy, _buffer_size) >= 0 && + snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) { + pa_log_debug("Set only buffer size second."); + goto success; } } - /* Now set the buffer size */ - buffer_size = _periods * _period_size; - if ((ret = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size)) < 0) - pa_log_info("snd_pcm_hw_params_set_buffer_size_near() failed: %s", pa_alsa_strerror(ret)); + if (_period_size > 0) { + snd_pcm_hw_params_copy(hwparams_copy, hwparams); + + /* Fourth try: set only period size */ + if (set_period_size(pcm_handle, hwparams_copy, _period_size) >= 0 && + snd_pcm_hw_params(pcm_handle, hwparams_copy) >= 0) { + pa_log_debug("Set only period size second."); + goto success; + } + } } - if ((ret = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) + pa_log_debug("Set neither period nor buffer size."); + + /* Last chance, set nothing */ + if ((ret = snd_pcm_hw_params(pcm_handle, hwparams)) < 0) { + pa_log_info("snd_pcm_hw_params failed: %s", pa_alsa_strerror(ret)); goto finish; + } + +success: - if (ss->rate != r) - pa_log_info("Device %s doesn't support %u Hz, changed to %u Hz.", snd_pcm_name(pcm_handle), ss->rate, r); + if (ss->rate != _ss.rate) + pa_log_info("Device %s doesn't support %u Hz, changed to %u Hz.", snd_pcm_name(pcm_handle), ss->rate, _ss.rate); - if (ss->channels != c) - pa_log_info("Device %s doesn't support %u channels, changed to %u.", snd_pcm_name(pcm_handle), ss->channels, c); + if (ss->channels != _ss.channels) + pa_log_info("Device %s doesn't support %u channels, changed to %u.", snd_pcm_name(pcm_handle), ss->channels, _ss.channels); - if (ss->format != f) - pa_log_info("Device %s doesn't support sample format %s, changed to %s.", snd_pcm_name(pcm_handle), pa_sample_format_to_string(ss->format), pa_sample_format_to_string(f)); + if (ss->format != _ss.format) + pa_log_info("Device %s doesn't support sample format %s, changed to %s.", snd_pcm_name(pcm_handle), pa_sample_format_to_string(ss->format), pa_sample_format_to_string(_ss.format)); if ((ret = snd_pcm_prepare(pcm_handle)) < 0) { pa_log_info("snd_pcm_prepare() failed: %s", pa_alsa_strerror(ret)); goto finish; } + if ((ret = snd_pcm_hw_params_current(pcm_handle, hwparams)) < 0) { + pa_log_info("snd_pcm_hw_params_current() failed: %s", pa_alsa_strerror(ret)); + goto finish; + } + if ((ret = snd_pcm_hw_params_get_period_size(hwparams, &_period_size, &dir)) < 0 || - (ret = snd_pcm_hw_params_get_periods(hwparams, &_periods, &dir)) < 0) { - pa_log_info("snd_pcm_hw_params_get_period{s|_size}() failed: %s", pa_alsa_strerror(ret)); + (ret = snd_pcm_hw_params_get_buffer_size(hwparams, &_buffer_size)) < 0) { + pa_log_info("snd_pcm_hw_params_get_{period|buffer}_size() failed: %s", pa_alsa_strerror(ret)); goto finish; } /* If the sample rate deviates too much, we need to resample */ - if (r < ss->rate*.95 || r > ss->rate*1.05) - ss->rate = r; - ss->channels = (uint8_t) c; - ss->format = f; + if (_ss.rate < ss->rate*.95 || _ss.rate > ss->rate*1.05) + ss->rate = _ss.rate; + ss->channels = _ss.channels; + ss->format = _ss.format; - pa_assert(_periods > 0); pa_assert(_period_size > 0); + pa_assert(_buffer_size > 0); - if (periods) - *periods = _periods; + if (buffer_size) + *buffer_size = _buffer_size; if (period_size) *period_size = _period_size; @@ -393,8 +461,8 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto( pa_sample_spec *ss, pa_channel_map* map, int mode, - uint32_t *nfrags, snd_pcm_uframes_t *period_size, + snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, pa_bool_t *use_tsched, @@ -410,8 +478,6 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto( pa_assert(dev); pa_assert(ss); pa_assert(map); - pa_assert(nfrags); - pa_assert(period_size); pa_assert(ps); /* First we try to find a device string with a superset of the @@ -433,8 +499,8 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto( ss, map, mode, - nfrags, period_size, + buffer_size, tsched_size, use_mmap, use_tsched, @@ -460,8 +526,8 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto( ss, map, mode, - nfrags, period_size, + buffer_size, tsched_size, use_mmap, use_tsched, @@ -478,7 +544,18 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto( /* OK, we didn't find any good device, so let's try the raw hw: stuff */ d = pa_sprintf_malloc("hw:%s", dev_id); pa_log_debug("Trying %s as last resort...", d); - pcm_handle = pa_alsa_open_by_device_string(d, dev, ss, map, mode, nfrags, period_size, tsched_size, use_mmap, use_tsched, FALSE); + pcm_handle = pa_alsa_open_by_device_string( + d, + dev, + ss, + map, + mode, + period_size, + buffer_size, + tsched_size, + use_mmap, + use_tsched, + FALSE); pa_xfree(d); if (pcm_handle && mapping) @@ -493,8 +570,8 @@ snd_pcm_t *pa_alsa_open_by_device_id_mapping( pa_sample_spec *ss, pa_channel_map* map, int mode, - uint32_t *nfrags, snd_pcm_uframes_t *period_size, + snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, pa_bool_t *use_tsched, @@ -508,8 +585,6 @@ snd_pcm_t *pa_alsa_open_by_device_id_mapping( pa_assert(dev); pa_assert(ss); pa_assert(map); - pa_assert(nfrags); - pa_assert(period_size); pa_assert(m); try_ss.channels = m->channel_map.channels; @@ -524,8 +599,8 @@ snd_pcm_t *pa_alsa_open_by_device_id_mapping( &try_ss, &try_map, mode, - nfrags, period_size, + buffer_size, tsched_size, use_mmap, use_tsched, @@ -547,8 +622,8 @@ snd_pcm_t *pa_alsa_open_by_device_string( pa_sample_spec *ss, pa_channel_map* map, int mode, - uint32_t *nfrags, snd_pcm_uframes_t *period_size, + snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, pa_bool_t *use_tsched, @@ -579,7 +654,15 @@ snd_pcm_t *pa_alsa_open_by_device_string( pa_log_debug("Managed to open %s", d); - if ((err = pa_alsa_set_hw_params(pcm_handle, ss, nfrags, period_size, tsched_size, use_mmap, use_tsched, require_exact_channel_number)) < 0) { + if ((err = pa_alsa_set_hw_params( + pcm_handle, + ss, + period_size, + buffer_size, + tsched_size, + use_mmap, + use_tsched, + require_exact_channel_number)) < 0) { if (!reformat) { reformat = TRUE; @@ -632,8 +715,8 @@ snd_pcm_t *pa_alsa_open_by_template( pa_sample_spec *ss, pa_channel_map* map, int mode, - uint32_t *nfrags, snd_pcm_uframes_t *period_size, + snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, pa_bool_t *use_tsched, @@ -653,8 +736,8 @@ snd_pcm_t *pa_alsa_open_by_template( ss, map, mode, - nfrags, period_size, + buffer_size, tsched_size, use_mmap, use_tsched, @@ -900,7 +983,7 @@ void pa_alsa_init_proplist_ctl(pa_proplist *p, const char *name) { snd_ctl_card_info_alloca(&info); if ((err = snd_ctl_open(&ctl, name, 0)) < 0) { - pa_log_warn("Error opening low-level control device '%s'", name); + pa_log_warn("Error opening low-level control device '%s': %s", name, snd_strerror(err)); return; } diff --git a/src/modules/alsa/alsa-util.h b/src/modules/alsa/alsa-util.h index 830a922e..265cd28c 100644 --- a/src/modules/alsa/alsa-util.h +++ b/src/modules/alsa/alsa-util.h @@ -42,8 +42,8 @@ int pa_alsa_set_hw_params( snd_pcm_t *pcm_handle, pa_sample_spec *ss, /* modified at return */ - uint32_t *periods, /* modified at return */ snd_pcm_uframes_t *period_size, /* modified at return */ + snd_pcm_uframes_t *buffer_size, /* modified at return */ snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, /* modified at return */ pa_bool_t *use_tsched, /* modified at return */ @@ -60,8 +60,8 @@ snd_pcm_t *pa_alsa_open_by_device_id_auto( pa_sample_spec *ss, /* modified at return */ pa_channel_map* map, /* modified at return */ int mode, - uint32_t *nfrags, /* modified at return */ snd_pcm_uframes_t *period_size, /* modified at return */ + snd_pcm_uframes_t *buffer_size, /* modified at return */ snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, /* modified at return */ pa_bool_t *use_tsched, /* modified at return */ @@ -75,8 +75,8 @@ snd_pcm_t *pa_alsa_open_by_device_id_mapping( pa_sample_spec *ss, /* modified at return */ pa_channel_map* map, /* modified at return */ int mode, - uint32_t *nfrags, /* modified at return */ snd_pcm_uframes_t *period_size, /* modified at return */ + snd_pcm_uframes_t *buffer_size, /* modified at return */ snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, /* modified at return */ pa_bool_t *use_tsched, /* modified at return */ @@ -89,8 +89,8 @@ snd_pcm_t *pa_alsa_open_by_device_string( pa_sample_spec *ss, /* modified at return */ pa_channel_map* map, /* modified at return */ int mode, - uint32_t *nfrags, /* modified at return */ snd_pcm_uframes_t *period_size, /* modified at return */ + snd_pcm_uframes_t *buffer_size, /* modified at return */ snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, /* modified at return */ pa_bool_t *use_tsched, /* modified at return */ @@ -104,8 +104,8 @@ snd_pcm_t *pa_alsa_open_by_template( pa_sample_spec *ss, /* modified at return */ pa_channel_map* map, /* modified at return */ int mode, - uint32_t *nfrags, /* modified at return */ snd_pcm_uframes_t *period_size, /* modified at return */ + snd_pcm_uframes_t *buffer_size, /* modified at return */ snd_pcm_uframes_t tsched_size, pa_bool_t *use_mmap, /* modified at return */ pa_bool_t *use_tsched, /* modified at return */ diff --git a/src/modules/alsa/mixer/paths/analog-input.conf.common b/src/modules/alsa/mixer/paths/analog-input.conf.common index 6728a6ae..87af38b3 100644 --- a/src/modules/alsa/mixer/paths/analog-input.conf.common +++ b/src/modules/alsa/mixer/paths/analog-input.conf.common @@ -78,6 +78,10 @@ priority = 19 name = input-microphone priority = 19 +[Option Input Source:Internal Mic] +name = input-microphone +priority = 19 + [Option Input Source:Line] name = input-linein priority = 18 @@ -90,6 +94,10 @@ priority = 18 name = input-linein priority = 18 +[Option Input Source:Docking-Station] +name = input-docking +priority = 17 + ;;; ' Capture Source' [Element Capture Source] diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index 55f6a6e2..6bea33d7 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -329,7 +329,7 @@ int pa__init(pa_module *m) { if (!u->profile_set) goto fail; - pa_alsa_profile_set_probe(u->profile_set, u->device_id, &m->core->default_sample_spec); + pa_alsa_profile_set_probe(u->profile_set, u->device_id, &m->core->default_sample_spec, m->core->default_n_fragments, m->core->default_fragment_size_msec); pa_card_new_data_init(&data); data.driver = __FILE__; diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index b8a88042..4592fca1 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -221,9 +221,7 @@ static int service_recv(struct userdata *u, bt_audio_msg_header_t *msg, size_t r pa_assert(u); pa_assert(u->service_fd >= 0); pa_assert(msg); - - if (room <= 0) - room = BT_SUGGESTED_BUFFER_SIZE; + pa_assert(room >= sizeof(*msg)); pa_log_debug("Trying to receive message from audio service..."); @@ -236,6 +234,11 @@ static int service_recv(struct userdata *u, bt_audio_msg_header_t *msg, size_t r return -1; } + if (msg->length > room) { + pa_log_error("Not enough room."); + return -1; + } + /* Secondly, read the payload */ if (msg->length > sizeof(*msg)) { diff --git a/src/modules/hal-util.c b/src/modules/hal-util.c index e2a2d8d7..2d59f51d 100644 --- a/src/modules/hal-util.c +++ b/src/modules/hal-util.c @@ -65,7 +65,7 @@ int pa_hal_get_info(pa_core *core, pa_proplist *p, int card) { goto finish; } - if (!(udis = libhal_find_device_by_capability(hal, "sound", &n, &error)) < 0) { + if (!(udis = libhal_find_device_by_capability(hal, "sound", &n, &error))) { pa_log_error("Couldn't find devices: %s: %s", error.name, error.message); goto finish; } diff --git a/src/modules/module-always-sink.c b/src/modules/module-always-sink.c index aee1c650..3d7de9c6 100644 --- a/src/modules/module-always-sink.c +++ b/src/modules/module-always-sink.c @@ -24,6 +24,7 @@ #endif #include <pulse/xmalloc.h> +#include <pulse/i18n.h> #include <pulsecore/core.h> #include <pulsecore/sink-input.h> @@ -35,7 +36,7 @@ #include "module-always-sink-symdef.h" PA_MODULE_AUTHOR("Colin Guthrie"); -PA_MODULE_DESCRIPTION("Always keeps at least one sink loaded even if it's a null one"); +PA_MODULE_DESCRIPTION(_("Always keeps at least one sink loaded even if it's a null one")); PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_LOAD_ONCE(TRUE); PA_MODULE_USAGE( @@ -78,7 +79,8 @@ static void load_null_sink_if_needed(pa_core *c, pa_sink *sink, struct userdata* u->ignore = TRUE; - t = pa_sprintf_malloc("sink_name=%s", u->sink_name); + t = pa_sprintf_malloc("sink_name=%s sink_properties='device.description=\"%s\"'", u->sink_name, + _("Dummy Output")); m = pa_module_load(c, "module-null-sink", t); u->null_module = m ? m->index : PA_INVALID_INDEX; pa_xfree(t); diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c index 6034d0ee..18519131 100644 --- a/src/modules/module-hal-detect.c +++ b/src/modules/module-hal-detect.c @@ -435,9 +435,7 @@ static int hal_device_add_all(struct userdata *u) { int i; for (i = 0; i < n; i++) { - struct device *d; - - if ((d = hal_device_add(u, udis[i]))) { + if (hal_device_add(u, udis[i])) { count++; pa_log_debug("Loaded device %s", udis[i]); } else diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index 36c50b05..74a2ebb1 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -35,6 +35,7 @@ #include <pulse/rtclock.h> #include <pulse/timeval.h> #include <pulse/xmalloc.h> +#include <pulse/i18n.h> #include <pulsecore/macro.h> #include <pulsecore/sink.h> @@ -51,7 +52,7 @@ #include "module-null-sink-symdef.h" PA_MODULE_AUTHOR("Lennart Poettering"); -PA_MODULE_DESCRIPTION("Clocked NULL sink"); +PA_MODULE_DESCRIPTION(_("Clocked NULL sink")); PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_LOAD_ONCE(FALSE); PA_MODULE_USAGE( @@ -287,7 +288,7 @@ int pa__init(pa_module*m) { pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME)); pa_sink_new_data_set_sample_spec(&data, &ss); pa_sink_new_data_set_channel_map(&data, &map); - pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, pa_modargs_get_value(ma, "description", "Null Output")); + pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, pa_modargs_get_value(ma, "description", _("Null Output"))); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "abstract"); if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist, PA_UPDATE_REPLACE) < 0) { diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c index 5ccb81d0..af4b8b2a 100644 --- a/src/modules/module-tunnel.c +++ b/src/modules/module-tunnel.c @@ -332,7 +332,7 @@ static void command_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa static void command_stream_buffer_attr_changed(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { struct userdata *u = userdata; - uint32_t channel, maxlength, tlength, fragsize, prebuf, minreq; + uint32_t channel, maxlength, tlength = 0, fragsize, prebuf, minreq; pa_usec_t usec; pa_assert(pd); @@ -1097,7 +1097,7 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag uint32_t idx, owner_module, client, sink; pa_usec_t buffer_usec, sink_usec; const char *name, *driver, *resample_method; - pa_bool_t mute; + pa_bool_t mute = FALSE; pa_sample_spec sample_spec; pa_channel_map channel_map; pa_cvolume volume; @@ -1345,12 +1345,11 @@ static void command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32 /* Called from main context */ static void start_subscribe(struct userdata *u) { pa_tagstruct *t; - uint32_t tag; pa_assert(u); t = pa_tagstruct_new(NULL, 0); pa_tagstruct_putu32(t, PA_COMMAND_SUBSCRIBE); - pa_tagstruct_putu32(t, tag = u->ctag++); + pa_tagstruct_putu32(t, u->ctag++); pa_tagstruct_putu32(t, PA_SUBSCRIPTION_MASK_SERVER| #ifdef TUNNEL_SINK PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SINK @@ -1526,7 +1525,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t reply = pa_tagstruct_new(NULL, 0); pa_tagstruct_putu32(reply, PA_COMMAND_SET_CLIENT_NAME); - pa_tagstruct_putu32(reply, tag = u->ctag++); + pa_tagstruct_putu32(reply, u->ctag++); if (u->version >= 13) { pa_proplist *pl; @@ -1753,7 +1752,6 @@ static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata static void sink_set_volume(pa_sink *sink) { struct userdata *u; pa_tagstruct *t; - uint32_t tag; pa_assert(sink); u = sink->userdata; @@ -1761,7 +1759,7 @@ static void sink_set_volume(pa_sink *sink) { t = pa_tagstruct_new(NULL, 0); pa_tagstruct_putu32(t, PA_COMMAND_SET_SINK_INPUT_VOLUME); - pa_tagstruct_putu32(t, tag = u->ctag++); + pa_tagstruct_putu32(t, u->ctag++); pa_tagstruct_putu32(t, u->device_index); pa_tagstruct_put_cvolume(t, &sink->real_volume); pa_pstream_send_tagstruct(u->pstream, t); @@ -1771,7 +1769,6 @@ static void sink_set_volume(pa_sink *sink) { static void sink_set_mute(pa_sink *sink) { struct userdata *u; pa_tagstruct *t; - uint32_t tag; pa_assert(sink); u = sink->userdata; @@ -1782,7 +1779,7 @@ static void sink_set_mute(pa_sink *sink) { t = pa_tagstruct_new(NULL, 0); pa_tagstruct_putu32(t, PA_COMMAND_SET_SINK_INPUT_MUTE); - pa_tagstruct_putu32(t, tag = u->ctag++); + pa_tagstruct_putu32(t, u->ctag++); pa_tagstruct_putu32(t, u->device_index); pa_tagstruct_put_boolean(t, !!sink->muted); pa_pstream_send_tagstruct(u->pstream, t); diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c index b41b9c0f..1b1e9c1a 100644 --- a/src/modules/module-udev-detect.c +++ b/src/modules/module-udev-detect.c @@ -29,10 +29,13 @@ #include <sys/inotify.h> #include <libudev.h> +#include <pulse/timeval.h> + #include <pulsecore/modargs.h> #include <pulsecore/core-error.h> #include <pulsecore/core-util.h> #include <pulsecore/namereg.h> +#include <pulsecore/ratelimit.h> #include "module-udev-detect-symdef.h" @@ -50,6 +53,7 @@ struct device { char *card_name; char *args; uint32_t module; + pa_ratelimit ratelimit; }; struct userdata { @@ -110,6 +114,9 @@ static pa_bool_t is_card_busy(const char *id) { pa_assert(id); + /* This simply uses /proc/asound/card.../pcm.../sub.../status to + * check whether there is still a process using this audio device. */ + card_path = pa_sprintf_malloc("/proc/asound/card%s", id); if (!(card_dir = opendir(card_path))) { @@ -234,14 +241,41 @@ static void verify_access(struct userdata *u, struct device *d) { pa_log_debug("%s is busy: %s", d->path, pa_yes_no(busy)); if (!busy) { - pa_log_debug("Loading module-alsa-card with arguments '%s'", d->args); - m = pa_module_load(u->core, "module-alsa-card", d->args); - if (m) { - d->module = m->index; - pa_log_info("Card %s (%s) module loaded.", d->path, d->card_name); + /* So, why do we rate limit here? It's certainly ugly, + * but there seems to be no other way. Problem is + * this: if we are unable to configure/probe an audio + * device after opening it we will close it again and + * the module initialization will fail. This will then + * cause an inotify event on the device node which + * will be forwarded to us. We then try to reopen the + * audio device again, practically entering a busy + * loop. + * + * A clean fix would be if we would be able to ignore + * our own inotify close events. However, inotify + * lacks such functionality. Also, during probing of + * the device we cannot really distuingish between + * other processes causing EBUSY or ourselves, which + * means we have no way to figure out if the probing + * during opening was canceled by a "try again" + * failure or a "fatal" failure. */ + + if (pa_ratelimit_test(&d->ratelimit)) { + pa_log_debug("Loading module-alsa-card with arguments '%s'", d->args); + m = pa_module_load(u->core, "module-alsa-card", d->args); + + if (m) { + d->module = m->index; + pa_log_info("Card %s (%s) module loaded.", d->path, d->card_name); + } else + pa_log_info("Card %s (%s) failed to load module.", d->path, d->card_name); } else - pa_log_info("Card %s (%s) failed to load module.", d->path, d->card_name); + pa_log_warn("Tried to configure %s (%s) more often than %u times in %llus", + d->path, + d->card_name, + d->ratelimit.burst, + (long long unsigned) (d->ratelimit.interval / PA_USEC_PER_SEC)); } } @@ -277,6 +311,7 @@ static void card_changed(struct userdata *u, struct udev_device *dev) { d = pa_xnew0(struct device, 1); d->path = pa_xstrdup(path); d->module = PA_INVALID_INDEX; + PA_INIT_RATELIMIT(d->ratelimit, 10*PA_USEC_PER_SEC, 5); if (!(t = udev_device_get_property_value(dev, "PULSE_NAME"))) if (!(t = udev_device_get_property_value(dev, "ID_ID"))) diff --git a/src/modules/raop/base64.c b/src/modules/raop/base64.c index e1cbed02..5b061034 100644 --- a/src/modules/raop/base64.c +++ b/src/modules/raop/base64.c @@ -57,7 +57,6 @@ int pa_base64_encode(const void *data, int size, char **str) p = s = pa_xnew(char, size * 4 / 3 + 4); q = (const unsigned char *) data; - i = 0; for (i = 0; i < size;) { c = q[i++]; c *= 256; diff --git a/src/modules/rtp/rtsp_client.c b/src/modules/rtp/rtsp_client.c index ba657f74..915c1072 100644 --- a/src/modules/rtp/rtsp_client.c +++ b/src/modules/rtp/rtsp_client.c @@ -456,6 +456,8 @@ static int rtsp_exec(pa_rtsp_client* c, const char* cmd, l = pa_iochannel_write(c->io, hdrs, strlen(hdrs)); pa_xfree(hdrs); + /* FIXME: this is broken, not necessarily all bytes are written */ + return 0; } diff --git a/src/modules/x11/module-x11-publish.c b/src/modules/x11/module-x11-publish.c index 2c7fdc12..7ee1b6da 100644 --- a/src/modules/x11/module-x11-publish.c +++ b/src/modules/x11/module-x11-publish.c @@ -90,7 +90,7 @@ static void publish_servers(struct userdata *u, pa_strlist *l) { l = pa_strlist_reverse(l); s = pa_strlist_tostring(l); - l = pa_strlist_reverse(l); + pa_strlist_reverse(l); pa_x11_set_prop(pa_x11_wrapper_get_display(u->x11_wrapper), "PULSE_SERVER", s); pa_xfree(s); diff --git a/src/pulse/context.h b/src/pulse/context.h index cd129313..670b23e8 100644 --- a/src/pulse/context.h +++ b/src/pulse/context.h @@ -267,7 +267,6 @@ pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_even for mainloop->time_restart). \since 0.9.16 */ void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec); - PA_C_DECL_END #endif diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h index ee982100..68cfc874 100644 --- a/src/pulse/introspect.h +++ b/src/pulse/introspect.h @@ -331,6 +331,12 @@ pa_operation* pa_context_set_source_mute_by_index(pa_context *c, uint32_t idx, i /** Set the mute switch of a source device specified by its name */ pa_operation* pa_context_set_source_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata); +/** Suspend/Resume a source. \since 0.9.7 */ +pa_operation* pa_context_suspend_source_by_name(pa_context *c, const char *source_name, int suspend, pa_context_success_cb_t cb, void* userdata); + +/** Suspend/Resume a source. If idx is PA_INVALID_INDEX all sources will be suspended. \since 0.9.7 */ +pa_operation* pa_context_suspend_source_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata); + /** Change the profile of a source. \since 0.9.16 */ pa_operation* pa_context_set_source_port_by_index(pa_context *c, uint32_t idx, const char*port, pa_context_success_cb_t cb, void *userdata); @@ -557,12 +563,6 @@ pa_operation* pa_context_move_source_output_by_name(pa_context *c, uint32_t idx, /** Move the specified source output to a different source. \since 0.9.5 */ pa_operation* pa_context_move_source_output_by_index(pa_context *c, uint32_t idx, uint32_t source_idx, pa_context_success_cb_t cb, void* userdata); -/** Suspend/Resume a source. \since 0.9.7 */ -pa_operation* pa_context_suspend_source_by_name(pa_context *c, const char *source_name, int suspend, pa_context_success_cb_t cb, void* userdata); - -/** Suspend/Resume a source. If idx is PA_INVALID_INDEX all sources will be suspended. \since 0.9.7 */ -pa_operation* pa_context_suspend_source_by_index(pa_context *c, uint32_t idx, int suspend, pa_context_success_cb_t cb, void* userdata); - /** Kill a source output. */ pa_operation* pa_context_kill_source_output(pa_context *c, uint32_t idx, pa_context_success_cb_t cb, void *userdata); diff --git a/src/pulse/sample.h b/src/pulse/sample.h index 53d7dea3..7a4a55a0 100644 --- a/src/pulse/sample.h +++ b/src/pulse/sample.h @@ -302,6 +302,13 @@ pa_sample_format_t pa_parse_sample_format(const char *format) PA_GCC_PURE; /** Pretty print a sample type specification to a string */ char* pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec); +/** Maximum required string length for pa_bytes_snprint(). Please note + * that this value can change with any release without warning and + * without being considered API or ABI breakage. You should not use + * this definition anywhere where it might become part of an + * ABI. \since 0.9.16 */ +#define PA_BYTES_SNPRINT_MAX 11 + /** Pretty print a byte size value. (i.e. "2.5 MiB") */ char* pa_bytes_snprint(char *s, size_t l, unsigned v); diff --git a/src/pulse/scache.c b/src/pulse/scache.c index 77f60d72..27da6887 100644 --- a/src/pulse/scache.c +++ b/src/pulse/scache.c @@ -187,7 +187,7 @@ pa_operation *pa_context_play_sample(pa_context *c, const char *name, const char pa_tagstruct_putu32(t, PA_INVALID_INDEX); pa_tagstruct_puts(t, dev); - if (volume == (pa_volume_t) -1 && c->version < 15) + if (volume == PA_VOLUME_INVALID && c->version < 15) volume = PA_VOLUME_NORM; pa_tagstruct_putu32(t, volume); @@ -216,7 +216,6 @@ pa_operation *pa_context_play_sample_with_proplist(pa_context *c, const char *na PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); PA_CHECK_VALIDITY_RETURN_NULL(c, name && *name, PA_ERR_INVALID); PA_CHECK_VALIDITY_RETURN_NULL(c, !dev || *dev, PA_ERR_INVALID); - PA_CHECK_VALIDITY_RETURN_NULL(c, p, PA_ERR_INVALID); PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 13, PA_ERR_NOTSUPPORTED); o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata); @@ -228,12 +227,19 @@ pa_operation *pa_context_play_sample_with_proplist(pa_context *c, const char *na pa_tagstruct_putu32(t, PA_INVALID_INDEX); pa_tagstruct_puts(t, dev); - if (volume == (pa_volume_t) -1 && c->version < 15) + if (volume == PA_VOLUME_INVALID && c->version < 15) volume = PA_VOLUME_NORM; pa_tagstruct_putu32(t, volume); pa_tagstruct_puts(t, name); - pa_tagstruct_put_proplist(t, p); + + if (p) + pa_tagstruct_put_proplist(t, p); + else { + p = pa_proplist_new(); + pa_tagstruct_put_proplist(t, p); + pa_proplist_free(p); + } pa_pstream_send_tagstruct(c->pstream, t); pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, play_sample_with_proplist_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref); diff --git a/src/pulse/scache.h b/src/pulse/scache.h index cd579d2e..31cf7b01 100644 --- a/src/pulse/scache.h +++ b/src/pulse/scache.h @@ -101,7 +101,7 @@ pa_operation* pa_context_play_sample( pa_context *c /**< Context */, const char *name /**< Name of the sample to play */, const char *dev /**< Sink to play this sample on */, - pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here (pa_volume_t) -1 which will leave the decision about the volume to the server side which is a good idea. */ , + pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here PA_VOLUME_INVALID which will leave the decision about the volume to the server side which is a good idea. */ , pa_context_success_cb_t cb /**< Call this function after successfully starting playback, or NULL */, void *userdata /**< Userdata to pass to the callback */); @@ -113,7 +113,7 @@ pa_operation* pa_context_play_sample_with_proplist( pa_context *c /**< Context */, const char *name /**< Name of the sample to play */, const char *dev /**< Sink to play this sample on */, - pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here (pa_volume_t) -1 which will leave the decision about the volume to the server side which is a good idea. */ , + pa_volume_t volume /**< Volume to play this sample with. Starting with 0.9.15 you may pass here PA_VOLUME_INVALID which will leave the decision about the volume to the server side which is a good idea. */ , pa_proplist *proplist /**< Property list for this sound. The property list of the cached entry will be merged into this property list */, pa_context_play_sample_cb_t cb /**< Call this function after successfully starting playback, or NULL */, void *userdata /**< Userdata to pass to the callback */); diff --git a/src/pulse/stream.h b/src/pulse/stream.h index 8a08421f..21dd0a85 100644 --- a/src/pulse/stream.h +++ b/src/pulse/stream.h @@ -319,7 +319,7 @@ typedef struct pa_stream pa_stream; typedef void (*pa_stream_success_cb_t) (pa_stream*s, int success, void *userdata); /** A generic request callback */ -typedef void (*pa_stream_request_cb_t)(pa_stream *p, size_t bytes, void *userdata); +typedef void (*pa_stream_request_cb_t)(pa_stream *p, size_t nbytes, void *userdata); /** A generic notification callback */ typedef void (*pa_stream_notify_cb_t)(pa_stream *p, void *userdata); diff --git a/src/pulse/utf8.c b/src/pulse/utf8.c index 6b58bde3..fe7bcd26 100644 --- a/src/pulse/utf8.c +++ b/src/pulse/utf8.c @@ -120,10 +120,8 @@ static char* utf8_validate(const char *str, char *output) { size = 4; min = (1 << 16); val = (uint32_t) (*p & 0x07); - } else { - size = 1; + } else goto error; - } p++; if (!is_continuation_char(*p)) @@ -150,12 +148,9 @@ ONE_REMAINING: if (o) { memcpy(o, last, (size_t) size); - o += size - 1; + o += size; } - if (o) - o++; - continue; error: diff --git a/src/pulse/volume.c b/src/pulse/volume.c index 234c3f72..2d2bba25 100644 --- a/src/pulse/volume.c +++ b/src/pulse/volume.c @@ -64,7 +64,7 @@ pa_cvolume* pa_cvolume_init(pa_cvolume *a) { a->channels = 0; for (c = 0; c < PA_CHANNELS_MAX; c++) - a->values[c] = (pa_volume_t) -1; + a->values[c] = PA_VOLUME_INVALID; return a; } @@ -155,7 +155,7 @@ pa_volume_t pa_cvolume_min(const pa_cvolume *a) { pa_volume_t pa_cvolume_max_mask(const pa_cvolume *a, const pa_channel_map *cm, pa_channel_position_mask_t mask) { pa_volume_t m = PA_VOLUME_MUTED; - unsigned c, n; + unsigned c; pa_assert(a); @@ -164,7 +164,7 @@ pa_volume_t pa_cvolume_max_mask(const pa_cvolume *a, const pa_channel_map *cm, p pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(a, cm), PA_VOLUME_MUTED); - for (c = n = 0; c < a->channels; c++) { + for (c = 0; c < a->channels; c++) { if (!(PA_CHANNEL_POSITION_MASK(cm->map[c]) & mask)) continue; @@ -178,7 +178,7 @@ pa_volume_t pa_cvolume_max_mask(const pa_cvolume *a, const pa_channel_map *cm, p pa_volume_t pa_cvolume_min_mask(const pa_cvolume *a, const pa_channel_map *cm, pa_channel_position_mask_t mask) { pa_volume_t m = PA_VOLUME_MAX; - unsigned c, n; + unsigned c; pa_assert(a); @@ -187,7 +187,7 @@ pa_volume_t pa_cvolume_min_mask(const pa_cvolume *a, const pa_channel_map *cm, p pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(a, cm), PA_VOLUME_MUTED); - for (c = n = 0; c < a->channels; c++) { + for (c = 0; c < a->channels; c++) { if (!(PA_CHANNEL_POSITION_MASK(cm->map[c]) & mask)) continue; @@ -201,6 +201,9 @@ pa_volume_t pa_cvolume_min_mask(const pa_cvolume *a, const pa_channel_map *cm, p pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) { + pa_return_val_if_fail(a != PA_VOLUME_INVALID, PA_VOLUME_INVALID); + pa_return_val_if_fail(b != PA_VOLUME_INVALID, PA_VOLUME_INVALID); + /* cbrt((a/PA_VOLUME_NORM)^3*(b/PA_VOLUME_NORM)^3)*PA_VOLUME_NORM = a*b/PA_VOLUME_NORM */ return (pa_volume_t) (((uint64_t) a * (uint64_t) b + (uint64_t) PA_VOLUME_NORM / 2ULL) / (uint64_t) PA_VOLUME_NORM); @@ -208,6 +211,9 @@ pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) { pa_volume_t pa_sw_volume_divide(pa_volume_t a, pa_volume_t b) { + pa_return_val_if_fail(a != PA_VOLUME_INVALID, PA_VOLUME_INVALID); + pa_return_val_if_fail(b != PA_VOLUME_INVALID, PA_VOLUME_INVALID); + if (b <= PA_VOLUME_MUTED) return 0; @@ -232,6 +238,8 @@ pa_volume_t pa_sw_volume_from_dB(double dB) { double pa_sw_volume_to_dB(pa_volume_t v) { + pa_return_val_if_fail(v != PA_VOLUME_INVALID, PA_DECIBEL_MININFTY); + if (v <= PA_VOLUME_MUTED) return PA_DECIBEL_MININFTY; @@ -259,6 +267,8 @@ pa_volume_t pa_sw_volume_from_linear(double v) { double pa_sw_volume_to_linear(pa_volume_t v) { double f; + pa_return_val_if_fail(v != PA_VOLUME_INVALID, 0.0); + if (v <= PA_VOLUME_MUTED) return 0.0; @@ -307,7 +317,7 @@ char *pa_volume_snprint(char *s, size_t l, pa_volume_t v) { pa_init_i18n(); - if (v == (pa_volume_t) -1) { + if (v == PA_VOLUME_INVALID) { pa_snprintf(s, l, _("(invalid)")); return s; } @@ -357,7 +367,7 @@ char *pa_sw_volume_snprint_dB(char *s, size_t l, pa_volume_t v) { pa_init_i18n(); - if (v == (pa_volume_t) -1) { + if (v == PA_VOLUME_INVALID) { pa_snprintf(s, l, _("(invalid)")); return s; } @@ -374,6 +384,7 @@ int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) { pa_assert(a); pa_return_val_if_fail(pa_cvolume_valid(a), 0); + pa_return_val_if_fail(v != PA_VOLUME_INVALID, 0); for (c = 0; c < a->channels; c++) if (a->values[c] != v) @@ -407,6 +418,7 @@ pa_cvolume *pa_sw_cvolume_multiply_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_assert(a); pa_return_val_if_fail(pa_cvolume_valid(a), NULL); + pa_return_val_if_fail(b != PA_VOLUME_INVALID, NULL); for (i = 0; i < a->channels; i++) dest->values[i] = pa_sw_volume_multiply(a->values[i], b); @@ -441,6 +453,7 @@ pa_cvolume *pa_sw_cvolume_divide_scalar(pa_cvolume *dest, const pa_cvolume *a, p pa_assert(a); pa_return_val_if_fail(pa_cvolume_valid(a), NULL); + pa_return_val_if_fail(b != PA_VOLUME_INVALID, NULL); for (i = 0; i < a->channels; i++) dest->values[i] = pa_sw_volume_divide(a->values[i], b); @@ -459,7 +472,7 @@ int pa_cvolume_valid(const pa_cvolume *v) { return 0; for (c = 0; c < v->channels; c++) - if (v->values[c] == (pa_volume_t) -1) + if (v->values[c] == PA_VOLUME_INVALID) return 0; return 1; @@ -497,8 +510,6 @@ pa_cvolume *pa_cvolume_remap(pa_cvolume *v, const pa_channel_map *from, const pa pa_assert(from); pa_assert(to); - pa_return_val_if_fail(pa_cvolume_valid(v), NULL); - pa_return_val_if_fail(pa_channel_map_valid(from), NULL); pa_return_val_if_fail(pa_channel_map_valid(to), NULL); pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, from), NULL); @@ -600,8 +611,6 @@ float pa_cvolume_get_balance(const pa_cvolume *v, const pa_channel_map *map) { pa_assert(v); pa_assert(map); - pa_return_val_if_fail(pa_cvolume_valid(v), 0.0f); - pa_return_val_if_fail(pa_channel_map_valid(map), 0.0f); pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), 0.0f); if (!pa_channel_map_can_balance(map)) @@ -633,12 +642,10 @@ pa_cvolume* pa_cvolume_set_balance(pa_cvolume *v, const pa_channel_map *map, flo pa_assert(map); pa_assert(v); - pa_assert(new_balance >= -1.0f); - pa_assert(new_balance <= 1.0f); - pa_return_val_if_fail(pa_cvolume_valid(v), NULL); - pa_return_val_if_fail(pa_channel_map_valid(map), NULL); pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), NULL); + pa_return_val_if_fail(new_balance >= -1.0f, NULL); + pa_return_val_if_fail(new_balance <= 1.0f, NULL); if (!pa_channel_map_can_balance(map)) return v; @@ -679,7 +686,7 @@ pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max) { pa_assert(v); pa_return_val_if_fail(pa_cvolume_valid(v), NULL); - pa_return_val_if_fail(max != (pa_volume_t) -1, NULL); + pa_return_val_if_fail(max != PA_VOLUME_INVALID, NULL); t = pa_cvolume_max(v); @@ -698,8 +705,12 @@ pa_cvolume* pa_cvolume_scale_mask(pa_cvolume *v, pa_volume_t max, pa_channel_map pa_assert(v); - pa_return_val_if_fail(pa_cvolume_valid(v), NULL); - pa_return_val_if_fail(max != (pa_volume_t) -1, NULL); + pa_return_val_if_fail(max != PA_VOLUME_INVALID, NULL); + + if (!cm) + return pa_cvolume_scale(v, max); + + pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, cm), NULL); t = pa_cvolume_max_mask(v, cm, mask); @@ -750,8 +761,6 @@ float pa_cvolume_get_fade(const pa_cvolume *v, const pa_channel_map *map) { pa_assert(v); pa_assert(map); - pa_return_val_if_fail(pa_cvolume_valid(v), 0.0f); - pa_return_val_if_fail(pa_channel_map_valid(map), 0.0f); pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), 0.0f); if (!pa_channel_map_can_fade(map)) @@ -774,12 +783,10 @@ pa_cvolume* pa_cvolume_set_fade(pa_cvolume *v, const pa_channel_map *map, float pa_assert(map); pa_assert(v); - pa_assert(new_fade >= -1.0f); - pa_assert(new_fade <= 1.0f); - pa_return_val_if_fail(pa_cvolume_valid(v), NULL); - pa_return_val_if_fail(pa_channel_map_valid(map), NULL); pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), NULL); + pa_return_val_if_fail(new_fade >= -1.0f, NULL); + pa_return_val_if_fail(new_fade <= 1.0f, NULL); if (!pa_channel_map_can_fade(map)) return v; @@ -827,6 +834,7 @@ pa_cvolume* pa_cvolume_set_position( pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(cv, map), NULL); pa_return_val_if_fail(t < PA_CHANNEL_POSITION_MAX, NULL); + pa_return_val_if_fail(v != PA_VOLUME_INVALID, NULL); for (c = 0; c < map->channels; c++) if (map->map[c] == t) { @@ -883,6 +891,7 @@ pa_cvolume* pa_cvolume_inc(pa_cvolume *v, pa_volume_t inc) { pa_assert(v); pa_return_val_if_fail(pa_cvolume_valid(v), NULL); + pa_return_val_if_fail(inc != PA_VOLUME_INVALID, NULL); m = pa_cvolume_max(v); @@ -900,6 +909,7 @@ pa_cvolume* pa_cvolume_dec(pa_cvolume *v, pa_volume_t dec) { pa_assert(v); pa_return_val_if_fail(pa_cvolume_valid(v), NULL); + pa_return_val_if_fail(dec != PA_VOLUME_INVALID, NULL); m = pa_cvolume_max(v); diff --git a/src/pulse/volume.h b/src/pulse/volume.h index 543b0af1..c964020a 100644 --- a/src/pulse/volume.h +++ b/src/pulse/volume.h @@ -106,11 +106,14 @@ typedef uint32_t pa_volume_t; /** Normal volume (100%, 0 dB) */ #define PA_VOLUME_NORM ((pa_volume_t) 0x10000U) -/** Muted volume (0%, -inf dB) */ +/** Muted (minimal valid) volume (0%, -inf dB) */ #define PA_VOLUME_MUTED ((pa_volume_t) 0U) -/** Maximum volume we can store. \since 0.9.15 */ -#define PA_VOLUME_MAX ((pa_volume_t) UINT32_MAX) +/** Maximum valid volume we can store. \since 0.9.15 */ +#define PA_VOLUME_MAX ((pa_volume_t) UINT32_MAX-1) + +/** Special 'invalid' volume. \since 0.9.16 */ +#define PA_VOLUME_INVALID ((pa_volume_t) UINT32_MAX) /** A structure encapsulating a per-channel volume */ typedef struct pa_cvolume { diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 3c94960c..b57919a4 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -328,7 +328,7 @@ static int pa_cli_command_source_outputs(pa_core *c, pa_tokenizer *t, pa_strbuf static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) { char ss[PA_SAMPLE_SPEC_SNPRINT_MAX]; char cm[PA_CHANNEL_MAP_SNPRINT_MAX]; - char s[256]; + char bytes[PA_BYTES_SNPRINT_MAX]; const pa_mempool_stat *stat; unsigned k; pa_sink *def_sink; @@ -352,22 +352,22 @@ static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b pa_strbuf_printf(buf, "Memory blocks currently allocated: %u, size: %s.\n", (unsigned) pa_atomic_load(&stat->n_allocated), - pa_bytes_snprint(s, sizeof(s), (unsigned) pa_atomic_load(&stat->allocated_size))); + pa_bytes_snprint(bytes, sizeof(bytes), (unsigned) pa_atomic_load(&stat->allocated_size))); pa_strbuf_printf(buf, "Memory blocks allocated during the whole lifetime: %u, size: %s.\n", (unsigned) pa_atomic_load(&stat->n_accumulated), - pa_bytes_snprint(s, sizeof(s), (unsigned) pa_atomic_load(&stat->accumulated_size))); + pa_bytes_snprint(bytes, sizeof(bytes), (unsigned) pa_atomic_load(&stat->accumulated_size))); pa_strbuf_printf(buf, "Memory blocks imported from other processes: %u, size: %s.\n", (unsigned) pa_atomic_load(&stat->n_imported), - pa_bytes_snprint(s, sizeof(s), (unsigned) pa_atomic_load(&stat->imported_size))); + pa_bytes_snprint(bytes, sizeof(bytes), (unsigned) pa_atomic_load(&stat->imported_size))); pa_strbuf_printf(buf, "Memory blocks exported to other processes: %u, size: %s.\n", (unsigned) pa_atomic_load(&stat->n_exported), - pa_bytes_snprint(s, sizeof(s), (unsigned) pa_atomic_load(&stat->exported_size))); + pa_bytes_snprint(bytes, sizeof(bytes), (unsigned) pa_atomic_load(&stat->exported_size))); pa_strbuf_printf(buf, "Total sample cache size: %s.\n", - pa_bytes_snprint(s, sizeof(s), (unsigned) pa_scache_total_size(c))); + pa_bytes_snprint(bytes, sizeof(bytes), (unsigned) pa_scache_total_size(c))); pa_strbuf_printf(buf, "Default sample spec: %s\n", pa_sample_spec_snprint(ss, sizeof(ss), &c->default_sample_spec)); @@ -1549,7 +1549,7 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b pa_sink *sink; pa_source *source; pa_card *card; - int nl; + pa_bool_t nl; uint32_t idx; char txt[256]; time_t now; @@ -1567,7 +1567,7 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b pa_strbuf_printf(buf, "### Configuration dump generated at %s\n", ctime(&now)); #endif - for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx)) { + PA_IDXSET_FOREACH(m, c->modules, idx) { pa_strbuf_printf(buf, "load-module %s", m->name); @@ -1577,13 +1577,12 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b pa_strbuf_puts(buf, "\n"); } - nl = 0; - - for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) { + nl = FALSE; + PA_IDXSET_FOREACH(sink, c->sinks, idx) { if (!nl) { pa_strbuf_puts(buf, "\n"); - nl = 1; + nl = TRUE; } pa_strbuf_printf(buf, "set-sink-volume %s 0x%03x\n", sink->name, pa_cvolume_max(pa_sink_get_volume(sink, FALSE))); @@ -1591,11 +1590,12 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b pa_strbuf_printf(buf, "suspend-sink %s %s\n", sink->name, pa_yes_no(pa_sink_get_state(sink) == PA_SINK_SUSPENDED)); } - for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) { + nl = FALSE; + PA_IDXSET_FOREACH(source, c->sources, idx) { if (!nl) { pa_strbuf_puts(buf, "\n"); - nl = 1; + nl = TRUE; } pa_strbuf_printf(buf, "set-source-volume %s 0x%03x\n", source->name, pa_cvolume_max(pa_source_get_volume(source, FALSE))); @@ -1603,32 +1603,32 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b pa_strbuf_printf(buf, "suspend-source %s %s\n", source->name, pa_yes_no(pa_source_get_state(source) == PA_SOURCE_SUSPENDED)); } - for (card = pa_idxset_first(c->cards, &idx); card; card = pa_idxset_next(c->cards, &idx)) { + nl = FALSE; + PA_IDXSET_FOREACH(card, c->cards, idx) { if (!nl) { pa_strbuf_puts(buf, "\n"); - nl = 1; + nl = TRUE; } if (card->active_profile) pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name); } - nl = 0; - + nl = FALSE; if ((sink = pa_namereg_get_default_sink(c))) { if (!nl) { pa_strbuf_puts(buf, "\n"); - nl = 1; + nl = TRUE; } + pa_strbuf_printf(buf, "set-default-sink %s\n", sink->name); } if ((source = pa_namereg_get_default_source(c))) { - if (!nl) { + if (!nl) pa_strbuf_puts(buf, "\n"); - nl = 1; - } + pa_strbuf_printf(buf, "set-default-source %s\n", source->name); } @@ -1813,8 +1813,6 @@ int pa_cli_command_execute_file(pa_core *c, const char *fn, pa_strbuf *buf, pa_b ret = pa_cli_command_execute_file_stream(c, f, buf, fail); - ret = 0; - fail: if (f) fclose(f); diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c index b4ab23cc..dd4a99ee 100644 --- a/src/pulsecore/conf-parser.c +++ b/src/pulsecore/conf-parser.c @@ -113,7 +113,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const return 0; if (pa_startswith(b, ".include ")) { - char *path, *fn; + char *path = NULL, *fn; int r; fn = strip(b+9); diff --git a/src/pulsecore/core-scache.c b/src/pulsecore/core-scache.c index fde12ecf..1fb81d0d 100644 --- a/src/pulsecore/core-scache.c +++ b/src/pulsecore/core-scache.c @@ -335,12 +335,12 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t pass_volume = TRUE; - if (e->volume_is_set && volume != (pa_volume_t) -1) { + if (e->volume_is_set && volume != PA_VOLUME_INVALID) { pa_cvolume_set(&r, e->sample_spec.channels, volume); pa_sw_cvolume_multiply(&r, &r, &e->volume); } else if (e->volume_is_set) r = e->volume; - else if (volume != (pa_volume_t) -1) + else if (volume != PA_VOLUME_INVALID) pa_cvolume_set(&r, e->sample_spec.channels, volume); else pass_volume = FALSE; diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 1daa46eb..7a9f458c 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -591,13 +591,13 @@ static int set_scheduler(int rtprio) { sp.sched_priority = rtprio; #ifdef SCHED_RESET_ON_FORK - if ((r = pthread_setschedparam(pthread_self(), SCHED_RR|SCHED_RESET_ON_FORK, &sp)) == 0) { + if (pthread_setschedparam(pthread_self(), SCHED_RR|SCHED_RESET_ON_FORK, &sp) == 0) { pa_log_debug("SCHED_RR|SCHED_RESET_ON_FORK worked."); return 0; } #endif - if ((r = pthread_setschedparam(pthread_self(), SCHED_RR, &sp)) == 0) { + if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp) == 0) { pa_log_debug("SCHED_RR worked."); return 0; } @@ -786,7 +786,6 @@ int pa_match(const char *expr, const char *v) { /* Try to parse a boolean string value.*/ int pa_parse_boolean(const char *v) { const char *expr; - int r; pa_assert(v); /* First we check language independant */ @@ -798,12 +797,12 @@ int pa_parse_boolean(const char *v) { /* And then we check language dependant */ if ((expr = nl_langinfo(YESEXPR))) if (expr[0]) - if ((r = pa_match(expr, v)) > 0) + if (pa_match(expr, v) > 0) return 1; if ((expr = nl_langinfo(NOEXPR))) if (expr[0]) - if ((r = pa_match(expr, v)) > 0) + if (pa_match(expr, v) > 0) return 0; errno = EINVAL; @@ -1195,7 +1194,7 @@ char* pa_strip_nl(char *s) { /* Create a temporary lock file and lock it. */ int pa_lock_lockfile(const char *fn) { - int fd = -1; + int fd; pa_assert(fn); for (;;) { @@ -1238,8 +1237,6 @@ int pa_lock_lockfile(const char *fn) { fd = -1; goto fail; } - - fd = -1; } return fd; @@ -2407,7 +2404,7 @@ int pa_reset_sigs(int except, ...) { p[i++] = except; while ((sig = va_arg(ap, int)) >= 0) - sig = p[i++]; + p[i++] = sig; } p[i] = -1; diff --git a/src/pulsecore/cpu-x86.c b/src/pulsecore/cpu-x86.c index 1ba9f1a4..f194a608 100644 --- a/src/pulsecore/cpu-x86.c +++ b/src/pulsecore/cpu-x86.c @@ -115,7 +115,7 @@ void pa_cpu_init_x86 (void) { pa_remap_func_init_mmx (flags); } - if (flags & PA_CPU_X86_SSE) { + if (flags & (PA_CPU_X86_SSE | PA_CPU_X86_SSE2)) { pa_volume_func_init_sse (flags); pa_remap_func_init_sse (flags); pa_convert_func_init_sse (flags); diff --git a/src/pulsecore/flist.c b/src/pulsecore/flist.c index 6fb944f9..7e5ee244 100644 --- a/src/pulsecore/flist.c +++ b/src/pulsecore/flist.c @@ -130,15 +130,22 @@ void pa_flist_free(pa_flist *l, pa_free_cb_t free_cb) { } int pa_flist_push(pa_flist*l, void *p) { - unsigned idx, n, len; + unsigned idx, n; pa_atomic_ptr_t*cells; +#ifdef PROFILE + unsigned len; +#endif pa_assert(l); pa_assert(p); cells = PA_FLIST_CELLS(l); - n = len = l->size + N_EXTRA_SCAN - (unsigned) pa_atomic_load(&l->length); + n = l->size + N_EXTRA_SCAN - (unsigned) pa_atomic_load(&l->length); + +#ifdef PROFILE + len = n; +#endif _Y; idx = reduce(l, (unsigned) pa_atomic_load(&l->write_idx)); @@ -171,14 +178,21 @@ int pa_flist_push(pa_flist*l, void *p) { } void* pa_flist_pop(pa_flist*l) { - unsigned idx, len, n; + unsigned idx, n; pa_atomic_ptr_t *cells; +#ifdef PROFILE + unsigned len; +#endif pa_assert(l); cells = PA_FLIST_CELLS(l); - n = len = (unsigned) pa_atomic_load(&l->length) + N_EXTRA_SCAN; + n = (unsigned) pa_atomic_load(&l->length) + N_EXTRA_SCAN; + +#ifdef PROFILE + len = n; +#endif _Y; idx = reduce(l, (unsigned) pa_atomic_load(&l->read_idx)); diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c index 441b397b..0e40d12b 100644 --- a/src/pulsecore/memblock.c +++ b/src/pulsecore/memblock.c @@ -694,7 +694,7 @@ static void memblock_replace_import(pa_memblock *b) { pa_mempool* pa_mempool_new(pa_bool_t shared, size_t size) { pa_mempool *p; - char t1[64], t2[64]; + char t1[PA_BYTES_SNPRINT_MAX], t2[PA_BYTES_SNPRINT_MAX]; p = pa_xnew(pa_mempool, 1); diff --git a/src/pulsecore/memtrap.c b/src/pulsecore/memtrap.c index c647e507..373872c1 100644 --- a/src/pulsecore/memtrap.c +++ b/src/pulsecore/memtrap.c @@ -200,13 +200,13 @@ pa_memtrap *pa_memtrap_update(pa_memtrap *m, const void *start, size_t size) { goto unlock; memtrap_unlink(m, j); - j = pa_aupdate_write_swap(aupdate); + pa_aupdate_write_swap(aupdate); m->start = (void*) start; m->size = size; pa_atomic_store(&m->bad, 0); - j = pa_aupdate_write_swap(aupdate); + pa_assert_se(pa_aupdate_write_swap(aupdate) == j); memtrap_link(m, j); unlock: diff --git a/src/pulsecore/pid.c b/src/pulsecore/pid.c index 00878462..996946c2 100644 --- a/src/pulsecore/pid.c +++ b/src/pulsecore/pid.c @@ -81,7 +81,7 @@ static pid_t read_pid(const char *fn, int fd) { } static int open_pid_file(const char *fn, int mode) { - int fd = -1; + int fd; pa_assert(fn); @@ -123,8 +123,6 @@ static int open_pid_file(const char *fn, int mode) { fd = -1; goto fail; } - - fd = -1; } return fd; diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c index 480af6d5..2326eb3a 100644 --- a/src/pulsecore/protocol-esound.c +++ b/src/pulsecore/protocol-esound.c @@ -771,7 +771,6 @@ static int esd_proto_stream_pan(connection *c, esd_proto_t request, const void * memcpy(&rvolume, data, sizeof(uint32_t)); rvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, rvolume); - data = (const char*)data + sizeof(uint32_t); if ((conn = pa_idxset_get_by_index(c->protocol->connections, idx)) && conn->sink_input) { pa_cvolume volume; @@ -809,7 +808,6 @@ static int esd_proto_sample_pan(connection *c, esd_proto_t request, const void * memcpy(&rvolume, data, sizeof(uint32_t)); rvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, rvolume); - data = (const char*)data + sizeof(uint32_t); volume.values[0] = (lvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE; volume.values[1] = (rvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE; @@ -1123,7 +1121,7 @@ static int do_read(connection *c) { ssize_t r; size_t l; void *p; - size_t space; + size_t space = 0; pa_assert(c->input_memblockq); diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index d961dba2..17aee4b1 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -628,7 +628,6 @@ static record_stream* record_stream_new( record_stream *s; pa_source_output *source_output = NULL; - size_t base; pa_source_output_new_data data; pa_assert(c); @@ -682,7 +681,7 @@ static record_stream* record_stream_new( 0, s->buffer_attr.maxlength, 0, - base = pa_frame_size(&source_output->sample_spec), + pa_frame_size(&source_output->sample_spec), 1, 0, 0, @@ -2274,6 +2273,8 @@ static void command_exit(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_ta ret = pa_core_exit(c->protocol->core, FALSE, 0); CHECK_VALIDITY(c->pstream, ret >= 0, tag, PA_ERR_ACCESS); + pa_log_debug("Client %s asks us to terminate.", pa_strnull(pa_proplist_gets(c->client->proplist, PA_PROP_APPLICATION_PROCESS_BINARY))); + pa_pstream_send_simple_ack(c->pstream, tag); /* nonsense */ } diff --git a/src/pulsecore/protocol-simple.c b/src/pulsecore/protocol-simple.c index d66db4b7..a9f73896 100644 --- a/src/pulsecore/protocol-simple.c +++ b/src/pulsecore/protocol-simple.c @@ -154,7 +154,7 @@ static int do_read(connection *c) { ssize_t r; size_t l; void *p; - size_t space; + size_t space = 0; connection_assert_ref(c); diff --git a/src/pulsecore/ratelimit.h b/src/pulsecore/ratelimit.h index ec3b5a38..9857a291 100644 --- a/src/pulsecore/ratelimit.h +++ b/src/pulsecore/ratelimit.h @@ -26,21 +26,31 @@ #include <pulsecore/macro.h> typedef struct pa_ratelimit { - const pa_usec_t interval; - const unsigned burst; + pa_usec_t interval; + unsigned burst; unsigned n_printed, n_missed; pa_usec_t begin; } pa_ratelimit; #define PA_DEFINE_RATELIMIT(_name, _interval, _burst) \ pa_ratelimit _name = { \ - .interval = _interval, \ - .burst = _burst, \ + .interval = (_interval), \ + .burst = (_burst), \ .n_printed = 0, \ .n_missed = 0, \ .begin = 0 \ } +#define PA_INIT_RATELIMIT(v, _interval, _burst) \ + do { \ + pa_ratelimit *r = &(v); \ + r->interval = (_interval); \ + r->burst = (_burst); \ + r->n_printed = 0; \ + r->n_missed = 0; \ + r->begin = 0; \ + } while (FALSE); + pa_bool_t pa_ratelimit_test(pa_ratelimit *r); #endif diff --git a/src/pulsecore/remap_mmx.c b/src/pulsecore/remap_mmx.c index 79e4f1fc..d358a58b 100644 --- a/src/pulsecore/remap_mmx.c +++ b/src/pulsecore/remap_mmx.c @@ -150,8 +150,12 @@ static void init_remap_mmx (pa_remap_t *m) { void pa_remap_func_init_mmx (pa_cpu_x86_flag_t flags) { #if defined (__i386__) || defined (__amd64__) - pa_log_info("Initialising MMX optimized remappers."); - pa_set_init_remap_func ((pa_init_remap_func_t) init_remap_mmx); + if (flags & PA_CPU_X86_MMX) { + pa_log_info("Initialising MMX optimized remappers."); + + pa_set_init_remap_func ((pa_init_remap_func_t) init_remap_mmx); + } + #endif /* defined (__i386__) || defined (__amd64__) */ } diff --git a/src/pulsecore/remap_sse.c b/src/pulsecore/remap_sse.c index bf22df7c..0ccf3161 100644 --- a/src/pulsecore/remap_sse.c +++ b/src/pulsecore/remap_sse.c @@ -102,7 +102,7 @@ "4: \n\t" #if defined (__i386__) || defined (__amd64__) -static void remap_mono_to_stereo_sse (pa_remap_t *m, void *dst, const void *src, unsigned n) { +static void remap_mono_to_stereo_sse2 (pa_remap_t *m, void *dst, const void *src, unsigned n) { pa_reg_x86 temp, temp2; switch (*m->format) { @@ -132,7 +132,7 @@ static void remap_mono_to_stereo_sse (pa_remap_t *m, void *dst, const void *src, } /* set the function that will execute the remapping based on the matrices */ -static void init_remap_sse (pa_remap_t *m) { +static void init_remap_sse2 (pa_remap_t *m) { unsigned n_oc, n_ic; n_oc = m->o_ss->channels; @@ -141,7 +141,7 @@ static void init_remap_sse (pa_remap_t *m) { /* find some common channel remappings, fall back to full matrix operation. */ if (n_ic == 1 && n_oc == 2 && m->map_table_f[0][0] >= 1.0 && m->map_table_f[1][0] >= 1.0) { - m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_sse; + m->do_remap = (pa_do_remap_func_t) remap_mono_to_stereo_sse2; pa_log_info("Using SSE mono to stereo remapping"); } } @@ -149,8 +149,11 @@ static void init_remap_sse (pa_remap_t *m) { void pa_remap_func_init_sse (pa_cpu_x86_flag_t flags) { #if defined (__i386__) || defined (__amd64__) - pa_log_info("Initialising SSE optimized remappers."); - pa_set_init_remap_func ((pa_init_remap_func_t) init_remap_sse); + if (flags & PA_CPU_X86_SSE2) { + pa_log_info("Initialising SSE2 optimized remappers."); + pa_set_init_remap_func ((pa_init_remap_func_t) init_remap_sse2); + } + #endif /* defined (__i386__) || defined (__amd64__) */ } diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c index 5fae1928..a26dc876 100644 --- a/src/pulsecore/sample-util.c +++ b/src/pulsecore/sample-util.c @@ -1056,3 +1056,13 @@ void pa_memchunk_sine(pa_memchunk *c, pa_mempool *pool, unsigned rate, unsigned calc_sine(p, c->length, freq * l / rate); pa_memblock_release(c->memblock); } + +size_t pa_convert_size(size_t size, const pa_sample_spec *from, const pa_sample_spec *to) { + pa_usec_t usec; + + pa_assert(from); + pa_assert(to); + + usec = pa_bytes_to_usec_round_up(size, from); + return pa_usec_to_bytes_round_up(usec, to); +} diff --git a/src/pulsecore/sample-util.h b/src/pulsecore/sample-util.h index 34df5cf3..d0235d60 100644 --- a/src/pulsecore/sample-util.h +++ b/src/pulsecore/sample-util.h @@ -91,6 +91,8 @@ typedef void (*pa_do_volume_func_t) (void *samples, void *volumes, unsigned chan pa_do_volume_func_t pa_get_volume_func(pa_sample_format_t f); void pa_set_volume_func(pa_sample_format_t f, pa_do_volume_func_t func); +size_t pa_convert_size(size_t size, const pa_sample_spec *from, const pa_sample_spec *to); + #define PA_CHANNEL_POSITION_MASK_LEFT \ (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_FRONT_LEFT) \ | PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_REAR_LEFT) \ diff --git a/src/pulsecore/sconv_sse.c b/src/pulsecore/sconv_sse.c index 7c3aa199..3737af2a 100644 --- a/src/pulsecore/sconv_sse.c +++ b/src/pulsecore/sconv_sse.c @@ -218,16 +218,18 @@ static void run_test (void) { void pa_convert_func_init_sse (pa_cpu_x86_flag_t flags) { #if defined (__i386__) || defined (__amd64__) - pa_log_info("Initialising SSE optimized conversions."); #ifdef RUN_TEST run_test (); #endif - if (flags & PA_CPU_X86_SSE2) - pa_set_convert_from_float32ne_function (PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_sse2); - else - pa_set_convert_from_float32ne_function (PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_sse); + if (flags & PA_CPU_X86_SSE2) { + pa_log_info("Initialising SSE2 optimized conversions."); + pa_set_convert_from_float32ne_function (PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_sse2); + } else { + pa_log_info("Initialising SSE optimized conversions."); + pa_set_convert_from_float32ne_function (PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_sse); + } #endif /* defined (__i386__) || defined (__amd64__) */ } diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index adda2aff..5f79ab1e 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -1152,7 +1152,6 @@ pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest) { /* Called from main context */ int pa_sink_input_start_move(pa_sink_input *i) { pa_source_output *o, *p = NULL; - pa_sink *origin; int r; pa_sink_input_assert_ref(i); @@ -1166,8 +1165,6 @@ int pa_sink_input_start_move(pa_sink_input *i) { if ((r = pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], i)) < 0) return r; - origin = i->sink; - /* Kill directly connected outputs */ while ((o = pa_idxset_first(i->direct_outputs, NULL))) { pa_assert(o != p); diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c index 24535157..c9cfdbe3 100644 --- a/src/pulsecore/socket-client.c +++ b/src/pulsecore/socket-client.c @@ -202,8 +202,6 @@ static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, pa_io_event } static int do_connect(pa_socket_client *c, const struct sockaddr *sa, socklen_t len) { - int r; - pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); pa_assert(sa); @@ -211,7 +209,7 @@ static int do_connect(pa_socket_client *c, const struct sockaddr *sa, socklen_t pa_make_fd_nonblock(c->fd); - if ((r = connect(c->fd, sa, len)) < 0) { + if (connect(c->fd, sa, len) < 0) { #ifdef OS_IS_WIN32 if (WSAGetLastError() != EWOULDBLOCK) { pa_log_debug("connect(): %d", WSAGetLastError()); diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 8510b0c4..74918e78 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -301,13 +301,16 @@ static void run_test (void) { void pa_volume_func_init_mmx (pa_cpu_x86_flag_t flags) { #if defined (__i386__) || defined (__amd64__) - pa_log_info("Initialising MMX optimized functions."); #ifdef RUN_TEST run_test (); #endif - pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_mmx); - pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_mmx); + if (flags & PA_CPU_X86_MMX) { + pa_log_info("Initialising MMX optimized functions."); + + pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_mmx); + pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_mmx); + } #endif /* defined (__i386__) || defined (__amd64__) */ } diff --git a/src/pulsecore/svolume_sse.c b/src/pulsecore/svolume_sse.c index 54af4a57..bbd73a9b 100644 --- a/src/pulsecore/svolume_sse.c +++ b/src/pulsecore/svolume_sse.c @@ -75,7 +75,7 @@ " por %%xmm5, "#s2" \n\t" static void -pa_volume_s16ne_sse (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) +pa_volume_s16ne_sse2 (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { pa_reg_x86 channel, temp; @@ -155,7 +155,7 @@ pa_volume_s16ne_sse (int16_t *samples, int32_t *volumes, unsigned channels, unsi } static void -pa_volume_s16re_sse (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) +pa_volume_s16re_sse2 (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { pa_reg_x86 channel, temp; @@ -302,13 +302,16 @@ static void run_test (void) { void pa_volume_func_init_sse (pa_cpu_x86_flag_t flags) { #if defined (__i386__) || defined (__amd64__) - pa_log_info("Initialising SSE optimized functions."); #ifdef RUN_TEST run_test (); #endif - pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_sse); - pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_sse); + if (flags & PA_CPU_X86_SSE2) { + pa_log_info("Initialising SSE2 optimized functions."); + + pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_sse2); + pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_sse2); + } #endif /* defined (__i386__) || defined (__amd64__) */ } diff --git a/src/pulsecore/vector.h b/src/pulsecore/vector.h index 924e3cb8..9de3b8cd 100644 --- a/src/pulsecore/vector.h +++ b/src/pulsecore/vector.h @@ -23,7 +23,8 @@ #include <inttypes.h> /* First, define HAVE_VECTOR if we have the gcc vector extensions at all */ -#if defined(__SSE2__) || defined(__ALTIVEC__) +#if defined(__SSE2__) + /* || defined(__ALTIVEC__)*/ #define HAVE_VECTOR diff --git a/src/tests/stripnul.c b/src/tests/stripnul.c index 1d8c4938..d677ad20 100644 --- a/src/tests/stripnul.c +++ b/src/tests/stripnul.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) { FILE *i, *o; size_t granularity; - pa_bool_t found; + pa_bool_t found = FALSE; uint8_t *zero; pa_assert_se(argc >= 2); diff --git a/src/utils/pacat.c b/src/utils/pacat.c index 9264a062..781bfa33 100644 --- a/src/utils/pacat.c +++ b/src/utils/pacat.c @@ -406,7 +406,6 @@ static void context_state_callback(pa_context *c, void *userdata) { break; case PA_CONTEXT_READY: { - int r; pa_buffer_attr buffer_attr; pa_assert(c); @@ -443,13 +442,13 @@ static void context_state_callback(pa_context *c, void *userdata) { if (mode == PLAYBACK) { pa_cvolume cv; - if ((r = pa_stream_connect_playback(stream, device, latency > 0 ? &buffer_attr : NULL, flags, volume_is_set ? pa_cvolume_set(&cv, sample_spec.channels, volume) : NULL, NULL)) < 0) { + if (pa_stream_connect_playback(stream, device, latency > 0 ? &buffer_attr : NULL, flags, volume_is_set ? pa_cvolume_set(&cv, sample_spec.channels, volume) : NULL, NULL) < 0) { pa_log(_("pa_stream_connect_playback() failed: %s"), pa_strerror(pa_context_errno(c))); goto fail; } } else { - if ((r = pa_stream_connect_record(stream, device, latency > 0 ? &buffer_attr : NULL, flags)) < 0) { + if (pa_stream_connect_record(stream, device, latency > 0 ? &buffer_attr : NULL, flags) < 0) { pa_log(_("pa_stream_connect_record() failed: %s"), pa_strerror(pa_context_errno(c))); goto fail; } @@ -574,9 +573,10 @@ static void stream_update_timing_callback(pa_stream *s, int success, void *userd return; } - pa_log(_("Time: %0.3f sec; Latency: %0.0f usec. \r"), + fprintf(stderr, _("Time: %0.3f sec; Latency: %0.0f usec."), (float) usec / 1000000, (float) l * (negative?-1.0f:1.0f)); + fprintf(stderr, " \r"); } /* Someone requested that the latency is shown */ @@ -768,7 +768,6 @@ int main(int argc, char *argv[]) { case ARG_STREAM_NAME: { char *t; - t = pa_locale_to_utf8(optarg); if (!(t = pa_locale_to_utf8(optarg)) || pa_proplist_sets(proplist, PA_PROP_MEDIA_NAME, t) < 0) { diff --git a/src/utils/pactl.c b/src/utils/pactl.c index b8f4ea75..141ab5b1 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -130,7 +130,7 @@ static void complete_action(void) { } static void stat_callback(pa_context *c, const pa_stat_info *i, void *userdata) { - char s[128]; + char s[PA_BYTES_SNPRINT_MAX]; if (!i) { pa_log(_("Failed to get statistics: %s"), pa_strerror(pa_context_errno(c))); quit(1); @@ -598,7 +598,7 @@ static void get_source_output_info_callback(pa_context *c, const pa_source_outpu } static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int is_last, void *userdata) { - char t[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; + char t[PA_BYTES_SNPRINT_MAX], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; char *pl; if (is_last < 0) { diff --git a/src/utils/padsp.c b/src/utils/padsp.c index 882522c4..41bfd741 100644 --- a/src/utils/padsp.c +++ b/src/utils/padsp.c @@ -1821,7 +1821,7 @@ fail: pa_threaded_mainloop_unlock(i->mainloop); - return 0; + return r; } static int dsp_trigger(fd_info *i) { @@ -1864,7 +1864,7 @@ fail: pa_threaded_mainloop_unlock(i->mainloop); - return 0; + return r; } static int dsp_cork(fd_info *i, pa_stream *s, int b) { @@ -1902,7 +1902,7 @@ fail: pa_threaded_mainloop_unlock(i->mainloop); - return 0; + return r; } static int dsp_ioctl(fd_info *i, unsigned long request, void*argp, int *_errno) { |