diff options
author | Martin Pycko <martinp@digium.com> | 2003-08-28 20:02:10 +0000 |
---|---|---|
committer | Martin Pycko <martinp@digium.com> | 2003-08-28 20:02:10 +0000 |
commit | f14004abfd974a328736442971caee22053cfeec (patch) | |
tree | 457a4a3e8dec7fcff81b0a750356704758734e0c /channel.c | |
parent | 3ee27a8a8992dce78c0bf062d32ef7034d98b555 (diff) |
Fix synchronization of recorded files when using Monitor application
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1446 65c4cc65-6c06-0410-ace0-fbb531ad65f3
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; } } |