<commit_before>/*
 * (C) Copyright 2014 Kurento (http://kurento.org/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * 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
 * Lesser General Public License for more details.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst.h>

#include "kms-marshal.h"
#include "kmsconfcontroller.h"
#include "kmselement.h"
#include "kmsrecordingprofile.h"
#include "kms-enumtypes.h"
#include "kmsloop.h"

#define DEFAULT_RECORDING_PROFILE KMS_RECORDING_PROFILE_WEBM
#define DEFAULT_HAS_DATA_VALUE FALSE

#define AUDIO_APPSINK "audio_appsink"
#define VIDEO_APPSINK "video_appsink"

#define KEY_DESTINATION_PAD_NAME "kms-pad-key-destination-pad-name"
#define KEY_USE_DVR "kms-use_dvr"
#define KEY_PAD_PROBE_ID "kms-pad-key-probe-id"
#define KEY_APP_SINK "kms-key_app_sink"

#define NAME "confcontroller"

GST_DEBUG_CATEGORY_STATIC (kms_conf_controller_debug_category);
#define GST_CAT_DEFAULT kms_conf_controller_debug_category

G_DEFINE_TYPE_WITH_CODE (KmsConfController, kms_conf_controller,
    G_TYPE_OBJECT,
    GST_DEBUG_CATEGORY_INIT (kms_conf_controller_debug_category, NAME,
        0, "debug category for configuration controller"));

#define KMS_CONF_CONTROLLER_GET_PRIVATE(obj) ( \
  G_TYPE_INSTANCE_GET_PRIVATE (     \
    (obj),                          \
    KMS_TYPE_CONF_CONTROLLER,       \
    KmsConfControllerPrivate        \
  )                                 \
)

typedef enum
{
  UNCONFIGURED,
  CONFIGURING,
  WAIT_PENDING,
  CONFIGURED
} ControllerState;

struct config_data
{
  guint padblocked;
  guint pendingpadsblocked;
  GSList *blockedpads;
  GSList *pendingvalves;
};

struct _KmsConfControllerPrivate
{
  KmsLoop *loop;
  KmsElement *element;
  GstElement *encodebin;
  GstElement *queue;
  GstPipeline *pipeline;
  GstElement *sink;
  KmsRecordingProfile profile;
  ControllerState state;
  gboolean has_data;
  gboolean use_dvr;
  GSList *pads;
  struct config_data *confdata;
};

/* Object properties */
enum
{
  PROP_0,
  PROP_DVR,
  PROP_ELEMENT,
  PROP_HAS_DATA,
  PROP_PIPELINE,
  PROP_PROFILE,
  PROP_SINK,
  N_PROPERTIES
};

static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };

/* signals */
enum
{
  MATCHED_ELEMENTS,
  SINK_REQUIRED,
  SINK_UNREQUIRED,
  LAST_SIGNAL
};

static guint obj_signals[LAST_SIGNAL] = { 0 };

struct config_valve
{
  GstElement *valve;
  const gchar *sinkname;
  const gchar *srcname;
  const gchar *destpadname;
};

static void
destroy_configuration_data (gpointer data)
{
  g_slice_free (struct config_valve, data);
}

static void
destroy_gboolean (gpointer data)
{
  g_slice_free (gboolean, data);
}

static void
destroy_ulong (gpointer data)
{
  g_slice_free (gulong, data);
}

static struct config_valve *
create_configuration_data (GstElement * valve, const gchar * sinkname,
    const gchar * srcname, const gchar * destpadname)
{
  struct config_valve *conf;

  conf = g_slice_new0 (struct config_valve);

  conf->valve = valve;
  conf->sinkname = sinkname;
  conf->srcname = srcname;
  conf->destpadname = destpadname;

  return conf;
}

static GstPadProbeReturn
fake_seek_support (GstPad * pad, GstPadProbeInfo * info, gpointer data)
{
  GstEvent *event = gst_pad_probe_info_get_event (info);

  if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
    GST_INFO ("Seek event received, dropping: %" GST_PTR_FORMAT, event);
    return GST_PAD_PROBE_DROP;
  }

  return GST_PAD_PROBE_OK;
}

static gboolean
fake_query_func (GstPad * pad, GstObject * parent, GstQuery * query)
{
  if (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING) {
    gst_query_set_seeking (query, GST_FORMAT_BYTES, TRUE,
        G_GUINT64_CONSTANT (0), GST_CLOCK_TIME_NONE);

    return TRUE;
  } else if (GST_QUERY_TYPE (query) | GST_QUERY_TYPE_UPSTREAM) {
    return gst_pad_peer_query (pad, query);
  } else {
    return FALSE;<commit_msg>kmsconfcontroller: Use default query function when no other criteria matches our ones.<commit_after>/*
 * (C) Copyright 2014 Kurento (http://kurento.org/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * 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
 * Lesser General Public License for more details.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst.h>

#include "kms-marshal.h"
#include "kmsconfcontroller.h"
#include "kmselement.h"
#include "kmsrecordingprofile.h"
#include "kms-enumtypes.h"
#include "kmsloop.h"

#define DEFAULT_RECORDING_PROFILE KMS_RECORDING_PROFILE_WEBM
#define DEFAULT_HAS_DATA_VALUE FALSE

#define AUDIO_APPSINK "audio_appsink"
#define VIDEO_APPSINK "video_appsink"

#define KEY_DESTINATION_PAD_NAME "kms-pad-key-destination-pad-name"
#define KEY_USE_DVR "kms-use_dvr"
#define KEY_PAD_PROBE_ID "kms-pad-key-probe-id"
#define KEY_APP_SINK "kms-key_app_sink"

#define NAME "confcontroller"

GST_DEBUG_CATEGORY_STATIC (kms_conf_controller_debug_category);
#define GST_CAT_DEFAULT kms_conf_controller_debug_category

G_DEFINE_TYPE_WITH_CODE (KmsConfController, kms_conf_controller,
    G_TYPE_OBJECT,
    GST_DEBUG_CATEGORY_INIT (kms_conf_controller_debug_category, NAME,
        0, "debug category for configuration controller"));

#define KMS_CONF_CONTROLLER_GET_PRIVATE(obj) ( \
  G_TYPE_INSTANCE_GET_PRIVATE (     \
    (obj),                          \
    KMS_TYPE_CONF_CONTROLLER,       \
    KmsConfControllerPrivate        \
  )                                 \
)

typedef enum
{
  UNCONFIGURED,
  CONFIGURING,
  WAIT_PENDING,
  CONFIGURED
} ControllerState;

struct config_data
{
  guint padblocked;
  guint pendingpadsblocked;
  GSList *blockedpads;
  GSList *pendingvalves;
};

struct _KmsConfControllerPrivate
{
  KmsLoop *loop;
  KmsElement *element;
  GstElement *encodebin;
  GstElement *queue;
  GstPipeline *pipeline;
  GstElement *sink;
  KmsRecordingProfile profile;
  ControllerState state;
  gboolean has_data;
  gboolean use_dvr;
  GSList *pads;
  struct config_data *confdata;
};

/* Object properties */
enum
{
  PROP_0,
  PROP_DVR,
  PROP_ELEMENT,
  PROP_HAS_DATA,
  PROP_PIPELINE,
  PROP_PROFILE,
  PROP_SINK,
  N_PROPERTIES
};

static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };

/* signals */
enum
{
  MATCHED_ELEMENTS,
  SINK_REQUIRED,
  SINK_UNREQUIRED,
  LAST_SIGNAL
};

static guint obj_signals[LAST_SIGNAL] = { 0 };

struct config_valve
{
  GstElement *valve;
  const gchar *sinkname;
  const gchar *srcname;
  const gchar *destpadname;
};

static void
destroy_configuration_data (gpointer data)
{
  g_slice_free (struct config_valve, data);
}

static void
destroy_gboolean (gpointer data)
{
  g_slice_free (gboolean, data);
}

static void
destroy_ulong (gpointer data)
{
  g_slice_free (gulong, data);
}

static struct config_valve *
create_configuration_data (GstElement * valve, const gchar * sinkname,
    const gchar * srcname, const gchar * destpadname)
{
  struct config_valve *conf;

  conf = g_slice_new0 (struct config_valve);

  conf->valve = valve;
  conf->sinkname = sinkname;
  conf->srcname = srcname;
  conf->destpadname = destpadname;

  return conf;
}

static GstPadProbeReturn
fake_seek_support (GstPad * pad, GstPadProbeInfo * info, gpointer data)
{
  GstEvent *event = gst_pad_probe_info_get_event (info);

  if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
    GST_INFO ("Seek event received, dropping: %" GST_PTR_FORMAT, event);
    return GST_PAD_PROBE_DROP;
  }

  return GST_PAD_PROBE_OK;
}

static gboolean
fake_query_func (GstPad * pad, GstObject * parent, GstQuery * query)
{
  if (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING) {
    gst_query_set_seeking (query, GST_FORMAT_BYTES, TRUE,
        G_GUINT64_CONSTANT (0), GST_CLOCK_TIME_NONE);

    return TRUE;
  } else if (GST_QUERY_TYPE (query) | GST_QUERY_TYPE_UPSTREAM) {
    return gst_pad_peer_query (pad, query);
  } else {
    return gst_pad_query_default (pad, parent, query);
{'fraction_non_alphanumeric': 0.08689558514365803, 'fraction_numerical': 0.00350385423966363, 'mean_word_length': 4.447201017811705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '875387', 'n_tokens_mistral': 3185, 'n_tokens_neox': 3085, 'n_words': 713}