Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-gpu
Commits
2ec9d996
Commit
2ec9d996
authored
May 20, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
block_File: loads a file into a block_t
parent
c65b4ea9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
10 deletions
+86
-10
include/vlc_block.h
include/vlc_block.h
+1
-10
src/libvlccore.sym
src/libvlccore.sym
+1
-0
src/misc/block.c
src/misc/block.c
+84
-0
No files found.
include/vlc_block.h
View file @
2ec9d996
...
@@ -148,17 +148,8 @@ static inline void block_Release( block_t *p_block )
...
@@ -148,17 +148,8 @@ static inline void block_Release( block_t *p_block )
p_block
->
pf_release
(
p_block
);
p_block
->
pf_release
(
p_block
);
}
}
/**
* Creates a block from a virtual address memory mapping (mmap).
* This is provided by LibVLC so that mmap blocks can safely be deallocated
* even after the allocating plugin has been unloaded from memory.
*
* @param addr base address of the mapping (as returned by mmap)
* @param length length (bytes) of the mapping (as passed to mmap)
* @return NULL if addr is MAP_FAILED, or an error occurred (in the later
* case, munmap(addr, length) is invoked before returning).
*/
VLC_EXPORT
(
block_t
*
,
block_mmap_Alloc
,
(
void
*
addr
,
size_t
length
)
);
VLC_EXPORT
(
block_t
*
,
block_mmap_Alloc
,
(
void
*
addr
,
size_t
length
)
);
VLC_EXPORT
(
block_t
*
,
block_File
,
(
int
fd
)
);
/****************************************************************************
/****************************************************************************
* Chains of blocks functions helper
* Chains of blocks functions helper
...
...
src/libvlccore.sym
View file @
2ec9d996
...
@@ -41,6 +41,7 @@ block_FifoRelease
...
@@ -41,6 +41,7 @@ block_FifoRelease
block_FifoShow
block_FifoShow
block_FifoSize
block_FifoSize
block_FifoWake
block_FifoWake
block_File
block_Init
block_Init
block_mmap_Alloc
block_mmap_Alloc
block_Realloc
block_Realloc
...
...
src/misc/block.c
View file @
2ec9d996
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#endif
#endif
#include <vlc/vlc.h>
#include <vlc/vlc.h>
#include <sys/stat.h>
#include "vlc_block.h"
#include "vlc_block.h"
/*****************************************************************************
/*****************************************************************************
...
@@ -208,6 +209,16 @@ static void block_mmap_Release (block_t *block)
...
@@ -208,6 +209,16 @@ static void block_mmap_Release (block_t *block)
free
(
p_sys
);
free
(
p_sys
);
}
}
/**
* Creates a block from a virtual address memory mapping (mmap).
* This is provided by LibVLC so that mmap blocks can safely be deallocated
* even after the allocating plugin has been unloaded from memory.
*
* @param addr base address of the mapping (as returned by mmap)
* @param length length (bytes) of the mapping (as passed to mmap)
* @return NULL if addr is MAP_FAILED, or an error occurred (in the later
* case, munmap(addr, length) is invoked before returning).
*/
block_t
*
block_mmap_Alloc
(
void
*
addr
,
size_t
length
)
block_t
*
block_mmap_Alloc
(
void
*
addr
,
size_t
length
)
{
{
if
(
addr
==
MAP_FAILED
)
if
(
addr
==
MAP_FAILED
)
...
@@ -247,6 +258,79 @@ ssize_t pread (int fd, void *buf, size_t count, off_t offset)
...
@@ -247,6 +258,79 @@ ssize_t pread (int fd, void *buf, size_t count, off_t offset)
}
}
#endif
#endif
/**
* Loads a file into a block of memory. If possible a private file mapping is
* created. Otherwise, the file is read normally. On 32-bits platforms, this
* function will not work for very large files, due to memory space
* constraints.
*
* @param fd file descriptor to load from
* @return a new block with the file content at p_buffer, and file length at
* i_buffer (release it with block_Release()), or NULL upon error (see errno).
*/
block_t
*
block_File
(
int
fd
)
{
size_t
length
;
struct
stat
st
;
/* First, get the file size */
if
(
fstat
(
fd
,
&
st
))
return
NULL
;
/* st_size is meaningful for regular files, shared memory and typed memory.
* It's also meaning for symlinks, but that's not possible with fstat().
* In other cases, it's undefined, and we should really not go further. */
#ifndef S_TYPEISSHM
# define S_TYPEISSHM( buf ) (0)
#endif
if
(
S_ISDIR
(
st
.
st_mode
))
{
errno
=
EISDIR
;
return
NULL
;
}
if
(
!
S_ISREG
(
st
.
st_mode
)
&&
!
S_TYPEISSHM
(
&
st
))
{
errno
=
ESPIPE
;
return
NULL
;
}
/* Prevent an integer overflow in mmap() and malloc() */
if
(
st
.
st_size
>=
SIZE_MAX
)
{
errno
=
ENOMEM
;
return
NULL
;
}
length
=
(
size_t
)
st
.
st_size
;
#ifdef HAVE_MMAP
if
(
length
>
0
)
{
void
*
addr
;
addr
=
mmap
(
NULL
,
length
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
,
fd
,
0
);
if
(
addr
!=
MAP_FAILED
)
return
block_mmap_Alloc
(
addr
,
length
);
}
#endif
/* If mmap() is not implemented by the OS _or_ the filesystem... */
block_t
*
block
=
block_Alloc
(
length
);
if
(
block
==
NULL
)
return
NULL
;
for
(
size_t
i
=
0
;
i
<
length
;)
{
ssize_t
len
=
pread
(
fd
,
block
->
p_buffer
+
i
,
length
-
i
,
i
);
if
(
len
==
-
1
)
{
block_Release
(
block
);
return
NULL
;
}
i
+=
len
;
}
return
block
;
}
/*****************************************************************************
/*****************************************************************************
* block_fifo_t management
* block_fifo_t management
*****************************************************************************/
*****************************************************************************/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment