Fixed overflow bug in length calculation, added force option, and added trailing silence in the output file
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1684 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
b823dc55f6
commit
9b65ba5007
|
@ -49,10 +49,12 @@ static const char *desc =
|
||||||
"\n"
|
"\n"
|
||||||
" options:\n"
|
" options:\n"
|
||||||
" -c N Set clock rate to N Hz (default 16000)\n"
|
" -c N Set clock rate to N Hz (default 16000)\n"
|
||||||
|
" -f Force write (overwrite output without warning\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
#define MAX_WAV 16
|
#define MAX_WAV 16
|
||||||
#define PTIME 20
|
#define PTIME 20
|
||||||
|
#define APPEND 1000
|
||||||
|
|
||||||
struct wav_input
|
struct wav_input
|
||||||
{
|
{
|
||||||
|
@ -75,7 +77,7 @@ int main(int argc, char *argv[])
|
||||||
pj_pool_t *pool;
|
pj_pool_t *pool;
|
||||||
pjmedia_endpt *med_ept;
|
pjmedia_endpt *med_ept;
|
||||||
unsigned clock_rate = 16000;
|
unsigned clock_rate = 16000;
|
||||||
int c;
|
int c, force=0;
|
||||||
const char *out_fname;
|
const char *out_fname;
|
||||||
pjmedia_conf *conf;
|
pjmedia_conf *conf;
|
||||||
pjmedia_port *wavout;
|
pjmedia_port *wavout;
|
||||||
|
@ -92,7 +94,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
|
||||||
/* Parse arguments */
|
/* Parse arguments */
|
||||||
while ((c=pj_getopt(argc, argv, "c:")) != -1) {
|
while ((c=pj_getopt(argc, argv, "c:f")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
clock_rate = atoi(pj_optarg);
|
clock_rate = atoi(pj_optarg);
|
||||||
|
@ -101,6 +103,9 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
force = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +116,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
out_fname = argv[pj_optind++];
|
out_fname = argv[pj_optind++];
|
||||||
if (pj_file_exists(out_fname)) {
|
if (force==0 && pj_file_exists(out_fname)) {
|
||||||
char in[8];
|
char in[8];
|
||||||
|
|
||||||
printf("File %s exists, overwrite? [Y/N] ", out_fname);
|
printf("File %s exists, overwrite? [Y/N] ", out_fname);
|
||||||
|
@ -166,7 +171,8 @@ int main(int argc, char *argv[])
|
||||||
PJMEDIA_FILE_NO_LOOP, 0,
|
PJMEDIA_FILE_NO_LOOP, 0,
|
||||||
&wav_input[i].port) );
|
&wav_input[i].port) );
|
||||||
len = pjmedia_wav_player_get_len(wav_input[i].port);
|
len = pjmedia_wav_player_get_len(wav_input[i].port);
|
||||||
len = len * clock_rate / wav_input[i].port->info.clock_rate;
|
len = (pj_ssize_t)(len * 1.0 * clock_rate /
|
||||||
|
wav_input[i].port->info.clock_rate);
|
||||||
if (len > longest)
|
if (len > longest)
|
||||||
longest = len;
|
longest = len;
|
||||||
|
|
||||||
|
@ -178,7 +184,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Loop reading frame from the bridge and write it to WAV */
|
/* Loop reading frame from the bridge and write it to WAV */
|
||||||
processed = 0;
|
processed = 0;
|
||||||
while (processed < longest) {
|
while (processed < longest + clock_rate * APPEND * 2 / 1000) {
|
||||||
pj_int16_t framebuf[PTIME * 48000 / 1000];
|
pj_int16_t framebuf[PTIME * 48000 / 1000];
|
||||||
pjmedia_port *cp = pjmedia_conf_get_master_port(conf);
|
pjmedia_port *cp = pjmedia_conf_get_master_port(conf);
|
||||||
pjmedia_frame frame;
|
pjmedia_frame frame;
|
||||||
|
@ -187,15 +193,17 @@ int main(int argc, char *argv[])
|
||||||
frame.size = cp->info.samples_per_frame * 2;
|
frame.size = cp->info.samples_per_frame * 2;
|
||||||
pj_assert(frame.size <= sizeof(framebuf));
|
pj_assert(frame.size <= sizeof(framebuf));
|
||||||
|
|
||||||
status = pjmedia_port_get_frame(cp, &frame);
|
CHECK( pjmedia_port_get_frame(cp, &frame) );
|
||||||
if (status != PJ_SUCCESS)
|
|
||||||
break;
|
|
||||||
|
|
||||||
CHECK( pjmedia_port_put_frame(wavout, &frame));
|
CHECK( pjmedia_port_put_frame(wavout, &frame));
|
||||||
|
|
||||||
processed += frame.size;
|
processed += frame.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PJ_LOG(3,(THIS_FILE, "Done. Output duration: %d.%03d",
|
||||||
|
(processed >> 2)/clock_rate,
|
||||||
|
((processed >> 2)*1000/clock_rate) % 1000));
|
||||||
|
|
||||||
/* Shutdown everything */
|
/* Shutdown everything */
|
||||||
CHECK( pjmedia_port_destroy(wavout) );
|
CHECK( pjmedia_port_destroy(wavout) );
|
||||||
for (i=0; i<input_cnt; ++i) {
|
for (i=0; i<input_cnt; ++i) {
|
||||||
|
|
Loading…
Reference in New Issue