Commit 3ef4b196 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix EOF check and remove fprintf

parent 956c05ba
...@@ -343,7 +343,6 @@ static void mmapRelease (block_t *block) ...@@ -343,7 +343,6 @@ static void mmapRelease (block_t *block)
{ {
block_sys_t *p_sys = (block_sys_t *)block; block_sys_t *p_sys = (block_sys_t *)block;
fprintf (stderr, "munmap (%p, %u)\n", p_sys->base_addr, MMAP_SIZE);
munmap (p_sys->base_addr, p_sys->length); munmap (p_sys->base_addr, p_sys->length);
//vlc_object_release (p_sys->owner); //vlc_object_release (p_sys->owner);
free (p_sys); free (p_sys);
...@@ -360,30 +359,34 @@ static block_t *mmapBlock (access_t *p_access) ...@@ -360,30 +359,34 @@ static block_t *mmapBlock (access_t *p_access)
size_t length = (MMAP_SIZE > pagesize) ? MMAP_SIZE : pagesize; size_t length = (MMAP_SIZE > pagesize) ? MMAP_SIZE : pagesize;
void *addr; void *addr;
/* File grown while being played? */ if (p_access->info.i_pos >= p_access->info.i_size)
if (offset + length >= p_access->info.i_size)
{ {
/* End of file - check that file size hasn't change... */
struct stat st; struct stat st;
if ((fstat (p_sys->fd, &st) == 0) if ((fstat (p_sys->fd, &st) == 0)
&& (st.st_size > p_access->info.i_size)) && (st.st_size != p_access->info.i_size))
{ {
p_access->info.i_size = st.st_size; p_access->info.i_size = st.st_size;
p_access->info.i_update |= INPUT_UPDATE_SIZE; p_access->info.i_update |= INPUT_UPDATE_SIZE;
} }
}
/* Really at end of file? */ /* Really at end of file then */
if (offset >= p_access->info.i_size) if (p_access->info.i_pos >= p_access->info.i_size)
{ {
p_access->info.b_eof = VLC_TRUE; p_access->info.b_eof = VLC_TRUE;
msg_Dbg (p_access, "at end of memory mapped file"); msg_Dbg (p_access, "at end of memory mapped file");
return NULL; return NULL;
} }
}
if (offset + length > p_access->info.i_size) if (offset + length > p_access->info.i_size)
/* Don't mmap paste end of file */
length = p_access->info.i_size - offset; length = p_access->info.i_size - offset;
assert (offset <= p_access->info.i_pos); /* and */
assert (p_access->info.i_pos < p_access->info.i_size); /* imply */
assert (offset < p_access->info.i_size); /* imply */
assert (length > 0); assert (length > 0);
addr = mmap (NULL, length, PROT_READ, flags, p_sys->fd, offset); addr = mmap (NULL, length, PROT_READ, flags, p_sys->fd, offset);
...@@ -394,7 +397,7 @@ static block_t *mmapBlock (access_t *p_access) ...@@ -394,7 +397,7 @@ static block_t *mmapBlock (access_t *p_access)
return NULL; return NULL;
} }
p_access->info.i_pos += length; p_access->info.i_pos = offset + length;
msg_Dbg (p_access, "mapped %lu bytes at %p from offset %lu", msg_Dbg (p_access, "mapped %lu bytes at %p from offset %lu",
(unsigned long)length, addr, (unsigned long)offset); (unsigned long)length, addr, (unsigned long)offset);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment