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
|
|
|
#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"
|
|
|
|
|
2020-08-04 14:33:34 +00:00
|
|
|
class GstOnTheFlyPass2 : public OnTheFlyPass2 {
|
|
|
|
public:
|
|
|
|
GstOnTheFlyPass2 (EncoderParams &encoder, gboolean disable_encode_retries): OnTheFlyPass2(encoder), disable_encode_retries(disable_encode_retries) {}
|
|
|
|
bool ReencodeRequired() const { return disable_encode_retries ? false : OnTheFlyPass2::ReencodeRequired(); }
|
|
|
|
private:
|
|
|
|
gboolean disable_encode_retries;
|
|
|
|
};
|
|
|
|
|
2003-12-11 21:07:25 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2020-08-04 14:33:34 +00:00
|
|
|
disable_encode_retries = options->disable_encode_retries;
|
2006-07-13 11:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2012-10-01 11:11:29 +00:00
|
|
|
GstVideoEncoder *
|
|
|
|
video_encoder;
|
2006-07-13 11:06:45 +00:00
|
|
|
|
2012-10-01 11:11:29 +00:00
|
|
|
video_encoder = GST_VIDEO_ENCODER (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);
|
2006-07-13 11:06:45 +00:00
|
|
|
if (options.SetFormatPresets (strm)) {
|
2012-10-01 11:11:29 +00:00
|
|
|
delete reader;
|
|
|
|
reader = NULL;
|
|
|
|
writer = NULL;
|
|
|
|
quantizer = NULL;
|
|
|
|
pass1ratectl = NULL;
|
|
|
|
pass2ratectl = NULL;
|
|
|
|
/* sequencer */
|
|
|
|
seqencoder = NULL;
|
|
|
|
|
2006-07-13 11:06:45 +00:00
|
|
|
return FALSE;
|
2003-12-11 21:07:25 +00:00
|
|
|
}
|
2013-06-23 15:38:49 +00:00
|
|
|
writer = new GstMpeg2EncStreamWriter (video_encoder, &parms);
|
2003-12-11 21:07:25 +00:00
|
|
|
|
|
|
|
/* encoding internals */
|
|
|
|
quantizer = new Quantizer (parms);
|
2008-01-27 07:32:19 +00:00
|
|
|
pass1ratectl = new OnTheFlyPass1 (parms);
|
2020-08-04 14:33:34 +00:00
|
|
|
pass2ratectl = new GstOnTheFlyPass2 (parms, disable_encode_retries);
|
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);
|
2006-07-13 11:06:45 +00:00
|
|
|
|
|
|
|
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 ();
|
|
|
|
seqencoder->Init ();
|
|
|
|
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! */
|
2006-07-13 11:06:45 +00:00
|
|
|
seqencoder->EncodeStream ();
|
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
|
|
|
}
|