[asterisk-commits] file: branch group/media_formats r408870 - in /team/group/media_formats: incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 24 07:31:38 CST 2014


Author: file
Date: Mon Feb 24 07:31:31 2014
New Revision: 408870

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408870
Log:
Add a self-contained bitfield compatibility API.

Added:
    team/group/media_formats/include/asterisk/format_compatibility.h   (with props)
    team/group/media_formats/main/format_compatibility.c   (with props)

Added: team/group/media_formats/include/asterisk/format_compatibility.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_compatibility.h?view=auto&rev=408870
==============================================================================
--- team/group/media_formats/include/asterisk/format_compatibility.h (added)
+++ team/group/media_formats/include/asterisk/format_compatibility.h Mon Feb 24 07:31:31 2014
@@ -1,0 +1,77 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Media Format Bitfield Compatibility API
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+#ifndef _AST_FORMAT_COMPATIBILITY_H_
+#define _AST_FORMAT_COMPATIBILITY_H_
+
+struct ast_format;
+struct ast_format_cap;
+
+/*!
+ * \brief Convert a format structure to its respective bitfield
+ *
+ * \param format The media format
+ *
+ * \retval non-zero success
+ * \retval zero format not supported
+ */
+uint64_t ast_format_compatibility_format2bitfield(const struct ast_format *format);
+
+/*!
+ * \brief Convert a bitfield to its respective format structure
+ *
+ * \param bitfield The bitfield for the media format
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * \note The reference count of the returned format is NOT incremented
+ */
+struct ast_format *ast_format_compatibility_bitfield2format(uint64_t bitfield);
+
+/*!
+ * \brief Convert a format capabilities structure to a bitfield
+ *
+ * \param cap Capabilities structure containing formats
+ *
+ * \retval non-zero success
+ * \retval zero no formats present or no formats supported
+ */
+uint64_t ast_format_compatibility_cap2bitfield(const struct ast_format_cap *cap);
+
+/*!
+ * \brief Convert a bitfield to a format capabilities structure
+ *
+ * \param bitfield The bitfield for the media formats
+ * \param cap Capabilities structure to place formats into
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * \note If failure occurs the capabilities structure may contain a partial set of formats
+ */
+int ast_format_compatibility_bitfield2cap(uint64_t bitfield, struct ast_format_cap *cap);
+
+#endif /* _AST_FORMAT_COMPATIBILITY_H */

Propchange: team/group/media_formats/include/asterisk/format_compatibility.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/media_formats/include/asterisk/format_compatibility.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/media_formats/include/asterisk/format_compatibility.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/group/media_formats/main/format_compatibility.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/format_compatibility.c?view=auto&rev=408870
==============================================================================
--- team/group/media_formats/main/format_compatibility.c (added)
+++ team/group/media_formats/main/format_compatibility.c Mon Feb 24 07:31:31 2014
@@ -1,0 +1,235 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Media Format Bitfield Compatibility API
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/logger.h"
+#include "asterisk/codec.h"
+#include "asterisk/format_ng.h"
+#include "asterisk/format_cache.h"
+
+uint64_t ast_format_compatibility_format2bitfield(const struct ast_format *format)
+{
+	if (ast_format_cmp(format, ast_format_g723) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 0);
+	} else if (ast_format_cmp(format, ast_format_gsm) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 1);
+	} else if (ast_format_cmp(format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 2);
+	} else if (ast_format_cmp(format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 3);
+	} else if (ast_format_cmp(format, ast_format_g726_aal2) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 4);
+	} else if (ast_format_cmp(format, ast_format_g726_adpcm) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 5);
+	} else if (ast_format_cmp(format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 6);
+	} else if (ast_format_cmp(format, ast_format_lpc10) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 7);
+	} else if (ast_format_cmp(format, ast_format_g729) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 8);
+	} else if (ast_format_cmp(format, ast_format_speex) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 9);
+	} else if (ast_format_cmp(format, ast_format_ilbc) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 10);
+	} else if (ast_format_cmp(format, ast_format_g726) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 11);
+	} else if (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 12);
+	} else if (ast_format_cmp(format, ast_format_siren7) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 13);
+	} else if (ast_format_cmp(format, ast_format_siren14) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 14);
+	} else if (ast_format_cmp(format, ast_format_slin16) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 15);
+	} else if (ast_format_cmp(format, ast_format_g719) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 32);
+	} else if (ast_format_cmp(format, ast_format_speex16) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 33);
+	} else if (ast_format_cmp(format, ast_format_opus) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 34);
+	} else if (ast_format_cmp(format, ast_format_testlaw) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 47);
+	} else if (ast_format_cmp(format, ast_format_h261) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 18);
+	} else if (ast_format_cmp(format, ast_format_h263) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 19);
+	} else if (ast_format_cmp(format, ast_format_h263p) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 20);
+	} else if (ast_format_cmp(format, ast_format_h264) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 21);
+	} else if (ast_format_cmp(format, ast_format_mp4) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 22);
+	} else if (ast_format_cmp(format, ast_format_vp8) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 23);
+	} else if (ast_format_cmp(format, ast_format_jpeg) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 16);
+	} else if (ast_format_cmp(format, ast_format_png) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 17);
+	} else if (ast_format_cmp(format, ast_format_t140_red) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 26);
+	} else if (ast_format_cmp(format, ast_format_t140) == AST_FORMAT_CMP_EQUAL) {
+		return (1ULL << 27);
+	}
+
+	return 0;
+}
+
+struct ast_format *ast_format_compatibility_bitfield2format(uint64_t bitfield)
+{
+	switch (src) {
+	/*! G.723.1 compression */
+	case (1ULL << 0):
+		return ast_format_g723;
+	/*! GSM compression */
+	case (1ULL << 1):
+		return ast_format_gsm;
+	/*! Raw mu-law data (G.711) */
+	case (1ULL << 2):
+		return ast_format_ulaw;
+	/*! Raw A-law data (G.711) */
+	case (1ULL << 3):
+		return ast_format_alaw;
+	/*! ADPCM (G.726, 32kbps, AAL2 codeword packing) */
+	case (1ULL << 4):
+		return ast_format_g726_aal2;
+	/*! ADPCM (IMA) */
+	case (1ULL << 5):
+		return ast_format_adpcm;
+	/*! Raw 16-bit Signed Linear (8000 Hz) PCM */
+	case (1ULL << 6):
+		return ast_format_slin;
+	/*! LPC10, 180 samples/frame */
+	case (1ULL << 7):
+		return ast_format_lpc10;
+	/*! G.729A audio */
+	case (1ULL << 8):
+		return ast_format_g729;
+	/*! SpeeX Free Compression */
+	case (1ULL << 9):
+		return ast_format_speex;
+	/*! iLBC Free Compression */
+	case (1ULL << 10):
+		return ast_format_ilbc;
+	/*! ADPCM (G.726, 32kbps, RFC3551 codeword packing) */
+	case (1ULL << 11):
+		return ast_format_g726;
+	/*! G.722 */
+	case (1ULL << 12):
+		return ast_format_g722;
+	/*! G.722.1 (also known as Siren7, 32kbps assumed) */
+	case (1ULL << 13):
+		return ast_format_siren7;
+	/*! G.722.1 Annex C (also known as Siren14, 48kbps assumed) */
+	case (1ULL << 14):
+		return ast_format_siren14;
+	/*! Raw 16-bit Signed Linear (16000 Hz) PCM */
+	case (1ULL << 15):
+		return ast_format_slin16;
+	/*! G.719 (64 kbps assumed) */
+	case (1ULL << 32):
+		return ast_format_g719;
+	/*! SpeeX Wideband (16kHz) Free Compression */
+	case (1ULL << 33):
+		return ast_format_speex16;
+	/*! Opus audio (8kHz, 16kHz, 24kHz, 48Khz) */
+	case (1ULL << 34):
+		return ast_format_opus;
+	/*! Raw mu-law data (G.711) */
+	case (1ULL << 47):
+		return ast_format_testlaw;
+
+	/*! H.261 Video */
+	case (1ULL << 18):
+		return ast_format_h261;
+	/*! H.263 Video */
+	case (1ULL << 19):
+		return ast_format_h263;
+	/*! H.263+ Video */
+	case (1ULL << 20):
+		return ast_format_h263p;
+	/*! H.264 Video */
+	case (1ULL << 21):
+		return ast_format_h264;
+	/*! MPEG4 Video */
+	case (1ULL << 22):
+		return ast_format_mp4;
+	/*! VP8 Video */
+	case (1ULL << 23):
+		return ast_format_vp8;
+
+	/*! JPEG Images */
+	case (1ULL << 16):
+		return ast_format_jpeg;
+	/*! PNG Images */
+	case (1ULL << 17):
+		return ast_format_png;
+
+	/*! T.140 RED Text format RFC 4103 */
+	case (1ULL << 26):
+		return ast_format_t140;
+	/*! T.140 Text format - ITU T.140, RFC 4103 */
+	case (1ULL << 27):
+		return ast_format_t140_red;
+	}
+	return 0;
+}
+
+uint64_t ast_format_compatibility_cap2bitfield(const struct ast_format_cap *cap)
+{
+	uint64_t bitfield = 0;
+	int x;
+
+	for (x = 0; x < ast_format_cap_count(cap); x++) {
+		struct ast_format *format = ast_format_cap_get_format(cap, x);
+
+		bitfield |= ast_format_compatibility_format2bitfield(format);
+
+		ao2_ref(format, -1);
+	}
+
+	return bitfield;
+}
+
+int ast_format_compatibility_bitfield2cap(uint64_t bitfield, struct ast_format_cap *cap)
+{
+	int x;
+
+	for (x = 0; x < 64; x++) {
+		uint64_t tmp = (1ULL << x);
+
+		if ((tmp & bitfield) && ast_format_cap_add(cap, ast_format_compatibility_bitfield2format(tmp), 0)) {
+			return -1;
+		}
+	}
+
+	return 0;
+}

Propchange: team/group/media_formats/main/format_compatibility.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/media_formats/main/format_compatibility.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/media_formats/main/format_compatibility.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list