[gst-devel] Sink autodetect and async state change

Steve Baker steve at stevebaker.org
Tue Jul 29 00:57:07 CEST 2003


On Tue, 2003-07-29 at 02:15, in7y118 at public.uni-hamburg.de wrote:
> The recommended solution make autodetection somehow like this:
> for every sound output we know of from an ordered list do
>   if (installed)
>     if (custom code to check if it is likely to be used) [1]
>       use it;
> next
> 
> [1] This would probably check for the sound server plugins if the server is 
> running and not use it if the server isn't running and return TRUE for every 
> hardware plugin
> 
> You would probably want to check esd, artsd, alsa, oss (in that order).
> 
> I know that Steve Baker wanted to work on this, there was a discussion about 
> this on the list some months ago. I don't know what the state of his work is 
> though.

Indeed. I put something together weeks ago in the gconf support lib but
haven't got around to cleaning it up enough to commit it. I was going to
ignore artsd for now as I wasn't sure if it was rock solid. Has a clock
been implemented? Can any developers say they use the artsd plugin on a
daily basis? 

The only thing I need to do is to make the esdsink test fail if esd
isn't already running - like add a no-spawn property to the element.

Another thought is that this auto-detection stuff might be too generic
and useful to put in the gconf helper lib, but is it really worth making
another tiny lib for those who don't want the gconf dependency?

Here is the code in question:

GstElement *
gst_gconf_default_audio_sink (GError **error)
{
  gboolean autodetect;
  GstElement *ret;
 
  autodetect = gst_gconf_get_bool("default/autodetect_audiosink",
error);

  if (!autodetect){
    ret = gst_gconf_bin_from_key ("default/audiosink", error);

    if (ret && ! *error) {
      return ret;
    }
    /* the key must be wrong for some reason, lets autodetect anyway */
  }

  if(gst_gconf_test_audio_sink("esdsink")){
    ret = gst_gconf_bin_from_description ("esdsink", error);
    return ret;
  }

  if(gst_gconf_test_audio_sink("alsasink")){
    ret = gst_gconf_bin_from_description ("alsasink", error);
    return ret;
  }

  if(gst_gconf_test_audio_sink("osssink")){
    ret = gst_gconf_bin_from_description ("osssink", error);
    return ret;
  }


  /* error: no pipeline */
  return NULL;
}

gboolean
gst_gconf_test_audio_sink(const gchar *description)
{
  GError *error = NULL;
  GstElement *pipeline = NULL;
  gchar *desc = NULL;
  gboolean ret = TRUE;

  /* parse the pipeline to a pipeline */
  desc = g_strdup_printf ("silence ! %s", description);

  g_print("testing %s\n", desc);

  pipeline = GST_ELEMENT (gst_parse_launch (desc, &error));
  g_free (desc);

  if (error){
    /* this probably happened because the element doesn't exist */
    g_error_free(error);
    g_print("error parsing pipeline");
    ret = FALSE;
    goto end;
  }

  /* start playing */
  g_print("playing\n");
  if (gst_element_set_state (pipeline, GST_STATE_PLAYING) ==
GST_STATE_FAILURE) {
    g_print("pipeline doesn't want to play\n");
    ret = FALSE;
    goto end;
  }

  /* iterate once */
  g_print("iterating\n");
  gst_bin_iterate (GST_BIN (pipeline));
  
  if (gst_element_get_state (pipeline) != GST_STATE_PLAYING) {
    /* the pipeline is no longer playing, an error must have occured */
    g_print("pipeline didn't iterate\n");
    ret = FALSE;
    goto end;
  }

end:
  if (pipeline){

    if (gst_element_get_state (pipeline) != GST_STATE_NULL) {
      /* stop the pipeline */
      g_print("nulling\n");
      gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
    }
    
    g_print("unreffing\n");
    gst_object_unref(GST_OBJECT(pipeline));
  }

  return ret;
}

> 
> 
> Zitat von Tim Otten <tim at cap.american.edu>:
> 
> > I recently filed:
> > 
> > http://bugzilla.gnome.org/show_bug.cgi?id=118033
> > 
> > which concerns autodetection for audio sinks. I don't know much about
> > GStreamer or media systems in general, so I decided that I was The Right
> > Man For The Job. My test code
> > 
> > http://unix.cap.american.edu/~tim/csc/gst-detect-sink/
> > 
> > mimics the approach from the xine-libs autodetection routine -- try each
> > module and look for errors. There are two tests in particular: (a) can we
> > instantiate the audio sink? (b) can the sink handle a switch to the PLAY
> > (or READY) state?
> > 
> > My main concern is with (b). An element can change states asynchronously,
> > but I can't find any examples among the sinks. test4 includes some BS
> > which calls gst_element_wait_state_change and then checks if the PLAY (or
> > READY) state was achieved. Is this reasonable?
> > 
> > At any rate, it seems to work with esdsink, osssink, and artsdsink on my
> > Debian unstable box. I'd appreciate comments/test results from others. If
> > it seems to work generally, I'll try to repackage test4 as a
> > voodooautomagicalaudiosink module.
> > 
> > Tim Otten
> > tim of cap of american of edu
> > 
> > 
> > 
> > 
> > 
> > -------------------------------------------------------
> > This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> > Data Reports, E-commerce, Portals, and Forums are available now.
> > Download today and enter to win an XBOX or Visual Studio .NET.
> > http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> > _______________________________________________
> > gstreamer-devel mailing list
> > gstreamer-devel at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
> > 
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
-- 
Steve Baker <steve at stevebaker.org>






More information about the gstreamer-devel mailing list