From 587e93a55e6d58076c76f3c611dab002c34001e6 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Fri, 18 Sep 2015 15:13:29 -0700 Subject: Start moving RTP decoding routines to the ui directory. Move decode_rtp_packet to ui/rtp_media.[ch]. Change-Id: Ib138781c37ac17b807bf75f9d772351aadf72071 Reviewed-on: https://code.wireshark.org/review/10575 Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs --- ui/CMakeLists.txt | 2 + ui/Makefile.common | 2 + ui/gtk/rtp_player.c | 97 ++++--------------------------------- ui/rtp_media.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ui/rtp_media.h | 88 ++++++++++++++++++++++++++++++++++ 5 files changed, 234 insertions(+), 89 deletions(-) create mode 100644 ui/rtp_media.c create mode 100644 ui/rtp_media.h (limited to 'ui') diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 6bf323733a..3a36920839 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -44,6 +44,7 @@ set(COMMON_UI_SRC profile.c proto_hier_stats.c recent.c + rtp_media.c rtp_stream.c service_response_time.c software_update.c @@ -63,6 +64,7 @@ set(COMMON_UI_SRC # Enables visibility in IDEs file(GLOB EXTRA_UI_HEADERS + rtp_media.h rtp_stream.h tap-iax2-analysis.h tap-rtp-analysis.h diff --git a/ui/Makefile.common b/ui/Makefile.common index 81bd16ffa0..15ce1010c1 100644 --- a/ui/Makefile.common +++ b/ui/Makefile.common @@ -65,6 +65,7 @@ WIRESHARK_UI_SRC = \ profile.c \ proto_hier_stats.c \ recent.c \ + rtp_media.c \ rtp_stream.c \ service_response_time.c \ software_update.c \ @@ -107,6 +108,7 @@ noinst_HEADERS = \ proto_hier_stats.h \ recent.h \ recent_utils.h \ + rtp_media.h \ rtp_stream.h \ service_response_time.h \ simple_dialog.h \ diff --git a/ui/gtk/rtp_player.c b/ui/gtk/rtp_player.c index 50bbf70fbe..2774544926 100644 --- a/ui/gtk/rtp_player.c +++ b/ui/gtk/rtp_player.c @@ -66,10 +66,9 @@ #include #include -#include - #include "globals.h" +#include "ui/rtp_media.h" #include "ui/rtp_stream.h" #include "ui/simple_dialog.h" #include "ui/voip_calls.h" @@ -127,7 +126,6 @@ static unsigned channels = 1; static unsigned output_channels = 2; #define PA_SAMPLE_TYPE paInt16 -typedef gint16 SAMPLE; #define SAMPLE_SILENCE (0) #define FRAMES_PER_BUFFER (512) @@ -190,13 +188,6 @@ typedef struct _rtp_channel_info { guint32 num_packets; } rtp_channel_info_t; -/* defines a RTP packet */ -typedef struct _rtp_packet { - struct _rtp_info *info; /* the RTP dissected info */ - double arrive_offset; /* arrive offset time since the beginning of the stream in ms */ - guint8* payload_data; -} rtp_packet_t; - /* defines the two RTP channels to be played */ typedef struct _rtp_play_channles { rtp_channel_info_t* rci[2]; /* Channels to be played */ @@ -219,11 +210,6 @@ typedef struct _rtp_play_channles { /* The two RTP channels to play */ static rtp_play_channels_t *rtp_channels = NULL; -typedef struct _rtp_decoder_t { - codec_handle_t handle; - void *context; -} rtp_decoder_t; - typedef struct _data_info { int current_channel; @@ -274,17 +260,6 @@ rtp_stream_value_destroy(gpointer rsi_arg) rsi = NULL; } -/****************************************************************************/ -static void -rtp_decoder_value_destroy(gpointer dec_arg) -{ - rtp_decoder_t *dec = (rtp_decoder_t *)dec_arg; - - if (dec->handle) - codec_release(dec->handle, dec->context); - g_free(dec_arg); -} - /****************************************************************************/ static void set_sensitive_check_bt(gchar *key _U_ , rtp_channel_info_t *rci, guint *stop_p ) @@ -379,14 +354,14 @@ add_rtp_packet(const struct _rtp_info *rtp_info, packet_info *pinfo) } /* increment the number of packets in this stream, this is used for the progress bar and statistics */ - stream_info->packet_count++; + stream_info->packet_count++; /* Add the RTP packet to the list */ - new_rtp_packet = g_new0(rtp_packet_t, 1); + new_rtp_packet = g_new0(rtp_packet_t, 1); new_rtp_packet->info = (struct _rtp_info *)g_malloc(sizeof(struct _rtp_info)); memcpy(new_rtp_packet->info, rtp_info, sizeof(struct _rtp_info)); - new_rtp_packet->arrive_offset = nstime_to_msec(&pinfo->rel_ts) - nstime_to_msec(&stream_info->start_rel_time); + new_rtp_packet->arrive_offset = nstime_to_msec(&pinfo->rel_ts) - nstime_to_msec(&stream_info->start_rel_time); /* copy the RTP payload to the rtp_packet to be decoded later */ if (rtp_info->info_all_data_present && (rtp_info->info_payload_len != 0)) { new_rtp_packet->payload_data = (guint8 *)g_malloc(rtp_info->info_payload_len); @@ -395,7 +370,7 @@ add_rtp_packet(const struct _rtp_info *rtp_info, packet_info *pinfo) new_rtp_packet->payload_data = NULL; } - stream_info->rtp_packet_list = g_list_append(stream_info->rtp_packet_list, new_rtp_packet); + stream_info->rtp_packet_list = g_list_append(stream_info->rtp_packet_list, new_rtp_packet); g_string_free(key_str, TRUE); } @@ -415,7 +390,7 @@ mark_rtp_stream_to_play(gchar *key _U_ , rtp_stream_info_t *rsi, gpointer ptr _U /* Reset the "to be play" value because the user can close and reopen the RTP Player window * and the streams are not reset in that case */ - rsi->decode = FALSE; + rsi->decode = FALSE; /* and associate the RTP stream with a call using the first RTP packet in the stream */ graph_list = g_queue_peek_nth_link(voip_calls->graph_analysis->items, 0); @@ -453,62 +428,6 @@ mark_all_rtp_stream_to_decode(gchar *key _U_ , rtp_stream_info_t *rsi, gpointer total_packets += rsi->packet_count; } -/****************************************************************************/ -/* Decode a RTP packet - * Return the number of decoded bytes - */ -static size_t -decode_rtp_packet(rtp_packet_t *rp, SAMPLE **out_buff, GHashTable *decoders_hash) -{ - unsigned int payload_type; - const gchar *p; - rtp_decoder_t *decoder; - SAMPLE *tmp_buff = NULL; - size_t tmp_buff_len; - size_t decoded_bytes = 0; - - if ((rp->payload_data == NULL) || (rp->info->info_payload_len == 0) ) { - return 0; - } - - payload_type = rp->info->info_payload_type; - - /* Look for registered codecs */ - decoder = (rtp_decoder_t *)g_hash_table_lookup(decoders_hash, GUINT_TO_POINTER(payload_type)); - if (!decoder) { /* Put either valid or empty decoder into the hash table */ - decoder = g_new(rtp_decoder_t,1); - decoder->handle = NULL; - decoder->context = NULL; - - if (rp->info->info_payload_type_str && find_codec(rp->info->info_payload_type_str)) { - p = rp->info->info_payload_type_str; - } else { - p = try_val_to_str_ext(payload_type, &rtp_payload_type_short_vals_ext); - } - - if (p) { - decoder->handle = find_codec(p); - if (decoder->handle) - decoder->context = codec_init(decoder->handle); - } - g_hash_table_insert(decoders_hash, GUINT_TO_POINTER(payload_type), decoder); - } - if (decoder->handle) { /* Decode with registered codec */ - tmp_buff_len = codec_decode(decoder->handle, decoder->context, rp->payload_data, rp->info->info_payload_len, NULL, NULL); - tmp_buff = (SAMPLE *)g_malloc(tmp_buff_len); - decoded_bytes = codec_decode(decoder->handle, decoder->context, rp->payload_data, rp->info->info_payload_len, tmp_buff, &tmp_buff_len); - *out_buff = tmp_buff; - - channels = codec_get_channels(decoder->handle, decoder->context); - sample_rate = codec_get_frequency(decoder->handle, decoder->context); - - return decoded_bytes; - } - - *out_buff = NULL; - return 0; -} - /****************************************************************************/ static void update_progress_bar(gfloat fraction) @@ -633,7 +552,7 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr) #endif seq = 0; start_timestamp = 0; - decoders_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, rtp_decoder_value_destroy); + decoders_hash = rtp_decoder_hash_table_new(); /* we update the progress bar 100 times */ @@ -671,7 +590,7 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr) seq = rp->info->info_seq_num - 1; } - decoded_bytes = decode_rtp_packet(rp, &out_buff, decoders_hash); + decoded_bytes = decode_rtp_packet(rp, &out_buff, decoders_hash, &channels, &sample_rate); if (decoded_bytes == 0) { seq = rp->info->info_seq_num; } diff --git a/ui/rtp_media.c b/ui/rtp_media.c new file mode 100644 index 0000000000..93f1f0b8ea --- /dev/null +++ b/ui/rtp_media.c @@ -0,0 +1,134 @@ +/* rtp_media.c + * + * RTP decoding routines for Wireshark. + * Copied from ui/gtk/rtp_player.c + * + * Copyright 2006, Alejandro Vaquero + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1999 Gerald Combs + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include + +#include +#include + +#include + +/****************************************************************************/ +/* DECODING */ +/****************************************************************************/ + +typedef struct _rtp_decoder_t { + codec_handle_t handle; + void *context; +} rtp_decoder_t; + +/****************************************************************************/ +/* + * Return the number of decoded bytes + */ + +size_t +decode_rtp_packet(rtp_packet_t *rp, SAMPLE **out_buff, GHashTable *decoders_hash, unsigned *channels_ptr, unsigned *sample_rate_ptr) +{ + unsigned int payload_type; + const gchar *p; + rtp_decoder_t *decoder; + SAMPLE *tmp_buff = NULL; + size_t tmp_buff_len; + size_t decoded_bytes = 0; + + if ((rp->payload_data == NULL) || (rp->info->info_payload_len == 0) ) { + return 0; + } + + payload_type = rp->info->info_payload_type; + + /* Look for registered codecs */ + decoder = (rtp_decoder_t *)g_hash_table_lookup(decoders_hash, GUINT_TO_POINTER(payload_type)); + if (!decoder) { /* Put either valid or empty decoder into the hash table */ + decoder = g_new(rtp_decoder_t,1); + decoder->handle = NULL; + decoder->context = NULL; + + if (rp->info->info_payload_type_str && find_codec(rp->info->info_payload_type_str)) { + p = rp->info->info_payload_type_str; + } else { + p = try_val_to_str_ext(payload_type, &rtp_payload_type_short_vals_ext); + } + + if (p) { + decoder->handle = find_codec(p); + if (decoder->handle) + decoder->context = codec_init(decoder->handle); + } + g_hash_table_insert(decoders_hash, GUINT_TO_POINTER(payload_type), decoder); + } + if (decoder->handle) { /* Decode with registered codec */ + tmp_buff_len = codec_decode(decoder->handle, decoder->context, rp->payload_data, rp->info->info_payload_len, NULL, NULL); + tmp_buff = (SAMPLE *)g_malloc(tmp_buff_len); + decoded_bytes = codec_decode(decoder->handle, decoder->context, rp->payload_data, rp->info->info_payload_len, tmp_buff, &tmp_buff_len); + *out_buff = tmp_buff; + + if (channels_ptr) { + *channels_ptr = codec_get_channels(decoder->handle, decoder->context); + } + + if (sample_rate_ptr) { + *sample_rate_ptr = codec_get_frequency(decoder->handle, decoder->context); + } + + return decoded_bytes; + } + + *out_buff = NULL; + return 0; +} + +/****************************************************************************/ +static void +rtp_decoder_value_destroy(gpointer dec_arg) +{ + rtp_decoder_t *dec = (rtp_decoder_t *)dec_arg; + + if (dec->handle) + codec_release(dec->handle, dec->context); + g_free(dec_arg); +} + +GHashTable *rtp_decoder_hash_table_new(void) +{ + return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, rtp_decoder_value_destroy); +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/rtp_media.h b/ui/rtp_media.h new file mode 100644 index 0000000000..444c1db18c --- /dev/null +++ b/ui/rtp_media.h @@ -0,0 +1,88 @@ +/* rtp_media.h + * + * RTP decoding routines for Wireshark. + * Copied from ui/gtk/rtp_player.c + * + * Copyright 2006, Alejandro Vaquero + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1999 Gerald Combs + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __RTP_MEDIA_H__ +#define __RTP_MEDIA_H__ + +/** @file + * "RTP Player" dialog box common routines. + * @ingroup main_ui_group + */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +/****************************************************************************/ +/* INTERFACE */ +/****************************************************************************/ + +typedef gint16 SAMPLE; + +/* Defines an RTP packet */ +typedef struct _rtp_packet { + struct _rtp_info *info; /* the RTP dissected info */ + double arrive_offset; /* arrive offset time since the beginning of the stream in ms */ + guint8* payload_data; +} rtp_packet_t; + +/** Create a new hash table. + * + * @return A new hash table suitable for passing to decode_rtp_packet. + */ +GHashTable *rtp_decoder_hash_table_new(void); + +/** Decode an RTP packet + * + * @param rp Wrapper for per-packet RTP tap data. + * @param out_buff Output audio samples. + * @param decoders_hash Hash table created with rtp_decoder_hash_table_new. + * @param channels_ptr If non-NULL, receives the number of channels in the sample. + * @param sample_rate_ptr If non-NULL, receives the sample rate. + * @return The number of decoded bytes on success, 0 on failure. + */ +size_t decode_rtp_packet(rtp_packet_t *rp, SAMPLE **out_buff, GHashTable *decoders_hash, unsigned *channels_ptr, unsigned *sample_rate_ptr); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __RTP_MEDIA_H__ */ + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ -- cgit v1.2.1