From patchwork Thu May 15 08:29:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Erlbeck X-Patchwork-Id: 349099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 70FE01400DE for ; Thu, 15 May 2014 18:47:38 +1000 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1WkrK1-0000GY-Bf; Thu, 15 May 2014 10:47:25 +0200 Received: from mail.sysmocom.de ([144.76.43.93]) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1WkrDo-0007xP-5a for openbsc@lists.osmocom.org; Thu, 15 May 2014 10:41:05 +0200 Received: from sysmocom-tmp.home (24-134-58-61-dynip.superkabel.de [24.134.58.61]) by mail.sysmocom.de (Postfix) with ESMTPSA id 0716D58F0F; Thu, 15 May 2014 08:40:53 +0000 (UTC) From: Jacob Erlbeck To: openbsc@lists.osmocom.org Subject: [PATCH 06/11] mgcp: Add CLI tool to test audio conversion Date: Thu, 15 May 2014 10:29:14 +0200 Message-Id: <1400142559-26788-6-git-send-email-jerlbeck@sysmocom.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1400142559-26788-1-git-send-email-jerlbeck@sysmocom.de> References: <1399891147-31419-1-git-send-email-jerlbeck@sysmocom.de> <1400142559-26788-1-git-send-email-jerlbeck@sysmocom.de> X-Spam-Score: 0.3 (/) X-Spam-Report: SpamASsassin versoin 3.3.1 on ganesha.gnumonks.org summary: Content analysis details: (0.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.1 TW_CF BODY: Odd Letter Triples with CF 0.1 TW_MG BODY: Odd Letter Triples with MG 0.1 TW_GC BODY: Odd Letter Triples with GC 0.1 TW_LR BODY: Odd Letter Triples with LR 0.0 T_FILL_THIS_FORM_SHORT Fill in a short form with personal information Cc: Jacob Erlbeck X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openbsc-bounces@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org This tool uses mgcp_transcode.c to convert audio data from stdin to stdout. Sponsored-by: On-Waves ehf --- openbsc/contrib/testconv/Makefile | 17 ++++++ openbsc/contrib/testconv/testconv_main.c | 91 ++++++++++++++++++++++++++++ openbsc/src/osmo-bsc_mgcp/mgcp_transcode.c | 13 ++++ openbsc/src/osmo-bsc_mgcp/mgcp_transcode.h | 2 + 4 files changed, 123 insertions(+) create mode 100644 openbsc/contrib/testconv/Makefile create mode 100644 openbsc/contrib/testconv/testconv_main.c diff --git a/openbsc/contrib/testconv/Makefile b/openbsc/contrib/testconv/Makefile new file mode 100644 index 0000000..90adecc --- /dev/null +++ b/openbsc/contrib/testconv/Makefile @@ -0,0 +1,17 @@ + +OBJS = testconv_main.o mgcp_transcode.o + +CC = gcc +CFLAGS = -O0 -ggdb -Wall +LDFLAGS = +CPPFLAGS = -I../.. -I../../include $(shell pkg-config --cflags libosmocore) $(shell pkg-config --cflags libbcg729) +LIBS = ../../src/libmgcp/libmgcp.a ../../src/libcommon/libcommon.a $(shell pkg-config --libs libosmocore) $(shell pkg-config --libs libbcg729) -lgsm -lrt + +testconv: $(OBJS) + $(CC) -o $@ $^ $(LDFLAGS) $(LIBS) + +testconv_main.o: testconv_main.c +mgcp_transcode.o: ../../src/osmo-bsc_mgcp/mgcp_transcode.c + +$(OBJS): + $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< diff --git a/openbsc/contrib/testconv/testconv_main.c b/openbsc/contrib/testconv/testconv_main.c new file mode 100644 index 0000000..c2785f2 --- /dev/null +++ b/openbsc/contrib/testconv/testconv_main.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "bscconfig.h" +#ifndef BUILD_MGCP_TRANSCODING +#error "Requires MGCP transcoding enabled (see --enable-mgcp-transcoding)" +#endif + +#include "src/osmo-bsc_mgcp/mgcp_transcode.h" + +static int audio_name_to_type(const char *name) +{ + if (!strcasecmp(name, "gsm")) + return 3; +#ifdef HAVE_BCG729 + else if (!strcasecmp(name, "g729")) + return 18; +#endif + else if (!strcasecmp(name, "pcma")) + return 8; + else if (!strcasecmp(name, "l16")) + return 11; + return -1; +} + +int mgcp_get_trans_frame_size(void *state_, int nsamples, int dst); + +int main(int argc, char **argv) +{ + char buf[4096] = {0}; + int cc, rc; + struct mgcp_rtp_end dst_end = {0}; + struct mgcp_rtp_end src_end = {0}; + struct mgcp_trunk_config tcfg = {{0}}; + struct mgcp_endpoint endp = {0}; + struct mgcp_process_rtp_state *state; + int in_size; + + osmo_init_logging(&log_info); + + tcfg.endpoints = &endp; + tcfg.number_endpoints = 1; + endp.tcfg = &tcfg; + + if (argc <= 2) + errx(1, "Usage: {gsm|g729|pcma|l16} {gsm|g729|pcma|l16}"); + + if ((src_end.payload_type = audio_name_to_type(argv[1])) == -1) + errx(1, "invalid input format '%s'", argv[1]); + if ((dst_end.payload_type = audio_name_to_type(argv[2])) == -1) + errx(1, "invalid output format '%s'", argv[2]); + + rc = mgcp_transcoding_setup(&endp, &dst_end, &src_end); + if (rc < 0) + errx(1, "setup failed: %s", strerror(-rc)); + + state = dst_end.rtp_process_data; + OSMO_ASSERT(state != NULL); + + in_size = mgcp_transcoding_get_frame_size(state, 160, 0); + OSMO_ASSERT(sizeof(buf) >= in_size + 12); + + while ((cc = read(0, buf + 12, in_size))) { + if (cc != in_size) + err(1, "read"); + + cc += 12; /* include RTP header */ + + rc = mgcp_transcoding_process_rtp(&endp, &dst_end, + buf, &cc, sizeof(buf)); + if (rc < 0) + errx(1, "processing failed: %s", strerror(-rc)); + + cc -= 12; /* ignore RTP header */ + if (write(1, buf + 12, cc) != cc) + err(1, "write"); + } + return 0; +} + diff --git a/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.c b/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.c index 7247c88..67e7e52 100644 --- a/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.c +++ b/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.c @@ -72,6 +72,19 @@ struct mgcp_process_rtp_state { size_t dst_samples_per_frame; }; +int mgcp_transcoding_get_frame_size(void *state_, int nsamples, int dst) +{ + struct mgcp_process_rtp_state *state = state_; + if (dst) + return (nsamples >= 0 ? + nsamples / state->dst_samples_per_frame : + 1) * state->dst_frame_size; + else + return (nsamples >= 0 ? + nsamples / state->src_samples_per_frame : + 1) * state->src_frame_size; +} + static enum audio_format get_audio_format(const struct mgcp_rtp_end *rtp_end) { if (rtp_end->subtype_name) { diff --git a/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.h b/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.h index 2dfb06a..0961634 100644 --- a/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.h +++ b/openbsc/src/osmo-bsc_mgcp/mgcp_transcode.h @@ -31,4 +31,6 @@ void mgcp_transcoding_net_downlink_format(struct mgcp_endpoint *endp, int mgcp_transcoding_process_rtp(struct mgcp_endpoint *endp, struct mgcp_rtp_end *dst_end, char *data, int *len, int buf_size); + +int mgcp_transcoding_get_frame_size(void *state_, int nsamples, int dst); #endif /* OPENBSC_MGCP_TRANSCODE_H */