Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
res_format_attr_celt.c File Reference

CELT format attribute interface. More...

#include "asterisk.h"
#include <ctype.h>
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/astobj2.h"
#include "asterisk/logger.h"
#include "asterisk/strings.h"
#include "asterisk/utils.h"
Include dependency graph for res_format_attr_celt.c:

Go to the source code of this file.

Data Structures

struct  celt_attr
 CELT attribute structure. More...
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int celt_clone (const struct ast_format *src, struct ast_format *dst)
 
static enum ast_format_cmp_res celt_cmp (const struct ast_format *format1, const struct ast_format *format2)
 
static void celt_destroy (struct ast_format *format)
 
static void celt_generate_sdp_fmtp (const struct ast_format *format, unsigned int payload, struct ast_str **str)
 
static struct ast_formatcelt_getjoint (const struct ast_format *format1, const struct ast_format *format2)
 
static struct ast_formatcelt_parse_sdp_fmtp (const struct ast_format *format, const char *attributes)
 
static struct ast_formatcelt_set (const struct ast_format *format, const char *name, const char *value)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "CELT Format Attribute Module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_format_interface celt_interface
 

Detailed Description

CELT format attribute interface.

Author
David Vossel dvoss.nosp@m.el@d.nosp@m.igium.nosp@m..com

Definition in file res_format_attr_celt.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 216 of file res_format_attr_celt.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 216 of file res_format_attr_celt.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 216 of file res_format_attr_celt.c.

◆ celt_clone()

static int celt_clone ( const struct ast_format src,
struct ast_format dst 
)
static

Definition at line 59 of file res_format_attr_celt.c.

References ast_calloc, ast_format_get_attribute_data(), and ast_format_set_attribute_data().

60 {
61  struct celt_attr *original = ast_format_get_attribute_data(src);
62  struct celt_attr *attr = ast_calloc(1, sizeof(*attr));
63 
64  if (!attr) {
65  return -1;
66  }
67 
68  if (original) {
69  *attr = *original;
70  }
71 
73 
74  return 0;
75 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void ast_format_set_attribute_data(struct ast_format *format, void *attribute_data)
Set the attribute data on a format.
Definition: format.c:130
CELT attribute structure.

◆ celt_cmp()

static enum ast_format_cmp_res celt_cmp ( const struct ast_format format1,
const struct ast_format format2 
)
static

Definition at line 113 of file res_format_attr_celt.c.

References AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_attribute_data(), and celt_attr::samplerate.

114 {
115  struct celt_attr *attr1 = ast_format_get_attribute_data(format1);
116  struct celt_attr *attr2 = ast_format_get_attribute_data(format2);
117 
118  if (((!attr1 || !attr1->samplerate) && (!attr2 || !attr2->samplerate)) ||
119  (attr1->samplerate == attr2->samplerate)) {
120  return AST_FORMAT_CMP_EQUAL;
121  }
122 
124 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
unsigned int samplerate
CELT attribute structure.

◆ celt_destroy()

static void celt_destroy ( struct ast_format format)
static

Definition at line 52 of file res_format_attr_celt.c.

References ast_format_get_attribute_data(), and ast_free.

53 {
54  struct celt_attr *attr = ast_format_get_attribute_data(format);
55 
56  ast_free(attr);
57 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define ast_free(a)
Definition: astmm.h:182
CELT attribute structure.

◆ celt_generate_sdp_fmtp()

static void celt_generate_sdp_fmtp ( const struct ast_format format,
unsigned int  payload,
struct ast_str **  str 
)
static

Definition at line 102 of file res_format_attr_celt.c.

References ast_format_get_attribute_data(), ast_str_append(), and celt_attr::framesize.

103 {
104  struct celt_attr *attr = ast_format_get_attribute_data(format);
105 
106  if (!attr || !attr->framesize) {
107  return;
108  }
109 
110  ast_str_append(str, 0, "a=fmtp:%u framesize=%u\r\n", payload, attr->framesize);
111 }
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:1091
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
unsigned int framesize
CELT attribute structure.

◆ celt_getjoint()

static struct ast_format* celt_getjoint ( const struct ast_format format1,
const struct ast_format format2 
)
static

Definition at line 126 of file res_format_attr_celt.c.

References ast_format_clone(), ast_format_get_attribute_data(), celt_attr::framesize, celt_attr::maxbitrate, MIN, NULL, and celt_attr::samplerate.

127 {
128  struct celt_attr *attr1 = ast_format_get_attribute_data(format1);
129  struct celt_attr *attr2 = ast_format_get_attribute_data(format2);
130  struct ast_format *jointformat;
131  struct celt_attr *jointattr;
132 
133  if (attr1 && attr2 && (attr1->samplerate != attr2->samplerate)) {
134  return NULL;
135  }
136 
137  jointformat = ast_format_clone(format1);
138  if (!jointformat) {
139  return NULL;
140  }
141  jointattr = ast_format_get_attribute_data(jointformat);
142 
143  /* either would work, they are guaranteed the same at this point. */
144  jointattr->samplerate = attr1->samplerate;
145  /* Take the lowest max bitrate */
146  jointattr->maxbitrate = MIN(attr1->maxbitrate, attr2->maxbitrate);
147 
148  jointattr->framesize = attr2->framesize; /* TODO figure out what joint framesize means */
149 
150  return jointformat;
151 }
Definition of a media format.
Definition: format.c:43
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
unsigned int maxbitrate
#define NULL
Definition: resample.c:96
#define MIN(a, b)
Definition: utils.h:226
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
unsigned int framesize
unsigned int samplerate
CELT attribute structure.

◆ celt_parse_sdp_fmtp()

static struct ast_format* celt_parse_sdp_fmtp ( const struct ast_format format,
const char *  attributes 
)
static

Definition at line 77 of file res_format_attr_celt.c.

References ast_format_clone(), ast_format_get_attribute_data(), ast_strdupa, celt_attr::framesize, and NULL.

78 {
79  char *attribs = ast_strdupa(attributes), *attrib;
80  struct ast_format *cloned;
81  struct celt_attr *attr;
82  unsigned int val;
83 
84  cloned = ast_format_clone(format);
85  if (!cloned) {
86  return NULL;
87  }
88  attr = ast_format_get_attribute_data(cloned);
89 
90  /* lower-case everything, so we are case-insensitive */
91  for (attrib = attribs; *attrib; ++attrib) {
92  *attrib = tolower(*attrib);
93  } /* based on channels/chan_sip.c:process_a_sdp_image() */
94 
95  if (sscanf(attribs, "framesize=%30u", &val) == 1) {
96  attr->framesize = val;
97  }
98 
99  return cloned;
100 }
Definition: ast_expr2.c:325
Definition of a media format.
Definition: format.c:43
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define NULL
Definition: resample.c:96
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
unsigned int framesize
CELT attribute structure.

◆ celt_set()

static struct ast_format* celt_set ( const struct ast_format format,
const char *  name,
const char *  value 
)
static

Definition at line 153 of file res_format_attr_celt.c.

References ao2_ref, ast_format_clone(), ast_format_get_attribute_data(), ast_log, celt_attr::framesize, LOG_WARNING, celt_attr::maxbitrate, NULL, and celt_attr::samplerate.

154 {
155  struct ast_format *cloned;
156  struct celt_attr *attr;
157  unsigned int val;
158 
159  cloned = ast_format_clone(format);
160  if (!cloned) {
161  return NULL;
162  }
163  attr = ast_format_get_attribute_data(cloned);
164 
165  if (sscanf(value, "%30u", &val) != 1) {
166  ast_log(LOG_WARNING, "Unknown value '%s' for attribute type '%s'\n",
167  value, name);
168  ao2_ref(cloned, -1);
169  return NULL;
170  }
171 
172  if (!strcasecmp(name, "sample_rate")) {
173  attr->samplerate = val;
174  } else if (!strcasecmp(name, "max_bitrate")) {
175  attr->maxbitrate = val;
176  } else if (!strcasecmp(name, "frame_size")) {
177  attr->framesize = val;
178  } else {
179  ast_log(LOG_WARNING, "Unknown attribute type '%s'\n", name);
180  ao2_ref(cloned, -1);
181  return NULL;
182  }
183 
184  return cloned;
185 }
Definition: ast_expr2.c:325
#define LOG_WARNING
Definition: logger.h:274
Definition of a media format.
Definition: format.c:43
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
unsigned int maxbitrate
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
struct ast_format * ast_format_clone(const struct ast_format *format)
Clone an existing media format so it can be modified.
Definition: format.c:180
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static const char name[]
Definition: cdr_mysql.c:74
unsigned int framesize
unsigned int samplerate
CELT attribute structure.

◆ load_module()

static int load_module ( void  )
static

Definition at line 197 of file res_format_attr_celt.c.

References ast_format_interface_register, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

Referenced by unload_module().

198 {
201  }
202 
204 }
#define ast_format_interface_register(codec, interface)
Register a format interface for use with the provided codec.
Definition: format.h:273
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_format_interface celt_interface

◆ unload_module()

static int unload_module ( void  )
static

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "CELT Format Attribute Module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, }
static

Definition at line 216 of file res_format_attr_celt.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 216 of file res_format_attr_celt.c.

◆ celt_interface

struct ast_format_interface celt_interface
static

Definition at line 187 of file res_format_attr_celt.c.