Skip to content

Commit

Permalink
AE: improve sync by using pause bursts
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Jan 21, 2016
1 parent 0ad4065 commit 565bd35
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
23 changes: 9 additions & 14 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2229,13 +2229,6 @@ CSampleBuffer* CActiveAE::SyncStream(CActiveAEStream *stream)
if (!stream->m_pClock)
return ret;

if (m_mode == MODE_RAW)
{
// TODO
// implement pause bursts for passthrough, until then we need to exit here
stream->m_syncClock = CActiveAEStream::INSYNC;
}

if (stream->m_syncClock == CActiveAEStream::STARTSYNC)
{
stream->m_syncClock = CActiveAEStream::MUTE;
Expand All @@ -2257,13 +2250,6 @@ CSampleBuffer* CActiveAE::SyncStream(CActiveAEStream *stream)

bool newerror = stream->m_syncError.Get(error, stream->m_syncClock ? 100 : 1000);

// TODO: delete if passthrough ever gets a proper sync method
// for now I recommend to every one just not to use it, it has zero advantage anyway
if (m_mode == MODE_RAW)
{
return ret;
}

if (newerror && fabs(error) > threshold && stream->m_syncClock == CActiveAEStream::INSYNC)
{
stream->m_syncClock = CActiveAEStream::ADJUST;
Expand Down Expand Up @@ -2305,6 +2291,11 @@ CSampleBuffer* CActiveAE::SyncStream(CActiveAEStream *stream)
framesToDelay = 0;
}
ret->pkt->nb_samples = framesToDelay;
if (m_mode == MODE_RAW)
{
ret->pkt->nb_samples = 0;
ret->pkt->pause_burst_ms = error;
}
for(int i=0; i<ret->pkt->planes; i++)
{
memset(ret->pkt->data[i], 0, ret->pkt->linesize);
Expand All @@ -2326,6 +2317,10 @@ CSampleBuffer* CActiveAE::SyncStream(CActiveAEStream *stream)
else
framesToSkip = 0;
}
else if (m_mode == MODE_RAW)
{
framesToSkip = buf->pkt->nb_samples;
}
int bytesToSkip = framesToSkip*buf->pkt->bytes_per_sample;
for(int i=0; i<buf->pkt->planes; i++)
{
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CSoundPacket::CSoundPacket(SampleConfig conf, int samples) : config(conf)
data = AE.AllocSoundSample(config, samples, bytes_per_sample, planes, linesize);
max_nb_samples = samples;
nb_samples = 0;
pause_burst_ms = 0;
}

CSoundPacket::~CSoundPacket()
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CSoundPacket
int planes; // 1 for non planar formats, #channels for planar
int nb_samples; // number of frames used
int max_nb_samples; // max number of frames this packet can hold
int pause_burst_ms;
};

class CActiveAEBufferPool;
Expand Down
51 changes: 37 additions & 14 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAESink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,11 @@ void CActiveAESink::OpenSink()
m_sampleOfSilence.pkt->nb_samples = m_sampleOfSilence.pkt->max_nb_samples;
if (!passthrough)
GenerateNoise();
else
{
m_sampleOfSilence.pkt->nb_samples = 0;
m_sampleOfSilence.pkt->pause_burst_ms = m_sinkFormat.m_frames * 1000 / m_sinkFormat.m_sampleRate;

This comment has been minimized.

Copy link
@fritsch

fritsch Jan 22, 2016

m_frames = 1881
m_sampleRate= 48000

Integer-Division (!) -> 0 always.

This comment has been minimized.

Copy link
@fritsch

fritsch Jan 22, 2016

No I feel confused ... on what I commented

This comment has been minimized.

Copy link
@fritsch

fritsch Jan 22, 2016

8d5e26d#diff-b53cfd76db45d86d6c5c1f265451d22bR945 <- that was the first version! which had that issue.

}

m_swapState = CHECK_SWAP;
}
Expand Down Expand Up @@ -898,30 +903,48 @@ unsigned int CActiveAESink::OutputSamples(CSampleBuffer* samples)
std::unique_ptr<uint8_t[]> mergebuffer;
uint8_t* p_mergebuffer = NULL;

if (m_requestedFormat.m_dataFormat == AE_FMT_RAW && frames > 0 && samples->pool)
if (m_requestedFormat.m_dataFormat == AE_FMT_RAW)
{
if (m_needIecPack)
{
if (m_sinkFormat.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_TRUEHD && frames == 61440)
if (frames > 0)
{
int offset;
int len;
m_packer->GetBuffer();
for (int i=0; i<24; i++)
if (m_sinkFormat.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_TRUEHD && frames == 61440)
{
offset = i*2560;
len = (*(buffer[0] + offset+2560-2) << 8) + *(buffer[0] + offset+2560-1);
m_packer->Pack(m_sinkFormat.m_streamInfo, buffer[0] + offset, len);
int offset;
int len;
m_packer->GetBuffer();
for (int i=0; i<24; i++)
{
offset = i*2560;
len = (*(buffer[0] + offset+2560-2) << 8) + *(buffer[0] + offset+2560-1);
m_packer->Pack(m_sinkFormat.m_streamInfo, buffer[0] + offset, len);
}
}
else
m_packer->Pack(m_sinkFormat.m_streamInfo, buffer[0], frames);
}
else if (samples->pkt->pause_burst_ms > 0)
{
// construct a pause burst
uint8_t payload[4];
m_packer->Pack(m_sinkFormat.m_streamInfo, payload, 4);
uint16_t* buf = (uint16_t*)m_packer->GetBuffer();
buf[3] = 3; // Pc, burst type
buf[4] = 32; // length-code
buf[5] = samples->pkt->pause_burst_ms * m_sinkFormat.m_sampleRate / 1000;
buf[6] = 0;
}
else
m_packer->Pack(m_sinkFormat.m_streamInfo, buffer[0], frames);

unsigned int size = m_packer->GetSize();
packBuffer = m_packer->GetBuffer();
buffer = &packBuffer;
totalFrames = size / m_sinkFormat.m_frameSize;
if (frames > 0)
totalFrames = size / m_sinkFormat.m_frameSize;
else if (samples->pkt->pause_burst_ms > 0)
totalFrames = samples->pkt->pause_burst_ms * m_sinkFormat.m_sampleRate / 1000;
frames = totalFrames;

switch(m_swapState)
{
case SKIP_SWAP:
Expand Down Expand Up @@ -1005,8 +1028,8 @@ unsigned int CActiveAESink::OutputSamples(CSampleBuffer* samples)
m_stats->UpdateSinkDelay(status, samples->pool ? written : 0);
}

if (m_requestedFormat.m_dataFormat == AE_FMT_RAW && samples->pool)
m_stats->UpdateSinkDelay(status, 1);
if (m_requestedFormat.m_dataFormat == AE_FMT_RAW)
m_stats->UpdateSinkDelay(status, samples->pool ? 1 : 0);

return status.delay * 1000;
}
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ unsigned int CActiveAEStream::AddData(uint8_t* const *data, unsigned int offset,
{
m_currentBuffer = *((CSampleBuffer**)msg->data);
m_currentBuffer->timestamp = 0;
m_currentBuffer->pkt->nb_samples = 0;
m_currentBuffer->pkt->pause_burst_ms = 0;
msg->Release();
DecFreeBuffers();
continue;
Expand Down

0 comments on commit 565bd35

Please sign in to comment.