1
/* $Id: util.h 3550 2011-05-05 05:33:27Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#include <stdlib.h> /* strtol() */
22
/* Util to display the error message for the specified error code */
23
static int app_perror( const char *sender, const char *title,
26
char errmsg[PJ_ERR_MSG_SIZE];
28
pj_strerror(status, errmsg, sizeof(errmsg));
30
PJ_LOG(3,(sender, "%s: %s [code=%d]", title, errmsg, status));
37
#define CLOCK_RATE 44100
38
#define NSAMPLES (CLOCK_RATE * 20 / 1000)
43
* Common sound options.
46
" -d, --dev=NUM Sound device use device id NUM (default=-1) \n"\
47
" -r, --rate=HZ Set clock rate in samples per sec (default=44100)\n"\
48
" -c, --channel=NUM Set # of channels (default=1 for mono). \n"\
49
" -f, --frame=NUM Set # of samples per frame (default equival 20ms)\n"\
50
" -b, --bit=NUM Set # of bits per sample (default=16) \n"
54
* This utility function parses the command line and look for
55
* common sound options.
57
pj_status_t get_snd_options(const char *app_name,
63
int *samples_per_frame,
66
struct pj_getopt_option long_options[] = {
68
{ "rate", 1, 0, 'r' },
69
{ "channel", 1, 0, 'c' },
70
{ "frame", 1, 0, 'f' },
79
*samples_per_frame = 0;
82
while((c=pj_getopt_long(argc,argv, "d:r:c:f:b:",
83
long_options, &option_index))!=-1)
89
val = strtol(pj_optarg, &err, 10);
91
PJ_LOG(3,(app_name, "Error: invalid value for device id"));
99
val = strtol(pj_optarg, &err, 10);
101
PJ_LOG(3,(app_name, "Error: invalid value for clock rate"));
109
val = strtol(pj_optarg, &err, 10);
111
PJ_LOG(3,(app_name, "Error: invalid channel count"));
114
*channel_count = val;
118
/* frame count/samples per frame */
119
val = strtol(pj_optarg, &err, 10);
121
PJ_LOG(3,(app_name, "Error: invalid samples per frame"));
124
*samples_per_frame = val;
129
val = strtol(pj_optarg, &err, 10);
131
PJ_LOG(3,(app_name, "Error: invalid samples bits per sample"));
134
*bits_per_sample = val;
138
/* Unknown options */
139
PJ_LOG(3,(app_name, "Error: unknown options '%c'", pj_optopt));
145
if (*samples_per_frame == 0) {
146
*samples_per_frame = *clock_rate * *channel_count * 20 / 1000;
153
/* Dump memory pool usage. */
154
void dump_pool_usage( const char *app_name, pj_caching_pool *cp )
156
#if !defined(PJ_HAS_POOL_ALT_API) || PJ_HAS_POOL_ALT_API==0
158
unsigned total_alloc = 0;
159
unsigned total_used = 0;
161
/* Accumulate memory usage in active list. */
162
p = cp->used_list.next;
163
while (p != (pj_pool_t*) &cp->used_list) {
164
total_alloc += pj_pool_get_capacity(p);
165
total_used += pj_pool_get_used_size(p);
169
PJ_LOG(3, (app_name, "Total pool memory allocated=%d KB, used=%d KB",