Commit Graph

110 Commits

Author SHA1 Message Date
Matan Perelman e00ac3b227 fmt_rtp_amr,fmt_rtp_efr: replace damaged packets with silence
Change-Id: I7245aa0bc0955cc8b94d5401a15e694f50498093
2023-03-28 16:29:45 +03:00
Vadim Yanitskiy 166a189c4f src/Makefile.am: fix building with --enable-gsmhr
In change [1] I moved libraries from _LDFLAGS to _LIBADD, but I did
not notice that there was another problem: when building with gsmhr,
the content of _LIBADD gets overwritten in a conditional block.

Do not overwrite but append libgsmhr.la to _LIBADD.

Change-Id: Ib46b1f6555b13e0937a8d6fe6e2ad70ed9d06d58
Fixes: [1] 08c1edb986
2023-03-16 00:56:21 +07:00
Vadim Yanitskiy 08c1edb986 src/Makefile.am: there shall be no libraries in LDFLAGS
AM_LDFLAGS is for linker flags like '-no-undefined', not libraries!

Change-Id: I7620e0c4e6444081e351e1dd021e0a8e2ae20337
2023-03-13 04:26:08 +07:00
Oliver Smith 29baab4c58 Run struct_endianness.py
Use the OSMO_IS_LITTLE_ENDIAN / OSMO_IS_BIG_ENDIAN macros from
libosmocore and run struct_endianness.py to auto-generate the big endian
part.

Related: OS#5884
Change-Id: Ibeb96f61054b11ca9d82f8d9a00c3935ffb086a6
2023-02-20 09:45:04 +01:00
Harald Welte 75df4ca2a3 gapk: add optional throttling
When throttling is enabled, one voice frame will be processed every
20ms.  This is useful for e.g. playback of a file as a RTP stream.

Without this option, the entire file would generate a flood of RTP
messages, rather than a continuous stream.

Change-Id: I0dcd4248cc800b82142722aa36a811f0657b3e0c
2020-08-01 19:00:37 +02:00
Harald Welte 5613b7d850 don't assert just because a broken RTP packet (wrong lenth) is received
Change-Id: I373308ed40614d29d9b578ddc056f27e20e4aa21
2020-07-01 09:50:01 +02:00
Martin Hauke ee62e46019 Fix typos
Change-Id: Ie8054f3d484fe5d82cc5d91f159906a470fc4511
2019-07-17 22:45:14 +02:00
Vadim Yanitskiy 89c1082b3d Make RTP payload type configurable
For a long time the RTP payload type was hard-coded for outgoing
frames. The problem is that according to RFC 3551 only GSM FR has
a static payload type value (see table 4, value 3). For other
codecs the payload type may be negotiated between the both
sides dynamically (i.e. in range 96-127).

Let's allow a binary/API user to configure this manually.

Change-Id: Ia07ed4e13b4a70c8bb4181564a8190861fd269da
Closes: OS#2482
2018-07-09 22:16:45 +07:00
Vadim Yanitskiy 664a866d59 fmt_ti.c: fix: properly pre-clean the output buffer
Despite it was stated that only the last nibble isn't being
written, some other bytes in the middle of the output buffer
were uninitialized during the first exectution of a queue.

The problem was observed with AddressSanitizer enabled.

Valgrind output:

  $ valgrind --track-origins=yes \
      src/.libs/lt-osmo-gapk \
      -i tests/ref-files/hhgttg_part1_5.s16.ti-efr \
      -f ti-efr -g rawpcm-s16le \
      -o /dev/null -v

 Conditional jump or move depends on uninitialised value(s)
    at 0x52728F2: msb_put_bit (utils.h:39)
    by 0x52728F2: amr_efr_from_canon (fmt_amr.c:45)
    by 0x5270A7D: osmo_gapk_pq_execute (procqueue.c:202)
    by 0x40296A: run (app_osmo_gapk.c:650)
    by 0x40296A: main (app_osmo_gapk.c:778)
  Uninitialised value was created by a heap allocation
    at 0x4C2AB80: malloc (in vgpreload_memcheck-amd64-linux.so)
    by 0x4E3C2A8: talloc_named_const (in libtalloc.so.2.1.5)
    by 0x5270A1B: osmo_gapk_pq_prepare (procqueue.c:180)
    by 0x402940: run (app_osmo_gapk.c:645)
    by 0x402940: main (app_osmo_gapk.c:778)

Change-Id: I79df56dde23702b0eac8e8fdbc0efd270cc0ace4
Related: OS#2934
2018-07-03 15:29:32 +00:00
Vadim Yanitskiy 3f22f18790 Implement ECU (Error Concealment Unit) block for FR
In I06a21f60db01bfe1c2b838f93866fad1d53fdcd1 the Error Concealment
Unit API for FR codec was introduced. This change implements a
corresponding block.

Note: at the moment, only Full Rate is supported by the ECU API.

Change-Id: Ia929ee04f6be3d842c6ef7bc40cce0fdab16e90a
2018-06-29 20:54:04 +07:00
Vadim Yanitskiy 6d0156b89a procqueue.c: rely on item type instead of its position
In the osmo_gapk_pq_prepare() we do allocate an item's buffer
conditionally, only when its type is not sink, because an output
buffer is not required for sink.

Let's use a bit more elegant way to check, whether item is sink.

Change-Id: I770a1d02273d9d8301a9e4ec72426fb8f4060277
2018-06-29 20:54:04 +07:00
Vadim Yanitskiy 379b657c57 app_osmo_gapk.c: use recommended osmo_init_logging2()
The osmo_init_logging() was deprecated.

Change-Id: Ic30a924571feb273274587998e87c86b688c3544
2018-06-29 20:54:04 +07:00
Vadim Yanitskiy a70b22376c src/Makefile.am: fix osmo-gapk LDADD dependency
This change fixes parallel building problem, when osmo-gapk was
being compiled before its libosmogapk dependency:

  make[2]: *** No rule to make target '../src/libosmogapk.la',
               needed by 'osmo-gapk'.  Stop.
  make[2]: *** Waiting for unfinished jobs....

For some reason, automake ignores a dependency if the full
path is provided:

  $(top_builddir)/src/libosmogapk.la

while the relative path solves the problem:

  libosmogapk.la

Closes: OS#2907
Change-Id: I3fdd1731bd372bbb42fe57981e757386e8ede0f0
2018-02-02 15:52:50 +07:00
Vadim Yanitskiy 7a79fc1169 Merge branch 'fixeria/lib' into master
The previous GAPK implementation was represented by a single
executable. So, all audio transcoding operations were available
only via calling the 'gapk' binary. This approach didn't allow
external applications to benefit from using GAPK API directly.

The following set of changes separates the common code into a
shared library called 'libosmogapk', linking the 'gapk' binary
against it:

  - 95e6664 Introduce a shared 'libosmogapk' library
  - 30209ce Install GAPK headers to '${includedir}/osmocom/gapk/'
  - a8d4657 Add an 'osmo_gapk' prefix to the exposed symbols
  - 40d59f1 Add a pkg-config manifest for libosmogapk
  - 4f0a47d Add the symbol export map for libosmogapk

All memory management operations are now based on talloc library:

  - 3c20dac libosmogapk: use talloc for memory management
  - 5cabe1e osmo-gapk: use talloc for memory management

Integrated Osmocom logging framework:

  - c35ba8a libosmogapk: use Osmocom logging framework
  - 4b7cd2c osmo-gapk: drop useless printf calls
  - 0fe18af osmo-gapk: use Osmocom logging framework
  - 11943bf osmo-gapk: adjust application verbosity

Integrated GNU Autotest environment and basic test coverage:

  - f069eb3 Init automake test environment
  - 1fe6a9b tests: add procqueue test
  - 3e9e57f tests: add pq_file test
  - 9d2b15d tests: add pq_rtp test
  - f59f3f1 tests: add format / codec transcoding tests

For more details, see commits history.

Change-Id: I3c6d4a9d326ee49153e4ad83823d094831c112da
2018-01-17 20:54:03 +06:00
Vadim Yanitskiy 6f34c8f301 procqueue: introduce and use shared cat_name definitions
Let's use the common string representation for item category
names, defined in the shared header, instead of defining
them in every file.

Change-Id: Ie0c449d77fa383cad27f67b8ce902bd071342dbb
2018-01-15 00:25:44 +06:00
Vadim Yanitskiy 2254861efb pq_alsa.c: fix memory leak after pq_cb_alsa_exit()
Abusing the talloc hierarchical nature may cause some problems,
e.g. on embedded systems with emulated talloc API. Let's release
the memory allocated for a state explicitly.

Change-Id: Ie675a92b1e52a4886dc447af19f65ff5e12a4c40
2018-01-09 00:13:18 +06:00
Vadim Yanitskiy 30493c78b3 Fix BENCHMARK_STOP call for both AMR and FR codecs
The BENCHMARK_STOP should be called with a correct codec type and
a correct operation type (encode or decode). Otherwise the results
could be incorrect.

Change-Id: Ie90e85ca8d9ec3175a58dde60525e0b7d6daf608
2018-01-08 23:44:50 +06: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 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 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 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