mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	client-source: set format on client source
Set the format on the client source when it is created so that other clients can inspect the format. It also makes client sources show up in the device monitor.
This commit is contained in:
		
							parent
							
								
									81b7f15a0c
								
							
						
					
					
						commit
						1fec75d2a5
					
				
					 5 changed files with 109 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -37,11 +37,64 @@ struct _PinosClientSourcePrivate
 | 
			
		|||
 | 
			
		||||
  GSocket *socket;
 | 
			
		||||
 | 
			
		||||
  GBytes *possible_formats;
 | 
			
		||||
 | 
			
		||||
  PinosSourceOutput *input;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (PinosClientSource, pinos_client_source, PINOS_TYPE_SOURCE);
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
  PROP_0,
 | 
			
		||||
  PROP_POSSIBLE_FORMATS
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
client_source_get_property (GObject    *_object,
 | 
			
		||||
                            guint       prop_id,
 | 
			
		||||
                            GValue     *value,
 | 
			
		||||
                            GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
  PinosClientSource *source = PINOS_CLIENT_SOURCE (_object);
 | 
			
		||||
  PinosClientSourcePrivate *priv = source->priv;
 | 
			
		||||
 | 
			
		||||
  switch (prop_id) {
 | 
			
		||||
    case PROP_POSSIBLE_FORMATS:
 | 
			
		||||
      g_value_set_boxed (value, priv->possible_formats);
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
client_source_set_property (GObject      *_object,
 | 
			
		||||
                            guint         prop_id,
 | 
			
		||||
                            const GValue *value,
 | 
			
		||||
                            GParamSpec   *pspec)
 | 
			
		||||
{
 | 
			
		||||
  PinosClientSource *source = PINOS_CLIENT_SOURCE (_object);
 | 
			
		||||
  PinosClientSourcePrivate *priv = source->priv;
 | 
			
		||||
 | 
			
		||||
  switch (prop_id) {
 | 
			
		||||
    case PROP_POSSIBLE_FORMATS:
 | 
			
		||||
      if (priv->possible_formats)
 | 
			
		||||
        g_bytes_unref (priv->possible_formats);
 | 
			
		||||
      priv->possible_formats = g_value_dup_boxed (value);
 | 
			
		||||
      pinos_source_update_possible_formats (PINOS_SOURCE (source),
 | 
			
		||||
                                            priv->possible_formats);
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      G_OBJECT_WARN_INVALID_PROPERTY_ID (source, prop_id, pspec);
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static gboolean
 | 
			
		||||
bus_handler (GstBus     *bus,
 | 
			
		||||
             GstMessage *message,
 | 
			
		||||
| 
						 | 
				
			
			@ -287,14 +340,14 @@ on_input_socket_notify (GObject    *gobject,
 | 
			
		|||
    g_assert (requested_format != NULL);
 | 
			
		||||
    g_object_set (gobject, "format", requested_format, NULL);
 | 
			
		||||
 | 
			
		||||
    /* and set as caps on the filter */
 | 
			
		||||
    /* and set as caps on the source */
 | 
			
		||||
    caps = gst_caps_from_string (g_bytes_get_data (requested_format, NULL));
 | 
			
		||||
    g_assert (caps != NULL);
 | 
			
		||||
    g_object_set (priv->filter, "caps", caps, NULL);
 | 
			
		||||
    g_object_set (priv->src, "caps", caps, NULL);
 | 
			
		||||
    gst_caps_unref (caps);
 | 
			
		||||
    g_bytes_unref (requested_format);
 | 
			
		||||
  } else {
 | 
			
		||||
    g_object_set (priv->filter, "caps", NULL, NULL);
 | 
			
		||||
    g_object_set (priv->src, "caps", NULL, NULL);
 | 
			
		||||
  }
 | 
			
		||||
  g_object_set (priv->src, "socket", socket, NULL);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -316,7 +369,12 @@ pinos_client_source_get_source_input (PinosClientSource *source,
 | 
			
		|||
  g_return_val_if_fail (PINOS_IS_CLIENT_SOURCE (source), NULL);
 | 
			
		||||
  priv = source->priv;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  if (priv->input == NULL) {
 | 
			
		||||
    GstCaps *caps = gst_caps_from_string (g_bytes_get_data (format_filter, NULL));
 | 
			
		||||
 | 
			
		||||
    g_object_set (priv->filter, "caps", caps, NULL);
 | 
			
		||||
 | 
			
		||||
    priv->input = PINOS_SOURCE_CLASS (pinos_client_source_parent_class)
 | 
			
		||||
                        ->create_source_output (PINOS_SOURCE (source),
 | 
			
		||||
                                                client_path,
 | 
			
		||||
| 
						 | 
				
			
			@ -342,6 +400,18 @@ pinos_client_source_class_init (PinosClientSourceClass * klass)
 | 
			
		|||
  gobject_class->dispose = client_source_dispose;
 | 
			
		||||
  gobject_class->finalize = client_source_finalize;
 | 
			
		||||
 | 
			
		||||
  gobject_class->get_property = client_source_get_property;
 | 
			
		||||
  gobject_class->set_property = client_source_set_property;
 | 
			
		||||
 | 
			
		||||
  g_object_class_install_property (gobject_class,
 | 
			
		||||
                                   PROP_POSSIBLE_FORMATS,
 | 
			
		||||
                                   g_param_spec_boxed ("possible-formats",
 | 
			
		||||
                                                       "Possible Format",
 | 
			
		||||
                                                       "The possible formats of the stream",
 | 
			
		||||
                                                       G_TYPE_BYTES,
 | 
			
		||||
                                                       G_PARAM_READWRITE |
 | 
			
		||||
                                                       G_PARAM_STATIC_STRINGS));
 | 
			
		||||
 | 
			
		||||
  source_class->get_formats = client_get_formats;
 | 
			
		||||
  source_class->set_state = client_set_state;
 | 
			
		||||
  source_class->create_source_output = client_create_source_output;
 | 
			
		||||
| 
						 | 
				
			
			@ -357,10 +427,12 @@ pinos_client_source_init (PinosClientSource * source)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
PinosSource *
 | 
			
		||||
pinos_client_source_new (PinosDaemon *daemon)
 | 
			
		||||
pinos_client_source_new (PinosDaemon *daemon,
 | 
			
		||||
                         GBytes      *possible_formats)
 | 
			
		||||
{
 | 
			
		||||
  return g_object_new (PINOS_TYPE_CLIENT_SOURCE,
 | 
			
		||||
                              "daemon", daemon,
 | 
			
		||||
                              "name", "client-source",
 | 
			
		||||
                              "possible-formats", possible_formats,
 | 
			
		||||
                              NULL);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,7 +63,8 @@ struct _PinosClientSourceClass {
 | 
			
		|||
/* normal GObject stuff */
 | 
			
		||||
GType               pinos_client_source_get_type         (void);
 | 
			
		||||
 | 
			
		||||
PinosSource *       pinos_client_source_new              (PinosDaemon *daemon);
 | 
			
		||||
PinosSource *       pinos_client_source_new              (PinosDaemon *daemon,
 | 
			
		||||
                                                          GBytes      *possible_formats);
 | 
			
		||||
 | 
			
		||||
PinosSourceOutput * pinos_client_source_get_source_input (PinosClientSource *source,
 | 
			
		||||
                                                          const gchar       *client_path,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -230,7 +230,9 @@ handle_create_source_input (PinosClient1           *interface,
 | 
			
		|||
  if (g_strcmp0 (pinos_client_get_sender (client), sender) != 0)
 | 
			
		||||
    goto not_allowed;
 | 
			
		||||
 | 
			
		||||
  source = pinos_client_source_new (priv->daemon);
 | 
			
		||||
  formats = g_bytes_new (arg_possible_formats, strlen (arg_possible_formats) + 1);
 | 
			
		||||
 | 
			
		||||
  source = pinos_client_source_new (priv->daemon, formats);
 | 
			
		||||
  if (source == NULL)
 | 
			
		||||
    goto no_source;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -241,7 +243,6 @@ handle_create_source_input (PinosClient1           *interface,
 | 
			
		|||
 | 
			
		||||
  sender = g_dbus_method_invocation_get_sender (invocation);
 | 
			
		||||
 | 
			
		||||
  formats = g_bytes_new (arg_possible_formats, strlen (arg_possible_formats) + 1);
 | 
			
		||||
 | 
			
		||||
  input = pinos_client_source_get_source_input (PINOS_CLIENT_SOURCE (source),
 | 
			
		||||
                                                priv->object_path,
 | 
			
		||||
| 
						 | 
				
			
			@ -277,6 +278,7 @@ no_source:
 | 
			
		|||
  {
 | 
			
		||||
    g_dbus_method_invocation_return_dbus_error (invocation,
 | 
			
		||||
        "org.pinos.Error", "Can't create source");
 | 
			
		||||
    g_bytes_unref (formats);
 | 
			
		||||
    return TRUE;
 | 
			
		||||
  }
 | 
			
		||||
no_input:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -417,6 +417,19 @@ pinos_source_report_error (PinosSource *source,
 | 
			
		|||
  g_object_notify (G_OBJECT (source), "state");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
pinos_source_update_possible_formats (PinosSource *source, GBytes *formats)
 | 
			
		||||
{
 | 
			
		||||
  PinosSourcePrivate *priv;
 | 
			
		||||
 | 
			
		||||
  g_return_if_fail (PINOS_IS_SOURCE (source));
 | 
			
		||||
  priv = source->priv;
 | 
			
		||||
 | 
			
		||||
  g_object_set (priv->iface, "possible-formats",
 | 
			
		||||
                g_bytes_get_data (formats, NULL),
 | 
			
		||||
                NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PinosSourceOutput *
 | 
			
		||||
pinos_source_create_source_output (PinosSource *source,
 | 
			
		||||
                                   const gchar *client_path,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -78,23 +78,24 @@ struct _PinosSourceClass {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
/* normal GObject stuff */
 | 
			
		||||
GType               pinos_source_get_type               (void);
 | 
			
		||||
GType               pinos_source_get_type                (void);
 | 
			
		||||
 | 
			
		||||
const gchar *       pinos_source_get_object_path        (PinosSource *source);
 | 
			
		||||
const gchar *       pinos_source_get_object_path         (PinosSource *source);
 | 
			
		||||
 | 
			
		||||
GBytes *            pinos_source_get_formats            (PinosSource *source, GBytes *filter);
 | 
			
		||||
GBytes *            pinos_source_get_formats             (PinosSource *source, GBytes *filter);
 | 
			
		||||
 | 
			
		||||
gboolean            pinos_source_set_state              (PinosSource *source, PinosSourceState state);
 | 
			
		||||
void                pinos_source_update_state           (PinosSource *source, PinosSourceState state);
 | 
			
		||||
void                pinos_source_report_error           (PinosSource *source, GError *error);
 | 
			
		||||
gboolean            pinos_source_set_state               (PinosSource *source, PinosSourceState state);
 | 
			
		||||
void                pinos_source_update_state            (PinosSource *source, PinosSourceState state);
 | 
			
		||||
void                pinos_source_report_error            (PinosSource *source, GError *error);
 | 
			
		||||
void                pinos_source_update_possible_formats (PinosSource *source, GBytes *formats);
 | 
			
		||||
 | 
			
		||||
PinosSourceOutput * pinos_source_create_source_output   (PinosSource *source,
 | 
			
		||||
                                                         const gchar *client_path,
 | 
			
		||||
                                                         GBytes      *format_filter,
 | 
			
		||||
                                                         const gchar *prefix,
 | 
			
		||||
                                                         GError      **error);
 | 
			
		||||
gboolean            pinos_source_release_source_output  (PinosSource       *source,
 | 
			
		||||
                                                         PinosSourceOutput *output);
 | 
			
		||||
PinosSourceOutput * pinos_source_create_source_output    (PinosSource *source,
 | 
			
		||||
                                                          const gchar *client_path,
 | 
			
		||||
                                                          GBytes      *format_filter,
 | 
			
		||||
                                                          const gchar *prefix,
 | 
			
		||||
                                                          GError      **error);
 | 
			
		||||
gboolean            pinos_source_release_source_output   (PinosSource       *source,
 | 
			
		||||
                                                          PinosSourceOutput *output);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue