Skip to content

Commit

Permalink
ao_avfoundation: sleep on zero sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Mar 21, 2024
1 parent 60a3a53 commit 0624592
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions audio/out/ao_avfoundation.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,10 @@ static void feed(struct ao *ao)

int real_sample_count = ao_read_data_nonblocking(ao, data, request_sample_count, p->end_time_mp);
if (real_sample_count == 0) {
// in this case, we must satisfy renderer to avoid spining
real_sample_count = ao_read_data(ao, data, request_sample_count, p->end_time_mp);
if (real_sample_count == 0) {
// ao_read_data may still return zero?
real_sample_count = request_sample_count;
}
CFRelease(block_buffer);
block_buffer = NULL;
mp_sleep_ns(1000000); // avoid spinning
return;
}

CMSampleTimingInfo sample_timing_into[] = {(CMSampleTimingInfo) {
Expand Down Expand Up @@ -159,9 +157,11 @@ static void stop(struct ao *ao)
{
struct priv *p = ao->priv;

[p->renderer stopRequestingMediaData];
[p->renderer flush];
[p->synchronizer setRate:0];
dispatch_sync(p->queue, ^{
[p->renderer stopRequestingMediaData];
[p->renderer flush];
[p->synchronizer setRate:0];
});
}

static int control(struct ao *ao, enum aocontrol cmd, void *arg)
Expand Down Expand Up @@ -326,6 +326,8 @@ static void uninit(struct ao *ao)
{
struct priv *p = ao->priv;

stop(ao);

[p->renderer release];
[p->synchronizer release];
dispatch_release(p->queue);
Expand Down

0 comments on commit 0624592

Please sign in to comment.