[Thoggen-cvs] SF.net SVN: thoggen: [287] trunk/thoggen
Status: Beta
Brought to you by:
tp-m
|
From: <tp...@us...> - 2007-12-26 16:25:11
|
Revision: 287
http://thoggen.svn.sourceforge.net/thoggen/?rev=287&view=rev
Author: tp-m
Date: 2007-12-26 08:25:13 -0800 (Wed, 26 Dec 2007)
Log Message:
-----------
* src/gst-plugins/Makefile.am:
* src/gst-plugins/th-parsetter.c:
* src/gst-plugins/th-parsetter.h:
* src/gst-plugins/th-plugins.c:
Add thparsetter plugin that munges the pixel-aspect-ratio field in
the decoder caps to something else. We use this to force the pixel
aspect ratio on the stream according to the DVD headers, working
around a bug in libmpeg2 (see bug #323332 in gnome bugzilla).
* src/th-disc-drive.c: (disk_drive_import_titles_from_pipe_data):
* src/th-job.c: (job_create_pipeline):
Force pixel-aspect-ratio as per DVD headers. Should fix bug
#1717949. Please test extensively.
* src/th-utils.c: (th_simplify_fraction):
* src/th-utils.h:
Add th_simplify_fraction().
Modified Paths:
--------------
trunk/thoggen/ChangeLog
trunk/thoggen/src/gst-plugins/Makefile.am
trunk/thoggen/src/gst-plugins/th-plugins.c
trunk/thoggen/src/th-disc-drive.c
trunk/thoggen/src/th-job.c
trunk/thoggen/src/th-utils.c
trunk/thoggen/src/th-utils.h
Added Paths:
-----------
trunk/thoggen/src/gst-plugins/th-parsetter.c
trunk/thoggen/src/gst-plugins/th-parsetter.h
Modified: trunk/thoggen/ChangeLog
===================================================================
--- trunk/thoggen/ChangeLog 2007-12-26 03:20:42 UTC (rev 286)
+++ trunk/thoggen/ChangeLog 2007-12-26 16:25:13 UTC (rev 287)
@@ -1,5 +1,25 @@
2007-12-26 Tim-Philipp Müller <tim at centricular dot net>
+ * src/gst-plugins/Makefile.am:
+ * src/gst-plugins/th-parsetter.c:
+ * src/gst-plugins/th-parsetter.h:
+ * src/gst-plugins/th-plugins.c:
+ Add thparsetter plugin that munges the pixel-aspect-ratio field in
+ the decoder caps to something else. We use this to force the pixel
+ aspect ratio on the stream according to the DVD headers, working
+ around a bug in libmpeg2 (see bug #323332 in gnome bugzilla).
+
+ * src/th-disc-drive.c: (disk_drive_import_titles_from_pipe_data):
+ * src/th-job.c: (job_create_pipeline):
+ Force pixel-aspect-ratio as per DVD headers. Should fix bug
+ #1717949. Please test extensively.
+
+ * src/th-utils.c: (th_simplify_fraction):
+ * src/th-utils.h:
+ Add th_simplify_fraction().
+
+2007-12-26 Tim-Philipp Müller <tim at centricular dot net>
+
* src/th-utils.c: (gui_thread), (log_text_buffer), (pending_log_lines),
(create_log_text_buffer), (process_pending_log_lines),
(th_log_add_line):
Modified: trunk/thoggen/src/gst-plugins/Makefile.am
===================================================================
--- trunk/thoggen/src/gst-plugins/Makefile.am 2007-12-26 03:20:42 UTC (rev 286)
+++ trunk/thoggen/src/gst-plugins/Makefile.am 2007-12-26 16:25:13 UTC (rev 287)
@@ -13,11 +13,13 @@
# th-yuvscale.h
libthoggenplugins_a_SOURCES = \
- th-pixbufsink.c \
- th-pixbufsink.h \
+ th-pixbufsink.c \
+ th-pixbufsink.h \
th-deinterlace.c \
th-deinterlace.h \
- th-plugins.c \
+ th-parsetter.c \
+ th-parsetter.h \
+ th-plugins.c \
th-plugins.h
CLEANFILES = Makefile.am~ *.c~ *.h~ *.glade~ *.gladep *.gladep.bak
Added: trunk/thoggen/src/gst-plugins/th-parsetter.c
===================================================================
--- trunk/thoggen/src/gst-plugins/th-parsetter.c (rev 0)
+++ trunk/thoggen/src/gst-plugins/th-parsetter.c 2007-12-26 16:25:13 UTC (rev 287)
@@ -0,0 +1,221 @@
+/***************************************************************************
+ th-parsetter.c
+ --------------
+ begin : Sat Mar 26 2007
+ copyright : (C) 2007 by Tim-Philipp Müller
+ email : t....@or...
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+/* Munges the pixel-aspect-ratio field in the caps */
+
+#include "th-parsetter.h"
+
+enum {
+ PROP_PAR = 1
+};
+
+#define DEFAULT_PAR_NUM 0
+#define DEFAULT_PAR_DENOM 1
+
+GST_BOILERPLATE (ThParSetter, th_par_setter, GstBaseTransform, GST_TYPE_BASE_TRANSFORM);
+
+static GstFlowReturn th_par_setter_transform_ip (GstBaseTransform * bt,
+ GstBuffer * buf);
+static GstFlowReturn th_par_setter_prepare_output_buffer (GstBaseTransform * bt,
+ GstBuffer * inbuf, gint size, GstCaps * caps, GstBuffer ** p_outbuf);
+static GstCaps * th_par_setter_transform_caps (GstBaseTransform * trans,
+ GstPadDirection dir, GstCaps * caps);
+static gboolean th_par_setter_transform_size (GstBaseTransform * trans,
+ GstPadDirection dir, GstCaps * caps, guint size, GstCaps * othercaps,
+ guint * othersize);
+
+static GstStaticPadTemplate parsetter_sink_factory =
+ GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("video/x-raw-rgb; video/x-raw-yuv"));
+
+static GstStaticPadTemplate parsetter_src_factory =
+ GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("video/x-raw-rgb; video/x-raw-yuv"));
+
+static const GstElementDetails parsetter_details =
+GST_ELEMENT_DETAILS ("Pixel-Aspect Ratio Setter",
+ "Filter/Effect/Video",
+ "Force a particular pixel aspect ratio on a video stream",
+ "Tim-Philipp Müller <tim centricular net>");
+
+static void
+th_par_setter_base_init (gpointer g_class)
+{
+ GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+ gst_element_class_set_details (element_class, &parsetter_details);
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&parsetter_sink_factory));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&parsetter_src_factory));
+}
+
+static void
+th_par_setter_set_property (GObject * obj, guint prop_id, const GValue * val,
+ GParamSpec * pspec)
+{
+ ThParSetter *setter = TH_PAR_SETTER (obj);
+
+ switch (prop_id) {
+ case PROP_PAR: {
+ gint num = gst_value_get_fraction_numerator (val);
+ gint denom = gst_value_get_fraction_denominator (val);
+ if (denom == 0)
+ g_warning ("Trying to set invalid pixel-aspect-ratio %d/%d", num, denom);
+ else
+ gst_value_set_fraction (&setter->par, num, denom);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+static void
+th_par_setter_class_init (ThParSetterClass *klass)
+{
+ GstBaseTransformClass *basetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->set_property = th_par_setter_set_property;
+
+ g_object_class_install_property (gobject_class, PROP_PAR,
+ gst_param_spec_fraction ("pixel-aspect-ratio", "Pixel Aspect Ratio",
+ "Pixel Aspect Ratio to force on the video stream (0/1 = no change)",
+ 0, 1, G_MAXINT, 1, DEFAULT_PAR_NUM, DEFAULT_PAR_DENOM,
+ G_PARAM_WRITABLE));
+
+ basetrans_class->prepare_output_buffer =
+ GST_DEBUG_FUNCPTR (th_par_setter_prepare_output_buffer);
+ basetrans_class->transform_caps =
+ GST_DEBUG_FUNCPTR (th_par_setter_transform_caps);
+ basetrans_class->transform_ip =
+ GST_DEBUG_FUNCPTR (th_par_setter_transform_ip);
+ basetrans_class->transform_size =
+ GST_DEBUG_FUNCPTR (th_par_setter_transform_size);
+}
+
+static void
+th_par_setter_init (ThParSetter *setter, ThParSetterClass *klass)
+{
+ /* kids: technically, we should have a corresponding g_value_unset() in a
+ * finalize function, but we know we can skip that because there aren't any
+ * deep allocs in the value structure in this case */
+ g_value_init (&setter->par, GST_TYPE_FRACTION);
+ gst_value_set_fraction (&setter->par, DEFAULT_PAR_NUM, DEFAULT_PAR_DENOM);
+
+ gst_base_transform_set_in_place (GST_BASE_TRANSFORM (setter), TRUE);
+}
+
+static GstFlowReturn
+th_par_setter_prepare_output_buffer (GstBaseTransform * basetrans,
+ GstBuffer * inbuf, gint size, GstCaps * caps, GstBuffer ** p_outbuf)
+{
+ ThParSetter *setter = TH_PAR_SETTER (basetrans);
+
+ if (gst_value_get_fraction_numerator (&setter->par) == 0) {
+ *p_outbuf = gst_buffer_ref (inbuf);
+ /* don't touch caps */
+ } else {
+ /* ref to make sure make_metadata_writable creates a subbuffer */
+ gst_buffer_ref (inbuf);
+ *p_outbuf = gst_buffer_make_metadata_writable (inbuf);
+ gst_buffer_set_caps (*p_outbuf,
+ GST_PAD_CAPS (GST_BASE_TRANSFORM_SRC_PAD (basetrans)));
+ }
+ return GST_FLOW_OK;
+}
+
+static gboolean
+th_par_setter_transform_size (GstBaseTransform * trans, GstPadDirection dir,
+ GstCaps * caps, guint size, GstCaps * othercaps, guint * othersize)
+{
+ *othersize = size;
+ return TRUE;
+}
+
+static GstFlowReturn
+th_par_setter_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
+{
+ /* nothing to do, we set the new caps in prepare_output_buffer */
+ return GST_FLOW_OK;
+}
+
+static GstCaps *
+th_par_setter_transform_caps (GstBaseTransform * trans, GstPadDirection dir,
+ GstCaps * caps)
+{
+ ThParSetter *setter = TH_PAR_SETTER (trans);
+ GstCaps *ret;
+ guint i;
+
+ ret = gst_caps_copy (caps);
+
+ for (i = 0; i < gst_caps_get_size (ret); ++i) {
+ GstStructure *s;
+
+ s = gst_caps_get_structure (ret, i);
+
+ if (dir == GST_PAD_SINK) {
+ gst_structure_remove_field (s, "pixel-aspect-ratio");
+ gst_structure_set_value (s, "pixel-aspect-ratio", &setter->par);
+ } else {
+ GValue par_range = { 0, };
+
+ g_value_init (&par_range, GST_TYPE_FRACTION_RANGE);
+ gst_value_set_fraction_range_full (&par_range, 1, 1, G_MAXINT, 1);
+ gst_structure_set_value (s, "pixel-aspect-ratio", &par_range);
+ g_value_unset (&par_range);
+ }
+ }
+
+ GST_LOG_OBJECT (setter, "transformed %" GST_PTR_FORMAT " to %" GST_PTR_FORMAT,
+ caps, ret);
+
+ return ret;
+}
+
+#if 0
+static gboolean
+th_par_setter_set_caps (GstBaseTransform *basetrans, GstCaps *caps)
+{
+ ThParSetter *setter = TH_PAR_SETTER (basetrans);
+ GstStructure *s;
+
+ s = gst_caps_get_structure (caps, 0);
+ if (!gst_structure_get_int (s, "width", &sink->width) ||
+ !gst_structure_get_int (s, "height", &sink->height)) {
+ return FALSE;
+ }
+
+ if (!gst_structure_get_fraction (s, "pixel-aspect-ratio", &sink->par_n,
+ &sink->par_d)) {
+ sink->par_n = 1;
+ sink->par_d = 1;
+ }
+
+ GST_INFO_OBJECT (setter, "width x height = %d x %d", sink->width, sink->height);
+ GST_INFO_OBJECT (setter, "pixel-aspect-ratio = %d/%d", sink->par_d, sink->par_n);
+ return TRUE;
+}
+#endif
+
Added: trunk/thoggen/src/gst-plugins/th-parsetter.h
===================================================================
--- trunk/thoggen/src/gst-plugins/th-parsetter.h (rev 0)
+++ trunk/thoggen/src/gst-plugins/th-parsetter.h 2007-12-26 16:25:13 UTC (rev 287)
@@ -0,0 +1,58 @@
+/***************************************************************************
+ th-parsetter.h
+ --------------
+ begin : Sat Mar 26 2007
+ copyright : (C) 2007 by Tim-Philipp Müller
+ email : t....@or...
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This element forces a given pixel-aspect-ratio on a video stream, *
+ * which is required to work around a bug in libmpeg2/mpeg2dec, see *
+ * http://bugzilla.gnome.org/show_bug.cgi?id=323332 for details. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef _th_par_setter_h_included_
+#define _th_par_setter_h_included_
+
+#include <gst/gst.h>
+#include <gst/base/gstbasetransform.h>
+
+#define TH_TYPE_PAR_SETTER (th_par_setter_get_type())
+#define TH_PAR_SETTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),TH_TYPE_PAR_SETTER,ThParSetter))
+#define TH_PAR_SETTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),TH_TYPE_PAR_SETTER,ThParSetterClass))
+#define TH_IS_PAR_SETTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),TH_TYPE_PAR_SETTER))
+#define TH_IS_PAR_SETTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),TH_TYPE_PAR_SETTER))
+
+typedef struct _ThParSetter ThParSetter;
+typedef struct _ThParSetterClass ThParSetterClass;
+
+struct _ThParSetter
+{
+ GstBaseTransform basetrans;
+
+ GValue par; /* pixel-aspect-ratio to force on the output */
+};
+
+struct _ThParSetterClass
+{
+ GstBaseTransformClass basetransclass;
+};
+
+GType th_par_setter_get_type (void);
+
+#endif /* _th_par_setter_h_included_ */
+
+
Modified: trunk/thoggen/src/gst-plugins/th-plugins.c
===================================================================
--- trunk/thoggen/src/gst-plugins/th-plugins.c 2007-12-26 03:20:42 UTC (rev 286)
+++ trunk/thoggen/src/gst-plugins/th-plugins.c 2007-12-26 16:25:13 UTC (rev 287)
@@ -20,6 +20,7 @@
#endif
#include "th-plugins.h"
+#include "th-parsetter.h"
#include "th-pixbufsink.h"
#include "th-deinterlace.h"
@@ -62,6 +63,11 @@
return FALSE;
}
+ if (!gst_element_register (plugin, "thparsetter", GST_RANK_NONE,
+ TH_TYPE_PAR_SETTER)) {
+ return FALSE;
+ }
+
return TRUE;
}
Modified: trunk/thoggen/src/th-disc-drive.c
===================================================================
--- trunk/thoggen/src/th-disc-drive.c 2007-12-26 03:20:42 UTC (rev 286)
+++ trunk/thoggen/src/th-disc-drive.c 2007-12-26 16:25:13 UTC (rev 287)
@@ -745,6 +745,19 @@
job->video_info.fps_denom = 1;
}
+ if (titles[i].video_aspect == 0) {
+ job->video_info.aspect_num = 4;
+ job->video_info.aspect_denom = 3;
+ } else {
+ job->video_info.aspect_num = 16;
+ job->video_info.aspect_denom = 9;
+ }
+ job->video_info.aspect_num *= titles[i].size_y;
+ job->video_info.aspect_denom *= titles[i].size_x;
+
+ th_simplify_fraction (&job->video_info.aspect_num,
+ &job->video_info.aspect_denom);
+
dd_job_add_audio_streams (job, &titles[i]);
dd_job_add_subpicture_streams (job, &titles[i]);
Modified: trunk/thoggen/src/th-job.c
===================================================================
--- trunk/thoggen/src/th-job.c 2007-12-26 03:20:42 UTC (rev 286)
+++ trunk/thoggen/src/th-job.c 2007-12-26 16:25:13 UTC (rev 287)
@@ -1967,6 +1967,7 @@
" demux.%s "
" ! queue name=q-v-in "
" ! mpeg2dec "
+ " ! thparsetter pixel-aspect-ratio=%u/%u "
" ! videorate "
" ! video/x-raw-yuv,framerate=(fraction)%u/%u "
" ! videobox left=%u right=%u top=%u bottom=%u "
@@ -1978,6 +1979,7 @@
" ! mux. ",
audio_pipe,
j->priv->video_pad_name,
+ j->video_info.aspect_num, j->video_info.aspect_denom,
j->video_info.fps_num, j->video_info.fps_denom,
j->priv->crop_left, j->priv->crop_right,
j->priv->crop_top, j->priv->crop_bottom,
Modified: trunk/thoggen/src/th-utils.c
===================================================================
--- trunk/thoggen/src/th-utils.c 2007-12-26 03:20:42 UTC (rev 286)
+++ trunk/thoggen/src/th-utils.c 2007-12-26 16:25:13 UTC (rev 287)
@@ -1562,3 +1562,26 @@
gst_object_unref (child);
}
+
+/***************************************************************************
+ *
+ * th_simplify_fraction
+ *
+ ***************************************************************************/
+
+void
+th_simplify_fraction (guint * num, guint * denom)
+{
+ guint a, b, tmp;
+
+ a = *num;
+ b = *denom;
+ while (a) { /* find greatest common divisor */
+ tmp = a;
+ a = b % tmp;
+ b = tmp;
+ }
+ *num = *num / b;
+ *denom = *denom / b;
+}
+
Modified: trunk/thoggen/src/th-utils.h
===================================================================
--- trunk/thoggen/src/th-utils.h 2007-12-26 03:20:42 UTC (rev 286)
+++ trunk/thoggen/src/th-utils.h 2007-12-26 16:25:13 UTC (rev 287)
@@ -108,4 +108,6 @@
const gchar *prop1_name,
...) G_GNUC_NULL_TERMINATED;
+void th_simplify_fraction (guint * num, guint * denom);
+
#endif /* _th_utils_h_included_ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|