As we noted on demuxers before, we love common programming paradigms such as clean, lean and mean code. To achieve that in muxers, it's generally a good idea to separate the actual data stream markup from the data processing. To illustrate, here's how AVI muxers should write out RIFF tag chunks:
static void gst_avi_mux_write_chunk (GstAviMux *mux, guint32 id, GstBuffer *data) { GstBuffer *hdr; hdr = gst_buffer_new_and_alloc (8); ((guint32 *) GST_BUFFER_DATA (buf))[0] = GUINT32_TO_LE (id); ((guint32 *) GST_BUFFER_DATA (buf))[1] = GUINT32_TO_LE (GST_BUFFER_SIZE (data)); gst_pad_push (mux->srcpad, hdr); gst_pad_push (mux->srcpad, data); } static void gst_avi_mux_loop (GstElement *element) { GstAviMux *mux = GST_AVI_MUX (element); GstBuffer *buf; [..] buf = gst_pad_pull (mux->sinkpad[0]); [..] gst_avi_mux_write_chunk (GST_MAKE_FOURCC ('0','0','d','b'), buf); }
In general, try to program clean code, that should cover pretty much everything.