--- include/asterisk/channel.h (svn) +++ include/asterisk/channel.h (working copy) @@ -116,6 +116,8 @@ #include "asterisk/utils.h" #include "asterisk/linkedlists.h" #include "asterisk/stringfields.h" +#include "asterisk/options.h" +#include "asterisk/strings.h" #include "asterisk/compiler.h" @@ -631,6 +633,14 @@ */ struct ast_channel *ast_request(const char *type, int format, void *data, int *status); + +/*! \brief call ast_request with format/type of parent channel + */ +static inline struct ast_channel *ast_request_inherit(struct ast_channel *chan, const char *type, void *data, int *status) +{ + return ast_request(S_OR(type, chan->tech->type), chan->nativeformats, data, status); +} + /*! * \brief Request a channel of a given type, with data as optional information used * by the low level module and attempt to place a call on it @@ -851,6 +861,28 @@ */ int ast_set_read_format(struct ast_channel *chan, int format); +/*! \brief Gets read format from channel chan + * \param chan channel to get info + * Get read format for channel + * Returns read format + */ +static inline int ast_get_read_format(struct ast_channel *chan) +{ + return chan->readformat; +} + +/*! Gets write format from channel chan */ +/*! + * \param chan channel to get info + * Get write format for channel + * Returns write format + */ +static inline int ast_get_write_format(struct ast_channel *chan) +{ + return chan->writeformat; +} + + /*! \brief Sets write format on channel chan * Set write format for channel to whichever compoent of "format" is best. * \param chan channel to change @@ -1040,7 +1072,66 @@ /* Choose the best codec... Uhhh... Yah. */ int ast_best_codec(int fmts); +/*! + * \brief Pick the best codec from channel nativeformats + * \param channel channel, from that nativeformats used + */ +static inline int ast_channel_best_codec(struct ast_channel *channel) +{ +#ifndef BUG_4825 + return ast_best_codec(channel->nativeformats); +#else + return ast_best_codec(channel->nativeformats.audio_bits); +#endif +} +/*! \brief Get the names of a set of formats + * \param buf a buffer for the output string + * \param size size of buf (bytes) + * \param channel the channel + * Prints a list of readable codec names corresponding to "format". + * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)" + * \return The return value is buf. + */ +inline static char * ast_channel_getformatname_multiple(char *buf, size_t size, struct ast_channel *chan) +{ + return ast_getformatname_multiple(buf, size, chan->nativeformats); +} + +static inline const char * ast_channel_getformatname(struct ast_channel *chan) +{ +#ifndef BUG_4825 + return chan ? ast_getformatname(chan->nativeformats) : "undefined"; +#else + return chan ? ast_getformatname(chan->nativeformats.audio_bits) : "undefined"; +#endif +} + +static inline void ast_channel_formats_reset(struct ast_channel *channel) +{ + int r, w; + r = ast_get_read_format(channel); + w = ast_get_write_format(channel); + + if (option_debug) + ast_log(LOG_DEBUG, "Resetting read to %d and write to %d on channel %s\n", r, w, channel->name); + if (r) + ast_set_read_format(channel, r); + if (w) + ast_set_write_format(channel, w); +} + +/*! + * \brief Set best format, identical to read/write + * \param channel channel, from that nativeformats used and formats set + */ +static inline void ast_set_best_format(struct ast_channel *channel) +{ + int format = ast_channel_best_codec(channel); + ast_set_read_format(channel, format); + ast_set_write_format(channel, format); +} + /*! Checks the value of an option */ /*! * Query the value of an option, optionally blocking until a reply is received