summaryrefslogtreecommitdiff
path: root/alsa_write.c (follow)
Commit message (Collapse)AuthorAge
* Switch to SPDX identifiers.Andre Noll2026-03-17
| | | | | | | | Generated with sed -i 's|Copyright.*Andre Noll.*|SPDX-License-Identifier: GPL-2.0 */|g' *.c *.h followed by manually tweaking the result a bit. No license change intended.
* doxygen: Hide user_data variables.Andre Noll2025-10-08
| | | | | These just clutter the generated documentation, particularly the list of global variables.
* Include regex.h from para.h.Andre Noll2025-05-19
| | | | Every .c file includes it anyway.
* New audio formats: 32 bit float (little and big endian).Andre Noll2024-09-15
| | | | | | | | | | | | | | | | | | | At least the little endian version seems to be popular these days. It is only supported by ALSA, however. To check whether a given wave file employs one of the two SF_FLOAT formats (aka IEEE float) we have to consult the format code, a 16 bit integer stored at offset 20 of the wave header which describes the waveform data according to the table below. 0x0001 PCM 0x0003 IEEE float 0x0006 8-bit ITU-T G.711 A-law 0x0007 8-bit ITU-T G.711 MU-law 0xFFFE Determined by SubFormat Additional checks are added to check_wav_post_select() which make sure that the format code is either 1 or 3, and that the number is compatible with the bits per sample value.
* Consolidate EOF error codes.Andre Noll2023-03-11
| | | | | | Currently we have ~15 error codes which indicate an EOF condition. One should suffice, so drop all codes except the generic E_EOF and use that everywhere.
* Merge topic branch t/overflow into masterAndre Noll2022-10-03
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This series implements a new memory allocation API which checks for overflows. The first part of the series just renames the main allocation functions. Later patches in the series implement allocators which take two size_t arguments (like calloc(3)) and check whether the multiplication overflows by employing the __builtin_mul_overflow() primitive supported by gcc and clang. This requires us to bump the lowest supported gcc and clang version. * refs/heads/t/overflow: build: Compile with -ftrapv. string: Introduce arr_zalloc(). string: Introduce arr_alloc(). string: Introduce arr_realloc() and check for integer overflow. string: Rename para_calloc() -> zalloc(). string: Rename para_malloc() -> alloc(). string: Overhaul para_strdup().
| * string: Rename para_calloc() -> zalloc().Andre Noll2022-07-29
| | | | | | | | | | Reword the documentation a bit since the function has never been a wrapper for calloc(3). No code changes.
* | Rename ->{pre,post}_select methods to ->{pre,post}_monitor.Andre Noll2022-08-25
| | | | | | | | | | | | | | The word "monitor" is neutral and continues to be correct after the switch from select(2) to poll(2). Pure rename, nothing to see here.
* | Misc documentation cleanups related to select().Andre Noll2022-08-25
| | | | | | | | | | Assorted comment cleanups which avoid to talk about select(2) and fd sets. No code changes.
* | Hide implementation of para_fd_set().Andre Noll2022-08-25
| | | | | | | | | | | | | | | | This preparatory patch for replacing select() renames para_fd_set() to sched_fd_set(), moves it to sched.c and makes it static. All users are modified to call either of the two new public functions sched_monitor_{read,write}fd() which take a pointer to struct sched rather than an fd set pointer.
* | sched: Introduce sched_{read,write}_ok().Andre Noll2022-08-25
|/ | | | | Two trivial wrappers for FD_ISSET() which hide the fact that we're still using the select(2) API.
* alsa_write: Avoid spurious underrun warnings.Andre Noll2021-10-21
| | | | | Receiving EPIPE does not necessarily mean that an underrun occurred. We also have to check the pcm state.
* Teach writers to abort gracefully on early EOF.Andre Noll2021-10-21
| | | | | | | | | | | | | | | | | | | | For very short streams it may happen that the receiver and decoder unregister themselves from the buffer tree before the writer had a chance to query the information from the decoder which it needs to open the audio device. This leads to errors such as Aug 25 14:24:51 schubert (5) get_btr_value: cmd sample_rate: Operation not supported Aug 25 14:24:51 schubert (5) get_btr_value: cmd channels: Operation not supported Aug 25 14:24:51 schubert (5) get_btr_value: cmd sample_format: Operation not supported Aug 25 14:24:51 schubert (4) alsa_init: channels count not available: Invalid argument This may happen with all receivers, audio formats and writers, although it is most common with ogg streams. This commit changes get_btr_sample_rate() and friends to return a standard error code rather than assuming success. The alsa, ao and oss writers are patched to check the return value and fail gracefully if one of these functions fails.
* alsa_write: Simplify alsa_post_select().Andre Noll2021-10-21
| | | | | | Clean up the private alsa data structure in alsa_close() and teach this function to DTRT even if pad->handle is NULL because alsa_init() failed.
* alsa_write: Avoid hung tasks.Andre Noll2021-01-08
| | | | | | | Without this fix the alsa writer may never shutdown, occupying a slot of audiod. The hang was observed with in conjunction to the udp receiver and the prebuffer filter. See also the recent commit 23913cbbfc98.
* Shorten copyright notice.Andre Noll2017-09-22
| | | | | | | | | | | | | | | | | | | | | The GPLv2 line does not add any additional information, so drop it. This leaves a single line of legalese text for most files, which is about the amount of screen real estate it deserves. This patch was created with the following script (plus some manual fixups): awk '{ if (NR <= 5) { gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g") if (gs != $0) year = gs next } if (NR == 6 && year != "") printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year) print }'
* Convert writers to lopsub.Andre Noll2017-03-26
| | | | | | | | | | | | | | | | | | | | | Similar to the previous commits for receivers and filters, this commit replaces the five gengetopt parsers for the alsa, ao, file, oss, osx writers by a lopsub suite and links para_write with -llopsub. This allows to get rid of the WRITER_ENUM and the writers array as a reference to each writer structure are stored in the lopsub user_data pointer. Moreover, ->init(), ->parse_config(), ->free_config() and ->ggo_help() of struct writer are not needed any more and can be removed. The patch also removes write_common.h and moves the few prototypes write.h. Now that receivers, filters and writers have all been converted, we may also stop to include ggo.h from audiod_command.c and play.c. As for the receivers and filters, t0005 needs slight adjustments due to the new section header in the man page.
* Fix signedness issues in format strings.Andre Noll2016-12-04
| | | | | | | | | | | | | | Compiling with -Wformat-signedness (not enabled so far) causes many warnings because of format strings which specify an unsigned type but correspond to an argument of signed type, or vice versa. This commit fixes all these mismatches. For "%u", "%d", "%lu", "%ld" we let the format string match the type of the argument, but for "%x" we need to cast the argument to a suitable unsigned type. After this patch the tree compiles cleanly with -Wformat-signedness given. The warning will be enabled in a subsequent commit.
* alsa: Avoid alloca().Andre Noll2015-04-04
| | | | | | It is not in POSIX.1-2001, and its use is discouraged. Fortunately, the alsa library provides also variants which call ordinary malloc(), so use these instead.
* alsa_write: Use NULL instead of 0.Andre Noll2015-01-25
| | | | | | This silences the following sparse warning: sparse: alsa_write.c:128:31: warning: Using plain integer as NULL pointer
* Update year in copyright headers.Andre Noll2015-01-12
| | | | | | | | | | | | | | | | Done with files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2014\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2014 Andre Noll/Copyright (C) \1 Andre Noll/1' $files In previous years we ran a similar script to set the second year in the range to the current year. This is kind of silly, so let's get rid of this useless information. This commit replaces "Copyright (C) A-B" by "Copyright (C) A" in all file headers, i.e. only the first year (A) is left in. Accurate information including time stamps for each change can be obtained from the git history.
* doc: Change email address to maan@tuebingen.mpg.deAndre Noll2014-08-18
| | | | | | | | | | | | | | The mail server on systemlinux.org was down for more than a week lately, so let's use an alternative official address. This commit changes all maan@systemlinux.org addresses to maan@tuebingen.mpg.de. Most .c and .h files contain the email address in the copyright header, so they must all be patched. Three other files contain the address for a different reason: * README lists email and git, gitweb and home page URLs * configure.ac needs it for configure -h * version.c contains it for the -V option of all commands
* sched: Directly pass context pointer to pre/post_select().Andre Noll2014-05-25
| | | | | | | | | | | | | | | The patch is large, but it's fairly straight forward: Instead of a task pointer all ->pre_select() and ->post_select() methods now receive the context pointer that was passed to the scheduler when the task was registered. This allows to kill the public task_context(). Two pre_select/post_select functions are not directly called by the scheduler: session_post_select(), generic_recv_pre_select(). These are changed to receive a proper struct rather than a void pointer. Note that generic_filter_pre_select() is not changed in this manner because some filters do not provide a pre_select wrapper but set task->pre_select to generic_filter_pre_select().
* task_register() conversion: writersAndre Noll2014-05-25
|
* Merge branch 't/alsa_improvements'Andre Noll2014-05-03
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Was cooking for almost two months. * t/alsa_improvements: alsa: Remove pointless initialization. alsa_mix: Allow non-positive mixer values. alsa: New writer option: --buffer-time. alsa: Work around poll fd problems. alsa: Set period time. alsa: Also dump hardware params. alsa: Improve help text of --device. alsa: Improve documentation of struct private_alsa_write_data. alsa: Don't set t->error in ->pre_select().
| * alsa: Remove pointless initialization.Andre Noll2014-03-08
| | | | | | | | The value stored in msg is never read. Found by the clang analyzer.
| * alsa: New writer option: --buffer-time.Andre Noll2014-03-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes the old way of setting of private_alsa_write_data->buffer_time Currently we set the buffer time to the minimum of the maximum buffer time and 500ms. This results in different values for different hardware. In view of the introduction of the sync filter it seems to be desirable to have more control over this value. This patch adds the --buffer-time config option to the alsa writer which allows to specify a suitable value, the default being 170ms. The unit of private_alsa_write_data->buffer_time is changed from microseconds to milliseconds as this avoids to divide by 1000 in ->pre_select().
| * alsa: Work around poll fd problems.Andre Noll2014-03-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In its ->pre_select method the alsa writer adds the alsa poll file descriptor to the set of fds to be monitored during the next select call. When this fd is ready for I/O, select() returns and ->post_select is called. Currently ->post_select checks if the alsa poll fd is set and returns early if it is not. The problem is that on some hardware/kernel/alsa-lib combinations, the poll fd is never marked as ready for I/O. This happens at least on the raspberry pi with linux-3.10.10 and alsa-lib-1.0.27. The result is no audio at all. We address this problem in two ways: * In alsa_init() we remember the buffer duration for later use in ->pre_select where we ask the scheduler to impose half of the duration as an upper bound on the select timeout. * In ->post_select, if there is input data available, we don't check any more whether the poll fd is ready but try to write unconditionally. On EAGAIN, we read from the poll fd to discard any pending events.
| * alsa: Set period time.Andre Noll2014-03-08
| | | | | | | | | | This is probably not necessary, but since aplay from the alsa-utils package sets it in the same way, it can't hurt to do this.
| * alsa: Also dump hardware params.Andre Noll2014-03-08
| | | | | | | | | | Since this makes the alsa output even more verbose, let's downgrade the loglevel of config dump messages to DEBUG.
| * alsa: Improve documentation of struct private_alsa_write_data.Andre Noll2014-03-08
| | | | | | | | | | Remove the stale reference to writer node groups and explain how sample_rate and channel count are determined.
| * alsa: Don't set t->error in ->pre_select().Andre Noll2014-03-08
| | | | | | | | | | ->pre_select() methods should never fail, and tasks should not set this variable at all. It is ignored anyway when set there.
* | Change copyright year to 2014.Andre Noll2014-02-22
|/ | | | | | | | | This year, we're really on time. The changes in this patch were created by the following silly script: files=$(git grep -l 'Copyright (C) [0-9]\{4\}\(-2013\)* Andre Noll') sed --in-place= -e 's/Copyright (C) \([0-9]\{4\}\)-2013 Andre Noll/Copyright (C) \1-2014 Andre Noll/1' $files sed --in-place= -e 's/Copyright (C) 2013 Andre Noll/Copyright (C) 2013-2014 Andre Noll/1' $files
* Revamp ggo help.Andre Noll2013-06-13
| | | | | | | | | | | | | This adds usage and description fields to struct ggo_help and changes ggo_print_help() to optionally print these. The boolean detailed_help flag of ggo_print_help() is replaced by a bitmask which lets the caller specify what to print. Four pre-defined masks are used to print the normal help, the detailed help, the help for modules (receivers, filters, writers) and the detailed module help. The new macro DEFINE_GGO_HELP can be employed to create a struct ggo_help from a gengetopt structure.
* alsa writer: Do not print uninitialized data.Andre Noll2013-05-19
| | | | | | | | | | | | | | ALSA's snd_output_buffer_string() returns the current size of valid data in the returned data buffer, but this buffer is not guaranteed to be zero-terminated. Currently alsa_init() ignores this fact and prints the buffer up to the first NULL byte. Therefore it may print garbage that follows the valid data in the buffer. If there is no zero byte after the data, it may even segfault. Fix this bug by using memchr() instead of strchr() and carefully tracking the number of bytes processed.
* sched: Rename new_post_select back to post_select.Andre Noll2013-04-30
|
* sched: Kill old ->post_select variant.Andre Noll2013-04-30
| | | | It has no more users.
* alsa: Switch to the alternative post select method.Andre Noll2013-04-30
|
* Replace gettimeofday() by clock_gettime().Andre Noll2013-04-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | POSIX.1-2008 marks gettimeofday() as obsolete, so let's switch to clock_gettime(). clock_gettime() operates on timespecs rather than on timevals like gettimeofday() does. Since timevals are extensively used in all parts of paraslash, and select() takes a timeval pointer as the timeout parameter, it seems to be easiest to add a new wrapper, clock_get_realtime(). It calls clock_gettime(), performs error checking (all errors are treated fatal and abort the program), and converts the result to a timeval. Another difference between gettimeofday() and clock_gettime() is that sys/time.h needs to be included for gettimeofday(), while clock_gettime() is declared in time.h which gets included from para.h. Hence we can remove the include statement for sys/time.h everywhere. Programs which call clock_gettime need to be linked against librt on glibc versions before 2.17 while BSD and newer glibc-based systems have no such requirement. To make matters more interesting, MacOS lacks clock_gettime() completely although this function conforms to SUSv2 and POSIX.1-2001. We'd like to avoid the unnecessary dependence on librt on systems that have clock_gettime() in -lc, and we must fall back to gettimeofday() on MacOS. Hence this commit also introduces a check in configure.ac which determines whether clock_gettime() is available and, if it is, whether -lrt is needed. Executables are only linked with -lrt if configure found that this is necessary.
* Change copyright year to 2013.Andre Noll2013-03-25
| | | | Better late than never.
* Make writer nodes honor notifications.Andre Noll2012-11-18
| | | | | | Currently, nobody is notifying any writer node but the para_play executable, which will be introduced in subsequent patches, will use this facility to terminate the audio stream.
* Simplify ggo makefile.Andre Noll2012-08-27
| | | | | | | | | | | | | Currently we have three different targets for creating *_cmdline.[ch] files. This is because receivers, filters and writers need slightly different command line options. This patch defines the common options in the ggo makefile and moves additional parameters to the individual .m4 files so that a single target to create *_cmdline.[ch] is now sufficient. The name of the command line parsers of some filters and writers changed due to this unification, so these are updated accordingly.
* write: Get rid of gengetopt's string parser.Andre Noll2012-08-27
| | | | | | | | | | | | | It causes gengetopt to generate quite some additional code for the string parsers of all writers. Moreover, this string parser is inferior to create_argv() and create_shifted_argv() of string.c as gengetopt's parser does not honor any quoting at all. This commit changes the signature of the ->parse_config_or_die method of struct writer to take an (argc, argv) pair instead of a string. All writers can thus call the vanilla command line parser of gengetopt. The single user in write_common.c now calls ->parse_config_or_die() with an (argc, argv) pair obtained from create_shifted_argv().
* Merge branch 't/btr_improvements'Andre Noll2012-07-19
|\ | | | | | | | | | | | | | | 146316 btr_exec_up(): Also ask given node. 6d9c35 btr: Introduce btr_add_output_dont_free(). 4ac313 btr: Remove btr_free_node(). Has been cooking in next for a week.
| * btr: Remove btr_free_node().Andre Noll2012-07-08
| | | | | | | | | | | | | | | | | | This has turned out to be source for bugs. Deallocate everything in btr_remove_node() hence making removing the node and freeing its resources an atomic operation. To avoid dangling pointers to freed btrn nodes, the argument of btr_remove_node() is changed to to struct btr_node **btrnp.
* | Merge branch 't/old_gcc_fixes'Andre Noll2012-07-15
|\ \ | |/ |/| | | | | | | | | 82d304 buffer_tree.h: Fix gcc warning. 5535f6 alsa: Fix gcc warning. Simple enough and well tested with no regressions found.
| * alsa: Fix gcc warning.Andre Noll2012-06-26
| | | | | | | | | | | | | | | | gcc-3.3.3 complains about the local variable "log" in alsa_write.c: alsa_write.c:75: warning: declaration of `log' shadows a global declaration Rename this variable to "output_log" to silence the warning.
* | write: Remove ->shutdown.Andre Noll2012-07-08
| | | | | | | | | | No writer implements this method, and nobody even looks at this pointer. Remove it.
* | alsa: Do not buffer more than 500ms.Andre Noll2012-06-17
|/ | | | | | | | | In alsa_init() we set the buffer time to the maximum value supported by the device. However, on some systems this time is more than 10 seconds, which is much too high. This patch changes alsa_init() to use a buffer time of at most 0.5 seconds.
* Change year in copyright message to 2012.Andre Noll2012-01-07
|