--- asterisk-11.7.0.o/formats/format_g729.c 2014-01-27 21:01:24.201722187 +0200 +++ asterisk-11.7.0/formats/format_g729.c 2014-01-27 22:30:19.182767226 +0200 @@ -37,6 +37,7 @@ #include "asterisk/mod_format.h" #include "asterisk/module.h" #include "asterisk/endian.h" +#include "asterisk/channel.h" /* Some Ideas for this code came from makeg729e.c by Jeffrey Chilton */ @@ -50,6 +51,9 @@ struct ast_g729_pvt { int detected_vad; /* simple flag indicating whether or not we detected and reported on VAD on this stream yet or not */ + long expectpos; /* Where we *expect* the next ftell to be */ + long cleanwrites; /* Number of writes that was clean */ + long cleanstart ; /* byte offset that was clean */ }; static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext) @@ -74,6 +78,22 @@ { struct ast_g729_pvt* pvt = fs->_private; int res, writelen = f->datalen; + long position = ftell(fs->f); + + if (position == pvt->expectpos) { + pvt->cleanwrites++; + } + ast_log(LOG_WARNING, "filestream(filename=%s,owner=%s,orig_chan_name=%s,pos=%ld), frame(datalen=%d,samples=%d,ts=%ld,len=%ld,seqno=%d),expectpos=%ld,cleanwrites=%ld,cleanstart=%ld\n", + fs->filename, fs->owner ? ast_channel_name(fs->owner) : "(none)", + fs->orig_chan_name, position, + f->datalen, f->samples, f->ts, f->len, f->seqno, + pvt->expectpos, pvt->cleanwrites, pvt->cleanstart); + if (position != pvt->expectpos) { + pvt->cleanwrites = 0; + pvt->cleanstart = position; + } + pvt->expectpos = position + f->samples * G729A_FRAME_SIZE / (G729A_SAMPLES >> 1); + if (f->frametype != AST_FRAME_VOICE) { ast_log(LOG_WARNING, "Asked to write non-voice frame!\n"); return -1; @@ -122,6 +142,12 @@ } /* protect against seeking beyond begining. */ offset = (offset < min)?min:offset; + ast_log(LOG_WARNING, "g729_seek(%s, %lu, %s), offset=%lu\n", + fs->filename, sample_offset, whence == SEEK_SET ? "SEEK_SET" : + whence == SEEK_CUR ? "SEEK_CUR" : + whence == SEEK_FORCECUR ? "SEEK_FORCECUR" : + whence == SEEK_END ? "SEEK_END" : "SEEK_???", + offset); if (fseeko(fs->f, offset, SEEK_SET) < 0) return -1; return 0;