Skip to content

Commit

Permalink
AE: pass entire AEAudioFormat to MakeStream
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Nov 17, 2015
1 parent b488d90 commit 6099c4a
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 42 deletions.
8 changes: 4 additions & 4 deletions addons/library.kodi.audioengine/libKODI_audioengine.h
Expand Up @@ -103,7 +103,7 @@ class CHelper_libKODI_audioengine
dlsym(m_libKODI_audioengine, "AudioEngine_unregister_me");
if (AudioEngine_unregister_me == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }

AudioEngine_MakeStream = (CAddonAEStream* (*)(void*, void*, AEDataFormat, unsigned int, enum AEChannel*, unsigned int))
AudioEngine_MakeStream = (CAddonAEStream* (*)(void*, void*, AudioEngineFormat, unsigned int))
dlsym(m_libKODI_audioengine, "AudioEngine_make_stream");
if (AudioEngine_MakeStream == NULL) { fprintf(stderr, "Unable to assign function %s\n", dlerror()); return false; }

Expand All @@ -127,9 +127,9 @@ class CHelper_libKODI_audioengine
* @param Options A bit field of stream options (see: enum AEStreamOptions)
* @return a new Handle to an IAEStream that will accept data in the requested format
*/
CAddonAEStream* MakeStream(AEDataFormat DataFormat, unsigned int SampleRate, CAEChannelInfo &ChannelLayout, unsigned int Options = 0)
CAddonAEStream* MakeStream(AudioEngineFormat Format, unsigned int Options = 0)
{
return AudioEngine_MakeStream(m_Handle, m_Callbacks, DataFormat, SampleRate, ChannelLayout.m_channels, Options);
return AudioEngine_MakeStream(m_Handle, m_Callbacks, Format, Options);
}

/**
Expand Down Expand Up @@ -158,7 +158,7 @@ class CHelper_libKODI_audioengine
protected:
void* (*AudioEngine_register_me)(void*);
void (*AudioEngine_unregister_me)(void*, void*);
CAddonAEStream* (*AudioEngine_MakeStream)(void*, void*, AEDataFormat, unsigned int, enum AEChannel*, unsigned int);
CAddonAEStream* (*AudioEngine_MakeStream)(void*, void*, AudioEngineFormat, unsigned int);
bool (*AudioEngine_GetCurrentSinkFormat)(void*, void*, AudioEngineFormat *SinkFormat);
void (*AudioEngine_FreeStream)(CAddonAEStream*);

Expand Down
4 changes: 2 additions & 2 deletions lib/addons/library.kodi.audioengine/libKODI_audioengine.cpp
Expand Up @@ -62,15 +62,15 @@ DLLEXPORT void AudioEngine_unregister_me(void *hdl, void* cb)
// ---------------------------------------------
// CAddonAEStream implementations
// ---------------------------------------------
DLLEXPORT CAddonAEStream* AudioEngine_make_stream(void *hdl, void *cb, AEDataFormat DataFormat, unsigned int SampleRate, enum AEChannel *Channels, unsigned int Options)
DLLEXPORT CAddonAEStream* AudioEngine_make_stream(void *hdl, void *cb, AudioEngineFormat Format, unsigned int Options)
{
if (!hdl || !cb)
{
fprintf(stderr, "%s-ERROR: AudioEngine_register_me is called with NULL handle !!!\n", LIBRARY_NAME);
return NULL;
}

AEStreamHandle *streamHandle = ((CB_AudioEngineLib*)cb)->MakeStream(DataFormat, SampleRate, Channels, Options);
AEStreamHandle *streamHandle = ((CB_AudioEngineLib*)cb)->MakeStream(Format, Options);
if (!streamHandle)
{
fprintf(stderr, "%s-ERROR: AudioEngine_make_stream MakeStream failed!\n", LIBRARY_NAME);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/addons/AddonCallbacks.h
Expand Up @@ -402,7 +402,7 @@ typedef struct CB_ADSPLib
// ---------------------------------------
// libKODI_audioengine definitions
// ---------------------------------------
typedef AEStreamHandle* (*AudioEngine_MakeStream)(AEDataFormat DataFormat, unsigned int SampleRate, enum AEChannel *ChannelLayout, unsigned int Options);
typedef AEStreamHandle* (*AudioEngine_MakeStream)(AudioEngineFormat Format, unsigned int Options);
typedef void (*AudioEngine_FreeStream)(AEStreamHandle *stream);
typedef bool (*AudioEngine_GetCurrentSinkFormat)(void *addonData, AudioEngineFormat *SinkFormat);

Expand Down
15 changes: 6 additions & 9 deletions xbmc/addons/AddonCallbacksAudioEngine.cpp
Expand Up @@ -64,16 +64,13 @@ CAddonCallbacksAudioEngine::CAddonCallbacksAudioEngine(CAddon* addon)
m_callbacks->AEStream_Discontinuity = AEStream_Discontinuity;
}

AEStreamHandle* CAddonCallbacksAudioEngine::AudioEngine_MakeStream(AEDataFormat DataFormat, unsigned int SampleRate, enum AEChannel *Channels, unsigned int Options)
AEStreamHandle* CAddonCallbacksAudioEngine::AudioEngine_MakeStream(AudioEngineFormat StreamFormat, unsigned int Options)

This comment has been minimized.

Copy link
@FernetMenta

FernetMenta Nov 17, 2015

Author Owner

@AchimTuran please check if something got broken here. Not ideal that AEAudioFormat is almost duplicated here. The struct has changed

This comment has been minimized.

Copy link
@AlwinEsch

AlwinEsch Nov 25, 2015

Hi @FernetMenta I'm still working on the libraries rework. Has seen this places and planed on end to change as much as possible to use own library parts to prevent add-on problems on changes inside kodi.

Want to use inside kodi something like a translation functions where the kodi format becomes changes to the own add-on format.

This comment has been minimized.

Copy link
@FernetMenta

FernetMenta Nov 26, 2015

Author Owner

do you wnat me to do anything in this case?

This comment has been minimized.

Copy link
@AlwinEsch

AlwinEsch Nov 26, 2015

No, not direct. With my planned changes where the add-on have a own format is to reduce API level changes.

The probability for changes on headers in kodi is higher as on add-on's itself. Want to have the binary add-on's still usable with any changes on Kodi itself.

This comment has been minimized.

Copy link
@AchimTuran

AchimTuran Nov 26, 2015

@FernetMenta
sorry that I didn't responde to your ping until yet. Currently my adsp.xconvolver addon, which uses the library is not working. Thats why I don't have a possibility for testing. But if you break something I will fix it.

@AlwinEsch
I'm thinking about dropping that extra header file and the translation. When something is changed in core you have to adapt it on the addon side. I think it would make more sense if you bump the addon API and use only headers that are stable.

{
if (!Channels)
{
CLog::Log(LOGERROR, "CAddonCallbacksAudioEngine - %s - Invalid input! Channels is a NULL pointer!", __FUNCTION__);
return NULL;
}

CAEChannelInfo channelInfo(Channels);
return CAEFactory::MakeStream(DataFormat, SampleRate, channelInfo, Options);
AEAudioFormat format;
format.m_dataFormat = StreamFormat.m_dataFormat;
format.m_sampleRate = StreamFormat.m_sampleRate;
format.m_channelLayout = StreamFormat.m_channels;
return CAEFactory::MakeStream(format, Options);
}

void CAddonCallbacksAudioEngine::AudioEngine_FreeStream(AEStreamHandle *StreamHandle)
Expand Down
6 changes: 2 additions & 4 deletions xbmc/addons/AddonCallbacksAudioEngine.h
Expand Up @@ -41,13 +41,11 @@ class CAddonCallbacksAudioEngine

/**
* Creates and returns a new handle to an IAEStream in the format specified, this function should never fail
* @param dataFormat The data format the incoming audio will be in (eg, AE_FMT_S16LE)
* @param sampleRate The sample rate of the audio data (eg, 48000)
* @param channelLayout The order of the channels in the audio data
* @param audioFormat
* @param options A bit field of stream options (see: enum AEStreamOptions)
* @return a new Handle to an IAEStream that will accept data in the requested format
*/
static AEStreamHandle* AudioEngine_MakeStream(AEDataFormat DataFormat, unsigned int SampleRate, enum AEChannel *Channels, unsigned int Options);
static AEStreamHandle* AudioEngine_MakeStream(AudioEngineFormat StreamFormat, unsigned int Options);

/**
* This method will remove the specifyed stream from the engine.
Expand Down
5 changes: 2 additions & 3 deletions xbmc/cores/AudioEngine/AEFactory.cpp
Expand Up @@ -277,11 +277,10 @@ void CAEFactory::Shutdown()
AE->Shutdown();
}

IAEStream *CAEFactory::MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate,
CAEChannelInfo channelLayout, unsigned int options, IAEClockCallback *clock)
IAEStream *CAEFactory::MakeStream(AEAudioFormat &audioFormat, unsigned int options, IAEClockCallback *clock)
{
if(AE)
return AE->MakeStream(dataFormat, sampleRate, channelLayout, options, clock);
return AE->MakeStream(audioFormat, options, clock);

return NULL;
}
Expand Down
3 changes: 1 addition & 2 deletions xbmc/cores/AudioEngine/AEFactory.h
Expand Up @@ -60,8 +60,7 @@ class CAEFactory
static float GetVolume();
static void SetVolume(const float volume);
static void Shutdown();
static IAEStream *MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate,
CAEChannelInfo channelLayout, unsigned int options = 0, IAEClockCallback *clock = NULL);
static IAEStream *MakeStream(AEAudioFormat &audioFormat, unsigned int options = 0, IAEClockCallback *clock = NULL);
static bool FreeStream(IAEStream *stream);
static void GarbageCollect();

Expand Down
7 changes: 2 additions & 5 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp
Expand Up @@ -3086,17 +3086,14 @@ bool CActiveAE::ResampleSound(CActiveAESound *sound)
// Streams
//-----------------------------------------------------------------------------

IAEStream *CActiveAE::MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate, CAEChannelInfo& channelLayout, unsigned int options, IAEClockCallback *clock)
IAEStream *CActiveAE::MakeStream(AEAudioFormat &audioFormat, unsigned int options, IAEClockCallback *clock)
{
if (IsSuspended())
return NULL;

//TODO: pass number of samples in audio packet

AEAudioFormat format;
format.m_dataFormat = dataFormat;
format.m_sampleRate = sampleRate;
format.m_channelLayout = channelLayout;
AEAudioFormat format = audioFormat;
format.m_frames = format.m_sampleRate / 10;
format.m_frameSize = format.m_channelLayout.Count() *
(CAEUtil::DataFormatToBits(format.m_dataFormat) >> 3);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h
Expand Up @@ -237,7 +237,7 @@ class CActiveAE : public IAE, private CThread
virtual void SetSoundMode(const int mode);

/* returns a new stream for data in the specified format */
virtual IAEStream *MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate, CAEChannelInfo& channelLayout, unsigned int options = 0, IAEClockCallback *clock = NULL);
virtual IAEStream *MakeStream(AEAudioFormat &audioFormat, unsigned int options = 0, IAEClockCallback *clock = NULL);
virtual bool FreeStream(IAEStream *stream);

/* returns a new sound object */
Expand Down
6 changes: 2 additions & 4 deletions xbmc/cores/AudioEngine/Interfaces/AE.h
Expand Up @@ -153,13 +153,11 @@ class IAE

/**
* Creates and returns a new IAEStream in the format specified, this function should never fail
* @param dataFormat The data format the incoming audio will be in (eg, AE_FMT_S16LE)
* @param sampleRate The sample rate of the audio data (eg, 48000)
* @param channelLayout The order of the channels in the audio data
* @param audioFormat
* @param options A bit field of stream options (see: enum AEStreamOptions)
* @return a new IAEStream that will accept data in the requested format
*/
virtual IAEStream *MakeStream(enum AEDataFormat dataFormat, unsigned int sampleRate, CAEChannelInfo& channelLayout, unsigned int options = 0, IAEClockCallback *clock = NULL) = 0;
virtual IAEStream *MakeStream(AEAudioFormat &audioFormat, unsigned int options = 0, IAEClockCallback *clock = NULL) = 0;

/**
* This method will remove the specifyed stream from the engine.
Expand Down
3 changes: 2 additions & 1 deletion xbmc/cores/AudioEngine/Utils/AEUtil.cpp
Expand Up @@ -123,7 +123,8 @@ const unsigned int CAEUtil::DataFormatToBits(const enum AEDataFormat dataFormat)

sizeof(double) << 3, /* DOUBLE */
sizeof(float ) << 3, /* FLOAT */


16, /* RAW */
16, /* AAC */
16, /* AC3 */
16, /* DTS */
Expand Down
9 changes: 6 additions & 3 deletions xbmc/cores/VideoPlayer/DVDAudio.cpp
Expand Up @@ -25,6 +25,7 @@
#include "DVDCodecs/Audio/DVDAudioCodec.h"
#include "cores/AudioEngine/AEFactory.h"
#include "cores/AudioEngine/Interfaces/AEStream.h"
#include "cores/AudioEngine/Utils/AEAudioFormat.h"
#include "settings/MediaSettings.h"

CDVDAudio::CDVDAudio(volatile bool &bStop, CDVDClock *clock) : m_bStop(bStop), m_pClock(clock)
Expand Down Expand Up @@ -63,10 +64,12 @@ bool CDVDAudio::Create(const DVDAudioFrame &audioframe, AVCodecID codec, bool ne
unsigned int options = needresampler && !audioframe.passthrough ? AESTREAM_FORCE_RESAMPLE : 0;
options |= AESTREAM_PAUSED;

AEAudioFormat format;
format.m_dataFormat = audioframe.data_format;
format.m_sampleRate = audioframe.sample_rate;
format.m_channelLayout = audioframe.channel_layout;
m_pAudioStream = CAEFactory::MakeStream(
audioframe.data_format,
audioframe.sample_rate,
audioframe.channel_layout,
format,
options,
this
);
Expand Down
8 changes: 5 additions & 3 deletions xbmc/cores/paplayer/PAPlayer.cpp
Expand Up @@ -475,10 +475,12 @@ inline bool PAPlayer::PrepareStream(StreamInfo *si)
return true;

/* get a paused stream */
AEAudioFormat format;
format.m_dataFormat = si->m_dataFormat;
format.m_sampleRate = si->m_sampleRate;
format.m_channelLayout = si->m_channelInfo;
si->m_stream = CAEFactory::MakeStream(
si->m_dataFormat,
si->m_sampleRate,
si->m_channelInfo,
format,
AESTREAM_PAUSED
);

Expand Down

0 comments on commit 6099c4a

Please sign in to comment.