/* The create() virtual function is responsible for returning the next buffer.
 * We just pop buffers off of the queue and block if necessary.
 */
static GstFlowReturn
shell_recorder_src_create (GstPushSrc  *push_src,
			   GstBuffer  **buffer_out)
{
  ShellRecorderSrc *src = SHELL_RECORDER_SRC (push_src);
  GstBuffer *buffer;

  if (src->closed)
    return GST_FLOW_EOS;

  buffer = g_async_queue_pop (src->queue);

  if (src->last_frame_time == 0)
    src->last_frame_time = gst_clock_get_time (GST_CLOCK (src->clock));

  if (buffer == RECORDER_QUEUE_END)
    {
      /* Returning UNEXPECTED here will cause a EOS message to be sent */
      src->closed = TRUE;
      return GST_FLOW_EOS;
    }

  shell_recorder_src_update_memory_used (src,
					 - (int)(gst_buffer_get_size(buffer) / 1024));

  *buffer_out = buffer;
  GST_BUFFER_DURATION(*buffer_out) = GST_CLOCK_DIFF (src->last_frame_time, gst_clock_get_time (GST_CLOCK (src->clock)));

  src->last_frame_time = gst_clock_get_time (GST_CLOCK (src->clock));

  return GST_FLOW_OK;
}
Пример #2
0
/* The create() virtual function is responsible for returning the next buffer.
 * We just pop buffers off of the queue and block if necessary.
 */
static GstFlowReturn
shell_recorder_src_create (GstPushSrc  *push_src,
			   GstBuffer  **buffer_out)
{
  ShellRecorderSrc *src = SHELL_RECORDER_SRC (push_src);
  GstBuffer *buffer;

  if (src->closed)
    return GST_FLOW_UNEXPECTED;

  buffer = g_async_queue_pop (src->queue);
  if (buffer == RECORDER_QUEUE_END)
    {
      /* Returning UNEXPECTED here will cause a EOS message to be sent */
      src->closed = TRUE;
      return GST_FLOW_UNEXPECTED;
    }

  shell_recorder_src_update_memory_used (src,
					 - (int)(GST_BUFFER_SIZE(buffer) / 1024));

  *buffer_out = buffer;

  return GST_FLOW_OK;
}
Пример #3
0
/**
 * shell_recorder_src_add_buffer:
 *
 * Adds a buffer to the internal queue to be pushed out at the next opportunity.
 * There is no flow control, so arbitrary amounts of memory may be used by
 * the buffers on the queue. The buffer contents must match the #GstCaps
 * set in the :caps property.
 */
void
shell_recorder_src_add_buffer (ShellRecorderSrc *src,
			       GstBuffer        *buffer)
{
  g_return_if_fail (SHELL_IS_RECORDER_SRC (src));
  g_return_if_fail (src->caps != NULL);

  gst_buffer_set_caps (buffer, src->caps);
  shell_recorder_src_update_memory_used (src,
					 (int) (GST_BUFFER_SIZE(buffer) / 1024));

  g_async_queue_push (src->queue, gst_buffer_ref (buffer));
}