summaryrefslogtreecommitdiffstats
path: root/ext/mpeg2enc/gstmpeg2encpicturereader.cc
diff options
context:
space:
mode:
authorMark Nauwelaerts <manauw@skynet.be>2006-07-13 11:06:45 +0000
committerTim-Philipp Müller <tim@centricular.net>2006-07-13 11:06:45 +0000
commit676eafc77c2799521925d54ba43b26df72c76b14 (patch)
treede46f5bf8f22a83cd7a55fa1cdb26507986e22fd /ext/mpeg2enc/gstmpeg2encpicturereader.cc
parent0e9af4401ec81f82b3b4d7f548a96b2585f1e0e1 (diff)
downloadgst-plugins-bad-676eafc77c2799521925d54ba43b26df72c76b14.tar.gz
gst-plugins-bad-676eafc77c2799521925d54ba43b26df72c76b14.tar.bz2
gst-plugins-bad-676eafc77c2799521925d54ba43b26df72c76b14.zip
Port mpeg2enc to 0.10 (#343184).
Original commit message from CVS: Patch by: Mark Nauwelaerts <manauw at skynet be> * configure.ac: * ext/Makefile.am: * ext/mpeg2enc/Makefile.am: * ext/mpeg2enc/gstmpeg2enc.cc: * ext/mpeg2enc/gstmpeg2enc.hh: * ext/mpeg2enc/gstmpeg2encoder.cc: * ext/mpeg2enc/gstmpeg2encoder.hh: * ext/mpeg2enc/gstmpeg2encoptions.cc: * ext/mpeg2enc/gstmpeg2encpicturereader.cc: * ext/mpeg2enc/gstmpeg2encpicturereader.hh: * ext/mpeg2enc/gstmpeg2encstreamwriter.cc: * ext/mpeg2enc/gstmpeg2encstreamwriter.hh: Port mpeg2enc to 0.10 (#343184). * tests/check/Makefile.am: * tests/check/elements/.cvsignore: * tests/check/elements/mpeg2enc.c: Add unit test for mpeg2enc. * tests/icles/.cvsignore: Ignore pitch-test.
Diffstat (limited to 'ext/mpeg2enc/gstmpeg2encpicturereader.cc')
-rw-r--r--ext/mpeg2enc/gstmpeg2encpicturereader.cc105
1 files changed, 40 insertions, 65 deletions
diff --git a/ext/mpeg2enc/gstmpeg2encpicturereader.cc b/ext/mpeg2enc/gstmpeg2encpicturereader.cc
index 9ed8afc0..9bc59edf 100644
--- a/ext/mpeg2enc/gstmpeg2encpicturereader.cc
+++ b/ext/mpeg2enc/gstmpeg2encpicturereader.cc
@@ -25,23 +25,26 @@
#include <encoderparams.hh>
+#include "gstmpeg2enc.hh"
#include "gstmpeg2encpicturereader.hh"
/*
* Class init stuff.
*/
-GstMpeg2EncPictureReader::GstMpeg2EncPictureReader (GstPad * in_pad,
- const GstCaps * in_caps, EncoderParams * params):
+GstMpeg2EncPictureReader::GstMpeg2EncPictureReader (GstElement * in_element, GstCaps * in_caps, EncoderParams * params):
PictureReader (*params)
{
- pad = in_pad;
- caps = gst_caps_copy (in_caps);
+ element = in_element;
+ gst_object_ref (element);
+ caps = in_caps;
+ gst_caps_ref (caps);
}
GstMpeg2EncPictureReader::~GstMpeg2EncPictureReader ()
{
- gst_caps_free (caps);
+ gst_caps_unref (caps);
+ gst_object_unref (element);
}
/*
@@ -53,83 +56,50 @@ GstMpeg2EncPictureReader::StreamPictureParams (MPEG2EncInVidParams & strm)
{
GstStructure *structure = gst_caps_get_structure (caps, 0);
gint width, height;
- gdouble fps;
+ const GValue *fps_val;
+ y4m_ratio_t fps;
gst_structure_get_int (structure, "width", &width);
gst_structure_get_int (structure, "height", &height);
- gst_structure_get_double (structure, "framerate", &fps);
+ fps_val = gst_structure_get_value (structure, "framerate");
+ fps.n = gst_value_get_fraction_numerator (fps_val);
+ fps.d = gst_value_get_fraction_denominator (fps_val);
strm.horizontal_size = width;
strm.vertical_size = height;
- strm.frame_rate_code = mpeg_framerate_code (mpeg_conform_framerate (fps));
+ strm.frame_rate_code = mpeg_framerate_code (fps);
strm.interlacing_code = Y4M_ILACE_NONE;
+ /* FIXME perhaps involve pixel-aspect-ratio for 'better' sar */
strm.aspect_ratio_code = mpeg_guess_mpeg_aspect_code (2, y4m_sar_SQUARE,
strm.horizontal_size, strm.vertical_size);
-
- /* FIXME:
- * strm.interlacing_code = y4m_si_get_interlace(&si);
- * sar = y4m_si_get_sampleaspect(&si);
- * strm.aspect_ratio_code =
- * mpeg_guess_mpeg_aspect_code(2, sar,
- * strm.horizontal_size,
- * strm.vertical_size);
- */
}
/*
* Read a frame. Return true means EOS or error.
*/
-bool GstMpeg2EncPictureReader::LoadFrame ()
+bool
+GstMpeg2EncPictureReader::LoadFrame ()
{
- GstData *
- data;
- GstBuffer *
- buf =
- NULL;
-
- gint
- i,
- x,
- y,
- n;
- guint8 *
- frame;
-
- GstFormat
- fmt =
- GST_FORMAT_DEFAULT;
- gint64
- pos =
- 0,
- tot =
- 0;
-
- gst_pad_query (GST_PAD_PEER (pad), GST_QUERY_POSITION, &fmt, &pos);
- gst_pad_query (GST_PAD_PEER (pad), GST_QUERY_TOTAL, &fmt, &tot);
-
- do {
- if ((data = (GstData *) gst_pad_get_element_private (pad))) {
- gst_pad_set_element_private (pad, NULL);
- } else if (!(data = gst_pad_pull (pad))) {
- GST_ELEMENT_ERROR (gst_pad_get_parent (pad), RESOURCE, READ,
- (NULL), (NULL));
- return true;
- }
+ gint i, x, y, n;
+ guint8 *frame;
+ GstMpeg2enc *enc;
+
+ enc = GST_MPEG2ENC (element);
- if (GST_IS_EVENT (data)) {
- if (GST_EVENT_TYPE (data) == GST_EVENT_EOS) {
- gst_event_unref (GST_EVENT (data));
- return true;
- } else {
- gst_pad_event_default (pad, GST_EVENT (data));
- }
- } else {
- buf = GST_BUFFER (data);
+ GST_MPEG2ENC_MUTEX_LOCK (enc);
+
+ /* hang around until the element provides us with a buffer */
+ while (!enc->buffer) {
+ if (enc->eos) {
+ GST_MPEG2ENC_MUTEX_UNLOCK (enc);
+ /* inform the mpeg encoding loop that it can give up */
+ return TRUE;
}
- } while (!buf);
+ GST_MPEG2ENC_WAIT (enc);
+ }
- frame = GST_BUFFER_DATA (buf);
+ frame = GST_BUFFER_DATA (enc->buffer);
n = frames_read % input_imgs_buf_size;
x = encparams.horizontal_size;
y = encparams.vertical_size;
@@ -149,7 +119,12 @@ bool GstMpeg2EncPictureReader::LoadFrame ()
memcpy (input_imgs_buf[n][2] + i * encparams.phy_chrom_width, frame, x);
frame += x;
}
- gst_buffer_unref (buf);
+ gst_buffer_unref (enc->buffer);
+ enc->buffer = NULL;
+
+ /* inform the element the buffer has been processed */
+ GST_MPEG2ENC_SIGNAL (enc);
+ GST_MPEG2ENC_MUTEX_UNLOCK (enc);
- return false;
+ return FALSE;
}