<commit_before>/*
 * Copyright (C) 2013 Jolla LTD.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "test.h"
#define CAMERA_SRC "droidcamsrc"
#define VIDEO_SINK "hwcsink"

static gboolean
timeout_cb (gpointer user_data)
{
  TestPipeline *pipeline = (TestPipeline *) user_data;

  gst_element_send_event (pipeline->pipeline, gst_event_new_eos ());

  g_main_loop_quit (pipeline->loop);

  return FALSE;                 /* Bye! */
}

static gboolean
bus_call (GstBus * bus, GstMessage * msg, gpointer data)
{
  TestPipeline *pipeline = (TestPipeline *) data;

  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_ELEMENT:{
      const GstStructure *structure = gst_message_get_structure (msg);
      const gchar *filename;

      if (gst_structure_has_name (structure, "GstMultiFileSink")) {
        filename = gst_structure_get_string (structure, "filename");
        g_print ("Image %s has been saved\n", filename);

        gst_element_set_state (pipeline->fs, GST_STATE_NULL);
        gst_element_set_locked_state (pipeline->fs, TRUE);
      }

      break;
    }

    case GST_MESSAGE_EOS:
      g_printerr ("End of stream\n");
      pipeline->ret = 0;
      g_main_loop_quit (pipeline->loop);
      break;

    case GST_MESSAGE_ERROR:{
      gchar *debug;
      GError *error;

      gst_message_parse_error (msg, &error, &debug);
      g_printerr ("Error: %s (%s)\n", error->message, debug);
      g_error_free (error);

      if (debug) {
        g_free (debug);
      }

      pipeline->ret = 1;
      g_main_loop_quit (pipeline->loop);
      break;
    }

    case GST_MESSAGE_WARNING:{
      gchar *debug;
      GError *error;

      gst_message_parse_warning (msg, &error, &debug);

      g_printerr ("Warning: %s (%s)\n", error->message, debug);
      g_error_free (error);

      if (debug) {
        g_free (debug);
      }

      pipeline->ret = 1;
      g_main_loop_quit (pipeline->loop);
      break;
    }

    default:
      break;
  }

  return TRUE;
}

static gboolean
imgsrc_data_probe (GstPad * pad, GstMiniObject * obj, gpointer user_data)
{
  TestPipeline *pipeline = (TestPipeline *) user_data;

  gst_element_set_locked_state (pipeline->fs, FALSE);

  gst_element_set_state (pipeline->fs, GST_STATE_PLAYING);

  return TRUE;                  /* keep data. */
}

TestPipeline *
test_pipeline_new (int argc, char *argv[])
{
  GstBus *bus;
  TestPipeline *pipeline;
  GstPad *pad;

  gst_init (&argc, &argv);

  pipeline = g_new0 (TestPipeline, 1);
  pipeline->loop = g_main_loop_new (NULL, FALSE);

  pipeline->src = gst_element_factory_make (CAMERA_SRC, NULL);
  if (!pipeline->src) {
    g_printerr ("Failed to create %s element", CAMERA_SRC);
    goto error;
  }

  pipeline->vf_csp = gst_element_factory_make ("capsfilter", NULL);
  if (!pipeline->vf_csp) {
    g_printerr ("Failed to create viewfinder capsfilter element");
    goto error;
  }

  pipeline->vf = gst_element_factory_make (VIDEO_SINK, NULL);
  if (!pipeline->vf) {
    g_printerr ("Failed to create %s element", VIDEO_SINK);
    goto error;
  }

  pipeline->vf_q = gst_element_factory_make ("queue", NULL);
  if (!pipeline->vf_q) {
    g_printerr ("Failed to create viewfinder queue");
    goto error;
  }

  pipeline->fs = gst_element_factory_make ("multifilesink", NULL);
  if (!pipeline->fs) {
    g_printerr ("Failed to create multifilesink element");
    goto error;
  }

  g_object_set (pipeline->fs, "async", FALSE, "post-messages", TRUE, "location",
      "%05d.jpg", NULL);
  gst_element_set_locked_state (pipeline->fs, TRUE);

  pipeline->fs_csp = gst_element_factory_make ("capsfilter", NULL);
  if (!pipeline->fs_csp) {
    g_printerr ("Failed to create image capture capsfilter element");
    goto error;
  }

  pipeline->fs_q = gst_element_factory_make ("queue", NULL);
  if (!pipeline->fs_q) {
    g_printerr ("Failed to create image capture queue");
    goto error;
  }
<commit_msg>Set our pipeline queues to leaky and allow them to hold 1 maximum of 1 buffer<commit_after>/*
 * Copyright (C) 2013 Jolla LTD.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "test.h"
#define CAMERA_SRC "droidcamsrc"
#define VIDEO_SINK "hwcsink"

static gboolean
timeout_cb (gpointer user_data)
{
  TestPipeline *pipeline = (TestPipeline *) user_data;

  gst_element_send_event (pipeline->pipeline, gst_event_new_eos ());

  g_main_loop_quit (pipeline->loop);

  return FALSE;                 /* Bye! */
}

static gboolean
bus_call (GstBus * bus, GstMessage * msg, gpointer data)
{
  TestPipeline *pipeline = (TestPipeline *) data;

  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_ELEMENT:{
      const GstStructure *structure = gst_message_get_structure (msg);
      const gchar *filename;

      if (gst_structure_has_name (structure, "GstMultiFileSink")) {
        filename = gst_structure_get_string (structure, "filename");
        g_print ("Image %s has been saved\n", filename);

        gst_element_set_state (pipeline->fs, GST_STATE_NULL);
        gst_element_set_locked_state (pipeline->fs, TRUE);
      }

      break;
    }

    case GST_MESSAGE_EOS:
      g_printerr ("End of stream\n");
      pipeline->ret = 0;
      g_main_loop_quit (pipeline->loop);
      break;

    case GST_MESSAGE_ERROR:{
      gchar *debug;
      GError *error;

      gst_message_parse_error (msg, &error, &debug);
      g_printerr ("Error: %s (%s)\n", error->message, debug);
      g_error_free (error);

      if (debug) {
        g_free (debug);
      }

      pipeline->ret = 1;
      g_main_loop_quit (pipeline->loop);
      break;
    }

    case GST_MESSAGE_WARNING:{
      gchar *debug;
      GError *error;

      gst_message_parse_warning (msg, &error, &debug);

      g_printerr ("Warning: %s (%s)\n", error->message, debug);
      g_error_free (error);

      if (debug) {
        g_free (debug);
      }

      pipeline->ret = 1;
      g_main_loop_quit (pipeline->loop);
      break;
    }

    default:
      break;
  }

  return TRUE;
}

static gboolean
imgsrc_data_probe (GstPad * pad, GstMiniObject * obj, gpointer user_data)
{
  TestPipeline *pipeline = (TestPipeline *) user_data;

  gst_element_set_locked_state (pipeline->fs, FALSE);

  gst_element_set_state (pipeline->fs, GST_STATE_PLAYING);

  return TRUE;                  /* keep data. */
}

TestPipeline *
test_pipeline_new (int argc, char *argv[])
{
  GstBus *bus;
  TestPipeline *pipeline;
  GstPad *pad;

  gst_init (&argc, &argv);

  pipeline = g_new0 (TestPipeline, 1);
  pipeline->loop = g_main_loop_new (NULL, FALSE);

  pipeline->src = gst_element_factory_make (CAMERA_SRC, NULL);
  if (!pipeline->src) {
    g_printerr ("Failed to create %s element", CAMERA_SRC);
    goto error;
  }

  pipeline->vf_csp = gst_element_factory_make ("capsfilter", NULL);
  if (!pipeline->vf_csp) {
    g_printerr ("Failed to create viewfinder capsfilter element");
    goto error;
  }

  pipeline->vf = gst_element_factory_make (VIDEO_SINK, NULL);
  if (!pipeline->vf) {
    g_printerr ("Failed to create %s element", VIDEO_SINK);
    goto error;
  }

  pipeline->vf_q = gst_element_factory_make ("queue", NULL);
  if (!pipeline->vf_q) {
    g_printerr ("Failed to create viewfinder queue");
    goto error;
  }

  g_object_set (pipeline->vf_q, "leaky", 1, "max-size-buffers", 1, NULL);
  pipeline->fs = gst_element_factory_make ("multifilesink", NULL);
  if (!pipeline->fs) {
    g_printerr ("Failed to create multifilesink element");
    goto error;
  }

  g_object_set (pipeline->fs, "async", FALSE, "post-messages", TRUE, "location",
      "%05d.jpg", NULL);
  gst_element_set_locked_state (pipeline->fs, TRUE);

  pipeline->fs_csp = gst_element_factory_make ("capsfilter", NULL);
  if (!pipeline->fs_csp) {
    g_printerr ("Failed to create image capture capsfilter element");
    goto error;
  }

  pipeline->fs_q = gst_element_factory_make ("queue", NULL);
  if (!pipeline->fs_q) {
    g_printerr ("Failed to create image capture queue");
    goto error;
  }

  g_object_set (pipeline->fs_q, "leaky", 1, "max-size-buffers", 1, NULL);

{'fraction_non_alphanumeric': 0.11355194736283561, 'fraction_numerical': 0.0061551522869574445, 'mean_word_length': 3.3934731934731936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2425262', 'n_tokens_mistral': 3201, 'n_tokens_neox': 3137, 'n_words': 881}