return slot[newest_slot].receiver_node->btrn;
}
-/* returns slot num on success. */
-static int open_current_receiver(void)
+/* whether a new instance of a decoder should be started. */
+static bool must_start_decoder(void)
{
int ret, cafn = stat_task->current_audio_format_num;
if (cafn < 0 || !stat_task->ct)
- return -1;
+ return false;
/* Do nothing if the 'N' flag is set or the 'P' flag is unset */
if (stat_task->vss_status != VSS_STATUS_FLAG_PLAYING)
- return -1;
+ return false;
ret = receiver_running(cafn);
if (ret != 0) /* already running */
- return -1;
+ return false;
if (tv_diff(now, &afi[cafn].restart_barrier, NULL) < 0)
- return -1;
- /* start a new receiver */
- return open_receiver(cafn);
+ return false;
+ return true;
}
static unsigned compute_time_diff(const struct timeval *status_time)
&tmp);
stat_task->sa_time_diff = tmp;
PARA_INFO_LOG("time diff (cur/avg): %s%lums/%s%lums\n",
- sign > 0? "+" : "-",
+ sign < 0? "-" : "+",
tv2ms(&diff),
- sa_time_diff_sign ? "+" : "-",
+ sa_time_diff_sign < 0? "-" : "+",
tv2ms(&stat_task->sa_time_diff)
);
out:
if (audiod_status != AUDIOD_ON ||
!(stat_task->vss_status & VSS_STATUS_FLAG_PLAYING))
return kill_all_decoders(-E_NOT_PLAYING);
- ret = open_current_receiver();
+ if (!must_start_decoder())
+ return;
+ ret = open_receiver(stat_task->current_audio_format_num);
if (ret < 0)
return;
sl = slot + ret;
static void status_pre_select(struct sched *s, struct task *t)
{
struct status_task *st = container_of(t, struct status_task, task);
- int ret;
+ int ret, cafn = stat_task->current_audio_format_num;
+ if (must_start_decoder())
+ goto min_delay;
ret = btr_node_status(st->btrn, 0, BTR_NT_LEAF);
- sched_request_barrier(&st->restart_barrier, s);
+ if (ret > 0)
+ goto min_delay;
+ if (!st->ct)
+ sched_request_barrier_or_min_delay(&st->restart_barrier, s);
+ if (cafn >= 0)
+ sched_request_barrier(&afi[cafn].restart_barrier, s);
+ return;
+min_delay:
+ sched_min_delay(s);
}
/* restart the client task if necessary */
free(home);
if (ret < 0) {
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ btr_remove_node(ct->btrn);
btr_free_node(ct->btrn);
client_close(ct);
*ct_ptr = NULL;
sched_request_timeout(&diff, s);
}
+void sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s)
+{
+ struct timeval diff;
+ if (tv_diff(now, barrier, &diff) > 0)
+ return sched_min_delay(s);
+ sched_request_timeout(&diff, s);
+}
void sched_request_timeout(struct timeval *timeout, struct sched *s);
void sched_request_timeout_ms(long unsigned ms, struct sched *s);
void sched_request_barrier(struct timeval *barrier, struct sched *s);
+void sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s);
/**
* Compute a convex combination of two time values.
*
- * \param a The first coefiicent.
+ * \param a The first coefficient.
* \param tv1 The first time value.
- * \param b The second coefiicent.
+ * \param b The second coefficient.
* \param tv2 The second time value.
* \param result Contains the convex combination upon return.
*
- * compute x := (a * tv1 + b * tv2) / (|a| + |b|) and store |x| in \a result.
+ * Compute x := (a * tv1 + b * tv2) / (|a| + |b|) and store |x| in \a result.
* Both \a a and \a b may be negative.
*
- * \return One if \a x is positive, -1 otherwise.
+ * \return Zero, 1 or -1, if \a x is zero, positive or negative, respectively.
*/
int tv_convex_combination(const long a, const struct timeval *tv1,
const long b, const struct timeval *tv2,
struct timeval *result)
{
struct timeval tmp1, tmp2, tmp3;
- int ret = 1, subtract = ((a > 0 && b < 0) || (a < 0 && b > 0));
- unsigned long a1 = PARA_ABS(a), b1 = PARA_ABS(b);
+ int ret = 1;
+ unsigned long a1, b1;
+ if (a == 0 && b == 0) {
+ result->tv_sec = 0;
+ result->tv_usec = 0;
+ return 0;
+ }
+ a1 = PARA_ABS(a);
+ b1 = PARA_ABS(b);
tv_scale(a1, tv1, &tmp1);
tv_scale(b1, tv2, &tmp2);
- if (subtract)
+ if ((a > 0 && b < 0) || (a < 0 && b > 0)) /* subtract */
ret = tv_diff(&tmp1, &tmp2, &tmp3);
else
tv_add(&tmp1, &tmp2, &tmp3);
- if (a1 + b1)
- tv_divide(a1 + b1, &tmp3, result);
- else {
- result->tv_sec = 0;
- result->tv_usec = 0;
- }
+ tv_divide(a1 + b1, &tmp3, result);
if (!a || !b) {
if (a + b < 0)
ret = -1;
- } else
- if (a < 0)
- ret = -ret;
+ } else if (a < 0)
+ ret = -ret;
return ret;
}
fn->min_iqs += 4096;
goto next_buffer;
}
- fn->min_iqs = WMA_FRAME_SKIP + pwd->ahi.block_align;
+ fn->min_iqs = 2 * (WMA_FRAME_SKIP + pwd->ahi.block_align);
fn->private_data = pwd;
converted = pwd->ahi.header_len;
goto success;
}
+ fn->min_iqs = WMA_FRAME_SKIP + pwd->ahi.block_align;
for (;;) {
char *out;
int out_size = WMA_OUTPUT_BUFFER_SIZE;