Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2879 from aballier/dvdaudioffmpeg_improvements2

Some improvements in the resampling code in DVDAudioCodecFFmpeg
  • Loading branch information...
commit 87ec33d6d6c80a5b6408905b93bada017f79b1a9 2 parents 377f2a7 + 3c6c0fc
Alexis Ballier aballier authored
38 xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
View
@@ -34,8 +34,8 @@ CDVDAudioCodecFFmpeg::CDVDAudioCodecFFmpeg() : CDVDAudioCodec()
{
m_iBufferSize1 = 0;
m_iBufferSize2 = 0;
- m_pBuffer2 = (uint8_t*)_aligned_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE, 16);
- memset(m_pBuffer2, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+ m_iBufferTotalSize2 = 0;
+ m_pBuffer2 = NULL;
m_iBuffered = 0;
m_pCodecContext = NULL;
@@ -54,7 +54,6 @@ CDVDAudioCodecFFmpeg::CDVDAudioCodecFFmpeg() : CDVDAudioCodec()
CDVDAudioCodecFFmpeg::~CDVDAudioCodecFFmpeg()
{
- _aligned_free(m_pBuffer2);
Dispose();
}
@@ -130,6 +129,9 @@ void CDVDAudioCodecFFmpeg::Dispose()
if (m_pConvert)
m_dllSwResample.swr_free(&m_pConvert);
+ if (m_pBuffer2)
+ m_dllAvUtil.av_freep(&m_pBuffer2);
+
if (m_pCodecContext)
{
if (m_bOpenedCodec) m_dllAvCodec.avcodec_close(m_pCodecContext);
@@ -144,6 +146,7 @@ void CDVDAudioCodecFFmpeg::Dispose()
m_iBufferSize1 = 0;
m_iBufferSize2 = 0;
+ m_iBufferTotalSize2 = 0;
m_iBuffered = 0;
}
@@ -152,7 +155,6 @@ int CDVDAudioCodecFFmpeg::Decode(uint8_t* pData, int iSize)
int iBytesUsed, got_frame;
if (!m_pCodecContext) return -1;
- m_iBufferSize1 = AVCODEC_MAX_AUDIO_FRAME_SIZE ;
m_iBufferSize2 = 0;
AVPacket avpkt;
@@ -212,8 +214,25 @@ void CDVDAudioCodecFFmpeg::ConvertToFloat()
}
}
- int len = m_iBufferSize1 / m_dllAvUtil.av_get_bytes_per_sample(m_pCodecContext->sample_fmt);
- if(m_dllSwResample.swr_convert(m_pConvert, &m_pBuffer2, len, (const uint8_t**)m_pFrame1->data, m_pFrame1->nb_samples) < 0)
+ int needed_buf_size = m_dllAvUtil.av_samples_get_buffer_size(NULL, m_pCodecContext->channels, m_pFrame1->nb_samples, AV_SAMPLE_FMT_FLT, 0);
+ if(m_iBufferTotalSize2 < needed_buf_size)
+ {
+ m_pBuffer2 = (uint8_t*)m_dllAvUtil.av_realloc(m_pBuffer2, needed_buf_size);
+ if(!m_pBuffer2)
+ {
+ CLog::Log(LOGERROR, "CDVDAudioCodecFFmpeg::Decode - Unable to allocate a %i bytes buffer for resampling", needed_buf_size);
+ m_iBufferSize1 = 0;
+ m_iBufferSize2 = 0;
+ m_iBufferTotalSize2 = 0;
+ return;
+ }
+ m_iBufferTotalSize2 = needed_buf_size;
+ }
+
+ int outsamples;
+ outsamples = m_dllSwResample.swr_convert(m_pConvert, &m_pBuffer2, m_iBufferTotalSize2, (const uint8_t**)m_pFrame1->extended_data, m_pFrame1->nb_samples);
+
+ if(outsamples < 0)
{
CLog::Log(LOGERROR, "CDVDAudioCodecFFmpeg::Decode - Unable to convert %d to AV_SAMPLE_FMT_FLT", (int)m_pCodecContext->sample_fmt);
m_iBufferSize1 = 0;
@@ -221,8 +240,13 @@ void CDVDAudioCodecFFmpeg::ConvertToFloat()
return;
}
+ if(outsamples < m_pFrame1->nb_samples)
+ {
+ CLog::Log(LOGWARNING, "CDVDAudioCodecFFmpeg::Decode - Resampler produced less samples than what it was given");
+ }
+
m_iBufferSize1 = 0;
- m_iBufferSize2 = len * m_dllAvUtil.av_get_bytes_per_sample(AV_SAMPLE_FMT_FLT);
+ m_iBufferSize2 = m_dllAvUtil.av_samples_get_buffer_size(NULL, m_pCodecContext->channels, m_pFrame1->nb_samples, AV_SAMPLE_FMT_FLT, 0);
}
}
1  xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h
View
@@ -57,6 +57,7 @@ class CDVDAudioCodecFFmpeg : public CDVDAudioCodec
int m_iBufferSize1;
uint8_t* m_pBuffer2;
int m_iBufferSize2;
+ int m_iBufferTotalSize2;
bool m_bOpenedCodec;
int m_iBuffered;
Please sign in to comment.
Something went wrong with that request. Please try again.