mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	source: add method to mark a source idle or busy
Marking a source idle will start an idle timeout to suspend the source.
This commit is contained in:
		
							parent
							
								
									04eca27890
								
							
						
					
					
						commit
						12301b6ef1
					
				
					 2 changed files with 53 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -42,6 +42,7 @@ struct _PinosSourcePrivate
 | 
			
		|||
 | 
			
		||||
  PinosSourceState state;
 | 
			
		||||
  GError *error;
 | 
			
		||||
  guint idle_timeout;
 | 
			
		||||
 | 
			
		||||
  GList *outputs;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -367,6 +368,17 @@ pinos_source_get_formats (PinosSource *source,
 | 
			
		|||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
remove_idle_timeout (PinosSource *source)
 | 
			
		||||
{
 | 
			
		||||
  PinosSourcePrivate *priv = source->priv;
 | 
			
		||||
 | 
			
		||||
  if (priv->idle_timeout) {
 | 
			
		||||
    g_source_remove (priv->idle_timeout);
 | 
			
		||||
    priv->idle_timeout = 0;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
pinos_source_set_state (PinosSource      *source,
 | 
			
		||||
                        PinosSourceState  state)
 | 
			
		||||
| 
						 | 
				
			
			@ -378,6 +390,8 @@ pinos_source_set_state (PinosSource      *source,
 | 
			
		|||
 | 
			
		||||
  klass = PINOS_SOURCE_GET_CLASS (source);
 | 
			
		||||
 | 
			
		||||
  remove_idle_timeout (source);
 | 
			
		||||
 | 
			
		||||
  if (klass->set_state)
 | 
			
		||||
    res = klass->set_state (source, state);
 | 
			
		||||
  else
 | 
			
		||||
| 
						 | 
				
			
			@ -412,11 +426,47 @@ pinos_source_report_error (PinosSource *source,
 | 
			
		|||
  priv = source->priv;
 | 
			
		||||
 | 
			
		||||
  g_clear_error (&priv->error);
 | 
			
		||||
  remove_idle_timeout (source);
 | 
			
		||||
  priv->error = error;
 | 
			
		||||
  priv->state = PINOS_SOURCE_STATE_ERROR;
 | 
			
		||||
  pinos_source1_set_state (priv->iface, priv->state);
 | 
			
		||||
  g_object_notify (G_OBJECT (source), "state");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static gboolean
 | 
			
		||||
idle_timeout (PinosSource *source)
 | 
			
		||||
{
 | 
			
		||||
  PinosSourcePrivate *priv = source->priv;
 | 
			
		||||
 | 
			
		||||
  priv->idle_timeout = 0;
 | 
			
		||||
  pinos_source_set_state (source, PINOS_SOURCE_STATE_SUSPENDED);
 | 
			
		||||
 | 
			
		||||
  return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
pinos_source_report_idle (PinosSource *source)
 | 
			
		||||
{
 | 
			
		||||
  PinosSourcePrivate *priv;
 | 
			
		||||
 | 
			
		||||
  g_return_if_fail (PINOS_IS_SOURCE (source));
 | 
			
		||||
  priv = source->priv;
 | 
			
		||||
 | 
			
		||||
  pinos_source_set_state (source, PINOS_SOURCE_STATE_IDLE);
 | 
			
		||||
 | 
			
		||||
  priv->idle_timeout = g_timeout_add_seconds (3,
 | 
			
		||||
                                              (GSourceFunc) idle_timeout,
 | 
			
		||||
                                              source);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
pinos_source_report_busy (PinosSource *source)
 | 
			
		||||
{
 | 
			
		||||
  g_return_if_fail (PINOS_IS_SOURCE (source));
 | 
			
		||||
 | 
			
		||||
  pinos_source_set_state (source, PINOS_SOURCE_STATE_RUNNING);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
pinos_source_update_possible_formats (PinosSource *source, GBytes *formats)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue