Outdated: GstBaseParse was introduced in gstreamer-0.10.33. The text below may or may not reflect the current implementation. Read the current documentation for more information.

We need a base class for general parsers as most current parsers share a lot of rather complex code.

Implementation has started at bug 518857.


  • Keeping synchronization and splitting into complete frames that the subclass handles
  • TIMESTAMP and other metadata of buffers should be set by the base class as good as possible if the subclass didn't already
  • Pull & Push mode support
  • ?GstIndex
  • Event handling, especially NEWSEGMENT/SEEKING/EOS and friends
  • Query handling, especially DURATION/POSITION/CONVERT, let subclass provide methods for conversions
  • Seek handling, by calling the subclass' conversion method and in pull mode by scanning for the required frame and generating a seek table. Allow subclass to overwrite the accurate seeking behaviour.

Base class structure:

  • guint min_frame_size: minimal size required to check if this could be a valid frame and to calculate the size of the complete frame
  • gboolean check_valid_frame (GstBaseParse *parse, ?GstBuffer *buffer, guint *size): Gets a buffer of at least min_frame_size bytes passed. Should return TRUE if this looks like a valid frame and the size of the complete frame in size. Otherwise should return FALSE and the base class activates resynchronization logic.
  • ?GstFlowReturn parse_frame (GstBaseParse *parse, ?GstBuffer *buffer): Gets a complete frame passed. subclass should parse this, set caps as appropiate, set timestamp/duration/etc if it can, mark as keyframe, set duration if possible. Has a custom return value to get this frame dropped. The base class pushes the buffer downstream after processing, updating it's position values and adding buffer metadata that is missing and can be calculated. The passed buffer's offset, if set, is the byte offset from which this frame was read.
  • gboolean convert (GstBaseParse * parse, ?GstFormat src_format, gint64 src_value, ?GstFormat dest_format, gint64 * dest_value): converts from source to target format if possible, otherwise returns FALSE. Is used for queries and inaccurate seeks. GST_FORMAT_DEFAULT has the meaning of frames. Optional, if not implemented seeking will not be supported and queries might also not be supported in all formats.
  • gboolean find_frame (GstBaseParse *parse, ?GstFormat src_format, gint64 src_value, gint64 * dest_value): Gets a position passed and should return TRUE and the offset in bytes where this position is. Will only be called in pull mode and the subclass can pull whatever it wants from upstream. Optional, if not implemented the base class will implement it by calling check_valid_frame() and parse_frame() to find the wanted frame and build a seek table.


  • void gst_base_parse_set_duration (GstBaseParse *parse, ?GstFormat fmt, gint64 duration): Updates the duration in the given format for duration queries, etc.


Is something missing or not optimal?

It might make sense to have a way to let subclasses specify the minimal frame size necessary to read timestamp and other useful information and then let them implement a parse_frame_minimal() method that can be used for building the seek table in pull mode.