Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
res_format_attr_vp8.c File Reference

VP8 format attribute interface. More...

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

Go to the source code of this file.

Data Structures

struct  vp8_attr
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 
static int vp8_clone (const struct ast_format *src, struct ast_format *dst)
 
static void vp8_destroy (struct ast_format *format)
 
static void vp8_generate_sdp_fmtp (const struct ast_format *format, unsigned int payload, struct ast_str **str)
 
static struct ast_formatvp8_getjoint (const struct ast_format *format1, const struct ast_format *format2)
 
static struct ast_formatvp8_parse_sdp_fmtp (const struct ast_format *format, const char *attributes)
 
static struct ast_formatvp8_set (const struct ast_format *format, const char *name, const char *value)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "VP8 Format Attribute Module" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .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 vp8_attr default_vp8_attr
 
static struct ast_format_interface vp8_interface
 

Detailed Description

VP8 format attribute interface.

Author
Alexander Traud pabst.nosp@m.raud.nosp@m.@comp.nosp@m.user.nosp@m.ve.co.nosp@m.m
Note
http://tools.ietf.org/html/draft-ietf-payload-vp8

Definition in file res_format_attr_vp8.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 234 of file res_format_attr_vp8.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 234 of file res_format_attr_vp8.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 234 of file res_format_attr_vp8.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 215 of file res_format_attr_vp8.c.

216{
219 }
220
222}
#define ast_format_interface_register(codec, interface)
Register a format interface for use with the provided codec.
Definition format.h:273
@ 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 vp8_interface

References ast_format_interface_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and vp8_interface.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 224 of file res_format_attr_vp8.c.

225{
226 return 0;
227}

◆ vp8_clone()

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

Definition at line 59 of file res_format_attr_vp8.c.

60{
61 struct vp8_attr *original = ast_format_get_attribute_data(src);
62 struct vp8_attr *attr = ast_malloc(sizeof(*attr));
63
64 if (!attr) {
65 return -1;
66 }
67
68 if (original) {
69 *attr = *original;
70 } else {
71 *attr = default_vp8_attr;
72 }
73
75
76 return 0;
77}
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition format.c:125
void ast_format_set_attribute_data(struct ast_format *format, void *attribute_data)
Set the attribute data on a format.
Definition format.c:130
static struct vp8_attr default_vp8_attr

References ast_format_get_attribute_data(), ast_format_set_attribute_data(), ast_malloc, and default_vp8_attr.

◆ vp8_destroy()

static void vp8_destroy ( struct ast_format format)
static

Definition at line 52 of file res_format_attr_vp8.c.

53{
54 struct vp8_attr *attr = ast_format_get_attribute_data(format);
55
56 ast_free(attr);
57}
#define ast_free(a)
Definition astmm.h:180

References ast_format_get_attribute_data(), and ast_free.

◆ vp8_generate_sdp_fmtp()

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

Definition at line 113 of file res_format_attr_vp8.c.

114{
115 struct vp8_attr *attr = ast_format_get_attribute_data(format);
116 int added = 0;
117
118 if (!attr) {
119 /*
120 * (Only) cached formats do not have attribute data assigned because
121 * they were created before this attribute module was registered.
122 * Therefore, we assume the default attribute values here.
123 */
124 attr = &default_vp8_attr;
125 }
126
127 if (UINT_MAX != attr->maximum_frame_rate) {
128 if (added) {
129 ast_str_append(str, 0, ";");
130 } else if (0 < ast_str_append(str, 0, "a=fmtp:%u ", payload)) {
131 added = 1;
132 }
133 ast_str_append(str, 0, "max-fr=%u", attr->maximum_frame_rate);
134 }
135
136 if (UINT_MAX != attr->maximum_frame_size) {
137 if (added) {
138 ast_str_append(str, 0, ";");
139 } else if (0 < ast_str_append(str, 0, "a=fmtp:%u ", payload)) {
140 added = 1;
141 }
142 ast_str_append(str, 0, "max-fs=%u", attr->maximum_frame_size);
143 }
144
145 if (added) {
146 ast_str_append(str, 0, "\r\n");
147 }
148}
const char * str
Definition app_jack.c:150
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
unsigned int maximum_frame_rate
unsigned int maximum_frame_size

References ast_format_get_attribute_data(), ast_str_append(), default_vp8_attr, vp8_attr::maximum_frame_rate, vp8_attr::maximum_frame_size, and str.

◆ vp8_getjoint()

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

Definition at line 150 of file res_format_attr_vp8.c.

151{
152 struct vp8_attr *attr1 = ast_format_get_attribute_data(format1);
153 struct vp8_attr *attr2 = ast_format_get_attribute_data(format2);
154 struct ast_format *jointformat;
155 struct vp8_attr *attr_res;
156
157 if (!attr1) {
158 attr1 = &default_vp8_attr;
159 }
160
161 if (!attr2) {
162 attr2 = &default_vp8_attr;
163 }
164
165 jointformat = ast_format_clone(format1);
166 if (!jointformat) {
167 return NULL;
168 }
169 attr_res = ast_format_get_attribute_data(jointformat);
170
173
174 return jointformat;
175}
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 NULL
Definition resample.c:96
Definition of a media format.
Definition format.c:43
#define MIN(a, b)
Definition utils.h:252

References ast_format_clone(), ast_format_get_attribute_data(), default_vp8_attr, vp8_attr::maximum_frame_rate, vp8_attr::maximum_frame_size, MIN, and NULL.

◆ vp8_parse_sdp_fmtp()

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

Definition at line 79 of file res_format_attr_vp8.c.

80{
81 char *attribs = ast_strdupa(attributes), *attrib;
82 struct ast_format *cloned;
83 struct vp8_attr *attr;
84 const char *kvp;
85 unsigned int val;
86
87 cloned = ast_format_clone(format);
88 if (!cloned) {
89 return NULL;
90 }
91 attr = ast_format_get_attribute_data(cloned);
92
93 /* lower-case everything, so we are case-insensitive */
94 for (attrib = attribs; *attrib; ++attrib) {
95 *attrib = tolower(*attrib);
96 } /* based on channels/chan_sip.c:process_a_sdp_image() */
97
98 if ((kvp = strstr(attribs, "max-fr")) && sscanf(kvp, "max-fr=%30u", &val) == 1) {
99 attr->maximum_frame_rate = val;
100 } else {
101 attr->maximum_frame_rate = UINT_MAX;
102 }
103
104 if ((kvp = strstr(attribs, "max-fs")) && sscanf(kvp, "max-fs=%30u", &val) == 1) {
105 attr->maximum_frame_size = val;
106 } else {
107 attr->maximum_frame_size = UINT_MAX;
108 }
109
110 return cloned;
111}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298

References ast_format_clone(), ast_format_get_attribute_data(), ast_strdupa, vp8_attr::maximum_frame_rate, vp8_attr::maximum_frame_size, and NULL.

◆ vp8_set()

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

Definition at line 177 of file res_format_attr_vp8.c.

178{
179 struct ast_format *cloned;
180 struct vp8_attr *attr;
181 unsigned int val;
182
183 if (sscanf(value, "%30u", &val) != 1) {
184 ast_log(LOG_WARNING, "Unknown value '%s' for attribute type '%s'\n",
185 value, name);
186 return NULL;
187 }
188
189 cloned = ast_format_clone(format);
190 if (!cloned) {
191 return NULL;
192 }
193 attr = ast_format_get_attribute_data(cloned);
194
195 if (!strcasecmp(name, "maximum_frame_rate")) {
196 attr->maximum_frame_rate = val;
197 } else if (!strcasecmp(name, "maximum_frame_size")) {
198 attr->maximum_frame_size = val;
199 } else {
200 ast_log(LOG_WARNING, "unknown attribute type %s\n", name);
201 }
202
203 return cloned;
204}
#define ast_log
Definition astobj2.c:42
static const char name[]
Definition format_mp3.c:68
#define LOG_WARNING
int value
Definition syslog.c:37

References ast_format_clone(), ast_format_get_attribute_data(), ast_log, LOG_WARNING, vp8_attr::maximum_frame_rate, vp8_attr::maximum_frame_size, name, NULL, and value.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "VP8 Format Attribute Module" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, }
static

Definition at line 234 of file res_format_attr_vp8.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 234 of file res_format_attr_vp8.c.

◆ default_vp8_attr

struct vp8_attr default_vp8_attr
static
Initial value:
= {
.maximum_frame_rate = UINT_MAX,
.maximum_frame_size = UINT_MAX,
}

Definition at line 47 of file res_format_attr_vp8.c.

47 {
48 .maximum_frame_rate = UINT_MAX,
49 .maximum_frame_size = UINT_MAX,
50};

Referenced by vp8_clone(), vp8_generate_sdp_fmtp(), and vp8_getjoint().

◆ vp8_interface

struct ast_format_interface vp8_interface
static

Definition at line 206 of file res_format_attr_vp8.c.

206 {
207 .format_destroy = vp8_destroy,
208 .format_clone = vp8_clone,
209 .format_get_joint = vp8_getjoint,
210 .format_attribute_set = vp8_set,
211 .format_parse_sdp_fmtp = vp8_parse_sdp_fmtp,
212 .format_generate_sdp_fmtp = vp8_generate_sdp_fmtp,
213};
static void vp8_generate_sdp_fmtp(const struct ast_format *format, unsigned int payload, struct ast_str **str)
static struct ast_format * vp8_set(const struct ast_format *format, const char *name, const char *value)
static int vp8_clone(const struct ast_format *src, struct ast_format *dst)
static struct ast_format * vp8_getjoint(const struct ast_format *format1, const struct ast_format *format2)
static struct ast_format * vp8_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
static void vp8_destroy(struct ast_format *format)

Referenced by load_module().