All pastes #170154 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-09-14 12:31 UTC
rendered paste body
/* This is the asterisk 1.2 code from svn */

static void *moh_files_alloc(struct ast_channel *chan, void *params)
{
	struct moh_files_state *state;
	struct mohclass *class = params;
	int allocated = 0;

	if (!chan->music_state && (state = malloc(sizeof(struct moh_files_state)))) {
		chan->music_state = state;
		allocated = 1;
	} else 
		state = chan->music_state;

	if (state) {
		if (allocated || state->class != class) {
			/* initialize */
			memset(state, 0, sizeof(struct moh_files_state));
			state->class = class;
		}

		state->origwfmt = chan->writeformat;

		if (option_verbose > 2)
			ast_verbose(VERBOSE_PREFIX_3 "Started music on hold, class '%s', on %s\n", class->name, chan->name);
	}
	
	return chan->music_state;
}

/* and here is the same bit of opbx code (with additional comments from me marked // DRMOUSE: */

static void *moh_files_alloc(struct opbx_channel *chan, void *params)
{
	struct moh_files_state *state;
	struct mohclass *class = params;
	int allocated = 0;

	if (!chan->music_state && (state = malloc(sizeof(struct moh_files_state)))) {
		chan->music_state = state;
		allocated = 1;
	} else 
		state = chan->music_state;

	if (state) {
		if (allocated || state->class != class) {
			/* initialize */
			memset(state, 0, sizeof(struct moh_files_state));
			state->class = class;
		}

		state->origwfmt = chan->writeformat;

                                                   // DRMOUSE: This is the bit that is different.
                                                   // DRMOUSE: Notice that it always sets to OPBX_FORMAT_SLINEAR
                                                   // DRMOUSE: In *, it doesnt. I dont know if it is easily possible
                                                   // DRMOUSE: to port this change over, i dont know the differences
                                                   // DRMOUSE: in the rest, but this is where native moh fails in
                                                   // DRMOUSE: OPBX.

		if (opbx_set_write_format(chan, OPBX_FORMAT_SLINEAR)) {
			opbx_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name);
			free(chan->music_state);
			chan->music_state = NULL;
		} else {
			if (option_verbose > 2)
				opbx_verbose(VERBOSE_PREFIX_3 "Started music on hold, class '%s', on %s\n", class->name, chan->name);
		}
	}
	
	return chan->music_state;
}