/*
- * Copyright (C) 2005-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2009 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
void tv_scale(const unsigned long mult, const struct timeval *tv,
struct timeval *result)
{
- result->tv_sec = mult * tv->tv_sec;
- result->tv_sec += tv->tv_usec * mult / 1000 / 1000;
- result->tv_usec = tv->tv_usec * mult % (1000 * 1000);
+ uint64_t x = ((uint64_t)tv->tv_sec * 1000 * 1000 + tv->tv_usec) * mult;
+
+ result->tv_sec = x / 1000 / 1000;
+ result->tv_usec = x % (1000 * 1000);
}
/**
return ret;
}
+/**
+ * Compute when to send a chunk of an audio file.
+ *
+ * \param chunk_num The number of the chunk.
+ * \param chunk_tv The duration of one chunk.
+ * \param stream_start When the first chunk was sent.
+ * \param result The time when to send chunk number \a chunk_num.
+ *
+ * This function computes stream_start + chunk_num * chunk_time.
+ */
void compute_chunk_time(long unsigned chunk_num,
struct timeval *chunk_tv, struct timeval *stream_start,
struct timeval *result)