aboutsummaryrefslogtreecommitdiffstats
path: root/formats/format_pcm.c
diff options
context:
space:
mode:
authormattf <mattf@f38db490-d61c-443f-a65b-d21fe96a405b>2006-01-20 21:36:33 +0000
committermattf <mattf@f38db490-d61c-443f-a65b-d21fe96a405b>2006-01-20 21:36:33 +0000
commit73a64f9573ac445e0bd36511e4f18c94b1b88270 (patch)
treea505f7710460e8e2a46fe2a7d8fac675705bf95e /formats/format_pcm.c
parent834f1b57898c31c92aa60d7ab9dc6ab8dea0e206 (diff)
Fix for formats so they give better output on failure conditions. (#6141)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@8357 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'formats/format_pcm.c')
-rw-r--r--formats/format_pcm.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index 289038ced..da72a559e 100644
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -177,6 +177,7 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
{
long cur, max, offset = 0;
+ int ret = -1; /* assume error */
cur = ftell(fs->f);
fseek(fs->f, 0, SEEK_END);
@@ -193,29 +194,33 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
case SEEK_FORCECUR:
offset = cur + sample_offset;
break;
+ default:
+ ast_log(LOG_WARNING, "invalid whence %d, assuming SEEK_SET\n", whence);
+ offset = sample_offset;
}
-
- switch (whence) {
- case SEEK_FORCECUR:
+ if (offset < 0) {
+ ast_log(LOG_WARNING, "negative offset %ld, resetting to 0\n", offset);
+ offset = 0;
+ }
+ if (whence == SEEK_FORCECUR && offset > max) { /* extend the file */
+ size_t left = offset - max;
+
+ while (left) {
+ size_t written = fwrite(ulaw_silence, sizeof(ulaw_silence[0]),
+ (left > BUF_SIZE) ? BUF_SIZE : left, fs->f);
+ if (written == -1)
+ break; /* error */
+ left -= written * sizeof(ulaw_silence[0]);
+ }
+ ret = 0; /* successful */
+ } else {
if (offset > max) {
- size_t left = offset - max;
- size_t res;
-
- while (left) {
- res = fwrite(ulaw_silence, sizeof(ulaw_silence[0]),
- (left > BUF_SIZE) ? BUF_SIZE : left, fs->f);
- if (res == -1)
- return res;
- left -= res * sizeof(ulaw_silence[0]);
- }
- return offset;
+ ast_log(LOG_WARNING, "offset too large %ld, truncating to %ld\n", offset, max);
+ offset = max;
}
- /* fall through */
- default:
- offset = (offset > max) ? max : offset;
- offset = (offset < 0) ? 0 : offset;
- return fseek(fs->f, offset, SEEK_SET);
+ ret = fseek(fs->f, offset, SEEK_SET);
}
+ return ret;
}
static int pcm_trunc(struct ast_filestream *fs)