{
GstBuffer *buf;
gint retval;
+ void *mmapregion;
g_return_val_if_fail (offset >= 0, NULL);
fs_print ("mapping region %08llx+%08x from file into memory\n",offset,size);
+ mmapregion = mmap (NULL, size, PROT_READ, MAP_SHARED, src->fd, offset);
- /* time to allocate a new mapbuf */
- buf = gst_buffer_new();
- /* mmap() the data into this new buffer */
- GST_BUFFER_DATA(buf) = mmap (NULL, size, PROT_READ, MAP_SHARED, src->fd, offset);
- if (GST_BUFFER_DATA(buf) == NULL) {
+ if (mmapregion == NULL) {
gst_element_error (GST_ELEMENT (src), "couldn't map file");
- } else if (GST_BUFFER_DATA(buf) == MAP_FAILED) {
+ return NULL;
+ }
+ else if (mmapregion == MAP_FAILED) {
gst_element_error (GST_ELEMENT (src), "mmap (0x%x, %d, 0x%llx) : %s",
size, src->fd, offset, strerror (errno));
+ return NULL;
}
+
+ /* time to allocate a new mapbuf */
+ buf = gst_buffer_new();
+ /* mmap() the data into this new buffer */
+ GST_BUFFER_DATA(buf) = mmapregion;
+
#ifdef MADV_SEQUENTIAL
/* madvise to tell the kernel what to do with it */
retval = madvise(GST_BUFFER_DATA(buf),GST_BUFFER_SIZE(buf),MADV_SEQUENTIAL);
mapsize = ((size + mod + src->pagesize - 1) / src->pagesize) * src->pagesize;
/* printf("not on page boundaries, resizing map to %d+%d\n",mapbase,mapsize);*/
map = gst_filesrc_map_region(src, mapbase, mapsize);
+ if (map == NULL)
+ return NULL;
+
ret = gst_buffer_create_sub (map, offset - mapbase, size);
gst_buffer_unref (map);
}
/* create a new one */
src->mapbuf = gst_filesrc_map_region (src, nextmap, mapsize);
+ if (src->mapbuf == NULL)
+ return NULL;
+
/* subbuffer it */
buf = gst_buffer_create_sub (src->mapbuf, src->curoffset - nextmap, readsize);
}
/* allocate the first mmap'd region */
src->mapbuf = gst_filesrc_map_region (src, 0, src->mapsize);
+ if (src->mapbuf == NULL)
+ return FALSE;
src->curoffset = 0;
{
GstBuffer *buf;
gint retval;
+ void *mmapregion;
g_return_val_if_fail (offset >= 0, NULL);
fs_print ("mapping region %08llx+%08x from file into memory\n",offset,size);
+ mmapregion = mmap (NULL, size, PROT_READ, MAP_SHARED, src->fd, offset);
- /* time to allocate a new mapbuf */
- buf = gst_buffer_new();
- /* mmap() the data into this new buffer */
- GST_BUFFER_DATA(buf) = mmap (NULL, size, PROT_READ, MAP_SHARED, src->fd, offset);
- if (GST_BUFFER_DATA(buf) == NULL) {
+ if (mmapregion == NULL) {
gst_element_error (GST_ELEMENT (src), "couldn't map file");
- } else if (GST_BUFFER_DATA(buf) == MAP_FAILED) {
+ return NULL;
+ }
+ else if (mmapregion == MAP_FAILED) {
gst_element_error (GST_ELEMENT (src), "mmap (0x%x, %d, 0x%llx) : %s",
size, src->fd, offset, strerror (errno));
+ return NULL;
}
+
+ /* time to allocate a new mapbuf */
+ buf = gst_buffer_new();
+ /* mmap() the data into this new buffer */
+ GST_BUFFER_DATA(buf) = mmapregion;
+
#ifdef MADV_SEQUENTIAL
/* madvise to tell the kernel what to do with it */
retval = madvise(GST_BUFFER_DATA(buf),GST_BUFFER_SIZE(buf),MADV_SEQUENTIAL);
mapsize = ((size + mod + src->pagesize - 1) / src->pagesize) * src->pagesize;
/* printf("not on page boundaries, resizing map to %d+%d\n",mapbase,mapsize);*/
map = gst_filesrc_map_region(src, mapbase, mapsize);
+ if (map == NULL)
+ return NULL;
+
ret = gst_buffer_create_sub (map, offset - mapbase, size);
gst_buffer_unref (map);
}
/* create a new one */
src->mapbuf = gst_filesrc_map_region (src, nextmap, mapsize);
+ if (src->mapbuf == NULL)
+ return NULL;
+
/* subbuffer it */
buf = gst_buffer_create_sub (src->mapbuf, src->curoffset - nextmap, readsize);
}
/* allocate the first mmap'd region */
src->mapbuf = gst_filesrc_map_region (src, 0, src->mapsize);
+ if (src->mapbuf == NULL)
+ return FALSE;
src->curoffset = 0;