mpeg2enc: remove code paths for older mjpegtools versions

Gets rid of lots of code paths that no one has built,
used or tested for ages, and makes code more maintainable.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1491>
This commit is contained in:
Tim-Philipp Müller 2013-06-23 14:32:15 +01:00 committed by GStreamer Merge Bot
parent 79d90b4fd2
commit 7f6eb54d42
6 changed files with 0 additions and 192 deletions

View file

@ -33,8 +33,6 @@
#include <ontheflyratectl.hh> #include <ontheflyratectl.hh>
#include <pass1ratectl.hh> #include <pass1ratectl.hh>
#include <pass2ratectl.hh> #include <pass2ratectl.hh>
#else
#include <ratectl.hh>
#endif #endif
#include <seqencoder.hh> #include <seqencoder.hh>
#include <mpeg2coder.hh> #include <mpeg2coder.hh>
@ -74,32 +72,15 @@ gboolean GstMpeg2Encoder::setup ()
/* I/O */ /* I/O */
reader = new GstMpeg2EncPictureReader (element, caps, &parms); reader = new GstMpeg2EncPictureReader (element, caps, &parms);
reader->StreamPictureParams (strm); reader->StreamPictureParams (strm);
#if GST_MJPEGTOOLS_API == 10800
/* chain thread caters for reading, do not need another thread for this */
options.allow_parallel_read = FALSE;
#endif
if (options.SetFormatPresets (strm)) { if (options.SetFormatPresets (strm)) {
delete reader; delete reader;
reader = NULL; reader = NULL;
writer = NULL; writer = NULL;
quantizer = NULL; quantizer = NULL;
#if GST_MJPEGTOOLS_API < 10900
bitrate_controller = NULL;
#else
pass1ratectl = NULL; pass1ratectl = NULL;
pass2ratectl = NULL; pass2ratectl = NULL;
#endif
#if GST_MJPEGTOOLS_API >= 10900
/* sequencer */ /* sequencer */
seqencoder = NULL; seqencoder = NULL;
#elif GST_MJPEGTOOLS_API >= 10800
/* sequencer */
seqencoder = NULL;
#else
coder = NULL;
/* sequencer */
seqencoder = NULL;
#endif
return FALSE; return FALSE;
} }
@ -107,26 +88,11 @@ gboolean GstMpeg2Encoder::setup ()
/* encoding internals */ /* encoding internals */
quantizer = new Quantizer (parms); quantizer = new Quantizer (parms);
#if GST_MJPEGTOOLS_API < 10900
bitrate_controller = new OnTheFlyRateCtl (parms);
#else
pass1ratectl = new OnTheFlyPass1 (parms); pass1ratectl = new OnTheFlyPass1 (parms);
pass2ratectl = new OnTheFlyPass2 (parms); pass2ratectl = new OnTheFlyPass2 (parms);
#endif
#if GST_MJPEGTOOLS_API >= 10900
/* sequencer */ /* sequencer */
seqencoder = new SeqEncoder (parms, *reader, *quantizer, seqencoder = new SeqEncoder (parms, *reader, *quantizer,
*writer, *pass1ratectl, *pass2ratectl); *writer, *pass1ratectl, *pass2ratectl);
#elif GST_MJPEGTOOLS_API >= 10800
/* sequencer */
seqencoder = new SeqEncoder (parms, *reader, *quantizer,
*writer, *bitrate_controller);
#else
coder = new MPEG2Coder (parms, *writer);
/* sequencer */
seqencoder = new SeqEncoder (parms, *reader, *quantizer,
*writer, *coder, *bitrate_controller);
#endif
return TRUE; return TRUE;
} }
@ -138,9 +104,7 @@ GstMpeg2Encoder::init ()
parms.Init (options); parms.Init (options);
reader->Init (); reader->Init ();
quantizer->Init (); quantizer->Init ();
#if GST_MJPEGTOOLS_API >= 10800
seqencoder->Init (); seqencoder->Init ();
#endif
init_done = TRUE; init_done = TRUE;
} }
} }
@ -153,11 +117,7 @@ void
GstMpeg2Encoder::encode () GstMpeg2Encoder::encode ()
{ {
/* hm, this is all... eek! */ /* hm, this is all... eek! */
#if GST_MJPEGTOOLS_API >= 10800
seqencoder->EncodeStream (); seqencoder->EncodeStream ();
#else
seqencoder->Encode ();
#endif
} }
/* /*

View file

@ -495,7 +495,6 @@ GstMpeg2EncOptions::initProperties (GObjectClass * klass)
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 | G_PARAM_STATIC_STRINGS))); TRUE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
#if GST_MJPEGTOOLS_API >= 10800
g_object_class_install_property (klass, ARG_DUALPRIME_MPEG2, g_object_class_install_property (klass, ARG_DUALPRIME_MPEG2,
g_param_spec_boolean ("dualprime", "Dual Prime Motion Estimation", g_param_spec_boolean ("dualprime", "Dual Prime Motion Estimation",
"Dual Prime Motion Estimation Mode for MPEG-2 I/P-frame only " "Dual Prime Motion Estimation Mode for MPEG-2 I/P-frame only "
@ -632,11 +631,9 @@ GstMpeg2EncOptions::getProperty (guint prop_id, GValue * value)
case ARG_CONSTRAINTS: case ARG_CONSTRAINTS:
g_value_set_boolean (value, !ignore_constraints); g_value_set_boolean (value, !ignore_constraints);
break; break;
#if GST_MJPEGTOOLS_API >= 10800
case ARG_DUALPRIME_MPEG2: case ARG_DUALPRIME_MPEG2:
g_value_set_boolean (value, hack_dualprime); g_value_set_boolean (value, hack_dualprime);
break; break;
#endif
default: default:
break; break;
} }
@ -770,11 +767,9 @@ GstMpeg2EncOptions::setProperty (guint prop_id, const GValue * value)
case ARG_CONSTRAINTS: case ARG_CONSTRAINTS:
ignore_constraints = !g_value_get_boolean (value); ignore_constraints = !g_value_get_boolean (value);
break; break;
#if GST_MJPEGTOOLS_API >= 10800
case ARG_DUALPRIME_MPEG2: case ARG_DUALPRIME_MPEG2:
hack_dualprime = g_value_get_boolean (value); hack_dualprime = g_value_get_boolean (value);
break; break;
#endif
default: default:
break; break;
} }

View file

@ -104,15 +104,8 @@ GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams & strm)
*/ */
bool bool
#if GST_MJPEGTOOLS_API >= 10900
GstMpeg2EncPictureReader::LoadFrame (ImagePlanes & image) GstMpeg2EncPictureReader::LoadFrame (ImagePlanes & image)
#else
GstMpeg2EncPictureReader::LoadFrame ()
#endif
{ {
#if GST_MJPEGTOOLS_API < 10900
gint n;
#endif
gint i, x, y, s; gint i, x, y, s;
guint8 *frame; guint8 *frame;
GstMpeg2enc *enc; GstMpeg2enc *enc;
@ -137,45 +130,27 @@ bool
gst_video_frame_map (&vframe, &enc->input_state->info, inframe->input_buffer, GST_MAP_READ); gst_video_frame_map (&vframe, &enc->input_state->info, inframe->input_buffer, GST_MAP_READ);
// frame = GST_BUFFER_DATA (enc->buffer); // frame = GST_BUFFER_DATA (enc->buffer);
#if GST_MJPEGTOOLS_API < 10900
n = frames_read % input_imgs_buf_size;
#endif
frame = GST_VIDEO_FRAME_COMP_DATA (&vframe, 0); frame = GST_VIDEO_FRAME_COMP_DATA (&vframe, 0);
s = GST_VIDEO_FRAME_COMP_STRIDE (&vframe, 0); s = GST_VIDEO_FRAME_COMP_STRIDE (&vframe, 0);
x = encparams.horizontal_size; x = encparams.horizontal_size;
y = encparams.vertical_size; y = encparams.vertical_size;
for (i = 0; i < y; i++) { for (i = 0; i < y; i++) {
#if GST_MJPEGTOOLS_API >= 10900
memcpy (image.Plane (0) + i * encparams.phy_width, frame, x); memcpy (image.Plane (0) + i * encparams.phy_width, frame, x);
#else
memcpy (input_imgs_buf[n][0] + i * encparams.phy_width, frame, x);
#endif
frame += s; frame += s;
} }
#if GST_MJPEGTOOLS_API < 10900
lum_mean[n] = LumMean (input_imgs_buf[n][0]);
#endif
frame = GST_VIDEO_FRAME_COMP_DATA (&vframe, 1); frame = GST_VIDEO_FRAME_COMP_DATA (&vframe, 1);
s = GST_VIDEO_FRAME_COMP_STRIDE (&vframe, 1); s = GST_VIDEO_FRAME_COMP_STRIDE (&vframe, 1);
x >>= 1; x >>= 1;
y >>= 1; y >>= 1;
for (i = 0; i < y; i++) { for (i = 0; i < y; i++) {
#if GST_MJPEGTOOLS_API >= 10900
memcpy (image.Plane (1) + i * encparams.phy_chrom_width, frame, x); memcpy (image.Plane (1) + i * encparams.phy_chrom_width, frame, x);
#else
memcpy (input_imgs_buf[n][1] + i * encparams.phy_chrom_width, frame, x);
#endif
frame += s; frame += s;
} }
frame = GST_VIDEO_FRAME_COMP_DATA (&vframe, 2); frame = GST_VIDEO_FRAME_COMP_DATA (&vframe, 2);
s = GST_VIDEO_FRAME_COMP_STRIDE (&vframe, 2); s = GST_VIDEO_FRAME_COMP_STRIDE (&vframe, 2);
for (i = 0; i < y; i++) { for (i = 0; i < y; i++) {
#if GST_MJPEGTOOLS_API >= 10900
memcpy (image.Plane (2) + i * encparams.phy_chrom_width, frame, x); memcpy (image.Plane (2) + i * encparams.phy_chrom_width, frame, x);
#else
memcpy (input_imgs_buf[n][2] + i * encparams.phy_chrom_width, frame, x);
#endif
frame += s; frame += s;
} }
gst_video_frame_unmap (&vframe); gst_video_frame_unmap (&vframe);

View file

@ -25,9 +25,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <picturereader.hh> #include <picturereader.hh>
#if GST_MJPEGTOOLS_API >= 10900
#include <imageplanes.hh> #include <imageplanes.hh>
#endif
class GstMpeg2EncPictureReader : public PictureReader { class GstMpeg2EncPictureReader : public PictureReader {
@ -41,11 +39,7 @@ public:
protected: protected:
/* read a frame */ /* read a frame */
#if GST_MJPEGTOOLS_API >= 10900
bool LoadFrame (ImagePlanes &image); bool LoadFrame (ImagePlanes &image);
#else
bool LoadFrame ();
#endif
private: private:
GstElement *element; GstElement *element;

View file

@ -28,8 +28,6 @@
#include "gstmpeg2encstreamwriter.hh" #include "gstmpeg2encstreamwriter.hh"
#include <string.h> #include <string.h>
#if GST_MJPEGTOOLS_API >= 10800
/* /*
* Class init stuff. * Class init stuff.
*/ */
@ -78,96 +76,3 @@ GstMpeg2EncStreamWriter::BitCount ()
{ {
return flushed * 8ll; return flushed * 8ll;
} }
#else
#define BUFSIZE (128*1024)
/*
* Class init stuff.
*/
GstMpeg2EncStreamWriter::GstMpeg2EncStreamWriter (GstPad * in_pad, EncoderParams * params):
ElemStrmWriter (*params)
{
pad = in_pad;
gst_object_ref (pad);
buf = NULL;
}
GstMpeg2EncStreamWriter::~GstMpeg2EncStreamWriter ()
{
gst_object_unref (pad);
}
/*
* Output functions.
*/
void
GstMpeg2EncStreamWriter::PutBits (guint32 val, gint n)
{
/* only relevant bits. Note that (according to Andrew),
* some CPUs do bitshifts modulo wordsize (32), which
* means that we have to check for n != 32 before
* bitshifting to the relevant bits (i.e. 0xffffffff <<
* 32 == 0xffffffff). */
if (n != 32)
val &= ~(0xffffffffU << n);
/* write data */
while (n >= outcnt) {
if (!buf) {
buf = gst_buffer_new_and_alloc (BUFSIZE);
GST_BUFFER_SIZE (buf) = 0;
}
outbfr = (outbfr << outcnt) | (val >> (n - outcnt));
GST_BUFFER_DATA (buf)[GST_BUFFER_SIZE (buf)++] = outbfr;
n -= outcnt;
outcnt = 8;
bytecnt++;
if (GST_BUFFER_SIZE (buf) >= BUFSIZE)
FrameFlush ();
}
/* cache remaining bits */
if (n != 0) {
outbfr = (outbfr << n) | val;
outcnt -= n;
}
}
void
GstMpeg2EncStreamWriter::FrameBegin ()
{
}
void
GstMpeg2EncStreamWriter::FrameFlush ()
{
GstVideoCodecFrame *frame;
GstVideoEncoder *video_encoder = GST_VIDEO_ENCODER (GST_PAD_PARENT (pad));
GstMpeg2enc *enc = GST_MPEG2ENC (video_encoder);
frame = gst_video_encoder_get_oldest_frame (video_encoder);
g_assert (frame != NULL);
if (buf) {
frame->output_buffer = buf;
/* this should not block anything else (e.g. chain), but if it does,
* it's ok as mpeg2enc is not really a loop-based element, but push-based */
GST_MPEG2ENC_MUTEX_LOCK (enc);
gst_buffer_set_caps (buf, pad->get_current_caps());
enc->srcresult = gst_video_encoder_finish_frame (video_encoder, frame);
GST_MPEG2ENC_MUTEX_UNLOCK (enc);
buf = NULL;
}
}
void
GstMpeg2EncStreamWriter::FrameDiscard ()
{
}
#endif /* GST_MJPEGTOOLS_API >= 10800 */

View file

@ -27,8 +27,6 @@
#include <elemstrmwriter.hh> #include <elemstrmwriter.hh>
#if GST_MJPEGTOOLS_API >= 10800
class GstMpeg2EncStreamWriter : public ElemStrmWriter { class GstMpeg2EncStreamWriter : public ElemStrmWriter {
public: public:
GstMpeg2EncStreamWriter (GstPad *pad, EncoderParams *params); GstMpeg2EncStreamWriter (GstPad *pad, EncoderParams *params);
@ -44,23 +42,4 @@ class GstMpeg2EncStreamWriter : public ElemStrmWriter {
GstBuffer *buf; GstBuffer *buf;
}; };
#else
class GstMpeg2EncStreamWriter : public ElemStrmWriter {
public:
GstMpeg2EncStreamWriter (GstPad *pad, EncoderParams *params);
~GstMpeg2EncStreamWriter ();
/* output functions */
void PutBits (guint32 val, gint n);
void FrameBegin ();
void FrameFlush ();
void FrameDiscard ();
private:
GstPad *pad;
GstBuffer *buf;
};
#endif /* GST_MJPEGTOOLS_API >= 10800 */
#endif /* __GST_MPEG2ENCSTREAMWRITER_H__ */ #endif /* __GST_MPEG2ENCSTREAMWRITER_H__ */