1 /* GStreamer mpeg2enc (mjpegtools) wrapper
2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3 * (c) 2006 Mark Nauwelaerts <manauw@skynet.be>
5 * gstmpeg2encstreamwriter.cc: GStreamer/mpeg2enc output wrapper
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.
27 #include "gstmpeg2enc.hh"
28 #include "gstmpeg2encstreamwriter.hh"
35 GstMpeg2EncStreamWriter::GstMpeg2EncStreamWriter (GstVideoEncoder * venc,
36 EncoderParams * params)
38 video_encoder = GST_VIDEO_ENCODER_CAST (gst_object_ref (venc));
41 GstMpeg2EncStreamWriter::~GstMpeg2EncStreamWriter ()
43 gst_object_unref (video_encoder);
47 GstMpeg2EncStreamWriter::WriteOutBufferUpto (const guint8 * buffer,
48 const guint32 flush_upto)
50 GstVideoCodecFrame *frame;
52 GstMpeg2enc *enc = GST_MPEG2ENC (video_encoder);
55 frame = gst_video_encoder_get_oldest_frame (video_encoder);
56 g_assert (frame != NULL);
58 buf = gst_buffer_new_and_alloc (flush_upto);
59 gst_buffer_fill (buf, 0, buffer, flush_upto);
60 flushed += flush_upto;
61 frame->output_buffer = buf;
63 /* this should not block anything else (e.g. handle_frame), but if it does,
64 * it's ok as mpeg2enc is not really a loop-based element, but push-based */
65 ret = gst_video_encoder_finish_frame (video_encoder, frame);
66 gst_video_codec_frame_unref (frame);
67 GST_MPEG2ENC_MUTEX_LOCK (enc);
69 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
73 GstMpeg2EncStreamWriter::BitCount ()