1 /* GStreamer mpeg2enc (mjpegtools) wrapper
2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3 * (c) 2006 Mark Nauwelaerts <manauw@skynet.be>
5 * gstmpeg2enc.cc: gstreamer mpeg2enc wrapping
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * SECTION:element-mpeg2enc
27 * This element encodes raw video into an MPEG-1/2 elementary stream using the
28 * [mjpegtools](http://mjpeg.sourceforge.net/) library.
30 * Documentation on MPEG encoding in general can be found in the
31 * [MJPEG Howto](https://sourceforge.net/docman/display_doc.php?docid=3456&group_id=5776)
32 * and on the various available parameters in the documentation
33 * of the mpeg2enc tool in particular, which shares options with this element.
38 * gst-launch-1.0 videotestsrc num-buffers=1000 ! mpeg2enc ! filesink location=videotestsrc.m1v
39 * ]| This example pipeline will encode a test video source to a an MPEG1
40 * elementary stream (with Generic MPEG1 profile).
42 * Likely, the #GstMpeg2enc:format property
43 * is most important, as it selects the type of MPEG stream that is produced.
44 * In particular, default property values are dependent on the format,
45 * and can even be forcibly restrained to certain pre-sets (and thereby ignored).
46 * Note that the (S)VCD profiles also restrict the image size, so some scaling
47 * may be needed to accommodate this. The so-called generic profiles (as used
48 * in the example above) allow most parameters to be adjusted.
51 * gst-launch-1.0 videotestsrc num-buffers=1000 ! videoscale ! mpeg2enc format=1 norm=p ! filesink location=videotestsrc.m1v
52 * ]| This will produce an MPEG1 profile stream according to VCD2.0 specifications
53 * for PAL #GstMpeg2enc:norm (as the image height is dependent on video norm).
60 #include <gst/glib-compat-private.h>
61 #include "gstmpeg2enc.hh"
63 GST_DEBUG_CATEGORY (mpeg2enc_debug);
65 #define COMMON_VIDEO_CAPS \
66 "width = (int) [ 16, 4096 ], " \
67 "height = (int) [ 16, 4096 ], " \
69 " (fraction) { 24000/1001, 24/1, 25/1, 30000/1001, 30/1, 50/1, 60000/1001 }"
71 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
74 GST_STATIC_CAPS ("video/x-raw, format = (string) I420, " COMMON_VIDEO_CAPS)
77 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
80 GST_STATIC_CAPS ("video/mpeg, "
81 "systemstream = (boolean) false, "
82 "mpegversion = (int) { 1, 2 }, " COMMON_VIDEO_CAPS)
86 static void gst_mpeg2enc_finalize (GObject * object);
87 static void gst_mpeg2enc_reset (GstMpeg2enc * enc);
89 static gboolean gst_mpeg2enc_start (GstVideoEncoder * video_encoder);
90 static gboolean gst_mpeg2enc_stop (GstVideoEncoder * video_encoder);
91 static gboolean gst_mpeg2enc_set_format (GstVideoEncoder *
92 video_encoder, GstVideoCodecState * state);
93 static GstCaps * gst_mpeg2enc_getcaps (GstVideoEncoder *
94 video_encoder, GstCaps * filter);
95 static GstFlowReturn gst_mpeg2enc_handle_frame (GstVideoEncoder *
96 video_encoder, GstVideoCodecFrame * frame);
97 static gboolean gst_mpeg2enc_sink_event (GstVideoEncoder *
98 video_encoder, GstEvent * event);
100 static GstFlowReturn gst_mpeg2enc_finish (GstVideoEncoder * video_encoder);
101 static void gst_mpeg2enc_loop (GstVideoEncoder * video_encoder);
103 static void gst_mpeg2enc_get_property (GObject * object,
104 guint prop_id, GValue * value, GParamSpec * pspec);
105 static void gst_mpeg2enc_set_property (GObject * object,
106 guint prop_id, const GValue * value, GParamSpec * pspec);
107 static gboolean gst_mpeg2enc_src_activate_mode (GstPad * pad, GstObject * parent,
108 GstPadMode mode, gboolean active);
109 static gboolean mpeg2enc_element_init (GstPlugin * plugin);
111 #define gst_mpeg2enc_parent_class parent_class
112 G_DEFINE_TYPE_WITH_CODE (GstMpeg2enc, gst_mpeg2enc, GST_TYPE_VIDEO_ENCODER,
113 G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL));
114 GST_ELEMENT_REGISTER_DEFINE_CUSTOM (mpeg2enc, mpeg2enc_element_init);
117 gst_mpeg2enc_class_init (GstMpeg2encClass * klass)
119 GObjectClass *object_class = G_OBJECT_CLASS (klass);
120 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
121 GstVideoEncoderClass *video_encoder_class = GST_VIDEO_ENCODER_CLASS (klass);
123 GST_DEBUG_CATEGORY_INIT (mpeg2enc_debug, "mpeg2enc", 0, "MPEG1/2 encoder");
125 object_class->set_property = gst_mpeg2enc_set_property;
126 object_class->get_property = gst_mpeg2enc_get_property;
128 /* register properties */
129 GstMpeg2EncOptions::initProperties (object_class);
131 object_class->finalize = GST_DEBUG_FUNCPTR (gst_mpeg2enc_finalize);
134 element_class->change_state = GST_DEBUG_FUNCPTR (gst_mpeg2enc_change_state);
137 gst_element_class_add_static_pad_template (element_class, &src_template);
138 gst_element_class_add_static_pad_template (element_class, &sink_template);
140 gst_element_class_set_static_metadata (element_class,
141 "mpeg2enc video encoder", "Codec/Encoder/Video",
142 "High-quality MPEG-1/2 video encoder",
143 "Andrew Stevens <andrew.stevens@nexgo.de>\n"
144 "Ronald Bultje <rbultje@ronald.bitfreak.net>");
146 video_encoder_class->start = GST_DEBUG_FUNCPTR (gst_mpeg2enc_start);
147 video_encoder_class->stop = GST_DEBUG_FUNCPTR (gst_mpeg2enc_stop);
148 video_encoder_class->handle_frame = GST_DEBUG_FUNCPTR (gst_mpeg2enc_handle_frame);
149 video_encoder_class->set_format = GST_DEBUG_FUNCPTR (gst_mpeg2enc_set_format);
150 video_encoder_class->finish = GST_DEBUG_FUNCPTR (gst_mpeg2enc_finish);
151 //video_encoder_class->pre_push = GST_DEBUG_FUNCPTR (gst_mpeg2enc_pre_push);
152 video_encoder_class->sink_event = GST_DEBUG_FUNCPTR (gst_mpeg2enc_sink_event);
153 video_encoder_class->getcaps = GST_DEBUG_FUNCPTR (gst_mpeg2enc_getcaps);
157 gst_mpeg2enc_finalize (GObject * object)
159 GstMpeg2enc *enc = GST_MPEG2ENC (object);
162 gst_mpeg2enc_reset (enc);
166 g_mutex_clear (&enc->tlock);
167 g_cond_clear (&enc->cond);
169 G_OBJECT_CLASS (parent_class)->finalize (object);
173 gst_mpeg2enc_init (GstMpeg2enc * enc)
175 enc->options = new GstMpeg2EncOptions ();
178 g_mutex_init (&enc->tlock);
179 g_cond_init (&enc->cond);
180 enc->started = FALSE;
182 gst_pad_set_activatemode_function (GST_VIDEO_ENCODER_SRC_PAD (enc),
183 GST_DEBUG_FUNCPTR (gst_mpeg2enc_src_activate_mode));
185 gst_mpeg2enc_reset (enc);
189 gst_mpeg2enc_src_activate_mode (GstPad * pad, GstObject * parent,
190 GstPadMode mode, gboolean active)
192 gboolean result = TRUE;
195 enc = GST_MPEG2ENC (parent);
197 if (mode != GST_PAD_MODE_PUSH)
201 /* setcaps will start task once encoder is setup */
203 /* can only end the encoding loop by forcing eos */
204 GST_MPEG2ENC_MUTEX_LOCK (enc);
206 enc->srcresult = GST_FLOW_FLUSHING;
207 GST_MPEG2ENC_SIGNAL (enc);
208 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
215 gst_mpeg2enc_reset (GstMpeg2enc * enc)
218 enc->srcresult = GST_FLOW_OK;
220 /* in case of error'ed ending */
221 if (enc->pending_frame) {
222 gst_video_encoder_finish_frame (GST_VIDEO_ENCODER (enc), enc->pending_frame);
223 enc->pending_frame = NULL;
234 gst_mpeg2enc_start (GstVideoEncoder * video_encoder)
236 GstMpeg2enc *enc = GST_MPEG2ENC (video_encoder);
238 GST_DEBUG_OBJECT (video_encoder, "start");
241 GST_ELEMENT_ERROR (enc, LIBRARY, INIT,
242 ("Failed to get default encoder options"), (NULL));
245 /* start task to create multiplexor and start muxing */
246 if (G_UNLIKELY (enc->srcresult != GST_FLOW_OK)) {
247 GST_ELEMENT_ERROR (enc, LIBRARY, INIT,
248 ("Invalid encoder state"), (NULL));
256 gst_mpeg2enc_stop (GstVideoEncoder * video_encoder)
258 gboolean result = TRUE;
261 GST_DEBUG_OBJECT (video_encoder, "stop");
263 enc = GST_MPEG2ENC (video_encoder);
265 /* can only end the encoding loop by forcing eos */
266 GST_MPEG2ENC_MUTEX_LOCK (enc);
268 enc->srcresult = GST_FLOW_FLUSHING;
269 GST_MPEG2ENC_SIGNAL (enc);
270 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
272 /* encoding loop should have ended now and can be joined */
274 result = gst_pad_stop_task (video_encoder->srcpad);
275 enc->started = FALSE;
279 GST_MPEG2ENC_MUTEX_LOCK (enc);
280 gst_mpeg2enc_reset (enc);
281 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
288 /* some (!) coding to get caps depending on the video norm and chosen format */
290 gst_mpeg2enc_add_fps (GstStructure * structure, gint fpss[])
292 GValue list = { 0, }, fps = {
296 g_value_init (&list, GST_TYPE_LIST);
297 g_value_init (&fps, GST_TYPE_FRACTION);
298 for (n = 0; fpss[n] != 0; n += 2) {
299 gst_value_set_fraction (&fps, fpss[n], fpss[n + 1]);
300 gst_value_list_append_value (&list, &fps);
302 gst_structure_set_value (structure, "framerate", &list);
303 g_value_unset (&list);
304 g_value_unset (&fps);
308 gst_mpeg2enc_get_fps (GstMpeg2enc * enc)
310 static gint fps_pal[]
311 = { 24, 1, 25, 1, 50, 1, 0 };
312 static gint fps_ntsc[]
313 = { 24000, 1001, 24, 1, 30000, 1001, 30, 1, 60000, 1001, 0 };
314 static gint fps_all[]
315 = { 24000, 1001, 24, 1, 30000, 1001, 30, 1, 60000, 1001, 25, 1, 50, 1, 0 };
317 if (enc->options->norm == 'n')
319 else if (enc->options->norm == 0)
326 gst_mpeg2enc_set_format (GstVideoEncoder * video_encoder, GstVideoCodecState * state)
328 GstVideoCodecState *output_state;
332 enc = GST_MPEG2ENC (video_encoder);
334 GST_DEBUG_OBJECT (video_encoder, "set_format");
335 /* Store input state */
336 if (enc->input_state)
337 gst_video_codec_state_unref (enc->input_state);
338 enc->input_state = gst_video_codec_state_ref (state);
340 /* does not go well to restart stream mid-way */
341 if (enc->encoder != NULL)
342 goto refuse_renegotiation;
345 /* since mpeg encoder does not really check, let's check caps */
346 if (GST_VIDEO_INFO_FORMAT (&state->info) != GST_VIDEO_FORMAT_I420)
349 caps = gst_caps_new_simple ("video/mpeg",
350 "systemstream", G_TYPE_BOOLEAN, FALSE,
351 "mpegversion", G_TYPE_INT, (enc->options->mpeg == 1)?1:2, NULL);
354 gst_video_encoder_set_output_state (video_encoder,
356 gst_video_codec_state_unref (output_state);
358 gst_video_encoder_negotiate (GST_VIDEO_ENCODER (enc));
364 GST_WARNING_OBJECT (enc, "refused caps %" GST_PTR_FORMAT, state->caps);
368 refuse_renegotiation:
370 GST_WARNING_OBJECT (enc, "refused renegotiation (to %" GST_PTR_FORMAT ")",
377 static GstStructure *
378 gst_mpeg2enc_structure_from_norm (GstMpeg2enc * enc, gint horiz,
379 gint pal_v, gint ntsc_v)
381 GstStructure *structure;
383 structure = gst_structure_new ("video/x-raw",
384 "format", G_TYPE_STRING, "I420", NULL);
386 switch (enc->options->norm) {
393 g_value_init (&list, GST_TYPE_LIST);
394 g_value_init (&val, G_TYPE_INT);
395 g_value_set_int (&val, pal_v);
396 gst_value_list_append_value (&list, &val);
397 g_value_set_int (&val, ntsc_v);
398 gst_value_list_append_value (&list, &val);
399 gst_structure_set_value (structure, "height", &list);
400 g_value_unset (&list);
401 g_value_unset (&val);
405 gst_structure_set (structure, "height", G_TYPE_INT, ntsc_v,
409 gst_structure_set (structure, "height", G_TYPE_INT, pal_v, (void *) NULL);
412 gst_structure_set (structure, "width", G_TYPE_INT, horiz, (void *) NULL);
413 gst_mpeg2enc_add_fps (structure, gst_mpeg2enc_get_fps (enc));
419 gst_mpeg2enc_getcaps (GstVideoEncoder * video_encoder, GstCaps * filter)
422 GstMpeg2enc *enc = GST_MPEG2ENC (video_encoder);
424 caps = gst_pad_get_current_caps (video_encoder->sinkpad);
428 switch (enc->options->format) {
430 case 2: /* user vcd */
431 caps = gst_caps_new_full (gst_mpeg2enc_structure_from_norm (enc,
432 352, 288, 240), NULL);
435 case 5: /* user svcd */
436 caps = gst_caps_new_full (gst_mpeg2enc_structure_from_norm (enc,
437 480, 576, 480), NULL);
439 case 6: /* vcd stills */
441 caps = gst_caps_new_full (gst_mpeg2enc_structure_from_norm (enc,
442 352, 288, 240), NULL);
443 /* high resolution */
444 gst_caps_append_structure (caps,
445 gst_mpeg2enc_structure_from_norm (enc, 704, 576, 480));
447 case 7: /* svcd stills */
449 caps = gst_caps_new_full (gst_mpeg2enc_structure_from_norm (enc,
450 480, 576, 480), NULL);
451 /* high resolution */
452 gst_caps_append_structure (caps,
453 gst_mpeg2enc_structure_from_norm (enc, 704, 576, 480));
460 caps = gst_caps_copy (gst_pad_get_pad_template_caps (video_encoder->sinkpad));
461 gst_mpeg2enc_add_fps (gst_caps_get_structure (caps, 0),
462 gst_mpeg2enc_get_fps (enc));
470 gst_mpeg2enc_finish (GstVideoEncoder * video_encoder)
474 enc = GST_MPEG2ENC (video_encoder);
476 GST_DEBUG_OBJECT (video_encoder, "finish");
478 /* inform the encoding task that it can stop now */
479 GST_MPEG2ENC_MUTEX_LOCK (enc);
481 GST_MPEG2ENC_SIGNAL (enc);
482 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
488 gst_mpeg2enc_sink_event (GstVideoEncoder * video_encoder, GstEvent * event)
491 gboolean result = TRUE;
493 enc = GST_MPEG2ENC (video_encoder);
494 GST_DEBUG_OBJECT (video_encoder, "sink_event");
496 switch (GST_EVENT_TYPE (event)) {
497 case GST_EVENT_FLUSH_START:
499 result = GST_VIDEO_ENCODER_CLASS (parent_class)->sink_event (video_encoder, event);
501 /* no special action as there is not much to flush;
502 * neither is it possible to halt the mpeg encoding loop */
504 case GST_EVENT_FLUSH_STOP:
506 result = GST_VIDEO_ENCODER_CLASS (parent_class)->sink_event (video_encoder, event);
510 /* this clears the error state in case of a failure in encoding task;
511 * so handle_frame function can carry on again */
512 GST_MPEG2ENC_MUTEX_LOCK (enc);
513 enc->srcresult = GST_FLOW_OK;
514 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
517 /* inform the encoding task that it can stop now */
518 GST_MPEG2ENC_MUTEX_LOCK (enc);
520 GST_MPEG2ENC_SIGNAL (enc);
521 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
523 /* eat this event for now, task will send eos when finished */
524 gst_event_unref (event);
527 /* for a serialized event, wait until an earlier buffer is gone,
528 * though this is no guarantee as to when the encoder is done with it */
529 if (GST_EVENT_IS_SERIALIZED (event)) {
530 GST_MPEG2ENC_MUTEX_LOCK (enc);
531 while (enc->pending_frame != NULL)
532 GST_MPEG2ENC_WAIT (enc);
533 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
538 result = GST_VIDEO_ENCODER_CLASS (parent_class)->sink_event (video_encoder, event);
545 gst_mpeg2enc_loop (GstVideoEncoder * video_encoder)
547 GstMpeg2enc *enc = GST_MPEG2ENC (video_encoder);
549 GST_DEBUG_OBJECT (enc, "encoding task loop:START");
550 /* do not try to resume or start when output problems;
551 * also ensures a proper (forced) state change */
552 if (enc->srcresult != GST_FLOW_OK) {
553 GST_MPEG2ENC_MUTEX_LOCK (enc);
554 enc->srcresult = GST_FLOW_ERROR;
555 GST_MPEG2ENC_SIGNAL (enc);
556 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
559 GST_DEBUG_OBJECT (enc, "encoding task loop: flow OK");
563 GstClockTime latency;
564 GstVideoInfo *info = &enc->input_state->info;
566 /* create new encoder with these settings */
567 enc->encoder = new GstMpeg2Encoder (enc->options, GST_ELEMENT (video_encoder),
568 gst_pad_get_current_caps(video_encoder->sinkpad));
570 ret = enc->encoder->setup ();
572 /* We must have a fixated max GOP size after setting up */
573 g_assert (enc->options->max_GOP_size != -1);
575 /* mjpeg tools outputs encoded data on a GOP basis, our latency is
576 * thus at least max_GOP_size. It also introduces a 5-frame delay on
577 * top of that, this was determined empirically, a surface level inspection
578 * of the code didn't show where and why that delay is introduced exactly,
579 * and this is not specifically documented, but it needs to be taken
580 * into account when calculating the latency
582 if (GST_VIDEO_INFO_FPS_D (info) == 0 || GST_VIDEO_INFO_FPS_N (info) == 0) {
583 /* Assume 25fps for unknown framerates. Better than reporting
584 * that we introduce no latency while we actually do
586 latency = gst_util_uint64_scale (enc->options->max_GOP_size + 5,
589 latency = gst_util_uint64_scale (enc->options->max_GOP_size + 5,
590 GST_VIDEO_INFO_FPS_D (info) * GST_SECOND, GST_VIDEO_INFO_FPS_N (info));
593 gst_video_encoder_set_latency (video_encoder, latency, latency);
595 /* SeqEncoder init requires at least two frames */
596 enc->encoder->init ();
599 GST_MPEG2ENC_MUTEX_LOCK (enc);
600 enc->srcresult = GST_FLOW_NOT_NEGOTIATED;
601 GST_MPEG2ENC_SIGNAL (enc);
602 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
606 GST_DEBUG_OBJECT (enc, "encoding task loop: setup and init DONE");
608 /* note that init performs a pre-fill and therefore needs buffers */
609 /* task will stay in here during all of the encoding */
610 enc->encoder->encode ();
611 GST_DEBUG_OBJECT (enc, "encoding task loop: encode DONE");
612 /* if not well and truly eos, something strange happened */
614 GST_ERROR_OBJECT (enc, "encoding task ended without being eos");
615 /* notify the handle_frame function that it's over */
616 GST_MPEG2ENC_MUTEX_LOCK (enc);
617 enc->srcresult = GST_FLOW_ERROR;
618 GST_MPEG2ENC_SIGNAL (enc);
619 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
621 /* send eos if this was not a forced stop or other problem */
622 GST_DEBUG_OBJECT (enc, "encoding task loop: eos REACHED");
623 if (enc->srcresult == GST_FLOW_OK) {
624 gst_pad_push_event (video_encoder->srcpad, gst_event_new_eos ());
625 GST_DEBUG_OBJECT (enc, "encoding task loop: eos SENT");
633 /* no need to run wildly, stopped elsewhere, e.g. state change */
634 GST_DEBUG_OBJECT (enc, "pausing encoding task");
635 gst_pad_pause_task (video_encoder->srcpad);
641 GST_ELEMENT_ERROR (enc, CORE, NEGOTIATION, (NULL),
642 ("encoder setup failed"));
653 GST_DEBUG_OBJECT (enc, "encoding task reached eos");
658 GST_DEBUG_OBJECT (enc, "not looping because encoding task encountered %s",
659 gst_flow_get_name (enc->srcresult));
665 gst_mpeg2enc_handle_frame (GstVideoEncoder *video_encoder, GstVideoCodecFrame *frame)
667 GstMpeg2enc *enc = GST_MPEG2ENC (video_encoder);
669 GST_DEBUG_OBJECT (video_encoder, "handle_frame");
670 GST_MPEG2ENC_MUTEX_LOCK (enc);
672 if (G_UNLIKELY (enc->eos))
674 GST_DEBUG_OBJECT (video_encoder, "handle_frame: NOT eos");
676 if (G_UNLIKELY (enc->srcresult != GST_FLOW_OK))
678 GST_DEBUG_OBJECT (video_encoder, "handle_frame: flow OK");
680 /* If the encoder is busy with a previous frame still, wait
681 * for it to be done */
682 if (enc->pending_frame != NULL) {
684 GST_VIDEO_ENCODER_STREAM_UNLOCK (enc);
685 GST_MPEG2ENC_WAIT (enc);
686 GST_VIDEO_ENCODER_STREAM_LOCK (enc);
688 /* Re-check the srcresult, since we waited */
689 if (G_UNLIKELY (enc->srcresult != GST_FLOW_OK))
691 } while (enc->pending_frame != NULL);
694 /* frame will be released by task */
695 enc->pending_frame = frame;
698 GST_DEBUG_OBJECT (video_encoder, "handle_frame: START task");
699 gst_pad_start_task (video_encoder->srcpad, (GstTaskFunction) gst_mpeg2enc_loop, enc, NULL);
703 /* things look good, now inform the encoding task that a frame is ready */
704 GST_MPEG2ENC_SIGNAL (enc);
705 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
710 GST_DEBUG_OBJECT (enc, "ignoring frame at end-of-stream");
711 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
713 gst_video_encoder_finish_frame (video_encoder, frame);
719 GstFlowReturn ret = enc->srcresult;
721 GST_DEBUG_OBJECT (enc,
722 "ignoring frame because encoding task encountered %s",
723 gst_flow_get_name (enc->srcresult));
727 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
729 gst_video_encoder_finish_frame (video_encoder, frame);
736 gst_mpeg2enc_get_property (GObject * object,
737 guint prop_id, GValue * value, GParamSpec * pspec)
739 GST_MPEG2ENC (object)->options->getProperty (prop_id, value);
743 gst_mpeg2enc_set_property (GObject * object,
744 guint prop_id, const GValue * value, GParamSpec * pspec)
746 GST_MPEG2ENC (object)->options->setProperty (prop_id, value);
749 #ifndef GST_DISABLE_GST_DEBUG
751 static mjpeg_log_handler_t old_handler = NULL;
753 /* note that this will affect all mjpegtools elements/threads */
755 gst_mpeg2enc_log_callback (log_level_t level, const char *message)
757 GstDebugLevel gst_level;
759 #if GST_MJPEGTOOLS_API >= 10903
760 static const gint mjpeg_log_error = mjpeg_loglev_t ("error");
761 static const gint mjpeg_log_warn = mjpeg_loglev_t ("warn");
762 static const gint mjpeg_log_info = mjpeg_loglev_t ("info");
763 static const gint mjpeg_log_debug = mjpeg_loglev_t ("debug");
765 static const gint mjpeg_log_error = LOG_ERROR;
766 static const gint mjpeg_log_warn = LOG_WARN;
767 static const gint mjpeg_log_info = LOG_INFO;
768 static const gint mjpeg_log_debug = LOG_DEBUG;
771 if (level == mjpeg_log_error) {
772 gst_level = GST_LEVEL_ERROR;
773 } else if (level == mjpeg_log_warn) {
774 gst_level = GST_LEVEL_WARNING;
775 } else if (level == mjpeg_log_info) {
776 gst_level = GST_LEVEL_INFO;
777 } else if (level == mjpeg_log_debug) {
778 gst_level = GST_LEVEL_DEBUG;
780 gst_level = GST_LEVEL_INFO;
783 /* message could have a % in it, do not segfault in such case */
784 gst_debug_log (mpeg2enc_debug, gst_level, "", "", 0, NULL, "%s", message);
786 /* chain up to the old handler;
787 * this could actually be a handler from another mjpegtools based
788 * plugin; in which case messages can come out double or from
789 * the wrong plugin (element)... */
790 old_handler (level, message);
795 mpeg2enc_element_init (GstPlugin * plugin)
797 #ifndef GST_DISABLE_GST_DEBUG
798 old_handler = mjpeg_log_set_handler (gst_mpeg2enc_log_callback);
799 g_assert (old_handler != NULL);
801 /* in any case, we do not want default handler output */
802 mjpeg_default_handler_verbosity (0);
804 return gst_element_register (plugin, "mpeg2enc",
805 GST_RANK_MARGINAL, GST_TYPE_MPEG2ENC);
809 plugin_init (GstPlugin * plugin)
811 return GST_ELEMENT_REGISTER (mpeg2enc, plugin);
814 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
817 "High-quality MPEG-1/2 video encoder",
818 plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)