In order to give advanced control over a processing queue,
it would be better to have the checking function separated from
the osmo_gapk_pq_prepare(). Moreover, this change introduces an
additional 'strict' checking mode that requires a queue to have
a source item first and a sink item in the last position.
This change adds two meta-information fields to the processing
queue item structure. Both of them will be used for more
detailed logging and for the human-readable processing
queue description.
There are currently three types of prcessing queue items:
- source (file, alsa, rtp)
- proc (format, codec)
- sink (file, alsa, rtp)
Let's assign corresponding type for each item.
This would facilitate logging and the queue checking.
Since this change, every processing queue may optionally have
an associated human-readable name. If name is not required,
NULL should be passed to the osmo_gapk_pq_create().
In order to simplify memory leak debugging, this change introduces
the library's internal talloc context that may be changed by
external application by calling the osmo_gapk_set_talloc_ctx().
There are not so much code, related to internal logging subsystem.
So, there is no reason to keep a few lines in a dedicated file.
In the future one may also be used for other routines.
Previously the osmo-gapk application used to exit as soon as all
the frames are processed, no matter has the sink finished its
internal processing (e.g. ALSA playback).
In some cases it's required to wait for some queue items
to finish processing. For example, the ALSA sink writes the
audio samples to the buffer in non-blocking mode, so as soon
as all of them will be written, a program may finish execution,
causing the playback abort.
To prevent that, this change extends the library's API, allowing
each queue item to have a processing state callback that returns
a positive integer if processing is not finished yet,
and 0 otherwise.
Instead of immediately shutting down the application, it is
better to try to break the processing queue first, and stop
the execution immediately if second SIGINT is received.
The printf() writes the text into stdout, which may be undesirable
in some use cases. Moreover, the printed information was redundant.
So, let's drop such calls.
Since this change, the libosmogapk uses the Osmocom logging
framework. By default, logging is disabled and could be enabled
by the external applications calling the osmo_gapk_log_init()
with a desired log target as an argument.
Since GAPK package contains a library and the representative
osmo-gapk application, the 'main.c' looks a bit confusing. Let's
use the common naming scheme.
The usage of linuxlist is more flexible than having a limited
array of pointers. This approach allows to have as much items
in a processing queue as required.
To simplify the benchrarking process via the library API, this
change introduces two new functions, which are intended to
provide total cycle and frame count.
Having statically allocated memory for benchmark data of every
codec causes high memory usage, especially if actual benchmarking
is not required for a particular use case. Instead of that, let's
provide an optional opportunity to enable benchmarking for a
particular codec by calling the osmo_gapk_bench_enable(). The
required amount of memory would be allocated, and then can be
freed by calling the osmo_gapk_bench_free() or manually.
There is no need to expose the implementation details of both
BENCHMARK_START and BENCHMARK_STOP macros via public header.
This change moves them to a separate private header 'bench.h'.
The benchmark_dump() is only used by the osmo-gapk binary, and
is intended to prepare and print benchmarking results to stderr,
what is most likely unusable for the library users.
To avoid a naming conflict between libosmogapk and other projects
during linkage, all the exposed symbols should have an unique
prefix. Let's use 'osmo_gapk' for that.
To be able to use the library, external applications need to know,
which symbols are exposed. This information is provided by header
files, which are being installed to a system's ${includedir}
since this change.
The previous GAPK implementation was represented as a single
executable. So, all audio transcoding operations were available
only by calling the 'gapk' binary. This approach didn't allow
external applications to benefit from using GAPK API directly.
Since there are some projects (such as GR-GSM and OsmocomBB),
which are potential users of GAPK code base, it would be better
to have all transcoding functions within a shared library.
So, this change separates the common code into a shared library,
named 'libosmogapk', and links the 'gapk' binary against one.
Currently there are no shared headers, pkg-config manifest and
the export map, but they will be done latter.
On some systems the ALSA output buffer is pretty big, and
if the audio samples are not being passed into the buffer
quickly enough, it becomes starved for data, resulting
in an error called underrun.
Previously, when it happenned, GAPK used to stop processing
with the following message (where X is a random number):
[+] PQ: Adding ALSA output (dev='default', blk_len=320)
[!] pq_execute(): abort, item returned -1
[+] Processed X frames
According to the ALSA documentation, the pcm_handle
changes its state when the problem happens, and should
be recovered using the snd_pcm_prepare() call. This change
actually does that.
While EFR has a canonical format of 31 bytes, the codec_efr.c *does not*
use that canonical format as input. Rather, it uses the format of .amr
files with a 0x3C header as first byte. So the resulting encode/decode
functions should not assume 31 bytes, but 32 bytes.
I noticed that ti-hr format doesn't pass an encode-decode-playback test,
and discussion with tnt resulted in the following conclusion:
19:29 <@tnt> looking at fr and efr, it's always msb_xxx
19:30 <@tnt> and if I ever used it, then most likely it was for decoding
meaning ti_hr_to_canon would have been used and not the
other way around.
The RTP EFR payload is a bit like the FR payload: one nibble magic
marker, then followed by the actual codec bits. So we need to
add/remove that magic marker and shift the remainder by one nibble.
The ETSI reference codec actually uses an array of 20/22 16bit values
rather than a "canonical" format. The conversion is what fmt_hr_ref.c
is doing. However, codec_hr.c must then subsequently not check for the
canonical input/output sizes, but those specific to it.