Asterisk - The Open Source Telephony Project GIT-master-f36a736
res_format_attr_siren14.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2016, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*!
20 * \file
21 * \brief Siren14 format attribute interface
22 *
23 * \author Joshua Colp <jcolp@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include <ctype.h> /* for tolower */
33
34#include "asterisk/module.h"
35#include "asterisk/format.h"
36#include "asterisk/astobj2.h" /* for ao2_bump */
37#include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
38#include "asterisk/strings.h" /* for ast_str_append */
39
40/* Destroy is a required callback and must exist */
41static void siren14_destroy(struct ast_format *format)
42{
43}
44
45/* Clone is a required callback and must exist */
46static int siren14_clone(const struct ast_format *src, struct ast_format *dst)
47{
48 return 0;
49}
50
51static struct ast_format *siren14_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
52{
53 char *attribs = ast_strdupa(attributes), *attrib;
54 unsigned int val;
55
56 /* lower-case everything, so we are case-insensitive */
57 for (attrib = attribs; *attrib; ++attrib) {
58 *attrib = tolower(*attrib);
59 } /* based on channels/chan_sip.c:process_a_sdp_image() */
60
61 if (sscanf(attribs, "bitrate=%30u", &val) == 1) {
62 if (val != 48000) {
63 ast_log(LOG_WARNING, "Got siren14 offer at %u bps, but only 48000 bps supported; ignoring.\n", val);
64 return NULL;
65 }
66 }
67
68 /* We aren't modifying the format and once passed back it won't be touched, so use what we were given */
69 return ao2_bump((struct ast_format *)format);
70}
71
72static void siren14_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
73{
74 ast_str_append(str, 0, "a=fmtp:%u bitrate=48000\r\n", payload);
75}
76
79 .format_clone = siren14_clone,
80 .format_parse_sdp_fmtp = siren14_parse_sdp_fmtp,
81 .format_generate_sdp_fmtp = siren14_generate_sdp_fmtp,
82};
83
84static int load_module(void)
85{
88 }
89
91}
92
93static int unload_module(void)
94{
95 return 0;
96}
97
98AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Siren14 Format Attribute Module",
99 .support_level = AST_MODULE_SUPPORT_CORE,
100 .load = load_module,
101 .unload = unload_module,
102 .load_pri = AST_MODPRI_CHANNEL_DEPEND,
const char * str
Definition: app_jack.c:147
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
Media Format API.
#define ast_format_interface_register(codec, interface)
Register a format interface for use with the provided codec.
Definition: format.h:273
Support for logging to various files, console and syslog Configuration in file logger....
#define LOG_WARNING
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:331
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODPRI_CHANNEL_DEPEND
Definition: module.h:340
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_format_interface siren14_interface
static void siren14_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
static void siren14_destroy(struct ast_format *format)
static int load_module(void)
static int siren14_clone(const struct ast_format *src, struct ast_format *dst)
static int unload_module(void)
static struct ast_format * siren14_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
#define NULL
Definition: resample.c:96
String manipulation functions.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
Optional format interface to extend format operations.
Definition: format.h:44
void(*const format_destroy)(struct ast_format *format)
Callback for when the format is destroyed, used to release attribute resources.
Definition: format.h:50
Definition of a media format.
Definition: format.c:43
Support for dynamic strings.
Definition: strings.h:623
Definition: ast_expr2.c:325