1 /* GStreamer mpeg2enc (mjpegtools) wrapper
2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3 * (c) 2006 Mark Nauwelaerts <manauw@skynet.be>
4 *
5 * gstmpeg2encstreamwriter.cc: GStreamer/mpeg2enc output wrapper
6 *
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.
11 *
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.
16 *
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.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "gstmpeg2enc.hh"
28 #include "gstmpeg2encstreamwriter.hh"
29 #include <string.h>
30
31 /*
32 * Class init stuff.
33 */
34
GstMpeg2EncStreamWriter(GstVideoEncoder * venc,EncoderParams * params)35 GstMpeg2EncStreamWriter::GstMpeg2EncStreamWriter (GstVideoEncoder * venc,
36 EncoderParams * params)
37 {
38 video_encoder = GST_VIDEO_ENCODER_CAST (gst_object_ref (venc));
39 }
40
~GstMpeg2EncStreamWriter()41 GstMpeg2EncStreamWriter::~GstMpeg2EncStreamWriter ()
42 {
43 gst_object_unref (video_encoder);
44 }
45
46 void
WriteOutBufferUpto(const guint8 * buffer,const guint32 flush_upto)47 GstMpeg2EncStreamWriter::WriteOutBufferUpto (const guint8 * buffer,
48 const guint32 flush_upto)
49 {
50 GstVideoCodecFrame *frame;
51 GstBuffer *buf;
52 GstMpeg2enc *enc = GST_MPEG2ENC (video_encoder);
53 GstFlowReturn ret;
54
55 frame = gst_video_encoder_get_oldest_frame (video_encoder);
56 g_assert (frame != NULL);
57
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;
62
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);
68 enc->srcresult = ret;
69 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
70 }
71
72 guint64
BitCount()73 GstMpeg2EncStreamWriter::BitCount ()
74 {
75 return flushed * 8ll;
76 }
77