Exemple #1
0
AEDataFormat OMXPlayerAudio::GetDataFormat(CDVDStreamInfo hints)
{
  AEDataFormat dataFormat = AE_FMT_S16NE;
  bool hdmi_passthrough_dts = false;
  bool hdmi_passthrough_ac3 = false;

  if (m_DllBcmHost.vc_tv_hdmi_audio_supported(EDID_AudioFormat_eAC3, 2, EDID_AudioSampleRate_e44KHz, EDID_AudioSampleSize_16bit ) == 0)
    hdmi_passthrough_ac3 = true;
  if (m_DllBcmHost.vc_tv_hdmi_audio_supported(EDID_AudioFormat_eDTS, 2, EDID_AudioSampleRate_e44KHz, EDID_AudioSampleSize_16bit ) == 0)
    hdmi_passthrough_dts = true;

  m_passthrough = false;
  m_hw_decode   = false;

  /* check our audio capabilties */

  /* pathrought is overriding hw decode*/
  if(AUDIO_IS_BITSTREAM(CSettings::Get().GetInt("audiooutput.mode")) && m_use_passthrough)
  {
    if(hints.codec == AV_CODEC_ID_AC3 && CSettings::Get().GetBool("audiooutput.ac3passthrough") && hdmi_passthrough_ac3)
    {
      dataFormat = AE_FMT_AC3;
      m_passthrough = true;
    }
    if(hints.codec == AV_CODEC_ID_DTS && CSettings::Get().GetBool("audiooutput.dtspassthrough") && hdmi_passthrough_dts)
    {
      dataFormat = AE_FMT_DTS;
      m_passthrough = true;
    }
  }

  /* hw decode */
  if(m_use_hw_decode && !m_passthrough)
  {
    if(hints.codec == AV_CODEC_ID_AC3 && COMXAudio::CanHWDecode(m_hints.codec))
    {
      dataFormat = AE_FMT_AC3;
      m_hw_decode = true;
    }
    if(hints.codec == AV_CODEC_ID_DTS && COMXAudio::CanHWDecode(m_hints.codec))
    {
      dataFormat = AE_FMT_DTS;
      m_hw_decode = true;
    }
  }

  /* software path */
  if(!m_passthrough && !m_hw_decode)
  {
    if (m_pAudioCodec && m_pAudioCodec->GetBitsPerSample() == 16)
      dataFormat = AE_FMT_S16NE;
    else
      dataFormat = AE_FMT_FLOAT;
  }

  return dataFormat;
}
Exemple #2
0
// \brief set a new speaker config
void CAudioContext::SetupSpeakerConfig(int iChannels, bool& bAudioOnAllSpeakers, bool bIsMusic)
{
  m_bAC3EncoderActive = false;
  bAudioOnAllSpeakers = false;

#ifdef HAS_AUDIO
  return; //not implemented
  DWORD spconfig = DSSPEAKER_USE_DEFAULT;
  if (AUDIO_IS_BITSTREAM(g_guiSettings.GetInt("audiooutput.mode")))
  {
    if (g_settings.m_currentVideoSettings.m_OutputToAllSpeakers && !bIsMusic)
    {
      bAudioOnAllSpeakers = true;
      m_bAC3EncoderActive = true;
      spconfig = DSSPEAKER_USE_DEFAULT; //Allows ac3 encoder should it be enabled
    }
    else
    {
      if (iChannels == 1)
        spconfig = DSSPEAKER_MONO;
      else if (iChannels == 2)
        spconfig = DSSPEAKER_STEREO;
      else
        spconfig = DSSPEAKER_USE_DEFAULT; //Allows ac3 encoder should it be enabled
    }
  }
  else // We don't want to use the Dolby Digital Encoder output. Downmix to surround instead.
  {
    if (iChannels == 1)
      spconfig = DSSPEAKER_MONO;
    else
    {
      // check if surround mode is allowed, if not then use normal stereo
      // don't always set it to default as that enabled ac3 encoder if that is allowed in dash
      // ruining quality
      spconfig = DSSPEAKER_STEREO;
    }
  }

  DWORD spconfig_old = DSSPEAKER_USE_DEFAULT;
  if(m_pDirectSoundDevice)
  {
    m_pDirectSoundDevice->GetSpeakerConfig(&spconfig_old);
    spconfig_old = DSSPEAKER_CONFIG(spconfig_old);
  }

  /* speaker config identical, no need to do anything */
  if(spconfig == spconfig_old) return;
  CLog::Log(LOGDEBUG, "%s - Speakerconfig changed from %i to %i", __FUNCTION__, spconfig_old, spconfig);
#endif

  /* speaker config has changed, caller need to recreate it */
  RemoveActiveDevice();
}
bool CDVDAudioCodecPassthrough::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
{
    /* dont open if AE doesnt support RAW */
    if (!CAEFactory::SupportsRaw())
        return false;

    bool bSupportsAC3Out    = false;
    bool bSupportsEAC3Out   = false;
    bool bSupportsDTSOut    = false;
    bool bSupportsTrueHDOut = false;
    bool bSupportsDTSHDOut  = false;

    int audioMode = CSettings::Get().GetInt("audiooutput.mode");
    if (AUDIO_IS_BITSTREAM(audioMode))
    {
        bSupportsAC3Out = CSettings::Get().GetBool("audiooutput.ac3passthrough");
        bSupportsEAC3Out = CSettings::Get().GetBool("audiooutput.eac3passthrough");
        bSupportsDTSOut = CSettings::Get().GetBool("audiooutput.dtspassthrough");
    }

    if (audioMode == AUDIO_HDMI)
    {
        bSupportsTrueHDOut = CSettings::Get().GetBool("audiooutput.truehdpassthrough");
        bSupportsDTSHDOut  = CSettings::Get().GetBool("audiooutput.dtshdpassthrough" ) && bSupportsDTSOut;
    }

    /* only get the dts core from the parser if we don't support dtsHD */
    m_info.SetCoreOnly(!bSupportsDTSHDOut);
    m_bufferSize = 0;

    /* 32kHz E-AC-3 passthrough requires 128kHz IEC 60958 stream
     * which HDMI does not support, and IEC 61937 does not mention
     * reduced sample rate support, so support only 44.1 and 48 */
    if ((hints.codec == AV_CODEC_ID_AC3 && bSupportsAC3Out) ||
            (hints.codec == AV_CODEC_ID_EAC3 && bSupportsEAC3Out && (hints.samplerate == 44100 || hints.samplerate == 48000)) ||
            (hints.codec == AV_CODEC_ID_DTS && bSupportsDTSOut) ||
            (hints.codec == AV_CODEC_ID_TRUEHD && bSupportsTrueHDOut))
    {
        return true;
    }

    return false;
}
bool CDVDAudioCodecPassthrough::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
{
  /* dont open if AE doesnt support RAW */
  if (!CAEFactory::SupportsRaw())
    return false;

  bool bSupportsAC3Out    = false;
  bool bSupportsDTSOut    = false;
  bool bSupportsTrueHDOut = false;
  bool bSupportsDTSHDOut  = false;

  int audioMode = g_guiSettings.GetInt("audiooutput.mode");
  if (AUDIO_IS_BITSTREAM(audioMode))
  {
    bSupportsAC3Out = g_guiSettings.GetBool("audiooutput.ac3passthrough");
    bSupportsDTSOut = g_guiSettings.GetBool("audiooutput.dtspassthrough");
  }

  if (audioMode == AUDIO_HDMI)
  {
    bSupportsTrueHDOut = g_guiSettings.GetBool("audiooutput.truehdpassthrough");
    bSupportsDTSHDOut  = g_guiSettings.GetBool("audiooutput.dtshdpassthrough" ) && bSupportsDTSOut;
  }

  /* only get the dts core from the parser if we don't support dtsHD */
  m_info.SetCoreOnly(!bSupportsDTSHDOut);
  m_bufferSize = 0;

  if (
      (hints.codec == CODEC_ID_AC3 && bSupportsAC3Out) ||
      (hints.codec == CODEC_ID_DTS && bSupportsDTSOut) ||
      (audioMode == AUDIO_HDMI &&
        (
          (hints.codec == CODEC_ID_EAC3   && bSupportsAC3Out   ) ||
          (hints.codec == CODEC_ID_TRUEHD && bSupportsTrueHDOut)
        )
      )
  )
    return true;

  return false;
}
bool DVDPlayerCodec::Init(const CStdString &strFile, unsigned int filecache)
{
  m_decoded = NULL;;
  m_nDecodedLen = 0;

  CStdString strFileToOpen = strFile;

  CURL urlFile(strFile);
  if (urlFile.GetProtocol() == "shout" )
    strFileToOpen.Replace("shout://","http://");

  m_pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, strFileToOpen, m_strContentType);
  if (!m_pInputStream)
  {
    CLog::Log(LOGERROR, "%s: Error creating input stream for %s", __FUNCTION__, strFileToOpen.c_str());
    return false;
  }

  if (!m_pInputStream->Open(strFileToOpen.c_str(), m_strContentType))
  {
    CLog::Log(LOGERROR, "%s: Error opening file %s", __FUNCTION__, strFileToOpen.c_str());
    if (m_pInputStream)
      delete m_pInputStream;
    m_pInputStream = NULL;
    return false;
  }

  m_pDemuxer = NULL;

  try
  {
    m_pDemuxer = CDVDFactoryDemuxer::CreateDemuxer(m_pInputStream);
    if (!m_pDemuxer)
    {
      delete m_pInputStream;
      m_pInputStream = NULL;
      CLog::Log(LOGERROR, "%s: Error creating demuxer", __FUNCTION__);
      return false;
    }
  }
  catch(...)
  {
    CLog::Log(LOGERROR, "%s: Exception thrown when opeing demuxer", __FUNCTION__);
    if (m_pDemuxer)
    {
      delete m_pDemuxer;
      m_pDemuxer = NULL;
    }
    delete m_pInputStream;
    m_pInputStream = NULL;
    return false;
  }

  CDemuxStream* pStream = NULL;
  m_nAudioStream = -1;
  for (int i = 0; i < m_pDemuxer->GetNrOfStreams(); i++)
  {
    pStream = m_pDemuxer->GetStream(i);
    if (pStream && pStream->type == STREAM_AUDIO)
    {
      m_nAudioStream = i;
      break;
    }
  }

  if (m_nAudioStream == -1)
  {
    CLog::Log(LOGERROR, "%s: Could not find audio stream", __FUNCTION__);
    delete m_pDemuxer;
    m_pDemuxer = NULL;
    delete m_pInputStream;
    m_pInputStream = NULL;
    return false;
  }

  CDVDStreamInfo hint(*pStream, true);

  bool passthrough = AUDIO_IS_BITSTREAM(g_guiSettings.GetInt("audiooutput.mode"));
  m_pAudioCodec = CDVDFactoryCodec::CreateAudioCodec(hint, passthrough);
  if (!m_pAudioCodec)
  {
    CLog::Log(LOGERROR, "%s: Could not create audio codec", __FUNCTION__);
    delete m_pDemuxer;
    m_pDemuxer = NULL;
    delete m_pInputStream;
    m_pInputStream = NULL;
    return false;
  }

  // we have to decode initial data in order to get channels/samplerate
  // for sanity - we read no more than 10 packets
  int nErrors = 0;
  for (int nPacket=0; nPacket < 10 && (m_Channels == 0 || m_SampleRate == 0); nPacket++)
  {
    BYTE dummy[256];
    int nSize = 256;
    if (ReadPCM(dummy, nSize, &nSize) == READ_ERROR)
      ++nErrors;

    m_DataFormat    = m_pAudioCodec->GetDataFormat();
    m_BitsPerSample = CAEUtil::DataFormatToBits(m_DataFormat);
    m_SampleRate = m_pAudioCodec->GetSampleRate();
    m_EncodedSampleRate = m_pAudioCodec->GetEncodedSampleRate();
    m_Channels = m_pAudioCodec->GetChannels();
    m_ChannelInfo = m_pAudioCodec->GetChannelMap();

  }
  if (nErrors >= 10)
  {
    CLog::Log(LOGDEBUG, "%s: Could not decode data", __FUNCTION__);
    return false;
  }

  m_nDecodedLen = 0;

  if (m_Channels == 0) // no data - just guess and hope for the best
    m_Channels = 2;

  if (m_SampleRate == 0)
    m_SampleRate = 44100;

  m_TotalTime = m_pDemuxer->GetStreamLength();
  m_Bitrate = m_pAudioCodec->GetBitRate();
  m_pDemuxer->GetStreamCodecName(m_nAudioStream,m_CodecName);

  return true;
}