mirror of https://gerrit.osmocom.org/gapk
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.
This commit is contained in:
parent
f8d91a07b4
commit
c35ba8a725
|
@ -1,4 +1,5 @@
|
|||
noinst_HEADERS = \
|
||||
osmocom/gapk/logging.h \
|
||||
osmocom/gapk/utils.h \
|
||||
osmocom/gapk/bench.h \
|
||||
$(NULL)
|
||||
|
@ -9,6 +10,7 @@ nobase_include_HEADERS = \
|
|||
osmocom/gapk/procqueue.h \
|
||||
osmocom/gapk/formats.h \
|
||||
osmocom/gapk/codecs.h \
|
||||
osmocom/gapk/common.h \
|
||||
$(NULL)
|
||||
|
||||
if ENABLE_GSMHR
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of gapk (GSM Audio Pocket Knife).
|
||||
*
|
||||
* gapk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gapk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gapk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void osmo_gapk_log_init(int subsys);
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* This file is part of gapk (GSM Audio Pocket Knife).
|
||||
*
|
||||
* gapk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gapk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gapk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <osmocom/core/logging.h>
|
||||
|
||||
extern int osmo_gapk_log_init_complete;
|
||||
extern int osmo_gapk_log_subsys;
|
||||
|
||||
#define LOGPGAPK(level, fmt, args...) \
|
||||
if (osmo_gapk_log_init_complete) \
|
||||
LOGP(osmo_gapk_log_subsys, level, fmt, ## args)
|
|
@ -76,6 +76,11 @@ libosmogapk_la_SOURCES += \
|
|||
benchmark.c \
|
||||
$(NULL)
|
||||
|
||||
# Logging
|
||||
libosmogapk_la_SOURCES += \
|
||||
logging.c \
|
||||
$(NULL)
|
||||
|
||||
# libosmogapk representative application
|
||||
bin_PROGRAMS = osmo-gapk
|
||||
|
||||
|
|
|
@ -31,8 +31,12 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <osmocom/core/application.h>
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/core/socket.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
|
||||
#include <osmocom/gapk/common.h>
|
||||
#include <osmocom/gapk/codecs.h>
|
||||
#include <osmocom/gapk/formats.h>
|
||||
#include <osmocom/gapk/procqueue.h>
|
||||
|
@ -85,6 +89,25 @@ struct gapk_state
|
|||
} out;
|
||||
};
|
||||
|
||||
/* Logging related routines */
|
||||
enum {
|
||||
DAPP,
|
||||
};
|
||||
|
||||
static struct log_info_cat gapk_log_info_cat[] = {
|
||||
[DAPP] = {
|
||||
.name = "DAPP",
|
||||
.description = "Application",
|
||||
.color = "\033[0;36m",
|
||||
.enabled = 1, .loglevel = LOGL_DEBUG,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct log_info gapk_log_info = {
|
||||
.cat = gapk_log_info_cat,
|
||||
.num_cat = ARRAY_SIZE(gapk_log_info_cat),
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
print_help(char *progname)
|
||||
|
@ -620,6 +643,11 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
int rv;
|
||||
|
||||
/* Init Osmocom logging framework */
|
||||
osmo_init_logging(&gapk_log_info);
|
||||
/* and GAPK logging wrapper */
|
||||
osmo_gapk_log_init(DAPP);
|
||||
|
||||
/* Clear state */
|
||||
memset(gs, 0x00, sizeof(struct gapk_state));
|
||||
gs->in.rtp.fd = -1;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
LIBOSMOGAPK_1.0 {
|
||||
global:
|
||||
|
||||
osmo_gapk_log_init;
|
||||
|
||||
osmo_gapk_pq;
|
||||
osmo_gapk_pq_item;
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* This file is part of gapk (GSM Audio Pocket Knife).
|
||||
*
|
||||
* (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>
|
||||
*
|
||||
* gapk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gapk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gapk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
int osmo_gapk_log_init_complete = 0;
|
||||
int osmo_gapk_log_subsys;
|
||||
|
||||
void osmo_gapk_log_init(int subsys)
|
||||
{
|
||||
osmo_gapk_log_subsys = subsys;
|
||||
osmo_gapk_log_init_complete = 1;
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <osmocom/gapk/logging.h>
|
||||
#include <osmocom/gapk/codecs.h>
|
||||
#include <osmocom/gapk/formats.h>
|
||||
#include <osmocom/gapk/procqueue.h>
|
||||
|
@ -147,7 +148,7 @@ out_close:
|
|||
snd_pcm_close(state->pcm_handle);
|
||||
free(state);
|
||||
out_print:
|
||||
fprintf(stderr, "[!] Couldn't init ALSA device '%s': %s\n",
|
||||
LOGPGAPK(LOGL_ERROR, "Couldn't init ALSA device '%s': %s\n",
|
||||
alsa_dev, snd_strerror(rc));
|
||||
return rc;
|
||||
}
|
||||
|
@ -162,7 +163,8 @@ out_print:
|
|||
int
|
||||
osmo_gapk_pq_queue_alsa_input(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len)
|
||||
{
|
||||
fprintf(stderr, "[+] PQ: Adding ALSA input (dev='%s', blk_len=%u)\n", hwdev, blk_len);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding ALSA input "
|
||||
"(dev='%s', blk_len=%u)\n", hwdev, blk_len);
|
||||
return pq_queue_alsa_op(pq, hwdev, blk_len, 1);
|
||||
}
|
||||
|
||||
|
@ -175,7 +177,8 @@ osmo_gapk_pq_queue_alsa_input(struct osmo_gapk_pq *pq, const char *hwdev, unsign
|
|||
int
|
||||
osmo_gapk_pq_queue_alsa_output(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len)
|
||||
{
|
||||
fprintf(stderr, "[+] PQ: Adding ALSA output (dev='%s', blk_len=%u)\n", hwdev, blk_len);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding ALSA output "
|
||||
"(dev='%s', blk_len=%u)\n", hwdev, blk_len);
|
||||
return pq_queue_alsa_op(pq, hwdev, blk_len, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <osmocom/gapk/logging.h>
|
||||
#include <osmocom/gapk/codecs.h>
|
||||
#include <osmocom/gapk/formats.h>
|
||||
#include <osmocom/gapk/procqueue.h>
|
||||
|
@ -71,7 +72,7 @@ osmo_gapk_pq_queue_codec(struct osmo_gapk_pq *pq, const struct osmo_gapk_codec_d
|
|||
|
||||
item->exit = codec->codec_exit;
|
||||
|
||||
fprintf(stderr, "[+] PQ: Adding Codec %s, %s format %s\n", codec->name,
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding codec %s, %s format %s\n", codec->name,
|
||||
enc_dec_n ? "encoding to" : "decoding from", fmt->name);
|
||||
|
||||
if (!item->proc)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <osmocom/gapk/logging.h>
|
||||
#include <osmocom/gapk/codecs.h>
|
||||
#include <osmocom/gapk/formats.h>
|
||||
#include <osmocom/gapk/procqueue.h>
|
||||
|
@ -97,7 +98,7 @@ pq_queue_file_op(struct osmo_gapk_pq *pq, FILE *fh, unsigned int blk_len, int in
|
|||
int
|
||||
osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int blk_len)
|
||||
{
|
||||
fprintf(stderr, "[+] PQ: Adding file input (blk_len=%u)\n", blk_len);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding file input (blk_len=%u)\n", blk_len);
|
||||
return pq_queue_file_op(pq, src, blk_len, 1);
|
||||
}
|
||||
|
||||
|
@ -110,6 +111,6 @@ osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int b
|
|||
int
|
||||
osmo_gapk_pq_queue_file_output(struct osmo_gapk_pq *pq, FILE *dst, unsigned int blk_len)
|
||||
{
|
||||
fprintf(stderr, "[+] PQ: Adding file output (blk_len=%u)\n", blk_len);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding file output (blk_len=%u)\n", blk_len);
|
||||
return pq_queue_file_op(pq, dst, blk_len, 0);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <osmocom/gapk/logging.h>
|
||||
#include <osmocom/gapk/codecs.h>
|
||||
#include <osmocom/gapk/formats.h>
|
||||
#include <osmocom/gapk/procqueue.h>
|
||||
|
@ -44,7 +45,8 @@ osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_f
|
|||
|
||||
codec = osmo_gapk_codec_get_from_type(fmt->codec_type);
|
||||
if (!codec) {
|
||||
fprintf(stderr, "[!] Cannot determine codec from format %s\n", fmt->name);
|
||||
LOGPGAPK(LOGL_ERROR, "Cannot determine codec from "
|
||||
"format %s\n", fmt->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -54,14 +56,14 @@ osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_f
|
|||
return -ENOMEM;
|
||||
|
||||
if (to_from_n) {
|
||||
fprintf(stderr, "[+] PQ: Adding conversion from canon to %s (for codec %s)\n",
|
||||
fmt->name, codec->name);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding conversion from canon "
|
||||
"to %s (for codec %s)\n", fmt->name, codec->name);
|
||||
item->len_in = codec->canon_frame_len;
|
||||
item->len_out = fmt->frame_len;
|
||||
item->state = fmt->conv_from_canon;
|
||||
} else {
|
||||
fprintf(stderr, "[+] PQ: Adding conversion from %s to canon (for codec %s)\n",
|
||||
fmt->name, codec->name);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding conversion from %s "
|
||||
"to canon (for codec %s)\n", fmt->name, codec->name);
|
||||
item->len_in = fmt->frame_len;
|
||||
item->len_out = codec->canon_frame_len;
|
||||
item->state = fmt->conv_to_canon;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <osmocom/gapk/logging.h>
|
||||
#include <osmocom/gapk/codecs.h>
|
||||
#include <osmocom/gapk/formats.h>
|
||||
#include <osmocom/gapk/procqueue.h>
|
||||
|
@ -86,7 +87,8 @@ struct pq_state_rtp {
|
|||
uint32_t ssrc;
|
||||
};
|
||||
|
||||
#define rtp_err(x, args...) fprintf(stderr, "[!] %s():" x, __func__, ## args)
|
||||
#define rtp_err(err_msg, args...) \
|
||||
LOGPGAPK(LOGL_ERROR, "%s():" err_msg, __func__, ## args)
|
||||
|
||||
static int
|
||||
pq_cb_rtp_input(void *_state, uint8_t *out, const uint8_t *in, unsigned int in_len)
|
||||
|
@ -241,7 +243,7 @@ pq_queue_rtp_op(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len, int i
|
|||
int
|
||||
osmo_gapk_pq_queue_rtp_input(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len)
|
||||
{
|
||||
fprintf(stderr, "[+] PQ: Adding RTP input (blk_len=%u)\n", blk_len);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding RTP input (blk_len=%u)\n", blk_len);
|
||||
return pq_queue_rtp_op(pq, udp_fd, blk_len, 1);
|
||||
}
|
||||
|
||||
|
@ -253,6 +255,6 @@ osmo_gapk_pq_queue_rtp_input(struct osmo_gapk_pq *pq, int udp_fd, unsigned int b
|
|||
int
|
||||
osmo_gapk_pq_queue_rtp_output(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len)
|
||||
{
|
||||
fprintf(stderr, "[+] PQ: Adding RTP output (blk_len=%u)\n", blk_len);
|
||||
LOGPGAPK(LOGL_DEBUG, "PQ: Adding RTP output (blk_len=%u)\n", blk_len);
|
||||
return pq_queue_rtp_op(pq, udp_fd, blk_len, 0);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <osmocom/core/linuxlist.h>
|
||||
|
||||
#include <osmocom/gapk/procqueue.h>
|
||||
#include <osmocom/gapk/logging.h>
|
||||
|
||||
/* crate a new (empty) processing queue */
|
||||
struct osmo_gapk_pq *
|
||||
|
@ -102,7 +103,7 @@ osmo_gapk_pq_prepare(struct osmo_gapk_pq *pq)
|
|||
llist_for_each_entry(item, &pq->items, list) {
|
||||
/* Make sure I/O data lengths are equal */
|
||||
if (item->len_in && item->len_in != len_prev) {
|
||||
fprintf(stderr, "[!] PQ item requires input size %u, "
|
||||
LOGPGAPK(LOGL_ERROR, "PQ item requires input size %u, "
|
||||
"but previous output is %u\n", item->len_in, len_prev);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -151,8 +152,8 @@ osmo_gapk_pq_execute(struct osmo_gapk_pq *pq)
|
|||
/* Call item's processing handler */
|
||||
rv = item->proc(item->state, item->buf, buf_prev, len_prev);
|
||||
if (rv < 0) {
|
||||
fprintf(stderr, "[!] osmo_gapk_pq_execute(): "
|
||||
"abort, item returned %d\n", rv);
|
||||
LOGPGAPK(LOGL_ERROR, "Queue execution aborted: "
|
||||
"item returned %d\n", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue