IAudioRenderer* CAudioRendererFactory::CreateAudioRenderer(IAudioCallback* pCallback, int iChannels, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, const char* strAudioCodec, bool bIsMusic, bool bPassthrough)
{
  IAudioRenderer* audioSink = NULL;

/* First pass creation */
#ifdef HAS_PULSEAUDIO
  audioSink = new CPulseAudioDirectSound();
  ReturnOnValidInitialize();
#endif

/* incase none in the first pass was able to be created, fall back to os specific */

#ifdef WIN32
  audioSink = new CWin32DirectSound();
  ReturnOnValidInitialize();
#endif
#ifdef __APPLE__
  audioSink = new PortAudioDirectSound();
  ReturnOnValidInitialize();
#elif defined(_LINUX)
  audioSink = new CALSADirectSound();
  ReturnOnValidInitialize();
#endif

  audioSink = new CNullDirectSound();
  audioSink->Initialize(pCallback, iChannels, uiSamplesPerSec, uiBitsPerSample, bResample, strAudioCodec, bIsMusic, bPassthrough);
  return audioSink;
}
Beispiel #2
0
IAudioRenderer* CAudioRendererFactory::CreateAudioRenderer(IAudioCallback* pCallback, int iChannels, enum PCMChannels* channelMap, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, const char* strAudioCodec, bool bIsMusic, bool bPassthrough, bool bTimed, AudioMediaFormat audioMediaFormat)
{
  IAudioRenderer* audioSink = NULL;

/* in case none in the first pass was able to be created, fall back to os specific */

#ifdef WIN32
/*  if (bPassthrough)
  {
    audioSink = new CWin32WASAPI();
    ReturnOnValidInitialize();
  }
  else
  {*/
  audioSink = new CWin32DirectSound();
  ReturnOnValidInitialize();
#elif defined(__APPLE__)
  audioSink = new CCoreAudioRenderer();
  ReturnOnValidInitialize();
#elif defined(HAS_INTEL_SMD)
  audioSink = new CIntelSMDAudioRenderer();
  ReturnOnValidInitialize();
#elif defined(HAS_ALSA)
  int requestedLibrary = g_guiSettings.GetInt("audiooutput.library");
  if (requestedLibrary == AUDIO_LIBRARY_ALSA)
  {
    audioSink = new CALSADirectSound();
    ReturnOnValidInitialize();
  }
#endif

  audioSink = new CNullDirectSound();
  audioSink->Initialize(pCallback, iChannels, channelMap, uiSamplesPerSec, uiBitsPerSample, bResample, strAudioCodec, bIsMusic, bPassthrough, bTimed, audioMediaFormat);
  return audioSink;
}
IAudioRenderer* CAudioRendererFactory::Create(IAudioCallback* pCallback, int iChannels, enum PCMChannels *channelMap, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool bIsMusic, IAudioRenderer::EEncoded encoded, bool bAudio2)
{
  IAudioRenderer* audioSink = NULL;
  CStdString renderer;

  if(channelMap == NULL)
  {
    CLog::Log(LOGINFO, "CAudioRendererFactory: no input channel map specified assume windows\n");
    channelMap = (enum PCMChannels *)dsound_default_channel_layout[iChannels - 1];
  }

  CStdString deviceString, device;
  if (!bAudio2)
  {
    if (encoded)
    {
  #if defined(_LINUX) && !defined(__APPLE__)
      deviceString = g_guiSettings.GetString("audiooutput.passthroughdevice");
      if (deviceString.Equals("custom"))
        deviceString = g_guiSettings.GetString("audiooutput.custompassthrough");
  #else
      // osx/win platforms do not have an "audiooutput.passthroughdevice" setting but can do passthrough
      deviceString = g_guiSettings.GetString("audiooutput.audiodevice");
  #endif
    }
    else
    {
      deviceString = g_guiSettings.GetString("audiooutput.audiodevice");
      if (deviceString.Equals("custom"))
        deviceString = g_guiSettings.GetString("audiooutput.customdevice");
    }
  }
  else
  {
    if (encoded)
    {
#if defined(_LINUX) && !defined(__APPLE__)
      deviceString = g_guiSettings.GetString("audiooutput2.passthroughdevice");
      if (deviceString.Equals("custom"))
        deviceString = g_guiSettings.GetString("audiooutput2.custompassthrough");
#else
      // osx/win platforms do not have an "audiooutput.passthroughdevice" setting but can do passthrough
      deviceString = g_guiSettings.GetString("audiooutput2.audiodevice");
#endif
    }
    else
    {
      deviceString = g_guiSettings.GetString("audiooutput2.audiodevice");
      if (deviceString.Equals("custom"))
        deviceString = g_guiSettings.GetString("audiooutput2.customdevice");
    }
  }
  int iPos = deviceString.Find(":");
  if (iPos > 0)
  {
    audioSink = CreateFromUri(deviceString.Left(iPos), renderer, bAudio2);
    if (audioSink)
    {
      device = deviceString.Right(deviceString.length() - iPos - 1);
      ReturnOnValidInitialize(renderer.c_str());

#ifdef _WIN32
      //If WASAPI failed try DirectSound.
      if(deviceString.Left(iPos).Equals("wasapi"))
      {
        audioSink = CreateFromUri("directsound", renderer, bAudio2);
        ReturnOnValidInitialize(renderer.c_str());
      }
#endif

      CreateAndReturnOnValidInitialize(CNullDirectSound, bAudio2);
      /* should never get here */
      assert(false);
    }
  }
  CLog::Log(LOGINFO, "AudioRendererFactory: %s not a explicit device, trying to autodetect.", device.c_str());

  device = deviceString;

/* First pass creation */
#ifdef HAS_PULSEAUDIO
  CreateAndReturnOnValidInitialize(CPulseAudioDirectSound, bAudio2);
#endif

/* incase none in the first pass was able to be created, fall back to os specific */
#ifdef WIN32
  CreateAndReturnOnValidInitialize(CWin32DirectSound, bAudio2);
#endif
#if defined(__APPLE__)
  #if defined(__arm__)
    CreateAndReturnOnValidInitialize(CIOSAudioRenderer, bAudio2);
  #else
    CreateAndReturnOnValidInitialize(CCoreAudioRenderer, bAudio2);
  #endif
#elif defined(USE_ALSA)
  CreateAndReturnOnValidInitialize(CALSADirectSound, bAudio2);
#endif

  CreateAndReturnOnValidInitialize(CNullDirectSound, bAudio2);
  /* should never get here */
  assert(false);
  return NULL;
}