Asterisk - The Open Source Telephony Project  18.5.0
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 = "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 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.

References ast_format_interface_register, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

Referenced by unload_module().

216 {
219  }
220 
222 }
static struct ast_format_interface vp8_interface
#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

◆ unload_module()

static int unload_module ( void  )
static

◆ 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.

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

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 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
static struct vp8_attr default_vp8_attr
void ast_format_set_attribute_data(struct ast_format *format, void *attribute_data)
Set the attribute data on a format.
Definition: format.c:130

◆ vp8_destroy()

static void vp8_destroy ( struct ast_format format)
static

Definition at line 52 of file res_format_attr_vp8.c.

References ast_format_get_attribute_data(), and ast_free.

53 {
54  struct vp8_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

◆ 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.

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

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 }
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 maximum_frame_size
unsigned int maximum_frame_rate
static struct vp8_attr default_vp8_attr

◆ 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.

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.

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 
171  attr_res->maximum_frame_rate = MIN(attr1->maximum_frame_rate, attr2->maximum_frame_rate);
172  attr_res->maximum_frame_size = MIN(attr1->maximum_frame_size, attr2->maximum_frame_size);
173 
174  return jointformat;
175 }
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
unsigned int maximum_frame_size
unsigned int maximum_frame_rate
#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
static struct vp8_attr default_vp8_attr

◆ 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.

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

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 }
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
unsigned int maximum_frame_size
unsigned int maximum_frame_rate
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

◆ 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.

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

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 }
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
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
unsigned int maximum_frame_size
unsigned int maximum_frame_rate
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
static const char name[]
Definition: cdr_mysql.c:74

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "VP8 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 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.

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.