Commit Graph

179 Commits

Author SHA1 Message Date
Vadim Yanitskiy f59f3f1ba8 tests: add format / codec transcoding tests
This test group is intended to check the format / codec transcoding
capabilities of the library. The reference files are used to ensure
that encoding or decoding was successful.

The following formats are currently being tested:

  - amr_efr
  - gsm
  - racal_hr
  - racal_fr
  - racal_efr
  - ti_hr
  - ti_fr
  - ti_efr
  - rtp_efr
  - rtp_hr_etsi
  - rtp_hr_ietf
2017-12-31 12:21:00 +01:00
Vadim Yanitskiy 10076f0acc osmo-gapk: fix I/O count check condition
The stdin / stdout operation was broken by a new check condition,
introduced by the 15fa605576a81803c57a144231e9e9720aa133a1.
2017-12-31 12:21:00 +01:00
Vadim Yanitskiy 9d2b15dc8a tests: add pq_rtp test
This test is intended to check the RTP source / sink operability.
To do this, two processing queues are being allocated:

  "generator": source/random -> sink/rtp
  "checker": source/rtp -> sink/checker

The first one generates some amount of random bytes (payload),
and stores them inside a buffer that is shared between both
queues.

After generation, a payload is being sent from the first
queue via an RTP sink, and then being received by the second
via an RTP source.

As both queues do use a shared buffer, the last item of the
second queue (named 'sink/checker') is able to compare a
received payload with expected.
2017-12-31 12:21:00 +01:00
Vadim Yanitskiy 3e9e57fb40 tests: add pq_file test
This test is intended to check the file source / sink
operability. To do that, the following processing chain
is being composed:

  source/file -> proc/dummy -> sink/file (stdout)

The source item opens the sample file named 'io_sample.txt'
for reading. The next processing item simply converts all
uppercase latters to the lowercase. The last one writes
the result to stdout.

This processing cycle is being repeated several times
with different block length values.
2017-12-31 12:21:00 +01:00
Vadim Yanitskiy 1fe6a9b9ed tests: add procqueue test
This test is intended to validate the processing queue
management API. Moreover, the talloc debugging API is
used to ensure that there are no memory leaks.

First, four processing queues are being allocated. One
of them is empty, while others have different count of
items. Then the human-readable description is being
generated for all of them. And finally, the processing
and exit cllback are being tested.

During the test execution, the talloc NULL-context
tracking feature is enabled, allowing to observe every
memory allocation within the libosmogapk, and to detect
memory leaks.
2017-12-31 12:21:00 +01:00
Vadim Yanitskiy f069eb37fe Init automake test environment 2017-12-31 12:21:00 +01:00
Vadim Yanitskiy f496a998e5 procqueue: allocate an output buffer as named chunk
The talloc_size() call sets the current file name and the current
line number as name for chunk being allocated. This combination
is not so informative during debugging, so let's use the static
'.buffer' string as context name for item's output buffer.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy fb2326fbcf procqueue: set talloc name and context for queue description
Previously a queue description string was allocated without
setting proper parental talloc context and proper name.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 7279d9f057 src/libosmogapk.map: export osmo_gapk_* with a wilcard 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 9e7e889278 procqueue: use queue / item names in logging 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 3839a88ea6 procqueue: separate queue check function
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 459791c488 procqueue: add item catedory and sub-category fields
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 408be3638b procqueue: add item type enum (source, sink, proc)
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 2286a36ace procqueue: add human-readable name to osmo_gapk_pq
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().
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 262ae0f98f libosmogapk: drop an 'osmo' prefix from internal log variables
It would be better to have an 'osmo_gapk' prefix for exposed
symbols only. Both internal logging variables aren't exposed,
so they shouldn't have one.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 5cabe1eeec osmo-gapk: use talloc for memory management 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy f23b747364 libosmogapk: introduce the internal root talloc context
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().
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 750c896b4a libosmogapk: rename the 'logging.c' to 'common.c'
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 14637746d3 libosmogapk: fix memory leak in both AMR and EFR codecs
The memory, allocated by codec_efr_init() / codec_amr_init(),
was not cleaned after calling the codec_exit(). Found using
talloc memory debugging API.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 3c20dac38c libosmogapk: use talloc for memory management 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy a4d88ae13b osmo-gapk: fix I/O combinations check
Previously both ALSA source and sink were out of attention.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 6831ebd958 configure.ac: use actual bug report address in AC_INIT 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 01f5c5bebf osmo-gapk: wait until sink finish processing
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).
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy a183ced71e src/pq_alsa.c: implement processing state callback
Using the snd_pcm_avail_update() call from ALSA API it's possible
to know, how much samples are still to be processed.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 1f6f807bb3 procqueue: add processing state callback
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy b40a54dc97 osmo-gapk: abort the processing queue on SIGINT
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 11943bf320 osmo-gapk: adjust application verbosity
This change allows user to enable advanced verbosity using the
'-v' command line option, which is disabled by default.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 0fe18af82d osmo-gapk: use Osmocom logging framework 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 4b7cd2c677 osmo-gapk: drop useless printf calls
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy c35ba8a725 libosmogapk: use Osmocom logging framework
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy f8d91a07b4 osmo-gapk: use more convenient name for the source file
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 4ffd6f20a9 osmo-gapk: create a common shutdown function
Previously the code intended to shutdown the osmo-gapk application
was repeated two times. It's better to have a single function.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 5716ca636d osmo-gapk: add an option to enable / disable benchmark
If the codec benchmarking is required in particular case, it
could be activated by a special command line option introduced
by this change.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 539af39e29 procqueue: use linuxlist to store queue items
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 1cf7f34444 procqueue: use uint8_t as output buffer type 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 304fa73421 procqueue: store output buffers inside queue items
An output buffer belongs to its queue item, so it will be more
correctly to store its pointer inside the osmo_gapk_pq_item.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 3be9c7ae3c procqueue: use unsigned int for I/O frame size fields
A frame size cannot be negative, so 'unsigned' is more
suitable for frame size fields.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 4f0a47d0e3 Add the symbol export map for libosmogapk 2017-12-31 12:20:59 +01:00
Vadim Yanitskiy cda8995ac8 benchmark: add functions to get cycle and frame count
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 72218e7da0 benchmark: allocate memory dynamically
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy c9a75e59c6 benchmark: get rid of 'static inline' definition
The usage of a 'static inline' function definition in the 'bench.h'
is resulting in separate independent function definitions in each
translation unit from which the header is included. This is
increasing the size of compiled code unnecessarily.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy ba46856bb4 benchmark: move benchmark impl to a private header
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'.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 349219c148 benchmark: move benchmark_dump() outside the library
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy a8d46571ce Add an 'osmo_gapk' prefix to the exposed symbols
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 9cba760ba2 procqueue: expose the processing queue struct definition
To be able to use processing queues from outside, the pq struct
should be shared in the corresponding header file.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 40d59f14a2 Add a pkg-config manifest for libosmogapk
In order to make pkg-config 'see' the libosmogapk, a corresponding
package description is required. For more details, see:

https://autotools.io/pkgconfig/file-format.html
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 5f941573b0 Use '#pragma once' instead of include guard
The most compilers today do support the '#pragma once', which is
designed to cause the current source file to be included only once
in a single compilation. One has several advantages, including:
less code, avoidance of name clashes, and sometimes improvement
in compilation speed.

See: https://en.wikipedia.org/wiki/Pragma_once for details.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 30209ceddd Install GAPK headers to '${includedir}/osmocom/gapk/'
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.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 48206ad2e0 Add an 'osmo' prefix to the 'gapk' binary
This is a common practice of all Osmocom executables
to have an 'osmo' prefix. Let's follow this here too.
2017-12-31 12:20:59 +01:00
Vadim Yanitskiy 95e666404e Introduce a shared 'libosmogapk' library
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.
2017-12-31 12:20:59 +01:00