1 /* GStreamer mpeg2enc (mjpegtools) wrapper
2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * gstmpeg2encpicturereader.cc: GStreamer/mpeg2enc input wrapper
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
26 #include <encoderparams.hh>
29 #include "gstmpeg2enc.hh"
30 #include "gstmpeg2encpicturereader.hh"
36 GstMpeg2EncPictureReader::GstMpeg2EncPictureReader (GstElement * in_element, GstCaps * in_caps, EncoderParams * params):
37 PictureReader (*params)
40 gst_object_ref (element);
45 GstMpeg2EncPictureReader::~GstMpeg2EncPictureReader ()
47 gst_caps_unref (caps);
48 gst_object_unref (element);
52 * Get input picture parameters (width/height etc.).
56 GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams & strm)
58 GstStructure *structure = gst_caps_get_structure (caps, 0);
60 const GValue *fps_val;
61 const GValue *par_val;
65 if (!gst_structure_get_int (structure, "width", &width))
68 if (!gst_structure_get_int (structure, "height", &height))
71 fps_val = gst_structure_get_value (structure, "framerate");
72 if (fps_val != NULL) {
73 fps.n = gst_value_get_fraction_numerator (fps_val);
74 fps.d = gst_value_get_fraction_denominator (fps_val);
76 strm.frame_rate_code = mpeg_framerate_code (fps);
78 strm.frame_rate_code = 0;
80 par_val = gst_structure_get_value (structure, "pixel-aspect-ratio");
81 if (par_val != NULL) {
82 par.n = gst_value_get_fraction_numerator (par_val);
83 par.d = gst_value_get_fraction_denominator (par_val);
85 /* By default, assume square pixels */
90 strm.horizontal_size = width;
91 strm.vertical_size = height;
93 strm.interlacing_code = Y4M_ILACE_NONE;
95 strm.aspect_ratio_code = mpeg_guess_mpeg_aspect_code (2, par,
96 strm.horizontal_size, strm.vertical_size);
98 GST_DEBUG_OBJECT (element, "Guessing aspect ratio code for PAR %d/%d "
99 "yielded: %d", par.n, par.d, strm.aspect_ratio_code);
103 * Read a frame. Return true means EOS or error.
107 #if GST_MJPEGTOOLS_API >= 10900
108 GstMpeg2EncPictureReader::LoadFrame (ImagePlanes & image)
110 GstMpeg2EncPictureReader::LoadFrame ()
113 #if GST_MJPEGTOOLS_API < 10900
120 enc = GST_MPEG2ENC (element);
122 GST_MPEG2ENC_MUTEX_LOCK (enc);
124 /* hang around until the element provides us with a buffer */
125 while (!enc->buffer) {
127 GST_MPEG2ENC_MUTEX_UNLOCK (enc);
128 /* inform the mpeg encoding loop that it can give up */
131 GST_MPEG2ENC_WAIT (enc);
134 frame = GST_BUFFER_DATA (enc->buffer);
135 #if GST_MJPEGTOOLS_API < 10900
136 n = frames_read % input_imgs_buf_size;
138 x = encparams.horizontal_size;
139 y = encparams.vertical_size;
141 for (i = 0; i < y; i++) {
142 #if GST_MJPEGTOOLS_API >= 10900
143 memcpy (image.Plane (0) + i * encparams.phy_width, frame, x);
145 memcpy (input_imgs_buf[n][0] + i * encparams.phy_width, frame, x);
149 #if GST_MJPEGTOOLS_API < 10900
150 lum_mean[n] = LumMean (input_imgs_buf[n][0]);
154 for (i = 0; i < y; i++) {
155 #if GST_MJPEGTOOLS_API >= 10900
156 memcpy (image.Plane (1) + i * encparams.phy_chrom_width, frame, x);
158 memcpy (input_imgs_buf[n][1] + i * encparams.phy_chrom_width, frame, x);
162 for (i = 0; i < y; i++) {
163 #if GST_MJPEGTOOLS_API >= 10900
164 memcpy (image.Plane (2) + i * encparams.phy_chrom_width, frame, x);
166 memcpy (input_imgs_buf[n][2] + i * encparams.phy_chrom_width, frame, x);
170 gst_buffer_unref (enc->buffer);
173 /* inform the element the buffer has been processed */
174 GST_MPEG2ENC_SIGNAL (enc);
175 GST_MPEG2ENC_MUTEX_UNLOCK (enc);