Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3259 from FernetMenta/aefixes

Audio fixes
  • Loading branch information...
commit 555354d4a64d8de5b6e03023b011782d2c558304 2 parents 25bf01a + 2c88347
@fritsch fritsch authored
View
3  xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEResample.cpp
@@ -93,8 +93,10 @@ bool CActiveAEResample::Init(uint64_t dst_chan_layout, int dst_channels, int dst
// remapLayout is the layout of the sink, if the channel is in our src layout
// the channel is mapped by setting coef 1.0
memset(m_rematrix, 0, sizeof(m_rematrix));
+ m_dst_chan_layout = 0;
for (unsigned int out=0; out<remapLayout->Count(); out++)
{
+ m_dst_chan_layout += (1 << out);
int idx = GetAVChannelIndex((*remapLayout)[out], m_src_chan_layout);
if (idx >= 0)
{
@@ -102,7 +104,6 @@ bool CActiveAEResample::Init(uint64_t dst_chan_layout, int dst_channels, int dst
}
}
- m_dst_chan_layout = m_dllAvUtil.av_get_default_channel_layout(m_dst_channels);
m_dllAvUtil.av_opt_set_int(m_pContext, "out_channel_count", m_dst_channels, 0);
m_dllAvUtil.av_opt_set_int(m_pContext, "out_channel_layout", m_dst_chan_layout, 0);
View
37 xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp
@@ -53,10 +53,13 @@ CActiveAEStream::CActiveAEStream(AEAudioFormat *format)
m_streamIsBuffering = true;
m_streamSlave = NULL;
m_convertFn = NULL;
+ m_leftoverBuffer = new uint8_t[m_format.m_frameSize];
+ m_leftoverBytes = 0;
}
CActiveAEStream::~CActiveAEStream()
{
+ delete [] m_leftoverBuffer;
}
void CActiveAEStream::IncFreeBuffers()
@@ -88,10 +91,28 @@ unsigned int CActiveAEStream::AddData(void *data, unsigned int size)
Message *msg;
unsigned int copied = 0;
int bytesToCopy = size;
+ uint8_t *buf = (uint8_t*)data;
+
while(copied < size)
{
+ buf = (uint8_t*)data;
+ bytesToCopy = size - copied;
+
if (m_currentBuffer)
{
+ // fill leftover buffer and copy it first
+ if (m_leftoverBytes && bytesToCopy >= (m_format.m_frameSize - m_leftoverBytes))
+ {
+ int fillbytes = m_format.m_frameSize - m_leftoverBytes;
+ memcpy(m_leftoverBuffer+m_leftoverBytes, (uint8_t*)data, fillbytes);
+ data = (uint8_t*)data + fillbytes;
+ size -= fillbytes;
+ // leftover buffer will be copied on next cycle
+ buf = m_leftoverBuffer;
+ bytesToCopy = m_format.m_frameSize;
+ m_leftoverBytes = 0;
+ }
+
int start = m_currentBuffer->pkt->nb_samples *
m_currentBuffer->pkt->bytes_per_sample *
m_currentBuffer->pkt->config.channels /
@@ -99,20 +120,29 @@ unsigned int CActiveAEStream::AddData(void *data, unsigned int size)
int freeSamples = m_currentBuffer->pkt->max_nb_samples - m_currentBuffer->pkt->nb_samples;
int availableSamples = bytesToCopy / m_format.m_frameSize;
+
+ // if we don't have a full frame, copy to leftover buffer
+ if (!availableSamples && bytesToCopy)
+ {
+ memcpy(m_leftoverBuffer+m_leftoverBytes, buf+copied, bytesToCopy);
+ m_leftoverBytes = bytesToCopy;
+ copied += bytesToCopy;
+ }
+
int samples = std::min(freeSamples, availableSamples);
int bytes = samples * m_format.m_frameSize;
+
//TODO: handle planar formats
if (m_convertFn)
- m_convertFn((uint8_t*)data+copied, samples*m_currentBuffer->pkt->config.channels, (float*)(m_currentBuffer->pkt->data[0] + start));
+ m_convertFn(buf+copied, samples*m_currentBuffer->pkt->config.channels, (float*)(m_currentBuffer->pkt->data[0] + start));
else
- memcpy(m_currentBuffer->pkt->data[0] + start, (uint8_t*)data+copied, bytes);
+ memcpy(m_currentBuffer->pkt->data[0] + start, buf+copied, bytes);
{
CSingleLock lock(*m_statsLock);
m_currentBuffer->pkt->nb_samples += samples;
m_bufferedTime += (double)samples / m_currentBuffer->pkt->config.sample_rate;
}
copied += bytes;
- bytesToCopy -= bytes;
if (m_currentBuffer->pkt->nb_samples == m_currentBuffer->pkt->max_nb_samples)
{
MsgStreamSample msgData;
@@ -249,6 +279,7 @@ bool CActiveAEStream::IsDrained()
void CActiveAEStream::Flush()
{
m_currentBuffer = NULL;
+ m_leftoverBytes = 0;
AE.FlushStream(this);
ResetFreeBuffers();
}
View
2  xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.h
@@ -92,6 +92,8 @@ class CActiveAEStream : public IAEStream
IAEStream *m_streamSlave;
CAEConvert::AEConvertToFn m_convertFn;
CCriticalSection m_streamLock;
+ uint8_t *m_leftoverBuffer;
+ int m_leftoverBytes;
// only accessed by engine
CActiveAEBufferPool *m_inputBuffers;
View
8 xbmc/cores/paplayer/FLACcodec.cpp
@@ -311,17 +311,19 @@ void FLACCodec::DecoderMetadataCallback(const FLAC__StreamDecoder *decoder, cons
if (metadata->type==FLAC__METADATA_TYPE_STREAMINFO)
{
- static enum AEChannel map[6][7] = {
+ static enum AEChannel map[8][9] = {
{AE_CH_FC, AE_CH_NULL},
{AE_CH_FL, AE_CH_FR, AE_CH_NULL},
{AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_NULL},
{AE_CH_FL, AE_CH_FR, AE_CH_BL, AE_CH_BR, AE_CH_NULL},
{AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_BL, AE_CH_BR, AE_CH_NULL},
- {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BL, AE_CH_BR, AE_CH_NULL}
+ {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BL, AE_CH_BR, AE_CH_NULL}, // 6 channels
+ {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BC, AE_CH_BL, AE_CH_BR, AE_CH_NULL}, // 7 channels
+ {AE_CH_FL, AE_CH_FR, AE_CH_FC, AE_CH_LFE, AE_CH_BL, AE_CH_BR, AE_CH_SL, AE_CH_SR, AE_CH_NULL} // 8 channels
};
/* channel counts greater then 6 are undefined */
- if (metadata->data.stream_info.channels > 6)
+ if (metadata->data.stream_info.channels > 8)
pThis->m_ChannelInfo = CAEUtil::GuessChLayout(metadata->data.stream_info.channels);
else
pThis->m_ChannelInfo = CAEChannelInfo(map[metadata->data.stream_info.channels - 1]);
Please sign in to comment.
Something went wrong with that request. Please try again.