On Wed, Nov 25, 2009 at 06:03:37PM -0500, José Alburquerque wrote:
> You know, rechecking the docs, the C API does have a macro called
> GST_MIXER_TRACK_HAS_FLAG() used to check what flags a Gst::MixerTrack
> has.  We'll try to add a convenience function for this.  For now, using
> the Gst::MixerTrack::property_flags() property and seeing if the
> appropriate flag from Gst::MixerTrackFlags is set should work just as
> well.

K, I now made these function, which work :)


Glib::RefPtr<Gst::Mixer> create_mixer(void)
{
  // Use the ALSA mixer plugin.
  Glib::RefPtr<Gst::AlsaMixer> alsa_mixer = Gst::AlsaMixer::create("mixer");

  if (!alsa_mixer)
    DoutFatal(dc::fatal, "The AlsaMixer could not be created.");

  // Must set the state to ready before using it.
  alsa_mixer->set_state(Gst::STATE_READY);

  return alsa_mixer;
}

void select_microphone(Glib::RefPtr<Gst::Mixer> const& mixer, bool const 
print_tracks)
{
  typedef std::list<Glib::RefPtr<Gst::MixerTrack> > tracks_type;

  tracks_type tracks = mixer->list_tracks();
  for (tracks_type::iterator iter = tracks.begin(); iter != tracks.end(); 
++iter)
  {
    Glib::RefPtr<Gst::MixerTrack const> track = *iter;
    Glib::ustring const label = track->get_label();
    bool const is_microphone =
        !label.compare("Mic") ||
        !label.compare(0, 4, "Mic ") ||
        !label.compare(0, 10, "Microphone");
    bool const is_capture =
        !label.compare("Capture");
    bool const is_AC97 =
        !label.compare(0, 4, "AC97");
    bool const has_channels = track->get_num_channels() > 0;
    if (print_tracks)
    {
      std::cout << label;
      if (is_microphone)
        std::cout << " [MICROPHONE]";
      if (has_channels)
      {
        std::vector<int> volumes = mixer->get_volume(track);
        for (std::vector<int>::iterator volume_iter = volumes.begin(); 
volume_iter != volumes.end(); ++volume_iter)
          std::cout << ' ' << *volume_iter;
      }
    }
    guint flags = track->property_flags();
    if ((flags & Gst::MIXER_TRACK_INPUT))
    {
      // Turn off all other input, except Capture and AC97 Capture.
      if (has_channels)
      {
        bool const need_capture = is_capture || is_AC97;
        mixer->set_record(*iter, need_capture);
        if (need_capture)
        {
          std::vector<int> volumes = mixer->get_volume(track);
          bool zero_volume = false;
          for (size_t channel = 0; channel < volumes.size(); ++channel)
            if (volumes[channel] == 0)
              zero_volume = true;
          // Only set the volume to max if it is zero (on any channel).
          if (zero_volume)
          {
            int const max_volume = track->get_max_volume();
            for (size_t channel = 0; channel < volumes.size(); ++channel)
              volumes[channel] = max_volume;
            mixer->set_volume(*iter, volumes);
            if (is_capture)
              std::cerr << "Warning: setting Capture volume to max. This 
probably leads to distortion. Reduce Capture as needed." << std::endl;
          }
        }
      }
      // Select microphone as capture input.
      if (is_microphone)
      {
        assert(!has_channels);          // Otherwise we'd need to set the 
volume to max too.
        mixer->set_record(*iter, true);
      }
      if (print_tracks)
        std::cout << " [input]";
    }
    if ((flags & Gst::MIXER_TRACK_OUTPUT))
    {
      // Turn off microphone playback.
      if (is_microphone && has_channels)
        mixer->set_mute(*iter, true);
      if (is_AC97)
      {
        assert(has_channels);
        // Turn off AC97 playback.
        std::vector<int> volumes(track->get_num_channels(), 
track->get_min_volume());
        mixer->set_volume(*iter, volumes);
      }
      if (print_tracks)
        std::cout << " [output]";
    }
    if (print_tracks)
    {
      if ((flags & Gst::MIXER_TRACK_MUTE))
        std::cout << " [muted]";
      if ((flags & Gst::MIXER_TRACK_RECORD))
        std::cout << " [CAPTURE]";
      std::cout << std::endl;
    }
  }
}

-- 
Carlo Wood <[email protected]>
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to