OMX_ERRORTYPE
graph::gmusicops::set_channels_and_rate_on_renderer (
    const OMX_U32 channels, const OMX_U32 sampling_rate,
    const std::string encoding_str)
{
  const OMX_HANDLETYPE handle = handles_[2];  // renderer's handle
  const OMX_U32 port_id = 0;                  // renderer's input port

  TIZ_LOG (TIZ_PRIORITY_TRACE, "channels = [%d] sampling_rate = [%d]", channels,
           sampling_rate);

  // Retrieve the pcm settings from the renderer component
  TIZ_INIT_OMX_PORT_STRUCT (renderer_pcmtype_, port_id);
  tiz_check_omx_err (
      OMX_GetParameter (handle, OMX_IndexParamAudioPcm, &renderer_pcmtype_));

  // Now assign the actual settings to the pcmtype structure
  renderer_pcmtype_.nChannels = channels;
  renderer_pcmtype_.nSamplingRate = sampling_rate;
  renderer_pcmtype_.eNumData = OMX_NumericalDataSigned;
  renderer_pcmtype_.eEndian
      = (encoding_ == OMX_AUDIO_CodingMP3 ? OMX_EndianBig : OMX_EndianLittle);

  // Set the new pcm settings
  tiz_check_omx_err (
      OMX_SetParameter (handle, OMX_IndexParamAudioPcm, &renderer_pcmtype_));

  std::string coding_type_str ("gmusic");
  tiz::graph::util::dump_graph_info (coding_type_str.c_str (),
                                     "Connection established",
                                     playlist_->get_current_uri ().c_str ());
  dump_stream_metadata ();

  return OMX_ErrorNone;
}
OMX_ERRORTYPE
graph::httpclntops::set_channels_and_rate_on_renderer (
    const OMX_U32 channels, const OMX_U32 sampling_rate,
    const std::string encoding_str)
{
  const OMX_HANDLETYPE handle = handles_[2];  // renderer's handle
  const OMX_U32 port_id = 0;                  // renderer's input port

  TIZ_LOG (TIZ_PRIORITY_TRACE, "channels = [%d] sampling_rate = [%d]", channels,
           sampling_rate);

  // Retrieve the pcm settings from the renderer component
  OMX_AUDIO_PARAM_PCMMODETYPE renderer_pcmtype;
  TIZ_INIT_OMX_PORT_STRUCT (renderer_pcmtype, port_id);
  tiz_check_omx_err (
      OMX_GetParameter (handle, OMX_IndexParamAudioPcm, &renderer_pcmtype));

  // Now assign the actual settings to the pcmtype structure
  renderer_pcmtype.nChannels = channels;
  renderer_pcmtype.nSamplingRate = sampling_rate;
  renderer_pcmtype.eNumData = OMX_NumericalDataSigned;
  renderer_pcmtype.eEndian
      = (encoding_ == OMX_AUDIO_CodingMP3 ? OMX_EndianBig : OMX_EndianLittle);

  if (OMX_AUDIO_CodingOPUS == encoding_ || OMX_AUDIO_CodingVORBIS == encoding_)
  {
    // Opus and Vorbis decoders output 32 bit samples (floats)
    renderer_pcmtype.nBitPerSample = 32;
  }

  // Set the new pcm settings
  tiz_check_omx_err (
      OMX_SetParameter (handle, OMX_IndexParamAudioPcm, &renderer_pcmtype));

  std::string coding_type_str ("http/");
  coding_type_str.append (encoding_str);
  tiz::graph::util::dump_graph_info (coding_type_str.c_str (),
                                     "Connection established",
                                     playlist_->get_current_uri ().c_str ());

  TIZ_PRINTF_YEL ("   %ld Ch, %g KHz, %lu:%s:%s\n",
           renderer_pcmtype.nChannels,
           ((float)renderer_pcmtype.nSamplingRate) / 1000,
           renderer_pcmtype.nBitPerSample,
           renderer_pcmtype.eNumData == OMX_NumericalDataSigned ? "s" : "u",
           renderer_pcmtype.eEndian == OMX_EndianBig ? "b" : "l");

  return OMX_ErrorNone;
}
OMX_ERRORTYPE
graph::gmusicops::set_channels_and_rate_on_renderer (
    const OMX_U32 channels, const OMX_U32 sampling_rate)
{
  const OMX_HANDLETYPE handle = handles_[2];  // renderer's handle
  const OMX_U32 port_id = 0;                  // renderer's input port

  TIZ_LOG (TIZ_PRIORITY_TRACE, "channels = [%d] sampling_rate = [%d]", channels,
           sampling_rate);

  // Retrieve the pcm settings from the renderer component
  TIZ_INIT_OMX_PORT_STRUCT (renderer_pcmtype_, port_id);
  tiz_check_omx (
      OMX_GetParameter (handle, OMX_IndexParamAudioPcm, &renderer_pcmtype_));

  // Now assign the actual settings to the pcmtype structure
  renderer_pcmtype_.nChannels = channels;
  renderer_pcmtype_.nSamplingRate = sampling_rate;
  renderer_pcmtype_.eNumData = OMX_NumericalDataSigned;
  renderer_pcmtype_.eEndian
      = (encoding_ == OMX_AUDIO_CodingMP3 ? OMX_EndianBig : OMX_EndianLittle);

  // Set the new pcm settings
  tiz_check_omx (
      OMX_SetParameter (handle, OMX_IndexParamAudioPcm, &renderer_pcmtype_));

  tizgmusicconfig_ptr_t gmusic_config
    = boost::dynamic_pointer_cast< gmusicconfig >(config_);
  assert (gmusic_config);

  std::string coding_type_str ("Google Play Music");
  tiz::graph::util::dump_graph_info (coding_type_str.c_str (),
                                     "Connected",
                                     gmusic_config->get_user_name ().c_str ());

  return OMX_ErrorNone;
}