Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Data Structures | Macros | Functions | Variables
res_format_attr_h263.c File Reference

H.263 Format Attribute Module. More...

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

Go to the source code of this file.

Data Structures

struct  h263_attr
 

Macros

#define APPEND_IF_NONZERO(field, str, name)
 
#define APPEND_IF_NOT_H263_UNSET(field, str, name)
 
#define DETERMINE_JOINT(joint, attr1, attr2, field)   (joint->field = (attr1 && attr1->field) ? attr1->field : (attr2 && attr2->field) ? attr2->field : 0)
 
#define H263_ATTR_KEY_UNSET   UINT8_MAX
 Value that indicates an attribute is actually unset. More...
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int h263_clone (const struct ast_format *src, struct ast_format *dst)
 
static enum ast_format_cmp_res h263_cmp (const struct ast_format *format1, const struct ast_format *format2)
 
static void h263_destroy (struct ast_format *format)
 
static void h263_generate_sdp_fmtp (const struct ast_format *format, unsigned int payload, struct ast_str **str)
 
static struct ast_formath263_getjoint (const struct ast_format *format1, const struct ast_format *format2)
 
static struct ast_formath263_parse_sdp_fmtp (const struct ast_format *format, const char *attributes)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "H.263 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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_format_interface h263_interface
 

Detailed Description

H.263 Format Attribute Module.

Author
Joshua Colp <jcolp@digium.com> 

This is a format attribute module for the H.263 codec.

Definition in file res_format_attr_h263.c.

Macro Definition Documentation

◆ APPEND_IF_NONZERO

#define APPEND_IF_NONZERO (   field,
  str,
  name 
)

Definition at line 277 of file res_format_attr_h263.c.

◆ APPEND_IF_NOT_H263_UNSET

#define APPEND_IF_NOT_H263_UNSET (   field,
  str,
  name 
)

Definition at line 266 of file res_format_attr_h263.c.

◆ DETERMINE_JOINT

#define DETERMINE_JOINT (   joint,
  attr1,
  attr2,
  field 
)    (joint->field = (attr1 && attr1->field) ? attr1->field : (attr2 && attr2->field) ? attr2->field : 0)

Definition at line 117 of file res_format_attr_h263.c.

◆ H263_ATTR_KEY_UNSET

#define H263_ATTR_KEY_UNSET   UINT8_MAX

Value that indicates an attribute is actually unset.

Definition at line 44 of file res_format_attr_h263.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 399 of file res_format_attr_h263.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 399 of file res_format_attr_h263.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 399 of file res_format_attr_h263.c.

◆ h263_clone()

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

Definition at line 88 of file res_format_attr_h263.c.

89{
90 struct h263_attr *original = ast_format_get_attribute_data(src);
91 struct h263_attr *attr = ast_calloc(1, sizeof(*attr));
92
93 if (!attr) {
94 return -1;
95 }
96
97 if (original) {
98 *attr = *original;
99 }
100
102
103 return 0;
104}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
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

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

◆ h263_cmp()

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

Definition at line 106 of file res_format_attr_h263.c.

107{
108 struct h263_attr *attr1 = ast_format_get_attribute_data(format1);
109 struct h263_attr *attr2 = ast_format_get_attribute_data(format2);
110
111 if (!attr1 || !attr2 || (attr1 && attr2 && !memcmp(attr1, attr2, sizeof(*attr1)))) {
113 }
115}
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38

References AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, and ast_format_get_attribute_data().

◆ h263_destroy()

static void h263_destroy ( struct ast_format format)
static

Definition at line 81 of file res_format_attr_h263.c.

82{
83 struct h263_attr *attr = ast_format_get_attribute_data(format);
84
85 ast_free(attr);
86}
#define ast_free(a)
Definition: astmm.h:180

References ast_format_get_attribute_data(), and ast_free.

◆ h263_generate_sdp_fmtp()

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

Definition at line 288 of file res_format_attr_h263.c.

289{
290 struct h263_attr *attr = ast_format_get_attribute_data(format);
291 int added = 0;
292
293 if (!attr) {
294 return;
295 }
296
297 if (attr->CPCF) {
298 if (added) {
299 ast_str_append(str, 0, ";");
300 } else if (0 < ast_str_append(str, 0, "a=fmtp:%u ", payload)) {
301 added = 1;
302 }
303 ast_str_append(str, 0, "CPCF=%u,%u,%u,%u,%u,%u,%u,%u", attr->CPCF, attr->CPCF_2, attr->CPCF_3,
304 attr->CPCF_4, attr->CPCF_5, attr->CPCF_6, attr->CPCF_7, attr->CPCF_MPI);
305 }
306
307 APPEND_IF_NONZERO(attr->CIF16, str, "CIF16");
308 APPEND_IF_NONZERO(attr->CIF4, str, "CIF4");
309 APPEND_IF_NONZERO(attr->VGA, str, "VGA");
310 APPEND_IF_NONZERO(attr->CIF, str, "CIF");
311 APPEND_IF_NONZERO(attr->QCIF, str, "QCIF");
312 APPEND_IF_NONZERO(attr->SQCIF, str, "SQCIF");
313
314 if (attr->CUSTOM_XMAX && attr->CUSTOM_YMAX && attr->CUSTOM_MPI) {
315 if (added) {
316 ast_str_append(str, 0, ";");
317 } else if (0 < ast_str_append(str, 0, "a=fmtp:%u ", payload)) {
318 added = 1;
319 }
320 ast_str_append(str, 0, "CUSTOM=%u,%u,%u", attr->CUSTOM_XMAX, attr->CUSTOM_YMAX, attr->CUSTOM_MPI);
321 }
322
323 APPEND_IF_NONZERO(attr->F, str, "F");
324 APPEND_IF_NONZERO(attr->I, str, "I");
325 APPEND_IF_NONZERO(attr->J, str, "J");
326 APPEND_IF_NONZERO(attr->T, str, "T");
327 APPEND_IF_NONZERO(attr->K, str, "K");
328 APPEND_IF_NONZERO(attr->N, str, "N");
329
330 if (attr->P_SUB1) {
331 if (added) {
332 ast_str_append(str, 0, ";");
333 } else if (0 < ast_str_append(str, 0, "a=fmtp:%u ", payload)) {
334 added = 1;
335 }
336 ast_str_append(str, 0, "P=%u", attr->P_SUB1);
337 if (attr->P_SUB2) {
338 ast_str_append(str, 0, ",%u", attr->P_SUB2);
339 }
340 if (attr->P_SUB3) {
341 ast_str_append(str, 0, ",%u", attr->P_SUB3);
342 }
343 if (attr->P_SUB4) {
344 ast_str_append(str, 0, ",%u", attr->P_SUB4);
345 }
346 }
347
349 if (added) {
350 ast_str_append(str, 0, ";");
351 } else if (0 < ast_str_append(str, 0, "a=fmtp:%u ", payload)) {
352 added = 1; \
353 }
354 ast_str_append(str, 0, "PAR=%u:%u", attr->PAR_WIDTH, attr->PAR_HEIGHT);
355 }
356
357 APPEND_IF_NOT_H263_UNSET(attr->BPP, str, "BPP");
358
359 APPEND_IF_NONZERO(attr->HRD, str, "HRD");
360
361 APPEND_IF_NOT_H263_UNSET(attr->MaxBR, str, "MaxBR");
362
363 ast_str_append(str, 0, "\r\n");
364
365 return;
366}
const char * str
Definition: app_jack.c:147
#define APPEND_IF_NOT_H263_UNSET(field, str, name)
#define APPEND_IF_NONZERO(field, str, name)
#define H263_ATTR_KEY_UNSET
Value that indicates an attribute is actually unset.
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 CPCF_2
unsigned int CUSTOM_YMAX
unsigned int F
unsigned int CIF4
unsigned int J
unsigned int HRD
unsigned int K
unsigned int CPCF_4
unsigned int P_SUB1
unsigned int P_SUB4
unsigned int CPCF
unsigned int CPCF_6
unsigned int CPCF_3
unsigned int VGA
unsigned int SQCIF
unsigned int CPCF_MPI
unsigned int P_SUB3
unsigned int I
unsigned int PAR_HEIGHT
unsigned int CUSTOM_XMAX
unsigned int QCIF
unsigned int CUSTOM_MPI
unsigned int CIF16
unsigned int T
unsigned int BPP
unsigned int CPCF_7
unsigned int MaxBR
unsigned int CIF
unsigned int N
unsigned int P_SUB2
unsigned int CPCF_5
unsigned int PAR_WIDTH

References APPEND_IF_NONZERO, APPEND_IF_NOT_H263_UNSET, ast_format_get_attribute_data(), ast_str_append(), h263_attr::BPP, h263_attr::CIF, h263_attr::CIF16, h263_attr::CIF4, h263_attr::CPCF, h263_attr::CPCF_2, h263_attr::CPCF_3, h263_attr::CPCF_4, h263_attr::CPCF_5, h263_attr::CPCF_6, h263_attr::CPCF_7, h263_attr::CPCF_MPI, h263_attr::CUSTOM_MPI, h263_attr::CUSTOM_XMAX, h263_attr::CUSTOM_YMAX, h263_attr::F, H263_ATTR_KEY_UNSET, h263_attr::HRD, h263_attr::I, h263_attr::J, h263_attr::K, h263_attr::MaxBR, h263_attr::N, h263_attr::P_SUB1, h263_attr::P_SUB2, h263_attr::P_SUB3, h263_attr::P_SUB4, h263_attr::PAR_HEIGHT, h263_attr::PAR_WIDTH, h263_attr::QCIF, h263_attr::SQCIF, str, h263_attr::T, and h263_attr::VGA.

◆ h263_getjoint()

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

Definition at line 119 of file res_format_attr_h263.c.

120{
121 struct ast_format *cloned;
122 struct h263_attr *attr, *attr1, *attr2;
123
124 cloned = ast_format_clone(format1);
125 if (!cloned) {
126 return NULL;
127 }
128 attr = ast_format_get_attribute_data(cloned);
129
130 attr1 = ast_format_get_attribute_data(format1);
131 attr2 = ast_format_get_attribute_data(format2);
132
133 DETERMINE_JOINT(attr, attr1, attr2, SQCIF);
134 DETERMINE_JOINT(attr, attr1, attr2, QCIF);
135 DETERMINE_JOINT(attr, attr1, attr2, CIF);
136 DETERMINE_JOINT(attr, attr1, attr2, CIF4);
137 DETERMINE_JOINT(attr, attr1, attr2, CIF16);
138 DETERMINE_JOINT(attr, attr1, attr2, VGA);
139 DETERMINE_JOINT(attr, attr1, attr2, CUSTOM_XMAX);
140 DETERMINE_JOINT(attr, attr1, attr2, CUSTOM_YMAX);
141 DETERMINE_JOINT(attr, attr1, attr2, CUSTOM_MPI);
142 DETERMINE_JOINT(attr, attr1, attr2, CPCF);
143 DETERMINE_JOINT(attr, attr1, attr2, CPCF_2);
144 DETERMINE_JOINT(attr, attr1, attr2, CPCF_3);
145 DETERMINE_JOINT(attr, attr1, attr2, CPCF_4);
146 DETERMINE_JOINT(attr, attr1, attr2, CPCF_5);
147 DETERMINE_JOINT(attr, attr1, attr2, CPCF_6);
148 DETERMINE_JOINT(attr, attr1, attr2, CPCF_7);
149 DETERMINE_JOINT(attr, attr1, attr2, CPCF_MPI);
150 DETERMINE_JOINT(attr, attr1, attr2, F);
151 DETERMINE_JOINT(attr, attr1, attr2, I);
152 DETERMINE_JOINT(attr, attr1, attr2, J);
153 DETERMINE_JOINT(attr, attr1, attr2, T);
154 DETERMINE_JOINT(attr, attr1, attr2, K);
155 DETERMINE_JOINT(attr, attr1, attr2, N);
156 DETERMINE_JOINT(attr, attr1, attr2, P_SUB1);
157 DETERMINE_JOINT(attr, attr1, attr2, P_SUB2);
158 DETERMINE_JOINT(attr, attr1, attr2, P_SUB3);
159 DETERMINE_JOINT(attr, attr1, attr2, P_SUB4);
160 DETERMINE_JOINT(attr, attr1, attr2, PAR_WIDTH);
161 DETERMINE_JOINT(attr, attr1, attr2, PAR_HEIGHT);
162 DETERMINE_JOINT(attr, attr1, attr2, BPP);
163 DETERMINE_JOINT(attr, attr1, attr2, HRD);
164 DETERMINE_JOINT(attr, attr1, attr2, MaxBR);
165
166 return cloned;
167}
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 DETERMINE_JOINT(joint, attr1, attr2, field)
#define NULL
Definition: resample.c:96
Definition of a media format.
Definition: format.c:43

References ast_format_clone(), ast_format_get_attribute_data(), h263_attr::BPP, h263_attr::CIF, h263_attr::CIF16, h263_attr::CIF4, h263_attr::CPCF, h263_attr::CPCF_2, h263_attr::CPCF_3, h263_attr::CPCF_4, h263_attr::CPCF_5, h263_attr::CPCF_6, h263_attr::CPCF_7, h263_attr::CPCF_MPI, h263_attr::CUSTOM_MPI, h263_attr::CUSTOM_XMAX, h263_attr::CUSTOM_YMAX, DETERMINE_JOINT, h263_attr::F, h263_attr::HRD, h263_attr::I, h263_attr::J, h263_attr::K, h263_attr::MaxBR, h263_attr::N, NULL, h263_attr::P_SUB1, h263_attr::P_SUB2, h263_attr::P_SUB3, h263_attr::P_SUB4, h263_attr::PAR_HEIGHT, h263_attr::PAR_WIDTH, h263_attr::QCIF, h263_attr::SQCIF, h263_attr::T, and h263_attr::VGA.

◆ h263_parse_sdp_fmtp()

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

Definition at line 169 of file res_format_attr_h263.c.

170{
171 char *attribs = ast_strdupa(attributes), *attrib;
172 struct ast_format *cloned;
173 struct h263_attr *attr;
174
175 cloned = ast_format_clone(format);
176 if (!cloned) {
177 return NULL;
178 }
179 attr = ast_format_get_attribute_data(cloned);
180
181 /* upper-case everything, so we are case-insensitive */
182 for (attrib = attribs; *attrib; ++attrib) {
183 *attrib = toupper(*attrib);
184 } /* based on channels/chan_sip.c:process_a_sdp_image() */
185
186 attr->BPP = H263_ATTR_KEY_UNSET;
190
191 while ((attrib = strsep(&attribs, ";"))) {
192 unsigned int val, val2 = 0, val3 = 0, val4 = 0, val5 = 0, val6 = 0, val7 = 0, val8 = 0;
193
194 attrib = ast_strip(attrib);
195
196 if (sscanf(attrib, "SQCIF=%30u", &val) == 1) {
197 attr->SQCIF = val;
198 } else if (strcmp(attrib, "SQCIF") == 0) {
199 attr->SQCIF = 1;
200 } else if (sscanf(attrib, "QCIF=%30u", &val) == 1) {
201 attr->QCIF = val;
202 } else if (strcmp(attrib, "QCIF") == 0) {
203 attr->QCIF = 1;
204 } else if (sscanf(attrib, "CIF=%30u", &val) == 1) {
205 attr->CIF = val;
206 } else if (strcmp(attrib, "CIF") == 0) {
207 attr->CIF = 1;
208 } else if (sscanf(attrib, "CIF4=%30u", &val) == 1) {
209 attr->CIF4 = val;
210 } else if (strcmp(attrib, "CIF4") == 0) {
211 attr->CIF4 = 1;
212 } else if (sscanf(attrib, "CIF16=%30u", &val) == 1) {
213 attr->CIF16 = val;
214 } else if (strcmp(attrib, "CIF16") == 0) {
215 attr->CIF16 = 1;
216 } else if (sscanf(attrib, "VGA=%30u", &val) == 1) {
217 attr->VGA = val;
218 } else if (strcmp(attrib, "VGA") == 0) {
219 attr->VGA = 1;
220 } else if (sscanf(attrib, "CUSTOM=%30u,%30u,%30u", &val, &val2, &val3) == 3) {
221 attr->CUSTOM_XMAX = val;
222 attr->CUSTOM_YMAX = val2;
223 attr->CUSTOM_MPI = val3;
224 } else if (sscanf(attrib, "CPCF=%30u,%30u,%30u,%30u,%30u,%30u,%30u,%30u",
225 &val, &val2, &val3, &val4, &val5, &val6, &val7, &val8) == 8) {
226 attr->CPCF = val;
227 attr->CPCF_2 = val2;
228 attr->CPCF_3 = val3;
229 attr->CPCF_4 = val4;
230 attr->CPCF_5 = val5;
231 attr->CPCF_6 = val6;
232 attr->CPCF_7 = val7;
233 attr->CPCF_MPI = val8;
234 } else if (sscanf(attrib, "F=%30u", &val) == 1) {
235 attr->F = val;
236 } else if (sscanf(attrib, "I=%30u", &val) == 1) {
237 attr->I = val;
238 } else if (sscanf(attrib, "J=%30u", &val) == 1) {
239 attr->J = val;
240 } else if (sscanf(attrib, "T=%30u", &val) == 1) {
241 attr->T = val;
242 } else if (sscanf(attrib, "K=%30u", &val) == 1) {
243 attr->K = val;
244 } else if (sscanf(attrib, "N=%30u", &val) == 1) {
245 attr->N = val;
246 } else if (sscanf(attrib, "PAR=%30u:%30u", &val, &val2) == 2) {
247 attr->PAR_WIDTH = val;
248 attr->PAR_HEIGHT = val2;
249 } else if (sscanf(attrib, "BPP=%30u", &val) == 1) {
250 attr->BPP = val;
251 } else if (sscanf(attrib, "HRD=%30u", &val) == 1) {
252 attr->HRD = val;
253 } else if (sscanf(attrib, "P=%30u,%30u,%30u,%30u", &val, &val2, &val3, &val4) > 0) {
254 attr->P_SUB1 = val;
255 attr->P_SUB2 = val2;
256 attr->P_SUB3 = val3;
257 attr->P_SUB4 = val4;
258 } else if (sscanf(attrib, "MAXBR=%30u", &val) == 1) {
259 attr->MaxBR = val;
260 }
261 }
262
263 return cloned;
264}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
char * strsep(char **str, const char *delims)
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
Definition: ast_expr2.c:325

References ast_format_clone(), ast_format_get_attribute_data(), ast_strdupa, ast_strip(), h263_attr::BPP, h263_attr::CIF, h263_attr::CIF16, h263_attr::CIF4, h263_attr::CPCF, h263_attr::CPCF_2, h263_attr::CPCF_3, h263_attr::CPCF_4, h263_attr::CPCF_5, h263_attr::CPCF_6, h263_attr::CPCF_7, h263_attr::CPCF_MPI, h263_attr::CUSTOM_MPI, h263_attr::CUSTOM_XMAX, h263_attr::CUSTOM_YMAX, h263_attr::F, H263_ATTR_KEY_UNSET, h263_attr::HRD, h263_attr::I, h263_attr::J, h263_attr::K, h263_attr::MaxBR, h263_attr::N, NULL, h263_attr::P_SUB1, h263_attr::P_SUB2, h263_attr::P_SUB3, h263_attr::P_SUB4, h263_attr::PAR_HEIGHT, h263_attr::PAR_WIDTH, h263_attr::QCIF, h263_attr::SQCIF, strsep(), h263_attr::T, and h263_attr::VGA.

◆ load_module()

static int load_module ( void  )
static

Definition at line 382 of file res_format_attr_h263.c.

383{
386 }
387
390 }
391
393}
#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 h263_interface

References ast_format_interface_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and h263_interface.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 377 of file res_format_attr_h263.c.

378{
379 return 0;
380}

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "H.263 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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static

Definition at line 399 of file res_format_attr_h263.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 399 of file res_format_attr_h263.c.

◆ h263_interface

struct ast_format_interface h263_interface
static

Definition at line 368 of file res_format_attr_h263.c.

Referenced by load_module().