mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
New "show codecs" option and mysql feature requests from Tilghman
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1349 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -37,8 +37,9 @@
|
|||||||
static char *desc = "MySQL CDR Backend";
|
static char *desc = "MySQL CDR Backend";
|
||||||
static char *name = "mysql";
|
static char *name = "mysql";
|
||||||
static char *config = "cdr_mysql.conf";
|
static char *config = "cdr_mysql.conf";
|
||||||
static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL;
|
static char *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL;
|
||||||
static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0;
|
static int hostname_alloc = 0, dbname_alloc = 0, dbuser_alloc = 0, password_alloc = 0, dbsock_alloc = 0;
|
||||||
|
static int dbport = 0;
|
||||||
static int connected = 0;
|
static int connected = 0;
|
||||||
|
|
||||||
static ast_mutex_t mysql_lock = AST_MUTEX_INITIALIZER;
|
static ast_mutex_t mysql_lock = AST_MUTEX_INITIALIZER;
|
||||||
@@ -61,10 +62,10 @@ static int mysql_log(struct ast_cdr *cdr)
|
|||||||
localtime_r(&t,&tm);
|
localtime_r(&t,&tm);
|
||||||
strftime(timestr,128,DATE_FORMAT,&tm);
|
strftime(timestr,128,DATE_FORMAT,&tm);
|
||||||
|
|
||||||
if ((!connected) && hostname && dbuser && password && dbname) {
|
if ((!connected) && (hostname || dbsock) && dbuser && password && dbname) {
|
||||||
/* Attempt to connect */
|
/* Attempt to connect */
|
||||||
mysql_init(&mysql);
|
mysql_init(&mysql);
|
||||||
if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, 0, NULL, 0)) {
|
if (mysql_real_connect(&mysql, hostname, dbuser, password, dbname, dbport, dbsock, 0)) {
|
||||||
connected = 1;
|
connected = 1;
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_ERROR, "cdr_mysql: cannot connect to database server %s. Call will not be logged\n", hostname);
|
ast_log(LOG_ERROR, "cdr_mysql: cannot connect to database server %s. Call will not be logged\n", hostname);
|
||||||
@@ -129,11 +130,17 @@ int unload_module(void)
|
|||||||
dbuser = NULL;
|
dbuser = NULL;
|
||||||
dbuser_alloc = 0;
|
dbuser_alloc = 0;
|
||||||
}
|
}
|
||||||
|
if (dbsock && dbsock_alloc) {
|
||||||
|
free(dbsock);
|
||||||
|
dbsock = NULL;
|
||||||
|
dbsock_alloc = 0;
|
||||||
|
}
|
||||||
if (password && password_alloc) {
|
if (password && password_alloc) {
|
||||||
free(password);
|
free(password);
|
||||||
password = NULL;
|
password = NULL;
|
||||||
password_alloc = 0;
|
password_alloc = 0;
|
||||||
}
|
}
|
||||||
|
dbport = 0;
|
||||||
ast_cdr_unregister(name);
|
ast_cdr_unregister(name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -202,6 +209,21 @@ int load_module(void)
|
|||||||
dbuser = "root";
|
dbuser = "root";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp = ast_variable_retrieve(cfg,"global","sock");
|
||||||
|
if (tmp) {
|
||||||
|
dbsock = malloc(strlen(tmp) + 1);
|
||||||
|
if (dbsock != NULL) {
|
||||||
|
dbsock_alloc = 1;
|
||||||
|
strcpy(dbsock,tmp);
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_ERROR,"Out of memory error.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_WARNING,"MySQL database sock file not specified. Assuming default\n");
|
||||||
|
dbsock = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
tmp = ast_variable_retrieve(cfg,"global","password");
|
tmp = ast_variable_retrieve(cfg,"global","password");
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
password = malloc(strlen(tmp) + 1);
|
password = malloc(strlen(tmp) + 1);
|
||||||
@@ -217,9 +239,20 @@ int load_module(void)
|
|||||||
password = "";
|
password = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp = ast_variable_retrieve(cfg,"global","port");
|
||||||
|
if (tmp) {
|
||||||
|
if (sscanf(tmp,"%d",&dbport) < 1) {
|
||||||
|
ast_log(LOG_WARNING,"Invalid MySQL port number. Using default\n");
|
||||||
|
dbport = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ast_destroy(cfg);
|
ast_destroy(cfg);
|
||||||
|
|
||||||
ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname);
|
ast_log(LOG_DEBUG,"cdr_mysql: got hostname of %s\n",hostname);
|
||||||
|
ast_log(LOG_DEBUG,"cdr_mysql: got port of %d\n",dbport);
|
||||||
|
if (dbsock)
|
||||||
|
ast_log(LOG_DEBUG,"cdr_mysql: got sock file of %s\n",dbsock);
|
||||||
ast_log(LOG_DEBUG,"cdr_mysql: got user of %s\n",dbuser);
|
ast_log(LOG_DEBUG,"cdr_mysql: got user of %s\n",dbuser);
|
||||||
ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname);
|
ast_log(LOG_DEBUG,"cdr_mysql: got dbname of %s\n",dbname);
|
||||||
ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password);
|
ast_log(LOG_DEBUG,"cdr_mysql: got password of %s\n",password);
|
||||||
|
@@ -3,8 +3,17 @@
|
|||||||
; asterisk server, you can achieve a local Unix socket connection by
|
; asterisk server, you can achieve a local Unix socket connection by
|
||||||
; setting hostname=localhost
|
; setting hostname=localhost
|
||||||
;
|
;
|
||||||
|
; port and sock are both optional parameters. If hostname is specified
|
||||||
|
; and is not "localhost", then cdr_mysql will attempt to connect to the
|
||||||
|
; port specified or use the default port. If hostname is not specified
|
||||||
|
; or if hostname is "localhost", then cdr_mysql will attempt to connect
|
||||||
|
; to the socket file specified by sock or otherwise use the default socket
|
||||||
|
; file.
|
||||||
|
;
|
||||||
;[global]
|
;[global]
|
||||||
;hostname=database.host.name
|
;hostname=database.host.name
|
||||||
;dbname=asteriskcdrdb
|
;dbname=asteriskcdrdb
|
||||||
;password=password
|
;password=password
|
||||||
;user=asteriskcdruser
|
;user=asteriskcdruser
|
||||||
|
;port=3306
|
||||||
|
;sock=/tmp/mysql.sock
|
||||||
|
111
frame.c
111
frame.c
@@ -411,6 +411,112 @@ int ast_getformatbyname(char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *ast_codec2str(int codec) {
|
||||||
|
static char codecs[25][30] = {
|
||||||
|
/* Audio formats */
|
||||||
|
"G.723.1", /* 0 */
|
||||||
|
"GSM", /* 1 */
|
||||||
|
"G.711 u-law", /* 2 */
|
||||||
|
"G.711 A-law", /* 3 */
|
||||||
|
"MPEG-2 layer 3", /* 4 */
|
||||||
|
"ADPCM", /* 5 */
|
||||||
|
"16 bit Signed Linear PCM", /* 6 */
|
||||||
|
"LPC10", /* 7 */
|
||||||
|
"G.729A audio", /* 8 */
|
||||||
|
"SpeeX", /* 9 */
|
||||||
|
"iLBC", /* 10 */
|
||||||
|
"undefined", /* 11 */
|
||||||
|
"undefined", /* 12 */
|
||||||
|
"undefined", /* 13 */
|
||||||
|
"undefined", /* 14 */
|
||||||
|
"Maximum audio format", /* 15 */
|
||||||
|
/* Image formats */
|
||||||
|
"JPEG image", /* 16 */
|
||||||
|
"PNG image", /* 17 */
|
||||||
|
"H.261 Video", /* 18 */
|
||||||
|
"H.263 Video", /* 19 */
|
||||||
|
"undefined", /* 20 */
|
||||||
|
"undefined", /* 21 */
|
||||||
|
"undefined", /* 22 */
|
||||||
|
"undefined", /* 23 */
|
||||||
|
"Maximum video format", /* 24 */
|
||||||
|
};
|
||||||
|
return codecs[codec];
|
||||||
|
}
|
||||||
|
|
||||||
|
static int show_codecs(int fd, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int i, found=0;
|
||||||
|
|
||||||
|
if ((argc < 2) || (argc > 3))
|
||||||
|
return RESULT_SHOWUSAGE;
|
||||||
|
|
||||||
|
if ((argc == 2) || (!strcasecmp(argv[1],"audio"))) {
|
||||||
|
found = 1;
|
||||||
|
for (i=0;i<11;i++)
|
||||||
|
ast_cli(fd, "%8d (1 << %2d) %s\n",1 << i,i,ast_codec2str(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((argc == 2) || (!strcasecmp(argv[1],"image"))) {
|
||||||
|
found = 1;
|
||||||
|
for (i=16;i<18;i++)
|
||||||
|
ast_cli(fd, "%8d (1 << %2d) %s\n",1 << i,i,ast_codec2str(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((argc == 2) || (!strcasecmp(argv[1],"video"))) {
|
||||||
|
found = 1;
|
||||||
|
for (i=18;i<20;i++)
|
||||||
|
ast_cli(fd, "%8d (1 << %2d) %s\n",1 << i,i,ast_codec2str(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! found)
|
||||||
|
return RESULT_SHOWUSAGE;
|
||||||
|
else
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char frame_show_codecs_usage[] =
|
||||||
|
"Usage: show [audio|video|image] codecs\n"
|
||||||
|
" Displays codec mapping\n";
|
||||||
|
|
||||||
|
struct ast_cli_entry cli_show_codecs =
|
||||||
|
{ { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage };
|
||||||
|
struct ast_cli_entry cli_show_codecs_audio =
|
||||||
|
{ { "show", "audio", "codecs", NULL }, show_codecs, "Shows audio codecs", frame_show_codecs_usage };
|
||||||
|
struct ast_cli_entry cli_show_codecs_video =
|
||||||
|
{ { "show", "video", "codecs", NULL }, show_codecs, "Shows video codecs", frame_show_codecs_usage };
|
||||||
|
struct ast_cli_entry cli_show_codecs_image =
|
||||||
|
{ { "show", "image", "codecs", NULL }, show_codecs, "Shows image codecs", frame_show_codecs_usage };
|
||||||
|
|
||||||
|
static int show_codec_n(int fd, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int codec, i, found=0;
|
||||||
|
|
||||||
|
if (argc != 3)
|
||||||
|
return RESULT_SHOWUSAGE;
|
||||||
|
|
||||||
|
if (sscanf(argv[2],"%d",&codec) != 1)
|
||||||
|
return RESULT_SHOWUSAGE;
|
||||||
|
|
||||||
|
for (i=0;i<32;i++)
|
||||||
|
if (codec == (1 << i)) {
|
||||||
|
found = 1;
|
||||||
|
ast_cli(fd, "%d (1 << %d) %s\n",1 << i,i,ast_codec2str(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! found)
|
||||||
|
ast_cli(fd, "Codec %d not found\n", codec);
|
||||||
|
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char frame_show_codec_n_usage[] =
|
||||||
|
"Usage: show codec <number>\n"
|
||||||
|
" Displays codec mapping\n";
|
||||||
|
|
||||||
|
struct ast_cli_entry cli_show_codec_n =
|
||||||
|
{ { "show", "codec", NULL }, show_codec_n, "Shows a specific codec", frame_show_codec_n_usage };
|
||||||
|
|
||||||
void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
|
void ast_frame_dump(char *name, struct ast_frame *f, char *prefix)
|
||||||
{
|
{
|
||||||
char *n = "unknown";
|
char *n = "unknown";
|
||||||
@@ -598,5 +704,10 @@ int init_framer(void)
|
|||||||
#ifdef TRACE_FRAMES
|
#ifdef TRACE_FRAMES
|
||||||
ast_cli_register(&cli_frame_stats);
|
ast_cli_register(&cli_frame_stats);
|
||||||
#endif
|
#endif
|
||||||
|
ast_cli_register(&cli_show_codecs);
|
||||||
|
ast_cli_register(&cli_show_codecs_audio);
|
||||||
|
ast_cli_register(&cli_show_codecs_video);
|
||||||
|
ast_cli_register(&cli_show_codecs_image);
|
||||||
|
ast_cli_register(&cli_show_codec_n);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -323,6 +323,14 @@ extern char* ast_getformatname(int format);
|
|||||||
*/
|
*/
|
||||||
extern int ast_getformatbyname(char *name);
|
extern int ast_getformatbyname(char *name);
|
||||||
|
|
||||||
|
//! Get a name from a format
|
||||||
|
/*!
|
||||||
|
* \param codec codec number (1,2,4,8,16,etc.)
|
||||||
|
* Gets a name from a format
|
||||||
|
* This returns a static string identifying the format on success, 0 on error.
|
||||||
|
*/
|
||||||
|
extern char *ast_codec2str(int codec);
|
||||||
|
|
||||||
//! Pick the best codec
|
//! Pick the best codec
|
||||||
/* Choose the best codec... Uhhh... Yah. */
|
/* Choose the best codec... Uhhh... Yah. */
|
||||||
extern int ast_best_codec(int fmts);
|
extern int ast_best_codec(int fmts);
|
||||||
|
Reference in New Issue
Block a user