Andre Noll [Sat, 4 May 2013 16:13:56 +0000 (18:13 +0200)]
aacdec: Fix check of return value of NeAACDecInit2().
This function returns (char)-1 on errors and zero on success. Checking
whether the return value is negative is incorrect on systems where
char is unsigned. On raspberry/ARM, gcc complains:
aacdec_filter.c:126:6: warning: comparison is always false due to limited range of data type [-Wtype-limits]
Andre Noll [Mon, 25 Mar 2013 18:02:54 +0000 (18:02 +0000)]
string: Add discard feature for for_each_line().
This adds the new FELF_DISCARD_FIRST flag which instructs
for_each_line() to discard everything up to the next newline.
The new feature is only used by para_gui. When para_gui detects
a partial overlong input line, it ignores this data and passes the
FELF_DISCARD_FIRST flag in subsequent calls to for_each_line(). Hence
output continues at the next line.
Andre Noll [Mon, 25 Mar 2013 16:10:28 +0000 (16:10 +0000)]
string: Clean up for_each_line() and related functions.
While for_each_complete_line() is a static function, there are two
public functions, for_each_line() and for_each_line_ro(), which are
implemented as simple wrappers for the static one. The only difference
between the two is that for_each_line_ro() sets the FELF_READ_ONLY
bit while for_each_line() does not.
Since we are about to add another bit of information soon, let's make
the bitmap and the static function public, and remove the two wrappers.
All callers are changed to pass an additional "unsigned flags" to
indicate whether they want the read-only behavior.
Andre Noll [Mon, 25 Mar 2013 15:36:10 +0000 (15:36 +0000)]
string: Replace the for_each_line_modes enum by a bitmap.
Currently we pass an "enum for_each_line_modes" as the first argument
to for_each_complete_line(). The parameter is effectively a boolean
since the enumeration defines only two possible values.
For the upcoming discard feature of for_each_line_modes() we'll need
to pass another bit of information, so this patch changes the type of
the first argument to for_each_complete_line() to unsigned and treats
it as a bit array. The only bit defined so far is LINE_MODE_RO, with
unchanged semantics.
The two callers are updated to reflect this change.
Andre Noll [Wed, 27 Mar 2013 20:49:40 +0000 (20:49 +0000)]
gui: Don't sleep before executing the status command.
This results in uncacceptable delays when the status command fails
for any reason, for example because the server is down.
Replace this code by introducing a struct timeval variable "next_exec",
which stores the earliest possible time to restart the status command.
Move all status fetching code before the select() call in do_select()
to open_stat_pipe() and rename the function to status_pre_select(),
which is more appropriate.
Andre Noll [Mon, 25 Mar 2013 03:08:12 +0000 (03:08 +0000)]
gui: Rename do_exit().
This function sends SIGTERM to every process in the process group of
para_gui and dies thereafter. So kill_pg_and_die() is more descriptive
than the old name.
Andre Noll [Mon, 18 Mar 2013 19:13:35 +0000 (20:13 +0100)]
gui: Discard overlong input lines.
If an external command produces output without newlines, the current
code ends up calling read_nonblock() with a buffer size of zero which
triggers the assertion in readv_nonblock().
Increase the output buffer to 32K and fix the problem by simply
discarding all input if the input buffer is full and contains no
newline character.
A better fix would be to discard everything until the next newline
character is read, but this requires more work, so let's go with this
simple fix for now.
Andre Noll [Sun, 31 Mar 2013 12:32:07 +0000 (12:32 +0000)]
sched: Provide alternative post_select variant.
Code which accesses the ->error field of another task has been
a source of bugs in the past. This patch is a first step to make
->error private to sched.c.
Currently the ->post_select() methods of all tasks are supposed
to set ->error to a negative value to indicate that the task
should be terminated, i.e. t->error being negative instructs the
scheduler to not call t->pre_select() or t->post_select() any more
in subsequent iterations. An equivalent way to achieve the same
is to let ->post_select() return an error code instead. Benefits
include
* It reduces the use of ->error outside of sched.c
* It's impossible to miss setting the error code
* It simplifies code slightly
Therefore we'd like to change the prototype of the ->post_select()
methods from
void (*post_select)(struct sched *s, struct task *t);
to
int (*post_select)(struct sched *s, struct task *t);
Changes to struct sched affects many parts of the code base,
hence converting all users at once would result in a very
large patch. Therefore we temporarily introduce an additional
->new_post_select() method according to the second declaration
above. The scheduler calls the new method if it is defined and falls
back to the old variant otherwise. This approach allows to switch
over one task after another without breaking things.
This patch introduces the infrastructure just described and switches
over the http receiver. Subsequent commits will change all other tasks
in the same way. After all tasks have been switched over we can get
rid of the old ->post_select variant and rename ->new_post_select()
back to ->post_select().
Andre Noll [Sun, 31 Mar 2013 02:03:04 +0000 (02:03 +0000)]
Replace gettimeofday() by clock_gettime().
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.
Andre Noll [Tue, 2 Apr 2013 17:10:08 +0000 (17:10 +0000)]
compress: Further optimize inner loop.
This kills the local adjusted_sample variable of the inner loop of
compress_post_select(). Surprisingly enough, this saves another 5%
of execution time.
Andre Noll [Tue, 2 Apr 2013 15:02:09 +0000 (15:02 +0000)]
compress: Avoid PARA_ABS and PARA_MAX in inner loop.
These macros are type-safe and evaluate their arguments only once.
However, they are also slow. For the compress filter we are dealing
with ints and unsigned ints only, so the additional checks performed
by the macros only slow things down. Getting rid of the macros reduces
the running time of
Andre Noll [Tue, 2 Apr 2013 14:46:35 +0000 (14:46 +0000)]
compress: Compile with -O3.
By default all objects are compiled with -Os. For the compress filter,
which has to deal with large amounts of uncompressed audio data,
gcc emits rather inefficient code. Switching to -O3 resulted in a 10%
performance improvement on my Lenovo laptop.
Andre Noll [Sat, 30 Mar 2013 22:43:38 +0000 (22:43 +0000)]
sched: Get rid of (pre)select shortcuts.
These shortcuts let the scheduler skip any subsequent ->pre_select()
calls as well as the actual call to select(2) if the current task's
->pre_select() requested a zero timeout.
This idea turned out to be dubios at best. The main problem is that
->post_select no longer knows whether ->pre_select() and select()
have been called. For example, if ->pre_select() monitors some file
descriptor, ->post_select() might find it not ready for I/O even when
it actually is because ->pre_select() or select() was optimized away.
Another problem are tasks whose ->post_select() method expects that
->pre_select() sets some variable in a shared data structure.
This patch removes the scheduler optimizations so that all
->pre_select() methods of all tasks are called once per scheduler
interval.
Andre Noll [Sun, 31 Mar 2013 14:58:18 +0000 (14:58 +0000)]
audiod: Avoid delay when closing slot.
Currently we might wait up to a full scheduler interval until a slot
is closed.
This commit changes the pre_select method of the status task to check
whether some slot can be closed. In this case it requests a minimal
delay from the scheduler.
The current try_to_close_slot() is split into two functions,
must_close_slot() and close_unused_slots(). The former function is
called from ->pre_select(). It only checks whether a slot must be
closed but performs no action.
The latter function, close_unused_slots() probes all slots and closes
those for which must_close_slot() returns true.
Andre Noll [Wed, 27 Mar 2013 02:51:38 +0000 (02:51 +0000)]
configure.ac: Shorten config summary.
With many filters/writers the output line becomes rather long.
Moreover, filters and writers are also used by para_play but para_play
is not mentionend in the prefix. Just skip the prefix.
Andre Noll [Thu, 4 Apr 2013 17:00:01 +0000 (17:00 +0000)]
Add documentation of public functions in check_wav.c.
The init, shutdown, pre_select and post_select functions of this
file are exported via check_wav.h, so they should be documented. This
commit adds doxygen comments for all of them.
Andre Noll [Tue, 24 Jul 2012 06:14:12 +0000 (08:14 +0200)]
Allow addblob commands to create output.
Currently all addblob commands remain silent even on fatal errors
because para_client either reads the command output, or sends its
stdin, but never both.
This patch overcomes this shortcoming. It makes para_client create
two buffer trees instead of one. The client states CL_SENT_COMMAND
and CL_RECEIVING are replaced by a single CL_EXECUTING state.
Blob data is now sent as a sideband packet. The change breaks
compatibility with earlier 0.4.x versions again, but that's OK as
this is 0.5.0 material anyway.
Andre Noll [Tue, 24 Jul 2012 06:11:24 +0000 (08:11 +0200)]
client: Remove client_recv_buffer().
After the cleanup of the previous patch, only a single caller of
this function remains. It calls client_recv_buffer() when the client
state is CL_CONNECTED, in which case the function is just a wrapper
for read_nonblock(). So we may as well call read_nonblock() directly
and get rid of client_recv_buffer().
Andre Noll [Mon, 23 Jul 2012 17:07:07 +0000 (19:07 +0200)]
Reject non-sideband connections.
This makes the client abort the connection if the server does not
support sideband. Conversely, the server closes the socket if the
client did not request a sideband connection.
This breaks compatibility with earlier versions of para_server and
para_client but allows to clean up the code considerably.
Andre Noll [Sun, 10 Mar 2013 14:53:05 +0000 (15:53 +0100)]
blob: Avoid zero sized memcpy().
Calling memcpy() with a size argument of zero is a noop on Linux,
so this should be OK. However, memcpy(3) does not say anything about
this case, so let's be conservative here and call it only if there is
anything to copy.
Andre Noll [Sun, 27 Jan 2013 18:12:57 +0000 (19:12 +0100)]
Fix mood reload.
There was some confusion about how to determine whether the dummy mode
is currently active. At some places we tested if current_mood is NULL,
at others if current_mood->name is NULL. In fact neither check works:
* if a playlist is open, current_mood is NULL (but the dummy
mood is not loaded),
* loading the dummy mood currently sets current_mood->name to
"(dummy)".
This patch makes the latter variant the official one and fixes up
the code accordingly.
This also fixes the critical log message
Jan 27 18:57:29 (5) (13487) afs_event: table moods, event 9: key not found in rbtree
which occured if the dummy mood was active while an event caused the
mood to be reloaded.
Andre Noll [Tue, 1 Jan 2013 23:20:04 +0000 (23:20 +0000)]
afs: Add assertion to afs_cb_result_handler().
If cc is NULL we always have a bug, so it's OK to dereference this
pointer unconditionally. However, if the command handler crashes
due to cc being NULL, it is not obvious what has happened, so make
this explicit.
Andre Noll [Sat, 9 Feb 2013 18:29:14 +0000 (19:29 +0100)]
signal: Restore errno on exit from signal handler.
This probably is not necessary since generic_signal_handler() calls
exit(3) if the write to the signal pipe fails. However, nobody is
going to stop write(2) from setting errno also on success, so let's
play safe and always restore its value on exit.
Andre Noll [Mon, 31 Dec 2012 00:10:50 +0000 (00:10 +0000)]
Speed up dep target.
By default "make" removes intermediate files during the build. However,
some of the files generated by gengetopt are needed again later for
a different target.
This patch declares these generated files as "precious", so they
will no longer be removed. On one system the build time went down
from 30s to 25s due to this one-liner.
Andre Noll [Sun, 3 Jun 2012 21:22:13 +0000 (23:22 +0200)]
gui: Try to link against libncursesw.
This variant of the curses library supports wide characters so we
should link against it if it is available. If it is not, we may still
fall back to libcurses instead.
Andre Noll [Sun, 3 Jun 2012 12:08:55 +0000 (14:08 +0200)]
UTF-8 support for para_gui.
This adds two public helper functions to string.c which operate on
multibyte strings if the character encoding used in the selected
locale is UTF-8.
The first new helper, strwidth(), computes the width of the UTF-8
string while skip_cells() determines the number of bytes the given
multibyte string must be advanced in order to skip the given number
of cells.
para_gui is changed to use the new functions to properly display
UTF-8 encoded data in its top and bottom windows.
Andre Noll [Sun, 3 Jun 2012 20:00:31 +0000 (22:00 +0200)]
mp3_afh: Switch to UTF-8 encoding.
The interface of libid3tag allows to get the tag contents in various
formats. Currently, we always call the latin1 variants of these
library functions.
However, as UTF-8 encoding is more widespread these days and almost
all distributions, including the two year old Ubuntu lucid, have
switched to UTF-8, UTF-8 is probably a better choice today.
This patch changes mp3_afh.c to use the UTF-8 variants instead.
Andre Noll [Sun, 3 Jun 2012 20:42:42 +0000 (22:42 +0200)]
Fix --with-curses configure option.
We only honored the provided -L<dir> for the tests in configure but
not when linking para_gui. This patch creates an output variable,
gui_ldflags, which is used in the Makefile for linking para_gui.