From patchwork Tue Apr 29 10:40:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Erlbeck X-Patchwork-Id: 343783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [213.95.27.120]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7F93B14007A for ; Tue, 29 Apr 2014 20:41:05 +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 1Wf5T2-0004zL-I1; Tue, 29 Apr 2014 12:40:52 +0200 Received: from mail.sysmocom.de ([2a01:4f8:191:444c::2:4]) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1Wf5Sa-0004ts-W5 for openbsc@lists.osmocom.org; Tue, 29 Apr 2014 12:40:31 +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 BEB5655CAB; Tue, 29 Apr 2014 10:40:24 +0000 (UTC) From: Jacob Erlbeck To: openbsc@lists.osmocom.org Subject: [PATCH] contrib/rtp: Use payload data files directly by gen_rtp_header Date: Tue, 29 Apr 2014 12:40:21 +0200 Message-Id: <1398768021-27350-1-git-send-email-jerlbeck@sysmocom.de> X-Mailer: git-send-email 1.7.9.5 X-Spam-Score: 0.0 (/) 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 adds a --frame-size option to read payload binary files with a fixed frame size directly. The file must not contain RTP headers. In addition '--rate' and '--duration' can be used to configure the timing. Sponsored-by: On-Waves ehf --- openbsc/contrib/rtp/gen_rtp_header.erl | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/openbsc/contrib/rtp/gen_rtp_header.erl b/openbsc/contrib/rtp/gen_rtp_header.erl index cc4c61c..47839c1 100755 --- a/openbsc/contrib/rtp/gen_rtp_header.erl +++ b/openbsc/contrib/rtp/gen_rtp_header.erl @@ -28,6 +28,7 @@ main(Args) -> DefaultOpts = [{format, state}, {ssrc, 16#11223344}, + {rate, 8000}, {pt, 98}], {PosArgs, Opts} = getopts_checked(Args, DefaultOpts), log(debug, fun (Dev) -> @@ -144,7 +145,8 @@ show_help() -> "Options:~n" ++ " -h, --help this text~n" ++ " --version show version info~n" ++ - " -i, --file=FILE reads payload from state file~n" ++ + " -i, --file=FILE reads payload from file (state format by default)~n" ++ + " -f, --frame-size=N read payload as binary frames of size N instead~n" ++ " -p, --payload=HEX set constant payload~n" ++ " --verbose=N set verbosity~n" ++ " -v increase verbosity~n" ++ @@ -153,6 +155,8 @@ show_help() -> " --format=carray use a C array for output~n" ++ " -s, --ssrc=SSRC set the SSRC~n" ++ " -t, --type=N set the payload type~n" ++ + " -r, --rate=N set the RTP rate [8000]~n" ++ + " -D, --duration=N set the packet duration in RTP time units [160]~n" ++ " -d, --delay=FLOAT add offset to playout timestamp~n" ++ "~n" ++ "Arguments:~n" ++ @@ -165,6 +169,21 @@ getopts([ "--file=" ++ File | R], Opts) -> getopts(R, [{file, File} | Opts]); getopts([ "-i" ++ T | R], Opts) -> getopts_alias_arg("--file", T, R, Opts); +getopts([ "--frame-size=" ++ N | R], Opts) -> + Size = list_to_integer(N), + getopts(R, [{frame_size, Size}, {in_format, bin} | Opts]); +getopts([ "-f" ++ T | R], Opts) -> + getopts_alias_arg("--frame-size", T, R, Opts); +getopts([ "--duration=" ++ N | R], Opts) -> + Duration = list_to_integer(N), + getopts(R, [{duration, Duration} | Opts]); +getopts([ "-D" ++ T | R], Opts) -> + getopts_alias_arg("--duration", T, R, Opts); +getopts([ "--rate=" ++ N | R], Opts) -> + Rate = list_to_integer(N), + getopts(R, [{rate, Rate} | Opts]); +getopts([ "-r" ++ T | R], Opts) -> + getopts_alias_arg("--rate", T, R, Opts); getopts([ "--version" | _], _Opts) -> show_version(), halt(0); @@ -328,9 +347,10 @@ write_packets(Dev, DataSource, P = #rtp_packet{}, F, L, O, Opts) -> Format = proplists:get_value(format, Opts, state), Ptime = proplists:get_value(duration, Opts, 160), Delay = proplists:get_value(delay, Opts, 0), + Rate = proplists:get_value(rate, Opts, 8000), case next_payload(DataSource) of {Payload, DataSource2} -> - write_packet(Dev, 0.020 * F + Delay, + write_packet(Dev, Ptime * F / Rate + Delay, P#rtp_packet{seqno = F, timestamp = F*Ptime+O, payload = Payload}, Format), @@ -376,12 +396,18 @@ read_packets(Dev, Opts) -> read_packets(Dev, Opts, Format). read_packets(Dev, Opts, Format) -> - case read_packet(Dev, Format) of + case read_packet(Dev, Opts, Format) of eof -> []; Tuple -> [Tuple | read_packets(Dev, Opts, Format)] end. -read_packet(Dev, Format) -> +read_packet(Dev, Opts, bin) -> + Size = proplists:get_value(frame_size, Opts), + case file:read(Dev, Size) of + {ok, Data} -> {0, #rtp_packet{payload = iolist_to_binary(Data)}}; + eof -> eof + end; +read_packet(Dev, _Opts, Format) -> case read_packet_line(Dev, Format) of {Time, Bin} -> {Time, parse_rtp_packet(Bin)}; eof -> eof