Skip to content

Commit

Permalink
Merge pull request xbmc#1893 from huceke/raspberrypi
Browse files Browse the repository at this point in the history
Raspberrypi fixes
  • Loading branch information
davilla committed Dec 7, 2012
2 parents b6e17f5 + ab8d9e9 commit bea17d8
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 257 deletions.
132 changes: 40 additions & 92 deletions xbmc/cores/omxplayer/OMXAudio.cpp
Expand Up @@ -96,15 +96,14 @@ COMXAudio::COMXAudio() :
m_BitsPerSample (0 ),
m_omx_clock (NULL ),
m_av_clock (NULL ),
m_external_clock (false ),
m_first_frame (true ),
m_LostSync (true ),
m_SampleRate (0 ),
m_eEncoding (OMX_AUDIO_CodingPCM),
m_extradata (NULL ),
m_extrasize (0 ),
m_omx_render (NULL ),
m_last_pts (DVD_NOPTS_VALUE)
m_last_pts (DVD_NOPTS_VALUE),
m_omx_render (NULL )
{
m_vizBufferSize = m_vizRemapBufferSize = VIS_PACKET_SIZE * sizeof(float);
m_vizRemapBuffer = (uint8_t *)_aligned_malloc(m_vizRemapBufferSize,16);
Expand All @@ -113,8 +112,7 @@ COMXAudio::COMXAudio() :

COMXAudio::~COMXAudio()
{
if(m_Initialized)
Deinitialize();
Deinitialize();

_aligned_free(m_vizRemapBuffer);
_aligned_free(m_vizBuffer);
Expand Down Expand Up @@ -156,14 +154,27 @@ CAEChannelInfo COMXAudio::GetChannelLayout(AEAudioFormat format)

bool COMXAudio::Initialize(AEAudioFormat format, std::string& device, OMXClock *clock, CDVDStreamInfo &hints, bool bUsePassthrough, bool bUseHWDecode)
{
Deinitialize();

if(!m_dllAvUtil.Load())
return false;

m_HWDecode = bUseHWDecode;
m_Passthrough = bUsePassthrough;

m_format = format;

if(m_format.m_channelLayout.Count() == 0)
return false;

if(hints.samplerate == 0)
return false;

m_av_clock = clock;

if(!m_av_clock)
return false;

/* passthrough overwrites hw decode */
if(m_Passthrough)
{
Expand All @@ -176,55 +187,14 @@ bool COMXAudio::Initialize(AEAudioFormat format, std::string& device, OMXClock *
}
SetCodingType(format.m_dataFormat);

SetClock(clock);

if(hints.extrasize > 0 && hints.extradata != NULL)
{
m_extrasize = hints.extrasize;
m_extradata = (uint8_t *)malloc(m_extrasize);
memcpy(m_extradata, hints.extradata, hints.extrasize);
}

return Initialize(format, device);
}

bool COMXAudio::Initialize(AEAudioFormat format, std::string& device)
{
if(m_Initialized)
Deinitialize();

m_format = format;

if(m_format.m_channelLayout.Count() == 0)
return false;

if(!m_dllAvUtil.Load())
return false;

if(m_av_clock == NULL)
{
/* no external clock set. generate one */
m_external_clock = false;

m_av_clock = new OMXClock();

if(!m_av_clock->OMXInitialize(false, true))
{
delete m_av_clock;
m_av_clock = NULL;
CLog::Log(LOGERROR, "COMXAudio::Initialize error creating av clock\n");
return false;
}
}

m_omx_clock = m_av_clock->GetOMXClock();

/*
m_Passthrough = false;
if(OMX_IS_RAW(m_format.m_dataFormat))
m_Passthrough =true;
*/
m_omx_clock = m_av_clock->GetOMXClock();

m_drc = 0;

Expand Down Expand Up @@ -342,7 +312,9 @@ bool COMXAudio::Initialize(AEAudioFormat format, std::string& device)
std::string componentName = "";

componentName = "OMX.broadcom.audio_render";
m_omx_render = new COMXCoreComponent();

if(!m_omx_render)
m_omx_render = new COMXCoreComponent();
if(!m_omx_render)
{
CLog::Log(LOGERROR, "COMXAudio::Initialize error allocate OMX.broadcom.audio_render\n");
Expand Down Expand Up @@ -441,16 +413,6 @@ bool COMXAudio::Initialize(AEAudioFormat format, std::string& device)
return false;
}

if(!m_external_clock)
{
omx_err = m_omx_clock->SetStateForComponent(OMX_StateExecuting);
if (omx_err != OMX_ErrorNone)
{
CLog::Log(LOGERROR, "COMXAudio::Initialize m_omx_clock.SetStateForComponent\n");
return false;
}
}

omx_err = m_omx_decoder.AllocInputBuffers();
if(omx_err != OMX_ErrorNone)
{
Expand Down Expand Up @@ -575,6 +537,10 @@ bool COMXAudio::Initialize(AEAudioFormat format, std::string& device)
}
}

/* return on decoder error so m_Initialized stays false */
if(m_omx_decoder.BadState())
return false;

m_Initialized = true;
m_first_frame = true;
m_last_pts = DVD_NOPTS_VALUE;
Expand All @@ -585,56 +551,46 @@ bool COMXAudio::Initialize(AEAudioFormat format, std::string& device)
(int)m_pcm_output.nBitPerSample, (int)m_pcm_output.nSamplingRate, (int)m_pcm_output.nChannels, m_BufferLen, m_BytesPerSec);
CLog::Log(LOGDEBUG, "COMXAudio::Initialize Input bps %d samplerate %d channels %d buffer size %d bytes per second %d",
(int)m_pcm_input.nBitPerSample, (int)m_pcm_input.nSamplingRate, (int)m_pcm_input.nChannels, m_BufferLen, m_BytesPerSec);
CLog::Log(LOGDEBUG, "COMXAudio::Initialize device %s passthrough %d hwdecode %d external clock %d",
device.c_str(), m_Passthrough, m_HWDecode, m_external_clock);

m_av_clock->OMXStateExecute(false);
CLog::Log(LOGDEBUG, "COMXAudio::Initialize device %s passthrough %d hwdecode %d",
device.c_str(), m_Passthrough, m_HWDecode);

return true;
}

//***********************************************************************************************
bool COMXAudio::Deinitialize()
{
if(!m_Initialized)
return true;

CSingleLock lock (m_critSection);

if(m_av_clock && !m_external_clock)
{
m_av_clock->Lock();
m_av_clock->OMXStop(false);
}

m_omx_tunnel_decoder.Flush();
if(!m_Passthrough)
m_omx_tunnel_mixer.Flush();
m_omx_tunnel_clock.Flush();

m_omx_tunnel_clock.Deestablish();
if(!m_Passthrough)
m_omx_tunnel_mixer.Deestablish();
{
// workaround for the strange BCM mixer component
if(m_omx_mixer.GetState() == OMX_StateExecuting)
m_omx_mixer.SetStateForComponent(OMX_StatePause);
if(m_omx_mixer.GetState() != OMX_StateIdle)
m_omx_mixer.SetStateForComponent(OMX_StateIdle);
m_omx_mixer.DisableAllPorts();
m_omx_tunnel_mixer.Deestablish(true);
}
m_omx_tunnel_decoder.Deestablish();

m_omx_decoder.FlushInput();

m_omx_render->Deinitialize();
if(m_omx_render)
m_omx_render->Deinitialize();
if(!m_Passthrough)
m_omx_mixer.Deinitialize();
m_omx_decoder.Deinitialize();

m_BytesPerSec = 0;
m_BufferLen = 0;

if(m_av_clock && !m_external_clock)
{
m_av_clock->OMXReset(false);
m_av_clock->UnLock();
delete m_av_clock;
m_external_clock = false;
}

m_omx_clock = NULL;
m_av_clock = NULL;

Expand Down Expand Up @@ -852,7 +808,7 @@ unsigned int COMXAudio::AddPackets(const void* data, unsigned int len, double dt

m_last_pts = pts;

CLog::Log(LOGDEBUG, "ADec : setStartTime %f\n", (float)val / DVD_TIME_BASE);
CLog::Log(LOGDEBUG, "COMXAudio::Decode ADec : setStartTime %f\n", (float)val / DVD_TIME_BASE);
m_av_clock->AudioStart(false);
}
else
Expand Down Expand Up @@ -1209,6 +1165,8 @@ void COMXAudio::WaitCompletion()
nTimeOut -= 50;
}

m_omx_render->ResetEos();

return;
}

Expand All @@ -1217,16 +1175,6 @@ void COMXAudio::SwitchChannels(int iAudioStream, bool bAudioOnAllSpeakers)
return ;
}

bool COMXAudio::SetClock(OMXClock *clock)
{
if(m_av_clock != NULL)
return false;

m_av_clock = clock;
m_external_clock = true;
return true;
}

void COMXAudio::SetCodingType(AEDataFormat dataFormat)
{
switch(dataFormat)
Expand Down
5 changes: 2 additions & 3 deletions xbmc/cores/omxplayer/OMXAudio.h
Expand Up @@ -61,7 +61,6 @@ class COMXAudio
float GetCacheTotal();
COMXAudio();
bool Initialize(AEAudioFormat format, std::string& device, OMXClock *clock, CDVDStreamInfo &hints, bool bUsePassthrough, bool bUseHWDecode);
bool Initialize(AEAudioFormat format, std::string& device);
~COMXAudio();

unsigned int AddPackets(const void* data, unsigned int len);
Expand All @@ -84,7 +83,6 @@ class COMXAudio

void Process();

bool SetClock(OMXClock *clock);
void SetCodingType(AEDataFormat dataFormat);
static bool CanHWDecode(CodecID codec);

Expand All @@ -95,6 +93,8 @@ class COMXAudio
unsigned int SyncDTS(BYTE* pData, unsigned int iSize);
unsigned int SyncAC3(BYTE* pData, unsigned int iSize);

bool BadState() { return !m_Initialized; };

private:
IAudioCallback* m_pCallback;
bool m_Initialized;
Expand All @@ -111,7 +111,6 @@ class COMXAudio
unsigned int m_BitsPerSample;
COMXCoreComponent *m_omx_clock;
OMXClock *m_av_clock;
bool m_external_clock;
bool m_first_frame;
bool m_LostSync;
int m_SampleRate;
Expand Down
6 changes: 6 additions & 0 deletions xbmc/cores/omxplayer/OMXImage.cpp
Expand Up @@ -830,6 +830,9 @@ bool COMXImage::Decode(unsigned width, unsigned height)

m_omx_tunnel_decode.Deestablish();

if(m_omx_decoder.BadState())
return false;

return true;
}

Expand Down Expand Up @@ -1007,6 +1010,9 @@ bool COMXImage::Encode(unsigned char *buffer, int size, unsigned width, unsigned
return false;
}

if(m_omx_encoder.BadState())
return false;

return true;
}

Expand Down

0 comments on commit bea17d8

Please sign in to comment.