aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorTomas Kukosa <tomas.kukosa@siemens.com>2007-10-25 09:38:15 +0000
committerTomas Kukosa <tomas.kukosa@siemens.com>2007-10-25 09:38:15 +0000
commit136de3920c4f703e9d7aeb5f6d3b6484a2bc6479 (patch)
treeb55286be4fe6da2b8556a21a18dea5b3563ed374 /gtk
parent821106256bf98c026652181dbdf9480abf080f6a (diff)
new codec table for registering codecs by name
new codec plugin type search registered codecs in rtp player fix memory leak in rtp player svn path=/trunk/; revision=23270
Diffstat (limited to 'gtk')
-rw-r--r--gtk/plugins_dlg.c6
-rw-r--r--gtk/rtp_player.c68
2 files changed, 66 insertions, 8 deletions
diff --git a/gtk/plugins_dlg.c b/gtk/plugins_dlg.c
index 7bb76af491..23dfad4028 100644
--- a/gtk/plugins_dlg.c
+++ b/gtk/plugins_dlg.c
@@ -66,6 +66,12 @@ plugins_scan(GtkWidget *list)
{
type = g_string_append(type, sep);
type = g_string_append(type, "file_format");
+ sep = ", ";
+ }
+ if (pt_plug->register_codec_module)
+ {
+ type = g_string_append(type, sep);
+ type = g_string_append(type, "codec");
}
simple_list_append(list, 0, pt_plug->name, 1, pt_plug->version,
2, type->str, -1);
diff --git a/gtk/rtp_player.c b/gtk/rtp_player.c
index a2a3b7cf32..c1ee8cbe24 100644
--- a/gtk/rtp_player.c
+++ b/gtk/rtp_player.c
@@ -79,6 +79,7 @@
#include <epan/dissectors/packet-rtp.h>
#include <epan/rtp_pt.h>
+#include <epan/codecs.h>
#include "rtp_player.h"
#include "codecs/G711a/G711adecode.h"
@@ -238,6 +239,11 @@ typedef struct _rtp_play_channles {
/* The two RTP channles to play */
static rtp_play_channles_t *rtp_channels = NULL;
+typedef struct _rtp_decoder_t {
+ codec_handle_t handle;
+ void *context;
+} rtp_decoder_t;
+
/****************************************************************************/
static void
@@ -283,6 +289,17 @@ rtp_stream_value_destroy(gpointer rsi_arg)
}
/****************************************************************************/
+static void
+rtp_decoder_value_destroy(gpointer dec_arg)
+{
+ rtp_decoder_t *dec = 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 _U_ )
{
@@ -440,10 +457,13 @@ mark_rtp_stream_to_play(gchar *key _U_ , rtp_stream_info_t *rsi, gpointer ptr _U
* Return the number of decoded bytes
*/
static int
-decode_rtp_packet(rtp_packet_t *rp, SAMPLE **out_buff)
+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;
+ int tmp_buff_len;
int decoded_bytes = 0;
if ((rp->payload_data == NULL) || (rp->info->info_payload_len == 0) ) {
@@ -451,32 +471,57 @@ decode_rtp_packet(rtp_packet_t *rp, SAMPLE **out_buff)
}
payload_type = rp->info->info_payload_type;
+
+ /* Look for registered codecs */
+ decoder = g_hash_table_lookup(decoders_hash, (gpointer)payload_type);
+ if (!decoder) { /* Put either valid or empty decoder into the hash table */
+ decoder = g_malloc(sizeof(rtp_decoder_t));
+ decoder->handle = NULL;
+ decoder->context = NULL;
+ p = match_strval(payload_type, rtp_payload_type_short_vals);
+ if (p) {
+ decoder->handle = find_codec(p);
+ if (decoder->handle)
+ decoder->context = codec_init(decoder->handle);
+ }
+ g_hash_table_insert(decoders_hash, (gpointer)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 = 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;
+ return decoded_bytes;
+ }
+
+ /* Try to decode with built-in codec */
+
switch (payload_type) {
case PT_PCMU: /* G.711 u-law */
- tmp_buff = malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 1);
+ tmp_buff = g_malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 1);
decodeG711u(rp->payload_data, rp->info->info_payload_len,
tmp_buff, &decoded_bytes);
break;
case PT_PCMA: /* G.711 A-law */
- tmp_buff = malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 1);
+ tmp_buff = g_malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 1);
decodeG711a(rp->payload_data, rp->info->info_payload_len,
tmp_buff, &decoded_bytes);
break;
#ifdef HAVE_G729_G723
case PT_G729: /* G.729 */
- tmp_buff = malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 8); /* G729 8kbps => 64kbps/8kbps = 8 */
+ tmp_buff = g_malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 8); /* G729 8kbps => 64kbps/8kbps = 8 */
decodeG729(rp->payload_data, rp->info->info_payload_len,
tmp_buff, &decoded_bytes);
break;
case PT_G723: /* G.723 */
if (rp->info->info_payload_len%24 == 0) /* G723 High 6.4kbps */
- tmp_buff = malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 10); /* G723 High 64kbps/6.4kbps = 10 */
+ tmp_buff = g_malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 10); /* G723 High 64kbps/6.4kbps = 10 */
else if (rp->info->info_payload_len%20 == 0) /* G723 Low 5.3kbps */
- tmp_buff = malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 13); /* G723 High 64kbps/5.3kbps = 13 */
+ tmp_buff = g_malloc(sizeof(SAMPLE) * rp->info->info_payload_len * 13); /* G723 High 64kbps/5.3kbps = 13 */
else {
return 0;
}
@@ -546,6 +591,7 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr _U_)
sample_t sample;
guint8 status;
guint32 start_timestamp;
+ GHashTable *decoders_hash = NULL;
guint32 progbar_nextstep;
int progbar_quantum;
@@ -580,7 +626,7 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr _U_)
/* ..if it is not in the hash, create an entry */
if (rci == NULL) {
- rci = malloc(sizeof(rtp_channel_info_t));
+ rci = g_malloc(sizeof(rtp_channel_info_t));
rci->call_num = rsi->call_num;
rci->start_time = rsi->start_time;
rci->end_time = rsi->start_time;
@@ -628,6 +674,7 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr _U_)
mean_delay = 0;
variation = 0;
start_timestamp = 0;
+ decoders_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, rtp_decoder_value_destroy);
/* we update the progress bar 100 times */
@@ -663,7 +710,7 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr _U_)
seq = rp->info->info_seq_num - 1;
}
- decoded_bytes = decode_rtp_packet(rp, &out_buff);
+ decoded_bytes = decode_rtp_packet(rp, &out_buff, decoders_hash);
if (decoded_bytes == 0) {
seq = rp->info->info_seq_num;
}
@@ -744,6 +791,10 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr _U_)
}
+ if (out_buff) {
+ g_free(out_buff);
+ out_buff = NULL;
+ }
rtp_packets_list = g_list_next (rtp_packets_list);
progbar_count++;
}
@@ -751,6 +802,7 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr _U_)
rci->end_time = rci->start_time + ((double)rci->samples->len/SAMPLE_RATE)*1000;
g_string_free(key_str, TRUE);
+ g_hash_table_destroy(decoders_hash);
}
/****************************************************************************/