/* ********************** typefinding in pull mode ************************ */
static void
-helper_find_suggest (gpointer data, guint probability, const GstCaps * caps);
+helper_find_suggest (gpointer data, guint probability, GstCaps * caps);
+
+typedef struct
+{
+ GstBuffer *buffer;
+ GstMapInfo map;
+} GstMappedBuffer;
typedef struct
{
GSList *insert_pos = NULL;
gsize buf_size;
guint64 buf_offset;
- GstMapInfo info;
+ GstMappedBuffer *bmap;
#if 0
GstCaps *caps;
#endif
GSList *walk;
for (walk = helper->buffers; walk; walk = walk->next) {
- GstBuffer *buf = GST_BUFFER_CAST (walk->data);
+ GstMappedBuffer *bmp = (GstMappedBuffer *) walk->data;
+ GstBuffer *buf = GST_BUFFER_CAST (bmp->buffer);
guint64 buf_offset = GST_BUFFER_OFFSET (buf);
guint buf_size = gst_buffer_get_size (buf);
* we're after the searched end offset */
if (buf_offset <= offset) {
if ((offset + size) < (buf_offset + buf_size)) {
- /* FIXME, unmap after usage */
- if (!gst_buffer_map (buf, &info, GST_MAP_READ))
- return NULL;
- return (guint8 *) info.data + (offset - buf_offset);
+ /* must already have been mapped before */
+ return (guint8 *) bmp->map.data + (offset - buf_offset);
}
} else if (offset + size >= buf_offset + buf_size) {
insert_pos = walk;
return NULL;
}
+ bmap = g_slice_new0 (GstMappedBuffer);
+ bmap->buffer = buffer;
if (insert_pos) {
- helper->buffers =
- g_slist_insert_before (helper->buffers, insert_pos, buffer);
+ helper->buffers = g_slist_insert_before (helper->buffers, insert_pos, bmap);
} else {
/* if insert_pos is not set, our offset is bigger than the largest offset
* we have so far; since we keep the list sorted with highest offsets
* first, we need to prepend the buffer to the list */
helper->last_offset = GST_BUFFER_OFFSET (buffer) + buf_size;
- helper->buffers = g_slist_prepend (helper->buffers, buffer);
+ helper->buffers = g_slist_prepend (helper->buffers, bmap);
}
- /* FIXME, unmap */
- gst_buffer_map (buffer, &info, GST_MAP_READ);
+ gst_buffer_map (buffer, &bmap->map, GST_MAP_READ);
- return info.data;
+ return bmap->map.data;
error:
{
*/
static void
helper_find_suggest (gpointer data, GstTypeFindProbability probability,
- const GstCaps * caps)
+ GstCaps * caps)
{
GstTypeFindHelper *helper = (GstTypeFindHelper *) data;
GST_OBJECT_NAME (helper->factory), probability, caps);
if (probability > helper->best_probability) {
- GstCaps *copy = gst_caps_copy (caps);
-
- gst_caps_take (&helper->caps, copy);
+ gst_caps_replace (&helper->caps, caps);
helper->best_probability = probability;
}
}
}
gst_plugin_feature_list_free (type_list);
- for (walk = helper.buffers; walk; walk = walk->next)
- gst_buffer_unref (GST_BUFFER_CAST (walk->data));
+ for (walk = helper.buffers; walk; walk = walk->next) {
+ GstMappedBuffer *bmap = (GstMappedBuffer *) walk->data;
+
+ gst_buffer_unmap (bmap->buffer, &bmap->map);
+ gst_buffer_unref (bmap->buffer);
+ g_slice_free (GstMappedBuffer, bmap);
+ }
g_slist_free (helper.buffers);
if (helper.best_probability > 0)
*/
static void
buf_helper_find_suggest (gpointer data, GstTypeFindProbability probability,
- const GstCaps * caps)
+ GstCaps * caps)
{
GstTypeFindBufHelper *helper = (GstTypeFindBufHelper *) data;
/* Note: not >= as we call typefinders in order of rank, highest first */
if (probability > helper->best_probability) {
- GstCaps *copy = gst_caps_copy (caps);
-
- gst_caps_replace (&helper->caps, copy);
- gst_caps_unref (copy);
+ gst_caps_replace (&helper->caps, caps);
helper->best_probability = probability;
}
}