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.
This commit is contained in:
Vadim Yanitskiy 2017-08-31 17:22:56 +07:00
parent 9cba760ba2
commit a8d46571ce
30 changed files with 212 additions and 188 deletions

View File

@ -24,18 +24,19 @@
#define NUM_AVG 102400
struct benchmark_cycles {
struct osmo_gapk_bench_cycles {
cycles_t enc[NUM_AVG];
unsigned int enc_used;
cycles_t dec[NUM_AVG];
unsigned int dec_used;
};
extern struct benchmark_cycles codec_cycles[_CODEC_MAX];
extern struct osmo_gapk_bench_cycles osmo_gapk_bench_codec[_CODEC_MAX];
static inline void benchmark_stop(enum codec_type codec, int encode, unsigned long cycles)
static inline void benchmark_stop(enum osmo_gapk_codec_type codec,
int encode, unsigned long cycles)
{
struct benchmark_cycles *bc = &codec_cycles[codec];
struct osmo_gapk_bench_cycles *bc = &osmo_gapk_bench_codec[codec];
if (encode) {
bc->enc_used = (bc->enc_used + 1) % NUM_AVG;

View File

@ -28,7 +28,7 @@
#define HR_REF_ENC_LEN (20 * sizeof(uint16_t))
#define HR_REF_DEC_LEN (22 * sizeof(uint16_t))
enum codec_type {
enum osmo_gapk_codec_type {
CODEC_INVALID = 0,
CODEC_PCM, /* 16 bits PCM samples */
CODEC_HR, /* GSM Half Rate codec GSM 06.20 */
@ -38,7 +38,8 @@ enum codec_type {
_CODEC_MAX,
};
#include <osmocom/gapk/formats.h> /* need to import here because or enum interdep */
/* Need to import here because of enum interdep */
#include <osmocom/gapk/formats.h>
/*! call-back for actual codec conversion function
* \param[in] state opaque state pointer (returned by codec->init)
@ -46,23 +47,33 @@ enum codec_type {
* \param[in] src input data
* \param[in] src_len length of input data \a src
* \returns number of output bytes written to \a dst; negative on error */
typedef int (*codec_conv_cb_t)(void *state, uint8_t *dst, const uint8_t *src, unsigned int src_len);
typedef int (*osmo_gapk_codec_conv_cb_t)(void *state, uint8_t *dst,
const uint8_t *src, unsigned int src_len);
struct codec_desc {
enum codec_type type;
const char * name;
const char * description;
/*! canonical frame size (in bytes); 0 in case of variable length */
unsigned int canon_frame_len;
struct osmo_gapk_codec_desc {
enum osmo_gapk_codec_type type;
const char *description;
const char *name;
enum format_type codec_enc_format_type; /* what the encoder provides */
enum format_type codec_dec_format_type; /* what to give the decoder */
/*! codec initialization function pointer, returns opaque state */
void * (*codec_init)(void);
/*! codec exit function pointer, gets passed opaque state */
void (*codec_exit)(void *state);
codec_conv_cb_t codec_encode;
codec_conv_cb_t codec_decode;
/*!
* Canonical frame size (in bytes);
* 0 in case of variable length
*/
unsigned int canon_frame_len;
/*! What the encoder provides */
enum osmo_gapk_format_type codec_enc_format_type;
/*! What to give the decoder */
enum osmo_gapk_format_type codec_dec_format_type;
/* (De)initialization function pointers */
void *(*codec_init)(void);
void (*codec_exit)(void *state);
/* Encoding / decoding function pointers */
osmo_gapk_codec_conv_cb_t codec_encode;
osmo_gapk_codec_conv_cb_t codec_decode;
};
const struct codec_desc *codec_get_from_type(enum codec_type type);
const struct osmo_gapk_codec_desc *
osmo_gapk_codec_get_from_type(enum osmo_gapk_codec_type type);

View File

@ -21,7 +21,7 @@
#include <stdint.h>
enum format_type {
enum osmo_gapk_format_type {
FMT_INVALID = 0,
/* Classic .amr container */
@ -61,31 +61,37 @@ enum format_type {
_FMT_MAX,
};
#include <osmocom/gapk/codecs.h> /* need to import here because or enum interdep */
/* Need to import here because of enum interdep */
#include <osmocom/gapk/codecs.h>
/*! call-back for actual format conversion function
* \param[out] dst caller-allocated buffer for output data
* \param[in] src input data
* \param[in] src_len length of input data \a src
* \returns number of output bytes written to \a dst; negative on error */
typedef int (*fmt_conv_cb_t)(uint8_t *dst, const uint8_t *src, unsigned int src_len);
typedef int (*osmo_gapk_fmt_conv_cb_t)(uint8_t *dst,
const uint8_t *src, unsigned int src_len);
struct format_desc {
enum format_type type;
enum codec_type codec_type;
const char * name;
const char * description;
struct osmo_gapk_format_desc {
enum osmo_gapk_format_type type;
enum osmo_gapk_codec_type codec_type;
const char *description;
const char *name;
/*! length of frames in this format (as opposed to canonical) */
unsigned int frame_len;
fmt_conv_cb_t conv_from_canon;
fmt_conv_cb_t conv_to_canon;
/*! Length of frames in this format (as opposed to canonical) */
unsigned int frame_len;
/*! length of a (global) header at start of file */
unsigned int header_len;
/*! exact match for (global) header at start of file */
const uint8_t * header;
/* Format conversation function pointers */
osmo_gapk_fmt_conv_cb_t conv_from_canon;
osmo_gapk_fmt_conv_cb_t conv_to_canon;
/*! Length of a (global) header at start of file */
unsigned int header_len;
/*! Exact match for (global) header at start of file */
const uint8_t *header;
};
const struct format_desc *fmt_get_from_type(enum format_type type);
const struct format_desc *fmt_get_from_name(const char *name);
const struct osmo_gapk_format_desc *
osmo_gapk_fmt_get_from_type(enum osmo_gapk_format_type type);
const struct osmo_gapk_format_desc *
osmo_gapk_fmt_get_from_name(const char *name);

View File

@ -22,7 +22,7 @@
#include <stdint.h>
#include <stdio.h> /* for FILE */
struct pq_item {
struct osmo_gapk_pq_item {
/*! input frame size (in bytes). '0' in case of variable frames */
int len_in;
/*! output frame size (in bytes). '0' in case of variable frames */
@ -42,35 +42,37 @@ struct pq_item {
#define VAR_BUF_SIZE 320
#define MAX_PQ_ITEMS 8
struct pq {
struct osmo_gapk_pq {
unsigned n_items;
struct pq_item *items[MAX_PQ_ITEMS];
struct osmo_gapk_pq_item *items[MAX_PQ_ITEMS];
void *buffers[MAX_PQ_ITEMS + 1];
};
/* Management */
struct pq * pq_create(void);
void pq_destroy(struct pq *pq);
struct pq_item * pq_add_item(struct pq *pq);
int pq_prepare(struct pq *pq);
int pq_execute(struct pq *pq);
/* Processing queue management */
struct osmo_gapk_pq *osmo_gapk_pq_create(void);
int osmo_gapk_pq_prepare(struct osmo_gapk_pq *pq);
int osmo_gapk_pq_execute(struct osmo_gapk_pq *pq);
void osmo_gapk_pq_destroy(struct osmo_gapk_pq *pq);
/* Processing queue item management */
struct osmo_gapk_pq_item *osmo_gapk_pq_add_item(struct osmo_gapk_pq *pq);
/* File */
int pq_queue_file_input(struct pq *pq, FILE *src, unsigned int block_len);
int pq_queue_file_output(struct pq *pq, FILE *dst, unsigned int block_len);
int osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int block_len);
int osmo_gapk_pq_queue_file_output(struct osmo_gapk_pq *pq, FILE *dst, unsigned int block_len);
/* RTP */
int pq_queue_rtp_input(struct pq *pq, int rtp_fd, unsigned int block_len);
int pq_queue_rtp_output(struct pq *pq, int rtp_fd, unsigned int block_len);
int osmo_gapk_pq_queue_rtp_input(struct osmo_gapk_pq *pq, int rtp_fd, unsigned int block_len);
int osmo_gapk_pq_queue_rtp_output(struct osmo_gapk_pq *pq, int rtp_fd, unsigned int block_len);
/* ALSA */
int pq_queue_alsa_input(struct pq *pq, const char *hwdev, unsigned int blk_len);
int pq_queue_alsa_output(struct pq *pq, const char *hwdev, unsigned int blk_len);
int osmo_gapk_pq_queue_alsa_input(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len);
int osmo_gapk_pq_queue_alsa_output(struct osmo_gapk_pq *pq, const char *hwdev, unsigned int blk_len);
/* Format */
struct format_desc;
int pq_queue_fmt_convert(struct pq *pq, const struct format_desc *fmt, int to_from_n);
struct osmo_gapk_format_desc;
int osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_format_desc *fmt, int to_from_n);
/* Codec */
struct codec_desc;
int pq_queue_codec(struct pq *pq, const struct codec_desc *codec, int encode);
struct osmo_gapk_codec_desc;
int osmo_gapk_pq_queue_codec(struct osmo_gapk_pq *pq, const struct osmo_gapk_codec_desc *codec, int encode);

View File

@ -21,14 +21,14 @@
#include <osmocom/gapk/benchmark.h>
struct benchmark_cycles codec_cycles[_CODEC_MAX];
struct osmo_gapk_bench_cycles osmo_gapk_bench_codec[_CODEC_MAX];
void benchmark_dump(void)
{
int i;
for (i = 0; i < _CODEC_MAX; i++) {
struct benchmark_cycles *bc = &codec_cycles[i];
struct osmo_gapk_bench_cycles *bc = &osmo_gapk_bench_codec[i];
unsigned long long total;
int j;

View File

@ -103,7 +103,7 @@ codec_amr_decode(void *state, uint8_t *pcm, const uint8_t *cod, unsigned int cod
#endif /* HAVE_OPENCORE_AMRNB */
const struct codec_desc codec_amr_desc = {
const struct osmo_gapk_codec_desc codec_amr_desc = {
.type = CODEC_AMR,
.name = "amr",
.description = "GSM 26.071 Adaptive Multi Rate codec",

View File

@ -108,7 +108,7 @@ codec_efr_decode(void *state, uint8_t *pcm, const uint8_t *cod, unsigned int cod
#endif /* HAVE_OPENCORE_AMRNB */
const struct codec_desc codec_efr_desc = {
const struct osmo_gapk_codec_desc codec_efr_desc = {
.type = CODEC_EFR,
.name = "efr",
.description = "GSM 06.60 Enhanced Full Rate codec",

View File

@ -83,7 +83,7 @@ codec_fr_decode(void *state, uint8_t *pcm, const uint8_t *cod, unsigned int cod_
#endif /* HAVE_LIBGSM */
const struct codec_desc codec_fr_desc = {
const struct osmo_gapk_codec_desc codec_fr_desc = {
.type = CODEC_FR,
.name = "fr",
.description = "GSM 06.10 Full Rate codec (classic gsm codec)",

View File

@ -73,7 +73,7 @@ codec_hr_decode(void *_state, uint8_t *pcm, const uint8_t *cod, unsigned int cod
#endif /* HAVE_LIBGSMHR */
const struct codec_desc codec_hr_desc = {
const struct osmo_gapk_codec_desc codec_hr_desc = {
.type = CODEC_HR,
.name = "hr",
.description = "GSM 06.20 Half Rate codec",

View File

@ -19,7 +19,7 @@
#include <osmocom/gapk/codecs.h>
const struct codec_desc codec_pcm_desc = {
const struct osmo_gapk_codec_desc codec_pcm_desc = {
.type = CODEC_PCM,
.name = "pcm",
.description = "Raw PCM signed 16 bits samples",

View File

@ -22,15 +22,15 @@
#include <osmocom/gapk/codecs.h>
/* Extern codec descriptors */
extern const struct codec_desc codec_pcm_desc;
extern const struct codec_desc codec_hr_desc;
extern const struct codec_desc codec_fr_desc;
extern const struct codec_desc codec_efr_desc;
extern const struct codec_desc codec_amr_desc;
extern const struct osmo_gapk_codec_desc codec_pcm_desc;
extern const struct osmo_gapk_codec_desc codec_hr_desc;
extern const struct osmo_gapk_codec_desc codec_fr_desc;
extern const struct osmo_gapk_codec_desc codec_efr_desc;
extern const struct osmo_gapk_codec_desc codec_amr_desc;
const struct codec_desc *
codec_get_from_type(enum codec_type type)
const struct osmo_gapk_codec_desc *
osmo_gapk_codec_get_from_type(enum osmo_gapk_codec_type type)
{
switch (type) {
case CODEC_PCM: return &codec_pcm_desc;

View File

@ -70,7 +70,7 @@ amr_efr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return EFR_CANON_LEN;
}
const struct format_desc fmt_amr_efr = {
const struct osmo_gapk_format_desc fmt_amr_efr = {
.type = FMT_AMR_EFR,
.codec_type = CODEC_EFR,
.name = "amr-efr",

View File

@ -39,7 +39,7 @@ amr_opencore_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return src_len;
}
const struct format_desc fmt_amr_opencore = {
const struct osmo_gapk_format_desc fmt_amr_opencore = {
.type = FMT_AMR_OPENCORE,
.codec_type = CODEC_AMR,
.name = "amr-opencore",

View File

@ -54,7 +54,7 @@ gsm_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return FR_CANON_LEN;
}
const struct format_desc fmt_gsm = {
const struct osmo_gapk_format_desc fmt_gsm = {
.type = FMT_GSM,
.codec_type = CODEC_FR,
.name = "gsm",

View File

@ -191,7 +191,7 @@ hr_ref_enc_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
}
const struct format_desc fmt_hr_ref_dec = {
const struct osmo_gapk_format_desc fmt_hr_ref_dec = {
.type = FMT_HR_REF_DEC,
.codec_type = CODEC_HR,
.name = "hr-ref-dec",
@ -202,7 +202,7 @@ const struct format_desc fmt_hr_ref_dec = {
.conv_to_canon = hr_ref_dec_to_canon,
};
const struct format_desc fmt_hr_ref_enc = {
const struct osmo_gapk_format_desc fmt_hr_ref_enc = {
.type = FMT_HR_REF_ENC,
.codec_type = CODEC_HR,
.name = "hr-ref-enc",

View File

@ -76,7 +76,7 @@ racal_hr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return RACAL_HR_LEN;
}
const struct format_desc fmt_racal_hr = {
const struct osmo_gapk_format_desc fmt_racal_hr = {
.type = FMT_RACAL_HR,
.codec_type = CODEC_HR,
.name = "racal-hr",
@ -124,7 +124,7 @@ racal_fr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return FR_CANON_LEN;
}
const struct format_desc fmt_racal_fr = {
const struct osmo_gapk_format_desc fmt_racal_fr = {
.type = FMT_RACAL_FR,
.codec_type = CODEC_FR,
.name = "racal-fr",
@ -166,7 +166,7 @@ racal_efr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return EFR_CANON_LEN;
}
const struct format_desc fmt_racal_efr = {
const struct osmo_gapk_format_desc fmt_racal_efr = {
.type = FMT_RACAL_EFR,
.codec_type = CODEC_EFR,
.name = "racal-efr",

View File

@ -53,7 +53,7 @@ rawpcm_s16le_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return PCM_CANON_LEN;
}
const struct format_desc fmt_rawpcm_s16le = {
const struct osmo_gapk_format_desc fmt_rawpcm_s16le = {
.type = FMT_RAWPCM_S16LE,
.codec_type = CODEC_PCM,
.name = "rawpcm-s16le",

View File

@ -48,7 +48,7 @@ rtp_amr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return src_len-1;
}
const struct format_desc fmt_rtp_amr = {
const struct osmo_gapk_format_desc fmt_rtp_amr = {
.type = FMT_RTP_AMR,
.codec_type = CODEC_AMR,
.name = "rtp-amr",

View File

@ -61,7 +61,7 @@ rtp_efr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return EFR_CANON_LEN;
}
const struct format_desc fmt_rtp_efr = {
const struct osmo_gapk_format_desc fmt_rtp_efr = {
.type = FMT_RTP_EFR,
.codec_type = CODEC_EFR,
.name = "rtp-efr",

View File

@ -48,7 +48,7 @@ rtp_hr_etsi_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return HR_CANON_LEN;
}
const struct format_desc fmt_rtp_hr_etsi = {
const struct osmo_gapk_format_desc fmt_rtp_hr_etsi = {
.type = FMT_RTP_HR_ETSI,
.codec_type = CODEC_HR,
.name = "rtp-hr-etsi",

View File

@ -68,7 +68,7 @@ rtp_hr_ietf_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return HR_CANON_LEN;
}
const struct format_desc fmt_rtp_hr_ietf = {
const struct osmo_gapk_format_desc fmt_rtp_hr_ietf = {
.type = FMT_RTP_HR_IETF,
.codec_type = CODEC_HR,
.name = "rtp-hr-ietf",

View File

@ -84,7 +84,7 @@ ti_hr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return HR_CANON_LEN;
}
const struct format_desc fmt_ti_hr = {
const struct osmo_gapk_format_desc fmt_ti_hr = {
.type = FMT_TI_HR,
.codec_type = CODEC_HR,
.name = "ti-hr",
@ -132,7 +132,7 @@ ti_fr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return FR_CANON_LEN;
}
const struct format_desc fmt_ti_fr = {
const struct osmo_gapk_format_desc fmt_ti_fr = {
.type = FMT_TI_FR,
.codec_type = CODEC_FR,
.name = "ti-fr",
@ -224,7 +224,7 @@ ti_efr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
return EFR_CANON_LEN;
}
const struct format_desc fmt_ti_efr = {
const struct osmo_gapk_format_desc fmt_ti_efr = {
.type = FMT_TI_EFR,
.codec_type = CODEC_EFR,
.name = "ti-efr",

View File

@ -23,24 +23,24 @@
#include <osmocom/gapk/formats.h>
/* Extern format descriptors */
extern const struct format_desc fmt_amr_efr;
extern const struct format_desc fmt_gsm;
extern const struct format_desc fmt_hr_ref_dec;
extern const struct format_desc fmt_hr_ref_enc;
extern const struct format_desc fmt_racal_hr;
extern const struct format_desc fmt_racal_fr;
extern const struct format_desc fmt_racal_efr;
extern const struct format_desc fmt_rawpcm_s16le;
extern const struct format_desc fmt_ti_hr;
extern const struct format_desc fmt_ti_fr;
extern const struct format_desc fmt_ti_efr;
extern const struct format_desc fmt_amr_opencore;
extern const struct format_desc fmt_rtp_amr;
extern const struct format_desc fmt_rtp_efr;
extern const struct format_desc fmt_rtp_hr_etsi;
extern const struct format_desc fmt_rtp_hr_ietf;
extern const struct osmo_gapk_format_desc fmt_amr_efr;
extern const struct osmo_gapk_format_desc fmt_gsm;
extern const struct osmo_gapk_format_desc fmt_hr_ref_dec;
extern const struct osmo_gapk_format_desc fmt_hr_ref_enc;
extern const struct osmo_gapk_format_desc fmt_racal_hr;
extern const struct osmo_gapk_format_desc fmt_racal_fr;
extern const struct osmo_gapk_format_desc fmt_racal_efr;
extern const struct osmo_gapk_format_desc fmt_rawpcm_s16le;
extern const struct osmo_gapk_format_desc fmt_ti_hr;
extern const struct osmo_gapk_format_desc fmt_ti_fr;
extern const struct osmo_gapk_format_desc fmt_ti_efr;
extern const struct osmo_gapk_format_desc fmt_amr_opencore;
extern const struct osmo_gapk_format_desc fmt_rtp_amr;
extern const struct osmo_gapk_format_desc fmt_rtp_efr;
extern const struct osmo_gapk_format_desc fmt_rtp_hr_etsi;
extern const struct osmo_gapk_format_desc fmt_rtp_hr_ietf;
static const struct format_desc *supported_formats[_FMT_MAX] = {
static const struct osmo_gapk_format_desc *supported_formats[_FMT_MAX] = {
[FMT_INVALID] = NULL,
[FMT_AMR_EFR] = &fmt_amr_efr,
[FMT_GSM] = &fmt_gsm,
@ -61,20 +61,20 @@ static const struct format_desc *supported_formats[_FMT_MAX] = {
};
const struct format_desc *
fmt_get_from_type(enum format_type type)
const struct osmo_gapk_format_desc *
osmo_gapk_fmt_get_from_type(enum osmo_gapk_format_type type)
{
if (type <= FMT_INVALID || type >= _FMT_MAX)
return NULL;
return supported_formats[type];
}
const struct format_desc *
fmt_get_from_name(const char *name)
const struct osmo_gapk_format_desc *
osmo_gapk_fmt_get_from_name(const char *name)
{
int i;
for (i=FMT_INVALID+1; i<_FMT_MAX; i++) {
const struct format_desc *fmt = supported_formats[i];
const struct osmo_gapk_format_desc *fmt = supported_formats[i];
if (!fmt)
continue;
if (!strcmp(fmt->name, name))

View File

@ -47,7 +47,7 @@ struct gapk_options
uint16_t port;
} rtp_in;
const char *alsa_in;
const struct format_desc *fmt_in;
const struct osmo_gapk_format_desc *fmt_in;
const char *fname_out;
struct {
@ -55,14 +55,14 @@ struct gapk_options
uint16_t port;
} rtp_out;
const char *alsa_out;
const struct format_desc *fmt_out;
const struct osmo_gapk_format_desc *fmt_out;
};
struct gapk_state
{
struct gapk_options opts;
struct pq *pq;
struct osmo_gapk_pq *pq;
struct {
struct {
@ -87,6 +87,7 @@ struct gapk_state
static void
print_help(char *progname)
{
const struct osmo_gapk_codec_desc *codec;
int i;
/* Header */
@ -110,7 +111,7 @@ print_help(char *progname)
fprintf(stdout, " name\tfmt enc dec\tdescription\n");
for (i=CODEC_INVALID+1; i<_CODEC_MAX; i++) {
const struct codec_desc *codec = codec_get_from_type(i);
codec = osmo_gapk_codec_get_from_type(i);
fprintf(stdout, " %4s %c %c %c \t%s\n",
codec->name,
'*',
@ -126,7 +127,7 @@ print_help(char *progname)
fprintf(stdout, "Supported formats:\n");
for (i=FMT_INVALID+1; i<_FMT_MAX; i++) {
const struct format_desc *fmt = fmt_get_from_type(i);
const struct osmo_gapk_format_desc *fmt = osmo_gapk_fmt_get_from_type(i);
fprintf(stdout, " %-19s %s\n",
fmt->name,
fmt->description
@ -230,7 +231,7 @@ parse_options(struct gapk_state *state, int argc, char *argv[])
break;
case 'f':
opt->fmt_in = fmt_get_from_name(optarg);
opt->fmt_in = osmo_gapk_fmt_get_from_name(optarg);
if (!opt->fmt_in) {
fprintf(stderr, "[!] Unsupported format: %s\n", optarg);
return -EINVAL;
@ -238,7 +239,7 @@ parse_options(struct gapk_state *state, int argc, char *argv[])
break;
case 'g':
opt->fmt_out = fmt_get_from_name(optarg);
opt->fmt_out = osmo_gapk_fmt_get_from_name(optarg);
if (!opt->fmt_out) {
fprintf(stderr, "[!] Unsupported format: %s\n", optarg);
return -EINVAL;
@ -269,10 +270,10 @@ check_options(struct gapk_state *gs)
/* Transcoding */
if (gs->opts.fmt_in->codec_type != gs->opts.fmt_out->codec_type) {
const struct codec_desc *codec;
const struct osmo_gapk_codec_desc *codec;
/* Check source codec */
codec = codec_get_from_type(gs->opts.fmt_in->codec_type);
codec = osmo_gapk_codec_get_from_type(gs->opts.fmt_in->codec_type);
if (!codec) {
fprintf(stderr, "[!] Internal error: bad codec reference\n");
return -EINVAL;
@ -283,7 +284,7 @@ check_options(struct gapk_state *gs)
}
/* Check destination codec */
codec = codec_get_from_type(gs->opts.fmt_out->codec_type);
codec = osmo_gapk_codec_get_from_type(gs->opts.fmt_out->codec_type);
if (!codec) {
fprintf(stderr, "[!] Internal error: bad codec reference\n");
return -EINVAL;
@ -413,16 +414,16 @@ handle_headers(struct gapk_state *gs)
static int
make_processing_chain(struct gapk_state *gs)
{
const struct format_desc *fmt_in, *fmt_out;
const struct codec_desc *codec_in, *codec_out;
const struct osmo_gapk_format_desc *fmt_in, *fmt_out;
const struct osmo_gapk_codec_desc *codec_in, *codec_out;
int need_dec, need_enc;
fmt_in = gs->opts.fmt_in;
fmt_out = gs->opts.fmt_out;
codec_in = codec_get_from_type(fmt_in->codec_type);
codec_out = codec_get_from_type(fmt_out->codec_type);
codec_in = osmo_gapk_codec_get_from_type(fmt_in->codec_type);
codec_out = osmo_gapk_codec_get_from_type(fmt_out->codec_type);
need_dec = (fmt_in->codec_type != CODEC_PCM) &&
(fmt_in->codec_type != fmt_out->codec_type);
@ -431,12 +432,12 @@ make_processing_chain(struct gapk_state *gs)
/* File read */
if (gs->in.file.fh)
pq_queue_file_input(gs->pq, gs->in.file.fh, fmt_in->frame_len);
osmo_gapk_pq_queue_file_input(gs->pq, gs->in.file.fh, fmt_in->frame_len);
else if (gs->in.rtp.fd != -1)
pq_queue_rtp_input(gs->pq, gs->in.rtp.fd, fmt_in->frame_len);
osmo_gapk_pq_queue_rtp_input(gs->pq, gs->in.rtp.fd, fmt_in->frame_len);
#ifdef HAVE_ALSA
else if (gs->opts.alsa_in)
pq_queue_alsa_input(gs->pq, gs->opts.alsa_in, fmt_in->frame_len);
osmo_gapk_pq_queue_alsa_input(gs->pq, gs->opts.alsa_in, fmt_in->frame_len);
#endif
else {
fprintf(stderr, "Unknown/invalid input\n");
@ -449,64 +450,64 @@ make_processing_chain(struct gapk_state *gs)
/* Convert input to decoder input fmt */
if (fmt_in->type != codec_in->codec_dec_format_type)
{
const struct format_desc *fmt_dec;
const struct osmo_gapk_format_desc *fmt_dec;
fmt_dec = fmt_get_from_type(codec_in->codec_dec_format_type);
fmt_dec = osmo_gapk_fmt_get_from_type(codec_in->codec_dec_format_type);
if (!fmt_dec) {
fprintf(stderr, "Cannot determine decoder input format for codec %s\n",
codec_in->name);
return -EINVAL;
}
pq_queue_fmt_convert(gs->pq, fmt_in, 0);
pq_queue_fmt_convert(gs->pq, fmt_dec, 1);
osmo_gapk_pq_queue_fmt_convert(gs->pq, fmt_in, 0);
osmo_gapk_pq_queue_fmt_convert(gs->pq, fmt_dec, 1);
}
/* Do decoding */
pq_queue_codec(gs->pq, codec_in, 0);
osmo_gapk_pq_queue_codec(gs->pq, codec_in, 0);
}
else if (fmt_in->type != fmt_out->type)
{
/* Convert input to canonical fmt */
pq_queue_fmt_convert(gs->pq, fmt_in, 0);
osmo_gapk_pq_queue_fmt_convert(gs->pq, fmt_in, 0);
}
/* Encoding from PCM ? */
if (need_enc)
{
/* Do encoding */
pq_queue_codec(gs->pq, codec_out, 1);
osmo_gapk_pq_queue_codec(gs->pq, codec_out, 1);
/* Convert encoder output to output fmt */
if (fmt_out->type != codec_out->codec_enc_format_type)
{
const struct format_desc *fmt_enc;
const struct osmo_gapk_format_desc *fmt_enc;
fmt_enc = fmt_get_from_type(codec_out->codec_enc_format_type);
fmt_enc = osmo_gapk_fmt_get_from_type(codec_out->codec_enc_format_type);
if (!fmt_enc) {
fprintf(stderr, "Cannot determine encoder output format for codec %s\n",
codec_out->name);
return -EINVAL;
}
pq_queue_fmt_convert(gs->pq, fmt_enc, 0);
pq_queue_fmt_convert(gs->pq, fmt_out, 1);
osmo_gapk_pq_queue_fmt_convert(gs->pq, fmt_enc, 0);
osmo_gapk_pq_queue_fmt_convert(gs->pq, fmt_out, 1);
}
}
else if (fmt_in->type != fmt_out->type)
{
/* Convert canonical to output fmt */
pq_queue_fmt_convert(gs->pq, fmt_out, 1);
osmo_gapk_pq_queue_fmt_convert(gs->pq, fmt_out, 1);
}
/* File write */
if (gs->out.file.fh)
pq_queue_file_output(gs->pq, gs->out.file.fh, fmt_out->frame_len);
osmo_gapk_pq_queue_file_output(gs->pq, gs->out.file.fh, fmt_out->frame_len);
else if (gs->out.rtp.fd != -1)
pq_queue_rtp_output(gs->pq, gs->out.rtp.fd, fmt_out->frame_len);
osmo_gapk_pq_queue_rtp_output(gs->pq, gs->out.rtp.fd, fmt_out->frame_len);
#ifdef HAVE_ALSA
else if (gs->opts.alsa_out)
pq_queue_alsa_output(gs->pq, gs->opts.alsa_out, fmt_out->frame_len);
osmo_gapk_pq_queue_alsa_output(gs->pq, gs->opts.alsa_out, fmt_out->frame_len);
#endif
else {
fprintf(stderr, "Unknown/invalid output\n");
@ -521,11 +522,11 @@ run(struct gapk_state *gs)
{
int rv, frames;
rv = pq_prepare(gs->pq);
rv = osmo_gapk_pq_prepare(gs->pq);
if (rv)
return rv;
for (frames=0; !(rv = pq_execute(gs->pq)); frames++);
for (frames=0; !(rv = osmo_gapk_pq_execute(gs->pq)); frames++);
fprintf(stderr, "[+] Processed %d frames\n", frames);
@ -541,7 +542,7 @@ static void signal_handler(int signal)
case SIGINT:
fprintf(stderr, "catching sigint, closing files\n");
files_close(gs);
pq_destroy(gs->pq);
osmo_gapk_pq_destroy(gs->pq);
exit(0);
break;
default:
@ -574,7 +575,7 @@ int main(int argc, char *argv[])
return rv;
/* Create processing queue */
gs->pq = pq_create();
gs->pq = osmo_gapk_pq_create();
if (!gs->pq) {
rv = -ENOMEM;
fprintf(stderr, "Error creating processing queue\n");
@ -612,7 +613,7 @@ error:
files_close(gs);
/* Release processing queue */
pq_destroy(gs->pq);
osmo_gapk_pq_destroy(gs->pq);
benchmark_dump();

View File

@ -77,9 +77,9 @@ pq_cb_alsa_exit(void *_state)
}
static int
pq_queue_alsa_op(struct pq *pq, const char *alsa_dev, unsigned int blk_len, int in_out_n)
pq_queue_alsa_op(struct osmo_gapk_pq *pq, const char *alsa_dev, unsigned int blk_len, int in_out_n)
{
struct pq_item *item;
struct osmo_gapk_pq_item *item;
struct pq_state_alsa *state;
snd_pcm_hw_params_t *hw_params;
int rc = -1;
@ -127,7 +127,7 @@ pq_queue_alsa_op(struct pq *pq, const char *alsa_dev, unsigned int blk_len, int
snd_pcm_hw_params_free(hw_params);
item = pq_add_item(pq);
item = osmo_gapk_pq_add_item(pq);
if (!item) {
rc = -ENOMEM;
goto out_close;
@ -160,7 +160,7 @@ out_print:
* \param[in] blk_len block length to be read from device
* \returns 0 on sucess; negative on error */
int
pq_queue_alsa_input(struct pq *pq, const char *hwdev, unsigned int blk_len)
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);
return pq_queue_alsa_op(pq, hwdev, blk_len, 1);
@ -173,7 +173,7 @@ pq_queue_alsa_input(struct pq *pq, const char *hwdev, unsigned int blk_len)
* \param[in] blk_len block length to be written to device
* \returns 0 on sucess; negative on error */
int
pq_queue_alsa_output(struct pq *pq, const char *hwdev, unsigned int blk_len)
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);
return pq_queue_alsa_op(pq, hwdev, blk_len, 0);

View File

@ -31,14 +31,14 @@
* \param[in] encode (1) or decode (0)
* \returns 0 on success; negative on error */
int
pq_queue_codec(struct pq *pq, const struct codec_desc *codec, int enc_dec_n)
osmo_gapk_pq_queue_codec(struct osmo_gapk_pq *pq, const struct osmo_gapk_codec_desc *codec, int enc_dec_n)
{
const struct codec_desc *codec_pcm = codec_get_from_type(CODEC_PCM);
const struct format_desc *fmt;
struct pq_item *item;
const struct osmo_gapk_codec_desc *codec_pcm;
const struct osmo_gapk_format_desc *fmt;
struct osmo_gapk_pq_item *item;
/* allocate a new item to the processing queue */
item = pq_add_item(pq);
item = osmo_gapk_pq_add_item(pq);
if (!item)
return -ENOMEM;
@ -50,7 +50,8 @@ pq_queue_codec(struct pq *pq, const struct codec_desc *codec, int enc_dec_n)
}
if (enc_dec_n) {
fmt = fmt_get_from_type(codec->codec_enc_format_type);
codec_pcm = osmo_gapk_codec_get_from_type(CODEC_PCM);
fmt = osmo_gapk_fmt_get_from_type(codec->codec_enc_format_type);
if (!fmt)
return -EINVAL;
@ -58,7 +59,8 @@ pq_queue_codec(struct pq *pq, const struct codec_desc *codec, int enc_dec_n)
item->len_out = fmt->frame_len;
item->proc = codec->codec_encode;
} else {
fmt = fmt_get_from_type(codec->codec_dec_format_type);
codec_pcm = osmo_gapk_codec_get_from_type(CODEC_PCM);
fmt = osmo_gapk_fmt_get_from_type(codec->codec_dec_format_type);
if (!fmt)
return -EINVAL;

View File

@ -60,9 +60,9 @@ pq_cb_file_exit(void *_state)
}
static int
pq_queue_file_op(struct pq *pq, FILE *fh, unsigned int blk_len, int in_out_n)
pq_queue_file_op(struct osmo_gapk_pq *pq, FILE *fh, unsigned int blk_len, int in_out_n)
{
struct pq_item *item;
struct osmo_gapk_pq_item *item;
struct pq_state_file *state;
state = calloc(1, sizeof(struct pq_state_file));
@ -72,7 +72,7 @@ pq_queue_file_op(struct pq *pq, FILE *fh, unsigned int blk_len, int in_out_n)
state->fh = fh;
state->blk_len = blk_len;
item = pq_add_item(pq);
item = osmo_gapk_pq_add_item(pq);
if (!item) {
free(state);
return -ENOMEM;
@ -95,7 +95,7 @@ pq_queue_file_op(struct pq *pq, FILE *fh, unsigned int blk_len, int in_out_n)
* \param[in] blk_len block length to be read from file
* \returns 0 on sucess; negative on error */
int
pq_queue_file_input(struct pq *pq, FILE *src, unsigned int blk_len)
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);
return pq_queue_file_op(pq, src, blk_len, 1);
@ -108,7 +108,7 @@ pq_queue_file_input(struct pq *pq, FILE *src, unsigned int blk_len)
* \param[in] blk_len block length to be written to file
* \returns 0 on sucess; negative on error */
int
pq_queue_file_output(struct pq *pq, FILE *dst, unsigned int blk_len)
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);
return pq_queue_file_op(pq, dst, blk_len, 0);

View File

@ -28,7 +28,7 @@
static int
pq_cb_fmt_convert(void *_state, uint8_t *out, const uint8_t *in, unsigned int in_len)
{
fmt_conv_cb_t f = _state;
osmo_gapk_fmt_conv_cb_t f = _state;
return f(out, in, in_len);
}
@ -37,18 +37,19 @@ pq_cb_fmt_convert(void *_state, uint8_t *out, const uint8_t *in, unsigned int in
* \param[in] fmt Format description for conversion
* \param[in] to_from_n convert to (0) or from (1) specified format */
int
pq_queue_fmt_convert(struct pq *pq, const struct format_desc *fmt, int to_from_n)
osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_format_desc *fmt, int to_from_n)
{
struct pq_item *item;
const struct codec_desc *codec = codec_get_from_type(fmt->codec_type);
const struct osmo_gapk_codec_desc *codec;
struct osmo_gapk_pq_item *item;
codec = osmo_gapk_codec_get_from_type(fmt->codec_type);
if (!codec) {
fprintf(stderr, "[!] Cannot determine codec from format %s\n", fmt->name);
return -EINVAL;
}
item = pq_add_item(pq);
item = osmo_gapk_pq_add_item(pq);
if (!item)
return -ENOMEM;

View File

@ -192,9 +192,9 @@ pq_cb_rtp_exit(void *_state)
}
static int
pq_queue_rtp_op(struct pq *pq, int udp_fd, unsigned int blk_len, int in_out_n)
pq_queue_rtp_op(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len, int in_out_n)
{
struct pq_item *item;
struct osmo_gapk_pq_item *item;
struct pq_state_rtp *state;
state = calloc(1, sizeof(struct pq_state_rtp));
@ -217,7 +217,7 @@ pq_queue_rtp_op(struct pq *pq, int udp_fd, unsigned int blk_len, int in_out_n)
state->payload_type = RTP_PT_GSM_FULL;
}
item = pq_add_item(pq);
item = osmo_gapk_pq_add_item(pq);
if (!item) {
free(state);
return -ENOMEM;
@ -239,7 +239,7 @@ pq_queue_rtp_op(struct pq *pq, int udp_fd, unsigned int blk_len, int in_out_n)
* \param[in] udp_fd UDP file descriptor for the RTP input
* \param[in] blk_len Block Length to read from RTP */
int
pq_queue_rtp_input(struct pq *pq, int udp_fd, unsigned int blk_len)
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);
return pq_queue_rtp_op(pq, udp_fd, blk_len, 1);
@ -251,7 +251,7 @@ pq_queue_rtp_input(struct pq *pq, int udp_fd, unsigned int blk_len)
* \param[in] udp_fd UDP file descriptor for the RTP output
* \param[in] blk_len Block Length to read from RTP */
int
pq_queue_rtp_output(struct pq *pq, int udp_fd, unsigned int blk_len)
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);
return pq_queue_rtp_op(pq, udp_fd, blk_len, 0);

View File

@ -24,16 +24,16 @@
#include <osmocom/gapk/procqueue.h>
/* crate a new (empty) processing queue */
struct pq *
pq_create(void)
struct osmo_gapk_pq *
osmo_gapk_pq_create(void)
{
return (struct pq *) calloc(1, sizeof(struct pq));
return (struct osmo_gapk_pq *) calloc(1, sizeof(struct osmo_gapk_pq));
}
/*! destroy a processing queue, calls exit() callback of each item
* \param[in] pq Processing Queue to be destroyed */
void
pq_destroy(struct pq *pq)
osmo_gapk_pq_destroy(struct osmo_gapk_pq *pq)
{
int i;
@ -57,10 +57,10 @@ pq_destroy(struct pq *pq)
/*! allocate + add an item to a processing queue; return new item
* \param[in] pq Processing Queue to which item is added
* \returns new PQ item; NULL on error */
struct pq_item *
pq_add_item(struct pq *pq)
struct osmo_gapk_pq_item *
osmo_gapk_pq_add_item(struct osmo_gapk_pq *pq)
{
struct pq_item *item;
struct osmo_gapk_pq_item *item;
if (pq->n_items == MAX_PQ_ITEMS) {
fprintf(stderr, "[!] Processing Queue cannot handle more than %u items\n",
@ -68,7 +68,7 @@ pq_add_item(struct pq *pq)
return NULL;
}
item = calloc(1, sizeof(struct pq_item));
item = calloc(1, sizeof(struct osmo_gapk_pq_item));
if (!item)
return NULL;
@ -81,7 +81,7 @@ pq_add_item(struct pq *pq)
* \param[in] pq Processing Queue to be prepared
* \returns 0 on succcess; negative on error */
int
pq_prepare(struct pq *pq)
osmo_gapk_pq_prepare(struct osmo_gapk_pq *pq)
{
int i;
unsigned int len_prev;
@ -89,7 +89,7 @@ pq_prepare(struct pq *pq)
len_prev = 0;
for (i=0; i<pq->n_items; i++) {
struct pq_item *item = pq->items[i];
struct osmo_gapk_pq_item *item = pq->items[i];
if (item->len_in && item->len_in != len_prev) {
fprintf(stderr, "[!] PQ item requires input size %u, but previous output is %u\n",
@ -121,7 +121,7 @@ pq_prepare(struct pq *pq)
* \param[in] pq Processing Queue to be executed
* \returns 0 on success; negative on error (if any item returns negative) */
int
pq_execute(struct pq *pq)
osmo_gapk_pq_execute(struct osmo_gapk_pq *pq)
{
int i;
void *buf_prev, *buf;
@ -132,13 +132,13 @@ pq_execute(struct pq *pq)
for (i=0; i<pq->n_items; i++) {
int rv;
struct pq_item *item = pq->items[i];
struct osmo_gapk_pq_item *item = pq->items[i];
buf = i < (pq->n_items-1) ? pq->buffers[i] : NULL;
rv = item->proc(item->state, buf, buf_prev, len_prev);
if (rv < 0) {
fprintf(stderr, "[!] pq_execute(): abort, item returned %d\n", rv);
fprintf(stderr, "[!] osmo_gapk_pq_execute(): abort, item returned %d\n", rv);
return rv;
}