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

H.263 Format Attribute Module. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/format.h"

Go to the source code of this file.

Data Structures

struct  h263_attr
 

Macros

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

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

◆ 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 101 of file res_format_attr_h263.c.

Referenced by h263_getjoint().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 276 of file res_format_attr_h263.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 276 of file res_format_attr_h263.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 276 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 72 of file res_format_attr_h263.c.

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

73 {
74  struct h263_attr *original = ast_format_get_attribute_data(src);
75  struct h263_attr *attr = ast_calloc(1, sizeof(*attr));
76 
77  if (!attr) {
78  return -1;
79  }
80 
81  if (original) {
82  *attr = *original;
83  }
84 
86 
87  return 0;
88 }
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

◆ h263_cmp()

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

Definition at line 90 of file res_format_attr_h263.c.

References AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, and ast_format_get_attribute_data().

91 {
92  struct h263_attr *attr1 = ast_format_get_attribute_data(format1);
93  struct h263_attr *attr2 = ast_format_get_attribute_data(format2);
94 
95  if (!attr1 || !attr2 || (attr1 && attr2 && !memcmp(attr1, attr2, sizeof(*attr1)))) {
96  return AST_FORMAT_CMP_EQUAL;
97  }
99 }
void * ast_format_get_attribute_data(const struct ast_format *format)
Get the attribute data on a format.
Definition: format.c:125

◆ h263_destroy()

static void h263_destroy ( struct ast_format format)
static

Definition at line 65 of file res_format_attr_h263.c.

References ast_format_get_attribute_data(), and ast_free.

66 {
67  struct h263_attr *attr = ast_format_get_attribute_data(format);
68 
69  ast_free(attr);
70 }
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

◆ 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 207 of file res_format_attr_h263.c.

References ast_format_get_attribute_data(), ast_str_append(), h263_attr::BPP, h263_attr::CIF, h263_attr::CIF16, h263_attr::CIF4, h263_attr::CUSTOM_MPI, h263_attr::CUSTOM_XMAX, h263_attr::CUSTOM_YMAX, h263_attr::F, h263_attr::HRD, h263_attr::I, h263_attr::J, h263_attr::K, 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, h263_attr::T, and h263_attr::VGA.

208 {
209  struct h263_attr *attr = ast_format_get_attribute_data(format);
210 
211  if (!attr) {
212  return;
213  }
214 
215  ast_str_append(str, 0, "a=fmtp:%u SQCIF=%u;QCIF=%u;CIF=%u;CIF4=%u;CIF16=%u;VGA=%u;F=%u;I=%u;J=%u;T=%u;K=%u;N=%u;BPP=%u;HRD=%u",
216  payload, attr->SQCIF, attr->QCIF, attr->CIF, attr->CIF4, attr->CIF16, attr->VGA, attr->F, attr->I, attr->J,
217  attr->T, attr->K, attr->N, attr->BPP, attr->HRD);
218 
219  if (attr->CUSTOM_XMAX && attr->CUSTOM_YMAX && attr->CUSTOM_MPI) {
220  ast_str_append(str, 0, ";CUSTOM=%u,%u,%u", attr->CUSTOM_XMAX, attr->CUSTOM_YMAX, attr->CUSTOM_MPI);
221  }
222 
223  if (attr->PAR_WIDTH && attr->PAR_HEIGHT) {
224  ast_str_append(str, 0, ";PAR=%u:%u", attr->PAR_WIDTH, attr->PAR_HEIGHT);
225  }
226 
227  if (attr->P_SUB1) {
228  ast_str_append(str, 0, ";P=%u", attr->P_SUB1);
229  if (attr->P_SUB2) {
230  ast_str_append(str, 0, ",%u", attr->P_SUB2);
231  }
232  if (attr->P_SUB3) {
233  ast_str_append(str, 0, ",%u", attr->P_SUB3);
234  }
235  if (attr->P_SUB4) {
236  ast_str_append(str, 0, ",%u", attr->P_SUB4);
237  }
238  }
239 
240  ast_str_append(str, 0, "\r\n");
241 
242  return;
243 }
unsigned int N
unsigned int HRD
unsigned int CIF4
unsigned int VGA
unsigned int CIF16
unsigned int CUSTOM_MPI
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 P_SUB2
unsigned int P_SUB4
unsigned int BPP
unsigned int P_SUB1
unsigned int T
unsigned int I
unsigned int PAR_HEIGHT
unsigned int SQCIF
unsigned int PAR_WIDTH
unsigned int K
unsigned int P_SUB3
unsigned int CUSTOM_YMAX
unsigned int CUSTOM_XMAX
unsigned int QCIF
unsigned int CIF
unsigned int F
unsigned int J

◆ h263_getjoint()

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

Definition at line 103 of file res_format_attr_h263.c.

References ast_format_clone(), ast_format_get_attribute_data(), h263_attr::BPP, h263_attr::CIF, h263_attr::CIF16, h263_attr::CIF4, 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::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.

104 {
105  struct ast_format *cloned;
106  struct h263_attr *attr, *attr1, *attr2;
107 
108  cloned = ast_format_clone(format1);
109  if (!cloned) {
110  return NULL;
111  }
112  attr = ast_format_get_attribute_data(cloned);
113 
114  attr1 = ast_format_get_attribute_data(format1);
115  attr2 = ast_format_get_attribute_data(format2);
116 
117  DETERMINE_JOINT(attr, attr1, attr2, SQCIF);
118  DETERMINE_JOINT(attr, attr1, attr2, QCIF);
119  DETERMINE_JOINT(attr, attr1, attr2, CIF);
120  DETERMINE_JOINT(attr, attr1, attr2, CIF4);
121  DETERMINE_JOINT(attr, attr1, attr2, CIF16);
122  DETERMINE_JOINT(attr, attr1, attr2, VGA);
123  DETERMINE_JOINT(attr, attr1, attr2, CUSTOM_XMAX);
124  DETERMINE_JOINT(attr, attr1, attr2, CUSTOM_YMAX);
125  DETERMINE_JOINT(attr, attr1, attr2, CUSTOM_MPI);
126  DETERMINE_JOINT(attr, attr1, attr2, F);
127  DETERMINE_JOINT(attr, attr1, attr2, I);
128  DETERMINE_JOINT(attr, attr1, attr2, J);
129  DETERMINE_JOINT(attr, attr1, attr2, T);
130  DETERMINE_JOINT(attr, attr1, attr2, K);
131  DETERMINE_JOINT(attr, attr1, attr2, N);
132  DETERMINE_JOINT(attr, attr1, attr2, P_SUB1);
133  DETERMINE_JOINT(attr, attr1, attr2, P_SUB2);
134  DETERMINE_JOINT(attr, attr1, attr2, P_SUB3);
135  DETERMINE_JOINT(attr, attr1, attr2, P_SUB4);
136  DETERMINE_JOINT(attr, attr1, attr2, PAR_WIDTH);
137  DETERMINE_JOINT(attr, attr1, attr2, PAR_HEIGHT);
138  DETERMINE_JOINT(attr, attr1, attr2, BPP);
139  DETERMINE_JOINT(attr, attr1, attr2, HRD);
140 
141  return cloned;
142 }
unsigned int N
unsigned int HRD
unsigned int CIF4
unsigned int VGA
unsigned int CIF16
unsigned int CUSTOM_MPI
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 P_SUB2
#define NULL
Definition: resample.c:96
unsigned int P_SUB4
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 BPP
unsigned int P_SUB1
unsigned int T
unsigned int I
unsigned int PAR_HEIGHT
unsigned int SQCIF
unsigned int PAR_WIDTH
unsigned int K
unsigned int P_SUB3
unsigned int CUSTOM_YMAX
unsigned int CUSTOM_XMAX
unsigned int QCIF
#define DETERMINE_JOINT(joint, attr1, attr2, field)
unsigned int CIF
unsigned int F
unsigned int J

◆ h263_parse_sdp_fmtp()

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

Definition at line 144 of file res_format_attr_h263.c.

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::CUSTOM_MPI, h263_attr::CUSTOM_XMAX, h263_attr::CUSTOM_YMAX, h263_attr::F, h263_attr::HRD, h263_attr::I, h263_attr::J, h263_attr::K, 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.

145 {
146  char *attribs = ast_strdupa(attributes), *attrib;
147  struct ast_format *cloned;
148  struct h263_attr *attr;
149 
150  cloned = ast_format_clone(format);
151  if (!cloned) {
152  return NULL;
153  }
154  attr = ast_format_get_attribute_data(cloned);
155 
156  while ((attrib = strsep(&attribs, ";"))) {
157  unsigned int val, val2 = 0, val3 = 0, val4 = 0;
158 
159  attrib = ast_strip(attrib);
160 
161  if (sscanf(attrib, "SQCIF=%30u", &val) == 1) {
162  attr->SQCIF = val;
163  } else if (sscanf(attrib, "QCIF=%30u", &val) == 1) {
164  attr->QCIF = val;
165  } else if (sscanf(attrib, "CIF=%30u", &val) == 1) {
166  attr->CIF = val;
167  } else if (sscanf(attrib, "CIF4=%30u", &val) == 1) {
168  attr->CIF4 = val;
169  } else if (sscanf(attrib, "CIF16=%30u", &val) == 1) {
170  attr->CIF16 = val;
171  } else if (sscanf(attrib, "VGA=%30u", &val) == 1) {
172  attr->VGA = val;
173  } else if (sscanf(attrib, "CUSTOM=%30u,%30u,%30u", &val, &val2, &val3) == 3) {
174  attr->CUSTOM_XMAX = val;
175  attr->CUSTOM_YMAX = val2;
176  attr->CUSTOM_MPI = val3;
177  } else if (sscanf(attrib, "F=%30u", &val) == 1) {
178  attr->F = val;
179  } else if (sscanf(attrib, "I=%30u", &val) == 1) {
180  attr->I = val;
181  } else if (sscanf(attrib, "J=%30u", &val) == 1) {
182  attr->J = val;
183  } else if (sscanf(attrib, "T=%30u", &val) == 1) {
184  attr->T = val;
185  } else if (sscanf(attrib, "K=%30u", &val) == 1) {
186  attr->K = val;
187  } else if (sscanf(attrib, "N=%30u", &val) == 1) {
188  attr->N = val;
189  } else if (sscanf(attrib, "PAR=%30u:%30u", &val, &val2) == 2) {
190  attr->PAR_WIDTH = val;
191  attr->PAR_HEIGHT = val2;
192  } else if (sscanf(attrib, "BPP=%30u", &val) == 1) {
193  attr->BPP = val;
194  } else if (sscanf(attrib, "HRD=%30u", &val) == 1) {
195  attr->HRD = val;
196  } else if (sscanf(attrib, "P=%30u,%30u,%30u,%30u", &val, &val2, &val3, &val4) > 0) {
197  attr->P_SUB1 = val;
198  attr->P_SUB2 = val2;
199  attr->P_SUB3 = val3;
200  attr->P_SUB4 = val4;
201  }
202  }
203 
204  return cloned;
205 }
unsigned int N
unsigned int HRD
unsigned int CIF4
unsigned int VGA
Definition: ast_expr2.c:325
unsigned int CIF16
unsigned int CUSTOM_MPI
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 P_SUB2
#define NULL
Definition: resample.c:96
unsigned int P_SUB4
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
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
unsigned int BPP
unsigned int P_SUB1
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
unsigned int T
unsigned int I
unsigned int PAR_HEIGHT
unsigned int SQCIF
unsigned int PAR_WIDTH
unsigned int K
unsigned int P_SUB3
unsigned int CUSTOM_YMAX
char * strsep(char **str, const char *delims)
unsigned int CUSTOM_XMAX
unsigned int QCIF
unsigned int CIF
unsigned int F
unsigned int J

◆ load_module()

static int load_module ( void  )
static

Definition at line 259 of file res_format_attr_h263.c.

References ast_format_interface_register, AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, and unload_module().

260 {
263  }
264 
267  }
268 
270 }
#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 h263_interface

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 254 of file res_format_attr_h263.c.

Referenced by load_module().

255 {
256  return 0;
257 }

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 276 of file res_format_attr_h263.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 276 of file res_format_attr_h263.c.

◆ h263_interface

struct ast_format_interface h263_interface
static

Definition at line 245 of file res_format_attr_h263.c.