Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENTOK-48681: Add range to estimated playout delay #272

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Broadcast-Ext/OpenTok Live/OTBroadcastExtAudioDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#endif

static double kPreferredIOBufferDuration = 0.01;
static double kToMicroSecond = 1000000;
static UInt8 kMaxPlayoutDelay = 150;

static mach_timebase_info_data_t info;

Expand Down Expand Up @@ -280,7 +282,7 @@ - (BOOL)isCapturing

- (uint16_t)estimatedRenderDelay
{
return _playoutDelay;
return (uint16_t)MIN(_playoutDelay, (UInt32)kMaxPlayoutDelay);
}

- (uint16_t)estimatedCaptureDelay
Expand Down Expand Up @@ -670,17 +672,18 @@ static void update_playout_delay(OTBroadcastExtAudioDevice* device) {
// HW output latency
NSTimeInterval interval = [mySession outputLatency];

device->_playoutDelay += (int)(interval * 1000000);
device->_playoutDelay += (int)(interval * kToMicroSecond);

// HW buffer duration
interval = [mySession IOBufferDuration];
device->_playoutDelay += (int)(interval * 1000000);
device->_playoutDelay += (int)(interval * kToMicroSecond);

device->_playoutDelay += (int)(device->_playout_AudioUnitProperty_Latency * 1000000);
device->_playoutDelay += (int)(device->_playout_AudioUnitProperty_Latency * kToMicroSecond);

// To ms
device->_playoutDelay = (device->_playoutDelay - 500) / 1000;

if ( device->_playoutDelay >= 500 ) {
device->_playoutDelay = (device->_playoutDelay - 500) / 1000;
}
// Reset counter
device->_playoutDelayMeasurementCounter = 0;
}
Expand Down
15 changes: 9 additions & 6 deletions Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#endif

static double kPreferredIOBufferDuration = 0.01;
static double kToMicroSecond = 1000000;
static UInt8 kMaxPlayoutDelay = 150;

static mach_timebase_info_data_t info;

Expand Down Expand Up @@ -331,7 +333,7 @@ - (BOOL)isCapturing

- (uint16_t)estimatedRenderDelay
{
return _playoutDelay;
return (uint16_t)MIN(_playoutDelay, (UInt32)kMaxPlayoutDelay);
}

- (uint16_t)estimatedCaptureDelay
Expand Down Expand Up @@ -878,17 +880,18 @@ static void update_playout_delay(OTDefaultAudioDevice* device) {
// HW output latency
NSTimeInterval interval = [mySession outputLatency];

device->_playoutDelay += (int)(interval * 1000000);
device->_playoutDelay += (int)(interval * kToMicroSecond);

// HW buffer duration
interval = [mySession IOBufferDuration];
device->_playoutDelay += (int)(interval * 1000000);
device->_playoutDelay += (int)(interval * kToMicroSecond);

device->_playoutDelay += (int)(device->_playout_AudioUnitProperty_Latency * 1000000);
device->_playoutDelay += (int)(device->_playout_AudioUnitProperty_Latency * kToMicroSecond);

// To ms
device->_playoutDelay = (device->_playoutDelay - 500) / 1000;

if ( device->_playoutDelay >= 500 ) {
device->_playoutDelay = (device->_playoutDelay - 500) / 1000;
}
// Reset counter
device->_playoutDelayMeasurementCounter = 0;
}
Expand Down