Permalink
Browse files

[dvdplayer]: Use the SwResample API.

This drops all usage of the private libavcodec::audiocovert API in xbmc.
  • Loading branch information...
1 parent 274679d commit 6fc07309d0e7f1ef93ded8706fe966dd0578d3a7 @aballier aballier committed Aug 14, 2012
View
29 xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
@@ -56,7 +56,7 @@ bool CDVDAudioCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
AVCodec* pCodec;
m_bOpenedCodec = false;
- if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load())
+ if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load() || !m_dllSwResample.Load())
return false;
m_dllAvCodec.avcodec_register_all();
@@ -118,10 +118,7 @@ void CDVDAudioCodecFFmpeg::Dispose()
m_pFrame1 = NULL;
if (m_pConvert)
- {
- m_dllAvCodec.av_audio_convert_free(m_pConvert);
- m_pConvert = NULL;
- }
+ m_dllSwResample.swr_free(&m_pConvert);
if (m_pCodecContext)
{
@@ -185,31 +182,27 @@ void CDVDAudioCodecFFmpeg::ConvertToFloat()
if(m_pCodecContext->sample_fmt != AV_SAMPLE_FMT_FLT && m_iBufferSize1 > 0)
{
if(m_pConvert && m_pCodecContext->sample_fmt != m_iSampleFormat)
- {
- m_dllAvCodec.av_audio_convert_free(m_pConvert);
- m_pConvert = NULL;
- }
+ m_dllSwResample.swr_free(&m_pConvert);
if(!m_pConvert)
{
m_iSampleFormat = m_pCodecContext->sample_fmt;
- m_pConvert = m_dllAvCodec.av_audio_convert_alloc(AV_SAMPLE_FMT_FLT, 1, m_pCodecContext->sample_fmt, 1, NULL, 0);
+ m_pConvert = m_dllSwResample.swr_alloc_set_opts(NULL,
+ m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels), AV_SAMPLE_FMT_FLT, m_pCodecContext->sample_rate,
+ m_dllAvUtil.av_get_default_channel_layout(m_pCodecContext->channels), m_pCodecContext->sample_fmt, m_pCodecContext->sample_rate,
+ 0, NULL);
}
- if(!m_pConvert)
+ if(!m_pConvert || m_dllSwResample.swr_init(m_pConvert) < 0)
{
CLog::Log(LOGERROR, "CDVDAudioCodecFFmpeg::Decode - Unable to convert %d to AV_SAMPLE_FMT_FLT", m_pCodecContext->sample_fmt);
m_iBufferSize1 = 0;
m_iBufferSize2 = 0;
return;
}
- const void *ibuf[6] = { m_pFrame1->data[0] };
- void *obuf[6] = { m_pBuffer2 };
- int istr[6] = { m_dllAvUtil.av_get_bytes_per_sample(m_pCodecContext->sample_fmt) };
- int ostr[6] = { m_dllAvUtil.av_get_bytes_per_sample(AV_SAMPLE_FMT_FLT) };
- int len = m_iBufferSize1 / istr[0];
- if(m_dllAvCodec.av_audio_convert(m_pConvert, obuf, ostr, ibuf, istr, len) < 0)
+ 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)
{
CLog::Log(LOGERROR, "CDVDAudioCodecFFmpeg::Decode - Unable to convert %d to AV_SAMPLE_FMT_FLT", (int)m_pCodecContext->sample_fmt);
m_iBufferSize1 = 0;
@@ -218,7 +211,7 @@ void CDVDAudioCodecFFmpeg::ConvertToFloat()
}
m_iBufferSize1 = 0;
- m_iBufferSize2 = len * ostr[0];
+ m_iBufferSize2 = len * av_get_bytes_per_sample(AV_SAMPLE_FMT_FLT);
}
}
View
4 xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h
@@ -25,6 +25,7 @@
#include "DllAvCodec.h"
#include "DllAvFormat.h"
#include "DllAvUtil.h"
+#include "DllSwResample.h"
class CDVDAudioCodecFFmpeg : public CDVDAudioCodec
{
@@ -47,7 +48,7 @@ class CDVDAudioCodecFFmpeg : public CDVDAudioCodec
protected:
AVCodecContext* m_pCodecContext;
- AVAudioConvert* m_pConvert;
+ SwrContext* m_pConvert;
enum AVSampleFormat m_iSampleFormat;
CAEChannelInfo m_channelLayout;
int m_iMapChannels;
@@ -66,6 +67,7 @@ class CDVDAudioCodecFFmpeg : public CDVDAudioCodec
DllAvCodec m_dllAvCodec;
DllAvUtil m_dllAvUtil;
+ DllSwResample m_dllSwResample;
void BuildChannelMap();
void ConvertToFloat();

0 comments on commit 6fc0730

Please sign in to comment.