summaryrefslogtreecommitdiff
blob: 2a791d018139e59e7fd3dd17c75124f63c61a69e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
From c1b33e01fa6fa867b950ba0e6f4426e5a878cbe7 Mon Sep 17 00:00:00 2001
From: Rob Clark <rob@ti.com>
Date: Sun, 16 Aug 2009 21:04:40 -0500
Subject: [PATCH 05/24] add gst_stride_transform_transform_size()

input buffer size and output buffer size many not be multiples of a common unit size, so the transform_size() method should be used
---
 gst/stride/gststridetransform.c |   38 ++++++++++++++++++++++++++++++++++++--
 gst/stride/gststridetransform.h |   34 +++++-----------------------------
 2 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/gst/stride/gststridetransform.c b/gst/stride/gststridetransform.c
index a911cd0..adc22ce 100644
--- a/gst/stride/gststridetransform.c
+++ b/gst/stride/gststridetransform.c
@@ -62,7 +62,7 @@ GST_ELEMENT_DETAILS ("Stride transform",
 
 /* TODO: add rgb formats too! */
 #define SUPPORTED_CAPS                                                        \
-  GST_VIDEO_CAPS_YUV_STRIDED ("{ I420, YV12, YUY2 }", "[ 0, max ]")
+  GST_VIDEO_CAPS_YUV_STRIDED ("{ I420, YV12, YUY2, UYVY }", "[ 0, max ]")
 
 
 static GstStaticPadTemplate src_template =
@@ -89,6 +89,10 @@ static void gst_stride_transform_dispose (GObject *obj);
 /* GstBaseTransform functions */
 static gboolean gst_stride_transform_get_unit_size (GstBaseTransform *base,
     GstCaps *caps, guint *size);
+static gboolean gst_stride_transform_transform_size (GstBaseTransform *base,
+    GstPadDirection direction,
+    GstCaps *caps, guint size,
+    GstCaps *othercaps, guint *othersize);
 static GstCaps *gst_stride_transform_transform_caps (GstBaseTransform *base,
     GstPadDirection direction, GstCaps *caps);
 static gboolean gst_stride_transform_set_caps (GstBaseTransform *base,
@@ -126,6 +130,8 @@ gst_stride_transform_class_init (GstStrideTransformClass *klass)
 
   basetransform_class->get_unit_size =
       GST_DEBUG_FUNCPTR (gst_stride_transform_get_unit_size);
+  basetransform_class->transform_size =
+      GST_DEBUG_FUNCPTR (gst_stride_transform_transform_size);
   basetransform_class->transform_caps =
       GST_DEBUG_FUNCPTR (gst_stride_transform_transform_caps);
   basetransform_class->set_caps =
@@ -176,6 +182,34 @@ gst_stride_transform_get_unit_size (GstBaseTransform *base,
   return TRUE;
 }
 
+/**
+ * Default transform_size function is no good, as it assumes that the output
+ * buffer size is a multiple of the unit size.. which doesn't hold true.
+ */
+static gboolean
+gst_stride_transform_transform_size (GstBaseTransform *base,
+    GstPadDirection direction,
+    GstCaps *caps, guint size,
+    GstCaps *othercaps, guint *othersize)
+{
+  GstStrideTransform *self = GST_STRIDE_TRANSFORM (base);
+  guint idx = (direction == GST_PAD_SINK) ? 0 : 1;
+
+  if (self->cached_caps[idx] != othercaps)
+  {
+    if (!gst_stride_transform_get_unit_size (base, othercaps,
+        &(self->cached_size[idx])))
+    {
+      return FALSE;
+    }
+  }
+
+  *othersize = self->cached_size[idx];
+
+  return TRUE;
+}
+
+
 
 /**
  * helper to add all fields, other than rowstride to @caps, copied from @s.
@@ -187,7 +221,7 @@ add_all_fields (GstCaps *caps, const gchar *name, GstStructure *s, gboolean rows
   GstStructure *new_s = gst_structure_new (name, NULL);
 
   if (rowstride) {
-    gst_structure_set (new_s, "rowstride", GST_TYPE_INT_RANGE, 1, 1000, NULL);  // TODO
+    gst_structure_set (new_s, "rowstride", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
   }
 
   idx = gst_structure_n_fields (s) - 1;
diff --git a/gst/stride/gststridetransform.h b/gst/stride/gststridetransform.h
index d80197f..481959e 100644
--- a/gst/stride/gststridetransform.h
+++ b/gst/stride/gststridetransform.h
@@ -59,6 +59,10 @@ struct _GstStrideTransform {
   gint width, height;
   gint in_rowstride;
   gint out_rowstride;
+
+  /* for caching the tranform_size() results.. */
+  GstCaps *cached_caps[2];
+  guint cached_size[2];
 };
 
 struct _GstStrideTransformClass {
@@ -70,35 +74,7 @@ GType gst_stride_transform_get_type (void);
 G_END_DECLS
 
 
-
-
-/* note:  in case this is a build with TTIF logging, we can optimize slightly
- * and avoid the gst_caps_to_string() in case logging isn't enabled by using
- * the TTIF_TRACE_ARG_PROCESSOR feature of ttif_trace_fprintf():
- */
-#ifdef GST_LOG_OVER_TTIF
-#  define LOG_CAPS(obj, caps)    G_STMT_START {                 \
-    if (caps) {                                                 \
-      static TTIF_TRACE_ARG_PROCESSOR proc = {                  \
-        .convert = (char (*)(void *))gst_caps_to_string,        \
-        .free    = (void (*)(char *))g_free                     \
-      };                                                        \
-      GST_DEBUG_OBJECT (obj, "%s: %qs", #caps, &proc, (caps));  \
-    } else {                                                    \
-      GST_DEBUG_OBJECT (obj, "null");                           \
-    }                                                           \
-  } G_STMT_END
-#else
-#  define LOG_CAPS(obj, caps)    G_STMT_START {                 \
-    if (caps) {                                                 \
-      gchar *capstr = gst_caps_to_string (caps);                \
-      GST_DEBUG_OBJECT (obj, "%s: %s", #caps, capstr);          \
-      g_free (capstr);                                          \
-    } else {                                                    \
-      GST_DEBUG_OBJECT (obj, "null");                           \
-    }                                                           \
-  } G_STMT_END
-#endif
+#define LOG_CAPS(obj, caps)  GST_DEBUG_OBJECT (obj, "%s: %"GST_PTR_FORMAT, #caps, caps)
 
 
 #endif /* __GSTSTRIDETRANSFORM_H__ */
-- 
1.7.1