[asterisk-commits] branch file/coremedia - r7372 in /team/file/coremedia: ./ include/asterisk/ s...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Dec 6 18:34:15 CST 2005


Author: file
Date: Tue Dec  6 18:34:12 2005
New Revision: 7372

URL: http://svn.digium.com/view/asterisk?rev=7372&view=rev
Log:
Clean up to coding guidelines specs, and add ability to set sample rate when simply going through decoding to get signed linear frames

Modified:
    team/file/coremedia/channel.c
    team/file/coremedia/coremedia.c
    team/file/coremedia/include/asterisk/coremedia.h
    team/file/coremedia/shims/shim_test.c
    team/file/coremedia/shims/shim_volume.c

Modified: team/file/coremedia/channel.c
URL: http://svn.digium.com/view/asterisk/team/file/coremedia/channel.c?rev=7372&r1=7371&r2=7372&view=diff
==============================================================================
--- team/file/coremedia/channel.c (original)
+++ team/file/coremedia/channel.c Tue Dec  6 18:34:12 2005
@@ -2320,97 +2320,101 @@
 	return res;
 }
 
-static int set_format(struct ast_channel *chan, ast_coremedia_t *fmt, const int direction)
-{
-  struct ast_coremedia_shim *shims = NULL;
-
-  /* Okay we probably need to setup a translation path */
-  ast_mutex_lock(&chan->lock);
-  switch (direction) {
-  case 0:
-    /* Reading */
-    if (chan->readtrans != NULL) {
-      /* Inherit any shims if here */
-      if (chan->readtrans->shims)
-	shims = chan->readtrans->shims;
-      ast_coremedia_translate_free(chan->readtrans);
-      chan->readtrans = NULL;
-    }
-    if (shims != NULL) {
-      chan->readtrans = ast_coremedia_translate_new(chan->nativeformat, NULL);
-      chan->readtrans->shims = shims;
-    } else if (chan->nativeformat != fmt) {
-      /* Build the translation path */
-      chan->readtrans = ast_coremedia_translate_new(chan->nativeformat, fmt);
-    } else {
-      /* No translation required */
-      chan->rawreadformat = fmt;
-      chan->writeformat = fmt;
-    }
-    break;
-  case 1:
-    /* Writing */
-    if (chan->writetrans != NULL) {
-      /* Inherit any shims if here */
-      if (chan->writetrans->shims != NULL)
-	shims = chan->writetrans->shims;
-      ast_coremedia_translate_free(chan->writetrans);
-      chan->writetrans = NULL;
-    }
-    if (shims != NULL) {
-      /* We have shims... HAVE to go through signed linear */
-      chan->writetrans = ast_coremedia_translate_new(NULL, chan->nativeformat);
-      chan->writetrans->shims = shims;
-    } else if (chan->nativeformat != fmt) {
-      /* Build the translation path */
-      chan->writetrans = ast_coremedia_translate_new(fmt, chan->nativeformat);
-    } else {
-      /* No translation required */
-      chan->rawwriteformat = fmt;
-      chan->writeformat = fmt;
-    }
-    break;
-  default:
-    break;
-  }
-  ast_mutex_unlock(&chan->lock);
-  
-  return 0;
+static int set_format(struct ast_channel *chan, ast_coremedia_t *fmt, const int direction, int sample_rate)
+{
+	struct ast_coremedia_shim *shims = NULL;
+	
+	/* Okay we probably need to setup a translation path */
+	ast_mutex_lock(&chan->lock);
+	switch (direction) {
+	case 0:
+		/* Reading */
+		if (chan->readtrans != NULL) {
+			/* Inherit any shims if here */
+			if (chan->readtrans->shims)
+				shims = chan->readtrans->shims;
+			ast_coremedia_translate_free(chan->readtrans);
+			chan->readtrans = NULL;
+		}
+		if (shims != NULL) {
+			chan->readtrans = ast_coremedia_translate_new(chan->nativeformat, NULL);
+			chan->readtrans->shims = shims;
+			/* Set native sample rate */
+			chan->readtrans->sample_rate = sample_rate;
+		} else if (chan->nativeformat != fmt) {
+			/* Build the translation path */
+			chan->readtrans = ast_coremedia_translate_new(chan->nativeformat, fmt);
+			/* If going just to signed linear - set native sample rate */
+			chan->readtrans->sample_rate = sample_rate;
+		} else {
+			/* No translation required */
+			chan->rawreadformat = fmt;
+			chan->writeformat = fmt;
+		}
+		break;
+	case 1:
+		/* Writing */
+		if (chan->writetrans != NULL) {
+			/* Inherit any shims if here */
+			if (chan->writetrans->shims != NULL)
+				shims = chan->writetrans->shims;
+			ast_coremedia_translate_free(chan->writetrans);
+			chan->writetrans = NULL;
+		}
+		if (shims != NULL) {
+			/* We have shims... HAVE to go through signed linear */
+			chan->writetrans = ast_coremedia_translate_new(NULL, chan->nativeformat);
+			chan->writetrans->shims = shims;
+		} else if (chan->nativeformat != fmt) {
+			/* Build the translation path */
+			chan->writetrans = ast_coremedia_translate_new(fmt, chan->nativeformat);
+		} else {
+			/* No translation required */
+			chan->rawwriteformat = fmt;
+			chan->writeformat = fmt;
+		}
+		break;
+	default:
+		break;
+	}
+	ast_mutex_unlock(&chan->lock);
+	
+	return 0;
 }
 
 /* New coremedia APIs */
 int ast_set_read_format_cm(struct ast_channel *chan, ast_coremedia_t *fmt)
 {
-  return set_format(chan, fmt, 0);
+	return set_format(chan, fmt, 0, 8000);
 }
 
 int ast_set_write_format_cm(struct ast_channel *chan, ast_coremedia_t *fmt)
 {
-  return set_format(chan, fmt, 1);
+	return set_format(chan, fmt, 1, 8000);
 }
 
 /* Set read format wrapper for coremedia */
 int ast_set_read_format(struct ast_channel *chan, int fmt)
 {
-  ast_coremedia_t *entry = NULL;
-
-  entry = ast_coremedia_get_by_format(fmt);
-  if (entry == NULL)
-    return -1;
-  else /* Set read format to this coremedia entry */
-    return set_format(chan, entry, 0);
+	ast_coremedia_t *entry = NULL;
+	
+	entry = ast_coremedia_get_by_format(fmt);
+	if (entry == NULL)
+		return -1;
+	else /* Set read format to this coremedia entry */
+		return set_format(chan, entry, 0, 8000);
 }
 
 /* Set write format wrapper for coremedia */
 int ast_set_write_format(struct ast_channel *chan, int fmt)
 {
-  ast_coremedia_t *entry = NULL;
-
-  entry = ast_coremedia_get_by_format(fmt);
-  if (entry == NULL)
-    return -1;
-  else /* Set write format to this coremedia entry */
-    return set_format(chan, entry, 1);
+	ast_coremedia_t *entry = NULL;
+	
+	entry = ast_coremedia_get_by_format(fmt);
+	if (entry == NULL)
+		return -1;
+	else /* Set write format to this coremedia entry */
+		return set_format(chan, entry, 1, 8000);
 }
 
 struct ast_channel *__ast_request_and_dial(const char *type, struct ast_coremedia_entry *format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)

Modified: team/file/coremedia/coremedia.c
URL: http://svn.digium.com/view/asterisk/team/file/coremedia/coremedia.c?rev=7372&r1=7371&r2=7372&view=diff
==============================================================================
--- team/file/coremedia/coremedia.c (original)
+++ team/file/coremedia/coremedia.c Tue Dec  6 18:34:12 2005
@@ -46,687 +46,748 @@
 static int subclass = 0;
 /* RTP mappings */
 AST_MUTEX_DEFINE_STATIC(rtplock);
-static struct ast_coremedia_rtp *rtp_root[MAX_PAYLOADS+1];
+static struct ast_coremedia_rtp *rtp_root[MAX_PAYLOADS + 1];
 /* Dynamic RTP payload support */
 AST_MUTEX_DEFINE_STATIC(dynamicrtplock);
 static int dynamic_payload = 96;
 
-static struct ast_coremedia_entry slinear_entry =
-  { "slinear",
-    TYPE_AUDIO,
-    0,
-    8000,
-    AST_FORMAT_SLINEAR,
-  };
+static struct ast_coremedia_entry slinear_entry = { "slinear",
+	TYPE_AUDIO,
+	0,
+	8000,
+	AST_FORMAT_SLINEAR,
+};
 
 /* Integrated telephone-event */
-static struct ast_coremedia_entry telephone_event =
-  { "telephone-event",
-    TYPE_DTMF,
-    0,
-    8000,
-  };
-
-static struct ast_coremedia_rtp rfc2833_rtp =
-  { "telephone-event",
-    101,
-    0,
-    8000,
-    "telephone-event",
-  };
+static struct ast_coremedia_entry telephone_event = { "telephone-event",
+	TYPE_DTMF,
+	0,
+	8000,
+};
+
+static struct ast_coremedia_rtp rfc2833_rtp = { "telephone-event",
+	101,
+	0,
+	8000,
+	"telephone-event",
+};
 
 /* Integrated cisco-event */
-static struct ast_coremedia_entry cisco_event =
-  { "cisco-event",
-    TYPE_DTMF,
-    0,
-    8000,
-  };
+static struct ast_coremedia_entry cisco_event = { "cisco-event",
+	TYPE_DTMF,
+	0,
+	8000,
+};
 
 /* Initialize the coremedia system */
 void ast_coremedia_init(void)
 {
-  /* Embed signed linear passthrough into ourselves */
-  ast_coremedia_register(&slinear_entry);
-  ast_coremedia_register(&telephone_event);
-  ast_coremedia_register(&cisco_event);
-  ast_coremedia_rtp_register(&rfc2833_rtp);
-  return;
+	/* Embed signed linear passthrough into ourselves */
+	ast_coremedia_register(&slinear_entry);
+	ast_coremedia_register(&telephone_event);
+	ast_coremedia_register(&cisco_event);
+	ast_coremedia_rtp_register(&rfc2833_rtp);
+	return;
 }
 
 /* Parsing helper functions */
 struct ast_coremedia_handle *ast_coremedia_parse_codec(char *codec)
 {
-  char tmp[128] = "";
-  char *codecs = NULL;
-  char *name = NULL, *bitrate2 = NULL, *samples2 = NULL;
-  int bitrate = 0, samples = 8000;
-  struct ast_coremedia_entry *entry = NULL;
-  struct ast_coremedia_handle *return_handle = NULL, *new_handle = NULL;
-
-  /* Simple check */
-  if (codec == NULL)
-    return NULL;
-
-  strncpy(tmp, codec, sizeof(tmp));
-
-  codecs = tmp;
-
-  /* The one time I've ever actually used a do loop for something */
-  do {
-    name = codecs;
-    /* See if there is another codec in the list */
-    codecs = strchr(codecs, ';');
-    if (codecs != NULL) {
-      *codecs = '\0';
-      codecs++;
-    }
-    bitrate2 = strchr(name, '-');
-    if (bitrate2) {
-      *bitrate2 = '\0';
-      bitrate2++;
-      samples2 = strchr(bitrate2, '/');
-    } else {
-      samples2 = strchr(name, '/');
-    }
-    if (samples2) {
-      *samples2 = '\0';
-      samples2++;
-    }
-    /* Sanitize the values slightly */
-    if (bitrate2)
-      bitrate = atoi(bitrate2);
-    else
-      bitrate = 0;
-    if (samples2)
-      samples = atoi(samples2);
-    else
-      samples = 8000;
-    entry = ast_coremedia_get(name, bitrate, samples);
-    if (entry != NULL) {
-      /* Found the entry */
-      new_handle = ast_coremedia_handle_new(entry);
-      if (new_handle == NULL)
-	continue;
-      if (return_handle != NULL)
-	new_handle->next = return_handle;
-      return_handle = new_handle;
-    }
-  } while (codecs);
-
-  return return_handle;
+	char tmp[128] = "";
+	char *codecs = NULL;
+	char *name = NULL, *bitrate2 = NULL, *samples2 = NULL;
+	int bitrate = 0, samples = 8000;
+	struct ast_coremedia_entry *entry = NULL;
+	struct ast_coremedia_handle *return_handle = NULL, *new_handle = NULL;
+
+	/* Simple check */
+	if (codec == NULL)
+		return NULL;
+
+	strncpy(tmp, codec, sizeof(tmp));
+
+	codecs = tmp;
+
+	/* The one time I've ever actually used a do loop for something */
+	do {
+		name = codecs;
+		/* See if there is another codec in the list */
+		codecs = strchr(codecs, ';');
+		if (codecs != NULL) {
+			*codecs = '\0';
+			codecs++;
+		}
+		bitrate2 = strchr(name, '-');
+		if (bitrate2) {
+			*bitrate2 = '\0';
+			bitrate2++;
+			samples2 = strchr(bitrate2, '/');
+		} else {
+			samples2 = strchr(name, '/');
+		}
+		if (samples2) {
+			*samples2 = '\0';
+			samples2++;
+		}
+		/* Sanitize the values slightly */
+		if (bitrate2)
+			bitrate = atoi(bitrate2);
+		else
+			bitrate = 0;
+		if (samples2)
+			samples = atoi(samples2);
+		else
+			samples = 8000;
+		entry = ast_coremedia_get(name, bitrate, samples);
+		if (entry != NULL) {
+			/* Found the entry */
+			new_handle = ast_coremedia_handle_new(entry);
+			if (new_handle == NULL)
+				continue;
+			if (return_handle != NULL)
+				new_handle->next = return_handle;
+			return_handle = new_handle;
+		}
+	} while (codecs);
+
+	return return_handle;
 }
 
 /* Create a brand new shim and attach it to a channel */
-int ast_coremedia_shimmy(struct ast_channel *channel, struct ast_coremedia_shim *shim, struct ast_coremedia_shim_pvt *pvt, int direction)
-{
-  int res = -1;
-  struct ast_coremedia_shim *new_shim = NULL;
-
-  /* Duplicate the shim for addition to the coremedia translator path */
-  new_shim = (struct ast_coremedia_shim*)malloc(sizeof(struct ast_coremedia_shim));
-  if (new_shim == NULL)
-    return -1;
-  memset(new_shim, 0, sizeof(struct ast_coremedia_shim));
-  new_shim->callback = shim->callback;
-  new_shim->destroy = shim->destroy;
-  /* Link the created pvt structure to the new shim */
-  new_shim->pvt = pvt;
-  /* Make sure we have no next */
-  new_shim->next = NULL;
-
-  switch (direction) {
-  case 0:
-    /* Make sure we go through signed linear */
-    if (channel->readtrans == NULL && ast_set_read_format_cm(channel, NULL)) {
-      ast_log(LOG_WARNING, "Failed to set read format to signed linear!\n");
-    } else {
-      /* All is fine */
-      ast_mutex_lock(&channel->lock);
-      new_shim->next = channel->readtrans->shims;
-      channel->readtrans->shims = new_shim;
-      ast_mutex_unlock(&channel->lock);
-      res = 0;
-    }
-    break;
-  case 1:
-    if (channel->writetrans == NULL && ast_set_write_format_cm(channel, NULL)) {
-      ast_log(LOG_WARNING, "Failed to set write format to signed linear!\n");
-    } else {
-      ast_mutex_lock(&channel->lock);
-      new_shim->next = channel->writetrans->shims;
-      channel->writetrans->shims = new_shim;
-      ast_mutex_unlock(&channel->lock);
-      res = 0;
-    }
-    break;
-  default:
-    break;
-  }
-
-  /* If this failed in some way - get rid of our duplicated shim */
-  if (res != 0) {
-    ast_coremedia_shims_destroy(new_shim);
-  }
-
-  return res;
+int ast_coremedia_shimmy(struct ast_channel *channel,
+						 struct ast_coremedia_shim *shim,
+						 struct ast_coremedia_shim_pvt *pvt, int direction)
+{
+	int res = -1;
+	struct ast_coremedia_shim *new_shim = NULL;
+
+	/* Duplicate the shim for addition to the coremedia translator path */
+	new_shim =
+		(struct ast_coremedia_shim *)
+		malloc(sizeof(struct ast_coremedia_shim));
+	if (new_shim == NULL)
+		return -1;
+	memset(new_shim, 0, sizeof(struct ast_coremedia_shim));
+	new_shim->callback = shim->callback;
+	new_shim->destroy = shim->destroy;
+	/* Link the created pvt structure to the new shim */
+	new_shim->pvt = pvt;
+	/* Make sure we have no next */
+	new_shim->next = NULL;
+
+	switch (direction) {
+	case 0:
+		/* Make sure we go through signed linear */
+		if (channel->readtrans == NULL
+			&& ast_set_read_format_cm(channel, NULL)) {
+			ast_log(LOG_WARNING,
+					"Failed to set read format to signed linear!\n");
+		} else {
+			/* All is fine */
+			ast_mutex_lock(&channel->lock);
+			new_shim->next = channel->readtrans->shims;
+			channel->readtrans->shims = new_shim;
+			ast_mutex_unlock(&channel->lock);
+			res = 0;
+		}
+		break;
+	case 1:
+		if (channel->writetrans == NULL
+			&& ast_set_write_format_cm(channel, NULL)) {
+			ast_log(LOG_WARNING,
+					"Failed to set write format to signed linear!\n");
+		} else {
+			ast_mutex_lock(&channel->lock);
+			new_shim->next = channel->writetrans->shims;
+			channel->writetrans->shims = new_shim;
+			ast_mutex_unlock(&channel->lock);
+			res = 0;
+		}
+		break;
+	default:
+		break;
+	}
+
+	/* If this failed in some way - get rid of our duplicated shim */
+	if (res != 0) {
+		ast_coremedia_shims_destroy(new_shim);
+	}
+
+	return res;
 }
 
 /* Destroy any linked shims */
 int ast_coremedia_shims_destroy(struct ast_coremedia_shim *shim)
 {
-  int res = -1;
-  struct ast_coremedia_shim *current = NULL, *previous = NULL;
-
-  current = shim;
-  while (current) {
-    /* If an instance is allocated - destroy it */
-    if (current->pvt != NULL && current->destroy != NULL)
-      current->destroy(current->pvt);
-    previous = current;
-    current = current->next;
-    /* Free the used memory */
-    free(previous);
-    previous = NULL;
-  }
-
-  return res;
+	int res = -1;
+	struct ast_coremedia_shim *current = NULL, *previous = NULL;
+
+	current = shim;
+	while (current) {
+		/* If an instance is allocated - destroy it */
+		if (current->pvt != NULL && current->destroy != NULL)
+			current->destroy(current->pvt);
+		previous = current;
+		current = current->next;
+		/* Free the used memory */
+		free(previous);
+		previous = NULL;
+	}
+
+	return res;
 }
 
 /* Shuffle the order of a set of coremedia handles backwards */
-struct ast_coremedia_handle *ast_coremedia_handle_shuffle(struct ast_coremedia_handle *existing_handle)
-{
-  struct ast_coremedia_handle *new_list = NULL, *handle = NULL, *dup_handle = NULL, *previous_handle = NULL;
-
-  /* Okay this is really cheesy... essentially iterate through the linked list and add it to a new linked list thus reversing the order */
-  handle = existing_handle;
-  while (handle) {
-    dup_handle = ast_coremedia_handle_new(handle->entry);
-    if (dup_handle != NULL) {
-      if (new_list != NULL)
-	dup_handle->next = new_list;
-      new_list = dup_handle;
-    }
-    previous_handle = handle;
-    /* Move to the next one */
-    handle = handle->next;
-    /* Free the previous one */
-    free(previous_handle);
-    previous_handle = NULL;
-  }
-
-  return new_list;
+struct ast_coremedia_handle *ast_coremedia_handle_shuffle(struct
+														  ast_coremedia_handle
+														  *existing_handle)
+{
+	struct ast_coremedia_handle *new_list = NULL, *handle =
+		NULL, *dup_handle = NULL, *previous_handle = NULL;
+
+	/* Okay this is really cheesy... essentially iterate through the linked list and add it to a new linked list thus reversing the order */
+	handle = existing_handle;
+	while (handle) {
+		dup_handle = ast_coremedia_handle_new(handle->entry);
+		if (dup_handle != NULL) {
+			if (new_list != NULL)
+				dup_handle->next = new_list;
+			new_list = dup_handle;
+		}
+		previous_handle = handle;
+		/* Move to the next one */
+		handle = handle->next;
+		/* Free the previous one */
+		free(previous_handle);
+		previous_handle = NULL;
+	}
+
+	return new_list;
 }
 
 /* Create a brand new coremedia handle */
-struct ast_coremedia_handle *ast_coremedia_handle_new(struct ast_coremedia_entry *entry)
-{
-  struct ast_coremedia_handle *new_handle = NULL;
-
-  new_handle = (struct ast_coremedia_handle*)malloc(sizeof(struct ast_coremedia_handle));
-  if (new_handle == NULL)
-    return NULL;
-
-  new_handle->entry = entry;
-  new_handle->next = NULL;
-
-  return new_handle;
+struct ast_coremedia_handle *ast_coremedia_handle_new(struct
+													  ast_coremedia_entry
+													  *entry)
+{
+	struct ast_coremedia_handle *new_handle = NULL;
+
+	new_handle =
+		(struct ast_coremedia_handle *)
+		malloc(sizeof(struct ast_coremedia_handle));
+	if (new_handle == NULL)
+		return NULL;
+
+	new_handle->entry = entry;
+	new_handle->next = NULL;
+
+	return new_handle;
 }
 
 /* Combine two groups of coremedia handles together to get a combination of supported coremedia entries */
-struct ast_coremedia_handle *ast_coremedia_handle_combine(struct ast_coremedia_handle *handle_1, struct ast_coremedia_handle *handle_2)
-{
-  struct ast_coremedia_handle *combined = NULL, *handle1 = NULL, *handle2 = NULL, *temp = NULL;
-
-  /* This is a very inefficient method... any other possible ways? - file. */
-  handle1 = handle_1;
-  while (handle1) {
-    /* See if this handle entry is in the other one */
-    handle2 = handle_2;
-    while (handle2) {
-      if (handle1->entry == handle2->entry) {
-	/* Found combined handle entry */
-	temp = ast_coremedia_handle_new(handle1->entry);
-	if (combined == NULL) {
-	  /* No combined ones so far */
-	  combined = temp;
-	} else {
-	  /* Yay we have one already... */
-	  temp->next = combined;
-	  combined = temp;
-	}
-      }
-      handle2 = handle2->next;
-    }
-    handle1 = handle1->next;
-  }
-
-  return combined;
+struct ast_coremedia_handle *ast_coremedia_handle_combine(struct
+														  ast_coremedia_handle
+														  *handle_1,
+														  struct
+														  ast_coremedia_handle
+														  *handle_2)
+{
+	struct ast_coremedia_handle *combined = NULL, *handle1 = NULL, *handle2 =
+		NULL, *temp = NULL;
+
+	/* This is a very inefficient method... any other possible ways? - file. */
+	handle1 = handle_1;
+	while (handle1) {
+		/* See if this handle entry is in the other one */
+		handle2 = handle_2;
+		while (handle2) {
+			if (handle1->entry == handle2->entry) {
+				/* Found combined handle entry */
+				temp = ast_coremedia_handle_new(handle1->entry);
+				if (combined == NULL) {
+					/* No combined ones so far */
+					combined = temp;
+				} else {
+					/* Yay we have one already... */
+					temp->next = combined;
+					combined = temp;
+				}
+			}
+			handle2 = handle2->next;
+		}
+		handle1 = handle1->next;
+	}
+
+	return combined;
 }
 
 /* Free a group of coremedia handles */
 int ast_coremedia_handle_free(struct ast_coremedia_handle *handle)
 {
-  int res = -1;
-  struct ast_coremedia_handle *muffin = NULL, *previous = NULL;
-
-  muffin = handle;
-  while (muffin) {
-    previous = muffin;
-    muffin = muffin->next;
-    free(previous);
-    previous = NULL;
-  }
-
-  return res;
+	int res = -1;
+	struct ast_coremedia_handle *muffin = NULL, *previous = NULL;
+
+	muffin = handle;
+	while (muffin) {
+		previous = muffin;
+		muffin = muffin->next;
+		free(previous);
+		previous = NULL;
+	}
+
+	return res;
 }
 
 /* Setup a coremedia translation path */
-struct ast_coremedia_translator_path *ast_coremedia_translate_new(struct ast_coremedia_entry *decoder, struct ast_coremedia_entry *encoder)
-{
-  struct ast_coremedia_translator_path *new_path = NULL;
-
-  /* Do some sanity checking */
-  if (encoder && decoder && decoder->type != encoder->type) {
-    /* We can't translate between types */
-    return NULL;
-  }
-
-  /* Setup a new structure */
-  new_path = (struct ast_coremedia_translator_path*)malloc(sizeof(struct ast_coremedia_translator_path));
-  if (new_path == NULL) {
-    /* Not enough memory to allocate for the translator path */
-    return NULL;
-  }
-  memset(new_path, 0, sizeof(struct ast_coremedia_translator_path));
-  /* Setup the decoder if available */
-  if (decoder != NULL) {
-    new_path->decoder = decoder->decoder;
-    new_path->decoder_entry = decoder;
-    new_path->dec_state = new_path->decoder->newpvt();
-  }
-  /* Setup the encoder if present - if not we just return signed linear audio from above decoder */
-  if (encoder != NULL) {
-    new_path->encoder = encoder->encoder;
-    new_path->encoder_entry = encoder;
-    new_path->enc_state = new_path->encoder->newpvt();
-  }
-
-  /* Now setup the timing */
-  new_path->nextin = new_path->nextout = ast_tv(0, 0);
-
-  /* Start off with no shims */
-  new_path->shims = NULL;
-
-  return new_path;
+struct ast_coremedia_translator_path *ast_coremedia_translate_new(struct
+																  ast_coremedia_entry
+																  *decoder,
+																  struct
+																  ast_coremedia_entry
+																  *encoder)
+{
+	struct ast_coremedia_translator_path *new_path = NULL;
+
+	/* Do some sanity checking */
+	if (encoder && decoder && decoder->type != encoder->type) {
+		/* We can't translate between types */
+		return NULL;
+	}
+
+	/* Setup a new structure */
+	new_path =
+		(struct ast_coremedia_translator_path *)
+		malloc(sizeof(struct ast_coremedia_translator_path));
+	if (new_path == NULL) {
+		/* Not enough memory to allocate for the translator path */
+		return NULL;
+	}
+	memset(new_path, 0, sizeof(struct ast_coremedia_translator_path));
+	/* Setup the decoder if available */
+	if (decoder != NULL) {
+		new_path->decoder = decoder->decoder;
+		new_path->decoder_entry = decoder;
+		new_path->dec_state = new_path->decoder->newpvt();
+	}
+	/* Setup the encoder if present - if not we just return signed linear audio from above decoder */
+	if (encoder != NULL) {
+		new_path->encoder = encoder->encoder;
+		new_path->encoder_entry = encoder;
+		new_path->enc_state = new_path->encoder->newpvt();
+	}
+
+	/* Now setup the timing */
+	new_path->nextin = new_path->nextout = ast_tv(0, 0);
+
+	/* Start off with no shims */
+	new_path->shims = NULL;
+
+	return new_path;
 }
 
 /* Do a coremedia translation - based on the ol' ast_translate */
 struct ast_frame *ast_coremedia_translate(struct ast_coremedia_translator_path *path, struct ast_frame *f, int consume)
 {
-  struct timeval delivery;
-  struct ast_frame *frame = NULL;
-  struct ast_coremedia_shim *shim = NULL;
-
-  /* Do our pass through the decoder if available */
-  if (path->decoder != NULL) {
-    if (frame->sample_rate != path->decoder_entry->sample_rate) {
-      ast_log(LOG_WARNING, "Uh... frame sample rate not that of the decoder... but this is an encoded frame... ah darn!\n");
-    }
-    path->decoder->framein(path->dec_state, f);
-    frame = path->decoder->frameout(path->dec_state);
-    /* Override subclass to be that of the decoder entry */
-    frame->subclass = path->decoder_entry->subclass;
-    /* Update frame with output sample rate */
-    frame->sample_rate = path->decoder_entry->sample_rate;
-  } else {
-    frame = f;
-  }
-
-  /* If we are here we are absolutely signed linear - so hand off to the shims */
-  shim = path->shims;
-  while (shim) {
-    if (shim->callback) {
-      frame = shim->callback(shim->pvt, frame);
-    }
-    shim = shim->next;
-  }
-
-  /* Do our pass through the encoder if available */
-  if (path->encoder != NULL) {
-    /* Make sure the incoming sample rate of the frame is acceptable for the encoder */
-    if (frame->sample_rate != path->encoder_entry->sample_rate) {
-      /* We can run this through the sample rate translator because it's signed linear ;) */
-    }
-    /* Now run it through this encoder */
-    path->encoder->framein(path->enc_state, frame);
-    frame = path->encoder->frameout(path->enc_state);
-    /* Override subclass to be that of the encoder entry */
-    frame->subclass = path->encoder_entry->subclass;
-    /* And override with the sample rate */
-    frame->sample_rate = path->encoder_entry->sample_rate;
-  } else {
-    /* Okay we are feeding out straight signed linear - see if they want it at another sample rate */
-    if (path->sample_rate > 0 && path->sample_rate != frame->sample_rate) {
-    }
-  }
-
-  /* If we need to consume the given frame... do so */
-  if (consume)
-    ast_frfree(f);
-
-  return frame;
+	struct timeval delivery;
+	struct ast_frame *frame = NULL;
+	struct ast_coremedia_shim *shim = NULL;
+
+	/* Do our pass through the decoder if available */
+	if (path->decoder != NULL) {
+		if (frame->sample_rate != path->decoder_entry->sample_rate) {
+			ast_log(LOG_WARNING,
+					"Uh... frame sample rate not that of the decoder... but this is an encoded frame... ah darn!\n");
+		}
+		path->decoder->framein(path->dec_state, f);
+		frame = path->decoder->frameout(path->dec_state);
+		/* Override subclass to be that of the decoder entry */
+		frame->subclass = path->decoder_entry->subclass;
+		/* Update frame with output sample rate */
+		frame->sample_rate = path->decoder_entry->sample_rate;
+	} else {
+		frame = f;
+	}
+
+	/* If we are here we are absolutely signed linear - so hand off to the shims */
+	shim = path->shims;
+	while (shim) {
+		if (shim->callback) {
+			if (frame->sample_rate != shim->sample_rate) {
+			}
+			frame = shim->callback(shim->pvt, frame);
+		}
+		shim = shim->next;
+	}
+
+	/* Do our pass through the encoder if available */
+	if (path->encoder != NULL) {
+		/* Make sure the incoming sample rate of the frame is acceptable for the encoder */
+		if (frame->sample_rate != path->encoder_entry->sample_rate) {
+			/* We can run this through the sample rate translator because it's signed linear ;) */
+		}
+		/* Now run it through this encoder */
+		path->encoder->framein(path->enc_state, frame);
+		frame = path->encoder->frameout(path->enc_state);
+		/* Override subclass to be that of the encoder entry */
+		frame->subclass = path->encoder_entry->subclass;
+		/* And override with the sample rate */
+		frame->sample_rate = path->encoder_entry->sample_rate;
+	} else {
+		/* Okay we are feeding out straight signed linear - see if they want it at another sample rate */
+		if (path->sample_rate > 0 && path->sample_rate != frame->sample_rate) {
+		}
+	}
+
+	/* If we need to consume the given frame... do so */
+	if (consume)
+		ast_frfree(f);
+
+	return frame;
 }
 
 /* Free a coremedia translation path */
 int ast_coremedia_translate_free(struct ast_coremedia_translator_path *path)
 {
-  int res = 0;
-
-  /* Free decoding state */
-  if (path->dec_state && path->decoder && path->decoder->destroy)
-    path->decoder->destroy(path->dec_state);
-
-  /* Free encoding state */
-  if (path->enc_state && path->encoder && path->encoder->destroy)
-    path->encoder->destroy(path->enc_state);
-
-  /* Now discard the translation path */
-  free(path);
-
-  return res;
+	int res = 0;
+
+	/* Free decoding state */
+	if (path->dec_state && path->decoder && path->decoder->destroy)
+		path->decoder->destroy(path->dec_state);
+
+	/* Free encoding state */
+	if (path->enc_state && path->encoder && path->encoder->destroy)
+		path->encoder->destroy(path->enc_state);
+
+	/* Now discard the translation path */
+	free(path);
+
+	return res;
 }
 
 /* Generate a dynamic payload type */
 static int generate_dynamic_payload(void)
 {
-  int payload = -1, start = 0;
-
-  ast_mutex_lock(&dynamicrtplock);
-  start = payload = dynamic_payload;
-  /* Make sure this place is free */
-  ast_mutex_lock(&rtplock);
-  while (rtp_root[payload] != NULL) {
-    dynamic_payload++;
-    if (dynamic_payload >= MAX_PAYLOADS) {
-      dynamic_payload = 96;
-    } else if (dynamic_payload == start) {
-      /* Give up... no available dynamic places */
-      payload = -1;
-      break;
-    }
-    payload = dynamic_payload;
-  }
-  ast_mutex_unlock(&rtplock);
-  ast_mutex_unlock(&dynamicrtplock);
-
-  return payload;
+	int payload = -1, start = 0;
+
+	ast_mutex_lock(&dynamicrtplock);
+	start = payload = dynamic_payload;
+	/* Make sure this place is free */
+	ast_mutex_lock(&rtplock);
+	while (rtp_root[payload] != NULL) {
+		dynamic_payload++;
+		if (dynamic_payload >= MAX_PAYLOADS) {
+			dynamic_payload = 96;
+		} else if (dynamic_payload == start) {
+			/* Give up... no available dynamic places */
+			payload = -1;
+			break;
+		}
+		payload = dynamic_payload;
+	}
+	ast_mutex_unlock(&rtplock);
+	ast_mutex_unlock(&dynamicrtplock);
+
+	return payload;
 }
 
 /* Lookup an ast_coremedia_rtp entry by the RTP payload */
 struct ast_coremedia_rtp *ast_coremedia_rtp_get_by_payload(int payload)
 {
-  return rtp_root[payload];
+	return rtp_root[payload];
 }
 
 /* Lookup an ast_coremedia_rtp entry by the entry name subclass */
 struct ast_coremedia_rtp *ast_coremedia_rtp_get_by_subclass(int subclass)
 {
-  int i = 0;
-  struct ast_coremedia_rtp *rtp = NULL;
-
-  /* This is actually an intensive process... */
-  ast_mutex_lock(&rtplock);
-  for (i=0; i<MAX_PAYLOADS; i++) {
-    if (rtp_root[i] != NULL && rtp_root[i]->entry != NULL && rtp_root[i]->entry->subclass == subclass) {
-      rtp = rtp_root[i];
-      break;
-    }
-  }
-  ast_mutex_unlock(&rtplock);
-
-  return rtp;
+	int i = 0;
+	struct ast_coremedia_rtp *rtp = NULL;
+
+	/* This is actually an intensive process... */
+	ast_mutex_lock(&rtplock);
+	for (i = 0; i < MAX_PAYLOADS; i++) {
+		if (rtp_root[i] != NULL && rtp_root[i]->entry != NULL
+			&& rtp_root[i]->entry->subclass == subclass) {
+			rtp = rtp_root[i];
+			break;
+		}
+	}
+	ast_mutex_unlock(&rtplock);
+
+	return rtp;
 }
 
 /* Register an RTP mapping */
 int ast_coremedia_rtp_register(struct ast_coremedia_rtp *rtp)
 {
-  struct ast_coremedia_entry *entry = NULL;
-
-  /* Make sure we have a coremedia entry for whichever thing this RTP mapping is for */
-  entry = ast_coremedia_get(rtp->entry_name, rtp->bitrate, rtp->sample_rate);
-  if (entry == NULL) {
-    /* No coremedia entry... either loading order is wrong or this is for a non-existant entry */
-    return -1;
-  }
-
-  /* See if this is a dynamic payload oriented RTP mapping */
-  if (rtp->payload == -1) {
-    rtp->payload = generate_dynamic_payload();
-  }
-  if (rtp->payload == -1) {
-    /* Failed to generate a dynamic payload... */
-    return -1;
-  }
-
-  /* Attach the coremedia entry */
-  rtp->entry = entry;
-
-  /* All done - add it into the array */
-  ast_mutex_lock(&rtplock);
-  rtp_root[rtp->payload] = rtp;
-  ast_mutex_unlock(&rtplock);
-
-  if (option_verbose > 1)
-    ast_verbose(VERBOSE_PREFIX_2 "Registered RTP mapping %d %s/%d to coremedia handler %s\n", rtp->payload, rtp->name, rtp->sample_rate, rtp->entry->name);
-
-  return 0;
+	struct ast_coremedia_entry *entry = NULL;
+
+	/* Make sure we have a coremedia entry for whichever thing this RTP mapping is for */
+	entry =
+		ast_coremedia_get(rtp->entry_name, rtp->bitrate, rtp->sample_rate);
+	if (entry == NULL) {
+		/* No coremedia entry... either loading order is wrong or this is for a non-existant entry */
+		return -1;
+	}
+
+	/* See if this is a dynamic payload oriented RTP mapping */
+	if (rtp->payload == -1) {
+		rtp->payload = generate_dynamic_payload();
+	}
+	if (rtp->payload == -1) {
+		/* Failed to generate a dynamic payload... */
+		return -1;
+	}
+
+	/* Attach the coremedia entry */
+	rtp->entry = entry;
+
+	/* All done - add it into the array */
+	ast_mutex_lock(&rtplock);
+	rtp_root[rtp->payload] = rtp;
+	ast_mutex_unlock(&rtplock);
+
+	if (option_verbose > 1)
+		ast_verbose(VERBOSE_PREFIX_2
+					"Registered RTP mapping %d %s/%d to coremedia handler %s\n",
+					rtp->payload, rtp->name, rtp->sample_rate,
+					rtp->entry->name);
+
+	return 0;
 }
 
 /* Unregister an RTP mapping */
 int ast_coremedia_rtp_unregister(struct ast_coremedia_rtp *rtp)
 {
-  int success = -1;
-
-  ast_mutex_lock(&rtplock);
-  if (rtp_root[rtp->payload] != NULL) {
-    success = 0;
-    rtp_root[rtp->payload] = NULL;
-    if (option_verbose > 1)
-      ast_verbose(VERBOSE_PREFIX_2 "Unregistered RTP mapping %d %s/%d from coremedia handler %s\n", rtp->payload, rtp->name, rtp->sample_rate, rtp->entry->name);
-  }
-  ast_mutex_unlock(&rtplock);
-
-  return success;
+	int success = -1;
+
+	ast_mutex_lock(&rtplock);
+	if (rtp_root[rtp->payload] != NULL) {
+		success = 0;
+		rtp_root[rtp->payload] = NULL;
+		if (option_verbose > 1)
+			ast_verbose(VERBOSE_PREFIX_2
+						"Unregistered RTP mapping %d %s/%d from coremedia handler %s\n",
+						rtp->payload, rtp->name, rtp->sample_rate,
+						rtp->entry->name);
+	}
+	ast_mutex_unlock(&rtplock);
+
+	return success;
 }
 
 /* Translate from a numerical type to a string representation */
 static char *type_to_name(int type)
 {
-  if (type == TYPE_AUDIO)
-    return "audio";
-  else if (type == TYPE_VIDEO)
-    return "video";
-  else if (type == TYPE_DATA)
-    return "data";
-  else if (type == TYPE_DTMF)
-    return "dtmf";
-  else
-    return "unknown";
+	if (type == TYPE_AUDIO)
+		return "audio";
+	else if (type == TYPE_VIDEO)
+		return "video";
+	else if (type == TYPE_DATA)
+		return "data";
+	else if (type == TYPE_DTMF)
+		return "dtmf";
+	else
+		return "unknown";
 }
 
 /* Find a coremedia entry by subclass */
 struct ast_coremedia_entry *ast_coremedia_get_by_subclass(int subclass)
 {
-  struct ast_coremedia_entry *entry = NULL;
-
-  ast_mutex_lock(&medialock);
-  if (ach_subclass[subclass] != NULL)
-    entry = ach_subclass[subclass];
-  ast_mutex_unlock(&medialock);
-
-  return entry;
+	struct ast_coremedia_entry *entry = NULL;
+
+	ast_mutex_lock(&medialock);
+	if (ach_subclass[subclass] != NULL)
+		entry = ach_subclass[subclass];
+	ast_mutex_unlock(&medialock);
+
+	return entry;
 }
 
 /* Find a coremedia handler by the old AST_FORMAT system */
 struct ast_coremedia_entry *ast_coremedia_get_by_format(int format)
 {
-  struct ast_coremedia_entry *entry = NULL;
-
-  ast_mutex_lock(&medialock);
-  entry = ach_root;
-  while (entry) {
-    if (entry->format == format)
-      break;
-    entry = entry->next;
-  }
-  ast_mutex_unlock(&medialock);
-
-  return entry;
+	struct ast_coremedia_entry *entry = NULL;
+
+	ast_mutex_lock(&medialock);
+	entry = ach_root;
+	while (entry) {
+		if (entry->format == format)
+			break;
+		entry = entry->next;
+	}
+	ast_mutex_unlock(&medialock);
+
+	return entry;
 }
 
 /* Find a coremedia handler by name, bitrate, and sample rate */
-struct ast_coremedia_entry *ast_coremedia_get(char *name, int bitrate, int sample_rate)
-{
-  struct ast_coremedia_entry *entry = NULL;
-
-  ast_mutex_lock(&medialock);
-  entry = ach_root;
-  while (entry) {
-    if (entry->name && !strcasecmp(entry->name, name) && entry->bitrate == bitrate && entry->sample_rate == sample_rate)
-      break;
-    entry = entry->next;
-  }
-  ast_mutex_unlock(&medialock);
-
-  return entry;
+struct ast_coremedia_entry *ast_coremedia_get(char *name, int bitrate,
+											  int sample_rate)
+{
+	struct ast_coremedia_entry *entry = NULL;
+
+	ast_mutex_lock(&medialock);
+	entry = ach_root;
+	while (entry) {
+		if (entry->name && !strcasecmp(entry->name, name)
+			&& entry->bitrate == bitrate && entry->sample_rate == sample_rate)
+			break;
+		entry = entry->next;
+	}
+	ast_mutex_unlock(&medialock);
+
+	return entry;
 }
 
 /* Link an encoder or decoder to a coremedia handler */
-int ast_coremedia_link(struct ast_coremedia_entry *cm, struct ast_coremedia_translator *tl, int direction)
-{
-
-  ast_mutex_lock(&medialock);
-  if (direction == CM_ENCODE) {
-    cm->encoder = tl;
-  } else if (direction == CM_DECODE) {
-    cm->decoder = tl;
-  }
-  ast_mutex_unlock(&medialock);
-
-  if (option_verbose > 1) {
-    if (cm->bitrate > 0)
-      ast_verbose(VERBOSE_PREFIX_2 "Linked %s to coremedia handler '%s' of type '%s' with bitrate %d and sample rate of %d\n", direction ? "decoder" : "encoder", cm->name, type_to_name(cm->type), cm->bitrate, cm->sample_rate);
-    else
-      ast_verbose(VERBOSE_PREFIX_2 "Linked %s to coremedia handler '%s' of type '%s' with sample rate of %d\n", direction ? "decoder" : "encoder", cm->name, type_to_name(cm->type), cm->sample_rate);
-  }
-
-  return 0;
+int ast_coremedia_link(struct ast_coremedia_entry *cm,
+					   struct ast_coremedia_translator *tl, int direction)
+{
+
+	ast_mutex_lock(&medialock);
+	if (direction == CM_ENCODE) {
+		cm->encoder = tl;
+	} else if (direction == CM_DECODE) {
+		cm->decoder = tl;
+	}
+	ast_mutex_unlock(&medialock);
+
+	if (option_verbose > 1) {
+		if (cm->bitrate > 0)
+			ast_verbose(VERBOSE_PREFIX_2
+						"Linked %s to coremedia handler '%s' of type '%s' with bitrate %d and sample rate of %d\n",
+						direction ? "decoder" : "encoder", cm->name,
+						type_to_name(cm->type), cm->bitrate, cm->sample_rate);
+		else
+			ast_verbose(VERBOSE_PREFIX_2
+						"Linked %s to coremedia handler '%s' of type '%s' with sample rate of %d\n",
+						direction ? "decoder" : "encoder", cm->name,
+						type_to_name(cm->type), cm->sample_rate);
+	}
+
+	return 0;
 }
 
 /* Link a file structure to a coremedia handler by name, bitrate, and sample rate */
 int ast_coremedia_link_file(char *name, int bitrate, int sample_rate)
 {
-  int success = -1;
-
-  return success;
+	int success = -1;
+
+	return success;
 }
 
 /* Link an encoder or decoder to a coremedia handler by name, bitrate, and sample rate */
-int ast_coremedia_link_by_data(char *name, int bitrate, int sample_rate, struct ast_coremedia_translator *tl, int direction)
-{
-  int success = -1;
-  struct ast_coremedia_entry *entry = NULL;
-
-  entry = ast_coremedia_get(name, bitrate, sample_rate);
-  if (entry != NULL) {
-    success = 0;
-    ast_coremedia_link(entry, tl, direction);
-  }
-
-  return success;
+int ast_coremedia_link_by_data(char *name, int bitrate, int sample_rate,
+							   struct ast_coremedia_translator *tl,
+							   int direction)
+{
+	int success = -1;
+	struct ast_coremedia_entry *entry = NULL;
+
+	entry = ast_coremedia_get(name, bitrate, sample_rate);
+	if (entry != NULL) {
+		success = 0;
+		ast_coremedia_link(entry, tl, direction);
+	}
+
+	return success;
 }
 
 /* Register a coremedia handler */
 int ast_coremedia_register(struct ast_coremedia_entry *cm)
 {
-  struct ast_coremedia_entry *entry = NULL;
-
-  /* Make sure a handler of this information is not already registered */

[... 494 lines stripped ...]


More information about the asterisk-commits mailing list