Repository: xbmc/xbmc
File: xbmc/cores/AudioEngine/Encoders/AEEncoderFFmpeg.cpp (C++)

Code before:
  if (ffmap & AV_CH_TOP_FRONT_CENTER     ) layout += AE_CH_TFC ;
  if (ffmap & AV_CH_TOP_FRONT_RIGHT      ) layout += AE_CH_TFR ;
  if (ffmap & AV_CH_TOP_BACK_LEFT        ) layout += AE_CH_TBL ;
  if (ffmap & AV_CH_TOP_BACK_CENTER      ) layout += AE_CH_TBC ;
  if (ffmap & AV_CH_TOP_BACK_RIGHT       ) layout += AE_CH_TBR ;

  return layout.Count();
}

bool CAEEncoderFFmpeg::Initialize(AEAudioFormat& format, bool allow_planar_input)
{
  Reset();

  const bool ac3 = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
      CSettings::SETTING_AUDIOOUTPUT_AC3PASSTHROUGH);

  const AVCodec* codec = nullptr;

  if (format.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_EAC3)
  {
    m_CodecName = "EAC3";
    m_CodecID = AV_CODEC_ID_EAC3;
    m_BitRate = EAC3_ENCODE_BITRATE;
    codec = avcodec_find_encoder(m_CodecID);
  }
  else if (ac3)
  {
    /* fallback to ac3 if we support it, we might not have DTS support */
    m_CodecName = "AC3";
    m_CodecID = AV_CODEC_ID_AC3;
    m_BitRate = AC3_ENCODE_BITRATE;
    codec = avcodec_find_encoder(m_CodecID);
  }

  /* check we got the codec */
  if (!codec)
    return false;

  m_CodecCtx = avcodec_alloc_context3(codec);
  if (!m_CodecCtx)
    return false;

  m_CodecCtx->bit_rate = m_BitRate;
  m_CodecCtx->sample_rate = format.m_sampleRate;

  uint64_t channelLayout = AV_CH_LAYOUT_5POINT1_BACK;
  if (format.m_channelLayout.IsLayoutValid())
  {
    const AVChannelLayout* channelLayouts = nullptr;
    int numLayouts = 0;
    avcodec_get_supported_config(m_CodecCtx, codec, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,

Review comment (suggestion):
```suggestion
  else if (ac3 || format.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_AC3)
```

Code after:
  if (ffmap & AV_CH_TOP_FRONT_CENTER     ) layout += AE_CH_TFC ;
  if (ffmap & AV_CH_TOP_FRONT_RIGHT      ) layout += AE_CH_TFR ;
  if (ffmap & AV_CH_TOP_BACK_LEFT        ) layout += AE_CH_TBL ;
  if (ffmap & AV_CH_TOP_BACK_CENTER      ) layout += AE_CH_TBC ;
  if (ffmap & AV_CH_TOP_BACK_RIGHT       ) layout += AE_CH_TBR ;

  return layout.Count();
}

bool CAEEncoderFFmpeg::Initialize(AEAudioFormat& format, bool allow_planar_input)
{
  Reset();

  const bool ac3 = CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
      CSettings::SETTING_AUDIOOUTPUT_AC3PASSTHROUGH);

  const AVCodec* codec = nullptr;

  if (format.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_EAC3)
  {
    m_CodecName = "EAC3";
    m_CodecID = AV_CODEC_ID_EAC3;
    m_BitRate = EAC3_ENCODE_BITRATE;
    codec = avcodec_find_encoder(m_CodecID);
  }
  else if (ac3 || format.m_streamInfo.m_type == CAEStreamInfo::STREAM_TYPE_AC3)
  {
    m_CodecName = "AC3";
    m_CodecID = AV_CODEC_ID_AC3;
    m_BitRate = AC3_ENCODE_BITRATE;
    codec = avcodec_find_encoder(m_CodecID);
  }

  /* check we got the codec */
  if (!codec)
    return false;

  m_CodecCtx = avcodec_alloc_context3(codec);
  if (!m_CodecCtx)
    return false;

  m_CodecCtx->bit_rate = m_BitRate;
  m_CodecCtx->sample_rate = format.m_sampleRate;

  uint64_t channelLayout = AV_CH_LAYOUT_5POINT1_BACK;
  if (format.m_channelLayout.IsLayoutValid())
  {
    const AVChannelLayout* channelLayouts = nullptr;
    int numLayouts = 0;
    avcodec_get_supported_config(m_CodecCtx, codec, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
                                 reinterpret_cast<const void**>(&channelLayouts), &numLayouts);