void graph::ops::do_ack_unpaused ()
{
  if (last_op_succeeded () && NULL != p_graph_)
  {
    p_graph_->graph_unpaused ();
  }
}
void graph::ops::do_ack_metadata ()
{
  if (last_op_succeeded () && NULL != p_graph_)
  {
    p_graph_->graph_metadata (metadata_);
  }
}
void graph::ops::do_ack_volume ()
{
  if (last_op_succeeded () && NULL != p_graph_)
  {
    p_graph_->graph_volume (volume_);
  }
}
void graph::youtubeops::do_configure_comp (const int comp_id)
{
  if (last_op_succeeded ())
  {
    if (comp_id == 0)
    {
      tizyoutubeconfig_ptr_t youtube_config
          = boost::dynamic_pointer_cast< youtubeconfig > (config_);
      assert (youtube_config);

      G_OPS_BAIL_IF_ERROR (
          tiz::graph::util::set_youtube_playlist (
              handles_[0], playlist_->get_current_uri (),
              youtube_config->get_playlist_type (), playlist_->shuffle ()),
          "Unable to set OMX_TizoniaIndexParamAudioYoutubePlaylist");
    }
    else if (comp_id == 2)
    {
      G_OPS_BAIL_IF_ERROR (
          apply_default_config_on_decoder (),
          "Unable to apply the decoder's initial configuration");
    }
    else if (comp_id == 3)
    {
      G_OPS_BAIL_IF_ERROR (apply_pcm_codec_info_from_decoder (),
                           "Unable to set OMX_IndexParamAudioPcm");
    }
  }
}
void graph::ops::do_ack_loaded ()
{
  TIZ_LOG (TIZ_PRIORITY_TRACE, " p_graph_ [%p]", p_graph_);
  if (last_op_succeeded () && NULL != p_graph_)
  {
    p_graph_->graph_loaded ();
  }
}
void graph::httpclntops::do_configure ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (apply_pcm_codec_info_from_http_source (),
                         "Unable to set OMX_IndexParamAudioPcm");
  }
}
void graph::ops::do_source_omx_loaded2idle ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (
        transition_source (OMX_StateIdle),
        "Unable to transition source component from Loaded->Idle");
  }
}
void graph::ops::do_source_omx_idle2exe ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (
        transition_source (OMX_StateExecuting),
        "Unable to transition source component from Idle->Exe");
  }
}
void graph::ops::do_skip ()
{
  if (last_op_succeeded () && 0 != jump_ && !is_end_of_play ())
  {
    playlist_->skip (jump_);
    // Reset the jump value, to its default value
    jump_ = SKIP_DEFAULT_VALUE;
  }
}
void graph::ops::do_omx_idle2loaded ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (
        util::transition_all (handles_, OMX_StateLoaded, OMX_StateIdle),
        "Unable to transition from Idle->Loaded");
    record_expected_transitions (OMX_StateLoaded);
  }
}
void graph::gmusicops::do_configure ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (override_decoder_and_renderer_sampling_rates (),
                         "Unable to override decoder/renderer sampling rates");
    G_OPS_BAIL_IF_ERROR (apply_pcm_codec_info_from_decoder (),
                         "Unable to set OMX_IndexParamAudioPcm");
  }
}
void graph::ops::do_setup ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (util::setup_suppliers (handles_),
                         "Unable to setup suppliers.");
    G_OPS_BAIL_IF_ERROR (util::setup_tunnels (handles_),
                         "Unable to setup the tunnels.");
  }
}
void graph::ops::do_omx_exe2idle ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (
        util::transition_all (handles_, OMX_StateIdle, OMX_StateExecuting),
        "Unable to transition from Exe->Idle");
    record_expected_transitions (OMX_StateIdle);
  }
}
void graph::gmusicops::do_skip ()
{
  if (last_op_succeeded () && 0 != jump_)
  {
    assert (!handles_.empty ());
    G_OPS_BAIL_IF_ERROR (util::apply_playlist_jump (handles_[0], jump_),
                         "Unable to skip in playlist");
    // Reset the jump value, to its default value
    jump_ = SKIP_DEFAULT_VALUE;
  }
}
void graph::ops::do_enable_tunnel (const int tunnel_id)
{
  if (last_op_succeeded ())
  {
    std::string err_msg ("Unable to enable tunnel id [");
    err_msg.append (boost::lexical_cast< std::string >(tunnel_id));
    err_msg.append ("]");
    G_OPS_BAIL_IF_ERROR (transition_tunnel (tunnel_id, OMX_CommandPortEnable),
                         err_msg);
  }
}
/**
 * Default implementation of do_mute () operation. It applies mute/unmute on
 * port #0 of the last element of the graph.
 *
 */
void graph::ops::do_mute ()
{
  if (last_op_succeeded ())
  {
    OMX_U32 input_port = 0;
    assert (!handles_.empty ());
    G_OPS_BAIL_IF_ERROR (
        util::apply_mute (handles_[handles_.size () - 1], input_port),
        "Unable to apply mute");
  }
}
/**
 * Default implementation of do_volume () operation. It applies a volume
 * increment or decrement on port #0 of the last element of the graph.
 *
 * @param vol 1.0 is maximum volume and 0.0 means mute.
 */
void graph::ops::do_volume (const double vol)
{
  if (last_op_succeeded ())
  {
    OMX_U32 input_port = 0;
    assert (!handles_.empty ());
    G_OPS_BAIL_IF_ERROR (util::apply_volume (handles_[handles_.size () - 1],
                                             input_port, vol, volume_),
                         "Unable to apply volume");
    // We update the mgr with the new volume here
    do_ack_volume ();
  }
}
void graph::ops::do_omx_pause2exe ()
{
  assert (!handles_.empty ());
  if (last_op_succeeded ())
  {
    const int renderer_handle_index = handles_.size () - 1;
    G_OPS_BAIL_IF_ERROR (util::transition_one (handles_, renderer_handle_index,
                                               OMX_StateExecuting),
                         "Unable to transition renderer from Pause->Exe");
    clear_expected_transitions ();
    add_expected_transition (handles_[renderer_handle_index],
                             OMX_StateExecuting);
  }
}
void graph::gmusicops::do_loaded2idle ()
{
  if (last_op_succeeded ())
  {
    // Transition the decoder and the renderer components to Idle
    omx_comp_handle_lst_t decoder_and_renderer_handles;
    decoder_and_renderer_handles.push_back (handles_[1]);  // the decoder
    decoder_and_renderer_handles.push_back (handles_[2]);  // the renderer
    G_OPS_BAIL_IF_ERROR (
        util::transition_all (decoder_and_renderer_handles, OMX_StateIdle,
                              OMX_StateLoaded),
        "Unable to transition decoder and renderer from Loaded->Idle");
    clear_expected_transitions ();
    add_expected_transition (handles_[1], OMX_StateIdle);
    add_expected_transition (handles_[2], OMX_StateIdle);
  }
}
void graph::httpclntops::do_omx_idle2exe ()
{
  if (last_op_succeeded ())
  {
    // Transition the decoder and the renderer components to Exe
    omx_comp_handle_lst_t decoder_and_renderer_handles;
    decoder_and_renderer_handles.push_back (handles_[1]);  // the decoder
    decoder_and_renderer_handles.push_back (handles_[2]);  // the renderer
    G_OPS_BAIL_IF_ERROR (
        util::transition_all (decoder_and_renderer_handles, OMX_StateExecuting,
                              OMX_StateIdle),
        "Unable to transition decoder and renderer from Idle->Exe");
    clear_expected_transitions ();
    add_expected_transition (handles_[1], OMX_StateExecuting);
    add_expected_transition (handles_[2], OMX_StateExecuting);
  }
}
void graph::gmusicops::do_reconfigure_tunnel (const int tunnel_id)
{
  if (last_op_succeeded ())
  {
    if (0 == tunnel_id)
    {
      do_reconfigure_first_tunnel ();
    }
    else if (1 == tunnel_id)
    {
      do_reconfigure_second_tunnel ();
    }
    else
    {
      assert (0);
    }
  }
}
void graph::ops::do_omx_pause2idle ()
{
  assert (!handles_.empty ());
  if (last_op_succeeded ())
  {
    const int renderer_handle_index = handles_.size () - 1;
    G_OPS_BAIL_IF_ERROR (
        util::transition_one (handles_, renderer_handle_index, OMX_StateIdle),
        "Unable to transition renderer from Pause->Idle");
    clear_expected_transitions ();
    add_expected_transition (handles_[renderer_handle_index], OMX_StateIdle);

    for (int i = renderer_handle_index - 1; i >= 0; --i)
    {
      G_OPS_BAIL_IF_ERROR (util::transition_one (handles_, i, OMX_StateIdle),
                           "Unable to transition from Idle->Exe");
      add_expected_transition (handles_[i], OMX_StateIdle);
    }
  }
}
void graph::httpclntops::do_reconfigure_tunnel (const int tunnel_id)
{
  if (last_op_succeeded ())
  {
    assert (1 == tunnel_id);     // We only expect tunnel reconfiguration in tunnel 1
    // Retrieve the pcm settings from the decoder component
    OMX_AUDIO_PARAM_PCMMODETYPE decoder_pcmtype;
    const OMX_U32 decoder_port_id = 1;
    TIZ_INIT_OMX_PORT_STRUCT (decoder_pcmtype, decoder_port_id);
    G_OPS_BAIL_IF_ERROR (
        OMX_GetParameter (handles_[1], OMX_IndexParamAudioPcm,
                          &decoder_pcmtype),
        "Unable to retrieve the PCM settings from the audio decoder");

    // Retrieve the pcm settings from the renderer component
    OMX_AUDIO_PARAM_PCMMODETYPE renderer_pcmtype;
    const OMX_U32 renderer_port_id = 0;
    TIZ_INIT_OMX_PORT_STRUCT (renderer_pcmtype, renderer_port_id);
    G_OPS_BAIL_IF_ERROR (
        OMX_GetParameter (handles_[2], OMX_IndexParamAudioPcm,
                          &renderer_pcmtype),
        "Unable to retrieve the PCM settings from the pcm renderer");

    // Now assign the current settings to the renderer structure
    renderer_pcmtype.nChannels = decoder_pcmtype.nChannels;
    renderer_pcmtype.nSamplingRate = decoder_pcmtype.nSamplingRate;

    // Set the new pcm settings
    G_OPS_BAIL_IF_ERROR (
        OMX_SetParameter (handles_[2], OMX_IndexParamAudioPcm,
                          &renderer_pcmtype),
        "Unable to set the PCM settings on the audio renderer");

    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");
  }
}
void graph::pcmdecops::do_configure ()
{
  if (last_op_succeeded ())
  {
    G_OPS_BAIL_IF_ERROR (
        util::set_content_uri (handles_[0], probe_ptr_->get_uri ()),
        "Unable to set OMX_IndexParamContentURI");
    OMX_ERRORTYPE rc = tiz::graph::util::
        normalize_tunnel_settings< OMX_AUDIO_PARAM_PCMMODETYPE,
                                   OMX_IndexParamAudioPcm >(
            handles_, 1,  // tunneld id, i.e. this is decoder <-> renderer),
            1,            // decoder's output port
            0);           // renderer's input port
    G_OPS_BAIL_IF_ERROR (rc, "Unable to transfer OMX_IndexParamAudioPcm");
    G_OPS_BAIL_IF_ERROR (
        tiz::graph::util::set_pcm_mode (
            handles_[2], 0,
            boost::bind (&tiz::graph::pcmdecops::get_pcm_codec_info, this, _1)),
        "Unable to set OMX_IndexParamAudioPcm");
  }
}