2003-12-11 21:07:25 +00:00
|
|
|
/* GStreamer mpeg2enc (mjpegtools) wrapper
|
|
|
|
* (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2006-07-13 11:06:45 +00:00
|
|
|
* (c) 2006 Mark Nauwelaerts <manauw@skynet.be>
|
2003-12-11 21:07:25 +00:00
|
|
|
*
|
|
|
|
* gstmpeg2encoder.cc: gstreamer/mpeg2enc encoder class
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2003-12-11 21:07:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <mpegconsts.h>
|
|
|
|
#include <quantize.hh>
|
2011-05-25 13:42:38 +00:00
|
|
|
#if GST_MJPEGTOOLS_API >= 20000
|
2011-05-24 13:42:44 +00:00
|
|
|
#include <ontheflyratectlpass1.hh>
|
|
|
|
#include <ontheflyratectlpass2.hh>
|
|
|
|
#elif GST_MJPEGTOOLS_API >= 10900
|
2008-01-27 07:32:19 +00:00
|
|
|
#include <ontheflyratectl.hh>
|
2008-03-05 05:38:06 +00:00
|
|
|
#include <pass1ratectl.hh>
|
|
|
|
#include <pass2ratectl.hh>
|
2008-01-27 07:32:19 +00:00
|
|
|
#else
|
2003-12-11 21:07:25 +00:00
|
|
|
#include <ratectl.hh>
|
2008-01-27 07:32:19 +00:00
|
|
|
#endif
|
2003-12-11 21:07:25 +00:00
|
|
|
#include <seqencoder.hh>
|
|
|
|
#include <mpeg2coder.hh>
|
|
|
|
|
2006-07-13 11:06:45 +00:00
|
|
|
#include "gstmpeg2enc.hh"
|
2003-12-11 21:07:25 +00:00
|
|
|
#include "gstmpeg2encoder.hh"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class init stuff.
|
|
|
|
*/
|
|
|
|
|
2006-07-13 11:06:45 +00:00
|
|
|
GstMpeg2Encoder::GstMpeg2Encoder (GstMpeg2EncOptions * options, GstElement * in_element, GstCaps * in_caps):
|
2004-03-14 23:20:41 +00:00
|
|
|
MPEG2Encoder (*options)
|
2003-12-11 21:07:25 +00:00
|
|
|
{
|
2006-07-13 11:06:45 +00:00
|
|
|
element = in_element;
|
|
|
|
gst_object_ref (element);
|
|
|
|
caps = in_caps;
|
|
|
|
gst_caps_ref (in_caps);
|
|
|
|
init_done = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstMpeg2Encoder::~GstMpeg2Encoder ()
|
|
|
|
{
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
gst_object_unref (element);
|
|
|
|
}
|
|
|
|
|
2008-03-05 05:38:06 +00:00
|
|
|
gboolean GstMpeg2Encoder::setup ()
|
2006-07-13 11:06:45 +00:00
|
|
|
{
|
2008-03-05 05:38:06 +00:00
|
|
|
MPEG2EncInVidParams
|
|
|
|
strm;
|
|
|
|
GstMpeg2enc *
|
|
|
|
enc;
|
2006-07-13 11:06:45 +00:00
|
|
|
|
|
|
|
enc = GST_MPEG2ENC (element);
|
2003-12-11 21:07:25 +00:00
|
|
|
|
|
|
|
/* I/O */
|
2006-07-13 11:06:45 +00:00
|
|
|
reader = new GstMpeg2EncPictureReader (element, caps, &parms);
|
2003-12-11 21:07:25 +00:00
|
|
|
reader->StreamPictureParams (strm);
|
2008-03-05 05:38:06 +00:00
|
|
|
#if GST_MJPEGTOOLS_API == 10800
|
2006-07-13 11:06:45 +00:00
|
|
|
/* chain thread caters for reading, do not need another thread for this */
|
|
|
|
options.allow_parallel_read = FALSE;
|
|
|
|
#endif
|
|
|
|
if (options.SetFormatPresets (strm)) {
|
|
|
|
return FALSE;
|
2003-12-11 21:07:25 +00:00
|
|
|
}
|
2006-07-13 11:06:45 +00:00
|
|
|
writer = new GstMpeg2EncStreamWriter (enc->srcpad, &parms);
|
2003-12-11 21:07:25 +00:00
|
|
|
|
|
|
|
/* encoding internals */
|
|
|
|
quantizer = new Quantizer (parms);
|
2008-03-05 05:38:06 +00:00
|
|
|
#if GST_MJPEGTOOLS_API < 10900
|
|
|
|
bitrate_controller = new OnTheFlyRateCtl (parms);
|
|
|
|
#else
|
2008-01-27 07:32:19 +00:00
|
|
|
pass1ratectl = new OnTheFlyPass1 (parms);
|
|
|
|
pass2ratectl = new OnTheFlyPass2 (parms);
|
|
|
|
#endif
|
2008-03-05 05:38:06 +00:00
|
|
|
#if GST_MJPEGTOOLS_API >= 10900
|
2006-07-13 11:06:45 +00:00
|
|
|
/* sequencer */
|
2008-01-27 07:32:19 +00:00
|
|
|
seqencoder = new SeqEncoder (parms, *reader, *quantizer,
|
|
|
|
*writer, *pass1ratectl, *pass2ratectl);
|
2008-03-05 05:38:06 +00:00
|
|
|
#elif GST_MJPEGTOOLS_API >= 10800
|
|
|
|
/* sequencer */
|
2006-07-13 11:06:45 +00:00
|
|
|
seqencoder = new SeqEncoder (parms, *reader, *quantizer,
|
|
|
|
*writer, *bitrate_controller);
|
|
|
|
#else
|
|
|
|
coder = new MPEG2Coder (parms, *writer);
|
2003-12-11 21:07:25 +00:00
|
|
|
/* sequencer */
|
|
|
|
seqencoder = new SeqEncoder (parms, *reader, *quantizer,
|
2004-03-14 23:20:41 +00:00
|
|
|
*writer, *coder, *bitrate_controller);
|
2006-07-13 11:06:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-12-11 21:07:25 +00:00
|
|
|
|
2006-07-13 11:06:45 +00:00
|
|
|
void
|
|
|
|
GstMpeg2Encoder::init ()
|
|
|
|
{
|
|
|
|
if (!init_done) {
|
|
|
|
parms.Init (options);
|
|
|
|
reader->Init ();
|
|
|
|
quantizer->Init ();
|
2008-03-05 05:38:06 +00:00
|
|
|
#if GST_MJPEGTOOLS_API >= 10800
|
2006-07-13 11:06:45 +00:00
|
|
|
seqencoder->Init ();
|
|
|
|
#endif
|
|
|
|
init_done = TRUE;
|
|
|
|
}
|
2003-12-11 21:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-13 11:06:45 +00:00
|
|
|
* Process all input provided by the reader until it signals eos.
|
2003-12-11 21:07:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2006-07-13 11:06:45 +00:00
|
|
|
GstMpeg2Encoder::encode ()
|
2003-12-11 21:07:25 +00:00
|
|
|
{
|
|
|
|
/* hm, this is all... eek! */
|
2008-03-05 05:38:06 +00:00
|
|
|
#if GST_MJPEGTOOLS_API >= 10800
|
2006-07-13 11:06:45 +00:00
|
|
|
seqencoder->EncodeStream ();
|
|
|
|
#else
|
2003-12-11 21:07:25 +00:00
|
|
|
seqencoder->Encode ();
|
2006-07-13 11:06:45 +00:00
|
|
|
#endif
|
2003-12-11 21:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get current output format.
|
|
|
|
*/
|
|
|
|
|
|
|
|
GstCaps *
|
|
|
|
GstMpeg2Encoder::getFormat ()
|
|
|
|
{
|
2006-07-13 11:06:45 +00:00
|
|
|
y4m_ratio_t fps = mpeg_framerate (options.frame_rate);
|
2003-12-11 21:07:25 +00:00
|
|
|
|
Fix caps breakage after Dave's caps branch merge.
Original commit message from CVS:
2003-12-23 Ronald Bultje <rbultje@ronald.bitfreak.net>
* ext/divx/gstdivxdec.c: (gst_divxdec_base_init),
(gst_divxdec_init), (gst_divxdec_negotiate):
* ext/divx/gstdivxdec.h:
* ext/divx/gstdivxenc.c: (gst_divxenc_base_init),
(gst_divxenc_init):
* ext/faac/gstfaac.c: (gst_faac_base_init), (gst_faac_init),
(gst_faac_sinkconnect), (gst_faac_srcconnect):
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* sys/dxr3/dxr3audiosink.c: (dxr3audiosink_base_init),
(dxr3audiosink_init), (dxr3audiosink_pcm_sinklink):
* sys/dxr3/dxr3spusink.c: (dxr3spusink_base_init),
(dxr3spusink_init):
* sys/dxr3/dxr3videosink.c: (dxr3videosink_base_init),
(dxr3videosink_init):
Fix caps breakage after Dave's caps branch merge.
2003-12-23 22:50:06 +00:00
|
|
|
return gst_caps_new_simple ("video/mpeg",
|
2004-03-14 23:20:41 +00:00
|
|
|
"systemstream", G_TYPE_BOOLEAN, FALSE,
|
|
|
|
"mpegversion", G_TYPE_INT, options.mpeg,
|
|
|
|
"width", G_TYPE_INT, options.in_img_width,
|
|
|
|
"height", G_TYPE_INT, options.in_img_height,
|
2006-07-13 11:06:45 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION, fps.n, fps.d, NULL);
|
2003-12-11 21:07:25 +00:00
|
|
|
}
|