Skip to content

crash when mapping empty GstBuffer #110

Closed
@i-n-g-o

Description

@i-n-g-o

testcode:

        final Element elem = ElementFactory.make("identity", "src");
        final Pad     src  = elem.getStaticPad("src");

        final DATA_PROBE data_probe = new DATA_PROBE() {

            @Override
            public PadProbeReturn dataReceived(final Pad pad, final Buffer buffer) {

                final ByteBuffer data = buffer.map(false);

                // do something with data
                if (data != null) {
                    System.out.println("probeCB: buf with size: " + data.capacity());
                }

                buffer.unmap();
                return PadProbeReturn.OK;
            }
        };

        // add a dataprobe
        src.addDataProbe(data_probe);

        // start element
        elem.play();

        // push buffers to pad
        // crash with 0-size buffers
        // no crash when using a size > 0
        for (int i = 0; i < 2; i++) {
            final Buffer b = new Buffer(0);
            src.push(b);
        }

        elem.stop();

similar code in c does not show this behaviour:

#include <gst/gst.h>

GstPadProbeReturn probeCB (GstPad *pad,
                           GstPadProbeInfo *info,
                           gpointer user_data) {

  GstMapInfo mapinfo;
  // we know what we do, no need to check info for type!
  // directly get buffer from GstPadProbeInfo
  GstBuffer *buf = gst_pad_probe_info_get_buffer(info);
  if (buf != NULL) {
    if (gst_buffer_map (buf, &mapinfo, GST_MAP_READ)) {
      g_print("probeCB: buf with size: %lu\n", mapinfo.size);
    }
    gst_buffer_unmap(buf, &mapinfo);
  }
  return GST_PAD_PROBE_OK;
}

int main (int   argc, char *argv[]) {

  gst_init (&argc, &argv);
  GstElement *src;
  GstPad* pad;
  gulong probeid;
  int i;

  src = gst_element_factory_make ("identity", "src");
  pad = gst_element_get_static_pad(src, "src");
  probeid = gst_pad_add_probe (pad,
                               GST_PAD_PROBE_TYPE_BUFFER,
                               probeCB,
                               NULL,
                               NULL);
  g_print("probe id: %lu\n", probeid);

  // play
  gst_element_set_state (src, GST_STATE_PLAYING);

  for (i=0; i<2; i++) {
    GstBuffer* buf = gst_buffer_new_allocate(NULL, 0, NULL);
    gst_pad_push(pad, buf);
  }

  // stop
  gst_element_set_state (src, GST_STATE_NULL);

  // cleanup
  gst_pad_remove_probe (pad, probeid);
  gst_object_unref (GST_OBJECT (pad));
  gst_object_unref (GST_OBJECT (src));

  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions