diff options
author | Mark Nauwelaerts <manauw@skynet.be> | 2008-03-05 05:38:06 +0000 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2008-03-05 05:38:06 +0000 |
commit | 646ac4cdf2054e5cd38c1869701a4e839f8436b2 (patch) | |
tree | 1b3a85ca8e1109983e8fc3c8c9138eb92c48615c /ext/mpeg2enc | |
parent | 15ac9f5a1398cc7a65f5d44fd53452c2cdf27bc6 (diff) | |
download | gst-plugins-bad-646ac4cdf2054e5cd38c1869701a4e839f8436b2.tar.gz gst-plugins-bad-646ac4cdf2054e5cd38c1869701a4e839f8436b2.tar.bz2 gst-plugins-bad-646ac4cdf2054e5cd38c1869701a4e839f8436b2.zip |
configure.ac: Clean up detection of different mjpegtoolsAPI versions.
Original commit message from CVS:
Patch by: Mark Nauwelaerts <manauw at skynet dot be>
* configure.ac:
Clean up detection of different mjpegtoolsAPI versions.
* ext/mpeg2enc/gstmpeg2enc.cc:
* ext/mpeg2enc/gstmpeg2enc.hh:
* ext/mpeg2enc/gstmpeg2encoder.cc:
* ext/mpeg2enc/gstmpeg2encoptions.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.cc:
* ext/mpeg2enc/gstmpeg2encpicturereader.hh:
* ext/mpeg2enc/gstmpeg2encstreamwriter.cc:
* ext/mpeg2enc/gstmpeg2encstreamwriter.hh:
Streamline conditional code for evolving mjpegtools API,
optimize and fix/prevent crash in log handling, use
names/nicks for enums in the usual way andm inor updates
in code and properties/settings. Partially fixes bug #520329.
Diffstat (limited to 'ext/mpeg2enc')
-rw-r--r-- | ext/mpeg2enc/gstmpeg2enc.cc | 63 | ||||
-rw-r--r-- | ext/mpeg2enc/gstmpeg2enc.hh | 2 | ||||
-rw-r--r-- | ext/mpeg2enc/gstmpeg2encoder.cc | 33 | ||||
-rw-r--r-- | ext/mpeg2enc/gstmpeg2encoptions.cc | 94 | ||||
-rw-r--r-- | ext/mpeg2enc/gstmpeg2encpicturereader.cc | 19 | ||||
-rw-r--r-- | ext/mpeg2enc/gstmpeg2encpicturereader.hh | 6 | ||||
-rw-r--r-- | ext/mpeg2enc/gstmpeg2encstreamwriter.cc | 17 | ||||
-rw-r--r-- | ext/mpeg2enc/gstmpeg2encstreamwriter.hh | 4 |
8 files changed, 128 insertions, 110 deletions
diff --git a/ext/mpeg2enc/gstmpeg2enc.cc b/ext/mpeg2enc/gstmpeg2enc.cc index 2d9d1229..0b8b728d 100644 --- a/ext/mpeg2enc/gstmpeg2enc.cc +++ b/ext/mpeg2enc/gstmpeg2enc.cc @@ -90,6 +90,7 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", "mpegversion = (int) { 1, 2 }, " COMMON_VIDEO_CAPS) ); + static void gst_mpeg2enc_finalize (GObject * object); static void gst_mpeg2enc_reset (GstMpeg2enc * enc); static gboolean gst_mpeg2enc_setcaps (GstPad * pad, GstCaps * caps); @@ -158,6 +159,7 @@ gst_mpeg2enc_finalize (GObject * object) g_mutex_free (enc->tlock); g_cond_free (enc->cond); + g_queue_free (enc->time); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -195,6 +197,7 @@ gst_mpeg2enc_init (GstMpeg2enc * enc, GstMpeg2encClass * g_class) enc->buffer = NULL; enc->tlock = g_mutex_new (); enc->cond = g_cond_new (); + enc->time = g_queue_new (); gst_mpeg2enc_reset (enc); } @@ -202,6 +205,8 @@ gst_mpeg2enc_init (GstMpeg2enc * enc, GstMpeg2encClass * g_class) static void gst_mpeg2enc_reset (GstMpeg2enc * enc) { + GstBuffer *buf; + enc->eos = FALSE; enc->srcresult = GST_FLOW_OK; @@ -209,6 +214,8 @@ gst_mpeg2enc_reset (GstMpeg2enc * enc) if (enc->buffer) gst_buffer_unref (enc->buffer); enc->buffer = NULL; + while ((buf = (GstBuffer *) g_queue_pop_head (enc->time))) + gst_buffer_unref (buf); if (enc->encoder) { delete enc->encoder; @@ -548,6 +555,7 @@ gst_mpeg2enc_chain (GstPad * pad, GstBuffer * buffer) while (enc->buffer) GST_MPEG2ENC_WAIT (enc); enc->buffer = buffer; + g_queue_push_tail (enc->time, gst_buffer_ref (buffer)); GST_MPEG2ENC_SIGNAL (enc); GST_MPEG2ENC_MUTEX_UNLOCK (enc); @@ -573,13 +581,15 @@ eos: } ignore: { + GstFlowReturn ret = enc->srcresult; + GST_DEBUG_OBJECT (enc, "ignoring buffer because encoding task encountered %s", gst_flow_get_name (enc->srcresult)); GST_MPEG2ENC_MUTEX_UNLOCK (enc); gst_buffer_unref (buffer); - return enc->srcresult; + return ret; } } @@ -649,44 +659,37 @@ done: static mjpeg_log_handler_t old_handler = NULL; /* note that this will affect all mjpegtools elements/threads */ - static void gst_mpeg2enc_log_callback (log_level_t level, const char *message) { GstDebugLevel gst_level; -#ifndef GST_MJPEGTOOLS_19rc3 - switch (level) { - case LOG_NONE: - gst_level = GST_LEVEL_NONE; - break; - case LOG_ERROR: - gst_level = GST_LEVEL_ERROR; - break; - case LOG_INFO: - gst_level = GST_LEVEL_INFO; - break; - case LOG_DEBUG: - gst_level = GST_LEVEL_DEBUG; - break; - default: - gst_level = GST_LEVEL_INFO; - break; - } +#if GST_MJPEGTOOLS_API >= 10903 + static const gint mjpeg_log_error = mjpeg_loglev_t ("error"); + static const gint mjpeg_log_warn = mjpeg_loglev_t ("warn"); + static const gint mjpeg_log_info = mjpeg_loglev_t ("info"); + static const gint mjpeg_log_debug = mjpeg_loglev_t ("debug"); #else - if (level == mjpeg_loglev_t ("debug")) - gst_level = GST_LEVEL_DEBUG; - else if (level == mjpeg_loglev_t ("info")) - gst_level = GST_LEVEL_INFO; - else if (level == mjpeg_loglev_t ("warn")) - gst_level = GST_LEVEL_WARNING; - else if (level == mjpeg_loglev_t ("error")) + static const gint mjpeg_log_error = LOG_ERROR; + static const gint mjpeg_log_warn = LOG_WARN; + static const gint mjpeg_log_info = LOG_INFO; + static const gint mjpeg_log_debug = LOG_DEBUG; +#endif + + if (level == mjpeg_log_error) { gst_level = GST_LEVEL_ERROR; - else + } else if (level == mjpeg_log_warn) { + gst_level = GST_LEVEL_WARNING; + } else if (level == mjpeg_log_info) { gst_level = GST_LEVEL_INFO; -#endif + } else if (level == mjpeg_log_debug) { + gst_level = GST_LEVEL_DEBUG; + } else { + gst_level = GST_LEVEL_INFO; + } - gst_debug_log (mpeg2enc_debug, gst_level, "", "", 0, NULL, message); + /* message could have a % in it, do not segfault in such case */ + gst_debug_log (mpeg2enc_debug, gst_level, "", "", 0, NULL, "%s", message); /* chain up to the old handler; * this could actually be a handler from another mjpegtools based diff --git a/ext/mpeg2enc/gstmpeg2enc.hh b/ext/mpeg2enc/gstmpeg2enc.hh index 66e799a0..413e51e4 100644 --- a/ext/mpeg2enc/gstmpeg2enc.hh +++ b/ext/mpeg2enc/gstmpeg2enc.hh @@ -88,6 +88,8 @@ typedef struct _GstMpeg2enc { GstFlowReturn srcresult; /* buffer for encoding task */ GstBuffer *buffer; + /* timestamps for output */ + GQueue *time; } GstMpeg2enc; diff --git a/ext/mpeg2enc/gstmpeg2encoder.cc b/ext/mpeg2enc/gstmpeg2encoder.cc index c8d1b3e0..acfda505 100644 --- a/ext/mpeg2enc/gstmpeg2encoder.cc +++ b/ext/mpeg2enc/gstmpeg2encoder.cc @@ -26,8 +26,10 @@ #include <mpegconsts.h> #include <quantize.hh> -#ifdef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API >= 10900 #include <ontheflyratectl.hh> +#include <pass1ratectl.hh> +#include <pass2ratectl.hh> #else #include <ratectl.hh> #endif @@ -57,18 +59,19 @@ GstMpeg2Encoder::~GstMpeg2Encoder () gst_object_unref (element); } -gboolean -GstMpeg2Encoder::setup () +gboolean GstMpeg2Encoder::setup () { - MPEG2EncInVidParams strm; - GstMpeg2enc *enc; + MPEG2EncInVidParams + strm; + GstMpeg2enc * + enc; enc = GST_MPEG2ENC (element); /* I/O */ reader = new GstMpeg2EncPictureReader (element, caps, &parms); reader->StreamPictureParams (strm); -#if defined(GST_MJPEGTOOLS_18x) && !defined(GST_MJPEGTOOLS_19x) +#if GST_MJPEGTOOLS_API == 10800 /* chain thread caters for reading, do not need another thread for this */ options.allow_parallel_read = FALSE; #endif @@ -79,22 +82,20 @@ GstMpeg2Encoder::setup () /* encoding internals */ quantizer = new Quantizer (parms); -#ifdef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API < 10900 + bitrate_controller = new OnTheFlyRateCtl (parms); +#else pass1ratectl = new OnTheFlyPass1 (parms); pass2ratectl = new OnTheFlyPass2 (parms); -#else - bitrate_controller = new OnTheFlyRateCtl (parms); #endif - -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10900 /* sequencer */ -# ifdef GST_MJPEGTOOLS_19x seqencoder = new SeqEncoder (parms, *reader, *quantizer, *writer, *pass1ratectl, *pass2ratectl); -# else +#elif GST_MJPEGTOOLS_API >= 10800 + /* sequencer */ seqencoder = new SeqEncoder (parms, *reader, *quantizer, *writer, *bitrate_controller); -# endif #else coder = new MPEG2Coder (parms, *writer); /* sequencer */ @@ -112,7 +113,7 @@ GstMpeg2Encoder::init () parms.Init (options); reader->Init (); quantizer->Init (); -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10800 seqencoder->Init (); #endif init_done = TRUE; @@ -127,7 +128,7 @@ void GstMpeg2Encoder::encode () { /* hm, this is all... eek! */ -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10800 seqencoder->EncodeStream (); #else seqencoder->Encode (); diff --git a/ext/mpeg2enc/gstmpeg2encoptions.cc b/ext/mpeg2enc/gstmpeg2encoptions.cc index 4635b81e..875c452c 100644 --- a/ext/mpeg2enc/gstmpeg2encoptions.cc +++ b/ext/mpeg2enc/gstmpeg2encoptions.cc @@ -88,16 +88,16 @@ gst_mpeg2enc_format_get_type (void) if (!mpeg2enc_format_type) { static const GEnumValue mpeg2enc_formats[] = { - {0, "0", "Generic MPEG-1"}, - {1, "1", "Standard VCD"}, - {2, "2", "User VCD"}, - {3, "3", "Generic MPEG-2"}, - {4, "4", "Standard SVCD"}, - {5, "5", "User SVCD"}, - {6, "6", "VCD Stills sequences"}, - {7, "7", "SVCD Stills sequences"}, - {8, "8", "DVD MPEG-2 for dvdauthor"}, - {9, "9", "DVD MPEG-2"}, + {0, "Generic MPEG-1", "0"}, + {1, "Standard VCD", "1"}, + {2, "User VCD", "2"}, + {3, "Generic MPEG-2", "3"}, + {4, "Standard SVCD", "4"}, + {5, "User SVCD", "5"}, + {6, "VCD Stills sequences", "6"}, + {7, "SVCD Stills sequences", "7"}, + {8, "DVD MPEG-2 for dvdauthor", "8"}, + {9, "DVD MPEG-2", "9"}, {0, NULL, NULL}, }; @@ -118,15 +118,15 @@ gst_mpeg2enc_framerate_get_type (void) if (!mpeg2enc_framerate_type) { static const GEnumValue mpeg2enc_framerates[] = { - {0, "0", "Same as input"}, - {1, "1", "24/1.001 (NTSC 3:2 pulldown converted film)"}, - {2, "2", "24 (native film)"}, - {3, "3", "25 (PAL/SECAM video)"}, - {4, "4", "30/1.001 (NTSC video)"}, - {5, "5", "30"}, - {6, "6", "50 (PAL/SECAM fields)"}, - {7, "7", "60/1.001 (NTSC fields)"}, - {8, "8", "60"}, + {0, "Same as input", "0"}, + {1, "24/1.001 (NTSC 3:2 pulldown converted film)", "1"}, + {2, "24 (native film)", "2"}, + {3, "25 (PAL/SECAM video)", "3"}, + {4, "30/1.001 (NTSC video)", "4"}, + {5, "30", "5"}, + {6, "50 (PAL/SECAM fields)", "6"}, + {7, "60/1.001 (NTSC fields)", "7"}, + {8, "60", "8"}, {0, NULL, NULL}, }; @@ -147,11 +147,11 @@ gst_mpeg2enc_aspect_get_type (void) if (!mpeg2enc_aspect_type) { static const GEnumValue mpeg2enc_aspects[] = { - {0, "0", "Deduce from input"}, - {1, "1", "1:1"}, - {2, "2", "4:3"}, - {3, "3", "16:9"}, - {4, "4", "2.21:1"}, + {0, "Deduce from input", "0"}, + {1, "1:1", "1"}, + {2, "4:3", "2"}, + {3, "16:9", "3"}, + {4, "2.21:1", "4"}, {0, NULL, NULL}, }; @@ -172,10 +172,10 @@ gst_mpeg2enc_interlace_mode_get_type (void) if (!mpeg2enc_interlace_mode_type) { static const GEnumValue mpeg2enc_interlace_modes[] = { - {-1, "-1", "Format default mode"}, - {0, "0", "Progressive"}, - {1, "1", "Interlaced, per-frame encoding"}, - {2, "2", "Interlaced, per-field-encoding"}, + {-1, "Format default mode", "-1"}, + {0, "Progressive", "0"}, + {1, "Interlaced, per-frame encoding", "1"}, + {2, "Interlaced, per-field-encoding", "2"}, {0, NULL, NULL}, }; @@ -203,13 +203,13 @@ gst_mpeg2enc_quantisation_matrix_get_type (void) if (!mpeg2enc_quantisation_matrix_type) { static const GEnumValue mpeg2enc_quantisation_matrixes[] = { {GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT, - "0", "Default"}, + "Default", "9"}, {GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES, - "1", "High resolution"}, + "High resolution", "1"}, {GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD, - "2", "KVCD"}, + "KVCD", "2"}, {GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC, - "3", "TMPGEnc"}, + "TMPGEnc", "3"}, {0, NULL, NULL}, }; @@ -231,10 +231,10 @@ gst_mpeg2enc_video_norm_get_type (void) if (!mpeg2enc_video_norm_type) { static const GEnumValue mpeg2enc_video_norms[] = { - {0, "0", "Unspecified"}, - {'p', "p", "PAL"}, - {'n', "n", "NTSC"}, - {'s', "s", "SECAM"}, + {0, "Unspecified", "0"}, + {'p', "PAL", "p"}, + {'n', "NTSC", "n"}, + {'s', "SECAM", "s"}, {0, NULL, NULL}, }; @@ -255,9 +255,9 @@ gst_mpeg2enc_playback_field_order_get_type (void) if (!mpeg2enc_playback_field_order_type) { static const GEnumValue mpeg2enc_playback_field_orders[] = { - {Y4M_UNKNOWN, "0", "Unspecified"}, - {Y4M_ILACE_TOP_FIRST, "1", "Top-field first"}, - {Y4M_ILACE_BOTTOM_FIRST, "2", "Bottom-field first"}, + {Y4M_UNKNOWN, "Unspecified", "0"}, + {Y4M_ILACE_TOP_FIRST, "Top-field first", "1"}, + {Y4M_ILACE_BOTTOM_FIRST, "Bottom-field first", "2"}, {0, NULL, NULL}, }; @@ -322,8 +322,8 @@ GstMpeg2EncOptions::initProperties (GObjectClass * klass) 0, 10 * 1024, 0, (GParamFlags) G_PARAM_READWRITE)); g_object_class_install_property (klass, ARG_QUANTISATION, g_param_spec_int ("quantisation", "Quantisation", - "Quantisation factor (0=default, 1=best, 31=worst)", - 0, 31, 0, (GParamFlags) G_PARAM_READWRITE)); + "Quantisation factor (-1=cbr, 0=default, 1=best, 31=worst)", + -1, 31, 0, (GParamFlags) G_PARAM_READWRITE)); /* stills options */ g_object_class_install_property (klass, ARG_VCD_STILL_SIZE, @@ -449,7 +449,7 @@ GstMpeg2EncOptions::initProperties (GObjectClass * klass) g_param_spec_boolean ("constraints", "Constraints", "Use strict video resolution and bitrate checks", TRUE, (GParamFlags) G_PARAM_READWRITE)); -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10800 g_object_class_install_property (klass, ARG_DUALPRIME_MPEG2, g_param_spec_boolean ("dualprime", "Dual Prime Motion Estimation", "Dual Prime Motion Estimation Mode for MPEG-2 I/P-frame only " @@ -485,7 +485,7 @@ GstMpeg2EncOptions::getProperty (guint prop_id, GValue * value) g_value_set_int (value, nonvid_bitrate / 1024); break; case ARG_QUANTISATION: - g_value_set_int (value, quant); + g_value_set_int (value, force_cbr ? -1 : quant); break; case ARG_VCD_STILL_SIZE: g_value_set_int (value, still_size / 1024); @@ -578,7 +578,7 @@ GstMpeg2EncOptions::getProperty (guint prop_id, GValue * value) case ARG_CONSTRAINTS: g_value_set_boolean (value, !ignore_constraints); break; -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10800 case ARG_DUALPRIME_MPEG2: g_value_set_boolean (value, hack_dualprime); break; @@ -612,6 +612,10 @@ GstMpeg2EncOptions::setProperty (guint prop_id, const GValue * value) break; case ARG_QUANTISATION: quant = g_value_get_int (value); + if (quant < 0) { + force_cbr = 1; + quant = 0; + } break; case ARG_VCD_STILL_SIZE: still_size = g_value_get_int (value) * 1024; @@ -707,7 +711,7 @@ GstMpeg2EncOptions::setProperty (guint prop_id, const GValue * value) case ARG_CONSTRAINTS: ignore_constraints = !g_value_get_boolean (value); break; -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10800 case ARG_DUALPRIME_MPEG2: hack_dualprime = g_value_get_boolean (value); break; diff --git a/ext/mpeg2enc/gstmpeg2encpicturereader.cc b/ext/mpeg2enc/gstmpeg2encpicturereader.cc index 6b09bd1c..5bd09dd7 100644 --- a/ext/mpeg2enc/gstmpeg2encpicturereader.cc +++ b/ext/mpeg2enc/gstmpeg2encpicturereader.cc @@ -25,10 +25,6 @@ #include <encoderparams.hh> -#ifdef GST_MJPEGTOOLS_19x -#include <imageplanes.hh> -#endif - #include "gstmpeg2enc.hh" #include "gstmpeg2encpicturereader.hh" @@ -107,14 +103,13 @@ GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams & strm) */ bool -#ifdef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API >= 10900 GstMpeg2EncPictureReader::LoadFrame (ImagePlanes & image) #else GstMpeg2EncPictureReader::LoadFrame () #endif { - -#ifndef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API < 10900 gint n; #endif gint i, x, y; @@ -136,27 +131,27 @@ bool } frame = GST_BUFFER_DATA (enc->buffer); -#ifndef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API < 10900 n = frames_read % input_imgs_buf_size; #endif x = encparams.horizontal_size; y = encparams.vertical_size; for (i = 0; i < y; i++) { -#ifdef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API >= 10900 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 += x; } -#ifndef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API < 10900 lum_mean[n] = LumMean (input_imgs_buf[n][0]); #endif x >>= 1; y >>= 1; for (i = 0; i < y; i++) { -#ifdef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API >= 10900 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); @@ -164,7 +159,7 @@ bool frame += x; } for (i = 0; i < y; i++) { -#ifdef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API >= 10900 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); diff --git a/ext/mpeg2enc/gstmpeg2encpicturereader.hh b/ext/mpeg2enc/gstmpeg2encpicturereader.hh index 89fb58d8..61b52b5c 100644 --- a/ext/mpeg2enc/gstmpeg2encpicturereader.hh +++ b/ext/mpeg2enc/gstmpeg2encpicturereader.hh @@ -25,6 +25,10 @@ #include <gst/gst.h> #include <picturereader.hh> +#if GST_MJPEGTOOLS_API >= 10900 +#include <imageplanes.hh> +#endif + class GstMpeg2EncPictureReader : public PictureReader { public: @@ -37,7 +41,7 @@ public: protected: /* read a frame */ -#ifdef GST_MJPEGTOOLS_19x +#if GST_MJPEGTOOLS_API >= 10900 bool LoadFrame (ImagePlanes &image); #else bool LoadFrame (); diff --git a/ext/mpeg2enc/gstmpeg2encstreamwriter.cc b/ext/mpeg2enc/gstmpeg2encstreamwriter.cc index ee3fefd6..a17e82dd 100644 --- a/ext/mpeg2enc/gstmpeg2encstreamwriter.cc +++ b/ext/mpeg2enc/gstmpeg2encstreamwriter.cc @@ -28,7 +28,7 @@ #include "gstmpeg2encstreamwriter.hh" #include <string.h> -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10800 /* * Class init stuff. @@ -51,7 +51,7 @@ void GstMpeg2EncStreamWriter::WriteOutBufferUpto (const guint8 * buffer, const guint32 flush_upto) { - GstBuffer *buf; + GstBuffer *buf, *inbuf; GstMpeg2enc *enc = GST_MPEG2ENC (GST_PAD_PARENT (pad)); buf = gst_buffer_new_and_alloc (flush_upto); @@ -62,12 +62,21 @@ GstMpeg2EncStreamWriter::WriteOutBufferUpto (const guint8 * buffer, /* 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); + /* best effort at giving output some meaningful time metadata + * no mpeg2enc specs on this though, but it might help getting the output + * into container formats that really do like timestamps (unlike mplex) */ + if ((inbuf = (GstBuffer *) g_queue_pop_head (enc->time))) { + GST_BUFFER_TIMESTAMP (buf) = GST_BUFFER_TIMESTAMP (inbuf); + GST_BUFFER_DURATION (buf) = GST_BUFFER_DURATION (inbuf); + gst_buffer_unref (inbuf); + } gst_buffer_set_caps (buf, GST_PAD_CAPS (pad)); enc->srcresult = gst_pad_push (pad, buf); GST_MPEG2ENC_MUTEX_UNLOCK (enc); } -guint64 GstMpeg2EncStreamWriter::BitCount () +guint64 +GstMpeg2EncStreamWriter::BitCount () { return flushed * 8ll; } @@ -157,4 +166,4 @@ void GstMpeg2EncStreamWriter::FrameDiscard () { } -#endif /* GST_MJPEGTOOLS_18x */ +#endif /* GST_MJPEGTOOLS_API >= 10800 */ diff --git a/ext/mpeg2enc/gstmpeg2encstreamwriter.hh b/ext/mpeg2enc/gstmpeg2encstreamwriter.hh index 766d7bd1..eaa9cbac 100644 --- a/ext/mpeg2enc/gstmpeg2encstreamwriter.hh +++ b/ext/mpeg2enc/gstmpeg2encstreamwriter.hh @@ -27,7 +27,7 @@ #include <elemstrmwriter.hh> -#ifdef GST_MJPEGTOOLS_18x +#if GST_MJPEGTOOLS_API >= 10800 class GstMpeg2EncStreamWriter : public ElemStrmWriter { public: @@ -61,6 +61,6 @@ private: GstPad *pad; GstBuffer *buf; }; -#endif /* GST_MJPEGTOOLS_18x */ +#endif /* GST_MJPEGTOOLS_API >= 10800 */ #endif /* __GST_MPEG2ENCSTREAMWRITER_H__ */ |