[asterisk-commits] file: branch file/mf-attributes r417741 - /team/file/mf-attributes/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 1 20:20:26 CDT 2014
Author: file
Date: Tue Jul 1 20:20:23 2014
New Revision: 417741
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=417741
Log:
Stash progress on moving res_format_attr_h264 over.
Modified:
team/file/mf-attributes/res/res_format_attr_h264.c
Modified: team/file/mf-attributes/res/res_format_attr_h264.c
URL: http://svnview.digium.com/svn/asterisk/team/file/mf-attributes/res/res_format_attr_h264.c?view=diff&rev=417741&r1=417740&r2=417741
==============================================================================
--- team/file/mf-attributes/res/res_format_attr_h264.c (original)
+++ team/file/mf-attributes/res/res_format_attr_h264.c Tue Jul 1 20:20:23 2014
@@ -50,132 +50,139 @@
* H264_MAX_SPS_PPS_SIZE */
#define H264_MAX_SPS_PPS_SIZE_SCAN_LIMIT "15"
-enum h264_attr_keys {
- H264_ATTR_KEY_PROFILE_IDC,
- H264_ATTR_KEY_PROFILE_IOP,
- H264_ATTR_KEY_LEVEL,
- H264_ATTR_KEY_MAX_MBPS,
- H264_ATTR_KEY_MAX_FS,
- H264_ATTR_KEY_MAX_CPB,
- H264_ATTR_KEY_MAX_DPB,
- H264_ATTR_KEY_MAX_BR,
- H264_ATTR_KEY_MAX_SMBPS,
- H264_ATTR_KEY_MAX_FPS,
- H264_ATTR_KEY_REDUNDANT_PIC_CAP,
- H264_ATTR_KEY_PARAMETER_ADD,
- H264_ATTR_KEY_PACKETIZATION_MODE,
- H264_ATTR_KEY_SPROP_INTERLEAVING_DEPTH,
- H264_ATTR_KEY_SPROP_DEINT_BUF_REQ,
- H264_ATTR_KEY_DEINT_BUF_CAP,
- H264_ATTR_KEY_SPROP_INIT_BUF_TIME,
- H264_ATTR_KEY_SPROP_MAX_DON_DIFF,
- H264_ATTR_KEY_MAX_RCMD_NALU_SIZE,
- H264_ATTR_KEY_LEVEL_ASYMMETRY_ALLOWED,
- H264_ATTR_KEY_SPS_LEN,
- H264_ATTR_KEY_PPS_LEN,
- H264_ATTR_KEY_SPS,
- H264_ATTR_KEY_PPS = H264_ATTR_KEY_SPS + H264_MAX_SPS_PPS_SIZE,
- H264_ATTR_KEY_END = H264_ATTR_KEY_PPS + H264_MAX_SPS_PPS_SIZE,
+struct h264_attr {
+ unsigned int PROFILE_IDC;
+ unsigned int PROFILE_IOP;
+ unsigned int LEVEL;
+ unsigned int MAX_MBPS;
+ unsigned int MAX_FS;
+ unsigned int MAX_CPB;
+ unsigned int MAX_DPB;
+ unsigned int MAX_BR;
+ unsigned int MAX_SMBPS;
+ unsigned int MAX_FPS;
+ unsigned int REDUNDANT_PIC_CAP;
+ unsigned int PARAMETER_ADD;
+ unsigned int PACKETIZATION_MODE;
+ unsigned int SPROP_INTERLEAVING_DEPTH;
+ unsigned int SPROP_DEINT_BUF_REQ;
+ unsigned int DEINT_BUF_CAP;
+ unsigned int SPROP_INIT_BUF_TIME;
+ unsigned int SPROP_MAX_DON_DIFF;
+ unsigned int MAX_RCMD_NALU_SIZE;
+ unsigned int LEVEL_ASYMMETRY_ALLOWED;
+ char SPS[H264_MAX_SPS_PPS_SIZE];
+ char PPS[H264_MAX_SPS_PPS_SIZE];
};
-static enum ast_format_cmp_res h264_format_attr_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
-{
- if (!fattr1->format_attr[H264_ATTR_KEY_PROFILE_IDC] || !fattr2->format_attr[H264_ATTR_KEY_PROFILE_IDC] ||
- (fattr1->format_attr[H264_ATTR_KEY_PROFILE_IDC] == fattr2->format_attr[H264_ATTR_KEY_PROFILE_IDC])) {
+static void h264_destroy(struct ast_format *format)
+{
+ struct h264_attr *attr = ast_format_get_attribute_data(format);
+
+ ast_free(attr);
+}
+
+static int h264_clone(const struct ast_format *src, struct ast_format *dst)
+{
+ struct h264_attr *original = ast_format_get_attribute_data(src);
+ struct h264_attr *attr = ast_calloc(1, sizeof(*attr));
+
+ if (!attr) {
+ return -1;
+ }
+
+ if (original) {
+ *attr = *original;
+ }
+
+ ast_format_set_attribute_data(dst, attr);
+
+ return 0;
+}
+
+static enum ast_format_cmp_res h264_cmp(const struct ast_format *format1, const struct ast_format *format2)
+{
+ struct h264_attr *attr1 = ast_format_get_attribute_data(format1);
+ struct h264_attr *attr2 = ast_format_get_attribute_data(format2);
+
+ if (!attr1 || !attr1->PROFILE_IDC || !attr2 || !attr2->PROFILE_IDC ||
+ (attr1->PROFILE_IDC == attr2->PROFILE_IDC)) {
return AST_FORMAT_CMP_EQUAL;
}
return AST_FORMAT_CMP_NOT_EQUAL;
}
-static int h264_format_attr_get_joint(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result)
-{
- int i;
-
- for (i = H264_ATTR_KEY_PROFILE_IDC; i < H264_ATTR_KEY_END; i++) {
- result->format_attr[i] = fattr1->format_attr[i] ? fattr1->format_attr[i] : fattr2->format_attr[i];
- }
-
- return 0;
-}
-
-static int h264_format_attr_sdp_parse(struct ast_format_attr *format_attr, const char *attributes)
+static struct ast_format *h264_getjoint(const struct ast_format *format1, const struct ast_format *format2)
+{
+ return ast_format_clone(format1);
+}
+
+static struct ast_format *h264_sdp_parse(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
-
- format_attr->format_attr[H264_ATTR_KEY_REDUNDANT_PIC_CAP] = H264_ATTR_KEY_UNSET;
- format_attr->format_attr[H264_ATTR_KEY_PARAMETER_ADD] = H264_ATTR_KEY_UNSET;
- format_attr->format_attr[H264_ATTR_KEY_PACKETIZATION_MODE] = H264_ATTR_KEY_UNSET;
- format_attr->format_attr[H264_ATTR_KEY_LEVEL_ASYMMETRY_ALLOWED] = H264_ATTR_KEY_UNSET;
+ struct ast_format *cloned;
+ struct h264_attr *attr;
+
+ cloned = ast_format_clone(format);
+ if (!cloned) {
+ return NULL;
+ }
+ attr = ast_format_get_attribute_data(cloned);
+
+ attr->REDUNDANT_PIC_CAP = H264_ATTR_KEY_UNSET;
+ attr->PARAMETER_ADD = H264_ATTR_KEY_UNSET;
+ attr->PACKETIZATION_MODE = H264_ATTR_KEY_UNSET;
+ attr->LEVEL_ASYMMETRY_ALLOWED = H264_ATTR_KEY_UNSET;
while ((attrib = strsep(&attribs, ";"))) {
unsigned int val;
unsigned long int val2;
- char sps[H264_MAX_SPS_PPS_SIZE], pps[H264_MAX_SPS_PPS_SIZE];
if (sscanf(attrib, "profile-level-id=%lx", &val2) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_PROFILE_IDC] = ((val2 >> 16) & 0xFF);
- format_attr->format_attr[H264_ATTR_KEY_PROFILE_IOP] = ((val2 >> 8) & 0xFF);
- format_attr->format_attr[H264_ATTR_KEY_LEVEL] = (val2 & 0xFF);
- } else if (sscanf(attrib, "sprop-parameter-sets=%" H264_MAX_SPS_PPS_SIZE_SCAN_LIMIT "[^','],%" H264_MAX_SPS_PPS_SIZE_SCAN_LIMIT "s", sps, pps) == 2) {
+ attr->PROFILE_IDC = ((val2 >> 16) & 0xFF);
+ attr->PROFILE_IOP = ((val2 >> 8) & 0xFF);
+ attr->LEVEL = (val2 & 0xFF);
+ } else if (sscanf(attrib, "sprop-parameter-sets=%" H264_MAX_SPS_PPS_SIZE_SCAN_LIMIT "[^','],%" H264_MAX_SPS_PPS_SIZE_SCAN_LIMIT "s", attr->SPS, attr->PPS) == 2) {
/* XXX sprop-parameter-sets can actually be of unlimited length. This may need to be addressed later. */
- unsigned char spsdecoded[H264_MAX_SPS_PPS_SIZE] = { 0, }, ppsdecoded[H264_MAX_SPS_PPS_SIZE] = { 0, };
- int i;
-
- ast_base64decode(spsdecoded, sps, sizeof(spsdecoded));
- ast_base64decode(ppsdecoded, pps, sizeof(ppsdecoded));
-
- format_attr->format_attr[H264_ATTR_KEY_SPS_LEN] = 0;
- format_attr->format_attr[H264_ATTR_KEY_PPS_LEN] = 0;
-
- for (i = 0; i < H264_MAX_SPS_PPS_SIZE; i++) {
- if (spsdecoded[i]) {
- format_attr->format_attr[H264_ATTR_KEY_SPS + i] = spsdecoded[i];
- format_attr->format_attr[H264_ATTR_KEY_SPS_LEN]++;
- }
- if (ppsdecoded[i]) {
- format_attr->format_attr[H264_ATTR_KEY_PPS + i] = ppsdecoded[i];
- format_attr->format_attr[H264_ATTR_KEY_PPS_LEN]++;
- }
- }
} else if (sscanf(attrib, "max-mbps=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_MBPS] = val;
+ attr->MAX_MBPS = val;
} else if (sscanf(attrib, "max-fs=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_FS] = val;
+ attr->MAX_FS = val;
} else if (sscanf(attrib, "max-cpb=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_CPB] = val;
+ attr->MAX_CPB = val;
} else if (sscanf(attrib, "max-dpb=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_DPB] = val;
+ attr->MAX_DPB = val;
} else if (sscanf(attrib, "max-br=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_BR] = val;
+ attr->MAX_BR = val;
} else if (sscanf(attrib, "max-smbps=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_SMBPS] = val;
+ attr->MAX_SMBPS = val;
} else if (sscanf(attrib, "max-fps=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_FPS] = val;
+ attr->MAX_FPS = val;
} else if (sscanf(attrib, "redundant-pic-cap=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_REDUNDANT_PIC_CAP] = val;
+ attr->REDUNDANT_PIC_CAP = val;
} else if (sscanf(attrib, "parameter-add=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_PARAMETER_ADD] = val;
+ attr->PARAMETER_ADD = val;
} else if (sscanf(attrib, "packetization-mode=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_PACKETIZATION_MODE] = val;
+ attr->PACKETIZATION_MODE = val;
} else if (sscanf(attrib, "sprop-interleaving-depth=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_SPROP_INTERLEAVING_DEPTH] = val;
+ attr->SPROP_INTERLEAVING_DEPTH = val;
} else if (sscanf(attrib, "sprop-deint-buf-req=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_SPROP_DEINT_BUF_REQ] = val;
+ attr->SPROP_DEINT_BUF_REQ = val;
} else if (sscanf(attrib, "deint-buf-cap=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_DEINT_BUF_CAP] = val;
+ attr->DEINT_BUF_CAP = val;
} else if (sscanf(attrib, "sprop-init-buf-time=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_SPROP_INIT_BUF_TIME] = val;
+ attr->SPROP_INIT_BUF_TIME = val;
} else if (sscanf(attrib, "sprop-max-don-diff=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_SPROP_MAX_DON_DIFF] = val;
+ attr->SPROP_MAX_DON_DIFF = val;
} else if (sscanf(attrib, "max-rcmd-nalu-size=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_MAX_RCMD_NALU_SIZE] = val;
+ attr->MAX_RCMD_NALU_SIZE = val;
} else if (sscanf(attrib, "level-asymmetry-allowed=%30u", &val) == 1) {
- format_attr->format_attr[H264_ATTR_KEY_LEVEL_ASYMMETRY_ALLOWED] = val;
+ attr->LEVEL_ASYMMETRY_ALLOWED = val;
}
}
- return 0;
+ return cloned;
}
/*! \brief Helper function which converts a key enum into a string value for SDP */
@@ -292,24 +299,23 @@
return;
}
-static struct ast_format_attr_interface h264_format_attr_interface = {
- .id = AST_FORMAT_H264,
- .format_attr_cmp = h264_format_attr_cmp,
- .format_attr_get_joint = h264_format_attr_get_joint,
- .format_attr_sdp_parse = h264_format_attr_sdp_parse,
- .format_attr_sdp_generate = h264_format_attr_sdp_generate,
+static struct ast_format_interface h264_interface = {
+ .format_destroy = h264_destroy,
+ .format_clone = h264_clone,
+ .format_cmp = h264_cmp,
+ .format_get_joint = h264_getjoint,
+ .format_sdp_parse = h264_sdp_parse,
+ .format_sdp_generate = h264_sdp_generate,
};
static int unload_module(void)
{
- ast_format_attr_unreg_interface(&h264_format_attr_interface);
-
return 0;
}
static int load_module(void)
{
- if (ast_format_attr_reg_interface(&h264_format_attr_interface)) {
+ if (ast_format_interface_register("h264", &h264_interface)) {
return AST_MODULE_LOAD_DECLINE;
}
More information about the asterisk-commits
mailing list