<commit_before>/*
 * Copyright (C) 2009-2010 <NAME>
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This file may be used under the terms of the GNU Lesser General Public
 * License version 2.1, a copy of which is found in LICENSE included in the
 * packaging of this file.
 */

#include "gstdsph263enc.h"
#include "plugin.h"

#include "util.h"
#include "dsp_bridge.h"

#include "log.h"

#include <string.h>

#define GST_CAT_DEFAULT gstdsp_debug

#define td_mp4venc_codec td_fake_codec

/*
 * H.263 supported levels
 * source: http://www.itu.int/rec/T-REC-H.263/  , page 208- table of levels.
 */

static struct gstdsp_codec_level levels[] = {
	{10,   99,  1485,    64000 },        /* Level 10 - QCIF@15fps */
	{20,  396,  5940,   128000 },        /* Level 20 - CIF@15fps */
	{30,  396, 11880,   384000 },        /* Level 30 - CIF@30fps */
	{40,  396, 11880,  2048000 },        /* Level 40 - CIF@30fps */
	{45,   99,  1485,   128000 },        /* Level 45 - QCIF@15fps */
	{50,  396, 19800,  4096000 },        /* Level 50 - CIF@50fps */
	{60,  810, 40500,  8192000 },        /* Level 60 - 720x288@50fps */
	{70, 1620, 81000, 16384000 },        /* Level 70 - 4CIF@50fps */
};

static inline GstCaps *
generate_src_template(void)
{
	GstCaps *caps;
	GstStructure *struc;

	caps = gst_caps_new_empty();

	struc = gst_structure_new("video/x-h263",
				  "variant", G_TYPE_STRING, "itu",
				  NULL);

	gst_caps_append_structure(caps, struc);

	return caps;
}

static inline gboolean
is_hd_codec()
{
	const gchar *codec = g_getenv(CODEC_ENV_VAR);

	/* default HD, otherwise as indicated by choice */
	if (codec)
		return (strcmp(codec, "HD") == 0);
	else
		return TRUE;
}

static void
instance_init(GTypeInstance *instance,
	      gpointer g_class)
{
	GstDspBase *base = GST_DSP_BASE(instance);
	GstDspVEnc *self = GST_DSP_VENC(instance);

	if (is_hd_codec()) {
		base->alg = GSTDSP_H263P0ENC;
		base->codec = &td_hdmp4venc_codec;
	} else {
		base->alg = GSTDSP_H263ENC;
		base->codec = &td_mp4venc_codec;
	}
	base->use_pinned = true;

	self->supported_levels = levels;
	self->nr_supported_levels = ARRAY_SIZE(levels);
}

static void
base_init(gpointer g_class)
{
	GstElementClass *element_class;
	GstPadTemplate *template;<commit_msg>h263enc: proxy downstream restrictions in getcaps<commit_after>/*
 * Copyright (C) 2009-2010 <NAME>
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This file may be used under the terms of the GNU Lesser General Public
 * License version 2.1, a copy of which is found in LICENSE included in the
 * packaging of this file.
 */

#include "gstdsph263enc.h"
#include "plugin.h"

#include "util.h"
#include "dsp_bridge.h"

#include "log.h"

#include <string.h>

#define GST_CAT_DEFAULT gstdsp_debug

#define td_mp4venc_codec td_fake_codec

/*
 * H.263 supported levels
 * source: http://www.itu.int/rec/T-REC-H.263/  , page 208- table of levels.
 */

static struct gstdsp_codec_level levels[] = {
	{10,   99,  1485,    64000 },        /* Level 10 - QCIF@15fps */
	{20,  396,  5940,   128000 },        /* Level 20 - CIF@15fps */
	{30,  396, 11880,   384000 },        /* Level 30 - CIF@30fps */
	{40,  396, 11880,  2048000 },        /* Level 40 - CIF@30fps */
	{45,   99,  1485,   128000 },        /* Level 45 - QCIF@15fps */
	{50,  396, 19800,  4096000 },        /* Level 50 - CIF@50fps */
	{60,  810, 40500,  8192000 },        /* Level 60 - 720x288@50fps */
	{70, 1620, 81000, 16384000 },        /* Level 70 - 4CIF@50fps */
};

static inline GstCaps *
generate_src_template(void)
{
	GstCaps *caps;
	GstStructure *struc;

	caps = gst_caps_new_empty();

	struc = gst_structure_new("video/x-h263",
				  "variant", G_TYPE_STRING, "itu",
				  NULL);

	gst_caps_append_structure(caps, struc);

	return caps;
}

static inline gboolean
is_hd_codec()
{
	const gchar *codec = g_getenv(CODEC_ENV_VAR);

	/* default HD, otherwise as indicated by choice */
	if (codec)
		return (strcmp(codec, "HD") == 0);
	else
		return TRUE;
}

static GstCaps *
sink_getcaps(GstPad *pad)
{
	GstDspBase *base = GST_DSP_BASE(GST_PAD_PARENT(pad));
	GstCaps *tmpcaps = gst_caps_new_empty();
	GstCaps *allowed_caps;
	GstCaps *caps = NULL;
	guint i;

	allowed_caps = gst_pad_get_allowed_caps(base->srcpad);

	if (!allowed_caps || gst_caps_is_any(allowed_caps))
		return gst_caps_copy(gst_pad_get_pad_template_caps(pad));

	if (gst_caps_is_empty(allowed_caps))
		return allowed_caps;

	for (i = 0; i < gst_caps_get_size(allowed_caps); i++) {
		GstStructure *s = gst_caps_get_structure(allowed_caps, i);
		const GValue *height = NULL;
		const GValue *width = NULL;
		const GValue *framerate = NULL;
		GstStructure *tmps;

		height = gst_structure_get_value(s, "height");
		width = gst_structure_get_value(s, "width");
		framerate = gst_structure_get_value(s, "framerate");

		tmps = gst_structure_new("video/x-raw-yuv", NULL);
		if (width)
			gst_structure_set_value(tmps, "width", width);
		if (height)
			gst_structure_set_value(tmps, "height", height);
		if (framerate)
			gst_structure_set_value(tmps, "framerate", framerate);
		gst_caps_merge_structure(tmpcaps, tmps);
	}
	gst_caps_unref(allowed_caps);

	caps = gst_caps_intersect(tmpcaps, gst_pad_get_pad_template_caps(pad));

	gst_caps_unref(tmpcaps);

	return caps;
}

static void
instance_init(GTypeInstance *instance,
	      gpointer g_class)
{
	GstDspBase *base = GST_DSP_BASE(instance);
	GstDspVEnc *self = GST_DSP_VENC(instance);

	if (is_hd_codec()) {
		base->alg = GSTDSP_H263P0ENC;
		base->codec = &td_hdmp4venc_codec;
	} else {
		base->alg = GSTDSP_H263ENC;
		base->codec = &td_mp4venc_codec;
	}
	base->use_pinned = true;

	self->supported_levels = levels;
	self->nr_supported_levels = ARRAY_SIZE(levels);

	/* FIXME pretty generic, should work for venc */
	gst_pad_set_getcaps_function(base->sinkpad, sink_getcaps);
}

static void
base_init(gpointer g_class)
{
	GstElementClass *element_class;
	GstPadTemplate *template;
{'fraction_non_alphanumeric': 0.13151152860802734, 'fraction_numerical': 0.07002561912894961, 'mean_word_length': 3.772616136919315, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6151010', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2312, 'n_words': 519}