1/* vim: set filetype=c: */ 2% ClassName 3GstBaseTransform 4% TYPE_CLASS_NAME 5GST_TYPE_BASE_TRANSFORM 6% pads 7srcpad-simple 8sinkpad-simple 9% pkg-config 10gstreamer-base-1.0 11% includes 12#include <gst/base/gstbasetransform.h> 13% prototypes 14static GstCaps *gst_replace_transform_caps (GstBaseTransform * trans, 15 GstPadDirection direction, GstCaps * caps, GstCaps * filter); 16static GstCaps *gst_replace_fixate_caps (GstBaseTransform * trans, 17 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps); 18static gboolean gst_replace_accept_caps (GstBaseTransform * trans, 19 GstPadDirection direction, GstCaps * caps); 20static gboolean gst_replace_set_caps (GstBaseTransform * trans, 21 GstCaps * incaps, GstCaps * outcaps); 22static gboolean gst_replace_query (GstBaseTransform * trans, 23 GstPadDirection direction, GstQuery * query); 24static gboolean gst_replace_decide_allocation (GstBaseTransform * trans, 25 GstQuery * query); 26static gboolean gst_replace_filter_meta (GstBaseTransform * trans, 27 GstQuery * query, GType api, const GstStructure * params); 28static gboolean gst_replace_propose_allocation (GstBaseTransform * trans, 29 GstQuery * decide_query, GstQuery * query); 30static gboolean gst_replace_transform_size (GstBaseTransform * trans, 31 GstPadDirection direction, GstCaps * caps, gsize size, GstCaps * othercaps, 32 gsize * othersize); 33static gboolean gst_replace_get_unit_size (GstBaseTransform * trans, 34 GstCaps * caps, gsize * size); 35static gboolean gst_replace_start (GstBaseTransform * trans); 36static gboolean gst_replace_stop (GstBaseTransform * trans); 37static gboolean gst_replace_sink_event (GstBaseTransform * trans, 38 GstEvent * event); 39static gboolean gst_replace_src_event (GstBaseTransform * trans, 40 GstEvent * event); 41static GstFlowReturn gst_replace_prepare_output_buffer (GstBaseTransform * 42 trans, GstBuffer * input, GstBuffer ** outbuf); 43static gboolean gst_replace_copy_metadata (GstBaseTransform * trans, 44 GstBuffer * input, GstBuffer * outbuf); 45static gboolean gst_replace_transform_meta (GstBaseTransform * trans, 46 GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf); 47static void gst_replace_before_transform (GstBaseTransform * trans, 48 GstBuffer * buffer); 49static GstFlowReturn gst_replace_transform (GstBaseTransform * trans, 50 GstBuffer * inbuf, GstBuffer * outbuf); 51static GstFlowReturn gst_replace_transform_ip (GstBaseTransform * trans, 52 GstBuffer * buf); 53% declare-class 54 GstBaseTransformClass *base_transform_class = GST_BASE_TRANSFORM_CLASS (klass); 55% set-methods 56 base_transform_class->transform_caps = GST_DEBUG_FUNCPTR (gst_replace_transform_caps); 57 base_transform_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_replace_fixate_caps); 58 base_transform_class->accept_caps = GST_DEBUG_FUNCPTR (gst_replace_accept_caps); 59 base_transform_class->set_caps = GST_DEBUG_FUNCPTR (gst_replace_set_caps); 60 base_transform_class->query = GST_DEBUG_FUNCPTR (gst_replace_query); 61 base_transform_class->decide_allocation = GST_DEBUG_FUNCPTR (gst_replace_decide_allocation); 62 base_transform_class->filter_meta = GST_DEBUG_FUNCPTR (gst_replace_filter_meta); 63 base_transform_class->propose_allocation = GST_DEBUG_FUNCPTR (gst_replace_propose_allocation); 64 base_transform_class->transform_size = GST_DEBUG_FUNCPTR (gst_replace_transform_size); 65 base_transform_class->get_unit_size = GST_DEBUG_FUNCPTR (gst_replace_get_unit_size); 66 base_transform_class->start = GST_DEBUG_FUNCPTR (gst_replace_start); 67 base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_replace_stop); 68 base_transform_class->sink_event = GST_DEBUG_FUNCPTR (gst_replace_sink_event); 69 base_transform_class->src_event = GST_DEBUG_FUNCPTR (gst_replace_src_event); 70 base_transform_class->prepare_output_buffer = GST_DEBUG_FUNCPTR (gst_replace_prepare_output_buffer); 71 base_transform_class->copy_metadata = GST_DEBUG_FUNCPTR (gst_replace_copy_metadata); 72 base_transform_class->transform_meta = GST_DEBUG_FUNCPTR (gst_replace_transform_meta); 73 base_transform_class->before_transform = GST_DEBUG_FUNCPTR (gst_replace_before_transform); 74 base_transform_class->transform = GST_DEBUG_FUNCPTR (gst_replace_transform); 75 base_transform_class->transform_ip = GST_DEBUG_FUNCPTR (gst_replace_transform_ip); 76% methods 77static GstCaps * 78gst_replace_transform_caps (GstBaseTransform * trans, GstPadDirection direction, 79 GstCaps * caps, GstCaps * filter) 80{ 81 GstReplace *replace = GST_REPLACE (trans); 82 GstCaps *othercaps; 83 84 GST_DEBUG_OBJECT (replace, "transform_caps"); 85 86 othercaps = gst_caps_copy (caps); 87 88 /* Copy other caps and modify as appropriate */ 89 /* This works for the simplest cases, where the transform modifies one 90 * or more fields in the caps structure. It does not work correctly 91 * if passthrough caps are preferred. */ 92 if (direction == GST_PAD_SRC) { 93 /* transform caps going upstream */ 94 } else { 95 /* transform caps going downstream */ 96 } 97 98 if (filter) { 99 GstCaps *intersect; 100 101 intersect = gst_caps_intersect (othercaps, filter); 102 gst_caps_unref (othercaps); 103 104 return intersect; 105 } else { 106 return othercaps; 107 } 108} 109 110static GstCaps * 111gst_replace_fixate_caps (GstBaseTransform * trans, GstPadDirection direction, 112 GstCaps * caps, GstCaps * othercaps) 113{ 114 GstReplace *replace = GST_REPLACE (trans); 115 116 GST_DEBUG_OBJECT (replace, "fixate_caps"); 117 118 return NULL; 119} 120 121static gboolean 122gst_replace_accept_caps (GstBaseTransform * trans, GstPadDirection direction, 123 GstCaps * caps) 124{ 125 GstReplace *replace = GST_REPLACE (trans); 126 127 GST_DEBUG_OBJECT (replace, "accept_caps"); 128 129 return TRUE; 130} 131 132static gboolean 133gst_replace_set_caps (GstBaseTransform * trans, GstCaps * incaps, 134 GstCaps * outcaps) 135{ 136 GstReplace *replace = GST_REPLACE (trans); 137 138 GST_DEBUG_OBJECT (replace, "set_caps"); 139 140 return TRUE; 141} 142 143static gboolean 144gst_replace_query (GstBaseTransform * trans, GstPadDirection direction, 145 GstQuery * query) 146{ 147 GstReplace *replace = GST_REPLACE (trans); 148 149 GST_DEBUG_OBJECT (replace, "query"); 150 151 return TRUE; 152} 153 154/* decide allocation query for output buffers */ 155static gboolean 156gst_replace_decide_allocation (GstBaseTransform * trans, GstQuery * query) 157{ 158 GstReplace *replace = GST_REPLACE (trans); 159 160 GST_DEBUG_OBJECT (replace, "decide_allocation"); 161 162 return TRUE; 163} 164 165static gboolean 166gst_replace_filter_meta (GstBaseTransform * trans, GstQuery * query, GType api, 167 const GstStructure * params) 168{ 169 GstReplace *replace = GST_REPLACE (trans); 170 171 GST_DEBUG_OBJECT (replace, "filter_meta"); 172 173 return TRUE; 174} 175 176/* propose allocation query parameters for input buffers */ 177static gboolean 178gst_replace_propose_allocation (GstBaseTransform * trans, 179 GstQuery * decide_query, GstQuery * query) 180{ 181 GstReplace *replace = GST_REPLACE (trans); 182 183 GST_DEBUG_OBJECT (replace, "propose_allocation"); 184 185 return TRUE; 186} 187 188/* transform size */ 189static gboolean 190gst_replace_transform_size (GstBaseTransform * trans, GstPadDirection direction, 191 GstCaps * caps, gsize size, GstCaps * othercaps, gsize * othersize) 192{ 193 GstReplace *replace = GST_REPLACE (trans); 194 195 GST_DEBUG_OBJECT (replace, "transform_size"); 196 197 return TRUE; 198} 199 200static gboolean 201gst_replace_get_unit_size (GstBaseTransform * trans, GstCaps * caps, 202 gsize * size) 203{ 204 GstReplace *replace = GST_REPLACE (trans); 205 206 GST_DEBUG_OBJECT (replace, "get_unit_size"); 207 208 return TRUE; 209} 210 211/* states */ 212static gboolean 213gst_replace_start (GstBaseTransform * trans) 214{ 215 GstReplace *replace = GST_REPLACE (trans); 216 217 GST_DEBUG_OBJECT (replace, "start"); 218 219 return TRUE; 220} 221 222static gboolean 223gst_replace_stop (GstBaseTransform * trans) 224{ 225 GstReplace *replace = GST_REPLACE (trans); 226 227 GST_DEBUG_OBJECT (replace, "stop"); 228 229 return TRUE; 230} 231 232/* sink and src pad event handlers */ 233static gboolean 234gst_replace_sink_event (GstBaseTransform * trans, GstEvent * event) 235{ 236 GstReplace *replace = GST_REPLACE (trans); 237 238 GST_DEBUG_OBJECT (replace, "sink_event"); 239 240 return GST_BASE_TRANSFORM_CLASS (gst_replace_parent_class)->sink_event ( 241 trans, event); 242} 243 244static gboolean 245gst_replace_src_event (GstBaseTransform * trans, GstEvent * event) 246{ 247 GstReplace *replace = GST_REPLACE (trans); 248 249 GST_DEBUG_OBJECT (replace, "src_event"); 250 251 return GST_BASE_TRANSFORM_CLASS (gst_replace_parent_class)->src_event ( 252 trans, event); 253} 254 255static GstFlowReturn 256gst_replace_prepare_output_buffer (GstBaseTransform * trans, GstBuffer * input, 257 GstBuffer ** outbuf) 258{ 259 GstReplace *replace = GST_REPLACE (trans); 260 261 GST_DEBUG_OBJECT (replace, "prepare_output_buffer"); 262 263 return GST_FLOW_OK; 264} 265 266/* metadata */ 267static gboolean 268gst_replace_copy_metadata (GstBaseTransform * trans, GstBuffer * input, 269 GstBuffer * outbuf) 270{ 271 GstReplace *replace = GST_REPLACE (trans); 272 273 GST_DEBUG_OBJECT (replace, "copy_metadata"); 274 275 return TRUE; 276} 277 278static gboolean 279gst_replace_transform_meta (GstBaseTransform * trans, GstBuffer * outbuf, 280 GstMeta * meta, GstBuffer * inbuf) 281{ 282 GstReplace *replace = GST_REPLACE (trans); 283 284 GST_DEBUG_OBJECT (replace, "transform_meta"); 285 286 return TRUE; 287} 288 289static void 290gst_replace_before_transform (GstBaseTransform * trans, GstBuffer * buffer) 291{ 292 GstReplace *replace = GST_REPLACE (trans); 293 294 GST_DEBUG_OBJECT (replace, "before_transform"); 295 296} 297 298/* transform */ 299static GstFlowReturn 300gst_replace_transform (GstBaseTransform * trans, GstBuffer * inbuf, 301 GstBuffer * outbuf) 302{ 303 GstReplace *replace = GST_REPLACE (trans); 304 305 GST_DEBUG_OBJECT (replace, "transform"); 306 307 return GST_FLOW_OK; 308} 309 310static GstFlowReturn 311gst_replace_transform_ip (GstBaseTransform * trans, GstBuffer * buf) 312{ 313 GstReplace *replace = GST_REPLACE (trans); 314 315 GST_DEBUG_OBJECT (replace, "transform_ip"); 316 317 return GST_FLOW_OK; 318} 319% end 320