1 /* $Id$ */
2 /*
3  * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4  * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #include <pjmedia/types.h>
21 #include <pj/assert.h>
22 #include <pj/string.h>
23 
24 
25 /* Map structure for pjmedia type names */
26 typedef struct pjmedia_type_map {
27     pjmedia_type type;
28     const char* name;
29 } pjmedia_type_map;
30 
31 /* Internal mapping for pjmedia type names */
32 static pjmedia_type_map media_type_names[] = {
33     {PJMEDIA_TYPE_NONE,		"none"},
34     {PJMEDIA_TYPE_AUDIO,	"audio"},
35     {PJMEDIA_TYPE_VIDEO,	"video"},
36     {PJMEDIA_TYPE_APPLICATION,	"application"},
37     {PJMEDIA_TYPE_UNKNOWN,	"unknown"}
38 };
39 
40 /*
41  * Utility function to return the string name for a pjmedia_type.
42  */
pjmedia_type_name(pjmedia_type t)43 PJ_DEF(const char*) pjmedia_type_name(pjmedia_type t)
44 {
45     pj_assert(t < (int)PJ_ARRAY_SIZE(media_type_names));
46     pj_assert(PJMEDIA_TYPE_UNKNOWN == 4);
47 
48     if (t < (int)PJ_ARRAY_SIZE(media_type_names))
49 	return media_type_names[t].name;
50     else
51 	return "??";
52 }
53 
54 /*
55  * Utility function to return the media type for a media name string.
56  */
pjmedia_get_type(const pj_str_t * name)57 PJ_DEF(pjmedia_type) pjmedia_get_type(const pj_str_t *name)
58 {
59     int i;
60     for (i = 0; i < PJ_ARRAY_SIZE(media_type_names); ++i) {
61 	if (pj_stricmp2(name, media_type_names[i].name)==0)
62 	    return media_type_names[i].type;
63     }
64     return PJMEDIA_TYPE_UNKNOWN;
65 }
66