mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-04 05:22:30 +00:00
Added lots of configurable parameters including the exported objects of fame.
Original commit message from CVS: Added lots of configurable parameters including the exported objects of fame.
This commit is contained in:
parent
d38b92ded9
commit
4ca1e48612
2 changed files with 364 additions and 171 deletions
|
@ -22,20 +22,23 @@
|
||||||
|
|
||||||
#include "gstlibfame.h"
|
#include "gstlibfame.h"
|
||||||
|
|
||||||
#define LIBFAME_BUFFER_SIZE (300 * 1024)
|
#define FAMEENC_BUFFER_SIZE (300 * 1024)
|
||||||
|
|
||||||
/* elementfactory information */
|
/* elementfactory information */
|
||||||
static GstElementDetails gst_libfame_details = {
|
static GstElementDetails gst_fameenc_details = {
|
||||||
"MPEG1 and MPEG4 video encoder using the libfame library",
|
"MPEG1 and MPEG4 video encoder using the fameenc library",
|
||||||
"Codec/Video/Encoder",
|
"Codec/Video/Encoder",
|
||||||
"Uses libfame to encode MPEG video streams",
|
"Uses fameenc to encode MPEG video streams",
|
||||||
VERSION,
|
VERSION,
|
||||||
"(C) 1996, MPEG Software Simulation Group\n"
|
"fameenc: (C) 2000-2001, Vivien Chappelier\n"
|
||||||
"Thomas Vander Stichele <thomas@apestaart.org>",
|
"Thomas Vander Stichele <thomas@apestaart.org>",
|
||||||
"(C) 2002",
|
"(C) 2002",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Libfame signals and args */
|
static GQuark fame_object_name;
|
||||||
|
|
||||||
|
|
||||||
|
/* FameEnc signals and args */
|
||||||
enum {
|
enum {
|
||||||
/* FILL ME */
|
/* FILL ME */
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
|
@ -44,9 +47,15 @@ enum {
|
||||||
enum {
|
enum {
|
||||||
ARG_0,
|
ARG_0,
|
||||||
ARG_VERSION,
|
ARG_VERSION,
|
||||||
ARG_FPS,
|
ARG_FRAMERATE,
|
||||||
|
ARG_BITRATE,
|
||||||
ARG_QUALITY,
|
ARG_QUALITY,
|
||||||
ARG_PATTERN,
|
ARG_PATTERN,
|
||||||
|
ARG_FAME_VERBOSE,
|
||||||
|
ARG_BUFFER_SIZE,
|
||||||
|
ARG_FRAMES_PER_SEQUENCE,
|
||||||
|
/* dynamically generated properties start here */
|
||||||
|
ARG_FAME_PROPS_START
|
||||||
/* FILL ME */
|
/* FILL ME */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,7 +64,7 @@ GST_PAD_TEMPLATE_FACTORY (sink_template_factory,
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_CAPS_NEW (
|
GST_CAPS_NEW (
|
||||||
"libfame_sink_caps",
|
"fameenc_sink_caps",
|
||||||
"video/raw",
|
"video/raw",
|
||||||
"format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('I','4','2','0')),
|
"format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('I','4','2','0')),
|
||||||
"width", GST_PROPS_INT_RANGE (16, 4096),
|
"width", GST_PROPS_INT_RANGE (16, 4096),
|
||||||
|
@ -68,7 +77,7 @@ GST_PAD_TEMPLATE_FACTORY (src_template_factory,
|
||||||
GST_PAD_SRC,
|
GST_PAD_SRC,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_CAPS_NEW (
|
GST_CAPS_NEW (
|
||||||
"libfame_src_caps",
|
"fameenc_src_caps",
|
||||||
"video/mpeg",
|
"video/mpeg",
|
||||||
"mpegversion", GST_PROPS_LIST (
|
"mpegversion", GST_PROPS_LIST (
|
||||||
GST_PROPS_INT (1), GST_PROPS_INT (4)),
|
GST_PROPS_INT (1), GST_PROPS_INT (4)),
|
||||||
|
@ -76,182 +85,317 @@ GST_PAD_TEMPLATE_FACTORY (src_template_factory,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
static void gst_libfame_class_init (GstLibfameClass *klass);
|
#define MAX_FRAME_RATES 16
|
||||||
static void gst_libfame_init (GstLibfame *libfame);
|
typedef struct
|
||||||
static void gst_libfame_dispose (GObject *object);
|
{
|
||||||
|
gint num;
|
||||||
|
gint den;
|
||||||
|
} frame_rate_entry;
|
||||||
|
|
||||||
static void gst_libfame_set_property (GObject *object, guint prop_id,
|
static const frame_rate_entry frame_rates[] =
|
||||||
|
{
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 24000, 1001 },
|
||||||
|
{ 24, 1 },
|
||||||
|
{ 25, 1 },
|
||||||
|
{ 30000, 1001 },
|
||||||
|
{ 30, 1 },
|
||||||
|
{ 50, 1 },
|
||||||
|
{ 60000, 1001 },
|
||||||
|
{ 60, 1 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
{ 0, 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static gint
|
||||||
|
framerate_to_index (num, den)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_FRAME_RATES; i++) {
|
||||||
|
if (frame_rates[i].num == num && frame_rates[i].den == den)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GST_TYPE_FAMEENC_FRAMERATE (gst_fameenc_framerate_get_type())
|
||||||
|
static GType
|
||||||
|
gst_fameenc_framerate_get_type(void) {
|
||||||
|
static GType fameenc_framerate_type = 0;
|
||||||
|
static GEnumValue fameenc_framerate[] = {
|
||||||
|
{1, "1", "24000/1001 (23.97)"},
|
||||||
|
{2, "2", "24"},
|
||||||
|
{3, "3", "25"},
|
||||||
|
{4, "4", "30000/1001 (29.97)"},
|
||||||
|
{5, "5", "30"},
|
||||||
|
{6, "6", "50"},
|
||||||
|
{7, "7", "60000/1001 (59.94)"},
|
||||||
|
{8, "8", "60"},
|
||||||
|
{0, NULL, NULL},
|
||||||
|
};
|
||||||
|
if (!fameenc_framerate_type) {
|
||||||
|
fameenc_framerate_type = g_enum_register_static("GstFameEncFrameRate", fameenc_framerate);
|
||||||
|
}
|
||||||
|
return fameenc_framerate_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gst_fameenc_class_init (GstFameEncClass *klass);
|
||||||
|
static void gst_fameenc_init (GstFameEnc *fameenc);
|
||||||
|
static void gst_fameenc_dispose (GObject *object);
|
||||||
|
|
||||||
|
static void gst_fameenc_set_property (GObject *object, guint prop_id,
|
||||||
const GValue *value, GParamSpec *pspec);
|
const GValue *value, GParamSpec *pspec);
|
||||||
static void gst_libfame_get_property (GObject *object, guint prop_id,
|
static void gst_fameenc_get_property (GObject *object, guint prop_id,
|
||||||
GValue *value, GParamSpec *pspec);
|
GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
static void gst_libfame_chain (GstPad *pad, GstBuffer *buf);
|
static void gst_fameenc_chain (GstPad *pad, GstBuffer *buf);
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
static GstElementClass *parent_class = NULL;
|
||||||
/*static guint gst_libfame_signals[LAST_SIGNAL] = { 0 };*/
|
/*static guint gst_fameenc_signals[LAST_SIGNAL] = { 0 };*/
|
||||||
|
|
||||||
GType
|
GType
|
||||||
gst_libfame_get_type (void)
|
gst_fameenc_get_type (void)
|
||||||
{
|
{
|
||||||
static GType libfame_type = 0;
|
static GType fameenc_type = 0;
|
||||||
|
|
||||||
if (!libfame_type) {
|
if (!fameenc_type) {
|
||||||
static const GTypeInfo libfame_info = {
|
static const GTypeInfo fameenc_info = {
|
||||||
sizeof (GstLibfameClass),
|
sizeof (GstFameEncClass),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
(GClassInitFunc) gst_libfame_class_init,
|
(GClassInitFunc) gst_fameenc_class_init,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
sizeof (GstLibfame),
|
sizeof (GstFameEnc),
|
||||||
0,
|
0,
|
||||||
(GInstanceInitFunc) gst_libfame_init,
|
(GInstanceInitFunc) gst_fameenc_init,
|
||||||
};
|
};
|
||||||
libfame_type = g_type_register_static (GST_TYPE_ELEMENT,
|
fameenc_type = g_type_register_static (GST_TYPE_ELEMENT,
|
||||||
"GstLibfame", &libfame_info, 0);
|
"GstFameEnc", &fameenc_info, 0);
|
||||||
}
|
}
|
||||||
return libfame_type;
|
return fameenc_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
gst_fameenc_item_compare (fame_list_t *item1, fame_list_t *item2)
|
||||||
|
{
|
||||||
|
return strcmp (item1->type, item2->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_libfame_class_init (GstLibfameClass *klass)
|
gst_fameenc_class_init (GstFameEncClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = NULL;
|
GObjectClass *gobject_class = NULL;
|
||||||
GstElementClass *gstelement_class = NULL;
|
GstElementClass *gstelement_class = NULL;
|
||||||
|
fame_context_t *context;
|
||||||
|
fame_list_t *walk;
|
||||||
|
GList *props = NULL, *props_walk;
|
||||||
|
gint current_prop = ARG_FAME_PROPS_START;
|
||||||
|
|
||||||
gobject_class = (GObjectClass*) klass;
|
gobject_class = (GObjectClass*) klass;
|
||||||
gstelement_class = (GstElementClass*) klass;
|
gstelement_class = (GstElementClass*) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
||||||
|
|
||||||
gobject_class->set_property = gst_libfame_set_property;
|
gobject_class->set_property = gst_fameenc_set_property;
|
||||||
gobject_class->get_property = gst_libfame_get_property;
|
gobject_class->get_property = gst_fameenc_get_property;
|
||||||
gobject_class->dispose = gst_libfame_dispose;
|
gobject_class->dispose = gst_fameenc_dispose;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_VERSION,
|
fame_object_name = g_quark_from_string ("GstFameObjectName");
|
||||||
g_param_spec_int ("mpeg_version", "MPEG Version",
|
|
||||||
"MPEG Codec Version (1 or 4)",
|
context = fame_open ();
|
||||||
1, 4, 1, G_PARAM_READWRITE));
|
g_assert (context);
|
||||||
g_object_class_install_property (gobject_class, ARG_FPS,
|
|
||||||
g_param_spec_double ("frames_per_second", "Frames per second",
|
/* first sort the list */
|
||||||
"Number of frames per second",
|
walk = context->type_list;
|
||||||
-G_MAXDOUBLE, G_MAXDOUBLE, 25.0, G_PARAM_READWRITE));
|
while (walk) {
|
||||||
|
props = g_list_insert_sorted (props, walk, (GCompareFunc)gst_fameenc_item_compare);
|
||||||
|
walk = walk->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
props_walk = props;
|
||||||
|
while (props_walk) {
|
||||||
|
GArray *array;
|
||||||
|
const gchar *current_type;
|
||||||
|
gint current_len;
|
||||||
|
gint current_value;
|
||||||
|
fame_object_t *current_default;
|
||||||
|
gint default_index;
|
||||||
|
|
||||||
|
walk = (fame_list_t *)props_walk->data;
|
||||||
|
array = g_array_new (TRUE, FALSE, sizeof (GEnumValue));
|
||||||
|
|
||||||
|
current_type = walk->type;
|
||||||
|
current_value = 0;
|
||||||
|
current_len = strlen (walk->type);
|
||||||
|
current_default = fame_get_object (context, current_type);
|
||||||
|
default_index = 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (strstr (walk->type, "/")) {
|
||||||
|
GEnumValue value;
|
||||||
|
|
||||||
|
if (current_default == walk->item)
|
||||||
|
default_index = current_value;
|
||||||
|
|
||||||
|
value.value = current_value++;
|
||||||
|
value.value_name = g_strdup (walk->type);
|
||||||
|
value.value_nick = g_strdup (walk->item->name);
|
||||||
|
|
||||||
|
g_array_append_val (array, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
props_walk = g_list_next (props_walk);
|
||||||
|
if (props_walk)
|
||||||
|
walk = (fame_list_t *)props_walk->data;
|
||||||
|
|
||||||
|
} while (props_walk && !strncmp (walk->type, current_type, current_len));
|
||||||
|
|
||||||
|
if (array->len > 0) {
|
||||||
|
GType type;
|
||||||
|
GParamSpec *pspec;
|
||||||
|
|
||||||
|
type = g_enum_register_static (g_strdup_printf ("GstFameEnc_%s", current_type), (GEnumValue *)array->data);
|
||||||
|
|
||||||
|
pspec = g_param_spec_enum (current_type, current_type, g_strdup_printf ("The FAME \"%s\" object", current_type),
|
||||||
|
type, default_index, G_PARAM_READWRITE);
|
||||||
|
|
||||||
|
g_param_spec_set_qdata (pspec, fame_object_name, (gpointer) current_type);
|
||||||
|
|
||||||
|
g_object_class_install_property (G_OBJECT_CLASS (klass), current_prop++, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, ARG_FRAMERATE,
|
||||||
|
g_param_spec_enum ("framerate", "Frame Rate", "Number of frames per second",
|
||||||
|
GST_TYPE_FAMEENC_FRAMERATE, 3, G_PARAM_READWRITE));
|
||||||
|
g_object_class_install_property (gobject_class, ARG_BITRATE,
|
||||||
|
g_param_spec_int ("bitrate", "Bitrate", "Target bitrate (0 = VBR)",
|
||||||
|
0, 5000000, 0, G_PARAM_READWRITE));
|
||||||
g_object_class_install_property (gobject_class, ARG_QUALITY,
|
g_object_class_install_property (gobject_class, ARG_QUALITY,
|
||||||
g_param_spec_int ("quality", "Quality",
|
g_param_spec_int ("quality", "Quality", "Percentage of quality of compression (versus size)",
|
||||||
"Percentage of quality of compression (versus size)",
|
0, 100, 75, G_PARAM_READWRITE));
|
||||||
0, 100, 75, G_PARAM_READWRITE)); /* CHECKME */
|
|
||||||
g_object_class_install_property (gobject_class, ARG_PATTERN,
|
g_object_class_install_property (gobject_class, ARG_PATTERN,
|
||||||
g_param_spec_string ("pattern", "Pattern",
|
g_param_spec_string ("pattern", "Pattern", "Encoding pattern of I, P, and B frames",
|
||||||
"Encoding pattern of I, P, and B frames",
|
"IPPPPPPPPPPP", G_PARAM_READWRITE));
|
||||||
"IPP", G_PARAM_READWRITE)); /* CHECKME */
|
g_object_class_install_property (gobject_class, ARG_FRAMES_PER_SEQUENCE,
|
||||||
|
g_param_spec_int ("frames_per_sequence", "Frames Per Sequence",
|
||||||
|
"The number of frames in one sequence",
|
||||||
|
1, G_MAXINT, 12, G_PARAM_READWRITE));
|
||||||
|
g_object_class_install_property (gobject_class, ARG_FAME_VERBOSE,
|
||||||
|
g_param_spec_boolean ("fame_verbose", "Fame Verbose", "Make FAME produce verbose output",
|
||||||
|
FALSE, G_PARAM_READWRITE));
|
||||||
|
g_object_class_install_property (gobject_class, ARG_BUFFER_SIZE,
|
||||||
|
g_param_spec_int ("buffer_size", "Buffer Size", "Set the decoding output buffer size",
|
||||||
|
0, 1024*1024, FAMEENC_BUFFER_SIZE, G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstPadConnectReturn
|
static GstPadConnectReturn
|
||||||
gst_libfame_sinkconnect (GstPad *pad, GstCaps *caps)
|
gst_fameenc_sinkconnect (GstPad *pad, GstCaps *caps)
|
||||||
{
|
{
|
||||||
gint width, height;
|
gint width, height;
|
||||||
GstLibfame *libfame;
|
GstFameEnc *fameenc;
|
||||||
|
|
||||||
libfame = GST_LIBFAME (gst_pad_get_parent (pad));
|
fameenc = GST_FAMEENC (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
if (!GST_CAPS_IS_FIXED (caps))
|
if (!GST_CAPS_IS_FIXED (caps))
|
||||||
return GST_PAD_CONNECT_DELAYED;
|
return GST_PAD_CONNECT_DELAYED;
|
||||||
|
|
||||||
if (libfame->initialized) {
|
if (fameenc->initialized) {
|
||||||
GST_DEBUG(0, "error: libfame encoder already initialized !");
|
GST_DEBUG(0, "error: fameenc encoder already initialized !");
|
||||||
return GST_PAD_CONNECT_REFUSED;
|
return GST_PAD_CONNECT_REFUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_caps_get_int (caps, "width", &width);
|
gst_caps_get_int (caps, "width", &width);
|
||||||
gst_caps_get_int (caps, "height", &height);
|
gst_caps_get_int (caps, "height", &height);
|
||||||
|
|
||||||
/* FIXME: do better error handling here */
|
/* fameenc requires width and height to be multiples of 16 */
|
||||||
/* libfame requires width and height to be multiples of 16 */
|
if (width % 16 != 0 || height % 16 != 0)
|
||||||
g_assert (width % 16 == 0);
|
return GST_PAD_CONNECT_REFUSED;
|
||||||
g_assert (height % 16 == 0);
|
|
||||||
|
|
||||||
libfame->fp.width = width;
|
fameenc->fp.width = width;
|
||||||
libfame->fp.height = height;
|
fameenc->fp.height = height;
|
||||||
libfame->fp.coding = (const char *) libfame->pattern;
|
fameenc->fp.coding = (const char *) fameenc->pattern;
|
||||||
|
|
||||||
/* FIXME: choose good parameters */
|
/* FIXME: choose good parameters */
|
||||||
libfame->fp.slices_per_frame = 1;
|
fameenc->fp.slices_per_frame = 1;
|
||||||
libfame->fp.frames_per_sequence = 12; /* infinite */
|
|
||||||
/* FIXME: 25 fps */
|
|
||||||
libfame->fp.frame_rate_num = 25;
|
|
||||||
libfame->fp.frame_rate_den = 1;
|
|
||||||
|
|
||||||
/* FIXME: handle these properly */
|
/* FIXME: handle these properly */
|
||||||
libfame->fp.shape_quality = 75;
|
fameenc->fp.shape_quality = 75;
|
||||||
libfame->fp.search_range = 0;
|
fameenc->fp.search_range = 0;
|
||||||
libfame->fp.verbose = 0;
|
fameenc->fp.total_frames = 0;
|
||||||
libfame->fp.profile = "mpeg1";
|
fameenc->fp.retrieve_cb = NULL;
|
||||||
libfame->fp.total_frames = 0;
|
|
||||||
libfame->fp.retrieve_cb = NULL;
|
|
||||||
|
|
||||||
fame_init (libfame->fc, &libfame->fp, libfame->buffer, libfame->buffer_size);
|
fame_init (fameenc->fc, &fameenc->fp, fameenc->buffer, fameenc->buffer_size);
|
||||||
|
|
||||||
g_print ("libfame: init done.\n");
|
fameenc->initialized = TRUE;
|
||||||
g_assert (libfame->fc != NULL); /* FIXME */
|
|
||||||
libfame->initialized = TRUE;
|
|
||||||
|
|
||||||
return GST_PAD_CONNECT_OK;
|
return GST_PAD_CONNECT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_libfame_init (GstLibfame *libfame)
|
gst_fameenc_init (GstFameEnc *fameenc)
|
||||||
{
|
{
|
||||||
g_assert (libfame != NULL);
|
g_assert (fameenc != NULL);
|
||||||
g_assert (GST_IS_LIBFAME (libfame));
|
g_assert (GST_IS_FAMEENC (fameenc));
|
||||||
|
|
||||||
/* open libfame */
|
/* open fameenc */
|
||||||
libfame->fc = fame_open ();
|
fameenc->fc = fame_open ();
|
||||||
g_assert (libfame->fc != NULL);
|
g_assert (fameenc->fc != NULL);
|
||||||
|
|
||||||
/* create the sink and src pads */
|
/* create the sink and src pads */
|
||||||
libfame->sinkpad = gst_pad_new_from_template (
|
fameenc->sinkpad = gst_pad_new_from_template (
|
||||||
GST_PAD_TEMPLATE_GET (sink_template_factory), "sink");
|
GST_PAD_TEMPLATE_GET (sink_template_factory), "sink");
|
||||||
gst_element_add_pad (GST_ELEMENT (libfame), libfame->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (fameenc), fameenc->sinkpad);
|
||||||
gst_pad_set_chain_function (libfame->sinkpad, gst_libfame_chain);
|
gst_pad_set_chain_function (fameenc->sinkpad, gst_fameenc_chain);
|
||||||
gst_pad_set_connect_function (libfame->sinkpad, gst_libfame_sinkconnect);
|
gst_pad_set_connect_function (fameenc->sinkpad, gst_fameenc_sinkconnect);
|
||||||
|
|
||||||
libfame->srcpad = gst_pad_new_from_template (
|
fameenc->srcpad = gst_pad_new_from_template (
|
||||||
GST_PAD_TEMPLATE_GET (src_template_factory), "src");
|
GST_PAD_TEMPLATE_GET (src_template_factory), "src");
|
||||||
gst_element_add_pad (GST_ELEMENT (libfame), libfame->srcpad);
|
gst_element_add_pad (GST_ELEMENT (fameenc), fameenc->srcpad);
|
||||||
/* FIXME: set some more handler functions here */
|
/* FIXME: set some more handler functions here */
|
||||||
|
|
||||||
|
fameenc->verbose = FALSE;
|
||||||
|
|
||||||
/* reset the initial video state */
|
/* reset the initial video state */
|
||||||
libfame->fp.width = -1;
|
fameenc->fp.width = -1;
|
||||||
libfame->fp.height = -1;
|
fameenc->fp.height = -1;
|
||||||
libfame->initialized = FALSE;
|
fameenc->initialized = FALSE;
|
||||||
|
|
||||||
/* defaults */
|
/* defaults */
|
||||||
libfame->fp.quality = 75;
|
fameenc->fp.bitrate = 0;
|
||||||
libfame->fp.frame_rate_num = 25;
|
fameenc->fp.quality = 75;
|
||||||
libfame->fp.frame_rate_den = 1; /* avoid floating point exceptions */
|
fameenc->fp.frame_rate_num = 25;
|
||||||
libfame->fp.profile = g_strdup ("mpeg1");
|
fameenc->fp.frame_rate_den = 1; /* avoid floating point exceptions */
|
||||||
|
fameenc->fp.frames_per_sequence = 12;
|
||||||
|
|
||||||
libfame->pattern = g_strdup ("IPP");
|
fameenc->pattern = g_strdup ("IPPPPPPPPPP");
|
||||||
|
|
||||||
/* allocate space for the buffer */
|
/* allocate space for the buffer */
|
||||||
libfame->buffer_size = LIBFAME_BUFFER_SIZE; /* FIXME */
|
fameenc->buffer_size = FAMEENC_BUFFER_SIZE; /* FIXME */
|
||||||
libfame->buffer = (unsigned char *) g_malloc (libfame->buffer_size);
|
fameenc->buffer = (unsigned char *) g_malloc (fameenc->buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_libfame_dispose (GObject *object)
|
gst_fameenc_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
GstLibfame *libfame = GST_LIBFAME (object);
|
GstFameEnc *fameenc = GST_FAMEENC (object);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
|
|
||||||
g_free (libfame->buffer);
|
g_free (fameenc->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_libfame_chain (GstPad *pad, GstBuffer *buf)
|
gst_fameenc_chain (GstPad *pad, GstBuffer *buf)
|
||||||
{
|
{
|
||||||
GstLibfame *libfame;
|
GstFameEnc *fameenc;
|
||||||
guchar *data;
|
guchar *data;
|
||||||
gulong size;
|
gulong size;
|
||||||
gint frame_size;
|
gint frame_size;
|
||||||
|
@ -262,118 +406,166 @@ gst_libfame_chain (GstPad *pad, GstBuffer *buf)
|
||||||
g_return_if_fail (buf != NULL);
|
g_return_if_fail (buf != NULL);
|
||||||
g_return_if_fail (GST_IS_BUFFER (buf));
|
g_return_if_fail (GST_IS_BUFFER (buf));
|
||||||
|
|
||||||
libfame = GST_LIBFAME (gst_pad_get_parent (pad));
|
fameenc = GST_FAMEENC (gst_pad_get_parent (pad));
|
||||||
|
|
||||||
data = (guchar *) GST_BUFFER_DATA (buf);
|
data = (guchar *) GST_BUFFER_DATA (buf);
|
||||||
size = GST_BUFFER_SIZE (buf);
|
size = GST_BUFFER_SIZE (buf);
|
||||||
|
|
||||||
GST_DEBUG (0,"gst_libfame_chain: got buffer of %ld bytes in '%s'",
|
GST_DEBUG (0,"gst_fameenc_chain: got buffer of %ld bytes in '%s'",
|
||||||
size, GST_OBJECT_NAME (libfame));
|
size, GST_OBJECT_NAME (fameenc));
|
||||||
|
|
||||||
/* the data contains the three planes side by side, with size w * h, w * h /4,
|
/* the data contains the three planes side by side, with size w * h, w * h /4,
|
||||||
* w * h / 4 */
|
* w * h / 4 */
|
||||||
libfame->fy.w = libfame->fp.width;
|
fameenc->fy.w = fameenc->fp.width;
|
||||||
libfame->fy.h = libfame->fp.height;
|
fameenc->fy.h = fameenc->fp.height;
|
||||||
|
|
||||||
frame_size = libfame->fp.width * libfame->fp.height;
|
frame_size = fameenc->fp.width * fameenc->fp.height;
|
||||||
|
|
||||||
libfame->fy.p = 0; /* FIXME: is this pointing to previous data ? */
|
fameenc->fy.p = 0;
|
||||||
libfame->fy.y = data;
|
fameenc->fy.y = data;
|
||||||
libfame->fy.u = data + frame_size;
|
fameenc->fy.u = data + frame_size;
|
||||||
libfame->fy.v = libfame->fy.u + (frame_size >> 2);
|
fameenc->fy.v = fameenc->fy.u + (frame_size >> 2);
|
||||||
|
|
||||||
fame_start_frame (libfame->fc, &libfame->fy, NULL);
|
fame_start_frame (fameenc->fc, &fameenc->fy, NULL);
|
||||||
|
|
||||||
while ((length = fame_encode_slice (libfame->fc)) != 0) {
|
while ((length = fame_encode_slice (fameenc->fc)) != 0) {
|
||||||
GstBuffer *outbuf;
|
GstBuffer *outbuf;
|
||||||
|
|
||||||
outbuf = gst_buffer_new ();
|
outbuf = gst_buffer_new ();
|
||||||
|
|
||||||
/* FIXME: safeguard, remove me when a better way is found */
|
/* FIXME: safeguard, remove me when a better way is found */
|
||||||
if (length > LIBFAME_BUFFER_SIZE)
|
if (length > FAMEENC_BUFFER_SIZE)
|
||||||
g_warning ("LIBFAME_BUFFER_SIZE is defined too low, encoded slice has size %d !\n", length);
|
g_warning ("FAMEENC_BUFFER_SIZE is defined too low, encoded slice has size %d !\n", length);
|
||||||
|
|
||||||
GST_BUFFER_SIZE (outbuf) = length;
|
GST_BUFFER_SIZE (outbuf) = length;
|
||||||
GST_BUFFER_DATA (outbuf) = g_malloc (length);
|
GST_BUFFER_DATA (outbuf) = g_malloc (length);
|
||||||
memcpy (GST_BUFFER_DATA(outbuf), libfame->buffer, length);
|
memcpy (GST_BUFFER_DATA(outbuf), fameenc->buffer, length);
|
||||||
|
|
||||||
GST_DEBUG (0,"gst_libfame_chain: pushing buffer of size %d",
|
GST_DEBUG (0,"gst_fameenc_chain: pushing buffer of size %d",
|
||||||
GST_BUFFER_SIZE(outbuf));
|
GST_BUFFER_SIZE(outbuf));
|
||||||
|
|
||||||
gst_pad_push (libfame->srcpad, outbuf);
|
gst_pad_push (fameenc->srcpad, outbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
fame_end_frame (libfame->fc, NULL); /* FIXME: get stats */
|
fame_end_frame (fameenc->fc, NULL);
|
||||||
|
|
||||||
gst_buffer_unref(buf);
|
gst_buffer_unref(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_libfame_set_property (GObject *object, guint prop_id,
|
gst_fameenc_set_property (GObject *object, guint prop_id,
|
||||||
const GValue *value, GParamSpec *pspec)
|
const GValue *value, GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
GstLibfame *src;
|
GstFameEnc *fameenc;
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_LIBFAME (object));
|
g_return_if_fail (GST_IS_FAMEENC (object));
|
||||||
src = GST_LIBFAME (object);
|
fameenc = GST_FAMEENC (object);
|
||||||
|
|
||||||
if (src->initialized) {
|
if (fameenc->initialized) {
|
||||||
GST_DEBUG(0, "error: libfame encoder already initialized, cannot set properties !");
|
GST_DEBUG(0, "error: fameenc encoder already initialized, cannot set properties !");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_VERSION:
|
case ARG_FRAMERATE:
|
||||||
{
|
{
|
||||||
gint version = g_value_get_int (value);
|
gint index = g_value_get_enum (value);
|
||||||
|
|
||||||
if (version != 1 && version != 4) {
|
fameenc->fp.frame_rate_num = frame_rates[index].num;
|
||||||
g_warning ("libfame: only use MPEG version 1 or 4 !");
|
fameenc->fp.frame_rate_den = frame_rates[index].den;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ARG_FPS:
|
case ARG_BITRATE:
|
||||||
/* FIXME: we could do a much better job of finding num and den here */
|
fameenc->fp.bitrate = g_value_get_int (value);
|
||||||
src->fp.frame_rate_num = g_value_get_double (value);
|
|
||||||
src->fp.frame_rate_den = 1;
|
|
||||||
gst_info ("libfame: setting framerate for encoding to %f (%d/%d)\n",
|
|
||||||
(float) src->fp.frame_rate_num / src->fp.frame_rate_den,
|
|
||||||
src->fp.frame_rate_num, src->fp.frame_rate_den);
|
|
||||||
break;
|
break;
|
||||||
case ARG_QUALITY:
|
case ARG_QUALITY:
|
||||||
src->fp.quality = CLAMP (g_value_get_int (value), 0, 100);
|
fameenc->fp.quality = CLAMP (g_value_get_int (value), 0, 100);
|
||||||
break;
|
break;
|
||||||
case ARG_PATTERN:
|
case ARG_PATTERN:
|
||||||
g_free (src->pattern);
|
g_free (fameenc->pattern);
|
||||||
src->pattern = g_strdup (g_value_get_string (value));
|
fameenc->pattern = g_strdup (g_value_get_string (value));
|
||||||
|
break;
|
||||||
|
case ARG_FAME_VERBOSE:
|
||||||
|
fameenc->verbose = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
|
case ARG_BUFFER_SIZE:
|
||||||
|
fameenc->buffer_size = g_value_get_int (value);
|
||||||
|
break;
|
||||||
|
case ARG_FRAMES_PER_SEQUENCE:
|
||||||
|
fameenc->fp.frames_per_sequence = g_value_get_int (value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
if (prop_id >= ARG_FAME_PROPS_START) {
|
||||||
|
gchar *name;
|
||||||
|
gint index = g_value_get_enum (value);
|
||||||
|
GEnumValue *values;
|
||||||
|
|
||||||
|
values = G_ENUM_CLASS (g_type_class_ref (pspec->value_type))->values;
|
||||||
|
name = (gchar *) g_param_spec_get_qdata (pspec, fame_object_name);
|
||||||
|
|
||||||
|
fame_register (fameenc->fc, name, fame_get_object (fameenc->fc, values[index].value_name));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_libfame_get_property (GObject *object, guint prop_id,
|
gst_fameenc_get_property (GObject *object, guint prop_id,
|
||||||
GValue *value, GParamSpec *pspec)
|
GValue *value, GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
GstLibfame *src;
|
GstFameEnc *fameenc;
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_LIBFAME (object));
|
g_return_if_fail (GST_IS_FAMEENC (object));
|
||||||
src = GST_LIBFAME (object);
|
fameenc = GST_FAMEENC (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case ARG_FPS:
|
case ARG_FRAMERATE:
|
||||||
g_value_set_double (value, (src->fp.frame_rate_num /
|
{
|
||||||
src->fp.frame_rate_den));
|
gint index = framerate_to_index (fameenc->fp.frame_rate_num,
|
||||||
|
fameenc->fp.frame_rate_den);
|
||||||
|
g_value_set_enum (value, index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ARG_BITRATE:
|
||||||
|
g_value_set_int (value, fameenc->fp.bitrate);
|
||||||
break;
|
break;
|
||||||
case ARG_QUALITY:
|
case ARG_QUALITY:
|
||||||
g_value_set_int (value, src->fp.quality);
|
g_value_set_int (value, fameenc->fp.quality);
|
||||||
break;
|
break;
|
||||||
case ARG_PATTERN:
|
case ARG_PATTERN:
|
||||||
g_value_set_string (value, g_strdup (src->pattern));
|
g_value_set_string (value, g_strdup (fameenc->pattern));
|
||||||
|
break;
|
||||||
|
case ARG_FAME_VERBOSE:
|
||||||
|
g_value_set_boolean (value, fameenc->verbose);
|
||||||
|
break;
|
||||||
|
case ARG_BUFFER_SIZE:
|
||||||
|
g_value_set_int (value, fameenc->buffer_size);
|
||||||
|
break;
|
||||||
|
case ARG_FRAMES_PER_SEQUENCE:
|
||||||
|
g_value_set_int (value, fameenc->fp.frames_per_sequence);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (prop_id >= ARG_FAME_PROPS_START) {
|
||||||
|
gchar *name;
|
||||||
|
gint index = 0;
|
||||||
|
GEnumValue *values;
|
||||||
|
fame_object_t *f_object;
|
||||||
|
|
||||||
|
values = G_ENUM_CLASS (g_type_class_ref (pspec->value_type))->values;
|
||||||
|
name = (gchar *) g_param_spec_get_qdata (pspec, fame_object_name);
|
||||||
|
|
||||||
|
f_object = fame_get_object (fameenc->fc, name);
|
||||||
|
|
||||||
|
while (values[index].value_name) {
|
||||||
|
if (!strcmp (values[index].value_nick, f_object->name)) {
|
||||||
|
g_value_set_enum (value, index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -384,9 +576,9 @@ plugin_init (GModule *module, GstPlugin *plugin)
|
||||||
{
|
{
|
||||||
GstElementFactory *factory;
|
GstElementFactory *factory;
|
||||||
|
|
||||||
/* create an elementfactory for the libfame element */
|
/* create an elementfactory for the fameenc element */
|
||||||
factory = gst_element_factory_new ("libfame", GST_TYPE_LIBFAME,
|
factory = gst_element_factory_new ("fameenc", GST_TYPE_FAMEENC,
|
||||||
&gst_libfame_details);
|
&gst_fameenc_details);
|
||||||
g_return_val_if_fail (factory != NULL, FALSE);
|
g_return_val_if_fail (factory != NULL, FALSE);
|
||||||
|
|
||||||
gst_element_factory_add_pad_template (factory,
|
gst_element_factory_add_pad_template (factory,
|
||||||
|
@ -402,6 +594,6 @@ plugin_init (GModule *module, GstPlugin *plugin)
|
||||||
GstPluginDesc plugin_desc = {
|
GstPluginDesc plugin_desc = {
|
||||||
GST_VERSION_MAJOR,
|
GST_VERSION_MAJOR,
|
||||||
GST_VERSION_MINOR,
|
GST_VERSION_MINOR,
|
||||||
"libfame",
|
"fameenc",
|
||||||
plugin_init
|
plugin_init
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __GST_LIBFAME_H__
|
#ifndef __GST_FAMEENC_H__
|
||||||
#define __GST_LIBFAME_H__
|
#define __GST_FAMEENC_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <fame.h>
|
#include <fame.h>
|
||||||
|
@ -29,21 +29,21 @@ extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
|
||||||
#define GST_TYPE_LIBFAME \
|
#define GST_TYPE_FAMEENC \
|
||||||
(gst_libfame_get_type())
|
(gst_fameenc_get_type())
|
||||||
#define GST_LIBFAME(obj) \
|
#define GST_FAMEENC(obj) \
|
||||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_LIBFAME,GstLibfame))
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FAMEENC,GstFameEnc))
|
||||||
#define GST_LIBFAME_CLASS(klass) \
|
#define GST_FAMEENC_CLASS(klass) \
|
||||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_LIBFAME,GstLibfame))
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FAMEENC,GstFameEnc))
|
||||||
#define GST_IS_LIBFAME(obj) \
|
#define GST_IS_FAMEENC(obj) \
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_LIBFAME))
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FAMEENC))
|
||||||
#define GST_IS_LIBFAME_CLASS(obj) \
|
#define GST_IS_FAMEENC_CLASS(obj) \
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_LIBFAME))
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FAMEENC))
|
||||||
|
|
||||||
typedef struct _GstLibfame GstLibfame;
|
typedef struct _GstFameEnc GstFameEnc;
|
||||||
typedef struct _GstLibfameClass GstLibfameClass;
|
typedef struct _GstFameEncClass GstFameEncClass;
|
||||||
|
|
||||||
struct _GstLibfame {
|
struct _GstFameEnc {
|
||||||
GstElement element;
|
GstElement element;
|
||||||
|
|
||||||
/* pads */
|
/* pads */
|
||||||
|
@ -62,7 +62,8 @@ struct _GstLibfame {
|
||||||
/* encoding pattern string */
|
/* encoding pattern string */
|
||||||
gchar *pattern;
|
gchar *pattern;
|
||||||
|
|
||||||
/* libfame stuff */
|
/* fameenc stuff */
|
||||||
|
gboolean verbose;
|
||||||
fame_context_t *fc;
|
fame_context_t *fc;
|
||||||
fame_parameters_t fp;
|
fame_parameters_t fp;
|
||||||
fame_yuv_t fy;
|
fame_yuv_t fy;
|
||||||
|
@ -71,11 +72,11 @@ struct _GstLibfame {
|
||||||
gboolean initialized;
|
gboolean initialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstLibfameClass {
|
struct _GstFameEncClass {
|
||||||
GstElementClass parent_class;
|
GstElementClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_libfame_get_type (void);
|
GType gst_fameenc_get_type (void);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -83,4 +84,4 @@ GType gst_libfame_get_type (void);
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GST_LIBFAME_H__ */
|
#endif /* __GST_FAMEENC_H__ */
|
||||||
|
|
Loading…
Reference in a new issue