mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pinossrc: use a queue for the buffers
Use a queue to keep the buffers around and pass them to the streaming thread.
This commit is contained in:
		
							parent
							
								
									c6079cf7d2
								
							
						
					
					
						commit
						a25bdf8acb
					
				
					 2 changed files with 18 additions and 16 deletions
				
			
		| 
						 | 
					@ -172,6 +172,7 @@ gst_pinos_src_finalize (GObject * object)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GstPinosSrc *pinossrc = GST_PINOS_SRC (object);
 | 
					  GstPinosSrc *pinossrc = GST_PINOS_SRC (object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_queue_free_full (&pinossrc->queue, (GDestroyNotify) gst_mini_object_unref);
 | 
				
			||||||
  if (pinossrc->properties)
 | 
					  if (pinossrc->properties)
 | 
				
			||||||
    gst_structure_free (pinossrc->properties);
 | 
					    gst_structure_free (pinossrc->properties);
 | 
				
			||||||
  g_object_unref (pinossrc->fd_allocator);
 | 
					  g_object_unref (pinossrc->fd_allocator);
 | 
				
			||||||
| 
						 | 
					@ -262,6 +263,8 @@ gst_pinos_src_init (GstPinosSrc * src)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
 | 
					  GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_queue_init (&src->queue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  src->fd_allocator = gst_fd_allocator_new ();
 | 
					  src->fd_allocator = gst_fd_allocator_new ();
 | 
				
			||||||
  src->client_name = pinos_client_name ();
 | 
					  src->client_name = pinos_client_name ();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -429,9 +432,7 @@ on_new_buffer (GObject    *gobject,
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (pinossrc->current)
 | 
					  g_queue_push_tail (&pinossrc->queue, buf);
 | 
				
			||||||
    gst_buffer_unref (pinossrc->current);
 | 
					 | 
				
			||||||
  pinossrc->current = buf;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_signal (pinossrc->loop, FALSE);
 | 
					  pinos_main_loop_signal (pinossrc->loop, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -740,8 +741,6 @@ gst_pinos_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
 | 
				
			||||||
    if (pinossrc->flushing)
 | 
					    if (pinossrc->flushing)
 | 
				
			||||||
      goto streaming_stopped;
 | 
					      goto streaming_stopped;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pinos_main_loop_wait (pinossrc->loop);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    state = pinos_stream_get_state (pinossrc->stream);
 | 
					    state = pinos_stream_get_state (pinossrc->stream);
 | 
				
			||||||
    if (state == PINOS_STREAM_STATE_ERROR)
 | 
					    if (state == PINOS_STREAM_STATE_ERROR)
 | 
				
			||||||
      goto streaming_error;
 | 
					      goto streaming_error;
 | 
				
			||||||
| 
						 | 
					@ -749,11 +748,12 @@ gst_pinos_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
 | 
				
			||||||
    if (state != PINOS_STREAM_STATE_STREAMING)
 | 
					    if (state != PINOS_STREAM_STATE_STREAMING)
 | 
				
			||||||
      goto streaming_stopped;
 | 
					      goto streaming_stopped;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pinossrc->current != NULL)
 | 
					    *buffer = g_queue_pop_head (&pinossrc->queue);
 | 
				
			||||||
 | 
					    if (*buffer != NULL)
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pinos_main_loop_wait (pinossrc->loop);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  *buffer = pinossrc->current;
 | 
					 | 
				
			||||||
  pinossrc->current = NULL;
 | 
					 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return GST_FLOW_OK;
 | 
					  return GST_FLOW_OK;
 | 
				
			||||||
| 
						 | 
					@ -780,6 +780,13 @@ gst_pinos_src_start (GstBaseSrc * basesrc)
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					clear_queue (GstPinosSrc *pinossrc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  g_queue_foreach (&pinossrc->queue, (GFunc) gst_mini_object_unref, NULL);
 | 
				
			||||||
 | 
					  g_queue_clear (&pinossrc->queue);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gboolean
 | 
					static gboolean
 | 
				
			||||||
gst_pinos_src_stop (GstBaseSrc * basesrc)
 | 
					gst_pinos_src_stop (GstBaseSrc * basesrc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -788,9 +795,7 @@ gst_pinos_src_stop (GstBaseSrc * basesrc)
 | 
				
			||||||
  pinossrc = GST_PINOS_SRC (basesrc);
 | 
					  pinossrc = GST_PINOS_SRC (basesrc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_main_loop_lock (pinossrc->loop);
 | 
					  pinos_main_loop_lock (pinossrc->loop);
 | 
				
			||||||
  if (pinossrc->current)
 | 
					  clear_queue (pinossrc);
 | 
				
			||||||
    gst_buffer_unref (pinossrc->current);
 | 
					 | 
				
			||||||
  pinossrc->current = NULL;
 | 
					 | 
				
			||||||
  pinos_main_loop_unlock (pinossrc->loop);
 | 
					  pinos_main_loop_unlock (pinossrc->loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
| 
						 | 
					@ -905,10 +910,7 @@ gst_pinos_src_close (GstPinosSrc * pinossrc)
 | 
				
			||||||
  pinossrc->stream_state = PINOS_STREAM_STATE_UNCONNECTED;
 | 
					  pinossrc->stream_state = PINOS_STREAM_STATE_UNCONNECTED;
 | 
				
			||||||
  g_clear_object (&pinossrc->stream);
 | 
					  g_clear_object (&pinossrc->stream);
 | 
				
			||||||
  GST_OBJECT_UNLOCK (pinossrc);
 | 
					  GST_OBJECT_UNLOCK (pinossrc);
 | 
				
			||||||
 | 
					  clear_queue (pinossrc);
 | 
				
			||||||
  if (pinossrc->current)
 | 
					 | 
				
			||||||
    gst_buffer_unref (pinossrc->current);
 | 
					 | 
				
			||||||
  pinossrc->current = NULL;
 | 
					 | 
				
			||||||
  if (pinossrc->clock)
 | 
					  if (pinossrc->clock)
 | 
				
			||||||
    gst_object_unref (pinossrc->clock);
 | 
					    gst_object_unref (pinossrc->clock);
 | 
				
			||||||
  pinossrc->clock = NULL;
 | 
					  pinossrc->clock = NULL;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ struct _GstPinosSrc {
 | 
				
			||||||
  GstAllocator *fd_allocator;
 | 
					  GstAllocator *fd_allocator;
 | 
				
			||||||
  GstStructure *properties;
 | 
					  GstStructure *properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  GstBuffer *current;
 | 
					  GQueue queue;
 | 
				
			||||||
  GstClock *clock;
 | 
					  GstClock *clock;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue