Commit Graph

101 Commits

Author SHA1 Message Date
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
Max 45d0fd66c3 Add git-review config
Change-Id: Id4304dc8248087c23aaf3a5d205cd341ed6a758a
2017-12-29 21:48:18 +01:00
Vadim Yanitskiy d5cfaa6a52 pq_alsa.c: print error message if device init fails 2017-09-02 17:03:06 +02:00
Vadim Yanitskiy 83aa99e7a9 pq_alsa.c: handle output buffer underrun
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.
2017-09-02 17:02:37 +02:00
Vadim Yanitskiy 6c42261cd2 test/common.sh: fix typo in gapk binary location 2017-08-31 13:06:55 +02:00
Harald Welte 1452203526 fmt_gsm: document that this format is also used for RTP 2017-05-29 11:25:03 +02:00
Harald Welte 2ba67e8c9e Add gapk testsuit
This testsuite takes a PCM auidio file and encodes from it every
supported format, and compares that output with a known sample (from an
earlier, trusted version of gakp, shipped as part of this project).

I then re-decodes this file to PCM and also compares that with a shipped
reference re-decode.
2017-05-28 21:28:57 +02:00
Harald Welte 84f4f86fdf fmt_rtp_hr_ietf.c: Fix error encoding this format
We used the wrong length constant during encoding of RTP-HR IETF style.
2017-05-28 21:06:20 +02:00
Harald Welte fa93cec8a1 EFR codec fixup.
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.
2017-05-28 20:58:10 +02:00
Harald Welte ac3517e715 alsa/file input: return -1 on eof (short read)
This will permit for a more graceful error than the next element in the
processing chain complaining that there's a 0-length input.
2017-05-28 20:06:01 +02:00
Harald Welte d045f1766f procqueue.c: Logging unficiation (always use the [x] prefix) 2017-05-28 20:06:01 +02:00
Harald Welte 6c7fd7958c codac_amr: Remove printf() left from debugging/testing 2017-05-28 19:44:26 +02:00
Harald Welte 0c655bce25 direct all log statements to stderr to avoid breaking stdout data out
The tool has the capability to be used in a pipe, so stdout should
recevie nothing else but actual codec/pcm data.
2017-05-28 19:44:26 +02:00
Harald Welte 7bdf34cc09 fmt_ti: fix lsb/msb mix-up in ti_hr_from_canon()
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.
2017-05-28 19:33:05 +02:00
Harald Welte 076d41aa79 print_help(): Fix formatting of help text 2017-05-28 16:22:43 +02:00
Harald Welte 848db7b662 Add support for RTP with GSM-HR payload according to RFC5993
This is incompatible with the ETSI TS 101 318 format!
2017-05-28 16:18:09 +02:00
Harald Welte dc3589a6be Add support for RTP with GSM-HR payload according to ETSI TS 101 318 2017-05-28 16:18:09 +02:00
Harald Welte f62e7a4936 Add "rtp-efr" format support for RTP payload according to RFC3551 4.5.9
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.
2017-05-28 16:18:09 +02:00
Harald Welte 526fc6e5e9 Fix HR codec block sizes
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.
2017-05-28 16:18:09 +02:00
Harald Welte bd42eba35d Print some useful information while putting together the procqueue 2017-05-28 14:30:05 +02:00
Harald Welte 495c694781 print meaningful error messages if something goes wrong in main/pq 2017-05-28 14:30:05 +02:00
Harald Welte 8b01f0ca05 Add AMR codec support
After merging this change, there is support for the AMR codec (by means
of libopencore-amr, which is already used for EFR).

In terms of gapk formats, we introdude
* the "amr-opencore" format, which serves both as the canonical format,
  and as the input format to opencore-amrnb itself.
* the "rtp-amr" format, which is the payload of RFC4867 octet-aligned mode

You can use the following command for a real-time RTP playback for AMR
frames:
  ./gapk -I 0.0.0.0/30000 -f rtp-amr -A default -g rawpcm-s16le
2017-05-28 14:29:59 +02:00
Harald Welte 494d92c3c7 more API documentation 2017-05-28 10:44:10 +02:00
Harald Welte 5912848d2e prepare gapk for dealing with variable-length frames
The existing architecture was modelled around fixed-length codec frame
sizes, which of course fails with multi-rate codecs such as AMR.
2017-05-28 10:44:06 +02:00
Harald Welte 62688b60c2 introduce #defines for canonical length + use them 2017-05-28 10:20:26 +02:00
Harald Welte 2ae47af0be Add ALSA input/output support to GAPK
The ALSA source/sink uses the pcm-s16le format.
2017-05-28 01:56:33 +02:00
Harald Welte 07d691314c RTP: give meaningful error messages if something fails
In fact, it should probably be better to silently ignore all those
errors as opposed to aborting the entire processing queue?  But that's
for another patch...
2017-05-28 01:56:33 +02:00
Harald Welte f3d2ad6a19 add some more comments throughout the code 2017-05-27 16:42:14 +02:00
Sylvain Munaut d192d8c017 benchmark: Fix cpuid clobbering
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2016-01-01 13:17:37 +01:00