diff options
author | martinp <martinp@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-08-28 20:02:10 +0000 |
---|---|---|
committer | martinp <martinp@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-08-28 20:02:10 +0000 |
commit | 0f7540708770a2ddd4c5afcb057e9ab89e658d3b (patch) | |
tree | 457a4a3e8dec7fcff81b0a750356704758734e0c /channel.c | |
parent | a5c52defec739c228fbc6e9c9bbfd79bbf57c04e (diff) |
Fix synchronization of recorded files when using Monitor application
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1446 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channel.c')
-rwxr-xr-x | channel.c | 51 |
1 files changed, 43 insertions, 8 deletions
@@ -39,6 +39,11 @@ #include <linux/zaptel.h> #endif +/* uncomment if you have problems with 'monitoring' synchronized files */ +#if 0 +#define MONITOR_CONSTANT_DELAY +#define MONITOR_DELAY 150 * 8 /* 150 ms of MONITORING DELAY */ +#endif static int shutting_down = 0; static int uniqueint = 0; @@ -1088,9 +1093,25 @@ struct ast_frame *ast_read(struct ast_channel *chan) f = &null_frame; } else { if (chan->monitor && chan->monitor->read_stream ) { - if( ast_writestream( chan->monitor->read_stream, f ) < 0 ) { +#ifndef MONITOR_CONSTANT_DELAY + int jump = chan->outsmpl - chan->insmpl - 2 * f->samples; + if (jump >= 0) { + if (ast_seekstream(chan->monitor->read_stream, jump + f->samples, SEEK_FORCECUR) == -1) + ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); + chan->insmpl += jump + 2 * f->samples; + } else + chan->insmpl+= f->samples; +#else + int jump = chan->outsmpl - chan->insmpl; + if (jump - MONITOR_DELAY >= 0) { + if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1) + ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); + chan->insmpl += jump; + } else + chan->insmpl += f->samples; +#endif + if (ast_writestream(chan->monitor->read_stream, f) < 0) ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n"); - } } if (chan->pvt->readtrans) { f = ast_translate(chan->pvt->readtrans, f, 1); @@ -1360,18 +1381,32 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr) f = ast_translate(chan->pvt->writetrans, fr, 0); } else f = fr; - if (f) - { + if (f) { res = chan->pvt->write(chan, f); if( chan->monitor && chan->monitor->write_stream && f && ( f->frametype == AST_FRAME_VOICE ) ) { - if( ast_writestream( chan->monitor->write_stream, f ) < 0 ) { +#ifndef MONITOR_CONSTANT_DELAY + int jump = chan->insmpl - chan->outsmpl - 2 * f->samples; + if (jump >= 0) { + if (ast_seekstream(chan->monitor->write_stream, jump + f->samples, SEEK_FORCECUR) == -1) + ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); + chan->outsmpl += jump + 2 * f->samples; + } else + chan->outsmpl += f->samples; +#else + int jump = chan->insmpl - chan->outsmpl; + if (jump - MONITOR_DELAY >= 0) { + if (ast_seekstream(chan->monitor->write_stream, jump - f->samples, SEEK_FORCECUR) == -1) + ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); + chan->outsmpl += jump; + } else + chan->outsmpl += f->samples; +#endif + if (ast_writestream(chan->monitor->write_stream, f) < 0) ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); - } } - } - else + } else res = 0; } } |