gst-indent c++ files

Original commit message from CVS:
gst-indent c++ files
This commit is contained in:
Thomas Vander Stichele 2004-03-14 23:20:41 +00:00
parent 7a778ee4b7
commit 87960e43ea
11 changed files with 886 additions and 949 deletions

View file

@ -14,166 +14,173 @@
using namespace Arts; using namespace Arts;
namespace Gst { namespace Gst
class ArtsStereoSink_impl : virtual public ArtsStereoSink_skel,
virtual public StdSynthModule
{ {
GstPad *sinkpad; class ArtsStereoSink_impl:virtual public ArtsStereoSink_skel,
GstPad *srcpad; virtual public StdSynthModule
unsigned long remainingsamples;
GstData *inbuf;
unsigned char *dataptr;
public:
ArtsStereoSink_impl()
{ {
remainingsamples = 0;
inbuf = NULL;
dataptr = NULL;
}
void calculateBlock (unsigned long samples) GstPad *sinkpad;
{ GstPad *srcpad;
unsigned long fulfilled = 0; unsigned long remainingsamples;
GstData *inbuf;
unsigned char *dataptr;
public:
ArtsStereoSink_impl ()
{
remainingsamples = 0;
inbuf = NULL;
dataptr = NULL;
}
void calculateBlock (unsigned long samples)
{
unsigned long fulfilled = 0;
//gint16 *s; //gint16 *s;
//fprintf(stderr,"StereoSink: getting %d samples\n",samples); //fprintf(stderr,"StereoSink: getting %d samples\n",samples);
while (fulfilled < samples) { while (fulfilled < samples)
if (remainingsamples == 0) { {
if (remainingsamples == 0) {
//fprintf(stderr,"need to get a buffer\n"); //fprintf(stderr,"need to get a buffer\n");
if (inbuf) { if (inbuf) {
gst_data_unref(inbuf); gst_data_unref (inbuf);
inbuf = NULL; inbuf = NULL;
}
// start by pulling a buffer from GStreamer
inbuf = gst_pad_pull (sinkpad);
while (GST_IS_EVENT (inbuf)) {
switch (GST_EVENT_TYPE (inbuf)) {
case GST_EVENT_EOS:
gst_element_set_eos (GST_PAD_PARENT (sinkpad));
default:
break;
}
gst_pad_event_default (srcpad, GST_EVENT (inbuf));
inbuf = gst_pad_pull (sinkpad);
}
dataptr = GST_BUFFER_DATA (GST_BUFFER (inbuf));
remainingsamples = GST_BUFFER_SIZE (GST_BUFFER (inbuf)) / 4;
//fprintf(stderr,"got a buffer with %d samples\n",remainingsamples);
} }
// start by pulling a buffer from GStreamer unsigned long count = MIN (remainingsamples, samples - fulfilled);
inbuf = gst_pad_pull (sinkpad);
while (GST_IS_EVENT (inbuf)) {
switch (GST_EVENT_TYPE (inbuf)) {
case GST_EVENT_EOS:
gst_element_set_eos (GST_PAD_PARENT (sinkpad));
default:
break;
}
gst_pad_event_default (srcpad, GST_EVENT(inbuf));
inbuf = gst_pad_pull (sinkpad);
}
dataptr = GST_BUFFER_DATA(GST_BUFFER(inbuf));
remainingsamples = GST_BUFFER_SIZE(GST_BUFFER(inbuf)) / 4;
//fprintf(stderr,"got a buffer with %d samples\n",remainingsamples);
}
unsigned long count = MIN(remainingsamples,samples-fulfilled);
//fprintf(stderr,"have %d samples left, can fill %d\n",remainingsamples,count); //fprintf(stderr,"have %d samples left, can fill %d\n",remainingsamples,count);
convert_stereo_i16le_2float(count,dataptr,outleft,outright); convert_stereo_i16le_2float (count, dataptr, outleft, outright);
//s = (gint16 *)dataptr; //s = (gint16 *)dataptr;
//fprintf(stderr,"samples in are %d and %d, out are %f and %f\n",s[0],s[1],outleft[0],outright[0]); //fprintf(stderr,"samples in are %d and %d, out are %f and %f\n",s[0],s[1],outleft[0],outright[0]);
remainingsamples -= count; remainingsamples -= count;
dataptr += 4 * count; dataptr += 4 * count;
fulfilled += count; fulfilled += count;
}
} }
}
void setPad(GstPad *pad) void setPad (GstPad * pad)
{
sinkpad = pad;
}
void setSrcPad (GstPad * pad)
{
srcpad = pad;
}
};
class ArtsStereoSrc_impl:virtual public ArtsStereoSrc_skel,
virtual public StdSynthModule
{ {
sinkpad = pad;
}
void setSrcPad(GstPad *pad)
{
srcpad = pad;
}
};
GstPad *srcpad;
GstBuffer *outbuf;
unsigned char *dataptr;
class ArtsStereoSrc_impl : virtual public ArtsStereoSrc_skel, public:
virtual public StdSynthModule
{
GstPad *srcpad; void calculateBlock (unsigned long samples)
GstBuffer *outbuf; {
unsigned char *dataptr;
public:
void calculateBlock (unsigned long samples)
{
//gint16 *s; //gint16 *s;
//fprintf(stderr,"StereoSrc: handed %d samples\n",samples); //fprintf(stderr,"StereoSrc: handed %d samples\n",samples);
outbuf = gst_buffer_new(); outbuf = gst_buffer_new ();
GST_BUFFER_DATA(outbuf) = (guchar *)g_malloc(samples*4); GST_BUFFER_DATA (outbuf) = (guchar *) g_malloc (samples * 4);
GST_BUFFER_SIZE(outbuf) = samples*4; GST_BUFFER_SIZE (outbuf) = samples * 4;
memset(GST_BUFFER_DATA(outbuf),0,samples*4); memset (GST_BUFFER_DATA (outbuf), 0, samples * 4);
convert_stereo_2float_i16le(samples,inleft,inright,GST_BUFFER_DATA(outbuf)); convert_stereo_2float_i16le (samples, inleft, inright,
GST_BUFFER_DATA (outbuf));
//s = (gint16 *)GST_BUFFER_DATA(outbuf); //s = (gint16 *)GST_BUFFER_DATA(outbuf);
//fprintf(stderr,"samples in are %f and %f, out are %d and %d\n",inleft[0],inright[0],s[0],s[1]); //fprintf(stderr,"samples in are %f and %f, out are %d and %d\n",inleft[0],inright[0],s[0],s[1]);
gst_pad_push(srcpad,GST_DATA(outbuf)); gst_pad_push (srcpad, GST_DATA (outbuf));
outbuf = NULL; outbuf = NULL;
} }
void setPad(GstPad *pad) void setPad (GstPad * pad)
{
srcpad = pad;
}
};
class GstArtsWrapper
{ {
srcpad = pad; Dispatcher *dispatcher;
} ArtsStereoSink sink;
}; ArtsStereoSrc source;
StereoVolumeControl effect;
class GstArtsWrapper { public:
Dispatcher *dispatcher; GstArtsWrapper (GstPad * sinkpad, GstPad * sourcepad)
ArtsStereoSink sink; {
ArtsStereoSrc source; dispatcher = new Arts::Dispatcher ();
StereoVolumeControl effect; ArtsStereoSink_impl *sink_impl = new ArtsStereoSink_impl ();
ArtsStereoSrc_impl *source_impl = new ArtsStereoSrc_impl ();
public: sink_impl->setPad (sinkpad);
GstArtsWrapper(GstPad *sinkpad, GstPad *sourcepad) { sink_impl->setSrcPad (sourcepad);
dispatcher = new Arts::Dispatcher(); source_impl->setPad (sourcepad);
ArtsStereoSink_impl *sink_impl = new ArtsStereoSink_impl(); sink = ArtsStereoSink::_from_base (sink_impl);
ArtsStereoSrc_impl *source_impl = new ArtsStereoSrc_impl(); source = ArtsStereoSrc::_from_base (source_impl);
sink_impl->setPad(sinkpad); sink.start ();
sink_impl->setSrcPad(sourcepad); effect.start ();
source_impl->setPad(sourcepad); source.start ();
sink = ArtsStereoSink::_from_base(sink_impl); effect.scaleFactor (0.5);
source = ArtsStereoSrc::_from_base(source_impl); connect (sink, effect);
sink.start(); connect (effect, source);
effect.start();
source.start();
effect.scaleFactor(0.5);
connect(sink, effect);
connect(effect, source);
// connect(sink,source); // connect(sink,source);
} }
void iterate() void iterate ()
{
source._node ()->requireFlow ();
}
};
};
extern "C"
{
void *gst_arts_wrapper_new (GstPad * sinkpad, GstPad * sourcepad)
{ {
source._node()->requireFlow(); return new Gst::GstArtsWrapper (sinkpad, sourcepad);
} }
};
void gst_arts_wrapper_free (void *wrapper)
{
Gst::GstArtsWrapper * w = (Gst::GstArtsWrapper *) wrapper;
delete w;
}
}; void gst_arts_wrapper_do (void *wrapper)
{
Gst::GstArtsWrapper * w = (Gst::GstArtsWrapper *) wrapper;
extern "C" { w->iterate ();
}
void *gst_arts_wrapper_new(GstPad *sinkpad, GstPad *sourcepad)
{
return new Gst::GstArtsWrapper(sinkpad, sourcepad);
}
void gst_arts_wrapper_free(void *wrapper)
{
Gst::GstArtsWrapper *w = (Gst::GstArtsWrapper *)wrapper;
delete w;
}
void gst_arts_wrapper_do(void *wrapper)
{
Gst::GstArtsWrapper *w = (Gst::GstArtsWrapper *)wrapper;
w->iterate();
}
} }

View file

@ -30,13 +30,15 @@
* we do something manual... * we do something manual...
*/ */
static void static void
add_fps (GstCaps *caps) add_fps (GstCaps * caps)
{ {
GstStructure *structure = gst_caps_get_structure (caps, 0); GstStructure *structure = gst_caps_get_structure (caps, 0);
GValue list = { 0 }, fps = { 0 }; GValue list = { 0 }, fps = {
gdouble fpss[] = { 24.0/1.001, 24.0, 25.0, 0};
30.0/1.001, 30.0, 50.0, gdouble fpss[] = { 24.0 / 1.001, 24.0, 25.0,
60.0/1.001, 60.0, 0 }; 30.0 / 1.001, 30.0, 50.0,
60.0 / 1.001, 60.0, 0
};
guint n; guint n;
g_value_init (&list, GST_TYPE_LIST); g_value_init (&list, GST_TYPE_LIST);
@ -59,15 +61,13 @@ sink_templ (void)
GstCaps *caps; GstCaps *caps;
caps = gst_caps_new_simple ("video/x-raw-yuv", caps = gst_caps_new_simple ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, "format", GST_TYPE_FOURCC,
GST_MAKE_FOURCC ('I','4','2','0'), GST_MAKE_FOURCC ('I', '4', '2', '0'),
"width", GST_TYPE_INT_RANGE, 16, 4096, "width", GST_TYPE_INT_RANGE, 16, 4096,
"height", GST_TYPE_INT_RANGE, 16, 4096, "height", GST_TYPE_INT_RANGE, 16, 4096, NULL);
NULL);
add_fps (caps); add_fps (caps);
templ = gst_pad_template_new ("sink", GST_PAD_SINK, templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
GST_PAD_ALWAYS, caps);
} }
return templ; return templ;
@ -82,42 +82,34 @@ src_templ (void)
GstCaps *caps; GstCaps *caps;
caps = gst_caps_new_simple ("video/mpeg", caps = gst_caps_new_simple ("video/mpeg",
"systemstream", G_TYPE_BOOLEAN, FALSE, "systemstream", G_TYPE_BOOLEAN, FALSE,
"mpegversion", GST_TYPE_INT_RANGE, 1, 2, "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
"width", GST_TYPE_INT_RANGE, 16, 4096, "width", GST_TYPE_INT_RANGE, 16, 4096,
"height", GST_TYPE_INT_RANGE, 16, 4096, "height", GST_TYPE_INT_RANGE, 16, 4096, NULL);
NULL);
add_fps (caps); add_fps (caps);
templ = gst_pad_template_new ("src", GST_PAD_SRC, templ = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
GST_PAD_ALWAYS, caps);
} }
return templ; return templ;
} }
static void gst_mpeg2enc_base_init (GstMpeg2encClass *klass); static void gst_mpeg2enc_base_init (GstMpeg2encClass * klass);
static void gst_mpeg2enc_class_init (GstMpeg2encClass *klass); static void gst_mpeg2enc_class_init (GstMpeg2encClass * klass);
static void gst_mpeg2enc_init (GstMpeg2enc *enc); static void gst_mpeg2enc_init (GstMpeg2enc * enc);
static void gst_mpeg2enc_dispose (GObject *object); static void gst_mpeg2enc_dispose (GObject * object);
static void gst_mpeg2enc_loop (GstElement *element); static void gst_mpeg2enc_loop (GstElement * element);
static GstPadLinkReturn static GstPadLinkReturn
gst_mpeg2enc_sink_link (GstPad *pad, gst_mpeg2enc_sink_link (GstPad * pad, const GstCaps * caps);
const GstCaps *caps);
static GstElementStateReturn static GstElementStateReturn gst_mpeg2enc_change_state (GstElement * element);
gst_mpeg2enc_change_state (GstElement *element);
static void gst_mpeg2enc_get_property (GObject *object, static void gst_mpeg2enc_get_property (GObject * object,
guint prop_id, guint prop_id, GValue * value, GParamSpec * pspec);
GValue *value, static void gst_mpeg2enc_set_property (GObject * object,
GParamSpec *pspec); guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_mpeg2enc_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -128,7 +120,7 @@ gst_mpeg2enc_get_type (void)
if (!gst_mpeg2enc_type) { if (!gst_mpeg2enc_type) {
static const GTypeInfo gst_mpeg2enc_info = { static const GTypeInfo gst_mpeg2enc_info = {
sizeof (GstMpeg2encClass), sizeof (GstMpeg2encClass),
(GBaseInitFunc) gst_mpeg2enc_base_init, (GBaseInitFunc) gst_mpeg2enc_base_init,
NULL, NULL,
(GClassInitFunc) gst_mpeg2enc_class_init, (GClassInitFunc) gst_mpeg2enc_class_init,
@ -141,34 +133,31 @@ gst_mpeg2enc_get_type (void)
gst_mpeg2enc_type = gst_mpeg2enc_type =
g_type_register_static (GST_TYPE_ELEMENT, g_type_register_static (GST_TYPE_ELEMENT,
"GstMpeg2enc", "GstMpeg2enc", &gst_mpeg2enc_info, (GTypeFlags) 0);
&gst_mpeg2enc_info,
(GTypeFlags) 0);
} }
return gst_mpeg2enc_type; return gst_mpeg2enc_type;
} }
static void static void
gst_mpeg2enc_base_init (GstMpeg2encClass *klass) gst_mpeg2enc_base_init (GstMpeg2encClass * klass)
{ {
static GstElementDetails gst_mpeg2enc_details = { static GstElementDetails gst_mpeg2enc_details = {
"mpeg2enc video encoder", "mpeg2enc video encoder",
"Codec/Video/Encoder", "Codec/Video/Encoder",
"High-quality MPEG-1/2 video encoder", "High-quality MPEG-1/2 video encoder",
"Andrew Stevens <andrew.stevens@nexgo.de>\n" "Andrew Stevens <andrew.stevens@nexgo.de>\n"
"Ronald Bultje <rbultje@ronald.bitfreak.net>" "Ronald Bultje <rbultje@ronald.bitfreak.net>"
}; };
GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class, src_templ ()); gst_element_class_add_pad_template (element_class, src_templ ());
gst_element_class_add_pad_template (element_class, sink_templ ()); gst_element_class_add_pad_template (element_class, sink_templ ());
gst_element_class_set_details (element_class, gst_element_class_set_details (element_class, &gst_mpeg2enc_details);
&gst_mpeg2enc_details);
} }
static void static void
gst_mpeg2enc_class_init (GstMpeg2encClass *klass) gst_mpeg2enc_class_init (GstMpeg2encClass * klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
@ -188,32 +177,35 @@ gst_mpeg2enc_class_init (GstMpeg2encClass *klass)
} }
static void static void
gst_mpeg2enc_dispose (GObject *object) gst_mpeg2enc_dispose (GObject * object)
{ {
GstMpeg2enc *enc = GST_MPEG2ENC (object); GstMpeg2enc *enc = GST_MPEG2ENC (object);
if (enc->encoder) { if (enc->encoder) {
delete enc->encoder; delete enc->encoder;
enc->encoder = NULL; enc->encoder = NULL;
} }
delete enc->options; delete enc->options;
} }
static void static void
gst_mpeg2enc_init (GstMpeg2enc *enc) gst_mpeg2enc_init (GstMpeg2enc * enc)
{ {
GstElement *element = GST_ELEMENT (enc); GstElement *element = GST_ELEMENT (enc);
GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
GST_FLAG_SET (element, GST_ELEMENT_EVENT_AWARE); GST_FLAG_SET (element, GST_ELEMENT_EVENT_AWARE);
enc->sinkpad = gst_pad_new_from_template ( enc->sinkpad =
gst_element_class_get_pad_template (klass, "sink"), "sink"); gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
"sink"), "sink");
gst_pad_set_link_function (enc->sinkpad, gst_mpeg2enc_sink_link); gst_pad_set_link_function (enc->sinkpad, gst_mpeg2enc_sink_link);
gst_element_add_pad (element, enc->sinkpad); gst_element_add_pad (element, enc->sinkpad);
enc->srcpad = gst_pad_new_from_template ( enc->srcpad =
gst_element_class_get_pad_template (klass, "src"), "src"); gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
"src"), "src");
gst_pad_use_explicit_caps (enc->srcpad); gst_pad_use_explicit_caps (enc->srcpad);
gst_element_add_pad (element, enc->srcpad); gst_element_add_pad (element, enc->srcpad);
@ -225,7 +217,7 @@ gst_mpeg2enc_init (GstMpeg2enc *enc)
} }
static void static void
gst_mpeg2enc_loop (GstElement *element) gst_mpeg2enc_loop (GstElement * element)
{ {
GstMpeg2enc *enc = GST_MPEG2ENC (element); GstMpeg2enc *enc = GST_MPEG2ENC (element);
@ -240,19 +232,20 @@ gst_mpeg2enc_loop (GstElement *element)
if (!(caps = GST_PAD_CAPS (enc->sinkpad))) { if (!(caps = GST_PAD_CAPS (enc->sinkpad))) {
GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL), GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL),
("format wasn't negotiated before loop function")); ("format wasn't negotiated before loop function"));
return; return;
} }
/* create new encoder with these settings */ /* create new encoder with these settings */
enc->encoder = new GstMpeg2Encoder (enc->options, enc->sinkpad, enc->encoder = new GstMpeg2Encoder (enc->options, enc->sinkpad,
caps, enc->srcpad); caps, enc->srcpad);
/* and set caps on other side */ /* and set caps on other side */
othercaps = enc->encoder->getFormat (); othercaps = enc->encoder->getFormat ();
if (gst_pad_set_explicit_caps (enc->srcpad, othercaps) <= 0) { if (gst_pad_set_explicit_caps (enc->srcpad, othercaps) <= 0) {
GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL), (NULL)); GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL), (NULL));
delete enc->encoder; delete enc->encoder;
enc->encoder = NULL; enc->encoder = NULL;
return; return;
} }
@ -263,8 +256,7 @@ gst_mpeg2enc_loop (GstElement *element)
} }
static GstPadLinkReturn static GstPadLinkReturn
gst_mpeg2enc_sink_link (GstPad *pad, gst_mpeg2enc_sink_link (GstPad * pad, const GstCaps * caps)
const GstCaps *caps)
{ {
GstMpeg2enc *enc = GST_MPEG2ENC (gst_pad_get_parent (pad)); GstMpeg2enc *enc = GST_MPEG2ENC (gst_pad_get_parent (pad));
@ -273,6 +265,7 @@ gst_mpeg2enc_sink_link (GstPad *pad,
if (enc->encoder) { if (enc->encoder) {
delete enc->encoder; delete enc->encoder;
enc->encoder = NULL; enc->encoder = NULL;
} }
@ -280,25 +273,21 @@ gst_mpeg2enc_sink_link (GstPad *pad,
} }
static void static void
gst_mpeg2enc_get_property (GObject *object, gst_mpeg2enc_get_property (GObject * object,
guint prop_id, guint prop_id, GValue * value, GParamSpec * pspec)
GValue *value,
GParamSpec *pspec)
{ {
GST_MPEG2ENC (object)->options->getProperty (prop_id, value); GST_MPEG2ENC (object)->options->getProperty (prop_id, value);
} }
static void static void
gst_mpeg2enc_set_property (GObject *object, gst_mpeg2enc_set_property (GObject * object,
guint prop_id, guint prop_id, const GValue * value, GParamSpec * pspec)
const GValue *value,
GParamSpec *pspec)
{ {
GST_MPEG2ENC (object)->options->setProperty (prop_id, value); GST_MPEG2ENC (object)->options->setProperty (prop_id, value);
} }
static GstElementStateReturn static GstElementStateReturn
gst_mpeg2enc_change_state (GstElement *element) gst_mpeg2enc_change_state (GstElement * element)
{ {
GstMpeg2enc *enc = GST_MPEG2ENC (element); GstMpeg2enc *enc = GST_MPEG2ENC (element);
@ -318,21 +307,14 @@ gst_mpeg2enc_change_state (GstElement *element)
} }
static gboolean static gboolean
plugin_init (GstPlugin *plugin) plugin_init (GstPlugin * plugin)
{ {
return gst_element_register (plugin, "mpeg2enc", return gst_element_register (plugin, "mpeg2enc",
GST_RANK_NONE, GST_RANK_NONE, GST_TYPE_MPEG2ENC);
GST_TYPE_MPEG2ENC);
} }
GST_PLUGIN_DEFINE ( GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MAJOR, GST_VERSION_MINOR,
GST_VERSION_MINOR, "mpeg2enc",
"mpeg2enc", "High-quality MPEG-1/2 video encoder",
"High-quality MPEG-1/2 video encoder", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN)
plugin_init,
VERSION,
"GPL",
GST_PACKAGE,
GST_ORIGIN
)

View file

@ -35,11 +35,9 @@
* Class init stuff. * Class init stuff.
*/ */
GstMpeg2Encoder::GstMpeg2Encoder (GstMpeg2EncOptions *options, GstMpeg2Encoder::GstMpeg2Encoder (GstMpeg2EncOptions * options,
GstPad *sinkpad, GstPad * sinkpad, const GstCaps * caps, GstPad * srcpad):
const GstCaps *caps, MPEG2Encoder (*options)
GstPad *srcpad) :
MPEG2Encoder (*options)
{ {
MPEG2EncInVidParams strm; MPEG2EncInVidParams strm;
@ -58,7 +56,7 @@ GstMpeg2Encoder::GstMpeg2Encoder (GstMpeg2EncOptions *options,
/* sequencer */ /* sequencer */
seqencoder = new SeqEncoder (parms, *reader, *quantizer, seqencoder = new SeqEncoder (parms, *reader, *quantizer,
*writer, *coder, *bitrate_controller); *writer, *coder, *bitrate_controller);
parms.Init (*options); parms.Init (*options);
reader->Init (); reader->Init ();
@ -86,10 +84,9 @@ GstMpeg2Encoder::getFormat ()
gdouble fps = Y4M_RATIO_DBL (mpeg_framerate (options.frame_rate)); gdouble fps = Y4M_RATIO_DBL (mpeg_framerate (options.frame_rate));
return gst_caps_new_simple ("video/mpeg", return gst_caps_new_simple ("video/mpeg",
"systemstream", G_TYPE_BOOLEAN, FALSE, "systemstream", G_TYPE_BOOLEAN, FALSE,
"mpegversion", G_TYPE_INT, options.mpeg, "mpegversion", G_TYPE_INT, options.mpeg,
"width", G_TYPE_INT, options.in_img_width, "width", G_TYPE_INT, options.in_img_width,
"height", G_TYPE_INT, options.in_img_height, "height", G_TYPE_INT, options.in_img_height,
"framerate", G_TYPE_DOUBLE, fps, "framerate", G_TYPE_DOUBLE, fps, NULL);
NULL);
} }

View file

@ -29,7 +29,8 @@
* Property enumeration. * Property enumeration.
*/ */
enum { enum
{
ARG_0, ARG_0,
ARG_FORMAT, ARG_FORMAT,
ARG_FRAMERATE, ARG_FRAMERATE,
@ -64,7 +65,7 @@ enum {
ARG_CORRECT_SVCD_HDS, ARG_CORRECT_SVCD_HDS,
ARG_ALTSCAN_MPEG2, ARG_ALTSCAN_MPEG2,
ARG_CONSTRAINTS ARG_CONSTRAINTS
/* FILL ME */ /* FILL ME */
}; };
/* /*
@ -81,22 +82,21 @@ gst_mpeg2enc_format_get_type (void)
if (!mpeg2enc_format_type) { if (!mpeg2enc_format_type) {
static const GEnumValue mpeg2enc_formats[] = { static const GEnumValue mpeg2enc_formats[] = {
{ 0, "0", "Generic MPEG-1" }, {0, "0", "Generic MPEG-1"},
{ 1, "1", "Standard VCD" }, {1, "1", "Standard VCD"},
{ 2, "2", "User VCD" }, {2, "2", "User VCD"},
{ 3, "3", "Generic MPEG-2" }, {3, "3", "Generic MPEG-2"},
{ 4, "4", "Standard SVCD" }, {4, "4", "Standard SVCD"},
{ 5, "5", "User SVCD" }, {5, "5", "User SVCD"},
{ 6, "6", "VCD Stills sequences" }, {6, "6", "VCD Stills sequences"},
{ 7, "7", "SVCD Stills sequences" }, {7, "7", "SVCD Stills sequences"},
{ 8, "8", "DVD MPEG-2 for dvdauthor" }, {8, "8", "DVD MPEG-2 for dvdauthor"},
{ 9, "9", "DVD MPEG-2" }, {9, "9", "DVD MPEG-2"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mpeg2enc_format_type = mpeg2enc_format_type =
g_enum_register_static ("GstMpeg2encFormat", g_enum_register_static ("GstMpeg2encFormat", mpeg2enc_formats);
mpeg2enc_formats);
} }
return mpeg2enc_format_type; return mpeg2enc_format_type;
@ -112,21 +112,20 @@ gst_mpeg2enc_framerate_get_type (void)
if (!mpeg2enc_framerate_type) { if (!mpeg2enc_framerate_type) {
static const GEnumValue mpeg2enc_framerates[] = { static const GEnumValue mpeg2enc_framerates[] = {
{ 0, "0", "Same as input" }, {0, "0", "Same as input"},
{ 1, "1", "24/1.001 (NTSC 3:2 pulldown converted film)" }, {1, "1", "24/1.001 (NTSC 3:2 pulldown converted film)"},
{ 2, "2", "24 (native film)" }, {2, "2", "24 (native film)"},
{ 3, "3", "25 (PAL/SECAM video)" }, {3, "3", "25 (PAL/SECAM video)"},
{ 4, "4", "30/1.001 (NTSC video)" }, {4, "4", "30/1.001 (NTSC video)"},
{ 5, "5", "30" }, {5, "5", "30"},
{ 6, "6", "50 (PAL/SECAM fields)" }, {6, "6", "50 (PAL/SECAM fields)"},
{ 7, "7", "60/1.001 (NTSC fields)" }, {7, "7", "60/1.001 (NTSC fields)"},
{ 8, "8", "60" }, {8, "8", "60"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mpeg2enc_framerate_type = mpeg2enc_framerate_type =
g_enum_register_static ("GstMpeg2encFramerate", g_enum_register_static ("GstMpeg2encFramerate", mpeg2enc_framerates);
mpeg2enc_framerates);
} }
return mpeg2enc_framerate_type; return mpeg2enc_framerate_type;
@ -142,17 +141,16 @@ gst_mpeg2enc_aspect_get_type (void)
if (!mpeg2enc_aspect_type) { if (!mpeg2enc_aspect_type) {
static const GEnumValue mpeg2enc_aspects[] = { static const GEnumValue mpeg2enc_aspects[] = {
{ 0, "0", "Deduce from input" }, {0, "0", "Deduce from input"},
{ 1, "1", "1:1" }, {1, "1", "1:1"},
{ 2, "2", "4:3" }, {2, "2", "4:3"},
{ 3, "3", "16:9" }, {3, "3", "16:9"},
{ 4, "4", "2.21:1" }, {4, "4", "2.21:1"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mpeg2enc_aspect_type = mpeg2enc_aspect_type =
g_enum_register_static ("GstMpeg2encAspect", g_enum_register_static ("GstMpeg2encAspect", mpeg2enc_aspects);
mpeg2enc_aspects);
} }
return mpeg2enc_aspect_type; return mpeg2enc_aspect_type;
@ -168,16 +166,16 @@ gst_mpeg2enc_interlace_mode_get_type (void)
if (!mpeg2enc_interlace_mode_type) { if (!mpeg2enc_interlace_mode_type) {
static const GEnumValue mpeg2enc_interlace_modes[] = { static const GEnumValue mpeg2enc_interlace_modes[] = {
{ -1, "-1", "Format default mode" }, {-1, "-1", "Format default mode"},
{ 0, "0", "Progressive" }, {0, "0", "Progressive"},
{ 1, "1", "Interlaced, per-frame encoding" }, {1, "1", "Interlaced, per-frame encoding"},
{ 2, "2", "Interlaced, per-field-encoding" }, {2, "2", "Interlaced, per-field-encoding"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mpeg2enc_interlace_mode_type = mpeg2enc_interlace_mode_type =
g_enum_register_static ("GstMpeg2encInterlaceMode", g_enum_register_static ("GstMpeg2encInterlaceMode",
mpeg2enc_interlace_modes); mpeg2enc_interlace_modes);
} }
return mpeg2enc_interlace_mode_type; return mpeg2enc_interlace_mode_type;
@ -198,20 +196,20 @@ gst_mpeg2enc_quantisation_matrix_get_type (void)
if (!mpeg2enc_quantisation_matrix_type) { if (!mpeg2enc_quantisation_matrix_type) {
static const GEnumValue mpeg2enc_quantisation_matrixes[] = { static const GEnumValue mpeg2enc_quantisation_matrixes[] = {
{ GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT, {GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT,
"0", "Default" }, "0", "Default"},
{ GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES, {GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES,
"1", "High resolution" }, "1", "High resolution"},
{ GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD, {GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD,
"2", "KVCD" }, "2", "KVCD"},
{ GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC, {GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC,
"3", "TMPGEnc" }, "3", "TMPGEnc"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mpeg2enc_quantisation_matrix_type = mpeg2enc_quantisation_matrix_type =
g_enum_register_static ("GstMpeg2encQuantisationMatrix", g_enum_register_static ("GstMpeg2encQuantisationMatrix",
mpeg2enc_quantisation_matrixes); mpeg2enc_quantisation_matrixes);
} }
return mpeg2enc_quantisation_matrix_type; return mpeg2enc_quantisation_matrix_type;
@ -227,16 +225,15 @@ gst_mpeg2enc_video_norm_get_type (void)
if (!mpeg2enc_video_norm_type) { if (!mpeg2enc_video_norm_type) {
static const GEnumValue mpeg2enc_video_norms[] = { static const GEnumValue mpeg2enc_video_norms[] = {
{ 0, "0", "Unspecified" }, {0, "0", "Unspecified"},
{ 'p', "p", "PAL" }, {'p', "p", "PAL"},
{ 'n', "n", "NTSC" }, {'n', "n", "NTSC"},
{ 's', "s", "SECAM" }, {'s', "s", "SECAM"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mpeg2enc_video_norm_type = mpeg2enc_video_norm_type =
g_enum_register_static ("GstMpeg2encVideoNorm", g_enum_register_static ("GstMpeg2encVideoNorm", mpeg2enc_video_norms);
mpeg2enc_video_norms);
} }
return mpeg2enc_video_norm_type; return mpeg2enc_video_norm_type;
@ -252,15 +249,15 @@ gst_mpeg2enc_playback_field_order_get_type (void)
if (!mpeg2enc_playback_field_order_type) { if (!mpeg2enc_playback_field_order_type) {
static const GEnumValue mpeg2enc_playback_field_orders[] = { static const GEnumValue mpeg2enc_playback_field_orders[] = {
{ Y4M_UNKNOWN, "0", "Unspecified" }, {Y4M_UNKNOWN, "0", "Unspecified"},
{ Y4M_ILACE_TOP_FIRST, "1", "Top-field first" }, {Y4M_ILACE_TOP_FIRST, "1", "Top-field first"},
{ Y4M_ILACE_BOTTOM_FIRST, "2", "Bottom-field first" }, {Y4M_ILACE_BOTTOM_FIRST, "2", "Bottom-field first"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mpeg2enc_playback_field_order_type = mpeg2enc_playback_field_order_type =
g_enum_register_static ("GstMpeg2encPlaybackFieldOrders", g_enum_register_static ("GstMpeg2encPlaybackFieldOrders",
mpeg2enc_playback_field_orders); mpeg2enc_playback_field_orders);
} }
return mpeg2enc_playback_field_order_type; return mpeg2enc_playback_field_order_type;
@ -270,8 +267,8 @@ gst_mpeg2enc_playback_field_order_get_type (void)
* Class init stuff. * Class init stuff.
*/ */
GstMpeg2EncOptions::GstMpeg2EncOptions () : GstMpeg2EncOptions::GstMpeg2EncOptions ():
MPEG2EncOptions () MPEG2EncOptions ()
{ {
/* autodetect number of CPUs */ /* autodetect number of CPUs */
num_cpus = sysconf (_SC_NPROCESSORS_ONLN); num_cpus = sysconf (_SC_NPROCESSORS_ONLN);
@ -286,169 +283,165 @@ GstMpeg2EncOptions::GstMpeg2EncOptions () :
*/ */
void void
GstMpeg2EncOptions::initProperties (GObjectClass *klass) GstMpeg2EncOptions::initProperties (GObjectClass * klass)
{ {
/* encoding profile */ /* encoding profile */
g_object_class_install_property (klass, ARG_FORMAT, g_object_class_install_property (klass, ARG_FORMAT,
g_param_spec_enum ("format", "Format", "Encoding profile format", g_param_spec_enum ("format", "Format", "Encoding profile format",
GST_TYPE_MPEG2ENC_FORMAT, 0, GST_TYPE_MPEG2ENC_FORMAT, 0, (GParamFlags) G_PARAM_READWRITE));
(GParamFlags) G_PARAM_READWRITE));
/* input/output stream overrides */ /* input/output stream overrides */
g_object_class_install_property (klass, ARG_FRAMERATE, g_object_class_install_property (klass, ARG_FRAMERATE,
g_param_spec_enum ("framerate", "Framerate", "Output framerate", g_param_spec_enum ("framerate", "Framerate", "Output framerate",
GST_TYPE_MPEG2ENC_FRAMERATE, 0, GST_TYPE_MPEG2ENC_FRAMERATE, 0, (GParamFlags) G_PARAM_READWRITE));
(GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_ASPECT, g_object_class_install_property (klass, ARG_ASPECT,
g_param_spec_enum ("aspect", "Aspect", "Display aspect ratio", g_param_spec_enum ("aspect", "Aspect", "Display aspect ratio",
GST_TYPE_MPEG2ENC_ASPECT, 0, GST_TYPE_MPEG2ENC_ASPECT, 0, (GParamFlags) G_PARAM_READWRITE));
(GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_INTERLACE_MODE, g_object_class_install_property (klass, ARG_INTERLACE_MODE,
g_param_spec_enum ("interlace-mode", "Interlace mode", g_param_spec_enum ("interlace-mode", "Interlace mode",
"MPEG-2 motion estimation and encoding modes", "MPEG-2 motion estimation and encoding modes",
GST_TYPE_MPEG2ENC_INTERLACE_MODE, 0, GST_TYPE_MPEG2ENC_INTERLACE_MODE, 0,
(GParamFlags) G_PARAM_READWRITE)); (GParamFlags) G_PARAM_READWRITE));
/* general encoding stream options */ /* general encoding stream options */
g_object_class_install_property (klass, ARG_BITRATE, g_object_class_install_property (klass, ARG_BITRATE,
g_param_spec_int ("bitrate", "Bitrate", "Compressed video bitrate (kbps)", g_param_spec_int ("bitrate", "Bitrate", "Compressed video bitrate (kbps)",
0, 10*1024, 1125, (GParamFlags) G_PARAM_READWRITE)); 0, 10 * 1024, 1125, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_NONVIDEO_BITRATE, g_object_class_install_property (klass, ARG_NONVIDEO_BITRATE,
g_param_spec_int ("non-video-bitrate", "Non-video bitrate", g_param_spec_int ("non-video-bitrate", "Non-video bitrate",
"Assumed bitrate of non-video for sequence splitting (kbps)", "Assumed bitrate of non-video for sequence splitting (kbps)",
0, 10*1024, 0, (GParamFlags) G_PARAM_READWRITE)); 0, 10 * 1024, 0, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_QUANTISATION, g_object_class_install_property (klass, ARG_QUANTISATION,
g_param_spec_int ("quantisation", "Quantisation", g_param_spec_int ("quantisation", "Quantisation",
"Quantisation factor (0=default, 1=best, 31=worst)", "Quantisation factor (0=default, 1=best, 31=worst)",
0, 31, 0, (GParamFlags) G_PARAM_READWRITE)); 0, 31, 0, (GParamFlags) G_PARAM_READWRITE));
/* stills options */ /* stills options */
g_object_class_install_property (klass, ARG_VCD_STILL_SIZE, g_object_class_install_property (klass, ARG_VCD_STILL_SIZE,
g_param_spec_int ("vcd-still-size", "VCD stills size", g_param_spec_int ("vcd-still-size", "VCD stills size",
"Size of VCD stills (in kB)", "Size of VCD stills (in kB)",
0, 512, 0, (GParamFlags) G_PARAM_READWRITE)); 0, 512, 0, (GParamFlags) G_PARAM_READWRITE));
/* motion estimation options */ /* motion estimation options */
g_object_class_install_property (klass, ARG_MOTION_SEARCH_RADIUS, g_object_class_install_property (klass, ARG_MOTION_SEARCH_RADIUS,
g_param_spec_int ("motion-search-radius", "Motion search radius", g_param_spec_int ("motion-search-radius", "Motion search radius",
"Motion compensation search radius", "Motion compensation search radius",
0, 32, 16, (GParamFlags) G_PARAM_READWRITE)); 0, 32, 16, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_REDUCTION_4_4, g_object_class_install_property (klass, ARG_REDUCTION_4_4,
g_param_spec_int ("reduction-4x4", "4x4 reduction", g_param_spec_int ("reduction-4x4", "4x4 reduction",
"Reduction factor for 4x4 subsampled candidate motion estimates" "Reduction factor for 4x4 subsampled candidate motion estimates"
" (1=max. quality, 4=max. speed)", " (1=max. quality, 4=max. speed)",
1, 4, 2, (GParamFlags) G_PARAM_READWRITE)); 1, 4, 2, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_REDUCTION_2_2, g_object_class_install_property (klass, ARG_REDUCTION_2_2,
g_param_spec_int ("reduction-2x2", "2x2 reduction", g_param_spec_int ("reduction-2x2", "2x2 reduction",
"Reduction factor for 2x2 subsampled candidate motion estimates" "Reduction factor for 2x2 subsampled candidate motion estimates"
" (1=max. quality, 4=max. speed)", " (1=max. quality, 4=max. speed)",
1, 4, 3, (GParamFlags) G_PARAM_READWRITE)); 1, 4, 3, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_UNIT_COEFF_ELIM, g_object_class_install_property (klass, ARG_UNIT_COEFF_ELIM,
g_param_spec_int ("unit-coeff-elim", "Unit coefficience elimination", g_param_spec_int ("unit-coeff-elim", "Unit coefficience elimination",
"How agressively small-unit picture blocks should be skipped", "How agressively small-unit picture blocks should be skipped",
-40, 40, 0, (GParamFlags) G_PARAM_READWRITE)); -40, 40, 0, (GParamFlags) G_PARAM_READWRITE));
/* GOP options */ /* GOP options */
g_object_class_install_property (klass, ARG_MIN_GOP_SIZE, g_object_class_install_property (klass, ARG_MIN_GOP_SIZE,
g_param_spec_int ("min-gop-size", "Min. GOP size", g_param_spec_int ("min-gop-size", "Min. GOP size",
"Minimal size per Group-of-Pictures (-1=default)", "Minimal size per Group-of-Pictures (-1=default)",
-1, 250, 0, (GParamFlags) G_PARAM_READWRITE)); -1, 250, 0, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_MAX_GOP_SIZE, g_object_class_install_property (klass, ARG_MAX_GOP_SIZE,
g_param_spec_int ("max-gop-size", "Max. GOP size", g_param_spec_int ("max-gop-size", "Max. GOP size",
"Maximal size per Group-of-Pictures (-1=default)", "Maximal size per Group-of-Pictures (-1=default)",
-1, 250, 0, (GParamFlags) G_PARAM_READWRITE)); -1, 250, 0, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_CLOSED_GOP, g_object_class_install_property (klass, ARG_CLOSED_GOP,
g_param_spec_boolean ("closed-gop", "Closed GOP", g_param_spec_boolean ("closed-gop", "Closed GOP",
"All Group-of-Pictures are closed (for multi-angle DVDs)", "All Group-of-Pictures are closed (for multi-angle DVDs)",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_FORCE_B_B_P, g_object_class_install_property (klass, ARG_FORCE_B_B_P,
g_param_spec_boolean ("force-b-b-p", "Force B-B-P", g_param_spec_boolean ("force-b-b-p", "Force B-B-P",
"Force two B frames between I/P frames when closing GOP boundaries", "Force two B frames between I/P frames when closing GOP boundaries",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_B_PER_REFFRAME, g_object_class_install_property (klass, ARG_B_PER_REFFRAME,
g_param_spec_int ("b-per-refframe", "B per ref. frame", g_param_spec_int ("b-per-refframe", "B per ref. frame",
"Number of B frames between each I/P frame", "Number of B frames between each I/P frame",
0, 2, 2, (GParamFlags) G_PARAM_READWRITE)); 0, 2, 2, (GParamFlags) G_PARAM_READWRITE));
/* quantisation options */ /* quantisation options */
g_object_class_install_property (klass, ARG_QUANTISATION_REDUCTION, g_object_class_install_property (klass, ARG_QUANTISATION_REDUCTION,
g_param_spec_float ("quantisation-reduction", "Quantisation reduction", g_param_spec_float ("quantisation-reduction", "Quantisation reduction",
"Max. quantisation reduction for highly active blocks", "Max. quantisation reduction for highly active blocks",
-4., 10., 0., (GParamFlags) G_PARAM_READWRITE)); -4., 10., 0., (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_QUANT_REDUCTION_MAX_VAR, g_object_class_install_property (klass, ARG_QUANT_REDUCTION_MAX_VAR,
g_param_spec_float ("quant-reduction-max-var", "Max. quant. reduction variance", g_param_spec_float ("quant-reduction-max-var",
"Maximal luma variance below which quantisation boost is used", "Max. quant. reduction variance",
0., 2500., 0., (GParamFlags) G_PARAM_READWRITE)); "Maximal luma variance below which quantisation boost is used", 0.,
2500., 0., (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_INTRA_DC_PRECISION, g_object_class_install_property (klass, ARG_INTRA_DC_PRECISION,
g_param_spec_int ("intra-dc-prec", "Intra. DC precision", g_param_spec_int ("intra-dc-prec", "Intra. DC precision",
"Number of bits precision for DC (base colour) in MPEG-2 blocks", "Number of bits precision for DC (base colour) in MPEG-2 blocks", 8,
8, 11, 9, (GParamFlags) G_PARAM_READWRITE)); 11, 9, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_REDUCE_HF, g_object_class_install_property (klass, ARG_REDUCE_HF,
g_param_spec_float ("reduce-hf", "Reduce HF", g_param_spec_float ("reduce-hf", "Reduce HF",
"How much to reduce high-frequency resolution (by increasing quantisation)", "How much to reduce high-frequency resolution (by increasing quantisation)",
0., 2., 0., (GParamFlags) G_PARAM_READWRITE)); 0., 2., 0., (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_KEEP_HF, g_object_class_install_property (klass, ARG_KEEP_HF,
g_param_spec_boolean ("keep-hf", "Keep HF", g_param_spec_boolean ("keep-hf", "Keep HF",
"Maximize high-frequency resolution (for high-quality sources)", "Maximize high-frequency resolution (for high-quality sources)",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_QUANTISATION_MATRIX, g_object_class_install_property (klass, ARG_QUANTISATION_MATRIX,
g_param_spec_enum ("quant-matrix", "Quant. matrix", g_param_spec_enum ("quant-matrix", "Quant. matrix",
"Quantisation matrix to use for encoding", "Quantisation matrix to use for encoding",
GST_TYPE_MPEG2ENC_QUANTISATION_MATRIX, 0, GST_TYPE_MPEG2ENC_QUANTISATION_MATRIX, 0,
(GParamFlags) G_PARAM_READWRITE)); (GParamFlags) G_PARAM_READWRITE));
/* general options */ /* general options */
g_object_class_install_property (klass, ARG_BUFSIZE, g_object_class_install_property (klass, ARG_BUFSIZE,
g_param_spec_int ("bufsize", "Decoder buf. size", g_param_spec_int ("bufsize", "Decoder buf. size",
"Target decoders video buffer size (kB)", "Target decoders video buffer size (kB)",
20, 4000, 46, (GParamFlags) G_PARAM_READWRITE)); 20, 4000, 46, (GParamFlags) G_PARAM_READWRITE));
/* header flag settings */ /* header flag settings */
g_object_class_install_property (klass, ARG_VIDEO_NORM, g_object_class_install_property (klass, ARG_VIDEO_NORM,
g_param_spec_enum ("norm", "Norm", g_param_spec_enum ("norm", "Norm",
"Tag output for specific video norm", "Tag output for specific video norm",
GST_TYPE_MPEG2ENC_VIDEO_NORM, 0, GST_TYPE_MPEG2ENC_VIDEO_NORM, 0, (GParamFlags) G_PARAM_READWRITE));
(GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_SEQUENCE_LENGTH, g_object_class_install_property (klass, ARG_SEQUENCE_LENGTH,
g_param_spec_int ("sequence-length", "Sequence length", g_param_spec_int ("sequence-length", "Sequence length",
"Place a sequence boundary after each <num> MB (0=disable)", "Place a sequence boundary after each <num> MB (0=disable)",
0, 10*1024, 0, (GParamFlags) G_PARAM_READWRITE)); 0, 10 * 1024, 0, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_3_2_PULLDOWN, g_object_class_install_property (klass, ARG_3_2_PULLDOWN,
g_param_spec_boolean ("pulldown-3-2", "3-2 pull down", g_param_spec_boolean ("pulldown-3-2", "3-2 pull down",
"Generate header flags for 3-2 pull down 24fps movies", "Generate header flags for 3-2 pull down 24fps movies",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_SEQUENCE_HEADER_EVERY_GOP, g_object_class_install_property (klass, ARG_SEQUENCE_HEADER_EVERY_GOP,
g_param_spec_boolean ("sequence-header-every-gop", g_param_spec_boolean ("sequence-header-every-gop",
"Sequence hdr. every GOP", "Sequence hdr. every GOP",
"Include a sequence header in every GOP", "Include a sequence header in every GOP",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_DUMMY_SVCD_SOF, g_object_class_install_property (klass, ARG_DUMMY_SVCD_SOF,
g_param_spec_boolean ("dummy-svcd-sof", "Dummy SVCD SOF", g_param_spec_boolean ("dummy-svcd-sof", "Dummy SVCD SOF",
"Generate dummy SVCD scan-data (for vcdimager)", "Generate dummy SVCD scan-data (for vcdimager)",
TRUE, (GParamFlags) G_PARAM_READWRITE)); TRUE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_PLAYBACK_FIELD_ORDER, g_object_class_install_property (klass, ARG_PLAYBACK_FIELD_ORDER,
g_param_spec_enum ("playback-field-order", "Playback field order", g_param_spec_enum ("playback-field-order", "Playback field order",
"Force specific playback field order", "Force specific playback field order",
GST_TYPE_MPEG2ENC_PLAYBACK_FIELD_ORDER, Y4M_UNKNOWN, GST_TYPE_MPEG2ENC_PLAYBACK_FIELD_ORDER, Y4M_UNKNOWN,
(GParamFlags) G_PARAM_READWRITE)); (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_CORRECT_SVCD_HDS, g_object_class_install_property (klass, ARG_CORRECT_SVCD_HDS,
g_param_spec_boolean ("correct-svcd-hds", "Correct SVCD hor. size", g_param_spec_boolean ("correct-svcd-hds", "Correct SVCD hor. size",
"Force SVCD width to 480 instead of 540/720", "Force SVCD width to 480 instead of 540/720",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_ALTSCAN_MPEG2, g_object_class_install_property (klass, ARG_ALTSCAN_MPEG2,
g_param_spec_boolean ("altscan-mpeg2", "Alt. MPEG-2 scan", g_param_spec_boolean ("altscan-mpeg2", "Alt. MPEG-2 scan",
"Alternate MPEG-2 block scanning. Disabling this might " "Alternate MPEG-2 block scanning. Disabling this might "
"make buggy players play SVCD streams", "make buggy players play SVCD streams",
TRUE, (GParamFlags) G_PARAM_READWRITE)); TRUE, (GParamFlags) G_PARAM_READWRITE));
#if 0 #if 0
"--dxr2-hack" "--dxr2-hack"
#endif #endif
/* dangerous/experimental stuff */
/* dangerous/experimental stuff */ g_object_class_install_property (klass, ARG_CONSTRAINTS,
g_object_class_install_property (klass, ARG_CONSTRAINTS, g_param_spec_boolean ("constraints", "Constraints",
g_param_spec_boolean ("constraints", "Constraints", "Use strict video resolution and bitrate checks",
"Use strict video resolution and bitrate checks", TRUE, (GParamFlags) G_PARAM_READWRITE));
TRUE, (GParamFlags) G_PARAM_READWRITE));
} }
/* /*
@ -456,8 +449,7 @@ GstMpeg2EncOptions::initProperties (GObjectClass *klass)
*/ */
void void
GstMpeg2EncOptions::getProperty (guint prop_id, GstMpeg2EncOptions::getProperty (guint prop_id, GValue * value)
GValue *value)
{ {
switch (prop_id) { switch (prop_id) {
case ARG_FORMAT: case ARG_FORMAT:
@ -473,10 +465,10 @@ GstMpeg2EncOptions::getProperty (guint prop_id,
g_value_set_enum (value, fieldenc); g_value_set_enum (value, fieldenc);
break; break;
case ARG_BITRATE: case ARG_BITRATE:
g_value_set_int (value, bitrate/1024); g_value_set_int (value, bitrate / 1024);
break; break;
case ARG_NONVIDEO_BITRATE: case ARG_NONVIDEO_BITRATE:
g_value_set_int (value, nonvid_bitrate/1024); g_value_set_int (value, nonvid_bitrate / 1024);
break; break;
case ARG_QUANTISATION: case ARG_QUANTISATION:
g_value_set_int (value, quant); g_value_set_int (value, quant);
@ -528,18 +520,18 @@ GstMpeg2EncOptions::getProperty (guint prop_id,
break; break;
case ARG_QUANTISATION_MATRIX: case ARG_QUANTISATION_MATRIX:
switch (hf_quant) { switch (hf_quant) {
case 0: case 0:
g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT); g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT);
break; break;
case 2: case 2:
g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES); g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES);
break; break;
case 3: case 3:
g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD); g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD);
break; break;
case 4: case 4:
g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC); g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC);
break; break;
} }
break; break;
case ARG_BUFSIZE: case ARG_BUFSIZE:
@ -578,8 +570,7 @@ GstMpeg2EncOptions::getProperty (guint prop_id,
} }
void void
GstMpeg2EncOptions::setProperty (guint prop_id, GstMpeg2EncOptions::setProperty (guint prop_id, const GValue * value)
const GValue *value)
{ {
switch (prop_id) { switch (prop_id) {
case ARG_FORMAT: case ARG_FORMAT:
@ -645,26 +636,26 @@ GstMpeg2EncOptions::setProperty (guint prop_id,
case ARG_REDUCE_HF: case ARG_REDUCE_HF:
hf_q_boost = g_value_get_float (value); hf_q_boost = g_value_get_float (value);
if (hf_quant == 0 && hf_q_boost != 0.) if (hf_quant == 0 && hf_q_boost != 0.)
hf_quant = 1; hf_quant = 1;
break; break;
case ARG_KEEP_HF: case ARG_KEEP_HF:
hf_quant = g_value_get_boolean (value) ? 2 : 0; hf_quant = g_value_get_boolean (value) ? 2 : 0;
break; break;
case ARG_QUANTISATION_MATRIX: case ARG_QUANTISATION_MATRIX:
switch (g_value_get_enum (value)) { switch (g_value_get_enum (value)) {
case GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT: case GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT:
hf_quant = 0; hf_quant = 0;
hf_q_boost = 0; hf_q_boost = 0;
break; break;
case GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES: case GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES:
hf_quant = 2; hf_quant = 2;
break; break;
case GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD: case GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD:
hf_quant = 3; hf_quant = 3;
break; break;
case GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC: case GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC:
hf_quant = 4; hf_quant = 4;
break; break;
} }
break; break;
case ARG_BUFSIZE: case ARG_BUFSIZE:

View file

@ -31,10 +31,9 @@
* Class init stuff. * Class init stuff.
*/ */
GstMpeg2EncPictureReader::GstMpeg2EncPictureReader (GstPad *in_pad, GstMpeg2EncPictureReader::GstMpeg2EncPictureReader (GstPad * in_pad,
const GstCaps *in_caps, const GstCaps * in_caps, EncoderParams * params):
EncoderParams *params) : PictureReader (*params)
PictureReader (*params)
{ {
pad = in_pad; pad = in_pad;
caps = gst_caps_copy (in_caps); caps = gst_caps_copy (in_caps);
@ -50,7 +49,7 @@ GstMpeg2EncPictureReader::~GstMpeg2EncPictureReader ()
*/ */
void void
GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams &strm) GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams & strm)
{ {
GstStructure *structure = gst_caps_get_structure (caps, 0); GstStructure *structure = gst_caps_get_structure (caps, 0);
gint width, height; gint width, height;
@ -65,8 +64,7 @@ GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams &strm)
strm.frame_rate_code = mpeg_framerate_code (mpeg_conform_framerate (fps)); strm.frame_rate_code = mpeg_framerate_code (mpeg_conform_framerate (fps));
strm.interlacing_code = Y4M_ILACE_NONE; strm.interlacing_code = Y4M_ILACE_NONE;
strm.aspect_ratio_code = mpeg_guess_mpeg_aspect_code (2, y4m_sar_SQUARE, strm.aspect_ratio_code = mpeg_guess_mpeg_aspect_code (2, y4m_sar_SQUARE,
strm.horizontal_size, strm.horizontal_size, strm.vertical_size);
strm.vertical_size);
/* FIXME: /* FIXME:
* strm.interlacing_code = y4m_si_get_interlace(&si); * strm.interlacing_code = y4m_si_get_interlace(&si);
@ -82,15 +80,24 @@ GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams &strm)
* Read a frame. Return true means EOS or error. * Read a frame. Return true means EOS or error.
*/ */
bool bool GstMpeg2EncPictureReader::LoadFrame ()
GstMpeg2EncPictureReader::LoadFrame ()
{ {
GstData *data; GstData *
GstBuffer *buf = NULL; data;
gint i, x, y, n; GstBuffer *
guint8 *frame; buf = NULL;
GstFormat fmt = GST_FORMAT_DEFAULT; gint
gint64 pos = 0, tot = 0; i,
x,
y,
n;
guint8 *
frame;
GstFormat
fmt = GST_FORMAT_DEFAULT;
gint64
pos = 0, tot = 0;
gst_pad_query (GST_PAD_PEER (pad), GST_QUERY_POSITION, &fmt, &pos); gst_pad_query (GST_PAD_PEER (pad), GST_QUERY_POSITION, &fmt, &pos);
gst_pad_query (GST_PAD_PEER (pad), GST_QUERY_TOTAL, &fmt, &tot); gst_pad_query (GST_PAD_PEER (pad), GST_QUERY_TOTAL, &fmt, &tot);
@ -99,16 +106,16 @@ GstMpeg2EncPictureReader::LoadFrame ()
gst_pad_set_element_private (pad, NULL); gst_pad_set_element_private (pad, NULL);
} else if (!(data = gst_pad_pull (pad))) { } else if (!(data = gst_pad_pull (pad))) {
GST_ELEMENT_ERROR (gst_pad_get_parent (pad), RESOURCE, READ, GST_ELEMENT_ERROR (gst_pad_get_parent (pad), RESOURCE, READ,
(NULL), (NULL)); (NULL), (NULL));
return true; return true;
} }
if (GST_IS_EVENT (data)) { if (GST_IS_EVENT (data)) {
if (GST_EVENT_TYPE (data) == GST_EVENT_EOS) { if (GST_EVENT_TYPE (data) == GST_EVENT_EOS) {
gst_event_unref (GST_EVENT (data)); gst_event_unref (GST_EVENT (data));
return true; return true;
} else { } else {
gst_pad_event_default (pad, GST_EVENT (data)); gst_pad_event_default (pad, GST_EVENT (data));
} }
} else { } else {
buf = GST_BUFFER (data); buf = GST_BUFFER (data);
@ -121,18 +128,18 @@ GstMpeg2EncPictureReader::LoadFrame ()
y = encparams.vertical_size; y = encparams.vertical_size;
for (i = 0; i < y; i++) { for (i = 0; i < y; i++) {
memcpy (input_imgs_buf[n][0]+i*encparams.phy_width, frame, x); memcpy (input_imgs_buf[n][0] + i * encparams.phy_width, frame, x);
frame += x; frame += x;
} }
lum_mean[n] = LumMean (input_imgs_buf[n][0]); lum_mean[n] = LumMean (input_imgs_buf[n][0]);
x >>= 1; x >>= 1;
y >>= 1; y >>= 1;
for (i = 0; i < y; i++) { for (i = 0; i < y; i++) {
memcpy (input_imgs_buf[n][1]+i*encparams.phy_chrom_width, frame, x); memcpy (input_imgs_buf[n][1] + i * encparams.phy_chrom_width, frame, x);
frame += x; frame += x;
} }
for (i = 0; i < y; i++) { for (i = 0; i < y; i++) {
memcpy (input_imgs_buf[n][2]+i*encparams.phy_chrom_width, frame, x); memcpy (input_imgs_buf[n][2] + i * encparams.phy_chrom_width, frame, x);
frame += x; frame += x;
} }
gst_buffer_unref (buf); gst_buffer_unref (buf);

View file

@ -31,9 +31,8 @@
* Class init stuff. * Class init stuff.
*/ */
GstMpeg2EncStreamWriter::GstMpeg2EncStreamWriter (GstPad *in_pad, GstMpeg2EncStreamWriter::GstMpeg2EncStreamWriter (GstPad * in_pad, EncoderParams * params):
EncoderParams *params) : ElemStrmWriter (*params)
ElemStrmWriter (*params)
{ {
pad = in_pad; pad = in_pad;
buf = NULL; buf = NULL;
@ -44,8 +43,7 @@ GstMpeg2EncStreamWriter::GstMpeg2EncStreamWriter (GstPad *in_pad,
*/ */
void void
GstMpeg2EncStreamWriter::PutBits (guint32 val, GstMpeg2EncStreamWriter::PutBits (guint32 val, gint n)
gint n)
{ {
/* only relevant bits. Note that (according to Andrew), /* only relevant bits. Note that (according to Andrew),
* some CPUs do bitshifts modulo wordsize (32), which * some CPUs do bitshifts modulo wordsize (32), which
@ -62,7 +60,7 @@ GstMpeg2EncStreamWriter::PutBits (guint32 val,
GST_BUFFER_SIZE (buf) = 0; GST_BUFFER_SIZE (buf) = 0;
} }
outbfr = (outbfr << outcnt ) | (val >> (n - outcnt)); outbfr = (outbfr << outcnt) | (val >> (n - outcnt));
GST_BUFFER_DATA (buf)[GST_BUFFER_SIZE (buf)++] = outbfr; GST_BUFFER_DATA (buf)[GST_BUFFER_SIZE (buf)++] = outbfr;
n -= outcnt; n -= outcnt;
outcnt = 8; outcnt = 8;

View file

@ -28,74 +28,55 @@
#include "gstmplexibitstream.hh" #include "gstmplexibitstream.hh"
#include "gstmplexjob.hh" #include "gstmplexjob.hh"
static GstStaticPadTemplate src_templ = static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_PAD_TEMPLATE ( GST_PAD_SRC,
"src", GST_PAD_ALWAYS,
GST_PAD_SRC, GST_STATIC_CAPS ("video/mpeg, " "systemstream = (boolean) true")
GST_PAD_ALWAYS, );
GST_STATIC_CAPS (
"video/mpeg, "
"systemstream = (boolean) true"
)
);
static GstStaticPadTemplate video_sink_templ = static GstStaticPadTemplate video_sink_templ =
GST_STATIC_PAD_TEMPLATE ( GST_STATIC_PAD_TEMPLATE ("video_%d",
"video_%d", GST_PAD_SINK,
GST_PAD_SINK, GST_PAD_REQUEST,
GST_PAD_REQUEST, GST_STATIC_CAPS ("video/mpeg, "
GST_STATIC_CAPS ( "mpegversion = (int) [ 1, 2 ], " "systemstream = (boolean) false")
"video/mpeg, " );
"mpegversion = (int) [ 1, 2 ], "
"systemstream = (boolean) false"
)
);
static GstStaticPadTemplate audio_sink_templ = static GstStaticPadTemplate audio_sink_templ =
GST_STATIC_PAD_TEMPLATE ( GST_STATIC_PAD_TEMPLATE ("audio_%d",
"audio_%d", GST_PAD_SINK,
GST_PAD_SINK, GST_PAD_REQUEST,
GST_PAD_REQUEST, GST_STATIC_CAPS ("audio/mpeg, "
GST_STATIC_CAPS ( "mpegversion = (int) 1, "
"audio/mpeg, " "layer = (int) [ 1, 2 ]; "
"mpegversion = (int) 1, " "audio/x-ac3; "
"layer = (int) [ 1, 2 ]; " "audio/x-dts; "
"audio/x-ac3; " "audio/x-raw-int, "
"audio/x-dts; " "endianness = (int) BYTE_ORDER, "
"audio/x-raw-int, " "signed = (boolean) TRUE, "
"endianness = (int) BYTE_ORDER, " "width = (int) { 16, 20, 24 }, "
"signed = (boolean) TRUE, " "depth = (int) { 16, 20, 24 }, "
"width = (int) { 16, 20, 24 }, " "rate = (int) { 48000, 96000 }, " "channels = (int) [ 1, 6 ]")
"depth = (int) { 16, 20, 24 }, " );
"rate = (int) { 48000, 96000 }, "
"channels = (int) [ 1, 6 ]"
)
);
/* FIXME: subtitles */ /* FIXME: subtitles */
static void gst_mplex_base_init (GstMplexClass *klass); static void gst_mplex_base_init (GstMplexClass * klass);
static void gst_mplex_class_init (GstMplexClass *klass); static void gst_mplex_class_init (GstMplexClass * klass);
static void gst_mplex_init (GstMplex *enc); static void gst_mplex_init (GstMplex * enc);
static void gst_mplex_dispose (GObject *object); static void gst_mplex_dispose (GObject * object);
static void gst_mplex_loop (GstElement *element); static void gst_mplex_loop (GstElement * element);
static GstPad *gst_mplex_request_new_pad (GstElement *element, static GstPad *gst_mplex_request_new_pad (GstElement * element,
GstPadTemplate *templ, GstPadTemplate * templ, const gchar * name);
const gchar *name);
static GstElementStateReturn static GstElementStateReturn gst_mplex_change_state (GstElement * element);
gst_mplex_change_state (GstElement *element);
static void gst_mplex_get_property (GObject *object, static void gst_mplex_get_property (GObject * object,
guint prop_id, guint prop_id, GValue * value, GParamSpec * pspec);
GValue *value, static void gst_mplex_set_property (GObject * object,
GParamSpec *pspec); guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_mplex_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -106,7 +87,7 @@ gst_mplex_get_type (void)
if (!gst_mplex_type) { if (!gst_mplex_type) {
static const GTypeInfo gst_mplex_info = { static const GTypeInfo gst_mplex_info = {
sizeof (GstMplexClass), sizeof (GstMplexClass),
(GBaseInitFunc) gst_mplex_base_init, (GBaseInitFunc) gst_mplex_base_init,
NULL, NULL,
(GClassInitFunc) gst_mplex_class_init, (GClassInitFunc) gst_mplex_class_init,
@ -119,38 +100,35 @@ gst_mplex_get_type (void)
gst_mplex_type = gst_mplex_type =
g_type_register_static (GST_TYPE_ELEMENT, g_type_register_static (GST_TYPE_ELEMENT,
"GstMplex", "GstMplex", &gst_mplex_info, (GTypeFlags) 0);
&gst_mplex_info,
(GTypeFlags) 0);
} }
return gst_mplex_type; return gst_mplex_type;
} }
static void static void
gst_mplex_base_init (GstMplexClass *klass) gst_mplex_base_init (GstMplexClass * klass)
{ {
static GstElementDetails gst_mplex_details = { static GstElementDetails gst_mplex_details = {
"mplex video multiplexer", "mplex video multiplexer",
"Codec/Muxer", "Codec/Muxer",
"High-quality MPEG/DVD/SVCD/VCD video/audio multiplexer", "High-quality MPEG/DVD/SVCD/VCD video/audio multiplexer",
"Andrew Stevens <andrew.stevens@nexgo.de>\n" "Andrew Stevens <andrew.stevens@nexgo.de>\n"
"Ronald Bultje <rbultje@ronald.bitfreak.net>" "Ronald Bultje <rbultje@ronald.bitfreak.net>"
}; };
GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_templ)); gst_static_pad_template_get (&src_templ));
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&video_sink_templ)); gst_static_pad_template_get (&video_sink_templ));
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&audio_sink_templ)); gst_static_pad_template_get (&audio_sink_templ));
gst_element_class_set_details (element_class, gst_element_class_set_details (element_class, &gst_mplex_details);
&gst_mplex_details);
} }
static void static void
gst_mplex_class_init (GstMplexClass *klass) gst_mplex_class_init (GstMplexClass * klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
@ -171,26 +149,28 @@ gst_mplex_class_init (GstMplexClass *klass)
} }
static void static void
gst_mplex_dispose (GObject *object) gst_mplex_dispose (GObject * object)
{ {
GstMplex *mplex = GST_MPLEX (object); GstMplex *mplex = GST_MPLEX (object);
if (mplex->mux) { if (mplex->mux) {
delete mplex->mux; delete mplex->mux;
mplex->mux = NULL; mplex->mux = NULL;
} }
delete mplex->job; delete mplex->job;
} }
static void static void
gst_mplex_init (GstMplex *mplex) gst_mplex_init (GstMplex * mplex)
{ {
GstElement *element = GST_ELEMENT (mplex); GstElement *element = GST_ELEMENT (mplex);
GST_FLAG_SET (element, GST_ELEMENT_EVENT_AWARE); GST_FLAG_SET (element, GST_ELEMENT_EVENT_AWARE);
mplex->srcpad = gst_pad_new_from_template ( mplex->srcpad =
gst_element_get_pad_template (element, "src"), "src"); gst_pad_new_from_template (gst_element_get_pad_template (element, "src"),
"src");
gst_element_add_pad (element, mplex->srcpad); gst_element_add_pad (element, mplex->srcpad);
mplex->job = new GstMplexJob (); mplex->job = new GstMplexJob ();
@ -202,7 +182,7 @@ gst_mplex_init (GstMplex *mplex)
} }
static void static void
gst_mplex_loop (GstElement *element) gst_mplex_loop (GstElement * element)
{ {
GstMplex *mplex = GST_MPLEX (element); GstMplex *mplex = GST_MPLEX (element);
@ -211,7 +191,7 @@ gst_mplex_loop (GstElement *element)
const GList *item; const GList *item;
for (item = gst_element_get_pad_list (element); for (item = gst_element_get_pad_list (element);
item != NULL; item = item->next) { item != NULL; item = item->next) {
StreamKind type; StreamKind type;
GstMplexIBitStream *inputstream; GstMplexIBitStream *inputstream;
JobStream *jobstream; JobStream *jobstream;
@ -222,15 +202,16 @@ gst_mplex_loop (GstElement *element)
/* skip our source pad */ /* skip our source pad */
if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC)
continue; continue;
/* create inputstream, assure we've got caps */ /* create inputstream, assure we've got caps */
inputstream = new GstMplexIBitStream (pad); inputstream = new GstMplexIBitStream (pad);
/* skip unnegotiated pads */ /* skip unnegotiated pads */
if (!(caps = GST_PAD_CAPS (pad))) { if (!(caps = GST_PAD_CAPS (pad))) {
delete inputstream; delete inputstream;
continue;
continue;
} }
/* get format */ /* get format */
@ -238,40 +219,41 @@ gst_mplex_loop (GstElement *element)
mime = gst_structure_get_name (structure); mime = gst_structure_get_name (structure);
if (!strcmp (mime, "video/mpeg")) { if (!strcmp (mime, "video/mpeg")) {
VideoParams *params; VideoParams *params;
type = MPEG_VIDEO; type = MPEG_VIDEO;
params = VideoParams::Default (mplex->job->mux_format); params = VideoParams::Default (mplex->job->mux_format);
mplex->job->video_param.push_back (params); mplex->job->video_param.push_back (params);
mplex->job->video_tracks++; mplex->job->video_tracks++;
} else if (!strcmp (mime, "audio/mpeg")) { } else if (!strcmp (mime, "audio/mpeg")) {
type = MPEG_AUDIO; type = MPEG_AUDIO;
mplex->job->audio_tracks++; mplex->job->audio_tracks++;
} else if (!strcmp (mime, "audio/x-ac3")) { } else if (!strcmp (mime, "audio/x-ac3")) {
type = AC3_AUDIO; type = AC3_AUDIO;
mplex->job->audio_tracks++; mplex->job->audio_tracks++;
} else if (!strcmp (mime, "audio/x-dts")) { } else if (!strcmp (mime, "audio/x-dts")) {
type = DTS_AUDIO; type = DTS_AUDIO;
mplex->job->audio_tracks++; mplex->job->audio_tracks++;
} else if (!strcmp (mime, "audio/x-raw-int")) { } else if (!strcmp (mime, "audio/x-raw-int")) {
LpcmParams *params; LpcmParams *params;
gint bits, chans, rate; gint bits, chans, rate;
type = LPCM_AUDIO; type = LPCM_AUDIO;
/* set LPCM params */ /* set LPCM params */
gst_structure_get_int (structure, "depth", &bits); gst_structure_get_int (structure, "depth", &bits);
gst_structure_get_int (structure, "rate", &rate); gst_structure_get_int (structure, "rate", &rate);
gst_structure_get_int (structure, "channels", &chans); gst_structure_get_int (structure, "channels", &chans);
params = LpcmParams::Checked (rate, chans, bits); params = LpcmParams::Checked (rate, chans, bits);
mplex->job->lpcm_param.push_back (params); mplex->job->lpcm_param.push_back (params);
mplex->job->audio_tracks++; mplex->job->audio_tracks++;
mplex->job->lpcm_tracks++; mplex->job->lpcm_tracks++;
} else { } else {
delete inputstream; delete inputstream;
continue;
continue;
} }
jobstream = new JobStream (inputstream, type); jobstream = new JobStream (inputstream, type);
@ -280,7 +262,7 @@ gst_mplex_loop (GstElement *element)
if (!mplex->job->video_tracks && !mplex->job->audio_tracks) { if (!mplex->job->video_tracks && !mplex->job->audio_tracks) {
GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL), GST_ELEMENT_ERROR (element, CORE, NEGOTIATION, (NULL),
("no input video or audio tracks set up before loop function")); ("no input video or audio tracks set up before loop function"));
return; return;
} }
@ -293,8 +275,7 @@ gst_mplex_loop (GstElement *element)
} }
static GstPadLinkReturn static GstPadLinkReturn
gst_mplex_sink_link (GstPad *pad, gst_mplex_sink_link (GstPad * pad, const GstCaps * caps)
const GstCaps *caps)
{ {
GstStructure *structure = gst_caps_get_structure (caps, 0); GstStructure *structure = gst_caps_get_structure (caps, 0);
const gchar *mime = gst_structure_get_name (structure); const gchar *mime = gst_structure_get_name (structure);
@ -318,9 +299,8 @@ gst_mplex_sink_link (GstPad *pad,
} }
static GstPad * static GstPad *
gst_mplex_request_new_pad (GstElement *element, gst_mplex_request_new_pad (GstElement * element,
GstPadTemplate *templ, GstPadTemplate * templ, const gchar * name)
const gchar *name)
{ {
GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
GstMplex *mplex = GST_MPLEX (element); GstMplex *mplex = GST_MPLEX (element);
@ -345,25 +325,21 @@ gst_mplex_request_new_pad (GstElement *element,
} }
static void static void
gst_mplex_get_property (GObject *object, gst_mplex_get_property (GObject * object,
guint prop_id, guint prop_id, GValue * value, GParamSpec * pspec)
GValue *value,
GParamSpec *pspec)
{ {
GST_MPLEX (object)->job->getProperty (prop_id, value); GST_MPLEX (object)->job->getProperty (prop_id, value);
} }
static void static void
gst_mplex_set_property (GObject *object, gst_mplex_set_property (GObject * object,
guint prop_id, guint prop_id, const GValue * value, GParamSpec * pspec)
const GValue *value,
GParamSpec *pspec)
{ {
GST_MPLEX (object)->job->setProperty (prop_id, value); GST_MPLEX (object)->job->setProperty (prop_id, value);
} }
static GstElementStateReturn static GstElementStateReturn
gst_mplex_change_state (GstElement *element) gst_mplex_change_state (GstElement * element)
{ {
GstMplex *mplex = GST_MPLEX (element); GstMplex *mplex = GST_MPLEX (element);
@ -385,24 +361,16 @@ gst_mplex_change_state (GstElement *element)
} }
static gboolean static gboolean
plugin_init (GstPlugin *plugin) plugin_init (GstPlugin * plugin)
{ {
if (!gst_library_load ("gstbytestream")) if (!gst_library_load ("gstbytestream"))
return FALSE; return FALSE;
return gst_element_register (plugin, "mplex", return gst_element_register (plugin, "mplex", GST_RANK_NONE, GST_TYPE_MPLEX);
GST_RANK_NONE,
GST_TYPE_MPLEX);
} }
GST_PLUGIN_DEFINE ( GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MAJOR, GST_VERSION_MINOR,
GST_VERSION_MINOR, "mplex",
"mplex", "High-quality MPEG/DVD/SVCD/VCD video/audio multiplexer",
"High-quality MPEG/DVD/SVCD/VCD video/audio multiplexer", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN)
plugin_init,
VERSION,
"GPL",
GST_PACKAGE,
GST_ORIGIN
)

View file

@ -31,9 +31,8 @@
* Class init/exit functions. * Class init/exit functions.
*/ */
GstMplexIBitStream::GstMplexIBitStream (GstPad *_pad, GstMplexIBitStream::GstMplexIBitStream (GstPad * _pad, guint buf_size):
guint buf_size) : IBitStream ()
IBitStream ()
{ {
guint8 *data; guint8 *data;
@ -54,8 +53,7 @@ GstMplexIBitStream::GstMplexIBitStream (GstPad *_pad,
if (!ReadIntoBuffer () && buffered == 0) { if (!ReadIntoBuffer () && buffered == 0) {
GST_ELEMENT_ERROR (gst_pad_get_parent (_pad), RESOURCE, READ, (NULL), GST_ELEMENT_ERROR (gst_pad_get_parent (_pad), RESOURCE, READ, (NULL),
("Failed to read from input pad %s", ("Failed to read from input pad %s", gst_pad_get_name (pad)));
gst_pad_get_name (pad)));
} }
} }
@ -68,28 +66,30 @@ GstMplexIBitStream::~GstMplexIBitStream (void)
* Read data. * Read data.
*/ */
size_t size_t GstMplexIBitStream::ReadStreamBytes (uint8_t * buf, size_t size)
GstMplexIBitStream::ReadStreamBytes (uint8_t *buf,
size_t size)
{ {
guint8 *data; guint8 *
guint read; data;
guint
read;
if (eos) if (eos)
return 0; return 0;
if ((read = gst_bytestream_peek_bytes (bs, &data, size)) != size) { if ((read = gst_bytestream_peek_bytes (bs, &data, size)) != size) {
GstEvent *event; GstEvent *
guint pending; event;
guint
pending;
gst_bytestream_get_status (bs, &pending, &event); gst_bytestream_get_status (bs, &pending, &event);
if (event) { if (event) {
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS: case GST_EVENT_EOS:
eos = TRUE; eos = TRUE;
break; break;
default: default:
break; break;
} }
gst_event_unref (event); gst_event_unref (event);
} }
@ -105,8 +105,7 @@ GstMplexIBitStream::ReadStreamBytes (uint8_t *buf,
* Are we at EOS? * Are we at EOS?
*/ */
bool bool GstMplexIBitStream::EndOfStream (void)
GstMplexIBitStream::EndOfStream (void)
{ {
return eos; return eos;
} }

View file

@ -26,7 +26,8 @@
#include "gstmplexjob.hh" #include "gstmplexjob.hh"
enum { enum
{
ARG_0, ARG_0,
ARG_FORMAT, ARG_FORMAT,
ARG_MUX_BITRATE, ARG_MUX_BITRATE,
@ -36,7 +37,7 @@ enum {
ARG_SEGMENT_SIZE, ARG_SEGMENT_SIZE,
ARG_PACKETS_PER_PACK, ARG_PACKETS_PER_PACK,
ARG_SECTOR_SIZE ARG_SECTOR_SIZE
/* FILL ME */ /* FILL ME */
}; };
/* /*
@ -53,22 +54,21 @@ gst_mplex_format_get_type (void)
if (!mplex_format_type) { if (!mplex_format_type) {
static const GEnumValue mplex_formats[] = { static const GEnumValue mplex_formats[] = {
{ 0, "0", "Generic MPEG-1" }, {0, "0", "Generic MPEG-1"},
{ 1, "1", "Standard VCD" }, {1, "1", "Standard VCD"},
{ 2, "2", "User VCD" }, {2, "2", "User VCD"},
{ 3, "3", "Generic MPEG-2" }, {3, "3", "Generic MPEG-2"},
{ 4, "4", "Standard SVCD" }, {4, "4", "Standard SVCD"},
{ 5, "5", "User SVCD" }, {5, "5", "User SVCD"},
{ 6, "6", "VCD Stills sequences" }, {6, "6", "VCD Stills sequences"},
{ 7, "7", "SVCD Stills sequences" }, {7, "7", "SVCD Stills sequences"},
{ 8, "8", "DVD MPEG-2 for dvdauthor" }, {8, "8", "DVD MPEG-2 for dvdauthor"},
{ 9, "9", "DVD MPEG-2" }, {9, "9", "DVD MPEG-2"},
{ 0, NULL, NULL }, {0, NULL, NULL},
}; };
mplex_format_type = mplex_format_type =
g_enum_register_static ("GstMplexFormat", g_enum_register_static ("GstMplexFormat", mplex_formats);
mplex_formats);
} }
return mplex_format_type; return mplex_format_type;
@ -78,8 +78,8 @@ gst_mplex_format_get_type (void)
* Class init functions. * Class init functions.
*/ */
GstMplexJob::GstMplexJob (void) : GstMplexJob::GstMplexJob (void):
MultiplexJob () MultiplexJob ()
{ {
/* blabla */ /* blabla */
} }
@ -89,58 +89,57 @@ GstMplexJob::GstMplexJob (void) :
*/ */
void void
GstMplexJob::initProperties (GObjectClass *klass) GstMplexJob::initProperties (GObjectClass * klass)
{ {
/* encoding profile */ /* encoding profile */
g_object_class_install_property (klass, ARG_FORMAT, g_object_class_install_property (klass, ARG_FORMAT,
g_param_spec_enum ("format", "Format", "Encoding profile format", g_param_spec_enum ("format", "Format", "Encoding profile format",
GST_TYPE_MPLEX_FORMAT, 0, GST_TYPE_MPLEX_FORMAT, 0, (GParamFlags) G_PARAM_READWRITE));
(GParamFlags) G_PARAM_READWRITE));
/* total stream datarate. Normally, this shouldn't be needed, but /* total stream datarate. Normally, this shouldn't be needed, but
* some DVD/VCD/SVCD players really need strict values to handle * some DVD/VCD/SVCD players really need strict values to handle
* the created files correctly. */ * the created files correctly. */
g_object_class_install_property (klass, ARG_MUX_BITRATE, g_object_class_install_property (klass, ARG_MUX_BITRATE,
g_param_spec_int ("mux-bitrate", "Mux. bitrate", g_param_spec_int ("mux-bitrate", "Mux. bitrate",
"Bitrate of output stream in kbps (0 = autodetect)", "Bitrate of output stream in kbps (0 = autodetect)",
0, 15 * 1024, 0, (GParamFlags) G_PARAM_READWRITE)); 0, 15 * 1024, 0, (GParamFlags) G_PARAM_READWRITE));
#if 0 #if 0
{ "video-buffer", 1, 0, 'b' }, {
"video-buffer", 1, 0, 'b'},
#endif #endif
/* some boolean stuff for headers */
/* some boolean stuff for headers */ g_object_class_install_property (klass, ARG_VBR,
g_object_class_install_property (klass, ARG_VBR, g_param_spec_boolean ("vbr", "VBR",
g_param_spec_boolean ("vbr", "VBR", "Whether the input video stream is variable bitrate",
"Whether the input video stream is variable bitrate", FALSE, (GParamFlags) G_PARAM_READWRITE));
FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_SYSTEM_HEADERS, g_object_class_install_property (klass, ARG_SYSTEM_HEADERS,
g_param_spec_boolean ("system-headers", "System headers", g_param_spec_boolean ("system-headers", "System headers",
"Create system header in every pack for generic formats", "Create system header in every pack for generic formats",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (klass, ARG_SPLIT_SEQUENCE, g_object_class_install_property (klass, ARG_SPLIT_SEQUENCE,
g_param_spec_boolean ("split-sequence", "Split sequence", g_param_spec_boolean ("split-sequence", "Split sequence",
"Simply split a sequence across files " "Simply split a sequence across files "
"(rather than building run-out/run-in)", "(rather than building run-out/run-in)",
FALSE, (GParamFlags) G_PARAM_READWRITE)); FALSE, (GParamFlags) G_PARAM_READWRITE));
/* size of a segment (followed by EOS) */ /* size of a segment (followed by EOS) */
g_object_class_install_property (klass, ARG_SEGMENT_SIZE, g_object_class_install_property (klass, ARG_SEGMENT_SIZE,
g_param_spec_int ("max-segment-size", "Max. segment size", g_param_spec_int ("max-segment-size", "Max. segment size",
"Max. size per segment/file in MB (0 = unlimited)", "Max. size per segment/file in MB (0 = unlimited)",
0, 10 * 1024, 0, (GParamFlags) G_PARAM_READWRITE)); 0, 10 * 1024, 0, (GParamFlags) G_PARAM_READWRITE));
/* packets per pack (generic formats) */ /* packets per pack (generic formats) */
g_object_class_install_property (klass, ARG_PACKETS_PER_PACK, g_object_class_install_property (klass, ARG_PACKETS_PER_PACK,
g_param_spec_int ("packets-per-pack", "Packets per pack", g_param_spec_int ("packets-per-pack", "Packets per pack",
"Number of packets per pack for generic formats", "Number of packets per pack for generic formats",
1, 100, 1, (GParamFlags) G_PARAM_READWRITE)); 1, 100, 1, (GParamFlags) G_PARAM_READWRITE));
/* size of one sector */ /* size of one sector */
g_object_class_install_property (klass, ARG_SECTOR_SIZE, g_object_class_install_property (klass, ARG_SECTOR_SIZE,
g_param_spec_int ("sector-size", "Sector size", g_param_spec_int ("sector-size", "Sector size",
"Specify sector size in bytes for generic formats", "Specify sector size in bytes for generic formats",
256, 16384, 2048, (GParamFlags) G_PARAM_READWRITE)); 256, 16384, 2048, (GParamFlags) G_PARAM_READWRITE));
} }
/* /*
@ -148,8 +147,7 @@ GstMplexJob::initProperties (GObjectClass *klass)
*/ */
void void
GstMplexJob::getProperty (guint prop_id, GstMplexJob::getProperty (guint prop_id, GValue * value)
GValue *value)
{ {
switch (prop_id) { switch (prop_id) {
case ARG_FORMAT: case ARG_FORMAT:
@ -182,8 +180,7 @@ GstMplexJob::getProperty (guint prop_id,
} }
void void
GstMplexJob::setProperty (guint prop_id, GstMplexJob::setProperty (guint prop_id, const GValue * value)
const GValue *value)
{ {
switch (prop_id) { switch (prop_id) {
case ARG_FORMAT: case ARG_FORMAT:
@ -193,7 +190,7 @@ GstMplexJob::setProperty (guint prop_id,
/* data_rate expects bytes (don't ask me why the property itself is /* data_rate expects bytes (don't ask me why the property itself is
* in bits, I'm just staying compatible to mjpegtools options), and * in bits, I'm just staying compatible to mjpegtools options), and
* rounded up to 50-bytes. */ * rounded up to 50-bytes. */
data_rate = ((g_value_get_int (value) * 1000 / 8 + 49) / 50 ) * 50; data_rate = ((g_value_get_int (value) * 1000 / 8 + 49) / 50) * 50;
break; break;
case ARG_VBR: case ARG_VBR:
VBR = g_value_get_boolean (value); VBR = g_value_get_boolean (value);

View file

@ -31,9 +31,8 @@
* Class init functions. * Class init functions.
*/ */
GstMplexOutputStream::GstMplexOutputStream (GstElement *_element, GstMplexOutputStream::GstMplexOutputStream (GstElement * _element, GstPad * _pad):
GstPad *_pad) : OutputStream ()
OutputStream ()
{ {
element = _element; element = _element;
pad = _pad; pad = _pad;
@ -63,8 +62,7 @@ GstMplexOutputStream::Close (void)
* Get size of current segment. * Get size of current segment.
*/ */
off_t off_t GstMplexOutputStream::SegmentSize (void)
GstMplexOutputStream::SegmentSize (void)
{ {
return size; return size;
} }
@ -88,8 +86,7 @@ GstMplexOutputStream::NextSegment (void)
*/ */
void void
GstMplexOutputStream::Write (guint8 *data, GstMplexOutputStream::Write (guint8 * data, guint len)
guint len)
{ {
GstBuffer *buf; GstBuffer *buf;

View file

@ -16,7 +16,7 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
/* /*
Code based on modplugxmms Code based on modplugxmms
XMMS plugin: XMMS plugin:
@ -48,12 +48,14 @@ GstElementDetails modplug_details = {
/* Filter signals and args */ /* Filter signals and args */
enum { enum
{
/* FILL ME */ /* FILL ME */
LAST_SIGNAL LAST_SIGNAL
}; };
enum { enum
{
ARG_0, ARG_0,
ARG_SONGNAME, ARG_SONGNAME,
ARG_REVERB, ARG_REVERB,
@ -70,163 +72,144 @@ enum {
}; };
static GstStaticPadTemplate modplug_src_template_factory = static GstStaticPadTemplate modplug_src_template_factory =
GST_STATIC_PAD_TEMPLATE ( GST_STATIC_PAD_TEMPLATE ("src",
"src", GST_PAD_SRC,
GST_PAD_SRC, GST_PAD_ALWAYS,
GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-raw-int, " "endianness = (int) BYTE_ORDER, " "signed = (boolean) TRUE, " "width = (int) 16, " "depth = (int) 16, " "rate = (int) { 8000, 11025, 22050, 44100 }, " /* FIXME? */
GST_STATIC_CAPS ( "channels = (int) [ 1, 2 ]; " "audio/x-raw-int, " "signed = (boolean) FALSE, " "width = (int) 8, " "depth = (int) 8, " "rate = (int) { 8000, 11025, 22050, 44100 }, " /* FIXME? */
"audio/x-raw-int, " "channels = (int) [ 1, 2 ]")
"endianness = (int) BYTE_ORDER, " );
"signed = (boolean) TRUE, "
"width = (int) 16, "
"depth = (int) 16, "
"rate = (int) { 8000, 11025, 22050, 44100 }, " /* FIXME? */
"channels = (int) [ 1, 2 ]; "
"audio/x-raw-int, "
"signed = (boolean) FALSE, "
"width = (int) 8, "
"depth = (int) 8, "
"rate = (int) { 8000, 11025, 22050, 44100 }, " /* FIXME? */
"channels = (int) [ 1, 2 ]"
)
);
static GstStaticPadTemplate modplug_sink_template_factory = static GstStaticPadTemplate modplug_sink_template_factory =
GST_STATIC_PAD_TEMPLATE ( GST_STATIC_PAD_TEMPLATE ("sink",
"sink", GST_PAD_SINK,
GST_PAD_SINK, GST_PAD_ALWAYS,
GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-mod")
GST_STATIC_CAPS ("audio/x-mod") );
);
enum { enum
{
MODPLUG_STATE_NEED_TUNE = 1, MODPLUG_STATE_NEED_TUNE = 1,
MODPLUG_STATE_LOAD_TUNE = 2, MODPLUG_STATE_LOAD_TUNE = 2,
MODPLUG_STATE_PLAY_TUNE = 3, MODPLUG_STATE_PLAY_TUNE = 3,
}; };
static void gst_modplug_base_init (GstModPlugClass *klass); static void gst_modplug_base_init (GstModPlugClass * klass);
static void gst_modplug_class_init (GstModPlugClass *klass); static void gst_modplug_class_init (GstModPlugClass * klass);
static void gst_modplug_init (GstModPlug *filter); static void gst_modplug_init (GstModPlug * filter);
static void gst_modplug_set_property (GObject *object, static void gst_modplug_set_property (GObject * object,
guint id, guint id, const GValue * value, GParamSpec * pspec);
const GValue *value, static void gst_modplug_get_property (GObject * object,
GParamSpec *pspec ); guint id, GValue * value, GParamSpec * pspec);
static void gst_modplug_get_property (GObject *object,
guint id,
GValue *value,
GParamSpec *pspec );
static GstPadLinkReturn static GstPadLinkReturn
gst_modplug_srclink (GstPad *pad, const GstCaps *caps); gst_modplug_srclink (GstPad * pad, const GstCaps * caps);
static GstCaps *gst_modplug_fixate (GstPad *pad, const GstCaps *caps); static GstCaps *gst_modplug_fixate (GstPad * pad, const GstCaps * caps);
static void gst_modplug_loop (GstElement *element); static void gst_modplug_loop (GstElement * element);
static void gst_modplug_setup (GstModPlug *modplug); static void gst_modplug_setup (GstModPlug * modplug);
static const GstFormat * static const GstFormat *gst_modplug_get_formats (GstPad * pad);
gst_modplug_get_formats (GstPad *pad); static const GstQueryType *gst_modplug_get_query_types (GstPad * pad);
static const GstQueryType * static gboolean gst_modplug_src_event (GstPad * pad, GstEvent * event);
gst_modplug_get_query_types (GstPad *pad); static gboolean gst_modplug_src_query (GstPad * pad,
static gboolean gst_modplug_src_event (GstPad *pad, GstEvent *event); GstQueryType type, GstFormat * format, gint64 * value);
static gboolean gst_modplug_src_query (GstPad *pad, static GstElementStateReturn gst_modplug_change_state (GstElement * element);
GstQueryType type,
GstFormat *format,
gint64 *value);
static GstElementStateReturn
gst_modplug_change_state (GstElement *element);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
GType GType
gst_modplug_get_type(void) { gst_modplug_get_type (void)
{
static GType modplug_type = 0; static GType modplug_type = 0;
if (!modplug_type) { if (!modplug_type) {
static const GTypeInfo modplug_info = { static const GTypeInfo modplug_info = {
sizeof(GstModPlugClass), sizeof (GstModPlugClass),
(GBaseInitFunc)gst_modplug_base_init, (GBaseInitFunc) gst_modplug_base_init,
NULL, NULL,
(GClassInitFunc)gst_modplug_class_init, (GClassInitFunc) gst_modplug_class_init,
NULL, NULL,
NULL, NULL,
sizeof(GstModPlug), sizeof (GstModPlug),
0, 0,
(GInstanceInitFunc)gst_modplug_init, (GInstanceInitFunc) gst_modplug_init,
NULL NULL
}; };
modplug_type = g_type_register_static(GST_TYPE_ELEMENT, "GstModPlug", &modplug_info, (GTypeFlags)0); modplug_type =
g_type_register_static (GST_TYPE_ELEMENT, "GstModPlug", &modplug_info,
(GTypeFlags) 0);
} }
return modplug_type; return modplug_type;
} }
static void static void
gst_modplug_base_init (GstModPlugClass *klass) gst_modplug_base_init (GstModPlugClass * klass)
{ {
GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&modplug_sink_template_factory)); gst_static_pad_template_get (&modplug_sink_template_factory));
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&modplug_src_template_factory)); gst_static_pad_template_get (&modplug_src_template_factory));
gst_element_class_set_details (element_class, &modplug_details); gst_element_class_set_details (element_class, &modplug_details);
} }
static void static void
gst_modplug_class_init (GstModPlugClass *klass) gst_modplug_class_init (GstModPlugClass * klass)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
gobject_class = (GObjectClass*)klass; gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass*)klass; gstelement_class = (GstElementClass *) klass;
parent_class = GST_ELEMENT_CLASS( g_type_class_ref(GST_TYPE_ELEMENT)); parent_class = GST_ELEMENT_CLASS (g_type_class_ref (GST_TYPE_ELEMENT));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SONGNAME, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SONGNAME,
g_param_spec_string("songname","Songname","The song name", g_param_spec_string ("songname", "Songname", "The song name",
"", G_PARAM_READABLE)); "", G_PARAM_READABLE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_REVERB, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB,
g_param_spec_boolean("reverb", "reverb", "reverb", g_param_spec_boolean ("reverb", "reverb", "reverb",
FALSE, (GParamFlags)G_PARAM_READWRITE )); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_REVERB_DEPTH, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB_DEPTH,
g_param_spec_int("reverb_depth", "reverb_depth", "reverb_depth", g_param_spec_int ("reverb_depth", "reverb_depth", "reverb_depth",
0, 100, 30, (GParamFlags)G_PARAM_READWRITE )); 0, 100, 30, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_REVERB_DELAY, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB_DELAY,
g_param_spec_int("reverb_delay", "reverb_delay", "reverb_delay", g_param_spec_int ("reverb_delay", "reverb_delay", "reverb_delay",
0, 200, 100, (GParamFlags)G_PARAM_READWRITE )); 0, 200, 100, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MEGABASS, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS,
g_param_spec_boolean("megabass", "megabass", "megabass", g_param_spec_boolean ("megabass", "megabass", "megabass",
FALSE, (GParamFlags)G_PARAM_READWRITE )); FALSE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MEGABASS_AMOUNT, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS_AMOUNT,
g_param_spec_int("megabass_amount", "megabass_amount", "megabass_amount", g_param_spec_int ("megabass_amount", "megabass_amount", "megabass_amount",
0, 100, 40, (GParamFlags)G_PARAM_READWRITE )); 0, 100, 40, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MEGABASS_RANGE,
g_param_spec_int("megabass_range", "megabass_range", "megabass_range",
0, 100, 30, (GParamFlags)G_PARAM_READWRITE ));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SURROUND, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MEGABASS_RANGE,
g_param_spec_boolean("surround", "surround", "surround", g_param_spec_int ("megabass_range", "megabass_range", "megabass_range",
TRUE, (GParamFlags)G_PARAM_READWRITE )); 0, 100, 30, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SURROUND_DEPTH, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND,
g_param_spec_int("surround_depth", "surround_depth", "surround_depth", g_param_spec_boolean ("surround", "surround", "surround",
0, 100, 20, (GParamFlags)G_PARAM_READWRITE )); TRUE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SURROUND_DELAY, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND_DEPTH,
g_param_spec_int("surround_delay", "surround_delay", "surround_delay", g_param_spec_int ("surround_depth", "surround_depth", "surround_depth",
0, 40, 20, (GParamFlags)G_PARAM_READWRITE )); 0, 100, 20, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_OVERSAMP, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND_DELAY,
g_param_spec_boolean("oversamp", "oversamp", "oversamp", g_param_spec_int ("surround_delay", "surround_delay", "surround_delay",
TRUE, (GParamFlags)G_PARAM_READWRITE )); 0, 40, 20, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NOISE_REDUCTION, g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_OVERSAMP,
g_param_spec_boolean("noise_reduction", "noise_reduction", "noise_reduction", g_param_spec_boolean ("oversamp", "oversamp", "oversamp",
TRUE, (GParamFlags)G_PARAM_READWRITE )); TRUE, (GParamFlags) G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NOISE_REDUCTION,
g_param_spec_boolean ("noise_reduction", "noise_reduction",
"noise_reduction", TRUE, (GParamFlags) G_PARAM_READWRITE));
gobject_class->set_property = gst_modplug_set_property; gobject_class->set_property = gst_modplug_set_property;
gobject_class->get_property = gst_modplug_get_property; gobject_class->get_property = gst_modplug_get_property;
@ -235,100 +218,114 @@ gst_modplug_class_init (GstModPlugClass *klass)
} }
static void static void
gst_modplug_init (GstModPlug *modplug) gst_modplug_init (GstModPlug * modplug)
{ {
modplug->sinkpad = gst_pad_new_from_template (gst_static_pad_template_get (&modplug_sink_template_factory), "sink"); modplug->sinkpad =
gst_element_add_pad (GST_ELEMENT(modplug), modplug->sinkpad); gst_pad_new_from_template (gst_static_pad_template_get
(&modplug_sink_template_factory), "sink");
gst_element_add_pad (GST_ELEMENT (modplug), modplug->sinkpad);
modplug->srcpad = gst_pad_new_from_template (gst_static_pad_template_get (&modplug_src_template_factory), "src"); modplug->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get
(&modplug_src_template_factory), "src");
gst_pad_set_link_function (modplug->srcpad, gst_modplug_srclink); gst_pad_set_link_function (modplug->srcpad, gst_modplug_srclink);
gst_pad_set_fixate_function (modplug->srcpad, gst_modplug_fixate); gst_pad_set_fixate_function (modplug->srcpad, gst_modplug_fixate);
gst_pad_set_event_function (modplug->srcpad, (GstPadEventFunction)GST_DEBUG_FUNCPTR(gst_modplug_src_event)); gst_pad_set_event_function (modplug->srcpad,
(GstPadEventFunction) GST_DEBUG_FUNCPTR (gst_modplug_src_event));
gst_pad_set_query_function (modplug->srcpad, gst_modplug_src_query); gst_pad_set_query_function (modplug->srcpad, gst_modplug_src_query);
gst_pad_set_query_type_function (modplug->srcpad, (GstPadQueryTypeFunction) GST_DEBUG_FUNCPTR (gst_modplug_get_query_types)); gst_pad_set_query_type_function (modplug->srcpad,
gst_pad_set_formats_function (modplug->srcpad, (GstPadFormatsFunction)GST_DEBUG_FUNCPTR (gst_modplug_get_formats)); (GstPadQueryTypeFunction)
gst_element_add_pad (GST_ELEMENT(modplug), modplug->srcpad); GST_DEBUG_FUNCPTR (gst_modplug_get_query_types));
gst_pad_set_formats_function (modplug->srcpad,
gst_element_set_loop_function (GST_ELEMENT (modplug), gst_modplug_loop); (GstPadFormatsFunction) GST_DEBUG_FUNCPTR (gst_modplug_get_formats));
gst_element_add_pad (GST_ELEMENT (modplug), modplug->srcpad);
modplug->reverb = FALSE;
modplug->reverb_depth = 30; gst_element_set_loop_function (GST_ELEMENT (modplug), gst_modplug_loop);
modplug->reverb_delay = 100;
modplug->megabass = FALSE; modplug->reverb = FALSE;
modplug->reverb_depth = 30;
modplug->reverb_delay = 100;
modplug->megabass = FALSE;
modplug->megabass_amount = 40; modplug->megabass_amount = 40;
modplug->megabass_range = 30; modplug->megabass_range = 30;
modplug->surround = TRUE; modplug->surround = TRUE;
modplug->surround_depth = 20; modplug->surround_depth = 20;
modplug->surround_delay = 20; modplug->surround_delay = 20;
modplug->oversamp = TRUE; modplug->oversamp = TRUE;
modplug->noise_reduction = TRUE; modplug->noise_reduction = TRUE;
modplug->_16bit = TRUE; modplug->_16bit = TRUE;
modplug->channel = 2; modplug->channel = 2;
modplug->frequency = 44100; modplug->frequency = 44100;
modplug->audiobuffer = NULL; modplug->audiobuffer = NULL;
modplug->buffer_in = NULL; modplug->buffer_in = NULL;
modplug->state = MODPLUG_STATE_NEED_TUNE; modplug->state = MODPLUG_STATE_NEED_TUNE;
GST_FLAG_SET (modplug, GST_ELEMENT_EVENT_AWARE); GST_FLAG_SET (modplug, GST_ELEMENT_EVENT_AWARE);
} }
static void static void
gst_modplug_setup (GstModPlug *modplug) gst_modplug_setup (GstModPlug * modplug)
{ {
if (modplug->_16bit) if (modplug->_16bit)
modplug->mSoundFile->SetWaveConfig (modplug->frequency, 16, modplug->channel); modplug->mSoundFile->SetWaveConfig (modplug->frequency, 16,
modplug->channel);
else else
modplug->mSoundFile->SetWaveConfig (modplug->frequency, 8, modplug->channel); modplug->mSoundFile->SetWaveConfig (modplug->frequency, 8,
modplug->channel);
modplug->mSoundFile->SetWaveConfigEx (modplug->surround, !modplug->oversamp, modplug->reverb, true, modplug->megabass, modplug->noise_reduction, true);
modplug->mSoundFile->SetWaveConfigEx (modplug->surround, !modplug->oversamp,
modplug->reverb, true, modplug->megabass, modplug->noise_reduction, true);
modplug->mSoundFile->SetResamplingMode (SRCMODE_POLYPHASE); modplug->mSoundFile->SetResamplingMode (SRCMODE_POLYPHASE);
if (modplug->surround) if (modplug->surround)
modplug->mSoundFile->SetSurroundParameters (modplug->surround_depth, modplug->surround_delay); modplug->mSoundFile->SetSurroundParameters (modplug->surround_depth,
modplug->surround_delay);
if (modplug->megabass) if (modplug->megabass)
modplug->mSoundFile->SetXBassParameters (modplug->megabass_amount, modplug->megabass_range); modplug->mSoundFile->SetXBassParameters (modplug->megabass_amount,
modplug->megabass_range);
if (modplug->reverb) if (modplug->reverb)
modplug->mSoundFile->SetReverbParameters (modplug->reverb_depth, modplug->reverb_delay); modplug->mSoundFile->SetReverbParameters (modplug->reverb_depth,
modplug->reverb_delay);
} }
static const GstFormat* static const GstFormat *
gst_modplug_get_formats (GstPad *pad) gst_modplug_get_formats (GstPad * pad)
{ {
static const GstFormat src_formats[] = { static const GstFormat src_formats[] = {
/* GST_FORMAT_BYTES, /* GST_FORMAT_BYTES,
GST_FORMAT_DEFAULT,*/ GST_FORMAT_DEFAULT,*/
GST_FORMAT_TIME, GST_FORMAT_TIME,
(GstFormat)0 (GstFormat) 0
}; };
static const GstFormat sink_formats[] = { static const GstFormat sink_formats[] = {
/*GST_FORMAT_BYTES,*/ /*GST_FORMAT_BYTES, */
GST_FORMAT_TIME, GST_FORMAT_TIME,
(GstFormat)0 (GstFormat) 0
}; };
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats); return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
} }
static const GstQueryType* static const GstQueryType *
gst_modplug_get_query_types (GstPad *pad) gst_modplug_get_query_types (GstPad * pad)
{ {
static const GstQueryType gst_modplug_src_query_types[] = { static const GstQueryType gst_modplug_src_query_types[] = {
GST_QUERY_TOTAL, GST_QUERY_TOTAL,
GST_QUERY_POSITION, GST_QUERY_POSITION,
(GstQueryType)0 (GstQueryType) 0
}; };
return gst_modplug_src_query_types; return gst_modplug_src_query_types;
} }
static gboolean static gboolean
gst_modplug_src_query (GstPad *pad, GstQueryType type, gst_modplug_src_query (GstPad * pad, GstQueryType type,
GstFormat *format, gint64 *value) GstFormat * format, gint64 * value)
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstModPlug *modplug; GstModPlug *modplug;
@ -339,39 +336,42 @@ gst_modplug_src_query (GstPad *pad, GstQueryType type,
switch (type) { switch (type) {
case GST_QUERY_TOTAL: case GST_QUERY_TOTAL:
switch (*format) { switch (*format) {
case GST_FORMAT_TIME: case GST_FORMAT_TIME:
*value=(gint64)modplug->mSoundFile->GetSongTime() * GST_SECOND; *value = (gint64) modplug->mSoundFile->GetSongTime () * GST_SECOND;
break; break;
default: default:
res = FALSE; res = FALSE;
break; break;
} }
break; break;
case GST_QUERY_POSITION: case GST_QUERY_POSITION:
switch (*format) { switch (*format) {
default: default:
tmp = ((float)( modplug->mSoundFile->GetSongTime() * modplug->mSoundFile->GetCurrentPos() ) / (float)modplug->mSoundFile->GetMaxPosition() ); tmp =
*value=(gint64)(tmp * GST_SECOND); ((float) (modplug->mSoundFile->GetSongTime () *
break; modplug->mSoundFile->GetCurrentPos ()) /
(float) modplug->mSoundFile->GetMaxPosition ());
*value = (gint64) (tmp * GST_SECOND);
break;
} }
default: default:
break; break;
} }
return res; return res;
} }
static gboolean static gboolean
gst_modplug_src_event (GstPad *pad, GstEvent *event) gst_modplug_src_event (GstPad * pad, GstEvent * event)
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstModPlug *modplug; GstModPlug *modplug;
modplug = GST_MODPLUG (gst_pad_get_parent (pad)); modplug = GST_MODPLUG (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) { switch (GST_EVENT_TYPE (event)) {
/* the all-formats seek logic */ /* the all-formats seek logic */
case GST_EVENT_SEEK: case GST_EVENT_SEEK:
{ {
gboolean flush; gboolean flush;
@ -389,63 +389,64 @@ gst_modplug_src_event (GstPad *pad, GstEvent *event)
res = FALSE; res = FALSE;
break; break;
} }
gst_event_unref (event); gst_event_unref (event);
return res; return res;
} }
#if 0 #if 0
static GstCaps* static GstCaps *
gst_modplug_get_streaminfo (GstModPlug *modplug) gst_modplug_get_streaminfo (GstModPlug * modplug)
{ {
GstCaps *caps; GstCaps *caps;
props = gst_props_empty_new (); props = gst_props_empty_new ();
entry = gst_props_entry_new ("Patterns", G_TYPE_INT ((gint)modplug->mSoundFile->GetNumPatterns())); entry =
gst_props_entry_new ("Patterns",
G_TYPE_INT ((gint) modplug->mSoundFile->GetNumPatterns ()));
gst_props_add_entry (props, (GstPropsEntry *) entry); gst_props_add_entry (props, (GstPropsEntry *) entry);
caps = gst_caps_new_simple ("application/x-gst-streaminfo", NULL); caps = gst_caps_new_simple ("application/x-gst-streaminfo", NULL);
return caps; return caps;
} }
static void static void
gst_modplug_update_info (GstModPlug *modplug) gst_modplug_update_info (GstModPlug * modplug)
{ {
if (modplug->streaminfo) { if (modplug->streaminfo) {
gst_caps_unref (modplug->streaminfo); gst_caps_unref (modplug->streaminfo);
} }
modplug->streaminfo = gst_modplug_get_streaminfo (modplug); modplug->streaminfo = gst_modplug_get_streaminfo (modplug);
g_object_notify (G_OBJECT (modplug), "streaminfo"); g_object_notify (G_OBJECT (modplug), "streaminfo");
} }
static void static void
gst_modplug_update_metadata (GstModPlug *modplug) gst_modplug_update_metadata (GstModPlug * modplug)
{ {
GstProps *props; GstProps *props;
GstPropsEntry *entry; GstPropsEntry *entry;
const gchar *title; const gchar *title;
props = gst_props_empty_new (); props = gst_props_empty_new ();
title = modplug->mSoundFile->GetTitle(); title = modplug->mSoundFile->GetTitle ();
entry = gst_props_entry_new ("Title", G_TYPE_STRING (title)); entry = gst_props_entry_new ("Title", G_TYPE_STRING (title));
gst_props_add_entry (props, entry); gst_props_add_entry (props, entry);
modplug->metadata = gst_caps_new_simple ("application/x-gst-metadata", modplug->metadata = gst_caps_new_simple ("application/x-gst-metadata", NULL);
NULL);
g_object_notify (G_OBJECT (modplug), "metadata"); g_object_notify (G_OBJECT (modplug), "metadata");
} }
#endif #endif
static GstPadLinkReturn static GstPadLinkReturn
gst_modplug_srclink (GstPad *pad, const GstCaps *caps) gst_modplug_srclink (GstPad * pad, const GstCaps * caps)
{ {
GstModPlug *modplug; GstModPlug *modplug;
GstStructure *structure; GstStructure *structure;
gint depth; gint depth;
@ -465,25 +466,25 @@ gst_modplug_srclink (GstPad *pad, const GstCaps *caps)
} }
static GstCaps * static GstCaps *
gst_modplug_fixate (GstPad *pad, const GstCaps *caps) gst_modplug_fixate (GstPad * pad, const GstCaps * caps)
{ {
if (gst_caps_is_simple (caps)) { if (gst_caps_is_simple (caps)) {
GstCaps *copy; GstCaps *copy;
GstStructure *structure; GstStructure *structure;
copy = gst_caps_copy (caps); copy = gst_caps_copy (caps);
structure = gst_caps_get_structure (copy, 0); structure = gst_caps_get_structure (copy, 0);
if (gst_caps_structure_fixate_field_nearest_int (structure, "rate", 44100)) if (gst_caps_structure_fixate_field_nearest_int (structure, "rate", 44100))
return copy; return copy;
if (gst_caps_structure_fixate_field_nearest_int (structure, "channels", 2)) if (gst_caps_structure_fixate_field_nearest_int (structure, "channels", 2))
return copy; return copy;
gst_caps_free (copy); gst_caps_free (copy);
} }
return NULL; return NULL;
} }
static void static void
gst_modplug_handle_event (GstModPlug *modplug) gst_modplug_handle_event (GstModPlug * modplug)
{ {
gint64 value; gint64 value;
guint32 remaining; guint32 remaining;
@ -515,20 +516,19 @@ gst_modplug_handle_event (GstModPlug *modplug)
} }
static void static void
gst_modplug_loop (GstElement *element) gst_modplug_loop (GstElement * element)
{ {
GstModPlug *modplug; GstModPlug *modplug;
GstEvent *event; GstEvent *event;
g_return_if_fail (element != NULL); g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_MODPLUG (element)); g_return_if_fail (GST_IS_MODPLUG (element));
modplug = GST_MODPLUG (element); modplug = GST_MODPLUG (element);
if (modplug->state == MODPLUG_STATE_NEED_TUNE) if (modplug->state == MODPLUG_STATE_NEED_TUNE) {
{
/* GstBuffer *buf;*/ /* GstBuffer *buf;*/
modplug->seek_at = -1; modplug->seek_at = -1;
modplug->need_discont = TRUE; modplug->need_discont = TRUE;
modplug->eos = FALSE; modplug->eos = FALSE;
@ -562,116 +562,114 @@ gst_modplug_loop (GstElement *element)
} }
*/ */
if (modplug->bs) if (modplug->bs) {
{
guint64 got; guint64 got;
modplug->song_size = gst_bytestream_length (modplug->bs); modplug->song_size = gst_bytestream_length (modplug->bs);
got = gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in, modplug->song_size); got =
gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in,
modplug->song_size);
if ( got < modplug->song_size ) if (got < modplug->song_size) {
{ gst_modplug_handle_event (modplug);
gst_modplug_handle_event (modplug); return;
return;
} }
modplug->state = MODPLUG_STATE_LOAD_TUNE; modplug->state = MODPLUG_STATE_LOAD_TUNE;
} }
} }
if (modplug->state == MODPLUG_STATE_LOAD_TUNE) if (modplug->state == MODPLUG_STATE_LOAD_TUNE) {
{
modplug->mSoundFile = new CSoundFile; modplug->mSoundFile = new CSoundFile;
if (!GST_PAD_CAPS (modplug->srcpad) && if (!GST_PAD_CAPS (modplug->srcpad) &&
GST_PAD_LINK_FAILED (gst_pad_renegotiate (modplug->srcpad))) { GST_PAD_LINK_FAILED (gst_pad_renegotiate (modplug->srcpad))) {
GST_ELEMENT_ERROR (modplug, CORE, NEGOTIATION, (NULL), (NULL)); GST_ELEMENT_ERROR (modplug, CORE, NEGOTIATION, (NULL), (NULL));
return; return;
} }
modplug->mSoundFile->Create (modplug->buffer_in, modplug->song_size); modplug->mSoundFile->Create (modplug->buffer_in, modplug->song_size);
modplug->opened = TRUE; modplug->opened = TRUE;
gst_bytestream_flush (modplug->bs, modplug->song_size); gst_bytestream_flush (modplug->bs, modplug->song_size);
modplug->buffer_in = NULL; modplug->buffer_in = NULL;
modplug->audiobuffer = (guchar *) g_malloc (modplug->length); modplug->audiobuffer = (guchar *) g_malloc (modplug->length);
//gst_modplug_update_metadata (modplug); //gst_modplug_update_metadata (modplug);
//gst_modplug_update_info (modplug); //gst_modplug_update_info (modplug);
modplug->state = MODPLUG_STATE_PLAY_TUNE; modplug->state = MODPLUG_STATE_PLAY_TUNE;
} }
if (modplug->state == MODPLUG_STATE_PLAY_TUNE && !modplug->eos) if (modplug->state == MODPLUG_STATE_PLAY_TUNE && !modplug->eos) {
{ if (modplug->seek_at != -1) {
if (modplug->seek_at != -1)
{
gint seek_to_pos; gint seek_to_pos;
gint64 total; gint64 total;
gfloat temp; gfloat temp;
total = modplug->mSoundFile->GetSongTime () * GST_SECOND; total = modplug->mSoundFile->GetSongTime () * GST_SECOND;
temp = (gfloat) total / modplug->seek_at; temp = (gfloat) total / modplug->seek_at;
seek_to_pos = (int) (modplug->mSoundFile->GetMaxPosition () / temp); seek_to_pos = (int) (modplug->mSoundFile->GetMaxPosition () / temp);
modplug->mSoundFile->SetCurrentPos (seek_to_pos); modplug->mSoundFile->SetCurrentPos (seek_to_pos);
modplug->need_discont = TRUE; modplug->need_discont = TRUE;
modplug->seek_at = -1; modplug->seek_at = -1;
} }
if (modplug->need_discont && GST_PAD_IS_USABLE (modplug->srcpad)) if (modplug->need_discont && GST_PAD_IS_USABLE (modplug->srcpad)) {
{
GstEvent *discont; GstEvent *discont;
gint64 value; gint64 value;
GstFormat format = GST_FORMAT_TIME; GstFormat format = GST_FORMAT_TIME;
if (gst_modplug_src_query (modplug->srcpad, GST_QUERY_POSITION, &format, &value)) { if (gst_modplug_src_query (modplug->srcpad, GST_QUERY_POSITION, &format,
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, value, GST_FORMAT_UNDEFINED); &value)) {
discont =
gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, value,
GST_FORMAT_UNDEFINED);
modplug->timestamp = value; modplug->timestamp = value;
} else { } else {
modplug->timestamp = GST_CLOCK_TIME_NONE; modplug->timestamp = GST_CLOCK_TIME_NONE;
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_UNDEFINED); discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_UNDEFINED);
} }
gst_pad_push (modplug->srcpad, GST_DATA (discont)); gst_pad_push (modplug->srcpad, GST_DATA (discont));
modplug->need_discont= FALSE; modplug->need_discont = FALSE;
} }
if (modplug->mSoundFile->Read (modplug->audiobuffer, modplug->length) != 0) if (modplug->mSoundFile->Read (modplug->audiobuffer, modplug->length) != 0) {
{
GstBuffer *buffer_out; GstBuffer *buffer_out;
buffer_out = gst_buffer_new (); buffer_out = gst_buffer_new ();
GST_BUFFER_DATA (buffer_out) = (guchar *) g_memdup (modplug->audiobuffer, modplug->length); GST_BUFFER_DATA (buffer_out) =
(guchar *) g_memdup (modplug->audiobuffer, modplug->length);
GST_BUFFER_SIZE (buffer_out) = modplug->length; GST_BUFFER_SIZE (buffer_out) = modplug->length;
GST_BUFFER_TIMESTAMP (buffer_out) = modplug->timestamp; GST_BUFFER_TIMESTAMP (buffer_out) = modplug->timestamp;
if (GST_CLOCK_TIME_IS_VALID (modplug->timestamp)) { if (GST_CLOCK_TIME_IS_VALID (modplug->timestamp)) {
GST_BUFFER_DURATION (buffer_out) = modplug->length * GST_SECOND / modplug->frequency / modplug->channel / (modplug->_16bit ? 2 : 1) ; GST_BUFFER_DURATION (buffer_out) =
modplug->length * GST_SECOND / modplug->frequency /
modplug->channel / (modplug->_16bit ? 2 : 1);
modplug->timestamp += GST_BUFFER_DURATION (buffer_out); modplug->timestamp += GST_BUFFER_DURATION (buffer_out);
} }
if (GST_PAD_IS_USABLE (modplug->srcpad)) if (GST_PAD_IS_USABLE (modplug->srcpad))
gst_pad_push (modplug->srcpad, GST_DATA (buffer_out)); gst_pad_push (modplug->srcpad, GST_DATA (buffer_out));
} else if (GST_PAD_IS_LINKED (modplug->srcpad)) {
/* FIXME, hack, pull final EOS from peer */
gst_bytestream_flush (modplug->bs, 1);
event = gst_event_new (GST_EVENT_EOS);
gst_pad_push (modplug->srcpad, GST_DATA (event));
gst_element_set_eos (element);
modplug->eos = TRUE;
} }
else
if (GST_PAD_IS_LINKED (modplug->srcpad))
{
/* FIXME, hack, pull final EOS from peer */
gst_bytestream_flush (modplug->bs, 1);
event = gst_event_new (GST_EVENT_EOS);
gst_pad_push (modplug->srcpad, GST_DATA (event));
gst_element_set_eos (element);
modplug->eos = TRUE;
}
} }
} }
static GstElementStateReturn static GstElementStateReturn
gst_modplug_change_state (GstElement *element) gst_modplug_change_state (GstElement * element)
{ {
GstModPlug *modplug; GstModPlug *modplug;
@ -680,7 +678,7 @@ gst_modplug_change_state (GstElement *element)
switch (GST_STATE_TRANSITION (element)) { switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_NULL_TO_READY: case GST_STATE_NULL_TO_READY:
break; break;
case GST_STATE_READY_TO_PAUSED: case GST_STATE_READY_TO_PAUSED:
modplug->bs = gst_bytestream_new (modplug->sinkpad); modplug->bs = gst_bytestream_new (modplug->sinkpad);
modplug->song_size = 0; modplug->song_size = 0;
modplug->state = MODPLUG_STATE_NEED_TUNE; modplug->state = MODPLUG_STATE_NEED_TUNE;
@ -689,20 +687,20 @@ gst_modplug_change_state (GstElement *element)
break; break;
case GST_STATE_PLAYING_TO_PAUSED: case GST_STATE_PLAYING_TO_PAUSED:
break; break;
case GST_STATE_PAUSED_TO_READY: case GST_STATE_PAUSED_TO_READY:
gst_bytestream_destroy (modplug->bs); gst_bytestream_destroy (modplug->bs);
modplug->bs = NULL; modplug->bs = NULL;
if (modplug->opened) if (modplug->opened) {
{ modplug->mSoundFile->Destroy ();
modplug->mSoundFile->Destroy (); modplug->opened = FALSE;
modplug->opened = FALSE;
} }
if (modplug->audiobuffer) g_free (modplug->audiobuffer); if (modplug->audiobuffer)
g_free (modplug->audiobuffer);
modplug->buffer_in = NULL; modplug->buffer_in = NULL;
modplug->audiobuffer = NULL; modplug->audiobuffer = NULL;
modplug->state = MODPLUG_STATE_NEED_TUNE; modplug->state = MODPLUG_STATE_NEED_TUNE;
break; break;
case GST_STATE_READY_TO_NULL: case GST_STATE_READY_TO_NULL:
break; break;
default: default:
break; break;
@ -710,18 +708,19 @@ gst_modplug_change_state (GstElement *element)
if (GST_ELEMENT_CLASS (parent_class)->change_state) if (GST_ELEMENT_CLASS (parent_class)->change_state)
return GST_ELEMENT_CLASS (parent_class)->change_state (element); return GST_ELEMENT_CLASS (parent_class)->change_state (element);
return GST_STATE_SUCCESS; return GST_STATE_SUCCESS;
} }
static void static void
gst_modplug_set_property (GObject *object, guint id, const GValue *value, GParamSpec *pspec ) gst_modplug_set_property (GObject * object, guint id, const GValue * value,
GParamSpec * pspec)
{ {
GstModPlug *modplug; GstModPlug *modplug;
/* it's not null if we got it, but it might not be ours */ /* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MODPLUG(object)); g_return_if_fail (GST_IS_MODPLUG (object));
modplug = GST_MODPLUG (object); modplug = GST_MODPLUG (object);
switch (id) { switch (id) {
@ -761,14 +760,15 @@ gst_modplug_set_property (GObject *object, guint id, const GValue *value, GParam
} }
static void static void
gst_modplug_get_property (GObject *object, guint id, GValue *value, GParamSpec *pspec ) gst_modplug_get_property (GObject * object, guint id, GValue * value,
GParamSpec * pspec)
{ {
GstModPlug *modplug; GstModPlug *modplug;
/* it's not null if we got it, but it might not be ours */ /* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_MODPLUG(object)); g_return_if_fail (GST_IS_MODPLUG (object));
modplug = GST_MODPLUG (object); modplug = GST_MODPLUG (object);
switch (id) { switch (id) {
case ARG_REVERB: case ARG_REVERB:
g_value_set_boolean (value, modplug->reverb); g_value_set_boolean (value, modplug->reverb);
@ -806,24 +806,18 @@ gst_modplug_get_property (GObject *object, guint id, GValue *value, GParamSpec *
} }
static gboolean static gboolean
plugin_init (GstPlugin *plugin) plugin_init (GstPlugin * plugin)
{ {
/* this filter needs the bytestream package */ /* this filter needs the bytestream package */
if (!gst_library_load ("gstbytestream")) if (!gst_library_load ("gstbytestream"))
return FALSE; return FALSE;
return gst_element_register (plugin, "modplug", return gst_element_register (plugin, "modplug",
GST_RANK_PRIMARY, GST_TYPE_MODPLUG); GST_RANK_PRIMARY, GST_TYPE_MODPLUG);
} }
GST_PLUGIN_DEFINE ( GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MAJOR, GST_VERSION_MINOR,
GST_VERSION_MINOR, "modplug",
"modplug", ".MOD audio decoding",
".MOD audio decoding", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
plugin_init,
VERSION,
"LGPL",
GST_PACKAGE,
GST_ORIGIN
)