[asterisk-commits] eliel: branch eliel/data_api_providers_gsoc2010 r276266 - in /team/eliel/data...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 13 20:38:15 CDT 2010


Author: eliel
Date: Tue Jul 13 20:38:02 2010
New Revision: 276266

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=276266
Log:
Implement the AstData codecs provider.


Modified:
    team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c
    team/eliel/data_api_providers_gsoc2010/channels/chan_local.c
    team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c
    team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h
    team/eliel/data_api_providers_gsoc2010/main/channel.c
    team/eliel/data_api_providers_gsoc2010/main/data.c
    team/eliel/data_api_providers_gsoc2010/main/frame.c

Modified: team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c?view=diff&rev=276266&r1=276265&r2=276266
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c (original)
+++ team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c Tue Jul 13 20:38:02 2010
@@ -14260,7 +14260,7 @@
 
 		ast_data_add_structure(iax2_peer, data_peer, peer);
 
-		ast_data_add_codecs(data_peer, "codecs", peer->capability);
+		ast_data_add_codecs(data_peer, "codecs", peer->capability, 0);
 
 		peer_status(peer, status, sizeof(status));
 		ast_data_add_str(data_peer, "status", status);
@@ -14324,7 +14324,7 @@
 
 		ast_data_add_structure(iax2_user, data_user, user);
 
-		ast_data_add_codecs(data_user, "codecs", user->capability);
+		ast_data_add_codecs(data_user, "codecs", user->capability, 0);
 
 		if (!ast_strlen_zero(user->secret)) {
 			ast_copy_string(auth, user->secret, sizeof(auth));

Modified: team/eliel/data_api_providers_gsoc2010/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/channels/chan_local.c?view=diff&rev=276266&r1=276265&r2=276266
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/channels/chan_local.c (original)
+++ team/eliel/data_api_providers_gsoc2010/channels/chan_local.c Tue Jul 13 20:38:02 2010
@@ -1029,7 +1029,7 @@
 			}
 			ast_mutex_lock(&p->lock);
 			ast_data_add_structure(local_pvt, data_channel, p);
-			ast_data_add_codecs(data_channel, "reqformat", p->reqformat);
+			ast_data_add_codecs(data_channel, "reqformat", p->reqformat, 0);
 			data_owner = ast_data_add_node(data_channel, "owner");
 			if (!data_owner) {
 				ast_mutex_unlock(&p->lock);

Modified: team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c?view=diff&rev=276266&r1=276265&r2=276266
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c (original)
+++ team/eliel/data_api_providers_gsoc2010/channels/chan_sip.c Tue Jul 13 20:38:02 2010
@@ -27902,7 +27902,7 @@
 		ast_data_add_str(enum_node, "text", ast_describe_caller_presentation(peer->callingpres));
 
 		/* codecs */
-		ast_data_add_codecs(data_peer, "codecs", peer->capability);
+		ast_data_add_codecs(data_peer, "codecs", peer->capability, 0);
 
 		if (!ast_data_search_match(search, data_peer)) {
 			ast_data_remove_node(data_root, data_peer);

Modified: team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h?view=diff&rev=276266&r1=276265&r2=276266
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h (original)
+++ team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h Tue Jul 13 20:38:02 2010
@@ -805,10 +805,11 @@
  * \param[in] node_name The name of the node where we are going to add the list of
  *                      codecs.
  * \param[in] capability The codecs allowed.
+ * \parma[in] all Show all the codecs without checking the capability parameter.
  * \return < 0 on error.
  * \return 0 on success.
  */
-int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability);
+int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability, int all);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/eliel/data_api_providers_gsoc2010/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/channel.c?view=diff&rev=276266&r1=276265&r2=276266
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/channel.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/channel.c Tue Jul 13 20:38:02 2010
@@ -356,12 +356,12 @@
 		}
 	}
 
-	ast_data_add_codecs(tree, "oldwriteformat", chan->oldwriteformat);
-	ast_data_add_codecs(tree, "nativeformats", chan->nativeformats);
-	ast_data_add_codecs(tree, "readformat", chan->readformat);
-	ast_data_add_codecs(tree, "writeformat", chan->writeformat);
-	ast_data_add_codecs(tree, "rawreadformat", chan->rawreadformat);
-	ast_data_add_codecs(tree, "rawwriteformat", chan->rawwriteformat);
+	ast_data_add_codecs(tree, "oldwriteformat", chan->oldwriteformat, 0);
+	ast_data_add_codecs(tree, "nativeformats", chan->nativeformats, 0);
+	ast_data_add_codecs(tree, "readformat", chan->readformat, 0);
+	ast_data_add_codecs(tree, "writeformat", chan->writeformat, 0);
+	ast_data_add_codecs(tree, "rawreadformat", chan->rawreadformat, 0);
+	ast_data_add_codecs(tree, "rawwriteformat", chan->rawwriteformat, 0);
 
 	/* state */
 	enum_node = ast_data_add_node(tree, "state");
@@ -7058,7 +7058,7 @@
 		ast_data_add_bool(data_type, "get_pvt_uniqueid", cl->tech->get_pvt_uniqueid ? 1 : 0);
 		ast_data_add_bool(data_type, "cc_callback", cl->tech->cc_callback ? 1 : 0);
 
-		ast_data_add_codecs(data_type, "capabilities", cl->tech->capabilities);
+		ast_data_add_codecs(data_type, "capabilities", cl->tech->capabilities, 0);
 
 		if (!ast_data_search_match(search, data_type)) {
 			ast_data_remove_node(data_root, data_type);

Modified: team/eliel/data_api_providers_gsoc2010/main/data.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/data.c?view=diff&rev=276266&r1=276265&r2=276266
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/data.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/data.c Tue Jul 13 20:38:02 2010
@@ -3140,20 +3140,25 @@
 	return RESULT_SUCCESS;
 }
 
-int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability)
+int ast_data_add_codecs(struct ast_data *root, const char *node_name, format_t capability, int all)
 {
 	struct ast_data *codecs, *codec;
 	size_t fmlist_size;
 	const struct ast_format_list *fmlist;
 	int x;
 
-	codecs = ast_data_add_node(root, node_name);
-	if (!codecs) {
-		return -1;
-	}
+	if (node_name) {
+		codecs = ast_data_add_node(root, node_name);
+		if (!codecs) {
+			return -1;
+		}
+	} else {
+		codecs = root;
+	}
+
 	fmlist = ast_get_format_list(&fmlist_size);
 	for (x = 0; x < fmlist_size; x++) {
-		if (fmlist[x].bits & capability) {
+		if (all || fmlist[x].bits & capability) {
 			codec = ast_data_add_node(codecs, "codec");
 			if (!codec) {
 				return -1;
@@ -3162,6 +3167,12 @@
 			ast_data_add_int(codec, "samplespersecond", fmlist[x].samplespersecond);
 			ast_data_add_str(codec, "description", fmlist[x].desc);
 			ast_data_add_int(codec, "frame_length", fmlist[x].fr_len);
+			ast_data_add_str(codec, "type",
+					(fmlist[x].bits & AST_FORMAT_AUDIO_MASK) ? "audio" :
+					fmlist[x].bits == AST_FORMAT_JPEG || fmlist[x].bits == AST_FORMAT_PNG ? "image" :
+					(fmlist[x].bits & AST_FORMAT_VIDEO_MASK) ? "video" :
+					(fmlist[x].bits & AST_FORMAT_TEXT_MASK) ? "text" :
+					"(unk)");
 		}
 	}
 

Modified: team/eliel/data_api_providers_gsoc2010/main/frame.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/frame.c?view=diff&rev=276266&r1=276265&r2=276266
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/frame.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/frame.c Tue Jul 13 20:38:02 2010
@@ -978,9 +978,35 @@
 	AST_CLI_DEFINE(show_codec_n, "Shows a specific codec"),
 };
 
+/*!
+ * \internal
+ * \brief Callback used to generate the codecs tree.
+ * \param[in] search The search pattern tree.
+ * \retval <0 on error.
+ * \retval 0 on success.
+ */
+static int codecs_data_provider_get(const struct ast_data_search *search,
+		struct ast_data *data_root)
+{
+	ast_data_add_codecs(data_root, NULL, 0, 1);
+
+	return 0;
+}
+
+static const struct ast_data_handler codecs_data_provider = {
+	.version = AST_DATA_HANDLER_VERSION,
+	.get = codecs_data_provider_get
+};              
+
+static const struct ast_data_entry codecs_data_providers[] = {
+	AST_DATA_ENTRY("asterisk/core/codecs", &codecs_data_provider),
+};
+
 int init_framer(void)
 {
 	ast_cli_register_multiple(my_clis, ARRAY_LEN(my_clis));
+	ast_data_register_multiple_core(codecs_data_providers, ARRAY_LEN(codecs_data_providers));
+
 	return 0;	
 }
 




More information about the asterisk-commits mailing list